symtable.pas 70 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229
  1. {
  2. $Id$
  3. Copyright (c) 1998-2000 by Florian Klaempfl, Pierre Muller
  4. This unit handles the symbol tables
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. unit symtable;
  19. {$i defines.inc}
  20. interface
  21. uses
  22. { common }
  23. cutils,cclasses,
  24. { global }
  25. globtype,tokens,
  26. { symtable }
  27. symconst,symbase,symtype,symdef,symsym,
  28. { ppu }
  29. ppu,symppu,
  30. { assembler }
  31. aasm
  32. ;
  33. {****************************************************************************
  34. Symtable types
  35. ****************************************************************************}
  36. type
  37. tstoredsymtable = class(tsymtable)
  38. private
  39. b_needs_init_final : boolean;
  40. procedure _needs_init_final(p : tnamedindexitem);
  41. procedure check_forward(sym : TNamedIndexItem);
  42. procedure labeldefined(p : TNamedIndexItem);
  43. procedure unitsymbolused(p : TNamedIndexItem);
  44. procedure varsymbolused(p : TNamedIndexItem);
  45. procedure TestPrivate(p : TNamedIndexItem);
  46. procedure objectprivatesymbolused(p : TNamedIndexItem);
  47. {$ifdef GDB}
  48. private
  49. asmoutput : taasmoutput;
  50. procedure concatstab(p : TNamedIndexItem);
  51. procedure resetstab(p : TNamedIndexItem);
  52. procedure concattypestab(p : TNamedIndexItem);
  53. {$endif}
  54. procedure order_overloads(p : TNamedIndexItem);
  55. procedure loaddefs(ppufile:tcompilerppufile);
  56. procedure loadsyms(ppufile:tcompilerppufile);
  57. procedure writedefs(ppufile:tcompilerppufile);
  58. procedure writesyms(ppufile:tcompilerppufile);
  59. public
  60. { load/write }
  61. procedure load(ppufile:tcompilerppufile);virtual;
  62. procedure write(ppufile:tcompilerppufile);virtual;
  63. procedure load_references(ppufile:tcompilerppufile;locals:boolean);virtual;
  64. procedure write_references(ppufile:tcompilerppufile;locals:boolean);virtual;
  65. procedure deref;virtual;
  66. procedure derefimpl;virtual;
  67. procedure insert(sym : tsymentry);override;
  68. function speedsearch(const s : stringid;speedvalue : cardinal) : tsymentry;override;
  69. procedure allsymbolsused;
  70. procedure allprivatesused;
  71. procedure allunitsused;
  72. procedure check_forwards;
  73. procedure checklabels;
  74. function needs_init_final : boolean;
  75. {$ifdef CHAINPROCSYMS}
  76. procedure chainprocsyms;
  77. {$endif CHAINPROCSYMS}
  78. procedure chainoperators;
  79. {$ifdef GDB}
  80. procedure concatstabto(asmlist : taasmoutput);virtual;
  81. function getnewtypecount : word; override;
  82. {$endif GDB}
  83. procedure testfordefaultproperty(p : TNamedIndexItem);
  84. end;
  85. tabstractrecordsymtable = class(tstoredsymtable)
  86. public
  87. procedure load(ppufile:tcompilerppufile);override;
  88. procedure write(ppufile:tcompilerppufile);override;
  89. procedure load_references(ppufile:tcompilerppufile;locals:boolean);override;
  90. procedure write_references(ppufile:tcompilerppufile;locals:boolean);override;
  91. end;
  92. trecordsymtable = class(tabstractrecordsymtable)
  93. public
  94. constructor create;
  95. procedure insert_in(tsymt : tsymtable;offset : longint);
  96. end;
  97. tobjectsymtable = class(tabstractrecordsymtable)
  98. public
  99. constructor create(const n:string);
  100. procedure insert(sym : tsymentry);override;
  101. end;
  102. tabstractlocalsymtable = class(tstoredsymtable)
  103. public
  104. procedure load(ppufile:tcompilerppufile);override;
  105. procedure write(ppufile:tcompilerppufile);override;
  106. procedure load_references(ppufile:tcompilerppufile;locals:boolean);override;
  107. procedure write_references(ppufile:tcompilerppufile;locals:boolean);override;
  108. end;
  109. tlocalsymtable = class(tabstractlocalsymtable)
  110. public
  111. constructor create;
  112. procedure insert(sym : tsymentry);override;
  113. end;
  114. tparasymtable = class(tabstractlocalsymtable)
  115. public
  116. constructor create;
  117. procedure insert(sym : tsymentry);override;
  118. { change alignment for args only parasymtable }
  119. procedure set_alignment(_alignment : longint);
  120. end;
  121. tabstractunitsymtable = class(tstoredsymtable)
  122. public
  123. {$ifdef GDB}
  124. dbx_count : longint;
  125. prev_dbx_counter : plongint;
  126. dbx_count_ok : boolean;
  127. is_stab_written : boolean;
  128. {$endif GDB}
  129. constructor create(const n : string);
  130. {$ifdef GDB}
  131. procedure concattypestabto(asmlist : taasmoutput);
  132. {$endif GDB}
  133. end;
  134. tglobalsymtable = class(tabstractunitsymtable)
  135. public
  136. unittypecount : word;
  137. unitsym : tunitsym;
  138. constructor create(const n : string);
  139. destructor destroy;override;
  140. procedure load(ppufile:tcompilerppufile);override;
  141. procedure write(ppufile:tcompilerppufile);override;
  142. procedure insert(sym : tsymentry);override;
  143. {$ifdef GDB}
  144. function getnewtypecount : word; override;
  145. {$endif}
  146. end;
  147. tstaticsymtable = class(tabstractunitsymtable)
  148. public
  149. constructor create(const n : string);
  150. procedure load(ppufile:tcompilerppufile);override;
  151. procedure write(ppufile:tcompilerppufile);override;
  152. procedure load_references(ppufile:tcompilerppufile;locals:boolean);override;
  153. procedure write_references(ppufile:tcompilerppufile;locals:boolean);override;
  154. procedure insert(sym : tsymentry);override;
  155. end;
  156. twithsymtable = class(tsymtable)
  157. direct_with : boolean;
  158. { in fact it is a tnode }
  159. withnode : pointer;
  160. { tnode to load of direct with var }
  161. { already usable before firstwith
  162. needed for firstpass of function parameters PM }
  163. withrefnode : pointer;
  164. constructor create(aowner:tdef;asymsearch:TDictionary);
  165. destructor destroy;override;
  166. procedure clear;override;
  167. function speedsearch(const s : stringid;speedvalue : cardinal) : tsymentry;override;
  168. end;
  169. tstt_exceptsymtable = class(tsymtable)
  170. public
  171. constructor create;
  172. end;
  173. var
  174. constsymtable : tsymtable; { symtable were the constants can be inserted }
  175. systemunit : tglobalsymtable; { pointer to the system unit }
  176. read_member : boolean; { reading members of an symtable }
  177. lexlevel : longint; { level of code }
  178. { 1 for main procedure }
  179. { 2 for normal function or proc }
  180. { higher for locals }
  181. {****************************************************************************
  182. Functions
  183. ****************************************************************************}
  184. {*** Misc ***}
  185. procedure globaldef(const s : string;var t:ttype);
  186. function findunitsymtable(st:tsymtable):tsymtable;
  187. procedure duplicatesym(sym:tsym);
  188. {*** Search ***}
  189. function searchsym(const s : stringid;var srsym:tsym;var srsymtable:tsymtable):boolean;
  190. function searchsymonlyin(p : tsymtable;const s : stringid):tsym;
  191. function search_class_member(pd : tobjectdef;const s : string):tsym;
  192. {*** Object Helpers ***}
  193. function search_default_property(pd : tobjectdef) : tpropertysym;
  194. {*** symtable stack ***}
  195. procedure dellexlevel;
  196. procedure RestoreUnitSyms;
  197. {$ifdef DEBUG}
  198. procedure test_symtablestack;
  199. procedure list_symtablestack;
  200. {$endif DEBUG}
  201. {$ifdef UNITALIASES}
  202. type
  203. punit_alias = ^tunit_alias;
  204. tunit_alias = object(TNamedIndexItem)
  205. newname : pstring;
  206. constructor init(const n:string);
  207. destructor done;virtual;
  208. end;
  209. var
  210. unitaliases : pdictionary;
  211. procedure addunitalias(const n:string);
  212. function getunitalias(const n:string):string;
  213. {$endif UNITALIASES}
  214. {*** Init / Done ***}
  215. procedure InitSymtable;
  216. procedure DoneSymtable;
  217. type
  218. toverloaded_operators = array[NOTOKEN..last_overloaded] of tprocsym;
  219. var
  220. overloaded_operators : toverloaded_operators;
  221. { unequal is not equal}
  222. const
  223. overloaded_names : array [NOTOKEN..last_overloaded] of string[16] =
  224. ('error',
  225. 'plus','minus','star','slash','equal',
  226. 'greater','lower','greater_or_equal',
  227. 'lower_or_equal',
  228. 'sym_diff','starstar',
  229. 'as','is','in','or',
  230. 'and','div','mod','not','shl','shr','xor',
  231. 'assign');
  232. implementation
  233. uses
  234. { global }
  235. version,verbose,globals,
  236. { target }
  237. systems,
  238. { module }
  239. finput,fmodule,
  240. {$ifdef GDB}
  241. gdb,
  242. {$endif GDB}
  243. { codegen }
  244. cgbase
  245. ;
  246. var
  247. in_loading : boolean; { remove !!! }
  248. {*****************************************************************************
  249. TStoredSymtable
  250. *****************************************************************************}
  251. procedure tstoredsymtable.load(ppufile:tcompilerppufile);
  252. begin
  253. { load definitions }
  254. loaddefs(ppufile);
  255. { load symbols }
  256. loadsyms(ppufile);
  257. end;
  258. procedure tstoredsymtable.write(ppufile:tcompilerppufile);
  259. begin
  260. { write definitions }
  261. writedefs(ppufile);
  262. { write symbols }
  263. writesyms(ppufile);
  264. end;
  265. procedure tstoredsymtable.loaddefs(ppufile:tcompilerppufile);
  266. var
  267. hp : tdef;
  268. b : byte;
  269. begin
  270. { load start of definition section, which holds the amount of defs }
  271. if ppufile.readentry<>ibstartdefs then
  272. Message(unit_f_ppu_read_error);
  273. ppufile.getlongint;
  274. { read definitions }
  275. repeat
  276. b:=ppufile.readentry;
  277. case b of
  278. ibpointerdef : hp:=tpointerdef.load(ppufile);
  279. ibarraydef : hp:=tarraydef.load(ppufile);
  280. iborddef : hp:=torddef.load(ppufile);
  281. ibfloatdef : hp:=tfloatdef.load(ppufile);
  282. ibprocdef : hp:=tprocdef.load(ppufile);
  283. ibshortstringdef : hp:=tstringdef.loadshort(ppufile);
  284. iblongstringdef : hp:=tstringdef.loadlong(ppufile);
  285. ibansistringdef : hp:=tstringdef.loadansi(ppufile);
  286. ibwidestringdef : hp:=tstringdef.loadwide(ppufile);
  287. ibrecorddef : hp:=trecorddef.load(ppufile);
  288. ibobjectdef : hp:=tobjectdef.load(ppufile);
  289. ibenumdef : hp:=tenumdef.load(ppufile);
  290. ibsetdef : hp:=tsetdef.load(ppufile);
  291. ibprocvardef : hp:=tprocvardef.load(ppufile);
  292. ibfiledef : hp:=tfiledef.load(ppufile);
  293. ibclassrefdef : hp:=tclassrefdef.load(ppufile);
  294. ibformaldef : hp:=tformaldef.load(ppufile);
  295. ibvariantdef : hp:=tvariantdef.load(ppufile);
  296. ibenddefs : break;
  297. ibend : Message(unit_f_ppu_read_error);
  298. else
  299. Message1(unit_f_ppu_invalid_entry,tostr(b));
  300. end;
  301. hp.owner:=self;
  302. defindex.insert(hp);
  303. until false;
  304. end;
  305. procedure tstoredsymtable.loadsyms(ppufile:tcompilerppufile);
  306. var
  307. b : byte;
  308. sym : tsym;
  309. begin
  310. { load start of definition section, which holds the amount of defs }
  311. if ppufile.readentry<>ibstartsyms then
  312. Message(unit_f_ppu_read_error);
  313. { skip amount of symbols, not used currently }
  314. ppufile.getlongint;
  315. { load datasize,dataalignment of this symboltable }
  316. datasize:=ppufile.getlongint;
  317. dataalignment:=ppufile.getlongint;
  318. { now read the symbols }
  319. repeat
  320. b:=ppufile.readentry;
  321. case b of
  322. ibtypesym : sym:=ttypesym.load(ppufile);
  323. ibprocsym : sym:=tprocsym.load(ppufile);
  324. ibconstsym : sym:=tconstsym.load(ppufile);
  325. ibvarsym : sym:=tvarsym.load(ppufile);
  326. ibfuncretsym : sym:=tfuncretsym.load(ppufile);
  327. ibabsolutesym : sym:=tabsolutesym.load(ppufile);
  328. ibenumsym : sym:=tenumsym.load(ppufile);
  329. ibtypedconstsym : sym:=ttypedconstsym.load(ppufile);
  330. ibpropertysym : sym:=tpropertysym.load(ppufile);
  331. ibunitsym : sym:=tunitsym.load(ppufile);
  332. iblabelsym : sym:=tlabelsym.load(ppufile);
  333. ibsyssym : sym:=tsyssym.load(ppufile);
  334. ibrttisym : sym:=trttisym.load(ppufile);
  335. ibendsyms : break;
  336. ibend : Message(unit_f_ppu_read_error);
  337. else
  338. Message1(unit_f_ppu_invalid_entry,tostr(b));
  339. end;
  340. sym.owner:=self;
  341. symindex.insert(sym);
  342. symsearch.insert(sym);
  343. until false;
  344. end;
  345. procedure tstoredsymtable.writedefs(ppufile:tcompilerppufile);
  346. var
  347. pd : tstoreddef;
  348. begin
  349. { each definition get a number, write then the amount of defs to the
  350. ibstartdef entry }
  351. ppufile.putlongint(defindex.count);
  352. ppufile.writeentry(ibstartdefs);
  353. { now write the definition }
  354. pd:=tstoreddef(defindex.first);
  355. while assigned(pd) do
  356. begin
  357. pd.write(ppufile);
  358. pd:=tstoreddef(pd.indexnext);
  359. end;
  360. { write end of definitions }
  361. ppufile.writeentry(ibenddefs);
  362. end;
  363. procedure tstoredsymtable.writesyms(ppufile:tcompilerppufile);
  364. var
  365. pd : tstoredsym;
  366. begin
  367. { each definition get a number, write then the amount of syms and the
  368. datasize to the ibsymdef entry }
  369. ppufile.putlongint(symindex.count);
  370. ppufile.putlongint(datasize);
  371. ppufile.putlongint(dataalignment);
  372. ppufile.writeentry(ibstartsyms);
  373. { foreach is used to write all symbols }
  374. pd:=tstoredsym(symindex.first);
  375. while assigned(pd) do
  376. begin
  377. pd.write(ppufile);
  378. pd:=tstoredsym(pd.indexnext);
  379. end;
  380. { end of symbols }
  381. ppufile.writeentry(ibendsyms);
  382. end;
  383. procedure tstoredsymtable.load_references(ppufile:tcompilerppufile;locals:boolean);
  384. var
  385. b : byte;
  386. sym : tstoredsym;
  387. prdef : tstoreddef;
  388. begin
  389. b:=ppufile.readentry;
  390. if b <> ibbeginsymtablebrowser then
  391. Message1(unit_f_ppu_invalid_entry,tostr(b));
  392. repeat
  393. b:=ppufile.readentry;
  394. case b of
  395. ibsymref :
  396. begin
  397. sym:=tstoredsym(ppufile.getderef);
  398. resolvesym(tsym(sym));
  399. if assigned(sym) then
  400. sym.load_references(ppufile,locals);
  401. end;
  402. ibdefref :
  403. begin
  404. prdef:=tstoreddef(ppufile.getderef);
  405. resolvedef(tdef(prdef));
  406. if assigned(prdef) then
  407. begin
  408. if prdef.deftype<>procdef then
  409. Message(unit_f_ppu_read_error);
  410. tprocdef(prdef).load_references(ppufile,locals);
  411. end;
  412. end;
  413. ibendsymtablebrowser :
  414. break;
  415. else
  416. Message1(unit_f_ppu_invalid_entry,tostr(b));
  417. end;
  418. until false;
  419. end;
  420. procedure tstoredsymtable.write_references(ppufile:tcompilerppufile;locals:boolean);
  421. var
  422. pd : tstoredsym;
  423. begin
  424. ppufile.writeentry(ibbeginsymtablebrowser);
  425. { write all symbols }
  426. pd:=tstoredsym(symindex.first);
  427. while assigned(pd) do
  428. begin
  429. pd.write_references(ppufile,locals);
  430. pd:=tstoredsym(pd.indexnext);
  431. end;
  432. ppufile.writeentry(ibendsymtablebrowser);
  433. end;
  434. procedure tstoredsymtable.deref;
  435. var
  436. hp : tdef;
  437. hs : tsym;
  438. begin
  439. { deref the interface definitions }
  440. hp:=tdef(defindex.first);
  441. while assigned(hp) do
  442. begin
  443. hp.deref;
  444. hp:=tdef(hp.indexnext);
  445. end;
  446. { first deref the interface ttype symbols }
  447. hs:=tsym(symindex.first);
  448. while assigned(hs) do
  449. begin
  450. if hs.typ=typesym then
  451. hs.deref;
  452. hs:=tsym(hs.indexnext);
  453. end;
  454. { deref the interface symbols }
  455. hs:=tsym(symindex.first);
  456. while assigned(hs) do
  457. begin
  458. if hs.typ<>typesym then
  459. hs.deref;
  460. hs:=tsym(hs.indexnext);
  461. end;
  462. end;
  463. procedure tstoredsymtable.derefimpl;
  464. var
  465. hp : tdef;
  466. begin
  467. { deref the implementation part of definitions }
  468. hp:=tdef(defindex.first);
  469. while assigned(hp) do
  470. begin
  471. hp.derefimpl;
  472. hp:=tdef(hp.indexnext);
  473. end;
  474. end;
  475. procedure tstoredsymtable.insert(sym:tsymentry);
  476. var
  477. hsym : tsym;
  478. begin
  479. { set owner and sym indexnb }
  480. sym.owner:=self;
  481. {$ifdef CHAINPROCSYMS}
  482. { set the nextprocsym field }
  483. if sym.typ=procsym then
  484. chainprocsym(sym);
  485. {$endif CHAINPROCSYMS}
  486. { writes the symbol in data segment if required }
  487. { also sets the datasize of owner }
  488. if not in_loading then
  489. tstoredsym(sym).insert_in_data;
  490. { check the current symtable }
  491. hsym:=tsym(search(sym.name));
  492. if assigned(hsym) then
  493. begin
  494. { in TP and Delphi you can have a local with the
  495. same name as the function, the function is then hidden for
  496. the user. (Under delphi it can still be accessed using result),
  497. but don't allow hiding of RESULT }
  498. if (m_tp in aktmodeswitches) and
  499. (hsym.typ=funcretsym) and
  500. not((m_result in aktmodeswitches) and
  501. (hsym.name='RESULT')) then
  502. hsym.owner.rename(hsym.name,'hidden'+hsym.name)
  503. else
  504. begin
  505. DuplicateSym(hsym);
  506. exit;
  507. end;
  508. end;
  509. { register definition of typesym }
  510. if (sym.typ = typesym) and
  511. assigned(ttypesym(sym).restype.def) then
  512. begin
  513. if not(assigned(ttypesym(sym).restype.def.owner)) and
  514. (ttypesym(sym).restype.def.deftype<>errordef) then
  515. registerdef(ttypesym(sym).restype.def);
  516. {$ifdef GDB}
  517. if (cs_debuginfo in aktmoduleswitches) and assigned(debuglist) and
  518. (symtabletype in [globalsymtable,staticsymtable]) then
  519. begin
  520. ttypesym(sym).isusedinstab := true;
  521. {sym.concatstabto(debuglist);}
  522. end;
  523. {$endif GDB}
  524. end;
  525. { insert in index and search hash }
  526. symindex.insert(sym);
  527. symsearch.insert(sym);
  528. end;
  529. function tstoredsymtable.speedsearch(const s : stringid;speedvalue : cardinal) : tsymentry;
  530. var
  531. hp : tstoredsym;
  532. newref : tref;
  533. begin
  534. hp:=tstoredsym(inherited speedsearch(s,speedvalue));
  535. if assigned(hp) then
  536. begin
  537. { reject non static members in static procedures,
  538. be carefull aktprocsym.definition is not allways
  539. loaded already (PFV) }
  540. if (symtabletype=objectsymtable) and
  541. not(sp_static in hp.symoptions) and
  542. allow_only_static
  543. {assigned(aktprocsym) and
  544. assigned(aktprocsym.definition) and
  545. ((aktprocsym.definition.options and postaticmethod)<>0)} then
  546. Message(sym_e_only_static_in_static);
  547. if (unitid<>0) and
  548. assigned(tglobalsymtable(self).unitsym) then
  549. inc(tglobalsymtable(self).unitsym.refs);
  550. {$ifdef GDB}
  551. { if it is a type, we need the stabs of this type
  552. this might be the cause of the class debug problems
  553. as TCHILDCLASS.Create did not generate appropriate
  554. stabs debug info if TCHILDCLASS wasn't used anywhere else PM }
  555. if (hp.typ=typesym) and make_ref then
  556. begin
  557. if assigned(ttypesym(hp).restype.def) then
  558. tstoreddef(ttypesym(hp).restype.def).numberstring
  559. else
  560. ttypesym(hp).isusedinstab:=true;
  561. end;
  562. {$endif GDB}
  563. { unitsym are only loaded for browsing PM }
  564. { this was buggy anyway because we could use }
  565. { unitsyms from other units in _USES !! }
  566. {if (symtabletype=unitsymtable) and (hp.typ=unitsym) and
  567. assigned(current_module) and (current_module.globalsymtable<>.load) then
  568. hp:=nil;}
  569. if assigned(hp) and
  570. (cs_browser in aktmoduleswitches) and make_ref then
  571. begin
  572. newref:=tref.create(hp.lastref,@akttokenpos);
  573. { for symbols that are in tables without
  574. browser info or syssyms (PM) }
  575. if hp.refcount=0 then
  576. begin
  577. hp.defref:=newref;
  578. hp.lastref:=newref;
  579. end
  580. else
  581. if resolving_forward and assigned(hp.defref) then
  582. { put it as second reference }
  583. begin
  584. newref.nextref:=hp.defref.nextref;
  585. hp.defref.nextref:=newref;
  586. hp.lastref.nextref:=nil;
  587. end
  588. else
  589. hp.lastref:=newref;
  590. inc(hp.refcount);
  591. end;
  592. if assigned(hp) and make_ref then
  593. begin
  594. inc(hp.refs);
  595. end;
  596. end;
  597. speedsearch:=hp;
  598. end;
  599. {**************************************
  600. Callbacks
  601. **************************************}
  602. procedure TStoredSymtable.check_forward(sym : TNamedIndexItem);
  603. begin
  604. if tsym(sym).typ=procsym then
  605. tprocsym(sym).check_forward
  606. { check also object method table }
  607. { we needn't to test the def list }
  608. { because each object has to have a type sym }
  609. else
  610. if (tsym(sym).typ=typesym) and
  611. assigned(ttypesym(sym).restype.def) and
  612. (ttypesym(sym).restype.def.deftype=objectdef) then
  613. tobjectdef(ttypesym(sym).restype.def).check_forwards;
  614. end;
  615. procedure TStoredSymtable.labeldefined(p : TNamedIndexItem);
  616. begin
  617. if (tsym(p).typ=labelsym) and
  618. not(tlabelsym(p).defined) then
  619. begin
  620. if tlabelsym(p).used then
  621. Message1(sym_e_label_used_and_not_defined,tlabelsym(p).realname)
  622. else
  623. Message1(sym_w_label_not_defined,tlabelsym(p).realname);
  624. end;
  625. end;
  626. procedure TStoredSymtable.unitsymbolused(p : TNamedIndexItem);
  627. begin
  628. if (tsym(p).typ=unitsym) and
  629. (tunitsym(p).refs=0) and
  630. { do not claim for unit name itself !! }
  631. (tunitsym(p).unitsymtable.symtabletype=globalsymtable) then
  632. MessagePos2(tsym(p).fileinfo,sym_n_unit_not_used,
  633. p.name,current_module.modulename^);
  634. end;
  635. procedure TStoredSymtable.varsymbolused(p : TNamedIndexItem);
  636. begin
  637. if (tsym(p).typ=varsym) and
  638. ((tsym(p).owner.symtabletype in
  639. [parasymtable,localsymtable,objectsymtable,staticsymtable])) then
  640. begin
  641. { unused symbol should be reported only if no }
  642. { error is reported }
  643. { if the symbol is in a register it is used }
  644. { also don't count the value parameters which have local copies }
  645. { also don't claim for high param of open parameters (PM) }
  646. if (Errorcount<>0) or
  647. (copy(p.name,1,3)='val') or
  648. (copy(p.name,1,4)='high') then
  649. exit;
  650. if (tvarsym(p).refs=0) then
  651. begin
  652. if (tsym(p).owner.symtabletype=parasymtable) or (vo_is_local_copy in tvarsym(p).varoptions) then
  653. begin
  654. MessagePos1(tsym(p).fileinfo,sym_h_para_identifier_not_used,tsym(p).realname);
  655. end
  656. else if (tsym(p).owner.symtabletype=objectsymtable) then
  657. MessagePos2(tsym(p).fileinfo,sym_n_private_identifier_not_used,tsym(p).owner.name^,tsym(p).realname)
  658. else
  659. MessagePos1(tsym(p).fileinfo,sym_n_local_identifier_not_used,tsym(p).realname);
  660. end
  661. else if tvarsym(p).varstate=vs_assigned then
  662. begin
  663. if (tsym(p).owner.symtabletype=parasymtable) then
  664. begin
  665. if not(tvarsym(p).varspez in [vs_var,vs_out]) then
  666. MessagePos1(tsym(p).fileinfo,sym_h_para_identifier_only_set,tsym(p).realname)
  667. end
  668. else if (vo_is_local_copy in tvarsym(p).varoptions) then
  669. begin
  670. if not(tvarsym(p).varspez in [vs_var,vs_out]) then
  671. MessagePos1(tsym(p).fileinfo,sym_h_para_identifier_only_set,tsym(p).realname);
  672. end
  673. else if (tsym(p).owner.symtabletype=objectsymtable) then
  674. MessagePos2(tsym(p).fileinfo,sym_n_private_identifier_only_set,tsym(p).owner.name^,tsym(p).realname)
  675. else if (tsym(p).owner.symtabletype<>parasymtable) then
  676. if not (vo_is_exported in tvarsym(p).varoptions) then
  677. MessagePos1(tsym(p).fileinfo,sym_n_local_identifier_only_set,tsym(p).realname);
  678. end;
  679. end
  680. else if ((tsym(p).owner.symtabletype in
  681. [objectsymtable,parasymtable,localsymtable,staticsymtable])) then
  682. begin
  683. if (Errorcount<>0) then
  684. exit;
  685. { do not claim for inherited private fields !! }
  686. if (tstoredsym(p).refs=0) and (tsym(p).owner.symtabletype=objectsymtable) then
  687. MessagePos2(tsym(p).fileinfo,sym_n_private_method_not_used,tsym(p).owner.name^,tsym(p).realname)
  688. { units references are problematic }
  689. else if (tstoredsym(p).refs=0) and not(tsym(p).typ in [funcretsym,enumsym,unitsym]) then
  690. if (tsym(p).typ<>procsym) or not (tprocsym(p).is_global) or
  691. { all program functions are declared global
  692. but unused should still be signaled PM }
  693. ((tsym(p).owner.symtabletype=staticsymtable) and
  694. not current_module.is_unit) then
  695. MessagePos2(tsym(p).fileinfo,sym_h_local_symbol_not_used,SymTypeName[tsym(p).typ],tsym(p).realname);
  696. end;
  697. end;
  698. procedure TStoredSymtable.TestPrivate(p : TNamedIndexItem);
  699. begin
  700. if sp_private in tsym(p).symoptions then
  701. varsymbolused(p);
  702. end;
  703. procedure TStoredSymtable.objectprivatesymbolused(p : TNamedIndexItem);
  704. begin
  705. {
  706. Don't test simple object aliases PM
  707. }
  708. if (tsym(p).typ=typesym) and
  709. (ttypesym(p).restype.def.deftype=objectdef) and
  710. (ttypesym(p).restype.def.typesym=tsym(p)) then
  711. tobjectdef(ttypesym(p).restype.def).symtable.foreach({$ifdef FPCPROCVAR}@{$endif}TestPrivate);
  712. end;
  713. procedure tstoredsymtable.order_overloads(p : TNamedIndexItem);
  714. begin
  715. if tsym(p).typ=procsym then
  716. tprocsym(p).order_overloaded;
  717. end;
  718. {$ifdef GDB}
  719. procedure TStoredSymtable.concatstab(p : TNamedIndexItem);
  720. begin
  721. if tsym(p).typ <> procsym then
  722. tstoredsym(p).concatstabto(asmoutput);
  723. end;
  724. procedure TStoredSymtable.resetstab(p : TNamedIndexItem);
  725. begin
  726. if tsym(p).typ <> procsym then
  727. tstoredsym(p).isstabwritten:=false;
  728. end;
  729. procedure TStoredSymtable.concattypestab(p : TNamedIndexItem);
  730. begin
  731. if tsym(p).typ = typesym then
  732. begin
  733. tstoredsym(p).isstabwritten:=false;
  734. tstoredsym(p).concatstabto(asmoutput);
  735. end;
  736. end;
  737. function tstoredsymtable.getnewtypecount : word;
  738. begin
  739. getnewtypecount:=pglobaltypecount^;
  740. inc(pglobaltypecount^);
  741. end;
  742. {$endif GDB}
  743. {$ifdef CHAINPROCSYMS}
  744. procedure chainprocsym(p : tsym);
  745. var
  746. storesymtablestack : tsymtable;
  747. srsym : tsym;
  748. srsymtable : tsymtable;
  749. begin
  750. if p.typ=procsym then
  751. begin
  752. storesymtablestack:=symtablestack;
  753. symtablestack:=p.owner.next;
  754. while assigned(symtablestack) do
  755. begin
  756. { search for same procsym in other units }
  757. searchsym(p.name,srsym,srsymtable)
  758. if assigned(srsym) and
  759. (srsym.typ=procsym) then
  760. begin
  761. tprocsym(p).nextprocsym:=tprocsym(srsym);
  762. symtablestack:=storesymtablestack;
  763. exit;
  764. end
  765. else if srsym=nil then
  766. symtablestack:=nil
  767. else
  768. symtablestack:=srsymtable.next;
  769. end;
  770. symtablestack:=storesymtablestack;
  771. end;
  772. end;
  773. {$endif}
  774. procedure tstoredsymtable.chainoperators;
  775. var
  776. p : tprocsym;
  777. t : ttoken;
  778. def : tprocdef;
  779. srsym : tsym;
  780. srsymtable,
  781. storesymtablestack : tsymtable;
  782. begin
  783. storesymtablestack:=symtablestack;
  784. symtablestack:=self;
  785. make_ref:=false;
  786. for t:=first_overloaded to last_overloaded do
  787. begin
  788. p:=nil;
  789. def:=nil;
  790. overloaded_operators[t]:=nil;
  791. { each operator has a unique lowercased internal name PM }
  792. while assigned(symtablestack) do
  793. begin
  794. searchsym(overloaded_names[t],srsym,srsymtable);
  795. if not assigned(srsym) then
  796. begin
  797. if (t=_STARSTAR) then
  798. begin
  799. symtablestack:=systemunit;
  800. searchsym('POWER',srsym,srsymtable);
  801. end;
  802. end;
  803. if assigned(srsym) then
  804. begin
  805. if (srsym.typ<>procsym) then
  806. internalerror(12344321);
  807. if assigned(p) then
  808. begin
  809. {$ifdef CHAINPROCSYMS}
  810. p.nextprocsym:=tprocsym(srsym);
  811. {$endif CHAINPROCSYMS}
  812. def.nextoverloaded:=tprocsym(srsym).definition;
  813. end
  814. else
  815. overloaded_operators[t]:=tprocsym(srsym);
  816. p:=tprocsym(srsym);
  817. def:=p.definition;
  818. while assigned(def.nextoverloaded) and
  819. (def.nextoverloaded.owner=p.owner) do
  820. def:=def.nextoverloaded;
  821. def.nextoverloaded:=nil;
  822. symtablestack:=srsym.owner.next;
  823. end
  824. else
  825. begin
  826. symtablestack:=nil;
  827. {$ifdef CHAINPROCSYMS}
  828. if assigned(p) then
  829. p.nextprocsym:=nil;
  830. {$endif CHAINPROCSYMS}
  831. end;
  832. { search for same procsym in other units }
  833. end;
  834. symtablestack:=self;
  835. end;
  836. make_ref:=true;
  837. symtablestack:=storesymtablestack;
  838. end;
  839. {***********************************************
  840. Process all entries
  841. ***********************************************}
  842. { checks, if all procsyms and methods are defined }
  843. procedure tstoredsymtable.check_forwards;
  844. begin
  845. foreach({$ifdef FPCPROCVAR}@{$endif}check_forward);
  846. end;
  847. procedure tstoredsymtable.checklabels;
  848. begin
  849. foreach({$ifdef FPCPROCVAR}@{$endif}labeldefined);
  850. end;
  851. procedure tstoredsymtable.allunitsused;
  852. begin
  853. foreach({$ifdef FPCPROCVAR}@{$endif}unitsymbolused);
  854. end;
  855. procedure tstoredsymtable.allsymbolsused;
  856. begin
  857. foreach({$ifdef FPCPROCVAR}@{$endif}varsymbolused);
  858. end;
  859. procedure tstoredsymtable.allprivatesused;
  860. begin
  861. foreach({$ifdef FPCPROCVAR}@{$endif}objectprivatesymbolused);
  862. end;
  863. {$ifdef CHAINPROCSYMS}
  864. procedure tstoredsymtable.chainprocsyms;
  865. begin
  866. foreach({$ifdef FPCPROCVAR}@{$endif}chainprocsym);
  867. end;
  868. {$endif CHAINPROCSYMS}
  869. {$ifdef GDB}
  870. procedure tstoredsymtable.concatstabto(asmlist : taasmoutput);
  871. begin
  872. asmoutput:=asmlist;
  873. if symtabletype in [inlineparasymtable,inlinelocalsymtable] then
  874. foreach({$ifdef FPCPROCVAR}@{$endif}resetstab);
  875. foreach({$ifdef FPCPROCVAR}@{$endif}concatstab);
  876. end;
  877. {$endif}
  878. { returns true, if p contains data which needs init/final code }
  879. function tstoredsymtable.needs_init_final : boolean;
  880. begin
  881. b_needs_init_final:=false;
  882. foreach({$ifdef FPCPROCVAR}@{$endif}_needs_init_final);
  883. needs_init_final:=b_needs_init_final;
  884. end;
  885. {****************************************************************************
  886. TAbstractRecordSymtable
  887. ****************************************************************************}
  888. procedure tabstractrecordsymtable.load(ppufile:tcompilerppufile);
  889. var
  890. storesymtable : tsymtable;
  891. begin
  892. storesymtable:=aktrecordsymtable;
  893. aktrecordsymtable:=self;
  894. inherited load(ppufile);
  895. aktrecordsymtable:=storesymtable;
  896. end;
  897. procedure tabstractrecordsymtable.write(ppufile:tcompilerppufile);
  898. var
  899. oldtyp : byte;
  900. storesymtable : tsymtable;
  901. begin
  902. storesymtable:=aktrecordsymtable;
  903. aktrecordsymtable:=self;
  904. oldtyp:=ppufile.entrytyp;
  905. ppufile.entrytyp:=subentryid;
  906. { order procsym overloads }
  907. foreach({$ifdef FPCPROCVAR}@{$endif}Order_overloads);
  908. inherited write(ppufile);
  909. ppufile.entrytyp:=oldtyp;
  910. aktrecordsymtable:=storesymtable;
  911. end;
  912. procedure tabstractrecordsymtable.load_references(ppufile:tcompilerppufile;locals:boolean);
  913. var
  914. storesymtable : tsymtable;
  915. begin
  916. storesymtable:=aktrecordsymtable;
  917. aktrecordsymtable:=self;
  918. inherited load_references(ppufile,locals);
  919. aktrecordsymtable:=storesymtable;
  920. end;
  921. procedure tabstractrecordsymtable.write_references(ppufile:tcompilerppufile;locals:boolean);
  922. var
  923. storesymtable : tsymtable;
  924. begin
  925. storesymtable:=aktrecordsymtable;
  926. aktrecordsymtable:=self;
  927. inherited write_references(ppufile,locals);
  928. aktrecordsymtable:=storesymtable;
  929. end;
  930. procedure TStoredSymtable._needs_init_final(p : tnamedindexitem);
  931. begin
  932. if (not b_needs_init_final) and
  933. (tsym(p).typ=varsym) and
  934. assigned(tvarsym(p).vartype.def) and
  935. not is_class(tvarsym(p).vartype.def) and
  936. tstoreddef(tvarsym(p).vartype.def).needs_inittable then
  937. b_needs_init_final:=true;
  938. end;
  939. {****************************************************************************
  940. TRecordSymtable
  941. ****************************************************************************}
  942. constructor trecordsymtable.create;
  943. begin
  944. inherited create('');
  945. symtabletype:=recordsymtable;
  946. end;
  947. { this procedure is reserved for inserting case variant into
  948. a record symtable }
  949. { the offset is the location of the start of the variant
  950. and datasize and dataalignment corresponds to
  951. the complete size (see code in pdecl unit) PM }
  952. procedure trecordsymtable.insert_in(tsymt : tsymtable;offset : longint);
  953. var
  954. ps,nps : tvarsym;
  955. pd,npd : tdef;
  956. storesize,storealign : longint;
  957. begin
  958. storesize:=tsymt.datasize;
  959. storealign:=tsymt.dataalignment;
  960. tsymt.datasize:=offset;
  961. ps:=tvarsym(symindex.first);
  962. while assigned(ps) do
  963. begin
  964. { this is used to insert case variant into the main
  965. record }
  966. tsymt.datasize:=ps.address+offset;
  967. nps:=tvarsym(ps.indexnext);
  968. symindex.deleteindex(ps);
  969. ps.left:=nil;
  970. ps.right:=nil;
  971. tsymt.insert(ps);
  972. ps:=nps;
  973. end;
  974. pd:=tdef(defindex.first);
  975. while assigned(pd) do
  976. begin
  977. npd:=tdef(pd.indexnext);
  978. defindex.deleteindex(pd);
  979. pd.left:=nil;
  980. pd.right:=nil;
  981. tsymt.registerdef(pd);
  982. pd:=npd;
  983. end;
  984. tsymt.datasize:=storesize;
  985. tsymt.dataalignment:=storealign;
  986. end;
  987. {****************************************************************************
  988. TObjectSymtable
  989. ****************************************************************************}
  990. constructor tobjectsymtable.create(const n:string);
  991. begin
  992. inherited create(n);
  993. symtabletype:=objectsymtable;
  994. end;
  995. procedure tobjectsymtable.insert(sym:tsymentry);
  996. var
  997. hsym : tsym;
  998. begin
  999. { check for duplicate field id in inherited classes }
  1000. if (sym.typ=varsym) and
  1001. assigned(defowner) and
  1002. (
  1003. not(m_delphi in aktmodeswitches) or
  1004. is_object(tdef(defowner))
  1005. ) then
  1006. begin
  1007. { but private ids can be reused }
  1008. hsym:=search_class_member(tobjectdef(defowner),sym.name);
  1009. if assigned(hsym) and
  1010. (not(sp_private in hsym.symoptions) or
  1011. (hsym.owner.defowner.owner.unitid=0)) then
  1012. begin
  1013. DuplicateSym(hsym);
  1014. exit;
  1015. end;
  1016. end;
  1017. inherited insert(sym);
  1018. end;
  1019. {****************************************************************************
  1020. TAbstractLocalSymtable
  1021. ****************************************************************************}
  1022. procedure tabstractlocalsymtable.load(ppufile:tcompilerppufile);
  1023. var
  1024. storesymtable : tsymtable;
  1025. begin
  1026. storesymtable:=aktlocalsymtable;
  1027. aktlocalsymtable:=self;
  1028. inherited load(ppufile);
  1029. aktlocalsymtable:=storesymtable;
  1030. end;
  1031. procedure tabstractlocalsymtable.write(ppufile:tcompilerppufile);
  1032. var
  1033. oldtyp : byte;
  1034. storesymtable : tsymtable;
  1035. begin
  1036. storesymtable:=aktlocalsymtable;
  1037. aktlocalsymtable:=self;
  1038. oldtyp:=ppufile.entrytyp;
  1039. ppufile.entrytyp:=subentryid;
  1040. { order procsym overloads }
  1041. foreach({$ifdef FPCPROCVAR}@{$endif}Order_overloads);
  1042. { write definitions }
  1043. writedefs(ppufile);
  1044. { write symbols }
  1045. writesyms(ppufile);
  1046. ppufile.entrytyp:=oldtyp;
  1047. aktlocalsymtable:=storesymtable;
  1048. end;
  1049. procedure tabstractlocalsymtable.load_references(ppufile:tcompilerppufile;locals:boolean);
  1050. var
  1051. storesymtable : tsymtable;
  1052. begin
  1053. storesymtable:=aktlocalsymtable;
  1054. aktlocalsymtable:=self;
  1055. inherited load_references(ppufile,locals);
  1056. aktlocalsymtable:=storesymtable;
  1057. end;
  1058. procedure tabstractlocalsymtable.write_references(ppufile:tcompilerppufile;locals:boolean);
  1059. var
  1060. storesymtable : tsymtable;
  1061. begin
  1062. storesymtable:=aktlocalsymtable;
  1063. aktlocalsymtable:=self;
  1064. inherited write_references(ppufile,locals);
  1065. aktlocalsymtable:=storesymtable;
  1066. end;
  1067. {****************************************************************************
  1068. TLocalSymtable
  1069. ****************************************************************************}
  1070. constructor tlocalsymtable.create;
  1071. begin
  1072. inherited create('');
  1073. symtabletype:=localsymtable;
  1074. end;
  1075. procedure tlocalsymtable.insert(sym:tsymentry);
  1076. var
  1077. hsym : tsym;
  1078. begin
  1079. if assigned(next) then
  1080. begin
  1081. if (next.symtabletype=parasymtable) then
  1082. begin
  1083. hsym:=tsym(next.search(sym.name));
  1084. if assigned(hsym) then
  1085. begin
  1086. { a parameter and the function can have the same
  1087. name in TP and Delphi, but RESULT not }
  1088. if (m_tp in aktmodeswitches) and
  1089. (sym.typ=funcretsym) and
  1090. not((m_result in aktmodeswitches) and
  1091. (sym.name='RESULT')) then
  1092. sym.name:='hidden'+sym.name
  1093. else
  1094. begin
  1095. DuplicateSym(hsym);
  1096. exit;
  1097. end;
  1098. end;
  1099. end;
  1100. { check for duplicate id in local symtable of methods }
  1101. if assigned(next.next) and
  1102. { funcretsym is allowed !! }
  1103. (sym.typ <> funcretsym) and
  1104. (next.next.symtabletype=objectsymtable) then
  1105. begin
  1106. hsym:=search_class_member(tobjectdef(next.next.defowner),sym.name);
  1107. if assigned(hsym) and
  1108. { private ids can be reused }
  1109. (not(sp_private in hsym.symoptions) or
  1110. (hsym.owner.defowner.owner.symtabletype<>globalsymtable)) then
  1111. begin
  1112. { delphi allows to reuse the names in a class, but not
  1113. in object (tp7 compatible) }
  1114. if not((m_delphi in aktmodeswitches) and
  1115. is_class(tdef(next.next.defowner))) then
  1116. begin
  1117. DuplicateSym(hsym);
  1118. exit;
  1119. end;
  1120. end;
  1121. end;
  1122. end;
  1123. inherited insert(sym);
  1124. end;
  1125. {****************************************************************************
  1126. TParaSymtable
  1127. ****************************************************************************}
  1128. constructor tparasymtable.create;
  1129. begin
  1130. inherited create('');
  1131. symtabletype:=parasymtable;
  1132. dataalignment:=aktalignment.paraalign;
  1133. end;
  1134. procedure tparasymtable.insert(sym:tsymentry);
  1135. var
  1136. hsym : tsym;
  1137. begin
  1138. { check for duplicate id in para symtable of methods }
  1139. if assigned(procinfo^._class) and
  1140. { but not in nested procedures !}
  1141. (not(assigned(procinfo^.parent)) or
  1142. (assigned(procinfo^.parent) and
  1143. not(assigned(procinfo^.parent^._class)))
  1144. ) and
  1145. { funcretsym is allowed !! }
  1146. (sym.typ <> funcretsym) then
  1147. begin
  1148. hsym:=search_class_member(procinfo^._class,sym.name);
  1149. if assigned(hsym) and
  1150. { private ids can be reused }
  1151. (not(sp_private in hsym.symoptions) or
  1152. (hsym.owner.defowner.owner.unitid=0)) then
  1153. begin
  1154. { delphi allows to reuse the names in a class, but not
  1155. in object (tp7 compatible) }
  1156. if not((m_delphi in aktmodeswitches) and
  1157. is_class(procinfo^._class)) then
  1158. begin
  1159. DuplicateSym(hsym);
  1160. exit;
  1161. end;
  1162. end;
  1163. end;
  1164. inherited insert(sym);
  1165. end;
  1166. procedure tparasymtable.set_alignment(_alignment : longint);
  1167. var
  1168. sym : tvarsym;
  1169. l : longint;
  1170. begin
  1171. dataalignment:=_alignment;
  1172. sym:=tvarsym(symindex.first);
  1173. datasize:=0;
  1174. { there can be only varsyms }
  1175. while assigned(sym) do
  1176. begin
  1177. l:=sym.getpushsize;
  1178. sym.address:=datasize;
  1179. datasize:=align(datasize+l,dataalignment);
  1180. sym:=tvarsym(sym.indexnext);
  1181. end;
  1182. end;
  1183. {****************************************************************************
  1184. TAbstractUnitSymtable
  1185. ****************************************************************************}
  1186. constructor tabstractunitsymtable.create(const n : string);
  1187. begin
  1188. inherited create(n);
  1189. symsearch.usehash;
  1190. {$ifdef GDB}
  1191. { reset GDB things }
  1192. prev_dbx_counter := dbx_counter;
  1193. dbx_counter := nil;
  1194. is_stab_written:=false;
  1195. dbx_count := -1;
  1196. {$endif GDB}
  1197. end;
  1198. {$ifdef GDB}
  1199. procedure tabstractunitsymtable.concattypestabto(asmlist : taasmoutput);
  1200. var prev_dbx_count : plongint;
  1201. begin
  1202. if is_stab_written then
  1203. exit;
  1204. if not assigned(name) then
  1205. name := stringdup('Main_program');
  1206. if (symtabletype = globalsymtable) and
  1207. (current_module.globalsymtable<>self) then
  1208. begin
  1209. unitid:=current_module.unitcount;
  1210. inc(current_module.unitcount);
  1211. end;
  1212. asmList.concat(Tai_asm_comment.Create(strpnew('Begin unit '+name^+' has index '+tostr(unitid))));
  1213. if cs_gdb_dbx in aktglobalswitches then
  1214. begin
  1215. if dbx_count_ok then
  1216. begin
  1217. asmList.concat(Tai_asm_comment.Create(strpnew('"repeated" unit '+name^
  1218. +' has index '+tostr(unitid)+' dbx count = '+tostr(dbx_count))));
  1219. asmList.concat(Tai_stabs.Create(strpnew('"'+name^+'",'
  1220. +tostr(N_EXCL)+',0,0,'+tostr(dbx_count))));
  1221. exit;
  1222. end
  1223. else if (current_module.globalsymtable<>self) then
  1224. begin
  1225. prev_dbx_count := dbx_counter;
  1226. dbx_counter := nil;
  1227. do_count_dbx:=false;
  1228. if (symtabletype = globalsymtable) and (unitid<>0) then
  1229. asmList.concat(Tai_stabs.Create(strpnew('"'+name^+'",'+tostr(N_BINCL)+',0,0,0')));
  1230. dbx_counter := @dbx_count;
  1231. dbx_count:=0;
  1232. do_count_dbx:=assigned(dbx_counter);
  1233. end;
  1234. end;
  1235. asmoutput:=asmlist;
  1236. foreach({$ifdef FPCPROCVAR}@{$endif}concattypestab);
  1237. if cs_gdb_dbx in aktglobalswitches then
  1238. begin
  1239. if (current_module.globalsymtable<>self) then
  1240. begin
  1241. dbx_counter := prev_dbx_count;
  1242. do_count_dbx:=false;
  1243. asmList.concat(Tai_asm_comment.Create(strpnew('End unit '+name^
  1244. +' has index '+tostr(unitid))));
  1245. asmList.concat(Tai_stabs.Create(strpnew('"'+name^+'",'
  1246. +tostr(N_EINCL)+',0,0,0')));
  1247. do_count_dbx:=assigned(dbx_counter);
  1248. dbx_count_ok := {true}false;
  1249. end;
  1250. end;
  1251. is_stab_written:=true;
  1252. end;
  1253. {$endif GDB}
  1254. {****************************************************************************
  1255. TStaticSymtable
  1256. ****************************************************************************}
  1257. constructor tstaticsymtable.create(const n : string);
  1258. begin
  1259. inherited create(n);
  1260. symtabletype:=staticsymtable;
  1261. end;
  1262. procedure tstaticsymtable.load(ppufile:tcompilerppufile);
  1263. begin
  1264. aktstaticsymtable:=self;
  1265. next:=symtablestack;
  1266. symtablestack:=self;
  1267. inherited load(ppufile);
  1268. { now we can deref the syms and defs }
  1269. deref;
  1270. { restore symtablestack }
  1271. symtablestack:=next;
  1272. end;
  1273. procedure tstaticsymtable.write(ppufile:tcompilerppufile);
  1274. begin
  1275. aktstaticsymtable:=self;
  1276. { order procsym overloads }
  1277. foreach({$ifdef FPCPROCVAR}@{$endif}Order_overloads);
  1278. inherited write(ppufile);
  1279. end;
  1280. procedure tstaticsymtable.load_references(ppufile:tcompilerppufile;locals:boolean);
  1281. begin
  1282. aktstaticsymtable:=self;
  1283. inherited load_references(ppufile,locals);
  1284. end;
  1285. procedure tstaticsymtable.write_references(ppufile:tcompilerppufile;locals:boolean);
  1286. begin
  1287. aktstaticsymtable:=self;
  1288. inherited write_references(ppufile,locals);
  1289. end;
  1290. procedure tstaticsymtable.insert(sym:tsymentry);
  1291. var
  1292. hsym : tsym;
  1293. begin
  1294. { also check the global symtable }
  1295. if assigned(next) and
  1296. (next.unitid=0) then
  1297. begin
  1298. hsym:=tsym(next.search(sym.name));
  1299. if assigned(hsym) then
  1300. begin
  1301. DuplicateSym(hsym);
  1302. exit;
  1303. end;
  1304. end;
  1305. inherited insert(sym);
  1306. end;
  1307. {****************************************************************************
  1308. TGlobalSymtable
  1309. ****************************************************************************}
  1310. constructor tglobalsymtable.create(const n : string);
  1311. begin
  1312. inherited create(n);
  1313. symtabletype:=globalsymtable;
  1314. unitid:=0;
  1315. unitsym:=nil;
  1316. {$ifdef GDB}
  1317. if cs_gdb_dbx in aktglobalswitches then
  1318. begin
  1319. dbx_count := 0;
  1320. unittypecount:=1;
  1321. pglobaltypecount := @unittypecount;
  1322. unitid:=current_module.unitcount;
  1323. debugList.concat(Tai_asm_comment.Create(strpnew('Global '+name^+' has index '+tostr(unitid))));
  1324. debugList.concat(Tai_stabs.Create(strpnew('"'+name^+'",'+tostr(N_BINCL)+',0,0,0')));
  1325. inc(current_module.unitcount);
  1326. dbx_count_ok:=false;
  1327. dbx_counter:=@dbx_count;
  1328. do_count_dbx:=true;
  1329. end;
  1330. {$endif GDB}
  1331. end;
  1332. destructor tglobalsymtable.destroy;
  1333. var
  1334. pus : tunitsym;
  1335. begin
  1336. pus:=unitsym;
  1337. while assigned(pus) do
  1338. begin
  1339. unitsym:=pus.prevsym;
  1340. pus.prevsym:=nil;
  1341. pus.unitsymtable:=nil;
  1342. pus:=unitsym;
  1343. end;
  1344. inherited destroy;
  1345. end;
  1346. procedure tglobalsymtable.load(ppufile:tcompilerppufile);
  1347. {$ifdef GDB}
  1348. var
  1349. storeGlobalTypeCount : pword;
  1350. {$endif GDB}
  1351. begin
  1352. {$ifdef GDB}
  1353. if cs_gdb_dbx in aktglobalswitches then
  1354. begin
  1355. UnitTypeCount:=1;
  1356. storeGlobalTypeCount:=PGlobalTypeCount;
  1357. PglobalTypeCount:=@UnitTypeCount;
  1358. end;
  1359. {$endif GDB}
  1360. symtablelevel:=0;
  1361. {$ifndef NEWMAP}
  1362. current_module.map^[0]:=self;
  1363. {$else NEWMAP}
  1364. current_module.globalsymtable:=self;
  1365. {$endif NEWMAP}
  1366. next:=symtablestack;
  1367. symtablestack:=self;
  1368. inherited load(ppufile);
  1369. { now we can deref the syms and defs }
  1370. deref;
  1371. { restore symtablestack }
  1372. symtablestack:=next;
  1373. {$ifdef NEWMAP}
  1374. { necessary for dependencies }
  1375. current_module.globalsymtable:=nil;
  1376. {$endif NEWMAP}
  1377. end;
  1378. procedure tglobalsymtable.write(ppufile:tcompilerppufile);
  1379. begin
  1380. { order procsym overloads }
  1381. foreach({$ifdef FPCPROCVAR}@{$endif}Order_overloads);
  1382. { write the symtable entries }
  1383. inherited write(ppufile);
  1384. { write dbx count }
  1385. {$ifdef GDB}
  1386. if cs_gdb_dbx in aktglobalswitches then
  1387. begin
  1388. {$IfDef EXTDEBUG}
  1389. writeln('Writing dbx_count ',dbx_count,' in unit ',name^,'.ppu');
  1390. {$ENDIF EXTDEBUG}
  1391. ppufile.do_crc:=false;
  1392. ppufile.putlongint(dbx_count);
  1393. ppufile.writeentry(ibdbxcount);
  1394. ppufile.do_crc:=true;
  1395. end;
  1396. {$endif GDB}
  1397. end;
  1398. procedure tglobalsymtable.insert(sym:tsymentry);
  1399. var
  1400. hsym : tsym;
  1401. begin
  1402. { also check the global symtable }
  1403. if assigned(next) and
  1404. (next.unitid=0) then
  1405. begin
  1406. hsym:=tsym(next.search(sym.name));
  1407. if assigned(hsym) then
  1408. begin
  1409. DuplicateSym(hsym);
  1410. exit;
  1411. end;
  1412. end;
  1413. hsym:=tsym(search(sym.name));
  1414. if assigned(hsym) then
  1415. begin
  1416. { Delphi you can have a symbol with the same name as the
  1417. unit, the unit can then not be accessed anymore using
  1418. <unit>.<id>, so we can hide the symbol }
  1419. if (m_tp in aktmodeswitches) and
  1420. (hsym.typ=symconst.unitsym) then
  1421. hsym.owner.rename(hsym.name,'hidden'+hsym.name)
  1422. else
  1423. begin
  1424. DuplicateSym(hsym);
  1425. exit;
  1426. end;
  1427. end;
  1428. inherited insert(sym);
  1429. end;
  1430. {$ifdef GDB}
  1431. function tglobalsymtable.getnewtypecount : word;
  1432. begin
  1433. if not (cs_gdb_dbx in aktglobalswitches) then
  1434. getnewtypecount:=inherited getnewtypecount
  1435. else
  1436. begin
  1437. getnewtypecount:=unittypecount;
  1438. inc(unittypecount);
  1439. end;
  1440. end;
  1441. {$endif}
  1442. {****************************************************************************
  1443. TWITHSYMTABLE
  1444. ****************************************************************************}
  1445. constructor twithsymtable.create(aowner:tdef;asymsearch:TDictionary);
  1446. begin
  1447. inherited create('');
  1448. symtabletype:=withsymtable;
  1449. direct_with:=false;
  1450. withnode:=nil;
  1451. withrefnode:=nil;
  1452. { we don't need the symsearch }
  1453. symsearch.free;
  1454. { set the defaults }
  1455. symsearch:=asymsearch;
  1456. defowner:=aowner;
  1457. end;
  1458. destructor twithsymtable.destroy;
  1459. begin
  1460. symsearch:=nil;
  1461. inherited destroy;
  1462. end;
  1463. procedure twithsymtable.clear;
  1464. begin
  1465. { remove no entry from a withsymtable as it is only a pointer to the
  1466. recorddef or objectdef symtable }
  1467. end;
  1468. function twithsymtable.speedsearch(const s : stringid;speedvalue : cardinal) : tsymentry;
  1469. var
  1470. hp : tsym;
  1471. begin
  1472. hp:=tsym(inherited speedsearch(s, speedvalue));
  1473. { skip private members that can't be seen }
  1474. if assigned(hp) and
  1475. (sp_private in hp.symoptions) and
  1476. (hp.owner.symtabletype=objectsymtable) and
  1477. (hp.owner.defowner.owner.symtabletype=globalsymtable) and
  1478. (hp.owner.defowner.owner.unitid<>0) then
  1479. hp:=nil;
  1480. speedsearch:=hp;
  1481. end;
  1482. {****************************************************************************
  1483. TSTT_ExceptionSymtable
  1484. ****************************************************************************}
  1485. constructor tstt_exceptsymtable.create;
  1486. begin
  1487. inherited create('');
  1488. symtabletype:=stt_exceptsymtable;
  1489. end;
  1490. {*****************************************************************************
  1491. Helper Routines
  1492. *****************************************************************************}
  1493. function findunitsymtable(st:tsymtable):tsymtable;
  1494. begin
  1495. findunitsymtable:=nil;
  1496. repeat
  1497. if not assigned(st) then
  1498. internalerror(5566561);
  1499. case st.symtabletype of
  1500. localsymtable,
  1501. parasymtable,
  1502. staticsymtable :
  1503. break;
  1504. globalsymtable :
  1505. begin
  1506. findunitsymtable:=st;
  1507. break;
  1508. end;
  1509. objectsymtable,
  1510. recordsymtable :
  1511. st:=st.defowner.owner;
  1512. else
  1513. internalerror(5566562);
  1514. end;
  1515. until false;
  1516. end;
  1517. procedure duplicatesym(sym:tsym);
  1518. var
  1519. st : tsymtable;
  1520. begin
  1521. Message1(sym_e_duplicate_id,sym.realname);
  1522. st:=findunitsymtable(sym.owner);
  1523. with sym.fileinfo do
  1524. begin
  1525. if assigned(st) and (st.unitid<>0) then
  1526. Message2(sym_h_duplicate_id_where,'unit '+st.name^,tostr(line))
  1527. else
  1528. Message2(sym_h_duplicate_id_where,current_module.sourcefiles.get_file_name(fileindex),tostr(line));
  1529. end;
  1530. end;
  1531. {*****************************************************************************
  1532. Search
  1533. *****************************************************************************}
  1534. function searchsym(const s : stringid;var srsym:tsym;var srsymtable:tsymtable):boolean;
  1535. var
  1536. speedvalue : cardinal;
  1537. begin
  1538. speedvalue:=getspeedvalue(s);
  1539. srsymtable:=symtablestack;
  1540. while assigned(srsymtable) do
  1541. begin
  1542. srsym:=tsym(srsymtable.speedsearch(s,speedvalue));
  1543. if assigned(srsym) then
  1544. begin
  1545. searchsym:=true;
  1546. exit;
  1547. end
  1548. else
  1549. srsymtable:=srsymtable.next;
  1550. end;
  1551. searchsym:=false;
  1552. end;
  1553. function searchsymonlyin(p : tsymtable;const s : stringid):tsym;
  1554. var
  1555. srsym : tsym;
  1556. begin
  1557. { the caller have to take care if srsym=nil }
  1558. if assigned(p) then
  1559. begin
  1560. srsym:=tsym(p.search(s));
  1561. if assigned(srsym) then
  1562. begin
  1563. searchsymonlyin:=srsym;
  1564. exit;
  1565. end;
  1566. { also check in the local symtbale if it exists }
  1567. if (p=tsymtable(current_module.globalsymtable)) then
  1568. begin
  1569. srsym:=tsym(current_module.localsymtable.search(s));
  1570. if assigned(srsym) then
  1571. begin
  1572. searchsymonlyin:=srsym;
  1573. exit;
  1574. end;
  1575. end
  1576. end;
  1577. searchsymonlyin:=nil;
  1578. end;
  1579. function search_class_member(pd : tobjectdef;const s : string):tsym;
  1580. { searches n in symtable of pd and all anchestors }
  1581. var
  1582. speedvalue : cardinal;
  1583. srsym : tsym;
  1584. begin
  1585. speedvalue:=getspeedvalue(s);
  1586. while assigned(pd) do
  1587. begin
  1588. srsym:=tsym(pd.symtable.speedsearch(s,speedvalue));
  1589. if assigned(srsym) then
  1590. begin
  1591. search_class_member:=srsym;
  1592. exit;
  1593. end;
  1594. pd:=pd.childof;
  1595. end;
  1596. search_class_member:=nil;
  1597. end;
  1598. {*****************************************************************************
  1599. Definition Helpers
  1600. *****************************************************************************}
  1601. procedure globaldef(const s : string;var t:ttype);
  1602. var st : string;
  1603. symt : tsymtable;
  1604. srsym : tsym;
  1605. srsymtable : tsymtable;
  1606. begin
  1607. srsym := nil;
  1608. if pos('.',s) > 0 then
  1609. begin
  1610. st := copy(s,1,pos('.',s)-1);
  1611. searchsym(st,srsym,srsymtable);
  1612. st := copy(s,pos('.',s)+1,255);
  1613. if assigned(srsym) then
  1614. begin
  1615. if srsym.typ = unitsym then
  1616. begin
  1617. symt := tunitsym(srsym).unitsymtable;
  1618. srsym := tsym(symt.search(st));
  1619. end else srsym := nil;
  1620. end;
  1621. end else st := s;
  1622. if srsym = nil then
  1623. searchsym(st,srsym,srsymtable);
  1624. if srsym = nil then
  1625. srsym:=searchsymonlyin(systemunit,st);
  1626. if (not assigned(srsym)) or
  1627. (srsym.typ<>typesym) then
  1628. begin
  1629. Message(type_e_type_id_expected);
  1630. t:=generrortype;
  1631. exit;
  1632. end;
  1633. t := ttypesym(srsym).restype;
  1634. end;
  1635. {****************************************************************************
  1636. Object Helpers
  1637. ****************************************************************************}
  1638. var
  1639. _defaultprop : tpropertysym;
  1640. procedure tstoredsymtable.testfordefaultproperty(p : TNamedIndexItem);
  1641. begin
  1642. if (tsym(p).typ=propertysym) and
  1643. (ppo_defaultproperty in tpropertysym(p).propoptions) then
  1644. _defaultprop:=tpropertysym(p);
  1645. end;
  1646. function search_default_property(pd : tobjectdef) : tpropertysym;
  1647. { returns the default property of a class, searches also anchestors }
  1648. begin
  1649. _defaultprop:=nil;
  1650. while assigned(pd) do
  1651. begin
  1652. pd.symtable.foreach({$ifdef FPCPROCVAR}@{$endif}tstoredsymtable(pd.symtable).testfordefaultproperty);
  1653. if assigned(_defaultprop) then
  1654. break;
  1655. pd:=pd.childof;
  1656. end;
  1657. search_default_property:=_defaultprop;
  1658. end;
  1659. {$ifdef UNITALIASES}
  1660. {****************************************************************************
  1661. TUNIT_ALIAS
  1662. ****************************************************************************}
  1663. constructor tunit_alias.create(const n:string);
  1664. var
  1665. i : longint;
  1666. begin
  1667. i:=pos('=',n);
  1668. if i=0 then
  1669. fail;
  1670. inherited createname(Copy(n,1,i-1));
  1671. newname:=stringdup(Copy(n,i+1,255));
  1672. end;
  1673. destructor tunit_alias.destroy;
  1674. begin
  1675. stringdispose(newname);
  1676. inherited destroy;
  1677. end;
  1678. procedure addunitalias(const n:string);
  1679. begin
  1680. unitaliases^.insert(tunit_alias,init(Upper(n))));
  1681. end;
  1682. function getunitalias(const n:string):string;
  1683. var
  1684. p : punit_alias;
  1685. begin
  1686. p:=punit_alias(unitaliases^.search(Upper(n)));
  1687. if assigned(p) then
  1688. getunitalias:=punit_alias(p).newname^
  1689. else
  1690. getunitalias:=n;
  1691. end;
  1692. {$endif UNITALIASES}
  1693. {****************************************************************************
  1694. Symtable Stack
  1695. ****************************************************************************}
  1696. procedure dellexlevel;
  1697. var
  1698. p : tsymtable;
  1699. begin
  1700. p:=symtablestack;
  1701. symtablestack:=p.next;
  1702. { symbol tables of unit interfaces are never disposed }
  1703. { this is handle by the unit unitm }
  1704. if not(p.symtabletype in [globalsymtable,stt_exceptsymtable]) then
  1705. p.free;
  1706. end;
  1707. procedure RestoreUnitSyms;
  1708. var
  1709. p : tsymtable;
  1710. begin
  1711. p:=symtablestack;
  1712. while assigned(p) do
  1713. begin
  1714. if (p.symtabletype=globalsymtable) and
  1715. assigned(tglobalsymtable(p).unitsym) and
  1716. ((tglobalsymtable(p).unitsym.owner=current_module.globalsymtable) or
  1717. (tglobalsymtable(p).unitsym.owner=current_module.localsymtable)) then
  1718. tglobalsymtable(p).unitsym.restoreunitsym;
  1719. p:=p.next;
  1720. end;
  1721. end;
  1722. {$ifdef DEBUG}
  1723. procedure test_symtablestack;
  1724. var
  1725. p : tsymtable;
  1726. i : longint;
  1727. begin
  1728. p:=symtablestack;
  1729. i:=0;
  1730. while assigned(p) do
  1731. begin
  1732. inc(i);
  1733. p:=p.next;
  1734. if i>500 then
  1735. Message(sym_f_internal_error_in_symtablestack);
  1736. end;
  1737. end;
  1738. procedure list_symtablestack;
  1739. var
  1740. p : tsymtable;
  1741. i : longint;
  1742. begin
  1743. p:=symtablestack;
  1744. i:=0;
  1745. while assigned(p) do
  1746. begin
  1747. inc(i);
  1748. writeln(i,' ',p.name^);
  1749. p:=p.next;
  1750. if i>500 then
  1751. Message(sym_f_internal_error_in_symtablestack);
  1752. end;
  1753. end;
  1754. {$endif DEBUG}
  1755. {****************************************************************************
  1756. Init/Done Symtable
  1757. ****************************************************************************}
  1758. procedure InitSymtable;
  1759. var
  1760. token : ttoken;
  1761. begin
  1762. { Reset symbolstack }
  1763. registerdef:=false;
  1764. read_member:=false;
  1765. symtablestack:=nil;
  1766. systemunit:=nil;
  1767. {$ifdef GDB}
  1768. firstglobaldef:=nil;
  1769. lastglobaldef:=nil;
  1770. globaltypecount:=1;
  1771. pglobaltypecount:=@globaltypecount;
  1772. {$endif GDB}
  1773. { create error syms and def }
  1774. generrorsym:=terrorsym.create;
  1775. generrortype.setdef(terrordef.create);
  1776. {$ifdef UNITALIASES}
  1777. { unit aliases }
  1778. unitaliases:=tdictionary.create;
  1779. {$endif}
  1780. for token:=first_overloaded to last_overloaded do
  1781. overloaded_operators[token]:=nil;
  1782. end;
  1783. procedure DoneSymtable;
  1784. begin
  1785. generrorsym.free;
  1786. generrortype.def.free;
  1787. {$ifdef UNITALIASES}
  1788. unitaliases.free;
  1789. {$endif}
  1790. end;
  1791. end.
  1792. {
  1793. $Log$
  1794. Revision 1.43 2001-08-30 20:13:56 peter
  1795. * rtti/init table updates
  1796. * rttisym for reusable global rtti/init info
  1797. * support published for interfaces
  1798. Revision 1.42 2001/08/26 13:36:51 florian
  1799. * some cg reorganisation
  1800. * some PPC updates
  1801. Revision 1.41 2001/08/19 09:39:29 peter
  1802. * local browser support fixed
  1803. Revision 1.40 2001/08/06 21:40:49 peter
  1804. * funcret moved from tprocinfo to tprocdef
  1805. Revision 1.39 2001/07/29 22:12:58 peter
  1806. * skip private symbols when found in withsymtable
  1807. Revision 1.38 2001/07/01 20:16:18 peter
  1808. * alignmentinfo record added
  1809. * -Oa argument supports more alignment settings that can be specified
  1810. per type: PROC,LOOP,VARMIN,VARMAX,CONSTMIN,CONSTMAX,RECORDMIN
  1811. RECORDMAX,LOCALMIN,LOCALMAX. It is possible to set the mimimum
  1812. required alignment and the maximum usefull alignment. The final
  1813. alignment will be choosen per variable size dependent on these
  1814. settings
  1815. Revision 1.37 2001/06/04 11:53:14 peter
  1816. + varargs directive
  1817. Revision 1.36 2001/06/03 21:57:38 peter
  1818. + hint directive parsing support
  1819. Revision 1.35 2001/05/06 14:49:18 peter
  1820. * ppu object to class rewrite
  1821. * move ppu read and write stuff to fppu
  1822. Revision 1.34 2001/04/18 22:01:59 peter
  1823. * registration of targets and assemblers
  1824. Revision 1.33 2001/04/13 20:05:15 peter
  1825. * better check for globalsymtable
  1826. Revision 1.32 2001/04/13 18:08:37 peter
  1827. * scanner object to class
  1828. Revision 1.31 2001/04/13 01:22:16 peter
  1829. * symtable change to classes
  1830. * range check generation and errors fixed, make cycle DEBUG=1 works
  1831. * memory leaks fixed
  1832. Revision 1.30 2001/04/02 21:20:35 peter
  1833. * resulttype rewrite
  1834. Revision 1.29 2001/03/22 00:10:58 florian
  1835. + basic variant type support in the compiler
  1836. Revision 1.28 2001/03/13 18:45:07 peter
  1837. * fixed some memory leaks
  1838. Revision 1.27 2001/03/11 22:58:51 peter
  1839. * getsym redesign, removed the globals srsym,srsymtable
  1840. Revision 1.26 2001/02/21 19:37:19 peter
  1841. * moved deref to be done after loading of implementation units. prederef
  1842. is still done directly after loading of symbols and definitions.
  1843. Revision 1.25 2001/02/20 21:41:16 peter
  1844. * new fixfilename, findfile for unix. Look first for lowercase, then
  1845. NormalCase and last for UPPERCASE names.
  1846. Revision 1.24 2001/01/08 21:40:27 peter
  1847. * fixed crash with unsupported token overloading
  1848. Revision 1.23 2000/12/25 00:07:30 peter
  1849. + new tlinkedlist class (merge of old tstringqueue,tcontainer and
  1850. tlinkedlist objects)
  1851. Revision 1.22 2000/12/23 19:50:09 peter
  1852. * fixed mem leak with withsymtable
  1853. Revision 1.21 2000/12/10 20:25:32 peter
  1854. * fixed missing typecast
  1855. Revision 1.20 2000/12/10 14:14:51 florian
  1856. * fixed web bug 1203: class fields can be now redefined
  1857. in Delphi mode though I don't like this :/
  1858. Revision 1.19 2000/11/30 22:16:49 florian
  1859. * moved to i386
  1860. Revision 1.18 2000/11/29 00:30:42 florian
  1861. * unused units removed from uses clause
  1862. * some changes for widestrings
  1863. Revision 1.17 2000/11/28 00:28:07 pierre
  1864. * stabs fixing
  1865. Revision 1.1.2.8 2000/11/17 11:14:37 pierre
  1866. * one more class stabs fix
  1867. Revision 1.16 2000/11/12 22:17:47 peter
  1868. * some realname updates for messages
  1869. Revision 1.15 2000/11/06 15:54:15 florian
  1870. * fixed two bugs to get make cycle work, but it's not enough
  1871. Revision 1.14 2000/11/04 14:25:22 florian
  1872. + merged Attila's changes for interfaces, not tested yet
  1873. Revision 1.13 2000/11/01 23:04:38 peter
  1874. * tprocdef.fullprocname added for better casesensitve writing of
  1875. procedures
  1876. Revision 1.12 2000/10/31 22:02:52 peter
  1877. * symtable splitted, no real code changes
  1878. Revision 1.1.2.7 2000/10/16 19:43:04 pierre
  1879. * trying to correct class stabss once more
  1880. Revision 1.11 2000/10/15 07:47:53 peter
  1881. * unit names and procedure names are stored mixed case
  1882. Revision 1.10 2000/10/14 10:14:53 peter
  1883. * moehrendorf oct 2000 rewrite
  1884. Revision 1.9 2000/10/01 19:48:25 peter
  1885. * lot of compile updates for cg11
  1886. Revision 1.8 2000/09/24 15:06:29 peter
  1887. * use defines.inc
  1888. Revision 1.7 2000/08/27 16:11:54 peter
  1889. * moved some util functions from globals,cobjects to cutils
  1890. * splitted files into finput,fmodule
  1891. Revision 1.6 2000/08/21 11:27:45 pierre
  1892. * fix the stabs problems
  1893. Revision 1.5 2000/08/20 14:58:41 peter
  1894. * give fatal if objfpc/delphi mode things are found (merged)
  1895. Revision 1.1.2.6 2000/08/20 14:56:46 peter
  1896. * give fatal if objfpc/delphi mode things are found
  1897. Revision 1.4 2000/08/16 18:33:54 peter
  1898. * splitted namedobjectitem.next into indexnext and listnext so it
  1899. can be used in both lists
  1900. * don't allow "word = word" type definitions (merged)
  1901. Revision 1.3 2000/08/08 19:28:57 peter
  1902. * memdebug/memory patches (merged)
  1903. * only once illegal directive (merged)
  1904. }