symdef.inc 117 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080
  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,s64bitint:
  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. s64bitint : 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. stabstring := strpnew('S'+setof^.numberstring);
  1342. end;
  1343. procedure tsetdef.concatstabto(asmlist : paasmoutput);
  1344. begin
  1345. if ( not assigned(sym) or sym^.isusedinstab or (cs_gdb_dbx in aktglobalswitches)) and
  1346. not is_def_stab_written then
  1347. begin
  1348. if assigned(setof) then
  1349. forcestabto(asmlist,setof);
  1350. inherited concatstabto(asmlist);
  1351. end;
  1352. end;
  1353. {$endif GDB}
  1354. procedure tsetdef.deref;
  1355. begin
  1356. resolvedef(setof);
  1357. end;
  1358. procedure tsetdef.write_rtti_data;
  1359. begin
  1360. rttilist^.concat(new(pai_const,init_8bit(tkSet)));
  1361. write_rtti_name;
  1362. rttilist^.concat(new(pai_const,init_8bit(otULong)));
  1363. rttilist^.concat(new(pai_const_symbol,initname(setof^.get_rtti_label)));
  1364. end;
  1365. procedure tsetdef.write_child_rtti_data;
  1366. begin
  1367. setof^.get_rtti_label;
  1368. end;
  1369. function tsetdef.is_publishable : boolean;
  1370. begin
  1371. is_publishable:=settype=smallset;
  1372. end;
  1373. function tsetdef.gettypename : string;
  1374. begin
  1375. gettypename:='Set Of '+setof^.typename;
  1376. end;
  1377. {***************************************************************************
  1378. TFORMALDEF
  1379. ***************************************************************************}
  1380. constructor tformaldef.init;
  1381. var
  1382. stregdef : boolean;
  1383. begin
  1384. stregdef:=registerdef;
  1385. registerdef:=false;
  1386. inherited init;
  1387. deftype:=formaldef;
  1388. registerdef:=stregdef;
  1389. { formaldef must be registered at unit level !! }
  1390. if registerdef and assigned(current_module) then
  1391. if assigned(current_module^.localsymtable) then
  1392. psymtable(current_module^.localsymtable)^.registerdef(@self)
  1393. else if assigned(current_module^.globalsymtable) then
  1394. psymtable(current_module^.globalsymtable)^.registerdef(@self);
  1395. savesize:=target_os.size_of_pointer;
  1396. end;
  1397. constructor tformaldef.load;
  1398. begin
  1399. inherited load;
  1400. deftype:=formaldef;
  1401. savesize:=target_os.size_of_pointer;
  1402. end;
  1403. procedure tformaldef.write;
  1404. begin
  1405. inherited write;
  1406. current_ppu^.writeentry(ibformaldef);
  1407. end;
  1408. {$ifdef GDB}
  1409. function tformaldef.stabstring : pchar;
  1410. begin
  1411. stabstring := strpnew('formal'+numberstring+';');
  1412. end;
  1413. procedure tformaldef.concatstabto(asmlist : paasmoutput);
  1414. begin
  1415. { formaldef can't be stab'ed !}
  1416. end;
  1417. {$endif GDB}
  1418. function tformaldef.gettypename : string;
  1419. begin
  1420. gettypename:='Var';
  1421. end;
  1422. {***************************************************************************
  1423. TARRAYDEF
  1424. ***************************************************************************}
  1425. constructor tarraydef.init(l,h : longint;rd : pdef);
  1426. begin
  1427. inherited init;
  1428. deftype:=arraydef;
  1429. lowrange:=l;
  1430. highrange:=h;
  1431. rangedef:=rd;
  1432. definition:=nil;
  1433. IsVariant:=false;
  1434. IsConstructor:=false;
  1435. IsArrayOfConst:=false;
  1436. rangenr:=0;
  1437. end;
  1438. constructor tarraydef.load;
  1439. begin
  1440. inherited load;
  1441. deftype:=arraydef;
  1442. { the addresses are calculated later }
  1443. definition:=readdefref;
  1444. rangedef:=readdefref;
  1445. lowrange:=readlong;
  1446. highrange:=readlong;
  1447. IsArrayOfConst:=boolean(readbyte);
  1448. IsVariant:=false;
  1449. IsConstructor:=false;
  1450. rangenr:=0;
  1451. end;
  1452. function tarraydef.getrangecheckstring : string;
  1453. begin
  1454. if (cs_smartlink in aktmoduleswitches) then
  1455. getrangecheckstring:='R_'+current_module^.modulename^+tostr(rangenr)
  1456. else
  1457. getrangecheckstring:='R_'+tostr(rangenr);
  1458. end;
  1459. procedure tarraydef.genrangecheck;
  1460. begin
  1461. if rangenr=0 then
  1462. begin
  1463. { generates the data for range checking }
  1464. getlabelnr(rangenr);
  1465. if (cs_smartlink in aktmoduleswitches) then
  1466. datasegment^.concat(new(pai_symbol,initname_global(getrangecheckstring,8)))
  1467. else
  1468. datasegment^.concat(new(pai_symbol,initname(getrangecheckstring,8)));
  1469. datasegment^.concat(new(pai_const,init_32bit(lowrange)));
  1470. datasegment^.concat(new(pai_const,init_32bit(highrange)));
  1471. end;
  1472. end;
  1473. procedure tarraydef.deref;
  1474. begin
  1475. resolvedef(definition);
  1476. resolvedef(rangedef);
  1477. end;
  1478. procedure tarraydef.write;
  1479. begin
  1480. inherited write;
  1481. writedefref(definition);
  1482. writedefref(rangedef);
  1483. writelong(lowrange);
  1484. writelong(highrange);
  1485. writebyte(byte(IsArrayOfConst));
  1486. current_ppu^.writeentry(ibarraydef);
  1487. end;
  1488. {$ifdef GDB}
  1489. function tarraydef.stabstring : pchar;
  1490. begin
  1491. stabstring := strpnew('ar'+rangedef^.numberstring+';'
  1492. +tostr(lowrange)+';'+tostr(highrange)+';'+definition^.numberstring);
  1493. end;
  1494. procedure tarraydef.concatstabto(asmlist : paasmoutput);
  1495. begin
  1496. if (not assigned(sym) or sym^.isusedinstab or (cs_gdb_dbx in aktglobalswitches))
  1497. and not is_def_stab_written then
  1498. begin
  1499. {when array are inserted they have no definition yet !!}
  1500. if assigned(definition) then
  1501. inherited concatstabto(asmlist);
  1502. end;
  1503. end;
  1504. {$endif GDB}
  1505. function tarraydef.elesize : longint;
  1506. begin
  1507. elesize:=definition^.size;
  1508. end;
  1509. function tarraydef.size : longint;
  1510. begin
  1511. { dirty hack to overcome an overflow (PFV) }
  1512. if highrange=$7fffffff then
  1513. size:=$7fffffff
  1514. else
  1515. size:=(highrange-lowrange+1)*elesize;
  1516. end;
  1517. function tarraydef.alignment : longint;
  1518. begin
  1519. { alignment is the size of the elements }
  1520. alignment:=definition^.size;
  1521. end;
  1522. function tarraydef.needs_inittable : boolean;
  1523. begin
  1524. needs_inittable:=definition^.needs_inittable;
  1525. end;
  1526. procedure tarraydef.write_child_rtti_data;
  1527. begin
  1528. definition^.get_rtti_label;
  1529. end;
  1530. procedure tarraydef.write_rtti_data;
  1531. begin
  1532. rttilist^.concat(new(pai_const,init_8bit(13)));
  1533. write_rtti_name;
  1534. { size of elements }
  1535. rttilist^.concat(new(pai_const,init_32bit(definition^.size)));
  1536. { count of elements }
  1537. rttilist^.concat(new(pai_const,init_32bit(highrange-lowrange+1)));
  1538. { element type }
  1539. rttilist^.concat(new(pai_const_symbol,initname(definition^.get_rtti_label)));
  1540. end;
  1541. function tarraydef.gettypename : string;
  1542. begin
  1543. if isarrayofconst or isConstructor then
  1544. gettypename:='Array Of Const'
  1545. else if is_open_array(@self) then
  1546. gettypename:='Array Of '+definition^.typename
  1547. else
  1548. begin
  1549. if rangedef^.deftype=enumdef then
  1550. gettypename:='Array['+rangedef^.typename+'] Of '+definition^.typename
  1551. else
  1552. gettypename:='Array['+tostr(lowrange)+'..'+
  1553. tostr(highrange)+'] Of '+definition^.typename
  1554. end;
  1555. end;
  1556. {***************************************************************************
  1557. TRECDEF
  1558. ***************************************************************************}
  1559. constructor trecdef.init(p : psymtable);
  1560. begin
  1561. inherited init;
  1562. deftype:=recorddef;
  1563. symtable:=p;
  1564. symtable^.defowner := @self;
  1565. symtable^.dataalignment:=packrecordalignment[aktpackrecords];
  1566. end;
  1567. constructor trecdef.load;
  1568. var
  1569. oldread_member : boolean;
  1570. begin
  1571. inherited load;
  1572. deftype:=recorddef;
  1573. savesize:=readlong;
  1574. oldread_member:=read_member;
  1575. read_member:=true;
  1576. symtable:=new(psymtable,loadas(recordsymtable));
  1577. read_member:=oldread_member;
  1578. symtable^.defowner := @self;
  1579. end;
  1580. destructor trecdef.done;
  1581. begin
  1582. if assigned(symtable) then
  1583. dispose(symtable,done);
  1584. inherited done;
  1585. end;
  1586. var
  1587. binittable : boolean;
  1588. procedure check_rec_inittable(s : pnamedindexobject);
  1589. begin
  1590. if (psym(s)^.typ=varsym) and
  1591. ((pvarsym(s)^.definition^.deftype<>objectdef) or
  1592. not(pobjectdef(pvarsym(s)^.definition)^.isclass)) then
  1593. binittable:=pvarsym(s)^.definition^.needs_inittable;
  1594. end;
  1595. function trecdef.needs_inittable : boolean;
  1596. var
  1597. oldb : boolean;
  1598. begin
  1599. { there are recursive calls to needs_rtti possible, }
  1600. { so we have to change to old value how else should }
  1601. { we do that ? check_rec_rtti can't be a nested }
  1602. { procedure of needs_rtti ! }
  1603. oldb:=binittable;
  1604. binittable:=false;
  1605. symtable^.foreach({$ifndef TP}@{$endif}check_rec_inittable);
  1606. needs_inittable:=binittable;
  1607. binittable:=oldb;
  1608. end;
  1609. procedure trecdef.deref;
  1610. var
  1611. oldrecsyms : psymtable;
  1612. begin
  1613. oldrecsyms:=aktrecordsymtable;
  1614. aktrecordsymtable:=symtable;
  1615. { now dereference the definitions }
  1616. symtable^.deref;
  1617. aktrecordsymtable:=oldrecsyms;
  1618. end;
  1619. procedure trecdef.write;
  1620. var
  1621. oldread_member : boolean;
  1622. begin
  1623. oldread_member:=read_member;
  1624. read_member:=true;
  1625. inherited write;
  1626. writelong(savesize);
  1627. current_ppu^.writeentry(ibrecorddef);
  1628. self.symtable^.writeas;
  1629. read_member:=oldread_member;
  1630. end;
  1631. function trecdef.size:longint;
  1632. begin
  1633. size:=symtable^.datasize;
  1634. end;
  1635. function trecdef.alignment:longint;
  1636. begin
  1637. alignment:=symtable^.dataalignment;
  1638. end;
  1639. {$ifdef GDB}
  1640. Const StabRecString : pchar = Nil;
  1641. StabRecSize : longint = 0;
  1642. RecOffset : Longint = 0;
  1643. procedure addname(p : pnamedindexobject);
  1644. var
  1645. news, newrec : pchar;
  1646. spec : string[2];
  1647. size : longint;
  1648. begin
  1649. { static variables from objects are like global objects }
  1650. if ((psym(p)^.properties and sp_static)<>0) then
  1651. exit;
  1652. if ((psym(p)^.properties and sp_protected)<>0) then
  1653. spec:='/1'
  1654. else if ((psym(p)^.properties and sp_private)<>0) then
  1655. spec:='/0'
  1656. else
  1657. spec:='';
  1658. If psym(p)^.typ = varsym then
  1659. begin
  1660. size:=pvarsym(p)^.definition^.size;
  1661. { open arrays made overflows !! }
  1662. if size>$fffffff then
  1663. size:=$fffffff;
  1664. newrec := strpnew(p^.name+':'+spec+pvarsym(p)^.definition^.numberstring
  1665. +','+tostr(pvarsym(p)^.address*8)+','
  1666. +tostr(size*8)+';');
  1667. if strlen(StabRecString) + strlen(newrec) >= StabRecSize-256 then
  1668. begin
  1669. getmem(news,stabrecsize+memsizeinc);
  1670. strcopy(news,stabrecstring);
  1671. freemem(stabrecstring,stabrecsize);
  1672. stabrecsize:=stabrecsize+memsizeinc;
  1673. stabrecstring:=news;
  1674. end;
  1675. strcat(StabRecstring,newrec);
  1676. strdispose(newrec);
  1677. {This should be used for case !!}
  1678. RecOffset := RecOffset + pvarsym(p)^.definition^.size;
  1679. end;
  1680. end;
  1681. function trecdef.stabstring : pchar;
  1682. Var oldrec : pchar;
  1683. oldsize : longint;
  1684. begin
  1685. oldrec := stabrecstring;
  1686. oldsize:=stabrecsize;
  1687. GetMem(stabrecstring,memsizeinc);
  1688. stabrecsize:=memsizeinc;
  1689. strpcopy(stabRecString,'s'+tostr(size));
  1690. RecOffset := 0;
  1691. symtable^.foreach({$ifndef TP}@{$endif}addname);
  1692. { FPC doesn't want to convert a char to a pchar}
  1693. { is this a bug ? }
  1694. strpcopy(strend(StabRecString),';');
  1695. stabstring := strnew(StabRecString);
  1696. Freemem(stabrecstring,stabrecsize);
  1697. stabrecstring := oldrec;
  1698. stabrecsize:=oldsize;
  1699. end;
  1700. procedure trecdef.concatstabto(asmlist : paasmoutput);
  1701. begin
  1702. if (not assigned(sym) or sym^.isusedinstab or (cs_gdb_dbx in aktglobalswitches)) and
  1703. (not is_def_stab_written) then
  1704. inherited concatstabto(asmlist);
  1705. end;
  1706. {$endif GDB}
  1707. var
  1708. count : longint;
  1709. procedure count_inittable_fields(sym : pnamedindexobject);{$ifndef fpc}far;{$endif}
  1710. begin
  1711. if (psym(sym)^.typ=varsym) and
  1712. (pvarsym(sym)^.definition^.needs_inittable) then
  1713. inc(count);
  1714. end;
  1715. procedure count_fields(sym : pnamedindexobject);{$ifndef fpc}far;{$endif}
  1716. begin
  1717. inc(count);
  1718. end;
  1719. procedure write_field_inittable(sym : pnamedindexobject);{$ifndef fpc}far;{$endif}
  1720. begin
  1721. if (psym(sym)^.typ=varsym) and
  1722. pvarsym(sym)^.definition^.needs_inittable then
  1723. begin
  1724. rttilist^.concat(new(pai_const_symbol,init(pvarsym(sym)^.definition^.get_inittable_label)));
  1725. rttilist^.concat(new(pai_const,init_32bit(pvarsym(sym)^.address)));
  1726. end;
  1727. end;
  1728. procedure write_field_rtti(sym : pnamedindexobject);{$ifndef fpc}far;{$endif}
  1729. begin
  1730. rttilist^.concat(new(pai_const_symbol,initname(pvarsym(sym)^.definition^.get_rtti_label)));
  1731. rttilist^.concat(new(pai_const,init_32bit(pvarsym(sym)^.address)));
  1732. end;
  1733. procedure generate_child_inittable(sym:pnamedindexobject);{$ifndef fpc}far;{$endif}
  1734. begin
  1735. if (psym(sym)^.typ=varsym) and
  1736. pvarsym(sym)^.definition^.needs_inittable then
  1737. { force inittable generation }
  1738. pvarsym(sym)^.definition^.get_inittable_label;
  1739. end;
  1740. procedure generate_child_rtti(sym : pnamedindexobject);{$ifndef fpc}far;{$endif}
  1741. begin
  1742. pvarsym(sym)^.definition^.get_rtti_label;
  1743. end;
  1744. procedure trecdef.write_child_rtti_data;
  1745. begin
  1746. symtable^.foreach({$ifndef TP}@{$endif}generate_child_rtti);
  1747. end;
  1748. procedure trecdef.write_child_init_data;
  1749. begin
  1750. symtable^.foreach({$ifndef TP}@{$endif}generate_child_inittable);
  1751. end;
  1752. procedure trecdef.write_rtti_data;
  1753. begin
  1754. rttilist^.concat(new(pai_const,init_8bit(tkrecord)));
  1755. write_rtti_name;
  1756. rttilist^.concat(new(pai_const,init_32bit(size)));
  1757. count:=0;
  1758. symtable^.foreach({$ifndef TP}@{$endif}count_fields);
  1759. rttilist^.concat(new(pai_const,init_32bit(count)));
  1760. symtable^.foreach({$ifndef TP}@{$endif}write_field_rtti);
  1761. end;
  1762. procedure trecdef.write_init_data;
  1763. begin
  1764. rttilist^.concat(new(pai_const,init_8bit(14)));
  1765. write_rtti_name;
  1766. rttilist^.concat(new(pai_const,init_32bit(size)));
  1767. count:=0;
  1768. symtable^.foreach({$ifndef TP}@{$endif}count_inittable_fields);
  1769. rttilist^.concat(new(pai_const,init_32bit(count)));
  1770. symtable^.foreach({$ifndef TP}@{$endif}write_field_inittable);
  1771. end;
  1772. function trecdef.gettypename : string;
  1773. begin
  1774. gettypename:='<record type>'
  1775. end;
  1776. {***************************************************************************
  1777. TABSTRACTPROCDEF
  1778. ***************************************************************************}
  1779. constructor tabstractprocdef.init;
  1780. begin
  1781. inherited init;
  1782. para1:=nil;
  1783. fpu_used:=0;
  1784. options:=0;
  1785. retdef:=voiddef;
  1786. savesize:=target_os.size_of_pointer;
  1787. end;
  1788. procedure disposepdefcoll(var para1 : pdefcoll);
  1789. var
  1790. hp : pdefcoll;
  1791. begin
  1792. hp:=para1;
  1793. while assigned(hp) do
  1794. begin
  1795. para1:=hp^.next;
  1796. dispose(hp);
  1797. hp:=para1;
  1798. end;
  1799. end;
  1800. destructor tabstractprocdef.done;
  1801. begin
  1802. disposepdefcoll(para1);
  1803. inherited done;
  1804. end;
  1805. procedure tabstractprocdef.concatdef(p : pdef;vsp : tvarspez);
  1806. var
  1807. hp : pdefcoll;
  1808. begin
  1809. new(hp);
  1810. hp^.paratyp:=vsp;
  1811. hp^.datasym:=nil;
  1812. hp^.data:=p;
  1813. hp^.next:=para1;
  1814. hp^.register:=R_NO;
  1815. para1:=hp;
  1816. end;
  1817. procedure tabstractprocdef.concattypesym(p : ptypesym;vsp : tvarspez);
  1818. var
  1819. hp : pdefcoll;
  1820. begin
  1821. new(hp);
  1822. hp^.paratyp:=vsp;
  1823. hp^.datasym:=p;
  1824. hp^.data:=p^.definition;
  1825. hp^.next:=para1;
  1826. hp^.register:=R_NO;
  1827. para1:=hp;
  1828. end;
  1829. { all functions returning in FPU are
  1830. assume to use 2 FPU registers
  1831. until the function implementation
  1832. is processed PM }
  1833. procedure tabstractprocdef.test_if_fpu_result;
  1834. begin
  1835. if assigned(retdef) and is_fpu(retdef) then
  1836. fpu_used:=2;
  1837. end;
  1838. procedure tabstractprocdef.deref;
  1839. var
  1840. hp : pdefcoll;
  1841. begin
  1842. inherited deref;
  1843. resolvedef(retdef);
  1844. hp:=para1;
  1845. while assigned(hp) do
  1846. begin
  1847. if assigned(hp^.datasym) then
  1848. begin
  1849. resolvesym(psym(hp^.datasym));
  1850. hp^.data:=hp^.datasym^.definition;
  1851. end
  1852. else
  1853. resolvedef(hp^.data);
  1854. hp:=hp^.next;
  1855. end;
  1856. end;
  1857. constructor tabstractprocdef.load;
  1858. var
  1859. last,hp : pdefcoll;
  1860. count,i : word;
  1861. begin
  1862. inherited load;
  1863. retdef:=readdefref;
  1864. fpu_used:=readbyte;
  1865. options:=readlong;
  1866. count:=readword;
  1867. para1:=nil;
  1868. savesize:=target_os.size_of_pointer;
  1869. for i:=1 to count do
  1870. begin
  1871. new(hp);
  1872. hp^.paratyp:=tvarspez(readbyte);
  1873. { hp^.register:=tregister(readbyte); }
  1874. hp^.register:=R_NO;
  1875. hp^.data:=readdefref;
  1876. hp^.datasym:=ptypesym(readsymref);
  1877. hp^.next:=nil;
  1878. if para1=nil then
  1879. para1:=hp
  1880. else
  1881. last^.next:=hp;
  1882. last:=hp;
  1883. end;
  1884. end;
  1885. function tabstractprocdef.para_size : longint;
  1886. var
  1887. pdc : pdefcoll;
  1888. l : longint;
  1889. begin
  1890. l:=0;
  1891. pdc:=para1;
  1892. while assigned(pdc) do
  1893. begin
  1894. case pdc^.paratyp of
  1895. vs_var : inc(l,target_os.size_of_pointer);
  1896. vs_value,
  1897. vs_const : if push_addr_param(pdc^.data) then
  1898. inc(l,target_os.size_of_pointer)
  1899. else
  1900. inc(l,align(pdc^.data^.size,target_os.stackalignment));
  1901. end;
  1902. pdc:=pdc^.next;
  1903. end;
  1904. para_size:=l;
  1905. end;
  1906. procedure tabstractprocdef.write;
  1907. var
  1908. count : word;
  1909. hp : pdefcoll;
  1910. begin
  1911. inherited write;
  1912. writedefref(retdef);
  1913. current_ppu^.do_interface_crc:=false;
  1914. writebyte(fpu_used);
  1915. writelong(options);
  1916. hp:=para1;
  1917. count:=0;
  1918. while assigned(hp) do
  1919. begin
  1920. inc(count);
  1921. hp:=hp^.next;
  1922. end;
  1923. writeword(count);
  1924. hp:=para1;
  1925. while assigned(hp) do
  1926. begin
  1927. writebyte(byte(hp^.paratyp));
  1928. { writebyte(byte(hp^.register)); }
  1929. if assigned(hp^.datasym) then
  1930. begin
  1931. writedefref(nil);
  1932. writesymref(psym(hp^.datasym));
  1933. end
  1934. else
  1935. begin
  1936. writedefref(hp^.data);
  1937. writesymref(nil);
  1938. end;
  1939. hp:=hp^.next;
  1940. end;
  1941. end;
  1942. function tabstractprocdef.demangled_paras : string;
  1943. var s : string;
  1944. procedure doconcat(p : pdefcoll);
  1945. begin
  1946. if assigned(p^.next) then
  1947. doconcat(p^.next)
  1948. else
  1949. s:='(';
  1950. if assigned(p^.data^.sym) then
  1951. s:=s+p^.data^.sym^.name
  1952. else if p^.paratyp=vs_var then
  1953. s:=s+'var'
  1954. else if p^.paratyp=vs_const then
  1955. s:=s+'const';
  1956. if p<>para1 then
  1957. s:=s+','
  1958. else
  1959. s:=s+')';
  1960. end;
  1961. begin
  1962. s:='';
  1963. { a recursive solution is the easiest way to inverse the parameter }
  1964. { collection }
  1965. if assigned(para1) then
  1966. doconcat(para1);
  1967. demangled_paras:=s;
  1968. end;
  1969. {$ifdef GDB}
  1970. function tabstractprocdef.stabstring : pchar;
  1971. begin
  1972. stabstring := strpnew('abstractproc'+numberstring+';');
  1973. end;
  1974. procedure tabstractprocdef.concatstabto(asmlist : paasmoutput);
  1975. begin
  1976. if (not assigned(sym) or sym^.isusedinstab or (cs_gdb_dbx in aktglobalswitches))
  1977. and not is_def_stab_written then
  1978. begin
  1979. if assigned(retdef) then forcestabto(asmlist,retdef);
  1980. inherited concatstabto(asmlist);
  1981. end;
  1982. end;
  1983. {$endif GDB}
  1984. {***************************************************************************
  1985. TPROCDEF
  1986. ***************************************************************************}
  1987. constructor tprocdef.init;
  1988. begin
  1989. inherited init;
  1990. deftype:=procdef;
  1991. _mangledname:=nil;
  1992. nextoverloaded:=nil;
  1993. fileinfo:=aktfilepos;
  1994. extnumber:=-1;
  1995. localst:=new(psymtable,init(localsymtable));
  1996. parast:=new(psymtable,init(parasymtable));
  1997. localst^.defowner:=@self;
  1998. parast^.defowner:=@self;
  1999. { this is used by insert
  2000. to check same names in parast and localst }
  2001. localst^.next:=parast;
  2002. defref:=nil;
  2003. crossref:=nil;
  2004. lastwritten:=nil;
  2005. refcount:=0;
  2006. if (cs_browser in aktmoduleswitches) and make_ref then
  2007. begin
  2008. defref:=new(pref,init(defref,@tokenpos));
  2009. inc(refcount);
  2010. end;
  2011. lastref:=defref;
  2012. { first, we assume that all registers are used }
  2013. {$ifdef i386}
  2014. usedregisters:=$ff;
  2015. {$endif i386}
  2016. {$ifdef m68k}
  2017. usedregisters:=$FFFF;
  2018. {$endif}
  2019. {$ifdef alpha}
  2020. usedregisters_int:=$ffffffff;
  2021. usedregisters_fpu:=$ffffffff;
  2022. {$endif alpha}
  2023. forwarddef:=true;
  2024. interfacedef:=false;
  2025. _class := nil;
  2026. code:=nil;
  2027. count:=false;
  2028. is_used:=false;
  2029. end;
  2030. constructor tprocdef.load;
  2031. var
  2032. s : string;
  2033. begin
  2034. inherited load;
  2035. deftype:=procdef;
  2036. {$ifdef i386}
  2037. usedregisters:=readbyte;
  2038. {$endif i386}
  2039. {$ifdef m68k}
  2040. usedregisters:=readword;
  2041. {$endif}
  2042. {$ifdef alpha}
  2043. usedregisters_int:=readlong;
  2044. usedregisters_fpu:=readlong;
  2045. {$endif alpha}
  2046. s:=readstring;
  2047. setstring(_mangledname,s);
  2048. extnumber:=readlong;
  2049. nextoverloaded:=pprocdef(readdefref);
  2050. _class := pobjectdef(readdefref);
  2051. readposinfo(fileinfo);
  2052. if (cs_link_deffile in aktglobalswitches) and ((options and poexports)<>0) then
  2053. deffile.AddExport(mangledname);
  2054. parast:=nil;
  2055. localst:=nil;
  2056. forwarddef:=false;
  2057. interfacedef:=false;
  2058. lastref:=nil;
  2059. lastwritten:=nil;
  2060. defref:=nil;
  2061. refcount:=0;
  2062. count:=true;
  2063. is_used:=false;
  2064. end;
  2065. Const local_symtable_index : longint = $8001;
  2066. procedure tprocdef.load_references;
  2067. var
  2068. pos : tfileposinfo;
  2069. {$ifndef NOLOCALBROWSER}
  2070. pdo : pobjectdef;
  2071. {$endif ndef NOLOCALBROWSER}
  2072. move_last : boolean;
  2073. begin
  2074. move_last:=lastwritten=lastref;
  2075. while (not current_ppu^.endofentry) do
  2076. begin
  2077. readposinfo(pos);
  2078. inc(refcount);
  2079. lastref:=new(pref,init(lastref,@pos));
  2080. lastref^.is_written:=true;
  2081. if refcount=1 then
  2082. defref:=lastref;
  2083. end;
  2084. if move_last then
  2085. lastwritten:=lastref;
  2086. if ((current_module^.flags and uf_local_browser)<>0)
  2087. and is_in_current then
  2088. begin
  2089. {$ifndef NOLOCALBROWSER}
  2090. pdo:=_class;
  2091. new(parast,loadas(parasymtable));
  2092. parast^.next:=owner;
  2093. parast^.load_browser;
  2094. new(localst,loadas(localsymtable));
  2095. localst^.next:=parast;
  2096. localst^.load_browser;
  2097. {$endif ndef NOLOCALBROWSER}
  2098. end;
  2099. end;
  2100. function tprocdef.write_references : boolean;
  2101. var
  2102. ref : pref;
  2103. {$ifndef NOLOCALBROWSER}
  2104. pdo : pobjectdef;
  2105. {$endif ndef NOLOCALBROWSER}
  2106. move_last : boolean;
  2107. begin
  2108. move_last:=lastwritten=lastref;
  2109. if move_last and (((current_module^.flags and uf_local_browser)=0)
  2110. or not is_in_current) then
  2111. exit;
  2112. { write address of this symbol }
  2113. writedefref(@self);
  2114. { write refs }
  2115. if assigned(lastwritten) then
  2116. ref:=lastwritten
  2117. else
  2118. ref:=defref;
  2119. while assigned(ref) do
  2120. begin
  2121. if ref^.moduleindex=current_module^.unit_index then
  2122. begin
  2123. writeposinfo(ref^.posinfo);
  2124. ref^.is_written:=true;
  2125. if move_last then
  2126. lastwritten:=ref;
  2127. end
  2128. else if not ref^.is_written then
  2129. move_last:=false
  2130. else if move_last then
  2131. lastwritten:=ref;
  2132. ref:=ref^.nextref;
  2133. end;
  2134. current_ppu^.writeentry(ibdefref);
  2135. write_references:=true;
  2136. if ((current_module^.flags and uf_local_browser)<>0)
  2137. and is_in_current then
  2138. begin
  2139. {$ifndef NOLOCALBROWSER}
  2140. pdo:=_class;
  2141. if (owner^.symtabletype<>localsymtable) then
  2142. while assigned(pdo) do
  2143. begin
  2144. if pdo^.publicsyms<>aktrecordsymtable then
  2145. begin
  2146. pdo^.publicsyms^.unitid:=local_symtable_index;
  2147. inc(local_symtable_index);
  2148. end;
  2149. pdo:=pdo^.childof;
  2150. end;
  2151. { we need TESTLOCALBROWSER para and local symtables
  2152. PPU files are then easier to read PM }
  2153. if not assigned(parast) then
  2154. parast:=new(psymtable,init(parasymtable));
  2155. parast^.writeas;
  2156. parast^.unitid:=local_symtable_index;
  2157. inc(local_symtable_index);
  2158. parast^.write_browser;
  2159. if not assigned(localst) then
  2160. localst:=new(psymtable,init(localsymtable));
  2161. localst^.writeas;
  2162. localst^.unitid:=local_symtable_index;
  2163. inc(local_symtable_index);
  2164. localst^.write_browser;
  2165. { decrement for }
  2166. local_symtable_index:=local_symtable_index-2;
  2167. pdo:=_class;
  2168. if (owner^.symtabletype<>localsymtable) then
  2169. while assigned(pdo) do
  2170. begin
  2171. if pdo^.publicsyms<>aktrecordsymtable then
  2172. dec(local_symtable_index);
  2173. pdo:=pdo^.childof;
  2174. end;
  2175. {$endif ndef NOLOCALBROWSER}
  2176. end;
  2177. end;
  2178. {$ifdef BrowserLog}
  2179. procedure tprocdef.add_to_browserlog;
  2180. begin
  2181. if assigned(defref) then
  2182. begin
  2183. browserlog.AddLog('***'+mangledname);
  2184. browserlog.AddLogRefs(defref);
  2185. if (current_module^.flags and uf_local_browser)<>0 then
  2186. begin
  2187. if assigned(parast) then
  2188. parast^.writebrowserlog;
  2189. if assigned(localst) then
  2190. localst^.writebrowserlog;
  2191. end;
  2192. end;
  2193. end;
  2194. {$endif BrowserLog}
  2195. destructor tprocdef.done;
  2196. begin
  2197. if assigned(defref) then
  2198. dispose(defref,done);
  2199. if assigned(parast) then
  2200. dispose(parast,done);
  2201. if assigned(localst) and (localst^.symtabletype<>staticsymtable) then
  2202. dispose(localst,done);
  2203. if ((options and poinline) <> 0) and assigned(code) then
  2204. disposetree(ptree(code));
  2205. if (options and pomsgstr)<>0 then
  2206. strdispose(messageinf.str);
  2207. if
  2208. {$ifdef tp}
  2209. not(use_big) and
  2210. {$endif}
  2211. assigned(_mangledname) then
  2212. globals.strdispose(_mangledname);
  2213. inherited done;
  2214. end;
  2215. procedure tprocdef.write;
  2216. begin
  2217. inherited write;
  2218. current_ppu^.do_interface_crc:=false;
  2219. {$ifdef i386}
  2220. writebyte(usedregisters);
  2221. {$endif i386}
  2222. {$ifdef m68k}
  2223. writeword(usedregisters);
  2224. {$endif}
  2225. {$ifdef alpha}
  2226. writelong(usedregisters_int);
  2227. writelong(usedregisters_fpu);
  2228. {$endif alpha}
  2229. writestring(mangledname);
  2230. current_ppu^.do_interface_crc:=true;
  2231. writelong(extnumber);
  2232. if (options and pooperator) = 0 then
  2233. writedefref(nextoverloaded)
  2234. else
  2235. begin
  2236. { only write the overloads from the same unit }
  2237. if assigned(nextoverloaded) and
  2238. (nextoverloaded^.owner=owner) then
  2239. writedefref(nextoverloaded)
  2240. else
  2241. writedefref(nil);
  2242. end;
  2243. writedefref(_class);
  2244. writeposinfo(fileinfo);
  2245. if (options and poinline) <> 0 then
  2246. begin
  2247. { we need to save
  2248. - the para and the local symtable
  2249. - the code ptree !! PM
  2250. writesymtable(parast);
  2251. writesymtable(localst);
  2252. writeptree(ptree(code));
  2253. }
  2254. end;
  2255. current_ppu^.writeentry(ibprocdef);
  2256. end;
  2257. function tprocdef.haspara:boolean;
  2258. begin
  2259. haspara:=assigned(aktprocsym^.definition^.parast^.symindex^.first);
  2260. end;
  2261. {$ifdef GDB}
  2262. procedure addparaname(p : psym);
  2263. var vs : char;
  2264. begin
  2265. if pvarsym(p)^.varspez = vs_value then vs := '1'
  2266. else vs := '0';
  2267. strpcopy(strend(StabRecString),p^.name+':'+pvarsym(p)^.definition^.numberstring+','+vs+';');
  2268. end;
  2269. function tprocdef.stabstring : pchar;
  2270. var param : pdefcoll;
  2271. i : word;
  2272. oldrec : pchar;
  2273. begin
  2274. oldrec := stabrecstring;
  2275. getmem(StabRecString,1024);
  2276. param := para1;
  2277. i := 0;
  2278. while assigned(param) do
  2279. begin
  2280. inc(i);
  2281. param := param^.next;
  2282. end;
  2283. strpcopy(StabRecString,'f'+retdef^.numberstring);
  2284. if i>0 then
  2285. begin
  2286. strpcopy(strend(StabRecString),','+tostr(i)+';');
  2287. (* confuse gdb !! PM
  2288. if assigned(parast) then
  2289. parast^.foreach({$ifndef TP}@{$endif}addparaname)
  2290. else
  2291. begin
  2292. param := para1;
  2293. i := 0;
  2294. while assigned(param) do
  2295. begin
  2296. inc(i);
  2297. if param^.paratyp = vs_value then vartyp := '1' else vartyp := '0';
  2298. {Here we have lost the parameter names !!}
  2299. {using lower case parameters }
  2300. strpcopy(strend(stabrecstring),'p'+tostr(i)
  2301. +':'+param^.data^.numberstring+','+vartyp+';');
  2302. param := param^.next;
  2303. end;
  2304. end; *)
  2305. {strpcopy(strend(StabRecString),';');}
  2306. end;
  2307. stabstring := strnew(stabrecstring);
  2308. freemem(stabrecstring,1024);
  2309. stabrecstring := oldrec;
  2310. end;
  2311. procedure tprocdef.concatstabto(asmlist : paasmoutput);
  2312. begin
  2313. end;
  2314. {$endif GDB}
  2315. procedure tprocdef.deref;
  2316. begin
  2317. inherited deref;
  2318. resolvedef(pdef(nextoverloaded));
  2319. resolvedef(pdef(_class));
  2320. end;
  2321. function tprocdef.mangledname : string;
  2322. {$ifdef tp}
  2323. var
  2324. oldpos : longint;
  2325. s : string;
  2326. b : byte;
  2327. {$endif tp}
  2328. begin
  2329. {$ifndef Delphi}
  2330. {$ifdef tp}
  2331. if use_big then
  2332. begin
  2333. symbolstream.seek(longint(_mangledname));
  2334. symbolstream.read(b,1);
  2335. symbolstream.read(s[1],b);
  2336. s[0]:=chr(b);
  2337. mangledname:=s;
  2338. end
  2339. else
  2340. {$endif}
  2341. {$endif Delphi}
  2342. mangledname:=strpas(_mangledname);
  2343. if count then
  2344. is_used:=true;
  2345. end;
  2346. {$IfDef GDB}
  2347. function tprocdef.cplusplusmangledname : string;
  2348. var
  2349. s,s2 : string;
  2350. param : pdefcoll;
  2351. begin
  2352. s := sym^.name;
  2353. if _class <> nil then
  2354. begin
  2355. s2 := _class^.objname^;
  2356. s := s+'__'+tostr(length(s2))+s2;
  2357. end else s := s + '_';
  2358. param := para1;
  2359. while assigned(param) do
  2360. begin
  2361. s2 := param^.data^.sym^.name;
  2362. s := s+tostr(length(s2))+s2;
  2363. param := param^.next;
  2364. end;
  2365. cplusplusmangledname:=s;
  2366. end;
  2367. {$EndIf GDB}
  2368. procedure tprocdef.setmangledname(const s : string);
  2369. begin
  2370. if {$ifdef tp}not(use_big) and{$endif} (assigned(_mangledname)) then
  2371. strdispose(_mangledname);
  2372. setstring(_mangledname,s);
  2373. if assigned(parast) then
  2374. begin
  2375. stringdispose(parast^.name);
  2376. parast^.name:=stringdup('args of '+s);
  2377. end;
  2378. if assigned(localst) then
  2379. begin
  2380. stringdispose(localst^.name);
  2381. localst^.name:=stringdup('locals of '+s);
  2382. end;
  2383. end;
  2384. {***************************************************************************
  2385. TPROCVARDEF
  2386. ***************************************************************************}
  2387. constructor tprocvardef.init;
  2388. begin
  2389. inherited init;
  2390. deftype:=procvardef;
  2391. end;
  2392. constructor tprocvardef.load;
  2393. begin
  2394. inherited load;
  2395. deftype:=procvardef;
  2396. end;
  2397. procedure tprocvardef.write;
  2398. begin
  2399. { here we cannot get a real good value so just give something }
  2400. { plausible (PM) }
  2401. { a more secure way would be
  2402. to allways store in a temp }
  2403. if is_fpu(retdef) then
  2404. fpu_used:=2
  2405. else
  2406. fpu_used:=0;
  2407. inherited write;
  2408. current_ppu^.writeentry(ibprocvardef);
  2409. end;
  2410. function tprocvardef.size : longint;
  2411. begin
  2412. if (options and pomethodpointer)=0 then
  2413. size:=target_os.size_of_pointer
  2414. else
  2415. size:=2*target_os.size_of_pointer;
  2416. end;
  2417. {$ifdef GDB}
  2418. function tprocvardef.stabstring : pchar;
  2419. var
  2420. nss : pchar;
  2421. i : word;
  2422. param : pdefcoll;
  2423. begin
  2424. i := 0;
  2425. param := para1;
  2426. while assigned(param) do
  2427. begin
  2428. inc(i);
  2429. param := param^.next;
  2430. end;
  2431. getmem(nss,1024);
  2432. { it is not a function but a function pointer !! (PM) }
  2433. strpcopy(nss,'*f'+retdef^.numberstring{+','+tostr(i)}+';');
  2434. param := para1;
  2435. i := 0;
  2436. { this confuses gdb !!
  2437. we should use 'F' instead of 'f' but
  2438. as we use c++ language mode
  2439. it does not like that either
  2440. Please do not remove this part
  2441. might be used once
  2442. gdb for pascal is ready PM }
  2443. (* while assigned(param) do
  2444. begin
  2445. inc(i);
  2446. if param^.paratyp = vs_value then vartyp := '1' else vartyp := '0';
  2447. {Here we have lost the parameter names !!}
  2448. pst := strpnew('p'+tostr(i)+':'+param^.data^.numberstring+','+vartyp+';');
  2449. strcat(nss,pst);
  2450. strdispose(pst);
  2451. param := param^.next;
  2452. end; *)
  2453. {strpcopy(strend(nss),';');}
  2454. stabstring := strnew(nss);
  2455. freemem(nss,1024);
  2456. end;
  2457. procedure tprocvardef.concatstabto(asmlist : paasmoutput);
  2458. begin
  2459. if ( not assigned(sym) or sym^.isusedinstab or (cs_gdb_dbx in aktglobalswitches))
  2460. and not is_def_stab_written then
  2461. inherited concatstabto(asmlist);
  2462. is_def_stab_written:=true;
  2463. end;
  2464. {$endif GDB}
  2465. procedure tprocvardef.write_rtti_data;
  2466. begin
  2467. {!!!!!!!}
  2468. end;
  2469. procedure tprocvardef.write_child_rtti_data;
  2470. begin
  2471. {!!!!!!!!}
  2472. end;
  2473. function tprocvardef.is_publishable : boolean;
  2474. begin
  2475. is_publishable:=(options and pomethodpointer)<>0;
  2476. end;
  2477. function tprocvardef.gettypename : string;
  2478. begin
  2479. if assigned(retdef) then
  2480. gettypename:='<procedure variable type of function'+demangled_paras+':'+retdef^.gettypename+'>'
  2481. else
  2482. gettypename:='<procedure variable type of procedure'+demangled_paras+'>';
  2483. end;
  2484. {***************************************************************************
  2485. TOBJECTDEF
  2486. ***************************************************************************}
  2487. {$ifdef GDB}
  2488. const
  2489. vtabletype : word = 0;
  2490. vtableassigned : boolean = false;
  2491. {$endif GDB}
  2492. constructor tobjectdef.init(const n : string;c : pobjectdef);
  2493. begin
  2494. tdef.init;
  2495. deftype:=objectdef;
  2496. options:=0;
  2497. childof:=nil;
  2498. publicsyms:=new(psymtable,init(objectsymtable));
  2499. publicsyms^.name := stringdup(n);
  2500. { create space for vmt !! }
  2501. options:=0;
  2502. vmt_offset:=0;
  2503. publicsyms^.datasize:=0;
  2504. publicsyms^.defowner:=@self;
  2505. publicsyms^.dataalignment:=packrecordalignment[aktpackrecords];
  2506. set_parent(c);
  2507. objname:=stringdup(n);
  2508. end;
  2509. procedure tobjectdef.set_parent( c : pobjectdef);
  2510. begin
  2511. { nothing to do if the parent was not forward !}
  2512. if assigned(childof) then
  2513. exit;
  2514. childof:=c;
  2515. { some options are inherited !! }
  2516. if assigned(c) then
  2517. begin
  2518. options:= options or (c^.options and
  2519. (oo_hasvirtual or oo_hasprivate or
  2520. oo_hasprotected or
  2521. oo_hasconstructor or oo_hasdestructor
  2522. ));
  2523. { add the data of the anchestor class }
  2524. publicsyms^.datasize:=publicsyms^.datasize
  2525. +childof^.publicsyms^.datasize;
  2526. if ((options and oo_hasvmt)<>0) and
  2527. ((c^.options and oo_hasvmt)<>0) then
  2528. publicsyms^.datasize:=publicsyms^.datasize-target_os.size_of_pointer;
  2529. { if parent has a vmt field then
  2530. the offset is the same for the child PM }
  2531. if ((c^.options and oo_hasvmt)<>0) or isclass then
  2532. begin
  2533. vmt_offset:=c^.vmt_offset;
  2534. options:=options or oo_hasvmt;
  2535. end;
  2536. end;
  2537. savesize := publicsyms^.datasize;
  2538. end;
  2539. constructor tobjectdef.load;
  2540. var
  2541. oldread_member : boolean;
  2542. begin
  2543. tdef.load;
  2544. deftype:=objectdef;
  2545. savesize:=readlong;
  2546. vmt_offset:=readlong;
  2547. objname:=stringdup(readstring);
  2548. childof:=pobjectdef(readdefref);
  2549. options:=readlong;
  2550. oldread_member:=read_member;
  2551. read_member:=true;
  2552. publicsyms:=new(psymtable,loadas(objectsymtable));
  2553. read_member:=oldread_member;
  2554. publicsyms^.defowner:=@self;
  2555. publicsyms^.name := stringdup(objname^);
  2556. { handles the predefined class tobject }
  2557. { the last TOBJECT which is loaded gets }
  2558. { it ! }
  2559. if (objname^='TOBJECT') and
  2560. isclass and (childof=nil) then
  2561. class_tobject:=@self;
  2562. has_rtti:=true;
  2563. end;
  2564. procedure tobjectdef.insertvmt;
  2565. begin
  2566. if (options and oo_hasvmt)<>0 then
  2567. internalerror(12345)
  2568. else
  2569. begin
  2570. { first round up to multiple of 4 }
  2571. if (publicsyms^.dataalignment=2) then
  2572. begin
  2573. if (publicsyms^.datasize and 1)<>0 then
  2574. inc(publicsyms^.datasize);
  2575. end
  2576. else
  2577. if (publicsyms^.dataalignment>=4) then
  2578. begin
  2579. if (publicsyms^.datasize mod 4) <> 0 then
  2580. publicsyms^.datasize:=publicsyms^.datasize+4-(publicsyms^.datasize mod 4);
  2581. end;
  2582. vmt_offset:=publicsyms^.datasize;
  2583. publicsyms^.datasize:=publicsyms^.datasize+target_os.size_of_pointer;
  2584. options:=options or oo_hasvmt;
  2585. end;
  2586. end;
  2587. procedure tobjectdef.check_forwards;
  2588. begin
  2589. publicsyms^.check_forwards;
  2590. if (options and oo_isforward)<>0 then
  2591. begin
  2592. { ok, in future, the forward can be resolved }
  2593. Message1(sym_e_class_forward_not_resolved,objname^);
  2594. options:=options and not(oo_isforward);
  2595. end;
  2596. end;
  2597. destructor tobjectdef.done;
  2598. begin
  2599. if assigned(publicsyms) then
  2600. dispose(publicsyms,done);
  2601. if (options and oo_isforward)<>0 then
  2602. Message1(sym_e_class_forward_not_resolved,objname^);
  2603. stringdispose(objname);
  2604. tdef.done;
  2605. end;
  2606. { true, if self inherits from d (or if they are equal) }
  2607. function tobjectdef.isrelated(d : pobjectdef) : boolean;
  2608. var
  2609. hp : pobjectdef;
  2610. begin
  2611. hp:=@self;
  2612. while assigned(hp) do
  2613. begin
  2614. if hp=d then
  2615. begin
  2616. isrelated:=true;
  2617. exit;
  2618. end;
  2619. hp:=hp^.childof;
  2620. end;
  2621. isrelated:=false;
  2622. end;
  2623. function tobjectdef.size : longint;
  2624. begin
  2625. if (options and oo_is_class)<>0 then
  2626. size:=target_os.size_of_pointer
  2627. else
  2628. size:=publicsyms^.datasize;
  2629. end;
  2630. function tobjectdef.alignment:longint;
  2631. begin
  2632. alignment:=publicsyms^.dataalignment;
  2633. end;
  2634. procedure tobjectdef.deref;
  2635. var
  2636. oldrecsyms : psymtable;
  2637. begin
  2638. resolvedef(pdef(childof));
  2639. oldrecsyms:=aktrecordsymtable;
  2640. aktrecordsymtable:=publicsyms;
  2641. publicsyms^.deref;
  2642. aktrecordsymtable:=oldrecsyms;
  2643. end;
  2644. function tobjectdef.vmt_mangledname : string;
  2645. {DM: I get a nil pointer on the owner name. I don't know if this
  2646. mayhappen, and I have therefore fixed the problem by doing nil pointer
  2647. checks.}
  2648. var
  2649. s1,s2:string;
  2650. begin
  2651. if (options and oo_hasvmt)=0 then
  2652. {internalerror(12346);}
  2653. Message1(parser_object_has_no_vmt,objname^);
  2654. if owner^.name=nil then
  2655. s1:=''
  2656. else
  2657. s1:=owner^.name^;
  2658. if objname=nil then
  2659. s2:=''
  2660. else
  2661. s2:=objname^;
  2662. vmt_mangledname:='VMT_'+s1+'$_'+s2;
  2663. end;
  2664. function tobjectdef.rtti_name : string;
  2665. var
  2666. s1,s2:string;
  2667. begin
  2668. if owner^.name=nil then
  2669. s1:=''
  2670. else
  2671. s1:=owner^.name^;
  2672. if objname=nil then
  2673. s2:=''
  2674. else
  2675. s2:=objname^;
  2676. rtti_name:='RTTI_'+s1+'$_'+s2;
  2677. end;
  2678. function tobjectdef.isclass : boolean;
  2679. begin
  2680. isclass:=(options and oo_is_class)<>0;
  2681. end;
  2682. procedure tobjectdef.write;
  2683. var
  2684. oldread_member : boolean;
  2685. begin
  2686. tdef.write;
  2687. writelong(size);
  2688. writelong(vmt_offset);
  2689. writestring(objname^);
  2690. writedefref(childof);
  2691. writelong(options);
  2692. current_ppu^.writeentry(ibobjectdef);
  2693. oldread_member:=read_member;
  2694. read_member:=true;
  2695. publicsyms^.writeas;
  2696. read_member:=oldread_member;
  2697. end;
  2698. {$ifdef GDB}
  2699. procedure addprocname(p :pnamedindexobject);
  2700. var virtualind,argnames : string;
  2701. news, newrec : pchar;
  2702. pd,ipd : pprocdef;
  2703. lindex : longint;
  2704. para : pdefcoll;
  2705. arglength : byte;
  2706. sp : char;
  2707. begin
  2708. If psym(p)^.typ = procsym then
  2709. begin
  2710. pd := pprocsym(p)^.definition;
  2711. { this will be used for full implementation of object stabs
  2712. not yet done }
  2713. ipd := pd;
  2714. while assigned(ipd^.nextoverloaded) do ipd := ipd^.nextoverloaded;
  2715. if (pd^.options and povirtualmethod) <> 0 then
  2716. begin
  2717. lindex := pd^.extnumber;
  2718. {doesnt seem to be necessary
  2719. lindex := lindex or $80000000;}
  2720. virtualind := '*'+tostr(lindex)+';'+ipd^._class^.numberstring+';'
  2721. end else virtualind := '.';
  2722. { arguments are not listed here }
  2723. {we don't need another definition}
  2724. para := pd^.para1;
  2725. { used by gdbpas to recognize constructor and destructors }
  2726. if (pd^.options and poconstructor) <> 0 then
  2727. argnames:='__ct__'
  2728. else if (pd^.options and podestructor) <> 0 then
  2729. argnames:='__dt__'
  2730. else
  2731. argnames := '';
  2732. while assigned(para) do
  2733. begin
  2734. if para^.data^.deftype = formaldef then
  2735. begin
  2736. if para^.paratyp=vs_var then
  2737. argnames := argnames+'3var'
  2738. else if para^.paratyp=vs_const then
  2739. argnames:=argnames+'5const';
  2740. end
  2741. else
  2742. begin
  2743. { if the arg definition is like (v: ^byte;..
  2744. there is no sym attached to data !!! }
  2745. if assigned(para^.data^.sym) then
  2746. begin
  2747. arglength := length(para^.data^.sym^.name);
  2748. argnames := argnames + tostr(arglength)+para^.data^.sym^.name;
  2749. end
  2750. else
  2751. begin
  2752. argnames:=argnames+'11unnamedtype';
  2753. end;
  2754. end;
  2755. para := para^.next;
  2756. end;
  2757. ipd^.is_def_stab_written := true;
  2758. { here 2A must be changed for private and protected }
  2759. { 0 is private 1 protected and 2 public }
  2760. if (psym(p)^.properties and sp_private)<>0 then sp:='0'
  2761. else if (psym(p)^.properties and sp_protected)<>0 then sp:='1'
  2762. else sp:='2';
  2763. newrec := strpnew(p^.name+'::'+ipd^.numberstring
  2764. +'=##'+pd^.retdef^.numberstring+';:'+argnames+';'+sp+'A'
  2765. +virtualind+';');
  2766. { get spare place for a string at the end }
  2767. if strlen(StabRecString) + strlen(newrec) >= StabRecSize-256 then
  2768. begin
  2769. getmem(news,stabrecsize+memsizeinc);
  2770. strcopy(news,stabrecstring);
  2771. freemem(stabrecstring,stabrecsize);
  2772. stabrecsize:=stabrecsize+memsizeinc;
  2773. stabrecstring:=news;
  2774. end;
  2775. strcat(StabRecstring,newrec);
  2776. {freemem(newrec,memsizeinc); }
  2777. strdispose(newrec);
  2778. {This should be used for case !!}
  2779. RecOffset := RecOffset + pd^.size;
  2780. end;
  2781. end;
  2782. function tobjectdef.stabstring : pchar;
  2783. var anc : pobjectdef;
  2784. oldrec : pchar;
  2785. oldrecsize : longint;
  2786. str_end : string;
  2787. begin
  2788. oldrec := stabrecstring;
  2789. oldrecsize:=stabrecsize;
  2790. stabrecsize:=memsizeinc;
  2791. GetMem(stabrecstring,stabrecsize);
  2792. strpcopy(stabRecString,'s'+tostr(size));
  2793. if assigned(childof) then
  2794. {only one ancestor not virtual, public, at base offset 0 }
  2795. { !1 , 0 2 0 , }
  2796. strpcopy(strend(stabrecstring),'!1,020,'+childof^.numberstring+';');
  2797. {virtual table to implement yet}
  2798. RecOffset := 0;
  2799. publicsyms^.foreach({$ifndef TP}@{$endif}addname);
  2800. if (options and oo_hasvmt) <> 0 then
  2801. if not assigned(childof) or ((childof^.options and oo_hasvmt) = 0) then
  2802. begin
  2803. strpcopy(strend(stabrecstring),'$vf'+numberstring+':'+typeglobalnumber('vtblarray')
  2804. +','+tostr(vmt_offset*8)+';');
  2805. end;
  2806. publicsyms^.foreach({$ifndef TP}@{$endif}addprocname);
  2807. if (options and oo_hasvmt) <> 0 then
  2808. begin
  2809. anc := @self;
  2810. while assigned(anc^.childof) and ((anc^.childof^.options and oo_hasvmt) <> 0) do
  2811. anc := anc^.childof;
  2812. str_end:=';~%'+anc^.numberstring+';';
  2813. end
  2814. else
  2815. str_end:=';';
  2816. strpcopy(strend(stabrecstring),str_end);
  2817. stabstring := strnew(StabRecString);
  2818. freemem(stabrecstring,stabrecsize);
  2819. stabrecstring := oldrec;
  2820. stabrecsize:=oldrecsize;
  2821. end;
  2822. {$endif GDB}
  2823. procedure tobjectdef.write_child_init_data;
  2824. begin
  2825. publicsyms^.foreach({$ifndef TP}@{$endif}generate_child_inittable);
  2826. end;
  2827. procedure tobjectdef.write_init_data;
  2828. begin
  2829. if isclass then
  2830. rttilist^.concat(new(pai_const,init_8bit(tkclass)))
  2831. else
  2832. rttilist^.concat(new(pai_const,init_8bit(tkobject)));
  2833. { generate the name }
  2834. rttilist^.concat(new(pai_const,init_8bit(length(objname^))));
  2835. rttilist^.concat(new(pai_string,init(objname^)));
  2836. rttilist^.concat(new(pai_const,init_32bit(size)));
  2837. count:=0;
  2838. publicsyms^.foreach({$ifndef TP}@{$endif}count_inittable_fields);
  2839. rttilist^.concat(new(pai_const,init_32bit(count)));
  2840. publicsyms^.foreach({$ifndef TP}@{$endif}write_field_inittable);
  2841. end;
  2842. function tobjectdef.needs_inittable : boolean;
  2843. var
  2844. oldb : boolean;
  2845. begin
  2846. { there are recursive calls to needs_inittable possible, }
  2847. { so we have to change to old value how else should }
  2848. { we do that ? check_rec_rtti can't be a nested }
  2849. { procedure of needs_rtti ! }
  2850. oldb:=binittable;
  2851. binittable:=false;
  2852. publicsyms^.foreach({$ifndef TP}@{$endif}check_rec_inittable);
  2853. needs_inittable:=binittable;
  2854. binittable:=oldb;
  2855. end;
  2856. procedure count_published_properties(sym:pnamedindexobject);
  2857. {$ifndef fpc}far;{$endif}
  2858. begin
  2859. if (psym(sym)^.typ=propertysym) and ((psym(sym)^.properties and sp_published)<>0) then
  2860. inc(count);
  2861. end;
  2862. procedure write_property_info(sym : pnamedindexobject);{$ifndef fpc}far;{$endif}
  2863. var
  2864. proctypesinfo : byte;
  2865. procedure writeproc(sym : psym;def : pdef;shiftvalue : byte);
  2866. var
  2867. typvalue : byte;
  2868. begin
  2869. if not(assigned(sym)) then
  2870. begin
  2871. rttilist^.concat(new(pai_const,init_32bit(1)));
  2872. typvalue:=3;
  2873. end
  2874. else if sym^.typ=varsym then
  2875. begin
  2876. rttilist^.concat(new(pai_const,init_32bit(
  2877. pvarsym(sym)^.address)));
  2878. typvalue:=0;
  2879. end
  2880. else
  2881. begin
  2882. if (pprocdef(def)^.options and povirtualmethod)=0 then
  2883. begin
  2884. rttilist^.concat(new(pai_const_symbol,initname(pprocdef(def)^.mangledname)));
  2885. typvalue:=1;
  2886. end
  2887. else
  2888. begin
  2889. { virtual method, write vmt offset }
  2890. rttilist^.concat(new(pai_const,init_32bit(pprocdef(def)^.extnumber*4+12)));
  2891. typvalue:=2;
  2892. end;
  2893. end;
  2894. proctypesinfo:=proctypesinfo or (typvalue shl shiftvalue);
  2895. end;
  2896. begin
  2897. if (psym(sym)^.typ=propertysym) and
  2898. ((ppropertysym(sym)^.options and ppo_indexed)<>0) then
  2899. proctypesinfo:=$40
  2900. else
  2901. proctypesinfo:=0;
  2902. if (psym(sym)^.typ=propertysym) and
  2903. ((psym(sym)^.properties and sp_published)<>0) then
  2904. begin
  2905. rttilist^.concat(new(pai_const_symbol,initname(ppropertysym(sym)^.proptype^.get_rtti_label)));
  2906. writeproc(ppropertysym(sym)^.readaccesssym,ppropertysym(sym)^.readaccessdef,0);
  2907. writeproc(ppropertysym(sym)^.writeaccesssym,ppropertysym(sym)^.writeaccessdef,2);
  2908. { isn't it stored ? }
  2909. if (ppropertysym(sym)^.options and ppo_stored)=0 then
  2910. begin
  2911. rttilist^.concat(new(pai_const,init_32bit(1)));
  2912. proctypesinfo:=proctypesinfo or (3 shl 4);
  2913. end
  2914. else
  2915. writeproc(ppropertysym(sym)^.storedsym,ppropertysym(sym)^.storeddef,4);
  2916. rttilist^.concat(new(pai_const,init_32bit(ppropertysym(sym)^.index)));
  2917. rttilist^.concat(new(pai_const,init_32bit(ppropertysym(sym)^.default)));
  2918. rttilist^.concat(new(pai_const,init_16bit(count)));
  2919. inc(count);
  2920. rttilist^.concat(new(pai_const,init_8bit(proctypesinfo)));
  2921. rttilist^.concat(new(pai_const,init_8bit(length(ppropertysym(sym)^.name))));
  2922. rttilist^.concat(new(pai_string,init(ppropertysym(sym)^.name)));
  2923. end;
  2924. end;
  2925. procedure generate_published_child_rtti(sym : pnamedindexobject);
  2926. {$ifndef fpc}far;{$endif}
  2927. begin
  2928. if (psym(sym)^.typ=propertysym) and
  2929. ((psym(sym)^.properties and sp_published)<>0) then
  2930. ppropertysym(sym)^.proptype^.get_rtti_label;
  2931. end;
  2932. procedure tobjectdef.write_child_rtti_data;
  2933. begin
  2934. publicsyms^.foreach({$ifndef TP}@{$endif}generate_published_child_rtti);
  2935. end;
  2936. procedure tobjectdef.generate_rtti;
  2937. begin
  2938. has_rtti:=true;
  2939. getdatalabel(rtti_label);
  2940. write_child_rtti_data;
  2941. rttilist^.concat(new(pai_symbol,initname_global(rtti_name,0)));
  2942. rttilist^.concat(new(pai_label,init(rtti_label)));
  2943. write_rtti_data;
  2944. rttilist^.concat(new(pai_symbol_end,initname(rtti_name)));
  2945. end;
  2946. function tobjectdef.next_free_name_index : longint;
  2947. var
  2948. i : longint;
  2949. begin
  2950. if assigned(childof) and ((childof^.options and oo_can_have_published)<>0) then
  2951. i:=childof^.next_free_name_index
  2952. else
  2953. i:=0;
  2954. count:=0;
  2955. publicsyms^.foreach({$ifndef TP}@{$endif}count_published_properties);
  2956. next_free_name_index:=i+count;
  2957. end;
  2958. procedure tobjectdef.write_rtti_data;
  2959. begin
  2960. if isclass then
  2961. rttilist^.concat(new(pai_const,init_8bit(tkclass)))
  2962. else
  2963. rttilist^.concat(new(pai_const,init_8bit(tkobject)));
  2964. { generate the name }
  2965. rttilist^.concat(new(pai_const,init_8bit(length(objname^))));
  2966. rttilist^.concat(new(pai_string,init(objname^)));
  2967. { write class type }
  2968. rttilist^.concat(new(pai_const_symbol,initname(vmt_mangledname)));
  2969. { write owner typeinfo }
  2970. if assigned(childof) and ((childof^.options and oo_can_have_published)<>0) then
  2971. rttilist^.concat(new(pai_const_symbol,initname(childof^.get_rtti_label)))
  2972. else
  2973. rttilist^.concat(new(pai_const,init_32bit(0)));
  2974. { count total number of properties }
  2975. if assigned(childof) and ((childof^.options and oo_can_have_published)<>0) then
  2976. count:=childof^.next_free_name_index
  2977. else
  2978. count:=0;
  2979. { write it }
  2980. publicsyms^.foreach({$ifndef TP}@{$endif}count_published_properties);
  2981. rttilist^.concat(new(pai_const,init_16bit(count)));
  2982. { write unit name }
  2983. if assigned(owner^.name) then
  2984. begin
  2985. rttilist^.concat(new(pai_const,init_8bit(length(owner^.name^))));
  2986. rttilist^.concat(new(pai_string,init(owner^.name^)));
  2987. end
  2988. else
  2989. rttilist^.concat(new(pai_const,init_8bit(0)));
  2990. { write published properties count }
  2991. count:=0;
  2992. publicsyms^.foreach({$ifndef TP}@{$endif}count_published_properties);
  2993. rttilist^.concat(new(pai_const,init_16bit(count)));
  2994. { count is used to write nameindex }
  2995. { but we need an offset of the owner }
  2996. { to give each property an own slot }
  2997. if assigned(childof) and ((childof^.options and oo_can_have_published)<>0) then
  2998. count:=childof^.next_free_name_index
  2999. else
  3000. count:=0;
  3001. publicsyms^.foreach({$ifndef TP}@{$endif}write_property_info);
  3002. end;
  3003. function tobjectdef.is_publishable : boolean;
  3004. begin
  3005. is_publishable:=isclass;
  3006. end;
  3007. function tobjectdef.get_rtti_label : string;
  3008. begin
  3009. get_rtti_label:=rtti_name;
  3010. end;
  3011. {****************************************************************************
  3012. TERRORDEF
  3013. ****************************************************************************}
  3014. constructor terrordef.init;
  3015. begin
  3016. inherited init;
  3017. deftype:=errordef;
  3018. end;
  3019. {$ifdef GDB}
  3020. function terrordef.stabstring : pchar;
  3021. begin
  3022. stabstring:=strpnew('error'+numberstring);
  3023. end;
  3024. {$endif GDB}
  3025. function terrordef.gettypename:string;
  3026. begin
  3027. gettypename:='<erroneous type>';
  3028. end;
  3029. {
  3030. $Log$
  3031. Revision 1.137 1999-07-31 22:37:17 michael
  3032. * Fix of initialization information generation
  3033. Revision 1.136 1999/07/29 20:54:07 peter
  3034. * write .size also
  3035. Revision 1.135 1999/07/27 23:42:18 peter
  3036. * indirect type referencing is now allowed
  3037. Revision 1.134 1999/07/23 23:07:03 peter
  3038. * fixed stabs for record which still used savesize
  3039. Revision 1.133 1999/07/23 16:05:28 peter
  3040. * alignment is now saved in the symtable
  3041. * C alignment added for records
  3042. * PPU version increased to solve .12 <-> .13 probs
  3043. Revision 1.132 1999/07/18 14:47:32 florian
  3044. * bug 487 fixed, (inc(<property>) isn't allowed)
  3045. * more fixes to compile with Delphi
  3046. Revision 1.131 1999/07/06 21:48:27 florian
  3047. * a lot bug fixes:
  3048. - po_external isn't any longer necessary for procedure compatibility
  3049. - m_tp_procvar is in -Sd now available
  3050. - error messages of procedure variables improved
  3051. - return values with init./finalization fixed
  3052. - data types with init./finalization aren't any longer allowed in variant
  3053. record
  3054. Revision 1.130 1999/06/22 16:24:44 pierre
  3055. * local browser stuff corrected
  3056. Revision 1.129 1999/06/02 22:44:21 pierre
  3057. * previous wrong log corrected
  3058. Revision 1.128 1999/06/02 22:25:52 pierre
  3059. * changed $ifdef FPC @ into $ifndef TP
  3060. Revision 1.127 1999/06/02 10:26:50 florian
  3061. * corrected order of parameter type for -vb
  3062. Revision 1.126 1999/06/02 10:11:50 florian
  3063. * make cycle fixed i.e. compilation with 0.99.10
  3064. * some fixes for qword
  3065. * start of register calling conventions
  3066. Revision 1.125 1999/06/01 14:45:56 peter
  3067. * @procvar is now always needed for FPC
  3068. Revision 1.124 1999/05/31 16:42:33 peter
  3069. * interfacedef flag for procdef if it's defined in the interface, to
  3070. make a difference with 'forward;' directive forwarddef. Fixes 253
  3071. Revision 1.123 1999/05/27 19:45:02 peter
  3072. * removed oldasm
  3073. * plabel -> pasmlabel
  3074. * -a switches to source writing automaticly
  3075. * assembler readers OOPed
  3076. * asmsymbol automaticly external
  3077. * jumptables and other label fixes for asm readers
  3078. Revision 1.122 1999/05/23 18:42:14 florian
  3079. * better error recovering in typed constants
  3080. * some problems with arrays of const fixed, some problems
  3081. due my previous
  3082. - the location type of array constructor is now LOC_MEM
  3083. - the pushing of high fixed
  3084. - parameter copying fixed
  3085. - zero temp. allocation removed
  3086. * small problem in the assembler writers fixed:
  3087. ref to nil wasn't written correctly
  3088. Revision 1.121 1999/05/21 13:55:19 peter
  3089. * NEWLAB for label as symbol
  3090. Revision 1.120 1999/05/20 22:22:43 pierre
  3091. + added synonym filed for ttypesym
  3092. allows a clean disposal of tdefs and related ttypesyms
  3093. Revision 1.119 1999/05/19 16:48:26 florian
  3094. * tdef.typename: returns a now a proper type name for the most types
  3095. Revision 1.118 1999/05/19 12:08:11 florian
  3096. * tobject wasn't set as default anchestor, was a problem with the new ppu
  3097. handling
  3098. Revision 1.117 1999/05/17 21:57:15 florian
  3099. * new temporary ansistring handling
  3100. Revision 1.116 1999/05/16 02:26:51 peter
  3101. * fixed loading of classrefdef
  3102. Revision 1.115 1999/05/14 17:52:26 peter
  3103. * new deref code
  3104. Revision 1.114 1999/05/13 21:59:41 peter
  3105. * removed oldppu code
  3106. * warning if objpas is loaded from uses
  3107. * first things for new deref writing
  3108. Revision 1.113 1999/05/12 00:19:58 peter
  3109. * removed R_DEFAULT_SEG
  3110. * uniform float names
  3111. Revision 1.112 1999/05/08 19:52:35 peter
  3112. + MessagePos() which is enhanced Message() function but also gets the
  3113. position info
  3114. * Removed comp warnings
  3115. Revision 1.111 1999/05/07 11:06:37 florian
  3116. * enumeration type names are now written in lowercase (rtti)
  3117. Revision 1.110 1999/05/06 09:05:28 peter
  3118. * generic write_float and str_float
  3119. * fixed constant float conversions
  3120. Revision 1.109 1999/05/05 10:05:56 florian
  3121. * a delphi compiled compiler recompiles ppc
  3122. Revision 1.108 1999/04/28 22:30:52 pierre
  3123. * delete -> deleteindex in tdef.correct_owner_symtable
  3124. Revision 1.107 1999/04/28 06:02:11 florian
  3125. * changes of Bruessel:
  3126. + message handler can now take an explicit self
  3127. * typinfo fixed: sometimes the type names weren't written
  3128. * the type checking for pointer comparisations and subtraction
  3129. and are now more strict (was also buggy)
  3130. * small bug fix to link.pas to support compiling on another
  3131. drive
  3132. * probable bug in popt386 fixed: call/jmp => push/jmp
  3133. transformation didn't count correctly the jmp references
  3134. + threadvar support
  3135. * warning if ln/sqrt gets an invalid constant argument
  3136. Revision 1.106 1999/04/26 18:30:01 peter
  3137. * farpointerdef moved into pointerdef.is_far
  3138. Revision 1.105 1999/04/26 13:31:47 peter
  3139. * release storenumber,double_checksum
  3140. Revision 1.104 1999/04/21 09:43:50 peter
  3141. * storenumber works
  3142. * fixed some typos in double_checksum
  3143. + incompatible types type1 and type2 message (with storenumber)
  3144. Revision 1.103 1999/04/19 09:28:20 peter
  3145. * fixed crash when writing overload operator to ppu
  3146. Revision 1.102 1999/04/17 22:01:28 pierre
  3147. * typo error fix in STORENUMBER code
  3148. Revision 1.101 1999/04/14 09:14:58 peter
  3149. * first things to store the symbol/def number in the ppu
  3150. Revision 1.100 1999/04/08 15:57:51 peter
  3151. + subrange checking for readln()
  3152. Revision 1.99 1999/04/07 15:39:32 pierre
  3153. + double_checksum code added
  3154. Revision 1.98 1999/03/06 17:24:16 peter
  3155. * reset savesize in tdef.init
  3156. Revision 1.97 1999/03/01 13:45:04 pierre
  3157. + added staticppusymtable symtable type for local browsing
  3158. Revision 1.96 1999/02/25 21:02:52 peter
  3159. * ag386bin updates
  3160. + coff writer
  3161. Revision 1.95 1999/02/23 18:29:23 pierre
  3162. * win32 compilation error fix
  3163. + some work for local browser (not cl=omplete yet)
  3164. Revision 1.94 1999/02/22 20:13:38 florian
  3165. + first implementation of message keyword
  3166. Revision 1.93 1999/02/22 13:07:07 pierre
  3167. + -b and -bl options work !
  3168. + cs_local_browser ($L+) is disabled if cs_browser ($Y+)
  3169. is not enabled when quitting global section
  3170. * local vars and procedures are not yet stored into PPU
  3171. Revision 1.92 1999/02/17 10:14:20 peter
  3172. * set the first enumsym also for subrange types
  3173. Revision 1.91 1999/02/08 09:51:21 pierre
  3174. * gdb info for local functions was wrong
  3175. Revision 1.90 1999/01/26 09:57:29 pierre
  3176. * open arrays stabs changed
  3177. Revision 1.89 1999/01/22 17:29:30 pierre
  3178. * overflow in addname for open arrays removed
  3179. Revision 1.88 1999/01/20 14:18:39 pierre
  3180. * bugs related to mangledname solved
  3181. - linux external without name
  3182. -external procs already used
  3183. (added count and is_used boolean fiels in tprocvar)
  3184. Revision 1.87 1999/01/19 10:56:05 pierre
  3185. typeof(object) without vmt generates an error instead of an internalerror
  3186. Revision 1.86 1999/01/12 14:25:32 peter
  3187. + BrowserLog for browser.log generation
  3188. + BrowserCol for browser info in TCollections
  3189. * released all other UseBrowser
  3190. Revision 1.85 1998/12/30 22:15:52 peter
  3191. + farpointer type
  3192. * absolutesym now also stores if its far
  3193. Revision 1.84 1998/12/30 13:41:12 peter
  3194. * released valuepara
  3195. Revision 1.83 1998/12/21 14:03:08 pierre
  3196. * procvar stabs correction
  3197. Revision 1.82 1998/12/19 00:23:52 florian
  3198. * ansistring memory leaks fixed
  3199. Revision 1.81 1998/12/11 08:57:22 pierre
  3200. * internal gdb types for booleans and 64bit integers
  3201. Revision 1.80 1998/12/10 09:47:26 florian
  3202. + basic operations with int64/qord (compiler with -dint64)
  3203. + rtti of enumerations extended: names are now written
  3204. Revision 1.79 1998/12/08 10:18:12 peter
  3205. + -gh for heaptrc unit
  3206. Revision 1.78 1998/12/08 09:06:30 pierre
  3207. + constructor destructor info for gdbpas
  3208. Revision 1.77 1998/12/01 23:37:39 pierre
  3209. * function type problem for gdb fix
  3210. Revision 1.76 1998/11/29 21:45:48 florian
  3211. * problem with arrays with init tables fixed
  3212. Revision 1.75 1998/11/29 12:45:59 peter
  3213. * hack for arraydef.size overflow
  3214. Revision 1.74 1998/11/27 14:50:47 peter
  3215. + open strings, $P switch support
  3216. Revision 1.73 1998/11/26 14:47:00 michael
  3217. + Fixed RTTI constants
  3218. Revision 1.72 1998/11/25 14:35:28 florian
  3219. * writting of rtti for properties fixed
  3220. Revision 1.71 1998/11/20 15:35:59 florian
  3221. * problems with rtti fixed, hope it works
  3222. Revision 1.70 1998/11/18 15:44:16 peter
  3223. * VALUEPARA for tp7 compatible value parameters
  3224. Revision 1.69 1998/11/10 17:54:56 peter
  3225. * removed warning
  3226. Revision 1.68 1998/11/05 23:34:36 peter
  3227. * don't dispose staticsymtable (caused crash under tp7 after a fatal
  3228. error)
  3229. Revision 1.67 1998/11/05 12:02:56 peter
  3230. * released useansistring
  3231. * removed -Sv, its now available in fpc modes
  3232. Revision 1.66 1998/10/26 22:58:22 florian
  3233. * new introduded problem with classes fix, the parent class wasn't set
  3234. correct, if the class was defined forward before
  3235. Revision 1.65 1998/10/26 14:19:28 pierre
  3236. + added options -lS and -lT for source and target os output
  3237. (to have a easier way to test OS_SOURCE abd OS_TARGET in makefiles)
  3238. * several problems with rtti data
  3239. (type of sym was not checked)
  3240. assumed to be varsym when they could be procsym or property syms !!
  3241. Revision 1.64 1998/10/22 17:11:21 pierre
  3242. + terminated the include exclude implementation for i386
  3243. * enums inside records fixed
  3244. Revision 1.63 1998/10/20 09:32:56 peter
  3245. * removed some unused vars
  3246. Revision 1.62 1998/10/20 08:06:58 pierre
  3247. * several memory corruptions due to double freemem solved
  3248. => never use p^.loc.location:=p^.left^.loc.location;
  3249. + finally I added now by default
  3250. that ra386dir translates global and unit symbols
  3251. + added a first field in tsymtable and
  3252. a nextsym field in tsym
  3253. (this allows to obtain ordered type info for
  3254. records and objects in gdb !)
  3255. Revision 1.61 1998/10/19 08:55:05 pierre
  3256. * wrong stabs info corrected once again !!
  3257. + variable vmt offset with vmt field only if required
  3258. implemented now !!!
  3259. Revision 1.60 1998/10/16 13:12:53 pierre
  3260. * added vmt_offsets in destructors code also !!!
  3261. * vmt_offset code for m68k
  3262. Revision 1.59 1998/10/16 08:51:51 peter
  3263. + target_os.stackalignment
  3264. + stack can be aligned at 2 or 4 byte boundaries
  3265. Revision 1.58 1998/10/15 15:13:30 pierre
  3266. + added oo_hasconstructor and oo_hasdestructor
  3267. for objects options
  3268. Revision 1.57 1998/10/14 15:54:20 pierre
  3269. * smallsets are not entirely implemented for
  3270. m68k added a ifdef usesmallset
  3271. that is allways defined for i386
  3272. (enables testing for m68k)
  3273. Revision 1.56 1998/10/09 11:47:56 pierre
  3274. * still more memory leaks fixes !!
  3275. Revision 1.55 1998/10/06 17:16:55 pierre
  3276. * some memory leaks fixed (thanks to Peter for heaptrc !)
  3277. Revision 1.54 1998/10/05 21:33:28 peter
  3278. * fixed 161,165,166,167,168
  3279. Revision 1.53 1998/10/05 12:48:39 pierre
  3280. * wrong handling of range check for arrays fixed
  3281. Revision 1.52 1998/10/02 07:20:38 florian
  3282. * range checking in units doesn't work if the units are smartlinked, fixed
  3283. Revision 1.51 1998/09/25 12:01:41 florian
  3284. * tobjectdef.publicsyms.datasize was set to savesize, this is wrong now
  3285. because the symtable size is read from the ppu file
  3286. Revision 1.50 1998/09/23 15:46:40 florian
  3287. * problem with with and classes fixed
  3288. Revision 1.49 1998/09/23 12:03:55 peter
  3289. * overloading fix for array of const
  3290. Revision 1.48 1998/09/22 15:37:23 peter
  3291. + array of const start
  3292. Revision 1.47 1998/09/21 15:46:01 michael
  3293. Applied florians fix for check_rec_inittable
  3294. Revision 1.46 1998/09/21 08:45:21 pierre
  3295. + added vmt_offset in tobjectdef.write for fututre use
  3296. (first steps to have objects without vmt if no virtual !!)
  3297. + added fpu_used field for tabstractprocdef :
  3298. sets this level to 2 if the functions return with value in FPU
  3299. (is then set to correct value at parsing of implementation)
  3300. THIS MIGHT refuse some code with FPU expression too complex
  3301. that were accepted before and even in some cases
  3302. that don't overflow in fact
  3303. ( like if f : float; is a forward that finally in implementation
  3304. only uses one fpu register !!)
  3305. Nevertheless I think that it will improve security on
  3306. FPU operations !!
  3307. * most other changes only for UseBrowser code
  3308. (added symtable references for record and objects)
  3309. local switch for refs to args and local of each function
  3310. (static symtable still missing)
  3311. UseBrowser still not stable and probably broken by
  3312. the definition hash array !!
  3313. Revision 1.45 1998/09/20 08:31:29 florian
  3314. + bit 6 of tpropinfo.propprocs is set, if the property contains a
  3315. constant index
  3316. Revision 1.44 1998/09/19 15:23:58 florian
  3317. * rtti for ordtypes corrected
  3318. Revision 1.43 1998/09/18 17:12:40 florian
  3319. * problem with writing of class references fixed
  3320. Revision 1.42 1998/09/17 13:41:20 pierre
  3321. sizeof(TPOINT) problem
  3322. Revision 1.40.2.2 1998/09/17 08:42:33 pierre
  3323. TPOINT sizeof fix
  3324. Revision 1.41 1998/09/15 17:39:30 jonas
  3325. + bugfix from bugfix branch
  3326. Revision 1.40.2.1 1998/09/15 17:35:32 jonas
  3327. * chenged string_typ in tstringdef.wideload from ansistring to widestring
  3328. Revision 1.40 1998/09/09 15:34:00 peter
  3329. * removed warnings
  3330. Revision 1.39 1998/09/08 10:23:44 pierre
  3331. * name field of filedef corrected
  3332. Revision 1.38 1998/09/07 23:10:23 florian
  3333. * a lot of stuff fixed regarding rtti and publishing of properties,
  3334. basics should now work
  3335. Revision 1.37 1998/09/07 19:33:24 florian
  3336. + some stuff for property rtti added:
  3337. - NameIndex of the TPropInfo record is now written correctly
  3338. - the DEFAULT/NODEFAULT keyword is supported now
  3339. - the default value and the storedsym/def are now written to
  3340. the PPU fiel
  3341. Revision 1.36 1998/09/07 17:37:01 florian
  3342. * first fixes for published properties
  3343. Revision 1.35 1998/09/06 22:42:02 florian
  3344. + rtti genreation for properties added
  3345. Revision 1.34 1998/09/04 18:15:02 peter
  3346. * filedef updated
  3347. Revision 1.33 1998/09/03 17:08:49 pierre
  3348. * better lines for stabs
  3349. (no scroll back to if before else part
  3350. no return to case line at jump outside case)
  3351. + source lines also if not in order
  3352. Revision 1.32 1998/09/03 16:03:20 florian
  3353. + rtti generation
  3354. * init table generation changed
  3355. Revision 1.31 1998/09/02 15:14:28 peter
  3356. * enum packing changed from len to max
  3357. Revision 1.30 1998/09/01 17:37:29 peter
  3358. * removed debug writeln :(
  3359. Revision 1.29 1998/09/01 12:53:25 peter
  3360. + aktpackenum
  3361. Revision 1.28 1998/09/01 07:54:22 pierre
  3362. * UseBrowser a little updated (might still be buggy !!)
  3363. * bug in psub.pas in function specifier removed
  3364. * stdcall allowed in interface and in implementation
  3365. (FPC will not yet complain if it is missing in either part
  3366. because stdcall is only a dummy !!)
  3367. Revision 1.27 1998/08/28 12:51:43 florian
  3368. + ansistring to pchar type cast fixed
  3369. Revision 1.26 1998/08/25 12:42:44 pierre
  3370. * CDECL changed to CVAR for variables
  3371. specifications are read in structures also
  3372. + started adding GPC compatibility mode ( option -Sp)
  3373. * names changed to lowercase
  3374. Revision 1.25 1998/08/23 21:04:38 florian
  3375. + rtti generation for classes added
  3376. + new/dispose do now also a call to INITIALIZE/FINALIZE, if necessaray
  3377. Revision 1.24 1998/08/20 12:53:26 peter
  3378. * object_options are always written for object syms
  3379. Revision 1.23 1998/08/19 00:42:42 peter
  3380. + subrange types for enums
  3381. + checking for bounds type with ranges
  3382. Revision 1.22 1998/08/17 10:10:10 peter
  3383. - removed OLDPPU
  3384. Revision 1.21 1998/08/10 14:50:28 peter
  3385. + localswitches, moduleswitches, globalswitches splitting
  3386. Revision 1.20 1998/07/18 22:54:30 florian
  3387. * some ansi/wide/longstring support fixed:
  3388. o parameter passing
  3389. o returning as result from functions
  3390. Revision 1.19 1998/07/14 14:47:05 peter
  3391. * released NEWINPUT
  3392. Revision 1.18 1998/07/10 10:51:04 peter
  3393. * m68k updates
  3394. Revision 1.16 1998/07/07 11:20:13 peter
  3395. + NEWINPUT for a better inputfile and scanner object
  3396. Revision 1.15 1998/06/24 14:48:37 peter
  3397. * ifdef newppu -> ifndef oldppu
  3398. Revision 1.14 1998/06/16 08:56:31 peter
  3399. + targetcpu
  3400. * cleaner pmodules for newppu
  3401. Revision 1.13 1998/06/15 15:38:09 pierre
  3402. * small bug in systems.pas corrected
  3403. + operators in different units better hanlded
  3404. Revision 1.12 1998/06/15 14:30:12 daniel
  3405. * Reverted my changes.
  3406. Revision 1.10 1998/06/13 00:10:16 peter
  3407. * working browser and newppu
  3408. * some small fixes against crashes which occured in bp7 (but not in
  3409. fpc?!)
  3410. Revision 1.9 1998/06/12 14:10:37 michael
  3411. * Fixed wrong code for ansistring
  3412. Revision 1.8 1998/06/11 10:11:58 peter
  3413. * -gb works again
  3414. Revision 1.7 1998/06/07 15:30:25 florian
  3415. + first working rtti
  3416. + data init/final. for local variables
  3417. Revision 1.6 1998/06/05 14:37:37 pierre
  3418. * fixes for inline for operators
  3419. * inline procedure more correctly restricted
  3420. Revision 1.5 1998/06/04 23:52:01 peter
  3421. * m68k compiles
  3422. + .def file creation moved to gendef.pas so it could also be used
  3423. for win32
  3424. Revision 1.4 1998/06/04 09:55:45 pierre
  3425. * demangled name of procsym reworked to become independant of the mangling
  3426. scheme
  3427. Revision 1.3 1998/06/03 22:49:03 peter
  3428. + wordbool,longbool
  3429. * rename bis,von -> high,low
  3430. * moved some systemunit loading/creating to psystem.pas
  3431. Revision 1.2 1998/05/31 14:13:37 peter
  3432. * fixed call bugs with assembler readers
  3433. + OPR_SYMBOL to hold a symbol in the asm parser
  3434. * fixed staticsymtable vars which were acessed through %ebp instead of
  3435. name
  3436. Revision 1.1 1998/05/27 19:45:09 peter
  3437. * symtable.pas splitted into includefiles
  3438. * symtable adapted for $ifndef OLDPPU
  3439. }