symbols.pas 39 KB

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