symtable.pas 72 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275
  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. begin
  1298. {$ifdef GDB}
  1299. if cs_gdb_dbx in aktglobalswitches then
  1300. begin
  1301. UnitTypeCount:=1;
  1302. PglobalTypeCount:=@UnitTypeCount;
  1303. end;
  1304. {$endif GDB}
  1305. symtablelevel:=0;
  1306. {$ifndef NEWMAP}
  1307. current_module.map^[0]:=self;
  1308. {$else NEWMAP}
  1309. current_module.globalsymtable:=self;
  1310. {$endif NEWMAP}
  1311. next:=symtablestack;
  1312. symtablestack:=self;
  1313. inherited load(ppufile);
  1314. { now we can deref the syms and defs }
  1315. deref;
  1316. { restore symtablestack }
  1317. symtablestack:=next;
  1318. {$ifdef NEWMAP}
  1319. { necessary for dependencies }
  1320. current_module.globalsymtable:=nil;
  1321. {$endif NEWMAP}
  1322. end;
  1323. procedure tglobalsymtable.write(ppufile:tcompilerppufile);
  1324. begin
  1325. { write the symtable entries }
  1326. inherited write(ppufile);
  1327. { write dbx count }
  1328. {$ifdef GDB}
  1329. if cs_gdb_dbx in aktglobalswitches then
  1330. begin
  1331. {$IfDef EXTDEBUG}
  1332. writeln('Writing dbx_count ',dbx_count,' in unit ',name^,'.ppu');
  1333. {$ENDIF EXTDEBUG}
  1334. ppufile.do_crc:=false;
  1335. ppufile.putlongint(dbx_count);
  1336. ppufile.writeentry(ibdbxcount);
  1337. ppufile.do_crc:=true;
  1338. end;
  1339. {$endif GDB}
  1340. end;
  1341. procedure tglobalsymtable.insert(sym:tsymentry);
  1342. var
  1343. hsym : tsym;
  1344. begin
  1345. { also check the global symtable }
  1346. if assigned(next) and
  1347. (next.unitid=0) then
  1348. begin
  1349. hsym:=tsym(next.search(sym.name));
  1350. if assigned(hsym) then
  1351. begin
  1352. DuplicateSym(hsym);
  1353. exit;
  1354. end;
  1355. end;
  1356. hsym:=tsym(search(sym.name));
  1357. if assigned(hsym) then
  1358. begin
  1359. { Delphi you can have a symbol with the same name as the
  1360. unit, the unit can then not be accessed anymore using
  1361. <unit>.<id>, so we can hide the symbol }
  1362. if (m_duplicate_names in aktmodeswitches) and
  1363. (hsym.typ=symconst.unitsym) then
  1364. hsym.owner.rename(hsym.name,'hidden'+hsym.name)
  1365. else
  1366. begin
  1367. DuplicateSym(hsym);
  1368. exit;
  1369. end;
  1370. end;
  1371. inherited insert(sym);
  1372. end;
  1373. {$ifdef GDB}
  1374. function tglobalsymtable.getnewtypecount : word;
  1375. begin
  1376. if not (cs_gdb_dbx in aktglobalswitches) then
  1377. getnewtypecount:=inherited getnewtypecount
  1378. else
  1379. begin
  1380. getnewtypecount:=unittypecount;
  1381. inc(unittypecount);
  1382. end;
  1383. end;
  1384. {$endif}
  1385. {****************************************************************************
  1386. TWITHSYMTABLE
  1387. ****************************************************************************}
  1388. constructor twithsymtable.create(aowner:tdef;asymsearch:TDictionary);
  1389. begin
  1390. inherited create('');
  1391. symtabletype:=withsymtable;
  1392. direct_with:=false;
  1393. withnode:=nil;
  1394. withrefnode:=nil;
  1395. { we don't need the symsearch }
  1396. symsearch.free;
  1397. { set the defaults }
  1398. symsearch:=asymsearch;
  1399. defowner:=aowner;
  1400. end;
  1401. destructor twithsymtable.destroy;
  1402. begin
  1403. symsearch:=nil;
  1404. inherited destroy;
  1405. end;
  1406. procedure twithsymtable.clear;
  1407. begin
  1408. { remove no entry from a withsymtable as it is only a pointer to the
  1409. recorddef or objectdef symtable }
  1410. end;
  1411. {****************************************************************************
  1412. TSTT_ExceptionSymtable
  1413. ****************************************************************************}
  1414. constructor tstt_exceptsymtable.create;
  1415. begin
  1416. inherited create('');
  1417. symtabletype:=stt_exceptsymtable;
  1418. end;
  1419. {*****************************************************************************
  1420. Helper Routines
  1421. *****************************************************************************}
  1422. function findunitsymtable(st:tsymtable):tsymtable;
  1423. begin
  1424. findunitsymtable:=nil;
  1425. repeat
  1426. if not assigned(st) then
  1427. internalerror(5566561);
  1428. case st.symtabletype of
  1429. localsymtable,
  1430. parasymtable,
  1431. staticsymtable :
  1432. break;
  1433. globalsymtable :
  1434. begin
  1435. findunitsymtable:=st;
  1436. break;
  1437. end;
  1438. objectsymtable,
  1439. recordsymtable :
  1440. st:=st.defowner.owner;
  1441. else
  1442. internalerror(5566562);
  1443. end;
  1444. until false;
  1445. end;
  1446. procedure duplicatesym(sym:tsym);
  1447. var
  1448. st : tsymtable;
  1449. begin
  1450. Message1(sym_e_duplicate_id,sym.realname);
  1451. st:=findunitsymtable(sym.owner);
  1452. with sym.fileinfo do
  1453. begin
  1454. if assigned(st) and (st.unitid<>0) then
  1455. Message2(sym_h_duplicate_id_where,'unit '+st.name^,tostr(line))
  1456. else
  1457. Message2(sym_h_duplicate_id_where,current_module.sourcefiles.get_file_name(fileindex),tostr(line));
  1458. end;
  1459. end;
  1460. {*****************************************************************************
  1461. Search
  1462. *****************************************************************************}
  1463. function searchsym(const s : stringid;var srsym:tsym;var srsymtable:tsymtable):boolean;
  1464. var
  1465. speedvalue : cardinal;
  1466. begin
  1467. speedvalue:=getspeedvalue(s);
  1468. srsymtable:=symtablestack;
  1469. while assigned(srsymtable) do
  1470. begin
  1471. srsym:=tsym(srsymtable.speedsearch(s,speedvalue));
  1472. if assigned(srsym) and
  1473. tstoredsym(srsym).is_visible_for_proc(aktprocdef) then
  1474. begin
  1475. searchsym:=true;
  1476. exit;
  1477. end
  1478. else
  1479. srsymtable:=srsymtable.next;
  1480. end;
  1481. searchsym:=false;
  1482. end;
  1483. function searchsymonlyin(p : tsymtable;const s : stringid):tsym;
  1484. var
  1485. srsym : tsym;
  1486. begin
  1487. { the caller have to take care if srsym=nil }
  1488. if assigned(p) then
  1489. begin
  1490. srsym:=tsym(p.search(s));
  1491. if assigned(srsym) then
  1492. begin
  1493. searchsymonlyin:=srsym;
  1494. exit;
  1495. end;
  1496. { also check in the local symtbale if it exists }
  1497. if (p=tsymtable(current_module.globalsymtable)) then
  1498. begin
  1499. srsym:=tsym(current_module.localsymtable.search(s));
  1500. if assigned(srsym) then
  1501. begin
  1502. searchsymonlyin:=srsym;
  1503. exit;
  1504. end;
  1505. end
  1506. end;
  1507. searchsymonlyin:=nil;
  1508. end;
  1509. function searchsym_in_class(classh:tobjectdef;const s : stringid):tsym;
  1510. var
  1511. speedvalue : cardinal;
  1512. topclassh : tobjectdef;
  1513. sym : tsym;
  1514. begin
  1515. speedvalue:=getspeedvalue(s);
  1516. { when the class passed is defined in this unit we
  1517. need to use the scope of that class. This is a trick
  1518. that can be used to access protected members in other
  1519. units. At least kylix supports it this way (PFV) }
  1520. if (classh.owner.symtabletype in [globalsymtable,staticsymtable]) and
  1521. (classh.owner.unitid=0) then
  1522. topclassh:=classh
  1523. else
  1524. topclassh:=nil;
  1525. sym:=nil;
  1526. while assigned(classh) do
  1527. begin
  1528. sym:=tsym(classh.symtable.speedsearch(s,speedvalue));
  1529. if assigned(sym) then
  1530. begin
  1531. if assigned(topclassh) then
  1532. begin
  1533. if tstoredsym(sym).is_visible_for_object(topclassh) then
  1534. break;
  1535. end
  1536. else
  1537. begin
  1538. if tstoredsym(sym).is_visible_for_proc(aktprocdef) then
  1539. break;
  1540. end;
  1541. end;
  1542. classh:=classh.childof;
  1543. end;
  1544. searchsym_in_class:=sym;
  1545. end;
  1546. function searchsystype(const s: stringid; var srsym: ttypesym): boolean;
  1547. var
  1548. symowner: tsymtable;
  1549. begin
  1550. if not(cs_compilesystem in aktmoduleswitches) then
  1551. srsym := ttypesym(searchsymonlyin(systemunit,s))
  1552. else
  1553. searchsym(s,srsym,symowner);
  1554. searchsystype :=
  1555. assigned(srsym) and
  1556. (srsym.typ = typesym);
  1557. end;
  1558. function searchsysvar(const s: stringid; var srsym: tvarsym; var symowner: tsymtable): boolean;
  1559. begin
  1560. if not(cs_compilesystem in aktmoduleswitches) then
  1561. begin
  1562. srsym := tvarsym(searchsymonlyin(systemunit,s));
  1563. symowner := systemunit;
  1564. end
  1565. else
  1566. searchsym(s,srsym,symowner);
  1567. searchsysvar :=
  1568. assigned(srsym) and
  1569. (srsym.typ = varsym);
  1570. end;
  1571. function search_class_member(pd : tobjectdef;const s : string):tsym;
  1572. { searches n in symtable of pd and all anchestors }
  1573. var
  1574. speedvalue : cardinal;
  1575. srsym : tsym;
  1576. begin
  1577. speedvalue:=getspeedvalue(s);
  1578. while assigned(pd) do
  1579. begin
  1580. srsym:=tsym(pd.symtable.speedsearch(s,speedvalue));
  1581. if assigned(srsym) then
  1582. begin
  1583. search_class_member:=srsym;
  1584. exit;
  1585. end;
  1586. pd:=pd.childof;
  1587. end;
  1588. search_class_member:=nil;
  1589. end;
  1590. {*****************************************************************************
  1591. Definition Helpers
  1592. *****************************************************************************}
  1593. procedure globaldef(const s : string;var t:ttype);
  1594. var st : string;
  1595. symt : tsymtable;
  1596. srsym : tsym;
  1597. srsymtable : tsymtable;
  1598. begin
  1599. srsym := nil;
  1600. if pos('.',s) > 0 then
  1601. begin
  1602. st := copy(s,1,pos('.',s)-1);
  1603. searchsym(st,srsym,srsymtable);
  1604. st := copy(s,pos('.',s)+1,255);
  1605. if assigned(srsym) then
  1606. begin
  1607. if srsym.typ = unitsym then
  1608. begin
  1609. symt := tunitsym(srsym).unitsymtable;
  1610. srsym := tsym(symt.search(st));
  1611. end else srsym := nil;
  1612. end;
  1613. end else st := s;
  1614. if srsym = nil then
  1615. searchsym(st,srsym,srsymtable);
  1616. if srsym = nil then
  1617. srsym:=searchsymonlyin(systemunit,st);
  1618. if (not assigned(srsym)) or
  1619. (srsym.typ<>typesym) then
  1620. begin
  1621. Message(type_e_type_id_expected);
  1622. t:=generrortype;
  1623. exit;
  1624. end;
  1625. t := ttypesym(srsym).restype;
  1626. end;
  1627. {****************************************************************************
  1628. Object Helpers
  1629. ****************************************************************************}
  1630. var
  1631. _defaultprop : tpropertysym;
  1632. procedure tstoredsymtable.testfordefaultproperty(p : TNamedIndexItem);
  1633. begin
  1634. if (tsym(p).typ=propertysym) and
  1635. (ppo_defaultproperty in tpropertysym(p).propoptions) then
  1636. _defaultprop:=tpropertysym(p);
  1637. end;
  1638. function search_default_property(pd : tobjectdef) : tpropertysym;
  1639. { returns the default property of a class, searches also anchestors }
  1640. begin
  1641. _defaultprop:=nil;
  1642. while assigned(pd) do
  1643. begin
  1644. pd.symtable.foreach({$ifdef FPCPROCVAR}@{$endif}tstoredsymtable(pd.symtable).testfordefaultproperty);
  1645. if assigned(_defaultprop) then
  1646. break;
  1647. pd:=pd.childof;
  1648. end;
  1649. search_default_property:=_defaultprop;
  1650. end;
  1651. {$ifdef UNITALIASES}
  1652. {****************************************************************************
  1653. TUNIT_ALIAS
  1654. ****************************************************************************}
  1655. constructor tunit_alias.create(const n:string);
  1656. var
  1657. i : longint;
  1658. begin
  1659. i:=pos('=',n);
  1660. if i=0 then
  1661. fail;
  1662. inherited createname(Copy(n,1,i-1));
  1663. newname:=stringdup(Copy(n,i+1,255));
  1664. end;
  1665. destructor tunit_alias.destroy;
  1666. begin
  1667. stringdispose(newname);
  1668. inherited destroy;
  1669. end;
  1670. procedure addunitalias(const n:string);
  1671. begin
  1672. unitaliases^.insert(tunit_alias,init(Upper(n))));
  1673. end;
  1674. function getunitalias(const n:string):string;
  1675. var
  1676. p : punit_alias;
  1677. begin
  1678. p:=punit_alias(unitaliases^.search(Upper(n)));
  1679. if assigned(p) then
  1680. getunitalias:=punit_alias(p).newname^
  1681. else
  1682. getunitalias:=n;
  1683. end;
  1684. {$endif UNITALIASES}
  1685. {****************************************************************************
  1686. Symtable Stack
  1687. ****************************************************************************}
  1688. procedure dellexlevel;
  1689. var
  1690. p : tsymtable;
  1691. begin
  1692. p:=symtablestack;
  1693. symtablestack:=p.next;
  1694. { symbol tables of unit interfaces are never disposed }
  1695. { this is handle by the unit unitm }
  1696. if not(p.symtabletype in [globalsymtable,stt_exceptsymtable]) then
  1697. p.free;
  1698. end;
  1699. procedure RestoreUnitSyms;
  1700. var
  1701. p : tsymtable;
  1702. begin
  1703. p:=symtablestack;
  1704. while assigned(p) do
  1705. begin
  1706. if (p.symtabletype=globalsymtable) and
  1707. assigned(tglobalsymtable(p).unitsym) and
  1708. ((tglobalsymtable(p).unitsym.owner=current_module.globalsymtable) or
  1709. (tglobalsymtable(p).unitsym.owner=current_module.localsymtable)) then
  1710. tglobalsymtable(p).unitsym.restoreunitsym;
  1711. p:=p.next;
  1712. end;
  1713. end;
  1714. {$ifdef DEBUG}
  1715. procedure test_symtablestack;
  1716. var
  1717. p : tsymtable;
  1718. i : longint;
  1719. begin
  1720. p:=symtablestack;
  1721. i:=0;
  1722. while assigned(p) do
  1723. begin
  1724. inc(i);
  1725. p:=p.next;
  1726. if i>500 then
  1727. Message(sym_f_internal_error_in_symtablestack);
  1728. end;
  1729. end;
  1730. procedure list_symtablestack;
  1731. var
  1732. p : tsymtable;
  1733. i : longint;
  1734. begin
  1735. p:=symtablestack;
  1736. i:=0;
  1737. while assigned(p) do
  1738. begin
  1739. inc(i);
  1740. writeln(i,' ',p.name^);
  1741. p:=p.next;
  1742. if i>500 then
  1743. Message(sym_f_internal_error_in_symtablestack);
  1744. end;
  1745. end;
  1746. {$endif DEBUG}
  1747. {****************************************************************************
  1748. Init/Done Symtable
  1749. ****************************************************************************}
  1750. procedure InitSymtable;
  1751. var
  1752. token : ttoken;
  1753. begin
  1754. { Reset symbolstack }
  1755. registerdef:=false;
  1756. read_member:=false;
  1757. symtablestack:=nil;
  1758. systemunit:=nil;
  1759. {$ifdef GDB}
  1760. firstglobaldef:=nil;
  1761. lastglobaldef:=nil;
  1762. globaltypecount:=1;
  1763. pglobaltypecount:=@globaltypecount;
  1764. {$endif GDB}
  1765. { create error syms and def }
  1766. generrorsym:=terrorsym.create;
  1767. generrortype.setdef(terrordef.create);
  1768. {$ifdef UNITALIASES}
  1769. { unit aliases }
  1770. unitaliases:=tdictionary.create;
  1771. {$endif}
  1772. for token:=first_overloaded to last_overloaded do
  1773. overloaded_operators[token]:=nil;
  1774. end;
  1775. procedure DoneSymtable;
  1776. begin
  1777. generrorsym.free;
  1778. generrortype.def.free;
  1779. {$ifdef UNITALIASES}
  1780. unitaliases.free;
  1781. {$endif}
  1782. end;
  1783. end.
  1784. {
  1785. $Log$
  1786. Revision 1.56 2002-03-04 19:10:11 peter
  1787. * removed compiler warnings
  1788. Revision 1.55 2002/02/03 09:30:07 peter
  1789. * more fixes for protected handling
  1790. Revision 1.54 2002/01/29 21:30:25 peter
  1791. * allow also dup id in delphi mode in interfaces
  1792. Revision 1.53 2002/01/29 19:46:00 peter
  1793. * fixed recordsymtable.insert_in() for inserting variant record fields
  1794. to not used symtable.insert() because that also updates alignmentinfo
  1795. which was already set
  1796. Revision 1.52 2002/01/24 18:25:50 peter
  1797. * implicit result variable generation for assembler routines
  1798. * removed m_tp modeswitch, use m_tp7 or not(m_fpc) instead
  1799. Revision 1.51 2001/12/31 16:59:43 peter
  1800. * protected/private symbols parsing fixed
  1801. Revision 1.50 2001/11/18 18:43:17 peter
  1802. * overloading supported in child classes
  1803. * fixed parsing of classes with private and virtual and overloaded
  1804. so it is compatible with delphi
  1805. Revision 1.49 2001/11/02 23:16:52 peter
  1806. * removed obsolete chainprocsym and test_procsym code
  1807. Revision 1.48 2001/11/02 22:58:08 peter
  1808. * procsym definition rewrite
  1809. Revision 1.47 2001/10/12 20:27:43 jonas
  1810. * fixed crashing bug in unit reference counting
  1811. Revision 1.46 2001/09/30 21:29:47 peter
  1812. * gdb fixes merged
  1813. Revision 1.45 2001/09/19 11:06:03 michael
  1814. * realname updated for some hints
  1815. * realname used for consts,labels
  1816. Revision 1.44 2001/09/04 11:38:55 jonas
  1817. + searchsystype() and searchsystype() functions in symtable
  1818. * changed ninl and nadd to use these functions
  1819. * i386 set comparison functions now return their results in al instead
  1820. of in the flags so that they can be sued as compilerprocs
  1821. - removed all processor specific code from n386add.pas that has to do
  1822. with set handling, it's now all done in nadd.pas
  1823. * fixed fpc_set_contains_sets in genset.inc
  1824. * fpc_set_in_byte is now coded inline in n386set.pas and doesn't use a
  1825. helper anymore
  1826. * some small fixes in compproc.inc/set.inc regarding the declaration of
  1827. internal helper types (fpc_small_set and fpc_normal_set)
  1828. Revision 1.43 2001/08/30 20:13:56 peter
  1829. * rtti/init table updates
  1830. * rttisym for reusable global rtti/init info
  1831. * support published for interfaces
  1832. Revision 1.42 2001/08/26 13:36:51 florian
  1833. * some cg reorganisation
  1834. * some PPC updates
  1835. Revision 1.41 2001/08/19 09:39:29 peter
  1836. * local browser support fixed
  1837. Revision 1.40 2001/08/06 21:40:49 peter
  1838. * funcret moved from tprocinfo to tprocdef
  1839. Revision 1.39 2001/07/29 22:12:58 peter
  1840. * skip private symbols when found in withsymtable
  1841. Revision 1.38 2001/07/01 20:16:18 peter
  1842. * alignmentinfo record added
  1843. * -Oa argument supports more alignment settings that can be specified
  1844. per type: PROC,LOOP,VARMIN,VARMAX,CONSTMIN,CONSTMAX,RECORDMIN
  1845. RECORDMAX,LOCALMIN,LOCALMAX. It is possible to set the mimimum
  1846. required alignment and the maximum usefull alignment. The final
  1847. alignment will be choosen per variable size dependent on these
  1848. settings
  1849. Revision 1.37 2001/06/04 11:53:14 peter
  1850. + varargs directive
  1851. Revision 1.36 2001/06/03 21:57:38 peter
  1852. + hint directive parsing support
  1853. Revision 1.35 2001/05/06 14:49:18 peter
  1854. * ppu object to class rewrite
  1855. * move ppu read and write stuff to fppu
  1856. Revision 1.34 2001/04/18 22:01:59 peter
  1857. * registration of targets and assemblers
  1858. Revision 1.33 2001/04/13 20:05:15 peter
  1859. * better check for globalsymtable
  1860. Revision 1.32 2001/04/13 18:08:37 peter
  1861. * scanner object to class
  1862. Revision 1.31 2001/04/13 01:22:16 peter
  1863. * symtable change to classes
  1864. * range check generation and errors fixed, make cycle DEBUG=1 works
  1865. * memory leaks fixed
  1866. Revision 1.30 2001/04/02 21:20:35 peter
  1867. * resulttype rewrite
  1868. Revision 1.29 2001/03/22 00:10:58 florian
  1869. + basic variant type support in the compiler
  1870. Revision 1.28 2001/03/13 18:45:07 peter
  1871. * fixed some memory leaks
  1872. Revision 1.27 2001/03/11 22:58:51 peter
  1873. * getsym redesign, removed the globals srsym,srsymtable
  1874. Revision 1.26 2001/02/21 19:37:19 peter
  1875. * moved deref to be done after loading of implementation units. prederef
  1876. is still done directly after loading of symbols and definitions.
  1877. Revision 1.25 2001/02/20 21:41:16 peter
  1878. * new fixfilename, findfile for unix. Look first for lowercase, then
  1879. NormalCase and last for UPPERCASE names.
  1880. Revision 1.24 2001/01/08 21:40:27 peter
  1881. * fixed crash with unsupported token overloading
  1882. Revision 1.23 2000/12/25 00:07:30 peter
  1883. + new tlinkedlist class (merge of old tstringqueue,tcontainer and
  1884. tlinkedlist objects)
  1885. Revision 1.22 2000/12/23 19:50:09 peter
  1886. * fixed mem leak with withsymtable
  1887. Revision 1.21 2000/12/10 20:25:32 peter
  1888. * fixed missing typecast
  1889. Revision 1.20 2000/12/10 14:14:51 florian
  1890. * fixed web bug 1203: class fields can be now redefined
  1891. in Delphi mode though I don't like this :/
  1892. Revision 1.19 2000/11/30 22:16:49 florian
  1893. * moved to i386
  1894. Revision 1.18 2000/11/29 00:30:42 florian
  1895. * unused units removed from uses clause
  1896. * some changes for widestrings
  1897. Revision 1.17 2000/11/28 00:28:07 pierre
  1898. * stabs fixing
  1899. Revision 1.1.2.8 2000/11/17 11:14:37 pierre
  1900. * one more class stabs fix
  1901. Revision 1.16 2000/11/12 22:17:47 peter
  1902. * some realname updates for messages
  1903. Revision 1.15 2000/11/06 15:54:15 florian
  1904. * fixed two bugs to get make cycle work, but it's not enough
  1905. Revision 1.14 2000/11/04 14:25:22 florian
  1906. + merged Attila's changes for interfaces, not tested yet
  1907. Revision 1.13 2000/11/01 23:04:38 peter
  1908. * tprocdef.fullprocname added for better casesensitve writing of
  1909. procedures
  1910. Revision 1.12 2000/10/31 22:02:52 peter
  1911. * symtable splitted, no real code changes
  1912. Revision 1.1.2.7 2000/10/16 19:43:04 pierre
  1913. * trying to correct class stabss once more
  1914. Revision 1.11 2000/10/15 07:47:53 peter
  1915. * unit names and procedure names are stored mixed case
  1916. Revision 1.10 2000/10/14 10:14:53 peter
  1917. * moehrendorf oct 2000 rewrite
  1918. Revision 1.9 2000/10/01 19:48:25 peter
  1919. * lot of compile updates for cg11
  1920. Revision 1.8 2000/09/24 15:06:29 peter
  1921. * use defines.inc
  1922. Revision 1.7 2000/08/27 16:11:54 peter
  1923. * moved some util functions from globals,cobjects to cutils
  1924. * splitted files into finput,fmodule
  1925. Revision 1.6 2000/08/21 11:27:45 pierre
  1926. * fix the stabs problems
  1927. Revision 1.5 2000/08/20 14:58:41 peter
  1928. * give fatal if objfpc/delphi mode things are found (merged)
  1929. Revision 1.1.2.6 2000/08/20 14:56:46 peter
  1930. * give fatal if objfpc/delphi mode things are found
  1931. Revision 1.4 2000/08/16 18:33:54 peter
  1932. * splitted namedobjectitem.next into indexnext and listnext so it
  1933. can be used in both lists
  1934. * don't allow "word = word" type definitions (merged)
  1935. Revision 1.3 2000/08/08 19:28:57 peter
  1936. * memdebug/memory patches (merged)
  1937. * only once illegal directive (merged)
  1938. }