2
0

symsym.pas 90 KB

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