symtable.pas 69 KB

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