symsym.pas 89 KB

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