symsym.pas 70 KB

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