symtable.pas 70 KB

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