symsym.pas 70 KB

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