symsym.pas 81 KB

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