symsym.pas 106 KB

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