symsym.pas 71 KB

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