symsym.pas 92 KB

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