symsym.pas 78 KB

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