symsym.pas 65 KB

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