symsym.pas 71 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261
  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. public
  38. constructor create(st:tsymtyp;const n : string);
  39. constructor ppuload(st:tsymtyp;ppufile:tcompilerppufile);
  40. destructor destroy;override;
  41. procedure ppuwrite(ppufile:tcompilerppufile);virtual;
  42. end;
  43. tlabelsym = class(tstoredsym)
  44. used,
  45. defined,
  46. nonlocal : boolean;
  47. { points to the matching node, only valid resultdef pass is run and
  48. the goto<->label relation in the node tree is created, should
  49. be a tnode }
  50. code : pointer;
  51. { points to the jump buffer }
  52. jumpbuf : tstoredsym;
  53. { when the label is defined in an asm block, this points to the
  54. generated asmlabel }
  55. asmblocklabel : tasmlabel;
  56. constructor create(const n : string);
  57. constructor ppuload(ppufile:tcompilerppufile);
  58. procedure ppuwrite(ppufile:tcompilerppufile);override;
  59. function mangledname:TSymStr;override;
  60. end;
  61. tunitsym = class(Tstoredsym)
  62. module : tobject; { tmodule }
  63. constructor create(const n : string;amodule : tobject);
  64. constructor ppuload(ppufile:tcompilerppufile);
  65. destructor destroy;override;
  66. procedure ppuwrite(ppufile:tcompilerppufile);override;
  67. end;
  68. terrorsym = class(Tsym)
  69. constructor create;
  70. end;
  71. { tprocsym }
  72. tprocsym = class(tstoredsym)
  73. protected
  74. FProcdefList : TFPObjectList;
  75. FProcdefDerefList : TFPList;
  76. public
  77. constructor create(const n : string);
  78. constructor ppuload(ppufile:tcompilerppufile);
  79. destructor destroy;override;
  80. { writes all declarations except the specified one }
  81. procedure write_parameter_lists(skipdef:tprocdef);
  82. { tests, if all procedures definitions are defined and not }
  83. { only forward }
  84. procedure check_forward;
  85. procedure ppuwrite(ppufile:tcompilerppufile);override;
  86. procedure buildderef;override;
  87. procedure deref;override;
  88. function find_procdef_bytype(pt:Tproctypeoption):Tprocdef;
  89. function find_bytype_parameterless(pt:Tproctypeoption):Tprocdef;
  90. function find_procdef_bypara(para:TFPObjectList;retdef:tdef;cpoptions:tcompare_paras_options):Tprocdef;
  91. function find_procdef_bytype_and_para(pt:Tproctypeoption;para:TFPObjectList;retdef:tdef;cpoptions:tcompare_paras_options):Tprocdef;
  92. function find_procdef_byoptions(ops:tprocoptions): Tprocdef;
  93. function find_procdef_byprocvardef(d:Tprocvardef):Tprocdef;
  94. function find_procdef_assignment_operator(fromdef,todef:tdef;var besteq:tequaltype):Tprocdef;
  95. function find_procdef_enumerator_operator(fromdef,todef:tdef;var besteq:tequaltype):Tprocdef;
  96. property ProcdefList:TFPObjectList read FProcdefList;
  97. end;
  98. ttypesym = class(Tstoredsym)
  99. typedef : tdef;
  100. typedefderef : tderef;
  101. fprettyname : ansistring;
  102. constructor create(const n : string;def:tdef);
  103. constructor ppuload(ppufile:tcompilerppufile);
  104. procedure ppuwrite(ppufile:tcompilerppufile);override;
  105. procedure buildderef;override;
  106. procedure deref;override;
  107. function prettyname : string;override;
  108. end;
  109. tabstractvarsym = class(tstoredsym)
  110. varoptions : tvaroptions;
  111. notifications : Tlinkedlist;
  112. varspez : tvarspez; { sets the type of access }
  113. varregable : tvarregable;
  114. varstate : tvarstate;
  115. { Has the address of this variable potentially escaped the }
  116. { block in which is was declared? }
  117. { could also be part of tabstractnormalvarsym, but there's }
  118. { one byte left here till the next 4 byte alignment }
  119. addr_taken : boolean;
  120. constructor create(st:tsymtyp;const n : string;vsp:tvarspez;def:tdef;vopts:tvaroptions);
  121. constructor ppuload(st:tsymtyp;ppufile:tcompilerppufile);
  122. destructor destroy;override;
  123. procedure ppuwrite(ppufile:tcompilerppufile);override;
  124. procedure buildderef;override;
  125. procedure deref;override;
  126. function getsize : asizeint;
  127. function getpackedbitsize : longint;
  128. function is_regvar(refpara: boolean):boolean;
  129. procedure trigger_notifications(what:Tnotification_flag);
  130. function register_notification(flags:Tnotification_flags;
  131. callback:Tnotification_callback):cardinal;
  132. procedure unregister_notification(id:cardinal);
  133. private
  134. _vardef : tdef;
  135. vardefderef : tderef;
  136. procedure setvardef(def:tdef);
  137. public
  138. property vardef: tdef read _vardef write setvardef;
  139. end;
  140. tfieldvarsym = class(tabstractvarsym)
  141. fieldoffset : asizeint; { offset in record/object }
  142. externalname : pshortstring;
  143. {$ifdef symansistr}
  144. cachedmangledname: TSymStr; { mangled name for ObjC or Java }
  145. {$else symansistr}
  146. cachedmangledname: pshortstring; { mangled name for ObjC or Java }
  147. {$endif symansistr}
  148. constructor create(const n : string;vsp:tvarspez;def:tdef;vopts:tvaroptions);
  149. constructor ppuload(ppufile:tcompilerppufile);
  150. procedure ppuwrite(ppufile:tcompilerppufile);override;
  151. procedure set_externalname(const s:string);
  152. function mangledname:TSymStr;override;
  153. destructor destroy;override;
  154. end;
  155. tabstractnormalvarsym = class(tabstractvarsym)
  156. defaultconstsym : tsym;
  157. defaultconstsymderef : tderef;
  158. localloc : TLocation; { register/reference for local var }
  159. initialloc : TLocation; { initial location so it can still be initialized later after the location was changed by SSA }
  160. inparentfpstruct : boolean; { migrated to a parentfpstruct because of nested access (not written to ppu, because not important and would change interface crc) }
  161. constructor create(st:tsymtyp;const n : string;vsp:tvarspez;def:tdef;vopts:tvaroptions);
  162. constructor ppuload(st:tsymtyp;ppufile:tcompilerppufile);
  163. procedure ppuwrite(ppufile:tcompilerppufile);override;
  164. procedure buildderef;override;
  165. procedure deref;override;
  166. end;
  167. tlocalvarsym = class(tabstractnormalvarsym)
  168. constructor create(const n : string;vsp:tvarspez;def:tdef;vopts:tvaroptions);
  169. constructor ppuload(ppufile:tcompilerppufile);
  170. procedure ppuwrite(ppufile:tcompilerppufile);override;
  171. end;
  172. tparavarsym = class(tabstractnormalvarsym)
  173. paraloc : array[tcallercallee] of TCGPara;
  174. paranr : word; { position of this parameter }
  175. { in MacPas mode, "univ" parameters mean that type checking should
  176. be disabled, except that the size of the passed parameter must
  177. match the size of the formal parameter }
  178. univpara : boolean;
  179. {$ifdef EXTDEBUG}
  180. eqval : tequaltype;
  181. {$endif EXTDEBUG}
  182. constructor create(const n : string;nr:word;vsp:tvarspez;def:tdef;vopts:tvaroptions);
  183. constructor ppuload(ppufile:tcompilerppufile);
  184. destructor destroy;override;
  185. procedure ppuwrite(ppufile:tcompilerppufile);override;
  186. end;
  187. tstaticvarsym = class(tabstractnormalvarsym)
  188. private
  189. {$ifdef symansistr}
  190. _mangledbasename,
  191. _mangledname : TSymStr;
  192. {$else symansistr}
  193. _mangledbasename,
  194. _mangledname : pshortstring;
  195. {$endif symansistr}
  196. public
  197. section : ansistring;
  198. constructor create(const n : string;vsp:tvarspez;def:tdef;vopts:tvaroptions);
  199. constructor create_dll(const n : string;vsp:tvarspez;def:tdef);
  200. constructor create_C(const n: string; const mangled : TSymStr;vsp:tvarspez;def:tdef);
  201. constructor ppuload(ppufile:tcompilerppufile);
  202. destructor destroy;override;
  203. procedure ppuwrite(ppufile:tcompilerppufile);override;
  204. function mangledname:TSymStr;override;
  205. procedure set_mangledbasename(const s: TSymStr);
  206. function mangledbasename: TSymStr;
  207. procedure set_mangledname(const s:TSymStr);
  208. procedure set_raw_mangledname(const s:TSymStr);
  209. end;
  210. tabsolutevarsym = class(tabstractvarsym)
  211. public
  212. abstyp : absolutetyp;
  213. {$ifdef i386}
  214. absseg : boolean;
  215. {$endif i386}
  216. asmname : pshortstring;
  217. addroffset : aword;
  218. ref : tpropaccesslist;
  219. constructor create(const n : string;def:tdef);
  220. constructor create_ref(const n : string;def:tdef;_ref:tpropaccesslist);
  221. destructor destroy;override;
  222. constructor ppuload(ppufile:tcompilerppufile);
  223. procedure buildderef;override;
  224. procedure deref;override;
  225. function mangledname : TSymStr;override;
  226. procedure ppuwrite(ppufile:tcompilerppufile);override;
  227. end;
  228. tpropaccesslisttypes=(palt_none,palt_read,palt_write,palt_stored);
  229. tpropertysym = class(Tstoredsym)
  230. propoptions : tpropertyoptions;
  231. overriddenpropsym : tpropertysym;
  232. overriddenpropsymderef : tderef;
  233. propdef : tdef;
  234. propdefderef : tderef;
  235. indexdef : tdef;
  236. indexdefderef : tderef;
  237. index,
  238. default : longint;
  239. dispid : longint;
  240. propaccesslist: array[tpropaccesslisttypes] of tpropaccesslist;
  241. constructor create(const n : string);
  242. destructor destroy;override;
  243. constructor ppuload(ppufile:tcompilerppufile);
  244. function getsize : asizeint;
  245. procedure ppuwrite(ppufile:tcompilerppufile);override;
  246. procedure buildderef;override;
  247. procedure deref;override;
  248. end;
  249. tconstvalue = record
  250. case integer of
  251. 0: (valueord : tconstexprint);
  252. 1: (valueordptr : tconstptruint);
  253. 2: (valueptr : pointer; len : longint);
  254. end;
  255. tconstsym = class(tstoredsym)
  256. constdef : tdef;
  257. constdefderef : tderef;
  258. consttyp : tconsttyp;
  259. value : tconstvalue;
  260. constructor create_ord(const n : string;t : tconsttyp;v : tconstexprint;def:tdef);
  261. constructor create_ordptr(const n : string;t : tconsttyp;v : tconstptruint;def:tdef);
  262. constructor create_ptr(const n : string;t : tconsttyp;v : pointer;def:tdef);
  263. constructor create_string(const n : string;t : tconsttyp;str:pchar;l:longint);
  264. constructor create_wstring(const n : string;t : tconsttyp;pw:pcompilerwidestring);
  265. constructor ppuload(ppufile:tcompilerppufile);
  266. destructor destroy;override;
  267. procedure buildderef;override;
  268. procedure deref;override;
  269. procedure ppuwrite(ppufile:tcompilerppufile);override;
  270. end;
  271. tenumsym = class(Tstoredsym)
  272. value : longint;
  273. definition : tenumdef;
  274. definitionderef : tderef;
  275. constructor create(const n : string;def : tenumdef;v : longint);
  276. constructor ppuload(ppufile:tcompilerppufile);
  277. procedure ppuwrite(ppufile:tcompilerppufile);override;
  278. procedure buildderef;override;
  279. procedure deref;override;
  280. end;
  281. tsyssym = class(Tstoredsym)
  282. number : longint;
  283. constructor create(const n : string;l : longint);
  284. constructor ppuload(ppufile:tcompilerppufile);
  285. destructor destroy;override;
  286. procedure ppuwrite(ppufile:tcompilerppufile);override;
  287. end;
  288. const
  289. maxmacrolen=16*1024;
  290. type
  291. pmacrobuffer = ^tmacrobuffer;
  292. tmacrobuffer = array[0..maxmacrolen-1] of char;
  293. tmacro = class(tstoredsym)
  294. {Normally true, but false when a previously defined macro is undef-ed}
  295. defined : boolean;
  296. {True if this is a mac style compiler variable, in which case no macro
  297. substitutions shall be done.}
  298. is_compiler_var : boolean;
  299. {Whether the macro was used. NOTE: A use of a macro which was never defined}
  300. {e. g. an IFDEF which returns false, will not be registered as used,}
  301. {since there is no place to register its use. }
  302. is_used : boolean;
  303. buftext : pchar;
  304. buflen : longint;
  305. constructor create(const n : string);
  306. constructor ppuload(ppufile:tcompilerppufile);
  307. procedure ppuwrite(ppufile:tcompilerppufile);override;
  308. destructor destroy;override;
  309. function GetCopy:tmacro;
  310. end;
  311. var
  312. generrorsym : tsym;
  313. { generate internal static field name based on regular field name }
  314. function internal_static_field_name(const fieldname: TSymStr): TSymStr;
  315. procedure check_hints(const srsym: tsym; const symoptions: tsymoptions; const deprecatedmsg : pshortstring);
  316. implementation
  317. uses
  318. { global }
  319. verbose,
  320. { target }
  321. systems,
  322. { symtable }
  323. defutil,symtable,
  324. {$ifdef jvm}
  325. jvmdef,
  326. {$endif}
  327. fmodule,
  328. { tree }
  329. node,
  330. { aasm }
  331. aasmtai,aasmdata,
  332. { codegen }
  333. paramgr,
  334. procinfo
  335. ;
  336. {****************************************************************************
  337. Helpers
  338. ****************************************************************************}
  339. function internal_static_field_name(const fieldname: TSymStr): TSymStr;
  340. begin
  341. result:='$_static_'+fieldname;
  342. end;
  343. procedure check_hints(const srsym: tsym; const symoptions: tsymoptions; const deprecatedmsg : pshortstring);
  344. begin
  345. if not assigned(srsym) then
  346. internalerror(200602051);
  347. if sp_hint_deprecated in symoptions then
  348. if (sp_has_deprecated_msg in symoptions) and (deprecatedmsg <> nil) then
  349. Message2(sym_w_deprecated_symbol_with_msg,srsym.realname,deprecatedmsg^)
  350. else
  351. Message1(sym_w_deprecated_symbol,srsym.realname);
  352. if sp_hint_experimental in symoptions then
  353. Message1(sym_w_experimental_symbol,srsym.realname);
  354. if sp_hint_platform in symoptions then
  355. Message1(sym_w_non_portable_symbol,srsym.realname);
  356. if sp_hint_library in symoptions then
  357. Message1(sym_w_library_symbol,srsym.realname);
  358. if sp_hint_unimplemented in symoptions then
  359. Message1(sym_w_non_implemented_symbol,srsym.realname);
  360. end;
  361. {****************************************************************************
  362. TSYM (base for all symtypes)
  363. ****************************************************************************}
  364. constructor tstoredsym.create(st:tsymtyp;const n : string);
  365. begin
  366. inherited create(st,n);
  367. { Register in current_module }
  368. if assigned(current_module) then
  369. begin
  370. current_module.symlist.Add(self);
  371. SymId:=current_module.symlist.Count-1;
  372. end;
  373. end;
  374. constructor tstoredsym.ppuload(st:tsymtyp;ppufile:tcompilerppufile);
  375. begin
  376. SymId:=ppufile.getlongint;
  377. inherited Create(st,ppufile.getstring);
  378. { Register symbol }
  379. current_module.symlist[SymId]:=self;
  380. ppufile.getposinfo(fileinfo);
  381. visibility:=tvisibility(ppufile.getbyte);
  382. ppufile.getsmallset(symoptions);
  383. if sp_has_deprecated_msg in symoptions then
  384. deprecatedmsg:=stringdup(ppufile.getstring)
  385. else
  386. deprecatedmsg:=nil;
  387. end;
  388. procedure tstoredsym.ppuwrite(ppufile:tcompilerppufile);
  389. begin
  390. ppufile.putlongint(SymId);
  391. ppufile.putstring(realname);
  392. ppufile.putposinfo(fileinfo);
  393. ppufile.putbyte(byte(visibility));
  394. ppufile.putsmallset(symoptions);
  395. if sp_has_deprecated_msg in symoptions then
  396. ppufile.putstring(deprecatedmsg^);
  397. end;
  398. destructor tstoredsym.destroy;
  399. begin
  400. inherited destroy;
  401. end;
  402. {****************************************************************************
  403. TLABELSYM
  404. ****************************************************************************}
  405. constructor tlabelsym.create(const n : string);
  406. begin
  407. inherited create(labelsym,n);
  408. used:=false;
  409. defined:=false;
  410. nonlocal:=false;
  411. code:=nil;
  412. end;
  413. constructor tlabelsym.ppuload(ppufile:tcompilerppufile);
  414. begin
  415. inherited ppuload(labelsym,ppufile);
  416. code:=nil;
  417. used:=false;
  418. nonlocal:=false;
  419. defined:=true;
  420. end;
  421. procedure tlabelsym.ppuwrite(ppufile:tcompilerppufile);
  422. begin
  423. if owner.symtabletype=globalsymtable then
  424. Message(sym_e_ill_label_decl)
  425. else
  426. begin
  427. inherited ppuwrite(ppufile);
  428. ppufile.writeentry(iblabelsym);
  429. end;
  430. end;
  431. function tlabelsym.mangledname:TSymStr;
  432. begin
  433. if not(defined) then
  434. begin
  435. defined:=true;
  436. if nonlocal then
  437. current_asmdata.getglobaljumplabel(asmblocklabel)
  438. else
  439. current_asmdata.getjumplabel(asmblocklabel);
  440. end;
  441. result:=asmblocklabel.name;
  442. end;
  443. {****************************************************************************
  444. TUNITSYM
  445. ****************************************************************************}
  446. constructor tunitsym.create(const n : string;amodule : tobject);
  447. begin
  448. inherited create(unitsym,n);
  449. module:=amodule;
  450. end;
  451. constructor tunitsym.ppuload(ppufile:tcompilerppufile);
  452. begin
  453. inherited ppuload(unitsym,ppufile);
  454. module:=nil;
  455. end;
  456. destructor tunitsym.destroy;
  457. begin
  458. inherited destroy;
  459. end;
  460. procedure tunitsym.ppuwrite(ppufile:tcompilerppufile);
  461. begin
  462. inherited ppuwrite(ppufile);
  463. ppufile.writeentry(ibunitsym);
  464. end;
  465. {****************************************************************************
  466. TPROCSYM
  467. ****************************************************************************}
  468. constructor tprocsym.create(const n : string);
  469. begin
  470. inherited create(procsym,n);
  471. FProcdefList:=TFPObjectList.Create(false);
  472. FProcdefderefList:=nil;
  473. { the tprocdef have their own symoptions, make the procsym
  474. always visible }
  475. visibility:=vis_public;
  476. end;
  477. constructor tprocsym.ppuload(ppufile:tcompilerppufile);
  478. var
  479. pdderef : tderef;
  480. i,
  481. pdcnt : longint;
  482. begin
  483. inherited ppuload(procsym,ppufile);
  484. FProcdefList:=TFPObjectList.Create(false);
  485. FProcdefDerefList:=TFPList.Create;
  486. pdcnt:=ppufile.getword;
  487. for i:=1 to pdcnt do
  488. begin
  489. ppufile.getderef(pdderef);
  490. FProcdefDerefList.Add(Pointer(PtrInt(pdderef.dataidx)));
  491. end;
  492. end;
  493. destructor tprocsym.destroy;
  494. begin
  495. FProcdefList.Free;
  496. if assigned(FProcdefDerefList) then
  497. FProcdefDerefList.Free;
  498. inherited destroy;
  499. end;
  500. procedure tprocsym.ppuwrite(ppufile:tcompilerppufile);
  501. var
  502. i : longint;
  503. d : tderef;
  504. begin
  505. inherited ppuwrite(ppufile);
  506. ppufile.putword(FProcdefDerefList.Count);
  507. for i:=0 to FProcdefDerefList.Count-1 do
  508. begin
  509. d.dataidx:=PtrInt(FProcdefDerefList[i]);
  510. ppufile.putderef(d);
  511. end;
  512. ppufile.writeentry(ibprocsym);
  513. end;
  514. procedure tprocsym.write_parameter_lists(skipdef:tprocdef);
  515. var
  516. i : longint;
  517. pd : tprocdef;
  518. begin
  519. for i:=0 to ProcdefList.Count-1 do
  520. begin
  521. pd:=tprocdef(ProcdefList[i]);
  522. if pd<>skipdef then
  523. MessagePos1(pd.fileinfo,sym_h_param_list,pd.fullprocname(false));
  524. end;
  525. end;
  526. procedure tprocsym.check_forward;
  527. var
  528. i : longint;
  529. pd : tprocdef;
  530. begin
  531. for i:=0 to ProcdefList.Count-1 do
  532. begin
  533. pd:=tprocdef(ProcdefList[i]);
  534. if (pd.owner=owner) and (pd.forwarddef) then
  535. begin
  536. { For mode macpas. Make implicit externals (procedures declared in the interface
  537. section which do not have a counterpart in the implementation)
  538. to be an imported procedure }
  539. if (m_mac in current_settings.modeswitches) and
  540. (pd.interfacedef) then
  541. begin
  542. pd.setmangledname(target_info.CPrefix+tprocdef(pd).procsym.realname);
  543. if (not current_module.interface_only) then
  544. MessagePos1(pd.fileinfo,sym_w_forward_not_resolved,pd.fullprocname(false));
  545. end
  546. else
  547. begin
  548. MessagePos1(pd.fileinfo,sym_e_forward_not_resolved,pd.fullprocname(false));
  549. end;
  550. { Turn further error messages off }
  551. pd.forwarddef:=false;
  552. end;
  553. end;
  554. end;
  555. procedure tprocsym.buildderef;
  556. var
  557. i : longint;
  558. pd : tprocdef;
  559. d : tderef;
  560. begin
  561. if not assigned(FProcdefDerefList) then
  562. FProcdefDerefList:=TFPList.Create
  563. else
  564. FProcdefDerefList.Clear;
  565. for i:=0 to ProcdefList.Count-1 do
  566. begin
  567. pd:=tprocdef(ProcdefList[i]);
  568. { only write the proc definitions that belong
  569. to this procsym and are in the global symtable }
  570. if pd.owner=owner then
  571. begin
  572. d.build(pd);
  573. FProcdefDerefList.Add(Pointer(PtrInt(d.dataidx)));
  574. end;
  575. end;
  576. end;
  577. procedure tprocsym.deref;
  578. var
  579. i : longint;
  580. pd : tprocdef;
  581. d : tderef;
  582. begin
  583. { Clear all procdefs }
  584. ProcdefList.Clear;
  585. if not assigned(FProcdefDerefList) then
  586. internalerror(200611031);
  587. for i:=0 to FProcdefDerefList.Count-1 do
  588. begin
  589. d.dataidx:=PtrInt(FProcdefDerefList[i]);
  590. pd:=tprocdef(d.resolve);
  591. ProcdefList.Add(pd);
  592. end;
  593. end;
  594. function Tprocsym.Find_procdef_bytype(pt:Tproctypeoption):Tprocdef;
  595. var
  596. i : longint;
  597. pd : tprocdef;
  598. begin
  599. result:=nil;
  600. for i:=0 to ProcdefList.Count-1 do
  601. begin
  602. pd:=tprocdef(ProcdefList[i]);
  603. if pd.proctypeoption=pt then
  604. begin
  605. result:=pd;
  606. exit;
  607. end;
  608. end;
  609. end;
  610. function tprocsym.find_bytype_parameterless(pt: Tproctypeoption): Tprocdef;
  611. var
  612. i,j : longint;
  613. pd : tprocdef;
  614. found : boolean;
  615. begin
  616. result:=nil;
  617. for i:=0 to ProcdefList.Count-1 do
  618. begin
  619. pd:=tprocdef(ProcdefList[i]);
  620. if (pd.proctypeoption=pt) then
  621. begin
  622. found:=true;
  623. for j:=0 to pd.paras.count-1 do
  624. begin
  625. if not(vo_is_hidden_para in tparavarsym(pd.paras[j]).varoptions) then
  626. begin
  627. found:=false;
  628. break;
  629. end;
  630. end;
  631. if found then
  632. begin
  633. result:=pd;
  634. exit;
  635. end;
  636. end;
  637. end;
  638. end;
  639. function check_procdef_paras(pd:tprocdef;para:TFPObjectList;retdef:tdef;
  640. cpoptions:tcompare_paras_options): tprocdef;
  641. var
  642. eq: tequaltype;
  643. begin
  644. result:=nil;
  645. if assigned(retdef) then
  646. eq:=compare_defs(retdef,pd.returndef,nothingn)
  647. else
  648. eq:=te_equal;
  649. if (eq>=te_equal) or
  650. ((cpo_allowconvert in cpoptions) and (eq>te_incompatible)) then
  651. begin
  652. eq:=compare_paras(para,pd.paras,cp_value_equal_const,cpoptions);
  653. if (eq>=te_equal) or
  654. ((cpo_allowconvert in cpoptions) and (eq>te_incompatible)) then
  655. begin
  656. result:=pd;
  657. exit;
  658. end;
  659. end;
  660. end;
  661. function Tprocsym.Find_procdef_bypara(para:TFPObjectList;retdef:tdef;
  662. cpoptions:tcompare_paras_options):Tprocdef;
  663. var
  664. i : longint;
  665. pd : tprocdef;
  666. begin
  667. result:=nil;
  668. for i:=0 to ProcdefList.Count-1 do
  669. begin
  670. pd:=tprocdef(ProcdefList[i]);
  671. result:=check_procdef_paras(pd,para,retdef,cpoptions);
  672. if assigned(result) then
  673. exit;
  674. end;
  675. end;
  676. function Tprocsym.find_procdef_bytype_and_para(pt:Tproctypeoption;
  677. para:TFPObjectList;retdef:tdef;cpoptions:tcompare_paras_options):Tprocdef;
  678. var
  679. i : longint;
  680. pd : tprocdef;
  681. begin
  682. result:=nil;
  683. for i:=0 to ProcdefList.Count-1 do
  684. begin
  685. pd:=tprocdef(ProcdefList[i]);
  686. if pd.proctypeoption=pt then
  687. begin
  688. result:=check_procdef_paras(pd,para,retdef,cpoptions);
  689. if assigned(result) then
  690. exit;
  691. end;
  692. end;
  693. end;
  694. function tprocsym.find_procdef_byoptions(ops: tprocoptions): Tprocdef;
  695. var
  696. i : longint;
  697. pd : tprocdef;
  698. begin
  699. result:=nil;
  700. for i:=0 to ProcdefList.Count-1 do
  701. begin
  702. pd:=tprocdef(ProcdefList[i]);
  703. if ops * pd.procoptions = ops then
  704. begin
  705. result:=pd;
  706. exit;
  707. end;
  708. end;
  709. end;
  710. function Tprocsym.Find_procdef_byprocvardef(d:Tprocvardef):Tprocdef;
  711. var
  712. i : longint;
  713. bestpd,
  714. pd : tprocdef;
  715. eq,besteq : tequaltype;
  716. begin
  717. { This function will return the pprocdef of pprocsym that
  718. is the best match for procvardef. When there are multiple
  719. matches it returns nil.}
  720. result:=nil;
  721. bestpd:=nil;
  722. besteq:=te_incompatible;
  723. for i:=0 to ProcdefList.Count-1 do
  724. begin
  725. pd:=tprocdef(ProcdefList[i]);
  726. eq:=proc_to_procvar_equal(pd,d,false);
  727. if eq>=te_convert_l1 then
  728. begin
  729. { multiple procvars with the same equal level }
  730. if assigned(bestpd) and
  731. (besteq=eq) then
  732. exit;
  733. if eq>besteq then
  734. begin
  735. besteq:=eq;
  736. bestpd:=pd;
  737. end;
  738. end;
  739. end;
  740. result:=bestpd;
  741. end;
  742. function Tprocsym.Find_procdef_assignment_operator(fromdef,todef:tdef;var besteq:tequaltype):Tprocdef;
  743. var
  744. paraidx, realparamcount,
  745. i, j : longint;
  746. bestpd,
  747. hpd,
  748. pd : tprocdef;
  749. convtyp : tconverttype;
  750. eq : tequaltype;
  751. begin
  752. { This function will return the pprocdef of pprocsym that
  753. is the best match for fromdef and todef. }
  754. result:=nil;
  755. bestpd:=nil;
  756. besteq:=te_incompatible;
  757. for i:=0 to ProcdefList.Count-1 do
  758. begin
  759. pd:=tprocdef(ProcdefList[i]);
  760. if (pd.owner.symtabletype=staticsymtable) and not pd.owner.iscurrentunit then
  761. continue;
  762. if (equal_defs(todef,pd.returndef) or
  763. { shortstrings of different lengths are ok as result }
  764. (is_shortstring(todef) and is_shortstring(pd.returndef))) and
  765. { the result type must be always really equal and not an alias,
  766. if you mess with this code, check tw4093 }
  767. ((todef=pd.returndef) or
  768. (
  769. not(df_unique in todef.defoptions) and
  770. not(df_unique in pd.returndef.defoptions)
  771. )
  772. ) then
  773. begin
  774. paraidx:=0;
  775. { ignore vs_hidden parameters }
  776. while (paraidx<pd.paras.count) and
  777. assigned(pd.paras[paraidx]) and
  778. (vo_is_hidden_para in tparavarsym(pd.paras[paraidx]).varoptions) do
  779. inc(paraidx);
  780. realparamcount:=0;
  781. for j := 0 to pd.paras.Count-1 do
  782. if assigned(pd.paras[j]) and not (vo_is_hidden_para in tparavarsym(pd.paras[j]).varoptions) then
  783. inc(realparamcount);
  784. if (paraidx<pd.paras.count) and
  785. assigned(pd.paras[paraidx]) and
  786. (realparamcount = 1) then
  787. begin
  788. eq:=compare_defs_ext(fromdef,tparavarsym(pd.paras[paraidx]).vardef,nothingn,convtyp,hpd,[]);
  789. { alias? if yes, only l1 choice,
  790. if you mess with this code, check tw4093 }
  791. if (eq=te_exact) and
  792. (fromdef<>tparavarsym(pd.paras[paraidx]).vardef) and
  793. ((df_unique in fromdef.defoptions) or
  794. (df_unique in tparavarsym(pd.paras[paraidx]).vardef.defoptions)) then
  795. eq:=te_convert_l1;
  796. if eq=te_exact then
  797. begin
  798. besteq:=eq;
  799. result:=pd;
  800. exit;
  801. end;
  802. if eq>besteq then
  803. begin
  804. bestpd:=pd;
  805. besteq:=eq;
  806. end;
  807. end;
  808. end;
  809. end;
  810. result:=bestpd;
  811. end;
  812. function Tprocsym.find_procdef_enumerator_operator(fromdef,todef:tdef;var besteq:tequaltype):Tprocdef;
  813. var
  814. paraidx, realparamcount,
  815. i, j : longint;
  816. bestpd,
  817. hpd,
  818. pd : tprocdef;
  819. current : tpropertysym;
  820. convtyp : tconverttype;
  821. eq : tequaltype;
  822. begin
  823. { This function will return the pprocdef of pprocsym that
  824. is the best match for fromdef and todef. }
  825. result:=nil;
  826. bestpd:=nil;
  827. besteq:=te_incompatible;
  828. for i:=0 to ProcdefList.Count-1 do
  829. begin
  830. pd:=tprocdef(ProcdefList[i]);
  831. if (pd.owner.symtabletype=staticsymtable) and not pd.owner.iscurrentunit then
  832. continue;
  833. if not (is_class_or_interface_or_object(pd.returndef) or is_record(pd.returndef)) then
  834. continue;
  835. current := tpropertysym(tabstractrecorddef(pd.returndef).search_enumerator_current);
  836. if (current = nil) then
  837. continue;
  838. // compare current result def with the todef
  839. if (equal_defs(todef, current.propdef) or
  840. { shortstrings of different lengths are ok as result }
  841. (is_shortstring(todef) and is_shortstring(current.propdef))) and
  842. { the result type must be always really equal and not an alias,
  843. if you mess with this code, check tw4093 }
  844. ((todef=current.propdef) or
  845. (
  846. not(df_unique in todef.defoptions) and
  847. not(df_unique in current.propdef.defoptions)
  848. )
  849. ) then
  850. begin
  851. paraidx:=0;
  852. { ignore vs_hidden parameters }
  853. while (paraidx<pd.paras.count) and
  854. assigned(pd.paras[paraidx]) and
  855. (vo_is_hidden_para in tparavarsym(pd.paras[paraidx]).varoptions) do
  856. inc(paraidx);
  857. realparamcount:=0;
  858. for j := 0 to pd.paras.Count-1 do
  859. if assigned(pd.paras[j]) and not (vo_is_hidden_para in tparavarsym(pd.paras[j]).varoptions) then
  860. inc(realparamcount);
  861. if (paraidx<pd.paras.count) and
  862. assigned(pd.paras[paraidx]) and
  863. (realparamcount = 1) then
  864. begin
  865. eq:=compare_defs_ext(fromdef,tparavarsym(pd.paras[paraidx]).vardef,nothingn,convtyp,hpd,[]);
  866. { alias? if yes, only l1 choice,
  867. if you mess with this code, check tw4093 }
  868. if (eq=te_exact) and
  869. (fromdef<>tparavarsym(pd.paras[paraidx]).vardef) and
  870. ((df_unique in fromdef.defoptions) or
  871. (df_unique in tparavarsym(pd.paras[paraidx]).vardef.defoptions)) then
  872. eq:=te_convert_l1;
  873. if eq=te_exact then
  874. begin
  875. besteq:=eq;
  876. result:=pd;
  877. exit;
  878. end;
  879. if eq>besteq then
  880. begin
  881. bestpd:=pd;
  882. besteq:=eq;
  883. end;
  884. end;
  885. end;
  886. end;
  887. result:=bestpd;
  888. end;
  889. {****************************************************************************
  890. TERRORSYM
  891. ****************************************************************************}
  892. constructor terrorsym.create;
  893. begin
  894. inherited create(errorsym,'');
  895. end;
  896. {****************************************************************************
  897. TPROPERTYSYM
  898. ****************************************************************************}
  899. constructor tpropertysym.create(const n : string);
  900. var
  901. pap : tpropaccesslisttypes;
  902. begin
  903. inherited create(propertysym,n);
  904. propoptions:=[];
  905. index:=0;
  906. default:=0;
  907. propdef:=nil;
  908. indexdef:=nil;
  909. for pap:=low(tpropaccesslisttypes) to high(tpropaccesslisttypes) do
  910. propaccesslist[pap]:=tpropaccesslist.create;
  911. end;
  912. constructor tpropertysym.ppuload(ppufile:tcompilerppufile);
  913. var
  914. pap : tpropaccesslisttypes;
  915. begin
  916. inherited ppuload(propertysym,ppufile);
  917. ppufile.getsmallset(propoptions);
  918. ppufile.getderef(overriddenpropsymderef);
  919. ppufile.getderef(propdefderef);
  920. index:=ppufile.getlongint;
  921. default:=ppufile.getlongint;
  922. ppufile.getderef(indexdefderef);
  923. for pap:=low(tpropaccesslisttypes) to high(tpropaccesslisttypes) do
  924. propaccesslist[pap]:=ppufile.getpropaccesslist;
  925. end;
  926. destructor tpropertysym.destroy;
  927. var
  928. pap : tpropaccesslisttypes;
  929. begin
  930. for pap:=low(tpropaccesslisttypes) to high(tpropaccesslisttypes) do
  931. propaccesslist[pap].free;
  932. inherited destroy;
  933. end;
  934. procedure tpropertysym.buildderef;
  935. var
  936. pap : tpropaccesslisttypes;
  937. begin
  938. overriddenpropsymderef.build(overriddenpropsym);
  939. propdefderef.build(propdef);
  940. indexdefderef.build(indexdef);
  941. for pap:=low(tpropaccesslisttypes) to high(tpropaccesslisttypes) do
  942. propaccesslist[pap].buildderef;
  943. end;
  944. procedure tpropertysym.deref;
  945. var
  946. pap : tpropaccesslisttypes;
  947. begin
  948. overriddenpropsym:=tpropertysym(overriddenpropsymderef.resolve);
  949. indexdef:=tdef(indexdefderef.resolve);
  950. propdef:=tdef(propdefderef.resolve);
  951. for pap:=low(tpropaccesslisttypes) to high(tpropaccesslisttypes) do
  952. propaccesslist[pap].resolve;
  953. end;
  954. function tpropertysym.getsize : asizeint;
  955. begin
  956. getsize:=0;
  957. end;
  958. procedure tpropertysym.ppuwrite(ppufile:tcompilerppufile);
  959. var
  960. pap : tpropaccesslisttypes;
  961. begin
  962. inherited ppuwrite(ppufile);
  963. ppufile.putsmallset(propoptions);
  964. ppufile.putderef(overriddenpropsymderef);
  965. ppufile.putderef(propdefderef);
  966. ppufile.putlongint(index);
  967. ppufile.putlongint(default);
  968. ppufile.putderef(indexdefderef);
  969. for pap:=low(tpropaccesslisttypes) to high(tpropaccesslisttypes) do
  970. ppufile.putpropaccesslist(propaccesslist[pap]);
  971. ppufile.writeentry(ibpropertysym);
  972. end;
  973. {****************************************************************************
  974. TABSTRACTVARSYM
  975. ****************************************************************************}
  976. constructor tabstractvarsym.create(st:tsymtyp;const n : string;vsp:tvarspez;def:tdef;vopts:tvaroptions);
  977. begin
  978. inherited create(st,n);
  979. vardef:=def;
  980. varspez:=vsp;
  981. varstate:=vs_declared;
  982. varoptions:=vopts;
  983. end;
  984. constructor tabstractvarsym.ppuload(st:tsymtyp;ppufile:tcompilerppufile);
  985. begin
  986. inherited ppuload(st,ppufile);
  987. varstate:=vs_readwritten;
  988. varspez:=tvarspez(ppufile.getbyte);
  989. varregable:=tvarregable(ppufile.getbyte);
  990. addr_taken:=boolean(ppufile.getbyte);
  991. ppufile.getderef(vardefderef);
  992. ppufile.getsmallset(varoptions);
  993. end;
  994. destructor tabstractvarsym.destroy;
  995. begin
  996. if assigned(notifications) then
  997. notifications.destroy;
  998. inherited destroy;
  999. end;
  1000. procedure tabstractvarsym.buildderef;
  1001. begin
  1002. vardefderef.build(vardef);
  1003. end;
  1004. procedure tabstractvarsym.deref;
  1005. var
  1006. oldvarregable: tvarregable;
  1007. begin
  1008. { setting the vardef also updates varregable. We just loaded this }
  1009. { value from a ppu, so it must not be changed (e.g. tw7817a.pp/ }
  1010. { tw7817b.pp: the address is taken of a local variable in an }
  1011. { inlined procedure -> must remain non-regable when inlining) }
  1012. oldvarregable:=varregable;
  1013. vardef:=tdef(vardefderef.resolve);
  1014. varregable:=oldvarregable;
  1015. end;
  1016. procedure tabstractvarsym.ppuwrite(ppufile:tcompilerppufile);
  1017. var
  1018. oldintfcrc : boolean;
  1019. begin
  1020. inherited ppuwrite(ppufile);
  1021. ppufile.putbyte(byte(varspez));
  1022. oldintfcrc:=ppufile.do_crc;
  1023. ppufile.do_crc:=false;
  1024. ppufile.putbyte(byte(varregable));
  1025. ppufile.putbyte(byte(addr_taken));
  1026. ppufile.do_crc:=oldintfcrc;
  1027. ppufile.putderef(vardefderef);
  1028. ppufile.putsmallset(varoptions);
  1029. end;
  1030. function tabstractvarsym.getsize : asizeint;
  1031. begin
  1032. if assigned(vardef) and
  1033. ((vardef.typ<>arraydef) or
  1034. is_dynamic_array(vardef) or
  1035. (tarraydef(vardef).highrange>=tarraydef(vardef).lowrange)) then
  1036. result:=vardef.size
  1037. else
  1038. result:=0;
  1039. end;
  1040. function tabstractvarsym.getpackedbitsize : longint;
  1041. begin
  1042. { bitpacking is only done for ordinals }
  1043. if not is_ordinal(vardef) then
  1044. internalerror(2006082010);
  1045. result:=vardef.packedbitsize;
  1046. end;
  1047. function tabstractvarsym.is_regvar(refpara: boolean):boolean;
  1048. begin
  1049. { Register variables are not allowed in the following cases:
  1050. - regvars are disabled
  1051. - exceptions are used (after an exception is raised the contents of the
  1052. registers is not valid anymore)
  1053. - it has a local copy
  1054. - the value needs to be in memory (i.e. reference counted) }
  1055. result:=(cs_opt_regvar in current_settings.optimizerswitches) and
  1056. not(pi_has_assembler_block in current_procinfo.flags) and
  1057. not(pi_uses_exceptions in current_procinfo.flags) and
  1058. not(pi_has_interproclabel in current_procinfo.flags) and
  1059. not(vo_has_local_copy in varoptions) and
  1060. ((refpara and
  1061. (varregable <> vr_none)) or
  1062. (not refpara and
  1063. not(varregable in [vr_none,vr_addr])))
  1064. {$if not defined(powerpc) and not defined(powerpc64)}
  1065. and ((vardef.typ <> recorddef) or
  1066. (varregable = vr_addr) or
  1067. not(varstate in [vs_written,vs_readwritten]));
  1068. {$endif}
  1069. end;
  1070. procedure tabstractvarsym.trigger_notifications(what:Tnotification_flag);
  1071. var n:Tnotification;
  1072. begin
  1073. if assigned(notifications) then
  1074. begin
  1075. n:=Tnotification(notifications.first);
  1076. while assigned(n) do
  1077. begin
  1078. if what in n.flags then
  1079. n.callback(what,self);
  1080. n:=Tnotification(n.next);
  1081. end;
  1082. end;
  1083. end;
  1084. function Tabstractvarsym.register_notification(flags:Tnotification_flags;callback:
  1085. Tnotification_callback):cardinal;
  1086. var n:Tnotification;
  1087. begin
  1088. if not assigned(notifications) then
  1089. notifications:=Tlinkedlist.create;
  1090. n:=Tnotification.create(flags,callback);
  1091. register_notification:=n.id;
  1092. notifications.concat(n);
  1093. end;
  1094. procedure Tabstractvarsym.unregister_notification(id:cardinal);
  1095. var n:Tnotification;
  1096. begin
  1097. if not assigned(notifications) then
  1098. internalerror(200212311)
  1099. else
  1100. begin
  1101. n:=Tnotification(notifications.first);
  1102. while assigned(n) do
  1103. begin
  1104. if n.id=id then
  1105. begin
  1106. notifications.remove(n);
  1107. n.destroy;
  1108. exit;
  1109. end;
  1110. n:=Tnotification(n.next);
  1111. end;
  1112. internalerror(200212311)
  1113. end;
  1114. end;
  1115. procedure tabstractvarsym.setvardef(def:tdef);
  1116. begin
  1117. _vardef := def;
  1118. { can we load the value into a register ? }
  1119. if not assigned(owner) or
  1120. (owner.symtabletype in [localsymtable,parasymtable]) or
  1121. (
  1122. (owner.symtabletype=staticsymtable) and
  1123. not(cs_create_pic in current_settings.moduleswitches)
  1124. ) then
  1125. begin
  1126. if tstoreddef(vardef).is_intregable then
  1127. varregable:=vr_intreg
  1128. else
  1129. { $warning TODO: no fpu regvar in staticsymtable yet, need initialization with 0 }
  1130. if {(
  1131. not assigned(owner) or
  1132. (owner.symtabletype<>staticsymtable)
  1133. ) and }
  1134. tstoreddef(vardef).is_fpuregable then
  1135. begin
  1136. if use_vectorfpu(vardef) then
  1137. varregable:=vr_mmreg
  1138. else
  1139. varregable:=vr_fpureg;
  1140. end;
  1141. end;
  1142. end;
  1143. {****************************************************************************
  1144. TFIELDVARSYM
  1145. ****************************************************************************}
  1146. constructor tfieldvarsym.create(const n : string;vsp:tvarspez;def:tdef;vopts:tvaroptions);
  1147. begin
  1148. inherited create(fieldvarsym,n,vsp,def,vopts);
  1149. fieldoffset:=-1;
  1150. end;
  1151. constructor tfieldvarsym.ppuload(ppufile:tcompilerppufile);
  1152. begin
  1153. inherited ppuload(fieldvarsym,ppufile);
  1154. fieldoffset:=ppufile.getaint;
  1155. if (vo_has_mangledname in varoptions) then
  1156. externalname:=stringdup(ppufile.getstring)
  1157. else
  1158. externalname:=nil;
  1159. end;
  1160. procedure tfieldvarsym.ppuwrite(ppufile:tcompilerppufile);
  1161. begin
  1162. inherited ppuwrite(ppufile);
  1163. ppufile.putaint(fieldoffset);
  1164. if (vo_has_mangledname in varoptions) then
  1165. ppufile.putstring(externalname^);
  1166. ppufile.writeentry(ibfieldvarsym);
  1167. end;
  1168. procedure tfieldvarsym.set_externalname(const s: string);
  1169. begin
  1170. { make sure it is recalculated }
  1171. {$ifdef symansistr}
  1172. cachedmangledname:='';
  1173. {$else symansistr}
  1174. stringdispose(cachedmangledname);
  1175. {$endif symansistr}
  1176. {$ifdef jvm}
  1177. if is_java_class_or_interface(tdef(owner.defowner)) then
  1178. begin
  1179. externalname:=stringdup(s);
  1180. include(varoptions,vo_has_mangledname);
  1181. end
  1182. else
  1183. {$endif jvm}
  1184. internalerror(2011031201);
  1185. end;
  1186. function tfieldvarsym.mangledname:TSymStr;
  1187. var
  1188. srsym : tsym;
  1189. srsymtable : tsymtable;
  1190. begin
  1191. {$ifdef jvm}
  1192. if is_java_class_or_interface(tdef(owner.defowner)) or
  1193. (tdef(owner.defowner).typ=recorddef) then
  1194. begin
  1195. if cachedmangledname<>'' then
  1196. result:=cachedmangledname
  1197. else
  1198. begin
  1199. result:=jvmmangledbasename(self,false);
  1200. jvmaddtypeownerprefix(owner,result);
  1201. cachedmangledname:=result;
  1202. end;
  1203. end
  1204. else
  1205. {$endif jvm}
  1206. if sp_static in symoptions then
  1207. begin
  1208. if searchsym(lower(owner.name^)+'_'+name,srsym,srsymtable) then
  1209. result:=srsym.mangledname
  1210. { when generating the debug info for the module in which the }
  1211. { symbol is defined, the localsymtable of that module is }
  1212. { already popped from the symtablestack }
  1213. else if searchsym_in_module(current_module,lower(owner.name^)+'_'+name,srsym,srsymtable) then
  1214. result:=srsym.mangledname
  1215. else
  1216. internalerror(2007012501);
  1217. end
  1218. else if is_objcclass(tdef(owner.defowner)) then
  1219. begin
  1220. {$ifdef symansistr}
  1221. if cachedmangledname<>'' then
  1222. result:=cachedmangledname
  1223. {$else symansistr}
  1224. if assigned(cachedmangledname) then
  1225. result:=cachedmangledname^
  1226. {$endif symansistr}
  1227. else
  1228. begin
  1229. result:=target_info.cprefix+'OBJC_IVAR_$_'+tobjectdef(owner.defowner).objextname^+'.'+RealName;
  1230. {$ifdef symansistr}
  1231. cachedmangledname:=result;
  1232. {$else symansistr}
  1233. cachedmangledname:=stringdup(result);
  1234. {$endif symansistr}
  1235. end;
  1236. end
  1237. else
  1238. result:=inherited mangledname;
  1239. end;
  1240. destructor tfieldvarsym.destroy;
  1241. begin
  1242. {$ifndef symansistr}
  1243. stringdispose(cachedmangledname);
  1244. {$endif symansistr}
  1245. stringdispose(externalname);
  1246. inherited destroy;
  1247. end;
  1248. {****************************************************************************
  1249. TABSTRACTNORMALVARSYM
  1250. ****************************************************************************}
  1251. constructor tabstractnormalvarsym.create(st:tsymtyp;const n : string;vsp:tvarspez;def:tdef;vopts:tvaroptions);
  1252. begin
  1253. inherited create(st,n,vsp,def,vopts);
  1254. fillchar(localloc,sizeof(localloc),0);
  1255. fillchar(initialloc,sizeof(initialloc),0);
  1256. defaultconstsym:=nil;
  1257. end;
  1258. constructor tabstractnormalvarsym.ppuload(st:tsymtyp;ppufile:tcompilerppufile);
  1259. begin
  1260. inherited ppuload(st,ppufile);
  1261. fillchar(localloc,sizeof(localloc),0);
  1262. fillchar(initialloc,sizeof(initialloc),0);
  1263. ppufile.getderef(defaultconstsymderef);
  1264. end;
  1265. procedure tabstractnormalvarsym.buildderef;
  1266. begin
  1267. inherited buildderef;
  1268. defaultconstsymderef.build(defaultconstsym);
  1269. end;
  1270. procedure tabstractnormalvarsym.deref;
  1271. begin
  1272. inherited deref;
  1273. defaultconstsym:=tsym(defaultconstsymderef.resolve);
  1274. end;
  1275. procedure tabstractnormalvarsym.ppuwrite(ppufile:tcompilerppufile);
  1276. begin
  1277. inherited ppuwrite(ppufile);
  1278. ppufile.putderef(defaultconstsymderef);
  1279. end;
  1280. {****************************************************************************
  1281. Tstaticvarsym
  1282. ****************************************************************************}
  1283. constructor tstaticvarsym.create(const n : string;vsp:tvarspez;def:tdef;vopts:tvaroptions);
  1284. begin
  1285. inherited create(staticvarsym,n,vsp,def,vopts);
  1286. {$ifdef symansistr}
  1287. _mangledname:='';
  1288. {$else symansistr}
  1289. _mangledname:=nil;
  1290. {$endif symansistr}
  1291. end;
  1292. constructor tstaticvarsym.create_dll(const n : string;vsp:tvarspez;def:tdef);
  1293. begin
  1294. tstaticvarsym(self).create(n,vsp,def,[vo_is_dll_var]);
  1295. end;
  1296. constructor tstaticvarsym.create_C(const n: string; const mangled : TSymStr;vsp:tvarspez;def:tdef);
  1297. begin
  1298. tstaticvarsym(self).create(n,vsp,def,[]);
  1299. set_mangledname(mangled);
  1300. end;
  1301. constructor tstaticvarsym.ppuload(ppufile:tcompilerppufile);
  1302. begin
  1303. inherited ppuload(staticvarsym,ppufile);
  1304. {$ifdef symansistr}
  1305. if vo_has_mangledname in varoptions then
  1306. _mangledname:=ppufile.getansistring
  1307. else
  1308. _mangledname:='';
  1309. {$else symansistr}
  1310. if vo_has_mangledname in varoptions then
  1311. _mangledname:=stringdup(ppufile.getstring)
  1312. else
  1313. _mangledname:=nil;
  1314. if vo_has_section in varoptions then
  1315. section:=ppufile.getansistring;
  1316. {$endif symansistr}
  1317. end;
  1318. destructor tstaticvarsym.destroy;
  1319. begin
  1320. {$ifndef symansistr}
  1321. if assigned(_mangledname) then
  1322. begin
  1323. {$ifdef MEMDEBUG}
  1324. memmanglednames.start;
  1325. {$endif MEMDEBUG}
  1326. stringdispose(_mangledname);
  1327. {$ifdef MEMDEBUG}
  1328. memmanglednames.stop;
  1329. {$endif MEMDEBUG}
  1330. end;
  1331. stringdispose(_mangledbasename);
  1332. {$endif}
  1333. inherited destroy;
  1334. end;
  1335. procedure tstaticvarsym.ppuwrite(ppufile:tcompilerppufile);
  1336. begin
  1337. inherited ppuwrite(ppufile);
  1338. { write mangledname rather than _mangledname in case the mangledname
  1339. has not been calculated yet (can happen in case only the
  1340. mangledbasename has been set) }
  1341. if vo_has_mangledname in varoptions then
  1342. {$ifdef symansistr}
  1343. ppufile.putansistring(mangledname);
  1344. {$else symansistr}
  1345. ppufile.putstring(mangledname);
  1346. {$endif symansistr}
  1347. if vo_has_section in varoptions then
  1348. ppufile.putansistring(section);
  1349. ppufile.writeentry(ibstaticvarsym);
  1350. end;
  1351. function tstaticvarsym.mangledname:TSymStr;
  1352. {$ifndef jvm}
  1353. var
  1354. usename,
  1355. prefix : TSymStr;
  1356. {$endif jvm}
  1357. begin
  1358. {$ifdef symansistr}
  1359. if _mangledname='' then
  1360. {$else symansistr}
  1361. if not assigned(_mangledname) then
  1362. {$endif symansistr}
  1363. begin
  1364. {$ifdef jvm}
  1365. if _mangledbasename='' then
  1366. _mangledname:=jvmmangledbasename(self,false)
  1367. else
  1368. _mangledname:=jvmmangledbasename(self,_mangledbasename,false);
  1369. jvmaddtypeownerprefix(owner,_mangledname);
  1370. {$else jvm}
  1371. if (vo_is_typed_const in varoptions) then
  1372. prefix:='TC'
  1373. else
  1374. prefix:='U';
  1375. {$ifdef symansistr}
  1376. if _mangledbasename='' then
  1377. usename:=name
  1378. else
  1379. usename:=_mangledbasename;
  1380. {$else symansistr}
  1381. if not assigned(_mangledbasename) then
  1382. usename:=name
  1383. else
  1384. usename:=_mangledbasename^;
  1385. {$endif symansistr}
  1386. {$ifdef compress}
  1387. {$error add ansistring support for symansistr}
  1388. _mangledname:=stringdup(minilzw_encode(make_mangledname(prefix,owner,usename)));
  1389. {$else compress}
  1390. {$ifdef symansistr}
  1391. _mangledname:=make_mangledname(prefix,owner,usename);
  1392. {$else symansistr}
  1393. _mangledname:=stringdup(make_mangledname(prefix,owner,usename));
  1394. {$endif symansistr}
  1395. {$endif compress}
  1396. {$endif jvm}
  1397. end;
  1398. {$ifdef symansistr}
  1399. result:=_mangledname;
  1400. {$else symansistr}
  1401. result:=_mangledname^;
  1402. {$endif symansistr}
  1403. end;
  1404. procedure tstaticvarsym.set_mangledbasename(const s: TSymStr);
  1405. begin
  1406. {$ifdef symansistr}
  1407. if _mangledname<>'' then
  1408. internalerror(2011082202);
  1409. _mangledbasename:=s;
  1410. {$else symansistr}
  1411. if assigned(_mangledname) then
  1412. internalerror(2011082202);
  1413. stringdispose(_mangledbasename);
  1414. _mangledbasename:=stringdup(s);
  1415. {$endif symansistr}
  1416. include(varoptions,vo_has_mangledname);
  1417. end;
  1418. function tstaticvarsym.mangledbasename: TSymStr;
  1419. begin
  1420. {$ifdef symansistr}
  1421. result:=_mangledbasename;
  1422. {$else symansistr}
  1423. if assigned(_mangledbasename) then
  1424. result:=_mangledbasename^
  1425. else
  1426. result:='';
  1427. {$endif symansistr}
  1428. end;
  1429. procedure tstaticvarsym.set_mangledname(const s:TSymStr);
  1430. begin
  1431. {$ifndef symansistr}
  1432. stringdispose(_mangledname);
  1433. {$endif}
  1434. {$if defined(jvm)}
  1435. _mangledname:=jvmmangledbasename(self,s,false);
  1436. jvmaddtypeownerprefix(owner,_mangledname);
  1437. {$elseif defined(compress)}
  1438. _mangledname:=stringdup(minilzw_encode(s));
  1439. {$else}
  1440. {$ifdef symansistr}
  1441. _mangledname:=s;
  1442. {$else symansistr}
  1443. _mangledname:=stringdup(s);
  1444. {$endif symansistr}
  1445. {$endif}
  1446. include(varoptions,vo_has_mangledname);
  1447. end;
  1448. procedure tstaticvarsym.set_raw_mangledname(const s: TSymStr);
  1449. begin
  1450. {$ifndef symansistr}
  1451. stringdispose(_mangledname);
  1452. _mangledname:=stringdup(s);
  1453. {$else}
  1454. _mangledname:=s;
  1455. {$endif}
  1456. include(varoptions,vo_has_mangledname);
  1457. end;
  1458. {****************************************************************************
  1459. TLOCALVARSYM
  1460. ****************************************************************************}
  1461. constructor tlocalvarsym.create(const n : string;vsp:tvarspez;def:tdef;vopts:tvaroptions);
  1462. begin
  1463. inherited create(localvarsym,n,vsp,def,vopts);
  1464. end;
  1465. constructor tlocalvarsym.ppuload(ppufile:tcompilerppufile);
  1466. begin
  1467. inherited ppuload(localvarsym,ppufile);
  1468. end;
  1469. procedure tlocalvarsym.ppuwrite(ppufile:tcompilerppufile);
  1470. begin
  1471. inherited ppuwrite(ppufile);
  1472. ppufile.writeentry(iblocalvarsym);
  1473. end;
  1474. {****************************************************************************
  1475. TPARAVARSYM
  1476. ****************************************************************************}
  1477. constructor tparavarsym.create(const n : string;nr:word;vsp:tvarspez;def:tdef;vopts:tvaroptions);
  1478. begin
  1479. inherited create(paravarsym,n,vsp,def,vopts);
  1480. if (vsp in [vs_var,vs_value,vs_const,vs_constref]) then
  1481. varstate := vs_initialised;
  1482. paranr:=nr;
  1483. paraloc[calleeside].init;
  1484. paraloc[callerside].init;
  1485. end;
  1486. destructor tparavarsym.destroy;
  1487. begin
  1488. paraloc[calleeside].done;
  1489. paraloc[callerside].done;
  1490. inherited destroy;
  1491. end;
  1492. constructor tparavarsym.ppuload(ppufile:tcompilerppufile);
  1493. var
  1494. b : byte;
  1495. begin
  1496. inherited ppuload(paravarsym,ppufile);
  1497. paranr:=ppufile.getword;
  1498. univpara:=boolean(ppufile.getbyte);
  1499. { The var state of parameter symbols is fixed after writing them so
  1500. we write them to the unit file.
  1501. This enables constant folding for inline procedures loaded from units
  1502. }
  1503. varstate:=tvarstate(ppufile.getbyte);
  1504. paraloc[calleeside].init;
  1505. paraloc[callerside].init;
  1506. if vo_has_explicit_paraloc in varoptions then
  1507. begin
  1508. paraloc[callerside].alignment:=ppufile.getbyte;
  1509. b:=ppufile.getbyte;
  1510. if b<>sizeof(paraloc[callerside].location^) then
  1511. internalerror(200411154);
  1512. ppufile.getdata(paraloc[callerside].add_location^,sizeof(paraloc[callerside].location^));
  1513. paraloc[callerside].size:=paraloc[callerside].location^.size;
  1514. paraloc[callerside].intsize:=tcgsize2size[paraloc[callerside].size];
  1515. end;
  1516. end;
  1517. procedure tparavarsym.ppuwrite(ppufile:tcompilerppufile);
  1518. var
  1519. oldintfcrc : boolean;
  1520. begin
  1521. inherited ppuwrite(ppufile);
  1522. ppufile.putword(paranr);
  1523. ppufile.putbyte(byte(univpara));
  1524. { The var state of parameter symbols is fixed after writing them so
  1525. we write them to the unit file.
  1526. This enables constant folding for inline procedures loaded from units
  1527. }
  1528. oldintfcrc:=ppufile.do_crc;
  1529. ppufile.do_crc:=false;
  1530. ppufile.putbyte(ord(varstate));
  1531. ppufile.do_crc:=oldintfcrc;
  1532. if vo_has_explicit_paraloc in varoptions then
  1533. begin
  1534. paraloc[callerside].check_simple_location;
  1535. ppufile.putbyte(sizeof(paraloc[callerside].alignment));
  1536. ppufile.putbyte(sizeof(paraloc[callerside].location^));
  1537. ppufile.putdata(paraloc[callerside].location^,sizeof(paraloc[callerside].location^));
  1538. end;
  1539. ppufile.writeentry(ibparavarsym);
  1540. end;
  1541. {****************************************************************************
  1542. TABSOLUTEVARSYM
  1543. ****************************************************************************}
  1544. constructor tabsolutevarsym.create(const n : string;def:tdef);
  1545. begin
  1546. inherited create(absolutevarsym,n,vs_value,def,[]);
  1547. ref:=nil;
  1548. end;
  1549. constructor tabsolutevarsym.create_ref(const n : string;def:tdef;_ref:tpropaccesslist);
  1550. begin
  1551. inherited create(absolutevarsym,n,vs_value,def,[]);
  1552. ref:=_ref;
  1553. end;
  1554. destructor tabsolutevarsym.destroy;
  1555. begin
  1556. if assigned(ref) then
  1557. ref.free;
  1558. inherited destroy;
  1559. end;
  1560. constructor tabsolutevarsym.ppuload(ppufile:tcompilerppufile);
  1561. begin
  1562. inherited ppuload(absolutevarsym,ppufile);
  1563. ref:=nil;
  1564. asmname:=nil;
  1565. abstyp:=absolutetyp(ppufile.getbyte);
  1566. {$ifdef i386}
  1567. absseg:=false;
  1568. {$endif i386}
  1569. case abstyp of
  1570. tovar :
  1571. ref:=ppufile.getpropaccesslist;
  1572. toasm :
  1573. asmname:=stringdup(ppufile.getstring);
  1574. toaddr :
  1575. begin
  1576. addroffset:=ppufile.getaword;
  1577. {$ifdef i386}
  1578. absseg:=boolean(ppufile.getbyte);
  1579. {$endif i386}
  1580. end;
  1581. end;
  1582. end;
  1583. procedure tabsolutevarsym.ppuwrite(ppufile:tcompilerppufile);
  1584. begin
  1585. inherited ppuwrite(ppufile);
  1586. ppufile.putbyte(byte(abstyp));
  1587. case abstyp of
  1588. tovar :
  1589. ppufile.putpropaccesslist(ref);
  1590. toasm :
  1591. ppufile.putstring(asmname^);
  1592. toaddr :
  1593. begin
  1594. ppufile.putaword(addroffset);
  1595. {$ifdef i386}
  1596. ppufile.putbyte(byte(absseg));
  1597. {$endif i386}
  1598. end;
  1599. end;
  1600. ppufile.writeentry(ibabsolutevarsym);
  1601. end;
  1602. procedure tabsolutevarsym.buildderef;
  1603. begin
  1604. inherited buildderef;
  1605. if (abstyp=tovar) then
  1606. ref.buildderef;
  1607. end;
  1608. procedure tabsolutevarsym.deref;
  1609. begin
  1610. inherited deref;
  1611. { own absolute deref }
  1612. if (abstyp=tovar) then
  1613. ref.resolve;
  1614. end;
  1615. function tabsolutevarsym.mangledname : TSymStr;
  1616. begin
  1617. case abstyp of
  1618. toasm :
  1619. mangledname:=asmname^;
  1620. toaddr :
  1621. mangledname:='$'+tostr(addroffset);
  1622. else
  1623. internalerror(200411062);
  1624. end;
  1625. end;
  1626. {****************************************************************************
  1627. TCONSTSYM
  1628. ****************************************************************************}
  1629. constructor tconstsym.create_ord(const n : string;t : tconsttyp;v : tconstexprint;def:tdef);
  1630. begin
  1631. inherited create(constsym,n);
  1632. fillchar(value, sizeof(value), #0);
  1633. consttyp:=t;
  1634. value.valueord:=v;
  1635. constdef:=def;
  1636. end;
  1637. constructor tconstsym.create_ordptr(const n : string;t : tconsttyp;v : tconstptruint;def:tdef);
  1638. begin
  1639. inherited create(constsym,n);
  1640. fillchar(value, sizeof(value), #0);
  1641. consttyp:=t;
  1642. value.valueordptr:=v;
  1643. constdef:=def;
  1644. end;
  1645. constructor tconstsym.create_ptr(const n : string;t : tconsttyp;v : pointer;def:tdef);
  1646. begin
  1647. inherited create(constsym,n);
  1648. fillchar(value, sizeof(value), #0);
  1649. consttyp:=t;
  1650. value.valueptr:=v;
  1651. constdef:=def;
  1652. end;
  1653. constructor tconstsym.create_string(const n : string;t : tconsttyp;str:pchar;l:longint);
  1654. begin
  1655. inherited create(constsym,n);
  1656. fillchar(value, sizeof(value), #0);
  1657. consttyp:=t;
  1658. value.valueptr:=str;
  1659. constdef:=nil;
  1660. value.len:=l;
  1661. end;
  1662. constructor tconstsym.create_wstring(const n : string;t : tconsttyp;pw:pcompilerwidestring);
  1663. begin
  1664. inherited create(constsym,n);
  1665. fillchar(value, sizeof(value), #0);
  1666. consttyp:=t;
  1667. pcompilerwidestring(value.valueptr):=pw;
  1668. constdef:=nil;
  1669. value.len:=getlengthwidestring(pw);
  1670. end;
  1671. constructor tconstsym.ppuload(ppufile:tcompilerppufile);
  1672. var
  1673. pd : pbestreal;
  1674. ps : pnormalset;
  1675. pc : pchar;
  1676. pw : pcompilerwidestring;
  1677. i : longint;
  1678. begin
  1679. inherited ppuload(constsym,ppufile);
  1680. constdef:=nil;
  1681. consttyp:=tconsttyp(ppufile.getbyte);
  1682. fillchar(value, sizeof(value), #0);
  1683. case consttyp of
  1684. constord :
  1685. begin
  1686. ppufile.getderef(constdefderef);
  1687. value.valueord:=ppufile.getexprint;
  1688. end;
  1689. constpointer :
  1690. begin
  1691. ppufile.getderef(constdefderef);
  1692. value.valueordptr:=ppufile.getptruint;
  1693. end;
  1694. constwstring :
  1695. begin
  1696. initwidestring(pw);
  1697. setlengthwidestring(pw,ppufile.getlongint);
  1698. { don't use getdata, because the compilerwidechars may have to
  1699. be byteswapped
  1700. }
  1701. {$if sizeof(tcompilerwidechar) = 2}
  1702. for i:=0 to pw^.len-1 do
  1703. pw^.data[i]:=ppufile.getword;
  1704. {$elseif sizeof(tcompilerwidechar) = 4}
  1705. for i:=0 to pw^.len-1 do
  1706. pw^.data[i]:=cardinal(ppufile.getlongint);
  1707. {$else}
  1708. {$error Unsupported tcompilerwidechar size}
  1709. {$endif}
  1710. pcompilerwidestring(value.valueptr):=pw;
  1711. end;
  1712. conststring,
  1713. constresourcestring :
  1714. begin
  1715. value.len:=ppufile.getlongint;
  1716. getmem(pc,value.len+1);
  1717. ppufile.getdata(pc^,value.len);
  1718. pc[value.len]:=#0;
  1719. value.valueptr:=pc;
  1720. end;
  1721. constreal :
  1722. begin
  1723. new(pd);
  1724. pd^:=ppufile.getreal;
  1725. value.valueptr:=pd;
  1726. end;
  1727. constset :
  1728. begin
  1729. ppufile.getderef(constdefderef);
  1730. new(ps);
  1731. ppufile.getnormalset(ps^);
  1732. value.valueptr:=ps;
  1733. end;
  1734. constguid :
  1735. begin
  1736. new(pguid(value.valueptr));
  1737. ppufile.getdata(value.valueptr^,sizeof(tguid));
  1738. end;
  1739. constnil : ;
  1740. else
  1741. Message1(unit_f_ppu_invalid_entry,tostr(ord(consttyp)));
  1742. end;
  1743. end;
  1744. destructor tconstsym.destroy;
  1745. begin
  1746. case consttyp of
  1747. conststring,
  1748. constresourcestring :
  1749. freemem(pchar(value.valueptr),value.len+1);
  1750. constwstring :
  1751. donewidestring(pcompilerwidestring(value.valueptr));
  1752. constreal :
  1753. dispose(pbestreal(value.valueptr));
  1754. constset :
  1755. dispose(pnormalset(value.valueptr));
  1756. constguid :
  1757. dispose(pguid(value.valueptr));
  1758. end;
  1759. inherited destroy;
  1760. end;
  1761. procedure tconstsym.buildderef;
  1762. begin
  1763. if consttyp in [constord,constpointer,constset] then
  1764. constdefderef.build(constdef);
  1765. end;
  1766. procedure tconstsym.deref;
  1767. begin
  1768. if consttyp in [constord,constpointer,constset] then
  1769. constdef:=tdef(constdefderef.resolve);
  1770. end;
  1771. procedure tconstsym.ppuwrite(ppufile:tcompilerppufile);
  1772. begin
  1773. inherited ppuwrite(ppufile);
  1774. ppufile.putbyte(byte(consttyp));
  1775. case consttyp of
  1776. constnil : ;
  1777. constord :
  1778. begin
  1779. ppufile.putderef(constdefderef);
  1780. ppufile.putexprint(value.valueord);
  1781. end;
  1782. constpointer :
  1783. begin
  1784. ppufile.putderef(constdefderef);
  1785. ppufile.putptruint(value.valueordptr);
  1786. end;
  1787. constwstring :
  1788. begin
  1789. ppufile.putlongint(getlengthwidestring(pcompilerwidestring(value.valueptr)));
  1790. ppufile.putdata(pcompilerwidestring(value.valueptr)^.data^,pcompilerwidestring(value.valueptr)^.len*sizeof(tcompilerwidechar));
  1791. end;
  1792. conststring,
  1793. constresourcestring :
  1794. begin
  1795. ppufile.putlongint(value.len);
  1796. ppufile.putdata(pchar(value.valueptr)^,value.len);
  1797. end;
  1798. constreal :
  1799. ppufile.putreal(pbestreal(value.valueptr)^);
  1800. constset :
  1801. begin
  1802. ppufile.putderef(constdefderef);
  1803. ppufile.putnormalset(value.valueptr^);
  1804. end;
  1805. constguid :
  1806. ppufile.putdata(value.valueptr^,sizeof(tguid));
  1807. else
  1808. internalerror(13);
  1809. end;
  1810. ppufile.writeentry(ibconstsym);
  1811. end;
  1812. {****************************************************************************
  1813. TENUMSYM
  1814. ****************************************************************************}
  1815. constructor tenumsym.create(const n : string;def : tenumdef;v : longint);
  1816. begin
  1817. inherited create(enumsym,n);
  1818. definition:=def;
  1819. value:=v;
  1820. end;
  1821. constructor tenumsym.ppuload(ppufile:tcompilerppufile);
  1822. begin
  1823. inherited ppuload(enumsym,ppufile);
  1824. ppufile.getderef(definitionderef);
  1825. value:=ppufile.getlongint;
  1826. end;
  1827. procedure tenumsym.buildderef;
  1828. begin
  1829. definitionderef.build(definition);
  1830. end;
  1831. procedure tenumsym.deref;
  1832. begin
  1833. definition:=tenumdef(definitionderef.resolve);
  1834. end;
  1835. procedure tenumsym.ppuwrite(ppufile:tcompilerppufile);
  1836. begin
  1837. inherited ppuwrite(ppufile);
  1838. ppufile.putderef(definitionderef);
  1839. ppufile.putlongint(value);
  1840. ppufile.writeentry(ibenumsym);
  1841. end;
  1842. {****************************************************************************
  1843. TTYPESYM
  1844. ****************************************************************************}
  1845. constructor ttypesym.create(const n : string;def:tdef);
  1846. begin
  1847. inherited create(typesym,n);
  1848. typedef:=def;
  1849. { register the typesym for the definition }
  1850. if assigned(typedef) and
  1851. (typedef.typ<>errordef) and
  1852. not(assigned(typedef.typesym)) then
  1853. typedef.typesym:=self;
  1854. end;
  1855. constructor ttypesym.ppuload(ppufile:tcompilerppufile);
  1856. begin
  1857. inherited ppuload(typesym,ppufile);
  1858. ppufile.getderef(typedefderef);
  1859. fprettyname:=ppufile.getansistring;
  1860. end;
  1861. procedure ttypesym.buildderef;
  1862. begin
  1863. typedefderef.build(typedef);
  1864. end;
  1865. procedure ttypesym.deref;
  1866. begin
  1867. typedef:=tdef(typedefderef.resolve);
  1868. end;
  1869. procedure ttypesym.ppuwrite(ppufile:tcompilerppufile);
  1870. begin
  1871. inherited ppuwrite(ppufile);
  1872. ppufile.putderef(typedefderef);
  1873. ppufile.putansistring(fprettyname);
  1874. ppufile.writeentry(ibtypesym);
  1875. end;
  1876. function ttypesym.prettyname : string;
  1877. begin
  1878. if fprettyname<>'' then
  1879. result:=fprettyname
  1880. else
  1881. result:=inherited prettyname;
  1882. end;
  1883. {****************************************************************************
  1884. TSYSSYM
  1885. ****************************************************************************}
  1886. constructor tsyssym.create(const n : string;l : longint);
  1887. begin
  1888. inherited create(syssym,n);
  1889. number:=l;
  1890. end;
  1891. constructor tsyssym.ppuload(ppufile:tcompilerppufile);
  1892. begin
  1893. inherited ppuload(syssym,ppufile);
  1894. number:=ppufile.getlongint;
  1895. end;
  1896. destructor tsyssym.destroy;
  1897. begin
  1898. inherited destroy;
  1899. end;
  1900. procedure tsyssym.ppuwrite(ppufile:tcompilerppufile);
  1901. begin
  1902. inherited ppuwrite(ppufile);
  1903. ppufile.putlongint(number);
  1904. ppufile.writeentry(ibsyssym);
  1905. end;
  1906. {*****************************************************************************
  1907. TMacro
  1908. *****************************************************************************}
  1909. constructor tmacro.create(const n : string);
  1910. begin
  1911. inherited create(macrosym,n);
  1912. owner:=nil;
  1913. defined:=false;
  1914. is_used:=false;
  1915. is_compiler_var:=false;
  1916. buftext:=nil;
  1917. buflen:=0;
  1918. end;
  1919. constructor tmacro.ppuload(ppufile:tcompilerppufile);
  1920. begin
  1921. inherited ppuload(macrosym,ppufile);
  1922. defined:=boolean(ppufile.getbyte);
  1923. is_compiler_var:=boolean(ppufile.getbyte);
  1924. is_used:=false;
  1925. buflen:= ppufile.getlongint;
  1926. if buflen > 0 then
  1927. begin
  1928. getmem(buftext, buflen);
  1929. ppufile.getdata(buftext^, buflen)
  1930. end
  1931. else
  1932. buftext:=nil;
  1933. end;
  1934. destructor tmacro.destroy;
  1935. begin
  1936. if assigned(buftext) then
  1937. freemem(buftext);
  1938. inherited destroy;
  1939. end;
  1940. procedure tmacro.ppuwrite(ppufile:tcompilerppufile);
  1941. begin
  1942. inherited ppuwrite(ppufile);
  1943. ppufile.putbyte(byte(defined));
  1944. ppufile.putbyte(byte(is_compiler_var));
  1945. ppufile.putlongint(buflen);
  1946. if buflen > 0 then
  1947. ppufile.putdata(buftext^,buflen);
  1948. ppufile.writeentry(ibmacrosym);
  1949. end;
  1950. function tmacro.GetCopy:tmacro;
  1951. var
  1952. p : tmacro;
  1953. begin
  1954. p:=tmacro.create(realname);
  1955. p.defined:=defined;
  1956. p.is_used:=is_used;
  1957. p.is_compiler_var:=is_compiler_var;
  1958. p.buflen:=buflen;
  1959. if assigned(buftext) then
  1960. begin
  1961. getmem(p.buftext,buflen);
  1962. move(buftext^,p.buftext^,buflen);
  1963. end;
  1964. Result:=p;
  1965. end;
  1966. end.