symsym.pas 80 KB

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