symsym.pas 105 KB

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