symsym.pas 107 KB

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