symsym.pas 76 KB

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