symsym.pas 69 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329
  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,
  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 : boolean;
  46. { points to the matching node, only valid resulttype pass is run and
  47. the goto<->label relation in the node tree is created, should
  48. be a tnode }
  49. code : pointer;
  50. { when the label is defined in an asm block, this points to the
  51. generated asmlabel }
  52. asmblocklabel : tasmlabel;
  53. constructor create(const n : string);
  54. constructor ppuload(ppufile:tcompilerppufile);
  55. procedure ppuwrite(ppufile:tcompilerppufile);override;
  56. end;
  57. tunitsym = class(Tstoredsym)
  58. module : tobject; { tmodule }
  59. constructor create(const n : string;amodule : tobject);
  60. constructor ppuload(ppufile:tcompilerppufile);
  61. destructor destroy;override;
  62. procedure ppuwrite(ppufile:tcompilerppufile);override;
  63. end;
  64. terrorsym = class(Tsym)
  65. constructor create;
  66. end;
  67. Tprocdefcallback = procedure(p:Tprocdef;arg:pointer);
  68. tprocsym = class(tstoredsym)
  69. protected
  70. pdlistfirst,
  71. pdlistlast : pprocdeflist; { linked list of overloaded procdefs }
  72. function getprocdef(nr:cardinal):Tprocdef;
  73. public
  74. procdef_count : byte;
  75. overloadchecked : boolean;
  76. property procdef[nr:cardinal]:Tprocdef read getprocdef;
  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 unchain_overload;
  86. procedure ppuwrite(ppufile:tcompilerppufile);override;
  87. procedure buildderef;override;
  88. procedure deref;override;
  89. procedure addprocdef(p:tprocdef);
  90. procedure addprocdef_deref(const d:tderef);
  91. procedure add_para_match_to(Aprocsym:Tprocsym;cpoptions:tcompare_paras_options);
  92. procedure concat_procdefs_to(s:Tprocsym);
  93. procedure foreach_procdef_static(proc2call:Tprocdefcallback;arg:pointer);
  94. function first_procdef:Tprocdef;
  95. function last_procdef:Tprocdef;
  96. function search_procdef_nopara_boolret:Tprocdef;
  97. function search_procdef_bytype(pt:Tproctypeoption):Tprocdef;
  98. function search_procdef_bypara(para:tlist;retdef:tdef;cpoptions:tcompare_paras_options):Tprocdef;
  99. function search_procdef_byprocvardef(d:Tprocvardef):Tprocdef;
  100. function search_procdef_assignment_operator(fromdef,todef:tdef;var besteq:tequaltype):Tprocdef;
  101. function write_references(ppufile:tcompilerppufile;locals:boolean):boolean;override;
  102. { currobjdef is the object def to assume, this is necessary for protected and
  103. private,
  104. context is the object def we're really in, this is for the strict stuff
  105. }
  106. function is_visible_for_object(currobjdef:tdef;context:tdef):boolean;override;
  107. end;
  108. ttypesym = class(Tstoredsym)
  109. restype : ttype;
  110. constructor create(const n : string;const tt : ttype);
  111. constructor ppuload(ppufile:tcompilerppufile);
  112. procedure ppuwrite(ppufile:tcompilerppufile);override;
  113. procedure buildderef;override;
  114. procedure deref;override;
  115. function gettypedef:tdef;override;
  116. procedure load_references(ppufile:tcompilerppufile;locals:boolean);override;
  117. function write_references(ppufile:tcompilerppufile;locals:boolean):boolean;override;
  118. end;
  119. tabstractvarsym = class(tstoredsym)
  120. varoptions : tvaroptions;
  121. varspez : tvarspez; { sets the type of access }
  122. varregable : tvarregable;
  123. varstate : tvarstate;
  124. notifications : Tlinkedlist;
  125. constructor create(st:tsymtyp;const n : string;vsp:tvarspez;const tt : ttype;vopts:tvaroptions);
  126. constructor ppuload(st:tsymtyp;ppufile:tcompilerppufile);
  127. destructor destroy;override;
  128. procedure ppuwrite(ppufile:tcompilerppufile);override;
  129. procedure buildderef;override;
  130. procedure deref;override;
  131. function getsize : longint;
  132. function is_regvar:boolean;
  133. procedure trigger_notifications(what:Tnotification_flag);
  134. function register_notification(flags:Tnotification_flags;
  135. callback:Tnotification_callback):cardinal;
  136. procedure unregister_notification(id:cardinal);
  137. private
  138. procedure setvartype(const newtype: ttype);
  139. _vartype : ttype;
  140. public
  141. property vartype: ttype read _vartype write setvartype;
  142. end;
  143. tfieldvarsym = class(tabstractvarsym)
  144. fieldoffset : aint; { offset in record/object }
  145. constructor create(const n : string;vsp:tvarspez;const tt : ttype;vopts:tvaroptions);
  146. constructor ppuload(ppufile:tcompilerppufile);
  147. procedure ppuwrite(ppufile:tcompilerppufile);override;
  148. end;
  149. tabstractnormalvarsym = class(tabstractvarsym)
  150. defaultconstsym : tsym;
  151. defaultconstsymderef : tderef;
  152. localloc : TLocation; { register/reference for local var }
  153. constructor create(st:tsymtyp;const n : string;vsp:tvarspez;const tt : ttype;vopts:tvaroptions);
  154. constructor ppuload(st:tsymtyp;ppufile:tcompilerppufile);
  155. procedure ppuwrite(ppufile:tcompilerppufile);override;
  156. procedure buildderef;override;
  157. procedure deref;override;
  158. end;
  159. tlocalvarsym = class(tabstractnormalvarsym)
  160. constructor create(const n : string;vsp:tvarspez;const tt : ttype;vopts:tvaroptions);
  161. constructor ppuload(ppufile:tcompilerppufile);
  162. procedure ppuwrite(ppufile:tcompilerppufile);override;
  163. end;
  164. tparavarsym = class(tabstractnormalvarsym)
  165. paraloc : array[tcallercallee] of TCGPara;
  166. paranr : word; { position of this parameter }
  167. {$ifdef EXTDEBUG}
  168. eqval : tequaltype;
  169. {$endif EXTDEBUG}
  170. constructor create(const n : string;nr:word;vsp:tvarspez;const tt : ttype;vopts:tvaroptions);
  171. constructor ppuload(ppufile:tcompilerppufile);
  172. destructor destroy;override;
  173. procedure ppuwrite(ppufile:tcompilerppufile);override;
  174. end;
  175. tglobalvarsym = class(tabstractnormalvarsym)
  176. private
  177. _mangledname : pstring;
  178. public
  179. constructor create(const n : string;vsp:tvarspez;const tt : ttype;vopts:tvaroptions);
  180. constructor create_dll(const n : string;vsp:tvarspez;const tt : ttype);
  181. constructor create_C(const n,mangled : string;vsp:tvarspez;const tt : ttype);
  182. constructor ppuload(ppufile:tcompilerppufile);
  183. destructor destroy;override;
  184. procedure ppuwrite(ppufile:tcompilerppufile);override;
  185. function mangledname:string;override;
  186. procedure set_mangledname(const s:string);
  187. end;
  188. tabsolutevarsym = class(tabstractvarsym)
  189. public
  190. abstyp : absolutetyp;
  191. {$ifdef i386}
  192. absseg : boolean;
  193. {$endif i386}
  194. asmname : pstring;
  195. addroffset : aint;
  196. ref : tsymlist;
  197. constructor create(const n : string;const tt : ttype);
  198. constructor create_ref(const n : string;const tt : ttype;_ref:tsymlist);
  199. destructor destroy;override;
  200. constructor ppuload(ppufile:tcompilerppufile);
  201. procedure buildderef;override;
  202. procedure deref;override;
  203. function mangledname : string;override;
  204. procedure ppuwrite(ppufile:tcompilerppufile);override;
  205. end;
  206. tpropertysym = class(Tstoredsym)
  207. propoptions : tpropertyoptions;
  208. propoverriden : tpropertysym;
  209. propoverridenderef : tderef;
  210. proptype,
  211. indextype : ttype;
  212. index,
  213. default : longint;
  214. readaccess,
  215. writeaccess,
  216. storedaccess : tsymlist;
  217. constructor create(const n : string);
  218. destructor destroy;override;
  219. constructor ppuload(ppufile:tcompilerppufile);
  220. function getsize : longint;
  221. procedure ppuwrite(ppufile:tcompilerppufile);override;
  222. function gettypedef:tdef;override;
  223. procedure buildderef;override;
  224. procedure deref;override;
  225. procedure dooverride(overriden:tpropertysym);
  226. end;
  227. ttypedconstsym = class(tstoredsym)
  228. private
  229. _mangledname : pstring;
  230. public
  231. typedconsttype : ttype;
  232. is_writable : boolean;
  233. constructor create(const n : string;p : tdef;writable : boolean);
  234. constructor createtype(const n : string;const tt : ttype;writable : boolean);
  235. constructor ppuload(ppufile:tcompilerppufile);
  236. destructor destroy;override;
  237. function mangledname : string;override;
  238. procedure ppuwrite(ppufile:tcompilerppufile);override;
  239. procedure buildderef;override;
  240. procedure deref;override;
  241. function getsize:longint;
  242. end;
  243. tconstvalue = record
  244. case integer of
  245. 0: (valueord : tconstexprint);
  246. 1: (valueordptr : tconstptruint);
  247. 2: (valueptr : pointer; len : longint);
  248. end;
  249. tconstsym = class(tstoredsym)
  250. consttype : ttype;
  251. consttyp : tconsttyp;
  252. value : tconstvalue;
  253. resstrindex : longint; { needed for resource strings }
  254. constructor create_ord(const n : string;t : tconsttyp;v : tconstexprint;const tt:ttype);
  255. constructor create_ordptr(const n : string;t : tconsttyp;v : tconstptruint;const tt:ttype);
  256. constructor create_ptr(const n : string;t : tconsttyp;v : pointer;const tt:ttype);
  257. constructor create_string(const n : string;t : tconsttyp;str:pchar;l:longint);
  258. constructor create_wstring(const n : string;t : tconsttyp;pw:pcompilerwidestring);
  259. constructor ppuload(ppufile:tcompilerppufile);
  260. destructor destroy;override;
  261. procedure buildderef;override;
  262. procedure deref;override;
  263. procedure ppuwrite(ppufile:tcompilerppufile);override;
  264. end;
  265. tenumsym = class(Tstoredsym)
  266. value : longint;
  267. definition : tenumdef;
  268. definitionderef : tderef;
  269. nextenum : tenumsym;
  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. procedure order;
  276. end;
  277. tsyssym = class(Tstoredsym)
  278. number : longint;
  279. constructor create(const n : string;l : longint);
  280. constructor ppuload(ppufile:tcompilerppufile);
  281. destructor destroy;override;
  282. procedure ppuwrite(ppufile:tcompilerppufile);override;
  283. end;
  284. const
  285. maxmacrolen=16*1024;
  286. type
  287. pmacrobuffer = ^tmacrobuffer;
  288. tmacrobuffer = array[0..maxmacrolen-1] of char;
  289. tmacro = class(tstoredsym)
  290. {Normally true, but false when a previously defined macro is undef-ed}
  291. defined : boolean;
  292. {True if this is a mac style compiler variable, in which case no macro
  293. substitutions shall be done.}
  294. is_compiler_var : boolean;
  295. {Whether the macro was used. NOTE: A use of a macro which was never defined}
  296. {e. g. an IFDEF which returns false, will not be registered as used,}
  297. {since there is no place to register its use. }
  298. is_used : boolean;
  299. buftext : pchar;
  300. buflen : longint;
  301. constructor create(const n : string);
  302. constructor ppuload(ppufile:tcompilerppufile);
  303. procedure ppuwrite(ppufile:tcompilerppufile);override;
  304. destructor destroy;override;
  305. function GetCopy:tmacro;
  306. end;
  307. { compiler generated symbol to point to rtti and init/finalize tables }
  308. trttisym = class(tstoredsym)
  309. private
  310. _mangledname : pstring;
  311. public
  312. lab : tasmsymbol;
  313. rttityp : trttitype;
  314. constructor create(const n:string;rt:trttitype);
  315. constructor ppuload(ppufile:tcompilerppufile);
  316. destructor destroy;override;
  317. procedure ppuwrite(ppufile:tcompilerppufile);override;
  318. function mangledname:string;override;
  319. function get_label:tasmsymbol;
  320. end;
  321. var
  322. generrorsym : tsym;
  323. implementation
  324. uses
  325. { global }
  326. verbose,
  327. { target }
  328. systems,
  329. { symtable }
  330. defutil,symtable,
  331. { tree }
  332. node,
  333. { aasm }
  334. { codegen }
  335. paramgr,cresstr,
  336. procinfo
  337. ;
  338. {****************************************************************************
  339. Helpers
  340. ****************************************************************************}
  341. {****************************************************************************
  342. TSYM (base for all symtypes)
  343. ****************************************************************************}
  344. constructor tstoredsym.create(st:tsymtyp;const n : string);
  345. begin
  346. inherited create(st,n);
  347. end;
  348. constructor tstoredsym.ppuload(st:tsymtyp;ppufile:tcompilerppufile);
  349. var
  350. nr : word;
  351. s : string;
  352. begin
  353. nr:=ppufile.getword;
  354. s:=ppufile.getstring;
  355. if s[1]='$' then
  356. inherited createname(copy(s,2,255))
  357. else
  358. inherited createname(upper(s));
  359. _realname:=stringdup(s);
  360. typ:=st;
  361. { force the correct indexnr. must be after create! }
  362. indexnr:=nr;
  363. ppufile.getposinfo(fileinfo);
  364. ppufile.getsmallset(symoptions);
  365. lastref:=nil;
  366. defref:=nil;
  367. refs:=0;
  368. lastwritten:=nil;
  369. refcount:=0;
  370. isstabwritten := false;
  371. end;
  372. procedure tstoredsym.ppuwrite(ppufile:tcompilerppufile);
  373. begin
  374. ppufile.putword(indexnr);
  375. ppufile.putstring(_realname^);
  376. ppufile.putposinfo(fileinfo);
  377. ppufile.putsmallset(symoptions);
  378. end;
  379. destructor tstoredsym.destroy;
  380. begin
  381. if assigned(defref) then
  382. begin
  383. {$ifdef MEMDEBUG}
  384. membrowser.start;
  385. {$endif MEMDEBUG}
  386. defref.freechain;
  387. defref.free;
  388. {$ifdef MEMDEBUG}
  389. membrowser.stop;
  390. {$endif MEMDEBUG}
  391. end;
  392. inherited destroy;
  393. end;
  394. {****************************************************************************
  395. TLABELSYM
  396. ****************************************************************************}
  397. constructor tlabelsym.create(const n : string);
  398. begin
  399. inherited create(labelsym,n);
  400. used:=false;
  401. defined:=false;
  402. code:=nil;
  403. end;
  404. constructor tlabelsym.ppuload(ppufile:tcompilerppufile);
  405. begin
  406. inherited ppuload(labelsym,ppufile);
  407. code:=nil;
  408. used:=false;
  409. defined:=true;
  410. end;
  411. procedure tlabelsym.ppuwrite(ppufile:tcompilerppufile);
  412. begin
  413. if owner.symtabletype=globalsymtable then
  414. Message(sym_e_ill_label_decl)
  415. else
  416. begin
  417. inherited ppuwrite(ppufile);
  418. ppufile.writeentry(iblabelsym);
  419. end;
  420. end;
  421. {****************************************************************************
  422. TUNITSYM
  423. ****************************************************************************}
  424. constructor tunitsym.create(const n : string;amodule : tobject);
  425. var
  426. old_make_ref : boolean;
  427. begin
  428. old_make_ref:=make_ref;
  429. make_ref:=false;
  430. inherited create(unitsym,n);
  431. make_ref:=old_make_ref;
  432. module:=amodule;
  433. end;
  434. constructor tunitsym.ppuload(ppufile:tcompilerppufile);
  435. begin
  436. inherited ppuload(unitsym,ppufile);
  437. module:=nil;
  438. end;
  439. destructor tunitsym.destroy;
  440. begin
  441. inherited destroy;
  442. end;
  443. procedure tunitsym.ppuwrite(ppufile:tcompilerppufile);
  444. begin
  445. inherited ppuwrite(ppufile);
  446. ppufile.writeentry(ibunitsym);
  447. end;
  448. {****************************************************************************
  449. TPROCSYM
  450. ****************************************************************************}
  451. constructor tprocsym.create(const n : string);
  452. begin
  453. inherited create(procsym,n);
  454. pdlistfirst:=nil;
  455. pdlistlast:=nil;
  456. { the tprocdef have their own symoptions, make the procsym
  457. always visible }
  458. symoptions:=[sp_public];
  459. overloadchecked:=false;
  460. procdef_count:=0;
  461. end;
  462. constructor tprocsym.ppuload(ppufile:tcompilerppufile);
  463. var
  464. pdderef : tderef;
  465. i,n : longint;
  466. begin
  467. inherited ppuload(procsym,ppufile);
  468. pdlistfirst:=nil;
  469. pdlistlast:=nil;
  470. procdef_count:=0;
  471. n:=ppufile.getword;
  472. for i:=1to n do
  473. begin
  474. ppufile.getderef(pdderef);
  475. addprocdef_deref(pdderef);
  476. end;
  477. overloadchecked:=false;
  478. end;
  479. destructor tprocsym.destroy;
  480. var
  481. hp,p : pprocdeflist;
  482. begin
  483. p:=pdlistfirst;
  484. while assigned(p) do
  485. begin
  486. hp:=p^.next;
  487. dispose(p);
  488. p:=hp;
  489. end;
  490. inherited destroy;
  491. end;
  492. procedure tprocsym.ppuwrite(ppufile:tcompilerppufile);
  493. var
  494. p : pprocdeflist;
  495. n : word;
  496. begin
  497. inherited ppuwrite(ppufile);
  498. { count procdefs }
  499. n:=0;
  500. p:=pdlistfirst;
  501. while assigned(p) do
  502. begin
  503. { only write the proc definitions that belong
  504. to this procsym and are in the global symtable }
  505. if p^.def.owner=owner then
  506. inc(n);
  507. p:=p^.next;
  508. end;
  509. ppufile.putword(n);
  510. { write procdefs }
  511. p:=pdlistfirst;
  512. while assigned(p) do
  513. begin
  514. { only write the proc definitions that belong
  515. to this procsym and are in the global symtable }
  516. if p^.def.owner=owner then
  517. ppufile.putderef(p^.defderef);
  518. p:=p^.next;
  519. end;
  520. ppufile.writeentry(ibprocsym);
  521. end;
  522. procedure tprocsym.write_parameter_lists(skipdef:tprocdef);
  523. var
  524. p : pprocdeflist;
  525. begin
  526. p:=pdlistfirst;
  527. while assigned(p) do
  528. begin
  529. if p^.def<>skipdef then
  530. MessagePos1(p^.def.fileinfo,sym_h_param_list,p^.def.fullprocname(false));
  531. p:=p^.next;
  532. end;
  533. end;
  534. {Makes implicit externals (procedures declared in the interface
  535. section which do not have a counterpart in the implementation)
  536. to be an imported procedure. For mode macpas.}
  537. procedure import_implict_external(pd:tabstractprocdef);
  538. begin
  539. tprocdef(pd).forwarddef:=false;
  540. tprocdef(pd).setmangledname(target_info.CPrefix+tprocdef(pd).procsym.realname);
  541. end;
  542. procedure tprocsym.check_forward;
  543. var
  544. p : pprocdeflist;
  545. begin
  546. p:=pdlistfirst;
  547. while assigned(p) do
  548. begin
  549. if (p^.def.owner=owner) and (p^.def.forwarddef) then
  550. begin
  551. if (m_mac in aktmodeswitches) and (p^.def.interfacedef) then
  552. import_implict_external(p^.def)
  553. else
  554. begin
  555. MessagePos1(p^.def.fileinfo,sym_e_forward_not_resolved,p^.def.fullprocname(false));
  556. { Turn further error messages off }
  557. p^.def.forwarddef:=false;
  558. end
  559. end;
  560. p:=p^.next;
  561. end;
  562. end;
  563. procedure tprocsym.buildderef;
  564. var
  565. p : pprocdeflist;
  566. begin
  567. p:=pdlistfirst;
  568. while assigned(p) do
  569. begin
  570. if p^.def.owner=owner then
  571. p^.defderef.build(p^.def);
  572. p:=p^.next;
  573. end;
  574. end;
  575. procedure tprocsym.deref;
  576. var
  577. p : pprocdeflist;
  578. begin
  579. { We have removed the overloaded entries, because they
  580. are not valid anymore and we can't deref them because
  581. the unit were they come from is not necessary in
  582. our uses clause (PFV) }
  583. unchain_overload;
  584. { Deref our own procdefs }
  585. p:=pdlistfirst;
  586. while assigned(p) do
  587. begin
  588. if not(
  589. (p^.def=nil) or
  590. (p^.def.owner=owner)
  591. ) then
  592. internalerror(200310291);
  593. p^.def:=tprocdef(p^.defderef.resolve);
  594. p:=p^.next;
  595. end;
  596. end;
  597. procedure tprocsym.addprocdef(p:tprocdef);
  598. var
  599. pd : pprocdeflist;
  600. begin
  601. new(pd);
  602. pd^.def:=p;
  603. pd^.defderef.reset;
  604. pd^.next:=nil;
  605. { Add at end of list to keep always
  606. a correct order, also after loading from ppu }
  607. if assigned(pdlistlast) then
  608. begin
  609. pdlistlast^.next:=pd;
  610. pdlistlast:=pd;
  611. end
  612. else
  613. begin
  614. pdlistfirst:=pd;
  615. pdlistlast:=pd;
  616. end;
  617. inc(procdef_count);
  618. end;
  619. procedure tprocsym.addprocdef_deref(const d:tderef);
  620. var
  621. pd : pprocdeflist;
  622. begin
  623. new(pd);
  624. pd^.def:=nil;
  625. pd^.defderef:=d;
  626. pd^.next:=nil;
  627. { Add at end of list to keep always
  628. a correct order, also after loading from ppu }
  629. if assigned(pdlistlast) then
  630. begin
  631. pdlistlast^.next:=pd;
  632. pdlistlast:=pd;
  633. end
  634. else
  635. begin
  636. pdlistfirst:=pd;
  637. pdlistlast:=pd;
  638. end;
  639. inc(procdef_count);
  640. end;
  641. function Tprocsym.getprocdef(nr:cardinal):Tprocdef;
  642. var
  643. i : cardinal;
  644. pd : pprocdeflist;
  645. begin
  646. pd:=pdlistfirst;
  647. for i:=2 to nr do
  648. begin
  649. if not assigned(pd) then
  650. internalerror(200209051);
  651. pd:=pd^.next;
  652. end;
  653. getprocdef:=pd^.def;
  654. end;
  655. procedure Tprocsym.add_para_match_to(Aprocsym:Tprocsym;cpoptions:tcompare_paras_options);
  656. var
  657. pd:pprocdeflist;
  658. begin
  659. pd:=pdlistfirst;
  660. while assigned(pd) do
  661. begin
  662. if Aprocsym.search_procdef_bypara(pd^.def.paras,nil,cpoptions)=nil then
  663. Aprocsym.addprocdef(pd^.def);
  664. pd:=pd^.next;
  665. end;
  666. end;
  667. procedure Tprocsym.concat_procdefs_to(s:Tprocsym);
  668. var
  669. pd : pprocdeflist;
  670. begin
  671. pd:=pdlistfirst;
  672. while assigned(pd) do
  673. begin
  674. s.addprocdef(pd^.def);
  675. pd:=pd^.next;
  676. end;
  677. end;
  678. function Tprocsym.first_procdef:Tprocdef;
  679. begin
  680. if assigned(pdlistfirst) then
  681. first_procdef:=pdlistfirst^.def
  682. else
  683. first_procdef:=nil;
  684. end;
  685. function Tprocsym.last_procdef:Tprocdef;
  686. begin
  687. if assigned(pdlistlast) then
  688. last_procdef:=pdlistlast^.def
  689. else
  690. last_procdef:=nil;
  691. end;
  692. procedure Tprocsym.foreach_procdef_static(proc2call:Tprocdefcallback;arg:pointer);
  693. var
  694. p : pprocdeflist;
  695. begin
  696. p:=pdlistfirst;
  697. while assigned(p) do
  698. begin
  699. proc2call(p^.def,arg);
  700. p:=p^.next;
  701. end;
  702. end;
  703. function Tprocsym.search_procdef_nopara_boolret:Tprocdef;
  704. var
  705. p : pprocdeflist;
  706. begin
  707. search_procdef_nopara_boolret:=nil;
  708. p:=pdlistfirst;
  709. while p<>nil do
  710. begin
  711. if (p^.def.maxparacount=0) and
  712. is_boolean(p^.def.rettype.def) then
  713. begin
  714. search_procdef_nopara_boolret:=p^.def;
  715. break;
  716. end;
  717. p:=p^.next;
  718. end;
  719. end;
  720. function Tprocsym.search_procdef_bytype(pt:Tproctypeoption):Tprocdef;
  721. var
  722. p : pprocdeflist;
  723. begin
  724. search_procdef_bytype:=nil;
  725. p:=pdlistfirst;
  726. while p<>nil do
  727. begin
  728. if p^.def.proctypeoption=pt then
  729. begin
  730. search_procdef_bytype:=p^.def;
  731. break;
  732. end;
  733. p:=p^.next;
  734. end;
  735. end;
  736. function Tprocsym.search_procdef_bypara(para:tlist;retdef:tdef;
  737. cpoptions:tcompare_paras_options):Tprocdef;
  738. var
  739. pd : pprocdeflist;
  740. eq : tequaltype;
  741. begin
  742. search_procdef_bypara:=nil;
  743. pd:=pdlistfirst;
  744. while assigned(pd) do
  745. begin
  746. if assigned(retdef) then
  747. eq:=compare_defs(retdef,pd^.def.rettype.def,nothingn)
  748. else
  749. eq:=te_equal;
  750. if (eq>=te_equal) or
  751. ((cpo_allowconvert in cpoptions) and (eq>te_incompatible)) then
  752. begin
  753. eq:=compare_paras(para,pd^.def.paras,cp_value_equal_const,cpoptions);
  754. if (eq>=te_equal) or
  755. ((cpo_allowconvert in cpoptions) and (eq>te_incompatible)) then
  756. begin
  757. search_procdef_bypara:=pd^.def;
  758. break;
  759. end;
  760. end;
  761. pd:=pd^.next;
  762. end;
  763. end;
  764. function Tprocsym.search_procdef_byprocvardef(d:Tprocvardef):Tprocdef;
  765. var
  766. pd : pprocdeflist;
  767. eq,besteq : tequaltype;
  768. bestpd : tprocdef;
  769. begin
  770. { This function will return the pprocdef of pprocsym that
  771. is the best match for procvardef. When there are multiple
  772. matches it returns nil.}
  773. search_procdef_byprocvardef:=nil;
  774. bestpd:=nil;
  775. besteq:=te_incompatible;
  776. pd:=pdlistfirst;
  777. while assigned(pd) do
  778. begin
  779. eq:=proc_to_procvar_equal(pd^.def,d);
  780. if eq>=te_equal then
  781. begin
  782. { multiple procvars with the same equal level }
  783. if assigned(bestpd) and
  784. (besteq=eq) then
  785. exit;
  786. if eq>besteq then
  787. begin
  788. besteq:=eq;
  789. bestpd:=pd^.def;
  790. end;
  791. end;
  792. pd:=pd^.next;
  793. end;
  794. search_procdef_byprocvardef:=bestpd;
  795. end;
  796. function Tprocsym.search_procdef_assignment_operator(fromdef,todef:tdef;var besteq:tequaltype):Tprocdef;
  797. var
  798. convtyp : tconverttype;
  799. pd : pprocdeflist;
  800. bestpd : tprocdef;
  801. eq : tequaltype;
  802. hpd : tprocdef;
  803. i : byte;
  804. begin
  805. result:=nil;
  806. bestpd:=nil;
  807. besteq:=te_incompatible;
  808. pd:=pdlistfirst;
  809. while assigned(pd) do
  810. begin
  811. if equal_defs(todef,pd^.def.rettype.def) and
  812. { the result type must be always really equal and not an alias,
  813. if you mess with this code, check tw4093 }
  814. ((todef=pd^.def.rettype.def) or
  815. (
  816. not(df_unique in todef.defoptions) and
  817. not(df_unique in pd^.def.rettype.def.defoptions)
  818. )
  819. ) then
  820. begin
  821. i:=0;
  822. { ignore vs_hidden parameters }
  823. while (i<pd^.def.paras.count) and
  824. assigned(pd^.def.paras[i]) and
  825. (vo_is_hidden_para in tparavarsym(pd^.def.paras[i]).varoptions) do
  826. inc(i);
  827. if (i<pd^.def.paras.count) and
  828. assigned(pd^.def.paras[i]) then
  829. begin
  830. eq:=compare_defs_ext(fromdef,tparavarsym(pd^.def.paras[i]).vartype.def,nothingn,convtyp,hpd,[]);
  831. { alias? if yes, only l1 choice,
  832. if you mess with this code, check tw4093 }
  833. if (eq=te_exact) and
  834. (fromdef<>tparavarsym(pd^.def.paras[i]).vartype.def) and
  835. ((df_unique in fromdef.defoptions) or
  836. (df_unique in tparavarsym(pd^.def.paras[i]).vartype.def.defoptions)) then
  837. eq:=te_convert_l1;
  838. if eq=te_exact then
  839. begin
  840. besteq:=eq;
  841. result:=pd^.def;
  842. exit;
  843. end;
  844. if eq>besteq then
  845. begin
  846. bestpd:=pd^.def;
  847. besteq:=eq;
  848. end;
  849. end;
  850. end;
  851. pd:=pd^.next;
  852. end;
  853. result:=bestpd;
  854. end;
  855. function tprocsym.write_references(ppufile:tcompilerppufile;locals:boolean) : boolean;
  856. var
  857. p : pprocdeflist;
  858. begin
  859. write_references:=false;
  860. if not inherited write_references(ppufile,locals) then
  861. exit;
  862. write_references:=true;
  863. p:=pdlistfirst;
  864. while assigned(p) do
  865. begin
  866. if p^.def.owner=owner then
  867. p^.def.write_references(ppufile,locals);
  868. p:=p^.next;
  869. end;
  870. end;
  871. procedure tprocsym.unchain_overload;
  872. var
  873. p,hp : pprocdeflist;
  874. begin
  875. { remove all overloaded procdefs from the
  876. procdeflist that are not in the current symtable }
  877. overloadchecked:=false;
  878. p:=pdlistfirst;
  879. { reset new lists }
  880. pdlistfirst:=nil;
  881. pdlistlast:=nil;
  882. while assigned(p) do
  883. begin
  884. hp:=p^.next;
  885. { only keep the proc definitions:
  886. - are not deref'd (def=nil)
  887. - are in the same symtable as the procsym (for example both
  888. are in the staticsymtable) }
  889. if (p^.def=nil) or
  890. (p^.def.owner=owner) then
  891. begin
  892. { keep, add to list }
  893. if assigned(pdlistlast) then
  894. begin
  895. pdlistlast^.next:=p;
  896. pdlistlast:=p;
  897. end
  898. else
  899. begin
  900. pdlistfirst:=p;
  901. pdlistlast:=p;
  902. end;
  903. p^.next:=nil;
  904. end
  905. else
  906. begin
  907. { remove }
  908. dispose(p);
  909. dec(procdef_count);
  910. end;
  911. p:=hp;
  912. end;
  913. end;
  914. function tprocsym.is_visible_for_object(currobjdef:tdef;context:tdef):boolean;
  915. var
  916. p : pprocdeflist;
  917. begin
  918. { This procsym is visible, when there is at least
  919. one of the procdefs visible }
  920. result:=false;
  921. p:=pdlistfirst;
  922. while assigned(p) do
  923. begin
  924. if (p^.def.owner=owner) and
  925. p^.def.is_visible_for_object(tobjectdef(currobjdef)) then
  926. begin
  927. result:=true;
  928. exit;
  929. end;
  930. p:=p^.next;
  931. end;
  932. end;
  933. {****************************************************************************
  934. TERRORSYM
  935. ****************************************************************************}
  936. constructor terrorsym.create;
  937. begin
  938. inherited create(errorsym,'');
  939. end;
  940. {****************************************************************************
  941. TPROPERTYSYM
  942. ****************************************************************************}
  943. constructor tpropertysym.create(const n : string);
  944. begin
  945. inherited create(propertysym,n);
  946. propoptions:=[];
  947. index:=0;
  948. default:=0;
  949. proptype.reset;
  950. indextype.reset;
  951. readaccess:=tsymlist.create;
  952. writeaccess:=tsymlist.create;
  953. storedaccess:=tsymlist.create;
  954. end;
  955. constructor tpropertysym.ppuload(ppufile:tcompilerppufile);
  956. begin
  957. inherited ppuload(propertysym,ppufile);
  958. ppufile.getsmallset(propoptions);
  959. if (ppo_is_override in propoptions) then
  960. begin
  961. ppufile.getderef(propoverridenderef);
  962. { we need to have these objects initialized }
  963. readaccess:=tsymlist.create;
  964. writeaccess:=tsymlist.create;
  965. storedaccess:=tsymlist.create;
  966. end
  967. else
  968. begin
  969. ppufile.gettype(proptype);
  970. index:=ppufile.getlongint;
  971. default:=ppufile.getlongint;
  972. ppufile.gettype(indextype);
  973. readaccess:=ppufile.getsymlist;
  974. writeaccess:=ppufile.getsymlist;
  975. storedaccess:=ppufile.getsymlist;
  976. end;
  977. end;
  978. destructor tpropertysym.destroy;
  979. begin
  980. readaccess.free;
  981. writeaccess.free;
  982. storedaccess.free;
  983. inherited destroy;
  984. end;
  985. function tpropertysym.gettypedef:tdef;
  986. begin
  987. gettypedef:=proptype.def;
  988. end;
  989. procedure tpropertysym.buildderef;
  990. begin
  991. if (ppo_is_override in propoptions) then
  992. begin
  993. propoverridenderef.build(propoverriden);
  994. end
  995. else
  996. begin
  997. proptype.buildderef;
  998. indextype.buildderef;
  999. readaccess.buildderef;
  1000. writeaccess.buildderef;
  1001. storedaccess.buildderef;
  1002. end;
  1003. end;
  1004. procedure tpropertysym.deref;
  1005. begin
  1006. if (ppo_is_override in propoptions) then
  1007. begin
  1008. propoverriden:=tpropertysym(propoverridenderef.resolve);
  1009. dooverride(propoverriden);
  1010. end
  1011. else
  1012. begin
  1013. proptype.resolve;
  1014. indextype.resolve;
  1015. readaccess.resolve;
  1016. writeaccess.resolve;
  1017. storedaccess.resolve;
  1018. end;
  1019. end;
  1020. function tpropertysym.getsize : longint;
  1021. begin
  1022. getsize:=0;
  1023. end;
  1024. procedure tpropertysym.ppuwrite(ppufile:tcompilerppufile);
  1025. begin
  1026. inherited ppuwrite(ppufile);
  1027. ppufile.putsmallset(propoptions);
  1028. if (ppo_is_override in propoptions) then
  1029. ppufile.putderef(propoverridenderef)
  1030. else
  1031. begin
  1032. ppufile.puttype(proptype);
  1033. ppufile.putlongint(index);
  1034. ppufile.putlongint(default);
  1035. ppufile.puttype(indextype);
  1036. ppufile.putsymlist(readaccess);
  1037. ppufile.putsymlist(writeaccess);
  1038. ppufile.putsymlist(storedaccess);
  1039. end;
  1040. ppufile.writeentry(ibpropertysym);
  1041. end;
  1042. procedure tpropertysym.dooverride(overriden:tpropertysym);
  1043. begin
  1044. propoverriden:=overriden;
  1045. proptype:=overriden.proptype;
  1046. propoptions:=overriden.propoptions+[ppo_is_override];
  1047. index:=overriden.index;
  1048. default:=overriden.default;
  1049. indextype:=overriden.indextype;
  1050. readaccess.free;
  1051. readaccess:=overriden.readaccess.getcopy;
  1052. writeaccess.free;
  1053. writeaccess:=overriden.writeaccess.getcopy;
  1054. storedaccess.free;
  1055. storedaccess:=overriden.storedaccess.getcopy;
  1056. end;
  1057. {****************************************************************************
  1058. TABSTRACTVARSYM
  1059. ****************************************************************************}
  1060. constructor tabstractvarsym.create(st:tsymtyp;const n : string;vsp:tvarspez;const tt : ttype;vopts:tvaroptions);
  1061. begin
  1062. inherited create(st,n);
  1063. vartype:=tt;
  1064. varspez:=vsp;
  1065. varstate:=vs_declared;
  1066. varoptions:=vopts;
  1067. end;
  1068. constructor tabstractvarsym.ppuload(st:tsymtyp;ppufile:tcompilerppufile);
  1069. begin
  1070. inherited ppuload(st,ppufile);
  1071. varstate:=vs_readwritten;
  1072. varspez:=tvarspez(ppufile.getbyte);
  1073. varregable:=tvarregable(ppufile.getbyte);
  1074. ppufile.gettype(_vartype);
  1075. ppufile.getsmallset(varoptions);
  1076. end;
  1077. destructor tabstractvarsym.destroy;
  1078. begin
  1079. if assigned(notifications) then
  1080. notifications.destroy;
  1081. inherited destroy;
  1082. end;
  1083. procedure tabstractvarsym.buildderef;
  1084. begin
  1085. vartype.buildderef;
  1086. end;
  1087. procedure tabstractvarsym.deref;
  1088. begin
  1089. vartype.resolve;
  1090. end;
  1091. procedure tabstractvarsym.ppuwrite(ppufile:tcompilerppufile);
  1092. var
  1093. oldintfcrc : boolean;
  1094. begin
  1095. inherited ppuwrite(ppufile);
  1096. ppufile.putbyte(byte(varspez));
  1097. oldintfcrc:=ppufile.do_crc;
  1098. ppufile.do_crc:=false;
  1099. ppufile.putbyte(byte(varregable));
  1100. ppufile.do_crc:=oldintfcrc;
  1101. ppufile.puttype(vartype);
  1102. ppufile.putsmallset(varoptions);
  1103. end;
  1104. function tabstractvarsym.getsize : longint;
  1105. begin
  1106. if assigned(vartype.def) and
  1107. ((vartype.def.deftype<>arraydef) or
  1108. tarraydef(vartype.def).isDynamicArray or
  1109. (tarraydef(vartype.def).highrange>=tarraydef(vartype.def).lowrange)) then
  1110. result:=vartype.def.size
  1111. else
  1112. result:=0;
  1113. end;
  1114. function tabstractvarsym.is_regvar:boolean;
  1115. begin
  1116. { Register variables are not allowed in the following cases:
  1117. - regvars are disabled
  1118. - exceptions are used (after an exception is raised the contents of the
  1119. registers is not valid anymore)
  1120. - it has a local copy
  1121. - the value needs to be in memory (i.e. reference counted) }
  1122. result:=(cs_regvars in aktglobalswitches) and
  1123. not(pi_has_assembler_block in current_procinfo.flags) and
  1124. not(pi_uses_exceptions in current_procinfo.flags) and
  1125. not(vo_has_local_copy in varoptions) and
  1126. (varregable<>vr_none);
  1127. end;
  1128. procedure tabstractvarsym.trigger_notifications(what:Tnotification_flag);
  1129. var n:Tnotification;
  1130. begin
  1131. if assigned(notifications) then
  1132. begin
  1133. n:=Tnotification(notifications.first);
  1134. while assigned(n) do
  1135. begin
  1136. if what in n.flags then
  1137. n.callback(what,self);
  1138. n:=Tnotification(n.next);
  1139. end;
  1140. end;
  1141. end;
  1142. function Tabstractvarsym.register_notification(flags:Tnotification_flags;callback:
  1143. Tnotification_callback):cardinal;
  1144. var n:Tnotification;
  1145. begin
  1146. if not assigned(notifications) then
  1147. notifications:=Tlinkedlist.create;
  1148. n:=Tnotification.create(flags,callback);
  1149. register_notification:=n.id;
  1150. notifications.concat(n);
  1151. end;
  1152. procedure Tabstractvarsym.unregister_notification(id:cardinal);
  1153. var n:Tnotification;
  1154. begin
  1155. if not assigned(notifications) then
  1156. internalerror(200212311)
  1157. else
  1158. begin
  1159. n:=Tnotification(notifications.first);
  1160. while assigned(n) do
  1161. begin
  1162. if n.id=id then
  1163. begin
  1164. notifications.remove(n);
  1165. n.destroy;
  1166. exit;
  1167. end;
  1168. n:=Tnotification(n.next);
  1169. end;
  1170. internalerror(200212311)
  1171. end;
  1172. end;
  1173. procedure tabstractvarsym.setvartype(const newtype: ttype);
  1174. begin
  1175. _vartype := newtype;
  1176. { can we load the value into a register ? }
  1177. if not assigned(owner) or
  1178. (owner.symtabletype in [localsymtable,parasymtable]) or
  1179. (
  1180. (owner.symtabletype=staticsymtable) and
  1181. not(cs_create_pic in aktmoduleswitches)
  1182. ) then
  1183. begin
  1184. if tstoreddef(vartype.def).is_intregable then
  1185. varregable:=vr_intreg
  1186. else
  1187. { $warning TODO: no fpu regvar in staticsymtable yet, need initialization with 0 }
  1188. if {(
  1189. not assigned(owner) or
  1190. (owner.symtabletype<>staticsymtable)
  1191. ) and }
  1192. tstoreddef(vartype.def).is_fpuregable then
  1193. begin
  1194. {$ifdef x86}
  1195. if use_sse(vartype.def) then
  1196. varregable:=vr_mmreg
  1197. else
  1198. {$else x86}
  1199. varregable:=vr_fpureg;
  1200. {$endif x86}
  1201. end;
  1202. end;
  1203. end;
  1204. {****************************************************************************
  1205. TFIELDVARSYM
  1206. ****************************************************************************}
  1207. constructor tfieldvarsym.create(const n : string;vsp:tvarspez;const tt : ttype;vopts:tvaroptions);
  1208. begin
  1209. inherited create(fieldvarsym,n,vsp,tt,vopts);
  1210. fieldoffset:=-1;
  1211. end;
  1212. constructor tfieldvarsym.ppuload(ppufile:tcompilerppufile);
  1213. begin
  1214. inherited ppuload(fieldvarsym,ppufile);
  1215. fieldoffset:=ppufile.getaint;
  1216. end;
  1217. procedure tfieldvarsym.ppuwrite(ppufile:tcompilerppufile);
  1218. begin
  1219. inherited ppuwrite(ppufile);
  1220. ppufile.putaint(fieldoffset);
  1221. ppufile.writeentry(ibfieldvarsym);
  1222. end;
  1223. {****************************************************************************
  1224. TABSTRACTNORMALVARSYM
  1225. ****************************************************************************}
  1226. constructor tabstractnormalvarsym.create(st:tsymtyp;const n : string;vsp:tvarspez;const tt : ttype;vopts:tvaroptions);
  1227. begin
  1228. inherited create(st,n,vsp,tt,vopts);
  1229. fillchar(localloc,sizeof(localloc),0);
  1230. defaultconstsym:=nil;
  1231. end;
  1232. constructor tabstractnormalvarsym.ppuload(st:tsymtyp;ppufile:tcompilerppufile);
  1233. begin
  1234. inherited ppuload(st,ppufile);
  1235. fillchar(localloc,sizeof(localloc),0);
  1236. ppufile.getderef(defaultconstsymderef);
  1237. end;
  1238. procedure tabstractnormalvarsym.buildderef;
  1239. begin
  1240. inherited buildderef;
  1241. defaultconstsymderef.build(defaultconstsym);
  1242. end;
  1243. procedure tabstractnormalvarsym.deref;
  1244. begin
  1245. inherited deref;
  1246. defaultconstsym:=tsym(defaultconstsymderef.resolve);
  1247. end;
  1248. procedure tabstractnormalvarsym.ppuwrite(ppufile:tcompilerppufile);
  1249. begin
  1250. inherited ppuwrite(ppufile);
  1251. ppufile.putderef(defaultconstsymderef);
  1252. end;
  1253. {****************************************************************************
  1254. TGLOBALVARSYM
  1255. ****************************************************************************}
  1256. constructor tglobalvarsym.create(const n : string;vsp:tvarspez;const tt : ttype;vopts:tvaroptions);
  1257. begin
  1258. inherited create(globalvarsym,n,vsp,tt,vopts);
  1259. _mangledname:=nil;
  1260. end;
  1261. constructor tglobalvarsym.create_dll(const n : string;vsp:tvarspez;const tt : ttype);
  1262. begin
  1263. tglobalvarsym(self).create(n,vsp,tt,[vo_is_dll_var]);
  1264. end;
  1265. constructor tglobalvarsym.create_C(const n,mangled : string;vsp:tvarspez;const tt : ttype);
  1266. begin
  1267. tglobalvarsym(self).create(n,vsp,tt,[]);
  1268. set_mangledname(mangled);
  1269. end;
  1270. constructor tglobalvarsym.ppuload(ppufile:tcompilerppufile);
  1271. begin
  1272. inherited ppuload(globalvarsym,ppufile);
  1273. if vo_has_mangledname in varoptions then
  1274. _mangledname:=stringdup(ppufile.getstring)
  1275. else
  1276. _mangledname:=nil;
  1277. end;
  1278. destructor tglobalvarsym.destroy;
  1279. begin
  1280. if assigned(_mangledname) then
  1281. begin
  1282. {$ifdef MEMDEBUG}
  1283. memmanglednames.start;
  1284. {$endif MEMDEBUG}
  1285. stringdispose(_mangledname);
  1286. {$ifdef MEMDEBUG}
  1287. memmanglednames.stop;
  1288. {$endif MEMDEBUG}
  1289. end;
  1290. inherited destroy;
  1291. end;
  1292. procedure tglobalvarsym.ppuwrite(ppufile:tcompilerppufile);
  1293. begin
  1294. inherited ppuwrite(ppufile);
  1295. if vo_has_mangledname in varoptions then
  1296. ppufile.putstring(_mangledname^);
  1297. ppufile.writeentry(ibglobalvarsym);
  1298. end;
  1299. function tglobalvarsym.mangledname:string;
  1300. begin
  1301. if not assigned(_mangledname) then
  1302. begin
  1303. {$ifdef compress}
  1304. _mangledname:=stringdup(minilzw_encode(make_mangledname('U',owner,name)));
  1305. {$else}
  1306. _mangledname:=stringdup(make_mangledname('U',owner,name));
  1307. {$endif}
  1308. end;
  1309. result:=_mangledname^;
  1310. end;
  1311. procedure tglobalvarsym.set_mangledname(const s:string);
  1312. begin
  1313. stringdispose(_mangledname);
  1314. {$ifdef compress}
  1315. _mangledname:=stringdup(minilzw_encode(s));
  1316. {$else}
  1317. _mangledname:=stringdup(s);
  1318. {$endif}
  1319. include(varoptions,vo_has_mangledname);
  1320. end;
  1321. {****************************************************************************
  1322. TLOCALVARSYM
  1323. ****************************************************************************}
  1324. constructor tlocalvarsym.create(const n : string;vsp:tvarspez;const tt : ttype;vopts:tvaroptions);
  1325. begin
  1326. inherited create(localvarsym,n,vsp,tt,vopts);
  1327. end;
  1328. constructor tlocalvarsym.ppuload(ppufile:tcompilerppufile);
  1329. begin
  1330. inherited ppuload(localvarsym,ppufile);
  1331. end;
  1332. procedure tlocalvarsym.ppuwrite(ppufile:tcompilerppufile);
  1333. begin
  1334. inherited ppuwrite(ppufile);
  1335. ppufile.writeentry(iblocalvarsym);
  1336. end;
  1337. {****************************************************************************
  1338. TPARAVARSYM
  1339. ****************************************************************************}
  1340. constructor tparavarsym.create(const n : string;nr:word;vsp:tvarspez;const tt : ttype;vopts:tvaroptions);
  1341. begin
  1342. inherited create(paravarsym,n,vsp,tt,vopts);
  1343. if (vsp in [vs_var,vs_value,vs_const]) then
  1344. varstate := vs_initialised;
  1345. paranr:=nr;
  1346. paraloc[calleeside].init;
  1347. paraloc[callerside].init;
  1348. end;
  1349. destructor tparavarsym.destroy;
  1350. begin
  1351. paraloc[calleeside].done;
  1352. paraloc[callerside].done;
  1353. inherited destroy;
  1354. end;
  1355. constructor tparavarsym.ppuload(ppufile:tcompilerppufile);
  1356. var
  1357. b : byte;
  1358. begin
  1359. inherited ppuload(paravarsym,ppufile);
  1360. paranr:=ppufile.getword;
  1361. paraloc[calleeside].init;
  1362. paraloc[callerside].init;
  1363. if vo_has_explicit_paraloc in varoptions then
  1364. begin
  1365. b:=ppufile.getbyte;
  1366. if b<>sizeof(paraloc[callerside].location^) then
  1367. internalerror(200411154);
  1368. ppufile.getdata(paraloc[callerside].add_location^,sizeof(paraloc[callerside].location^));
  1369. paraloc[callerside].size:=paraloc[callerside].location^.size;
  1370. paraloc[callerside].intsize:=tcgsize2size[paraloc[callerside].size];
  1371. end;
  1372. end;
  1373. procedure tparavarsym.ppuwrite(ppufile:tcompilerppufile);
  1374. begin
  1375. inherited ppuwrite(ppufile);
  1376. ppufile.putword(paranr);
  1377. if vo_has_explicit_paraloc in varoptions then
  1378. begin
  1379. paraloc[callerside].check_simple_location;
  1380. ppufile.putbyte(sizeof(paraloc[callerside].location^));
  1381. ppufile.putdata(paraloc[callerside].location^,sizeof(paraloc[callerside].location^));
  1382. end;
  1383. ppufile.writeentry(ibparavarsym);
  1384. end;
  1385. {****************************************************************************
  1386. TABSOLUTEVARSYM
  1387. ****************************************************************************}
  1388. constructor tabsolutevarsym.create(const n : string;const tt : ttype);
  1389. begin
  1390. inherited create(absolutevarsym,n,vs_value,tt,[]);
  1391. ref:=nil;
  1392. end;
  1393. constructor tabsolutevarsym.create_ref(const n : string;const tt : ttype;_ref:tsymlist);
  1394. begin
  1395. inherited create(absolutevarsym,n,vs_value,tt,[]);
  1396. ref:=_ref;
  1397. end;
  1398. destructor tabsolutevarsym.destroy;
  1399. begin
  1400. if assigned(ref) then
  1401. ref.free;
  1402. inherited destroy;
  1403. end;
  1404. constructor tabsolutevarsym.ppuload(ppufile:tcompilerppufile);
  1405. begin
  1406. inherited ppuload(absolutevarsym,ppufile);
  1407. ref:=nil;
  1408. asmname:=nil;
  1409. abstyp:=absolutetyp(ppufile.getbyte);
  1410. {$ifdef i386}
  1411. absseg:=false;
  1412. {$endif i386}
  1413. case abstyp of
  1414. tovar :
  1415. ref:=ppufile.getsymlist;
  1416. toasm :
  1417. asmname:=stringdup(ppufile.getstring);
  1418. toaddr :
  1419. begin
  1420. addroffset:=ppufile.getaint;
  1421. {$ifdef i386}
  1422. absseg:=boolean(ppufile.getbyte);
  1423. {$endif i386}
  1424. end;
  1425. end;
  1426. end;
  1427. procedure tabsolutevarsym.ppuwrite(ppufile:tcompilerppufile);
  1428. begin
  1429. inherited ppuwrite(ppufile);
  1430. ppufile.putbyte(byte(abstyp));
  1431. case abstyp of
  1432. tovar :
  1433. ppufile.putsymlist(ref);
  1434. toasm :
  1435. ppufile.putstring(asmname^);
  1436. toaddr :
  1437. begin
  1438. ppufile.putaint(addroffset);
  1439. {$ifdef i386}
  1440. ppufile.putbyte(byte(absseg));
  1441. {$endif i386}
  1442. end;
  1443. end;
  1444. ppufile.writeentry(ibabsolutevarsym);
  1445. end;
  1446. procedure tabsolutevarsym.buildderef;
  1447. begin
  1448. inherited buildderef;
  1449. if (abstyp=tovar) then
  1450. ref.buildderef;
  1451. end;
  1452. procedure tabsolutevarsym.deref;
  1453. begin
  1454. inherited deref;
  1455. { own absolute deref }
  1456. if (abstyp=tovar) then
  1457. ref.resolve;
  1458. end;
  1459. function tabsolutevarsym.mangledname : string;
  1460. begin
  1461. case abstyp of
  1462. toasm :
  1463. mangledname:=asmname^;
  1464. toaddr :
  1465. mangledname:='$'+tostr(addroffset);
  1466. else
  1467. internalerror(200411061);
  1468. end;
  1469. end;
  1470. {****************************************************************************
  1471. TTYPEDCONSTSYM
  1472. *****************************************************************************}
  1473. constructor ttypedconstsym.create(const n : string;p : tdef;writable : boolean);
  1474. begin
  1475. inherited create(typedconstsym,n);
  1476. typedconsttype.setdef(p);
  1477. is_writable:=writable;
  1478. end;
  1479. constructor ttypedconstsym.createtype(const n : string;const tt : ttype;writable : boolean);
  1480. begin
  1481. inherited create(typedconstsym,n);
  1482. typedconsttype:=tt;
  1483. is_writable:=writable;
  1484. end;
  1485. constructor ttypedconstsym.ppuload(ppufile:tcompilerppufile);
  1486. begin
  1487. inherited ppuload(typedconstsym,ppufile);
  1488. ppufile.gettype(typedconsttype);
  1489. is_writable:=boolean(ppufile.getbyte);
  1490. end;
  1491. destructor ttypedconstsym.destroy;
  1492. begin
  1493. if assigned(_mangledname) then
  1494. begin
  1495. {$ifdef MEMDEBUG}
  1496. memmanglednames.start;
  1497. {$endif MEMDEBUG}
  1498. stringdispose(_mangledname);
  1499. {$ifdef MEMDEBUG}
  1500. memmanglednames.stop;
  1501. {$endif MEMDEBUG}
  1502. end;
  1503. inherited destroy;
  1504. end;
  1505. function ttypedconstsym.mangledname:string;
  1506. begin
  1507. if not assigned(_mangledname) then
  1508. begin
  1509. {$ifdef compress}
  1510. _mangledname:=stringdup(make_mangledname('TC',owner,name));
  1511. {$else}
  1512. _mangledname:=stringdup(make_mangledname('TC',owner,name));
  1513. {$endif}
  1514. end;
  1515. result:=_mangledname^;
  1516. end;
  1517. function ttypedconstsym.getsize : longint;
  1518. begin
  1519. if assigned(typedconsttype.def) then
  1520. getsize:=typedconsttype.def.size
  1521. else
  1522. getsize:=0;
  1523. end;
  1524. procedure ttypedconstsym.buildderef;
  1525. begin
  1526. typedconsttype.buildderef;
  1527. end;
  1528. procedure ttypedconstsym.deref;
  1529. begin
  1530. typedconsttype.resolve;
  1531. end;
  1532. procedure ttypedconstsym.ppuwrite(ppufile:tcompilerppufile);
  1533. begin
  1534. inherited ppuwrite(ppufile);
  1535. ppufile.puttype(typedconsttype);
  1536. ppufile.putbyte(byte(is_writable));
  1537. ppufile.writeentry(ibtypedconstsym);
  1538. end;
  1539. {****************************************************************************
  1540. TCONSTSYM
  1541. ****************************************************************************}
  1542. constructor tconstsym.create_ord(const n : string;t : tconsttyp;v : tconstexprint;const tt:ttype);
  1543. begin
  1544. inherited create(constsym,n);
  1545. fillchar(value, sizeof(value), #0);
  1546. consttyp:=t;
  1547. value.valueord:=v;
  1548. ResStrIndex:=0;
  1549. consttype:=tt;
  1550. end;
  1551. constructor tconstsym.create_ordptr(const n : string;t : tconsttyp;v : tconstptruint;const tt:ttype);
  1552. begin
  1553. inherited create(constsym,n);
  1554. fillchar(value, sizeof(value), #0);
  1555. consttyp:=t;
  1556. value.valueordptr:=v;
  1557. ResStrIndex:=0;
  1558. consttype:=tt;
  1559. end;
  1560. constructor tconstsym.create_ptr(const n : string;t : tconsttyp;v : pointer;const tt:ttype);
  1561. begin
  1562. inherited create(constsym,n);
  1563. fillchar(value, sizeof(value), #0);
  1564. consttyp:=t;
  1565. value.valueptr:=v;
  1566. ResStrIndex:=0;
  1567. consttype:=tt;
  1568. end;
  1569. constructor tconstsym.create_string(const n : string;t : tconsttyp;str:pchar;l:longint);
  1570. begin
  1571. inherited create(constsym,n);
  1572. fillchar(value, sizeof(value), #0);
  1573. consttyp:=t;
  1574. value.valueptr:=str;
  1575. consttype.reset;
  1576. value.len:=l;
  1577. if t=constresourcestring then
  1578. ResStrIndex:=resourcestrings.Register(name,pchar(value.valueptr),value.len);
  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. consttype.reset;
  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. begin
  1596. inherited ppuload(constsym,ppufile);
  1597. consttype.reset;
  1598. consttyp:=tconsttyp(ppufile.getbyte);
  1599. fillchar(value, sizeof(value), #0);
  1600. case consttyp of
  1601. constord :
  1602. begin
  1603. ppufile.gettype(consttype);
  1604. value.valueord:=ppufile.getexprint;
  1605. end;
  1606. constpointer :
  1607. begin
  1608. ppufile.gettype(consttype);
  1609. value.valueordptr:=ppufile.getptruint;
  1610. end;
  1611. constwstring :
  1612. begin
  1613. initwidestring(pw);
  1614. setlengthwidestring(pw,ppufile.getlongint);
  1615. ppufile.getdata(pw^.data,pw^.len*sizeof(tcompilerwidechar));
  1616. pcompilerwidestring(value.valueptr):=pw;
  1617. end;
  1618. conststring,
  1619. constresourcestring :
  1620. begin
  1621. value.len:=ppufile.getlongint;
  1622. getmem(pc,value.len+1);
  1623. ppufile.getdata(pc^,value.len);
  1624. if consttyp=constresourcestring then
  1625. ResStrIndex:=ppufile.getlongint;
  1626. value.valueptr:=pc;
  1627. end;
  1628. constreal :
  1629. begin
  1630. new(pd);
  1631. pd^:=ppufile.getreal;
  1632. value.valueptr:=pd;
  1633. end;
  1634. constset :
  1635. begin
  1636. ppufile.gettype(consttype);
  1637. new(ps);
  1638. ppufile.getnormalset(ps^);
  1639. value.valueptr:=ps;
  1640. end;
  1641. constguid :
  1642. begin
  1643. new(pguid(value.valueptr));
  1644. ppufile.getdata(value.valueptr^,sizeof(tguid));
  1645. end;
  1646. constnil : ;
  1647. else
  1648. Message1(unit_f_ppu_invalid_entry,tostr(ord(consttyp)));
  1649. end;
  1650. end;
  1651. destructor tconstsym.destroy;
  1652. begin
  1653. case consttyp of
  1654. conststring,
  1655. constresourcestring :
  1656. freemem(pchar(value.valueptr),value.len+1);
  1657. constwstring :
  1658. donewidestring(pcompilerwidestring(value.valueptr));
  1659. constreal :
  1660. dispose(pbestreal(value.valueptr));
  1661. constset :
  1662. dispose(pnormalset(value.valueptr));
  1663. constguid :
  1664. dispose(pguid(value.valueptr));
  1665. end;
  1666. inherited destroy;
  1667. end;
  1668. procedure tconstsym.buildderef;
  1669. begin
  1670. if consttyp in [constord,constpointer,constset] then
  1671. consttype.buildderef;
  1672. end;
  1673. procedure tconstsym.deref;
  1674. begin
  1675. if consttyp in [constord,constpointer,constset] then
  1676. consttype.resolve;
  1677. end;
  1678. procedure tconstsym.ppuwrite(ppufile:tcompilerppufile);
  1679. begin
  1680. inherited ppuwrite(ppufile);
  1681. ppufile.putbyte(byte(consttyp));
  1682. case consttyp of
  1683. constnil : ;
  1684. constord :
  1685. begin
  1686. ppufile.puttype(consttype);
  1687. ppufile.putexprint(value.valueord);
  1688. end;
  1689. constpointer :
  1690. begin
  1691. ppufile.puttype(consttype);
  1692. ppufile.putptruint(value.valueordptr);
  1693. end;
  1694. constwstring :
  1695. begin
  1696. ppufile.putlongint(getlengthwidestring(pcompilerwidestring(value.valueptr)));
  1697. ppufile.putdata(pcompilerwidestring(value.valueptr)^.data,pcompilerwidestring(value.valueptr)^.len*sizeof(tcompilerwidechar));
  1698. end;
  1699. conststring,
  1700. constresourcestring :
  1701. begin
  1702. ppufile.putlongint(value.len);
  1703. ppufile.putdata(pchar(value.valueptr)^,value.len);
  1704. if consttyp=constresourcestring then
  1705. ppufile.putlongint(ResStrIndex);
  1706. end;
  1707. constreal :
  1708. ppufile.putreal(pbestreal(value.valueptr)^);
  1709. constset :
  1710. begin
  1711. ppufile.puttype(consttype);
  1712. ppufile.putnormalset(value.valueptr^);
  1713. end;
  1714. constguid :
  1715. ppufile.putdata(value.valueptr^,sizeof(tguid));
  1716. else
  1717. internalerror(13);
  1718. end;
  1719. ppufile.writeentry(ibconstsym);
  1720. end;
  1721. {****************************************************************************
  1722. TENUMSYM
  1723. ****************************************************************************}
  1724. constructor tenumsym.create(const n : string;def : tenumdef;v : longint);
  1725. begin
  1726. inherited create(enumsym,n);
  1727. definition:=def;
  1728. value:=v;
  1729. { First entry? Then we need to set the minval }
  1730. if def.firstenum=nil then
  1731. begin
  1732. if v>0 then
  1733. def.has_jumps:=true;
  1734. def.setmin(v);
  1735. def.setmax(v);
  1736. end
  1737. else
  1738. begin
  1739. { check for jumps }
  1740. if v>def.max+1 then
  1741. def.has_jumps:=true;
  1742. { update low and high }
  1743. if def.min>v then
  1744. def.setmin(v);
  1745. if def.max<v then
  1746. def.setmax(v);
  1747. end;
  1748. order;
  1749. end;
  1750. constructor tenumsym.ppuload(ppufile:tcompilerppufile);
  1751. begin
  1752. inherited ppuload(enumsym,ppufile);
  1753. ppufile.getderef(definitionderef);
  1754. value:=ppufile.getlongint;
  1755. nextenum := Nil;
  1756. end;
  1757. procedure tenumsym.buildderef;
  1758. begin
  1759. definitionderef.build(definition);
  1760. end;
  1761. procedure tenumsym.deref;
  1762. begin
  1763. definition:=tenumdef(definitionderef.resolve);
  1764. order;
  1765. end;
  1766. procedure tenumsym.order;
  1767. var
  1768. sym : tenumsym;
  1769. begin
  1770. sym := tenumsym(definition.firstenum);
  1771. if sym = nil then
  1772. begin
  1773. definition.firstenum := self;
  1774. nextenum := nil;
  1775. exit;
  1776. end;
  1777. { reorder the symbols in increasing value }
  1778. if value < sym.value then
  1779. begin
  1780. nextenum := sym;
  1781. definition.firstenum := self;
  1782. end
  1783. else
  1784. begin
  1785. while (sym.value <= value) and assigned(sym.nextenum) do
  1786. sym := sym.nextenum;
  1787. nextenum := sym.nextenum;
  1788. sym.nextenum := self;
  1789. end;
  1790. end;
  1791. procedure tenumsym.ppuwrite(ppufile:tcompilerppufile);
  1792. begin
  1793. inherited ppuwrite(ppufile);
  1794. ppufile.putderef(definitionderef);
  1795. ppufile.putlongint(value);
  1796. ppufile.writeentry(ibenumsym);
  1797. end;
  1798. {****************************************************************************
  1799. TTYPESYM
  1800. ****************************************************************************}
  1801. constructor ttypesym.create(const n : string;const tt : ttype);
  1802. begin
  1803. inherited create(typesym,n);
  1804. restype:=tt;
  1805. { register the typesym for the definition }
  1806. if assigned(restype.def) and
  1807. (restype.def.deftype<>errordef) and
  1808. not(assigned(restype.def.typesym)) then
  1809. restype.def.typesym:=self;
  1810. end;
  1811. constructor ttypesym.ppuload(ppufile:tcompilerppufile);
  1812. begin
  1813. inherited ppuload(typesym,ppufile);
  1814. ppufile.gettype(restype);
  1815. end;
  1816. function ttypesym.gettypedef:tdef;
  1817. begin
  1818. gettypedef:=restype.def;
  1819. end;
  1820. procedure ttypesym.buildderef;
  1821. begin
  1822. restype.buildderef;
  1823. end;
  1824. procedure ttypesym.deref;
  1825. begin
  1826. restype.resolve;
  1827. end;
  1828. procedure ttypesym.ppuwrite(ppufile:tcompilerppufile);
  1829. begin
  1830. inherited ppuwrite(ppufile);
  1831. ppufile.puttype(restype);
  1832. ppufile.writeentry(ibtypesym);
  1833. end;
  1834. procedure ttypesym.load_references(ppufile:tcompilerppufile;locals:boolean);
  1835. begin
  1836. inherited load_references(ppufile,locals);
  1837. if (restype.def.deftype=recorddef) then
  1838. tstoredsymtable(trecorddef(restype.def).symtable).load_references(ppufile,locals);
  1839. if (restype.def.deftype=objectdef) then
  1840. tstoredsymtable(tobjectdef(restype.def).symtable).load_references(ppufile,locals);
  1841. end;
  1842. function ttypesym.write_references(ppufile:tcompilerppufile;locals:boolean):boolean;
  1843. var
  1844. d : tderef;
  1845. begin
  1846. d.reset;
  1847. if not inherited write_references(ppufile,locals) then
  1848. begin
  1849. { write address of this symbol if record or object
  1850. even if no real refs are there
  1851. because we need it for the symtable }
  1852. if (restype.def.deftype in [recorddef,objectdef]) then
  1853. begin
  1854. d.build(self);
  1855. ppufile.putderef(d);
  1856. ppufile.writeentry(ibsymref);
  1857. end;
  1858. end;
  1859. write_references:=true;
  1860. if (restype.def.deftype=recorddef) then
  1861. tstoredsymtable(trecorddef(restype.def).symtable).write_references(ppufile,locals);
  1862. if (restype.def.deftype=objectdef) then
  1863. tstoredsymtable(tobjectdef(restype.def).symtable).write_references(ppufile,locals);
  1864. end;
  1865. {****************************************************************************
  1866. TSYSSYM
  1867. ****************************************************************************}
  1868. constructor tsyssym.create(const n : string;l : longint);
  1869. begin
  1870. inherited create(syssym,n);
  1871. number:=l;
  1872. end;
  1873. constructor tsyssym.ppuload(ppufile:tcompilerppufile);
  1874. begin
  1875. inherited ppuload(syssym,ppufile);
  1876. number:=ppufile.getlongint;
  1877. end;
  1878. destructor tsyssym.destroy;
  1879. begin
  1880. inherited destroy;
  1881. end;
  1882. procedure tsyssym.ppuwrite(ppufile:tcompilerppufile);
  1883. begin
  1884. inherited ppuwrite(ppufile);
  1885. ppufile.putlongint(number);
  1886. ppufile.writeentry(ibsyssym);
  1887. end;
  1888. {*****************************************************************************
  1889. TMacro
  1890. *****************************************************************************}
  1891. constructor tmacro.create(const n : string);
  1892. begin
  1893. inherited create(macrosym,n);
  1894. owner:=nil;
  1895. defined:=false;
  1896. is_used:=false;
  1897. is_compiler_var:=false;
  1898. buftext:=nil;
  1899. buflen:=0;
  1900. end;
  1901. constructor tmacro.ppuload(ppufile:tcompilerppufile);
  1902. begin
  1903. inherited ppuload(macrosym,ppufile);
  1904. name:=ppufile.getstring;
  1905. defined:=boolean(ppufile.getbyte);
  1906. is_compiler_var:=boolean(ppufile.getbyte);
  1907. is_used:=false;
  1908. buflen:= ppufile.getlongint;
  1909. if buflen > 0 then
  1910. begin
  1911. getmem(buftext, buflen);
  1912. ppufile.getdata(buftext^, buflen)
  1913. end
  1914. else
  1915. buftext:=nil;
  1916. end;
  1917. destructor tmacro.destroy;
  1918. begin
  1919. if assigned(buftext) then
  1920. freemem(buftext);
  1921. inherited destroy;
  1922. end;
  1923. procedure tmacro.ppuwrite(ppufile:tcompilerppufile);
  1924. begin
  1925. inherited ppuwrite(ppufile);
  1926. ppufile.putstring(name);
  1927. ppufile.putbyte(byte(defined));
  1928. ppufile.putbyte(byte(is_compiler_var));
  1929. ppufile.putlongint(buflen);
  1930. if buflen > 0 then
  1931. ppufile.putdata(buftext^,buflen);
  1932. ppufile.writeentry(ibmacrosym);
  1933. end;
  1934. function tmacro.GetCopy:tmacro;
  1935. var
  1936. p : tmacro;
  1937. begin
  1938. p:=tmacro.create(realname);
  1939. p.defined:=defined;
  1940. p.is_used:=is_used;
  1941. p.is_compiler_var:=is_compiler_var;
  1942. p.buflen:=buflen;
  1943. if assigned(buftext) then
  1944. begin
  1945. getmem(p.buftext,buflen);
  1946. move(buftext^,p.buftext^,buflen);
  1947. end;
  1948. Result:=p;
  1949. end;
  1950. {****************************************************************************
  1951. TRTTISYM
  1952. ****************************************************************************}
  1953. constructor trttisym.create(const n:string;rt:trttitype);
  1954. const
  1955. prefix : array[trttitype] of string[5]=('$rtti','$init');
  1956. begin
  1957. inherited create(rttisym,prefix[rt]+n);
  1958. include(symoptions,sp_internal);
  1959. lab:=nil;
  1960. rttityp:=rt;
  1961. end;
  1962. destructor trttisym.destroy;
  1963. begin
  1964. if assigned(_mangledname) then
  1965. begin
  1966. {$ifdef MEMDEBUG}
  1967. memmanglednames.start;
  1968. {$endif MEMDEBUG}
  1969. stringdispose(_mangledname);
  1970. {$ifdef MEMDEBUG}
  1971. memmanglednames.stop;
  1972. {$endif MEMDEBUG}
  1973. end;
  1974. inherited destroy;
  1975. end;
  1976. constructor trttisym.ppuload(ppufile:tcompilerppufile);
  1977. begin
  1978. inherited ppuload(rttisym,ppufile);
  1979. lab:=nil;
  1980. rttityp:=trttitype(ppufile.getbyte);
  1981. end;
  1982. procedure trttisym.ppuwrite(ppufile:tcompilerppufile);
  1983. begin
  1984. inherited ppuwrite(ppufile);
  1985. ppufile.putbyte(byte(rttityp));
  1986. ppufile.writeentry(ibrttisym);
  1987. end;
  1988. function trttisym.mangledname : string;
  1989. const
  1990. prefix : array[trttitype] of string[5]=('RTTI_','INIT_');
  1991. begin
  1992. if not assigned(_mangledname) then
  1993. _mangledname:=stringdup(make_mangledname(prefix[rttityp],owner,Copy(name,5,255)));
  1994. result:=_mangledname^;
  1995. end;
  1996. function trttisym.get_label:tasmsymbol;
  1997. begin
  1998. { the label is always a global label }
  1999. if not assigned(lab) then
  2000. lab:=objectlibrary.newasmsymbol(mangledname,AB_EXTERNAL,AT_DATA);
  2001. get_label:=lab;
  2002. end;
  2003. end.