symsym.pas 76 KB

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