symdef.inc 119 KB

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