symsym.pas 69 KB

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