symsym.pas 69 KB

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