symsym.pas 66 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070
  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);
  57. constructor ppuload(ppufile:tcompilerppufile);
  58. procedure ppuwrite(ppufile:tcompilerppufile);override;
  59. function mangledname:string;override;
  60. end;
  61. tunitsym = class(Tstoredsym)
  62. module : tobject; { tmodule }
  63. constructor create(const n : string;amodule : tobject);
  64. constructor ppuload(ppufile:tcompilerppufile);
  65. destructor destroy;override;
  66. procedure ppuwrite(ppufile:tcompilerppufile);override;
  67. end;
  68. tnamespacesym = class(Tstoredsym)
  69. unitsym:tsym;
  70. unitsymderef:tderef;
  71. constructor create(const n : string);
  72. constructor ppuload(ppufile:tcompilerppufile);
  73. procedure ppuwrite(ppufile:tcompilerppufile);override;
  74. procedure buildderef;override;
  75. procedure deref;override;
  76. end;
  77. terrorsym = class(Tsym)
  78. constructor create;
  79. end;
  80. { tprocsym }
  81. tprocsym = class(tstoredsym)
  82. protected
  83. FProcdefList : TFPObjectList;
  84. FProcdefDerefList : TFPList;
  85. public
  86. constructor create(const n : string);
  87. constructor ppuload(ppufile:tcompilerppufile);
  88. destructor destroy;override;
  89. { writes all declarations except the specified one }
  90. procedure write_parameter_lists(skipdef:tprocdef);
  91. { tests, if all procedures definitions are defined and not }
  92. { only forward }
  93. procedure check_forward;
  94. procedure ppuwrite(ppufile:tcompilerppufile);override;
  95. procedure buildderef;override;
  96. procedure deref;override;
  97. function find_procdef_bytype(pt:Tproctypeoption):Tprocdef;
  98. function find_procdef_bypara(para:TFPObjectList;retdef:tdef;cpoptions:tcompare_paras_options):Tprocdef;
  99. function find_procdef_byoptions(ops:tprocoptions): Tprocdef;
  100. function find_procdef_byprocvardef(d:Tprocvardef):Tprocdef;
  101. function find_procdef_assignment_operator(fromdef,todef:tdef;var besteq:tequaltype):Tprocdef;
  102. function find_procdef_enumerator_operator(fromdef,todef:tdef;var besteq:tequaltype):Tprocdef;
  103. property ProcdefList:TFPObjectList read FProcdefList;
  104. end;
  105. ttypesym = class(Tstoredsym)
  106. typedef : tdef;
  107. typedefderef : tderef;
  108. fprettyname : ansistring;
  109. constructor create(const n : string;def:tdef);
  110. constructor ppuload(ppufile:tcompilerppufile);
  111. procedure ppuwrite(ppufile:tcompilerppufile);override;
  112. procedure buildderef;override;
  113. procedure deref;override;
  114. function prettyname : string;override;
  115. end;
  116. tabstractvarsym = class(tstoredsym)
  117. varoptions : tvaroptions;
  118. notifications : Tlinkedlist;
  119. varspez : tvarspez; { sets the type of access }
  120. varregable : tvarregable;
  121. varstate : tvarstate;
  122. { Has the address of this variable potentially escaped the }
  123. { block in which is was declared? }
  124. { could also be part of tabstractnormalvarsym, but there's }
  125. { one byte left here till the next 4 byte alignment }
  126. addr_taken : boolean;
  127. constructor create(st:tsymtyp;const n : string;vsp:tvarspez;def:tdef;vopts:tvaroptions);
  128. constructor ppuload(st:tsymtyp;ppufile:tcompilerppufile);
  129. destructor destroy;override;
  130. procedure ppuwrite(ppufile:tcompilerppufile);override;
  131. procedure buildderef;override;
  132. procedure deref;override;
  133. function getsize : asizeint;
  134. function getpackedbitsize : longint;
  135. function is_regvar(refpara: boolean):boolean;
  136. procedure trigger_notifications(what:Tnotification_flag);
  137. function register_notification(flags:Tnotification_flags;
  138. callback:Tnotification_callback):cardinal;
  139. procedure unregister_notification(id:cardinal);
  140. private
  141. _vardef : tdef;
  142. vardefderef : tderef;
  143. procedure setvardef(def:tdef);
  144. public
  145. property vardef: tdef read _vardef write setvardef;
  146. end;
  147. tfieldvarsym = class(tabstractvarsym)
  148. fieldoffset : asizeint; { offset in record/object }
  149. objcoffsetmangledname: pshortstring; { mangled name of offset, calculated as needed }
  150. constructor create(const n : string;vsp:tvarspez;def:tdef;vopts:tvaroptions);
  151. constructor ppuload(ppufile:tcompilerppufile);
  152. procedure ppuwrite(ppufile:tcompilerppufile);override;
  153. function mangledname:string;override;
  154. destructor destroy;override;
  155. end;
  156. tabstractnormalvarsym = class(tabstractvarsym)
  157. defaultconstsym : tsym;
  158. defaultconstsymderef : tderef;
  159. localloc : TLocation; { register/reference for local var }
  160. initialloc : TLocation; { initial location so it can still be initialized later after the location was changed by SSA }
  161. constructor create(st:tsymtyp;const n : string;vsp:tvarspez;def:tdef;vopts:tvaroptions);
  162. constructor ppuload(st:tsymtyp;ppufile:tcompilerppufile);
  163. procedure ppuwrite(ppufile:tcompilerppufile);override;
  164. procedure buildderef;override;
  165. procedure deref;override;
  166. end;
  167. tlocalvarsym = class(tabstractnormalvarsym)
  168. constructor create(const n : string;vsp:tvarspez;def:tdef;vopts:tvaroptions);
  169. constructor ppuload(ppufile:tcompilerppufile);
  170. procedure ppuwrite(ppufile:tcompilerppufile);override;
  171. end;
  172. tparavarsym = class(tabstractnormalvarsym)
  173. paraloc : array[tcallercallee] of TCGPara;
  174. paranr : word; { position of this parameter }
  175. { in MacPas mode, "univ" parameters mean that type checking should
  176. be disabled, except that the size of the passed parameter must
  177. match the size of the formal parameter }
  178. univpara : boolean;
  179. {$ifdef EXTDEBUG}
  180. eqval : tequaltype;
  181. {$endif EXTDEBUG}
  182. constructor create(const n : string;nr:word;vsp:tvarspez;def:tdef;vopts:tvaroptions);
  183. constructor ppuload(ppufile:tcompilerppufile);
  184. destructor destroy;override;
  185. procedure ppuwrite(ppufile:tcompilerppufile);override;
  186. end;
  187. tstaticvarsym = class(tabstractnormalvarsym)
  188. private
  189. _mangledname : pshortstring;
  190. public
  191. section : ansistring;
  192. constructor create(const n : string;vsp:tvarspez;def:tdef;vopts:tvaroptions);
  193. constructor create_dll(const n : string;vsp:tvarspez;def:tdef);
  194. constructor create_C(const n,mangled : string;vsp:tvarspez;def:tdef);
  195. constructor ppuload(ppufile:tcompilerppufile);
  196. destructor destroy;override;
  197. procedure ppuwrite(ppufile:tcompilerppufile);override;
  198. function mangledname:string;override;
  199. procedure set_mangledname(const s:string);
  200. end;
  201. tabsolutevarsym = class(tabstractvarsym)
  202. public
  203. abstyp : absolutetyp;
  204. {$ifdef i386}
  205. absseg : boolean;
  206. {$endif i386}
  207. asmname : pshortstring;
  208. addroffset : aword;
  209. ref : tpropaccesslist;
  210. constructor create(const n : string;def:tdef);
  211. constructor create_ref(const n : string;def:tdef;_ref:tpropaccesslist);
  212. destructor destroy;override;
  213. constructor ppuload(ppufile:tcompilerppufile);
  214. procedure buildderef;override;
  215. procedure deref;override;
  216. function mangledname : string;override;
  217. procedure ppuwrite(ppufile:tcompilerppufile);override;
  218. end;
  219. tpropaccesslisttypes=(palt_none,palt_read,palt_write,palt_stored);
  220. tpropertysym = class(Tstoredsym)
  221. propoptions : tpropertyoptions;
  222. overriddenpropsym : tpropertysym;
  223. overriddenpropsymderef : tderef;
  224. propdef : tdef;
  225. propdefderef : tderef;
  226. indexdef : tdef;
  227. indexdefderef : tderef;
  228. index,
  229. default : longint;
  230. dispid : longint;
  231. propaccesslist: array[tpropaccesslisttypes] of tpropaccesslist;
  232. parast : tsymtable;
  233. constructor create(const n : string);
  234. destructor destroy;override;
  235. constructor ppuload(ppufile:tcompilerppufile);
  236. function getsize : asizeint;
  237. procedure ppuwrite(ppufile:tcompilerppufile);override;
  238. procedure buildderef;override;
  239. procedure deref;override;
  240. end;
  241. tconstvalue = record
  242. case integer of
  243. 0: (valueord : tconstexprint);
  244. 1: (valueordptr : tconstptruint);
  245. 2: (valueptr : pointer; len : longint);
  246. end;
  247. tconstsym = class(tstoredsym)
  248. constdef : tdef;
  249. constdefderef : tderef;
  250. consttyp : tconsttyp;
  251. value : tconstvalue;
  252. constructor create_ord(const n : string;t : tconsttyp;v : tconstexprint;def:tdef);
  253. constructor create_ordptr(const n : string;t : tconsttyp;v : tconstptruint;def:tdef);
  254. constructor create_ptr(const n : string;t : tconsttyp;v : pointer;def:tdef);
  255. constructor create_string(const n : string;t : tconsttyp;str:pchar;l:longint);
  256. constructor create_wstring(const n : string;t : tconsttyp;pw:pcompilerwidestring);
  257. constructor ppuload(ppufile:tcompilerppufile);
  258. destructor destroy;override;
  259. procedure buildderef;override;
  260. procedure deref;override;
  261. procedure ppuwrite(ppufile:tcompilerppufile);override;
  262. end;
  263. tenumsym = class(Tstoredsym)
  264. value : longint;
  265. definition : tenumdef;
  266. definitionderef : tderef;
  267. constructor create(const n : string;def : tenumdef;v : longint);
  268. constructor ppuload(ppufile:tcompilerppufile);
  269. procedure ppuwrite(ppufile:tcompilerppufile);override;
  270. procedure buildderef;override;
  271. procedure deref;override;
  272. end;
  273. tsyssym = class(Tstoredsym)
  274. number : longint;
  275. constructor create(const n : string;l : longint);
  276. constructor ppuload(ppufile:tcompilerppufile);
  277. destructor destroy;override;
  278. procedure ppuwrite(ppufile:tcompilerppufile);override;
  279. end;
  280. const
  281. maxmacrolen=16*1024;
  282. type
  283. pmacrobuffer = ^tmacrobuffer;
  284. tmacrobuffer = array[0..maxmacrolen-1] of char;
  285. tmacro = class(tstoredsym)
  286. {Normally true, but false when a previously defined macro is undef-ed}
  287. defined : boolean;
  288. {True if this is a mac style compiler variable, in which case no macro
  289. substitutions shall be done.}
  290. is_compiler_var : boolean;
  291. {Whether the macro was used. NOTE: A use of a macro which was never defined}
  292. {e. g. an IFDEF which returns false, will not be registered as used,}
  293. {since there is no place to register its use. }
  294. is_used : boolean;
  295. buftext : pchar;
  296. buflen : longint;
  297. constructor create(const n : string);
  298. constructor ppuload(ppufile:tcompilerppufile);
  299. procedure ppuwrite(ppufile:tcompilerppufile);override;
  300. destructor destroy;override;
  301. function GetCopy:tmacro;
  302. end;
  303. var
  304. generrorsym : tsym;
  305. implementation
  306. uses
  307. { global }
  308. verbose,
  309. { target }
  310. systems,
  311. { symtable }
  312. defutil,symtable,
  313. fmodule,
  314. { tree }
  315. node,
  316. { aasm }
  317. aasmtai,aasmdata,
  318. { codegen }
  319. paramgr,
  320. procinfo
  321. ;
  322. {****************************************************************************
  323. Helpers
  324. ****************************************************************************}
  325. {****************************************************************************
  326. TSYM (base for all symtypes)
  327. ****************************************************************************}
  328. constructor tstoredsym.create(st:tsymtyp;const n : string);
  329. begin
  330. inherited create(st,n);
  331. { Register in current_module }
  332. if assigned(current_module) then
  333. begin
  334. current_module.symlist.Add(self);
  335. SymId:=current_module.symlist.Count-1;
  336. end;
  337. end;
  338. constructor tstoredsym.ppuload(st:tsymtyp;ppufile:tcompilerppufile);
  339. begin
  340. SymId:=ppufile.getlongint;
  341. inherited Create(st,ppufile.getstring);
  342. { Register symbol }
  343. current_module.symlist[SymId]:=self;
  344. ppufile.getposinfo(fileinfo);
  345. visibility:=tvisibility(ppufile.getbyte);
  346. ppufile.getsmallset(symoptions);
  347. if sp_has_deprecated_msg in symoptions then
  348. deprecatedmsg:=stringdup(ppufile.getstring)
  349. else
  350. deprecatedmsg:=nil;
  351. end;
  352. procedure tstoredsym.ppuwrite(ppufile:tcompilerppufile);
  353. var
  354. oldintfcrc : boolean;
  355. begin
  356. ppufile.putlongint(SymId);
  357. ppufile.putstring(realname);
  358. ppufile.putposinfo(fileinfo);
  359. ppufile.putbyte(byte(visibility));
  360. { symoptions can differ between interface and implementation, except
  361. for overload (this is checked in pdecsub.proc_add_definition() )
  362. These differences can lead to compiler crashes, so ignore them.
  363. This does mean that changing e.g. the "deprecated" state of a symbol
  364. by itself will not trigger a recompilation of dependent units.
  365. }
  366. oldintfcrc:=ppufile.do_interface_crc;
  367. ppufile.do_interface_crc:=false;
  368. ppufile.putsmallset(symoptions);
  369. if sp_has_deprecated_msg in symoptions then
  370. ppufile.putstring(deprecatedmsg^);
  371. ppufile.do_interface_crc:=oldintfcrc;
  372. end;
  373. destructor tstoredsym.destroy;
  374. begin
  375. inherited destroy;
  376. end;
  377. {****************************************************************************
  378. TLABELSYM
  379. ****************************************************************************}
  380. constructor tlabelsym.create(const n : string);
  381. begin
  382. inherited create(labelsym,n);
  383. used:=false;
  384. defined:=false;
  385. nonlocal:=false;
  386. code:=nil;
  387. end;
  388. constructor tlabelsym.ppuload(ppufile:tcompilerppufile);
  389. begin
  390. inherited ppuload(labelsym,ppufile);
  391. code:=nil;
  392. used:=false;
  393. nonlocal:=false;
  394. defined:=true;
  395. end;
  396. procedure tlabelsym.ppuwrite(ppufile:tcompilerppufile);
  397. begin
  398. if owner.symtabletype=globalsymtable then
  399. Message(sym_e_ill_label_decl)
  400. else
  401. begin
  402. inherited ppuwrite(ppufile);
  403. ppufile.writeentry(iblabelsym);
  404. end;
  405. end;
  406. function tlabelsym.mangledname:string;
  407. begin
  408. if not(defined) then
  409. begin
  410. defined:=true;
  411. if nonlocal then
  412. current_asmdata.getglobaljumplabel(asmblocklabel)
  413. else
  414. current_asmdata.getjumplabel(asmblocklabel);
  415. end;
  416. result:=asmblocklabel.name;
  417. end;
  418. {****************************************************************************
  419. TUNITSYM
  420. ****************************************************************************}
  421. constructor tunitsym.create(const n : string;amodule : tobject);
  422. begin
  423. inherited create(unitsym,n);
  424. module:=amodule;
  425. end;
  426. constructor tunitsym.ppuload(ppufile:tcompilerppufile);
  427. begin
  428. inherited ppuload(unitsym,ppufile);
  429. module:=nil;
  430. end;
  431. destructor tunitsym.destroy;
  432. begin
  433. inherited destroy;
  434. end;
  435. procedure tunitsym.ppuwrite(ppufile:tcompilerppufile);
  436. begin
  437. inherited ppuwrite(ppufile);
  438. ppufile.writeentry(ibunitsym);
  439. end;
  440. {****************************************************************************
  441. TNAMESPACESYM
  442. ****************************************************************************}
  443. constructor tnamespacesym.create(const n : string);
  444. begin
  445. inherited create(namespacesym,n);
  446. unitsym:=nil;
  447. end;
  448. constructor tnamespacesym.ppuload(ppufile:tcompilerppufile);
  449. begin
  450. inherited ppuload(namespacesym,ppufile);
  451. ppufile.getderef(unitsymderef);
  452. end;
  453. procedure tnamespacesym.ppuwrite(ppufile:tcompilerppufile);
  454. begin
  455. inherited ppuwrite(ppufile);
  456. ppufile.putderef(unitsymderef);
  457. ppufile.writeentry(ibnamespacesym);
  458. end;
  459. procedure tnamespacesym.buildderef;
  460. begin
  461. inherited buildderef;
  462. unitsymderef.build(unitsym);
  463. end;
  464. procedure tnamespacesym.deref;
  465. begin
  466. inherited deref;
  467. unitsym:=tsym(unitsymderef.resolve);
  468. end;
  469. {****************************************************************************
  470. TPROCSYM
  471. ****************************************************************************}
  472. constructor tprocsym.create(const n : string);
  473. begin
  474. inherited create(procsym,n);
  475. FProcdefList:=TFPObjectList.Create(false);
  476. FProcdefderefList:=nil;
  477. { the tprocdef have their own symoptions, make the procsym
  478. always visible }
  479. visibility:=vis_public;
  480. end;
  481. constructor tprocsym.ppuload(ppufile:tcompilerppufile);
  482. var
  483. pdderef : tderef;
  484. i,
  485. pdcnt : longint;
  486. begin
  487. inherited ppuload(procsym,ppufile);
  488. FProcdefList:=TFPObjectList.Create(false);
  489. FProcdefDerefList:=TFPList.Create;
  490. pdcnt:=ppufile.getword;
  491. for i:=1 to pdcnt do
  492. begin
  493. ppufile.getderef(pdderef);
  494. FProcdefDerefList.Add(Pointer(PtrInt(pdderef.dataidx)));
  495. end;
  496. end;
  497. destructor tprocsym.destroy;
  498. begin
  499. FProcdefList.Free;
  500. if assigned(FProcdefDerefList) then
  501. FProcdefDerefList.Free;
  502. inherited destroy;
  503. end;
  504. procedure tprocsym.ppuwrite(ppufile:tcompilerppufile);
  505. var
  506. i : longint;
  507. d : tderef;
  508. begin
  509. inherited ppuwrite(ppufile);
  510. ppufile.putword(FProcdefDerefList.Count);
  511. for i:=0 to FProcdefDerefList.Count-1 do
  512. begin
  513. d.dataidx:=PtrInt(FProcdefDerefList[i]);
  514. ppufile.putderef(d);
  515. end;
  516. ppufile.writeentry(ibprocsym);
  517. end;
  518. procedure tprocsym.write_parameter_lists(skipdef:tprocdef);
  519. var
  520. i : longint;
  521. pd : tprocdef;
  522. begin
  523. for i:=0 to ProcdefList.Count-1 do
  524. begin
  525. pd:=tprocdef(ProcdefList[i]);
  526. if pd<>skipdef then
  527. MessagePos1(pd.fileinfo,sym_h_param_list,pd.fullprocname(false));
  528. end;
  529. end;
  530. procedure tprocsym.check_forward;
  531. var
  532. i : longint;
  533. pd : tprocdef;
  534. begin
  535. for i:=0 to ProcdefList.Count-1 do
  536. begin
  537. pd:=tprocdef(ProcdefList[i]);
  538. if (pd.owner=owner) and (pd.forwarddef) then
  539. begin
  540. { For mode macpas. Make implicit externals (procedures declared in the interface
  541. section which do not have a counterpart in the implementation)
  542. to be an imported procedure }
  543. if (m_mac in current_settings.modeswitches) and
  544. (pd.interfacedef) then
  545. begin
  546. pd.setmangledname(target_info.CPrefix+tprocdef(pd).procsym.realname);
  547. if (not current_module.interface_only) then
  548. MessagePos1(pd.fileinfo,sym_w_forward_not_resolved,pd.fullprocname(false));
  549. end
  550. else
  551. begin
  552. MessagePos1(pd.fileinfo,sym_e_forward_not_resolved,pd.fullprocname(false));
  553. end;
  554. { Turn further error messages off }
  555. pd.forwarddef:=false;
  556. end;
  557. end;
  558. end;
  559. procedure tprocsym.buildderef;
  560. var
  561. i : longint;
  562. pd : tprocdef;
  563. d : tderef;
  564. begin
  565. if not assigned(FProcdefDerefList) then
  566. FProcdefDerefList:=TFPList.Create
  567. else
  568. FProcdefDerefList.Clear;
  569. for i:=0 to ProcdefList.Count-1 do
  570. begin
  571. pd:=tprocdef(ProcdefList[i]);
  572. { only write the proc definitions that belong
  573. to this procsym and are in the global symtable }
  574. if pd.owner=owner then
  575. begin
  576. d.build(pd);
  577. FProcdefDerefList.Add(Pointer(PtrInt(d.dataidx)));
  578. end;
  579. end;
  580. end;
  581. procedure tprocsym.deref;
  582. var
  583. i : longint;
  584. pd : tprocdef;
  585. d : tderef;
  586. begin
  587. { Clear all procdefs }
  588. ProcdefList.Clear;
  589. if not assigned(FProcdefDerefList) then
  590. internalerror(200611031);
  591. for i:=0 to FProcdefDerefList.Count-1 do
  592. begin
  593. d.dataidx:=PtrInt(FProcdefDerefList[i]);
  594. pd:=tprocdef(d.resolve);
  595. ProcdefList.Add(pd);
  596. end;
  597. end;
  598. function Tprocsym.Find_procdef_bytype(pt:Tproctypeoption):Tprocdef;
  599. var
  600. i : longint;
  601. pd : tprocdef;
  602. begin
  603. result:=nil;
  604. for i:=0 to ProcdefList.Count-1 do
  605. begin
  606. pd:=tprocdef(ProcdefList[i]);
  607. if pd.proctypeoption=pt then
  608. begin
  609. result:=pd;
  610. exit;
  611. end;
  612. end;
  613. end;
  614. function Tprocsym.Find_procdef_bypara(para:TFPObjectList;retdef:tdef;
  615. cpoptions:tcompare_paras_options):Tprocdef;
  616. var
  617. i : longint;
  618. pd : tprocdef;
  619. eq : tequaltype;
  620. begin
  621. result:=nil;
  622. for i:=0 to ProcdefList.Count-1 do
  623. begin
  624. pd:=tprocdef(ProcdefList[i]);
  625. if assigned(retdef) then
  626. eq:=compare_defs(retdef,pd.returndef,nothingn)
  627. else
  628. eq:=te_equal;
  629. if (eq>=te_equal) or
  630. ((cpo_allowconvert in cpoptions) and (eq>te_incompatible)) then
  631. begin
  632. eq:=compare_paras(para,pd.paras,cp_value_equal_const,cpoptions);
  633. if (eq>=te_equal) or
  634. ((cpo_allowconvert in cpoptions) and (eq>te_incompatible)) then
  635. begin
  636. result:=pd;
  637. exit;
  638. end;
  639. end;
  640. end;
  641. end;
  642. function tprocsym.find_procdef_byoptions(ops: tprocoptions): Tprocdef;
  643. var
  644. i : longint;
  645. pd : tprocdef;
  646. begin
  647. result:=nil;
  648. for i:=0 to ProcdefList.Count-1 do
  649. begin
  650. pd:=tprocdef(ProcdefList[i]);
  651. if ops * pd.procoptions = ops then
  652. begin
  653. result:=pd;
  654. exit;
  655. end;
  656. end;
  657. end;
  658. function Tprocsym.Find_procdef_byprocvardef(d:Tprocvardef):Tprocdef;
  659. var
  660. i : longint;
  661. bestpd,
  662. pd : tprocdef;
  663. eq,besteq : tequaltype;
  664. begin
  665. { This function will return the pprocdef of pprocsym that
  666. is the best match for procvardef. When there are multiple
  667. matches it returns nil.}
  668. result:=nil;
  669. bestpd:=nil;
  670. besteq:=te_incompatible;
  671. for i:=0 to ProcdefList.Count-1 do
  672. begin
  673. pd:=tprocdef(ProcdefList[i]);
  674. eq:=proc_to_procvar_equal(pd,d,false);
  675. if eq>=te_convert_l1 then
  676. begin
  677. { multiple procvars with the same equal level }
  678. if assigned(bestpd) and
  679. (besteq=eq) then
  680. exit;
  681. if eq>besteq then
  682. begin
  683. besteq:=eq;
  684. bestpd:=pd;
  685. end;
  686. end;
  687. end;
  688. result:=bestpd;
  689. end;
  690. function Tprocsym.Find_procdef_assignment_operator(fromdef,todef:tdef;var besteq:tequaltype):Tprocdef;
  691. var
  692. paraidx, realparamcount,
  693. i, j : longint;
  694. bestpd,
  695. hpd,
  696. pd : tprocdef;
  697. convtyp : tconverttype;
  698. eq : tequaltype;
  699. begin
  700. { This function will return the pprocdef of pprocsym that
  701. is the best match for fromdef and todef. }
  702. result:=nil;
  703. bestpd:=nil;
  704. besteq:=te_incompatible;
  705. for i:=0 to ProcdefList.Count-1 do
  706. begin
  707. pd:=tprocdef(ProcdefList[i]);
  708. if (pd.owner.symtabletype=staticsymtable) and not pd.owner.iscurrentunit then
  709. continue;
  710. if (equal_defs(todef,pd.returndef) or
  711. { shortstrings of different lengths are ok as result }
  712. (is_shortstring(todef) and is_shortstring(pd.returndef))) and
  713. { the result type must be always really equal and not an alias,
  714. if you mess with this code, check tw4093 }
  715. ((todef=pd.returndef) or
  716. (
  717. not(df_unique in todef.defoptions) and
  718. not(df_unique in pd.returndef.defoptions)
  719. )
  720. ) then
  721. begin
  722. paraidx:=0;
  723. { ignore vs_hidden parameters }
  724. while (paraidx<pd.paras.count) and
  725. assigned(pd.paras[paraidx]) and
  726. (vo_is_hidden_para in tparavarsym(pd.paras[paraidx]).varoptions) do
  727. inc(paraidx);
  728. realparamcount:=0;
  729. for j := 0 to pd.paras.Count-1 do
  730. if assigned(pd.paras[j]) and not (vo_is_hidden_para in tparavarsym(pd.paras[j]).varoptions) then
  731. inc(realparamcount);
  732. if (paraidx<pd.paras.count) and
  733. assigned(pd.paras[paraidx]) and
  734. (realparamcount = 1) then
  735. begin
  736. eq:=compare_defs_ext(fromdef,tparavarsym(pd.paras[paraidx]).vardef,nothingn,convtyp,hpd,[]);
  737. { alias? if yes, only l1 choice,
  738. if you mess with this code, check tw4093 }
  739. if (eq=te_exact) and
  740. (fromdef<>tparavarsym(pd.paras[paraidx]).vardef) and
  741. ((df_unique in fromdef.defoptions) or
  742. (df_unique in tparavarsym(pd.paras[paraidx]).vardef.defoptions)) then
  743. eq:=te_convert_l1;
  744. if eq=te_exact then
  745. begin
  746. besteq:=eq;
  747. result:=pd;
  748. exit;
  749. end;
  750. if eq>besteq then
  751. begin
  752. bestpd:=pd;
  753. besteq:=eq;
  754. end;
  755. end;
  756. end;
  757. end;
  758. result:=bestpd;
  759. end;
  760. function Tprocsym.find_procdef_enumerator_operator(fromdef,todef:tdef;var besteq:tequaltype):Tprocdef;
  761. var
  762. paraidx, realparamcount,
  763. i, j : longint;
  764. bestpd,
  765. hpd,
  766. pd : tprocdef;
  767. current : tpropertysym;
  768. convtyp : tconverttype;
  769. eq : tequaltype;
  770. begin
  771. { This function will return the pprocdef of pprocsym that
  772. is the best match for fromdef and todef. }
  773. result:=nil;
  774. bestpd:=nil;
  775. besteq:=te_incompatible;
  776. for i:=0 to ProcdefList.Count-1 do
  777. begin
  778. pd:=tprocdef(ProcdefList[i]);
  779. if (pd.owner.symtabletype=staticsymtable) and not pd.owner.iscurrentunit then
  780. continue;
  781. if not (is_class_or_interface_or_object(pd.returndef) or is_record(pd.returndef)) then
  782. continue;
  783. current := tpropertysym(tabstractrecorddef(pd.returndef).search_enumerator_current);
  784. if (current = nil) then
  785. continue;
  786. // compare current result def with the todef
  787. if (equal_defs(todef, current.propdef) or
  788. { shortstrings of different lengths are ok as result }
  789. (is_shortstring(todef) and is_shortstring(current.propdef))) and
  790. { the result type must be always really equal and not an alias,
  791. if you mess with this code, check tw4093 }
  792. ((todef=current.propdef) or
  793. (
  794. not(df_unique in todef.defoptions) and
  795. not(df_unique in current.propdef.defoptions)
  796. )
  797. ) then
  798. begin
  799. paraidx:=0;
  800. { ignore vs_hidden parameters }
  801. while (paraidx<pd.paras.count) and
  802. assigned(pd.paras[paraidx]) and
  803. (vo_is_hidden_para in tparavarsym(pd.paras[paraidx]).varoptions) do
  804. inc(paraidx);
  805. realparamcount:=0;
  806. for j := 0 to pd.paras.Count-1 do
  807. if assigned(pd.paras[j]) and not (vo_is_hidden_para in tparavarsym(pd.paras[j]).varoptions) then
  808. inc(realparamcount);
  809. if (paraidx<pd.paras.count) and
  810. assigned(pd.paras[paraidx]) and
  811. (realparamcount = 1) then
  812. begin
  813. eq:=compare_defs_ext(fromdef,tparavarsym(pd.paras[paraidx]).vardef,nothingn,convtyp,hpd,[]);
  814. { alias? if yes, only l1 choice,
  815. if you mess with this code, check tw4093 }
  816. if (eq=te_exact) and
  817. (fromdef<>tparavarsym(pd.paras[paraidx]).vardef) and
  818. ((df_unique in fromdef.defoptions) or
  819. (df_unique in tparavarsym(pd.paras[paraidx]).vardef.defoptions)) then
  820. eq:=te_convert_l1;
  821. if eq=te_exact then
  822. begin
  823. besteq:=eq;
  824. result:=pd;
  825. exit;
  826. end;
  827. if eq>besteq then
  828. begin
  829. bestpd:=pd;
  830. besteq:=eq;
  831. end;
  832. end;
  833. end;
  834. end;
  835. result:=bestpd;
  836. end;
  837. {****************************************************************************
  838. TERRORSYM
  839. ****************************************************************************}
  840. constructor terrorsym.create;
  841. begin
  842. inherited create(errorsym,'');
  843. end;
  844. {****************************************************************************
  845. TPROPERTYSYM
  846. ****************************************************************************}
  847. constructor tpropertysym.create(const n : string);
  848. var
  849. pap : tpropaccesslisttypes;
  850. begin
  851. inherited create(propertysym,n);
  852. propoptions:=[];
  853. index:=0;
  854. default:=0;
  855. propdef:=nil;
  856. indexdef:=nil;
  857. parast:=nil;
  858. for pap:=low(tpropaccesslisttypes) to high(tpropaccesslisttypes) do
  859. propaccesslist[pap]:=tpropaccesslist.create;
  860. end;
  861. constructor tpropertysym.ppuload(ppufile:tcompilerppufile);
  862. var
  863. pap : tpropaccesslisttypes;
  864. begin
  865. inherited ppuload(propertysym,ppufile);
  866. ppufile.getsmallset(propoptions);
  867. if ppo_overrides in propoptions then
  868. ppufile.getderef(overriddenpropsymderef);
  869. ppufile.getderef(propdefderef);
  870. index:=ppufile.getlongint;
  871. default:=ppufile.getlongint;
  872. ppufile.getderef(indexdefderef);
  873. for pap:=low(tpropaccesslisttypes) to high(tpropaccesslisttypes) do
  874. propaccesslist[pap]:=ppufile.getpropaccesslist;
  875. if [ppo_hasparameters,ppo_overrides]*propoptions=[ppo_hasparameters] then
  876. begin
  877. parast:=tparasymtable.create(nil,0);
  878. tparasymtable(parast).ppuload(ppufile);
  879. end
  880. else
  881. parast:=nil;
  882. end;
  883. destructor tpropertysym.destroy;
  884. var
  885. pap : tpropaccesslisttypes;
  886. begin
  887. for pap:=low(tpropaccesslisttypes) to high(tpropaccesslisttypes) do
  888. propaccesslist[pap].free;
  889. parast.free;
  890. inherited destroy;
  891. end;
  892. procedure tpropertysym.buildderef;
  893. var
  894. pap : tpropaccesslisttypes;
  895. begin
  896. propdefderef.build(propdef);
  897. indexdefderef.build(indexdef);
  898. for pap:=low(tpropaccesslisttypes) to high(tpropaccesslisttypes) do
  899. propaccesslist[pap].buildderef;
  900. if ppo_overrides in propoptions then
  901. overriddenpropsymderef.build(overriddenpropsym)
  902. else
  903. if ppo_hasparameters in propoptions then
  904. tparasymtable(parast).buildderef;
  905. end;
  906. procedure tpropertysym.deref;
  907. var
  908. pap : tpropaccesslisttypes;
  909. begin
  910. indexdef:=tdef(indexdefderef.resolve);
  911. propdef:=tdef(propdefderef.resolve);
  912. for pap:=low(tpropaccesslisttypes) to high(tpropaccesslisttypes) do
  913. propaccesslist[pap].resolve;
  914. if ppo_overrides in propoptions then
  915. begin
  916. overriddenpropsym:=tpropertysym(overriddenpropsymderef.resolve);
  917. if ppo_hasparameters in propoptions then
  918. parast:=overriddenpropsym.parast.getcopy;
  919. end
  920. else
  921. if ppo_hasparameters in propoptions then
  922. tparasymtable(parast).deref
  923. end;
  924. function tpropertysym.getsize : asizeint;
  925. begin
  926. getsize:=0;
  927. end;
  928. procedure tpropertysym.ppuwrite(ppufile:tcompilerppufile);
  929. var
  930. pap : tpropaccesslisttypes;
  931. begin
  932. inherited ppuwrite(ppufile);
  933. ppufile.putsmallset(propoptions);
  934. if ppo_overrides in propoptions then
  935. ppufile.putderef(overriddenpropsymderef);
  936. ppufile.putderef(propdefderef);
  937. ppufile.putlongint(index);
  938. ppufile.putlongint(default);
  939. ppufile.putderef(indexdefderef);
  940. for pap:=low(tpropaccesslisttypes) to high(tpropaccesslisttypes) do
  941. ppufile.putpropaccesslist(propaccesslist[pap]);
  942. ppufile.writeentry(ibpropertysym);
  943. if [ppo_hasparameters,ppo_overrides]*propoptions=[ppo_hasparameters] then
  944. tparasymtable(parast).ppuwrite(ppufile);
  945. end;
  946. {****************************************************************************
  947. TABSTRACTVARSYM
  948. ****************************************************************************}
  949. constructor tabstractvarsym.create(st:tsymtyp;const n : string;vsp:tvarspez;def:tdef;vopts:tvaroptions);
  950. begin
  951. inherited create(st,n);
  952. vardef:=def;
  953. varspez:=vsp;
  954. varstate:=vs_declared;
  955. varoptions:=vopts;
  956. end;
  957. constructor tabstractvarsym.ppuload(st:tsymtyp;ppufile:tcompilerppufile);
  958. begin
  959. inherited ppuload(st,ppufile);
  960. varstate:=vs_readwritten;
  961. varspez:=tvarspez(ppufile.getbyte);
  962. varregable:=tvarregable(ppufile.getbyte);
  963. addr_taken:=boolean(ppufile.getbyte);
  964. ppufile.getderef(vardefderef);
  965. ppufile.getsmallset(varoptions);
  966. end;
  967. destructor tabstractvarsym.destroy;
  968. begin
  969. if assigned(notifications) then
  970. notifications.destroy;
  971. inherited destroy;
  972. end;
  973. procedure tabstractvarsym.buildderef;
  974. begin
  975. vardefderef.build(vardef);
  976. end;
  977. procedure tabstractvarsym.deref;
  978. var
  979. oldvarregable: tvarregable;
  980. begin
  981. { setting the vardef also updates varregable. We just loaded this }
  982. { value from a ppu, so it must not be changed (e.g. tw7817a.pp/ }
  983. { tw7817b.pp: the address is taken of a local variable in an }
  984. { inlined procedure -> must remain non-regable when inlining) }
  985. oldvarregable:=varregable;
  986. vardef:=tdef(vardefderef.resolve);
  987. varregable:=oldvarregable;
  988. end;
  989. procedure tabstractvarsym.ppuwrite(ppufile:tcompilerppufile);
  990. var
  991. oldintfcrc : boolean;
  992. begin
  993. inherited ppuwrite(ppufile);
  994. ppufile.putbyte(byte(varspez));
  995. oldintfcrc:=ppufile.do_crc;
  996. ppufile.do_crc:=false;
  997. ppufile.putbyte(byte(varregable));
  998. ppufile.putbyte(byte(addr_taken));
  999. ppufile.do_crc:=oldintfcrc;
  1000. ppufile.putderef(vardefderef);
  1001. ppufile.putsmallset(varoptions);
  1002. end;
  1003. function tabstractvarsym.getsize : asizeint;
  1004. begin
  1005. if assigned(vardef) and
  1006. ((vardef.typ<>arraydef) or
  1007. is_dynamic_array(vardef) or
  1008. (tarraydef(vardef).highrange>=tarraydef(vardef).lowrange)) then
  1009. result:=vardef.size
  1010. else
  1011. result:=0;
  1012. end;
  1013. function tabstractvarsym.getpackedbitsize : longint;
  1014. begin
  1015. { bitpacking is only done for ordinals }
  1016. if not is_ordinal(vardef) then
  1017. internalerror(2006082010);
  1018. result:=vardef.packedbitsize;
  1019. end;
  1020. function tabstractvarsym.is_regvar(refpara: boolean):boolean;
  1021. begin
  1022. { Register variables are not allowed in the following cases:
  1023. - regvars are disabled
  1024. - exceptions are used (after an exception is raised the contents of the
  1025. registers is not valid anymore)
  1026. - it has a local copy
  1027. - the value needs to be in memory (i.e. reference counted) }
  1028. result:=(cs_opt_regvar in current_settings.optimizerswitches) and
  1029. not(pi_has_assembler_block in current_procinfo.flags) and
  1030. not(pi_uses_exceptions in current_procinfo.flags) and
  1031. not(pi_has_interproclabel in current_procinfo.flags) and
  1032. not(vo_has_local_copy in varoptions) and
  1033. ((refpara and
  1034. (varregable <> vr_none)) or
  1035. (not refpara and
  1036. not(varregable in [vr_none,vr_addr])))
  1037. {$if not defined(powerpc) and not defined(powerpc64)}
  1038. and ((vardef.typ <> recorddef) or
  1039. (varregable = vr_addr) or
  1040. not(varstate in [vs_written,vs_readwritten]));
  1041. {$endif}
  1042. end;
  1043. procedure tabstractvarsym.trigger_notifications(what:Tnotification_flag);
  1044. var n:Tnotification;
  1045. begin
  1046. if assigned(notifications) then
  1047. begin
  1048. n:=Tnotification(notifications.first);
  1049. while assigned(n) do
  1050. begin
  1051. if what in n.flags then
  1052. n.callback(what,self);
  1053. n:=Tnotification(n.next);
  1054. end;
  1055. end;
  1056. end;
  1057. function Tabstractvarsym.register_notification(flags:Tnotification_flags;callback:
  1058. Tnotification_callback):cardinal;
  1059. var n:Tnotification;
  1060. begin
  1061. if not assigned(notifications) then
  1062. notifications:=Tlinkedlist.create;
  1063. n:=Tnotification.create(flags,callback);
  1064. register_notification:=n.id;
  1065. notifications.concat(n);
  1066. end;
  1067. procedure Tabstractvarsym.unregister_notification(id:cardinal);
  1068. var n:Tnotification;
  1069. begin
  1070. if not assigned(notifications) then
  1071. internalerror(200212311)
  1072. else
  1073. begin
  1074. n:=Tnotification(notifications.first);
  1075. while assigned(n) do
  1076. begin
  1077. if n.id=id then
  1078. begin
  1079. notifications.remove(n);
  1080. n.destroy;
  1081. exit;
  1082. end;
  1083. n:=Tnotification(n.next);
  1084. end;
  1085. internalerror(200212311)
  1086. end;
  1087. end;
  1088. procedure tabstractvarsym.setvardef(def:tdef);
  1089. begin
  1090. _vardef := def;
  1091. { can we load the value into a register ? }
  1092. if not assigned(owner) or
  1093. (owner.symtabletype in [localsymtable,parasymtable]) or
  1094. (
  1095. (owner.symtabletype=staticsymtable) and
  1096. not(cs_create_pic in current_settings.moduleswitches)
  1097. ) then
  1098. begin
  1099. if tstoreddef(vardef).is_intregable then
  1100. varregable:=vr_intreg
  1101. else
  1102. { $warning TODO: no fpu regvar in staticsymtable yet, need initialization with 0 }
  1103. if {(
  1104. not assigned(owner) or
  1105. (owner.symtabletype<>staticsymtable)
  1106. ) and }
  1107. tstoreddef(vardef).is_fpuregable then
  1108. begin
  1109. if use_vectorfpu(vardef) then
  1110. varregable:=vr_mmreg
  1111. else
  1112. varregable:=vr_fpureg;
  1113. end;
  1114. end;
  1115. end;
  1116. {****************************************************************************
  1117. TFIELDVARSYM
  1118. ****************************************************************************}
  1119. constructor tfieldvarsym.create(const n : string;vsp:tvarspez;def:tdef;vopts:tvaroptions);
  1120. begin
  1121. inherited create(fieldvarsym,n,vsp,def,vopts);
  1122. fieldoffset:=-1;
  1123. end;
  1124. constructor tfieldvarsym.ppuload(ppufile:tcompilerppufile);
  1125. begin
  1126. inherited ppuload(fieldvarsym,ppufile);
  1127. fieldoffset:=ppufile.getaint;
  1128. end;
  1129. procedure tfieldvarsym.ppuwrite(ppufile:tcompilerppufile);
  1130. begin
  1131. inherited ppuwrite(ppufile);
  1132. ppufile.putaint(fieldoffset);
  1133. ppufile.writeentry(ibfieldvarsym);
  1134. end;
  1135. function tfieldvarsym.mangledname:string;
  1136. var
  1137. srsym : tsym;
  1138. srsymtable : tsymtable;
  1139. begin
  1140. if sp_static in symoptions then
  1141. begin
  1142. if searchsym(lower(owner.name^)+'_'+name,srsym,srsymtable) then
  1143. result:=srsym.mangledname
  1144. { when generating the debug info for the module in which the }
  1145. { symbol is defined, the localsymtable of that module is }
  1146. { already popped from the symtablestack }
  1147. else if searchsym_in_module(current_module,lower(owner.name^)+'_'+name,srsym,srsymtable) then
  1148. result:=srsym.mangledname
  1149. else
  1150. internalerror(2007012501);
  1151. end
  1152. else if is_objcclass(tdef(owner.defowner)) then
  1153. begin
  1154. if assigned(objcoffsetmangledname) then
  1155. result:=objcoffsetmangledname^
  1156. else
  1157. begin
  1158. result:=target_info.cprefix+'OBJC_IVAR_$_'+tobjectdef(owner.defowner).objextname^+'.'+RealName;
  1159. objcoffsetmangledname:=stringdup(result);
  1160. end;
  1161. end
  1162. else
  1163. result:=inherited mangledname;
  1164. end;
  1165. destructor tfieldvarsym.destroy;
  1166. begin
  1167. stringdispose(objcoffsetmangledname);
  1168. inherited destroy;
  1169. end;
  1170. {****************************************************************************
  1171. TABSTRACTNORMALVARSYM
  1172. ****************************************************************************}
  1173. constructor tabstractnormalvarsym.create(st:tsymtyp;const n : string;vsp:tvarspez;def:tdef;vopts:tvaroptions);
  1174. begin
  1175. inherited create(st,n,vsp,def,vopts);
  1176. fillchar(localloc,sizeof(localloc),0);
  1177. fillchar(initialloc,sizeof(initialloc),0);
  1178. defaultconstsym:=nil;
  1179. end;
  1180. constructor tabstractnormalvarsym.ppuload(st:tsymtyp;ppufile:tcompilerppufile);
  1181. begin
  1182. inherited ppuload(st,ppufile);
  1183. fillchar(localloc,sizeof(localloc),0);
  1184. fillchar(initialloc,sizeof(initialloc),0);
  1185. ppufile.getderef(defaultconstsymderef);
  1186. end;
  1187. procedure tabstractnormalvarsym.buildderef;
  1188. begin
  1189. inherited buildderef;
  1190. defaultconstsymderef.build(defaultconstsym);
  1191. end;
  1192. procedure tabstractnormalvarsym.deref;
  1193. begin
  1194. inherited deref;
  1195. defaultconstsym:=tsym(defaultconstsymderef.resolve);
  1196. end;
  1197. procedure tabstractnormalvarsym.ppuwrite(ppufile:tcompilerppufile);
  1198. begin
  1199. inherited ppuwrite(ppufile);
  1200. ppufile.putderef(defaultconstsymderef);
  1201. end;
  1202. {****************************************************************************
  1203. Tstaticvarsym
  1204. ****************************************************************************}
  1205. constructor tstaticvarsym.create(const n : string;vsp:tvarspez;def:tdef;vopts:tvaroptions);
  1206. begin
  1207. inherited create(staticvarsym,n,vsp,def,vopts);
  1208. _mangledname:=nil;
  1209. end;
  1210. constructor tstaticvarsym.create_dll(const n : string;vsp:tvarspez;def:tdef);
  1211. begin
  1212. tstaticvarsym(self).create(n,vsp,def,[vo_is_dll_var]);
  1213. end;
  1214. constructor tstaticvarsym.create_C(const n,mangled : string;vsp:tvarspez;def:tdef);
  1215. begin
  1216. tstaticvarsym(self).create(n,vsp,def,[]);
  1217. set_mangledname(mangled);
  1218. end;
  1219. constructor tstaticvarsym.ppuload(ppufile:tcompilerppufile);
  1220. begin
  1221. inherited ppuload(staticvarsym,ppufile);
  1222. if vo_has_mangledname in varoptions then
  1223. _mangledname:=stringdup(ppufile.getstring)
  1224. else
  1225. _mangledname:=nil;
  1226. if vo_has_section in varoptions then
  1227. section:=ppufile.getansistring;
  1228. end;
  1229. destructor tstaticvarsym.destroy;
  1230. begin
  1231. if assigned(_mangledname) then
  1232. begin
  1233. {$ifdef MEMDEBUG}
  1234. memmanglednames.start;
  1235. {$endif MEMDEBUG}
  1236. stringdispose(_mangledname);
  1237. {$ifdef MEMDEBUG}
  1238. memmanglednames.stop;
  1239. {$endif MEMDEBUG}
  1240. end;
  1241. inherited destroy;
  1242. end;
  1243. procedure tstaticvarsym.ppuwrite(ppufile:tcompilerppufile);
  1244. begin
  1245. inherited ppuwrite(ppufile);
  1246. if vo_has_mangledname in varoptions then
  1247. ppufile.putstring(_mangledname^);
  1248. if vo_has_section in varoptions then
  1249. ppufile.putansistring(section);
  1250. ppufile.writeentry(ibstaticvarsym);
  1251. end;
  1252. function tstaticvarsym.mangledname:string;
  1253. var
  1254. prefix : string[2];
  1255. begin
  1256. if not assigned(_mangledname) then
  1257. begin
  1258. if (vo_is_typed_const in varoptions) then
  1259. prefix:='TC'
  1260. else
  1261. prefix:='U';
  1262. {$ifdef compress}
  1263. _mangledname:=stringdup(minilzw_encode(make_mangledname(prefix,owner,name)));
  1264. {$else}
  1265. _mangledname:=stringdup(make_mangledname(prefix,owner,name));
  1266. {$endif}
  1267. end;
  1268. result:=_mangledname^;
  1269. end;
  1270. procedure tstaticvarsym.set_mangledname(const s:string);
  1271. begin
  1272. stringdispose(_mangledname);
  1273. {$ifdef compress}
  1274. _mangledname:=stringdup(minilzw_encode(s));
  1275. {$else}
  1276. _mangledname:=stringdup(s);
  1277. {$endif}
  1278. include(varoptions,vo_has_mangledname);
  1279. end;
  1280. {****************************************************************************
  1281. TLOCALVARSYM
  1282. ****************************************************************************}
  1283. constructor tlocalvarsym.create(const n : string;vsp:tvarspez;def:tdef;vopts:tvaroptions);
  1284. begin
  1285. inherited create(localvarsym,n,vsp,def,vopts);
  1286. end;
  1287. constructor tlocalvarsym.ppuload(ppufile:tcompilerppufile);
  1288. begin
  1289. inherited ppuload(localvarsym,ppufile);
  1290. end;
  1291. procedure tlocalvarsym.ppuwrite(ppufile:tcompilerppufile);
  1292. begin
  1293. inherited ppuwrite(ppufile);
  1294. ppufile.writeentry(iblocalvarsym);
  1295. end;
  1296. {****************************************************************************
  1297. TPARAVARSYM
  1298. ****************************************************************************}
  1299. constructor tparavarsym.create(const n : string;nr:word;vsp:tvarspez;def:tdef;vopts:tvaroptions);
  1300. begin
  1301. inherited create(paravarsym,n,vsp,def,vopts);
  1302. if (vsp in [vs_var,vs_value,vs_const,vs_constref]) then
  1303. varstate := vs_initialised;
  1304. paranr:=nr;
  1305. paraloc[calleeside].init;
  1306. paraloc[callerside].init;
  1307. end;
  1308. destructor tparavarsym.destroy;
  1309. begin
  1310. paraloc[calleeside].done;
  1311. paraloc[callerside].done;
  1312. inherited destroy;
  1313. end;
  1314. constructor tparavarsym.ppuload(ppufile:tcompilerppufile);
  1315. var
  1316. b : byte;
  1317. begin
  1318. inherited ppuload(paravarsym,ppufile);
  1319. paranr:=ppufile.getword;
  1320. univpara:=boolean(ppufile.getbyte);
  1321. { The var state of parameter symbols is fixed after writing them so
  1322. we write them to the unit file.
  1323. This enables constant folding for inline procedures loaded from units
  1324. }
  1325. varstate:=tvarstate(ppufile.getbyte);
  1326. paraloc[calleeside].init;
  1327. paraloc[callerside].init;
  1328. if vo_has_explicit_paraloc in varoptions then
  1329. begin
  1330. paraloc[callerside].alignment:=ppufile.getbyte;
  1331. b:=ppufile.getbyte;
  1332. if b<>sizeof(paraloc[callerside].location^) then
  1333. internalerror(200411154);
  1334. ppufile.getdata(paraloc[callerside].add_location^,sizeof(paraloc[callerside].location^));
  1335. paraloc[callerside].size:=paraloc[callerside].location^.size;
  1336. paraloc[callerside].intsize:=tcgsize2size[paraloc[callerside].size];
  1337. end;
  1338. end;
  1339. procedure tparavarsym.ppuwrite(ppufile:tcompilerppufile);
  1340. var
  1341. oldintfcrc : boolean;
  1342. begin
  1343. inherited ppuwrite(ppufile);
  1344. ppufile.putword(paranr);
  1345. ppufile.putbyte(byte(univpara));
  1346. { The var state of parameter symbols is fixed after writing them so
  1347. we write them to the unit file.
  1348. This enables constant folding for inline procedures loaded from units
  1349. }
  1350. oldintfcrc:=ppufile.do_crc;
  1351. ppufile.do_crc:=false;
  1352. ppufile.putbyte(ord(varstate));
  1353. ppufile.do_crc:=oldintfcrc;
  1354. if vo_has_explicit_paraloc in varoptions then
  1355. begin
  1356. paraloc[callerside].check_simple_location;
  1357. ppufile.putbyte(sizeof(paraloc[callerside].alignment));
  1358. ppufile.putbyte(sizeof(paraloc[callerside].location^));
  1359. ppufile.putdata(paraloc[callerside].location^,sizeof(paraloc[callerside].location^));
  1360. end;
  1361. ppufile.writeentry(ibparavarsym);
  1362. end;
  1363. {****************************************************************************
  1364. TABSOLUTEVARSYM
  1365. ****************************************************************************}
  1366. constructor tabsolutevarsym.create(const n : string;def:tdef);
  1367. begin
  1368. inherited create(absolutevarsym,n,vs_value,def,[]);
  1369. ref:=nil;
  1370. end;
  1371. constructor tabsolutevarsym.create_ref(const n : string;def:tdef;_ref:tpropaccesslist);
  1372. begin
  1373. inherited create(absolutevarsym,n,vs_value,def,[]);
  1374. ref:=_ref;
  1375. end;
  1376. destructor tabsolutevarsym.destroy;
  1377. begin
  1378. if assigned(ref) then
  1379. ref.free;
  1380. inherited destroy;
  1381. end;
  1382. constructor tabsolutevarsym.ppuload(ppufile:tcompilerppufile);
  1383. begin
  1384. inherited ppuload(absolutevarsym,ppufile);
  1385. ref:=nil;
  1386. asmname:=nil;
  1387. abstyp:=absolutetyp(ppufile.getbyte);
  1388. {$ifdef i386}
  1389. absseg:=false;
  1390. {$endif i386}
  1391. case abstyp of
  1392. tovar :
  1393. ref:=ppufile.getpropaccesslist;
  1394. toasm :
  1395. asmname:=stringdup(ppufile.getstring);
  1396. toaddr :
  1397. begin
  1398. addroffset:=ppufile.getaword;
  1399. {$ifdef i386}
  1400. absseg:=boolean(ppufile.getbyte);
  1401. {$endif i386}
  1402. end;
  1403. end;
  1404. end;
  1405. procedure tabsolutevarsym.ppuwrite(ppufile:tcompilerppufile);
  1406. begin
  1407. inherited ppuwrite(ppufile);
  1408. ppufile.putbyte(byte(abstyp));
  1409. case abstyp of
  1410. tovar :
  1411. ppufile.putpropaccesslist(ref);
  1412. toasm :
  1413. ppufile.putstring(asmname^);
  1414. toaddr :
  1415. begin
  1416. ppufile.putaword(addroffset);
  1417. {$ifdef i386}
  1418. ppufile.putbyte(byte(absseg));
  1419. {$endif i386}
  1420. end;
  1421. end;
  1422. ppufile.writeentry(ibabsolutevarsym);
  1423. end;
  1424. procedure tabsolutevarsym.buildderef;
  1425. begin
  1426. inherited buildderef;
  1427. if (abstyp=tovar) then
  1428. ref.buildderef;
  1429. end;
  1430. procedure tabsolutevarsym.deref;
  1431. begin
  1432. inherited deref;
  1433. { own absolute deref }
  1434. if (abstyp=tovar) then
  1435. ref.resolve;
  1436. end;
  1437. function tabsolutevarsym.mangledname : string;
  1438. begin
  1439. case abstyp of
  1440. toasm :
  1441. mangledname:=asmname^;
  1442. toaddr :
  1443. mangledname:='$'+tostr(addroffset);
  1444. else
  1445. internalerror(200411062);
  1446. end;
  1447. end;
  1448. {****************************************************************************
  1449. TCONSTSYM
  1450. ****************************************************************************}
  1451. constructor tconstsym.create_ord(const n : string;t : tconsttyp;v : tconstexprint;def:tdef);
  1452. begin
  1453. inherited create(constsym,n);
  1454. fillchar(value, sizeof(value), #0);
  1455. consttyp:=t;
  1456. value.valueord:=v;
  1457. constdef:=def;
  1458. end;
  1459. constructor tconstsym.create_ordptr(const n : string;t : tconsttyp;v : tconstptruint;def:tdef);
  1460. begin
  1461. inherited create(constsym,n);
  1462. fillchar(value, sizeof(value), #0);
  1463. consttyp:=t;
  1464. value.valueordptr:=v;
  1465. constdef:=def;
  1466. end;
  1467. constructor tconstsym.create_ptr(const n : string;t : tconsttyp;v : pointer;def:tdef);
  1468. begin
  1469. inherited create(constsym,n);
  1470. fillchar(value, sizeof(value), #0);
  1471. consttyp:=t;
  1472. value.valueptr:=v;
  1473. constdef:=def;
  1474. end;
  1475. constructor tconstsym.create_string(const n : string;t : tconsttyp;str:pchar;l:longint);
  1476. begin
  1477. inherited create(constsym,n);
  1478. fillchar(value, sizeof(value), #0);
  1479. consttyp:=t;
  1480. value.valueptr:=str;
  1481. constdef:=nil;
  1482. value.len:=l;
  1483. end;
  1484. constructor tconstsym.create_wstring(const n : string;t : tconsttyp;pw:pcompilerwidestring);
  1485. begin
  1486. inherited create(constsym,n);
  1487. fillchar(value, sizeof(value), #0);
  1488. consttyp:=t;
  1489. pcompilerwidestring(value.valueptr):=pw;
  1490. constdef:=nil;
  1491. value.len:=getlengthwidestring(pw);
  1492. end;
  1493. constructor tconstsym.ppuload(ppufile:tcompilerppufile);
  1494. var
  1495. pd : pbestreal;
  1496. ps : pnormalset;
  1497. pc : pchar;
  1498. pw : pcompilerwidestring;
  1499. i : longint;
  1500. begin
  1501. inherited ppuload(constsym,ppufile);
  1502. constdef:=nil;
  1503. consttyp:=tconsttyp(ppufile.getbyte);
  1504. fillchar(value, sizeof(value), #0);
  1505. case consttyp of
  1506. constord :
  1507. begin
  1508. ppufile.getderef(constdefderef);
  1509. value.valueord:=ppufile.getexprint;
  1510. end;
  1511. constpointer :
  1512. begin
  1513. ppufile.getderef(constdefderef);
  1514. value.valueordptr:=ppufile.getptruint;
  1515. end;
  1516. constwstring :
  1517. begin
  1518. initwidestring(pw);
  1519. setlengthwidestring(pw,ppufile.getlongint);
  1520. { don't use getdata, because the compilerwidechars may have to
  1521. be byteswapped
  1522. }
  1523. {$if sizeof(tcompilerwidechar) = 2}
  1524. for i:=0 to pw^.len-1 do
  1525. pw^.data[i]:=ppufile.getword;
  1526. {$elseif sizeof(tcompilerwidechar) = 4}
  1527. for i:=0 to pw^.len-1 do
  1528. pw^.data[i]:=cardinal(ppufile.getlongint);
  1529. {$else}
  1530. {$error Unsupported tcompilerwidechar size}
  1531. {$endif}
  1532. pcompilerwidestring(value.valueptr):=pw;
  1533. end;
  1534. conststring,
  1535. constresourcestring :
  1536. begin
  1537. value.len:=ppufile.getlongint;
  1538. getmem(pc,value.len+1);
  1539. ppufile.getdata(pc^,value.len);
  1540. pc[value.len]:=#0;
  1541. value.valueptr:=pc;
  1542. end;
  1543. constreal :
  1544. begin
  1545. new(pd);
  1546. pd^:=ppufile.getreal;
  1547. value.valueptr:=pd;
  1548. end;
  1549. constset :
  1550. begin
  1551. ppufile.getderef(constdefderef);
  1552. new(ps);
  1553. ppufile.getnormalset(ps^);
  1554. value.valueptr:=ps;
  1555. end;
  1556. constguid :
  1557. begin
  1558. new(pguid(value.valueptr));
  1559. ppufile.getdata(value.valueptr^,sizeof(tguid));
  1560. end;
  1561. constnil : ;
  1562. else
  1563. Message1(unit_f_ppu_invalid_entry,tostr(ord(consttyp)));
  1564. end;
  1565. end;
  1566. destructor tconstsym.destroy;
  1567. begin
  1568. case consttyp of
  1569. conststring,
  1570. constresourcestring :
  1571. freemem(pchar(value.valueptr),value.len+1);
  1572. constwstring :
  1573. donewidestring(pcompilerwidestring(value.valueptr));
  1574. constreal :
  1575. dispose(pbestreal(value.valueptr));
  1576. constset :
  1577. dispose(pnormalset(value.valueptr));
  1578. constguid :
  1579. dispose(pguid(value.valueptr));
  1580. end;
  1581. inherited destroy;
  1582. end;
  1583. procedure tconstsym.buildderef;
  1584. begin
  1585. if consttyp in [constord,constpointer,constset] then
  1586. constdefderef.build(constdef);
  1587. end;
  1588. procedure tconstsym.deref;
  1589. begin
  1590. if consttyp in [constord,constpointer,constset] then
  1591. constdef:=tdef(constdefderef.resolve);
  1592. end;
  1593. procedure tconstsym.ppuwrite(ppufile:tcompilerppufile);
  1594. begin
  1595. inherited ppuwrite(ppufile);
  1596. ppufile.putbyte(byte(consttyp));
  1597. case consttyp of
  1598. constnil : ;
  1599. constord :
  1600. begin
  1601. ppufile.putderef(constdefderef);
  1602. ppufile.putexprint(value.valueord);
  1603. end;
  1604. constpointer :
  1605. begin
  1606. ppufile.putderef(constdefderef);
  1607. ppufile.putptruint(value.valueordptr);
  1608. end;
  1609. constwstring :
  1610. begin
  1611. ppufile.putlongint(getlengthwidestring(pcompilerwidestring(value.valueptr)));
  1612. ppufile.putdata(pcompilerwidestring(value.valueptr)^.data^,pcompilerwidestring(value.valueptr)^.len*sizeof(tcompilerwidechar));
  1613. end;
  1614. conststring,
  1615. constresourcestring :
  1616. begin
  1617. ppufile.putlongint(value.len);
  1618. ppufile.putdata(pchar(value.valueptr)^,value.len);
  1619. end;
  1620. constreal :
  1621. ppufile.putreal(pbestreal(value.valueptr)^);
  1622. constset :
  1623. begin
  1624. ppufile.putderef(constdefderef);
  1625. ppufile.putnormalset(value.valueptr^);
  1626. end;
  1627. constguid :
  1628. ppufile.putdata(value.valueptr^,sizeof(tguid));
  1629. else
  1630. internalerror(13);
  1631. end;
  1632. ppufile.writeentry(ibconstsym);
  1633. end;
  1634. {****************************************************************************
  1635. TENUMSYM
  1636. ****************************************************************************}
  1637. constructor tenumsym.create(const n : string;def : tenumdef;v : longint);
  1638. begin
  1639. inherited create(enumsym,n);
  1640. definition:=def;
  1641. value:=v;
  1642. end;
  1643. constructor tenumsym.ppuload(ppufile:tcompilerppufile);
  1644. begin
  1645. inherited ppuload(enumsym,ppufile);
  1646. ppufile.getderef(definitionderef);
  1647. value:=ppufile.getlongint;
  1648. end;
  1649. procedure tenumsym.buildderef;
  1650. begin
  1651. definitionderef.build(definition);
  1652. end;
  1653. procedure tenumsym.deref;
  1654. begin
  1655. definition:=tenumdef(definitionderef.resolve);
  1656. end;
  1657. procedure tenumsym.ppuwrite(ppufile:tcompilerppufile);
  1658. begin
  1659. inherited ppuwrite(ppufile);
  1660. ppufile.putderef(definitionderef);
  1661. ppufile.putlongint(value);
  1662. ppufile.writeentry(ibenumsym);
  1663. end;
  1664. {****************************************************************************
  1665. TTYPESYM
  1666. ****************************************************************************}
  1667. constructor ttypesym.create(const n : string;def:tdef);
  1668. begin
  1669. inherited create(typesym,n);
  1670. typedef:=def;
  1671. { register the typesym for the definition }
  1672. if assigned(typedef) and
  1673. (typedef.typ<>errordef) and
  1674. not(assigned(typedef.typesym)) then
  1675. typedef.typesym:=self;
  1676. end;
  1677. constructor ttypesym.ppuload(ppufile:tcompilerppufile);
  1678. begin
  1679. inherited ppuload(typesym,ppufile);
  1680. ppufile.getderef(typedefderef);
  1681. fprettyname:=ppufile.getansistring;
  1682. end;
  1683. procedure ttypesym.buildderef;
  1684. begin
  1685. typedefderef.build(typedef);
  1686. end;
  1687. procedure ttypesym.deref;
  1688. begin
  1689. typedef:=tdef(typedefderef.resolve);
  1690. end;
  1691. procedure ttypesym.ppuwrite(ppufile:tcompilerppufile);
  1692. begin
  1693. inherited ppuwrite(ppufile);
  1694. ppufile.putderef(typedefderef);
  1695. ppufile.putansistring(fprettyname);
  1696. ppufile.writeentry(ibtypesym);
  1697. end;
  1698. function ttypesym.prettyname : string;
  1699. begin
  1700. if fprettyname<>'' then
  1701. result:=fprettyname
  1702. else
  1703. result:=inherited prettyname;
  1704. end;
  1705. {****************************************************************************
  1706. TSYSSYM
  1707. ****************************************************************************}
  1708. constructor tsyssym.create(const n : string;l : longint);
  1709. begin
  1710. inherited create(syssym,n);
  1711. number:=l;
  1712. end;
  1713. constructor tsyssym.ppuload(ppufile:tcompilerppufile);
  1714. begin
  1715. inherited ppuload(syssym,ppufile);
  1716. number:=ppufile.getlongint;
  1717. end;
  1718. destructor tsyssym.destroy;
  1719. begin
  1720. inherited destroy;
  1721. end;
  1722. procedure tsyssym.ppuwrite(ppufile:tcompilerppufile);
  1723. begin
  1724. inherited ppuwrite(ppufile);
  1725. ppufile.putlongint(number);
  1726. ppufile.writeentry(ibsyssym);
  1727. end;
  1728. {*****************************************************************************
  1729. TMacro
  1730. *****************************************************************************}
  1731. constructor tmacro.create(const n : string);
  1732. begin
  1733. inherited create(macrosym,n);
  1734. owner:=nil;
  1735. defined:=false;
  1736. is_used:=false;
  1737. is_compiler_var:=false;
  1738. buftext:=nil;
  1739. buflen:=0;
  1740. end;
  1741. constructor tmacro.ppuload(ppufile:tcompilerppufile);
  1742. begin
  1743. inherited ppuload(macrosym,ppufile);
  1744. defined:=boolean(ppufile.getbyte);
  1745. is_compiler_var:=boolean(ppufile.getbyte);
  1746. is_used:=false;
  1747. buflen:= ppufile.getlongint;
  1748. if buflen > 0 then
  1749. begin
  1750. getmem(buftext, buflen);
  1751. ppufile.getdata(buftext^, buflen)
  1752. end
  1753. else
  1754. buftext:=nil;
  1755. end;
  1756. destructor tmacro.destroy;
  1757. begin
  1758. if assigned(buftext) then
  1759. freemem(buftext);
  1760. inherited destroy;
  1761. end;
  1762. procedure tmacro.ppuwrite(ppufile:tcompilerppufile);
  1763. begin
  1764. inherited ppuwrite(ppufile);
  1765. ppufile.putbyte(byte(defined));
  1766. ppufile.putbyte(byte(is_compiler_var));
  1767. ppufile.putlongint(buflen);
  1768. if buflen > 0 then
  1769. ppufile.putdata(buftext^,buflen);
  1770. ppufile.writeentry(ibmacrosym);
  1771. end;
  1772. function tmacro.GetCopy:tmacro;
  1773. var
  1774. p : tmacro;
  1775. begin
  1776. p:=tmacro.create(realname);
  1777. p.defined:=defined;
  1778. p.is_used:=is_used;
  1779. p.is_compiler_var:=is_compiler_var;
  1780. p.buflen:=buflen;
  1781. if assigned(buftext) then
  1782. begin
  1783. getmem(p.buftext,buflen);
  1784. move(buftext^,p.buftext^,buflen);
  1785. end;
  1786. Result:=p;
  1787. end;
  1788. end.