symsym.pas 65 KB

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