symtable.pas 72 KB

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