symsym.pas 90 KB

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