symsym.pas 91 KB

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