symsym.inc 61 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076
  1. {
  2. $Id$
  3. Copyright (c) 1993-98 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. {****************************************************************************
  19. TSYM (base for all symtypes)
  20. ****************************************************************************}
  21. constructor tsym.init(const n : string);
  22. begin
  23. left:=nil;
  24. right:=nil;
  25. {$ifdef nextfield}
  26. nextsym:=nil;
  27. {$endif nextfield}
  28. setname(n);
  29. typ:=abstractsym;
  30. properties:=current_object_option;
  31. {$ifdef GDB}
  32. isstabwritten := false;
  33. {$endif GDB}
  34. fileinfo:=tokenpos;
  35. {$ifdef UseBrowser}
  36. defref:=nil;
  37. lastwritten:=nil;
  38. refcount:=0;
  39. if (cs_browser in aktmoduleswitches) and make_ref then
  40. begin
  41. defref:=new(pref,init(defref,@tokenpos));
  42. inc(refcount);
  43. end;
  44. lastref:=defref;
  45. {$endif UseBrowser}
  46. end;
  47. constructor tsym.load;
  48. begin
  49. left:=nil;
  50. right:=nil;
  51. setname(readstring);
  52. typ:=abstractsym;
  53. fillchar(fileinfo,sizeof(fileinfo),0);
  54. if object_options then
  55. properties:=symprop(readbyte)
  56. else
  57. properties:=sp_public;
  58. {$ifdef UseBrowser}
  59. lastref:=nil;
  60. defref:=nil;
  61. lastwritten:=nil;
  62. refcount:=0;
  63. {$endif UseBrowser}
  64. {$ifdef GDB}
  65. isstabwritten := false;
  66. {$endif GDB}
  67. end;
  68. {$ifdef UseBrowser}
  69. procedure tsym.load_references;
  70. var
  71. pos : tfileposinfo;
  72. move_last : boolean;
  73. begin
  74. move_last:=lastwritten=lastref;
  75. while (not current_ppu^.endofentry) do
  76. begin
  77. readposinfo(pos);
  78. inc(refcount);
  79. lastref:=new(pref,init(lastref,@pos));
  80. lastref^.is_written:=true;
  81. if refcount=1 then
  82. defref:=lastref;
  83. end;
  84. if move_last then
  85. lastwritten:=lastref;
  86. end;
  87. { big problem here :
  88. wrong refs were written because of
  89. interface parsing of other units PM
  90. moduleindex must be checked !! }
  91. function tsym.write_references : boolean;
  92. var
  93. ref : pref;
  94. symref_written,move_last : boolean;
  95. begin
  96. write_references:=false;
  97. if lastwritten=lastref then
  98. exit;
  99. { should we update lastref }
  100. move_last:=true;
  101. symref_written:=false;
  102. { write symbol refs }
  103. if assigned(lastwritten) then
  104. ref:=lastwritten
  105. else
  106. ref:=defref;
  107. while assigned(ref) do
  108. begin
  109. if ref^.moduleindex=current_module^.unit_index then
  110. begin
  111. { write address to this symbol }
  112. if not symref_written then
  113. begin
  114. writesymref(@self);
  115. symref_written:=true;
  116. end;
  117. writeposinfo(ref^.posinfo);
  118. ref^.is_written:=true;
  119. if move_last then
  120. lastwritten:=ref;
  121. end
  122. else if not ref^.is_written then
  123. move_last:=false
  124. else if move_last then
  125. lastwritten:=ref;
  126. ref:=ref^.nextref;
  127. end;
  128. if symref_written then
  129. current_ppu^.writeentry(ibsymref);
  130. write_references:=symref_written;
  131. end;
  132. procedure tsym.add_to_browserlog;
  133. begin
  134. if assigned(defref) then
  135. begin
  136. Browse.AddLog('***'+name+'***');
  137. Browse.AddLogRefs(defref);
  138. end;
  139. end;
  140. {$endif UseBrowser}
  141. destructor tsym.done;
  142. begin
  143. {$ifdef tp}
  144. if not(use_big) then
  145. {$endif tp}
  146. strdispose(_name);
  147. {$ifdef UseBrowser}
  148. if assigned(defref) then
  149. dispose(defref,done);
  150. {$endif UseBrowser}
  151. if assigned(left) then
  152. dispose(left,done);
  153. if assigned(right) then
  154. dispose(right,done);
  155. end;
  156. procedure tsym.write;
  157. begin
  158. writestring(name);
  159. if object_options then
  160. writebyte(byte(properties));
  161. end;
  162. procedure tsym.deref;
  163. begin
  164. end;
  165. function tsym.name : string;
  166. {$ifdef tp}
  167. var
  168. s : string;
  169. b : byte;
  170. {$endif}
  171. begin
  172. {$ifdef tp}
  173. if use_big then
  174. begin
  175. symbolstream.seek(longint(_name));
  176. symbolstream.read(b,1);
  177. symbolstream.read(s[1],b);
  178. s[0]:=chr(b);
  179. name:=s;
  180. end
  181. else
  182. {$endif}
  183. if assigned(_name) then
  184. name:=strpas(_name)
  185. else
  186. name:='';
  187. end;
  188. function tsym.mangledname : string;
  189. begin
  190. mangledname:=name;
  191. end;
  192. procedure tsym.setname(const s : string);
  193. begin
  194. setstring(_name,s);
  195. end;
  196. { for most symbol types there is nothing to do at all }
  197. procedure tsym.insert_in_data;
  198. begin
  199. end;
  200. {$ifdef GDB}
  201. function tsym.stabstring : pchar;
  202. begin
  203. stabstring:=strpnew('"'+name+'",'+tostr(N_LSYM)+',0,'+
  204. tostr(fileinfo.line)+',0');
  205. end;
  206. procedure tsym.concatstabto(asmlist : paasmoutput);
  207. var stab_str : pchar;
  208. begin
  209. if not isstabwritten then
  210. begin
  211. stab_str := stabstring;
  212. if asmlist = debuglist then do_count_dbx := true;
  213. { count_dbx(stab_str); moved to GDB.PAS }
  214. asmlist^.concat(new(pai_stabs,init(stab_str)));
  215. isstabwritten:=true;
  216. end;
  217. end;
  218. {$endif GDB}
  219. {****************************************************************************
  220. TLABELSYM
  221. ****************************************************************************}
  222. constructor tlabelsym.init(const n : string; l : plabel);
  223. begin
  224. inherited init(n);
  225. typ:=labelsym;
  226. number:=l;
  227. number^.is_used:=false;
  228. number^.is_set:=true;
  229. number^.refcount:=0;
  230. defined:=false;
  231. end;
  232. constructor tlabelsym.load;
  233. begin
  234. tsym.load;
  235. typ:=labelsym;
  236. { this is all dummy
  237. it is only used for local browsing }
  238. number:=nil;
  239. defined:=true;
  240. end;
  241. destructor tlabelsym.done;
  242. begin
  243. inherited done;
  244. end;
  245. function tlabelsym.mangledname : string;
  246. begin
  247. { this also sets the is_used field }
  248. mangledname:=lab2str(number);
  249. end;
  250. procedure tlabelsym.write;
  251. begin
  252. if owner^.symtabletype in [unitsymtable,globalsymtable] then
  253. Message(sym_e_ill_label_decl)
  254. else
  255. begin
  256. tsym.write;
  257. current_ppu^.writeentry(iblabelsym);
  258. end;
  259. end;
  260. {****************************************************************************
  261. TUNITSYM
  262. ****************************************************************************}
  263. constructor tunitsym.init(const n : string;ref : punitsymtable);
  264. var
  265. old_make_ref : boolean;
  266. begin
  267. old_make_ref:=make_ref;
  268. make_ref:=false;
  269. inherited init(n);
  270. make_ref:=old_make_ref;
  271. typ:=unitsym;
  272. unitsymtable:=ref;
  273. prevsym:=ref^.unitsym;
  274. ref^.unitsym:=@self;
  275. refs:=0;
  276. end;
  277. constructor tunitsym.load;
  278. begin
  279. tsym.load;
  280. typ:=unitsym;
  281. unitsymtable:=punitsymtable(current_module^.globalsymtable);
  282. prevsym:=nil;
  283. end;
  284. destructor tunitsym.done;
  285. begin
  286. if assigned(unitsymtable) and (unitsymtable^.unitsym=@self) then
  287. unitsymtable^.unitsym:=prevsym;
  288. inherited done;
  289. end;
  290. procedure tunitsym.write;
  291. begin
  292. tsym.write;
  293. current_ppu^.writeentry(ibunitsym);
  294. end;
  295. {$ifdef GDB}
  296. procedure tunitsym.concatstabto(asmlist : paasmoutput);
  297. begin
  298. {Nothing to write to stabs !}
  299. end;
  300. {$endif GDB}
  301. {****************************************************************************
  302. TPROCSYM
  303. ****************************************************************************}
  304. constructor tprocsym.init(const n : string);
  305. begin
  306. tsym.init(n);
  307. typ:=procsym;
  308. definition:=nil;
  309. owner:=nil;
  310. {$ifdef GDB}
  311. is_global := false;
  312. {$endif GDB}
  313. end;
  314. constructor tprocsym.load;
  315. begin
  316. tsym.load;
  317. typ:=procsym;
  318. definition:=pprocdef(readdefref);
  319. {$ifdef GDB}
  320. is_global := false;
  321. {$endif GDB}
  322. end;
  323. destructor tprocsym.done;
  324. begin
  325. check_forward;
  326. tsym.done;
  327. end;
  328. function tprocsym.mangledname : string;
  329. begin
  330. mangledname:=definition^.mangledname;
  331. end;
  332. function tprocsym.demangledname:string;
  333. begin
  334. demangledname:=name+definition^.demangled_paras;
  335. end;
  336. procedure tprocsym.write_parameter_lists;
  337. var
  338. p : pprocdef;
  339. begin
  340. p:=definition;
  341. while assigned(p) do
  342. begin
  343. { force the error to be printed }
  344. Verbose.Message1(sym_b_param_list,name+p^.demangled_paras);
  345. p:=p^.nextoverloaded;
  346. end;
  347. end;
  348. procedure tprocsym.check_forward;
  349. var
  350. pd : pprocdef;
  351. oldaktfilepos : tfileposinfo;
  352. begin
  353. { don't check if errors !! }
  354. if status.errorcount>0 then
  355. exit;
  356. pd:=definition;
  357. while assigned(pd) do
  358. begin
  359. if pd^.forwarddef then
  360. begin
  361. oldaktfilepos:=aktfilepos;
  362. aktfilepos:=fileinfo;
  363. if assigned(pd^._class) then
  364. Message1(sym_e_forward_not_resolved,pd^._class^.name^+'.'+name+demangledparas(pd^.demangled_paras))
  365. else
  366. Message1(sym_e_forward_not_resolved,name+pd^.demangled_paras);
  367. aktfilepos:=oldaktfilepos;
  368. end;
  369. pd:=pd^.nextoverloaded;
  370. end;
  371. end;
  372. procedure tprocsym.deref;
  373. var
  374. t : ttoken;
  375. last : pprocdef;
  376. begin
  377. resolvedef(pdef(definition));
  378. if (definition^.options and pooperator) <> 0 then
  379. begin
  380. last:=definition;
  381. while assigned(last^.nextoverloaded) do
  382. last:=last^.nextoverloaded;
  383. for t:=first_overloaded to last_overloaded do
  384. if (name=overloaded_names[t]) then
  385. begin
  386. if assigned(overloaded_operators[t]) then
  387. last^.nextoverloaded:=overloaded_operators[t]^.definition;
  388. overloaded_operators[t]:=@self;
  389. end;
  390. end;
  391. end;
  392. procedure tprocsym.write;
  393. begin
  394. tsym.write;
  395. writedefref(pdef(definition));
  396. current_ppu^.writeentry(ibprocsym);
  397. end;
  398. {$ifdef UseBrowser}
  399. procedure tprocsym.load_references;
  400. var
  401. prdef : pprocdef;
  402. begin
  403. inherited load_references;
  404. prdef:=definition;
  405. { take care about operators !! }
  406. while assigned(prdef) and (prdef^.owner=definition^.owner) do
  407. begin
  408. prdef^.load_references;
  409. prdef:=prdef^.nextoverloaded;
  410. end;
  411. end;
  412. function tprocsym.write_references : boolean;
  413. var
  414. prdef : pprocdef;
  415. begin
  416. write_references:=false;
  417. if not inherited write_references then
  418. exit;
  419. write_references:=true;
  420. prdef:=definition;
  421. while assigned(prdef) and (prdef^.owner=definition^.owner) do
  422. begin
  423. prdef^.write_references;
  424. prdef:=prdef^.nextoverloaded;
  425. end;
  426. end;
  427. procedure tprocsym.add_to_browserlog;
  428. var
  429. prdef : pprocdef;
  430. begin
  431. inherited add_to_browserlog;
  432. prdef:=definition;
  433. while assigned(prdef) do
  434. begin
  435. pprocdef(prdef)^.add_to_browserlog;
  436. prdef:=pprocdef(prdef)^.nextoverloaded;
  437. end;
  438. end;
  439. {$endif UseBrowser}
  440. {$ifdef GDB}
  441. function tprocsym.stabstring : pchar;
  442. Var RetType : Char;
  443. Obj,Info : String;
  444. stabsstr : string;
  445. p : pchar;
  446. begin
  447. obj := name;
  448. info := '';
  449. if is_global then
  450. RetType := 'F'
  451. else
  452. RetType := 'f';
  453. if assigned(owner) then
  454. begin
  455. if (owner^.symtabletype = objectsymtable) then
  456. obj := owner^.name^+'__'+name;
  457. if (owner^.symtabletype=localsymtable) and assigned(owner^.name) then
  458. info := ','+name+','+owner^.name^;
  459. end;
  460. stabsstr:=definition^.mangledname;
  461. getmem(p,length(stabsstr)+255);
  462. strpcopy(p,'"'+obj+':'+RetType
  463. +definition^.retdef^.numberstring+info+'",'+tostr(n_function)
  464. +',0,'+
  465. tostr(aktfilepos.line)
  466. +',');
  467. strpcopy(strend(p),stabsstr);
  468. stabstring:=strnew(p);
  469. freemem(p,length(stabsstr)+255);
  470. end;
  471. procedure tprocsym.concatstabto(asmlist : paasmoutput);
  472. begin
  473. if (definition^.options and pointernproc) <> 0 then exit;
  474. if not isstabwritten then
  475. asmlist^.concat(new(pai_stabs,init(stabstring)));
  476. isstabwritten := true;
  477. if assigned(definition^.parast) then
  478. definition^.parast^.concatstabto(asmlist);
  479. if assigned(definition^.localst) then
  480. definition^.localst^.concatstabto(asmlist);
  481. definition^.is_def_stab_written := true;
  482. end;
  483. {$endif GDB}
  484. {****************************************************************************
  485. TPROGRAMSYM
  486. ****************************************************************************}
  487. constructor tprogramsym.init(const n : string);
  488. begin
  489. inherited init(n);
  490. typ:=programsym;
  491. end;
  492. {****************************************************************************
  493. TERRORSYM
  494. ****************************************************************************}
  495. constructor terrorsym.init;
  496. begin
  497. inherited init('');
  498. typ:=errorsym;
  499. end;
  500. {****************************************************************************
  501. TPROPERTYSYM
  502. ****************************************************************************}
  503. constructor tpropertysym.init(const n : string);
  504. begin
  505. inherited init(n);
  506. typ:=propertysym;
  507. options:=0;
  508. proptype:=nil;
  509. readaccessdef:=nil;
  510. writeaccessdef:=nil;
  511. readaccesssym:=nil;
  512. writeaccesssym:=nil;
  513. storedsym:=nil;
  514. storeddef:=nil;
  515. index:=0;
  516. default:=0;
  517. end;
  518. destructor tpropertysym.done;
  519. begin
  520. inherited done;
  521. end;
  522. constructor tpropertysym.load;
  523. begin
  524. inherited load;
  525. typ:=propertysym;
  526. proptype:=readdefref;
  527. options:=readlong;
  528. index:=readlong;
  529. default:=readlong;
  530. { it's hack ... }
  531. readaccesssym:=psym(stringdup(readstring));
  532. writeaccesssym:=psym(stringdup(readstring));
  533. storedsym:=psym(stringdup(readstring));
  534. { now the defs: }
  535. readaccessdef:=readdefref;
  536. writeaccessdef:=readdefref;
  537. storeddef:=readdefref;
  538. end;
  539. procedure tpropertysym.deref;
  540. begin
  541. resolvedef(proptype);
  542. resolvedef(readaccessdef);
  543. resolvedef(writeaccessdef);
  544. resolvedef(storeddef);
  545. { solve the hack we did in load: }
  546. if pstring(readaccesssym)^<>'' then
  547. begin
  548. srsym:=search_class_member(pobjectdef(owner^.defowner),pstring(readaccesssym)^);
  549. if not(assigned(srsym)) then
  550. srsym:=generrorsym;
  551. end
  552. else
  553. srsym:=nil;
  554. stringdispose(pstring(readaccesssym));
  555. readaccesssym:=srsym;
  556. if pstring(writeaccesssym)^<>'' then
  557. begin
  558. srsym:=search_class_member(pobjectdef(owner^.defowner),pstring(writeaccesssym)^);
  559. if not(assigned(srsym)) then
  560. srsym:=generrorsym;
  561. end
  562. else
  563. srsym:=nil;
  564. stringdispose(pstring(writeaccesssym));
  565. writeaccesssym:=srsym;
  566. if pstring(storedsym)^<>'' then
  567. begin
  568. srsym:=search_class_member(pobjectdef(owner^.defowner),pstring(storedsym)^);
  569. if not(assigned(srsym)) then
  570. srsym:=generrorsym;
  571. end
  572. else
  573. srsym:=nil;
  574. stringdispose(pstring(storedsym));
  575. storedsym:=srsym;
  576. end;
  577. function tpropertysym.getsize : longint;
  578. begin
  579. getsize:=0;
  580. end;
  581. procedure tpropertysym.write;
  582. begin
  583. tsym.write;
  584. writedefref(proptype);
  585. writelong(options);
  586. writelong(index);
  587. writelong(default);
  588. if assigned(readaccesssym) then
  589. writestring(readaccesssym^.name)
  590. else
  591. writestring('');
  592. if assigned(writeaccesssym) then
  593. writestring(writeaccesssym^.name)
  594. else
  595. writestring('');
  596. if assigned(storedsym) then
  597. writestring(storedsym^.name)
  598. else
  599. writestring('');
  600. writedefref(readaccessdef);
  601. writedefref(writeaccessdef);
  602. writedefref(storeddef);
  603. current_ppu^.writeentry(ibpropertysym);
  604. end;
  605. {$ifdef GDB}
  606. function tpropertysym.stabstring : pchar;
  607. begin
  608. { !!!! don't know how to handle }
  609. stabstring:=strpnew('');
  610. end;
  611. procedure tpropertysym.concatstabto(asmlist : paasmoutput);
  612. begin
  613. { !!!! don't know how to handle }
  614. end;
  615. {$endif GDB}
  616. {****************************************************************************
  617. TFUNCRETSYM
  618. ****************************************************************************}
  619. constructor tfuncretsym.init(const n : string;approcinfo : pointer{pprocinfo});
  620. begin
  621. tsym.init(n);
  622. typ:=funcretsym;
  623. funcretprocinfo:=approcinfo;
  624. funcretdef:=pprocinfo(approcinfo)^.retdef;
  625. { address valid for ret in param only }
  626. { otherwise set by insert }
  627. address:=pprocinfo(approcinfo)^.retoffset;
  628. end;
  629. {$ifdef GDB}
  630. procedure tfuncretsym.concatstabto(asmlist : paasmoutput);
  631. begin
  632. { Nothing to do here, it is done in genexitcode }
  633. end;
  634. {$endif GDB}
  635. {****************************************************************************
  636. TABSOLUTESYM
  637. ****************************************************************************}
  638. { constructor tabsolutesym.init(const s : string;p : pdef;newref : psym);
  639. begin
  640. inherited init(s,p);
  641. ref:=newref;
  642. typ:=absolutesym;
  643. end; }
  644. constructor tabsolutesym.load;
  645. begin
  646. tvarsym.load;
  647. typ:=absolutesym;
  648. ref:=nil;
  649. address:=0;
  650. asmname:=nil;
  651. abstyp:=absolutetyp(readbyte);
  652. absseg:=false;
  653. case abstyp of
  654. tovar : begin
  655. asmname:=stringdup(readstring);
  656. ref:=srsym;
  657. end;
  658. toasm : asmname:=stringdup(readstring);
  659. toaddr : address:=readlong;
  660. end;
  661. end;
  662. procedure tabsolutesym.write;
  663. begin
  664. tsym.write;
  665. writebyte(byte(varspez));
  666. if read_member then
  667. writelong(address);
  668. writedefref(definition);
  669. writebyte(var_options and (not vo_regable));
  670. writebyte(byte(abstyp));
  671. case abstyp of
  672. tovar : writestring(ref^.name);
  673. toasm : writestring(asmname^);
  674. toaddr : writelong(address);
  675. end;
  676. current_ppu^.writeentry(ibabsolutesym);
  677. end;
  678. procedure tabsolutesym.deref;
  679. begin
  680. resolvedef(definition);
  681. if (abstyp=tovar) and (asmname<>nil) then
  682. begin
  683. { search previous loaded symtables }
  684. getsym(asmname^,false);
  685. if not(assigned(srsym)) then
  686. getsymonlyin(owner,asmname^);
  687. if not(assigned(srsym)) then
  688. srsym:=generrorsym;
  689. ref:=srsym;
  690. stringdispose(asmname);
  691. end;
  692. end;
  693. function tabsolutesym.mangledname : string;
  694. begin
  695. case abstyp of
  696. tovar : mangledname:=ref^.mangledname;
  697. toasm : mangledname:=asmname^;
  698. toaddr : mangledname:='$'+tostr(address);
  699. else
  700. internalerror(10002);
  701. end;
  702. end;
  703. procedure tabsolutesym.insert_in_data;
  704. begin
  705. end;
  706. {$ifdef GDB}
  707. procedure tabsolutesym.concatstabto(asmlist : paasmoutput);
  708. begin
  709. { I don't know how to handle this !! }
  710. end;
  711. {$endif GDB}
  712. {****************************************************************************
  713. TVARSYM
  714. ****************************************************************************}
  715. constructor tvarsym.init(const n : string;p : pdef);
  716. begin
  717. tsym.init(n);
  718. typ:=varsym;
  719. definition:=p;
  720. _mangledname:=nil;
  721. varspez:=vs_value;
  722. address:=0;
  723. {$ifdef VALUEPARA}
  724. localaddress:=-1;
  725. islocalcopy:=false;
  726. {$endif}
  727. refs:=0;
  728. is_valid := 1;
  729. var_options:=0;
  730. { can we load the value into a register ? }
  731. case p^.deftype of
  732. pointerdef,
  733. enumdef,
  734. procvardef : var_options:=var_options or vo_regable;
  735. orddef : case porddef(p)^.typ of
  736. u8bit,u16bit,u32bit,
  737. bool8bit,bool16bit,bool32bit,
  738. s8bit,s16bit,s32bit :
  739. var_options:=var_options or vo_regable;
  740. else
  741. var_options:=var_options and not vo_regable;
  742. end;
  743. else
  744. var_options:=var_options and not vo_regable;
  745. end;
  746. reg:=R_NO;
  747. end;
  748. constructor tvarsym.init_dll(const n : string;p : pdef);
  749. begin
  750. { The tvarsym is necessary for 0.99.5 (PFV) }
  751. tvarsym.init(n,p);
  752. var_options:=var_options or vo_is_dll_var;
  753. end;
  754. constructor tvarsym.init_C(const n,mangled : string;p : pdef);
  755. begin
  756. { The tvarsym is necessary for 0.99.5 (PFV) }
  757. tvarsym.init(n,p);
  758. var_options:=var_options or vo_is_C_var;
  759. setmangledname(mangled);
  760. end;
  761. constructor tvarsym.load;
  762. begin
  763. tsym.load;
  764. typ:=varsym;
  765. _mangledname:=nil;
  766. reg:=R_NO;
  767. refs := 0;
  768. is_valid := 1;
  769. varspez:=tvarspez(readbyte);
  770. if read_member then
  771. address:=readlong
  772. else
  773. address:=0;
  774. {$ifdef VALUEPARA}
  775. localaddress:=-1;
  776. islocalcopy:=false;
  777. {$endif}
  778. definition:=readdefref;
  779. var_options:=readbyte;
  780. if (var_options and vo_is_C_var)<>0 then
  781. setmangledname(readstring);
  782. end;
  783. procedure tvarsym.deref;
  784. begin
  785. resolvedef(definition);
  786. end;
  787. procedure tvarsym.write;
  788. begin
  789. tsym.write;
  790. writebyte(byte(varspez));
  791. if read_member then
  792. writelong(address);
  793. writedefref(definition);
  794. { symbols which are load are never candidates for a register,
  795. turn of the regable }
  796. writebyte(var_options and (not vo_regable));
  797. if (var_options and vo_is_C_var)<>0 then
  798. writestring(mangledname);
  799. current_ppu^.writeentry(ibvarsym);
  800. end;
  801. procedure tvarsym.setmangledname(const s : string);
  802. begin
  803. _mangledname:=strpnew(s);
  804. end;
  805. function tvarsym.mangledname : string;
  806. var
  807. prefix : string;
  808. begin
  809. if assigned(_mangledname) then
  810. begin
  811. mangledname:=strpas(_mangledname);
  812. exit;
  813. end;
  814. case owner^.symtabletype of
  815. staticsymtable : if (cs_smartlink in aktmoduleswitches) then
  816. prefix:='_'+owner^.name^+'$$$_'
  817. else
  818. prefix:='_';
  819. unitsymtable,
  820. globalsymtable : prefix:='U_'+owner^.name^+'_';
  821. else
  822. Message(sym_e_invalid_call_tvarsymmangledname);
  823. end;
  824. mangledname:=prefix+name;
  825. end;
  826. {$ifndef VALUEPARA}
  827. function tvarsym.getsize : longint;
  828. begin
  829. { only if the definition is set, we could determine the }
  830. { size, this is if an error occurs while reading the type }
  831. { also used for operator, this allows not to allocate the }
  832. { return size twice }
  833. if assigned(definition) then
  834. begin
  835. case varspez of
  836. vs_value : begin
  837. if is_open_array(definition) then
  838. getsize:=target_os.size_of_pointer+target_os.size_of_longint
  839. else
  840. getsize:=definition^.size;
  841. end;
  842. vs_var : begin
  843. { open arrays push also the high valye }
  844. if is_open_array(definition) or
  845. is_open_string(definition) then
  846. getsize:=target_os.size_of_pointer+target_os.size_of_longint
  847. else
  848. getsize:=target_os.size_of_pointer;
  849. end;
  850. vs_const : begin
  851. case definition^.deftype of
  852. stringdef,
  853. recorddef,
  854. objectdef,
  855. setdef : getsize:=target_os.size_of_pointer;
  856. arraydef : begin
  857. { open arrays push also the high valye }
  858. if is_open_array(definition) then
  859. getsize:=target_os.size_of_pointer+target_os.size_of_longint
  860. else
  861. getsize:=target_os.size_of_pointer;
  862. end;
  863. else
  864. getsize:=definition^.size;
  865. end;
  866. end;
  867. end;
  868. end
  869. else
  870. getsize:=0;
  871. end;
  872. {$else}
  873. function tvarsym.getsize : longint;
  874. begin
  875. if assigned(definition) and (varspez=vs_value) then
  876. getsize:=definition^.size
  877. else
  878. getsize:=0;
  879. end;
  880. function tvarsym.getpushsize : longint;
  881. begin
  882. if assigned(definition) then
  883. begin
  884. case varspez of
  885. vs_var :
  886. begin
  887. { open arrays push also the high valye }
  888. if is_open_array(definition) or
  889. is_open_string(definition) then
  890. getpushsize:=target_os.size_of_pointer+target_os.size_of_longint
  891. else
  892. getpushsize:=target_os.size_of_pointer;
  893. end;
  894. vs_value,
  895. vs_const :
  896. begin
  897. case definition^.deftype of
  898. setdef,
  899. stringdef,
  900. recorddef,
  901. objectdef :
  902. getpushsize:=target_os.size_of_pointer;
  903. arraydef :
  904. if is_open_array(definition) then
  905. getpushsize:=target_os.size_of_pointer+target_os.size_of_longint
  906. else
  907. getpushsize:=target_os.size_of_pointer;
  908. else
  909. getpushsize:=definition^.size;
  910. end;
  911. end;
  912. end;
  913. end
  914. else
  915. getpushsize:=0;
  916. end;
  917. {$endif}
  918. procedure tvarsym.insert_in_data;
  919. var
  920. l,modulo : longint;
  921. begin
  922. if (var_options and vo_is_external)<>0 then
  923. exit;
  924. { handle static variables of objects especially }
  925. if read_member and (owner^.symtabletype=objectsymtable) and
  926. ((properties and sp_static)<>0) then
  927. begin
  928. { the data filed is generated in parser.pas
  929. with a tobject_FIELDNAME variable }
  930. { this symbol can't be loaded to a register }
  931. var_options:=var_options and not vo_regable;
  932. end
  933. else
  934. if not(read_member) then
  935. begin
  936. { made problems with parameters etc. ! (FK) }
  937. { check for instance of an abstract object or class }
  938. {
  939. if (pvarsym(sym)^.definition^.deftype=objectdef) and
  940. ((pobjectdef(pvarsym(sym)^.definition)^.options and oo_is_abstract)<>0) then
  941. Message(sym_e_no_instance_of_abstract_object);
  942. }
  943. l:=getsize;
  944. case owner^.symtabletype of
  945. stt_exceptsymtable:
  946. { can contain only one symbol, address calculated later }
  947. ;
  948. localsymtable :
  949. begin
  950. is_valid := 0;
  951. modulo:=owner^.datasize and 3;
  952. {$ifdef m68k}
  953. { word alignment required for motorola }
  954. if (l=1) then
  955. l:=2
  956. else
  957. {$endif}
  958. if (l>=4) and (modulo<>0) then
  959. inc(l,4-modulo)
  960. else
  961. if (l>=2) and ((modulo and 1)<>0) then
  962. inc(l,2-(modulo and 1));
  963. inc(owner^.datasize,l);
  964. address:=owner^.datasize;
  965. end;
  966. staticsymtable :
  967. begin
  968. if (cs_smartlink in aktmoduleswitches) then
  969. bsssegment^.concat(new(pai_cut,init));
  970. {$ifdef GDB}
  971. if cs_debuginfo in aktmoduleswitches then
  972. concatstabto(bsssegment);
  973. {$endif GDB}
  974. if (cs_smartlink in aktmoduleswitches) or
  975. ((var_options and vo_is_c_var)<>0) then
  976. bsssegment^.concat(new(pai_datablock,init_global(mangledname,l)))
  977. else
  978. bsssegment^.concat(new(pai_datablock,init(mangledname,l)));
  979. { increase datasize }
  980. inc(owner^.datasize,l);
  981. { this symbol can't be loaded to a register }
  982. var_options:=var_options and not vo_regable;
  983. end;
  984. globalsymtable :
  985. begin
  986. if (cs_smartlink in aktmoduleswitches) then
  987. bsssegment^.concat(new(pai_cut,init));
  988. {$ifdef GDB}
  989. if cs_debuginfo in aktmoduleswitches then
  990. concatstabto(bsssegment);
  991. {$endif GDB}
  992. bsssegment^.concat(new(pai_datablock,init_global(mangledname,l)));
  993. inc(owner^.datasize,l);
  994. { this symbol can't be loaded to a register }
  995. var_options:=var_options and not vo_regable;
  996. end;
  997. recordsymtable,
  998. objectsymtable :
  999. begin
  1000. { this symbol can't be loaded to a register }
  1001. var_options:=var_options and not vo_regable;
  1002. { align record and object fields }
  1003. if (l=1) or (aktpackrecords=1) then
  1004. begin
  1005. address:=owner^.datasize;
  1006. inc(owner^.datasize,l)
  1007. end
  1008. else
  1009. if (l=2) or (aktpackrecords=2) then
  1010. begin
  1011. owner^.datasize:=(owner^.datasize+1) and (not 1);
  1012. address:=owner^.datasize;
  1013. inc(owner^.datasize,l)
  1014. end
  1015. else
  1016. if (l<=4) or (aktpackrecords=4) then
  1017. begin
  1018. owner^.datasize:=(owner^.datasize+3) and (not 3);
  1019. address:=owner^.datasize;
  1020. inc(owner^.datasize,l);
  1021. end
  1022. else
  1023. if (l<=8) or (aktpackrecords=8) then
  1024. begin
  1025. owner^.datasize:=(owner^.datasize+7) and (not 7);
  1026. address:=owner^.datasize;
  1027. inc(owner^.datasize,l);
  1028. end
  1029. else
  1030. if (l<=16) or (aktpackrecords=16) then
  1031. begin
  1032. owner^.datasize:=(owner^.datasize+15) and (not 15);
  1033. address:=owner^.datasize;
  1034. inc(owner^.datasize,l);
  1035. end
  1036. else
  1037. if (l<=32) or (aktpackrecords=32) then
  1038. begin
  1039. owner^.datasize:=(owner^.datasize+31) and (not 31);
  1040. address:=owner^.datasize;
  1041. inc(owner^.datasize,l);
  1042. end;
  1043. end;
  1044. parasymtable :
  1045. begin
  1046. {$ifdef VALUEPARA}
  1047. { here we need the size of a push instead of the
  1048. size of the data }
  1049. l:=getpushsize;
  1050. {$endif}
  1051. address:=owner^.datasize;
  1052. owner^.datasize:=align(owner^.datasize+l,target_os.stackalignment);
  1053. end
  1054. else
  1055. begin
  1056. modulo:=owner^.datasize and 3 ;
  1057. if (l>=4) and (modulo<>0) then
  1058. inc(owner^.datasize,4-modulo)
  1059. else
  1060. if (l>=2) and ((modulo and 1)<>0) then
  1061. inc(owner^.datasize);
  1062. address:=owner^.datasize;
  1063. inc(owner^.datasize,l);
  1064. end;
  1065. end;
  1066. end;
  1067. end;
  1068. {$ifdef GDB}
  1069. function tvarsym.stabstring : pchar;
  1070. var
  1071. st : char;
  1072. begin
  1073. if (owner^.symtabletype = objectsymtable) and
  1074. ((properties and sp_static)<>0) then
  1075. begin
  1076. if (cs_gdb_gsym in aktglobalswitches) then st := 'G' else st := 'S';
  1077. stabstring := strpnew('"'+owner^.name^+'__'+name+':'+
  1078. +definition^.numberstring+'",'+
  1079. tostr(N_LCSYM)+',0,'+tostr(fileinfo.line)+','+mangledname);
  1080. end
  1081. else if (owner^.symtabletype = globalsymtable) or
  1082. (owner^.symtabletype = unitsymtable) then
  1083. begin
  1084. { Here we used S instead of
  1085. because with G GDB doesn't look at the address field
  1086. but searches the same name or with a leading underscore
  1087. but these names don't exist in pascal !}
  1088. if (cs_gdb_gsym in aktglobalswitches) then st := 'G' else st := 'S';
  1089. stabstring := strpnew('"'+name+':'+st
  1090. +definition^.numberstring+'",'+
  1091. tostr(N_LCSYM)+',0,'+tostr(fileinfo.line)+','+mangledname);
  1092. end
  1093. else if owner^.symtabletype = staticsymtable then
  1094. begin
  1095. stabstring := strpnew('"'+name+':S'
  1096. +definition^.numberstring+'",'+
  1097. tostr(N_LCSYM)+',0,'+tostr(fileinfo.line)+','+mangledname);
  1098. end
  1099. else if (owner^.symtabletype=parasymtable) then
  1100. begin
  1101. case varspez of
  1102. vs_value : st := 'p';
  1103. vs_var : st := 'v';
  1104. {$ifdef VALUEPARA}
  1105. vs_const : if push_addr_param(definition) then
  1106. {$else}
  1107. vs_const : if dont_copy_const_param(definition) then
  1108. {$endif}
  1109. st := 'v'{ should be 'i' but 'i' doesn't work }
  1110. else
  1111. st := 'p';
  1112. end;
  1113. stabstring := strpnew('"'+name+':'+st
  1114. +definition^.numberstring+'",'+
  1115. tostr(N_PSYM)+',0,'+tostr(fileinfo.line)+','+
  1116. tostr(address+owner^.call_offset));
  1117. {offset to ebp => will not work if the framepointer is esp
  1118. so some optimizing will make things harder to debug }
  1119. end
  1120. else if (owner^.symtabletype=localsymtable) then
  1121. {$ifdef i386}
  1122. if reg<>R_NO then
  1123. begin
  1124. { "eax", "ecx", "edx", "ebx", "esp", "ebp", "esi", "edi", "eip", "ps", "cs", "ss", "ds", "es", "fs", "gs", }
  1125. { this is the register order for GDB}
  1126. stabstring:=strpnew('"'+name+':r'
  1127. +definition^.numberstring+'",'+
  1128. tostr(N_RSYM)+',0,'+
  1129. tostr(fileinfo.line)+','+tostr(GDB_i386index[reg]));
  1130. end
  1131. else
  1132. {$endif i386}
  1133. stabstring := strpnew('"'+name+':'
  1134. +definition^.numberstring+'",'+
  1135. tostr(N_LSYM)+',0,'+tostr(fileinfo.line)+',-'+tostr(address))
  1136. else
  1137. stabstring := inherited stabstring;
  1138. end;
  1139. procedure tvarsym.concatstabto(asmlist : paasmoutput);
  1140. {$ifdef i386}
  1141. var stab_str : pchar;
  1142. {$endif i386}
  1143. begin
  1144. inherited concatstabto(asmlist);
  1145. {$ifdef i386}
  1146. if (owner^.symtabletype=parasymtable) and
  1147. (reg<>R_NO) then
  1148. begin
  1149. { "eax", "ecx", "edx", "ebx", "esp", "ebp", "esi", "edi", "eip", "ps", "cs", "ss", "ds", "es", "fs", "gs", }
  1150. { this is the register order for GDB}
  1151. stab_str:=strpnew('"'+name+':r'
  1152. +definition^.numberstring+'",'+
  1153. tostr(N_RSYM)+',0,'+
  1154. tostr(fileinfo.line)+','+tostr(GDB_i386index[reg]));
  1155. asmlist^.concat(new(pai_stabs,init(stab_str)));
  1156. end;
  1157. {$endif i386}
  1158. end;
  1159. {$endif GDB}
  1160. destructor tvarsym.done;
  1161. begin
  1162. strdispose(_mangledname);
  1163. inherited done;
  1164. end;
  1165. {****************************************************************************
  1166. TTYPEDCONSTSYM
  1167. *****************************************************************************}
  1168. constructor ttypedconstsym.init(const n : string;p : pdef);
  1169. begin
  1170. tsym.init(n);
  1171. typ:=typedconstsym;
  1172. definition:=p;
  1173. prefix:=stringdup(procprefix);
  1174. end;
  1175. constructor ttypedconstsym.load;
  1176. begin
  1177. tsym.load;
  1178. typ:=typedconstsym;
  1179. definition:=readdefref;
  1180. prefix:=stringdup(readstring);
  1181. end;
  1182. destructor ttypedconstsym.done;
  1183. begin
  1184. stringdispose(prefix);
  1185. tsym.done;
  1186. end;
  1187. function ttypedconstsym.mangledname : string;
  1188. begin
  1189. mangledname:='TC_'+prefix^+'_'+name;
  1190. end;
  1191. function ttypedconstsym.getsize : longint;
  1192. begin
  1193. if assigned(definition) then
  1194. getsize:=definition^.size
  1195. else
  1196. getsize:=0;
  1197. end;
  1198. procedure ttypedconstsym.deref;
  1199. begin
  1200. resolvedef(definition);
  1201. end;
  1202. procedure ttypedconstsym.write;
  1203. begin
  1204. tsym.write;
  1205. writedefref(definition);
  1206. writestring(prefix^);
  1207. current_ppu^.writeentry(ibtypedconstsym);
  1208. end;
  1209. { for most symbol types ther is nothing to do at all }
  1210. procedure ttypedconstsym.insert_in_data;
  1211. begin
  1212. { here there is a problem for ansistrings !! }
  1213. { we must write the label only after the 12 header bytes (PM)
  1214. if not is_ansistring(definition) then
  1215. }
  1216. { solved, the ansis string is moved to consts (FK) }
  1217. really_insert_in_data;
  1218. end;
  1219. procedure ttypedconstsym.really_insert_in_data;
  1220. begin
  1221. if owner^.symtabletype=globalsymtable then
  1222. begin
  1223. if (cs_smartlink in aktmoduleswitches) then
  1224. datasegment^.concat(new(pai_cut,init));
  1225. {$ifdef GDB}
  1226. if cs_debuginfo in aktmoduleswitches then
  1227. concatstabto(datasegment);
  1228. {$endif GDB}
  1229. datasegment^.concat(new(pai_symbol,init_global(mangledname)));
  1230. end
  1231. else
  1232. if owner^.symtabletype<>unitsymtable then
  1233. begin
  1234. if (cs_smartlink in aktmoduleswitches) then
  1235. datasegment^.concat(new(pai_cut,init));
  1236. {$ifdef GDB}
  1237. if cs_debuginfo in aktmoduleswitches then
  1238. concatstabto(datasegment);
  1239. {$endif GDB}
  1240. if (cs_smartlink in aktmoduleswitches) then
  1241. datasegment^.concat(new(pai_symbol,init_global(mangledname)))
  1242. else
  1243. datasegment^.concat(new(pai_symbol,init(mangledname)));
  1244. end;
  1245. end;
  1246. {$ifdef GDB}
  1247. function ttypedconstsym.stabstring : pchar;
  1248. var
  1249. st : char;
  1250. begin
  1251. if (cs_gdb_gsym in aktglobalswitches) and (owner^.symtabletype in [unitsymtable,globalsymtable]) then
  1252. st := 'G'
  1253. else
  1254. st := 'S';
  1255. stabstring := strpnew('"'+name+':'+st+
  1256. definition^.numberstring+'",'+tostr(n_STSYM)+',0,'+
  1257. tostr(fileinfo.line)+','+mangledname);
  1258. end;
  1259. {$endif GDB}
  1260. {****************************************************************************
  1261. TCONSTSYM
  1262. ****************************************************************************}
  1263. constructor tconstsym.init(const n : string;t : tconsttype;v : longint;def : pdef);
  1264. begin
  1265. tsym.init(n);
  1266. typ:=constsym;
  1267. definition:=def;
  1268. consttype:=t;
  1269. value:=v;
  1270. end;
  1271. constructor tconstsym.load;
  1272. var
  1273. pd : pbestreal;
  1274. ps : pnormalset;
  1275. begin
  1276. tsym.load;
  1277. typ:=constsym;
  1278. consttype:=tconsttype(readbyte);
  1279. case consttype of
  1280. constint,
  1281. constbool,
  1282. constchar : value:=readlong;
  1283. constord : begin
  1284. definition:=readdefref;
  1285. value:=readlong;
  1286. end;
  1287. conststring : value:=longint(stringdup(readstring));
  1288. constreal : begin
  1289. new(pd);
  1290. pd^:=readreal;
  1291. value:=longint(pd);
  1292. end;
  1293. constset : begin
  1294. definition:=readdefref;
  1295. new(ps);
  1296. readnormalset(ps^);
  1297. value:=longint(ps);
  1298. end;
  1299. else
  1300. Message1(unit_f_ppu_invalid_entry,tostr(ord(consttype)));
  1301. end;
  1302. end;
  1303. destructor tconstsym.done;
  1304. begin
  1305. case consttype of
  1306. conststring : stringdispose(pstring(value));
  1307. constreal : dispose(pbestreal(value));
  1308. constset : dispose(pnormalset(value));
  1309. end;
  1310. inherited done;
  1311. end;
  1312. function tconstsym.mangledname : string;
  1313. begin
  1314. mangledname:=name;
  1315. end;
  1316. procedure tconstsym.deref;
  1317. begin
  1318. if consttype in [constord,constset] then
  1319. resolvedef(pdef(definition));
  1320. end;
  1321. procedure tconstsym.write;
  1322. begin
  1323. tsym.write;
  1324. writebyte(byte(consttype));
  1325. case consttype of
  1326. constint,
  1327. constbool,
  1328. constchar : writelong(value);
  1329. constord : begin
  1330. writedefref(definition);
  1331. writelong(value);
  1332. end;
  1333. conststring : writestring(pstring(value)^);
  1334. constreal : writereal(pbestreal(value)^);
  1335. constset : begin
  1336. writedefref(definition);
  1337. writenormalset(pointer(value)^);
  1338. end;
  1339. else
  1340. internalerror(13);
  1341. end;
  1342. current_ppu^.writeentry(ibconstsym);
  1343. end;
  1344. {$ifdef GDB}
  1345. function tconstsym.stabstring : pchar;
  1346. var st : string;
  1347. begin
  1348. {even GDB v4.16 only now 'i' 'r' and 'e' !!!}
  1349. case consttype of
  1350. conststring : begin
  1351. { I had to remove ibm2ascii !! }
  1352. st := pstring(value)^;
  1353. {st := ibm2ascii(pstring(value)^);}
  1354. st := 's'''+st+'''';
  1355. end;
  1356. constbool, constint, constord, constchar : st := 'i'+tostr(value);
  1357. constreal : begin
  1358. system.str(pbestreal(value)^,st);
  1359. st := 'r'+st;
  1360. end;
  1361. { if we don't know just put zero !! }
  1362. else st:='i0';
  1363. {***SETCONST}
  1364. {constset:;} {*** I don't know what to do with a set.}
  1365. { sets are not recognized by GDB}
  1366. {***}
  1367. end;
  1368. stabstring := strpnew('"'+name+':c='+st+'",'+tostr(N_function)+',0,'+
  1369. tostr(fileinfo.line)+',0');
  1370. end;
  1371. procedure tconstsym.concatstabto(asmlist : paasmoutput);
  1372. begin
  1373. if consttype <> conststring then
  1374. inherited concatstabto(asmlist);
  1375. end;
  1376. {$endif GDB}
  1377. {****************************************************************************
  1378. TENUMSYM
  1379. ****************************************************************************}
  1380. constructor tenumsym.init(const n : string;def : penumdef;v : longint);
  1381. begin
  1382. tsym.init(n);
  1383. typ:=enumsym;
  1384. definition:=def;
  1385. value:=v;
  1386. if def^.min>v then
  1387. def^.setmin(v);
  1388. if def^.max<v then
  1389. def^.setmax(v);
  1390. order;
  1391. end;
  1392. constructor tenumsym.load;
  1393. begin
  1394. tsym.load;
  1395. typ:=enumsym;
  1396. definition:=penumdef(readdefref);
  1397. value:=readlong;
  1398. next := Nil;
  1399. end;
  1400. procedure tenumsym.deref;
  1401. begin
  1402. resolvedef(pdef(definition));
  1403. order;
  1404. end;
  1405. procedure tenumsym.order;
  1406. var
  1407. sym : penumsym;
  1408. begin
  1409. sym := definition^.first;
  1410. if sym = nil then
  1411. begin
  1412. definition^.first := @self;
  1413. next := nil;
  1414. exit;
  1415. end;
  1416. { reorder the symbols in increasing value }
  1417. if value < sym^.value then
  1418. begin
  1419. next := sym;
  1420. definition^.first := @self;
  1421. end
  1422. else
  1423. begin
  1424. while (sym^.value <= value) and assigned(sym^.next) do
  1425. sym := sym^.next;
  1426. next := sym^.next;
  1427. sym^.next := @self;
  1428. end;
  1429. end;
  1430. procedure tenumsym.write;
  1431. begin
  1432. tsym.write;
  1433. writedefref(definition);
  1434. writelong(value);
  1435. current_ppu^.writeentry(ibenumsym);
  1436. end;
  1437. {$ifdef GDB}
  1438. procedure tenumsym.concatstabto(asmlist : paasmoutput);
  1439. begin
  1440. {enum elements have no stab !}
  1441. end;
  1442. {$EndIf GDB}
  1443. {****************************************************************************
  1444. TTYPESYM
  1445. ****************************************************************************}
  1446. constructor ttypesym.init(const n : string;d : pdef);
  1447. begin
  1448. tsym.init(n);
  1449. typ:=typesym;
  1450. definition:=d;
  1451. {$ifdef GDB}
  1452. isusedinstab := false;
  1453. {$endif GDB}
  1454. forwardpointer:=nil;
  1455. { this allows to link definitions with the type with declares }
  1456. { them }
  1457. if assigned(definition) then
  1458. if definition^.sym=nil then
  1459. definition^.sym:=@self;
  1460. end;
  1461. constructor ttypesym.load;
  1462. begin
  1463. tsym.load;
  1464. typ:=typesym;
  1465. forwardpointer:=nil;
  1466. {$ifdef GDB}
  1467. isusedinstab := false;
  1468. {$endif GDB}
  1469. definition:=readdefref;
  1470. end;
  1471. destructor ttypesym.done;
  1472. begin
  1473. if assigned(definition) then
  1474. if definition^.sym=@self then
  1475. definition^.sym:=nil;
  1476. inherited done;
  1477. end;
  1478. procedure ttypesym.deref;
  1479. begin
  1480. resolvedef(definition);
  1481. if assigned(definition) then
  1482. begin
  1483. if definition^.sym=nil then
  1484. definition^.sym:=@self;
  1485. if (definition^.deftype=recorddef) and assigned(precdef(definition)^.symtable) and
  1486. (definition^.sym=@self) then
  1487. precdef(definition)^.symtable^.name:=stringdup('record '+name);
  1488. end;
  1489. end;
  1490. procedure ttypesym.write;
  1491. begin
  1492. tsym.write;
  1493. writedefref(definition);
  1494. current_ppu^.writeentry(ibtypesym);
  1495. end;
  1496. {$ifdef UseBrowser}
  1497. procedure ttypesym.load_references;
  1498. begin
  1499. inherited load_references;
  1500. if (definition^.deftype=recorddef) then
  1501. precdef(definition)^.symtable^.load_browser;
  1502. if (definition^.deftype=objectdef) then
  1503. pobjectdef(definition)^.publicsyms^.load_browser;
  1504. end;
  1505. function ttypesym.write_references : boolean;
  1506. begin
  1507. if not inherited write_references then
  1508. { write address of this symbol if record or object
  1509. even if no real refs are there
  1510. because we need it for the symtable }
  1511. if (definition^.deftype=recorddef) or
  1512. (definition^.deftype=objectdef) then
  1513. begin
  1514. writesymref(@self);
  1515. current_ppu^.writeentry(ibsymref);
  1516. end;
  1517. write_references:=true;
  1518. if (definition^.deftype=recorddef) then
  1519. precdef(definition)^.symtable^.write_browser;
  1520. if (definition^.deftype=objectdef) then
  1521. pobjectdef(definition)^.publicsyms^.write_browser;
  1522. end;
  1523. procedure ttypesym.add_to_browserlog;
  1524. begin
  1525. inherited add_to_browserlog;
  1526. if (definition^.deftype=recorddef) then
  1527. precdef(definition)^.symtable^.writebrowserlog;
  1528. if (definition^.deftype=objectdef) then
  1529. pobjectdef(definition)^.publicsyms^.writebrowserlog;
  1530. end;
  1531. {$endif UseBrowser}
  1532. {$ifdef GDB}
  1533. function ttypesym.stabstring : pchar;
  1534. var stabchar : string[2];
  1535. short : string;
  1536. begin
  1537. if definition^.deftype in tagtypes then
  1538. stabchar := 'Tt'
  1539. else
  1540. stabchar := 't';
  1541. short := '"'+name+':'+stabchar+definition^.numberstring
  1542. +'",'+tostr(N_LSYM)+',0,'+tostr(fileinfo.line)+',0';
  1543. stabstring := strpnew(short);
  1544. end;
  1545. procedure ttypesym.concatstabto(asmlist : paasmoutput);
  1546. begin
  1547. {not stabs for forward defs }
  1548. if assigned(definition) then
  1549. if (definition^.sym = @self) then
  1550. definition^.concatstabto(asmlist)
  1551. else
  1552. inherited concatstabto(asmlist);
  1553. end;
  1554. {$endif GDB}
  1555. {****************************************************************************
  1556. TSYSSYM
  1557. ****************************************************************************}
  1558. constructor tsyssym.init(const n : string;l : longint);
  1559. begin
  1560. inherited init(n);
  1561. typ:=syssym;
  1562. number:=l;
  1563. end;
  1564. procedure tsyssym.write;
  1565. begin
  1566. end;
  1567. {$ifdef GDB}
  1568. procedure tsyssym.concatstabto(asmlist : paasmoutput);
  1569. begin
  1570. end;
  1571. {$endif GDB}
  1572. {****************************************************************************
  1573. TMACROSYM
  1574. ****************************************************************************}
  1575. constructor tmacrosym.init(const n : string);
  1576. begin
  1577. inherited init(n);
  1578. typ:=macrosym;
  1579. defined:=true;
  1580. buftext:=nil;
  1581. buflen:=0;
  1582. end;
  1583. destructor tmacrosym.done;
  1584. begin
  1585. if assigned(buftext) then
  1586. freemem(buftext,buflen);
  1587. inherited done;
  1588. end;
  1589. {
  1590. $Log$
  1591. Revision 1.64 1998-12-08 10:18:15 peter
  1592. + -gh for heaptrc unit
  1593. Revision 1.63 1998/11/28 16:20:56 peter
  1594. + support for dll variables
  1595. Revision 1.62 1998/11/27 14:50:48 peter
  1596. + open strings, $P switch support
  1597. Revision 1.61 1998/11/18 15:44:18 peter
  1598. * VALUEPARA for tp7 compatible value parameters
  1599. Revision 1.60 1998/11/16 10:13:51 peter
  1600. * label defines are checked at the end of the proc
  1601. Revision 1.59 1998/11/13 12:09:11 peter
  1602. * unused label is now a warning
  1603. Revision 1.58 1998/11/10 10:50:57 pierre
  1604. * temporary fix for long mangled procsym names
  1605. Revision 1.57 1998/11/05 23:39:31 peter
  1606. + typedconst.getsize
  1607. Revision 1.56 1998/10/28 18:26:18 pierre
  1608. * removed some erros after other errors (introduced by useexcept)
  1609. * stabs works again correctly (for how long !)
  1610. Revision 1.55 1998/10/20 08:07:00 pierre
  1611. * several memory corruptions due to double freemem solved
  1612. => never use p^.loc.location:=p^.left^.loc.location;
  1613. + finally I added now by default
  1614. that ra386dir translates global and unit symbols
  1615. + added a first field in tsymtable and
  1616. a nextsym field in tsym
  1617. (this allows to obtain ordered type info for
  1618. records and objects in gdb !)
  1619. Revision 1.54 1998/10/19 08:55:07 pierre
  1620. * wrong stabs info corrected once again !!
  1621. + variable vmt offset with vmt field only if required
  1622. implemented now !!!
  1623. Revision 1.53 1998/10/16 08:51:53 peter
  1624. + target_os.stackalignment
  1625. + stack can be aligned at 2 or 4 byte boundaries
  1626. Revision 1.52 1998/10/08 17:17:32 pierre
  1627. * current_module old scanner tagged as invalid if unit is recompiled
  1628. + added ppheap for better info on tracegetmem of heaptrc
  1629. (adds line column and file index)
  1630. * several memory leaks removed ith help of heaptrc !!
  1631. Revision 1.51 1998/10/08 13:48:50 peter
  1632. * fixed memory leaks for do nothing source
  1633. * fixed unit interdependency
  1634. Revision 1.50 1998/10/06 17:16:56 pierre
  1635. * some memory leaks fixed (thanks to Peter for heaptrc !)
  1636. Revision 1.49 1998/10/01 09:22:55 peter
  1637. * fixed value openarray
  1638. * ungettemp of arrayconstruct
  1639. Revision 1.48 1998/09/26 17:45:44 peter
  1640. + idtoken and only one token table
  1641. Revision 1.47 1998/09/24 15:11:17 peter
  1642. * fixed enum for not GDB
  1643. Revision 1.46 1998/09/23 15:39:13 pierre
  1644. * browser bugfixes
  1645. was adding a reference when looking for the symbol
  1646. if -bSYM_NAME was used
  1647. Revision 1.45 1998/09/21 08:45:24 pierre
  1648. + added vmt_offset in tobjectdef.write for fututre use
  1649. (first steps to have objects without vmt if no virtual !!)
  1650. + added fpu_used field for tabstractprocdef :
  1651. sets this level to 2 if the functions return with value in FPU
  1652. (is then set to correct value at parsing of implementation)
  1653. THIS MIGHT refuse some code with FPU expression too complex
  1654. that were accepted before and even in some cases
  1655. that don't overflow in fact
  1656. ( like if f : float; is a forward that finally in implementation
  1657. only uses one fpu register !!)
  1658. Nevertheless I think that it will improve security on
  1659. FPU operations !!
  1660. * most other changes only for UseBrowser code
  1661. (added symtable references for record and objects)
  1662. local switch for refs to args and local of each function
  1663. (static symtable still missing)
  1664. UseBrowser still not stable and probably broken by
  1665. the definition hash array !!
  1666. Revision 1.44 1998/09/18 16:03:47 florian
  1667. * some changes to compile with Delphi
  1668. Revision 1.43 1998/09/18 08:01:38 pierre
  1669. + improvement on the usebrowser part
  1670. (does not work correctly for now)
  1671. Revision 1.42 1998/09/07 19:33:25 florian
  1672. + some stuff for property rtti added:
  1673. - NameIndex of the TPropInfo record is now written correctly
  1674. - the DEFAULT/NODEFAULT keyword is supported now
  1675. - the default value and the storedsym/def are now written to
  1676. the PPU fiel
  1677. Revision 1.41 1998/09/07 18:46:12 peter
  1678. * update smartlinking, uses getdatalabel
  1679. * renamed ptree.value vars to value_str,value_real,value_set
  1680. Revision 1.40 1998/09/07 17:37:04 florian
  1681. * first fixes for published properties
  1682. Revision 1.39 1998/09/05 22:11:02 florian
  1683. + switch -vb
  1684. * while/repeat loops accept now also word/longbool conditions
  1685. * makebooltojump did an invalid ungetregister32, fixed
  1686. Revision 1.38 1998/09/01 12:53:26 peter
  1687. + aktpackenum
  1688. Revision 1.37 1998/09/01 07:54:25 pierre
  1689. * UseBrowser a little updated (might still be buggy !!)
  1690. * bug in psub.pas in function specifier removed
  1691. * stdcall allowed in interface and in implementation
  1692. (FPC will not yet complain if it is missing in either part
  1693. because stdcall is only a dummy !!)
  1694. Revision 1.36 1998/08/25 13:09:26 pierre
  1695. * corrected mangling sheme :
  1696. cvar add Cprefix to the mixed case name whereas
  1697. export or public use direct name
  1698. Revision 1.35 1998/08/25 12:42:46 pierre
  1699. * CDECL changed to CVAR for variables
  1700. specifications are read in structures also
  1701. + started adding GPC compatibility mode ( option -Sp)
  1702. * names changed to lowercase
  1703. Revision 1.34 1998/08/21 14:08:53 pierre
  1704. + TEST_FUNCRET now default (old code removed)
  1705. works also for m68k (at least compiles)
  1706. Revision 1.33 1998/08/20 12:53:27 peter
  1707. * object_options are always written for object syms
  1708. Revision 1.32 1998/08/20 09:26:46 pierre
  1709. + funcret setting in underproc testing
  1710. compile with _dTEST_FUNCRET
  1711. Revision 1.31 1998/08/17 10:10:12 peter
  1712. - removed OLDPPU
  1713. Revision 1.30 1998/08/13 10:57:29 peter
  1714. * constant sets are now written correctly to the ppufile
  1715. Revision 1.29 1998/08/11 15:31:42 peter
  1716. * write extended to ppu file
  1717. * new version 0.99.7
  1718. Revision 1.28 1998/08/11 14:07:27 peter
  1719. * fixed pushing of high value for openarray
  1720. Revision 1.27 1998/08/10 14:50:31 peter
  1721. + localswitches, moduleswitches, globalswitches splitting
  1722. Revision 1.26 1998/08/10 10:18:35 peter
  1723. + Compiler,Comphook unit which are the new interface units to the
  1724. compiler
  1725. Revision 1.25 1998/07/30 11:18:19 florian
  1726. + first implementation of try ... except on .. do end;
  1727. * limitiation of 65535 bytes parameters for cdecl removed
  1728. Revision 1.24 1998/07/20 18:40:16 florian
  1729. * handling of ansi string constants should now work
  1730. Revision 1.23 1998/07/14 21:37:24 peter
  1731. * fixed packrecords as discussed at the alias
  1732. Revision 1.22 1998/07/14 14:47:08 peter
  1733. * released NEWINPUT
  1734. Revision 1.21 1998/07/13 21:17:38 florian
  1735. * changed to compile with TP
  1736. Revision 1.20 1998/07/10 00:00:05 peter
  1737. * fixed ttypesym bug finally
  1738. * fileinfo in the symtable and better using for unused vars
  1739. Revision 1.19 1998/07/07 17:40:39 peter
  1740. * packrecords 4 works
  1741. * word aligning of parameters
  1742. Revision 1.18 1998/07/07 11:20:15 peter
  1743. + NEWINPUT for a better inputfile and scanner object
  1744. Revision 1.17 1998/06/24 14:48:40 peter
  1745. * ifdef newppu -> ifndef oldppu
  1746. Revision 1.16 1998/06/19 15:40:42 peter
  1747. * removed cosntructor/constructor warning and 0.99.5 recompiles it again
  1748. Revision 1.15 1998/06/17 14:10:18 peter
  1749. * small os2 fixes
  1750. * fixed interdependent units with newppu (remake3 under linux works now)
  1751. Revision 1.14 1998/06/16 08:56:34 peter
  1752. + targetcpu
  1753. * cleaner pmodules for newppu
  1754. Revision 1.13 1998/06/15 15:38:10 pierre
  1755. * small bug in systems.pas corrected
  1756. + operators in different units better hanlded
  1757. Revision 1.12 1998/06/15 14:23:44 daniel
  1758. * Reverted my changes.
  1759. Revision 1.10 1998/06/13 00:10:18 peter
  1760. * working browser and newppu
  1761. * some small fixes against crashes which occured in bp7 (but not in
  1762. fpc?!)
  1763. Revision 1.9 1998/06/12 16:15:35 pierre
  1764. * external name 'C_var';
  1765. export name 'intern_C_var';
  1766. cdecl;
  1767. cdecl;external;
  1768. are now supported only with -Sv switch
  1769. Revision 1.8 1998/06/11 10:11:59 peter
  1770. * -gb works again
  1771. Revision 1.7 1998/06/09 16:01:51 pierre
  1772. + added procedure directive parsing for procvars
  1773. (accepted are popstack cdecl and pascal)
  1774. + added C vars with the following syntax
  1775. var C calias 'true_c_name';(can be followed by external)
  1776. reason is that you must add the Cprefix
  1777. which is target dependent
  1778. Revision 1.6 1998/06/08 22:59:53 peter
  1779. * smartlinking works for win32
  1780. * some defines to exclude some compiler parts
  1781. Revision 1.5 1998/06/04 23:52:02 peter
  1782. * m68k compiles
  1783. + .def file creation moved to gendef.pas so it could also be used
  1784. for win32
  1785. Revision 1.4 1998/06/04 09:55:46 pierre
  1786. * demangled name of procsym reworked to become independant of the mangling scheme
  1787. Revision 1.3 1998/06/03 22:14:20 florian
  1788. * problem with sizes of classes fixed (if the anchestor was declared
  1789. forward, the compiler doesn't update the child classes size)
  1790. Revision 1.2 1998/05/28 14:40:29 peter
  1791. * fixes for newppu, remake3 works now with it
  1792. Revision 1.1 1998/05/27 19:45:09 peter
  1793. * symtable.pas splitted into includefiles
  1794. * symtable adapted for $ifndef OLDPPU
  1795. }