symsym.inc 61 KB

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