symbols.pas 38 KB

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