symsym.pas 76 KB

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