symsym.pas 92 KB

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