symsym.pas 70 KB

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