symdef.inc 113 KB

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