symsym.pas 84 KB

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