symsym.pas 69 KB

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