symsym.pas 82 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787
  1. {
  2. Copyright (c) 1998-2002 by Florian Klaempfl, Pierre Muller
  3. Implementation for the symbols types of the symtable
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. }
  17. unit symsym;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. { common }
  22. cutils,
  23. { target }
  24. globtype,globals,widestr,
  25. { symtable }
  26. symconst,symbase,symtype,symdef,defcmp,
  27. { ppu }
  28. ppu,
  29. cclasses,symnot,
  30. { aasm }
  31. aasmbase,aasmtai,
  32. cpuinfo,cpubase,cgbase,cgutils,parabase,
  33. node
  34. ;
  35. type
  36. { this class is the base for all symbol objects }
  37. tstoredsym = class(tsym)
  38. public
  39. constructor create(const n : string);
  40. constructor ppuload(ppufile:tcompilerppufile);
  41. destructor destroy;override;
  42. procedure ppuwrite(ppufile:tcompilerppufile);virtual;
  43. {$ifdef GDB}
  44. function get_var_value(const s:string):string;
  45. function stabstr_evaluate(const s:string;vars:array of string):Pchar;
  46. procedure concatstabto(asmlist : taasmoutput);
  47. {$endif GDB}
  48. function mangledname : string; virtual;
  49. end;
  50. tlabelsym = class(tstoredsym)
  51. used,
  52. defined : boolean;
  53. { points to the matching node, only valid resulttype pass is run and
  54. the goto<->label relation in the node tree is created, should
  55. be a tnode }
  56. code : pointer;
  57. { when the label is defined in an asm block, this points to the
  58. generated asmlabel }
  59. asmblocklabel : tasmlabel;
  60. constructor create(const n : string);
  61. constructor ppuload(ppufile:tcompilerppufile);
  62. procedure ppuwrite(ppufile:tcompilerppufile);override;
  63. {$ifdef GDB}
  64. function stabstring : pchar;override;
  65. {$endif GDB}
  66. function mangledname:string;override;
  67. end;
  68. tunitsym = class(Tstoredsym)
  69. unitsymtable : tsymtable;
  70. constructor create(const n : string;ref : tsymtable);
  71. constructor ppuload(ppufile:tcompilerppufile);
  72. destructor destroy;override;
  73. procedure ppuwrite(ppufile:tcompilerppufile);override;
  74. end;
  75. terrorsym = class(Tsym)
  76. constructor create;
  77. end;
  78. Tprocdefcallback = procedure(p:Tprocdef;arg:pointer);
  79. tprocsym = class(tstoredsym)
  80. protected
  81. pdlistfirst,
  82. pdlistlast : pprocdeflist; { linked list of overloaded procdefs }
  83. function getprocdef(nr:cardinal):Tprocdef;
  84. public
  85. procdef_count : byte;
  86. {$ifdef GDB}
  87. is_global : boolean;
  88. {$endif GDB}
  89. overloadchecked : boolean;
  90. property procdef[nr:cardinal]:Tprocdef read getprocdef;
  91. constructor create(const n : string);
  92. constructor ppuload(ppufile:tcompilerppufile);
  93. destructor destroy;override;
  94. { writes all declarations except the specified one }
  95. procedure write_parameter_lists(skipdef:tprocdef);
  96. { tests, if all procedures definitions are defined and not }
  97. { only forward }
  98. procedure check_forward;
  99. procedure unchain_overload;
  100. procedure ppuwrite(ppufile:tcompilerppufile);override;
  101. procedure buildderef;override;
  102. procedure deref;override;
  103. procedure addprocdef(p:tprocdef);
  104. procedure addprocdef_deref(const d:tderef);
  105. procedure add_para_match_to(Aprocsym:Tprocsym;cpoptions:tcompare_paras_options);
  106. procedure concat_procdefs_to(s:Tprocsym);
  107. procedure foreach_procdef_static(proc2call:Tprocdefcallback;arg:pointer);
  108. function first_procdef:Tprocdef;
  109. function last_procdef:Tprocdef;
  110. function search_procdef_nopara_boolret:Tprocdef;
  111. function search_procdef_bytype(pt:Tproctypeoption):Tprocdef;
  112. function search_procdef_bypara(para:tlist;retdef:tdef;cpoptions:tcompare_paras_options):Tprocdef;
  113. function search_procdef_byprocvardef(d:Tprocvardef):Tprocdef;
  114. function search_procdef_assignment_operator(fromdef,todef:tdef;var besteq:tequaltype):Tprocdef;
  115. function write_references(ppufile:tcompilerppufile;locals:boolean):boolean;override;
  116. { currobjdef is the object def to assume, this is necessary for protected and
  117. private,
  118. context is the object def we're really in, this is for the strict stuff
  119. }
  120. function is_visible_for_object(currobjdef:tdef;context:tdef):boolean;override;
  121. {$ifdef GDB}
  122. function stabstring : pchar;override;
  123. {$endif GDB}
  124. end;
  125. ttypesym = class(Tstoredsym)
  126. restype : ttype;
  127. constructor create(const n : string;const tt : ttype);
  128. constructor ppuload(ppufile:tcompilerppufile);
  129. procedure ppuwrite(ppufile:tcompilerppufile);override;
  130. procedure buildderef;override;
  131. procedure deref;override;
  132. function gettypedef:tdef;override;
  133. procedure load_references(ppufile:tcompilerppufile;locals:boolean);override;
  134. function write_references(ppufile:tcompilerppufile;locals:boolean):boolean;override;
  135. {$ifdef GDB}
  136. function stabstring : pchar;override;
  137. {$endif GDB}
  138. end;
  139. tabstractvarsym = class(tstoredsym)
  140. varoptions : tvaroptions;
  141. varspez : tvarspez; { sets the type of access }
  142. varregable : tvarregable;
  143. varstate : tvarstate;
  144. notifications : Tlinkedlist;
  145. constructor create(const n : string;vsp:tvarspez;const tt : ttype;vopts:tvaroptions);
  146. constructor ppuload(ppufile:tcompilerppufile);
  147. destructor destroy;override;
  148. procedure ppuwrite(ppufile:tcompilerppufile);override;
  149. procedure buildderef;override;
  150. procedure deref;override;
  151. function getsize : longint;
  152. function is_regvar:boolean;
  153. procedure trigger_notifications(what:Tnotification_flag);
  154. function register_notification(flags:Tnotification_flags;
  155. callback:Tnotification_callback):cardinal;
  156. procedure unregister_notification(id:cardinal);
  157. private
  158. procedure setvartype(const newtype: ttype);
  159. _vartype : ttype;
  160. public
  161. property vartype: ttype read _vartype write setvartype;
  162. end;
  163. tfieldvarsym = class(tabstractvarsym)
  164. fieldoffset : aint; { offset in record/object }
  165. constructor create(const n : string;vsp:tvarspez;const tt : ttype;vopts:tvaroptions);
  166. constructor ppuload(ppufile:tcompilerppufile);
  167. procedure ppuwrite(ppufile:tcompilerppufile);override;
  168. {$ifdef GDB}
  169. function stabstring : pchar;override;
  170. {$endif GDB}
  171. function mangledname:string;override;
  172. end;
  173. tabstractnormalvarsym = class(tabstractvarsym)
  174. defaultconstsym : tsym;
  175. defaultconstsymderef : tderef;
  176. localloc : TLocation; { register/reference for local var }
  177. constructor create(const n : string;vsp:tvarspez;const tt : ttype;vopts:tvaroptions);
  178. constructor ppuload(ppufile:tcompilerppufile);
  179. procedure ppuwrite(ppufile:tcompilerppufile);override;
  180. procedure buildderef;override;
  181. procedure deref;override;
  182. end;
  183. tlocalvarsym = class(tabstractnormalvarsym)
  184. constructor create(const n : string;vsp:tvarspez;const tt : ttype;vopts:tvaroptions);
  185. constructor ppuload(ppufile:tcompilerppufile);
  186. procedure ppuwrite(ppufile:tcompilerppufile);override;
  187. {$ifdef GDB}
  188. function stabstring : pchar;override;
  189. {$endif GDB}
  190. end;
  191. tdefinitionsym = class(tabstractnormalvarsym)
  192. expr : tnode;
  193. constructor create(const n : string; const tt : ttype; aexpr : tnode);
  194. destructor destroy;
  195. end;
  196. tspecvarsym = class(tlocalvarsym)
  197. expr : tnode;
  198. constructor create(const n : string; const tt : ttype; aexpr : tnode);
  199. destructor destroy;
  200. end;
  201. tparavarsym = class(tabstractnormalvarsym)
  202. paraloc : array[tcallercallee] of TCGPara;
  203. paranr : word; { position of this parameter }
  204. {$ifdef EXTDEBUG}
  205. eqval : tequaltype;
  206. {$endif EXTDEBUG}
  207. constructor create(const n : string;nr:word;vsp:tvarspez;const tt : ttype;vopts:tvaroptions);
  208. constructor ppuload(ppufile:tcompilerppufile);
  209. destructor destroy;override;
  210. procedure ppuwrite(ppufile:tcompilerppufile);override;
  211. {$ifdef GDB}
  212. function stabstring : pchar;override;
  213. {$endif GDB}
  214. end;
  215. tglobalvarsym = class(tabstractnormalvarsym)
  216. private
  217. _mangledname : pstring;
  218. public
  219. constructor create(const n : string;vsp:tvarspez;const tt : ttype;vopts:tvaroptions);
  220. constructor create_dll(const n : string;vsp:tvarspez;const tt : ttype);
  221. constructor create_C(const n,mangled : string;vsp:tvarspez;const tt : ttype);
  222. constructor ppuload(ppufile:tcompilerppufile);
  223. destructor destroy;override;
  224. procedure ppuwrite(ppufile:tcompilerppufile);override;
  225. function mangledname:string;override;
  226. procedure set_mangledname(const s:string);
  227. {$ifdef GDB}
  228. function stabstring : pchar;override;
  229. {$endif GDB}
  230. end;
  231. tabsolutevarsym = class(tabstractvarsym)
  232. public
  233. abstyp : absolutetyp;
  234. {$ifdef i386}
  235. absseg : boolean;
  236. {$endif i386}
  237. asmname : pstring;
  238. addroffset : aint;
  239. ref : tsymlist;
  240. constructor create(const n : string;const tt : ttype);
  241. constructor create_ref(const n : string;const tt : ttype;_ref:tsymlist);
  242. destructor destroy;override;
  243. constructor ppuload(ppufile:tcompilerppufile);
  244. procedure buildderef;override;
  245. procedure deref;override;
  246. function mangledname : string;override;
  247. procedure ppuwrite(ppufile:tcompilerppufile);override;
  248. {$ifdef gdb}
  249. function stabstring:Pchar;override;
  250. {$endif gdb}
  251. end;
  252. tpropertysym = class(Tstoredsym)
  253. propoptions : tpropertyoptions;
  254. propoverriden : tpropertysym;
  255. propoverridenderef : tderef;
  256. proptype,
  257. indextype : ttype;
  258. index,
  259. default : longint;
  260. readaccess,
  261. writeaccess,
  262. storedaccess : tsymlist;
  263. constructor create(const n : string);
  264. destructor destroy;override;
  265. constructor ppuload(ppufile:tcompilerppufile);
  266. function getsize : longint;
  267. procedure ppuwrite(ppufile:tcompilerppufile);override;
  268. function gettypedef:tdef;override;
  269. procedure buildderef;override;
  270. procedure deref;override;
  271. procedure derefimpl;override;
  272. procedure dooverride(overriden:tpropertysym);
  273. end;
  274. ttypedconstsym = class(tstoredsym)
  275. private
  276. _mangledname : pstring;
  277. public
  278. typedconsttype : ttype;
  279. is_writable : boolean;
  280. constructor create(const n : string;p : tdef;writable : boolean);
  281. constructor createtype(const n : string;const tt : ttype;writable : boolean);
  282. constructor ppuload(ppufile:tcompilerppufile);
  283. destructor destroy;override;
  284. function mangledname : string;override;
  285. procedure ppuwrite(ppufile:tcompilerppufile);override;
  286. procedure buildderef;override;
  287. procedure deref;override;
  288. function getsize:longint;
  289. {$ifdef GDB}
  290. function stabstring : pchar;override;
  291. {$endif GDB}
  292. end;
  293. tconstvalue = record
  294. case integer of
  295. 0: (valueord : tconstexprint);
  296. 1: (valueordptr : tconstptruint);
  297. 2: (valueptr : pointer; len : longint);
  298. end;
  299. tconstsym = class(tstoredsym)
  300. consttype : ttype;
  301. consttyp : tconsttyp;
  302. value : tconstvalue;
  303. resstrindex : longint; { needed for resource strings }
  304. constructor create_ord(const n : string;t : tconsttyp;v : tconstexprint;const tt:ttype);
  305. constructor create_ordptr(const n : string;t : tconsttyp;v : tconstptruint;const tt:ttype);
  306. constructor create_ptr(const n : string;t : tconsttyp;v : pointer;const tt:ttype);
  307. constructor create_string(const n : string;t : tconsttyp;str:pchar;l:longint);
  308. constructor create_wstring(const n : string;t : tconsttyp;pw:pcompilerwidestring);
  309. constructor ppuload(ppufile:tcompilerppufile);
  310. destructor destroy;override;
  311. procedure buildderef;override;
  312. procedure deref;override;
  313. procedure ppuwrite(ppufile:tcompilerppufile);override;
  314. {$ifdef GDB}
  315. function stabstring : pchar;override;
  316. {$endif GDB}
  317. end;
  318. tenumsym = class(Tstoredsym)
  319. value : longint;
  320. definition : tenumdef;
  321. definitionderef : tderef;
  322. nextenum : tenumsym;
  323. constructor create(const n : string;def : tenumdef;v : longint);
  324. constructor ppuload(ppufile:tcompilerppufile);
  325. procedure ppuwrite(ppufile:tcompilerppufile);override;
  326. procedure buildderef;override;
  327. procedure deref;override;
  328. procedure order;
  329. end;
  330. tsyssym = class(Tstoredsym)
  331. number : longint;
  332. constructor create(const n : string;l : longint);
  333. constructor ppuload(ppufile:tcompilerppufile);
  334. destructor destroy;override;
  335. procedure ppuwrite(ppufile:tcompilerppufile);override;
  336. end;
  337. const
  338. maxmacrolen=16*1024;
  339. type
  340. pmacrobuffer = ^tmacrobuffer;
  341. tmacrobuffer = array[0..maxmacrolen-1] of char;
  342. tmacro = class(tstoredsym)
  343. {Normally true, but false when a previously defined macro is undef-ed}
  344. defined : boolean;
  345. {True if this is a mac style compiler variable, in which case no macro
  346. substitutions shall be done.}
  347. is_compiler_var : boolean;
  348. {Whether the macro was used. NOTE: A use of a macro which was never defined}
  349. {e. g. an IFDEF which returns false, will not be registered as used,}
  350. {since there is no place to register its use. }
  351. is_used : boolean;
  352. buftext : pchar;
  353. buflen : longint;
  354. constructor create(const n : string);
  355. constructor ppuload(ppufile:tcompilerppufile);
  356. procedure ppuwrite(ppufile:tcompilerppufile);override;
  357. destructor destroy;override;
  358. end;
  359. { compiler generated symbol to point to rtti and init/finalize tables }
  360. trttisym = class(tstoredsym)
  361. private
  362. _mangledname : pstring;
  363. public
  364. lab : tasmsymbol;
  365. rttityp : trttitype;
  366. constructor create(const n:string;rt:trttitype);
  367. constructor ppuload(ppufile:tcompilerppufile);
  368. destructor destroy;override;
  369. procedure ppuwrite(ppufile:tcompilerppufile);override;
  370. function mangledname:string;override;
  371. function get_label:tasmsymbol;
  372. end;
  373. var
  374. generrorsym : tsym;
  375. implementation
  376. uses
  377. { global }
  378. verbose,
  379. { target }
  380. systems,
  381. { symtable }
  382. defutil,symtable,
  383. { aasm }
  384. {$ifdef gdb}
  385. gdb,
  386. {$endif gdb}
  387. { codegen }
  388. paramgr,cresstr,
  389. procinfo
  390. ;
  391. {****************************************************************************
  392. Helpers
  393. ****************************************************************************}
  394. {****************************************************************************
  395. TSYM (base for all symtypes)
  396. ****************************************************************************}
  397. constructor tstoredsym.create(const n : string);
  398. begin
  399. inherited create(n);
  400. end;
  401. constructor tstoredsym.ppuload(ppufile:tcompilerppufile);
  402. var
  403. nr : word;
  404. s : string;
  405. begin
  406. nr:=ppufile.getword;
  407. s:=ppufile.getstring;
  408. if s[1]='$' then
  409. inherited createname(copy(s,2,255))
  410. else
  411. inherited createname(upper(s));
  412. _realname:=stringdup(s);
  413. typ:=abstractsym;
  414. { force the correct indexnr. must be after create! }
  415. indexnr:=nr;
  416. ppufile.getposinfo(fileinfo);
  417. ppufile.getsmallset(symoptions);
  418. lastref:=nil;
  419. defref:=nil;
  420. refs:=0;
  421. lastwritten:=nil;
  422. refcount:=0;
  423. {$ifdef GDB}
  424. isstabwritten := false;
  425. {$endif GDB}
  426. end;
  427. procedure tstoredsym.ppuwrite(ppufile:tcompilerppufile);
  428. begin
  429. ppufile.putword(indexnr);
  430. ppufile.putstring(_realname^);
  431. ppufile.putposinfo(fileinfo);
  432. ppufile.putsmallset(symoptions);
  433. end;
  434. destructor tstoredsym.destroy;
  435. begin
  436. if assigned(defref) then
  437. begin
  438. {$ifdef MEMDEBUG}
  439. membrowser.start;
  440. {$endif MEMDEBUG}
  441. defref.freechain;
  442. defref.free;
  443. {$ifdef MEMDEBUG}
  444. membrowser.stop;
  445. {$endif MEMDEBUG}
  446. end;
  447. inherited destroy;
  448. end;
  449. {$ifdef GDB}
  450. function Tstoredsym.get_var_value(const s:string):string;
  451. begin
  452. if s='mangledname' then
  453. get_var_value:=mangledname
  454. else
  455. get_var_value:=inherited get_var_value(s);
  456. end;
  457. function Tstoredsym.stabstr_evaluate(const s:string;vars:array of string):Pchar;
  458. begin
  459. stabstr_evaluate:=string_evaluate(s,@get_var_value,vars);
  460. end;
  461. procedure tstoredsym.concatstabto(asmlist : taasmoutput);
  462. var
  463. stabstr : Pchar;
  464. begin
  465. stabstr:=stabstring;
  466. if stabstr<>nil then
  467. asmlist.concat(Tai_stabs.create(stabstr));
  468. end;
  469. {$endif GDB}
  470. function tstoredsym.mangledname : string;
  471. begin
  472. internalerror(200204171);
  473. end;
  474. {****************************************************************************
  475. TLABELSYM
  476. ****************************************************************************}
  477. constructor tlabelsym.create(const n : string);
  478. begin
  479. inherited create(n);
  480. typ:=labelsym;
  481. used:=false;
  482. defined:=false;
  483. code:=nil;
  484. end;
  485. constructor tlabelsym.ppuload(ppufile:tcompilerppufile);
  486. begin
  487. inherited ppuload(ppufile);
  488. typ:=labelsym;
  489. code:=nil;
  490. used:=false;
  491. defined:=true;
  492. end;
  493. procedure tlabelsym.ppuwrite(ppufile:tcompilerppufile);
  494. begin
  495. if owner.symtabletype=globalsymtable then
  496. Message(sym_e_ill_label_decl)
  497. else
  498. begin
  499. inherited ppuwrite(ppufile);
  500. ppufile.writeentry(iblabelsym);
  501. end;
  502. end;
  503. {$ifdef GDB}
  504. function Tlabelsym.stabstring : pchar;
  505. begin
  506. stabstring:=stabstr_evaluate('"${name}",${N_LSYM},0,${line},0',[]);
  507. end;
  508. {$endif GDB}
  509. function tlabelsym.mangledname:string;
  510. begin
  511. if not(defined) then
  512. begin
  513. defined:=true;
  514. objectlibrary.getlabel(asmblocklabel);
  515. end;
  516. result:=asmblocklabel.getname;
  517. end;
  518. {****************************************************************************
  519. TUNITSYM
  520. ****************************************************************************}
  521. constructor tunitsym.create(const n : string;ref : tsymtable);
  522. var
  523. old_make_ref : boolean;
  524. begin
  525. old_make_ref:=make_ref;
  526. make_ref:=false;
  527. inherited create(n);
  528. make_ref:=old_make_ref;
  529. typ:=unitsym;
  530. unitsymtable:=ref;
  531. end;
  532. constructor tunitsym.ppuload(ppufile:tcompilerppufile);
  533. begin
  534. inherited ppuload(ppufile);
  535. typ:=unitsym;
  536. unitsymtable:=nil;
  537. end;
  538. destructor tunitsym.destroy;
  539. begin
  540. inherited destroy;
  541. end;
  542. procedure tunitsym.ppuwrite(ppufile:tcompilerppufile);
  543. begin
  544. inherited ppuwrite(ppufile);
  545. ppufile.writeentry(ibunitsym);
  546. end;
  547. {****************************************************************************
  548. TPROCSYM
  549. ****************************************************************************}
  550. constructor tprocsym.create(const n : string);
  551. begin
  552. inherited create(n);
  553. typ:=procsym;
  554. pdlistfirst:=nil;
  555. pdlistlast:=nil;
  556. owner:=nil;
  557. {$ifdef GDB}
  558. is_global:=false;
  559. {$endif GDB}
  560. { the tprocdef have their own symoptions, make the procsym
  561. always visible }
  562. symoptions:=[sp_public];
  563. overloadchecked:=false;
  564. procdef_count:=0;
  565. end;
  566. constructor tprocsym.ppuload(ppufile:tcompilerppufile);
  567. var
  568. pdderef : tderef;
  569. i,n : longint;
  570. begin
  571. inherited ppuload(ppufile);
  572. typ:=procsym;
  573. pdlistfirst:=nil;
  574. pdlistlast:=nil;
  575. procdef_count:=0;
  576. n:=ppufile.getword;
  577. for i:=1to n do
  578. begin
  579. ppufile.getderef(pdderef);
  580. addprocdef_deref(pdderef);
  581. end;
  582. {$ifdef GDB}
  583. is_global:=false;
  584. {$endif GDB}
  585. overloadchecked:=false;
  586. end;
  587. destructor tprocsym.destroy;
  588. var
  589. hp,p : pprocdeflist;
  590. begin
  591. p:=pdlistfirst;
  592. while assigned(p) do
  593. begin
  594. hp:=p^.next;
  595. dispose(p);
  596. p:=hp;
  597. end;
  598. inherited destroy;
  599. end;
  600. procedure tprocsym.ppuwrite(ppufile:tcompilerppufile);
  601. var
  602. p : pprocdeflist;
  603. n : word;
  604. begin
  605. inherited ppuwrite(ppufile);
  606. { count procdefs }
  607. n:=0;
  608. p:=pdlistfirst;
  609. while assigned(p) do
  610. begin
  611. { only write the proc definitions that belong
  612. to this procsym and are in the global symtable }
  613. if p^.def.owner=owner then
  614. inc(n);
  615. p:=p^.next;
  616. end;
  617. ppufile.putword(n);
  618. { write procdefs }
  619. p:=pdlistfirst;
  620. while assigned(p) do
  621. begin
  622. { only write the proc definitions that belong
  623. to this procsym and are in the global symtable }
  624. if p^.def.owner=owner then
  625. ppufile.putderef(p^.defderef);
  626. p:=p^.next;
  627. end;
  628. ppufile.writeentry(ibprocsym);
  629. end;
  630. procedure tprocsym.write_parameter_lists(skipdef:tprocdef);
  631. var
  632. p : pprocdeflist;
  633. begin
  634. p:=pdlistfirst;
  635. while assigned(p) do
  636. begin
  637. if p^.def<>skipdef then
  638. MessagePos1(p^.def.fileinfo,sym_h_param_list,p^.def.fullprocname(false));
  639. p:=p^.next;
  640. end;
  641. end;
  642. {Makes implicit externals (procedures declared in the interface
  643. section which do not have a counterpart in the implementation)
  644. to be an imported procedure. For mode macpas.}
  645. procedure import_implict_external(pd:tabstractprocdef);
  646. begin
  647. tprocdef(pd).forwarddef:=false;
  648. tprocdef(pd).setmangledname(target_info.CPrefix+tprocdef(pd).procsym.realname);
  649. end;
  650. procedure tprocsym.check_forward;
  651. var
  652. p : pprocdeflist;
  653. begin
  654. p:=pdlistfirst;
  655. while assigned(p) do
  656. begin
  657. if (p^.def.owner=owner) and (p^.def.forwarddef) then
  658. begin
  659. if (m_mac in aktmodeswitches) and (p^.def.interfacedef) then
  660. import_implict_external(p^.def)
  661. else
  662. begin
  663. MessagePos1(p^.def.fileinfo,sym_e_forward_not_resolved,p^.def.fullprocname(false));
  664. { Turn further error messages off }
  665. p^.def.forwarddef:=false;
  666. end
  667. end;
  668. p:=p^.next;
  669. end;
  670. end;
  671. procedure tprocsym.buildderef;
  672. var
  673. p : pprocdeflist;
  674. begin
  675. p:=pdlistfirst;
  676. while assigned(p) do
  677. begin
  678. if p^.def.owner=owner then
  679. p^.defderef.build(p^.def);
  680. p:=p^.next;
  681. end;
  682. end;
  683. procedure tprocsym.deref;
  684. var
  685. p : pprocdeflist;
  686. begin
  687. { We have removed the overloaded entries, because they
  688. are not valid anymore and we can't deref them because
  689. the unit were they come from is not necessary in
  690. our uses clause (PFV) }
  691. unchain_overload;
  692. { Deref our own procdefs }
  693. p:=pdlistfirst;
  694. while assigned(p) do
  695. begin
  696. if not(
  697. (p^.def=nil) or
  698. (p^.def.owner=owner)
  699. ) then
  700. internalerror(200310291);
  701. p^.def:=tprocdef(p^.defderef.resolve);
  702. p:=p^.next;
  703. end;
  704. end;
  705. procedure tprocsym.addprocdef(p:tprocdef);
  706. var
  707. pd : pprocdeflist;
  708. begin
  709. new(pd);
  710. pd^.def:=p;
  711. pd^.defderef.reset;
  712. pd^.next:=nil;
  713. { Add at end of list to keep always
  714. a correct order, also after loading from ppu }
  715. if assigned(pdlistlast) then
  716. begin
  717. pdlistlast^.next:=pd;
  718. pdlistlast:=pd;
  719. end
  720. else
  721. begin
  722. pdlistfirst:=pd;
  723. pdlistlast:=pd;
  724. end;
  725. inc(procdef_count);
  726. end;
  727. procedure tprocsym.addprocdef_deref(const d:tderef);
  728. var
  729. pd : pprocdeflist;
  730. begin
  731. new(pd);
  732. pd^.def:=nil;
  733. pd^.defderef:=d;
  734. pd^.next:=nil;
  735. { Add at end of list to keep always
  736. a correct order, also after loading from ppu }
  737. if assigned(pdlistlast) then
  738. begin
  739. pdlistlast^.next:=pd;
  740. pdlistlast:=pd;
  741. end
  742. else
  743. begin
  744. pdlistfirst:=pd;
  745. pdlistlast:=pd;
  746. end;
  747. inc(procdef_count);
  748. end;
  749. function Tprocsym.getprocdef(nr:cardinal):Tprocdef;
  750. var
  751. i : cardinal;
  752. pd : pprocdeflist;
  753. begin
  754. pd:=pdlistfirst;
  755. for i:=2 to nr do
  756. begin
  757. if not assigned(pd) then
  758. internalerror(200209051);
  759. pd:=pd^.next;
  760. end;
  761. getprocdef:=pd^.def;
  762. end;
  763. procedure Tprocsym.add_para_match_to(Aprocsym:Tprocsym;cpoptions:tcompare_paras_options);
  764. var
  765. pd:pprocdeflist;
  766. begin
  767. pd:=pdlistfirst;
  768. while assigned(pd) do
  769. begin
  770. if Aprocsym.search_procdef_bypara(pd^.def.paras,nil,cpoptions)=nil then
  771. Aprocsym.addprocdef(pd^.def);
  772. pd:=pd^.next;
  773. end;
  774. end;
  775. procedure Tprocsym.concat_procdefs_to(s:Tprocsym);
  776. var
  777. pd : pprocdeflist;
  778. begin
  779. pd:=pdlistfirst;
  780. while assigned(pd) do
  781. begin
  782. s.addprocdef(pd^.def);
  783. pd:=pd^.next;
  784. end;
  785. end;
  786. function Tprocsym.first_procdef:Tprocdef;
  787. begin
  788. if assigned(pdlistfirst) then
  789. first_procdef:=pdlistfirst^.def
  790. else
  791. first_procdef:=nil;
  792. end;
  793. function Tprocsym.last_procdef:Tprocdef;
  794. begin
  795. if assigned(pdlistlast) then
  796. last_procdef:=pdlistlast^.def
  797. else
  798. last_procdef:=nil;
  799. end;
  800. procedure Tprocsym.foreach_procdef_static(proc2call:Tprocdefcallback;arg:pointer);
  801. var
  802. p : pprocdeflist;
  803. begin
  804. p:=pdlistfirst;
  805. while assigned(p) do
  806. begin
  807. proc2call(p^.def,arg);
  808. p:=p^.next;
  809. end;
  810. end;
  811. function Tprocsym.search_procdef_nopara_boolret:Tprocdef;
  812. var
  813. p : pprocdeflist;
  814. begin
  815. search_procdef_nopara_boolret:=nil;
  816. p:=pdlistfirst;
  817. while p<>nil do
  818. begin
  819. if (p^.def.maxparacount=0) and
  820. is_boolean(p^.def.rettype.def) then
  821. begin
  822. search_procdef_nopara_boolret:=p^.def;
  823. break;
  824. end;
  825. p:=p^.next;
  826. end;
  827. end;
  828. function Tprocsym.search_procdef_bytype(pt:Tproctypeoption):Tprocdef;
  829. var
  830. p : pprocdeflist;
  831. begin
  832. search_procdef_bytype:=nil;
  833. p:=pdlistfirst;
  834. while p<>nil do
  835. begin
  836. if p^.def.proctypeoption=pt then
  837. begin
  838. search_procdef_bytype:=p^.def;
  839. break;
  840. end;
  841. p:=p^.next;
  842. end;
  843. end;
  844. function Tprocsym.search_procdef_bypara(para:tlist;retdef:tdef;
  845. cpoptions:tcompare_paras_options):Tprocdef;
  846. var
  847. pd : pprocdeflist;
  848. eq : tequaltype;
  849. begin
  850. search_procdef_bypara:=nil;
  851. pd:=pdlistfirst;
  852. while assigned(pd) do
  853. begin
  854. if assigned(retdef) then
  855. eq:=compare_defs(retdef,pd^.def.rettype.def,nothingn)
  856. else
  857. eq:=te_equal;
  858. if (eq>=te_equal) or
  859. ((cpo_allowconvert in cpoptions) and (eq>te_incompatible)) then
  860. begin
  861. eq:=compare_paras(para,pd^.def.paras,cp_value_equal_const,cpoptions);
  862. if (eq>=te_equal) or
  863. ((cpo_allowconvert in cpoptions) and (eq>te_incompatible)) then
  864. begin
  865. search_procdef_bypara:=pd^.def;
  866. break;
  867. end;
  868. end;
  869. pd:=pd^.next;
  870. end;
  871. end;
  872. function Tprocsym.search_procdef_byprocvardef(d:Tprocvardef):Tprocdef;
  873. var
  874. pd : pprocdeflist;
  875. eq,besteq : tequaltype;
  876. bestpd : tprocdef;
  877. begin
  878. { This function will return the pprocdef of pprocsym that
  879. is the best match for procvardef. When there are multiple
  880. matches it returns nil.}
  881. search_procdef_byprocvardef:=nil;
  882. bestpd:=nil;
  883. besteq:=te_incompatible;
  884. pd:=pdlistfirst;
  885. while assigned(pd) do
  886. begin
  887. eq:=proc_to_procvar_equal(pd^.def,d);
  888. if eq>=te_equal then
  889. begin
  890. { multiple procvars with the same equal level }
  891. if assigned(bestpd) and
  892. (besteq=eq) then
  893. exit;
  894. if eq>besteq then
  895. begin
  896. besteq:=eq;
  897. bestpd:=pd^.def;
  898. end;
  899. end;
  900. pd:=pd^.next;
  901. end;
  902. search_procdef_byprocvardef:=bestpd;
  903. end;
  904. function Tprocsym.search_procdef_assignment_operator(fromdef,todef:tdef;var besteq:tequaltype):Tprocdef;
  905. var
  906. convtyp : tconverttype;
  907. pd : pprocdeflist;
  908. bestpd : tprocdef;
  909. eq : tequaltype;
  910. hpd : tprocdef;
  911. i : byte;
  912. begin
  913. result:=nil;
  914. bestpd:=nil;
  915. besteq:=te_incompatible;
  916. pd:=pdlistfirst;
  917. while assigned(pd) do
  918. begin
  919. if equal_defs(todef,pd^.def.rettype.def) and
  920. { the result type must be always really equal and not an alias,
  921. if you mess with this code, check tw4093 }
  922. ((todef=pd^.def.rettype.def) or
  923. (
  924. not(df_unique in todef.defoptions) and
  925. not(df_unique in pd^.def.rettype.def.defoptions)
  926. )
  927. ) then
  928. begin
  929. i:=0;
  930. { ignore vs_hidden parameters }
  931. while (i<pd^.def.paras.count) and
  932. assigned(pd^.def.paras[i]) and
  933. (vo_is_hidden_para in tparavarsym(pd^.def.paras[i]).varoptions) do
  934. inc(i);
  935. if (i<pd^.def.paras.count) and
  936. assigned(pd^.def.paras[i]) then
  937. begin
  938. eq:=compare_defs_ext(fromdef,tparavarsym(pd^.def.paras[i]).vartype.def,nothingn,convtyp,hpd,[]);
  939. { alias? if yes, only l1 choice,
  940. if you mess with this code, check tw4093 }
  941. if (eq=te_exact) and
  942. (fromdef<>tparavarsym(pd^.def.paras[i]).vartype.def) and
  943. ((df_unique in fromdef.defoptions) or
  944. (df_unique in tparavarsym(pd^.def.paras[i]).vartype.def.defoptions)) then
  945. eq:=te_convert_l1;
  946. if eq=te_exact then
  947. begin
  948. besteq:=eq;
  949. result:=pd^.def;
  950. exit;
  951. end;
  952. if eq>besteq then
  953. begin
  954. bestpd:=pd^.def;
  955. besteq:=eq;
  956. end;
  957. end;
  958. end;
  959. pd:=pd^.next;
  960. end;
  961. result:=bestpd;
  962. end;
  963. function tprocsym.write_references(ppufile:tcompilerppufile;locals:boolean) : boolean;
  964. var
  965. p : pprocdeflist;
  966. begin
  967. write_references:=false;
  968. if not inherited write_references(ppufile,locals) then
  969. exit;
  970. write_references:=true;
  971. p:=pdlistfirst;
  972. while assigned(p) do
  973. begin
  974. if p^.def.owner=owner then
  975. p^.def.write_references(ppufile,locals);
  976. p:=p^.next;
  977. end;
  978. end;
  979. procedure tprocsym.unchain_overload;
  980. var
  981. p,hp : pprocdeflist;
  982. begin
  983. { remove all overloaded procdefs from the
  984. procdeflist that are not in the current symtable }
  985. overloadchecked:=false;
  986. p:=pdlistfirst;
  987. { reset new lists }
  988. pdlistfirst:=nil;
  989. pdlistlast:=nil;
  990. while assigned(p) do
  991. begin
  992. hp:=p^.next;
  993. { only keep the proc definitions:
  994. - are not deref'd (def=nil)
  995. - are in the same symtable as the procsym (for example both
  996. are in the staticsymtable) }
  997. if (p^.def=nil) or
  998. (p^.def.owner=owner) then
  999. begin
  1000. { keep, add to list }
  1001. if assigned(pdlistlast) then
  1002. begin
  1003. pdlistlast^.next:=p;
  1004. pdlistlast:=p;
  1005. end
  1006. else
  1007. begin
  1008. pdlistfirst:=p;
  1009. pdlistlast:=p;
  1010. end;
  1011. p^.next:=nil;
  1012. end
  1013. else
  1014. begin
  1015. { remove }
  1016. dispose(p);
  1017. dec(procdef_count);
  1018. end;
  1019. p:=hp;
  1020. end;
  1021. end;
  1022. function tprocsym.is_visible_for_object(currobjdef:tdef;context:tdef):boolean;
  1023. var
  1024. p : pprocdeflist;
  1025. begin
  1026. { This procsym is visible, when there is at least
  1027. one of the procdefs visible }
  1028. result:=false;
  1029. p:=pdlistfirst;
  1030. while assigned(p) do
  1031. begin
  1032. if (p^.def.owner=owner) and
  1033. p^.def.is_visible_for_object(tobjectdef(currobjdef)) then
  1034. begin
  1035. result:=true;
  1036. exit;
  1037. end;
  1038. p:=p^.next;
  1039. end;
  1040. end;
  1041. {$ifdef GDB}
  1042. function tprocsym.stabstring : pchar;
  1043. begin
  1044. internalerror(200111171);
  1045. result:=nil;
  1046. end;
  1047. {$endif GDB}
  1048. {****************************************************************************
  1049. TERRORSYM
  1050. ****************************************************************************}
  1051. constructor terrorsym.create;
  1052. begin
  1053. inherited create('');
  1054. typ:=errorsym;
  1055. end;
  1056. {****************************************************************************
  1057. TPROPERTYSYM
  1058. ****************************************************************************}
  1059. constructor tpropertysym.create(const n : string);
  1060. begin
  1061. inherited create(n);
  1062. typ:=propertysym;
  1063. propoptions:=[];
  1064. index:=0;
  1065. default:=0;
  1066. proptype.reset;
  1067. indextype.reset;
  1068. readaccess:=tsymlist.create;
  1069. writeaccess:=tsymlist.create;
  1070. storedaccess:=tsymlist.create;
  1071. end;
  1072. constructor tpropertysym.ppuload(ppufile:tcompilerppufile);
  1073. begin
  1074. inherited ppuload(ppufile);
  1075. typ:=propertysym;
  1076. ppufile.getsmallset(propoptions);
  1077. if (ppo_is_override in propoptions) then
  1078. begin
  1079. ppufile.getderef(propoverridenderef);
  1080. { we need to have these objects initialized }
  1081. readaccess:=tsymlist.create;
  1082. writeaccess:=tsymlist.create;
  1083. storedaccess:=tsymlist.create;
  1084. end
  1085. else
  1086. begin
  1087. ppufile.gettype(proptype);
  1088. index:=ppufile.getlongint;
  1089. default:=ppufile.getlongint;
  1090. ppufile.gettype(indextype);
  1091. readaccess:=ppufile.getsymlist;
  1092. writeaccess:=ppufile.getsymlist;
  1093. storedaccess:=ppufile.getsymlist;
  1094. end;
  1095. end;
  1096. destructor tpropertysym.destroy;
  1097. begin
  1098. readaccess.free;
  1099. writeaccess.free;
  1100. storedaccess.free;
  1101. inherited destroy;
  1102. end;
  1103. function tpropertysym.gettypedef:tdef;
  1104. begin
  1105. gettypedef:=proptype.def;
  1106. end;
  1107. procedure tpropertysym.buildderef;
  1108. begin
  1109. if (ppo_is_override in propoptions) then
  1110. begin
  1111. propoverridenderef.build(propoverriden);
  1112. end
  1113. else
  1114. begin
  1115. proptype.buildderef;
  1116. indextype.buildderef;
  1117. readaccess.buildderef;
  1118. writeaccess.buildderef;
  1119. storedaccess.buildderef;
  1120. end;
  1121. end;
  1122. procedure tpropertysym.deref;
  1123. begin
  1124. if not(ppo_is_override in propoptions) then
  1125. begin
  1126. proptype.resolve;
  1127. indextype.resolve;
  1128. readaccess.resolve;
  1129. writeaccess.resolve;
  1130. storedaccess.resolve;
  1131. end;
  1132. end;
  1133. procedure tpropertysym.derefimpl;
  1134. begin
  1135. if (ppo_is_override in propoptions) then
  1136. begin
  1137. propoverriden:=tpropertysym(propoverridenderef.resolve);
  1138. dooverride(propoverriden);
  1139. end
  1140. end;
  1141. function tpropertysym.getsize : longint;
  1142. begin
  1143. getsize:=0;
  1144. end;
  1145. procedure tpropertysym.ppuwrite(ppufile:tcompilerppufile);
  1146. begin
  1147. inherited ppuwrite(ppufile);
  1148. ppufile.putsmallset(propoptions);
  1149. if (ppo_is_override in propoptions) then
  1150. ppufile.putderef(propoverridenderef)
  1151. else
  1152. begin
  1153. ppufile.puttype(proptype);
  1154. ppufile.putlongint(index);
  1155. ppufile.putlongint(default);
  1156. ppufile.puttype(indextype);
  1157. ppufile.putsymlist(readaccess);
  1158. ppufile.putsymlist(writeaccess);
  1159. ppufile.putsymlist(storedaccess);
  1160. end;
  1161. ppufile.writeentry(ibpropertysym);
  1162. end;
  1163. procedure tpropertysym.dooverride(overriden:tpropertysym);
  1164. begin
  1165. propoverriden:=overriden;
  1166. proptype:=overriden.proptype;
  1167. propoptions:=overriden.propoptions+[ppo_is_override];
  1168. index:=overriden.index;
  1169. default:=overriden.default;
  1170. indextype:=overriden.indextype;
  1171. readaccess.free;
  1172. readaccess:=overriden.readaccess.getcopy;
  1173. writeaccess.free;
  1174. writeaccess:=overriden.writeaccess.getcopy;
  1175. storedaccess.free;
  1176. storedaccess:=overriden.storedaccess.getcopy;
  1177. end;
  1178. {****************************************************************************
  1179. TABSTRACTVARSYM
  1180. ****************************************************************************}
  1181. constructor tabstractvarsym.create(const n : string;vsp:tvarspez;const tt : ttype;vopts:tvaroptions);
  1182. begin
  1183. inherited create(n);
  1184. vartype:=tt;
  1185. varspez:=vsp;
  1186. varstate:=vs_declared;
  1187. varoptions:=vopts;
  1188. end;
  1189. constructor tabstractvarsym.ppuload(ppufile:tcompilerppufile);
  1190. begin
  1191. inherited ppuload(ppufile);
  1192. varstate:=vs_readwritten;
  1193. varspez:=tvarspez(ppufile.getbyte);
  1194. varregable:=tvarregable(ppufile.getbyte);
  1195. ppufile.gettype(_vartype);
  1196. ppufile.getsmallset(varoptions);
  1197. end;
  1198. destructor tabstractvarsym.destroy;
  1199. begin
  1200. if assigned(notifications) then
  1201. notifications.destroy;
  1202. inherited destroy;
  1203. end;
  1204. procedure tabstractvarsym.buildderef;
  1205. begin
  1206. vartype.buildderef;
  1207. end;
  1208. procedure tabstractvarsym.deref;
  1209. begin
  1210. vartype.resolve;
  1211. end;
  1212. procedure tabstractvarsym.ppuwrite(ppufile:tcompilerppufile);
  1213. var
  1214. oldintfcrc : boolean;
  1215. begin
  1216. inherited ppuwrite(ppufile);
  1217. ppufile.putbyte(byte(varspez));
  1218. oldintfcrc:=ppufile.do_crc;
  1219. ppufile.do_crc:=false;
  1220. ppufile.putbyte(byte(varregable));
  1221. ppufile.do_crc:=oldintfcrc;
  1222. ppufile.puttype(vartype);
  1223. ppufile.putsmallset(varoptions);
  1224. end;
  1225. function tabstractvarsym.getsize : longint;
  1226. begin
  1227. if assigned(vartype.def) and
  1228. ((vartype.def.deftype<>arraydef) or
  1229. tarraydef(vartype.def).isDynamicArray or
  1230. (tarraydef(vartype.def).highrange>=tarraydef(vartype.def).lowrange)) then
  1231. result:=vartype.def.size
  1232. else
  1233. result:=0;
  1234. end;
  1235. function tabstractvarsym.is_regvar:boolean;
  1236. begin
  1237. { Register variables are not allowed in the following cases:
  1238. - regvars are disabled
  1239. - exceptions are used (after an exception is raised the contents of the
  1240. registers is not valid anymore)
  1241. - it has a local copy
  1242. - the value needs to be in memory (i.e. reference counted) }
  1243. result:=(cs_regvars in aktglobalswitches) and
  1244. not(pi_has_assembler_block in current_procinfo.flags) and
  1245. not(pi_uses_exceptions in current_procinfo.flags) and
  1246. not(vo_has_local_copy in varoptions) and
  1247. (varregable<>vr_none);
  1248. end;
  1249. procedure tabstractvarsym.trigger_notifications(what:Tnotification_flag);
  1250. var n:Tnotification;
  1251. begin
  1252. if assigned(notifications) then
  1253. begin
  1254. n:=Tnotification(notifications.first);
  1255. while assigned(n) do
  1256. begin
  1257. if what in n.flags then
  1258. n.callback(what,self);
  1259. n:=Tnotification(n.next);
  1260. end;
  1261. end;
  1262. end;
  1263. function Tabstractvarsym.register_notification(flags:Tnotification_flags;callback:
  1264. Tnotification_callback):cardinal;
  1265. var n:Tnotification;
  1266. begin
  1267. if not assigned(notifications) then
  1268. notifications:=Tlinkedlist.create;
  1269. n:=Tnotification.create(flags,callback);
  1270. register_notification:=n.id;
  1271. notifications.concat(n);
  1272. end;
  1273. procedure Tabstractvarsym.unregister_notification(id:cardinal);
  1274. var n:Tnotification;
  1275. begin
  1276. if not assigned(notifications) then
  1277. internalerror(200212311)
  1278. else
  1279. begin
  1280. n:=Tnotification(notifications.first);
  1281. while assigned(n) do
  1282. begin
  1283. if n.id=id then
  1284. begin
  1285. notifications.remove(n);
  1286. n.destroy;
  1287. exit;
  1288. end;
  1289. n:=Tnotification(n.next);
  1290. end;
  1291. internalerror(200212311)
  1292. end;
  1293. end;
  1294. procedure tabstractvarsym.setvartype(const newtype: ttype);
  1295. begin
  1296. _vartype := newtype;
  1297. { can we load the value into a register ? }
  1298. if not assigned(owner) or
  1299. (owner.symtabletype in [localsymtable,parasymtable]) or
  1300. (
  1301. (owner.symtabletype=staticsymtable) and
  1302. not(cs_create_pic in aktmoduleswitches)
  1303. ) then
  1304. begin
  1305. if tstoreddef(vartype.def).is_intregable then
  1306. varregable:=vr_intreg
  1307. else
  1308. { $warning TODO: no fpu regvar in staticsymtable yet, need initialization with 0 }
  1309. if {(
  1310. not assigned(owner) or
  1311. (owner.symtabletype<>staticsymtable)
  1312. ) and }
  1313. tstoreddef(vartype.def).is_fpuregable then
  1314. begin
  1315. {$ifdef x86}
  1316. if use_sse(vartype.def) then
  1317. varregable:=vr_mmreg
  1318. else
  1319. {$else x86}
  1320. varregable:=vr_fpureg;
  1321. {$endif x86}
  1322. end;
  1323. end;
  1324. end;
  1325. {****************************************************************************
  1326. TFIELDVARSYM
  1327. ****************************************************************************}
  1328. constructor tfieldvarsym.create(const n : string;vsp:tvarspez;const tt : ttype;vopts:tvaroptions);
  1329. begin
  1330. inherited create(n,vsp,tt,vopts);
  1331. typ:=fieldvarsym;
  1332. fieldoffset:=0;
  1333. end;
  1334. constructor tfieldvarsym.ppuload(ppufile:tcompilerppufile);
  1335. begin
  1336. inherited ppuload(ppufile);
  1337. typ:=fieldvarsym;
  1338. fieldoffset:=ppufile.getaint;
  1339. end;
  1340. procedure tfieldvarsym.ppuwrite(ppufile:tcompilerppufile);
  1341. begin
  1342. inherited ppuwrite(ppufile);
  1343. ppufile.putaint(fieldoffset);
  1344. ppufile.writeentry(ibfieldvarsym);
  1345. end;
  1346. {$ifdef GDB}
  1347. function tfieldvarsym.stabstring:Pchar;
  1348. var
  1349. st : string;
  1350. begin
  1351. stabstring:=nil;
  1352. case owner.symtabletype of
  1353. objectsymtable :
  1354. begin
  1355. if (sp_static in symoptions) then
  1356. begin
  1357. st:=tstoreddef(vartype.def).numberstring;
  1358. if (cs_gdb_gsym in aktglobalswitches) then
  1359. st:='G'+st
  1360. else
  1361. st:='S'+st;
  1362. stabstring:=stabstr_evaluate('"${ownername}__${name}:$1",${N_LCSYM},0,${line},${mangledname}',[st]);
  1363. end;
  1364. end;
  1365. end;
  1366. end;
  1367. {$endif GDB}
  1368. function tfieldvarsym.mangledname:string;
  1369. var
  1370. srsym : tsym;
  1371. srsymtable : tsymtable;
  1372. begin
  1373. if sp_static in symoptions then
  1374. begin
  1375. searchsym(lower(owner.name^)+'_'+name,srsym,srsymtable);
  1376. if assigned(srsym) then
  1377. result:=tglobalvarsym(srsym).mangledname;
  1378. end
  1379. else
  1380. result:=inherited mangledname;
  1381. end;
  1382. {****************************************************************************
  1383. TABSTRACTNORMALVARSYM
  1384. ****************************************************************************}
  1385. constructor tabstractnormalvarsym.create(const n : string;vsp:tvarspez;const tt : ttype;vopts:tvaroptions);
  1386. begin
  1387. inherited create(n,vsp,tt,vopts);
  1388. fillchar(localloc,sizeof(localloc),0);
  1389. defaultconstsym:=nil;
  1390. end;
  1391. constructor tabstractnormalvarsym.ppuload(ppufile:tcompilerppufile);
  1392. begin
  1393. inherited ppuload(ppufile);
  1394. fillchar(localloc,sizeof(localloc),0);
  1395. ppufile.getderef(defaultconstsymderef);
  1396. end;
  1397. procedure tabstractnormalvarsym.buildderef;
  1398. begin
  1399. inherited buildderef;
  1400. defaultconstsymderef.build(defaultconstsym);
  1401. end;
  1402. procedure tabstractnormalvarsym.deref;
  1403. begin
  1404. inherited deref;
  1405. defaultconstsym:=tsym(defaultconstsymderef.resolve);
  1406. end;
  1407. procedure tabstractnormalvarsym.ppuwrite(ppufile:tcompilerppufile);
  1408. begin
  1409. inherited ppuwrite(ppufile);
  1410. ppufile.putderef(defaultconstsymderef);
  1411. end;
  1412. {****************************************************************************
  1413. TGLOBALVARSYM
  1414. ****************************************************************************}
  1415. constructor tglobalvarsym.create(const n : string;vsp:tvarspez;const tt : ttype;vopts:tvaroptions);
  1416. begin
  1417. inherited create(n,vsp,tt,vopts);
  1418. typ:=globalvarsym;
  1419. _mangledname:=nil;
  1420. end;
  1421. constructor tglobalvarsym.create_dll(const n : string;vsp:tvarspez;const tt : ttype);
  1422. begin
  1423. tglobalvarsym(self).create(n,vsp,tt,[vo_is_dll_var]);
  1424. end;
  1425. constructor tglobalvarsym.create_C(const n,mangled : string;vsp:tvarspez;const tt : ttype);
  1426. begin
  1427. tglobalvarsym(self).create(n,vsp,tt,[]);
  1428. set_mangledname(mangled);
  1429. end;
  1430. constructor tglobalvarsym.ppuload(ppufile:tcompilerppufile);
  1431. begin
  1432. inherited ppuload(ppufile);
  1433. typ:=globalvarsym;
  1434. if vo_has_mangledname in varoptions then
  1435. _mangledname:=stringdup(ppufile.getstring)
  1436. else
  1437. _mangledname:=nil;
  1438. end;
  1439. destructor tglobalvarsym.destroy;
  1440. begin
  1441. if assigned(_mangledname) then
  1442. begin
  1443. {$ifdef MEMDEBUG}
  1444. memmanglednames.start;
  1445. {$endif MEMDEBUG}
  1446. stringdispose(_mangledname);
  1447. {$ifdef MEMDEBUG}
  1448. memmanglednames.stop;
  1449. {$endif MEMDEBUG}
  1450. end;
  1451. inherited destroy;
  1452. end;
  1453. procedure tglobalvarsym.ppuwrite(ppufile:tcompilerppufile);
  1454. begin
  1455. inherited ppuwrite(ppufile);
  1456. if vo_has_mangledname in varoptions then
  1457. ppufile.putstring(_mangledname^);
  1458. ppufile.writeentry(ibglobalvarsym);
  1459. end;
  1460. function tglobalvarsym.mangledname:string;
  1461. begin
  1462. if not assigned(_mangledname) then
  1463. begin
  1464. {$ifdef compress}
  1465. _mangledname:=stringdup(minilzw_encode(make_mangledname('U',owner,name)));
  1466. {$else}
  1467. _mangledname:=stringdup(make_mangledname('U',owner,name));
  1468. {$endif}
  1469. end;
  1470. result:=_mangledname^;
  1471. end;
  1472. procedure tglobalvarsym.set_mangledname(const s:string);
  1473. begin
  1474. stringdispose(_mangledname);
  1475. {$ifdef compress}
  1476. _mangledname:=stringdup(minilzw_encode(s));
  1477. {$else}
  1478. _mangledname:=stringdup(s);
  1479. {$endif}
  1480. include(varoptions,vo_has_mangledname);
  1481. end;
  1482. {$ifdef GDB}
  1483. function Tglobalvarsym.stabstring:Pchar;
  1484. var st:string;
  1485. threadvaroffset:string;
  1486. regidx:Tregisterindex;
  1487. begin
  1488. result:=nil;
  1489. st:=tstoreddef(vartype.def).numberstring;
  1490. case localloc.loc of
  1491. LOC_REGISTER,
  1492. LOC_CREGISTER,
  1493. LOC_MMREGISTER,
  1494. LOC_CMMREGISTER,
  1495. LOC_FPUREGISTER,
  1496. LOC_CFPUREGISTER :
  1497. begin
  1498. regidx:=findreg_by_number(localloc.register);
  1499. { "eax", "ecx", "edx", "ebx", "esp", "ebp", "esi", "edi", "eip", "ps", "cs", "ss", "ds", "es", "fs", "gs", }
  1500. { this is the register order for GDB}
  1501. if regidx<>0 then
  1502. stabstring:=stabstr_evaluate('"${name}:r$1",${N_RSYM},0,${line},$2',[st,tostr(regstabs_table[regidx])]);
  1503. end;
  1504. else
  1505. begin
  1506. if (vo_is_thread_var in varoptions) then
  1507. threadvaroffset:='+'+tostr(sizeof(aint))
  1508. else
  1509. threadvaroffset:='';
  1510. { Here we used S instead of
  1511. because with G GDB doesn't look at the address field
  1512. but searches the same name or with a leading underscore
  1513. but these names don't exist in pascal !}
  1514. if (cs_gdb_gsym in aktglobalswitches) then
  1515. st:='G'+st
  1516. else
  1517. st:='S'+st;
  1518. stabstring:=stabstr_evaluate('"${name}:$1",${N_LCSYM},0,${line},${mangledname}$2',[st,threadvaroffset]);
  1519. end;
  1520. end;
  1521. end;
  1522. {$endif GDB}
  1523. {****************************************************************************
  1524. TDEFINITIONSYM
  1525. ****************************************************************************}
  1526. constructor tdefinitionsym.create(const n : string; const tt: ttype; aexpr : tnode);
  1527. begin
  1528. inherited create(n, vs_value, tt, []);
  1529. expr:=aexpr;
  1530. typ:=definitionsym;
  1531. end;
  1532. destructor tdefinitionsym.destroy;
  1533. begin
  1534. expr.free;
  1535. inherited destroy;
  1536. end;
  1537. {****************************************************************************
  1538. TSPECVARSYM
  1539. ****************************************************************************}
  1540. constructor tspecvarsym.create(const n : string; const tt: ttype; aexpr : tnode);
  1541. begin
  1542. inherited create(n, vs_value, tt, []);
  1543. expr:=aexpr;
  1544. end;
  1545. destructor tspecvarsym.destroy;
  1546. begin
  1547. expr.free;
  1548. inherited destroy;
  1549. end;
  1550. {****************************************************************************
  1551. TLOCALVARSYM
  1552. ****************************************************************************}
  1553. constructor tlocalvarsym.create(const n : string;vsp:tvarspez;const tt : ttype;vopts:tvaroptions);
  1554. begin
  1555. inherited create(n,vsp,tt,vopts);
  1556. typ:=localvarsym;
  1557. end;
  1558. constructor tlocalvarsym.ppuload(ppufile:tcompilerppufile);
  1559. begin
  1560. inherited ppuload(ppufile);
  1561. typ:=localvarsym;
  1562. end;
  1563. procedure tlocalvarsym.ppuwrite(ppufile:tcompilerppufile);
  1564. begin
  1565. inherited ppuwrite(ppufile);
  1566. ppufile.writeentry(iblocalvarsym);
  1567. end;
  1568. {$ifdef GDB}
  1569. function tlocalvarsym.stabstring:Pchar;
  1570. var st:string;
  1571. regidx:Tregisterindex;
  1572. begin
  1573. stabstring:=nil;
  1574. { There is no space allocated for not referenced locals }
  1575. if (owner.symtabletype=localsymtable) and (refs=0) then
  1576. exit;
  1577. st:=tstoreddef(vartype.def).numberstring;
  1578. case localloc.loc of
  1579. LOC_REGISTER,
  1580. LOC_CREGISTER,
  1581. LOC_MMREGISTER,
  1582. LOC_CMMREGISTER,
  1583. LOC_FPUREGISTER,
  1584. LOC_CFPUREGISTER :
  1585. begin
  1586. regidx:=findreg_by_number(localloc.register);
  1587. { "eax", "ecx", "edx", "ebx", "esp", "ebp", "esi", "edi", "eip", "ps", "cs", "ss", "ds", "es", "fs", "gs", }
  1588. { this is the register order for GDB}
  1589. if regidx<>0 then
  1590. stabstring:=stabstr_evaluate('"${name}:r$1",${N_RSYM},0,${line},$2',[st,tostr(regstabs_table[regidx])]);
  1591. end;
  1592. LOC_REFERENCE :
  1593. { offset to ebp => will not work if the framepointer is esp
  1594. so some optimizing will make things harder to debug }
  1595. stabstring:=stabstr_evaluate('"${name}:$1",${N_TSYM},0,${line},$2',[st,tostr(localloc.reference.offset)])
  1596. else
  1597. internalerror(2003091814);
  1598. end;
  1599. end;
  1600. {$endif GDB}
  1601. {****************************************************************************
  1602. TPARAVARSYM
  1603. ****************************************************************************}
  1604. constructor tparavarsym.create(const n : string;nr:word;vsp:tvarspez;const tt : ttype;vopts:tvaroptions);
  1605. begin
  1606. inherited create(n,vsp,tt,vopts);
  1607. typ:=paravarsym;
  1608. if (vsp in [vs_var,vs_value,vs_const]) then
  1609. varstate := vs_initialised;
  1610. paranr:=nr;
  1611. paraloc[calleeside].init;
  1612. paraloc[callerside].init;
  1613. end;
  1614. destructor tparavarsym.destroy;
  1615. begin
  1616. paraloc[calleeside].done;
  1617. paraloc[callerside].done;
  1618. inherited destroy;
  1619. end;
  1620. constructor tparavarsym.ppuload(ppufile:tcompilerppufile);
  1621. var
  1622. b : byte;
  1623. begin
  1624. inherited ppuload(ppufile);
  1625. paranr:=ppufile.getword;
  1626. paraloc[calleeside].init;
  1627. paraloc[callerside].init;
  1628. if vo_has_explicit_paraloc in varoptions then
  1629. begin
  1630. b:=ppufile.getbyte;
  1631. if b<>sizeof(paraloc[callerside].location^) then
  1632. internalerror(200411154);
  1633. ppufile.getdata(paraloc[callerside].add_location^,sizeof(paraloc[callerside].location^));
  1634. paraloc[callerside].size:=paraloc[callerside].location^.size;
  1635. paraloc[callerside].intsize:=tcgsize2size[paraloc[callerside].size];
  1636. end;
  1637. typ:=paravarsym;
  1638. end;
  1639. procedure tparavarsym.ppuwrite(ppufile:tcompilerppufile);
  1640. begin
  1641. inherited ppuwrite(ppufile);
  1642. ppufile.putword(paranr);
  1643. if vo_has_explicit_paraloc in varoptions then
  1644. begin
  1645. paraloc[callerside].check_simple_location;
  1646. ppufile.putbyte(sizeof(paraloc[callerside].location^));
  1647. ppufile.putdata(paraloc[callerside].location^,sizeof(paraloc[callerside].location^));
  1648. end;
  1649. ppufile.writeentry(ibparavarsym);
  1650. end;
  1651. {$ifdef GDB}
  1652. function tparavarsym.stabstring:Pchar;
  1653. var st:string;
  1654. regidx:Tregisterindex;
  1655. c:char;
  1656. begin
  1657. result:=nil;
  1658. { set loc to LOC_REFERENCE to get somewhat usable debugging info for -Or }
  1659. { while stabs aren't adapted for regvars yet }
  1660. if (vo_is_self in varoptions) then
  1661. begin
  1662. case localloc.loc of
  1663. LOC_REGISTER,
  1664. LOC_CREGISTER:
  1665. regidx:=findreg_by_number(localloc.register);
  1666. LOC_REFERENCE: ;
  1667. else
  1668. internalerror(2003091815);
  1669. end;
  1670. if (po_classmethod in current_procinfo.procdef.procoptions) or
  1671. (po_staticmethod in current_procinfo.procdef.procoptions) then
  1672. begin
  1673. if (localloc.loc=LOC_REFERENCE) then
  1674. stabstring:=stabstr_evaluate('"pvmt:p$1",${N_TSYM},0,0,$2',
  1675. [Tstoreddef(pvmttype.def).numberstring,tostr(localloc.reference.offset)]);
  1676. (* else
  1677. stabstring:=stabstr_evaluate('"pvmt:r$1",${N_RSYM},0,0,$2',
  1678. [Tstoreddef(pvmttype.def).numberstring,tostr(regstabs_table[regidx])]) *)
  1679. end
  1680. else
  1681. begin
  1682. if not(is_class(current_procinfo.procdef._class)) then
  1683. c:='v'
  1684. else
  1685. c:='p';
  1686. if (localloc.loc=LOC_REFERENCE) then
  1687. stabstring:=stabstr_evaluate('"$$t:$1",${N_TSYM},0,0,$2',
  1688. [c+current_procinfo.procdef._class.numberstring,tostr(localloc.reference.offset)]);
  1689. (* else
  1690. stabstring:=stabstr_evaluate('"$$t:r$1",${N_RSYM},0,0,$2',
  1691. [c+current_procinfo.procdef._class.numberstring,tostr(regstabs_table[regidx])]); *)
  1692. end;
  1693. end
  1694. else
  1695. begin
  1696. st:=tstoreddef(vartype.def).numberstring;
  1697. if paramanager.push_addr_param(varspez,vartype.def,tprocdef(owner.defowner).proccalloption) and
  1698. not(vo_has_local_copy in varoptions) and
  1699. not is_open_string(vartype.def) then
  1700. st := 'v'+st { should be 'i' but 'i' doesn't work }
  1701. else
  1702. st := 'p'+st;
  1703. case localloc.loc of
  1704. LOC_REGISTER,
  1705. LOC_CREGISTER,
  1706. LOC_MMREGISTER,
  1707. LOC_CMMREGISTER,
  1708. LOC_FPUREGISTER,
  1709. LOC_CFPUREGISTER :
  1710. begin
  1711. regidx:=findreg_by_number(localloc.register);
  1712. { "eax", "ecx", "edx", "ebx", "esp", "ebp", "esi", "edi", "eip", "ps", "cs", "ss", "ds", "es", "fs", "gs", }
  1713. { this is the register order for GDB}
  1714. if regidx<>0 then
  1715. stabstring:=stabstr_evaluate('"${name}:r$1",${N_RSYM},0,${line},$2',[st,tostr(longint(regstabs_table[regidx]))]);
  1716. end;
  1717. LOC_REFERENCE :
  1718. { offset to ebp => will not work if the framepointer is esp
  1719. so some optimizing will make things harder to debug }
  1720. stabstring:=stabstr_evaluate('"${name}:$1",${N_TSYM},0,${line},$2',[st,tostr(localloc.reference.offset)])
  1721. else
  1722. internalerror(2003091814);
  1723. end;
  1724. end;
  1725. end;
  1726. {$endif GDB}
  1727. {****************************************************************************
  1728. TABSOLUTEVARSYM
  1729. ****************************************************************************}
  1730. constructor tabsolutevarsym.create(const n : string;const tt : ttype);
  1731. begin
  1732. inherited create(n,vs_value,tt,[]);
  1733. typ:=absolutevarsym;
  1734. ref:=nil;
  1735. end;
  1736. constructor tabsolutevarsym.create_ref(const n : string;const tt : ttype;_ref:tsymlist);
  1737. begin
  1738. inherited create(n,vs_value,tt,[]);
  1739. typ:=absolutevarsym;
  1740. ref:=_ref;
  1741. end;
  1742. destructor tabsolutevarsym.destroy;
  1743. begin
  1744. if assigned(ref) then
  1745. ref.free;
  1746. inherited destroy;
  1747. end;
  1748. constructor tabsolutevarsym.ppuload(ppufile:tcompilerppufile);
  1749. begin
  1750. inherited ppuload(ppufile);
  1751. typ:=absolutevarsym;
  1752. ref:=nil;
  1753. asmname:=nil;
  1754. abstyp:=absolutetyp(ppufile.getbyte);
  1755. {$ifdef i386}
  1756. absseg:=false;
  1757. {$endif i386}
  1758. case abstyp of
  1759. tovar :
  1760. ref:=ppufile.getsymlist;
  1761. toasm :
  1762. asmname:=stringdup(ppufile.getstring);
  1763. toaddr :
  1764. begin
  1765. addroffset:=ppufile.getaint;
  1766. {$ifdef i386}
  1767. absseg:=boolean(ppufile.getbyte);
  1768. {$endif i386}
  1769. end;
  1770. end;
  1771. end;
  1772. procedure tabsolutevarsym.ppuwrite(ppufile:tcompilerppufile);
  1773. begin
  1774. inherited ppuwrite(ppufile);
  1775. ppufile.putbyte(byte(abstyp));
  1776. case abstyp of
  1777. tovar :
  1778. ppufile.putsymlist(ref);
  1779. toasm :
  1780. ppufile.putstring(asmname^);
  1781. toaddr :
  1782. begin
  1783. ppufile.putaint(addroffset);
  1784. {$ifdef i386}
  1785. ppufile.putbyte(byte(absseg));
  1786. {$endif i386}
  1787. end;
  1788. end;
  1789. ppufile.writeentry(ibabsolutevarsym);
  1790. end;
  1791. procedure tabsolutevarsym.buildderef;
  1792. begin
  1793. inherited buildderef;
  1794. if (abstyp=tovar) then
  1795. ref.buildderef;
  1796. end;
  1797. procedure tabsolutevarsym.deref;
  1798. begin
  1799. inherited deref;
  1800. { own absolute deref }
  1801. if (abstyp=tovar) then
  1802. ref.resolve;
  1803. end;
  1804. function tabsolutevarsym.mangledname : string;
  1805. begin
  1806. case abstyp of
  1807. toasm :
  1808. mangledname:=asmname^;
  1809. toaddr :
  1810. mangledname:='$'+tostr(addroffset);
  1811. else
  1812. internalerror(200411061);
  1813. end;
  1814. end;
  1815. {$ifdef GDB}
  1816. function tabsolutevarsym.stabstring:Pchar;
  1817. begin
  1818. stabstring:=nil;
  1819. end;
  1820. {$endif GDB}
  1821. {****************************************************************************
  1822. TTYPEDCONSTSYM
  1823. *****************************************************************************}
  1824. constructor ttypedconstsym.create(const n : string;p : tdef;writable : boolean);
  1825. begin
  1826. inherited create(n);
  1827. typ:=typedconstsym;
  1828. typedconsttype.setdef(p);
  1829. is_writable:=writable;
  1830. end;
  1831. constructor ttypedconstsym.createtype(const n : string;const tt : ttype;writable : boolean);
  1832. begin
  1833. inherited create(n);
  1834. typ:=typedconstsym;
  1835. typedconsttype:=tt;
  1836. is_writable:=writable;
  1837. end;
  1838. constructor ttypedconstsym.ppuload(ppufile:tcompilerppufile);
  1839. begin
  1840. inherited ppuload(ppufile);
  1841. typ:=typedconstsym;
  1842. ppufile.gettype(typedconsttype);
  1843. is_writable:=boolean(ppufile.getbyte);
  1844. end;
  1845. destructor ttypedconstsym.destroy;
  1846. begin
  1847. if assigned(_mangledname) then
  1848. begin
  1849. {$ifdef MEMDEBUG}
  1850. memmanglednames.start;
  1851. {$endif MEMDEBUG}
  1852. stringdispose(_mangledname);
  1853. {$ifdef MEMDEBUG}
  1854. memmanglednames.stop;
  1855. {$endif MEMDEBUG}
  1856. end;
  1857. inherited destroy;
  1858. end;
  1859. function ttypedconstsym.mangledname:string;
  1860. begin
  1861. if not assigned(_mangledname) then
  1862. begin
  1863. {$ifdef compress}
  1864. _mangledname:=stringdup(make_mangledname('TC',owner,name));
  1865. {$else}
  1866. _mangledname:=stringdup(make_mangledname('TC',owner,name));
  1867. {$endif}
  1868. end;
  1869. result:=_mangledname^;
  1870. end;
  1871. function ttypedconstsym.getsize : longint;
  1872. begin
  1873. if assigned(typedconsttype.def) then
  1874. getsize:=typedconsttype.def.size
  1875. else
  1876. getsize:=0;
  1877. end;
  1878. procedure ttypedconstsym.buildderef;
  1879. begin
  1880. typedconsttype.buildderef;
  1881. end;
  1882. procedure ttypedconstsym.deref;
  1883. begin
  1884. typedconsttype.resolve;
  1885. end;
  1886. procedure ttypedconstsym.ppuwrite(ppufile:tcompilerppufile);
  1887. begin
  1888. inherited ppuwrite(ppufile);
  1889. ppufile.puttype(typedconsttype);
  1890. ppufile.putbyte(byte(is_writable));
  1891. ppufile.writeentry(ibtypedconstsym);
  1892. end;
  1893. {$ifdef GDB}
  1894. function ttypedconstsym.stabstring : pchar;
  1895. var st:char;
  1896. begin
  1897. if (cs_gdb_gsym in aktglobalswitches) and (owner.symtabletype=globalsymtable) then
  1898. st:='G'
  1899. else
  1900. st:='S';
  1901. stabstring:=stabstr_evaluate('"${name}:$1$2",${N_STSYM},0,${line},${mangledname}',
  1902. [st,Tstoreddef(typedconsttype.def).numberstring]);
  1903. end;
  1904. {$endif GDB}
  1905. {****************************************************************************
  1906. TCONSTSYM
  1907. ****************************************************************************}
  1908. constructor tconstsym.create_ord(const n : string;t : tconsttyp;v : tconstexprint;const tt:ttype);
  1909. begin
  1910. inherited create(n);
  1911. fillchar(value, sizeof(value), #0);
  1912. typ:=constsym;
  1913. consttyp:=t;
  1914. value.valueord:=v;
  1915. ResStrIndex:=0;
  1916. consttype:=tt;
  1917. end;
  1918. constructor tconstsym.create_ordptr(const n : string;t : tconsttyp;v : tconstptruint;const tt:ttype);
  1919. begin
  1920. inherited create(n);
  1921. fillchar(value, sizeof(value), #0);
  1922. typ:=constsym;
  1923. consttyp:=t;
  1924. value.valueordptr:=v;
  1925. ResStrIndex:=0;
  1926. consttype:=tt;
  1927. end;
  1928. constructor tconstsym.create_ptr(const n : string;t : tconsttyp;v : pointer;const tt:ttype);
  1929. begin
  1930. inherited create(n);
  1931. fillchar(value, sizeof(value), #0);
  1932. typ:=constsym;
  1933. consttyp:=t;
  1934. value.valueptr:=v;
  1935. ResStrIndex:=0;
  1936. consttype:=tt;
  1937. end;
  1938. constructor tconstsym.create_string(const n : string;t : tconsttyp;str:pchar;l:longint);
  1939. begin
  1940. inherited create(n);
  1941. fillchar(value, sizeof(value), #0);
  1942. typ:=constsym;
  1943. consttyp:=t;
  1944. value.valueptr:=str;
  1945. consttype.reset;
  1946. value.len:=l;
  1947. if t=constresourcestring then
  1948. ResStrIndex:=ResourceStrings.Register(name,pchar(value.valueptr),value.len);
  1949. end;
  1950. constructor tconstsym.create_wstring(const n : string;t : tconsttyp;pw:pcompilerwidestring);
  1951. begin
  1952. inherited create(n);
  1953. fillchar(value, sizeof(value), #0);
  1954. typ:=constsym;
  1955. consttyp:=t;
  1956. pcompilerwidestring(value.valueptr):=pw;
  1957. consttype.reset;
  1958. value.len:=getlengthwidestring(pw);
  1959. end;
  1960. constructor tconstsym.ppuload(ppufile:tcompilerppufile);
  1961. var
  1962. pd : pbestreal;
  1963. ps : pnormalset;
  1964. pc : pchar;
  1965. pw : pcompilerwidestring;
  1966. begin
  1967. inherited ppuload(ppufile);
  1968. typ:=constsym;
  1969. consttype.reset;
  1970. consttyp:=tconsttyp(ppufile.getbyte);
  1971. fillchar(value, sizeof(value), #0);
  1972. case consttyp of
  1973. constord :
  1974. begin
  1975. ppufile.gettype(consttype);
  1976. value.valueord:=ppufile.getexprint;
  1977. end;
  1978. constpointer :
  1979. begin
  1980. ppufile.gettype(consttype);
  1981. value.valueordptr:=ppufile.getptruint;
  1982. end;
  1983. constwstring :
  1984. begin
  1985. initwidestring(pw);
  1986. setlengthwidestring(pw,ppufile.getlongint);
  1987. ppufile.getdata(pw^.data,pw^.len*sizeof(tcompilerwidechar));
  1988. pcompilerwidestring(value.valueptr):=pw;
  1989. end;
  1990. conststring,
  1991. constresourcestring :
  1992. begin
  1993. value.len:=ppufile.getlongint;
  1994. getmem(pc,value.len+1);
  1995. ppufile.getdata(pc^,value.len);
  1996. if consttyp=constresourcestring then
  1997. ResStrIndex:=ppufile.getlongint;
  1998. value.valueptr:=pc;
  1999. end;
  2000. constreal :
  2001. begin
  2002. new(pd);
  2003. pd^:=ppufile.getreal;
  2004. value.valueptr:=pd;
  2005. end;
  2006. constset :
  2007. begin
  2008. ppufile.gettype(consttype);
  2009. new(ps);
  2010. ppufile.getnormalset(ps^);
  2011. value.valueptr:=ps;
  2012. end;
  2013. constguid :
  2014. begin
  2015. new(pguid(value.valueptr));
  2016. ppufile.getdata(value.valueptr^,sizeof(tguid));
  2017. end;
  2018. constnil : ;
  2019. else
  2020. Message1(unit_f_ppu_invalid_entry,tostr(ord(consttyp)));
  2021. end;
  2022. end;
  2023. destructor tconstsym.destroy;
  2024. begin
  2025. case consttyp of
  2026. conststring,
  2027. constresourcestring :
  2028. freemem(pchar(value.valueptr),value.len+1);
  2029. constwstring :
  2030. donewidestring(pcompilerwidestring(value.valueptr));
  2031. constreal :
  2032. dispose(pbestreal(value.valueptr));
  2033. constset :
  2034. dispose(pnormalset(value.valueptr));
  2035. constguid :
  2036. dispose(pguid(value.valueptr));
  2037. end;
  2038. inherited destroy;
  2039. end;
  2040. procedure tconstsym.buildderef;
  2041. begin
  2042. if consttyp in [constord,constpointer,constset] then
  2043. consttype.buildderef;
  2044. end;
  2045. procedure tconstsym.deref;
  2046. begin
  2047. if consttyp in [constord,constpointer,constset] then
  2048. consttype.resolve;
  2049. end;
  2050. procedure tconstsym.ppuwrite(ppufile:tcompilerppufile);
  2051. begin
  2052. inherited ppuwrite(ppufile);
  2053. ppufile.putbyte(byte(consttyp));
  2054. case consttyp of
  2055. constnil : ;
  2056. constord :
  2057. begin
  2058. ppufile.puttype(consttype);
  2059. ppufile.putexprint(value.valueord);
  2060. end;
  2061. constpointer :
  2062. begin
  2063. ppufile.puttype(consttype);
  2064. ppufile.putptruint(value.valueordptr);
  2065. end;
  2066. constwstring :
  2067. begin
  2068. ppufile.putlongint(getlengthwidestring(pcompilerwidestring(value.valueptr)));
  2069. ppufile.putdata(pcompilerwidestring(value.valueptr)^.data,pcompilerwidestring(value.valueptr)^.len*sizeof(tcompilerwidechar));
  2070. end;
  2071. conststring,
  2072. constresourcestring :
  2073. begin
  2074. ppufile.putlongint(value.len);
  2075. ppufile.putdata(pchar(value.valueptr)^,value.len);
  2076. if consttyp=constresourcestring then
  2077. ppufile.putlongint(ResStrIndex);
  2078. end;
  2079. constreal :
  2080. ppufile.putreal(pbestreal(value.valueptr)^);
  2081. constset :
  2082. begin
  2083. ppufile.puttype(consttype);
  2084. ppufile.putnormalset(value.valueptr^);
  2085. end;
  2086. constguid :
  2087. ppufile.putdata(value.valueptr^,sizeof(tguid));
  2088. else
  2089. internalerror(13);
  2090. end;
  2091. ppufile.writeentry(ibconstsym);
  2092. end;
  2093. {$ifdef GDB}
  2094. function Tconstsym.stabstring:Pchar;
  2095. var st : string;
  2096. begin
  2097. {even GDB v4.16 only now 'i' 'r' and 'e' !!!}
  2098. case consttyp of
  2099. conststring:
  2100. st:='s'''+backspace_quote(octal_quote(strpas(pchar(value.valueptr)),[#0..#9,#11,#12,#14..#31,'''']),['"','\',#10,#13])+'''';
  2101. constord:
  2102. st:='i'+tostr(value.valueord);
  2103. constpointer:
  2104. st:='i'+tostr(value.valueordptr);
  2105. constreal:
  2106. begin
  2107. system.str(pbestreal(value.valueptr)^,st);
  2108. st := 'r'+st;
  2109. end;
  2110. { if we don't know just put zero !! }
  2111. else st:='i0';
  2112. {***SETCONST}
  2113. {constset:;} {*** I don't know what to do with a set.}
  2114. { sets are not recognized by GDB}
  2115. {***}
  2116. end;
  2117. { valgrind does not support constants }
  2118. if cs_gdb_valgrind in aktglobalswitches then
  2119. stabstring:=nil
  2120. else
  2121. stabstring:=stabstr_evaluate('"${name}:c=$1;",${N_FUNCTION},0,${line},0',[st]);
  2122. end;
  2123. {$endif GDB}
  2124. {****************************************************************************
  2125. TENUMSYM
  2126. ****************************************************************************}
  2127. constructor tenumsym.create(const n : string;def : tenumdef;v : longint);
  2128. begin
  2129. inherited create(n);
  2130. typ:=enumsym;
  2131. definition:=def;
  2132. value:=v;
  2133. { First entry? Then we need to set the minval }
  2134. if def.firstenum=nil then
  2135. begin
  2136. if v>0 then
  2137. def.has_jumps:=true;
  2138. def.setmin(v);
  2139. def.setmax(v);
  2140. end
  2141. else
  2142. begin
  2143. { check for jumps }
  2144. if v>def.max+1 then
  2145. def.has_jumps:=true;
  2146. { update low and high }
  2147. if def.min>v then
  2148. def.setmin(v);
  2149. if def.max<v then
  2150. def.setmax(v);
  2151. end;
  2152. order;
  2153. end;
  2154. constructor tenumsym.ppuload(ppufile:tcompilerppufile);
  2155. begin
  2156. inherited ppuload(ppufile);
  2157. typ:=enumsym;
  2158. ppufile.getderef(definitionderef);
  2159. value:=ppufile.getlongint;
  2160. nextenum := Nil;
  2161. end;
  2162. procedure tenumsym.buildderef;
  2163. begin
  2164. definitionderef.build(definition);
  2165. end;
  2166. procedure tenumsym.deref;
  2167. begin
  2168. definition:=tenumdef(definitionderef.resolve);
  2169. order;
  2170. end;
  2171. procedure tenumsym.order;
  2172. var
  2173. sym : tenumsym;
  2174. begin
  2175. sym := tenumsym(definition.firstenum);
  2176. if sym = nil then
  2177. begin
  2178. definition.firstenum := self;
  2179. nextenum := nil;
  2180. exit;
  2181. end;
  2182. { reorder the symbols in increasing value }
  2183. if value < sym.value then
  2184. begin
  2185. nextenum := sym;
  2186. definition.firstenum := self;
  2187. end
  2188. else
  2189. begin
  2190. while (sym.value <= value) and assigned(sym.nextenum) do
  2191. sym := sym.nextenum;
  2192. nextenum := sym.nextenum;
  2193. sym.nextenum := self;
  2194. end;
  2195. end;
  2196. procedure tenumsym.ppuwrite(ppufile:tcompilerppufile);
  2197. begin
  2198. inherited ppuwrite(ppufile);
  2199. ppufile.putderef(definitionderef);
  2200. ppufile.putlongint(value);
  2201. ppufile.writeentry(ibenumsym);
  2202. end;
  2203. {****************************************************************************
  2204. TTYPESYM
  2205. ****************************************************************************}
  2206. constructor ttypesym.create(const n : string;const tt : ttype);
  2207. begin
  2208. inherited create(n);
  2209. typ:=typesym;
  2210. restype:=tt;
  2211. { register the typesym for the definition }
  2212. if assigned(restype.def) and
  2213. (restype.def.deftype<>errordef) and
  2214. not(assigned(restype.def.typesym)) then
  2215. restype.def.typesym:=self;
  2216. end;
  2217. constructor ttypesym.ppuload(ppufile:tcompilerppufile);
  2218. begin
  2219. inherited ppuload(ppufile);
  2220. typ:=typesym;
  2221. ppufile.gettype(restype);
  2222. end;
  2223. function ttypesym.gettypedef:tdef;
  2224. begin
  2225. gettypedef:=restype.def;
  2226. end;
  2227. procedure ttypesym.buildderef;
  2228. begin
  2229. restype.buildderef;
  2230. end;
  2231. procedure ttypesym.deref;
  2232. begin
  2233. restype.resolve;
  2234. end;
  2235. procedure ttypesym.ppuwrite(ppufile:tcompilerppufile);
  2236. begin
  2237. inherited ppuwrite(ppufile);
  2238. ppufile.puttype(restype);
  2239. ppufile.writeentry(ibtypesym);
  2240. end;
  2241. procedure ttypesym.load_references(ppufile:tcompilerppufile;locals:boolean);
  2242. begin
  2243. inherited load_references(ppufile,locals);
  2244. if (restype.def.deftype=recorddef) then
  2245. tstoredsymtable(trecorddef(restype.def).symtable).load_references(ppufile,locals);
  2246. if (restype.def.deftype=objectdef) then
  2247. tstoredsymtable(tobjectdef(restype.def).symtable).load_references(ppufile,locals);
  2248. end;
  2249. function ttypesym.write_references(ppufile:tcompilerppufile;locals:boolean):boolean;
  2250. var
  2251. d : tderef;
  2252. begin
  2253. d.reset;
  2254. if not inherited write_references(ppufile,locals) then
  2255. begin
  2256. { write address of this symbol if record or object
  2257. even if no real refs are there
  2258. because we need it for the symtable }
  2259. if (restype.def.deftype in [recorddef,objectdef]) then
  2260. begin
  2261. d.build(self);
  2262. ppufile.putderef(d);
  2263. ppufile.writeentry(ibsymref);
  2264. end;
  2265. end;
  2266. write_references:=true;
  2267. if (restype.def.deftype=recorddef) then
  2268. tstoredsymtable(trecorddef(restype.def).symtable).write_references(ppufile,locals);
  2269. if (restype.def.deftype=objectdef) then
  2270. tstoredsymtable(tobjectdef(restype.def).symtable).write_references(ppufile,locals);
  2271. end;
  2272. {$ifdef GDB}
  2273. function ttypesym.stabstring : pchar;
  2274. var stabchar:string[2];
  2275. begin
  2276. stabstring:=nil;
  2277. if restype.def<>nil then
  2278. begin
  2279. if restype.def.deftype in tagtypes then
  2280. stabchar:='Tt'
  2281. else
  2282. stabchar:='t';
  2283. stabstring:=stabstr_evaluate('"${name}:$1$2",${N_LSYM},0,${line},0',[stabchar,tstoreddef(restype.def).numberstring]);
  2284. end;
  2285. end;
  2286. {$endif GDB}
  2287. {****************************************************************************
  2288. TSYSSYM
  2289. ****************************************************************************}
  2290. constructor tsyssym.create(const n : string;l : longint);
  2291. begin
  2292. inherited create(n);
  2293. typ:=syssym;
  2294. number:=l;
  2295. end;
  2296. constructor tsyssym.ppuload(ppufile:tcompilerppufile);
  2297. begin
  2298. inherited ppuload(ppufile);
  2299. typ:=syssym;
  2300. number:=ppufile.getlongint;
  2301. end;
  2302. destructor tsyssym.destroy;
  2303. begin
  2304. inherited destroy;
  2305. end;
  2306. procedure tsyssym.ppuwrite(ppufile:tcompilerppufile);
  2307. begin
  2308. inherited ppuwrite(ppufile);
  2309. ppufile.putlongint(number);
  2310. ppufile.writeentry(ibsyssym);
  2311. end;
  2312. {*****************************************************************************
  2313. TMacro
  2314. *****************************************************************************}
  2315. constructor tmacro.create(const n : string);
  2316. begin
  2317. inherited create(n);
  2318. typ:= macrosym;
  2319. owner:= nil;
  2320. defined:=false;
  2321. is_used:=false;
  2322. is_compiler_var:= false;
  2323. buftext:=nil;
  2324. buflen:=0;
  2325. end;
  2326. constructor tmacro.ppuload(ppufile:tcompilerppufile);
  2327. begin
  2328. inherited ppuload(ppufile);
  2329. typ:=macrosym;
  2330. name:=ppufile.getstring;
  2331. defined:=boolean(ppufile.getbyte);
  2332. is_compiler_var:=boolean(ppufile.getbyte);
  2333. is_used:=false;
  2334. buflen:= ppufile.getlongint;
  2335. if buflen > 0 then
  2336. begin
  2337. getmem(buftext, buflen);
  2338. ppufile.getdata(buftext^, buflen)
  2339. end
  2340. else
  2341. buftext:=nil;
  2342. end;
  2343. destructor tmacro.destroy;
  2344. begin
  2345. if assigned(buftext) then
  2346. freemem(buftext,buflen);
  2347. inherited destroy;
  2348. end;
  2349. procedure tmacro.ppuwrite(ppufile:tcompilerppufile);
  2350. begin
  2351. inherited ppuwrite(ppufile);
  2352. ppufile.putstring(name);
  2353. ppufile.putbyte(byte(defined));
  2354. ppufile.putbyte(byte(is_compiler_var));
  2355. ppufile.putlongint(buflen);
  2356. if buflen > 0 then
  2357. ppufile.putdata(buftext^,buflen);
  2358. ppufile.writeentry(ibmacrosym);
  2359. end;
  2360. {****************************************************************************
  2361. TRTTISYM
  2362. ****************************************************************************}
  2363. constructor trttisym.create(const n:string;rt:trttitype);
  2364. const
  2365. prefix : array[trttitype] of string[5]=('$rtti','$init');
  2366. begin
  2367. inherited create(prefix[rt]+n);
  2368. include(symoptions,sp_internal);
  2369. typ:=rttisym;
  2370. lab:=nil;
  2371. rttityp:=rt;
  2372. end;
  2373. destructor trttisym.destroy;
  2374. begin
  2375. if assigned(_mangledname) then
  2376. begin
  2377. {$ifdef MEMDEBUG}
  2378. memmanglednames.start;
  2379. {$endif MEMDEBUG}
  2380. stringdispose(_mangledname);
  2381. {$ifdef MEMDEBUG}
  2382. memmanglednames.stop;
  2383. {$endif MEMDEBUG}
  2384. end;
  2385. inherited destroy;
  2386. end;
  2387. constructor trttisym.ppuload(ppufile:tcompilerppufile);
  2388. begin
  2389. inherited ppuload(ppufile);
  2390. typ:=rttisym;
  2391. lab:=nil;
  2392. rttityp:=trttitype(ppufile.getbyte);
  2393. end;
  2394. procedure trttisym.ppuwrite(ppufile:tcompilerppufile);
  2395. begin
  2396. inherited ppuwrite(ppufile);
  2397. ppufile.putbyte(byte(rttityp));
  2398. ppufile.writeentry(ibrttisym);
  2399. end;
  2400. function trttisym.mangledname : string;
  2401. const
  2402. prefix : array[trttitype] of string[5]=('RTTI_','INIT_');
  2403. begin
  2404. if not assigned(_mangledname) then
  2405. _mangledname:=stringdup(make_mangledname(prefix[rttityp],owner,Copy(name,5,255)));
  2406. result:=_mangledname^;
  2407. end;
  2408. function trttisym.get_label:tasmsymbol;
  2409. begin
  2410. { the label is always a global label }
  2411. if not assigned(lab) then
  2412. lab:=objectlibrary.newasmsymbol(mangledname,AB_EXTERNAL,AT_DATA);
  2413. get_label:=lab;
  2414. end;
  2415. end.