symbols.pas 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418
  1. {
  2. $Id$
  3. This unit handles symbols
  4. Copyright (C) 1998-2000 by Daniel Mantione,
  5. member of the Free Pascal development team
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2 of the License, or
  9. (at your option) any later version.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with this program; if not, write to the Free Software
  16. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. ****************************************************************************
  18. }
  19. {$ifdef TP}
  20. {$N+,E+,F+}
  21. {$endif}
  22. unit symbols;
  23. interface
  24. uses symtable,aasm,objects,cobjects,defs
  25. {$ifdef i386}
  26. ,i386base
  27. {$endif}
  28. {$ifdef m68k}
  29. ,m68k
  30. {$endif}
  31. {$ifdef alpha}
  32. ,alpha
  33. {$endif};
  34. {Note: It is forbidden to add the symtablt unit. A symbol should not now in
  35. which symtable it is.}
  36. type Ttypeprop=(sp_primary_typesym);
  37. Ttypepropset=set of Ttypeprop;
  38. Tpropprop=(ppo_indexed,ppo_defaultproperty,
  39. ppo_stored,ppo_published);
  40. Tproppropset=set of Tpropprop;
  41. Tvarprop=(vo_regable,vo_is_C_var,vo_is_external,vo_is_dll_var,
  42. vo_is_thread_var);
  43. Tvarpropset=set of Tvarprop;
  44. Plabelsym=^Tlabelsym;
  45. Tlabelsym=object(Tsym)
  46. lab:Pasmlabel;
  47. defined:boolean;
  48. constructor init(const n:string;l:Pasmlabel);
  49. constructor load(var s:Tstream);
  50. function mangledname:string;virtual;
  51. procedure store(var s:Tstream);virtual;
  52. end;
  53. { Punitsym=^Tunitsym;
  54. Tunitsym=object(Tsym)
  55. unitsymtable : punitsymtable;
  56. prevsym : punitsym;
  57. refs : longint;
  58. constructor init(const n : string;ref : punitsymtable);
  59. constructor load(var s:Tstream);
  60. destructor done;virtual;
  61. procedure store(var s:Tstream);virtual;
  62. end;}
  63. Perrorsym=^Terrorsym;
  64. Terrorsym=object(tsym)
  65. constructor init;
  66. end;
  67. Pprocsym=^Tprocsym;
  68. Tprocsym=object(Tsym)
  69. definitions:Pobject; {Is Pprocdef when procedure not
  70. overloaded, or a Pcollection of
  71. Pprocdef when it is overloaded.
  72. Since most procedures are not
  73. overloaded, this saves a lot of
  74. memory.}
  75. sub_of:Pprocsym;
  76. _class:Pobjectdef;
  77. constructor init(const n:string;Asub_of:Pprocsym);
  78. constructor load(var s:Tstream);
  79. procedure foreach(action:pointer);
  80. procedure insert(def:Pdef);
  81. function mangledname:string;virtual; {Causes internalerror.}
  82. {Writes all declarations.}
  83. procedure write_parameter_lists;
  84. {Tests, if all procedures definitions are defined and not
  85. just available as forward,}
  86. procedure check_forward;
  87. procedure store(var s:Tstream);virtual;
  88. procedure deref;virtual;
  89. procedure load_references;virtual;
  90. function write_references:boolean;virtual;
  91. destructor done;virtual;
  92. end;
  93. Ptypesym=^Ttypesym;
  94. Ttypesym=object(Tsym)
  95. definition:Pdef;
  96. forwardpointers:Pcollection; {Contains the forwardpointers.}
  97. properties:Ttypepropset;
  98. synonym:Ptypesym;
  99. constructor init(const n:string;d:Pdef);
  100. constructor load(var s:Tstream);
  101. { procedure addforwardpointer(p:Ppointerdef);}
  102. procedure deref;virtual;
  103. procedure store(var s:Tstream);virtual;
  104. procedure load_references;virtual;
  105. procedure updateforwarddef(p:pdef);
  106. function write_references:boolean;virtual;
  107. destructor done;virtual;
  108. end;
  109. Psyssym=^Tsyssym;
  110. Tsyssym=object(Tsym)
  111. number:longint;
  112. constructor init(const n:string;l:longint);
  113. constructor load(var s:Tstream);
  114. procedure store(var s:Tstream);virtual;
  115. end;
  116. Pmacrosym=^Tmacrosym;
  117. Tmacrosym=object(Tsym)
  118. defined:boolean;
  119. buftext:Pchar;
  120. buflen:longint;
  121. {Macros aren't written to PPU files !}
  122. constructor init(const n:string);
  123. destructor done;virtual;
  124. end;
  125. Penumsym=^Tenumsym;
  126. Tenumsym=object(tsym)
  127. value:longint;
  128. definition:Penumdef;
  129. nextenum:Penumsym;
  130. constructor init(const n:string;def:Penumdef;v:longint);
  131. constructor load(var s:Tstream);
  132. procedure store(var s:Tstream);virtual;
  133. procedure deref;virtual;
  134. procedure order;
  135. end;
  136. Pprogramsym=^Tprogramsym;
  137. Tprogramsym=object(Tsym)
  138. end;
  139. Pvarsym=^Tvarsym;
  140. Tvarsym=object(tsym)
  141. address:longint;
  142. localvarsym:Pvarsym;
  143. islocalcopy:boolean;
  144. definition:Pdef;
  145. refs:longint;
  146. properties:Tvarpropset;
  147. objprop:Tobjpropset;
  148. _mangledname:Pstring;
  149. reg:Tregister; {If reg<>R_NO, then the variable is an register
  150. variable }
  151. constructor init(const n:string;p:Pdef);
  152. constructor init_dll(const n:string;p:Pdef);
  153. constructor init_C(const n,mangled:string;p:Pdef);
  154. constructor load(var s:Tstream);
  155. procedure concatdata(const n:string;len:longint);
  156. procedure deref;virtual;
  157. function getsize:longint;virtual;
  158. function mangledname:string;virtual;
  159. procedure insert_in_data;virtual;
  160. procedure setmangledname(const s:string);
  161. procedure store(var s:Tstream);virtual;
  162. destructor done;virtual;
  163. end;
  164. Pparamsym=^Tparamsym;
  165. Tparamsym=object(Tvarsym)
  166. varspez:Tvarspez;
  167. pushaddress:longint;
  168. constructor init(const n:string;p:Pdef;vs:Tvarspez);
  169. function getsize:longint;virtual;
  170. function getpushsize:longint;virtual;
  171. procedure insert_in_data;virtual;
  172. end;
  173. Ptypedconstsym=^Ttypedconstsym;
  174. Ttypedconstsym=object(Tsym)
  175. prefix:Pstring;
  176. definition:Pdef;
  177. is_really_const:boolean;
  178. constructor init(const n:string;p:Pdef;really_const:boolean);
  179. constructor load(var s:Tstream);
  180. destructor done;virtual;
  181. function mangledname:string;virtual;
  182. procedure store(var s:Tstream);virtual;
  183. procedure deref;virtual;
  184. function getsize:longint;
  185. procedure insert_in_data;virtual;
  186. end;
  187. Tconsttype=(constord,conststring,constreal,constbool,
  188. constint,constchar,constset,constnil);
  189. Pconstsym=^Tconstsym;
  190. Tconstsym=object(Tsym)
  191. definition:Pdef;
  192. consttype:Tconsttype;
  193. value,len:longint; {Len is needed for string length.}
  194. constructor init(const n:string;t:Tconsttype;v:longint);
  195. constructor init_def(const n:string;t:Tconsttype;v:longint;
  196. def:Pdef);
  197. constructor init_string(const n:string;t:Tconsttype;
  198. str:Pchar;l:longint);
  199. constructor load(var s:Tstream);
  200. procedure deref;virtual;
  201. procedure store(var s:Tstream);virtual;
  202. destructor done;virtual;
  203. end;
  204. absolutetyp = (tovar,toasm,toaddr);
  205. Pabsolutesym = ^tabsolutesym;
  206. Tabsolutesym = object(tvarsym)
  207. abstyp:absolutetyp;
  208. absseg:boolean;
  209. ref:Psym;
  210. asmname:Pstring;
  211. constructor load(var s:Tstream);
  212. procedure deref;virtual;
  213. function mangledname : string;virtual;
  214. procedure store(var s:Tstream);virtual;
  215. end;
  216. Pfuncretsym=^Tfuncretsym;
  217. Tfuncretsym=object(tsym)
  218. funcretprocinfo : pointer{ should be pprocinfo};
  219. funcretdef:Pdef;
  220. address:longint;
  221. constructor init(const n:string;approcinfo:pointer{pprocinfo});
  222. constructor load(var s:Tstream);
  223. procedure insert_in_data;virtual;
  224. procedure store(var s:Tstream);virtual;
  225. procedure deref;virtual;
  226. end;
  227. Ppropertysym=^Tpropertysym;
  228. Tpropertysym=object(Tsym)
  229. properties:Tproppropset;
  230. definition:Pdef;
  231. readaccesssym,writeaccesssym,storedsym:Psym;
  232. readaccessdef,writeaccessdef,storeddef:Pdef;
  233. index,default:longint;
  234. constructor load(var s:Tstream);
  235. function getsize:longint;virtual;
  236. procedure store(var s:Tstream);virtual;
  237. procedure deref;virtual;
  238. end;
  239. var current_object_option:Tobjpropset;
  240. current_type_option:Ttypepropset;
  241. implementation
  242. uses callspec,verbose,globals,systems,globtype;
  243. {****************************************************************************
  244. Tlabelsym
  245. ****************************************************************************}
  246. constructor Tlabelsym.init(const n:string;l:Pasmlabel);
  247. begin
  248. inherited init(n);
  249. lab:=l;
  250. defined:=false;
  251. end;
  252. constructor Tlabelsym.load(var s:Tstream);
  253. begin
  254. inherited load(s);
  255. defined:=true;
  256. end;
  257. function Tlabelsym.mangledname:string;
  258. begin
  259. mangledname:=lab^.name;
  260. end;
  261. procedure Tlabelsym.store(var s:Tstream);
  262. begin
  263. inherited store(s);
  264. { current_ppu^.writeentry(iblabelsym);}
  265. end;
  266. {****************************************************************************
  267. Terrorsym
  268. ****************************************************************************}
  269. constructor terrorsym.init;
  270. begin
  271. inherited init('');
  272. end;
  273. {****************************************************************************
  274. Tprocsym
  275. ****************************************************************************}
  276. constructor Tprocsym.init(const n:string;Asub_of:Pprocsym);
  277. begin
  278. inherited init(n);
  279. sub_of:=Asub_of;
  280. end;
  281. constructor Tprocsym.load(var s:Tstream);
  282. begin
  283. inherited load(s);
  284. { definition:=Pprocdef(readdefref);}
  285. end;
  286. procedure Tprocsym.foreach(action:pointer);
  287. begin
  288. if definitions<>nil then
  289. begin
  290. if typeof(definitions^)=typeof(Tcollection) then
  291. Pcollection(definitions)^.foreach(action)
  292. else
  293. callpointerlocal(action,previousframepointer,definitions);
  294. end;
  295. end;
  296. procedure Tprocsym.insert(def:Pdef);
  297. var c:Pcollection;
  298. begin
  299. if definitions=nil then
  300. definitions:=def
  301. else
  302. if typeof(definitions^)=typeof(Tcollection) then
  303. Pcollection(def)^.insert(def)
  304. else
  305. begin
  306. c:=new(Pcollection,init(8,4));
  307. c^.insert(definitions);
  308. definitions:=c;
  309. end;
  310. end;
  311. function Tprocsym.mangledname:string;
  312. begin
  313. internalerror($99080201);
  314. end;
  315. procedure Tprocsym.write_parameter_lists;
  316. {var p:Pprocdef;}
  317. begin
  318. (* p:=definition;
  319. while assigned(p) do
  320. begin
  321. {Force the error to be printed.}
  322. verbose.message1(sym_b_param_list,name+p^.demangled_paras);
  323. p:=p^.nextoverloaded;
  324. end;*)
  325. end;
  326. procedure tprocsym.check_forward;
  327. {var pd:Pprocdef;}
  328. begin
  329. (* pd:=definition;
  330. while assigned(pd) do
  331. begin
  332. if pd^.forwarddef then
  333. begin
  334. if assigned(pd^._class) then
  335. messagepos1(fileinfo,sym_e_forward_not_resolved,
  336. pd^._class^.objname^+'.'+name+
  337. demangledparas(pd^.demangled_paras))
  338. else
  339. messagepos1(fileinfo,sym_e_forward_not_resolved,
  340. name+pd^.demangled_paras);
  341. {Turn futher error messages off.}
  342. pd^.forwarddef:=false;
  343. end;
  344. pd:=pd^.nextoverloaded;
  345. end;*)
  346. end;
  347. procedure tprocsym.deref;
  348. {var t:ttoken;
  349. last:Pprocdef;}
  350. begin
  351. (*
  352. resolvedef(pdef(definition));
  353. if (definition^.options and pooperator) <> 0 then
  354. begin
  355. last:=definition;
  356. while assigned(last^.nextoverloaded) do
  357. last:=last^.nextoverloaded;
  358. for t:=first_overloaded to last_overloaded do
  359. if (name=overloaded_names[t]) then
  360. begin
  361. if assigned(overloaded_operators[t]) then
  362. last^.nextoverloaded:=overloaded_operators[t]^.definition;
  363. overloaded_operators[t]:=@self;
  364. end;
  365. end;*)
  366. end;
  367. procedure Tprocsym.store(var s:Tstream);
  368. begin
  369. inherited store(s);
  370. { writedefref(pdef(definition));
  371. current_ppu^.writeentry(ibprocsym);}
  372. end;
  373. procedure tprocsym.load_references;
  374. begin
  375. inherited load_references;
  376. end;
  377. function Tprocsym.write_references:boolean;
  378. {var prdef:Pprocdef;}
  379. begin
  380. (* write_references:=false;
  381. if not inherited write_references then
  382. exit;
  383. write_references:=true;
  384. prdef:=definition;
  385. while assigned(prdef) and (prdef^.owner=definition^.owner) do
  386. begin
  387. prdef^.write_references;
  388. prdef:=prdef^.nextoverloaded;
  389. end;*)
  390. end;
  391. destructor Tprocsym.done;
  392. begin
  393. {Don't check if errors !!}
  394. if errorcount=0 then
  395. check_forward;
  396. inherited done;
  397. end;
  398. {****************************************************************************
  399. Ttypesym
  400. ****************************************************************************}
  401. constructor Ttypesym.init(const n:string;d:Pdef);
  402. begin
  403. inherited init(n);
  404. definition:=d;
  405. if assigned(definition) then
  406. begin
  407. if definition^.sym<>nil then
  408. begin
  409. definition^.sym:=@self;
  410. properties:=[sp_primary_typesym];
  411. end
  412. else
  413. begin
  414. synonym:=Ptypesym(definition^.sym)^.synonym;
  415. Ptypesym(definition^.sym)^.synonym:=@self;
  416. end;
  417. end;
  418. end;
  419. constructor Ttypesym.load(var s:Tstream);
  420. begin
  421. inherited load(s);
  422. { definition:=readdefref;}
  423. end;
  424. {procedure Ttypesym.addforwardpointer(p:Ppointerdef);
  425. begin
  426. if forwardpointers=nil then
  427. new(forwardpointers,init(8,4));
  428. forwardpointers^.insert(p);
  429. end;}
  430. procedure ttypesym.deref;
  431. begin
  432. (* resolvedef(definition);
  433. if assigned(definition) then
  434. begin
  435. if properties=sp_primary_typesym then
  436. begin
  437. if definition^.sym<>@self then
  438. synonym:=definition^.sym;
  439. definition^.sym:=@self;
  440. end
  441. else
  442. begin
  443. if assigned(definition^.sym) then
  444. begin
  445. synonym:=definition^.sym^.synonym;
  446. if definition^.sym<>@self then
  447. definition^.sym^.synonym:=@self;
  448. end
  449. else
  450. definition^.sym:=@self;
  451. end;
  452. if (definition^.deftype=recorddef) and
  453. assigned(precdef(definition)^.symtable) and
  454. (definition^.sym=@self) then
  455. precdef(definition)^.symtable^.name:=stringdup('record '+name);
  456. end;*)
  457. end;
  458. procedure ttypesym.store(var s:Tstream);
  459. begin
  460. inherited store(s);
  461. { writedefref(definition);
  462. current_ppu^.writeentry(ibtypesym);}
  463. end;
  464. procedure ttypesym.load_references;
  465. begin
  466. inherited load_references;
  467. { if typeof(definition^)=typeof(Trecorddef) then
  468. Precdef(definition)^.symtable^.load_browser;
  469. if typeof(definition^)=typeof(Tobjectdef) then
  470. Pobjectdef(definition)^.publicsyms^.load_browser;}
  471. end;
  472. function ttypesym.write_references : boolean;
  473. begin
  474. (* if not inherited write_references then
  475. {Write address of this symbol if record or object
  476. even if no real refs are there
  477. because we need it for the symtable }
  478. if (definition^.deftype=recorddef) or
  479. (definition^.deftype=objectdef) then
  480. begin
  481. writesymref(@self);
  482. current_ppu^.writeentry(ibsymref);
  483. end;
  484. write_references:=true;
  485. if (definition^.deftype=recorddef) then
  486. precdef(definition)^.symtable^.write_browser;
  487. if (definition^.deftype=objectdef) then
  488. pobjectdef(definition)^.publicsyms^.write_browser;*)
  489. end;
  490. procedure ttypesym.updateforwarddef(p:pdef);
  491. var i:word;
  492. begin
  493. if definition<>nil then
  494. internalerror($99080203)
  495. else
  496. definition:=p;
  497. properties:=current_type_option;
  498. fileinfo:=tokenpos;
  499. if assigned(definition) and not(assigned(definition^.sym)) then
  500. definition^.sym:=@self;
  501. {Update all forwardpointers to this definition.}
  502. { for i:=1 to forwardpointers^.count do
  503. Ppointerdef(forwardpointers^.at(i))^.definition:=definition;}
  504. forwardpointers^.deleteall;
  505. dispose(forwardpointers,done);
  506. forwardpointers:=nil;
  507. end;
  508. destructor Ttypesym.done;
  509. var prevsym:Ptypesym;
  510. begin
  511. if assigned(definition) then
  512. begin
  513. prevsym:=Ptypesym(definition^.sym);
  514. if prevsym=@self then
  515. definition^.sym:=synonym;
  516. while assigned(prevsym) do
  517. begin
  518. if (prevsym^.synonym=@self) then
  519. begin
  520. prevsym^.synonym:=synonym;
  521. break;
  522. end;
  523. prevsym:=prevsym^.synonym;
  524. end;
  525. end;
  526. synonym:=nil;
  527. definition:=nil;
  528. inherited done;
  529. end;
  530. {****************************************************************************
  531. Tsyssym
  532. ****************************************************************************}
  533. constructor Tsyssym.init(const n:string;l:longint);
  534. begin
  535. inherited init(n);
  536. number:=l;
  537. end;
  538. constructor Tsyssym.load(var s:Tstream);
  539. begin
  540. inherited load(s);
  541. { number:=readlong;}
  542. end;
  543. procedure tsyssym.store(var s:Tstream);
  544. begin
  545. Tsym.store(s);
  546. { writelong(number);
  547. current_ppu^.writeentry(ibsyssym);}
  548. end;
  549. {****************************************************************************
  550. Tenumsym
  551. ****************************************************************************}
  552. constructor Tenumsym.init(const n:string;def:Penumdef;v:longint);
  553. begin
  554. inherited init(n);
  555. definition:=def;
  556. value:=v;
  557. if def^.minval>v then
  558. def^.setmin(v);
  559. if def^.maxval<v then
  560. def^.setmax(v);
  561. order;
  562. end;
  563. constructor Tenumsym.load(var s:Tstream);
  564. begin
  565. inherited load(s);
  566. { definition:=Penumdef(readdefref);
  567. value:=readlong;}
  568. end;
  569. procedure Tenumsym.deref;
  570. begin
  571. { resolvedef(pdef(definition));
  572. order;}
  573. end;
  574. procedure Tenumsym.order;
  575. var i:word;
  576. label inserted;
  577. begin
  578. {Keep the enum symbols ordered by value...}
  579. with definition^.symbols^ do
  580. begin
  581. {Most of the time, enums are defined in order, so we count down.}
  582. for i:=count-1 downto 0 do
  583. begin
  584. if Penumsym(at(i))^.value<value then
  585. begin
  586. atinsert(i+1,@self);
  587. {We have to use goto to keep the
  588. code efficient :( }
  589. goto inserted;
  590. end;
  591. end;
  592. atinsert(0,@self);
  593. inserted:
  594. end;
  595. end;
  596. procedure Tenumsym.store(var s:Tstream);
  597. begin
  598. inherited store(s);
  599. (* writedefref(definition);
  600. writelong(value);
  601. current_ppu^.writeentry(ibenumsym);*)
  602. end;
  603. {****************************************************************************
  604. Tmacrosym
  605. ****************************************************************************}
  606. constructor Tmacrosym.init(const n:string);
  607. begin
  608. inherited init(n);
  609. defined:=true;
  610. end;
  611. destructor Tmacrosym.done;
  612. begin
  613. if assigned(buftext) then
  614. freemem(buftext,buflen);
  615. inherited done;
  616. end;
  617. {****************************************************************************
  618. Tprogramsym
  619. ****************************************************************************}
  620. {****************************************************************************
  621. Tvarsym
  622. ****************************************************************************}
  623. constructor Tvarsym.init(const n:string;p:Pdef);
  624. begin
  625. inherited init(n);
  626. definition:=p;
  627. {Can we load the value into a register ? }
  628. if dp_regable in p^.properties then
  629. include(properties,vo_regable);
  630. reg:=R_NO;
  631. end;
  632. constructor Tvarsym.init_dll(const n:string;p:Pdef);
  633. begin
  634. init(n,p);
  635. include(properties,vo_is_dll_var);
  636. end;
  637. constructor Tvarsym.init_C(const n,mangled:string;p:Pdef);
  638. begin
  639. init(n,p);
  640. include(properties,vo_is_C_var);
  641. setmangledname(mangled);
  642. end;
  643. procedure Tvarsym.concatdata(const n:string;len:longint);
  644. begin
  645. end;
  646. constructor Tvarsym.load(var s:Tstream);
  647. begin
  648. inherited load(s);
  649. reg:=R_NO;
  650. { if read_member then
  651. address:=readlong
  652. else
  653. address:=0;
  654. definition:=readdefref;
  655. var_options:=readbyte;
  656. if (var_options and vo_is_C_var)<>0 then
  657. setmangledname(readstring);}
  658. end;
  659. function Tvarsym.getsize:longint;
  660. begin
  661. if definition<>nil then
  662. getsize:=definition^.size
  663. else
  664. getsize:=0;
  665. end;
  666. procedure Tvarsym.deref;
  667. begin
  668. { resolvedef(definition);}
  669. end;
  670. procedure Tvarsym.store(var s:Tstream);
  671. begin
  672. (* inherited store(s);
  673. if read_member then
  674. writelong(address);
  675. writedefref(definition);
  676. { symbols which are load are never candidates for a register,
  677. turn of the regable }
  678. writebyte(var_options and (not vo_regable));
  679. if (var_options and vo_is_C_var)<>0 then
  680. writestring(mangledname);
  681. current_ppu^.writeentry(ibvarsym);*)
  682. end;
  683. procedure Tvarsym.setmangledname(const s:string);
  684. begin
  685. _mangledname:=stringdup(s);
  686. end;
  687. function Tvarsym.mangledname:string;
  688. var prefix:string;
  689. begin
  690. if assigned(_mangledname) then
  691. mangledname:=_mangledname^
  692. else
  693. mangledname:=owner^.varsymprefix+name;
  694. end;
  695. procedure Tvarsym.insert_in_data;
  696. var l,ali,modulo:longint;
  697. storefilepos:Tfileposinfo;
  698. begin
  699. if (vo_is_external in properties) then
  700. begin
  701. {Handle static variables of objects especially }
  702. if read_member and (sp_static in objprop) then
  703. begin
  704. {The data field is generated in parser.pas
  705. with a tobject_FIELDNAME variable, so we do
  706. not need to do it in this procedure.}
  707. {This symbol can't be loaded to a register.}
  708. exclude(properties,vo_regable);
  709. end
  710. else
  711. if not(read_member) then
  712. begin
  713. storefilepos:=aktfilepos;
  714. aktfilepos:=tokenpos;
  715. if (vo_is_thread_var in properties) then
  716. l:=4
  717. else
  718. l:=getsize;
  719. address:=owner^.varsymtodata(@self,l);
  720. aktfilepos:=storefilepos;
  721. end;
  722. end;
  723. end;
  724. destructor Tvarsym.done;
  725. begin
  726. disposestr(_mangledname);
  727. inherited done;
  728. end;
  729. {****************************************************************************
  730. Tparamsym
  731. ****************************************************************************}
  732. constructor Tparamsym.init(const n:string;p:Pdef;vs:Tvarspez);
  733. begin
  734. inherited init(n,p);
  735. varspez:=vs;
  736. end;
  737. function Tparamsym.getsize:longint;
  738. begin
  739. if (definition<>nil) and (varspez=vs_value) then
  740. getsize:=definition^.size
  741. else
  742. getsize:=0;
  743. end;
  744. function Tparamsym.getpushsize:longint;
  745. begin
  746. if assigned(definition) then
  747. begin
  748. case varspez of
  749. vs_var:
  750. getpushsize:=target_os.size_of_pointer;
  751. vs_value,vs_const:
  752. if dp_pointer_param in definition^.properties then
  753. getpushsize:=target_os.size_of_pointer
  754. else
  755. getpushsize:=definition^.size;
  756. end;
  757. end
  758. else
  759. getpushsize:=0;
  760. end;
  761. procedure Tparamsym.insert_in_data;
  762. var storefilepos:Tfileposinfo;
  763. begin
  764. storefilepos:=aktfilepos;
  765. {Handle static variables of objects especially }
  766. if read_member and (sp_static in objprop) then
  767. begin
  768. {The data field is generated in parser.pas
  769. with a tobject_FIELDNAME variable, so we do
  770. not need to do it in this procedure.}
  771. {This symbol can't be loaded to a register.}
  772. exclude(properties,vo_regable);
  773. end
  774. else
  775. if not(read_member) then
  776. pushaddress:=owner^.varsymtodata(@self,getpushsize);
  777. if (varspez=vs_var) then
  778. address:=0
  779. else if (varspez=vs_value) then
  780. if dp_pointer_param in definition^.properties then
  781. begin
  782. {Allocate local space.}
  783. address:=owner^.datasize;
  784. inc(owner^.datasize,getsize);
  785. end
  786. else
  787. address:=pushaddress
  788. else
  789. {vs_const}
  790. if dp_pointer_param in definition^.properties then
  791. address:=0
  792. else
  793. address:=pushaddress;
  794. aktfilepos:=storefilepos;
  795. end;
  796. {****************************************************************************
  797. Ttypedconstsym
  798. *****************************************************************************}
  799. constructor Ttypedconstsym.init(const n:string;p:Pdef;really_const:boolean);
  800. begin
  801. inherited init(n);
  802. definition:=p;
  803. is_really_const:=really_const;
  804. prefix:=stringdup(procprefix);
  805. end;
  806. constructor Ttypedconstsym.load(var s:Tstream);
  807. begin
  808. inherited load(s);
  809. (* definition:=readdefref;
  810. {$ifdef DELPHI_CONST_IN_RODATA}
  811. is_really_const:=boolean(readbyte);
  812. {$else DELPHI_CONST_IN_RODATA}
  813. is_really_const:=false;
  814. {$endif DELPHI_CONST_IN_RODATA}
  815. prefix:=stringdup(readstring);*)
  816. end;
  817. procedure Ttypedconstsym.deref;
  818. begin
  819. { resolvedef(definition);}
  820. end;
  821. function Ttypedconstsym.mangledname:string;
  822. begin
  823. mangledname:='TC_'+prefix^+'_'+name;
  824. end;
  825. function Ttypedconstsym.getsize:longint;
  826. begin
  827. if assigned(definition) then
  828. getsize:=definition^.size
  829. else
  830. getsize:=0;
  831. end;
  832. procedure Ttypedconstsym.store(var s:Tstream);
  833. begin
  834. inherited store(s);
  835. (* writedefref(definition);
  836. writestring(prefix^);
  837. {$ifdef DELPHI_CONST_IN_RODATA}
  838. writebyte(byte(is_really_const));
  839. {$endif DELPHI_CONST_IN_RODATA}
  840. current_ppu^.writeentry(ibtypedconstsym);*)
  841. end;
  842. { for most symbol types ther is nothing to do at all }
  843. procedure Ttypedconstsym.insert_in_data;
  844. var constsegment:Paasmoutput;
  845. l,ali,modulo:longint;
  846. storefilepos:Tfileposinfo;
  847. begin
  848. storefilepos:=aktfilepos;
  849. aktfilepos:=tokenpos;
  850. owner^.tconstsymtodata(@self,getsize);
  851. aktfilepos:=storefilepos;
  852. end;
  853. destructor Ttypedconstsym.done;
  854. begin
  855. stringdispose(prefix);
  856. inherited done;
  857. end;
  858. {****************************************************************************
  859. TCONSTSYM
  860. ****************************************************************************}
  861. constructor Tconstsym.init(const n : string;t : tconsttype;v : longint);
  862. begin
  863. inherited init(n);
  864. consttype:=t;
  865. value:=v;
  866. end;
  867. constructor Tconstsym.init_def(const n:string;t:Tconsttype;
  868. v:longint;def:Pdef);
  869. begin
  870. inherited init(n);
  871. consttype:=t;
  872. value:=v;
  873. definition:=def;
  874. end;
  875. constructor Tconstsym.init_string(const n:string;t:Tconsttype;str:Pchar;l:longint);
  876. begin
  877. inherited init(n);
  878. consttype:=t;
  879. value:=longint(str);
  880. len:=l;
  881. end;
  882. constructor Tconstsym.load(var s:Tstream);
  883. var pd:Pbestreal;
  884. ps:Pnormalset;
  885. begin
  886. inherited load(s);
  887. (* consttype:=tconsttype(readbyte);
  888. case consttype of
  889. constint,
  890. constbool,
  891. constchar : value:=readlong;
  892. constord :
  893. begin
  894. definition:=readdefref;
  895. value:=readlong;
  896. end;
  897. conststring :
  898. begin
  899. len:=readlong;
  900. getmem(pchar(value),len+1);
  901. current_ppu^.getdata(pchar(value)^,len);
  902. end;
  903. constreal :
  904. begin
  905. new(pd);
  906. pd^:=readreal;
  907. value:=longint(pd);
  908. end;
  909. constset :
  910. begin
  911. definition:=readdefref;
  912. new(ps);
  913. readnormalset(ps^);
  914. value:=longint(ps);
  915. end;
  916. constnil : ;
  917. else
  918. Message1(unit_f_ppu_invalid_entry,tostr(ord(consttype)));
  919. end;*)
  920. end;
  921. procedure Tconstsym.deref;
  922. begin
  923. { if consttype in [constord,constset] then
  924. resolvedef(pdef(definition));}
  925. end;
  926. procedure Tconstsym.store(var s:Tstream);
  927. begin
  928. (* inherited store(s);
  929. writebyte(byte(consttype));
  930. case consttype of
  931. constnil : ;
  932. constint,
  933. constbool,
  934. constchar :
  935. writelong(value);
  936. constord :
  937. begin
  938. writedefref(definition);
  939. writelong(value);
  940. end;
  941. conststring :
  942. begin
  943. writelong(len);
  944. current_ppu^.putdata(pchar(value)^,len);
  945. end;
  946. constreal :
  947. writereal(pbestreal(value)^);
  948. constset :
  949. begin
  950. writedefref(definition);
  951. writenormalset(pointer(value)^);
  952. end;
  953. else
  954. internalerror(13);
  955. end;
  956. current_ppu^.writeentry(ibconstsym);*)
  957. end;
  958. destructor Tconstsym.done;
  959. begin
  960. case consttype of
  961. conststring:
  962. freemem(Pchar(value),len+1);
  963. constreal:
  964. dispose(Pbestreal(value));
  965. constset:
  966. dispose(Pnormalset(value));
  967. end;
  968. inherited done;
  969. end;
  970. {****************************************************************************
  971. Tabsolutesym
  972. ****************************************************************************}
  973. constructor Tabsolutesym.load(var s:Tstream);
  974. begin
  975. inherited load(s);
  976. (* typ:=absolutesym;
  977. abstyp:=absolutetyp(readbyte);
  978. case abstyp of
  979. tovar :
  980. begin
  981. asmname:=stringdup(readstring);
  982. ref:=srsym;
  983. end;
  984. toasm :
  985. asmname:=stringdup(readstring);
  986. toaddr :
  987. begin
  988. address:=readlong;
  989. absseg:=boolean(readbyte);
  990. end;
  991. end;*)
  992. end;
  993. procedure tabsolutesym.store(var s:Tstream);
  994. begin
  995. inherited store(s);
  996. (* writebyte(byte(varspez));
  997. if read_member then
  998. writelong(address);
  999. writedefref(definition);
  1000. writebyte(var_options and (not vo_regable));
  1001. writebyte(byte(abstyp));
  1002. case abstyp of
  1003. tovar :
  1004. writestring(ref^.name);
  1005. toasm :
  1006. writestring(asmname^);
  1007. toaddr :
  1008. begin
  1009. writelong(address);
  1010. writebyte(byte(absseg));
  1011. end;
  1012. end;
  1013. current_ppu^.writeentry(ibabsolutesym);*)
  1014. end;
  1015. procedure tabsolutesym.deref;
  1016. begin
  1017. (* resolvedef(definition);
  1018. if (abstyp=tovar) and (asmname<>nil) then
  1019. begin
  1020. { search previous loaded symtables }
  1021. getsym(asmname^,false);
  1022. if not(assigned(srsym)) then
  1023. getsymonlyin(owner,asmname^);
  1024. if not(assigned(srsym)) then
  1025. srsym:=generrorsym;
  1026. ref:=srsym;
  1027. stringdispose(asmname);
  1028. end;*)
  1029. end;
  1030. function Tabsolutesym.mangledname : string;
  1031. begin
  1032. case abstyp of
  1033. tovar :
  1034. mangledname:=ref^.mangledname;
  1035. toasm :
  1036. mangledname:=asmname^;
  1037. toaddr :
  1038. mangledname:='$'+tostr(address);
  1039. else
  1040. internalerror(10002);
  1041. end;
  1042. end;
  1043. {****************************************************************************
  1044. Tfuncretsym
  1045. ****************************************************************************}
  1046. constructor Tfuncretsym.init(const n:string;approcinfo:pointer{pprocinfo});
  1047. begin
  1048. inherited init(n);
  1049. funcretprocinfo:=approcinfo;
  1050. { funcretdef:=Pprocinfo(approcinfo)^.retdef;}
  1051. { address valid for ret in param only }
  1052. { otherwise set by insert }
  1053. { address:=pprocinfo(approcinfo)^.retoffset;}
  1054. end;
  1055. constructor Tfuncretsym.load(var s:Tstream);
  1056. begin
  1057. inherited load(s);
  1058. { funcretdef:=readdefref;
  1059. address:=readlong;
  1060. funcretprocinfo:=nil;
  1061. typ:=funcretsym;}
  1062. end;
  1063. procedure Tfuncretsym.store(var s:Tstream);
  1064. begin
  1065. (*
  1066. Normally all references are
  1067. transfered to the function symbol itself !! PM *)
  1068. inherited store(s);
  1069. { writedefref(funcretdef);
  1070. writelong(address);
  1071. current_ppu^.writeentry(ibfuncretsym);}
  1072. end;
  1073. procedure Tfuncretsym.deref;
  1074. begin
  1075. {resolvedef(funcretdef);}
  1076. end;
  1077. procedure Tfuncretsym.insert_in_data;
  1078. var l:longint;
  1079. begin
  1080. {Allocate space in local if ret in acc or in fpu.}
  1081. { if dp_ret_in_acc in procinfo.retdef^.properties
  1082. or (procinfo.retdef^.deftype=floatdef) then
  1083. begin
  1084. l:=funcretdef^.size;
  1085. adress:=owner^.varsymtodata('',l);
  1086. procinfo.retoffset:=-owner^.datasize;
  1087. end;}
  1088. end;
  1089. constructor tpropertysym.load(var s:Tstream);
  1090. begin
  1091. inherited load(s);
  1092. (* proptype:=readdefref;
  1093. options:=readlong;
  1094. index:=readlong;
  1095. default:=readlong;
  1096. { it's hack ... }
  1097. readaccesssym:=psym(stringdup(readstring));
  1098. writeaccesssym:=psym(stringdup(readstring));
  1099. storedsym:=psym(stringdup(readstring));
  1100. { now the defs: }
  1101. readaccessdef:=readdefref;
  1102. writeaccessdef:=readdefref;
  1103. storeddef:=readdefref;*)
  1104. end;
  1105. procedure Tpropertysym.deref;
  1106. begin
  1107. (* resolvedef(proptype);
  1108. resolvedef(readaccessdef);
  1109. resolvedef(writeaccessdef);
  1110. resolvedef(storeddef);
  1111. { solve the hack we did in load: }
  1112. if pstring(readaccesssym)^<>'' then
  1113. begin
  1114. srsym:=search_class_member(pobjectdef(owner^.defowner),pstring(readaccesssym)^);
  1115. if not(assigned(srsym)) then
  1116. srsym:=generrorsym;
  1117. end
  1118. else
  1119. srsym:=nil;
  1120. stringdispose(pstring(readaccesssym));
  1121. readaccesssym:=srsym;
  1122. if pstring(writeaccesssym)^<>'' then
  1123. begin
  1124. srsym:=search_class_member(pobjectdef(owner^.defowner),pstring(writeaccesssym)^);
  1125. if not(assigned(srsym)) then
  1126. srsym:=generrorsym;
  1127. end
  1128. else
  1129. srsym:=nil;
  1130. stringdispose(pstring(writeaccesssym));
  1131. writeaccesssym:=srsym;
  1132. if pstring(storedsym)^<>'' then
  1133. begin
  1134. srsym:=search_class_member(pobjectdef(owner^.defowner),pstring(storedsym)^);
  1135. if not(assigned(srsym)) then
  1136. srsym:=generrorsym;
  1137. end
  1138. else
  1139. srsym:=nil;
  1140. stringdispose(pstring(storedsym));
  1141. storedsym:=srsym;*)
  1142. end;
  1143. function Tpropertysym.getsize:longint;
  1144. begin
  1145. getsize:=0;
  1146. end;
  1147. procedure Tpropertysym.store(var s:Tstream);
  1148. begin
  1149. Tsym.store(s);
  1150. (* writedefref(proptype);
  1151. writelong(options);
  1152. writelong(index);
  1153. writelong(default);
  1154. if assigned(readaccesssym) then
  1155. writestring(readaccesssym^.name)
  1156. else
  1157. writestring('');
  1158. if assigned(writeaccesssym) then
  1159. writestring(writeaccesssym^.name)
  1160. else
  1161. writestring('');
  1162. if assigned(storedsym) then
  1163. writestring(storedsym^.name)
  1164. else
  1165. writestring('');
  1166. writedefref(readaccessdef);
  1167. writedefref(writeaccessdef);
  1168. writedefref(storeddef);
  1169. current_ppu^.writeentry(ibpropertysym);*)
  1170. end;
  1171. end.