symsym.inc 63 KB

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