symdef.inc 117 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076
  1. {
  2. $Id$
  3. Copyright (c) 1998-2000 by Florian Klaempfl, Pierre Muller
  4. Symbol table implementation for the definitions
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. {****************************************************************************
  19. TDEF (base class for definitions)
  20. ****************************************************************************}
  21. const
  22. { if you change one of the following contants, }
  23. { you have also to change the typinfo unit }
  24. { and the rtl/i386,template/rttip.inc files }
  25. tkUnknown = 0;
  26. tkInteger = 1;
  27. tkChar = 2;
  28. tkEnumeration = 3;
  29. tkFloat = 4;
  30. tkSet = 5;
  31. tkMethod = 6;
  32. tkSString = 7;
  33. tkString = tkSString;
  34. tkLString = 8;
  35. tkAString = 9;
  36. tkWString = 10;
  37. tkVariant = 11;
  38. tkArray = 12;
  39. tkRecord = 13;
  40. tkInterface = 14;
  41. tkClass = 15;
  42. tkObject = 16;
  43. tkWChar = 17;
  44. tkBool = 18;
  45. otSByte = 0;
  46. otUByte = 1;
  47. otSWord = 2;
  48. otUWord = 3;
  49. otSLong = 4;
  50. otULong = 5;
  51. ftSingle = 0;
  52. ftDouble = 1;
  53. ftExtended = 2;
  54. ftComp = 3;
  55. ftCurr = 4;
  56. ftFixed16 = 5;
  57. ftFixed32 = 6;
  58. mkProcedure = 0;
  59. mkFunction = 1;
  60. mkConstructor = 2;
  61. mkDestructor = 3;
  62. mkClassProcedure= 4;
  63. mkClassFunction = 5;
  64. pfvar = 1;
  65. pfConst = 2;
  66. pfArray = 4;
  67. pfAddress = 8;
  68. pfReference = 16;
  69. pfOut = 32;
  70. constructor tdef.init;
  71. begin
  72. inherited init;
  73. deftype:=abstractdef;
  74. owner := nil;
  75. typesym := nil;
  76. savesize := 0;
  77. if registerdef then
  78. symtablestack^.registerdef(@self);
  79. has_rtti:=false;
  80. has_inittable:=false;
  81. {$ifdef GDB}
  82. is_def_stab_written := false;
  83. globalnb := 0;
  84. {$endif GDB}
  85. if assigned(lastglobaldef) then
  86. begin
  87. lastglobaldef^.nextglobal := @self;
  88. previousglobal:=lastglobaldef;
  89. end
  90. else
  91. begin
  92. firstglobaldef := @self;
  93. previousglobal := nil;
  94. end;
  95. lastglobaldef := @self;
  96. nextglobal := nil;
  97. end;
  98. constructor tdef.load;
  99. begin
  100. deftype:=abstractdef;
  101. next := nil;
  102. owner := nil;
  103. has_rtti:=false;
  104. has_inittable:=false;
  105. {$ifdef GDB}
  106. is_def_stab_written := false;
  107. globalnb := 0;
  108. {$endif GDB}
  109. if assigned(lastglobaldef) then
  110. begin
  111. lastglobaldef^.nextglobal := @self;
  112. previousglobal:=lastglobaldef;
  113. end
  114. else
  115. begin
  116. firstglobaldef := @self;
  117. previousglobal:=nil;
  118. end;
  119. lastglobaldef := @self;
  120. nextglobal := nil;
  121. { load }
  122. indexnr:=readword;
  123. typesym:=ptypesym(readsymref);
  124. end;
  125. destructor tdef.done;
  126. begin
  127. { first element ? }
  128. if not(assigned(previousglobal)) then
  129. begin
  130. firstglobaldef := nextglobal;
  131. if assigned(firstglobaldef) then
  132. firstglobaldef^.previousglobal:=nil;
  133. end
  134. else
  135. begin
  136. { remove reference in the element before }
  137. previousglobal^.nextglobal:=nextglobal;
  138. end;
  139. { last element ? }
  140. if not(assigned(nextglobal)) then
  141. begin
  142. lastglobaldef := previousglobal;
  143. if assigned(lastglobaldef) then
  144. lastglobaldef^.nextglobal:=nil;
  145. end
  146. else
  147. nextglobal^.previousglobal:=previousglobal;
  148. previousglobal:=nil;
  149. nextglobal:=nil;
  150. {$ifdef SYNONYM}
  151. while assigned(typesym) do
  152. begin
  153. typesym^.restype.setdef(nil);
  154. typesym:=typesym^.synonym;
  155. end;
  156. {$endif}
  157. end;
  158. { used for enumdef because the symbols are
  159. inserted in the owner symtable }
  160. procedure tdef.correct_owner_symtable;
  161. var
  162. st : psymtable;
  163. begin
  164. if assigned(owner) and
  165. (owner^.symtabletype in [recordsymtable,objectsymtable]) then
  166. begin
  167. owner^.defindex^.deleteindex(@self);
  168. st:=owner;
  169. while (st^.symtabletype in [recordsymtable,objectsymtable]) do
  170. st:=st^.next;
  171. st^.registerdef(@self);
  172. end;
  173. end;
  174. function tdef.typename:string;
  175. begin
  176. if assigned(typesym) then
  177. typename:=Upper(typesym^.name)
  178. else
  179. typename:=gettypename;
  180. end;
  181. function tdef.gettypename : string;
  182. begin
  183. gettypename:='<unknown type>'
  184. end;
  185. function tdef.is_in_current : boolean;
  186. var
  187. p : psymtable;
  188. begin
  189. p:=owner;
  190. is_in_current:=false;
  191. while assigned(p) do
  192. begin
  193. if (p=current_module^.globalsymtable) or (p=current_module^.localsymtable)
  194. or (p^.symtabletype in [globalsymtable,staticsymtable]) then
  195. begin
  196. is_in_current:=true;
  197. exit;
  198. end
  199. else if p^.symtabletype in [localsymtable,parasymtable,objectsymtable] then
  200. begin
  201. if assigned(p^.defowner) then
  202. p:=pobjectdef(p^.defowner)^.owner
  203. else
  204. exit;
  205. end
  206. else
  207. exit;
  208. end;
  209. end;
  210. procedure tdef.write;
  211. begin
  212. writeword(indexnr);
  213. writesymref(typesym);
  214. {$ifdef GDB}
  215. if globalnb = 0 then
  216. begin
  217. if assigned(owner) then
  218. globalnb := owner^.getnewtypecount
  219. else
  220. begin
  221. globalnb := PGlobalTypeCount^;
  222. Inc(PGlobalTypeCount^);
  223. end;
  224. end;
  225. {$endif GDB}
  226. end;
  227. function tdef.size : longint;
  228. begin
  229. size:=savesize;
  230. end;
  231. function tdef.alignment : longint;
  232. begin
  233. { normal alignment by default }
  234. alignment:=0;
  235. end;
  236. {$ifdef GDB}
  237. procedure tdef.set_globalnb;
  238. begin
  239. globalnb :=PGlobalTypeCount^;
  240. inc(PglobalTypeCount^);
  241. end;
  242. function tdef.stabstring : pchar;
  243. begin
  244. stabstring := strpnew('t'+numberstring+';');
  245. end;
  246. function tdef.numberstring : string;
  247. var table : psymtable;
  248. begin
  249. {formal def have no type !}
  250. if deftype = formaldef then
  251. begin
  252. numberstring := voiddef^.numberstring;
  253. exit;
  254. end;
  255. if (not assigned(typesym)) or (not typesym^.isusedinstab) then
  256. begin
  257. {set even if debuglist is not defined}
  258. if assigned(typesym) then
  259. typesym^.isusedinstab := true;
  260. if assigned(debuglist) and not is_def_stab_written then
  261. concatstabto(debuglist);
  262. end;
  263. if not (cs_gdb_dbx in aktglobalswitches) then
  264. begin
  265. if globalnb = 0 then
  266. set_globalnb;
  267. numberstring := tostr(globalnb);
  268. end
  269. else
  270. begin
  271. if globalnb = 0 then
  272. begin
  273. if assigned(owner) then
  274. globalnb := owner^.getnewtypecount
  275. else
  276. begin
  277. globalnb := PGlobalTypeCount^;
  278. Inc(PGlobalTypeCount^);
  279. end;
  280. end;
  281. if assigned(typesym) then
  282. begin
  283. table := typesym^.owner;
  284. if table^.unitid > 0 then
  285. numberstring := '('+tostr(table^.unitid)+','+tostr(typesym^.restype.def^.globalnb)+')'
  286. else
  287. numberstring := tostr(globalnb);
  288. exit;
  289. end;
  290. numberstring := tostr(globalnb);
  291. end;
  292. end;
  293. function tdef.allstabstring : pchar;
  294. var stabchar : string[2];
  295. ss,st : pchar;
  296. sname : string;
  297. sym_line_no : longint;
  298. begin
  299. ss := stabstring;
  300. getmem(st,strlen(ss)+512);
  301. stabchar := 't';
  302. if deftype in tagtypes then
  303. stabchar := 'Tt';
  304. if assigned(typesym) then
  305. begin
  306. sname := typesym^.name;
  307. sym_line_no:=typesym^.fileinfo.line;
  308. end
  309. else
  310. begin
  311. sname := ' ';
  312. sym_line_no:=0;
  313. end;
  314. strpcopy(st,'"'+sname+':'+stabchar+numberstring+'=');
  315. strpcopy(strecopy(strend(st),ss),'",'+tostr(N_LSYM)+',0,'+tostr(sym_line_no)+',0');
  316. allstabstring := strnew(st);
  317. freemem(st,strlen(ss)+512);
  318. strdispose(ss);
  319. end;
  320. procedure tdef.concatstabto(asmlist : paasmoutput);
  321. var stab_str : pchar;
  322. begin
  323. if ((typesym = nil) or typesym^.isusedinstab or (cs_gdb_dbx in aktglobalswitches))
  324. and not is_def_stab_written then
  325. begin
  326. If cs_gdb_dbx in aktglobalswitches then
  327. begin
  328. { otherwise you get two of each def }
  329. If assigned(typesym) then
  330. begin
  331. if typesym^.typ=symconst.typesym then
  332. typesym^.isusedinstab:=true;
  333. if (typesym^.owner = nil) or
  334. ((typesym^.owner^.symtabletype = unitsymtable) and
  335. punitsymtable(typesym^.owner)^.dbx_count_ok) then
  336. begin
  337. {with DBX we get the definition from the other objects }
  338. is_def_stab_written := true;
  339. exit;
  340. end;
  341. end;
  342. end;
  343. { to avoid infinite loops }
  344. is_def_stab_written := true;
  345. stab_str := allstabstring;
  346. asmlist^.concat(new(pai_stabs,init(stab_str)));
  347. end;
  348. end;
  349. {$endif GDB}
  350. procedure tdef.deref;
  351. begin
  352. resolvesym(psym(typesym));
  353. end;
  354. { rtti generation }
  355. procedure tdef.generate_rtti;
  356. begin
  357. if not has_rtti then
  358. begin
  359. has_rtti:=true;
  360. getdatalabel(rtti_label);
  361. write_child_rtti_data;
  362. rttilist^.concat(new(pai_symbol,init(rtti_label,0)));
  363. write_rtti_data;
  364. rttilist^.concat(new(pai_symbol_end,init(rtti_label)));
  365. end;
  366. end;
  367. function tdef.get_rtti_label : string;
  368. begin
  369. generate_rtti;
  370. get_rtti_label:=rtti_label^.name;
  371. end;
  372. { init table handling }
  373. function tdef.needs_inittable : boolean;
  374. begin
  375. needs_inittable:=false;
  376. end;
  377. procedure tdef.generate_inittable;
  378. begin
  379. has_inittable:=true;
  380. getdatalabel(inittable_label);
  381. write_child_init_data;
  382. rttilist^.concat(new(pai_label,init(inittable_label)));
  383. write_init_data;
  384. end;
  385. procedure tdef.write_init_data;
  386. begin
  387. write_rtti_data;
  388. end;
  389. procedure tdef.write_child_init_data;
  390. begin
  391. write_child_rtti_data;
  392. end;
  393. function tdef.get_inittable_label : pasmlabel;
  394. begin
  395. if not(has_inittable) then
  396. generate_inittable;
  397. get_inittable_label:=inittable_label;
  398. end;
  399. procedure tdef.write_rtti_name;
  400. var
  401. str : string;
  402. begin
  403. { name }
  404. if assigned(typesym) then
  405. begin
  406. str:=typesym^.name;
  407. rttilist^.concat(new(pai_string,init(chr(length(str))+str)));
  408. end
  409. else
  410. rttilist^.concat(new(pai_string,init(#0)))
  411. end;
  412. { returns true, if the definition can be published }
  413. function tdef.is_publishable : boolean;
  414. begin
  415. is_publishable:=false;
  416. end;
  417. procedure tdef.write_rtti_data;
  418. begin
  419. end;
  420. procedure tdef.write_child_rtti_data;
  421. begin
  422. end;
  423. function tdef.is_intregable : boolean;
  424. begin
  425. is_intregable:=false;
  426. case deftype of
  427. pointerdef,
  428. enumdef,
  429. procvardef :
  430. is_intregable:=true;
  431. orddef :
  432. case porddef(@self)^.typ of
  433. bool8bit,bool16bit,bool32bit,
  434. u8bit,u16bit,u32bit,
  435. s8bit,s16bit,s32bit:
  436. is_intregable:=true;
  437. end;
  438. setdef:
  439. is_intregable:=is_smallset(@self);
  440. end;
  441. end;
  442. function tdef.is_fpuregable : boolean;
  443. begin
  444. is_fpuregable:=(deftype=floatdef) and not(pfloatdef(@self)^.typ in [f32bit,f16bit]);
  445. end;
  446. {****************************************************************************
  447. TSTRINGDEF
  448. ****************************************************************************}
  449. constructor tstringdef.shortinit(l : byte);
  450. begin
  451. tdef.init;
  452. string_typ:=st_shortstring;
  453. deftype:=stringdef;
  454. len:=l;
  455. savesize:=len+1;
  456. end;
  457. constructor tstringdef.shortload;
  458. begin
  459. tdef.load;
  460. string_typ:=st_shortstring;
  461. deftype:=stringdef;
  462. len:=readbyte;
  463. savesize:=len+1;
  464. end;
  465. constructor tstringdef.longinit(l : longint);
  466. begin
  467. tdef.init;
  468. string_typ:=st_longstring;
  469. deftype:=stringdef;
  470. len:=l;
  471. savesize:=target_os.size_of_pointer;
  472. end;
  473. constructor tstringdef.longload;
  474. begin
  475. tdef.load;
  476. deftype:=stringdef;
  477. string_typ:=st_longstring;
  478. len:=readlong;
  479. savesize:=target_os.size_of_pointer;
  480. end;
  481. constructor tstringdef.ansiinit(l : longint);
  482. begin
  483. tdef.init;
  484. string_typ:=st_ansistring;
  485. deftype:=stringdef;
  486. len:=l;
  487. savesize:=target_os.size_of_pointer;
  488. end;
  489. constructor tstringdef.ansiload;
  490. begin
  491. tdef.load;
  492. deftype:=stringdef;
  493. string_typ:=st_ansistring;
  494. len:=readlong;
  495. savesize:=target_os.size_of_pointer;
  496. end;
  497. constructor tstringdef.wideinit(l : longint);
  498. begin
  499. tdef.init;
  500. string_typ:=st_widestring;
  501. deftype:=stringdef;
  502. len:=l;
  503. savesize:=target_os.size_of_pointer;
  504. end;
  505. constructor tstringdef.wideload;
  506. begin
  507. tdef.load;
  508. deftype:=stringdef;
  509. string_typ:=st_widestring;
  510. len:=readlong;
  511. savesize:=target_os.size_of_pointer;
  512. end;
  513. function tstringdef.stringtypname:string;
  514. const
  515. typname:array[tstringtype] of string[8]=('',
  516. 'SHORTSTR','LONGSTR','ANSISTR','WIDESTR'
  517. );
  518. begin
  519. stringtypname:=typname[string_typ];
  520. end;
  521. function tstringdef.size : longint;
  522. begin
  523. size:=savesize;
  524. end;
  525. procedure tstringdef.write;
  526. begin
  527. tdef.write;
  528. if string_typ=st_shortstring then
  529. writebyte(len)
  530. else
  531. writelong(len);
  532. case string_typ of
  533. st_shortstring : current_ppu^.writeentry(ibshortstringdef);
  534. st_longstring : current_ppu^.writeentry(iblongstringdef);
  535. st_ansistring : current_ppu^.writeentry(ibansistringdef);
  536. st_widestring : current_ppu^.writeentry(ibwidestringdef);
  537. end;
  538. end;
  539. {$ifdef GDB}
  540. function tstringdef.stabstring : pchar;
  541. var
  542. bytest,charst,longst : string;
  543. begin
  544. case string_typ of
  545. st_shortstring:
  546. begin
  547. charst := typeglobalnumber('char');
  548. { this is what I found in stabs.texinfo but
  549. gdb 4.12 for go32 doesn't understand that !! }
  550. {$IfDef GDBknowsstrings}
  551. stabstring := strpnew('n'+charst+';'+tostr(len));
  552. {$else}
  553. bytest := typeglobalnumber('byte');
  554. stabstring := strpnew('s'+tostr(len+1)+'length:'+bytest
  555. +',0,8;st:ar'+bytest
  556. +';1;'+tostr(len)+';'+charst+',8,'+tostr(len*8)+';;');
  557. {$EndIf}
  558. end;
  559. st_longstring:
  560. begin
  561. charst := typeglobalnumber('char');
  562. { this is what I found in stabs.texinfo but
  563. gdb 4.12 for go32 doesn't understand that !! }
  564. {$IfDef GDBknowsstrings}
  565. stabstring := strpnew('n'+charst+';'+tostr(len));
  566. {$else}
  567. bytest := typeglobalnumber('byte');
  568. longst := typeglobalnumber('longint');
  569. stabstring := strpnew('s'+tostr(len+5)+'length:'+longst
  570. +',0,32;dummy:'+bytest+',32,8;st:ar'+bytest
  571. +';1;'+tostr(len)+';'+charst+',40,'+tostr(len*8)+';;');
  572. {$EndIf}
  573. end;
  574. st_ansistring:
  575. begin
  576. { an ansi string looks like a pchar easy !! }
  577. stabstring:=strpnew('*'+typeglobalnumber('char'));
  578. end;
  579. st_widestring:
  580. begin
  581. { an ansi string looks like a pchar easy !! }
  582. stabstring:=strpnew('*'+typeglobalnumber('char'));
  583. end;
  584. end;
  585. end;
  586. procedure tstringdef.concatstabto(asmlist : paasmoutput);
  587. begin
  588. inherited concatstabto(asmlist);
  589. end;
  590. {$endif GDB}
  591. function tstringdef.needs_inittable : boolean;
  592. begin
  593. needs_inittable:=string_typ in [st_ansistring,st_widestring];
  594. end;
  595. function tstringdef.gettypename : string;
  596. const
  597. names : array[tstringtype] of string[20] = ('',
  598. 'ShortString','LongString','AnsiString','WideString');
  599. begin
  600. gettypename:=names[string_typ];
  601. end;
  602. procedure tstringdef.write_rtti_data;
  603. begin
  604. case string_typ of
  605. st_ansistring:
  606. begin
  607. rttilist^.concat(new(pai_const,init_8bit(tkAString)));
  608. write_rtti_name;
  609. end;
  610. st_widestring:
  611. begin
  612. rttilist^.concat(new(pai_const,init_8bit(tkWString)));
  613. write_rtti_name;
  614. end;
  615. st_longstring:
  616. begin
  617. rttilist^.concat(new(pai_const,init_8bit(tkLString)));
  618. write_rtti_name;
  619. end;
  620. st_shortstring:
  621. begin
  622. rttilist^.concat(new(pai_const,init_8bit(tkSString)));
  623. write_rtti_name;
  624. rttilist^.concat(new(pai_const,init_8bit(len)));
  625. end;
  626. end;
  627. end;
  628. function tstringdef.is_publishable : boolean;
  629. begin
  630. is_publishable:=true;
  631. end;
  632. {****************************************************************************
  633. TENUMDEF
  634. ****************************************************************************}
  635. constructor tenumdef.init;
  636. begin
  637. tdef.init;
  638. deftype:=enumdef;
  639. minval:=0;
  640. maxval:=0;
  641. calcsavesize;
  642. has_jumps:=false;
  643. basedef:=nil;
  644. rangenr:=0;
  645. firstenum:=nil;
  646. correct_owner_symtable;
  647. end;
  648. constructor tenumdef.init_subrange(_basedef:penumdef;_min,_max:longint);
  649. begin
  650. tdef.init;
  651. deftype:=enumdef;
  652. minval:=_min;
  653. maxval:=_max;
  654. basedef:=_basedef;
  655. calcsavesize;
  656. has_jumps:=false;
  657. rangenr:=0;
  658. firstenum:=basedef^.firstenum;
  659. while assigned(firstenum) and (penumsym(firstenum)^.value<>minval) do
  660. firstenum:=firstenum^.nextenum;
  661. correct_owner_symtable;
  662. end;
  663. constructor tenumdef.load;
  664. begin
  665. tdef.load;
  666. deftype:=enumdef;
  667. basedef:=penumdef(readdefref);
  668. minval:=readlong;
  669. maxval:=readlong;
  670. savesize:=readlong;
  671. has_jumps:=false;
  672. firstenum:=Nil;
  673. end;
  674. procedure tenumdef.calcsavesize;
  675. begin
  676. if (aktpackenum=4) or (min<0) or (max>65535) then
  677. savesize:=4
  678. else
  679. if (aktpackenum=2) or (min<0) or (max>255) then
  680. savesize:=2
  681. else
  682. savesize:=1;
  683. end;
  684. procedure tenumdef.setmax(_max:longint);
  685. begin
  686. maxval:=_max;
  687. calcsavesize;
  688. end;
  689. procedure tenumdef.setmin(_min:longint);
  690. begin
  691. minval:=_min;
  692. calcsavesize;
  693. end;
  694. function tenumdef.min:longint;
  695. begin
  696. min:=minval;
  697. end;
  698. function tenumdef.max:longint;
  699. begin
  700. max:=maxval;
  701. end;
  702. procedure tenumdef.deref;
  703. begin
  704. inherited deref;
  705. resolvedef(pdef(basedef));
  706. end;
  707. destructor tenumdef.done;
  708. begin
  709. inherited done;
  710. end;
  711. procedure tenumdef.write;
  712. begin
  713. tdef.write;
  714. writedefref(basedef);
  715. writelong(min);
  716. writelong(max);
  717. writelong(savesize);
  718. current_ppu^.writeentry(ibenumdef);
  719. end;
  720. function tenumdef.getrangecheckstring : string;
  721. begin
  722. if (cs_create_smart in aktmoduleswitches) then
  723. getrangecheckstring:='R_'+current_module^.modulename^+tostr(rangenr)
  724. else
  725. getrangecheckstring:='R_'+tostr(rangenr);
  726. end;
  727. procedure tenumdef.genrangecheck;
  728. begin
  729. if rangenr=0 then
  730. begin
  731. { generate two constant for bounds }
  732. getlabelnr(rangenr);
  733. if (cs_create_smart in aktmoduleswitches) then
  734. datasegment^.concat(new(pai_symbol,initname_global(getrangecheckstring,8)))
  735. else
  736. datasegment^.concat(new(pai_symbol,initname(getrangecheckstring,8)));
  737. datasegment^.concat(new(pai_const,init_32bit(min)));
  738. datasegment^.concat(new(pai_const,init_32bit(max)));
  739. end;
  740. end;
  741. {$ifdef GDB}
  742. function tenumdef.stabstring : pchar;
  743. var st,st2 : pchar;
  744. p : penumsym;
  745. s : string;
  746. memsize : word;
  747. begin
  748. memsize := memsizeinc;
  749. getmem(st,memsize);
  750. strpcopy(st,'e');
  751. p := firstenum;
  752. while assigned(p) do
  753. begin
  754. s :=p^.name+':'+tostr(p^.value)+',';
  755. { place for the ending ';' also }
  756. if (strlen(st)+length(s)+1<memsize) then
  757. strpcopy(strend(st),s)
  758. else
  759. begin
  760. getmem(st2,memsize+memsizeinc);
  761. strcopy(st2,st);
  762. freemem(st,memsize);
  763. st := st2;
  764. memsize := memsize+memsizeinc;
  765. strpcopy(strend(st),s);
  766. end;
  767. p := p^.nextenum;
  768. end;
  769. strpcopy(strend(st),';');
  770. stabstring := strnew(st);
  771. freemem(st,memsize);
  772. end;
  773. {$endif GDB}
  774. procedure tenumdef.write_child_rtti_data;
  775. begin
  776. if assigned(basedef) then
  777. basedef^.get_rtti_label;
  778. end;
  779. procedure tenumdef.write_rtti_data;
  780. var
  781. hp : penumsym;
  782. begin
  783. rttilist^.concat(new(pai_const,init_8bit(tkEnumeration)));
  784. write_rtti_name;
  785. case savesize of
  786. 1:
  787. rttilist^.concat(new(pai_const,init_8bit(otUByte)));
  788. 2:
  789. rttilist^.concat(new(pai_const,init_8bit(otUWord)));
  790. 4:
  791. rttilist^.concat(new(pai_const,init_8bit(otULong)));
  792. end;
  793. rttilist^.concat(new(pai_const,init_32bit(min)));
  794. rttilist^.concat(new(pai_const,init_32bit(max)));
  795. if assigned(basedef) then
  796. rttilist^.concat(new(pai_const_symbol,initname(basedef^.get_rtti_label)))
  797. else
  798. rttilist^.concat(new(pai_const,init_32bit(0)));
  799. hp:=firstenum;
  800. while assigned(hp) do
  801. begin
  802. rttilist^.concat(new(pai_const,init_8bit(length(hp^.name))));
  803. rttilist^.concat(new(pai_string,init(globals.lower(hp^.name))));
  804. hp:=hp^.nextenum;
  805. end;
  806. rttilist^.concat(new(pai_const,init_8bit(0)));
  807. end;
  808. function tenumdef.is_publishable : boolean;
  809. begin
  810. is_publishable:=true;
  811. end;
  812. function tenumdef.gettypename : string;
  813. begin
  814. gettypename:='<enumeration type>';
  815. end;
  816. {****************************************************************************
  817. TORDDEF
  818. ****************************************************************************}
  819. constructor torddef.init(t : tbasetype;v,b : longint);
  820. begin
  821. inherited init;
  822. deftype:=orddef;
  823. low:=v;
  824. high:=b;
  825. typ:=t;
  826. rangenr:=0;
  827. setsize;
  828. end;
  829. constructor torddef.load;
  830. begin
  831. inherited load;
  832. deftype:=orddef;
  833. typ:=tbasetype(readbyte);
  834. low:=readlong;
  835. high:=readlong;
  836. rangenr:=0;
  837. setsize;
  838. end;
  839. procedure torddef.setsize;
  840. begin
  841. if typ=uauto then
  842. begin
  843. { generate a unsigned range if high<0 and low>=0 }
  844. if (low>=0) and (high<0) then
  845. begin
  846. savesize:=4;
  847. typ:=u32bit;
  848. end
  849. else if (low>=0) and (high<=255) then
  850. begin
  851. savesize:=1;
  852. typ:=u8bit;
  853. end
  854. else if (low>=-128) and (high<=127) then
  855. begin
  856. savesize:=1;
  857. typ:=s8bit;
  858. end
  859. else if (low>=0) and (high<=65536) then
  860. begin
  861. savesize:=2;
  862. typ:=u16bit;
  863. end
  864. else if (low>=-32768) and (high<=32767) then
  865. begin
  866. savesize:=2;
  867. typ:=s16bit;
  868. end
  869. else
  870. begin
  871. savesize:=4;
  872. typ:=s32bit;
  873. end;
  874. end
  875. else
  876. begin
  877. case typ of
  878. u8bit,s8bit,
  879. uchar,bool8bit:
  880. savesize:=1;
  881. u16bit,s16bit,
  882. bool16bit,uwidechar:
  883. savesize:=2;
  884. s32bit,u32bit,
  885. bool32bit:
  886. savesize:=4;
  887. u64bit,s64bit:
  888. savesize:=8;
  889. else
  890. savesize:=0;
  891. end;
  892. end;
  893. { there are no entrys for range checking }
  894. rangenr:=0;
  895. end;
  896. function torddef.getrangecheckstring : string;
  897. begin
  898. if (cs_create_smart in aktmoduleswitches) then
  899. getrangecheckstring:='R_'+current_module^.modulename^+tostr(rangenr)
  900. else
  901. getrangecheckstring:='R_'+tostr(rangenr);
  902. end;
  903. procedure torddef.genrangecheck;
  904. var
  905. rangechecksize : longint;
  906. begin
  907. if rangenr=0 then
  908. begin
  909. if low<=high then
  910. rangechecksize:=8
  911. else
  912. rangechecksize:=16;
  913. { generate two constant for bounds }
  914. getlabelnr(rangenr);
  915. if (cs_create_smart in aktmoduleswitches) then
  916. datasegment^.concat(new(pai_symbol,initname_global(getrangecheckstring,rangechecksize)))
  917. else
  918. datasegment^.concat(new(pai_symbol,initname(getrangecheckstring,rangechecksize)));
  919. if low<=high then
  920. begin
  921. datasegment^.concat(new(pai_const,init_32bit(low)));
  922. datasegment^.concat(new(pai_const,init_32bit(high)));
  923. end
  924. { for u32bit we need two bounds }
  925. else
  926. begin
  927. datasegment^.concat(new(pai_const,init_32bit(low)));
  928. datasegment^.concat(new(pai_const,init_32bit($7fffffff)));
  929. datasegment^.concat(new(pai_const,init_32bit($80000000)));
  930. datasegment^.concat(new(pai_const,init_32bit(high)));
  931. end;
  932. end;
  933. end;
  934. procedure torddef.write;
  935. begin
  936. tdef.write;
  937. writebyte(byte(typ));
  938. writelong(low);
  939. writelong(high);
  940. current_ppu^.writeentry(iborddef);
  941. end;
  942. {$ifdef GDB}
  943. function torddef.stabstring : pchar;
  944. begin
  945. case typ of
  946. uvoid : stabstring := strpnew(numberstring+';');
  947. {GDB 4.12 for go32 doesn't like boolean as range for 0 to 1 !!!}
  948. {$ifdef Use_integer_types_for_boolean}
  949. bool8bit,
  950. bool16bit,
  951. bool32bit : stabstring := strpnew('r'+numberstring+';0;255;');
  952. {$else : not Use_integer_types_for_boolean}
  953. bool8bit : stabstring := strpnew('-21;');
  954. bool16bit : stabstring := strpnew('-22;');
  955. bool32bit : stabstring := strpnew('-23;');
  956. u64bit : stabstring := strpnew('-32;');
  957. s64bit : stabstring := strpnew('-31;');
  958. {$endif not Use_integer_types_for_boolean}
  959. { u32bit : stabstring := strpnew('r'+
  960. s32bitdef^.numberstring+';0;-1;'); }
  961. else
  962. stabstring := strpnew('r'+s32bitdef^.numberstring+';'+tostr(low)+';'+tostr(high)+';');
  963. end;
  964. end;
  965. {$endif GDB}
  966. procedure torddef.write_rtti_data;
  967. const
  968. trans : array[uchar..bool8bit] of byte =
  969. (otUByte,otUByte,otUWord,otULong,otSByte,otSWord,otSLong,otUByte);
  970. begin
  971. case typ of
  972. bool8bit:
  973. rttilist^.concat(new(pai_const,init_8bit(tkBool)));
  974. uchar:
  975. rttilist^.concat(new(pai_const,init_8bit(tkWChar)));
  976. uwidechar:
  977. rttilist^.concat(new(pai_const,init_8bit(tkChar)));
  978. else
  979. rttilist^.concat(new(pai_const,init_8bit(tkInteger)));
  980. end;
  981. write_rtti_name;
  982. rttilist^.concat(new(pai_const,init_8bit(byte(trans[typ]))));
  983. rttilist^.concat(new(pai_const,init_32bit(low)));
  984. rttilist^.concat(new(pai_const,init_32bit(high)));
  985. end;
  986. function torddef.is_publishable : boolean;
  987. begin
  988. is_publishable:=typ in [uchar..bool8bit];
  989. end;
  990. function torddef.gettypename : string;
  991. const
  992. names : array[tbasetype] of string[20] = ('<unknown type>',
  993. 'untyped','Char','Byte','Word','DWord','ShortInt',
  994. 'SmallInt','LongInt','Boolean','WordBool',
  995. 'LongBool','QWord','Int64','WideChar');
  996. begin
  997. gettypename:=names[typ];
  998. end;
  999. {****************************************************************************
  1000. TFLOATDEF
  1001. ****************************************************************************}
  1002. constructor tfloatdef.init(t : tfloattype);
  1003. begin
  1004. inherited init;
  1005. deftype:=floatdef;
  1006. typ:=t;
  1007. setsize;
  1008. end;
  1009. constructor tfloatdef.load;
  1010. begin
  1011. inherited load;
  1012. deftype:=floatdef;
  1013. typ:=tfloattype(readbyte);
  1014. setsize;
  1015. end;
  1016. procedure tfloatdef.setsize;
  1017. begin
  1018. case typ of
  1019. f16bit : savesize:=2;
  1020. f32bit,
  1021. s32real : savesize:=4;
  1022. s64real : savesize:=8;
  1023. s80real : savesize:=extended_size;
  1024. s64comp : savesize:=8;
  1025. else
  1026. savesize:=0;
  1027. end;
  1028. end;
  1029. procedure tfloatdef.write;
  1030. begin
  1031. inherited write;
  1032. writebyte(byte(typ));
  1033. current_ppu^.writeentry(ibfloatdef);
  1034. end;
  1035. {$ifdef GDB}
  1036. function tfloatdef.stabstring : pchar;
  1037. begin
  1038. case typ of
  1039. s32real,
  1040. s64real : stabstring := strpnew('r'+
  1041. s32bitdef^.numberstring+';'+tostr(savesize)+';0;');
  1042. { for fixed real use longint instead to be able to }
  1043. { debug something at least }
  1044. f32bit:
  1045. stabstring := s32bitdef^.stabstring;
  1046. f16bit:
  1047. stabstring := strpnew('r'+s32bitdef^.numberstring+';0;'+
  1048. tostr($ffff)+';');
  1049. { found this solution in stabsread.c from GDB v4.16 }
  1050. s64comp : stabstring := strpnew('r'+
  1051. s32bitdef^.numberstring+';-'+tostr(savesize)+';0;');
  1052. {$ifdef i386}
  1053. { under dos at least you must give a size of twelve instead of 10 !! }
  1054. { this is probably do to the fact that in gcc all is pushed in 4 bytes size }
  1055. s80real : stabstring := strpnew('r'+s32bitdef^.numberstring+';12;0;');
  1056. {$endif i386}
  1057. else
  1058. internalerror(10005);
  1059. end;
  1060. end;
  1061. {$endif GDB}
  1062. procedure tfloatdef.write_rtti_data;
  1063. const
  1064. {tfloattype = (s32real,s64real,s80real,s64bit,f16bit,f32bit);}
  1065. translate : array[tfloattype] of byte =
  1066. (ftSingle,ftDouble,ftExtended,ftComp,ftFixed16,ftFixed32);
  1067. begin
  1068. rttilist^.concat(new(pai_const,init_8bit(tkFloat)));
  1069. write_rtti_name;
  1070. rttilist^.concat(new(pai_const,init_8bit(translate[typ])));
  1071. end;
  1072. function tfloatdef.is_publishable : boolean;
  1073. begin
  1074. is_publishable:=true;
  1075. end;
  1076. function tfloatdef.gettypename : string;
  1077. const
  1078. names : array[tfloattype] of string[20] = (
  1079. 'Single','Double','Extended','Comp','Fixed','Fixed16');
  1080. begin
  1081. gettypename:=names[typ];
  1082. end;
  1083. {****************************************************************************
  1084. TFILEDEF
  1085. ****************************************************************************}
  1086. constructor tfiledef.inittext;
  1087. begin
  1088. inherited init;
  1089. deftype:=filedef;
  1090. filetyp:=ft_text;
  1091. typedfiletype.reset;
  1092. setsize;
  1093. end;
  1094. constructor tfiledef.inituntyped;
  1095. begin
  1096. inherited init;
  1097. deftype:=filedef;
  1098. filetyp:=ft_untyped;
  1099. typedfiletype.reset;
  1100. setsize;
  1101. end;
  1102. constructor tfiledef.inittyped(const tt : ttype);
  1103. begin
  1104. inherited init;
  1105. deftype:=filedef;
  1106. filetyp:=ft_typed;
  1107. typedfiletype:=tt;
  1108. setsize;
  1109. end;
  1110. constructor tfiledef.inittypeddef(p : pdef);
  1111. begin
  1112. inherited init;
  1113. deftype:=filedef;
  1114. filetyp:=ft_typed;
  1115. typedfiletype.setdef(p);
  1116. setsize;
  1117. end;
  1118. constructor tfiledef.load;
  1119. begin
  1120. inherited load;
  1121. deftype:=filedef;
  1122. filetyp:=tfiletyp(readbyte);
  1123. if filetyp=ft_typed then
  1124. typedfiletype.load
  1125. else
  1126. typedfiletype.reset;
  1127. setsize;
  1128. end;
  1129. procedure tfiledef.deref;
  1130. begin
  1131. inherited deref;
  1132. if filetyp=ft_typed then
  1133. typedfiletype.resolve;
  1134. end;
  1135. procedure tfiledef.setsize;
  1136. begin
  1137. case filetyp of
  1138. ft_text :
  1139. savesize:=572;
  1140. ft_typed,
  1141. ft_untyped :
  1142. savesize:=316;
  1143. end;
  1144. end;
  1145. procedure tfiledef.write;
  1146. begin
  1147. inherited write;
  1148. writebyte(byte(filetyp));
  1149. if filetyp=ft_typed then
  1150. typedfiletype.write;
  1151. current_ppu^.writeentry(ibfiledef);
  1152. end;
  1153. {$ifdef GDB}
  1154. function tfiledef.stabstring : pchar;
  1155. begin
  1156. {$IfDef GDBknowsfiles}
  1157. case filetyp of
  1158. ft_typed :
  1159. stabstring := strpnew('d'+typedfiletype.def^.numberstring{+';'});
  1160. ft_untyped :
  1161. stabstring := strpnew('d'+voiddef^.numberstring{+';'});
  1162. ft_text :
  1163. stabstring := strpnew('d'+cchardef^.numberstring{+';'});
  1164. end;
  1165. {$Else}
  1166. {based on
  1167. FileRec = Packed Record
  1168. Handle,
  1169. Mode,
  1170. RecSize : longint;
  1171. _private : array[1..32] of byte;
  1172. UserData : array[1..16] of byte;
  1173. name : array[0..255] of char;
  1174. End; }
  1175. { the buffer part is still missing !! (PM) }
  1176. { but the string could become too long !! }
  1177. stabstring := strpnew('s'+tostr(savesize)+
  1178. 'HANDLE:'+typeglobalnumber('longint')+',0,32;'+
  1179. 'MODE:'+typeglobalnumber('longint')+',32,32;'+
  1180. 'RECSIZE:'+typeglobalnumber('longint')+',64,32;'+
  1181. '_PRIVATE:ar'+typeglobalnumber('word')+';1;32;'+typeglobalnumber('byte')
  1182. +',96,256;'+
  1183. 'USERDATA:ar'+typeglobalnumber('word')+';1;16;'+typeglobalnumber('byte')
  1184. +',352,128;'+
  1185. 'NAME:ar'+typeglobalnumber('word')+';0;255;'+typeglobalnumber('char')
  1186. +',480,2048;;');
  1187. {$EndIf}
  1188. end;
  1189. procedure tfiledef.concatstabto(asmlist : paasmoutput);
  1190. begin
  1191. { most file defs are unnamed !!! }
  1192. if ((typesym = nil) or typesym^.isusedinstab or (cs_gdb_dbx in aktglobalswitches)) and
  1193. not is_def_stab_written then
  1194. begin
  1195. if assigned(typedfiletype.def) then forcestabto(asmlist,typedfiletype.def);
  1196. inherited concatstabto(asmlist);
  1197. end;
  1198. end;
  1199. {$endif GDB}
  1200. function tfiledef.gettypename : string;
  1201. begin
  1202. case filetyp of
  1203. ft_untyped:
  1204. gettypename:='File';
  1205. ft_typed:
  1206. gettypename:='File Of '+typedfiletype.def^.typename;
  1207. ft_text:
  1208. gettypename:='Text'
  1209. end;
  1210. end;
  1211. {****************************************************************************
  1212. TPOINTERDEF
  1213. ****************************************************************************}
  1214. constructor tpointerdef.init(const tt : ttype);
  1215. begin
  1216. tdef.init;
  1217. deftype:=pointerdef;
  1218. pointertype:=tt;
  1219. is_far:=false;
  1220. savesize:=target_os.size_of_pointer;
  1221. end;
  1222. constructor tpointerdef.initfar(const tt : ttype);
  1223. begin
  1224. tdef.init;
  1225. deftype:=pointerdef;
  1226. pointertype:=tt;
  1227. is_far:=true;
  1228. savesize:=target_os.size_of_pointer;
  1229. end;
  1230. constructor tpointerdef.initdef(p : pdef);
  1231. var
  1232. t : ttype;
  1233. begin
  1234. t.setdef(p);
  1235. tpointerdef.init(t);
  1236. end;
  1237. constructor tpointerdef.initfardef(p : pdef);
  1238. var
  1239. t : ttype;
  1240. begin
  1241. t.setdef(p);
  1242. tpointerdef.initfar(t);
  1243. end;
  1244. constructor tpointerdef.load;
  1245. begin
  1246. tdef.load;
  1247. deftype:=pointerdef;
  1248. pointertype.load;
  1249. is_far:=(readbyte<>0);
  1250. savesize:=target_os.size_of_pointer;
  1251. end;
  1252. destructor tpointerdef.done;
  1253. begin
  1254. if assigned(pointertype.def) and
  1255. (pointertype.def^.deftype=forwarddef) then
  1256. begin
  1257. dispose(pointertype.def,done);
  1258. pointertype.reset;
  1259. end;
  1260. inherited done;
  1261. end;
  1262. procedure tpointerdef.deref;
  1263. begin
  1264. inherited deref;
  1265. pointertype.resolve;
  1266. end;
  1267. procedure tpointerdef.write;
  1268. begin
  1269. inherited write;
  1270. pointertype.write;
  1271. writebyte(byte(is_far));
  1272. current_ppu^.writeentry(ibpointerdef);
  1273. end;
  1274. {$ifdef GDB}
  1275. function tpointerdef.stabstring : pchar;
  1276. begin
  1277. stabstring := strpnew('*'+pointertype.def^.numberstring);
  1278. end;
  1279. procedure tpointerdef.concatstabto(asmlist : paasmoutput);
  1280. var st,nb : string;
  1281. sym_line_no : longint;
  1282. begin
  1283. if assigned(pointertype.def) and
  1284. (pointertype.def^.deftype=forwarddef) then
  1285. exit;
  1286. if ( (typesym=nil) or typesym^.isusedinstab or (cs_gdb_dbx in aktglobalswitches)) and
  1287. not is_def_stab_written then
  1288. begin
  1289. if assigned(pointertype.def) then
  1290. if pointertype.def^.deftype in [recorddef,objectdef] then
  1291. begin
  1292. is_def_stab_written := true;
  1293. nb:=pointertype.def^.numberstring;
  1294. {to avoid infinite recursion in record with next-like fields }
  1295. is_def_stab_written := false;
  1296. if not pointertype.def^.is_def_stab_written then
  1297. begin
  1298. if assigned(pointertype.def^.typesym) then
  1299. begin
  1300. if assigned(typesym) then
  1301. begin
  1302. st := typesym^.name;
  1303. sym_line_no:=typesym^.fileinfo.line;
  1304. end
  1305. else
  1306. begin
  1307. st := ' ';
  1308. sym_line_no:=0;
  1309. end;
  1310. st := '"'+st+':t'+numberstring+'=*'+nb
  1311. +'=xs'+pointertype.def^.typesym^.name+':",'+tostr(N_LSYM)+',0,'+tostr(sym_line_no)+',0';
  1312. asmlist^.concat(new(pai_stabs,init(strpnew(st))));
  1313. end;
  1314. end else inherited concatstabto(asmlist);
  1315. is_def_stab_written := true;
  1316. end else
  1317. begin
  1318. { p =^p1; p1=^p problem }
  1319. is_def_stab_written := true;
  1320. forcestabto(asmlist,pointertype.def);
  1321. is_def_stab_written := false;
  1322. inherited concatstabto(asmlist);
  1323. end;
  1324. end;
  1325. end;
  1326. {$endif GDB}
  1327. function tpointerdef.gettypename : string;
  1328. begin
  1329. gettypename:='^'+pointertype.def^.typename;
  1330. end;
  1331. {****************************************************************************
  1332. TCLASSREFDEF
  1333. ****************************************************************************}
  1334. constructor tclassrefdef.init(def : pdef);
  1335. begin
  1336. inherited initdef(def);
  1337. deftype:=classrefdef;
  1338. end;
  1339. constructor tclassrefdef.load;
  1340. begin
  1341. { be careful, tclassdefref inherits from tpointerdef }
  1342. tdef.load;
  1343. deftype:=classrefdef;
  1344. pointertype.load;
  1345. is_far:=false;
  1346. savesize:=target_os.size_of_pointer;
  1347. end;
  1348. procedure tclassrefdef.write;
  1349. begin
  1350. { be careful, tclassdefref inherits from tpointerdef }
  1351. tdef.write;
  1352. pointertype.write;
  1353. current_ppu^.writeentry(ibclassrefdef);
  1354. end;
  1355. {$ifdef GDB}
  1356. function tclassrefdef.stabstring : pchar;
  1357. begin
  1358. stabstring:=strpnew(pvmtdef^.numberstring+';');
  1359. end;
  1360. procedure tclassrefdef.concatstabto(asmlist : paasmoutput);
  1361. begin
  1362. inherited concatstabto(asmlist);
  1363. end;
  1364. {$endif GDB}
  1365. function tclassrefdef.gettypename : string;
  1366. begin
  1367. gettypename:='Class Of '+pointertype.def^.typename;
  1368. end;
  1369. {***************************************************************************
  1370. TSETDEF
  1371. ***************************************************************************}
  1372. { For i386 smallsets work,
  1373. for m68k there are problems
  1374. can be test by compiling with -dusesmallset PM }
  1375. {$ifdef i386}
  1376. {$define usesmallset}
  1377. {$endif i386}
  1378. constructor tsetdef.init(s : pdef;high : longint);
  1379. begin
  1380. inherited init;
  1381. deftype:=setdef;
  1382. elementtype.setdef(s);
  1383. {$ifdef usesmallset}
  1384. { small sets only working for i386 PM }
  1385. if high<32 then
  1386. begin
  1387. settype:=smallset;
  1388. savesize:=Sizeof(longint);
  1389. end
  1390. else
  1391. {$endif usesmallset}
  1392. if high<256 then
  1393. begin
  1394. settype:=normset;
  1395. savesize:=32;
  1396. end
  1397. else
  1398. {$ifdef testvarsets}
  1399. if high<$10000 then
  1400. begin
  1401. settype:=varset;
  1402. savesize:=4*((high+31) div 32);
  1403. end
  1404. else
  1405. {$endif testvarsets}
  1406. Message(sym_e_ill_type_decl_set);
  1407. end;
  1408. constructor tsetdef.load;
  1409. begin
  1410. inherited load;
  1411. deftype:=setdef;
  1412. elementtype.load;
  1413. settype:=tsettype(readbyte);
  1414. case settype of
  1415. normset : savesize:=32;
  1416. varset : savesize:=readlong;
  1417. smallset : savesize:=Sizeof(longint);
  1418. end;
  1419. end;
  1420. destructor tsetdef.done;
  1421. begin
  1422. inherited done;
  1423. end;
  1424. procedure tsetdef.write;
  1425. begin
  1426. inherited write;
  1427. elementtype.write;
  1428. writebyte(byte(settype));
  1429. if settype=varset then
  1430. writelong(savesize);
  1431. current_ppu^.writeentry(ibsetdef);
  1432. end;
  1433. {$ifdef GDB}
  1434. function tsetdef.stabstring : pchar;
  1435. begin
  1436. { For small sets write a longint, which can at least be seen
  1437. in the current GDB's (PFV)
  1438. this is obsolete with GDBPAS !!
  1439. and anyhow creates problems with version 4.18!! PM
  1440. if settype=smallset then
  1441. stabstring := strpnew('r'+s32bitdef^.numberstring+';0;0xffffffff;')
  1442. else }
  1443. stabstring := strpnew('S'+elementtype.def^.numberstring);
  1444. end;
  1445. procedure tsetdef.concatstabto(asmlist : paasmoutput);
  1446. begin
  1447. if ( not assigned(typesym) or typesym^.isusedinstab or (cs_gdb_dbx in aktglobalswitches)) and
  1448. not is_def_stab_written then
  1449. begin
  1450. if assigned(elementtype.def) then
  1451. forcestabto(asmlist,elementtype.def);
  1452. inherited concatstabto(asmlist);
  1453. end;
  1454. end;
  1455. {$endif GDB}
  1456. procedure tsetdef.deref;
  1457. begin
  1458. inherited deref;
  1459. elementtype.resolve;
  1460. end;
  1461. procedure tsetdef.write_rtti_data;
  1462. begin
  1463. rttilist^.concat(new(pai_const,init_8bit(tkSet)));
  1464. write_rtti_name;
  1465. rttilist^.concat(new(pai_const,init_8bit(otULong)));
  1466. rttilist^.concat(new(pai_const_symbol,initname(elementtype.def^.get_rtti_label)));
  1467. end;
  1468. procedure tsetdef.write_child_rtti_data;
  1469. begin
  1470. elementtype.def^.get_rtti_label;
  1471. end;
  1472. function tsetdef.is_publishable : boolean;
  1473. begin
  1474. is_publishable:=settype=smallset;
  1475. end;
  1476. function tsetdef.gettypename : string;
  1477. begin
  1478. gettypename:='Set Of '+elementtype.def^.typename;
  1479. end;
  1480. {***************************************************************************
  1481. TFORMALDEF
  1482. ***************************************************************************}
  1483. constructor tformaldef.init;
  1484. var
  1485. stregdef : boolean;
  1486. begin
  1487. stregdef:=registerdef;
  1488. registerdef:=false;
  1489. inherited init;
  1490. deftype:=formaldef;
  1491. registerdef:=stregdef;
  1492. { formaldef must be registered at unit level !! }
  1493. if registerdef and assigned(current_module) then
  1494. if assigned(current_module^.localsymtable) then
  1495. psymtable(current_module^.localsymtable)^.registerdef(@self)
  1496. else if assigned(current_module^.globalsymtable) then
  1497. psymtable(current_module^.globalsymtable)^.registerdef(@self);
  1498. savesize:=target_os.size_of_pointer;
  1499. end;
  1500. constructor tformaldef.load;
  1501. begin
  1502. inherited load;
  1503. deftype:=formaldef;
  1504. savesize:=target_os.size_of_pointer;
  1505. end;
  1506. procedure tformaldef.write;
  1507. begin
  1508. inherited write;
  1509. current_ppu^.writeentry(ibformaldef);
  1510. end;
  1511. {$ifdef GDB}
  1512. function tformaldef.stabstring : pchar;
  1513. begin
  1514. stabstring := strpnew('formal'+numberstring+';');
  1515. end;
  1516. procedure tformaldef.concatstabto(asmlist : paasmoutput);
  1517. begin
  1518. { formaldef can't be stab'ed !}
  1519. end;
  1520. {$endif GDB}
  1521. function tformaldef.gettypename : string;
  1522. begin
  1523. gettypename:='Var';
  1524. end;
  1525. {***************************************************************************
  1526. TARRAYDEF
  1527. ***************************************************************************}
  1528. constructor tarraydef.init(l,h : longint;rd : pdef);
  1529. begin
  1530. inherited init;
  1531. deftype:=arraydef;
  1532. lowrange:=l;
  1533. highrange:=h;
  1534. rangetype.setdef(rd);
  1535. elementtype.reset;
  1536. IsVariant:=false;
  1537. IsConstructor:=false;
  1538. IsArrayOfConst:=false;
  1539. rangenr:=0;
  1540. end;
  1541. constructor tarraydef.load;
  1542. begin
  1543. inherited load;
  1544. deftype:=arraydef;
  1545. { the addresses are calculated later }
  1546. elementtype.load;
  1547. rangetype.load;
  1548. lowrange:=readlong;
  1549. highrange:=readlong;
  1550. IsArrayOfConst:=boolean(readbyte);
  1551. IsVariant:=false;
  1552. IsConstructor:=false;
  1553. rangenr:=0;
  1554. end;
  1555. function tarraydef.getrangecheckstring : string;
  1556. begin
  1557. if (cs_create_smart in aktmoduleswitches) then
  1558. getrangecheckstring:='R_'+current_module^.modulename^+tostr(rangenr)
  1559. else
  1560. getrangecheckstring:='R_'+tostr(rangenr);
  1561. end;
  1562. procedure tarraydef.genrangecheck;
  1563. begin
  1564. if rangenr=0 then
  1565. begin
  1566. { generates the data for range checking }
  1567. getlabelnr(rangenr);
  1568. if (cs_create_smart in aktmoduleswitches) then
  1569. datasegment^.concat(new(pai_symbol,initname_global(getrangecheckstring,8)))
  1570. else
  1571. datasegment^.concat(new(pai_symbol,initname(getrangecheckstring,8)));
  1572. datasegment^.concat(new(pai_const,init_32bit(lowrange)));
  1573. datasegment^.concat(new(pai_const,init_32bit(highrange)));
  1574. end;
  1575. end;
  1576. procedure tarraydef.deref;
  1577. begin
  1578. inherited deref;
  1579. elementtype.resolve;
  1580. rangetype.resolve;
  1581. end;
  1582. procedure tarraydef.write;
  1583. begin
  1584. inherited write;
  1585. elementtype.write;
  1586. rangetype.write;
  1587. writelong(lowrange);
  1588. writelong(highrange);
  1589. writebyte(byte(IsArrayOfConst));
  1590. current_ppu^.writeentry(ibarraydef);
  1591. end;
  1592. {$ifdef GDB}
  1593. function tarraydef.stabstring : pchar;
  1594. begin
  1595. stabstring := strpnew('ar'+rangetype.def^.numberstring+';'
  1596. +tostr(lowrange)+';'+tostr(highrange)+';'+elementtype.def^.numberstring);
  1597. end;
  1598. procedure tarraydef.concatstabto(asmlist : paasmoutput);
  1599. begin
  1600. if (not assigned(typesym) or typesym^.isusedinstab or (cs_gdb_dbx in aktglobalswitches))
  1601. and not is_def_stab_written then
  1602. begin
  1603. {when array are inserted they have no definition yet !!}
  1604. if assigned(elementtype.def) then
  1605. inherited concatstabto(asmlist);
  1606. end;
  1607. end;
  1608. {$endif GDB}
  1609. function tarraydef.elesize : longint;
  1610. begin
  1611. elesize:=elementtype.def^.size;
  1612. end;
  1613. function tarraydef.size : longint;
  1614. begin
  1615. {Tarraydef.size may never be called for an open array!}
  1616. if highrange<lowrange then
  1617. internalerror(99080501);
  1618. If (elesize>0) and
  1619. (
  1620. (highrange-lowrange = $7fffffff) or
  1621. { () are needed around elesize-1 to avoid a possible
  1622. integer overflow for elesize=1 !! PM }
  1623. (($7fffffff div elesize + (elesize -1)) < (highrange - lowrange))
  1624. ) Then
  1625. Begin
  1626. Message(sym_e_segment_too_large);
  1627. size := 4
  1628. End
  1629. Else size:=(highrange-lowrange+1)*elesize;
  1630. end;
  1631. function tarraydef.alignment : longint;
  1632. begin
  1633. { alignment is the size of the elements }
  1634. alignment:=elementtype.def^.size;
  1635. end;
  1636. function tarraydef.needs_inittable : boolean;
  1637. begin
  1638. needs_inittable:=elementtype.def^.needs_inittable;
  1639. end;
  1640. procedure tarraydef.write_child_rtti_data;
  1641. begin
  1642. elementtype.def^.get_rtti_label;
  1643. end;
  1644. procedure tarraydef.write_rtti_data;
  1645. begin
  1646. rttilist^.concat(new(pai_const,init_8bit(tkarray)));
  1647. write_rtti_name;
  1648. { size of elements }
  1649. rttilist^.concat(new(pai_const,init_32bit(elementtype.def^.size)));
  1650. { count of elements }
  1651. rttilist^.concat(new(pai_const,init_32bit(highrange-lowrange+1)));
  1652. { element type }
  1653. rttilist^.concat(new(pai_const_symbol,initname(elementtype.def^.get_rtti_label)));
  1654. end;
  1655. function tarraydef.gettypename : string;
  1656. begin
  1657. if isarrayofconst or isConstructor then
  1658. begin
  1659. if isvariant then
  1660. gettypename:='Array Of Const'
  1661. else
  1662. gettypename:='Array Of '+elementtype.def^.typename;
  1663. end
  1664. else if is_open_array(@self) then
  1665. gettypename:='Array Of '+elementtype.def^.typename
  1666. else
  1667. begin
  1668. if rangetype.def^.deftype=enumdef then
  1669. gettypename:='Array['+rangetype.def^.typename+'] Of '+elementtype.def^.typename
  1670. else
  1671. gettypename:='Array['+tostr(lowrange)+'..'+
  1672. tostr(highrange)+'] Of '+elementtype.def^.typename
  1673. end;
  1674. end;
  1675. {***************************************************************************
  1676. trecorddef
  1677. ***************************************************************************}
  1678. constructor trecorddef.init(p : psymtable);
  1679. begin
  1680. inherited init;
  1681. deftype:=recorddef;
  1682. symtable:=p;
  1683. symtable^.defowner := @self;
  1684. symtable^.dataalignment:=packrecordalignment[aktpackrecords];
  1685. end;
  1686. constructor trecorddef.load;
  1687. var
  1688. oldread_member : boolean;
  1689. begin
  1690. inherited load;
  1691. deftype:=recorddef;
  1692. savesize:=readlong;
  1693. oldread_member:=read_member;
  1694. read_member:=true;
  1695. symtable:=new(psymtable,loadas(recordsymtable));
  1696. read_member:=oldread_member;
  1697. symtable^.defowner := @self;
  1698. end;
  1699. destructor trecorddef.done;
  1700. begin
  1701. if assigned(symtable) then
  1702. dispose(symtable,done);
  1703. inherited done;
  1704. end;
  1705. var
  1706. binittable : boolean;
  1707. procedure check_rec_inittable(s : pnamedindexobject);
  1708. begin
  1709. if (not binittable) and
  1710. (psym(s)^.typ=varsym) and
  1711. assigned(pvarsym(s)^.vartype.def) then
  1712. begin
  1713. if ((pvarsym(s)^.vartype.def^.deftype<>objectdef) or
  1714. not(pobjectdef(pvarsym(s)^.vartype.def)^.is_class)) then
  1715. binittable:=pvarsym(s)^.vartype.def^.needs_inittable;
  1716. end;
  1717. end;
  1718. function trecorddef.needs_inittable : boolean;
  1719. var
  1720. oldb : boolean;
  1721. begin
  1722. { there are recursive calls to needs_rtti possible, }
  1723. { so we have to change to old value how else should }
  1724. { we do that ? check_rec_rtti can't be a nested }
  1725. { procedure of needs_rtti ! }
  1726. oldb:=binittable;
  1727. binittable:=false;
  1728. symtable^.foreach({$ifndef TP}@{$endif}check_rec_inittable);
  1729. needs_inittable:=binittable;
  1730. binittable:=oldb;
  1731. end;
  1732. procedure trecorddef.deref;
  1733. var
  1734. oldrecsyms : psymtable;
  1735. begin
  1736. inherited deref;
  1737. oldrecsyms:=aktrecordsymtable;
  1738. aktrecordsymtable:=symtable;
  1739. { now dereference the definitions }
  1740. symtable^.deref;
  1741. aktrecordsymtable:=oldrecsyms;
  1742. end;
  1743. procedure trecorddef.write;
  1744. var
  1745. oldread_member : boolean;
  1746. begin
  1747. oldread_member:=read_member;
  1748. read_member:=true;
  1749. inherited write;
  1750. writelong(savesize);
  1751. current_ppu^.writeentry(ibrecorddef);
  1752. self.symtable^.writeas;
  1753. read_member:=oldread_member;
  1754. end;
  1755. function trecorddef.size:longint;
  1756. begin
  1757. size:=symtable^.datasize;
  1758. end;
  1759. function trecorddef.alignment:longint;
  1760. begin
  1761. alignment:=symtable^.dataalignment;
  1762. end;
  1763. {$ifdef GDB}
  1764. Const StabRecString : pchar = Nil;
  1765. StabRecSize : longint = 0;
  1766. RecOffset : Longint = 0;
  1767. procedure addname(p : pnamedindexobject);
  1768. var
  1769. news, newrec : pchar;
  1770. spec : string[3];
  1771. size : longint;
  1772. begin
  1773. { static variables from objects are like global objects }
  1774. if (sp_static in psym(p)^.symoptions) then
  1775. exit;
  1776. If psym(p)^.typ = varsym then
  1777. begin
  1778. if (sp_protected in psym(p)^.symoptions) then
  1779. spec:='/1'
  1780. else if (sp_private in psym(p)^.symoptions) then
  1781. spec:='/0'
  1782. else
  1783. spec:='';
  1784. { class fields are pointers PM }
  1785. if not assigned(pvarsym(p)^.vartype.def) then
  1786. writeln(pvarsym(p)^.name);
  1787. if (pvarsym(p)^.vartype.def^.deftype=objectdef) and
  1788. pobjectdef(pvarsym(p)^.vartype.def)^.is_class then
  1789. spec:=spec+'*';
  1790. size:=pvarsym(p)^.vartype.def^.size;
  1791. { open arrays made overflows !! }
  1792. if size>$fffffff then
  1793. size:=$fffffff;
  1794. newrec := strpnew(p^.name+':'+spec+pvarsym(p)^.vartype.def^.numberstring
  1795. +','+tostr(pvarsym(p)^.address*8)+','
  1796. +tostr(size*8)+';');
  1797. if strlen(StabRecString) + strlen(newrec) >= StabRecSize-256 then
  1798. begin
  1799. getmem(news,stabrecsize+memsizeinc);
  1800. strcopy(news,stabrecstring);
  1801. freemem(stabrecstring,stabrecsize);
  1802. stabrecsize:=stabrecsize+memsizeinc;
  1803. stabrecstring:=news;
  1804. end;
  1805. strcat(StabRecstring,newrec);
  1806. strdispose(newrec);
  1807. {This should be used for case !!}
  1808. RecOffset := RecOffset + pvarsym(p)^.vartype.def^.size;
  1809. end;
  1810. end;
  1811. function trecorddef.stabstring : pchar;
  1812. Var oldrec : pchar;
  1813. oldsize : longint;
  1814. begin
  1815. oldrec := stabrecstring;
  1816. oldsize:=stabrecsize;
  1817. GetMem(stabrecstring,memsizeinc);
  1818. stabrecsize:=memsizeinc;
  1819. strpcopy(stabRecString,'s'+tostr(size));
  1820. RecOffset := 0;
  1821. symtable^.foreach({$ifndef TP}@{$endif}addname);
  1822. { FPC doesn't want to convert a char to a pchar}
  1823. { is this a bug ? }
  1824. strpcopy(strend(StabRecString),';');
  1825. stabstring := strnew(StabRecString);
  1826. Freemem(stabrecstring,stabrecsize);
  1827. stabrecstring := oldrec;
  1828. stabrecsize:=oldsize;
  1829. end;
  1830. procedure trecorddef.concatstabto(asmlist : paasmoutput);
  1831. begin
  1832. if (not assigned(typesym) or typesym^.isusedinstab or (cs_gdb_dbx in aktglobalswitches)) and
  1833. (not is_def_stab_written) then
  1834. inherited concatstabto(asmlist);
  1835. end;
  1836. {$endif GDB}
  1837. var
  1838. count : longint;
  1839. procedure count_inittable_fields(sym : pnamedindexobject);{$ifndef fpc}far;{$endif}
  1840. begin
  1841. if ((psym(sym)^.typ=varsym) and
  1842. pvarsym(sym)^.vartype.def^.needs_inittable)
  1843. and ((pvarsym(sym)^.vartype.def^.deftype<>objectdef) or
  1844. (not pobjectdef(pvarsym(sym)^.vartype.def)^.is_class)) then
  1845. inc(count);
  1846. end;
  1847. procedure count_fields(sym : pnamedindexobject);{$ifndef fpc}far;{$endif}
  1848. begin
  1849. inc(count);
  1850. end;
  1851. procedure write_field_inittable(sym : pnamedindexobject);{$ifndef fpc}far;{$endif}
  1852. begin
  1853. if ((psym(sym)^.typ=varsym) and
  1854. pvarsym(sym)^.vartype.def^.needs_inittable) and
  1855. ((pvarsym(sym)^.vartype.def^.deftype<>objectdef) or
  1856. (not pobjectdef(pvarsym(sym)^.vartype.def)^.is_class)) then
  1857. begin
  1858. rttilist^.concat(new(pai_const_symbol,init(pvarsym(sym)^.vartype.def^.get_inittable_label)));
  1859. rttilist^.concat(new(pai_const,init_32bit(pvarsym(sym)^.address)));
  1860. end;
  1861. end;
  1862. procedure write_field_rtti(sym : pnamedindexobject);{$ifndef fpc}far;{$endif}
  1863. begin
  1864. rttilist^.concat(new(pai_const_symbol,initname(pvarsym(sym)^.vartype.def^.get_rtti_label)));
  1865. rttilist^.concat(new(pai_const,init_32bit(pvarsym(sym)^.address)));
  1866. end;
  1867. procedure generate_child_inittable(sym:pnamedindexobject);{$ifndef fpc}far;{$endif}
  1868. begin
  1869. if (psym(sym)^.typ=varsym) and
  1870. pvarsym(sym)^.vartype.def^.needs_inittable then
  1871. { force inittable generation }
  1872. pvarsym(sym)^.vartype.def^.get_inittable_label;
  1873. end;
  1874. procedure generate_child_rtti(sym : pnamedindexobject);{$ifndef fpc}far;{$endif}
  1875. begin
  1876. pvarsym(sym)^.vartype.def^.get_rtti_label;
  1877. end;
  1878. procedure trecorddef.write_child_rtti_data;
  1879. begin
  1880. symtable^.foreach({$ifndef TP}@{$endif}generate_child_rtti);
  1881. end;
  1882. procedure trecorddef.write_child_init_data;
  1883. begin
  1884. symtable^.foreach({$ifndef TP}@{$endif}generate_child_inittable);
  1885. end;
  1886. procedure trecorddef.write_rtti_data;
  1887. begin
  1888. rttilist^.concat(new(pai_const,init_8bit(tkrecord)));
  1889. write_rtti_name;
  1890. rttilist^.concat(new(pai_const,init_32bit(size)));
  1891. count:=0;
  1892. symtable^.foreach({$ifndef TP}@{$endif}count_fields);
  1893. rttilist^.concat(new(pai_const,init_32bit(count)));
  1894. symtable^.foreach({$ifndef TP}@{$endif}write_field_rtti);
  1895. end;
  1896. procedure trecorddef.write_init_data;
  1897. begin
  1898. rttilist^.concat(new(pai_const,init_8bit(14)));
  1899. write_rtti_name;
  1900. rttilist^.concat(new(pai_const,init_32bit(size)));
  1901. count:=0;
  1902. symtable^.foreach({$ifndef TP}@{$endif}count_inittable_fields);
  1903. rttilist^.concat(new(pai_const,init_32bit(count)));
  1904. symtable^.foreach({$ifndef TP}@{$endif}write_field_inittable);
  1905. end;
  1906. function trecorddef.gettypename : string;
  1907. begin
  1908. gettypename:='<record type>'
  1909. end;
  1910. {***************************************************************************
  1911. TABSTRACTPROCDEF
  1912. ***************************************************************************}
  1913. constructor tabstractprocdef.init;
  1914. begin
  1915. inherited init;
  1916. new(para,init);
  1917. fpu_used:=0;
  1918. proctypeoption:=potype_none;
  1919. proccalloptions:=[];
  1920. procoptions:=[];
  1921. rettype.setdef(voiddef);
  1922. symtablelevel:=0;
  1923. savesize:=target_os.size_of_pointer;
  1924. end;
  1925. destructor tabstractprocdef.done;
  1926. begin
  1927. dispose(para,done);
  1928. inherited done;
  1929. end;
  1930. procedure tabstractprocdef.concatpara(tt:ttype;vsp : tvarspez);
  1931. var
  1932. hp : pparaitem;
  1933. begin
  1934. new(hp,init);
  1935. hp^.paratyp:=vsp;
  1936. hp^.paratype:=tt;
  1937. hp^.register:=R_NO;
  1938. para^.insert(hp);
  1939. end;
  1940. { all functions returning in FPU are
  1941. assume to use 2 FPU registers
  1942. until the function implementation
  1943. is processed PM }
  1944. procedure tabstractprocdef.test_if_fpu_result;
  1945. begin
  1946. if assigned(rettype.def) and is_fpu(rettype.def) then
  1947. fpu_used:=2;
  1948. end;
  1949. procedure tabstractprocdef.deref;
  1950. var
  1951. hp : pparaitem;
  1952. begin
  1953. inherited deref;
  1954. rettype.resolve;
  1955. hp:=pparaitem(para^.first);
  1956. while assigned(hp) do
  1957. begin
  1958. hp^.paratype.resolve;
  1959. hp:=pparaitem(hp^.next);
  1960. end;
  1961. end;
  1962. constructor tabstractprocdef.load;
  1963. var
  1964. hp : pparaitem;
  1965. count,i : word;
  1966. begin
  1967. inherited load;
  1968. new(para,init);
  1969. rettype.load;
  1970. fpu_used:=readbyte;
  1971. proctypeoption:=tproctypeoption(readlong);
  1972. readsmallset(proccalloptions);
  1973. readsmallset(procoptions);
  1974. count:=readword;
  1975. savesize:=target_os.size_of_pointer;
  1976. for i:=1 to count do
  1977. begin
  1978. new(hp,init);
  1979. hp^.paratyp:=tvarspez(readbyte);
  1980. { hp^.register:=tregister(readbyte); }
  1981. hp^.register:=R_NO;
  1982. hp^.paratype.load;
  1983. para^.concat(hp);
  1984. end;
  1985. end;
  1986. procedure tabstractprocdef.write;
  1987. var
  1988. hp : pparaitem;
  1989. begin
  1990. inherited write;
  1991. rettype.write;
  1992. current_ppu^.do_interface_crc:=false;
  1993. writebyte(fpu_used);
  1994. writelong(ord(proctypeoption));
  1995. writesmallset(proccalloptions);
  1996. writesmallset(procoptions);
  1997. writeword(para^.count);
  1998. hp:=pparaitem(para^.first);
  1999. while assigned(hp) do
  2000. begin
  2001. writebyte(byte(hp^.paratyp));
  2002. { writebyte(byte(hp^.register)); }
  2003. hp^.paratype.write;
  2004. hp:=pparaitem(hp^.next);
  2005. end;
  2006. end;
  2007. function tabstractprocdef.para_size(alignsize:longint) : longint;
  2008. var
  2009. pdc : pparaitem;
  2010. l : longint;
  2011. begin
  2012. l:=0;
  2013. pdc:=pparaitem(para^.first);
  2014. while assigned(pdc) do
  2015. begin
  2016. case pdc^.paratyp of
  2017. vs_var : inc(l,target_os.size_of_pointer);
  2018. vs_value,
  2019. vs_const : if push_addr_param(pdc^.paratype.def) then
  2020. inc(l,target_os.size_of_pointer)
  2021. else
  2022. inc(l,pdc^.paratype.def^.size);
  2023. end;
  2024. l:=align(l,alignsize);
  2025. pdc:=pparaitem(pdc^.next);
  2026. end;
  2027. para_size:=l;
  2028. end;
  2029. function tabstractprocdef.demangled_paras : string;
  2030. var
  2031. s : string;
  2032. hp : pparaitem;
  2033. begin
  2034. s:='(';
  2035. hp:=pparaitem(para^.last);
  2036. while assigned(hp) do
  2037. begin
  2038. if assigned(hp^.paratype.def^.typesym) then
  2039. s:=s+hp^.paratype.def^.typesym^.name
  2040. else if hp^.paratyp=vs_var then
  2041. s:=s+'var'
  2042. else if hp^.paratyp=vs_const then
  2043. s:=s+'const';
  2044. hp:=pparaitem(hp^.previous);
  2045. if assigned(hp) then
  2046. s:=s+',';
  2047. end;
  2048. s:=s+')';
  2049. demangled_paras:=s;
  2050. end;
  2051. function tabstractprocdef.proccalloption2str : string;
  2052. type
  2053. tproccallopt=record
  2054. mask : tproccalloption;
  2055. str : string[30];
  2056. end;
  2057. const
  2058. proccallopts=12;
  2059. proccallopt : array[1..proccallopts] of tproccallopt=(
  2060. (mask:pocall_none; str:''),
  2061. (mask:pocall_clearstack; str:'ClearStack'),
  2062. (mask:pocall_leftright; str:'LeftRight'),
  2063. (mask:pocall_cdecl; str:'Cdecl'),
  2064. (mask:pocall_register; str:'Register'),
  2065. (mask:pocall_stdcall; str:'StdCall'),
  2066. (mask:pocall_safecall; str:'SafeCall'),
  2067. (mask:pocall_palmossyscall;str:'PalmOSSysCall'),
  2068. (mask:pocall_system; str:'System'),
  2069. (mask:pocall_inline; str:'Inline'),
  2070. (mask:pocall_internproc; str:'InternProc'),
  2071. (mask:pocall_internconst; str:'InternConst')
  2072. );
  2073. var
  2074. s : string;
  2075. i : longint;
  2076. first : boolean;
  2077. begin
  2078. s:='';
  2079. first:=true;
  2080. for i:=1to proccallopts do
  2081. if (proccallopt[i].mask in proccalloptions) then
  2082. begin
  2083. if first then
  2084. first:=false
  2085. else
  2086. s:=s+';';
  2087. s:=s+proccallopt[i].str;
  2088. end;
  2089. proccalloption2str:=s;
  2090. end;
  2091. {$ifdef GDB}
  2092. function tabstractprocdef.stabstring : pchar;
  2093. begin
  2094. stabstring := strpnew('abstractproc'+numberstring+';');
  2095. end;
  2096. procedure tabstractprocdef.concatstabto(asmlist : paasmoutput);
  2097. begin
  2098. if (not assigned(typesym) or typesym^.isusedinstab or (cs_gdb_dbx in aktglobalswitches))
  2099. and not is_def_stab_written then
  2100. begin
  2101. if assigned(rettype.def) then forcestabto(asmlist,rettype.def);
  2102. inherited concatstabto(asmlist);
  2103. end;
  2104. end;
  2105. {$endif GDB}
  2106. {***************************************************************************
  2107. TPROCDEF
  2108. ***************************************************************************}
  2109. constructor tprocdef.init;
  2110. begin
  2111. inherited init;
  2112. deftype:=procdef;
  2113. _mangledname:=nil;
  2114. nextoverloaded:=nil;
  2115. fileinfo:=aktfilepos;
  2116. extnumber:=-1;
  2117. localst:=new(psymtable,init(localsymtable));
  2118. parast:=new(psymtable,init(parasymtable));
  2119. localst^.defowner:=@self;
  2120. parast^.defowner:=@self;
  2121. { this is used by insert
  2122. to check same names in parast and localst }
  2123. localst^.next:=parast;
  2124. defref:=nil;
  2125. crossref:=nil;
  2126. lastwritten:=nil;
  2127. refcount:=0;
  2128. if (cs_browser in aktmoduleswitches) and make_ref then
  2129. begin
  2130. defref:=new(pref,init(defref,@tokenpos));
  2131. inc(refcount);
  2132. end;
  2133. lastref:=defref;
  2134. { first, we assume that all registers are used }
  2135. {$ifdef newcg}
  2136. usedregisters:=[firstreg..lastreg];
  2137. {$else newcg}
  2138. {$ifdef i386}
  2139. usedregisters:=$ff;
  2140. {$endif i386}
  2141. {$ifdef m68k}
  2142. usedregisters:=$FFFF;
  2143. {$endif}
  2144. {$endif newcg}
  2145. forwarddef:=true;
  2146. interfacedef:=false;
  2147. _class := nil;
  2148. code:=nil;
  2149. count:=false;
  2150. is_used:=false;
  2151. end;
  2152. constructor tprocdef.load;
  2153. var
  2154. s : string;
  2155. begin
  2156. inherited load;
  2157. deftype:=procdef;
  2158. {$ifdef newcg}
  2159. readnormalset(usedregisters);
  2160. {$else newcg}
  2161. {$ifdef i386}
  2162. usedregisters:=readbyte;
  2163. {$endif i386}
  2164. {$ifdef m68k}
  2165. usedregisters:=readword;
  2166. {$endif}
  2167. {$endif newcg}
  2168. s:=readstring;
  2169. setstring(_mangledname,s);
  2170. extnumber:=readlong;
  2171. nextoverloaded:=pprocdef(readdefref);
  2172. _class := pobjectdef(readdefref);
  2173. readposinfo(fileinfo);
  2174. if (cs_link_deffile in aktglobalswitches) and
  2175. (tf_need_export in target_info.flags) and
  2176. (po_exports in procoptions) then
  2177. deffile.AddExport(mangledname);
  2178. parast:=nil;
  2179. localst:=nil;
  2180. forwarddef:=false;
  2181. interfacedef:=false;
  2182. lastref:=nil;
  2183. lastwritten:=nil;
  2184. defref:=nil;
  2185. refcount:=0;
  2186. count:=true;
  2187. is_used:=false;
  2188. end;
  2189. Const local_symtable_index : longint = $8001;
  2190. procedure tprocdef.load_references;
  2191. var
  2192. pos : tfileposinfo;
  2193. {$ifndef NOLOCALBROWSER}
  2194. oldsymtablestack,
  2195. st : psymtable;
  2196. {$endif ndef NOLOCALBROWSER}
  2197. move_last : boolean;
  2198. begin
  2199. move_last:=lastwritten=lastref;
  2200. while (not current_ppu^.endofentry) do
  2201. begin
  2202. readposinfo(pos);
  2203. inc(refcount);
  2204. lastref:=new(pref,init(lastref,@pos));
  2205. lastref^.is_written:=true;
  2206. if refcount=1 then
  2207. defref:=lastref;
  2208. end;
  2209. if move_last then
  2210. lastwritten:=lastref;
  2211. if ((current_module^.flags and uf_local_browser)<>0)
  2212. and is_in_current then
  2213. begin
  2214. {$ifndef NOLOCALBROWSER}
  2215. oldsymtablestack:=symtablestack;
  2216. st:=aktlocalsymtable;
  2217. new(parast,loadas(parasymtable));
  2218. parast^.defowner:=@self;
  2219. aktlocalsymtable:=parast;
  2220. parast^.deref;
  2221. parast^.next:=owner;
  2222. parast^.load_browser;
  2223. aktlocalsymtable:=st;
  2224. new(localst,loadas(localsymtable));
  2225. localst^.defowner:=@self;
  2226. aktlocalsymtable:=localst;
  2227. symtablestack:=parast;
  2228. localst^.deref;
  2229. localst^.next:=parast;
  2230. localst^.load_browser;
  2231. aktlocalsymtable:=st;
  2232. symtablestack:=oldsymtablestack;
  2233. {$endif ndef NOLOCALBROWSER}
  2234. end;
  2235. end;
  2236. function tprocdef.write_references : boolean;
  2237. var
  2238. ref : pref;
  2239. {$ifndef NOLOCALBROWSER}
  2240. st : psymtable;
  2241. pdo : pobjectdef;
  2242. {$endif ndef NOLOCALBROWSER}
  2243. move_last : boolean;
  2244. begin
  2245. move_last:=lastwritten=lastref;
  2246. if move_last and (((current_module^.flags and uf_local_browser)=0)
  2247. or not is_in_current) then
  2248. exit;
  2249. { write address of this symbol }
  2250. writedefref(@self);
  2251. { write refs }
  2252. if assigned(lastwritten) then
  2253. ref:=lastwritten
  2254. else
  2255. ref:=defref;
  2256. while assigned(ref) do
  2257. begin
  2258. if ref^.moduleindex=current_module^.unit_index then
  2259. begin
  2260. writeposinfo(ref^.posinfo);
  2261. ref^.is_written:=true;
  2262. if move_last then
  2263. lastwritten:=ref;
  2264. end
  2265. else if not ref^.is_written then
  2266. move_last:=false
  2267. else if move_last then
  2268. lastwritten:=ref;
  2269. ref:=ref^.nextref;
  2270. end;
  2271. current_ppu^.writeentry(ibdefref);
  2272. write_references:=true;
  2273. if ((current_module^.flags and uf_local_browser)<>0)
  2274. and is_in_current then
  2275. begin
  2276. {$ifndef NOLOCALBROWSER}
  2277. pdo:=_class;
  2278. if (owner^.symtabletype<>localsymtable) then
  2279. while assigned(pdo) do
  2280. begin
  2281. if pdo^.symtable<>aktrecordsymtable then
  2282. begin
  2283. pdo^.symtable^.unitid:=local_symtable_index;
  2284. inc(local_symtable_index);
  2285. end;
  2286. pdo:=pdo^.childof;
  2287. end;
  2288. { we need TESTLOCALBROWSER para and local symtables
  2289. PPU files are then easier to read PM }
  2290. if not assigned(parast) then
  2291. parast:=new(psymtable,init(parasymtable));
  2292. parast^.defowner:=@self;
  2293. st:=aktlocalsymtable;
  2294. aktlocalsymtable:=parast;
  2295. parast^.writeas;
  2296. parast^.unitid:=local_symtable_index;
  2297. inc(local_symtable_index);
  2298. parast^.write_browser;
  2299. if not assigned(localst) then
  2300. localst:=new(psymtable,init(localsymtable));
  2301. localst^.defowner:=@self;
  2302. aktlocalsymtable:=localst;
  2303. localst^.writeas;
  2304. localst^.unitid:=local_symtable_index;
  2305. inc(local_symtable_index);
  2306. localst^.write_browser;
  2307. aktlocalsymtable:=st;
  2308. { decrement for }
  2309. local_symtable_index:=local_symtable_index-2;
  2310. pdo:=_class;
  2311. if (owner^.symtabletype<>localsymtable) then
  2312. while assigned(pdo) do
  2313. begin
  2314. if pdo^.symtable<>aktrecordsymtable then
  2315. dec(local_symtable_index);
  2316. pdo:=pdo^.childof;
  2317. end;
  2318. {$endif ndef NOLOCALBROWSER}
  2319. end;
  2320. end;
  2321. {$ifdef BrowserLog}
  2322. procedure tprocdef.add_to_browserlog;
  2323. begin
  2324. if assigned(defref) then
  2325. begin
  2326. browserlog.AddLog('***'+mangledname);
  2327. browserlog.AddLogRefs(defref);
  2328. if (current_module^.flags and uf_local_browser)<>0 then
  2329. begin
  2330. if assigned(parast) then
  2331. parast^.writebrowserlog;
  2332. if assigned(localst) then
  2333. localst^.writebrowserlog;
  2334. end;
  2335. end;
  2336. end;
  2337. {$endif BrowserLog}
  2338. destructor tprocdef.done;
  2339. begin
  2340. if assigned(defref) then
  2341. dispose(defref,done);
  2342. if assigned(parast) then
  2343. dispose(parast,done);
  2344. if assigned(localst) and (localst^.symtabletype<>staticsymtable) then
  2345. dispose(localst,done);
  2346. if (pocall_inline in proccalloptions) and assigned(code) then
  2347. disposetree(ptree(code));
  2348. if (po_msgstr in procoptions) then
  2349. strdispose(messageinf.str);
  2350. if
  2351. {$ifdef tp}
  2352. not(use_big) and
  2353. {$endif}
  2354. assigned(_mangledname) then
  2355. strdispose(_mangledname);
  2356. inherited done;
  2357. end;
  2358. procedure tprocdef.write;
  2359. begin
  2360. inherited write;
  2361. current_ppu^.do_interface_crc:=false;
  2362. { set all registers to used for simplified compilation PM }
  2363. if simplify_ppu then
  2364. begin
  2365. {$ifdef newcg}
  2366. usedregisters:=[firstreg..lastreg];
  2367. {$else newcg}
  2368. {$ifdef i386}
  2369. usedregisters:=$ff;
  2370. {$endif i386}
  2371. {$ifdef m68k}
  2372. usedregisters:=$ffff;
  2373. {$endif}
  2374. {$endif newcg}
  2375. end;
  2376. {$ifdef newcg}
  2377. writenormalset(usedregisters);
  2378. {$else newcg}
  2379. {$ifdef i386}
  2380. writebyte(usedregisters);
  2381. {$endif i386}
  2382. {$ifdef m68k}
  2383. writeword(usedregisters);
  2384. {$endif}
  2385. {$endif newcg}
  2386. current_ppu^.do_interface_crc:=true;
  2387. writestring(mangledname);
  2388. writelong(extnumber);
  2389. if (proctypeoption<>potype_operator) then
  2390. writedefref(nextoverloaded)
  2391. else
  2392. begin
  2393. { only write the overloads from the same unit }
  2394. if assigned(nextoverloaded) and
  2395. (nextoverloaded^.owner=owner) then
  2396. writedefref(nextoverloaded)
  2397. else
  2398. writedefref(nil);
  2399. end;
  2400. writedefref(_class);
  2401. writeposinfo(fileinfo);
  2402. if (pocall_inline in proccalloptions) then
  2403. begin
  2404. { we need to save
  2405. - the para and the local symtable
  2406. - the code ptree !! PM
  2407. writesymtable(parast);
  2408. writesymtable(localst);
  2409. writeptree(ptree(code));
  2410. }
  2411. end;
  2412. current_ppu^.writeentry(ibprocdef);
  2413. end;
  2414. function tprocdef.haspara:boolean;
  2415. begin
  2416. haspara:=assigned(aktprocsym^.definition^.parast^.symindex^.first);
  2417. end;
  2418. {$ifdef GDB}
  2419. procedure addparaname(p : psym);
  2420. var vs : char;
  2421. begin
  2422. if pvarsym(p)^.varspez = vs_value then vs := '1'
  2423. else vs := '0';
  2424. strpcopy(strend(StabRecString),p^.name+':'+pvarsym(p)^.vartype.def^.numberstring+','+vs+';');
  2425. end;
  2426. function tprocdef.stabstring : pchar;
  2427. var
  2428. i : longint;
  2429. oldrec : pchar;
  2430. begin
  2431. oldrec := stabrecstring;
  2432. getmem(StabRecString,1024);
  2433. strpcopy(StabRecString,'f'+rettype.def^.numberstring);
  2434. i:=para^.count;
  2435. if i>0 then
  2436. begin
  2437. strpcopy(strend(StabRecString),','+tostr(i)+';');
  2438. (* confuse gdb !! PM
  2439. if assigned(parast) then
  2440. parast^.foreach({$ifndef TP}@{$endif}addparaname)
  2441. else
  2442. begin
  2443. param := para1;
  2444. i := 0;
  2445. while assigned(param) do
  2446. begin
  2447. inc(i);
  2448. if param^.paratyp = vs_value then vartyp := '1' else vartyp := '0';
  2449. {Here we have lost the parameter names !!}
  2450. {using lower case parameters }
  2451. strpcopy(strend(stabrecstring),'p'+tostr(i)
  2452. +':'+param^.paratype.def^.numberstring+','+vartyp+';');
  2453. param := param^.next;
  2454. end;
  2455. end; *)
  2456. {strpcopy(strend(StabRecString),';');}
  2457. end;
  2458. stabstring := strnew(stabrecstring);
  2459. freemem(stabrecstring,1024);
  2460. stabrecstring := oldrec;
  2461. end;
  2462. procedure tprocdef.concatstabto(asmlist : paasmoutput);
  2463. begin
  2464. end;
  2465. {$endif GDB}
  2466. procedure tprocdef.deref;
  2467. begin
  2468. inherited deref;
  2469. resolvedef(pdef(nextoverloaded));
  2470. resolvedef(pdef(_class));
  2471. end;
  2472. function tprocdef.mangledname : string;
  2473. {$ifdef tp}
  2474. var
  2475. oldpos : longint;
  2476. s : string;
  2477. b : byte;
  2478. {$endif tp}
  2479. begin
  2480. {$ifndef Delphi}
  2481. {$ifdef tp}
  2482. if use_big then
  2483. begin
  2484. symbolstream.seek(longint(_mangledname));
  2485. symbolstream.read(b,1);
  2486. symbolstream.read(s[1],b);
  2487. s[0]:=chr(b);
  2488. mangledname:=s;
  2489. end
  2490. else
  2491. {$endif}
  2492. {$endif Delphi}
  2493. mangledname:=strpas(_mangledname);
  2494. if count then
  2495. is_used:=true;
  2496. end;
  2497. function tprocdef.procname: string;
  2498. var
  2499. s : string;
  2500. l : longint;
  2501. begin
  2502. s:=mangledname;
  2503. { delete leading $$'s }
  2504. l:=pos('$$',s);
  2505. while l<>0 do
  2506. begin
  2507. delete(s,1,l+1);
  2508. l:=pos('$$',s);
  2509. end;
  2510. { delete leading _$'s }
  2511. l:=pos('_$',s);
  2512. while l<>0 do
  2513. begin
  2514. delete(s,1,l+1);
  2515. l:=pos('_$',s);
  2516. end;
  2517. l:=pos('$',s);
  2518. if l=0 then
  2519. procname:=s
  2520. else
  2521. procname:=Copy(s,1,l-1);
  2522. end;
  2523. {$IfDef GDB}
  2524. function tprocdef.cplusplusmangledname : string;
  2525. var
  2526. s,s2 : string;
  2527. param : pparaitem;
  2528. begin
  2529. s := typesym^.name;
  2530. if _class <> nil then
  2531. begin
  2532. s2 := _class^.objname^;
  2533. s := s+'__'+tostr(length(s2))+s2;
  2534. end else s := s + '_';
  2535. param := pparaitem(para^.first);
  2536. while assigned(param) do
  2537. begin
  2538. s2 := param^.paratype.def^.typesym^.name;
  2539. s := s+tostr(length(s2))+s2;
  2540. param := pparaitem(param^.next);
  2541. end;
  2542. cplusplusmangledname:=s;
  2543. end;
  2544. {$EndIf GDB}
  2545. procedure tprocdef.setmangledname(const s : string);
  2546. begin
  2547. if {$ifdef tp}not(use_big) and{$endif} (assigned(_mangledname)) then
  2548. strdispose(_mangledname);
  2549. setstring(_mangledname,s);
  2550. if assigned(parast) then
  2551. begin
  2552. stringdispose(parast^.name);
  2553. parast^.name:=stringdup('args of '+s);
  2554. end;
  2555. if assigned(localst) then
  2556. begin
  2557. stringdispose(localst^.name);
  2558. localst^.name:=stringdup('locals of '+s);
  2559. end;
  2560. end;
  2561. {***************************************************************************
  2562. TPROCVARDEF
  2563. ***************************************************************************}
  2564. constructor tprocvardef.init;
  2565. begin
  2566. inherited init;
  2567. deftype:=procvardef;
  2568. end;
  2569. constructor tprocvardef.load;
  2570. begin
  2571. inherited load;
  2572. deftype:=procvardef;
  2573. end;
  2574. procedure tprocvardef.write;
  2575. begin
  2576. { here we cannot get a real good value so just give something }
  2577. { plausible (PM) }
  2578. { a more secure way would be
  2579. to allways store in a temp }
  2580. if is_fpu(rettype.def) then
  2581. fpu_used:=2
  2582. else
  2583. fpu_used:=0;
  2584. inherited write;
  2585. current_ppu^.writeentry(ibprocvardef);
  2586. end;
  2587. function tprocvardef.size : longint;
  2588. begin
  2589. if (po_methodpointer in procoptions) then
  2590. size:=2*target_os.size_of_pointer
  2591. else
  2592. size:=target_os.size_of_pointer;
  2593. end;
  2594. {$ifdef GDB}
  2595. function tprocvardef.stabstring : pchar;
  2596. var
  2597. nss : pchar;
  2598. { i : longint; }
  2599. begin
  2600. { i := para^.count; }
  2601. getmem(nss,1024);
  2602. { it is not a function but a function pointer !! (PM) }
  2603. strpcopy(nss,'*f'+rettype.def^.numberstring{+','+tostr(i)}+';');
  2604. { this confuses gdb !!
  2605. we should use 'F' instead of 'f' but
  2606. as we use c++ language mode
  2607. it does not like that either
  2608. Please do not remove this part
  2609. might be used once
  2610. gdb for pascal is ready PM }
  2611. (*
  2612. param := para1;
  2613. i := 0;
  2614. while assigned(param) do
  2615. begin
  2616. inc(i);
  2617. if param^.paratyp = vs_value then vartyp := '1' else vartyp := '0';
  2618. {Here we have lost the parameter names !!}
  2619. pst := strpnew('p'+tostr(i)+':'+param^.paratype.def^.numberstring+','+vartyp+';');
  2620. strcat(nss,pst);
  2621. strdispose(pst);
  2622. param := param^.next;
  2623. end; *)
  2624. {strpcopy(strend(nss),';');}
  2625. stabstring := strnew(nss);
  2626. freemem(nss,1024);
  2627. end;
  2628. procedure tprocvardef.concatstabto(asmlist : paasmoutput);
  2629. begin
  2630. if ( not assigned(typesym) or typesym^.isusedinstab or (cs_gdb_dbx in aktglobalswitches))
  2631. and not is_def_stab_written then
  2632. inherited concatstabto(asmlist);
  2633. is_def_stab_written:=true;
  2634. end;
  2635. {$endif GDB}
  2636. procedure tprocvardef.write_rtti_data;
  2637. var
  2638. pdc : pparaitem;
  2639. methodkind, paraspec : byte;
  2640. begin
  2641. if po_methodpointer in procoptions then
  2642. begin
  2643. { write method id and name }
  2644. rttilist^.concat(new(pai_const,init_8bit(tkmethod)));
  2645. write_rtti_name;
  2646. { write kind of method (can only be function or procedure)}
  2647. if rettype.def = pdef(voiddef) then { ### typecast shoudln't be necessary! (sg) }
  2648. methodkind := mkProcedure
  2649. else
  2650. methodkind := mkFunction;
  2651. rttilist^.concat(new(pai_const,init_8bit(methodkind)));
  2652. { get # of parameters }
  2653. rttilist^.concat(new(pai_const,init_8bit(para^.count)));
  2654. { write parameter info. The parameters must be written in reverse order
  2655. if this method uses right to left parameter pushing! }
  2656. if (pocall_leftright in proccalloptions) then
  2657. pdc:=pparaitem(para^.last)
  2658. else
  2659. pdc:=pparaitem(para^.first);
  2660. while assigned(pdc) do
  2661. begin
  2662. case pdc^.paratyp of
  2663. vs_value: paraspec := 0;
  2664. vs_const: paraspec := pfConst;
  2665. vs_var : paraspec := pfVar;
  2666. end;
  2667. { write flags for current parameter }
  2668. rttilist^.concat(new(pai_const,init_8bit(paraspec)));
  2669. { write name of current parameter ### how can I get this??? (sg)}
  2670. rttilist^.concat(new(pai_const,init_8bit(0)));
  2671. { write name of type of current parameter }
  2672. pdc^.paratype.def^.write_rtti_name;
  2673. if (pocall_leftright in proccalloptions) then
  2674. pdc:=pparaitem(pdc^.previous)
  2675. else
  2676. pdc:=pparaitem(pdc^.next);
  2677. end;
  2678. { write name of result type }
  2679. rettype.def^.write_rtti_name;
  2680. end;
  2681. end;
  2682. procedure tprocvardef.write_child_rtti_data;
  2683. begin
  2684. {!!!!!!!!}
  2685. end;
  2686. function tprocvardef.is_publishable : boolean;
  2687. begin
  2688. is_publishable:=(po_methodpointer in procoptions);
  2689. end;
  2690. function tprocvardef.gettypename : string;
  2691. begin
  2692. if assigned(rettype.def) and
  2693. (rettype.def<>pdef(voiddef)) then
  2694. gettypename:='<procedure variable type of function'+demangled_paras+
  2695. ':'+rettype.def^.gettypename+';'+proccalloption2str+'>'
  2696. else
  2697. gettypename:='<procedure variable type of procedure'+demangled_paras+
  2698. ';'+proccalloption2str+'>';
  2699. end;
  2700. {***************************************************************************
  2701. TOBJECTDEF
  2702. ***************************************************************************}
  2703. {$ifdef GDB}
  2704. const
  2705. vtabletype : word = 0;
  2706. vtableassigned : boolean = false;
  2707. {$endif GDB}
  2708. constructor tobjectdef.init(const n : string;c : pobjectdef);
  2709. begin
  2710. tdef.init;
  2711. deftype:=objectdef;
  2712. objectoptions:=[];
  2713. childof:=nil;
  2714. symtable:=new(psymtable,init(objectsymtable));
  2715. symtable^.name := stringdup(n);
  2716. { create space for vmt !! }
  2717. vmt_offset:=0;
  2718. symtable^.datasize:=0;
  2719. symtable^.defowner:=@self;
  2720. symtable^.dataalignment:=packrecordalignment[aktpackrecords];
  2721. set_parent(c);
  2722. objname:=stringdup(n);
  2723. end;
  2724. constructor tobjectdef.load;
  2725. var
  2726. oldread_member : boolean;
  2727. begin
  2728. tdef.load;
  2729. deftype:=objectdef;
  2730. savesize:=readlong;
  2731. vmt_offset:=readlong;
  2732. objname:=stringdup(readstring);
  2733. childof:=pobjectdef(readdefref);
  2734. readsmallset(objectoptions);
  2735. has_rtti:=boolean(readbyte);
  2736. oldread_member:=read_member;
  2737. read_member:=true;
  2738. symtable:=new(psymtable,loadas(objectsymtable));
  2739. read_member:=oldread_member;
  2740. symtable^.defowner:=@self;
  2741. symtable^.name := stringdup(objname^);
  2742. { handles the predefined class tobject }
  2743. { the last TOBJECT which is loaded gets }
  2744. { it ! }
  2745. if (childof=nil) and
  2746. is_class and
  2747. (objname^='TOBJECT') then
  2748. class_tobject:=@self;
  2749. end;
  2750. destructor tobjectdef.done;
  2751. begin
  2752. if assigned(symtable) then
  2753. dispose(symtable,done);
  2754. if (oo_is_forward in objectoptions) then
  2755. Message1(sym_e_class_forward_not_resolved,objname^);
  2756. stringdispose(objname);
  2757. tdef.done;
  2758. end;
  2759. procedure tobjectdef.write;
  2760. var
  2761. oldread_member : boolean;
  2762. begin
  2763. tdef.write;
  2764. writelong(size);
  2765. writelong(vmt_offset);
  2766. writestring(objname^);
  2767. writedefref(childof);
  2768. writesmallset(objectoptions);
  2769. writebyte(byte(has_rtti));
  2770. current_ppu^.writeentry(ibobjectdef);
  2771. oldread_member:=read_member;
  2772. read_member:=true;
  2773. symtable^.writeas;
  2774. read_member:=oldread_member;
  2775. end;
  2776. procedure tobjectdef.deref;
  2777. var
  2778. oldrecsyms : psymtable;
  2779. begin
  2780. inherited deref;
  2781. resolvedef(pdef(childof));
  2782. oldrecsyms:=aktrecordsymtable;
  2783. aktrecordsymtable:=symtable;
  2784. symtable^.deref;
  2785. aktrecordsymtable:=oldrecsyms;
  2786. end;
  2787. procedure tobjectdef.set_parent( c : pobjectdef);
  2788. begin
  2789. { nothing to do if the parent was not forward !}
  2790. if assigned(childof) then
  2791. exit;
  2792. childof:=c;
  2793. { some options are inherited !! }
  2794. if assigned(c) then
  2795. begin
  2796. objectoptions:=objectoptions+(c^.objectoptions*
  2797. [oo_has_virtual,oo_has_private,oo_has_protected,oo_has_constructor,oo_has_destructor]);
  2798. { add the data of the anchestor class }
  2799. inc(symtable^.datasize,c^.symtable^.datasize);
  2800. if (oo_has_vmt in objectoptions) and
  2801. (oo_has_vmt in c^.objectoptions) then
  2802. dec(symtable^.datasize,target_os.size_of_pointer);
  2803. { if parent has a vmt field then
  2804. the offset is the same for the child PM }
  2805. if (oo_has_vmt in c^.objectoptions) or is_class then
  2806. begin
  2807. vmt_offset:=c^.vmt_offset;
  2808. {$ifdef INCLUDEOK}
  2809. include(objectoptions,oo_has_vmt);
  2810. {$else}
  2811. objectoptions:=objectoptions+[oo_has_vmt];
  2812. {$endif}
  2813. end;
  2814. end;
  2815. savesize := symtable^.datasize;
  2816. end;
  2817. procedure tobjectdef.insertvmt;
  2818. begin
  2819. if (oo_has_vmt in objectoptions) then
  2820. internalerror(12345)
  2821. else
  2822. begin
  2823. { first round up to multiple of 4 }
  2824. if (symtable^.dataalignment=2) then
  2825. begin
  2826. if (symtable^.datasize and 1)<>0 then
  2827. inc(symtable^.datasize);
  2828. end
  2829. else
  2830. if (symtable^.dataalignment>=4) then
  2831. begin
  2832. if (symtable^.datasize mod 4) <> 0 then
  2833. inc(symtable^.datasize,4-(symtable^.datasize mod 4));
  2834. end;
  2835. vmt_offset:=symtable^.datasize;
  2836. inc(symtable^.datasize,target_os.size_of_pointer);
  2837. {$ifdef INCLUDEOK}
  2838. include(objectoptions,oo_has_vmt);
  2839. {$else}
  2840. objectoptions:=objectoptions+[oo_has_vmt];
  2841. {$endif}
  2842. end;
  2843. end;
  2844. procedure tobjectdef.check_forwards;
  2845. begin
  2846. symtable^.check_forwards;
  2847. if (oo_is_forward in objectoptions) then
  2848. begin
  2849. { ok, in future, the forward can be resolved }
  2850. Message1(sym_e_class_forward_not_resolved,objname^);
  2851. {$ifdef INCLUDEOK}
  2852. exclude(objectoptions,oo_is_forward);
  2853. {$else}
  2854. objectoptions:=objectoptions-[oo_is_forward];
  2855. {$endif}
  2856. end;
  2857. end;
  2858. { true, if self inherits from d (or if they are equal) }
  2859. function tobjectdef.is_related(d : pobjectdef) : boolean;
  2860. var
  2861. hp : pobjectdef;
  2862. begin
  2863. hp:=@self;
  2864. while assigned(hp) do
  2865. begin
  2866. if hp=d then
  2867. begin
  2868. is_related:=true;
  2869. exit;
  2870. end;
  2871. hp:=hp^.childof;
  2872. end;
  2873. is_related:=false;
  2874. end;
  2875. var
  2876. sd : pprocdef;
  2877. procedure _searchdestructor(sym : pnamedindexobject);{$ifndef fpc}far;{$endif}
  2878. var
  2879. p : pprocdef;
  2880. begin
  2881. { if we found already a destructor, then we exit }
  2882. if assigned(sd) then
  2883. exit;
  2884. if psym(sym)^.typ=procsym then
  2885. begin
  2886. p:=pprocsym(sym)^.definition;
  2887. while assigned(p) do
  2888. begin
  2889. if p^.proctypeoption=potype_destructor then
  2890. begin
  2891. sd:=p;
  2892. exit;
  2893. end;
  2894. p:=p^.nextoverloaded;
  2895. end;
  2896. end;
  2897. end;
  2898. function tobjectdef.searchdestructor : pprocdef;
  2899. var
  2900. o : pobjectdef;
  2901. begin
  2902. searchdestructor:=nil;
  2903. o:=@self;
  2904. sd:=nil;
  2905. while assigned(o) do
  2906. begin
  2907. symtable^.foreach({$ifndef TP}@{$endif}_searchdestructor);
  2908. if assigned(sd) then
  2909. begin
  2910. searchdestructor:=sd;
  2911. exit;
  2912. end;
  2913. o:=o^.childof;
  2914. end;
  2915. end;
  2916. function tobjectdef.size : longint;
  2917. begin
  2918. if (oo_is_class in objectoptions) then
  2919. size:=target_os.size_of_pointer
  2920. else
  2921. size:=symtable^.datasize;
  2922. end;
  2923. function tobjectdef.alignment:longint;
  2924. begin
  2925. alignment:=symtable^.dataalignment;
  2926. end;
  2927. function tobjectdef.vmtmethodoffset(index:longint):longint;
  2928. begin
  2929. { for offset of methods for classes, see rtl/inc/objpash.inc }
  2930. if is_class then
  2931. vmtmethodoffset:=(index+12)*target_os.size_of_pointer
  2932. else
  2933. {$ifdef WITHDMT}
  2934. vmtmethodoffset:=(index+4)*target_os.size_of_pointer;
  2935. {$else WITHDMT}
  2936. vmtmethodoffset:=(index+3)*target_os.size_of_pointer;
  2937. {$endif WITHDMT}
  2938. end;
  2939. function tobjectdef.vmt_mangledname : string;
  2940. {DM: I get a nil pointer on the owner name. I don't know if this
  2941. mayhappen, and I have therefore fixed the problem by doing nil pointer
  2942. checks.}
  2943. var
  2944. s1,s2:string;
  2945. begin
  2946. if not(oo_has_vmt in objectoptions) then
  2947. Message1(parser_object_has_no_vmt,objname^);
  2948. if owner^.name=nil then
  2949. s1:=''
  2950. else
  2951. s1:=owner^.name^;
  2952. if objname=nil then
  2953. s2:=''
  2954. else
  2955. s2:=objname^;
  2956. vmt_mangledname:='VMT_'+s1+'$_'+s2;
  2957. end;
  2958. function tobjectdef.rtti_name : string;
  2959. var
  2960. s1,s2:string;
  2961. begin
  2962. if owner^.name=nil then
  2963. s1:=''
  2964. else
  2965. s1:=owner^.name^;
  2966. if objname=nil then
  2967. s2:=''
  2968. else
  2969. s2:=objname^;
  2970. rtti_name:='RTTI_'+s1+'$_'+s2;
  2971. end;
  2972. function tobjectdef.is_class : boolean;
  2973. begin
  2974. is_class:=(oo_is_class in objectoptions);
  2975. end;
  2976. {$ifdef GDB}
  2977. procedure addprocname(p :pnamedindexobject);
  2978. var virtualind,argnames : string;
  2979. news, newrec : pchar;
  2980. pd,ipd : pprocdef;
  2981. lindex : longint;
  2982. para : pparaitem;
  2983. arglength : byte;
  2984. sp : char;
  2985. begin
  2986. If psym(p)^.typ = procsym then
  2987. begin
  2988. pd := pprocsym(p)^.definition;
  2989. { this will be used for full implementation of object stabs
  2990. not yet done }
  2991. ipd := pd;
  2992. while assigned(ipd^.nextoverloaded) do ipd := ipd^.nextoverloaded;
  2993. if (po_virtualmethod in pd^.procoptions) then
  2994. begin
  2995. lindex := pd^.extnumber;
  2996. {doesnt seem to be necessary
  2997. lindex := lindex or $80000000;}
  2998. virtualind := '*'+tostr(lindex)+';'+ipd^._class^.numberstring+';'
  2999. end else virtualind := '.';
  3000. { used by gdbpas to recognize constructor and destructors }
  3001. if (pd^.proctypeoption=potype_constructor) then
  3002. argnames:='__ct__'
  3003. else if (pd^.proctypeoption=potype_destructor) then
  3004. argnames:='__dt__'
  3005. else
  3006. argnames := '';
  3007. { arguments are not listed here }
  3008. {we don't need another definition}
  3009. para := pparaitem(pd^.para^.first);
  3010. while assigned(para) do
  3011. begin
  3012. if para^.paratype.def^.deftype = formaldef then
  3013. begin
  3014. if para^.paratyp=vs_var then
  3015. argnames := argnames+'3var'
  3016. else if para^.paratyp=vs_const then
  3017. argnames:=argnames+'5const';
  3018. end
  3019. else
  3020. begin
  3021. { if the arg definition is like (v: ^byte;..
  3022. there is no sym attached to data !!! }
  3023. if assigned(para^.paratype.def^.typesym) then
  3024. begin
  3025. arglength := length(para^.paratype.def^.typesym^.name);
  3026. argnames := argnames + tostr(arglength)+para^.paratype.def^.typesym^.name;
  3027. end
  3028. else
  3029. begin
  3030. argnames:=argnames+'11unnamedtype';
  3031. end;
  3032. end;
  3033. para := pparaitem(para^.next);
  3034. end;
  3035. ipd^.is_def_stab_written := true;
  3036. { here 2A must be changed for private and protected }
  3037. { 0 is private 1 protected and 2 public }
  3038. if (sp_private in psym(p)^.symoptions) then sp:='0'
  3039. else if (sp_protected in psym(p)^.symoptions) then sp:='1'
  3040. else sp:='2';
  3041. newrec := strpnew(p^.name+'::'+ipd^.numberstring
  3042. +'=##'+pd^.rettype.def^.numberstring+';:'+argnames+';'+sp+'A'
  3043. +virtualind+';');
  3044. { get spare place for a string at the end }
  3045. if strlen(StabRecString) + strlen(newrec) >= StabRecSize-256 then
  3046. begin
  3047. getmem(news,stabrecsize+memsizeinc);
  3048. strcopy(news,stabrecstring);
  3049. freemem(stabrecstring,stabrecsize);
  3050. stabrecsize:=stabrecsize+memsizeinc;
  3051. stabrecstring:=news;
  3052. end;
  3053. strcat(StabRecstring,newrec);
  3054. {freemem(newrec,memsizeinc); }
  3055. strdispose(newrec);
  3056. {This should be used for case !!}
  3057. RecOffset := RecOffset + pd^.size;
  3058. end;
  3059. end;
  3060. function tobjectdef.stabstring : pchar;
  3061. var anc : pobjectdef;
  3062. oldrec : pchar;
  3063. oldrecsize : longint;
  3064. str_end : string;
  3065. begin
  3066. oldrec := stabrecstring;
  3067. oldrecsize:=stabrecsize;
  3068. stabrecsize:=memsizeinc;
  3069. GetMem(stabrecstring,stabrecsize);
  3070. strpcopy(stabRecString,'s'+tostr(symtable^.datasize));
  3071. if assigned(childof) then
  3072. {only one ancestor not virtual, public, at base offset 0 }
  3073. { !1 , 0 2 0 , }
  3074. strpcopy(strend(stabrecstring),'!1,020,'+childof^.numberstring+';');
  3075. {virtual table to implement yet}
  3076. RecOffset := 0;
  3077. symtable^.foreach({$ifndef TP}@{$endif}addname);
  3078. if (oo_has_vmt in objectoptions) then
  3079. if not assigned(childof) or not(oo_has_vmt in childof^.objectoptions) then
  3080. begin
  3081. strpcopy(strend(stabrecstring),'$vf'+numberstring+':'+typeglobalnumber('vtblarray')
  3082. +','+tostr(vmt_offset*8)+';');
  3083. end;
  3084. symtable^.foreach({$ifndef TP}@{$endif}addprocname);
  3085. if (oo_has_vmt in objectoptions) then
  3086. begin
  3087. anc := @self;
  3088. while assigned(anc^.childof) and (oo_has_vmt in anc^.childof^.objectoptions) do
  3089. anc := anc^.childof;
  3090. str_end:=';~%'+anc^.numberstring+';';
  3091. end
  3092. else
  3093. str_end:=';';
  3094. strpcopy(strend(stabrecstring),str_end);
  3095. stabstring := strnew(StabRecString);
  3096. freemem(stabrecstring,stabrecsize);
  3097. stabrecstring := oldrec;
  3098. stabrecsize:=oldrecsize;
  3099. end;
  3100. {$endif GDB}
  3101. procedure tobjectdef.write_child_init_data;
  3102. begin
  3103. symtable^.foreach({$ifndef TP}@{$endif}generate_child_inittable);
  3104. end;
  3105. procedure tobjectdef.write_init_data;
  3106. begin
  3107. if is_class then
  3108. rttilist^.concat(new(pai_const,init_8bit(tkclass)))
  3109. else
  3110. rttilist^.concat(new(pai_const,init_8bit(tkobject)));
  3111. { generate the name }
  3112. rttilist^.concat(new(pai_const,init_8bit(length(objname^))));
  3113. rttilist^.concat(new(pai_string,init(objname^)));
  3114. rttilist^.concat(new(pai_const,init_32bit(size)));
  3115. count:=0;
  3116. symtable^.foreach({$ifndef TP}@{$endif}count_inittable_fields);
  3117. rttilist^.concat(new(pai_const,init_32bit(count)));
  3118. symtable^.foreach({$ifndef TP}@{$endif}write_field_inittable);
  3119. end;
  3120. function tobjectdef.needs_inittable : boolean;
  3121. var
  3122. oldb : boolean;
  3123. begin
  3124. if is_class then
  3125. needs_inittable:=false
  3126. else
  3127. begin
  3128. { there are recursive calls to needs_inittable possible, }
  3129. { so we have to change to old value how else should }
  3130. { we do that ? check_rec_rtti can't be a nested }
  3131. { procedure of needs_rtti ! }
  3132. oldb:=binittable;
  3133. binittable:=false;
  3134. symtable^.foreach({$ifndef TP}@{$endif}check_rec_inittable);
  3135. needs_inittable:=binittable;
  3136. binittable:=oldb;
  3137. end;
  3138. end;
  3139. procedure count_published_properties(sym:pnamedindexobject);
  3140. {$ifndef fpc}far;{$endif}
  3141. begin
  3142. if needs_prop_entry(psym(sym)) then
  3143. inc(count);
  3144. end;
  3145. procedure write_property_info(sym : pnamedindexobject);{$ifndef fpc}far;{$endif}
  3146. var
  3147. proctypesinfo : byte;
  3148. procedure writeproc(proc : psymlist; shiftvalue : byte);
  3149. var
  3150. typvalue : byte;
  3151. hp : psymlistitem;
  3152. address : longint;
  3153. begin
  3154. if not(assigned(proc) and assigned(proc^.firstsym)) then
  3155. begin
  3156. rttilist^.concat(new(pai_const,init_32bit(1)));
  3157. typvalue:=3;
  3158. end
  3159. else if proc^.firstsym^.sym^.typ=varsym then
  3160. begin
  3161. address:=0;
  3162. hp:=proc^.firstsym;
  3163. while assigned(hp) do
  3164. begin
  3165. inc(address,pvarsym(hp^.sym)^.address);
  3166. hp:=hp^.next;
  3167. end;
  3168. rttilist^.concat(new(pai_const,init_32bit(address)));
  3169. typvalue:=0;
  3170. end
  3171. else
  3172. begin
  3173. if not(po_virtualmethod in pprocdef(proc^.def)^.procoptions) then
  3174. begin
  3175. rttilist^.concat(new(pai_const_symbol,initname(pprocdef(proc^.def)^.mangledname)));
  3176. typvalue:=1;
  3177. end
  3178. else
  3179. begin
  3180. { virtual method, write vmt offset }
  3181. rttilist^.concat(new(pai_const,init_32bit(
  3182. pprocdef(proc^.def)^._class^.vmtmethodoffset(pprocdef(proc^.def)^.extnumber))));
  3183. typvalue:=2;
  3184. end;
  3185. end;
  3186. proctypesinfo:=proctypesinfo or (typvalue shl shiftvalue);
  3187. end;
  3188. begin
  3189. if needs_prop_entry(psym(sym)) then
  3190. case psym(sym)^.typ of
  3191. varsym:
  3192. begin
  3193. if not(pvarsym(sym)^.vartype.def^.deftype=objectdef) or
  3194. not(pobjectdef(pvarsym(sym)^.vartype.def)^.is_class) then
  3195. internalerror(1509992);
  3196. { access to implicit class property as field }
  3197. proctypesinfo:=(0 shl 0) or (0 shl 2) or (0 shl 4);
  3198. rttilist^.concat(new(pai_const_symbol,initname(pvarsym(sym)^.vartype.def^.get_rtti_label)));
  3199. rttilist^.concat(new(pai_const,init_32bit(pvarsym(sym)^.address)));
  3200. rttilist^.concat(new(pai_const,init_32bit(pvarsym(sym)^.address)));
  3201. { per default stored }
  3202. rttilist^.concat(new(pai_const,init_32bit(1)));
  3203. { index as well as ... }
  3204. rttilist^.concat(new(pai_const,init_32bit(0)));
  3205. { default value are zero }
  3206. rttilist^.concat(new(pai_const,init_32bit(0)));
  3207. rttilist^.concat(new(pai_const,init_16bit(count)));
  3208. inc(count);
  3209. rttilist^.concat(new(pai_const,init_8bit(proctypesinfo)));
  3210. rttilist^.concat(new(pai_const,init_8bit(length(pvarsym(sym)^.name))));
  3211. rttilist^.concat(new(pai_string,init(pvarsym(sym)^.name)));
  3212. end;
  3213. propertysym:
  3214. begin
  3215. if ppo_indexed in ppropertysym(sym)^.propoptions then
  3216. proctypesinfo:=$40
  3217. else
  3218. proctypesinfo:=0;
  3219. rttilist^.concat(new(pai_const_symbol,initname(ppropertysym(sym)^.proptype.def^.get_rtti_label)));
  3220. writeproc(ppropertysym(sym)^.readaccess,0);
  3221. writeproc(ppropertysym(sym)^.writeaccess,2);
  3222. { isn't it stored ? }
  3223. if not(ppo_stored in ppropertysym(sym)^.propoptions) then
  3224. begin
  3225. rttilist^.concat(new(pai_const,init_32bit(0)));
  3226. proctypesinfo:=proctypesinfo or (3 shl 4);
  3227. end
  3228. else
  3229. writeproc(ppropertysym(sym)^.storedaccess,4);
  3230. rttilist^.concat(new(pai_const,init_32bit(ppropertysym(sym)^.index)));
  3231. rttilist^.concat(new(pai_const,init_32bit(ppropertysym(sym)^.default)));
  3232. rttilist^.concat(new(pai_const,init_16bit(count)));
  3233. inc(count);
  3234. rttilist^.concat(new(pai_const,init_8bit(proctypesinfo)));
  3235. rttilist^.concat(new(pai_const,init_8bit(length(ppropertysym(sym)^.name))));
  3236. rttilist^.concat(new(pai_string,init(ppropertysym(sym)^.name)));
  3237. end;
  3238. else internalerror(1509992);
  3239. end;
  3240. end;
  3241. procedure generate_published_child_rtti(sym : pnamedindexobject);{$ifndef fpc}far;{$endif}
  3242. begin
  3243. if needs_prop_entry(psym(sym)) then
  3244. case psym(sym)^.typ of
  3245. varsym:
  3246. pvarsym(sym)^.vartype.def^.get_rtti_label;
  3247. propertysym:
  3248. ppropertysym(sym)^.proptype.def^.get_rtti_label;
  3249. else
  3250. internalerror(1509991);
  3251. end;
  3252. end;
  3253. procedure tobjectdef.write_child_rtti_data;
  3254. begin
  3255. symtable^.foreach({$ifndef TP}@{$endif}generate_published_child_rtti);
  3256. end;
  3257. procedure tobjectdef.generate_rtti;
  3258. begin
  3259. if not has_rtti then
  3260. begin
  3261. has_rtti:=true;
  3262. getdatalabel(rtti_label);
  3263. write_child_rtti_data;
  3264. rttilist^.concat(new(pai_symbol,initname_global(rtti_name,0)));
  3265. rttilist^.concat(new(pai_label,init(rtti_label)));
  3266. write_rtti_data;
  3267. rttilist^.concat(new(pai_symbol_end,initname(rtti_name)));
  3268. end;
  3269. end;
  3270. function tobjectdef.next_free_name_index : longint;
  3271. var
  3272. i : longint;
  3273. begin
  3274. if assigned(childof) and (oo_can_have_published in childof^.objectoptions) then
  3275. i:=childof^.next_free_name_index
  3276. else
  3277. i:=0;
  3278. count:=0;
  3279. symtable^.foreach({$ifndef TP}@{$endif}count_published_properties);
  3280. next_free_name_index:=i+count;
  3281. end;
  3282. procedure tobjectdef.write_rtti_data;
  3283. begin
  3284. if is_class then
  3285. rttilist^.concat(new(pai_const,init_8bit(tkclass)))
  3286. else
  3287. rttilist^.concat(new(pai_const,init_8bit(tkobject)));
  3288. { generate the name }
  3289. rttilist^.concat(new(pai_const,init_8bit(length(objname^))));
  3290. rttilist^.concat(new(pai_string,init(objname^)));
  3291. { write class type }
  3292. rttilist^.concat(new(pai_const_symbol,initname(vmt_mangledname)));
  3293. { write owner typeinfo }
  3294. if assigned(childof) and (oo_can_have_published in childof^.objectoptions) then
  3295. rttilist^.concat(new(pai_const_symbol,initname(childof^.get_rtti_label)))
  3296. else
  3297. rttilist^.concat(new(pai_const,init_32bit(0)));
  3298. { count total number of properties }
  3299. if assigned(childof) and (oo_can_have_published in childof^.objectoptions) then
  3300. count:=childof^.next_free_name_index
  3301. else
  3302. count:=0;
  3303. { write it }
  3304. symtable^.foreach({$ifndef TP}@{$endif}count_published_properties);
  3305. rttilist^.concat(new(pai_const,init_16bit(count)));
  3306. { write unit name }
  3307. if assigned(owner^.name) then
  3308. begin
  3309. rttilist^.concat(new(pai_const,init_8bit(length(owner^.name^))));
  3310. rttilist^.concat(new(pai_string,init(owner^.name^)));
  3311. end
  3312. else
  3313. rttilist^.concat(new(pai_const,init_8bit(0)));
  3314. { write published properties count }
  3315. count:=0;
  3316. symtable^.foreach({$ifndef TP}@{$endif}count_published_properties);
  3317. rttilist^.concat(new(pai_const,init_16bit(count)));
  3318. { count is used to write nameindex }
  3319. { but we need an offset of the owner }
  3320. { to give each property an own slot }
  3321. if assigned(childof) and (oo_can_have_published in childof^.objectoptions) then
  3322. count:=childof^.next_free_name_index
  3323. else
  3324. count:=0;
  3325. symtable^.foreach({$ifndef TP}@{$endif}write_property_info);
  3326. end;
  3327. function tobjectdef.is_publishable : boolean;
  3328. begin
  3329. is_publishable:=is_class;
  3330. end;
  3331. function tobjectdef.get_rtti_label : string;
  3332. begin
  3333. generate_rtti;
  3334. get_rtti_label:=rtti_name;
  3335. end;
  3336. {****************************************************************************
  3337. TFORWARDDEF
  3338. ****************************************************************************}
  3339. constructor tforwarddef.init(const s:string;const pos : tfileposinfo);
  3340. var
  3341. oldregisterdef : boolean;
  3342. begin
  3343. { never register the forwarddefs, they are disposed at the
  3344. end of the type declaration block }
  3345. oldregisterdef:=registerdef;
  3346. registerdef:=false;
  3347. inherited init;
  3348. registerdef:=oldregisterdef;
  3349. deftype:=forwarddef;
  3350. tosymname:=s;
  3351. forwardpos:=pos;
  3352. end;
  3353. function tforwarddef.gettypename:string;
  3354. begin
  3355. gettypename:='unresolved forward to '+tosymname;
  3356. end;
  3357. {****************************************************************************
  3358. TERRORDEF
  3359. ****************************************************************************}
  3360. constructor terrordef.init;
  3361. begin
  3362. inherited init;
  3363. deftype:=errordef;
  3364. end;
  3365. {$ifdef GDB}
  3366. function terrordef.stabstring : pchar;
  3367. begin
  3368. stabstring:=strpnew('error'+numberstring);
  3369. end;
  3370. {$endif GDB}
  3371. function terrordef.gettypename:string;
  3372. begin
  3373. gettypename:='<erroneous type>';
  3374. end;
  3375. {
  3376. $Log$
  3377. Revision 1.193 2000-02-05 14:33:32 florian
  3378. * fixed init table generation for classes and arrays
  3379. Revision 1.192 2000/02/04 20:00:22 florian
  3380. * an exception in a construcor calls now the destructor (this applies only
  3381. to classes)
  3382. Revision 1.191 2000/01/30 23:29:06 peter
  3383. * fixed dup rtti writing for classes
  3384. Revision 1.190 2000/01/28 23:17:53 florian
  3385. * virtual XXXX; support for objects, only if -dWITHDMT is defined
  3386. Revision 1.189 2000/01/26 12:02:29 peter
  3387. * abstractprocdef.para_size needs alignment parameter
  3388. * secondcallparan gets para_alignment size instead of dword_align
  3389. Revision 1.188 2000/01/23 16:35:31 peter
  3390. * localbrowser loading of absolute fixed. It needed a symtablestack
  3391. which was not setup correctly
  3392. Revision 1.187 2000/01/09 23:16:06 peter
  3393. * added st_default stringtype
  3394. * genstringconstnode extended with stringtype parameter using st_default
  3395. will do the old behaviour
  3396. Revision 1.186 2000/01/07 01:14:39 peter
  3397. * updated copyright to 2000
  3398. Revision 1.185 2000/01/03 19:26:03 peter
  3399. * fixed resolving of ttypesym which are reference from object/record
  3400. fields.
  3401. Revision 1.184 1999/12/31 14:24:34 peter
  3402. * fixed rtti generation for classes with no published section
  3403. Revision 1.183 1999/12/23 12:19:42 peter
  3404. * check_rec_inittable fix from sg
  3405. Revision 1.182 1999/12/19 17:00:27 peter
  3406. * has_rtti should be saved in the ppu for objects
  3407. Revision 1.181 1999/12/18 14:55:21 florian
  3408. * very basic widestring support
  3409. Revision 1.180 1999/12/06 18:21:03 peter
  3410. * support !ENVVAR for long commandlines
  3411. * win32/go32v2 write short pathnames to link.res so c:\Program Files\ is
  3412. finally supported as installdir.
  3413. Revision 1.179 1999/12/01 12:42:33 peter
  3414. * fixed bug 698
  3415. * removed some notes about unused vars
  3416. Revision 1.178 1999/12/01 10:26:38 pierre
  3417. * restore the correct way for stabs of forward defs
  3418. Revision 1.177 1999/11/30 10:40:54 peter
  3419. + ttype, tsymlist
  3420. Revision 1.176 1999/11/09 23:35:49 pierre
  3421. + better reference pos for forward defs
  3422. Revision 1.175 1999/11/07 23:57:36 pierre
  3423. + higher level browser
  3424. Revision 1.174 1999/11/06 14:34:26 peter
  3425. * truncated log to 20 revs
  3426. Revision 1.173 1999/11/05 17:18:02 pierre
  3427. * local browsing works at first level
  3428. ie for function defined in interface or implementation
  3429. not yet for functions inside other functions
  3430. Revision 1.172 1999/10/26 12:30:45 peter
  3431. * const parameter is now checked
  3432. * better and generic check if a node can be used for assigning
  3433. * export fixes
  3434. * procvar equal works now (it never had worked at least from 0.99.8)
  3435. * defcoll changed to linkedlist with pparaitem so it can easily be
  3436. walked both directions
  3437. Revision 1.171 1999/10/06 17:39:15 peter
  3438. * fixed stabs writting for forward types
  3439. Revision 1.170 1999/10/04 13:46:04 michael
  3440. * patch from peter for classes
  3441. Revision 1.169 1999/10/03 19:41:38 peter
  3442. * inittable for record fixed (it was only checking for classes)
  3443. Revision 1.168 1999/10/01 10:05:44 peter
  3444. + procedure directive support in const declarations, fixes bug 232
  3445. Revision 1.167 1999/10/01 08:02:48 peter
  3446. * forward type declaration rewritten
  3447. Revision 1.166 1999/09/26 21:30:21 peter
  3448. + constant pointer support which can happend with typecasting like
  3449. const p=pointer(1)
  3450. * better procvar parsing in typed consts
  3451. Revision 1.165 1999/09/20 16:39:02 peter
  3452. * cs_create_smart instead of cs_smartlink
  3453. * -CX is create smartlink
  3454. * -CD is create dynamic, but does nothing atm.
  3455. Revision 1.164 1999/09/15 22:09:26 florian
  3456. + rtti is now automatically generated for published classes, i.e.
  3457. they are handled like an implicit property
  3458. Revision 1.163 1999/09/15 20:35:44 florian
  3459. * small fix to operator overloading when in MMX mode
  3460. + the compiler uses now fldz and fld1 if possible
  3461. + some fixes to floating point registers
  3462. + some math. functions (arctan, ln, sin, cos, sqrt, sqr, pi) are now inlined
  3463. * .... ???
  3464. Revision 1.162 1999/09/12 08:48:09 florian
  3465. * bugs 593 and 607 fixed
  3466. * some other potential bugs with array constructors fixed
  3467. * for classes compiled in $M+ and it's childs, the default access method
  3468. is now published
  3469. * fixed copyright message (it is now 1998-2000)
  3470. Revision 1.161 1999/09/10 18:48:09 florian
  3471. * some bug fixes (e.g. must_be_valid and procinfo.funcret_is_valid)
  3472. * most things for stored properties fixed
  3473. Revision 1.160 1999/09/02 17:07:40 florian
  3474. * problems with -Or fixed: tdef.isfpuregable was wrong!
  3475. Revision 1.159 1999/08/27 10:52:19 pierre
  3476. + simplify_ppu code added :
  3477. sets all registers used at PPU writing
  3478. * tprocdef mangledname writing is CRC relevant
  3479. Revision 1.158 1999/08/27 10:24:34 michael
  3480. + Inittables should not contain fields which are classes
  3481. Revision 1.157 1999/08/26 21:13:58 peter
  3482. * array elementsize of 0 doesn't crash anymore
  3483. Revision 1.156 1999/08/17 13:58:56 michael
  3484. RTTI writing patch
  3485. Revision 1.155 1999/08/16 16:26:04 pierre
  3486. * error in stabs for tclassrefdef corrected
  3487. Revision 1.154 1999/08/14 00:38:58 peter
  3488. * hack to support property with record fields
  3489. }