symsym.pas 92 KB

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