symdef.inc 112 KB

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