symsym.pas 63 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094
  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,finput,
  29. cclasses,symnot,
  30. { aasm }
  31. aasmbase,
  32. cpuinfo,cpubase,cgbase,cgutils,parabase
  33. ;
  34. type
  35. { this class is the base for all symbol objects }
  36. tstoredsym = class(tsym)
  37. public
  38. constructor create(st:tsymtyp;const n : string);
  39. constructor ppuload(st:tsymtyp;ppufile:tcompilerppufile);
  40. destructor destroy;override;
  41. procedure ppuwrite(ppufile:tcompilerppufile);virtual;
  42. end;
  43. tlabelsym = class(tstoredsym)
  44. used,
  45. defined : boolean;
  46. { points to the matching node, only valid resultdef pass is run and
  47. the goto<->label relation in the node tree is created, should
  48. be a tnode }
  49. code : pointer;
  50. { when the label is defined in an asm block, this points to the
  51. generated asmlabel }
  52. asmblocklabel : tasmlabel;
  53. constructor create(const n : string);
  54. constructor ppuload(ppufile:tcompilerppufile);
  55. procedure ppuwrite(ppufile:tcompilerppufile);override;
  56. function mangledname:string;override;
  57. end;
  58. tunitsym = class(Tstoredsym)
  59. module : tobject; { tmodule }
  60. constructor create(const n : string;amodule : tobject);
  61. constructor ppuload(ppufile:tcompilerppufile);
  62. destructor destroy;override;
  63. procedure ppuwrite(ppufile:tcompilerppufile);override;
  64. end;
  65. terrorsym = class(Tsym)
  66. constructor create;
  67. end;
  68. tprocsym = class(tstoredsym)
  69. protected
  70. FProcdefList : TFPObjectList;
  71. FProcdefDerefList : TFPList;
  72. public
  73. overloadchecked : boolean;
  74. constructor create(const n : string);
  75. constructor ppuload(ppufile:tcompilerppufile);
  76. destructor destroy;override;
  77. { writes all declarations except the specified one }
  78. procedure write_parameter_lists(skipdef:tprocdef);
  79. { tests, if all procedures definitions are defined and not }
  80. { only forward }
  81. procedure check_forward;
  82. procedure unchain_overload;
  83. procedure ppuwrite(ppufile:tcompilerppufile);override;
  84. procedure buildderef;override;
  85. procedure deref;override;
  86. procedure add_para_match_to(Aprocsym:Tprocsym;cpoptions:tcompare_paras_options);
  87. function find_procdef_bytype(pt:Tproctypeoption):Tprocdef;
  88. function find_procdef_bypara(para:TFPObjectList;retdef:tdef;cpoptions:tcompare_paras_options):Tprocdef;
  89. function find_procdef_byprocvardef(d:Tprocvardef):Tprocdef;
  90. function find_procdef_assignment_operator(fromdef,todef:tdef;var besteq:tequaltype):Tprocdef;
  91. { currobjdef is the object def to assume, this is necessary for protected and
  92. private, context is the object def we're really in, this is for the strict stuff }
  93. function is_visible_for_object(currobjdef:tdef;context:tdef):boolean;override;
  94. property ProcdefList:TFPObjectList read FProcdefList;
  95. end;
  96. ttypesym = class(Tstoredsym)
  97. typedef : tdef;
  98. typedefderef : tderef;
  99. constructor create(const n : string;def:tdef);
  100. constructor ppuload(ppufile:tcompilerppufile);
  101. procedure ppuwrite(ppufile:tcompilerppufile);override;
  102. procedure buildderef;override;
  103. procedure deref;override;
  104. end;
  105. tabstractvarsym = class(tstoredsym)
  106. varoptions : tvaroptions;
  107. varspez : tvarspez; { sets the type of access }
  108. varregable : tvarregable;
  109. varstate : tvarstate;
  110. notifications : Tlinkedlist;
  111. constructor create(st:tsymtyp;const n : string;vsp:tvarspez;def:tdef;vopts:tvaroptions);
  112. constructor ppuload(st:tsymtyp;ppufile:tcompilerppufile);
  113. destructor destroy;override;
  114. procedure ppuwrite(ppufile:tcompilerppufile);override;
  115. procedure buildderef;override;
  116. procedure deref;override;
  117. function getsize : longint;
  118. function getpackedbitsize : longint;
  119. function is_regvar(refpara: boolean):boolean;
  120. procedure trigger_notifications(what:Tnotification_flag);
  121. function register_notification(flags:Tnotification_flags;
  122. callback:Tnotification_callback):cardinal;
  123. procedure unregister_notification(id:cardinal);
  124. private
  125. procedure setvardef(def:tdef);
  126. _vardef : tdef;
  127. vardefderef : tderef;
  128. public
  129. property vardef: tdef read _vardef write setvardef;
  130. end;
  131. tfieldvarsym = class(tabstractvarsym)
  132. fieldoffset : aint; { offset in record/object }
  133. constructor create(const n : string;vsp:tvarspez;def:tdef;vopts:tvaroptions);
  134. constructor ppuload(ppufile:tcompilerppufile);
  135. procedure ppuwrite(ppufile:tcompilerppufile);override;
  136. function mangledname:string;override;
  137. end;
  138. tabstractnormalvarsym = class(tabstractvarsym)
  139. defaultconstsym : tsym;
  140. defaultconstsymderef : tderef;
  141. localloc : TLocation; { register/reference for local var }
  142. initialloc : TLocation; { initial location so it can still be initialized later after the location was changed by SSA }
  143. constructor create(st:tsymtyp;const n : string;vsp:tvarspez;def:tdef;vopts:tvaroptions);
  144. constructor ppuload(st:tsymtyp;ppufile:tcompilerppufile);
  145. procedure ppuwrite(ppufile:tcompilerppufile);override;
  146. procedure buildderef;override;
  147. procedure deref;override;
  148. end;
  149. tlocalvarsym = class(tabstractnormalvarsym)
  150. constructor create(const n : string;vsp:tvarspez;def:tdef;vopts:tvaroptions);
  151. constructor ppuload(ppufile:tcompilerppufile);
  152. procedure ppuwrite(ppufile:tcompilerppufile);override;
  153. end;
  154. tparavarsym = class(tabstractnormalvarsym)
  155. paraloc : array[tcallercallee] of TCGPara;
  156. paranr : word; { position of this parameter }
  157. {$ifdef EXTDEBUG}
  158. eqval : tequaltype;
  159. {$endif EXTDEBUG}
  160. constructor create(const n : string;nr:word;vsp:tvarspez;def:tdef;vopts:tvaroptions);
  161. constructor ppuload(ppufile:tcompilerppufile);
  162. destructor destroy;override;
  163. procedure ppuwrite(ppufile:tcompilerppufile);override;
  164. end;
  165. tglobalvarsym = class(tabstractnormalvarsym)
  166. private
  167. _mangledname : pshortstring;
  168. public
  169. constructor create(const n : string;vsp:tvarspez;def:tdef;vopts:tvaroptions);
  170. constructor create_dll(const n : string;vsp:tvarspez;def:tdef);
  171. constructor create_C(const n,mangled : string;vsp:tvarspez;def:tdef);
  172. constructor ppuload(ppufile:tcompilerppufile);
  173. destructor destroy;override;
  174. procedure ppuwrite(ppufile:tcompilerppufile);override;
  175. function mangledname:string;override;
  176. procedure set_mangledname(const s:string);
  177. end;
  178. tabsolutevarsym = class(tabstractvarsym)
  179. public
  180. abstyp : absolutetyp;
  181. {$ifdef i386}
  182. absseg : boolean;
  183. {$endif i386}
  184. asmname : pshortstring;
  185. addroffset : aint;
  186. ref : tpropaccesslist;
  187. constructor create(const n : string;def:tdef);
  188. constructor create_ref(const n : string;def:tdef;_ref:tpropaccesslist);
  189. destructor destroy;override;
  190. constructor ppuload(ppufile:tcompilerppufile);
  191. procedure buildderef;override;
  192. procedure deref;override;
  193. function mangledname : string;override;
  194. procedure ppuwrite(ppufile:tcompilerppufile);override;
  195. end;
  196. tpropaccesslisttypes=(palt_none,palt_read,palt_write,palt_stored);
  197. tpropertysym = class(Tstoredsym)
  198. propoptions : tpropertyoptions;
  199. overridenpropsym : tpropertysym;
  200. overridenpropsymderef : tderef;
  201. propdef : tdef;
  202. propdefderef : tderef;
  203. indexdef : tdef;
  204. indexdefderef : tderef;
  205. index,
  206. default : longint;
  207. propaccesslist : array[tpropaccesslisttypes] of tpropaccesslist;
  208. constructor create(const n : string);
  209. destructor destroy;override;
  210. constructor ppuload(ppufile:tcompilerppufile);
  211. function getsize : longint;
  212. procedure ppuwrite(ppufile:tcompilerppufile);override;
  213. procedure buildderef;override;
  214. procedure deref;override;
  215. end;
  216. ttypedconstsym = class(tstoredsym)
  217. private
  218. _mangledname : pshortstring;
  219. public
  220. typedconstdef : tdef;
  221. typedconstdefderef : tderef;
  222. is_writable : boolean;
  223. constructor create(const n : string;def : tdef;writable : boolean);
  224. constructor ppuload(ppufile:tcompilerppufile);
  225. destructor destroy;override;
  226. function mangledname : string;override;
  227. procedure ppuwrite(ppufile:tcompilerppufile);override;
  228. procedure buildderef;override;
  229. procedure deref;override;
  230. function getsize:longint;
  231. procedure set_mangledname(const s:string);
  232. end;
  233. tconstvalue = record
  234. case integer of
  235. 0: (valueord : tconstexprint);
  236. 1: (valueordptr : tconstptruint);
  237. 2: (valueptr : pointer; len : longint);
  238. end;
  239. tconstsym = class(tstoredsym)
  240. constdef : tdef;
  241. constdefderef : tderef;
  242. consttyp : tconsttyp;
  243. value : tconstvalue;
  244. resstrindex : longint; { needed for resource strings }
  245. constructor create_ord(const n : string;t : tconsttyp;v : tconstexprint;def:tdef);
  246. constructor create_ordptr(const n : string;t : tconsttyp;v : tconstptruint;def:tdef);
  247. constructor create_ptr(const n : string;t : tconsttyp;v : pointer;def:tdef);
  248. constructor create_string(const n : string;t : tconsttyp;str:pchar;l:longint);
  249. constructor create_wstring(const n : string;t : tconsttyp;pw:pcompilerwidestring);
  250. constructor ppuload(ppufile:tcompilerppufile);
  251. destructor destroy;override;
  252. procedure buildderef;override;
  253. procedure deref;override;
  254. procedure ppuwrite(ppufile:tcompilerppufile);override;
  255. end;
  256. tenumsym = class(Tstoredsym)
  257. value : longint;
  258. definition : tenumdef;
  259. definitionderef : tderef;
  260. nextenum : tenumsym;
  261. constructor create(const n : string;def : tenumdef;v : longint);
  262. constructor ppuload(ppufile:tcompilerppufile);
  263. procedure ppuwrite(ppufile:tcompilerppufile);override;
  264. procedure buildderef;override;
  265. procedure deref;override;
  266. procedure order;
  267. end;
  268. tsyssym = class(Tstoredsym)
  269. number : longint;
  270. constructor create(const n : string;l : longint);
  271. constructor ppuload(ppufile:tcompilerppufile);
  272. destructor destroy;override;
  273. procedure ppuwrite(ppufile:tcompilerppufile);override;
  274. end;
  275. const
  276. maxmacrolen=16*1024;
  277. type
  278. pmacrobuffer = ^tmacrobuffer;
  279. tmacrobuffer = array[0..maxmacrolen-1] of char;
  280. tmacro = class(tstoredsym)
  281. {Normally true, but false when a previously defined macro is undef-ed}
  282. defined : boolean;
  283. {True if this is a mac style compiler variable, in which case no macro
  284. substitutions shall be done.}
  285. is_compiler_var : boolean;
  286. {Whether the macro was used. NOTE: A use of a macro which was never defined}
  287. {e. g. an IFDEF which returns false, will not be registered as used,}
  288. {since there is no place to register its use. }
  289. is_used : boolean;
  290. buftext : pchar;
  291. buflen : longint;
  292. constructor create(const n : string);
  293. constructor ppuload(ppufile:tcompilerppufile);
  294. procedure ppuwrite(ppufile:tcompilerppufile);override;
  295. destructor destroy;override;
  296. function GetCopy:tmacro;
  297. end;
  298. { compiler generated symbol to point to rtti and init/finalize tables }
  299. trttisym = class(tstoredsym)
  300. private
  301. _mangledname : pshortstring;
  302. public
  303. lab : tasmsymbol;
  304. rttityp : trttitype;
  305. constructor create(const n:string;rt:trttitype);
  306. constructor ppuload(ppufile:tcompilerppufile);
  307. destructor destroy;override;
  308. procedure ppuwrite(ppufile:tcompilerppufile);override;
  309. function mangledname:string;override;
  310. function get_label:tasmsymbol;
  311. end;
  312. var
  313. generrorsym : tsym;
  314. implementation
  315. uses
  316. { global }
  317. verbose,
  318. { target }
  319. systems,
  320. { symtable }
  321. defutil,symtable,
  322. fmodule,
  323. { tree }
  324. node,
  325. { aasm }
  326. aasmtai,aasmdata,
  327. { codegen }
  328. paramgr,
  329. procinfo
  330. ;
  331. {****************************************************************************
  332. Helpers
  333. ****************************************************************************}
  334. {****************************************************************************
  335. TSYM (base for all symtypes)
  336. ****************************************************************************}
  337. constructor tstoredsym.create(st:tsymtyp;const n : string);
  338. begin
  339. inherited create(st,n);
  340. { Register in current_module }
  341. if assigned(current_module) then
  342. begin
  343. current_module.symlist.Add(self);
  344. SymId:=current_module.symlist.Count-1;
  345. end;
  346. end;
  347. constructor tstoredsym.ppuload(st:tsymtyp;ppufile:tcompilerppufile);
  348. begin
  349. SymId:=ppufile.getlongint;
  350. inherited Create(st,ppufile.getstring);
  351. { Register symbol }
  352. current_module.symlist[SymId]:=self;
  353. ppufile.getposinfo(fileinfo);
  354. ppufile.getsmallset(symoptions);
  355. end;
  356. procedure tstoredsym.ppuwrite(ppufile:tcompilerppufile);
  357. begin
  358. ppufile.putlongint(SymId);
  359. ppufile.putstring(realname);
  360. ppufile.putposinfo(fileinfo);
  361. ppufile.putsmallset(symoptions);
  362. end;
  363. destructor tstoredsym.destroy;
  364. begin
  365. inherited destroy;
  366. end;
  367. {****************************************************************************
  368. TLABELSYM
  369. ****************************************************************************}
  370. constructor tlabelsym.create(const n : string);
  371. begin
  372. inherited create(labelsym,n);
  373. used:=false;
  374. defined:=false;
  375. code:=nil;
  376. end;
  377. constructor tlabelsym.ppuload(ppufile:tcompilerppufile);
  378. begin
  379. inherited ppuload(labelsym,ppufile);
  380. code:=nil;
  381. used:=false;
  382. defined:=true;
  383. end;
  384. procedure tlabelsym.ppuwrite(ppufile:tcompilerppufile);
  385. begin
  386. if owner.symtabletype=globalsymtable then
  387. Message(sym_e_ill_label_decl)
  388. else
  389. begin
  390. inherited ppuwrite(ppufile);
  391. ppufile.writeentry(iblabelsym);
  392. end;
  393. end;
  394. function tlabelsym.mangledname:string;
  395. begin
  396. if not(defined) then
  397. begin
  398. defined:=true;
  399. current_asmdata.getjumplabel(asmblocklabel);
  400. end;
  401. result:=asmblocklabel.name;
  402. end;
  403. {****************************************************************************
  404. TUNITSYM
  405. ****************************************************************************}
  406. constructor tunitsym.create(const n : string;amodule : tobject);
  407. var
  408. old_make_ref : boolean;
  409. begin
  410. old_make_ref:=make_ref;
  411. make_ref:=false;
  412. inherited create(unitsym,n);
  413. make_ref:=old_make_ref;
  414. module:=amodule;
  415. end;
  416. constructor tunitsym.ppuload(ppufile:tcompilerppufile);
  417. begin
  418. inherited ppuload(unitsym,ppufile);
  419. module:=nil;
  420. end;
  421. destructor tunitsym.destroy;
  422. begin
  423. inherited destroy;
  424. end;
  425. procedure tunitsym.ppuwrite(ppufile:tcompilerppufile);
  426. begin
  427. inherited ppuwrite(ppufile);
  428. ppufile.writeentry(ibunitsym);
  429. end;
  430. {****************************************************************************
  431. TPROCSYM
  432. ****************************************************************************}
  433. constructor tprocsym.create(const n : string);
  434. begin
  435. inherited create(procsym,n);
  436. FProcdefList:=TFPObjectList.Create(false);
  437. FProcdefderefList:=nil;
  438. { the tprocdef have their own symoptions, make the procsym
  439. always visible }
  440. symoptions:=[sp_public];
  441. overloadchecked:=false;
  442. end;
  443. constructor tprocsym.ppuload(ppufile:tcompilerppufile);
  444. var
  445. pdderef : tderef;
  446. i,
  447. pdcnt : longint;
  448. begin
  449. inherited ppuload(procsym,ppufile);
  450. FProcdefList:=TFPObjectList.Create(false);
  451. FProcdefDerefList:=TFPList.Create;
  452. pdcnt:=ppufile.getword;
  453. for i:=1 to pdcnt do
  454. begin
  455. ppufile.getderef(pdderef);
  456. FProcdefDerefList.Add(Pointer(PtrInt(pdderef.dataidx)));
  457. end;
  458. end;
  459. destructor tprocsym.destroy;
  460. begin
  461. FProcdefList.Free;
  462. if assigned(FProcdefDerefList) then
  463. FProcdefDerefList.Free;
  464. inherited destroy;
  465. end;
  466. procedure tprocsym.ppuwrite(ppufile:tcompilerppufile);
  467. var
  468. i : longint;
  469. d : tderef;
  470. begin
  471. inherited ppuwrite(ppufile);
  472. ppufile.putword(FProcdefDerefList.Count);
  473. for i:=0 to FProcdefDerefList.Count-1 do
  474. begin
  475. d.dataidx:=PtrInt(FProcdefDerefList[i]);
  476. ppufile.putderef(d);
  477. end;
  478. ppufile.writeentry(ibprocsym);
  479. end;
  480. procedure tprocsym.write_parameter_lists(skipdef:tprocdef);
  481. var
  482. i : longint;
  483. pd : tprocdef;
  484. begin
  485. for i:=0 to ProcdefList.Count-1 do
  486. begin
  487. pd:=tprocdef(ProcdefList[i]);
  488. if pd<>skipdef then
  489. MessagePos1(pd.fileinfo,sym_h_param_list,pd.fullprocname(false));
  490. end;
  491. end;
  492. procedure tprocsym.check_forward;
  493. var
  494. i : longint;
  495. pd : tprocdef;
  496. begin
  497. for i:=0 to ProcdefList.Count-1 do
  498. begin
  499. pd:=tprocdef(ProcdefList[i]);
  500. if (pd.owner=owner) and (pd.forwarddef) then
  501. begin
  502. { For mode macpas. Make implicit externals (procedures declared in the interface
  503. section which do not have a counterpart in the implementation)
  504. to be an imported procedure }
  505. if (m_mac in current_settings.modeswitches) and
  506. (pd.interfacedef) then
  507. begin
  508. pd.forwarddef:=false;
  509. pd.setmangledname(target_info.CPrefix+tprocdef(pd).procsym.realname);
  510. end
  511. else
  512. begin
  513. MessagePos1(pd.fileinfo,sym_e_forward_not_resolved,pd.fullprocname(false));
  514. { Turn further error messages off }
  515. pd.forwarddef:=false;
  516. end
  517. end;
  518. end;
  519. end;
  520. procedure tprocsym.buildderef;
  521. var
  522. i : longint;
  523. pd : tprocdef;
  524. d : tderef;
  525. begin
  526. if not assigned(FProcdefDerefList) then
  527. FProcdefDerefList:=TFPList.Create
  528. else
  529. FProcdefDerefList.Clear;
  530. for i:=0 to ProcdefList.Count-1 do
  531. begin
  532. pd:=tprocdef(ProcdefList[i]);
  533. { only write the proc definitions that belong
  534. to this procsym and are in the global symtable }
  535. if pd.owner=owner then
  536. begin
  537. d.build(pd);
  538. FProcdefDerefList.Add(Pointer(PtrInt(d.dataidx)));
  539. end;
  540. end;
  541. end;
  542. procedure tprocsym.deref;
  543. var
  544. i : longint;
  545. pd : tprocdef;
  546. d : tderef;
  547. begin
  548. { Clear all procdefs }
  549. ProcdefList.Clear;
  550. if not assigned(FProcdefDerefList) then
  551. internalerror(200611031);
  552. for i:=0 to FProcdefDerefList.Count-1 do
  553. begin
  554. d.dataidx:=PtrInt(FProcdefDerefList[i]);
  555. pd:=tprocdef(d.resolve);
  556. ProcdefList.Add(pd);
  557. end;
  558. end;
  559. procedure Tprocsym.add_para_match_to(Aprocsym:Tprocsym;cpoptions:tcompare_paras_options);
  560. var
  561. i : longint;
  562. pd : tprocdef;
  563. begin
  564. for i:=0 to ProcdefList.Count-1 do
  565. begin
  566. pd:=tprocdef(ProcdefList[i]);
  567. if Aprocsym.find_procdef_bypara(pd.paras,nil,cpoptions)=nil then
  568. Aprocsym.ProcdefList.Add(pd);
  569. end;
  570. end;
  571. function Tprocsym.Find_procdef_bytype(pt:Tproctypeoption):Tprocdef;
  572. var
  573. i : longint;
  574. pd : tprocdef;
  575. begin
  576. result:=nil;
  577. for i:=0 to ProcdefList.Count-1 do
  578. begin
  579. pd:=tprocdef(ProcdefList[i]);
  580. if pd.proctypeoption=pt then
  581. begin
  582. result:=pd;
  583. exit;
  584. end;
  585. end;
  586. end;
  587. function Tprocsym.Find_procdef_bypara(para:TFPObjectList;retdef:tdef;
  588. cpoptions:tcompare_paras_options):Tprocdef;
  589. var
  590. i : longint;
  591. pd : tprocdef;
  592. eq : tequaltype;
  593. begin
  594. result:=nil;
  595. for i:=0 to ProcdefList.Count-1 do
  596. begin
  597. pd:=tprocdef(ProcdefList[i]);
  598. if assigned(retdef) then
  599. eq:=compare_defs(retdef,pd.returndef,nothingn)
  600. else
  601. eq:=te_equal;
  602. if (eq>=te_equal) or
  603. ((cpo_allowconvert in cpoptions) and (eq>te_incompatible)) then
  604. begin
  605. eq:=compare_paras(para,pd.paras,cp_value_equal_const,cpoptions);
  606. if (eq>=te_equal) or
  607. ((cpo_allowconvert in cpoptions) and (eq>te_incompatible)) then
  608. begin
  609. result:=pd;
  610. exit;
  611. end;
  612. end;
  613. end;
  614. end;
  615. function Tprocsym.Find_procdef_byprocvardef(d:Tprocvardef):Tprocdef;
  616. var
  617. i : longint;
  618. bestpd,
  619. pd : tprocdef;
  620. eq,besteq : tequaltype;
  621. begin
  622. { This function will return the pprocdef of pprocsym that
  623. is the best match for procvardef. When there are multiple
  624. matches it returns nil.}
  625. result:=nil;
  626. bestpd:=nil;
  627. besteq:=te_incompatible;
  628. for i:=0 to ProcdefList.Count-1 do
  629. begin
  630. pd:=tprocdef(ProcdefList[i]);
  631. eq:=proc_to_procvar_equal(pd,d);
  632. if eq>=te_equal then
  633. begin
  634. { multiple procvars with the same equal level }
  635. if assigned(bestpd) and
  636. (besteq=eq) then
  637. exit;
  638. if eq>besteq then
  639. begin
  640. besteq:=eq;
  641. bestpd:=pd;
  642. end;
  643. end;
  644. end;
  645. result:=bestpd;
  646. end;
  647. function Tprocsym.Find_procdef_assignment_operator(fromdef,todef:tdef;var besteq:tequaltype):Tprocdef;
  648. var
  649. paraidx,
  650. i : longint;
  651. bestpd,
  652. hpd,
  653. pd : tprocdef;
  654. convtyp : tconverttype;
  655. eq : tequaltype;
  656. begin
  657. { This function will return the pprocdef of pprocsym that
  658. is the best match for procvardef. When there are multiple
  659. matches it returns nil.}
  660. result:=nil;
  661. bestpd:=nil;
  662. besteq:=te_incompatible;
  663. for i:=0 to ProcdefList.Count-1 do
  664. begin
  665. pd:=tprocdef(ProcdefList[i]);
  666. if equal_defs(todef,pd.returndef) and
  667. { the result type must be always really equal and not an alias,
  668. if you mess with this code, check tw4093 }
  669. ((todef=pd.returndef) or
  670. (
  671. not(df_unique in todef.defoptions) and
  672. not(df_unique in pd.returndef.defoptions)
  673. )
  674. ) then
  675. begin
  676. paraidx:=0;
  677. { ignore vs_hidden parameters }
  678. while (paraidx<pd.paras.count) and
  679. assigned(pd.paras[paraidx]) and
  680. (vo_is_hidden_para in tparavarsym(pd.paras[paraidx]).varoptions) do
  681. inc(paraidx);
  682. if (paraidx<pd.paras.count) and
  683. assigned(pd.paras[paraidx]) then
  684. begin
  685. eq:=compare_defs_ext(fromdef,tparavarsym(pd.paras[paraidx]).vardef,nothingn,convtyp,hpd,[]);
  686. { alias? if yes, only l1 choice,
  687. if you mess with this code, check tw4093 }
  688. if (eq=te_exact) and
  689. (fromdef<>tparavarsym(pd.paras[paraidx]).vardef) and
  690. ((df_unique in fromdef.defoptions) or
  691. (df_unique in tparavarsym(pd.paras[paraidx]).vardef.defoptions)) then
  692. eq:=te_convert_l1;
  693. if eq=te_exact then
  694. begin
  695. besteq:=eq;
  696. result:=pd;
  697. exit;
  698. end;
  699. if eq>besteq then
  700. begin
  701. bestpd:=pd;
  702. besteq:=eq;
  703. end;
  704. end;
  705. end;
  706. end;
  707. result:=bestpd;
  708. end;
  709. procedure tprocsym.unchain_overload;
  710. var
  711. i : longint;
  712. pd : tprocdef;
  713. begin
  714. { remove all overloaded procdefs from the
  715. procdeflist that are not in the current symtable }
  716. overloadchecked:=false;
  717. { reset new lists }
  718. for i:=0 to ProcdefList.Count-1 do
  719. begin
  720. pd:=tprocdef(ProcdefList[i]);
  721. { only keep the proc definitions:
  722. - are not deref'd (def=nil)
  723. - are in the same symtable as the procsym (for example both
  724. are in the staticsymtable) }
  725. if not(pd.owner=owner) then
  726. ProcdefList[i]:=nil;
  727. end;
  728. { Remove cleared entries }
  729. ProcdefList.Pack;
  730. end;
  731. function tprocsym.is_visible_for_object(currobjdef:tdef;context:tdef):boolean;
  732. var
  733. i : longint;
  734. pd : tprocdef;
  735. begin
  736. { This procsym is visible, when there is at least
  737. one of the procdefs visible }
  738. result:=false;
  739. for i:=0 to ProcdefList.Count-1 do
  740. begin
  741. pd:=tprocdef(ProcdefList[i]);
  742. if (pd.owner=owner) and
  743. pd.is_visible_for_object(tobjectdef(currobjdef),tobjectdef(context)) then
  744. begin
  745. result:=true;
  746. exit;
  747. end;
  748. end;
  749. end;
  750. {****************************************************************************
  751. TERRORSYM
  752. ****************************************************************************}
  753. constructor terrorsym.create;
  754. begin
  755. inherited create(errorsym,'');
  756. end;
  757. {****************************************************************************
  758. TPROPERTYSYM
  759. ****************************************************************************}
  760. constructor tpropertysym.create(const n : string);
  761. var
  762. pap : tpropaccesslisttypes;
  763. begin
  764. inherited create(propertysym,n);
  765. propoptions:=[];
  766. index:=0;
  767. default:=0;
  768. propdef:=nil;
  769. indexdef:=nil;
  770. for pap:=low(tpropaccesslisttypes) to high(tpropaccesslisttypes) do
  771. propaccesslist[pap]:=tpropaccesslist.create;
  772. end;
  773. constructor tpropertysym.ppuload(ppufile:tcompilerppufile);
  774. var
  775. pap : tpropaccesslisttypes;
  776. begin
  777. inherited ppuload(propertysym,ppufile);
  778. ppufile.getsmallset(propoptions);
  779. ppufile.getderef(overridenpropsymderef);
  780. ppufile.getderef(propdefderef);
  781. index:=ppufile.getlongint;
  782. default:=ppufile.getlongint;
  783. ppufile.getderef(indexdefderef);
  784. for pap:=low(tpropaccesslisttypes) to high(tpropaccesslisttypes) do
  785. propaccesslist[pap]:=ppufile.getpropaccesslist;
  786. end;
  787. destructor tpropertysym.destroy;
  788. var
  789. pap : tpropaccesslisttypes;
  790. begin
  791. for pap:=low(tpropaccesslisttypes) to high(tpropaccesslisttypes) do
  792. propaccesslist[pap].free;
  793. inherited destroy;
  794. end;
  795. procedure tpropertysym.buildderef;
  796. var
  797. pap : tpropaccesslisttypes;
  798. begin
  799. overridenpropsymderef.build(overridenpropsym);
  800. propdefderef.build(propdef);
  801. indexdefderef.build(indexdef);
  802. for pap:=low(tpropaccesslisttypes) to high(tpropaccesslisttypes) do
  803. propaccesslist[pap].buildderef;
  804. end;
  805. procedure tpropertysym.deref;
  806. var
  807. pap : tpropaccesslisttypes;
  808. begin
  809. overridenpropsym:=tpropertysym(overridenpropsymderef.resolve);
  810. indexdef:=tdef(indexdefderef.resolve);
  811. propdef:=tdef(propdefderef.resolve);
  812. for pap:=low(tpropaccesslisttypes) to high(tpropaccesslisttypes) do
  813. propaccesslist[pap].resolve;
  814. end;
  815. function tpropertysym.getsize : longint;
  816. begin
  817. getsize:=0;
  818. end;
  819. procedure tpropertysym.ppuwrite(ppufile:tcompilerppufile);
  820. var
  821. pap : tpropaccesslisttypes;
  822. begin
  823. inherited ppuwrite(ppufile);
  824. ppufile.putsmallset(propoptions);
  825. ppufile.putderef(overridenpropsymderef);
  826. ppufile.putderef(propdefderef);
  827. ppufile.putlongint(index);
  828. ppufile.putlongint(default);
  829. ppufile.putderef(indexdefderef);
  830. for pap:=low(tpropaccesslisttypes) to high(tpropaccesslisttypes) do
  831. ppufile.putpropaccesslist(propaccesslist[pap]);
  832. ppufile.writeentry(ibpropertysym);
  833. end;
  834. {****************************************************************************
  835. TABSTRACTVARSYM
  836. ****************************************************************************}
  837. constructor tabstractvarsym.create(st:tsymtyp;const n : string;vsp:tvarspez;def:tdef;vopts:tvaroptions);
  838. begin
  839. inherited create(st,n);
  840. vardef:=def;
  841. varspez:=vsp;
  842. varstate:=vs_declared;
  843. varoptions:=vopts;
  844. end;
  845. constructor tabstractvarsym.ppuload(st:tsymtyp;ppufile:tcompilerppufile);
  846. begin
  847. inherited ppuload(st,ppufile);
  848. varstate:=vs_readwritten;
  849. varspez:=tvarspez(ppufile.getbyte);
  850. varregable:=tvarregable(ppufile.getbyte);
  851. ppufile.getderef(vardefderef);
  852. ppufile.getsmallset(varoptions);
  853. end;
  854. destructor tabstractvarsym.destroy;
  855. begin
  856. if assigned(notifications) then
  857. notifications.destroy;
  858. inherited destroy;
  859. end;
  860. procedure tabstractvarsym.buildderef;
  861. begin
  862. vardefderef.build(vardef);
  863. end;
  864. procedure tabstractvarsym.deref;
  865. begin
  866. vardef:=tdef(vardefderef.resolve);
  867. end;
  868. procedure tabstractvarsym.ppuwrite(ppufile:tcompilerppufile);
  869. var
  870. oldintfcrc : boolean;
  871. begin
  872. inherited ppuwrite(ppufile);
  873. ppufile.putbyte(byte(varspez));
  874. oldintfcrc:=ppufile.do_crc;
  875. ppufile.do_crc:=false;
  876. ppufile.putbyte(byte(varregable));
  877. ppufile.do_crc:=oldintfcrc;
  878. ppufile.putderef(vardefderef);
  879. ppufile.putsmallset(varoptions);
  880. end;
  881. function tabstractvarsym.getsize : longint;
  882. begin
  883. if assigned(vardef) and
  884. ((vardef.typ<>arraydef) or
  885. is_dynamic_array(vardef) or
  886. (tarraydef(vardef).highrange>=tarraydef(vardef).lowrange)) then
  887. result:=vardef.size
  888. else
  889. result:=0;
  890. end;
  891. function tabstractvarsym.getpackedbitsize : longint;
  892. begin
  893. { bitpacking is only done for ordinals }
  894. if not is_ordinal(vardef) then
  895. internalerror(2006082010);
  896. result:=vardef.packedbitsize;
  897. end;
  898. function tabstractvarsym.is_regvar(refpara: boolean):boolean;
  899. begin
  900. { Register variables are not allowed in the following cases:
  901. - regvars are disabled
  902. - exceptions are used (after an exception is raised the contents of the
  903. registers is not valid anymore)
  904. - it has a local copy
  905. - the value needs to be in memory (i.e. reference counted) }
  906. result:=(cs_opt_regvar in current_settings.optimizerswitches) and
  907. not(pi_has_assembler_block in current_procinfo.flags) and
  908. not(pi_uses_exceptions in current_procinfo.flags) and
  909. not(vo_has_local_copy in varoptions) and
  910. ((refpara and
  911. (varregable <> vr_none)) or
  912. (not refpara and
  913. not(varregable in [vr_none,vr_addr])))
  914. {$if not defined(powerpc) and not defined(powerpc64)}
  915. and ((vardef.typ <> recorddef) or
  916. (varregable = vr_addr) or
  917. not(varstate in [vs_written,vs_readwritten]));
  918. {$endif}
  919. end;
  920. procedure tabstractvarsym.trigger_notifications(what:Tnotification_flag);
  921. var n:Tnotification;
  922. begin
  923. if assigned(notifications) then
  924. begin
  925. n:=Tnotification(notifications.first);
  926. while assigned(n) do
  927. begin
  928. if what in n.flags then
  929. n.callback(what,self);
  930. n:=Tnotification(n.next);
  931. end;
  932. end;
  933. end;
  934. function Tabstractvarsym.register_notification(flags:Tnotification_flags;callback:
  935. Tnotification_callback):cardinal;
  936. var n:Tnotification;
  937. begin
  938. if not assigned(notifications) then
  939. notifications:=Tlinkedlist.create;
  940. n:=Tnotification.create(flags,callback);
  941. register_notification:=n.id;
  942. notifications.concat(n);
  943. end;
  944. procedure Tabstractvarsym.unregister_notification(id:cardinal);
  945. var n:Tnotification;
  946. begin
  947. if not assigned(notifications) then
  948. internalerror(200212311)
  949. else
  950. begin
  951. n:=Tnotification(notifications.first);
  952. while assigned(n) do
  953. begin
  954. if n.id=id then
  955. begin
  956. notifications.remove(n);
  957. n.destroy;
  958. exit;
  959. end;
  960. n:=Tnotification(n.next);
  961. end;
  962. internalerror(200212311)
  963. end;
  964. end;
  965. procedure tabstractvarsym.setvardef(def:tdef);
  966. begin
  967. _vardef := def;
  968. { can we load the value into a register ? }
  969. if not assigned(owner) or
  970. (owner.symtabletype in [localsymtable,parasymtable]) or
  971. (
  972. (owner.symtabletype=staticsymtable) and
  973. not(cs_create_pic in current_settings.moduleswitches)
  974. ) then
  975. begin
  976. if tstoreddef(vardef).is_intregable then
  977. varregable:=vr_intreg
  978. else
  979. { $warning TODO: no fpu regvar in staticsymtable yet, need initialization with 0 }
  980. if {(
  981. not assigned(owner) or
  982. (owner.symtabletype<>staticsymtable)
  983. ) and }
  984. tstoreddef(vardef).is_fpuregable then
  985. begin
  986. {$ifdef x86}
  987. if use_sse(vardef) then
  988. varregable:=vr_mmreg
  989. else
  990. {$else x86}
  991. varregable:=vr_fpureg;
  992. {$endif x86}
  993. end;
  994. end;
  995. end;
  996. {****************************************************************************
  997. TFIELDVARSYM
  998. ****************************************************************************}
  999. constructor tfieldvarsym.create(const n : string;vsp:tvarspez;def:tdef;vopts:tvaroptions);
  1000. begin
  1001. inherited create(fieldvarsym,n,vsp,def,vopts);
  1002. fieldoffset:=-1;
  1003. end;
  1004. constructor tfieldvarsym.ppuload(ppufile:tcompilerppufile);
  1005. begin
  1006. inherited ppuload(fieldvarsym,ppufile);
  1007. fieldoffset:=ppufile.getaint;
  1008. end;
  1009. procedure tfieldvarsym.ppuwrite(ppufile:tcompilerppufile);
  1010. begin
  1011. inherited ppuwrite(ppufile);
  1012. ppufile.putaint(fieldoffset);
  1013. ppufile.writeentry(ibfieldvarsym);
  1014. end;
  1015. function tfieldvarsym.mangledname:string;
  1016. var
  1017. srsym : tsym;
  1018. srsymtable : TSymtable;
  1019. begin
  1020. if sp_static in symoptions then
  1021. begin
  1022. searchsym(lower(owner.name^)+'_'+name,srsym,srsymtable);
  1023. if assigned(srsym) then
  1024. result:=srsym.mangledname;
  1025. end
  1026. else
  1027. result:=inherited mangledname;
  1028. end;
  1029. {****************************************************************************
  1030. TABSTRACTNORMALVARSYM
  1031. ****************************************************************************}
  1032. constructor tabstractnormalvarsym.create(st:tsymtyp;const n : string;vsp:tvarspez;def:tdef;vopts:tvaroptions);
  1033. begin
  1034. inherited create(st,n,vsp,def,vopts);
  1035. fillchar(localloc,sizeof(localloc),0);
  1036. fillchar(initialloc,sizeof(initialloc),0);
  1037. defaultconstsym:=nil;
  1038. end;
  1039. constructor tabstractnormalvarsym.ppuload(st:tsymtyp;ppufile:tcompilerppufile);
  1040. begin
  1041. inherited ppuload(st,ppufile);
  1042. fillchar(localloc,sizeof(localloc),0);
  1043. fillchar(initialloc,sizeof(initialloc),0);
  1044. ppufile.getderef(defaultconstsymderef);
  1045. end;
  1046. procedure tabstractnormalvarsym.buildderef;
  1047. begin
  1048. inherited buildderef;
  1049. defaultconstsymderef.build(defaultconstsym);
  1050. end;
  1051. procedure tabstractnormalvarsym.deref;
  1052. begin
  1053. inherited deref;
  1054. defaultconstsym:=tsym(defaultconstsymderef.resolve);
  1055. end;
  1056. procedure tabstractnormalvarsym.ppuwrite(ppufile:tcompilerppufile);
  1057. begin
  1058. inherited ppuwrite(ppufile);
  1059. ppufile.putderef(defaultconstsymderef);
  1060. end;
  1061. {****************************************************************************
  1062. TGLOBALVARSYM
  1063. ****************************************************************************}
  1064. constructor tglobalvarsym.create(const n : string;vsp:tvarspez;def:tdef;vopts:tvaroptions);
  1065. begin
  1066. inherited create(globalvarsym,n,vsp,def,vopts);
  1067. _mangledname:=nil;
  1068. end;
  1069. constructor tglobalvarsym.create_dll(const n : string;vsp:tvarspez;def:tdef);
  1070. begin
  1071. tglobalvarsym(self).create(n,vsp,def,[vo_is_dll_var]);
  1072. end;
  1073. constructor tglobalvarsym.create_C(const n,mangled : string;vsp:tvarspez;def:tdef);
  1074. begin
  1075. tglobalvarsym(self).create(n,vsp,def,[]);
  1076. set_mangledname(mangled);
  1077. end;
  1078. constructor tglobalvarsym.ppuload(ppufile:tcompilerppufile);
  1079. begin
  1080. inherited ppuload(globalvarsym,ppufile);
  1081. if vo_has_mangledname in varoptions then
  1082. _mangledname:=stringdup(ppufile.getstring)
  1083. else
  1084. _mangledname:=nil;
  1085. end;
  1086. destructor tglobalvarsym.destroy;
  1087. begin
  1088. if assigned(_mangledname) then
  1089. begin
  1090. {$ifdef MEMDEBUG}
  1091. memmanglednames.start;
  1092. {$endif MEMDEBUG}
  1093. stringdispose(_mangledname);
  1094. {$ifdef MEMDEBUG}
  1095. memmanglednames.stop;
  1096. {$endif MEMDEBUG}
  1097. end;
  1098. inherited destroy;
  1099. end;
  1100. procedure tglobalvarsym.ppuwrite(ppufile:tcompilerppufile);
  1101. begin
  1102. inherited ppuwrite(ppufile);
  1103. if vo_has_mangledname in varoptions then
  1104. ppufile.putstring(_mangledname^);
  1105. ppufile.writeentry(ibglobalvarsym);
  1106. end;
  1107. function tglobalvarsym.mangledname:string;
  1108. begin
  1109. if not assigned(_mangledname) then
  1110. begin
  1111. {$ifdef compress}
  1112. _mangledname:=stringdup(minilzw_encode(make_mangledname('U',owner,name)));
  1113. {$else}
  1114. _mangledname:=stringdup(make_mangledname('U',owner,name));
  1115. {$endif}
  1116. end;
  1117. result:=_mangledname^;
  1118. end;
  1119. procedure tglobalvarsym.set_mangledname(const s:string);
  1120. begin
  1121. stringdispose(_mangledname);
  1122. {$ifdef compress}
  1123. _mangledname:=stringdup(minilzw_encode(s));
  1124. {$else}
  1125. _mangledname:=stringdup(s);
  1126. {$endif}
  1127. include(varoptions,vo_has_mangledname);
  1128. end;
  1129. {****************************************************************************
  1130. TLOCALVARSYM
  1131. ****************************************************************************}
  1132. constructor tlocalvarsym.create(const n : string;vsp:tvarspez;def:tdef;vopts:tvaroptions);
  1133. begin
  1134. inherited create(localvarsym,n,vsp,def,vopts);
  1135. end;
  1136. constructor tlocalvarsym.ppuload(ppufile:tcompilerppufile);
  1137. begin
  1138. inherited ppuload(localvarsym,ppufile);
  1139. end;
  1140. procedure tlocalvarsym.ppuwrite(ppufile:tcompilerppufile);
  1141. begin
  1142. inherited ppuwrite(ppufile);
  1143. ppufile.writeentry(iblocalvarsym);
  1144. end;
  1145. {****************************************************************************
  1146. TPARAVARSYM
  1147. ****************************************************************************}
  1148. constructor tparavarsym.create(const n : string;nr:word;vsp:tvarspez;def:tdef;vopts:tvaroptions);
  1149. begin
  1150. inherited create(paravarsym,n,vsp,def,vopts);
  1151. if (vsp in [vs_var,vs_value,vs_const]) then
  1152. varstate := vs_initialised;
  1153. paranr:=nr;
  1154. paraloc[calleeside].init;
  1155. paraloc[callerside].init;
  1156. end;
  1157. destructor tparavarsym.destroy;
  1158. begin
  1159. paraloc[calleeside].done;
  1160. paraloc[callerside].done;
  1161. inherited destroy;
  1162. end;
  1163. constructor tparavarsym.ppuload(ppufile:tcompilerppufile);
  1164. var
  1165. b : byte;
  1166. begin
  1167. inherited ppuload(paravarsym,ppufile);
  1168. paranr:=ppufile.getword;
  1169. { The var state of parameter symbols is fixed after writing them so
  1170. we write them to the unit file.
  1171. This enables constant folding for inline procedures loaded from units
  1172. }
  1173. varstate:=tvarstate(ppufile.getbyte);
  1174. paraloc[calleeside].init;
  1175. paraloc[callerside].init;
  1176. if vo_has_explicit_paraloc in varoptions then
  1177. begin
  1178. b:=ppufile.getbyte;
  1179. if b<>sizeof(paraloc[callerside].location^) then
  1180. internalerror(200411154);
  1181. ppufile.getdata(paraloc[callerside].add_location^,sizeof(paraloc[callerside].location^));
  1182. paraloc[callerside].size:=paraloc[callerside].location^.size;
  1183. paraloc[callerside].intsize:=tcgsize2size[paraloc[callerside].size];
  1184. end;
  1185. end;
  1186. procedure tparavarsym.ppuwrite(ppufile:tcompilerppufile);
  1187. var
  1188. oldintfcrc : boolean;
  1189. begin
  1190. inherited ppuwrite(ppufile);
  1191. ppufile.putword(paranr);
  1192. { The var state of parameter symbols is fixed after writing them so
  1193. we write them to the unit file.
  1194. This enables constant folding for inline procedures loaded from units
  1195. }
  1196. oldintfcrc:=ppufile.do_crc;
  1197. ppufile.do_crc:=false;
  1198. ppufile.putbyte(ord(varstate));
  1199. ppufile.do_crc:=oldintfcrc;
  1200. if vo_has_explicit_paraloc in varoptions then
  1201. begin
  1202. paraloc[callerside].check_simple_location;
  1203. ppufile.putbyte(sizeof(paraloc[callerside].location^));
  1204. ppufile.putdata(paraloc[callerside].location^,sizeof(paraloc[callerside].location^));
  1205. end;
  1206. ppufile.writeentry(ibparavarsym);
  1207. end;
  1208. {****************************************************************************
  1209. TABSOLUTEVARSYM
  1210. ****************************************************************************}
  1211. constructor tabsolutevarsym.create(const n : string;def:tdef);
  1212. begin
  1213. inherited create(absolutevarsym,n,vs_value,def,[]);
  1214. ref:=nil;
  1215. end;
  1216. constructor tabsolutevarsym.create_ref(const n : string;def:tdef;_ref:tpropaccesslist);
  1217. begin
  1218. inherited create(absolutevarsym,n,vs_value,def,[]);
  1219. ref:=_ref;
  1220. end;
  1221. destructor tabsolutevarsym.destroy;
  1222. begin
  1223. if assigned(ref) then
  1224. ref.free;
  1225. inherited destroy;
  1226. end;
  1227. constructor tabsolutevarsym.ppuload(ppufile:tcompilerppufile);
  1228. begin
  1229. inherited ppuload(absolutevarsym,ppufile);
  1230. ref:=nil;
  1231. asmname:=nil;
  1232. abstyp:=absolutetyp(ppufile.getbyte);
  1233. {$ifdef i386}
  1234. absseg:=false;
  1235. {$endif i386}
  1236. case abstyp of
  1237. tovar :
  1238. ref:=ppufile.getpropaccesslist;
  1239. toasm :
  1240. asmname:=stringdup(ppufile.getstring);
  1241. toaddr :
  1242. begin
  1243. addroffset:=ppufile.getaint;
  1244. {$ifdef i386}
  1245. absseg:=boolean(ppufile.getbyte);
  1246. {$endif i386}
  1247. end;
  1248. end;
  1249. end;
  1250. procedure tabsolutevarsym.ppuwrite(ppufile:tcompilerppufile);
  1251. begin
  1252. inherited ppuwrite(ppufile);
  1253. ppufile.putbyte(byte(abstyp));
  1254. case abstyp of
  1255. tovar :
  1256. ppufile.putpropaccesslist(ref);
  1257. toasm :
  1258. ppufile.putstring(asmname^);
  1259. toaddr :
  1260. begin
  1261. ppufile.putaint(addroffset);
  1262. {$ifdef i386}
  1263. ppufile.putbyte(byte(absseg));
  1264. {$endif i386}
  1265. end;
  1266. end;
  1267. ppufile.writeentry(ibabsolutevarsym);
  1268. end;
  1269. procedure tabsolutevarsym.buildderef;
  1270. begin
  1271. inherited buildderef;
  1272. if (abstyp=tovar) then
  1273. ref.buildderef;
  1274. end;
  1275. procedure tabsolutevarsym.deref;
  1276. begin
  1277. inherited deref;
  1278. { own absolute deref }
  1279. if (abstyp=tovar) then
  1280. ref.resolve;
  1281. end;
  1282. function tabsolutevarsym.mangledname : string;
  1283. begin
  1284. case abstyp of
  1285. toasm :
  1286. mangledname:=asmname^;
  1287. toaddr :
  1288. mangledname:='$'+tostr(addroffset);
  1289. else
  1290. internalerror(200411062);
  1291. end;
  1292. end;
  1293. {****************************************************************************
  1294. TTYPEDCONSTSYM
  1295. *****************************************************************************}
  1296. constructor ttypedconstsym.create(const n : string;def : tdef;writable : boolean);
  1297. begin
  1298. inherited create(typedconstsym,n);
  1299. typedconstdef:=def;
  1300. is_writable:=writable;
  1301. end;
  1302. constructor ttypedconstsym.ppuload(ppufile:tcompilerppufile);
  1303. begin
  1304. inherited ppuload(typedconstsym,ppufile);
  1305. ppufile.getderef(typedconstdefderef);
  1306. is_writable:=boolean(ppufile.getbyte);
  1307. end;
  1308. destructor ttypedconstsym.destroy;
  1309. begin
  1310. if assigned(_mangledname) then
  1311. begin
  1312. {$ifdef MEMDEBUG}
  1313. memmanglednames.start;
  1314. {$endif MEMDEBUG}
  1315. stringdispose(_mangledname);
  1316. {$ifdef MEMDEBUG}
  1317. memmanglednames.stop;
  1318. {$endif MEMDEBUG}
  1319. end;
  1320. inherited destroy;
  1321. end;
  1322. function ttypedconstsym.mangledname:string;
  1323. begin
  1324. if not assigned(_mangledname) then
  1325. begin
  1326. {$ifdef compress}
  1327. _mangledname:=stringdup(make_mangledname('TC',owner,name));
  1328. {$else}
  1329. _mangledname:=stringdup(make_mangledname('TC',owner,name));
  1330. {$endif}
  1331. end;
  1332. result:=_mangledname^;
  1333. end;
  1334. procedure ttypedconstsym.set_mangledname(const s:string);
  1335. begin
  1336. stringdispose(_mangledname);
  1337. {$ifdef compress}
  1338. _mangledname:=stringdup(minilzw_encode(s));
  1339. {$else}
  1340. _mangledname:=stringdup(s);
  1341. {$endif}
  1342. end;
  1343. function ttypedconstsym.getsize : longint;
  1344. begin
  1345. if assigned(typedconstdef) then
  1346. getsize:=typedconstdef.size
  1347. else
  1348. getsize:=0;
  1349. end;
  1350. procedure ttypedconstsym.buildderef;
  1351. begin
  1352. typedconstdefderef.build(typedconstdef);
  1353. end;
  1354. procedure ttypedconstsym.deref;
  1355. begin
  1356. typedconstdef:=tdef(typedconstdefderef.resolve);
  1357. end;
  1358. procedure ttypedconstsym.ppuwrite(ppufile:tcompilerppufile);
  1359. begin
  1360. inherited ppuwrite(ppufile);
  1361. ppufile.putderef(typedconstdefderef);
  1362. ppufile.putbyte(byte(is_writable));
  1363. ppufile.writeentry(ibtypedconstsym);
  1364. end;
  1365. {****************************************************************************
  1366. TCONSTSYM
  1367. ****************************************************************************}
  1368. constructor tconstsym.create_ord(const n : string;t : tconsttyp;v : tconstexprint;def:tdef);
  1369. begin
  1370. inherited create(constsym,n);
  1371. fillchar(value, sizeof(value), #0);
  1372. consttyp:=t;
  1373. value.valueord:=v;
  1374. ResStrIndex:=0;
  1375. constdef:=def;
  1376. end;
  1377. constructor tconstsym.create_ordptr(const n : string;t : tconsttyp;v : tconstptruint;def:tdef);
  1378. begin
  1379. inherited create(constsym,n);
  1380. fillchar(value, sizeof(value), #0);
  1381. consttyp:=t;
  1382. value.valueordptr:=v;
  1383. ResStrIndex:=0;
  1384. constdef:=def;
  1385. end;
  1386. constructor tconstsym.create_ptr(const n : string;t : tconsttyp;v : pointer;def:tdef);
  1387. begin
  1388. inherited create(constsym,n);
  1389. fillchar(value, sizeof(value), #0);
  1390. consttyp:=t;
  1391. value.valueptr:=v;
  1392. ResStrIndex:=0;
  1393. constdef:=def;
  1394. end;
  1395. constructor tconstsym.create_string(const n : string;t : tconsttyp;str:pchar;l:longint);
  1396. begin
  1397. inherited create(constsym,n);
  1398. fillchar(value, sizeof(value), #0);
  1399. consttyp:=t;
  1400. value.valueptr:=str;
  1401. constdef:=nil;
  1402. value.len:=l;
  1403. end;
  1404. constructor tconstsym.create_wstring(const n : string;t : tconsttyp;pw:pcompilerwidestring);
  1405. begin
  1406. inherited create(constsym,n);
  1407. fillchar(value, sizeof(value), #0);
  1408. consttyp:=t;
  1409. pcompilerwidestring(value.valueptr):=pw;
  1410. constdef:=nil;
  1411. value.len:=getlengthwidestring(pw);
  1412. end;
  1413. constructor tconstsym.ppuload(ppufile:tcompilerppufile);
  1414. var
  1415. pd : pbestreal;
  1416. ps : pnormalset;
  1417. pc : pchar;
  1418. pw : pcompilerwidestring;
  1419. begin
  1420. inherited ppuload(constsym,ppufile);
  1421. constdef:=nil;
  1422. consttyp:=tconsttyp(ppufile.getbyte);
  1423. fillchar(value, sizeof(value), #0);
  1424. case consttyp of
  1425. constord :
  1426. begin
  1427. ppufile.getderef(constdefderef);
  1428. value.valueord:=ppufile.getexprint;
  1429. end;
  1430. constpointer :
  1431. begin
  1432. ppufile.getderef(constdefderef);
  1433. value.valueordptr:=ppufile.getptruint;
  1434. end;
  1435. constwstring :
  1436. begin
  1437. initwidestring(pw);
  1438. setlengthwidestring(pw,ppufile.getlongint);
  1439. ppufile.getdata(pw^.data,pw^.len*sizeof(tcompilerwidechar));
  1440. pcompilerwidestring(value.valueptr):=pw;
  1441. end;
  1442. conststring,
  1443. constresourcestring :
  1444. begin
  1445. value.len:=ppufile.getlongint;
  1446. getmem(pc,value.len+1);
  1447. ppufile.getdata(pc^,value.len);
  1448. if consttyp=constresourcestring then
  1449. ResStrIndex:=ppufile.getlongint;
  1450. value.valueptr:=pc;
  1451. end;
  1452. constreal :
  1453. begin
  1454. new(pd);
  1455. pd^:=ppufile.getreal;
  1456. value.valueptr:=pd;
  1457. end;
  1458. constset :
  1459. begin
  1460. ppufile.getderef(constdefderef);
  1461. new(ps);
  1462. ppufile.getnormalset(ps^);
  1463. value.valueptr:=ps;
  1464. end;
  1465. constguid :
  1466. begin
  1467. new(pguid(value.valueptr));
  1468. ppufile.getdata(value.valueptr^,sizeof(tguid));
  1469. end;
  1470. constnil : ;
  1471. else
  1472. Message1(unit_f_ppu_invalid_entry,tostr(ord(consttyp)));
  1473. end;
  1474. end;
  1475. destructor tconstsym.destroy;
  1476. begin
  1477. case consttyp of
  1478. conststring,
  1479. constresourcestring :
  1480. freemem(pchar(value.valueptr),value.len+1);
  1481. constwstring :
  1482. donewidestring(pcompilerwidestring(value.valueptr));
  1483. constreal :
  1484. dispose(pbestreal(value.valueptr));
  1485. constset :
  1486. dispose(pnormalset(value.valueptr));
  1487. constguid :
  1488. dispose(pguid(value.valueptr));
  1489. end;
  1490. inherited destroy;
  1491. end;
  1492. procedure tconstsym.buildderef;
  1493. begin
  1494. if consttyp in [constord,constpointer,constset] then
  1495. constdefderef.build(constdef);
  1496. end;
  1497. procedure tconstsym.deref;
  1498. begin
  1499. if consttyp in [constord,constpointer,constset] then
  1500. constdef:=tdef(constdefderef.resolve);
  1501. end;
  1502. procedure tconstsym.ppuwrite(ppufile:tcompilerppufile);
  1503. begin
  1504. inherited ppuwrite(ppufile);
  1505. ppufile.putbyte(byte(consttyp));
  1506. case consttyp of
  1507. constnil : ;
  1508. constord :
  1509. begin
  1510. ppufile.putderef(constdefderef);
  1511. ppufile.putexprint(value.valueord);
  1512. end;
  1513. constpointer :
  1514. begin
  1515. ppufile.putderef(constdefderef);
  1516. ppufile.putptruint(value.valueordptr);
  1517. end;
  1518. constwstring :
  1519. begin
  1520. ppufile.putlongint(getlengthwidestring(pcompilerwidestring(value.valueptr)));
  1521. ppufile.putdata(pcompilerwidestring(value.valueptr)^.data,pcompilerwidestring(value.valueptr)^.len*sizeof(tcompilerwidechar));
  1522. end;
  1523. conststring,
  1524. constresourcestring :
  1525. begin
  1526. ppufile.putlongint(value.len);
  1527. ppufile.putdata(pchar(value.valueptr)^,value.len);
  1528. if consttyp=constresourcestring then
  1529. ppufile.putlongint(ResStrIndex);
  1530. end;
  1531. constreal :
  1532. ppufile.putreal(pbestreal(value.valueptr)^);
  1533. constset :
  1534. begin
  1535. ppufile.putderef(constdefderef);
  1536. ppufile.putnormalset(value.valueptr^);
  1537. end;
  1538. constguid :
  1539. ppufile.putdata(value.valueptr^,sizeof(tguid));
  1540. else
  1541. internalerror(13);
  1542. end;
  1543. ppufile.writeentry(ibconstsym);
  1544. end;
  1545. {****************************************************************************
  1546. TENUMSYM
  1547. ****************************************************************************}
  1548. constructor tenumsym.create(const n : string;def : tenumdef;v : longint);
  1549. begin
  1550. inherited create(enumsym,n);
  1551. definition:=def;
  1552. value:=v;
  1553. { First entry? Then we need to set the minval }
  1554. if def.firstenum=nil then
  1555. begin
  1556. if v>0 then
  1557. def.has_jumps:=true;
  1558. def.setmin(v);
  1559. def.setmax(v);
  1560. end
  1561. else
  1562. begin
  1563. { check for jumps }
  1564. if v>def.max+1 then
  1565. def.has_jumps:=true;
  1566. { update low and high }
  1567. if def.min>v then
  1568. def.setmin(v);
  1569. if def.max<v then
  1570. def.setmax(v);
  1571. end;
  1572. order;
  1573. end;
  1574. constructor tenumsym.ppuload(ppufile:tcompilerppufile);
  1575. begin
  1576. inherited ppuload(enumsym,ppufile);
  1577. ppufile.getderef(definitionderef);
  1578. value:=ppufile.getlongint;
  1579. nextenum := Nil;
  1580. end;
  1581. procedure tenumsym.buildderef;
  1582. begin
  1583. definitionderef.build(definition);
  1584. end;
  1585. procedure tenumsym.deref;
  1586. begin
  1587. definition:=tenumdef(definitionderef.resolve);
  1588. order;
  1589. end;
  1590. procedure tenumsym.order;
  1591. var
  1592. sym : tenumsym;
  1593. begin
  1594. sym := tenumsym(definition.firstenum);
  1595. if sym = nil then
  1596. begin
  1597. definition.firstenum := self;
  1598. nextenum := nil;
  1599. exit;
  1600. end;
  1601. { reorder the symbols in increasing value }
  1602. if value < sym.value then
  1603. begin
  1604. nextenum := sym;
  1605. definition.firstenum := self;
  1606. end
  1607. else
  1608. begin
  1609. while (sym.value <= value) and assigned(sym.nextenum) do
  1610. sym := sym.nextenum;
  1611. nextenum := sym.nextenum;
  1612. sym.nextenum := self;
  1613. end;
  1614. end;
  1615. procedure tenumsym.ppuwrite(ppufile:tcompilerppufile);
  1616. begin
  1617. inherited ppuwrite(ppufile);
  1618. ppufile.putderef(definitionderef);
  1619. ppufile.putlongint(value);
  1620. ppufile.writeentry(ibenumsym);
  1621. end;
  1622. {****************************************************************************
  1623. TTYPESYM
  1624. ****************************************************************************}
  1625. constructor ttypesym.create(const n : string;def:tdef);
  1626. begin
  1627. inherited create(typesym,n);
  1628. typedef:=def;
  1629. { register the typesym for the definition }
  1630. if assigned(typedef) and
  1631. (typedef.typ<>errordef) and
  1632. not(assigned(typedef.typesym)) then
  1633. typedef.typesym:=self;
  1634. end;
  1635. constructor ttypesym.ppuload(ppufile:tcompilerppufile);
  1636. begin
  1637. inherited ppuload(typesym,ppufile);
  1638. ppufile.getderef(typedefderef);
  1639. end;
  1640. procedure ttypesym.buildderef;
  1641. begin
  1642. typedefderef.build(typedef);
  1643. end;
  1644. procedure ttypesym.deref;
  1645. begin
  1646. typedef:=tdef(typedefderef.resolve);
  1647. end;
  1648. procedure ttypesym.ppuwrite(ppufile:tcompilerppufile);
  1649. begin
  1650. inherited ppuwrite(ppufile);
  1651. ppufile.putderef(typedefderef);
  1652. ppufile.writeentry(ibtypesym);
  1653. end;
  1654. {****************************************************************************
  1655. TSYSSYM
  1656. ****************************************************************************}
  1657. constructor tsyssym.create(const n : string;l : longint);
  1658. begin
  1659. inherited create(syssym,n);
  1660. number:=l;
  1661. end;
  1662. constructor tsyssym.ppuload(ppufile:tcompilerppufile);
  1663. begin
  1664. inherited ppuload(syssym,ppufile);
  1665. number:=ppufile.getlongint;
  1666. end;
  1667. destructor tsyssym.destroy;
  1668. begin
  1669. inherited destroy;
  1670. end;
  1671. procedure tsyssym.ppuwrite(ppufile:tcompilerppufile);
  1672. begin
  1673. inherited ppuwrite(ppufile);
  1674. ppufile.putlongint(number);
  1675. ppufile.writeentry(ibsyssym);
  1676. end;
  1677. {*****************************************************************************
  1678. TMacro
  1679. *****************************************************************************}
  1680. constructor tmacro.create(const n : string);
  1681. begin
  1682. inherited create(macrosym,n);
  1683. owner:=nil;
  1684. defined:=false;
  1685. is_used:=false;
  1686. is_compiler_var:=false;
  1687. buftext:=nil;
  1688. buflen:=0;
  1689. end;
  1690. constructor tmacro.ppuload(ppufile:tcompilerppufile);
  1691. begin
  1692. inherited ppuload(macrosym,ppufile);
  1693. defined:=boolean(ppufile.getbyte);
  1694. is_compiler_var:=boolean(ppufile.getbyte);
  1695. is_used:=false;
  1696. buflen:= ppufile.getlongint;
  1697. if buflen > 0 then
  1698. begin
  1699. getmem(buftext, buflen);
  1700. ppufile.getdata(buftext^, buflen)
  1701. end
  1702. else
  1703. buftext:=nil;
  1704. end;
  1705. destructor tmacro.destroy;
  1706. begin
  1707. if assigned(buftext) then
  1708. freemem(buftext);
  1709. inherited destroy;
  1710. end;
  1711. procedure tmacro.ppuwrite(ppufile:tcompilerppufile);
  1712. begin
  1713. inherited ppuwrite(ppufile);
  1714. ppufile.putbyte(byte(defined));
  1715. ppufile.putbyte(byte(is_compiler_var));
  1716. ppufile.putlongint(buflen);
  1717. if buflen > 0 then
  1718. ppufile.putdata(buftext^,buflen);
  1719. ppufile.writeentry(ibmacrosym);
  1720. end;
  1721. function tmacro.GetCopy:tmacro;
  1722. var
  1723. p : tmacro;
  1724. begin
  1725. p:=tmacro.create(realname);
  1726. p.defined:=defined;
  1727. p.is_used:=is_used;
  1728. p.is_compiler_var:=is_compiler_var;
  1729. p.buflen:=buflen;
  1730. if assigned(buftext) then
  1731. begin
  1732. getmem(p.buftext,buflen);
  1733. move(buftext^,p.buftext^,buflen);
  1734. end;
  1735. Result:=p;
  1736. end;
  1737. {****************************************************************************
  1738. TRTTISYM
  1739. ****************************************************************************}
  1740. constructor trttisym.create(const n:string;rt:trttitype);
  1741. const
  1742. prefix : array[trttitype] of string[5]=('$rtti','$init');
  1743. begin
  1744. inherited create(rttisym,prefix[rt]+n);
  1745. include(symoptions,sp_internal);
  1746. lab:=nil;
  1747. rttityp:=rt;
  1748. end;
  1749. destructor trttisym.destroy;
  1750. begin
  1751. if assigned(_mangledname) then
  1752. begin
  1753. {$ifdef MEMDEBUG}
  1754. memmanglednames.start;
  1755. {$endif MEMDEBUG}
  1756. stringdispose(_mangledname);
  1757. {$ifdef MEMDEBUG}
  1758. memmanglednames.stop;
  1759. {$endif MEMDEBUG}
  1760. end;
  1761. inherited destroy;
  1762. end;
  1763. constructor trttisym.ppuload(ppufile:tcompilerppufile);
  1764. begin
  1765. inherited ppuload(rttisym,ppufile);
  1766. lab:=nil;
  1767. rttityp:=trttitype(ppufile.getbyte);
  1768. end;
  1769. procedure trttisym.ppuwrite(ppufile:tcompilerppufile);
  1770. begin
  1771. inherited ppuwrite(ppufile);
  1772. ppufile.putbyte(byte(rttityp));
  1773. ppufile.writeentry(ibrttisym);
  1774. end;
  1775. function trttisym.mangledname : string;
  1776. const
  1777. prefix : array[trttitype] of string[5]=('RTTI_','INIT_');
  1778. begin
  1779. if not assigned(_mangledname) then
  1780. _mangledname:=stringdup(make_mangledname(prefix[rttityp],owner,Copy(name,5,255)));
  1781. result:=_mangledname^;
  1782. end;
  1783. function trttisym.get_label:tasmsymbol;
  1784. begin
  1785. { the label is always a global label }
  1786. if not assigned(lab) then
  1787. lab:=current_asmdata.RefAsmSymbol(mangledname);
  1788. get_label:=lab;
  1789. end;
  1790. end.