symtable.pas 71 KB

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