symsym.inc 63 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172
  1. {
  2. $Id$
  3. Copyright (c) 1998-2000 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. inherited initname(n);
  24. typ:=abstractsym;
  25. symoptions:=current_object_option;
  26. {$ifdef GDB}
  27. isstabwritten := false;
  28. {$endif GDB}
  29. fileinfo:=tokenpos;
  30. defref:=nil;
  31. refs:=0;
  32. lastwritten:=nil;
  33. refcount:=0;
  34. if (cs_browser in aktmoduleswitches) and make_ref then
  35. begin
  36. defref:=new(pref,init(defref,@tokenpos));
  37. inc(refcount);
  38. end;
  39. lastref:=defref;
  40. end;
  41. constructor tsym.load;
  42. begin
  43. inherited init;
  44. indexnr:=readword;
  45. setname(readstring);
  46. typ:=abstractsym;
  47. readsmallset(symoptions);
  48. readposinfo(fileinfo);
  49. lastref:=nil;
  50. defref:=nil;
  51. refs:=0;
  52. lastwritten:=nil;
  53. refcount:=0;
  54. {$ifdef GDB}
  55. isstabwritten := false;
  56. {$endif GDB}
  57. end;
  58. procedure tsym.load_references;
  59. var
  60. pos : tfileposinfo;
  61. move_last : boolean;
  62. begin
  63. move_last:=lastwritten=lastref;
  64. while (not current_ppu^.endofentry) do
  65. begin
  66. readposinfo(pos);
  67. inc(refcount);
  68. lastref:=new(pref,init(lastref,@pos));
  69. lastref^.is_written:=true;
  70. if refcount=1 then
  71. defref:=lastref;
  72. end;
  73. if move_last then
  74. lastwritten:=lastref;
  75. end;
  76. { big problem here :
  77. wrong refs were written because of
  78. interface parsing of other units PM
  79. moduleindex must be checked !! }
  80. function tsym.write_references : boolean;
  81. var
  82. ref : pref;
  83. symref_written,move_last : boolean;
  84. begin
  85. write_references:=false;
  86. if lastwritten=lastref then
  87. exit;
  88. { should we update lastref }
  89. move_last:=true;
  90. symref_written:=false;
  91. { write symbol refs }
  92. if assigned(lastwritten) then
  93. ref:=lastwritten
  94. else
  95. ref:=defref;
  96. while assigned(ref) do
  97. begin
  98. if ref^.moduleindex=current_module^.unit_index then
  99. begin
  100. { write address to this symbol }
  101. if not symref_written then
  102. begin
  103. writesymref(@self);
  104. symref_written:=true;
  105. end;
  106. writeposinfo(ref^.posinfo);
  107. ref^.is_written:=true;
  108. if move_last then
  109. lastwritten:=ref;
  110. end
  111. else if not ref^.is_written then
  112. move_last:=false
  113. else if move_last then
  114. lastwritten:=ref;
  115. ref:=ref^.nextref;
  116. end;
  117. if symref_written then
  118. current_ppu^.writeentry(ibsymref);
  119. write_references:=symref_written;
  120. end;
  121. {$ifdef BrowserLog}
  122. procedure tsym.add_to_browserlog;
  123. begin
  124. if assigned(defref) then
  125. begin
  126. browserlog.AddLog('***'+name+'***');
  127. browserlog.AddLogRefs(defref);
  128. end;
  129. end;
  130. {$endif BrowserLog}
  131. destructor tsym.done;
  132. begin
  133. if assigned(defref) then
  134. begin
  135. defref^.freechain;
  136. dispose(defref,done);
  137. end;
  138. inherited done;
  139. end;
  140. procedure tsym.write;
  141. begin
  142. writeword(indexnr);
  143. writestring(name);
  144. writesmallset(symoptions);
  145. writeposinfo(fileinfo);
  146. end;
  147. procedure tsym.prederef;
  148. begin
  149. end;
  150. procedure tsym.deref;
  151. begin
  152. end;
  153. function tsym.mangledname : string;
  154. begin
  155. mangledname:=name;
  156. end;
  157. { for most symbol types there is nothing to do at all }
  158. procedure tsym.insert_in_data;
  159. begin
  160. end;
  161. {$ifdef GDB}
  162. function tsym.stabstring : pchar;
  163. begin
  164. stabstring:=strpnew('"'+name+'",'+tostr(N_LSYM)+',0,'+
  165. tostr(fileinfo.line)+',0');
  166. end;
  167. procedure tsym.concatstabto(asmlist : paasmoutput);
  168. var stab_str : pchar;
  169. begin
  170. if not isstabwritten then
  171. begin
  172. stab_str := stabstring;
  173. { count_dbx(stab_str); moved to GDB.PAS }
  174. asmlist^.concat(new(pai_stabs,init(stab_str)));
  175. isstabwritten:=true;
  176. end;
  177. end;
  178. {$endif GDB}
  179. {****************************************************************************
  180. TLABELSYM
  181. ****************************************************************************}
  182. constructor tlabelsym.init(const n : string; l : pasmlabel);
  183. begin
  184. inherited init(n);
  185. typ:=labelsym;
  186. lab:=l;
  187. used:=false;
  188. defined:=false;
  189. code:=nil;
  190. end;
  191. constructor tlabelsym.load;
  192. begin
  193. tsym.load;
  194. typ:=labelsym;
  195. { this is all dummy
  196. it is only used for local browsing }
  197. lab:=nil;
  198. code:=nil;
  199. used:=false;
  200. defined:=true;
  201. end;
  202. destructor tlabelsym.done;
  203. begin
  204. inherited done;
  205. end;
  206. function tlabelsym.mangledname : string;
  207. begin
  208. mangledname:=lab^.name;
  209. end;
  210. procedure tlabelsym.write;
  211. begin
  212. if owner^.symtabletype in [unitsymtable,globalsymtable] then
  213. Message(sym_e_ill_label_decl)
  214. else
  215. begin
  216. tsym.write;
  217. current_ppu^.writeentry(iblabelsym);
  218. end;
  219. end;
  220. {****************************************************************************
  221. TUNITSYM
  222. ****************************************************************************}
  223. constructor tunitsym.init(const n : string;ref : punitsymtable);
  224. var
  225. old_make_ref : boolean;
  226. begin
  227. old_make_ref:=make_ref;
  228. make_ref:=false;
  229. inherited init(n);
  230. make_ref:=old_make_ref;
  231. typ:=unitsym;
  232. unitsymtable:=ref;
  233. prevsym:=ref^.unitsym;
  234. ref^.unitsym:=@self;
  235. refs:=0;
  236. end;
  237. constructor tunitsym.load;
  238. begin
  239. tsym.load;
  240. typ:=unitsym;
  241. unitsymtable:=punitsymtable(current_module^.globalsymtable);
  242. prevsym:=nil;
  243. end;
  244. { we need to remove it from the prevsym chain ! }
  245. procedure tunitsym.restoreunitsym;
  246. var pus,ppus : punitsym;
  247. begin
  248. if assigned(unitsymtable) then
  249. begin
  250. ppus:=nil;
  251. pus:=unitsymtable^.unitsym;
  252. if pus=@self then
  253. unitsymtable^.unitsym:=prevsym
  254. else while assigned(pus) do
  255. begin
  256. if pus=@self then
  257. begin
  258. ppus^.prevsym:=prevsym;
  259. break;
  260. end
  261. else
  262. begin
  263. ppus:=pus;
  264. pus:=ppus^.prevsym;
  265. end;
  266. end;
  267. end;
  268. prevsym:=nil;
  269. end;
  270. destructor tunitsym.done;
  271. begin
  272. restoreunitsym;
  273. inherited done;
  274. end;
  275. procedure tunitsym.write;
  276. begin
  277. tsym.write;
  278. current_ppu^.writeentry(ibunitsym);
  279. end;
  280. {$ifdef GDB}
  281. procedure tunitsym.concatstabto(asmlist : paasmoutput);
  282. begin
  283. {Nothing to write to stabs !}
  284. end;
  285. {$endif GDB}
  286. {****************************************************************************
  287. TPROCSYM
  288. ****************************************************************************}
  289. constructor tprocsym.init(const n : string);
  290. begin
  291. tsym.init(n);
  292. typ:=procsym;
  293. definition:=nil;
  294. owner:=nil;
  295. is_global := false;
  296. end;
  297. constructor tprocsym.load;
  298. begin
  299. tsym.load;
  300. typ:=procsym;
  301. definition:=pprocdef(readdefref);
  302. is_global := false;
  303. end;
  304. destructor tprocsym.done;
  305. begin
  306. { don't check if errors !! }
  307. if Errorcount=0 then
  308. check_forward;
  309. tsym.done;
  310. end;
  311. function tprocsym.mangledname : string;
  312. begin
  313. mangledname:=definition^.mangledname;
  314. end;
  315. function tprocsym.demangledname:string;
  316. begin
  317. demangledname:=name+definition^.demangled_paras;
  318. end;
  319. procedure tprocsym.write_parameter_lists(skipdef:pprocdef);
  320. var
  321. p : pprocdef;
  322. begin
  323. p:=definition;
  324. while assigned(p) do
  325. begin
  326. if p<>skipdef then
  327. MessagePos1(p^.fileinfo,sym_b_param_list,name+p^.demangled_paras);
  328. p:=p^.nextoverloaded;
  329. end;
  330. end;
  331. procedure tprocsym.check_forward;
  332. var
  333. pd : pprocdef;
  334. begin
  335. pd:=definition;
  336. while assigned(pd) do
  337. begin
  338. if pd^.forwarddef then
  339. begin
  340. if assigned(pd^._class) then
  341. MessagePos1(fileinfo,sym_e_forward_not_resolved,pd^._class^.objname^+'.'+demangledname)
  342. else
  343. MessagePos1(fileinfo,sym_e_forward_not_resolved,demangledname);
  344. { Turn futher error messages off }
  345. pd^.forwarddef:=false;
  346. end;
  347. pd:=pd^.nextoverloaded;
  348. { do not check defs of operators in other units }
  349. if assigned(pd) and (pd^.procsym<>@self) then
  350. pd:=nil;
  351. end;
  352. end;
  353. procedure tprocsym.deref;
  354. {$ifdef DONOTCHAINOPERATORS}
  355. var
  356. t : ttoken;
  357. last,pd : pprocdef;
  358. {$endif DONOTCHAINOPERATORS}
  359. begin
  360. resolvedef(pdef(definition));
  361. {$ifdef DONOTCHAINOPERATORS}
  362. if (definition^.proctypeoption=potype_operator) then
  363. begin
  364. last:=definition;
  365. while assigned(last^.nextoverloaded) do
  366. last:=last^.nextoverloaded;
  367. for t:=first_overloaded to last_overloaded do
  368. if (name=overloaded_names[t]) then
  369. begin
  370. if assigned(overloaded_operators[t]) then
  371. begin
  372. pd:=overloaded_operators[t]^.definition;
  373. { test if not already in list, bug report by KC Wong PM }
  374. while assigned(pd) do
  375. if pd=last then
  376. break
  377. else
  378. pd:=pd^.nextoverloaded;
  379. if pd=last then
  380. break;
  381. last^.nextoverloaded:=overloaded_operators[t]^.definition;
  382. end;
  383. overloaded_operators[t]:=@self;
  384. break;
  385. end;
  386. end;
  387. {$endif DONOTCHAINOPERATORS}
  388. end;
  389. procedure tprocsym.order_overloaded;
  390. var firstdef,currdef,lastdef,nextopdef : pprocdef;
  391. begin
  392. if not assigned(definition) then
  393. exit;
  394. firstdef:=definition;
  395. currdef:=definition;
  396. while assigned(currdef) and (currdef^.owner=firstdef^.owner) do
  397. begin
  398. currdef^.count:=false;
  399. currdef:=currdef^.nextoverloaded;
  400. end;
  401. nextopdef:=currdef;
  402. definition:=definition^.nextoverloaded;
  403. firstdef^.nextoverloaded:=nil;
  404. while (definition<>nextopdef) do
  405. begin
  406. currdef:=firstdef;
  407. lastdef:=definition;
  408. definition:=definition^.nextoverloaded;
  409. if lastdef^.mangledname<firstdef^.mangledname then
  410. begin
  411. lastdef^.nextoverloaded:=firstdef;
  412. firstdef:=lastdef;
  413. end
  414. else
  415. begin
  416. while assigned(currdef^.nextoverloaded) and
  417. (lastdef^.mangledname>currdef^.nextoverloaded^.mangledname) do
  418. currdef:=currdef^.nextoverloaded;
  419. lastdef^.nextoverloaded:=currdef^.nextoverloaded;
  420. currdef^.nextoverloaded:=lastdef;
  421. end;
  422. end;
  423. definition:=firstdef;
  424. currdef:=definition;
  425. while assigned(currdef) do
  426. begin
  427. currdef^.count:=true;
  428. lastdef:=currdef;
  429. currdef:=currdef^.nextoverloaded;
  430. end;
  431. lastdef^.nextoverloaded:=nextopdef;
  432. end;
  433. procedure tprocsym.write;
  434. begin
  435. tsym.write;
  436. writedefref(pdef(definition));
  437. current_ppu^.writeentry(ibprocsym);
  438. end;
  439. procedure tprocsym.load_references;
  440. (*var
  441. prdef,prdef2 : pprocdef;
  442. b : byte; *)
  443. begin
  444. inherited load_references;
  445. (*prdef:=definition;
  446. done in tsymtable.load_browser (PM)
  447. { take care about operators !! }
  448. if (current_module^.flags and uf_has_browser) <>0 then
  449. while assigned(prdef) and (prdef^.owner=definition^.owner) do
  450. begin
  451. b:=current_ppu^.readentry;
  452. if b<>ibdefref then
  453. Message(unit_f_ppu_read_error);
  454. prdef2:=pprocdef(readdefref);
  455. resolvedef(prdef2);
  456. if prdef<>prdef2 then
  457. Message(unit_f_ppu_read_error);
  458. prdef^.load_references;
  459. prdef:=prdef^.nextoverloaded;
  460. end; *)
  461. end;
  462. function tprocsym.write_references : boolean;
  463. var
  464. prdef : pprocdef;
  465. begin
  466. write_references:=false;
  467. if not inherited write_references then
  468. exit;
  469. write_references:=true;
  470. prdef:=definition;
  471. while assigned(prdef) and (prdef^.owner=definition^.owner) do
  472. begin
  473. prdef^.write_references;
  474. prdef:=prdef^.nextoverloaded;
  475. end;
  476. end;
  477. {$ifdef BrowserLog}
  478. procedure tprocsym.add_to_browserlog;
  479. var
  480. prdef : pprocdef;
  481. begin
  482. inherited add_to_browserlog;
  483. prdef:=definition;
  484. while assigned(prdef) do
  485. begin
  486. pprocdef(prdef)^.add_to_browserlog;
  487. prdef:=pprocdef(prdef)^.nextoverloaded;
  488. end;
  489. end;
  490. {$endif BrowserLog}
  491. {$ifdef GDB}
  492. function tprocsym.stabstring : pchar;
  493. Var RetType : Char;
  494. Obj,Info : String;
  495. stabsstr : string;
  496. p : pchar;
  497. begin
  498. obj := name;
  499. info := '';
  500. if is_global then
  501. RetType := 'F'
  502. else
  503. RetType := 'f';
  504. if assigned(owner) then
  505. begin
  506. if (owner^.symtabletype = objectsymtable) then
  507. obj := owner^.name^+'__'+name;
  508. { this code was correct only as long as the local symboltable
  509. of the parent had the same name as the function
  510. but this is no true anymore !! PM
  511. if (owner^.symtabletype=localsymtable) and assigned(owner^.name) then
  512. info := ','+name+','+owner^.name^; }
  513. if (owner^.symtabletype=localsymtable) and assigned(owner^.defowner) and
  514. assigned(pprocdef(owner^.defowner)^.procsym) then
  515. info := ','+name+','+pprocdef(owner^.defowner)^.procsym^.name;
  516. end;
  517. stabsstr:=definition^.mangledname;
  518. getmem(p,length(stabsstr)+255);
  519. strpcopy(p,'"'+obj+':'+RetType
  520. +definition^.rettype.def^.numberstring+info+'",'+tostr(n_function)
  521. +',0,'+
  522. tostr(aktfilepos.line)
  523. +',');
  524. strpcopy(strend(p),stabsstr);
  525. stabstring:=strnew(p);
  526. freemem(p,length(stabsstr)+255);
  527. end;
  528. procedure tprocsym.concatstabto(asmlist : paasmoutput);
  529. begin
  530. if (pocall_internproc in definition^.proccalloptions) then exit;
  531. if not isstabwritten then
  532. asmlist^.concat(new(pai_stabs,init(stabstring)));
  533. isstabwritten := true;
  534. if assigned(definition^.parast) then
  535. definition^.parast^.concatstabto(asmlist);
  536. if assigned(definition^.localst) then
  537. definition^.localst^.concatstabto(asmlist);
  538. definition^.is_def_stab_written := true;
  539. end;
  540. {$endif GDB}
  541. {****************************************************************************
  542. TPROGRAMSYM
  543. ****************************************************************************}
  544. constructor tprogramsym.init(const n : string);
  545. begin
  546. inherited init(n);
  547. typ:=programsym;
  548. end;
  549. {****************************************************************************
  550. TERRORSYM
  551. ****************************************************************************}
  552. constructor terrorsym.init;
  553. begin
  554. inherited init('');
  555. typ:=errorsym;
  556. end;
  557. {****************************************************************************
  558. TPROPERTYSYM
  559. ****************************************************************************}
  560. constructor tpropertysym.init(const n : string);
  561. begin
  562. inherited init(n);
  563. typ:=propertysym;
  564. propoptions:=[];
  565. index:=0;
  566. default:=0;
  567. proptype.reset;
  568. indextype.reset;
  569. new(readaccess,init);
  570. new(writeaccess,init);
  571. new(storedaccess,init);
  572. end;
  573. constructor tpropertysym.load;
  574. begin
  575. inherited load;
  576. typ:=propertysym;
  577. readsmallset(propoptions);
  578. if (ppo_is_override in propoptions) then
  579. begin
  580. propoverriden:=ppropertysym(readsymref);
  581. { we need to have these objects initialized }
  582. new(readaccess,init);
  583. new(writeaccess,init);
  584. new(storedaccess,init);
  585. end
  586. else
  587. begin
  588. proptype.load;
  589. index:=readlong;
  590. default:=readlong;
  591. indextype.load;
  592. new(readaccess,load);
  593. new(writeaccess,load);
  594. new(storedaccess,load);
  595. end;
  596. end;
  597. destructor tpropertysym.done;
  598. begin
  599. dispose(readaccess,done);
  600. dispose(writeaccess,done);
  601. dispose(storedaccess,done);
  602. inherited done;
  603. end;
  604. procedure tpropertysym.deref;
  605. begin
  606. if (ppo_is_override in propoptions) then
  607. begin
  608. resolvesym(psym(propoverriden));
  609. dooverride(propoverriden);
  610. end
  611. else
  612. begin
  613. proptype.resolve;
  614. indextype.resolve;
  615. readaccess^.resolve;
  616. writeaccess^.resolve;
  617. storedaccess^.resolve;
  618. end;
  619. end;
  620. function tpropertysym.getsize : longint;
  621. begin
  622. getsize:=0;
  623. end;
  624. procedure tpropertysym.write;
  625. begin
  626. tsym.write;
  627. writesmallset(propoptions);
  628. if (ppo_is_override in propoptions) then
  629. writesymref(propoverriden)
  630. else
  631. begin
  632. proptype.write;
  633. writelong(index);
  634. writelong(default);
  635. indextype.write;
  636. readaccess^.write;
  637. writeaccess^.write;
  638. storedaccess^.write;
  639. end;
  640. current_ppu^.writeentry(ibpropertysym);
  641. end;
  642. procedure tpropertysym.dooverride(overriden:ppropertysym);
  643. begin
  644. propoverriden:=overriden;
  645. proptype:=overriden^.proptype;
  646. propoptions:=overriden^.propoptions+[ppo_is_override];
  647. index:=overriden^.index;
  648. default:=overriden^.default;
  649. indextype:=overriden^.indextype;
  650. readaccess^.clear;
  651. readaccess:=overriden^.readaccess^.getcopy;
  652. writeaccess^.clear;
  653. writeaccess:=overriden^.writeaccess^.getcopy;
  654. storedaccess^.clear;
  655. storedaccess:=overriden^.storedaccess^.getcopy;
  656. end;
  657. {$ifdef GDB}
  658. function tpropertysym.stabstring : pchar;
  659. begin
  660. { !!!! don't know how to handle }
  661. stabstring:=strpnew('');
  662. end;
  663. procedure tpropertysym.concatstabto(asmlist : paasmoutput);
  664. begin
  665. { !!!! don't know how to handle }
  666. end;
  667. {$endif GDB}
  668. {****************************************************************************
  669. TFUNCRETSYM
  670. ****************************************************************************}
  671. constructor tfuncretsym.init(const n : string;approcinfo : pointer{pprocinfo});
  672. begin
  673. tsym.init(n);
  674. typ:=funcretsym;
  675. funcretprocinfo:=approcinfo;
  676. rettype:=pprocinfo(approcinfo)^.returntype;
  677. { address valid for ret in param only }
  678. { otherwise set by insert }
  679. address:=pprocinfo(approcinfo)^.return_offset;
  680. end;
  681. constructor tfuncretsym.load;
  682. begin
  683. tsym.load;
  684. rettype.load;
  685. address:=readlong;
  686. funcretprocinfo:=nil;
  687. typ:=funcretsym;
  688. end;
  689. destructor tfuncretsym.done;
  690. begin
  691. inherited done;
  692. end;
  693. procedure tfuncretsym.write;
  694. begin
  695. tsym.write;
  696. rettype.write;
  697. writelong(address);
  698. current_ppu^.writeentry(ibfuncretsym);
  699. end;
  700. procedure tfuncretsym.deref;
  701. begin
  702. rettype.resolve;
  703. end;
  704. {$ifdef GDB}
  705. procedure tfuncretsym.concatstabto(asmlist : paasmoutput);
  706. begin
  707. { Nothing to do here, it is done in genexitcode }
  708. end;
  709. {$endif GDB}
  710. procedure tfuncretsym.insert_in_data;
  711. var
  712. l : longint;
  713. begin
  714. { if retoffset is already set then reuse it, this is needed
  715. when inserting the result variable }
  716. if procinfo^.return_offset<>0 then
  717. address:=procinfo^.return_offset
  718. else
  719. begin
  720. { allocate space in local if ret in acc or in fpu }
  721. if ret_in_acc(procinfo^.returntype.def) or (procinfo^.returntype.def^.deftype=floatdef) then
  722. begin
  723. l:=rettype.def^.size;
  724. inc(owner^.datasize,l);
  725. {$ifdef m68k}
  726. { word alignment required for motorola }
  727. if (l=1) then
  728. inc(owner^.datasize,1)
  729. else
  730. {$endif}
  731. if (l>=4) and ((owner^.datasize and 3)<>0) then
  732. inc(owner^.datasize,4-(owner^.datasize and 3))
  733. else if (l>=2) and ((owner^.datasize and 1)<>0) then
  734. inc(owner^.datasize,2-(owner^.datasize and 1));
  735. address:=owner^.datasize;
  736. procinfo^.return_offset:=-owner^.datasize;
  737. end;
  738. end;
  739. end;
  740. {****************************************************************************
  741. TABSOLUTESYM
  742. ****************************************************************************}
  743. constructor tabsolutesym.init(const n : string;const tt : ttype);
  744. begin
  745. inherited init(n,tt);
  746. typ:=absolutesym;
  747. end;
  748. constructor tabsolutesym.initdef(const n : string;p : pdef);
  749. var
  750. t : ttype;
  751. begin
  752. t.setdef(p);
  753. tabsolutesym.init(n,t);
  754. end;
  755. constructor tabsolutesym.load;
  756. begin
  757. tvarsym.load;
  758. typ:=absolutesym;
  759. ref:=nil;
  760. address:=0;
  761. asmname:=nil;
  762. abstyp:=absolutetyp(readbyte);
  763. absseg:=false;
  764. case abstyp of
  765. tovar :
  766. begin
  767. asmname:=stringdup(readstring);
  768. ref:=srsym;
  769. end;
  770. toasm :
  771. asmname:=stringdup(readstring);
  772. toaddr :
  773. begin
  774. address:=readlong;
  775. absseg:=boolean(readbyte);
  776. end;
  777. end;
  778. end;
  779. procedure tabsolutesym.write;
  780. var
  781. hvo : tvaroptions;
  782. begin
  783. { Note: This needs to write everything of tvarsym.write }
  784. tsym.write;
  785. writebyte(byte(varspez));
  786. if read_member then
  787. writelong(address);
  788. { write only definition or definitionsym }
  789. vartype.write;
  790. hvo:=varoptions-[vo_regable];
  791. writesmallset(hvo);
  792. writebyte(byte(abstyp));
  793. case abstyp of
  794. tovar :
  795. writestring(ref^.name);
  796. toasm :
  797. writestring(asmname^);
  798. toaddr :
  799. begin
  800. writelong(address);
  801. writebyte(byte(absseg));
  802. end;
  803. end;
  804. current_ppu^.writeentry(ibabsolutesym);
  805. end;
  806. procedure tabsolutesym.deref;
  807. begin
  808. tvarsym.deref;
  809. if (abstyp=tovar) and (asmname<>nil) then
  810. begin
  811. { search previous loaded symtables }
  812. getsym(asmname^,false);
  813. if not(assigned(srsym)) then
  814. getsymonlyin(owner,asmname^);
  815. if not(assigned(srsym)) then
  816. srsym:=generrorsym;
  817. ref:=srsym;
  818. stringdispose(asmname);
  819. end;
  820. end;
  821. function tabsolutesym.mangledname : string;
  822. begin
  823. case abstyp of
  824. tovar :
  825. mangledname:=ref^.mangledname;
  826. toasm :
  827. mangledname:=asmname^;
  828. toaddr :
  829. mangledname:='$'+tostr(address);
  830. else
  831. internalerror(10002);
  832. end;
  833. end;
  834. procedure tabsolutesym.insert_in_data;
  835. begin
  836. end;
  837. {$ifdef GDB}
  838. procedure tabsolutesym.concatstabto(asmlist : paasmoutput);
  839. begin
  840. { I don't know how to handle this !! }
  841. end;
  842. {$endif GDB}
  843. {****************************************************************************
  844. TVARSYM
  845. ****************************************************************************}
  846. constructor tvarsym.init(const n : string;const tt : ttype);
  847. begin
  848. tsym.init(n);
  849. typ:=varsym;
  850. vartype:=tt;
  851. _mangledname:=nil;
  852. varspez:=vs_value;
  853. address:=0;
  854. localvarsym:=nil;
  855. refs:=0;
  856. varstate:=vs_used;
  857. varoptions:=[];
  858. { can we load the value into a register ? }
  859. if tt.def^.is_intregable then
  860. include(varoptions,vo_regable)
  861. else
  862. exclude(varoptions,vo_regable);
  863. if tt.def^.is_fpuregable then
  864. include(varoptions,vo_fpuregable)
  865. else
  866. exclude(varoptions,vo_fpuregable);
  867. reg:=R_NO;
  868. end;
  869. constructor tvarsym.init_dll(const n : string;const tt : ttype);
  870. begin
  871. tvarsym.init(n,tt);
  872. include(varoptions,vo_is_dll_var);
  873. end;
  874. constructor tvarsym.init_C(const n,mangled : string;const tt : ttype);
  875. begin
  876. tvarsym.init(n,tt);
  877. include(varoptions,vo_is_C_var);
  878. setmangledname(mangled);
  879. end;
  880. constructor tvarsym.initdef(const n : string;p : pdef);
  881. var
  882. t : ttype;
  883. begin
  884. t.setdef(p);
  885. tvarsym.init(n,t);
  886. end;
  887. constructor tvarsym.load;
  888. begin
  889. tsym.load;
  890. typ:=varsym;
  891. _mangledname:=nil;
  892. reg:=R_NO;
  893. refs := 0;
  894. varstate:=vs_used;
  895. varspez:=tvarspez(readbyte);
  896. if read_member then
  897. address:=readlong
  898. else
  899. address:=0;
  900. localvarsym:=nil;
  901. vartype.load;
  902. readsmallset(varoptions);
  903. if (vo_is_C_var in varoptions) then
  904. setmangledname(readstring);
  905. end;
  906. destructor tvarsym.done;
  907. begin
  908. strdispose(_mangledname);
  909. inherited done;
  910. end;
  911. procedure tvarsym.deref;
  912. begin
  913. vartype.resolve;
  914. end;
  915. procedure tvarsym.write;
  916. var
  917. hvo : tvaroptions;
  918. begin
  919. tsym.write;
  920. writebyte(byte(varspez));
  921. if read_member then
  922. writelong(address);
  923. vartype.write;
  924. { symbols which are load are never candidates for a register,
  925. turn off the regable }
  926. hvo:=varoptions-[vo_regable];
  927. writesmallset(hvo);
  928. if (vo_is_C_var in varoptions) then
  929. writestring(mangledname);
  930. current_ppu^.writeentry(ibvarsym);
  931. end;
  932. procedure tvarsym.setmangledname(const s : string);
  933. begin
  934. _mangledname:=strpnew(s);
  935. end;
  936. function tvarsym.mangledname : string;
  937. var
  938. prefix : string;
  939. begin
  940. if assigned(_mangledname) then
  941. begin
  942. mangledname:=strpas(_mangledname);
  943. exit;
  944. end;
  945. case owner^.symtabletype of
  946. staticsymtable :
  947. if (cs_create_smart in aktmoduleswitches) then
  948. prefix:='_'+owner^.name^+'$$$_'
  949. else
  950. prefix:='_';
  951. unitsymtable,
  952. globalsymtable :
  953. prefix:=
  954. 'U_'+owner^.name^+'_';
  955. else
  956. Message(sym_e_invalid_call_tvarsymmangledname);
  957. end;
  958. mangledname:=prefix+name;
  959. end;
  960. function tvarsym.getsize : longint;
  961. begin
  962. if assigned(vartype.def) then
  963. getsize:=vartype.def^.size
  964. else
  965. getsize:=0;
  966. end;
  967. function tvarsym.getvaluesize : longint;
  968. begin
  969. if assigned(vartype.def) and
  970. (varspez=vs_value) and
  971. ((vartype.def^.deftype<>arraydef) or
  972. (Parraydef(vartype.def)^.highrange>=Parraydef(vartype.def)^.lowrange)) then
  973. getvaluesize:=vartype.def^.size
  974. else
  975. getvaluesize:=0;
  976. end;
  977. function tvarsym.getpushsize : longint;
  978. begin
  979. if assigned(vartype.def) then
  980. begin
  981. case varspez of
  982. vs_out,
  983. vs_var :
  984. getpushsize:=target_os.size_of_pointer;
  985. vs_value,
  986. vs_const :
  987. begin
  988. if push_addr_param(vartype.def) then
  989. getpushsize:=target_os.size_of_pointer
  990. else
  991. getpushsize:=vartype.def^.size;
  992. end;
  993. end;
  994. end
  995. else
  996. getpushsize:=0;
  997. end;
  998. function data_align(length : longint) : longint;
  999. begin
  1000. (* this is useless under go32v2 at least
  1001. because the section are only align to dword
  1002. if length>8 then
  1003. data_align:=16
  1004. else if length>4 then
  1005. data_align:=8
  1006. else *)
  1007. if length>2 then
  1008. data_align:=4
  1009. else
  1010. if length>1 then
  1011. data_align:=2
  1012. else
  1013. data_align:=1;
  1014. end;
  1015. procedure tvarsym.insert_in_data;
  1016. var
  1017. varalign,
  1018. l,ali,modulo : longint;
  1019. storefilepos : tfileposinfo;
  1020. begin
  1021. if (vo_is_external in varoptions) then
  1022. exit;
  1023. { handle static variables of objects especially }
  1024. if read_member and (owner^.symtabletype=objectsymtable) and
  1025. (sp_static in symoptions) then
  1026. begin
  1027. { the data filed is generated in parser.pas
  1028. with a tobject_FIELDNAME variable }
  1029. { this symbol can't be loaded to a register }
  1030. exclude(varoptions,vo_regable);
  1031. exclude(varoptions,vo_fpuregable);
  1032. end
  1033. else
  1034. if not(read_member) then
  1035. begin
  1036. { made problems with parameters etc. ! (FK) }
  1037. { check for instance of an abstract object or class }
  1038. {
  1039. if (pvarsym(sym)^.definition^.deftype=objectdef) and
  1040. ((pobjectdef(pvarsym(sym)^.definition)^.options and oo_is_abstract)<>0) then
  1041. Message(sym_e_no_instance_of_abstract_object);
  1042. }
  1043. storefilepos:=aktfilepos;
  1044. aktfilepos:=tokenpos;
  1045. if (vo_is_thread_var in varoptions) then
  1046. l:=4
  1047. else
  1048. l:=getvaluesize;
  1049. case owner^.symtabletype of
  1050. stt_exceptsymtable:
  1051. { can contain only one symbol, address calculated later }
  1052. ;
  1053. localsymtable :
  1054. begin
  1055. varstate:=vs_declared;
  1056. modulo:=owner^.datasize and 3;
  1057. {$ifdef m68k}
  1058. { word alignment required for motorola }
  1059. if (l=1) then
  1060. l:=2
  1061. else
  1062. {$endif}
  1063. {
  1064. if (cs_optimize in aktglobalswitches) and
  1065. (aktoptprocessor in [classp5,classp6]) and
  1066. (l>=8) and ((owner^.datasize and 7)<>0) then
  1067. inc(owner^.datasize,8-(owner^.datasize and 7))
  1068. else
  1069. }
  1070. begin
  1071. if (l>=4) and (modulo<>0) then
  1072. inc(l,4-modulo)
  1073. else
  1074. if (l>=2) and ((modulo and 1)<>0) then
  1075. inc(l,2-(modulo and 1));
  1076. end;
  1077. inc(owner^.datasize,l);
  1078. address:=owner^.datasize;
  1079. end;
  1080. staticsymtable :
  1081. begin
  1082. { enable unitialized warning for local symbols }
  1083. varstate:=vs_declared;
  1084. if (cs_create_smart in aktmoduleswitches) then
  1085. bsssegment^.concat(new(pai_cut,init));
  1086. ali:=data_align(l);
  1087. if ali>1 then
  1088. begin
  1089. modulo:=owner^.datasize mod ali;
  1090. if modulo>0 then
  1091. inc(owner^.datasize,ali-modulo);
  1092. end;
  1093. {$ifdef GDB}
  1094. if cs_debuginfo in aktmoduleswitches then
  1095. concatstabto(bsssegment);
  1096. {$endif GDB}
  1097. if (cs_create_smart in aktmoduleswitches) or
  1098. DLLSource or
  1099. (vo_is_exported in varoptions) or
  1100. (vo_is_C_var in varoptions) then
  1101. bsssegment^.concat(new(pai_datablock,init_global(mangledname,l)))
  1102. else
  1103. bsssegment^.concat(new(pai_datablock,init(mangledname,l)));
  1104. { increase datasize }
  1105. inc(owner^.datasize,l);
  1106. { this symbol can't be loaded to a register }
  1107. exclude(varoptions,vo_regable);
  1108. exclude(varoptions,vo_fpuregable);
  1109. end;
  1110. globalsymtable :
  1111. begin
  1112. if (cs_create_smart in aktmoduleswitches) then
  1113. bsssegment^.concat(new(pai_cut,init));
  1114. ali:=data_align(l);
  1115. if ali>1 then
  1116. begin
  1117. modulo:=owner^.datasize mod ali;
  1118. if modulo>0 then
  1119. inc(owner^.datasize,ali-modulo);
  1120. end;
  1121. {$ifdef GDB}
  1122. if cs_debuginfo in aktmoduleswitches then
  1123. concatstabto(bsssegment);
  1124. {$endif GDB}
  1125. bsssegment^.concat(new(pai_datablock,init_global(mangledname,l)));
  1126. inc(owner^.datasize,l);
  1127. { this symbol can't be loaded to a register }
  1128. exclude(varoptions,vo_regable);
  1129. exclude(varoptions,vo_fpuregable);
  1130. end;
  1131. recordsymtable,
  1132. objectsymtable :
  1133. begin
  1134. { this symbol can't be loaded to a register }
  1135. exclude(varoptions,vo_regable);
  1136. exclude(varoptions,vo_fpuregable);
  1137. { get the alignment size }
  1138. if (aktpackrecords=packrecord_C) then
  1139. begin
  1140. varalign:=vartype.def^.alignment;
  1141. if (varalign>4) and ((varalign mod 4)<>0) and
  1142. (vartype.def^.deftype=arraydef) then
  1143. begin
  1144. Message1(sym_w_wrong_C_pack,vartype.def^.typename);
  1145. end;
  1146. if varalign=0 then
  1147. varalign:=l;
  1148. if (owner^.dataalignment<target_os.maxCrecordalignment) then
  1149. begin
  1150. if (varalign>16) and (owner^.dataalignment<32) then
  1151. owner^.dataalignment:=32
  1152. else if (varalign>12) and (owner^.dataalignment<16) then
  1153. owner^.dataalignment:=16
  1154. { 12 is needed for long double }
  1155. else if (varalign>8) and (owner^.dataalignment<12) then
  1156. owner^.dataalignment:=12
  1157. else if (varalign>4) and (owner^.dataalignment<8) then
  1158. owner^.dataalignment:=8
  1159. else if (varalign>2) and (owner^.dataalignment<4) then
  1160. owner^.dataalignment:=4
  1161. else if (varalign>1) and (owner^.dataalignment<2) then
  1162. owner^.dataalignment:=2;
  1163. end;
  1164. if owner^.dataalignment>target_os.maxCrecordalignment then
  1165. owner^.dataalignment:=target_os.maxCrecordalignment;
  1166. end
  1167. else
  1168. varalign:=vartype.def^.alignment;
  1169. if varalign=0 then
  1170. varalign:=l;
  1171. { align record and object fields }
  1172. if (varalign=1) or (owner^.dataalignment=1) then
  1173. begin
  1174. address:=owner^.datasize;
  1175. inc(owner^.datasize,l)
  1176. end
  1177. else if (varalign=2) or (owner^.dataalignment=2) then
  1178. begin
  1179. owner^.datasize:=(owner^.datasize+1) and (not 1);
  1180. address:=owner^.datasize;
  1181. inc(owner^.datasize,l)
  1182. end
  1183. else if (varalign<=4) or (owner^.dataalignment=4) then
  1184. begin
  1185. owner^.datasize:=(owner^.datasize+3) and (not 3);
  1186. address:=owner^.datasize;
  1187. inc(owner^.datasize,l);
  1188. end
  1189. else if (varalign<=8) or (owner^.dataalignment=8) then
  1190. begin
  1191. owner^.datasize:=(owner^.datasize+7) and (not 7);
  1192. address:=owner^.datasize;
  1193. inc(owner^.datasize,l);
  1194. end
  1195. { 12 is needed for C long double support }
  1196. else if (varalign<=12) and (owner^.dataalignment=12) then
  1197. begin
  1198. owner^.datasize:=((owner^.datasize+11) div 12) * 12;
  1199. address:=owner^.datasize;
  1200. inc(owner^.datasize,l);
  1201. end
  1202. else if (varalign<=16) or (owner^.dataalignment=16) then
  1203. begin
  1204. owner^.datasize:=(owner^.datasize+15) and (not 15);
  1205. address:=owner^.datasize;
  1206. inc(owner^.datasize,l);
  1207. end
  1208. else if (varalign<=32) or (owner^.dataalignment=32) then
  1209. begin
  1210. owner^.datasize:=(owner^.datasize+31) and (not 31);
  1211. address:=owner^.datasize;
  1212. inc(owner^.datasize,l);
  1213. end
  1214. else
  1215. internalerror(1000022);
  1216. end;
  1217. parasymtable :
  1218. begin
  1219. { here we need the size of a push instead of the
  1220. size of the data }
  1221. l:=getpushsize;
  1222. varstate:=vs_assigned;
  1223. address:=owner^.datasize;
  1224. owner^.datasize:=align(owner^.datasize+l,target_os.stackalignment);
  1225. end
  1226. else
  1227. begin
  1228. modulo:=owner^.datasize and 3;
  1229. if (l>=4) and (modulo<>0) then
  1230. inc(owner^.datasize,4-modulo)
  1231. else
  1232. if (l>=2) and ((modulo and 1)<>0) then
  1233. inc(owner^.datasize);
  1234. address:=owner^.datasize;
  1235. inc(owner^.datasize,l);
  1236. end;
  1237. end;
  1238. aktfilepos:=storefilepos;
  1239. end;
  1240. end;
  1241. {$ifdef GDB}
  1242. function tvarsym.stabstring : pchar;
  1243. var
  1244. st : string[2];
  1245. begin
  1246. if (vartype.def^.deftype=objectdef) and
  1247. pobjectdef(vartype.def)^.is_class then
  1248. st:='*'
  1249. else
  1250. st:='';
  1251. if (owner^.symtabletype = objectsymtable) and
  1252. (sp_static in symoptions) then
  1253. begin
  1254. if (cs_gdb_gsym in aktglobalswitches) then st := 'G'+st else st := 'S'+st;
  1255. {$ifndef Delphi}
  1256. stabstring := strpnew('"'+owner^.name^+'__'+name+':'+st+
  1257. +vartype.def^.numberstring+'",'+
  1258. tostr(N_LCSYM)+',0,'+tostr(fileinfo.line)+','+mangledname);
  1259. {$endif}
  1260. end
  1261. else if (owner^.symtabletype = globalsymtable) or
  1262. (owner^.symtabletype = unitsymtable) then
  1263. begin
  1264. { Here we used S instead of
  1265. because with G GDB doesn't look at the address field
  1266. but searches the same name or with a leading underscore
  1267. but these names don't exist in pascal !}
  1268. if (cs_gdb_gsym in aktglobalswitches) then st := 'G'+st else st := 'S'+st;
  1269. stabstring := strpnew('"'+name+':'+st
  1270. +vartype.def^.numberstring+'",'+
  1271. tostr(N_LCSYM)+',0,'+tostr(fileinfo.line)+','+mangledname);
  1272. end
  1273. else if owner^.symtabletype = staticsymtable then
  1274. begin
  1275. stabstring := strpnew('"'+name+':S'+st
  1276. +vartype.def^.numberstring+'",'+
  1277. tostr(N_LCSYM)+',0,'+tostr(fileinfo.line)+','+mangledname);
  1278. end
  1279. else if (owner^.symtabletype in [parasymtable,inlineparasymtable]) then
  1280. begin
  1281. case varspez of
  1282. vs_out,
  1283. vs_var : st := 'v'+st;
  1284. vs_value,
  1285. vs_const : if push_addr_param(vartype.def) then
  1286. st := 'v'+st { should be 'i' but 'i' doesn't work }
  1287. else
  1288. st := 'p'+st;
  1289. end;
  1290. stabstring := strpnew('"'+name+':'+st
  1291. +vartype.def^.numberstring+'",'+
  1292. tostr(N_PSYM)+',0,'+tostr(fileinfo.line)+','+
  1293. tostr(address+owner^.address_fixup));
  1294. {offset to ebp => will not work if the framepointer is esp
  1295. so some optimizing will make things harder to debug }
  1296. end
  1297. else if (owner^.symtabletype in [localsymtable,inlinelocalsymtable]) then
  1298. {$ifdef i386}
  1299. if reg<>R_NO then
  1300. begin
  1301. { "eax", "ecx", "edx", "ebx", "esp", "ebp", "esi", "edi", "eip", "ps", "cs", "ss", "ds", "es", "fs", "gs", }
  1302. { this is the register order for GDB}
  1303. stabstring:=strpnew('"'+name+':r'+st
  1304. +vartype.def^.numberstring+'",'+
  1305. tostr(N_RSYM)+',0,'+
  1306. tostr(fileinfo.line)+','+tostr(GDB_i386index[reg]));
  1307. end
  1308. else
  1309. {$endif i386}
  1310. { I don't know if this will work (PM) }
  1311. if (vo_is_C_var in varoptions) then
  1312. stabstring := strpnew('"'+name+':S'+st
  1313. +vartype.def^.numberstring+'",'+
  1314. tostr(N_LCSYM)+',0,'+tostr(fileinfo.line)+','+mangledname)
  1315. else
  1316. stabstring := strpnew('"'+name+':'+st
  1317. +vartype.def^.numberstring+'",'+
  1318. tostr(N_LSYM)+',0,'+tostr(fileinfo.line)+',-'+tostr(address-owner^.address_fixup))
  1319. else
  1320. stabstring := inherited stabstring;
  1321. end;
  1322. procedure tvarsym.concatstabto(asmlist : paasmoutput);
  1323. {$ifdef i386}
  1324. var stab_str : pchar;
  1325. {$endif i386}
  1326. begin
  1327. inherited concatstabto(asmlist);
  1328. {$ifdef i386}
  1329. if (owner^.symtabletype=parasymtable) and
  1330. (reg<>R_NO) then
  1331. begin
  1332. { "eax", "ecx", "edx", "ebx", "esp", "ebp", "esi", "edi", "eip", "ps", "cs", "ss", "ds", "es", "fs", "gs", }
  1333. { this is the register order for GDB}
  1334. stab_str:=strpnew('"'+name+':r'
  1335. +vartype.def^.numberstring+'",'+
  1336. tostr(N_RSYM)+',0,'+
  1337. tostr(fileinfo.line)+','+tostr(GDB_i386index[reg]));
  1338. asmlist^.concat(new(pai_stabs,init(stab_str)));
  1339. end;
  1340. {$endif i386}
  1341. end;
  1342. {$endif GDB}
  1343. {****************************************************************************
  1344. TTYPEDCONSTSYM
  1345. *****************************************************************************}
  1346. constructor ttypedconstsym.init(const n : string;p : pdef;really_const : boolean);
  1347. begin
  1348. tsym.init(n);
  1349. typ:=typedconstsym;
  1350. typedconsttype.setdef(p);
  1351. is_really_const:=really_const;
  1352. prefix:=stringdup(procprefix);
  1353. end;
  1354. constructor ttypedconstsym.inittype(const n : string;const tt : ttype;really_const : boolean);
  1355. begin
  1356. ttypedconstsym.init(n,nil,really_const);
  1357. typedconsttype:=tt;
  1358. end;
  1359. constructor ttypedconstsym.load;
  1360. begin
  1361. tsym.load;
  1362. typ:=typedconstsym;
  1363. typedconsttype.load;
  1364. prefix:=stringdup(readstring);
  1365. is_really_const:=boolean(readbyte);
  1366. end;
  1367. destructor ttypedconstsym.done;
  1368. begin
  1369. stringdispose(prefix);
  1370. tsym.done;
  1371. end;
  1372. function ttypedconstsym.mangledname : string;
  1373. begin
  1374. mangledname:='TC_'+prefix^+'_'+name;
  1375. end;
  1376. function ttypedconstsym.getsize : longint;
  1377. begin
  1378. if assigned(typedconsttype.def) then
  1379. getsize:=typedconsttype.def^.size
  1380. else
  1381. getsize:=0;
  1382. end;
  1383. procedure ttypedconstsym.deref;
  1384. begin
  1385. typedconsttype.resolve;
  1386. end;
  1387. procedure ttypedconstsym.write;
  1388. begin
  1389. tsym.write;
  1390. typedconsttype.write;
  1391. writestring(prefix^);
  1392. writebyte(byte(is_really_const));
  1393. current_ppu^.writeentry(ibtypedconstsym);
  1394. end;
  1395. procedure ttypedconstsym.insert_in_data;
  1396. var
  1397. curconstsegment : paasmoutput;
  1398. l,ali,modulo : longint;
  1399. storefilepos : tfileposinfo;
  1400. begin
  1401. storefilepos:=aktfilepos;
  1402. aktfilepos:=tokenpos;
  1403. if is_really_const then
  1404. curconstsegment:=consts
  1405. else
  1406. curconstsegment:=datasegment;
  1407. if (cs_create_smart in aktmoduleswitches) then
  1408. curconstsegment^.concat(new(pai_cut,init));
  1409. l:=getsize;
  1410. ali:=data_align(l);
  1411. if ali>1 then
  1412. begin
  1413. curconstsegment^.concat(new(pai_align,init(ali)));
  1414. modulo:=owner^.datasize mod ali;
  1415. if modulo>0 then
  1416. inc(owner^.datasize,ali-modulo);
  1417. end;
  1418. { Why was there no owner size update here ??? }
  1419. inc(owner^.datasize,l);
  1420. {$ifdef GDB}
  1421. if cs_debuginfo in aktmoduleswitches then
  1422. concatstabto(curconstsegment);
  1423. {$endif GDB}
  1424. if owner^.symtabletype=globalsymtable then
  1425. begin
  1426. curconstsegment^.concat(new(pai_symbol,initdataname_global(mangledname,getsize)));
  1427. end
  1428. else
  1429. if owner^.symtabletype<>unitsymtable then
  1430. begin
  1431. if (cs_create_smart in aktmoduleswitches) or
  1432. DLLSource then
  1433. curconstsegment^.concat(new(pai_symbol,initdataname_global(mangledname,getsize)))
  1434. else
  1435. curconstsegment^.concat(new(pai_symbol,initdataname(mangledname,getsize)));
  1436. end;
  1437. aktfilepos:=storefilepos;
  1438. end;
  1439. {$ifdef GDB}
  1440. function ttypedconstsym.stabstring : pchar;
  1441. var
  1442. st : char;
  1443. begin
  1444. if (cs_gdb_gsym in aktglobalswitches) and (owner^.symtabletype in [unitsymtable,globalsymtable]) then
  1445. st := 'G'
  1446. else
  1447. st := 'S';
  1448. stabstring := strpnew('"'+name+':'+st+
  1449. typedconsttype.def^.numberstring+'",'+tostr(n_STSYM)+',0,'+
  1450. tostr(fileinfo.line)+','+mangledname);
  1451. end;
  1452. {$endif GDB}
  1453. {****************************************************************************
  1454. TCONSTSYM
  1455. ****************************************************************************}
  1456. constructor tconstsym.init(const n : string;t : tconsttyp;v : longint);
  1457. begin
  1458. inherited init(n);
  1459. typ:=constsym;
  1460. consttyp:=t;
  1461. value:=v;
  1462. ResStrIndex:=0;
  1463. consttype.reset;
  1464. len:=0;
  1465. end;
  1466. constructor tconstsym.init_def(const n : string;t : tconsttyp;v : longint;def : pdef);
  1467. begin
  1468. inherited init(n);
  1469. typ:=constsym;
  1470. consttyp:=t;
  1471. value:=v;
  1472. consttype.setdef(def);
  1473. len:=0;
  1474. end;
  1475. constructor tconstsym.init_string(const n : string;t : tconsttyp;str:pchar;l:longint);
  1476. begin
  1477. inherited init(n);
  1478. typ:=constsym;
  1479. consttyp:=t;
  1480. value:=longint(str);
  1481. consttype.reset;
  1482. len:=l;
  1483. if t=constresourcestring then
  1484. ResStrIndex:=ResourceStrings^.Register(name,pchar(value),len);
  1485. end;
  1486. constructor tconstsym.load;
  1487. var
  1488. pd : pbestreal;
  1489. ps : pnormalset;
  1490. begin
  1491. tsym.load;
  1492. typ:=constsym;
  1493. consttype.reset;
  1494. consttyp:=tconsttyp(readbyte);
  1495. case consttyp of
  1496. constint,
  1497. constbool,
  1498. constchar :
  1499. value:=readlong;
  1500. constpointer,
  1501. constord :
  1502. begin
  1503. consttype.load;
  1504. value:=readlong;
  1505. end;
  1506. conststring,constresourcestring :
  1507. begin
  1508. len:=readlong;
  1509. getmem(pchar(value),len+1);
  1510. current_ppu^.getdata(pchar(value)^,len);
  1511. if consttyp=constresourcestring then
  1512. ResStrIndex:=readlong;
  1513. end;
  1514. constreal :
  1515. begin
  1516. new(pd);
  1517. pd^:=readreal;
  1518. value:=longint(pd);
  1519. end;
  1520. constset :
  1521. begin
  1522. consttype.load;
  1523. new(ps);
  1524. readnormalset(ps^);
  1525. value:=longint(ps);
  1526. end;
  1527. constnil : ;
  1528. else
  1529. Message1(unit_f_ppu_invalid_entry,tostr(ord(consttyp)));
  1530. end;
  1531. end;
  1532. destructor tconstsym.done;
  1533. begin
  1534. case consttyp of
  1535. conststring,constresourcestring :
  1536. freemem(pchar(value),len+1);
  1537. constreal :
  1538. dispose(pbestreal(value));
  1539. constset :
  1540. dispose(pnormalset(value));
  1541. end;
  1542. inherited done;
  1543. end;
  1544. function tconstsym.mangledname : string;
  1545. begin
  1546. mangledname:=name;
  1547. end;
  1548. procedure tconstsym.deref;
  1549. begin
  1550. if consttyp in [constord,constpointer,constset] then
  1551. consttype.resolve;
  1552. end;
  1553. procedure tconstsym.write;
  1554. begin
  1555. tsym.write;
  1556. writebyte(byte(consttyp));
  1557. case consttyp of
  1558. constnil : ;
  1559. constint,
  1560. constbool,
  1561. constchar :
  1562. writelong(value);
  1563. constpointer,
  1564. constord :
  1565. begin
  1566. consttype.write;
  1567. writelong(value);
  1568. end;
  1569. conststring,constresourcestring :
  1570. begin
  1571. writelong(len);
  1572. current_ppu^.putdata(pchar(value)^,len);
  1573. if consttyp=constresourcestring then
  1574. writelong(ResStrIndex);
  1575. end;
  1576. constreal :
  1577. writereal(pbestreal(value)^);
  1578. constset :
  1579. begin
  1580. consttype.write;
  1581. writenormalset(pointer(value)^);
  1582. end;
  1583. else
  1584. internalerror(13);
  1585. end;
  1586. current_ppu^.writeentry(ibconstsym);
  1587. end;
  1588. {$ifdef GDB}
  1589. function tconstsym.stabstring : pchar;
  1590. var st : string;
  1591. begin
  1592. {even GDB v4.16 only now 'i' 'r' and 'e' !!!}
  1593. case consttyp of
  1594. conststring : begin
  1595. { I had to remove ibm2ascii !! }
  1596. st := pstring(value)^;
  1597. {st := ibm2ascii(pstring(value)^);}
  1598. st := 's'''+st+'''';
  1599. end;
  1600. constbool,
  1601. constint,
  1602. constpointer,
  1603. constord,
  1604. constchar : st := 'i'+tostr(value);
  1605. constreal : begin
  1606. system.str(pbestreal(value)^,st);
  1607. st := 'r'+st;
  1608. end;
  1609. { if we don't know just put zero !! }
  1610. else st:='i0';
  1611. {***SETCONST}
  1612. {constset:;} {*** I don't know what to do with a set.}
  1613. { sets are not recognized by GDB}
  1614. {***}
  1615. end;
  1616. stabstring := strpnew('"'+name+':c='+st+'",'+tostr(N_function)+',0,'+
  1617. tostr(fileinfo.line)+',0');
  1618. end;
  1619. procedure tconstsym.concatstabto(asmlist : paasmoutput);
  1620. begin
  1621. if consttyp <> conststring then
  1622. inherited concatstabto(asmlist);
  1623. end;
  1624. {$endif GDB}
  1625. {****************************************************************************
  1626. TENUMSYM
  1627. ****************************************************************************}
  1628. constructor tenumsym.init(const n : string;def : penumdef;v : longint);
  1629. begin
  1630. tsym.init(n);
  1631. typ:=enumsym;
  1632. definition:=def;
  1633. value:=v;
  1634. if def^.min>v then
  1635. def^.setmin(v);
  1636. if def^.max<v then
  1637. def^.setmax(v);
  1638. order;
  1639. end;
  1640. constructor tenumsym.load;
  1641. begin
  1642. tsym.load;
  1643. typ:=enumsym;
  1644. definition:=penumdef(readdefref);
  1645. value:=readlong;
  1646. nextenum := Nil;
  1647. end;
  1648. procedure tenumsym.deref;
  1649. begin
  1650. resolvedef(pdef(definition));
  1651. order;
  1652. end;
  1653. procedure tenumsym.order;
  1654. var
  1655. sym : penumsym;
  1656. begin
  1657. sym := definition^.firstenum;
  1658. if sym = nil then
  1659. begin
  1660. definition^.firstenum := @self;
  1661. nextenum := nil;
  1662. exit;
  1663. end;
  1664. { reorder the symbols in increasing value }
  1665. if value < sym^.value then
  1666. begin
  1667. nextenum := sym;
  1668. definition^.firstenum := @self;
  1669. end
  1670. else
  1671. begin
  1672. while (sym^.value <= value) and assigned(sym^.nextenum) do
  1673. sym := sym^.nextenum;
  1674. nextenum := sym^.nextenum;
  1675. sym^.nextenum := @self;
  1676. end;
  1677. end;
  1678. procedure tenumsym.write;
  1679. begin
  1680. tsym.write;
  1681. writedefref(definition);
  1682. writelong(value);
  1683. current_ppu^.writeentry(ibenumsym);
  1684. end;
  1685. {$ifdef GDB}
  1686. procedure tenumsym.concatstabto(asmlist : paasmoutput);
  1687. begin
  1688. {enum elements have no stab !}
  1689. end;
  1690. {$EndIf GDB}
  1691. {****************************************************************************
  1692. TTYPESYM
  1693. ****************************************************************************}
  1694. constructor ttypesym.init(const n : string;const tt : ttype);
  1695. begin
  1696. tsym.init(n);
  1697. typ:=typesym;
  1698. restype:=tt;
  1699. {$ifdef GDB}
  1700. isusedinstab := false;
  1701. {$endif GDB}
  1702. {$ifdef SYNONYM}
  1703. if assigned(restype.def) then
  1704. begin
  1705. if not(assigned(restype.def^.typesym)) then
  1706. begin
  1707. restype.def^.typesym:=@self;
  1708. synonym:=nil;
  1709. include(symoptions,sp_primary_typesym);
  1710. end
  1711. else
  1712. begin
  1713. synonym:=restype.def^.typesym^.synonym;
  1714. restype.def^.typesym^.synonym:=@self;
  1715. end;
  1716. end;
  1717. {$else}
  1718. { register the typesym for the definition }
  1719. if assigned(restype.def) and
  1720. not(assigned(restype.def^.typesym)) then
  1721. restype.def^.typesym:=@self;
  1722. {$endif}
  1723. end;
  1724. constructor ttypesym.initdef(const n : string;d : pdef);
  1725. var
  1726. t : ttype;
  1727. begin
  1728. t.setdef(d);
  1729. ttypesym.init(n,t);
  1730. end;
  1731. constructor ttypesym.load;
  1732. begin
  1733. tsym.load;
  1734. typ:=typesym;
  1735. {$ifdef SYNONYM}
  1736. synonym:=nil;
  1737. {$endif}
  1738. {$ifdef GDB}
  1739. isusedinstab := false;
  1740. {$endif GDB}
  1741. restype.load;
  1742. end;
  1743. {$ifdef SYNONYM}
  1744. destructor ttypesym.done;
  1745. var
  1746. prevsym : ptypesym;
  1747. begin
  1748. if assigned(restype.def) then
  1749. begin
  1750. prevsym:=restype.def^.typesym;
  1751. if prevsym=@self then
  1752. restype.def^.typesym:=synonym;
  1753. while assigned(prevsym) do
  1754. begin
  1755. if (prevsym^.synonym=@self) then
  1756. begin
  1757. prevsym^.synonym:=synonym;
  1758. break;
  1759. end;
  1760. prevsym:=prevsym^.synonym;
  1761. end;
  1762. end;
  1763. synonym:=nil;
  1764. inherited done;
  1765. end;
  1766. {$endif}
  1767. procedure ttypesym.prederef;
  1768. begin
  1769. restype.resolve;
  1770. {$ifdef SYNONYM}
  1771. if assigned(restype.def) then
  1772. begin
  1773. if (sp_primary_typesym in symoptions) then
  1774. begin
  1775. if restype.def^.typesym<>@self then
  1776. synonym:=restype.def^.typesym;
  1777. restype.def^.typesym:=@self;
  1778. end
  1779. else
  1780. begin
  1781. if assigned(restype.def^.typesym) then
  1782. begin
  1783. synonym:=restype.def^.typesym^.synonym;
  1784. if restype.def^.typesym<>@self then
  1785. restype.def^.typesym^.synonym:=@self;
  1786. end
  1787. else
  1788. restype.def^.typesym:=@self;
  1789. end;
  1790. if (restype.def^.deftype=recorddef) and assigned(precorddef(restype.def)^.symtable) and
  1791. (restype.def^.typesym=@self) then
  1792. precorddef(restype.def)^.symtable^.name:=stringdup('record '+name);
  1793. end;
  1794. {$endif}
  1795. end;
  1796. procedure ttypesym.write;
  1797. begin
  1798. tsym.write;
  1799. restype.write;
  1800. current_ppu^.writeentry(ibtypesym);
  1801. end;
  1802. procedure ttypesym.load_references;
  1803. begin
  1804. inherited load_references;
  1805. if (restype.def^.deftype=recorddef) then
  1806. precorddef(restype.def)^.symtable^.load_browser;
  1807. if (restype.def^.deftype=objectdef) then
  1808. pobjectdef(restype.def)^.symtable^.load_browser;
  1809. end;
  1810. function ttypesym.write_references : boolean;
  1811. begin
  1812. if not inherited write_references then
  1813. { write address of this symbol if record or object
  1814. even if no real refs are there
  1815. because we need it for the symtable }
  1816. if (restype.def^.deftype=recorddef) or
  1817. (restype.def^.deftype=objectdef) then
  1818. begin
  1819. writesymref(@self);
  1820. current_ppu^.writeentry(ibsymref);
  1821. end;
  1822. write_references:=true;
  1823. if (restype.def^.deftype=recorddef) then
  1824. precorddef(restype.def)^.symtable^.write_browser;
  1825. if (restype.def^.deftype=objectdef) then
  1826. pobjectdef(restype.def)^.symtable^.write_browser;
  1827. end;
  1828. {$ifdef BrowserLog}
  1829. procedure ttypesym.add_to_browserlog;
  1830. begin
  1831. inherited add_to_browserlog;
  1832. if (restype.def^.deftype=recorddef) then
  1833. precorddef(restype.def)^.symtable^.writebrowserlog;
  1834. if (restype.def^.deftype=objectdef) then
  1835. pobjectdef(restype.def)^.symtable^.writebrowserlog;
  1836. end;
  1837. {$endif BrowserLog}
  1838. {$ifdef GDB}
  1839. function ttypesym.stabstring : pchar;
  1840. var
  1841. stabchar : string[2];
  1842. short : string;
  1843. begin
  1844. if restype.def^.deftype in tagtypes then
  1845. stabchar := 'Tt'
  1846. else
  1847. stabchar := 't';
  1848. short := '"'+name+':'+stabchar+restype.def^.numberstring
  1849. +'",'+tostr(N_LSYM)+',0,'+tostr(fileinfo.line)+',0';
  1850. stabstring := strpnew(short);
  1851. end;
  1852. procedure ttypesym.concatstabto(asmlist : paasmoutput);
  1853. begin
  1854. {not stabs for forward defs }
  1855. if assigned(restype.def) then
  1856. if (restype.def^.typesym = @self) then
  1857. restype.def^.concatstabto(asmlist)
  1858. else
  1859. inherited concatstabto(asmlist);
  1860. end;
  1861. {$endif GDB}
  1862. {****************************************************************************
  1863. TSYSSYM
  1864. ****************************************************************************}
  1865. constructor tsyssym.init(const n : string;l : longint);
  1866. begin
  1867. inherited init(n);
  1868. typ:=syssym;
  1869. number:=l;
  1870. end;
  1871. constructor tsyssym.load;
  1872. begin
  1873. tsym.load;
  1874. typ:=syssym;
  1875. number:=readlong;
  1876. end;
  1877. destructor tsyssym.done;
  1878. begin
  1879. inherited done;
  1880. end;
  1881. procedure tsyssym.write;
  1882. begin
  1883. tsym.write;
  1884. writelong(number);
  1885. current_ppu^.writeentry(ibsyssym);
  1886. end;
  1887. {$ifdef GDB}
  1888. procedure tsyssym.concatstabto(asmlist : paasmoutput);
  1889. begin
  1890. end;
  1891. {$endif GDB}
  1892. {****************************************************************************
  1893. TMACROSYM
  1894. ****************************************************************************}
  1895. constructor tmacrosym.init(const n : string);
  1896. begin
  1897. inherited init(n);
  1898. typ:=macrosym;
  1899. defined:=true;
  1900. defined_at_startup:=false;
  1901. is_used:=false;
  1902. buftext:=nil;
  1903. buflen:=0;
  1904. end;
  1905. destructor tmacrosym.done;
  1906. begin
  1907. if assigned(buftext) then
  1908. freemem(buftext,buflen);
  1909. inherited done;
  1910. end;
  1911. {
  1912. $Log$
  1913. Revision 1.4 2000-08-13 12:54:56 peter
  1914. * class member decl wrong then no other error after it
  1915. * -vb has now also line numbering
  1916. * -vb is also used for interface/implementation different decls and
  1917. doesn't list the current function (merged)
  1918. Revision 1.3 2000/07/13 12:08:27 michael
  1919. + patched to 1.1.0 with former 1.09patch from peter
  1920. Revision 1.2 2000/07/13 11:32:49 michael
  1921. + removed logs
  1922. }