symsym.pas 68 KB

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