2
0

symsym.pas 107 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221
  1. {
  2. Copyright (c) 1998-2002 by Florian Klaempfl, Pierre Muller
  3. Implementation for the symbols types of the symtable
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. }
  17. unit symsym;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. { common }
  22. cutils,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. inherited destroy;
  666. end;
  667. procedure tstoredsym.register_sym;
  668. var
  669. tmod : tmodule;
  670. begin
  671. if registered then
  672. exit;
  673. if assigned(owner) then
  674. begin
  675. tmod:=find_module_from_symtable(owner);
  676. if assigned(tmod) and assigned(current_module) and (tmod<>current_module) then
  677. begin
  678. comment(v_error,'Symbol '+realname+' from module '+tmod.mainsource+' registered with current module '+current_module.mainsource);
  679. end;
  680. if not assigned(tmod) then
  681. tmod:=current_module;
  682. end
  683. else
  684. tmod:=current_module;
  685. { Register in current_module }
  686. if assigned(tmod) then
  687. begin
  688. tmod.symlist.Add(self);
  689. SymId:=tmod.symlist.Count-1;
  690. end
  691. else
  692. SymId:=symid_registered_nost;
  693. end;
  694. {****************************************************************************
  695. TLABELSYM
  696. ****************************************************************************}
  697. constructor tlabelsym.create(const n : TSymStr);
  698. begin
  699. inherited create(labelsym,n);
  700. used:=false;
  701. defined:=false;
  702. nonlocal:=false;
  703. code:=nil;
  704. end;
  705. constructor tlabelsym.ppuload(ppufile:tcompilerppufile);
  706. begin
  707. inherited ppuload(labelsym,ppufile);
  708. code:=nil;
  709. used:=false;
  710. nonlocal:=false;
  711. defined:=true;
  712. ppuload_platform(ppufile);
  713. end;
  714. procedure tlabelsym.ppuwrite(ppufile:tcompilerppufile);
  715. begin
  716. if owner.symtabletype=globalsymtable then
  717. Message(sym_e_ill_label_decl)
  718. else
  719. begin
  720. inherited ppuwrite(ppufile);
  721. writeentry(ppufile,iblabelsym);
  722. end;
  723. end;
  724. function tlabelsym.mangledname:TSymStr;
  725. begin
  726. if (asmblocklabel=nil) then
  727. begin
  728. if nonlocal then
  729. current_asmdata.getglobaljumplabel(asmblocklabel)
  730. else
  731. current_asmdata.getjumplabel(asmblocklabel);
  732. end;
  733. result:=asmblocklabel.name;
  734. end;
  735. {****************************************************************************
  736. TUNITSYM
  737. ****************************************************************************}
  738. constructor tunitsym.create(const n : TSymStr;amodule : tobject);
  739. begin
  740. inherited create(unitsym,n);
  741. module:=amodule;
  742. end;
  743. constructor tunitsym.ppuload(ppufile:tcompilerppufile);
  744. begin
  745. inherited ppuload(unitsym,ppufile);
  746. module:=nil;
  747. ppuload_platform(ppufile);
  748. end;
  749. destructor tunitsym.destroy;
  750. begin
  751. inherited destroy;
  752. end;
  753. procedure tunitsym.ppuwrite(ppufile:tcompilerppufile);
  754. begin
  755. inherited ppuwrite(ppufile);
  756. writeentry(ppufile,ibunitsym);
  757. end;
  758. {****************************************************************************
  759. TPROGRAMPARASYM
  760. ****************************************************************************}
  761. constructor tprogramparasym.create(const n : TSymStr; i : dword);
  762. begin
  763. inherited create(programparasym,n);
  764. isoindex:=i;
  765. end;
  766. constructor tprogramparasym.ppuload(ppufile : tcompilerppufile);
  767. begin
  768. { program parameter syms (iso pascal style) might be never written to a ppu }
  769. internalerror(2015050102);
  770. end;
  771. destructor tprogramparasym.destroy;
  772. begin
  773. inherited destroy;
  774. end;
  775. procedure tprogramparasym.ppuwrite(ppufile : tcompilerppufile);
  776. begin
  777. { program parameter syms (iso pascal style) might be never written to a ppu }
  778. internalerror(2015050101);
  779. end;
  780. {****************************************************************************
  781. TNAMESPACESYM
  782. ****************************************************************************}
  783. constructor tnamespacesym.create(const n : TSymStr);
  784. begin
  785. inherited create(namespacesym,n);
  786. unitsym:=nil;
  787. unitsymderef.reset;
  788. end;
  789. constructor tnamespacesym.ppuload(ppufile:tcompilerppufile);
  790. begin
  791. inherited ppuload(namespacesym,ppufile);
  792. ppufile.getderef(unitsymderef);
  793. ppuload_platform(ppufile);
  794. end;
  795. procedure tnamespacesym.ppuwrite(ppufile:tcompilerppufile);
  796. begin
  797. inherited ppuwrite(ppufile);
  798. ppufile.putderef(unitsymderef);
  799. writeentry(ppufile,ibnamespacesym);
  800. end;
  801. procedure tnamespacesym.buildderef;
  802. begin
  803. inherited buildderef;
  804. unitsymderef.build(unitsym);
  805. end;
  806. procedure tnamespacesym.deref;
  807. begin
  808. inherited deref;
  809. unitsym:=tsym(unitsymderef.resolve);
  810. end;
  811. {****************************************************************************
  812. TPROCSYM
  813. ****************************************************************************}
  814. constructor tprocsym.create(const n : TSymStr);
  815. var
  816. i: longint;
  817. begin
  818. if not(ts_lowercase_proc_start in current_settings.targetswitches) or
  819. (n='') then
  820. inherited create(procsym,n)
  821. else
  822. begin
  823. { YToX -> yToX
  824. RC64Encode -> rc64Encode
  825. Test -> test
  826. }
  827. i:=2;
  828. while i<=length(n) do
  829. begin
  830. if not(n[i] in ['A'..'Z']) then
  831. begin
  832. if (i>2) and
  833. (n[i] in ['a'..'z']) then
  834. dec(i);
  835. break;
  836. end;
  837. inc(i);
  838. end;
  839. inherited create(procsym,lower(copy(n,1,i-1))+copy(n,i,length(n)));
  840. end;
  841. FProcdefList:=TFPObjectList.Create(false);
  842. FProcdefderefList:=nil;
  843. { the tprocdef have their own symoptions, make the procsym
  844. always visible }
  845. visibility:=vis_public;
  846. end;
  847. constructor tprocsym.ppuload(ppufile:tcompilerppufile);
  848. var
  849. symderef,
  850. pdderef : tderef;
  851. i,
  852. symcnt,
  853. pdcnt : longint;
  854. begin
  855. inherited ppuload(procsym,ppufile);
  856. FProcdefList:=TFPObjectList.Create(false);
  857. FProcdefDerefList:=TFPList.Create;
  858. pdcnt:=ppufile.getword;
  859. for i:=1 to pdcnt do
  860. begin
  861. ppufile.getderef(pdderef);
  862. FProcdefDerefList.Add(Pointer(PtrInt(pdderef.dataidx)));
  863. end;
  864. if sp_generic_dummy in symoptions then
  865. begin
  866. fgenprocsymovlds:=tfpobjectlist.create(false);
  867. fgenprocsymovldsderefs:=tfplist.create;
  868. symcnt:=ppufile.getword;
  869. for i:=1 to symcnt do
  870. begin
  871. ppufile.getderef(symderef);
  872. fgenprocsymovldsderefs.add(pointer(ptrint(symderef.dataidx)));
  873. end;
  874. end;
  875. ppuload_platform(ppufile);
  876. end;
  877. destructor tprocsym.destroy;
  878. begin
  879. FProcdefList.Free;
  880. if assigned(FProcdefDerefList) then
  881. FProcdefDerefList.Free;
  882. fgenprocsymovlds.free;
  883. fgenprocsymovldsderefs.free;
  884. inherited destroy;
  885. end;
  886. procedure tprocsym.ppuwrite(ppufile:tcompilerppufile);
  887. var
  888. i : longint;
  889. d : tderef;
  890. begin
  891. inherited ppuwrite(ppufile);
  892. if fprocdefdereflist=nil then
  893. internalerror(2013121801);
  894. ppufile.putword(FProcdefDerefList.Count);
  895. for i:=0 to FProcdefDerefList.Count-1 do
  896. begin
  897. d.dataidx:=PtrInt(FProcdefDerefList[i]);
  898. ppufile.putderef(d);
  899. end;
  900. if sp_generic_dummy in symoptions then
  901. begin
  902. if not assigned(fgenprocsymovldsderefs) then
  903. internalerror(2021010301);
  904. ppufile.putword(fgenprocsymovldsderefs.count);
  905. for i:=0 to fgenprocsymovldsderefs.count-1 do
  906. begin
  907. d.dataidx:=ptrint(fgenprocsymovldsderefs[i]);
  908. ppufile.putderef(d);
  909. end;
  910. end;
  911. writeentry(ppufile,ibprocsym);
  912. end;
  913. procedure tprocsym.write_parameter_lists(skipdef:tprocdef);
  914. var
  915. i : longint;
  916. pd : tprocdef;
  917. begin
  918. for i:=0 to ProcdefList.Count-1 do
  919. begin
  920. pd:=tprocdef(ProcdefList[i]);
  921. if pd<>skipdef then
  922. MessagePos1(pd.fileinfo,sym_e_param_list,pd.fullprocname(false));
  923. end;
  924. end;
  925. procedure tprocsym.check_forward;
  926. var
  927. i : longint;
  928. pd : tprocdef;
  929. begin
  930. for i:=0 to ProcdefList.Count-1 do
  931. begin
  932. pd:=tprocdef(ProcdefList[i]);
  933. if (pd.owner=owner) and (pd.forwarddef) then
  934. begin
  935. { For mode macpas. Make implicit externals (procedures declared in the interface
  936. section which do not have a counterpart in the implementation)
  937. to be an imported procedure }
  938. if (m_mac in current_settings.modeswitches) and
  939. (pd.interfacedef) then
  940. begin
  941. pd.setmangledname(target_info.CPrefix+tprocdef(pd).procsym.realname);
  942. if (not current_module.interface_only) then
  943. MessagePos1(pd.fileinfo,sym_w_forward_not_resolved,pd.fullprocname(false));
  944. end
  945. else
  946. begin
  947. MessagePos1(pd.fileinfo,sym_e_forward_not_resolved,pd.fullprocname(false));
  948. end;
  949. { Turn further error messages off }
  950. pd.forwarddef:=false;
  951. end;
  952. end;
  953. end;
  954. procedure tprocsym.buildderef;
  955. var
  956. i : longint;
  957. pd : tprocdef;
  958. d : tderef;
  959. sym : tprocsym;
  960. begin
  961. inherited;
  962. if not assigned(FProcdefDerefList) then
  963. FProcdefDerefList:=TFPList.Create
  964. else
  965. FProcdefDerefList.Clear;
  966. for i:=0 to ProcdefList.Count-1 do
  967. begin
  968. pd:=tprocdef(ProcdefList[i]);
  969. { only write the proc definitions that belong
  970. to this procsym and are in the global symtable }
  971. if pd.owner=owner then
  972. begin
  973. d.build(pd);
  974. FProcdefDerefList.Add(Pointer(PtrInt(d.dataidx)));
  975. end;
  976. end;
  977. if sp_generic_dummy in symoptions then
  978. begin
  979. if not assigned(fgenprocsymovldsderefs) then
  980. fgenprocsymovldsderefs:=tfplist.create
  981. else
  982. fgenprocsymovldsderefs.clear;
  983. { this might happen for procsyms in classes that override symbols
  984. in a parent class that generic overloads }
  985. if assigned(fgenprocsymovlds) then
  986. begin
  987. fgenprocsymovldsderefs.capacity:=fgenprocsymovldsderefs.count+fgenprocsymovlds.count;
  988. for i:=0 to fgenprocsymovlds.count-1 do
  989. begin
  990. sym:=tprocsym(fgenprocsymovlds[i]);
  991. d.build(sym);
  992. fgenprocsymovldsderefs.add(pointer(ptrint(d.dataidx)));
  993. end;
  994. end;
  995. end;
  996. end;
  997. procedure tprocsym.deref;
  998. var
  999. i : longint;
  1000. pd : tprocdef;
  1001. d : tderef;
  1002. sym : tsym;
  1003. begin
  1004. { Clear all procdefs }
  1005. ProcdefList.Clear;
  1006. if not assigned(FProcdefDerefList) then
  1007. internalerror(200611031);
  1008. ProcdefList.capacity:=FProcdefDerefList.count;
  1009. for i:=0 to FProcdefDerefList.Count-1 do
  1010. begin
  1011. d.dataidx:=PtrInt(FProcdefDerefList[i]);
  1012. pd:=tprocdef(d.resolve);
  1013. ProcdefList.Add(pd);
  1014. end;
  1015. if sp_generic_dummy in symoptions then
  1016. begin
  1017. {if not assigned(fgenprocsymovlds) then
  1018. internalerror(2021010603);}
  1019. if not assigned(fgenprocsymovldsderefs) then
  1020. internalerror(2021010302);
  1021. if assigned(fgenprocsymovlds) then
  1022. begin
  1023. fgenprocsymovlds.clear;
  1024. fgenprocsymovlds.capacity:=fgenprocsymovldsderefs.count;
  1025. for i:= 0 to fgenprocsymovldsderefs.count-1 do
  1026. begin
  1027. d.dataidx:=ptrint(fgenprocsymovldsderefs[i]);
  1028. sym:=tprocsym(d.resolve);
  1029. fgenprocsymovlds.add(sym);
  1030. end;
  1031. end;
  1032. end;
  1033. end;
  1034. function Tprocsym.Find_procdef_bytype(pt:Tproctypeoption):Tprocdef;
  1035. var
  1036. i : longint;
  1037. pd : tprocdef;
  1038. begin
  1039. result:=nil;
  1040. for i:=0 to ProcdefList.Count-1 do
  1041. begin
  1042. pd:=tprocdef(ProcdefList[i]);
  1043. if pd.proctypeoption=pt then
  1044. begin
  1045. result:=pd;
  1046. exit;
  1047. end;
  1048. end;
  1049. end;
  1050. function tprocsym.find_bytype_parameterless(pt: Tproctypeoption): Tprocdef;
  1051. var
  1052. i,j : longint;
  1053. pd : tprocdef;
  1054. found : boolean;
  1055. begin
  1056. result:=nil;
  1057. for i:=0 to ProcdefList.Count-1 do
  1058. begin
  1059. pd:=tprocdef(ProcdefList[i]);
  1060. if (pd.proctypeoption=pt) then
  1061. begin
  1062. found:=true;
  1063. for j:=0 to pd.paras.count-1 do
  1064. begin
  1065. if not(vo_is_hidden_para in tparavarsym(pd.paras[j]).varoptions) then
  1066. begin
  1067. found:=false;
  1068. break;
  1069. end;
  1070. end;
  1071. if found then
  1072. begin
  1073. result:=pd;
  1074. exit;
  1075. end;
  1076. end;
  1077. end;
  1078. end;
  1079. function check_procdef_paras(pd:tprocdef;para:TFPObjectList;retdef:tdef;
  1080. cpoptions:tcompare_paras_options): tprocdef;
  1081. var
  1082. eq: tequaltype;
  1083. begin
  1084. result:=nil;
  1085. if assigned(retdef) then
  1086. eq:=compare_defs(retdef,pd.returndef,nothingn)
  1087. else
  1088. eq:=te_equal;
  1089. if (eq>=te_equal) or
  1090. ((cpo_allowconvert in cpoptions) and (eq>te_incompatible)) then
  1091. begin
  1092. eq:=compare_paras(para,pd.paras,cp_value_equal_const,cpoptions);
  1093. if (eq>=te_equal) or
  1094. ((cpo_allowconvert in cpoptions) and (eq>te_incompatible)) then
  1095. begin
  1096. result:=pd;
  1097. exit;
  1098. end;
  1099. end;
  1100. end;
  1101. function Tprocsym.Find_procdef_bypara(para:TFPObjectList;retdef:tdef;
  1102. cpoptions:tcompare_paras_options):Tprocdef;
  1103. var
  1104. i : longint;
  1105. pd : tprocdef;
  1106. begin
  1107. result:=nil;
  1108. for i:=0 to ProcdefList.Count-1 do
  1109. begin
  1110. pd:=tprocdef(ProcdefList[i]);
  1111. result:=check_procdef_paras(pd,para,retdef,cpoptions);
  1112. if assigned(result) then
  1113. exit;
  1114. end;
  1115. end;
  1116. function Tprocsym.find_procdef_bytype_and_para(pt:Tproctypeoption;
  1117. para:TFPObjectList;retdef:tdef;cpoptions:tcompare_paras_options):Tprocdef;
  1118. var
  1119. i : longint;
  1120. pd : tprocdef;
  1121. begin
  1122. result:=nil;
  1123. for i:=0 to ProcdefList.Count-1 do
  1124. begin
  1125. pd:=tprocdef(ProcdefList[i]);
  1126. if pd.proctypeoption=pt then
  1127. begin
  1128. result:=check_procdef_paras(pd,para,retdef,cpoptions);
  1129. if assigned(result) then
  1130. exit;
  1131. end;
  1132. end;
  1133. end;
  1134. function tprocsym.find_procdef_byoptions(ops: tprocoptions): Tprocdef;
  1135. var
  1136. i : longint;
  1137. pd : tprocdef;
  1138. begin
  1139. result:=nil;
  1140. for i:=0 to ProcdefList.Count-1 do
  1141. begin
  1142. pd:=tprocdef(ProcdefList[i]);
  1143. if ops * pd.procoptions = ops then
  1144. begin
  1145. result:=pd;
  1146. exit;
  1147. end;
  1148. end;
  1149. end;
  1150. function Tprocsym.find_procdef_with_comparer(comparer:tprocdefcomparer;arg:tobject):tprocdef;
  1151. var
  1152. i : longint;
  1153. bestpd,
  1154. pd : tprocdef;
  1155. eq,besteq : tequaltype;
  1156. sym: tsym;
  1157. ps: tprocsym;
  1158. begin
  1159. { This function will return the pprocdef of pprocsym that
  1160. is the best match for procvardef. When there are multiple
  1161. matches it returns nil.}
  1162. result:=nil;
  1163. bestpd:=nil;
  1164. besteq:=te_incompatible;
  1165. ps:=self;
  1166. repeat
  1167. for i:=0 to ps.ProcdefList.Count-1 do
  1168. begin
  1169. pd:=tprocdef(ps.ProcdefList[i]);
  1170. eq:=comparer(pd,arg);
  1171. if eq>=te_convert_l1 then
  1172. begin
  1173. { multiple procvars with the same equal level }
  1174. if assigned(bestpd) and
  1175. (besteq=eq) then
  1176. exit;
  1177. if eq>besteq then
  1178. begin
  1179. besteq:=eq;
  1180. bestpd:=pd;
  1181. end;
  1182. end;
  1183. end;
  1184. { maybe TODO: also search class helpers? -- this code is similar to
  1185. what happens in htypechk in
  1186. tcallcandidates.collect_overloads_in_struct: keep searching in
  1187. parent types in case the currently found procdef is marked as
  1188. "overload" and we haven't found a proper match yet }
  1189. if assigned(ps.owner.defowner) and
  1190. (ps.owner.defowner.typ=objectdef) and
  1191. assigned(tobjectdef(ps.owner.defowner).childof) and
  1192. (not assigned(bestpd) or
  1193. (po_overload in bestpd.procoptions)) then
  1194. begin
  1195. sym:=tsym(tobjectdef(ps.owner.defowner).childof.symtable.find(ps.name));
  1196. if assigned(sym) and
  1197. (sym.typ=procsym) then
  1198. ps:=tprocsym(sym)
  1199. else
  1200. ps:=nil;
  1201. end
  1202. else
  1203. ps:=nil;
  1204. until (besteq>=te_equal) or
  1205. not assigned(ps);
  1206. result:=bestpd;
  1207. end;
  1208. class function Tprocsym.compare_procvardef(pd:tprocdef;arg:tobject):tequaltype;
  1209. begin
  1210. result:=proc_to_procvar_equal(pd,tprocvardef(arg),false);
  1211. end;
  1212. class function Tprocsym.compare_funcrefdef(pd:tprocdef;arg:tobject):tequaltype;
  1213. begin
  1214. result:=proc_to_funcref_equal(pd,tobjectdef(arg));
  1215. end;
  1216. function Tprocsym.Find_procdef_byprocvardef(d:Tprocvardef):Tprocdef;
  1217. begin
  1218. result:=find_procdef_with_comparer(@compare_procvardef,d);
  1219. end;
  1220. function Tprocsym.Find_procdef_byfuncrefdef(d:tobjectdef):Tprocdef;
  1221. begin
  1222. if not is_invokable(d) then
  1223. internalerror(2022033001);
  1224. result:=find_procdef_with_comparer(@compare_funcrefdef,d);
  1225. end;
  1226. function Tprocsym.Find_procdef_assignment_operator(fromdef,todef:tdef;var besteq:tequaltype;isexplicit:boolean):Tprocdef;
  1227. var
  1228. paraidx, realparamcount,
  1229. i, j : longint;
  1230. bestpd,
  1231. hpd,
  1232. pd : tprocdef;
  1233. convtyp : tconverttype;
  1234. eq : tequaltype;
  1235. shortstringcount : longint;
  1236. checkshortstring,
  1237. isgenshortstring : boolean;
  1238. begin
  1239. { This function will return the pprocdef of pprocsym that
  1240. is the best match for fromdef and todef. }
  1241. result:=nil;
  1242. bestpd:=nil;
  1243. besteq:=te_incompatible;
  1244. { special handling for assignment operators overloads to shortstring:
  1245. for implicit assignment we pick the ShortString one if available and
  1246. only pick one with specific length if it is the *only* one }
  1247. shortstringcount:=0;
  1248. checkshortstring:=not isexplicit and
  1249. is_shortstring(todef) and
  1250. (tstringdef(todef).len<>255);
  1251. for i:=0 to ProcdefList.Count-1 do
  1252. begin
  1253. pd:=tprocdef(ProcdefList[i]);
  1254. if (pd.owner.symtabletype=staticsymtable) and not pd.owner.iscurrentunit then
  1255. continue;
  1256. if (equal_defs(todef,pd.returndef) or
  1257. { shortstrings of different lengths are ok as result }
  1258. (not isexplicit and is_shortstring(todef) and is_shortstring(pd.returndef))) and
  1259. { the result type must be always really equal and not an alias,
  1260. if you mess with this code, check tw4093 }
  1261. ((todef=pd.returndef) or
  1262. (
  1263. not(df_unique in todef.defoptions) and
  1264. not(df_unique in pd.returndef.defoptions)
  1265. )
  1266. ) then
  1267. begin
  1268. paraidx:=0;
  1269. { ignore vs_hidden parameters }
  1270. while (paraidx<pd.paras.count) and
  1271. assigned(pd.paras[paraidx]) and
  1272. (vo_is_hidden_para in tparavarsym(pd.paras[paraidx]).varoptions) do
  1273. inc(paraidx);
  1274. realparamcount:=0;
  1275. for j := 0 to pd.paras.Count-1 do
  1276. if assigned(pd.paras[j]) and not (vo_is_hidden_para in tparavarsym(pd.paras[j]).varoptions) then
  1277. inc(realparamcount);
  1278. if (paraidx<pd.paras.count) and
  1279. assigned(pd.paras[paraidx]) and
  1280. (realparamcount = 1) then
  1281. begin
  1282. eq:=compare_defs_ext(fromdef,tparavarsym(pd.paras[paraidx]).vardef,nothingn,convtyp,hpd,[]);
  1283. { alias? if yes, only l1 choice,
  1284. if you mess with this code, check tw4093 }
  1285. if (eq=te_exact) and
  1286. (fromdef<>tparavarsym(pd.paras[paraidx]).vardef) and
  1287. ((df_unique in fromdef.defoptions) or
  1288. (df_unique in tparavarsym(pd.paras[paraidx]).vardef.defoptions)) then
  1289. eq:=te_convert_l1;
  1290. isgenshortstring:=false;
  1291. if checkshortstring and is_shortstring(pd.returndef) then
  1292. if tstringdef(pd.returndef).len<>255 then
  1293. inc(shortstringcount)
  1294. else
  1295. isgenshortstring:=true;
  1296. if (eq=te_exact) and (not checkshortstring or isgenshortstring) then
  1297. begin
  1298. besteq:=eq;
  1299. result:=pd;
  1300. exit;
  1301. end;
  1302. if eq>besteq then
  1303. begin
  1304. bestpd:=pd;
  1305. besteq:=eq;
  1306. end;
  1307. end;
  1308. end;
  1309. end;
  1310. if checkshortstring and (shortstringcount>1) then
  1311. begin
  1312. besteq:=te_incompatible;
  1313. bestpd:=nil;
  1314. end;
  1315. result:=bestpd;
  1316. end;
  1317. function Tprocsym.find_procdef_enumerator_operator(fromdef,todef:tdef;var besteq:tequaltype):Tprocdef;
  1318. var
  1319. paraidx, realparamcount,
  1320. i, j : longint;
  1321. bestpd,
  1322. hpd,
  1323. pd : tprocdef;
  1324. current : tpropertysym;
  1325. convtyp : tconverttype;
  1326. eq : tequaltype;
  1327. begin
  1328. { This function will return the pprocdef of pprocsym that
  1329. is the best match for fromdef and todef. }
  1330. result:=nil;
  1331. bestpd:=nil;
  1332. besteq:=te_incompatible;
  1333. for i:=0 to ProcdefList.Count-1 do
  1334. begin
  1335. pd:=tprocdef(ProcdefList[i]);
  1336. if (pd.owner.symtabletype=staticsymtable) and not pd.owner.iscurrentunit then
  1337. continue;
  1338. if not (is_class_or_interface_or_object(pd.returndef) or is_record(pd.returndef)) then
  1339. continue;
  1340. current := tpropertysym(tabstractrecorddef(pd.returndef).search_enumerator_current);
  1341. if (current = nil) then
  1342. continue;
  1343. // compare current result def with the todef
  1344. if (equal_defs(todef, current.propdef) or
  1345. { shortstrings of different lengths are ok as result }
  1346. (is_shortstring(todef) and is_shortstring(current.propdef))) and
  1347. { the result type must be always really equal and not an alias,
  1348. if you mess with this code, check tw4093 }
  1349. ((todef=current.propdef) or
  1350. (
  1351. not(df_unique in todef.defoptions) and
  1352. not(df_unique in current.propdef.defoptions)
  1353. )
  1354. ) then
  1355. begin
  1356. paraidx:=0;
  1357. { ignore vs_hidden parameters }
  1358. while (paraidx<pd.paras.count) and
  1359. assigned(pd.paras[paraidx]) and
  1360. (vo_is_hidden_para in tparavarsym(pd.paras[paraidx]).varoptions) do
  1361. inc(paraidx);
  1362. realparamcount:=0;
  1363. for j := 0 to pd.paras.Count-1 do
  1364. if assigned(pd.paras[j]) and not (vo_is_hidden_para in tparavarsym(pd.paras[j]).varoptions) then
  1365. inc(realparamcount);
  1366. if (paraidx<pd.paras.count) and
  1367. assigned(pd.paras[paraidx]) and
  1368. (realparamcount = 1) then
  1369. begin
  1370. eq:=compare_defs_ext(fromdef,tparavarsym(pd.paras[paraidx]).vardef,nothingn,convtyp,hpd,[]);
  1371. { alias? if yes, only l1 choice,
  1372. if you mess with this code, check tw4093 }
  1373. if (eq=te_exact) and
  1374. (fromdef<>tparavarsym(pd.paras[paraidx]).vardef) and
  1375. ((df_unique in fromdef.defoptions) or
  1376. (df_unique in tparavarsym(pd.paras[paraidx]).vardef.defoptions)) then
  1377. eq:=te_convert_l1;
  1378. if eq=te_exact then
  1379. begin
  1380. besteq:=eq;
  1381. result:=pd;
  1382. exit;
  1383. end;
  1384. if eq>besteq then
  1385. begin
  1386. bestpd:=pd;
  1387. besteq:=eq;
  1388. end;
  1389. end;
  1390. end;
  1391. end;
  1392. result:=bestpd;
  1393. end;
  1394. procedure tprocsym.add_generic_overload(sym:tprocsym);
  1395. var
  1396. i : longint;
  1397. begin
  1398. if not (sp_generic_dummy in symoptions) then
  1399. internalerror(2021010601);
  1400. if not assigned(fgenprocsymovlds) then
  1401. fgenprocsymovlds:=tfpobjectlist.create(false);
  1402. for i:=0 to genprocsymovlds.count-1 do
  1403. if tprocsym(genprocsymovlds[i])=sym then
  1404. exit;
  1405. genprocsymovlds.add(sym);
  1406. end;
  1407. function tprocsym.could_be_implicitly_specialized:boolean;
  1408. begin
  1409. result:=(m_implicit_function_specialization in current_settings.modeswitches) and
  1410. (sp_generic_dummy in symoptions) and
  1411. assigned(genprocsymovlds);
  1412. end;
  1413. {****************************************************************************
  1414. TERRORSYM
  1415. ****************************************************************************}
  1416. constructor terrorsym.create;
  1417. begin
  1418. inherited create(errorsym,'');
  1419. end;
  1420. procedure terrorsym.register_sym;
  1421. begin
  1422. { these should never be written to a ppu file, since they don't
  1423. derive from tstoredsym }
  1424. Internalerror(2015101801);
  1425. end;
  1426. {****************************************************************************
  1427. TPROPERTYSYM
  1428. ****************************************************************************}
  1429. procedure tpropertysym.finalize_getter_or_setter_for_sym(getset: tpropaccesslisttypes; sym: tsym; fielddef: tdef; accessordef: tprocdef);
  1430. begin
  1431. { do nothing by default }
  1432. end;
  1433. constructor tpropertysym.create(const n : TSymStr);
  1434. var
  1435. pap : tpropaccesslisttypes;
  1436. begin
  1437. inherited create(propertysym,n);
  1438. propoptions:=[];
  1439. index:=0;
  1440. default:=0;
  1441. propdef:=nil;
  1442. propdefderef.reset;
  1443. indexdef:=nil;
  1444. indexdefderef.reset;
  1445. parast:=nil;
  1446. for pap:=low(tpropaccesslisttypes) to high(tpropaccesslisttypes) do
  1447. propaccesslist[pap]:=tpropaccesslist.create;
  1448. end;
  1449. constructor tpropertysym.ppuload(ppufile:tcompilerppufile);
  1450. var
  1451. pap : tpropaccesslisttypes;
  1452. begin
  1453. inherited ppuload(propertysym,ppufile);
  1454. ppufile.getset(tppuset2(propoptions));
  1455. if ppo_overrides in propoptions then
  1456. ppufile.getderef(overriddenpropsymderef);
  1457. ppufile.getderef(propdefderef);
  1458. index:=ppufile.getlongint;
  1459. default:=ppufile.getlongint;
  1460. ppufile.getderef(indexdefderef);
  1461. for pap:=low(tpropaccesslisttypes) to high(tpropaccesslisttypes) do
  1462. propaccesslist[pap]:=ppufile.getpropaccesslist;
  1463. ppuload_platform(ppufile);
  1464. if [ppo_hasparameters,ppo_overrides]*propoptions=[ppo_hasparameters] then
  1465. begin
  1466. parast:=tparasymtable.create(nil,0);
  1467. tparasymtable(parast).ppuload(ppufile);
  1468. end
  1469. else
  1470. parast:=nil;
  1471. end;
  1472. destructor tpropertysym.destroy;
  1473. var
  1474. pap : tpropaccesslisttypes;
  1475. begin
  1476. for pap:=low(tpropaccesslisttypes) to high(tpropaccesslisttypes) do
  1477. propaccesslist[pap].free;
  1478. parast.free;
  1479. inherited destroy;
  1480. end;
  1481. procedure tpropertysym.buildderef;
  1482. var
  1483. pap : tpropaccesslisttypes;
  1484. begin
  1485. inherited;
  1486. propdefderef.build(propdef);
  1487. indexdefderef.build(indexdef);
  1488. for pap:=low(tpropaccesslisttypes) to high(tpropaccesslisttypes) do
  1489. propaccesslist[pap].buildderef;
  1490. if ppo_overrides in propoptions then
  1491. overriddenpropsymderef.build(overriddenpropsym)
  1492. else
  1493. if ppo_hasparameters in propoptions then
  1494. tparasymtable(parast).buildderef;
  1495. end;
  1496. procedure tpropertysym.deref;
  1497. var
  1498. pap : tpropaccesslisttypes;
  1499. begin
  1500. indexdef:=tdef(indexdefderef.resolve);
  1501. propdef:=tdef(propdefderef.resolve);
  1502. for pap:=low(tpropaccesslisttypes) to high(tpropaccesslisttypes) do
  1503. propaccesslist[pap].resolve;
  1504. if ppo_overrides in propoptions then
  1505. begin
  1506. overriddenpropsym:=tpropertysym(overriddenpropsymderef.resolve);
  1507. if ppo_hasparameters in propoptions then
  1508. parast:=overriddenpropsym.parast.getcopy;
  1509. end
  1510. else
  1511. if ppo_hasparameters in propoptions then
  1512. tparasymtable(parast).deref(false)
  1513. end;
  1514. function tpropertysym.getpropaccesslist(pap:tpropaccesslisttypes;out plist:tpropaccesslist):boolean;
  1515. var
  1516. hpropsym : tpropertysym;
  1517. begin
  1518. result:=false;
  1519. { find property in the overridden list }
  1520. hpropsym:=self;
  1521. repeat
  1522. plist:=hpropsym.propaccesslist[pap];
  1523. if not plist.empty then
  1524. begin
  1525. result:=true;
  1526. exit;
  1527. end;
  1528. hpropsym:=hpropsym.overriddenpropsym;
  1529. until not assigned(hpropsym);
  1530. end;
  1531. procedure tpropertysym.add_accessor_parameters(readprocdef, writeprocdef: tprocdef);
  1532. var
  1533. i: integer;
  1534. orig, hparavs: tparavarsym;
  1535. begin
  1536. for i := 0 to parast.SymList.Count - 1 do
  1537. begin
  1538. orig:=tparavarsym(parast.SymList[i]);
  1539. if assigned(readprocdef) then
  1540. begin
  1541. hparavs:=cparavarsym.create(orig.RealName,orig.paranr,orig.varspez,orig.vardef,[]);
  1542. readprocdef.parast.insertsym(hparavs);
  1543. end;
  1544. if assigned(writeprocdef) then
  1545. begin
  1546. hparavs:=cparavarsym.create(orig.RealName,orig.paranr,orig.varspez,orig.vardef,[]);
  1547. writeprocdef.parast.insertsym(hparavs);
  1548. end;
  1549. end;
  1550. end;
  1551. procedure tpropertysym.add_index_parameter(var paranr: word; readprocdef, writeprocdef: tprocdef);
  1552. var
  1553. hparavs: tparavarsym;
  1554. begin
  1555. inc(paranr);
  1556. if assigned(readprocdef) then
  1557. begin
  1558. hparavs:=cparavarsym.create('$index',10*paranr,vs_value,indexdef,[]);
  1559. readprocdef.parast.insertsym(hparavs);
  1560. end;
  1561. if assigned(writeprocdef) then
  1562. begin
  1563. hparavs:=cparavarsym.create('$index',10*paranr,vs_value,indexdef,[]);
  1564. writeprocdef.parast.insertsym(hparavs);
  1565. end;
  1566. end;
  1567. procedure tpropertysym.add_getter_or_setter_for_sym(getset: tpropaccesslisttypes; sym: tsym; fielddef: tdef; accessordef: tprocdef);
  1568. var
  1569. cpo: tcompare_paras_options;
  1570. begin
  1571. case sym.typ of
  1572. procsym :
  1573. begin
  1574. { search procdefs matching accessordef }
  1575. { we ignore hidden stuff here because the property access symbol might have
  1576. non default calling conventions which might change the hidden stuff;
  1577. see tw3216.pp (FK) }
  1578. cpo:=[cpo_allowdefaults,cpo_ignorehidden];
  1579. { allow var-parameters for setters in case of VARPROPSETTER+ }
  1580. if (getset=palt_write) and
  1581. (cs_varpropsetter in current_settings.localswitches) then
  1582. include(cpo,cpo_ignorevarspez);
  1583. propaccesslist[getset].procdef:=tprocsym(sym).find_procdef_bypara(accessordef.paras,accessordef.returndef,cpo);
  1584. if not assigned(propaccesslist[getset].procdef) or
  1585. { because of cpo_ignorehidden we need to compare if it is a static class method and we have a class property }
  1586. ((sp_static in symoptions)<>tprocdef(propaccesslist[getset].procdef).no_self_node) then
  1587. Message(parser_e_ill_property_access_sym)
  1588. else
  1589. finalize_getter_or_setter_for_sym(getset,sym,fielddef,accessordef);
  1590. end;
  1591. fieldvarsym :
  1592. begin
  1593. if not assigned(fielddef) then
  1594. internalerror(200310071);
  1595. if compare_defs(fielddef,propdef,nothingn)>=te_equal then
  1596. begin
  1597. { property parameters are allowed if this is
  1598. an indexed property, because the index is then
  1599. the parameter.
  1600. Note: In the help of Kylix it is written
  1601. that it isn't allowed, but the compiler accepts it (PFV) }
  1602. if (ppo_hasparameters in propoptions) or
  1603. ((sp_static in symoptions) <> (sp_static in sym.symoptions)) then
  1604. Message(parser_e_ill_property_access_sym)
  1605. else
  1606. finalize_getter_or_setter_for_sym(getset,sym,fielddef,accessordef);
  1607. end
  1608. else
  1609. IncompatibleTypes(fielddef,propdef);
  1610. end;
  1611. else
  1612. Message(parser_e_ill_property_access_sym);
  1613. end;
  1614. end;
  1615. procedure tpropertysym.register_override(overriddenprop: tpropertysym);
  1616. begin
  1617. overriddenpropsym:=tpropertysym(overriddenprop);
  1618. include(propoptions,ppo_overrides);
  1619. end;
  1620. procedure tpropertysym.inherit_accessor(getset: tpropaccesslisttypes);
  1621. begin
  1622. { nothing to do by default }
  1623. end;
  1624. procedure tpropertysym.makeduplicate(p: tpropertysym; readprocdef, writeprocdef: tprocdef; out paranr: word);
  1625. begin
  1626. { inherit all type related entries }
  1627. p.indexdef:=indexdef;
  1628. p.propdef:=propdef;
  1629. p.index:=index;
  1630. p.default:=default;
  1631. p.propoptions:=propoptions;
  1632. paranr:=0;
  1633. if ppo_hasparameters in propoptions then
  1634. begin
  1635. p.parast:=parast.getcopy;
  1636. p.add_accessor_parameters(readprocdef,writeprocdef);
  1637. paranr:=p.parast.SymList.Count;
  1638. end;
  1639. if ppo_indexed in p.propoptions then
  1640. p.add_index_parameter(paranr,readprocdef,writeprocdef);
  1641. end;
  1642. function tpropertysym.getsize : asizeint;
  1643. begin
  1644. getsize:=0;
  1645. end;
  1646. procedure tpropertysym.ppuwrite(ppufile:tcompilerppufile);
  1647. var
  1648. pap : tpropaccesslisttypes;
  1649. begin
  1650. inherited ppuwrite(ppufile);
  1651. ppufile.putset(tppuset2(propoptions));
  1652. if ppo_overrides in propoptions then
  1653. ppufile.putderef(overriddenpropsymderef);
  1654. ppufile.putderef(propdefderef);
  1655. ppufile.putlongint(index);
  1656. ppufile.putlongint(default);
  1657. ppufile.putderef(indexdefderef);
  1658. for pap:=low(tpropaccesslisttypes) to high(tpropaccesslisttypes) do
  1659. ppufile.putpropaccesslist(propaccesslist[pap]);
  1660. writeentry(ppufile,ibpropertysym);
  1661. if [ppo_hasparameters,ppo_overrides]*propoptions=[ppo_hasparameters] then
  1662. tparasymtable(parast).ppuwrite(ppufile);
  1663. end;
  1664. {****************************************************************************
  1665. TABSTRACTVARSYM
  1666. ****************************************************************************}
  1667. constructor tabstractvarsym.create(st:tsymtyp;const n : TSymStr;vsp:tvarspez;def:tdef;vopts:tvaroptions);
  1668. begin
  1669. inherited create(st,n);
  1670. vardef:=def;
  1671. vardefderef.reset;
  1672. varspez:=vsp;
  1673. varstate:=vs_declared;
  1674. varoptions:=vopts;
  1675. end;
  1676. constructor tabstractvarsym.ppuload(st:tsymtyp;ppufile:tcompilerppufile);
  1677. begin
  1678. inherited ppuload(st,ppufile);
  1679. varstate:=vs_readwritten;
  1680. varspez:=tvarspez(ppufile.getbyte);
  1681. varregable:=tvarregable(ppufile.getbyte);
  1682. ppufile.getset(tppuset1(varsymaccess));
  1683. ppufile.getderef(vardefderef);
  1684. ppufile.getset(tppuset4(varoptions));
  1685. end;
  1686. procedure tabstractvarsym.buildderef;
  1687. begin
  1688. inherited;
  1689. vardefderef.build(vardef);
  1690. end;
  1691. procedure tabstractvarsym.deref;
  1692. begin
  1693. { assigning vardef also updates varregable. We just loaded this }
  1694. { value from a ppu, so it must not be changed (e.g. tw7817a.pp/ }
  1695. { tw7817b.pp: the address is taken of a local variable in an }
  1696. { inlined procedure -> must remain non-regable when inlining) }
  1697. setvardef(tdef(vardefderef.resolve));
  1698. end;
  1699. procedure tabstractvarsym.ppuwrite(ppufile:tcompilerppufile);
  1700. var
  1701. oldintfcrc : boolean;
  1702. begin
  1703. inherited ppuwrite(ppufile);
  1704. ppufile.putbyte(byte(varspez));
  1705. oldintfcrc:=ppufile.do_crc;
  1706. ppufile.do_crc:=false;
  1707. ppufile.putbyte(byte(varregable));
  1708. ppufile.putset(tppuset1(varsymaccess));
  1709. ppufile.do_crc:=oldintfcrc;
  1710. ppufile.putderef(vardefderef);
  1711. ppufile.putset(tppuset4(varoptions));
  1712. end;
  1713. function tabstractvarsym.getsize : asizeint;
  1714. begin
  1715. if assigned(vardef) and
  1716. ((vardef.typ<>arraydef) or
  1717. is_dynamic_array(vardef) or
  1718. (tarraydef(vardef).highrange>=tarraydef(vardef).lowrange)) then
  1719. result:=vardef.size
  1720. else
  1721. result:=0;
  1722. end;
  1723. function tabstractvarsym.getpackedbitsize : longint;
  1724. begin
  1725. { bitpacking is only done for ordinals }
  1726. if not is_ordinal(vardef) then
  1727. internalerror(2006082010);
  1728. result:=vardef.packedbitsize;
  1729. end;
  1730. function tabstractvarsym.is_regvar(refpara: boolean):boolean;
  1731. var
  1732. tempdef : tdef;
  1733. begin
  1734. { Register variables are not allowed in the following cases:
  1735. - regvars are disabled
  1736. - exceptions are used (after an exception is raised the contents of the
  1737. registers is not valid anymore)
  1738. - it has a local copy
  1739. - the value needs to be in memory (i.e. reference counted) }
  1740. result:=(cs_opt_regvar in current_settings.optimizerswitches) and
  1741. not(pi_has_assembler_block in current_procinfo.flags) and
  1742. not(pi_uses_exceptions in current_procinfo.flags) and
  1743. not(pi_has_interproclabel in current_procinfo.flags) and
  1744. ((refpara and
  1745. (varregable <> vr_none)) or
  1746. (not refpara and
  1747. not(varregable in [vr_none,vr_addr])))
  1748. {$if not defined(powerpc) and not defined(powerpc64)}
  1749. and ((vardef.typ <> recorddef) or
  1750. (varregable = vr_addr) or
  1751. tabstractrecordsymtable(tabstractrecorddef(vardef).symtable).has_single_field(tempdef) or
  1752. not(varstate in [vs_written,vs_readwritten]));
  1753. {$endif}
  1754. end;
  1755. procedure tabstractvarsym.setvardef_and_regable(def:tdef);
  1756. begin
  1757. setvardef(def);
  1758. setregable;
  1759. end;
  1760. procedure tabstractvarsym.set_addr_taken(AValue: boolean);
  1761. begin
  1762. if AValue then
  1763. include(varsymaccess, vsa_addr_taken)
  1764. else
  1765. exclude(varsymaccess, vsa_addr_taken);
  1766. end;
  1767. procedure tabstractvarsym.set_different_scope(AValue: boolean);
  1768. begin
  1769. if AValue then
  1770. include(varsymaccess, vsa_different_scope)
  1771. else
  1772. exclude(varsymaccess, vsa_different_scope);
  1773. end;
  1774. procedure tabstractvarsym.setregable;
  1775. begin
  1776. if vo_volatile in varoptions then
  1777. exit;
  1778. { can we load the value into a register ? }
  1779. if not assigned(owner) or
  1780. (owner.symtabletype in [localsymtable, parasymtable]) or
  1781. (
  1782. (owner.symtabletype=staticsymtable) and
  1783. not(cs_create_pic in current_settings.moduleswitches)
  1784. ) then
  1785. begin
  1786. if (tstoreddef(vardef).is_intregable and
  1787. { we could keep all aint*2 records in registers, but this causes
  1788. too much spilling for CPUs with 8-16 registers so keep only
  1789. parameters and function results of this type in register because they are normally
  1790. passed by register anyways
  1791. This can be changed, as soon as we have full ssa (FK) }
  1792. ((typ=paravarsym) or
  1793. (vo_is_funcret in varoptions) or
  1794. (tstoreddef(vardef).typ<>recorddef) or
  1795. (tstoreddef(vardef).size<=sizeof(aint)))) or
  1796. { const parameters can be put into registers if the def fits into a register }
  1797. (tstoreddef(vardef).is_const_intregable and
  1798. (typ=paravarsym) and
  1799. (varspez=vs_const)) then
  1800. varregable:=vr_intreg
  1801. else if tstoreddef(vardef).is_fpuregable then
  1802. begin
  1803. if use_vectorfpu(vardef) then
  1804. varregable:=vr_mmreg
  1805. else
  1806. varregable:=vr_fpureg;
  1807. end
  1808. else if is_vector(vardef) and
  1809. fits_in_mm_register(vardef) then
  1810. begin
  1811. varregable:=vr_mmreg;
  1812. end;
  1813. end;
  1814. end;
  1815. function tabstractvarsym.get_addr_taken: boolean;
  1816. begin
  1817. result:=vsa_addr_taken in varsymaccess;
  1818. end;
  1819. function tabstractvarsym.get_different_scope: boolean;
  1820. begin
  1821. result:=vsa_different_scope in varsymaccess;
  1822. end;
  1823. procedure tabstractvarsym.setvardef(const def: tdef);
  1824. begin
  1825. _vardef := def;
  1826. end;
  1827. {****************************************************************************
  1828. TFIELDVARSYM
  1829. ****************************************************************************}
  1830. constructor tfieldvarsym.create(const n : TSymStr;vsp:tvarspez;def:tdef;vopts:tvaroptions);
  1831. begin
  1832. inherited create(fieldvarsym,n,vsp,def,vopts);
  1833. fieldoffset:=-1;
  1834. end;
  1835. constructor tfieldvarsym.ppuload(ppufile:tcompilerppufile);
  1836. begin
  1837. inherited ppuload(fieldvarsym,ppufile);
  1838. fieldoffset:=ppufile.getasizeint;
  1839. if (vo_has_mangledname in varoptions) then
  1840. externalname:=ppufile.getpshortstring
  1841. else
  1842. externalname:=nil;
  1843. ppuload_platform(ppufile);
  1844. end;
  1845. procedure tfieldvarsym.ppuwrite(ppufile:tcompilerppufile);
  1846. begin
  1847. inherited ppuwrite(ppufile);
  1848. ppufile.putasizeint(fieldoffset);
  1849. if (vo_has_mangledname in varoptions) then
  1850. ppufile.putstring(externalname^);
  1851. writeentry(ppufile,ibfieldvarsym);
  1852. end;
  1853. procedure tfieldvarsym.set_externalname(const s: string);
  1854. begin
  1855. internalerror(2014033001);
  1856. end;
  1857. function tfieldvarsym.bitoffset: asizeuint;
  1858. begin
  1859. result:=fieldoffset;
  1860. if tabstractrecordsymtable(owner).fieldalignment<>bit_alignment then
  1861. result:=result*8;
  1862. end;
  1863. function tfieldvarsym.mangledname:TSymStr;
  1864. var
  1865. srsym : tsym;
  1866. srsymtable : tsymtable;
  1867. begin
  1868. if sp_static in symoptions then
  1869. begin
  1870. if searchsym(lower(owner.name^)+'_'+name,srsym,srsymtable) then
  1871. result:=srsym.mangledname
  1872. { when generating the debug info for the module in which the }
  1873. { symbol is defined, the localsymtable of that module is }
  1874. { already popped from the symtablestack }
  1875. else if searchsym_in_module(current_module,lower(owner.name^)+'_'+name,srsym,srsymtable) then
  1876. result:=srsym.mangledname
  1877. else
  1878. internalerror(2007012501);
  1879. end
  1880. else if is_objcclass(tdef(owner.defowner)) then
  1881. begin
  1882. {$ifdef symansistr}
  1883. if cachedmangledname<>'' then
  1884. result:=cachedmangledname
  1885. {$else symansistr}
  1886. if assigned(cachedmangledname) then
  1887. result:=cachedmangledname^
  1888. {$endif symansistr}
  1889. else
  1890. begin
  1891. result:=target_info.cprefix+'OBJC_IVAR_$_'+tobjectdef(owner.defowner).objextname^+'.'+RealName;
  1892. {$ifdef symansistr}
  1893. cachedmangledname:=result;
  1894. {$else symansistr}
  1895. cachedmangledname:=stringdup(result);
  1896. {$endif symansistr}
  1897. end;
  1898. end
  1899. else
  1900. result:=inherited mangledname;
  1901. end;
  1902. destructor tfieldvarsym.destroy;
  1903. begin
  1904. {$ifndef symansistr}
  1905. stringdispose(cachedmangledname);
  1906. {$endif symansistr}
  1907. stringdispose(externalname);
  1908. inherited destroy;
  1909. end;
  1910. {$ifdef DEBUG_NODE_XML}
  1911. procedure TFieldVarSym.XMLPrintFieldData(var T: Text);
  1912. begin
  1913. WriteLn(T, PrintNodeIndention, '<type>', SanitiseXMLString(vardef.GetTypeName), '</type>');
  1914. WriteLn(T, PrintNodeIndention, '<visibility>', visibility, '</visibility>');
  1915. WriteLn(T, PrintNodeIndention, '<offset>', fieldoffset, '</offset>');
  1916. WriteLn(T, PrintNodeIndention, '<size>', vardef.size, '</size>');
  1917. end;
  1918. {$endif DEBUG_NODE_XML}
  1919. {****************************************************************************
  1920. TABSTRACTNORMALVARSYM
  1921. ****************************************************************************}
  1922. constructor tabstractnormalvarsym.create(st:tsymtyp;const n : TSymStr;vsp:tvarspez;def:tdef;vopts:tvaroptions);
  1923. begin
  1924. inherited create(st,n,vsp,def,vopts);
  1925. fillchar(localloc,sizeof(localloc),0);
  1926. fillchar(initialloc,sizeof(initialloc),0);
  1927. defaultconstsym:=nil;
  1928. defaultconstsymderef.reset;
  1929. end;
  1930. constructor tabstractnormalvarsym.ppuload(st:tsymtyp;ppufile:tcompilerppufile);
  1931. begin
  1932. inherited ppuload(st,ppufile);
  1933. fillchar(localloc,sizeof(localloc),0);
  1934. fillchar(initialloc,sizeof(initialloc),0);
  1935. ppufile.getderef(defaultconstsymderef);
  1936. end;
  1937. function tabstractnormalvarsym.globalasmsym: boolean;
  1938. begin
  1939. result:=
  1940. (owner.symtabletype=globalsymtable) or
  1941. (create_smartlink and
  1942. not(tf_smartlink_sections in target_info.flags)) or
  1943. current_module.islibrary or
  1944. (assigned(current_procinfo) and
  1945. ((po_inline in current_procinfo.procdef.procoptions) or
  1946. { globalasmsym is called normally before the body of a subroutine is parsed
  1947. so we cannot know if it will be auto inlined, so make all symbols of it
  1948. global if asked }
  1949. (not(po_noinline in current_procinfo.procdef.procoptions) and
  1950. (cs_opt_autoinline in current_settings.optimizerswitches)))
  1951. ) or
  1952. (vo_is_public in varoptions);
  1953. end;
  1954. procedure tabstractnormalvarsym.buildderef;
  1955. begin
  1956. inherited buildderef;
  1957. defaultconstsymderef.build(defaultconstsym);
  1958. end;
  1959. procedure tabstractnormalvarsym.deref;
  1960. begin
  1961. inherited deref;
  1962. defaultconstsym:=tsym(defaultconstsymderef.resolve);
  1963. end;
  1964. procedure tabstractnormalvarsym.ppuwrite(ppufile:tcompilerppufile);
  1965. begin
  1966. inherited ppuwrite(ppufile);
  1967. ppufile.putderef(defaultconstsymderef);
  1968. end;
  1969. function tabstractnormalvarsym.is_captured:boolean;
  1970. begin
  1971. result:=assigned(capture_sym);
  1972. end;
  1973. {****************************************************************************
  1974. Tstaticvarsym
  1975. ****************************************************************************}
  1976. constructor tstaticvarsym.create(const n : TSymStr;vsp:tvarspez;def:tdef;vopts:tvaroptions);
  1977. begin
  1978. inherited create(staticvarsym,n,vsp,def,vopts);
  1979. fieldvarsymderef.reset;
  1980. {$ifdef symansistr}
  1981. _mangledname:='';
  1982. {$else symansistr}
  1983. _mangledname:=nil;
  1984. {$endif symansistr}
  1985. end;
  1986. constructor tstaticvarsym.create_dll(const n : TSymStr;vsp:tvarspez;def:tdef);
  1987. begin
  1988. tstaticvarsym(self).create(n,vsp,def,[vo_is_dll_var]);
  1989. end;
  1990. constructor tstaticvarsym.create_C(const n: TSymStr; const mangled : TSymStr;vsp:tvarspez;def:tdef);
  1991. begin
  1992. tstaticvarsym(self).create(n,vsp,def,[]);
  1993. set_mangledname(mangled);
  1994. end;
  1995. constructor tstaticvarsym.create_from_fieldvar(const n: TSymStr;fieldvar:tfieldvarsym);
  1996. begin
  1997. create(internal_static_field_name(n),fieldvar.varspez,fieldvar.vardef,[]);
  1998. fieldvarsym:=fieldvar;
  1999. end;
  2000. constructor tstaticvarsym.ppuload(ppufile:tcompilerppufile);
  2001. begin
  2002. inherited ppuload(staticvarsym,ppufile);
  2003. {$ifdef symansistr}
  2004. if vo_has_mangledname in varoptions then
  2005. _mangledname:=ppufile.getansistring
  2006. else
  2007. _mangledname:='';
  2008. {$else symansistr}
  2009. if vo_has_mangledname in varoptions then
  2010. _mangledname:=ppufile.getpshortstring
  2011. else
  2012. _mangledname:=nil;
  2013. {$endif symansistr}
  2014. if vo_has_section in varoptions then
  2015. section:=ppufile.getansistring;
  2016. ppufile.getderef(fieldvarsymderef);
  2017. ppuload_platform(ppufile);
  2018. end;
  2019. destructor tstaticvarsym.destroy;
  2020. begin
  2021. {$ifndef symansistr}
  2022. if assigned(_mangledname) then
  2023. begin
  2024. {$ifdef MEMDEBUG}
  2025. memmanglednames.start;
  2026. {$endif MEMDEBUG}
  2027. stringdispose(_mangledname);
  2028. {$ifdef MEMDEBUG}
  2029. memmanglednames.stop;
  2030. {$endif MEMDEBUG}
  2031. end;
  2032. stringdispose(_mangledbasename);
  2033. {$endif}
  2034. inherited destroy;
  2035. end;
  2036. procedure tstaticvarsym.ppuwrite(ppufile:tcompilerppufile);
  2037. begin
  2038. inherited ppuwrite(ppufile);
  2039. { write mangledname rather than _mangledname in case the mangledname
  2040. has not been calculated yet (can happen in case only the
  2041. mangledbasename has been set) }
  2042. if vo_has_mangledname in varoptions then
  2043. {$ifdef symansistr}
  2044. ppufile.putansistring(mangledname);
  2045. {$else symansistr}
  2046. ppufile.putstring(mangledname);
  2047. {$endif symansistr}
  2048. if vo_has_section in varoptions then
  2049. ppufile.putansistring(section);
  2050. ppufile.putderef(fieldvarsymderef);
  2051. writeentry(ppufile,ibstaticvarsym);
  2052. end;
  2053. procedure tstaticvarsym.buildderef;
  2054. begin
  2055. inherited buildderef;
  2056. fieldvarsymderef.build(fieldvarsym);
  2057. end;
  2058. procedure tstaticvarsym.deref;
  2059. begin
  2060. inherited deref;
  2061. fieldvarsym:=tfieldvarsym(fieldvarsymderef.resolve);
  2062. end;
  2063. function tstaticvarsym.mangledname:TSymStr;
  2064. var
  2065. usename,
  2066. prefix : TSymStr;
  2067. begin
  2068. {$ifdef symansistr}
  2069. if _mangledname='' then
  2070. {$else symansistr}
  2071. if not assigned(_mangledname) then
  2072. {$endif symansistr}
  2073. begin
  2074. if (vo_is_typed_const in varoptions) then
  2075. prefix:='TC'
  2076. else
  2077. prefix:='U';
  2078. {$ifdef symansistr}
  2079. if _mangledbasename='' then
  2080. usename:=name
  2081. else
  2082. usename:=_mangledbasename;
  2083. _mangledname:=make_mangledname(prefix,owner,usename);
  2084. {$else symansistr}
  2085. if not assigned(_mangledbasename) then
  2086. usename:=name
  2087. else
  2088. usename:=_mangledbasename^;
  2089. _mangledname:=stringdup(make_mangledname(prefix,owner,usename));
  2090. {$endif symansistr}
  2091. end;
  2092. {$ifdef symansistr}
  2093. result:=_mangledname;
  2094. {$else symansistr}
  2095. result:=_mangledname^;
  2096. {$endif symansistr}
  2097. end;
  2098. procedure tstaticvarsym.set_mangledbasename(const s: TSymStr);
  2099. begin
  2100. {$ifdef symansistr}
  2101. _mangledbasename:=s;
  2102. _mangledname:='';
  2103. {$else symansistr}
  2104. stringdispose(_mangledname);
  2105. stringdispose(_mangledbasename);
  2106. _mangledbasename:=stringdup(s);
  2107. {$endif symansistr}
  2108. include(varoptions,vo_has_mangledname);
  2109. end;
  2110. function tstaticvarsym.mangledbasename: TSymStr;
  2111. begin
  2112. {$ifdef symansistr}
  2113. result:=_mangledbasename;
  2114. {$else symansistr}
  2115. if assigned(_mangledbasename) then
  2116. result:=_mangledbasename^
  2117. else
  2118. result:='';
  2119. {$endif symansistr}
  2120. end;
  2121. procedure tstaticvarsym.set_mangledname(const s:TSymStr);
  2122. begin
  2123. {$ifdef symansistr}
  2124. _mangledname:=s;
  2125. {$else symansistr}
  2126. stringdispose(_mangledname);
  2127. _mangledname:=stringdup(s);
  2128. {$endif symansistr}
  2129. include(varoptions,vo_has_mangledname);
  2130. end;
  2131. procedure tstaticvarsym.set_raw_mangledname(const s: TSymStr);
  2132. begin
  2133. {$ifndef symansistr}
  2134. stringdispose(_mangledname);
  2135. _mangledname:=stringdup(s);
  2136. {$else}
  2137. _mangledname:=s;
  2138. {$endif}
  2139. include(varoptions,vo_has_mangledname);
  2140. end;
  2141. {****************************************************************************
  2142. TLOCALVARSYM
  2143. ****************************************************************************}
  2144. constructor tlocalvarsym.create(const n : TSymStr;vsp:tvarspez;def:tdef;vopts:tvaroptions);
  2145. begin
  2146. inherited create(localvarsym,n,vsp,def,vopts);
  2147. end;
  2148. constructor tlocalvarsym.ppuload(ppufile:tcompilerppufile);
  2149. begin
  2150. inherited ppuload(localvarsym,ppufile);
  2151. ppuload_platform(ppufile);
  2152. end;
  2153. procedure tlocalvarsym.ppuwrite(ppufile:tcompilerppufile);
  2154. begin
  2155. inherited ppuwrite(ppufile);
  2156. writeentry(ppufile,iblocalvarsym);
  2157. end;
  2158. {****************************************************************************
  2159. TPARAVARSYM
  2160. ****************************************************************************}
  2161. constructor tparavarsym.create(const n : TSymStr;nr:word;vsp:tvarspez;def:tdef;vopts:tvaroptions);
  2162. begin
  2163. inherited create(paravarsym,n,vsp,def,vopts);
  2164. if (vsp in [vs_var,vs_value,vs_const,vs_constref]) and
  2165. not(vo_is_funcret in vopts) then
  2166. varstate := vs_initialised;
  2167. paranr:=nr;
  2168. paraloc[calleeside].init;
  2169. paraloc[callerside].init;
  2170. end;
  2171. destructor tparavarsym.destroy;
  2172. begin
  2173. paraloc[calleeside].done;
  2174. paraloc[callerside].done;
  2175. inherited destroy;
  2176. end;
  2177. constructor tparavarsym.ppuload(ppufile:tcompilerppufile);
  2178. begin
  2179. inherited ppuload(paravarsym,ppufile);
  2180. paranr:=ppufile.getword;
  2181. univpara:=ppufile.getboolean;
  2182. { The var state of parameter symbols is fixed after writing them so
  2183. we write them to the unit file.
  2184. This enables constant folding for inline procedures loaded from units
  2185. }
  2186. varstate:=tvarstate(ppufile.getbyte);
  2187. { read usage info }
  2188. refs:=ppufile.getbyte;
  2189. paraloc[calleeside].init;
  2190. paraloc[callerside].init;
  2191. if vo_has_explicit_paraloc in varoptions then
  2192. paraloc[callerside].ppuload(ppufile);
  2193. ppuload_platform(ppufile);
  2194. end;
  2195. procedure tparavarsym.ppuwrite(ppufile:tcompilerppufile);
  2196. var
  2197. oldintfcrc : boolean;
  2198. begin
  2199. inherited ppuwrite(ppufile);
  2200. ppufile.putword(paranr);
  2201. ppufile.putboolean(univpara);
  2202. { The var state of parameter symbols is fixed after writing them so
  2203. we write them to the unit file.
  2204. This enables constant folding for inline procedures loaded from units
  2205. }
  2206. oldintfcrc:=ppufile.do_crc;
  2207. ppufile.do_crc:=false;
  2208. ppufile.putbyte(ord(varstate));
  2209. { write also info about the usage of parameters,
  2210. the absolute usage does not matter }
  2211. ppufile.putbyte(min(1,refs));
  2212. ppufile.do_crc:=oldintfcrc;
  2213. if vo_has_explicit_paraloc in varoptions then
  2214. begin
  2215. paraloc[callerside].check_simple_location;
  2216. paraloc[callerside].ppuwrite(ppufile);
  2217. end;
  2218. writeentry(ppufile,ibparavarsym);
  2219. end;
  2220. function tparavarsym.needs_finalization:boolean;
  2221. begin
  2222. result:=(varspez=vs_value) and
  2223. (is_managed_type(vardef) or
  2224. (
  2225. (not (tabstractprocdef(owner.defowner).proccalloption in cdecl_pocalls)) and
  2226. (not paramanager.use_stackalloc) and
  2227. (is_open_array(vardef) or is_array_of_const(vardef))
  2228. )
  2229. );
  2230. end;
  2231. function tparavarsym.is_used: boolean;
  2232. begin
  2233. { Only the $parentfp parameter is supported for now }
  2234. result:=not (vo_is_parentfp in varoptions) or (varstate>vs_initialised);
  2235. end;
  2236. {****************************************************************************
  2237. TABSOLUTEVARSYM
  2238. ****************************************************************************}
  2239. constructor tabsolutevarsym.create(const n : TSymStr;def:tdef);
  2240. begin
  2241. inherited create(absolutevarsym,n,vs_value,def,[]);
  2242. ref:=nil;
  2243. end;
  2244. constructor tabsolutevarsym.create_ref(const n : TSymStr;def:tdef;_ref:tpropaccesslist);
  2245. begin
  2246. inherited create(absolutevarsym,n,vs_value,def,[]);
  2247. ref:=_ref;
  2248. end;
  2249. destructor tabsolutevarsym.destroy;
  2250. begin
  2251. if assigned(ref) then
  2252. ref.free;
  2253. inherited destroy;
  2254. end;
  2255. constructor tabsolutevarsym.ppuload(ppufile:tcompilerppufile);
  2256. begin
  2257. inherited ppuload(absolutevarsym,ppufile);
  2258. ref:=nil;
  2259. asmname:=nil;
  2260. abstyp:=absolutetyp(ppufile.getbyte);
  2261. case abstyp of
  2262. tovar :
  2263. ref:=ppufile.getpropaccesslist;
  2264. toasm :
  2265. asmname:=ppufile.getpshortstring;
  2266. toaddr :
  2267. addroffset:=ppufile.getpuint;
  2268. end;
  2269. ppuload_platform(ppufile);
  2270. end;
  2271. procedure tabsolutevarsym.ppuwrite(ppufile:tcompilerppufile);
  2272. begin
  2273. inherited ppuwrite(ppufile);
  2274. ppufile.putbyte(byte(abstyp));
  2275. case abstyp of
  2276. tovar :
  2277. ppufile.putpropaccesslist(ref);
  2278. toasm :
  2279. ppufile.putstring(asmname^);
  2280. toaddr :
  2281. ppufile.putpuint(addroffset);
  2282. end;
  2283. writeentry(ppufile,ibabsolutevarsym);
  2284. end;
  2285. procedure tabsolutevarsym.buildderef;
  2286. begin
  2287. inherited buildderef;
  2288. if (abstyp=tovar) then
  2289. ref.buildderef;
  2290. end;
  2291. procedure tabsolutevarsym.deref;
  2292. begin
  2293. inherited deref;
  2294. { own absolute deref }
  2295. if (abstyp=tovar) then
  2296. ref.resolve;
  2297. end;
  2298. function tabsolutevarsym.mangledname : TSymStr;
  2299. begin
  2300. case abstyp of
  2301. toasm :
  2302. mangledname:=asmname^;
  2303. toaddr :
  2304. mangledname:='$'+tostr(addroffset);
  2305. else
  2306. internalerror(200411062);
  2307. end;
  2308. end;
  2309. { returns the symbol type of the local variable or local parameter
  2310. referenced by the absolute symbol }
  2311. function tabsolutevarsym.reftyp : tsymtyp;
  2312. var
  2313. plist : ppropaccesslistitem;
  2314. begin
  2315. reftyp:=typ;
  2316. if abstyp=tovar then
  2317. begin
  2318. plist:=ref.firstsym;
  2319. if assigned(plist) and (plist^.sltype=sl_load) and
  2320. assigned(plist^.sym) and not(assigned(plist^.next)) then
  2321. reftyp:=plist^.sym.typ;
  2322. end;
  2323. end;
  2324. {****************************************************************************
  2325. TCONSTSYM
  2326. ****************************************************************************}
  2327. constructor tconstsym.create_ord(const n : TSymStr;t : tconsttyp;v : tconstexprint;def:tdef);
  2328. begin
  2329. inherited create(constsym,n);
  2330. fillchar(value, sizeof(value), #0);
  2331. consttyp:=t;
  2332. value.valueord:=v;
  2333. constdef:=def;
  2334. constdefderef.reset;
  2335. end;
  2336. constructor tconstsym.create_ordptr(const n : TSymStr;t : tconsttyp;v : tconstptruint;def:tdef);
  2337. begin
  2338. inherited create(constsym,n);
  2339. fillchar(value, sizeof(value), #0);
  2340. consttyp:=t;
  2341. value.valueordptr:=v;
  2342. constdef:=def;
  2343. constdefderef.reset;
  2344. end;
  2345. constructor tconstsym.create_ptr(const n : TSymStr;t : tconsttyp;v : pointer;def:tdef);
  2346. begin
  2347. inherited create(constsym,n);
  2348. fillchar(value, sizeof(value), #0);
  2349. consttyp:=t;
  2350. value.valueptr:=v;
  2351. constdef:=def;
  2352. constdefderef.reset;
  2353. end;
  2354. constructor tconstsym.create_string(const n : TSymStr;t : tconsttyp;str:pchar;l:longint;def: tdef);
  2355. begin
  2356. inherited create(constsym,n);
  2357. fillchar(value, sizeof(value), #0);
  2358. consttyp:=t;
  2359. value.valueptr:=str;
  2360. if assigned(def) then
  2361. constdef:=def
  2362. else
  2363. constdef:=carraydef.getreusable(cansichartype,l);
  2364. constdefderef.reset;
  2365. value.len:=l;
  2366. end;
  2367. constructor tconstsym.create_wstring(const n : TSymStr;t : tconsttyp;pw:tcompilerwidestring);
  2368. begin
  2369. inherited create(constsym,n);
  2370. fillchar(value, sizeof(value), #0);
  2371. consttyp:=t;
  2372. value.valuews:=pw;
  2373. constdef:=carraydef.getreusable(cwidechartype,getlengthwidestring(pw));
  2374. constdefderef.reset;
  2375. value.len:=getlengthwidestring(pw);
  2376. end;
  2377. constructor tconstsym.create_undefined(const n : TSymStr;def: tdef);
  2378. begin
  2379. inherited create(constsym,n);
  2380. fillchar(value,sizeof(value),#0);
  2381. consttyp:=constnone;
  2382. constdef:=def;
  2383. end;
  2384. constructor tconstsym.ppuload(ppufile:tcompilerppufile);
  2385. var
  2386. pd : pbestreal;
  2387. ps : pnormalset;
  2388. pc : pchar;
  2389. pw : tcompilerwidestring;
  2390. i : longint;
  2391. procedure do_widestring_const;
  2392. var
  2393. i : longint;
  2394. begin
  2395. initwidestring(pw);
  2396. setlengthwidestring(pw,ppufile.getlongint);
  2397. { don't use getdata, because the compilerwidechars may have to
  2398. be byteswapped
  2399. }
  2400. {$if sizeof(tcompilerwidechar) = 2}
  2401. for i:=0 to pw.len-1 do
  2402. pw.data[i]:=ppufile.getword;
  2403. {$elseif sizeof(tcompilerwidechar) = 4}
  2404. for i:=0 to pw.len-1 do
  2405. pw.data[i]:=cardinal(ppufile.getlongint);
  2406. {$else}
  2407. {$error Unsupported tcompilerwidechar size}
  2408. {$endif}
  2409. value.valuews:=pw;
  2410. end;
  2411. begin
  2412. inherited ppuload(constsym,ppufile);
  2413. constdef:=nil;
  2414. consttyp:=tconsttyp(ppufile.getbyte);
  2415. fillchar(value, sizeof(value), #0);
  2416. case consttyp of
  2417. constord :
  2418. begin
  2419. ppufile.getderef(constdefderef);
  2420. value.valueord:=ppufile.getexprint;
  2421. end;
  2422. constpointer :
  2423. begin
  2424. ppufile.getderef(constdefderef);
  2425. value.valueordptr:=ppufile.getptruint;
  2426. end;
  2427. constwstring :
  2428. begin
  2429. do_widestring_const;
  2430. end;
  2431. conststring,
  2432. constresourcestring :
  2433. begin
  2434. ppufile.getderef(constdefderef);
  2435. value.len:=ppufile.getlongint;
  2436. getmem(pc,value.len+1);
  2437. ppufile.getdata(pc^,value.len);
  2438. pc[value.len]:=#0;
  2439. value.valueptr:=pc;
  2440. end;
  2441. constwresourcestring :
  2442. begin
  2443. ppufile.getderef(constdefderef);
  2444. do_widestring_const;
  2445. end;
  2446. constreal :
  2447. begin
  2448. ppufile.getderef(constdefderef);
  2449. new(pd);
  2450. pd^:=ppufile.getreal;
  2451. value.valueptr:=pd;
  2452. end;
  2453. constset :
  2454. begin
  2455. ppufile.getderef(constdefderef);
  2456. new(ps);
  2457. ppufile.getset(tppuset32(ps^));
  2458. value.valueptr:=ps;
  2459. end;
  2460. constguid :
  2461. begin
  2462. ppufile.getderef(constdefderef);
  2463. new(pguid(value.valueptr));
  2464. ppufile.getdata(value.valueptr^,sizeof(tguid));
  2465. end;
  2466. constnil :
  2467. ppufile.getderef(constdefderef);
  2468. else
  2469. Message1(unit_f_ppu_invalid_entry,tostr(ord(consttyp)));
  2470. end;
  2471. ppuload_platform(ppufile);
  2472. end;
  2473. destructor tconstsym.destroy;
  2474. begin
  2475. case consttyp of
  2476. constnone,
  2477. constord,
  2478. constpointer,
  2479. constnil:
  2480. ;
  2481. conststring,
  2482. constresourcestring :
  2483. freemem(pchar(value.valueptr),value.len+1);
  2484. constwstring,
  2485. constwresourcestring:
  2486. donewidestring(value.valuews);
  2487. constreal :
  2488. dispose(pbestreal(value.valueptr));
  2489. constset :
  2490. dispose(pnormalset(value.valueptr));
  2491. constguid :
  2492. dispose(pguid(value.valueptr));
  2493. end;
  2494. inherited destroy;
  2495. end;
  2496. procedure tconstsym.buildderef;
  2497. begin
  2498. inherited;
  2499. case consttyp of
  2500. constnil,constord,constreal,constpointer,constset,conststring,constresourcestring,constwresourcestring,constguid:
  2501. constdefderef.build(constdef);
  2502. constwstring:
  2503. ;
  2504. else
  2505. internalerror(2015120802);
  2506. end;
  2507. end;
  2508. procedure tconstsym.deref;
  2509. begin
  2510. case consttyp of
  2511. constnil,constord,constreal,constpointer,constset,conststring,constresourcestring,constwresourcestring,constguid:
  2512. constdef:=tdef(constdefderef.resolve);
  2513. constwstring:
  2514. constdef:=carraydef.getreusable(cwidechartype,getlengthwidestring(value.valuews));
  2515. else
  2516. internalerror(2015120801);
  2517. end
  2518. end;
  2519. procedure tconstsym.ppuwrite(ppufile:tcompilerppufile);
  2520. procedure do_widestring_const;
  2521. var
  2522. len : integer;
  2523. begin
  2524. len:=getlengthwidestring(value.valuews);
  2525. ppufile.putlongint(len);
  2526. if len>0 then
  2527. ppufile.putdata(value.valuews.data[0],value.valuews.len*sizeof(tcompilerwidechar));
  2528. end;
  2529. begin
  2530. inherited ppuwrite(ppufile);
  2531. ppufile.putbyte(byte(consttyp));
  2532. case consttyp of
  2533. constnil :
  2534. ppufile.putderef(constdefderef);
  2535. constord :
  2536. begin
  2537. ppufile.putderef(constdefderef);
  2538. ppufile.putexprint(value.valueord);
  2539. end;
  2540. constpointer :
  2541. begin
  2542. ppufile.putderef(constdefderef);
  2543. ppufile.putptruint(value.valueordptr);
  2544. end;
  2545. constwstring :
  2546. begin
  2547. { no need to store the def, we can reconstruct it }
  2548. do_widestring_const;
  2549. end;
  2550. conststring,constresourcestring:
  2551. begin
  2552. ppufile.putderef(constdefderef);
  2553. ppufile.putlongint(value.len);
  2554. ppufile.putdata(pchar(value.valueptr)^,value.len);
  2555. end;
  2556. constwresourcestring:
  2557. begin
  2558. ppufile.putderef(constdefderef);
  2559. do_widestring_const
  2560. end;
  2561. constreal :
  2562. begin
  2563. ppufile.putderef(constdefderef);
  2564. ppufile.putreal(pbestreal(value.valueptr)^);
  2565. end;
  2566. constset :
  2567. begin
  2568. ppufile.putderef(constdefderef);
  2569. ppufile.putset(tppuset32(value.valueptr^));
  2570. end;
  2571. constguid :
  2572. begin
  2573. ppufile.putderef(constdefderef);
  2574. ppufile.putdata(value.valueptr^,sizeof(tguid));
  2575. end;
  2576. else
  2577. internalerror(13);
  2578. end;
  2579. writeentry(ppufile,ibconstsym);
  2580. end;
  2581. {$ifdef DEBUG_NODE_XML}
  2582. procedure TConstSym.XMLPrintConstData(var T: Text);
  2583. begin
  2584. WriteLn(T, PrintNodeIndention, '<type>', SanitiseXMLString(constdef.GetTypeName), '</type>');
  2585. case consttyp of
  2586. constnone:
  2587. ;
  2588. conststring,
  2589. constresourcestring,
  2590. constwresourcestring,
  2591. constwstring:
  2592. begin
  2593. WriteLn(T, PrintNodeIndention, '<length>', value.len, '</length>');
  2594. if value.len = 0 then
  2595. WriteLn(T, PrintNodeIndention, '<value />')
  2596. else
  2597. WriteLn(T, PrintNodeIndention, '<value>', SanitiseXMLString(PChar(value.valueptr)), '</value>');
  2598. end;
  2599. constord,
  2600. constset:
  2601. WriteLn(T, PrintNodeIndention, '<value>', tostr(value.valueord), '</value>');
  2602. constpointer:
  2603. WriteLn(T, PrintNodeIndention, '<value>', WriteConstPUInt(value.valueordptr), '</value>');
  2604. constreal:
  2605. WriteLn(T, PrintNodeIndention, '<value>', PBestReal(value.valueptr)^, '</value>');
  2606. constnil:
  2607. WriteLn(T, PrintNodeIndention, '<value>nil</value>');
  2608. constguid:
  2609. WriteLn(T, PrintNodeIndention, '<value>', WriteGUID(PGUID(value.valueptr)^), '</value>');
  2610. end;
  2611. WriteLn(T, PrintNodeIndention, '<visibility>', visibility, '</visibility>');
  2612. if not (consttyp in [conststring, constresourcestring, constwresourcestring, constwstring]) then
  2613. { constdef.size will return an internal error for string
  2614. constants because constdef is an open array internally }
  2615. WriteLn(T, PrintNodeIndention, '<size>', constdef.size, '</size>');
  2616. // WriteLn(T, PrintNodeIndention, '<const_type>', consttyp, '</const_type>');
  2617. end;
  2618. {$endif DEBUG_NODE_XML}
  2619. {****************************************************************************
  2620. TENUMSYM
  2621. ****************************************************************************}
  2622. constructor tenumsym.create(const n : TSymStr;def : tenumdef;v : longint);
  2623. begin
  2624. inherited create(enumsym,n);
  2625. definition:=def;
  2626. definitionderef.reset;
  2627. value:=v;
  2628. end;
  2629. constructor tenumsym.ppuload(ppufile:tcompilerppufile);
  2630. begin
  2631. inherited ppuload(enumsym,ppufile);
  2632. ppufile.getderef(definitionderef);
  2633. value:=ppufile.getlongint;
  2634. ppuload_platform(ppufile);
  2635. end;
  2636. procedure tenumsym.buildderef;
  2637. begin
  2638. inherited;
  2639. definitionderef.build(definition);
  2640. end;
  2641. procedure tenumsym.deref;
  2642. begin
  2643. definition:=tenumdef(definitionderef.resolve);
  2644. end;
  2645. procedure tenumsym.ppuwrite(ppufile:tcompilerppufile);
  2646. begin
  2647. inherited ppuwrite(ppufile);
  2648. ppufile.putderef(definitionderef);
  2649. ppufile.putlongint(value);
  2650. writeentry(ppufile,ibenumsym);
  2651. end;
  2652. {****************************************************************************
  2653. TTYPESYM
  2654. ****************************************************************************}
  2655. constructor ttypesym.create(const n : TSymStr;def:tdef);
  2656. begin
  2657. inherited create(typesym,n);
  2658. typedef:=def;
  2659. typedefderef.reset;
  2660. { register the typesym for the definition }
  2661. if assigned(typedef) and
  2662. (typedef.typ<>errordef) and
  2663. not(assigned(typedef.typesym)) then
  2664. typedef.typesym:=self;
  2665. end;
  2666. destructor ttypesym.destroy;
  2667. begin
  2668. inherited destroy;
  2669. end;
  2670. constructor ttypesym.ppuload(ppufile:tcompilerppufile);
  2671. begin
  2672. inherited ppuload(typesym,ppufile);
  2673. ppufile.getderef(typedefderef);
  2674. fprettyname:=ppufile.getansistring;
  2675. ppuload_platform(ppufile);
  2676. end;
  2677. procedure ttypesym.buildderef;
  2678. begin
  2679. inherited;
  2680. typedefderef.build(typedef);
  2681. end;
  2682. procedure ttypesym.deref;
  2683. begin
  2684. typedef:=tdef(typedefderef.resolve);
  2685. end;
  2686. procedure ttypesym.ppuwrite(ppufile:tcompilerppufile);
  2687. begin
  2688. inherited ppuwrite(ppufile);
  2689. ppufile.putderef(typedefderef);
  2690. ppufile.putansistring(fprettyname);
  2691. writeentry(ppufile,ibtypesym);
  2692. end;
  2693. function ttypesym.prettyname : string;
  2694. begin
  2695. if fprettyname<>'' then
  2696. result:=fprettyname
  2697. else
  2698. result:=inherited prettyname;
  2699. end;
  2700. {****************************************************************************
  2701. TSYSSYM
  2702. ****************************************************************************}
  2703. var
  2704. syssym_list : TFPHashObjectList;
  2705. constructor tsyssym.create(const n : TSymStr;l : tinlinenumber);
  2706. var
  2707. s : shortstring;
  2708. begin
  2709. inherited create(syssym,n);
  2710. number:=l;
  2711. str(longint(l),s);
  2712. if assigned(syssym_list.find(s)) then
  2713. internalerror(2016060303);
  2714. syssym_list.add(s,self);
  2715. end;
  2716. constructor tsyssym.ppuload(ppufile:tcompilerppufile);
  2717. var
  2718. s : shortstring;
  2719. begin
  2720. inherited ppuload(syssym,ppufile);
  2721. number:=tinlinenumber(ppufile.getlongint);
  2722. ppuload_platform(ppufile);
  2723. str(longint(number),s);
  2724. if assigned(syssym_list.find(s)) then
  2725. internalerror(2016060304);
  2726. syssym_list.add(s,self);
  2727. end;
  2728. destructor tsyssym.destroy;
  2729. begin
  2730. inherited destroy;
  2731. end;
  2732. procedure tsyssym.ppuwrite(ppufile:tcompilerppufile);
  2733. begin
  2734. inherited ppuwrite(ppufile);
  2735. ppufile.putlongint(longint(number));
  2736. writeentry(ppufile,ibsyssym);
  2737. end;
  2738. class function tsyssym.find_by_number(l:longint):tsyssym;
  2739. var
  2740. s : shortstring;
  2741. begin
  2742. str(l,s);
  2743. result:=tsyssym(syssym_list.find(s));
  2744. end;
  2745. {*****************************************************************************
  2746. TMacro
  2747. *****************************************************************************}
  2748. constructor tmacro.create(const n : TSymStr);
  2749. begin
  2750. inherited create(macrosym,n);
  2751. owner:=nil;
  2752. defined:=false;
  2753. is_used:=false;
  2754. is_compiler_var:=false;
  2755. buftext:=nil;
  2756. buflen:=0;
  2757. end;
  2758. constructor tmacro.ppuload(ppufile:tcompilerppufile);
  2759. begin
  2760. inherited ppuload(macrosym,ppufile);
  2761. defined:=ppufile.getboolean;
  2762. is_compiler_var:=ppufile.getboolean;
  2763. is_used:=false;
  2764. allocate_buftext(ppufile.getlongint);
  2765. if buflen>0 then
  2766. ppufile.getdata(buftext)
  2767. end;
  2768. destructor tmacro.destroy;
  2769. begin
  2770. buftext:=nil;
  2771. inherited destroy;
  2772. end;
  2773. procedure tmacro.ppuwrite(ppufile:tcompilerppufile);
  2774. begin
  2775. inherited ppuwrite(ppufile);
  2776. ppufile.putboolean(defined);
  2777. ppufile.putboolean(is_compiler_var);
  2778. ppufile.putlongint(buflen);
  2779. if buflen > 0 then
  2780. ppufile.putdata(buftext);
  2781. writeentry(ppufile,ibmacrosym);
  2782. end;
  2783. function tmacro.allocate_buftext(len:longint) : pchar;
  2784. begin
  2785. setlength(buftext,len);
  2786. buflen:=len;
  2787. result:=PAnsiChar(buftext);
  2788. end;
  2789. procedure tmacro.free_buftext;
  2790. begin
  2791. buftext:=nil;
  2792. buflen:=0;
  2793. end;
  2794. function tmacro.GetCopy:tmacro;
  2795. var
  2796. p : tmacro;
  2797. begin
  2798. p:=tmacro.create(realname);
  2799. p.defined:=defined;
  2800. p.is_used:=is_used;
  2801. p.is_compiler_var:=is_compiler_var;
  2802. p.is_c_macro:=is_c_macro;
  2803. p.allocate_buftext(buflen);
  2804. if buflen>0 then
  2805. move(buftext[0],p.buftext[0],buflen);
  2806. Result:=p;
  2807. end;
  2808. procedure init_symsym;
  2809. begin
  2810. syssym_list:=tfphashobjectlist.create(false);
  2811. end;
  2812. procedure done_symsym;
  2813. begin
  2814. syssym_list.free;
  2815. end;
  2816. initialization
  2817. register_initdone_proc(@init_symsym,@done_symsym);
  2818. end.