symtable.pas 70 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233
  1. {
  2. $Id$
  3. Copyright (c) 1998-2000 by Florian Klaempfl, Pierre Muller
  4. This unit handles the symbol tables
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. unit symtable;
  19. {$i defines.inc}
  20. interface
  21. uses
  22. { common }
  23. cutils,cclasses,
  24. { global }
  25. globtype,tokens,
  26. { symtable }
  27. symconst,symbase,symtype,symdef,symsym,
  28. { ppu }
  29. ppu,symppu,
  30. { assembler }
  31. aasm
  32. ;
  33. {****************************************************************************
  34. Symtable types
  35. ****************************************************************************}
  36. type
  37. tstoredsymtable = class(tsymtable)
  38. private
  39. b_needs_init_final : boolean;
  40. procedure _needs_init_final(p : tnamedindexitem);
  41. procedure check_forward(sym : TNamedIndexItem);
  42. procedure labeldefined(p : TNamedIndexItem);
  43. procedure unitsymbolused(p : TNamedIndexItem);
  44. procedure varsymbolused(p : TNamedIndexItem);
  45. procedure TestPrivate(p : TNamedIndexItem);
  46. procedure objectprivatesymbolused(p : TNamedIndexItem);
  47. {$ifdef GDB}
  48. private
  49. asmoutput : taasmoutput;
  50. procedure concatstab(p : TNamedIndexItem);
  51. procedure resetstab(p : TNamedIndexItem);
  52. procedure concattypestab(p : TNamedIndexItem);
  53. {$endif}
  54. procedure unchain_overloads(p : TNamedIndexItem);
  55. procedure loaddefs(ppufile:tcompilerppufile);
  56. procedure loadsyms(ppufile:tcompilerppufile);
  57. procedure writedefs(ppufile:tcompilerppufile);
  58. procedure writesyms(ppufile:tcompilerppufile);
  59. public
  60. { load/write }
  61. procedure load(ppufile:tcompilerppufile);virtual;
  62. procedure write(ppufile:tcompilerppufile);virtual;
  63. procedure load_references(ppufile:tcompilerppufile;locals:boolean);virtual;
  64. procedure write_references(ppufile:tcompilerppufile;locals:boolean);virtual;
  65. procedure deref;virtual;
  66. procedure derefimpl;virtual;
  67. procedure insert(sym : tsymentry);override;
  68. function speedsearch(const s : stringid;speedvalue : cardinal) : tsymentry;override;
  69. procedure allsymbolsused;
  70. procedure allprivatesused;
  71. procedure allunitsused;
  72. procedure check_forwards;
  73. procedure checklabels;
  74. function needs_init_final : boolean;
  75. procedure unchain_overloaded;
  76. procedure chainoperators;
  77. {$ifdef GDB}
  78. procedure concatstabto(asmlist : taasmoutput);virtual;
  79. function getnewtypecount : word; override;
  80. {$endif GDB}
  81. procedure testfordefaultproperty(p : TNamedIndexItem);
  82. end;
  83. tabstractrecordsymtable = class(tstoredsymtable)
  84. public
  85. procedure load(ppufile:tcompilerppufile);override;
  86. procedure write(ppufile:tcompilerppufile);override;
  87. procedure load_references(ppufile:tcompilerppufile;locals:boolean);override;
  88. procedure write_references(ppufile:tcompilerppufile;locals:boolean);override;
  89. end;
  90. trecordsymtable = class(tabstractrecordsymtable)
  91. public
  92. constructor create;
  93. procedure insert_in(tsymt : tsymtable;offset : longint);
  94. end;
  95. tobjectsymtable = class(tabstractrecordsymtable)
  96. public
  97. constructor create(const n:string);
  98. procedure insert(sym : tsymentry);override;
  99. end;
  100. tabstractlocalsymtable = class(tstoredsymtable)
  101. public
  102. procedure load(ppufile:tcompilerppufile);override;
  103. procedure write(ppufile:tcompilerppufile);override;
  104. procedure load_references(ppufile:tcompilerppufile;locals:boolean);override;
  105. procedure write_references(ppufile:tcompilerppufile;locals:boolean);override;
  106. end;
  107. tlocalsymtable = class(tabstractlocalsymtable)
  108. public
  109. constructor create;
  110. procedure insert(sym : tsymentry);override;
  111. end;
  112. tparasymtable = class(tabstractlocalsymtable)
  113. public
  114. constructor create;
  115. procedure insert(sym : tsymentry);override;
  116. { change alignment for args only parasymtable }
  117. procedure set_alignment(_alignment : longint);
  118. end;
  119. tabstractunitsymtable = class(tstoredsymtable)
  120. public
  121. {$ifdef GDB}
  122. dbx_count : longint;
  123. prev_dbx_counter : plongint;
  124. dbx_count_ok : boolean;
  125. is_stab_written : boolean;
  126. {$endif GDB}
  127. constructor create(const n : string);
  128. {$ifdef GDB}
  129. procedure concattypestabto(asmlist : taasmoutput);
  130. {$endif GDB}
  131. end;
  132. tglobalsymtable = class(tabstractunitsymtable)
  133. public
  134. unittypecount : word;
  135. unitsym : tunitsym;
  136. constructor create(const n : string);
  137. destructor destroy;override;
  138. procedure load(ppufile:tcompilerppufile);override;
  139. procedure write(ppufile:tcompilerppufile);override;
  140. procedure insert(sym : tsymentry);override;
  141. {$ifdef GDB}
  142. function getnewtypecount : word; override;
  143. {$endif}
  144. end;
  145. tstaticsymtable = class(tabstractunitsymtable)
  146. public
  147. constructor create(const n : string);
  148. procedure load(ppufile:tcompilerppufile);override;
  149. procedure write(ppufile:tcompilerppufile);override;
  150. procedure load_references(ppufile:tcompilerppufile;locals:boolean);override;
  151. procedure write_references(ppufile:tcompilerppufile;locals:boolean);override;
  152. procedure insert(sym : tsymentry);override;
  153. end;
  154. twithsymtable = class(tsymtable)
  155. direct_with : boolean;
  156. { in fact it is a tnode }
  157. withnode : pointer;
  158. { tnode to load of direct with var }
  159. { already usable before firstwith
  160. needed for firstpass of function parameters PM }
  161. withrefnode : pointer;
  162. constructor create(aowner:tdef;asymsearch:TDictionary);
  163. destructor destroy;override;
  164. procedure clear;override;
  165. function speedsearch(const s : stringid;speedvalue : cardinal) : tsymentry;override;
  166. end;
  167. tstt_exceptsymtable = class(tsymtable)
  168. public
  169. constructor create;
  170. end;
  171. var
  172. constsymtable : tsymtable; { symtable were the constants can be inserted }
  173. systemunit : tglobalsymtable; { pointer to the system unit }
  174. read_member : boolean; { reading members of an symtable }
  175. lexlevel : longint; { level of code }
  176. { 1 for main procedure }
  177. { 2 for normal function or proc }
  178. { higher for locals }
  179. {****************************************************************************
  180. Functions
  181. ****************************************************************************}
  182. {*** Misc ***}
  183. procedure globaldef(const s : string;var t:ttype);
  184. function findunitsymtable(st:tsymtable):tsymtable;
  185. procedure duplicatesym(sym:tsym);
  186. {*** Search ***}
  187. function searchsym(const s : stringid;var srsym:tsym;var srsymtable:tsymtable):boolean;
  188. function searchsymonlyin(p : tsymtable;const s : stringid):tsym;
  189. function searchsystype(const s: stringid; var srsym: ttypesym): boolean;
  190. function searchsysvar(const s: stringid; var srsym: tvarsym; var symowner: tsymtable): boolean;
  191. function search_class_member(pd : tobjectdef;const s : string):tsym;
  192. {*** Object Helpers ***}
  193. function search_default_property(pd : tobjectdef) : tpropertysym;
  194. {*** symtable stack ***}
  195. procedure dellexlevel;
  196. procedure RestoreUnitSyms;
  197. {$ifdef DEBUG}
  198. procedure test_symtablestack;
  199. procedure list_symtablestack;
  200. {$endif DEBUG}
  201. {$ifdef UNITALIASES}
  202. type
  203. punit_alias = ^tunit_alias;
  204. tunit_alias = object(TNamedIndexItem)
  205. newname : pstring;
  206. constructor init(const n:string);
  207. destructor done;virtual;
  208. end;
  209. var
  210. unitaliases : pdictionary;
  211. procedure addunitalias(const n:string);
  212. function getunitalias(const n:string):string;
  213. {$endif UNITALIASES}
  214. {*** Init / Done ***}
  215. procedure InitSymtable;
  216. procedure DoneSymtable;
  217. type
  218. toverloaded_operators = array[NOTOKEN..last_overloaded] of tprocsym;
  219. var
  220. overloaded_operators : toverloaded_operators;
  221. { unequal is not equal}
  222. const
  223. overloaded_names : array [NOTOKEN..last_overloaded] of string[16] =
  224. ('error',
  225. 'plus','minus','star','slash','equal',
  226. 'greater','lower','greater_or_equal',
  227. 'lower_or_equal',
  228. 'sym_diff','starstar',
  229. 'as','is','in','or',
  230. 'and','div','mod','not','shl','shr','xor',
  231. 'assign');
  232. implementation
  233. uses
  234. { global }
  235. version,verbose,globals,
  236. { target }
  237. systems,
  238. { module }
  239. finput,fmodule,
  240. {$ifdef GDB}
  241. gdb,
  242. {$endif GDB}
  243. { codegen }
  244. cgbase
  245. ;
  246. var
  247. in_loading : boolean; { remove !!! }
  248. {*****************************************************************************
  249. TStoredSymtable
  250. *****************************************************************************}
  251. procedure tstoredsymtable.load(ppufile:tcompilerppufile);
  252. begin
  253. { load definitions }
  254. loaddefs(ppufile);
  255. { load symbols }
  256. loadsyms(ppufile);
  257. end;
  258. procedure tstoredsymtable.write(ppufile:tcompilerppufile);
  259. begin
  260. { write definitions }
  261. writedefs(ppufile);
  262. { write symbols }
  263. writesyms(ppufile);
  264. end;
  265. procedure tstoredsymtable.loaddefs(ppufile:tcompilerppufile);
  266. var
  267. hp : tdef;
  268. b : byte;
  269. begin
  270. { load start of definition section, which holds the amount of defs }
  271. if ppufile.readentry<>ibstartdefs then
  272. Message(unit_f_ppu_read_error);
  273. ppufile.getlongint;
  274. { read definitions }
  275. repeat
  276. b:=ppufile.readentry;
  277. case b of
  278. ibpointerdef : hp:=tpointerdef.load(ppufile);
  279. ibarraydef : hp:=tarraydef.load(ppufile);
  280. iborddef : hp:=torddef.load(ppufile);
  281. ibfloatdef : hp:=tfloatdef.load(ppufile);
  282. ibprocdef : hp:=tprocdef.load(ppufile);
  283. ibshortstringdef : hp:=tstringdef.loadshort(ppufile);
  284. iblongstringdef : hp:=tstringdef.loadlong(ppufile);
  285. ibansistringdef : hp:=tstringdef.loadansi(ppufile);
  286. ibwidestringdef : hp:=tstringdef.loadwide(ppufile);
  287. ibrecorddef : hp:=trecorddef.load(ppufile);
  288. ibobjectdef : hp:=tobjectdef.load(ppufile);
  289. ibenumdef : hp:=tenumdef.load(ppufile);
  290. ibsetdef : hp:=tsetdef.load(ppufile);
  291. ibprocvardef : hp:=tprocvardef.load(ppufile);
  292. ibfiledef : hp:=tfiledef.load(ppufile);
  293. ibclassrefdef : hp:=tclassrefdef.load(ppufile);
  294. ibformaldef : hp:=tformaldef.load(ppufile);
  295. ibvariantdef : hp:=tvariantdef.load(ppufile);
  296. ibenddefs : break;
  297. ibend : Message(unit_f_ppu_read_error);
  298. else
  299. Message1(unit_f_ppu_invalid_entry,tostr(b));
  300. end;
  301. hp.owner:=self;
  302. defindex.insert(hp);
  303. until false;
  304. end;
  305. procedure tstoredsymtable.loadsyms(ppufile:tcompilerppufile);
  306. var
  307. b : byte;
  308. sym : tsym;
  309. begin
  310. { load start of definition section, which holds the amount of defs }
  311. if ppufile.readentry<>ibstartsyms then
  312. Message(unit_f_ppu_read_error);
  313. { skip amount of symbols, not used currently }
  314. ppufile.getlongint;
  315. { load datasize,dataalignment of this symboltable }
  316. datasize:=ppufile.getlongint;
  317. dataalignment:=ppufile.getlongint;
  318. { now read the symbols }
  319. repeat
  320. b:=ppufile.readentry;
  321. case b of
  322. ibtypesym : sym:=ttypesym.load(ppufile);
  323. ibprocsym : sym:=tprocsym.load(ppufile);
  324. ibconstsym : sym:=tconstsym.load(ppufile);
  325. ibvarsym : sym:=tvarsym.load(ppufile);
  326. ibfuncretsym : sym:=tfuncretsym.load(ppufile);
  327. ibabsolutesym : sym:=tabsolutesym.load(ppufile);
  328. ibenumsym : sym:=tenumsym.load(ppufile);
  329. ibtypedconstsym : sym:=ttypedconstsym.load(ppufile);
  330. ibpropertysym : sym:=tpropertysym.load(ppufile);
  331. ibunitsym : sym:=tunitsym.load(ppufile);
  332. iblabelsym : sym:=tlabelsym.load(ppufile);
  333. ibsyssym : sym:=tsyssym.load(ppufile);
  334. ibrttisym : sym:=trttisym.load(ppufile);
  335. ibendsyms : break;
  336. ibend : Message(unit_f_ppu_read_error);
  337. else
  338. Message1(unit_f_ppu_invalid_entry,tostr(b));
  339. end;
  340. sym.owner:=self;
  341. symindex.insert(sym);
  342. symsearch.insert(sym);
  343. until false;
  344. end;
  345. procedure tstoredsymtable.writedefs(ppufile:tcompilerppufile);
  346. var
  347. pd : tstoreddef;
  348. begin
  349. { each definition get a number, write then the amount of defs to the
  350. ibstartdef entry }
  351. ppufile.putlongint(defindex.count);
  352. ppufile.writeentry(ibstartdefs);
  353. { now write the definition }
  354. pd:=tstoreddef(defindex.first);
  355. while assigned(pd) do
  356. begin
  357. pd.write(ppufile);
  358. pd:=tstoreddef(pd.indexnext);
  359. end;
  360. { write end of definitions }
  361. ppufile.writeentry(ibenddefs);
  362. end;
  363. procedure tstoredsymtable.writesyms(ppufile:tcompilerppufile);
  364. var
  365. pd : tstoredsym;
  366. begin
  367. { each definition get a number, write then the amount of syms and the
  368. datasize to the ibsymdef entry }
  369. ppufile.putlongint(symindex.count);
  370. ppufile.putlongint(datasize);
  371. ppufile.putlongint(dataalignment);
  372. ppufile.writeentry(ibstartsyms);
  373. { foreach is used to write all symbols }
  374. pd:=tstoredsym(symindex.first);
  375. while assigned(pd) do
  376. begin
  377. pd.write(ppufile);
  378. pd:=tstoredsym(pd.indexnext);
  379. end;
  380. { end of symbols }
  381. ppufile.writeentry(ibendsyms);
  382. end;
  383. procedure tstoredsymtable.load_references(ppufile:tcompilerppufile;locals:boolean);
  384. var
  385. b : byte;
  386. sym : tstoredsym;
  387. prdef : tstoreddef;
  388. begin
  389. b:=ppufile.readentry;
  390. if b <> ibbeginsymtablebrowser then
  391. Message1(unit_f_ppu_invalid_entry,tostr(b));
  392. repeat
  393. b:=ppufile.readentry;
  394. case b of
  395. ibsymref :
  396. begin
  397. sym:=tstoredsym(ppufile.getderef);
  398. resolvesym(tsym(sym));
  399. if assigned(sym) then
  400. sym.load_references(ppufile,locals);
  401. end;
  402. ibdefref :
  403. begin
  404. prdef:=tstoreddef(ppufile.getderef);
  405. resolvedef(tdef(prdef));
  406. if assigned(prdef) then
  407. begin
  408. if prdef.deftype<>procdef then
  409. Message(unit_f_ppu_read_error);
  410. tprocdef(prdef).load_references(ppufile,locals);
  411. end;
  412. end;
  413. ibendsymtablebrowser :
  414. break;
  415. else
  416. Message1(unit_f_ppu_invalid_entry,tostr(b));
  417. end;
  418. until false;
  419. end;
  420. procedure tstoredsymtable.write_references(ppufile:tcompilerppufile;locals:boolean);
  421. var
  422. pd : tstoredsym;
  423. begin
  424. ppufile.writeentry(ibbeginsymtablebrowser);
  425. { write all symbols }
  426. pd:=tstoredsym(symindex.first);
  427. while assigned(pd) do
  428. begin
  429. pd.write_references(ppufile,locals);
  430. pd:=tstoredsym(pd.indexnext);
  431. end;
  432. ppufile.writeentry(ibendsymtablebrowser);
  433. end;
  434. procedure tstoredsymtable.deref;
  435. var
  436. hp : tdef;
  437. hs : tsym;
  438. begin
  439. { deref the interface definitions }
  440. hp:=tdef(defindex.first);
  441. while assigned(hp) do
  442. begin
  443. hp.deref;
  444. hp:=tdef(hp.indexnext);
  445. end;
  446. { first deref the interface ttype symbols }
  447. hs:=tsym(symindex.first);
  448. while assigned(hs) do
  449. begin
  450. if hs.typ=typesym then
  451. hs.deref;
  452. hs:=tsym(hs.indexnext);
  453. end;
  454. { deref the interface symbols }
  455. hs:=tsym(symindex.first);
  456. while assigned(hs) do
  457. begin
  458. if hs.typ<>typesym then
  459. hs.deref;
  460. hs:=tsym(hs.indexnext);
  461. end;
  462. end;
  463. procedure tstoredsymtable.derefimpl;
  464. var
  465. hp : tdef;
  466. begin
  467. { deref the implementation part of definitions }
  468. hp:=tdef(defindex.first);
  469. while assigned(hp) do
  470. begin
  471. hp.derefimpl;
  472. hp:=tdef(hp.indexnext);
  473. end;
  474. end;
  475. procedure tstoredsymtable.insert(sym:tsymentry);
  476. var
  477. hsym : tsym;
  478. begin
  479. { set owner and sym indexnb }
  480. sym.owner:=self;
  481. { 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_tp 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. p : tprocsym;
  741. pd : pprocdeflist;
  742. t : ttoken;
  743. def : tprocdef;
  744. srsym : tsym;
  745. srsymtable,
  746. storesymtablestack : tsymtable;
  747. begin
  748. storesymtablestack:=symtablestack;
  749. symtablestack:=self;
  750. make_ref:=false;
  751. for t:=first_overloaded to last_overloaded do
  752. begin
  753. p:=nil;
  754. def:=nil;
  755. overloaded_operators[t]:=nil;
  756. { each operator has a unique lowercased internal name PM }
  757. while assigned(symtablestack) do
  758. begin
  759. searchsym(overloaded_names[t],srsym,srsymtable);
  760. if not assigned(srsym) then
  761. begin
  762. if (t=_STARSTAR) then
  763. begin
  764. symtablestack:=systemunit;
  765. searchsym('POWER',srsym,srsymtable);
  766. end;
  767. end;
  768. if assigned(srsym) then
  769. begin
  770. if (srsym.typ<>procsym) then
  771. internalerror(12344321);
  772. { use this procsym as start ? }
  773. if not assigned(overloaded_operators[t]) then
  774. overloaded_operators[t]:=tprocsym(srsym)
  775. else
  776. begin
  777. { already got a procsym, only add defs of the current procsym }
  778. pd:=tprocsym(srsym).defs;
  779. while assigned(pd) do
  780. begin
  781. overloaded_operators[t].addprocdef(pd^.def);
  782. pd:=pd^.next;
  783. end;
  784. end;
  785. symtablestack:=srsym.owner.next;
  786. end
  787. else
  788. begin
  789. symtablestack:=nil;
  790. end;
  791. { search for same procsym in other units }
  792. end;
  793. symtablestack:=self;
  794. end;
  795. make_ref:=true;
  796. symtablestack:=storesymtablestack;
  797. end;
  798. {***********************************************
  799. Process all entries
  800. ***********************************************}
  801. { checks, if all procsyms and methods are defined }
  802. procedure tstoredsymtable.check_forwards;
  803. begin
  804. foreach({$ifdef FPCPROCVAR}@{$endif}check_forward);
  805. end;
  806. procedure tstoredsymtable.checklabels;
  807. begin
  808. foreach({$ifdef FPCPROCVAR}@{$endif}labeldefined);
  809. end;
  810. procedure tstoredsymtable.allunitsused;
  811. begin
  812. foreach({$ifdef FPCPROCVAR}@{$endif}unitsymbolused);
  813. end;
  814. procedure tstoredsymtable.allsymbolsused;
  815. begin
  816. foreach({$ifdef FPCPROCVAR}@{$endif}varsymbolused);
  817. end;
  818. procedure tstoredsymtable.allprivatesused;
  819. begin
  820. foreach({$ifdef FPCPROCVAR}@{$endif}objectprivatesymbolused);
  821. end;
  822. procedure tstoredsymtable.unchain_overloaded;
  823. begin
  824. foreach({$ifdef FPCPROCVAR}@{$endif}unchain_overloads);
  825. end;
  826. {$ifdef GDB}
  827. procedure tstoredsymtable.concatstabto(asmlist : taasmoutput);
  828. begin
  829. asmoutput:=asmlist;
  830. if symtabletype in [inlineparasymtable,inlinelocalsymtable] then
  831. foreach({$ifdef FPCPROCVAR}@{$endif}resetstab);
  832. foreach({$ifdef FPCPROCVAR}@{$endif}concatstab);
  833. end;
  834. {$endif}
  835. { returns true, if p contains data which needs init/final code }
  836. function tstoredsymtable.needs_init_final : boolean;
  837. begin
  838. b_needs_init_final:=false;
  839. foreach({$ifdef FPCPROCVAR}@{$endif}_needs_init_final);
  840. needs_init_final:=b_needs_init_final;
  841. end;
  842. {****************************************************************************
  843. TAbstractRecordSymtable
  844. ****************************************************************************}
  845. procedure tabstractrecordsymtable.load(ppufile:tcompilerppufile);
  846. var
  847. storesymtable : tsymtable;
  848. begin
  849. storesymtable:=aktrecordsymtable;
  850. aktrecordsymtable:=self;
  851. inherited load(ppufile);
  852. aktrecordsymtable:=storesymtable;
  853. end;
  854. procedure tabstractrecordsymtable.write(ppufile:tcompilerppufile);
  855. var
  856. oldtyp : byte;
  857. storesymtable : tsymtable;
  858. begin
  859. storesymtable:=aktrecordsymtable;
  860. aktrecordsymtable:=self;
  861. oldtyp:=ppufile.entrytyp;
  862. ppufile.entrytyp:=subentryid;
  863. inherited write(ppufile);
  864. ppufile.entrytyp:=oldtyp;
  865. aktrecordsymtable:=storesymtable;
  866. end;
  867. procedure tabstractrecordsymtable.load_references(ppufile:tcompilerppufile;locals:boolean);
  868. var
  869. storesymtable : tsymtable;
  870. begin
  871. storesymtable:=aktrecordsymtable;
  872. aktrecordsymtable:=self;
  873. inherited load_references(ppufile,locals);
  874. aktrecordsymtable:=storesymtable;
  875. end;
  876. procedure tabstractrecordsymtable.write_references(ppufile:tcompilerppufile;locals:boolean);
  877. var
  878. storesymtable : tsymtable;
  879. begin
  880. storesymtable:=aktrecordsymtable;
  881. aktrecordsymtable:=self;
  882. inherited write_references(ppufile,locals);
  883. aktrecordsymtable:=storesymtable;
  884. end;
  885. procedure TStoredSymtable._needs_init_final(p : tnamedindexitem);
  886. begin
  887. if (not b_needs_init_final) and
  888. (tsym(p).typ=varsym) and
  889. assigned(tvarsym(p).vartype.def) and
  890. not is_class(tvarsym(p).vartype.def) and
  891. tstoreddef(tvarsym(p).vartype.def).needs_inittable then
  892. b_needs_init_final:=true;
  893. end;
  894. {****************************************************************************
  895. TRecordSymtable
  896. ****************************************************************************}
  897. constructor trecordsymtable.create;
  898. begin
  899. inherited create('');
  900. symtabletype:=recordsymtable;
  901. end;
  902. { this procedure is reserved for inserting case variant into
  903. a record symtable }
  904. { the offset is the location of the start of the variant
  905. and datasize and dataalignment corresponds to
  906. the complete size (see code in pdecl unit) PM }
  907. procedure trecordsymtable.insert_in(tsymt : tsymtable;offset : longint);
  908. var
  909. ps,nps : tvarsym;
  910. pd,npd : tdef;
  911. storesize,storealign : longint;
  912. begin
  913. storesize:=tsymt.datasize;
  914. storealign:=tsymt.dataalignment;
  915. tsymt.datasize:=offset;
  916. ps:=tvarsym(symindex.first);
  917. while assigned(ps) do
  918. begin
  919. { this is used to insert case variant into the main
  920. record }
  921. tsymt.datasize:=ps.address+offset;
  922. nps:=tvarsym(ps.indexnext);
  923. symindex.deleteindex(ps);
  924. ps.left:=nil;
  925. ps.right:=nil;
  926. tsymt.insert(ps);
  927. ps:=nps;
  928. end;
  929. pd:=tdef(defindex.first);
  930. while assigned(pd) do
  931. begin
  932. npd:=tdef(pd.indexnext);
  933. defindex.deleteindex(pd);
  934. pd.left:=nil;
  935. pd.right:=nil;
  936. tsymt.registerdef(pd);
  937. pd:=npd;
  938. end;
  939. tsymt.datasize:=storesize;
  940. tsymt.dataalignment:=storealign;
  941. end;
  942. {****************************************************************************
  943. TObjectSymtable
  944. ****************************************************************************}
  945. constructor tobjectsymtable.create(const n:string);
  946. begin
  947. inherited create(n);
  948. symtabletype:=objectsymtable;
  949. end;
  950. procedure tobjectsymtable.insert(sym:tsymentry);
  951. var
  952. hsym : tsym;
  953. begin
  954. { check for duplicate field id in inherited classes }
  955. if (sym.typ=varsym) and
  956. assigned(defowner) and
  957. (
  958. not(m_delphi in aktmodeswitches) or
  959. is_object(tdef(defowner))
  960. ) then
  961. begin
  962. { but private ids can be reused }
  963. hsym:=search_class_member(tobjectdef(defowner),sym.name);
  964. if assigned(hsym) and
  965. (not(sp_private in hsym.symoptions) or
  966. (hsym.owner.defowner.owner.unitid=0)) 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_tp 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. if assigned(hsym) and
  1103. { private ids can be reused }
  1104. (not(sp_private in hsym.symoptions) or
  1105. (hsym.owner.defowner.owner.unitid=0)) then
  1106. begin
  1107. { delphi allows to reuse the names in a class, but not
  1108. in object (tp7 compatible) }
  1109. if not((m_delphi in aktmodeswitches) and
  1110. is_class(procinfo^._class)) then
  1111. begin
  1112. DuplicateSym(hsym);
  1113. exit;
  1114. end;
  1115. end;
  1116. end;
  1117. inherited insert(sym);
  1118. end;
  1119. procedure tparasymtable.set_alignment(_alignment : longint);
  1120. var
  1121. sym : tvarsym;
  1122. l : longint;
  1123. begin
  1124. dataalignment:=_alignment;
  1125. sym:=tvarsym(symindex.first);
  1126. datasize:=0;
  1127. { there can be only varsyms }
  1128. while assigned(sym) do
  1129. begin
  1130. l:=sym.getpushsize;
  1131. sym.address:=datasize;
  1132. datasize:=align(datasize+l,dataalignment);
  1133. sym:=tvarsym(sym.indexnext);
  1134. end;
  1135. end;
  1136. {****************************************************************************
  1137. TAbstractUnitSymtable
  1138. ****************************************************************************}
  1139. constructor tabstractunitsymtable.create(const n : string);
  1140. begin
  1141. inherited create(n);
  1142. symsearch.usehash;
  1143. {$ifdef GDB}
  1144. { reset GDB things }
  1145. prev_dbx_counter := dbx_counter;
  1146. dbx_counter := nil;
  1147. is_stab_written:=false;
  1148. dbx_count := -1;
  1149. {$endif GDB}
  1150. end;
  1151. {$ifdef GDB}
  1152. procedure tabstractunitsymtable.concattypestabto(asmlist : taasmoutput);
  1153. var prev_dbx_count : plongint;
  1154. begin
  1155. if is_stab_written then
  1156. exit;
  1157. if not assigned(name) then
  1158. name := stringdup('Main_program');
  1159. if (symtabletype = globalsymtable) and
  1160. (current_module.globalsymtable<>self) then
  1161. begin
  1162. unitid:=current_module.unitcount;
  1163. inc(current_module.unitcount);
  1164. end;
  1165. asmList.concat(Tai_asm_comment.Create(strpnew('Begin unit '+name^+' has index '+tostr(unitid))));
  1166. if cs_gdb_dbx in aktglobalswitches then
  1167. begin
  1168. if dbx_count_ok then
  1169. begin
  1170. asmList.concat(Tai_asm_comment.Create(strpnew('"repeated" unit '+name^
  1171. +' has index '+tostr(unitid)+' dbx count = '+tostr(dbx_count))));
  1172. asmList.concat(Tai_stabs.Create(strpnew('"'+name^+'",'
  1173. +tostr(N_EXCL)+',0,0,'+tostr(dbx_count))));
  1174. exit;
  1175. end
  1176. else if (current_module.globalsymtable<>self) then
  1177. begin
  1178. prev_dbx_count := dbx_counter;
  1179. dbx_counter := nil;
  1180. do_count_dbx:=false;
  1181. if (symtabletype = globalsymtable) and (unitid<>0) then
  1182. asmList.concat(Tai_stabs.Create(strpnew('"'+name^+'",'+tostr(N_BINCL)+',0,0,0')));
  1183. dbx_counter := @dbx_count;
  1184. dbx_count:=0;
  1185. do_count_dbx:=assigned(dbx_counter);
  1186. end;
  1187. end;
  1188. asmoutput:=asmlist;
  1189. foreach({$ifdef FPCPROCVAR}@{$endif}concattypestab);
  1190. if cs_gdb_dbx in aktglobalswitches then
  1191. begin
  1192. if (current_module.globalsymtable<>self) then
  1193. begin
  1194. dbx_counter := prev_dbx_count;
  1195. do_count_dbx:=false;
  1196. asmList.concat(Tai_asm_comment.Create(strpnew('End unit '+name^
  1197. +' has index '+tostr(unitid))));
  1198. asmList.concat(Tai_stabs.Create(strpnew('"'+name^+'",'
  1199. +tostr(N_EINCL)+',0,0,0')));
  1200. do_count_dbx:=assigned(dbx_counter);
  1201. dbx_count_ok := {true}false;
  1202. end;
  1203. end;
  1204. is_stab_written:=true;
  1205. end;
  1206. {$endif GDB}
  1207. {****************************************************************************
  1208. TStaticSymtable
  1209. ****************************************************************************}
  1210. constructor tstaticsymtable.create(const n : string);
  1211. begin
  1212. inherited create(n);
  1213. symtabletype:=staticsymtable;
  1214. end;
  1215. procedure tstaticsymtable.load(ppufile:tcompilerppufile);
  1216. begin
  1217. aktstaticsymtable:=self;
  1218. next:=symtablestack;
  1219. symtablestack:=self;
  1220. inherited load(ppufile);
  1221. { now we can deref the syms and defs }
  1222. deref;
  1223. { restore symtablestack }
  1224. symtablestack:=next;
  1225. end;
  1226. procedure tstaticsymtable.write(ppufile:tcompilerppufile);
  1227. begin
  1228. aktstaticsymtable:=self;
  1229. inherited write(ppufile);
  1230. end;
  1231. procedure tstaticsymtable.load_references(ppufile:tcompilerppufile;locals:boolean);
  1232. begin
  1233. aktstaticsymtable:=self;
  1234. inherited load_references(ppufile,locals);
  1235. end;
  1236. procedure tstaticsymtable.write_references(ppufile:tcompilerppufile;locals:boolean);
  1237. begin
  1238. aktstaticsymtable:=self;
  1239. inherited write_references(ppufile,locals);
  1240. end;
  1241. procedure tstaticsymtable.insert(sym:tsymentry);
  1242. var
  1243. hsym : tsym;
  1244. begin
  1245. { also check the global symtable }
  1246. if assigned(next) and
  1247. (next.unitid=0) then
  1248. begin
  1249. hsym:=tsym(next.search(sym.name));
  1250. if assigned(hsym) then
  1251. begin
  1252. DuplicateSym(hsym);
  1253. exit;
  1254. end;
  1255. end;
  1256. inherited insert(sym);
  1257. end;
  1258. {****************************************************************************
  1259. TGlobalSymtable
  1260. ****************************************************************************}
  1261. constructor tglobalsymtable.create(const n : string);
  1262. begin
  1263. inherited create(n);
  1264. symtabletype:=globalsymtable;
  1265. unitid:=0;
  1266. unitsym:=nil;
  1267. {$ifdef GDB}
  1268. if cs_gdb_dbx in aktglobalswitches then
  1269. begin
  1270. dbx_count := 0;
  1271. unittypecount:=1;
  1272. pglobaltypecount := @unittypecount;
  1273. {unitid:=current_module.unitcount;}
  1274. debugList.concat(Tai_asm_comment.Create(strpnew('Global '+name^+' has index '+tostr(unitid))));
  1275. debugList.concat(Tai_stabs.Create(strpnew('"'+name^+'",'+tostr(N_BINCL)+',0,0,0')));
  1276. {inc(current_module.unitcount);}
  1277. dbx_count_ok:=false;
  1278. dbx_counter:=@dbx_count;
  1279. do_count_dbx:=true;
  1280. end;
  1281. {$endif GDB}
  1282. end;
  1283. destructor tglobalsymtable.destroy;
  1284. var
  1285. pus : tunitsym;
  1286. begin
  1287. pus:=unitsym;
  1288. while assigned(pus) do
  1289. begin
  1290. unitsym:=pus.prevsym;
  1291. pus.prevsym:=nil;
  1292. pus.unitsymtable:=nil;
  1293. pus:=unitsym;
  1294. end;
  1295. inherited destroy;
  1296. end;
  1297. procedure tglobalsymtable.load(ppufile:tcompilerppufile);
  1298. {$ifdef GDB}
  1299. var
  1300. storeGlobalTypeCount : pword;
  1301. {$endif GDB}
  1302. begin
  1303. {$ifdef GDB}
  1304. if cs_gdb_dbx in aktglobalswitches then
  1305. begin
  1306. UnitTypeCount:=1;
  1307. storeGlobalTypeCount:=PGlobalTypeCount;
  1308. PglobalTypeCount:=@UnitTypeCount;
  1309. end;
  1310. {$endif GDB}
  1311. symtablelevel:=0;
  1312. {$ifndef NEWMAP}
  1313. current_module.map^[0]:=self;
  1314. {$else NEWMAP}
  1315. current_module.globalsymtable:=self;
  1316. {$endif NEWMAP}
  1317. next:=symtablestack;
  1318. symtablestack:=self;
  1319. inherited load(ppufile);
  1320. { now we can deref the syms and defs }
  1321. deref;
  1322. { restore symtablestack }
  1323. symtablestack:=next;
  1324. {$ifdef NEWMAP}
  1325. { necessary for dependencies }
  1326. current_module.globalsymtable:=nil;
  1327. {$endif NEWMAP}
  1328. end;
  1329. procedure tglobalsymtable.write(ppufile:tcompilerppufile);
  1330. begin
  1331. { write the symtable entries }
  1332. inherited write(ppufile);
  1333. { write dbx count }
  1334. {$ifdef GDB}
  1335. if cs_gdb_dbx in aktglobalswitches then
  1336. begin
  1337. {$IfDef EXTDEBUG}
  1338. writeln('Writing dbx_count ',dbx_count,' in unit ',name^,'.ppu');
  1339. {$ENDIF EXTDEBUG}
  1340. ppufile.do_crc:=false;
  1341. ppufile.putlongint(dbx_count);
  1342. ppufile.writeentry(ibdbxcount);
  1343. ppufile.do_crc:=true;
  1344. end;
  1345. {$endif GDB}
  1346. end;
  1347. procedure tglobalsymtable.insert(sym:tsymentry);
  1348. var
  1349. hsym : tsym;
  1350. begin
  1351. { also check the global symtable }
  1352. if assigned(next) and
  1353. (next.unitid=0) then
  1354. begin
  1355. hsym:=tsym(next.search(sym.name));
  1356. if assigned(hsym) then
  1357. begin
  1358. DuplicateSym(hsym);
  1359. exit;
  1360. end;
  1361. end;
  1362. hsym:=tsym(search(sym.name));
  1363. if assigned(hsym) then
  1364. begin
  1365. { Delphi you can have a symbol with the same name as the
  1366. unit, the unit can then not be accessed anymore using
  1367. <unit>.<id>, so we can hide the symbol }
  1368. if (m_tp in aktmodeswitches) and
  1369. (hsym.typ=symconst.unitsym) then
  1370. hsym.owner.rename(hsym.name,'hidden'+hsym.name)
  1371. else
  1372. begin
  1373. DuplicateSym(hsym);
  1374. exit;
  1375. end;
  1376. end;
  1377. inherited insert(sym);
  1378. end;
  1379. {$ifdef GDB}
  1380. function tglobalsymtable.getnewtypecount : word;
  1381. begin
  1382. if not (cs_gdb_dbx in aktglobalswitches) then
  1383. getnewtypecount:=inherited getnewtypecount
  1384. else
  1385. begin
  1386. getnewtypecount:=unittypecount;
  1387. inc(unittypecount);
  1388. end;
  1389. end;
  1390. {$endif}
  1391. {****************************************************************************
  1392. TWITHSYMTABLE
  1393. ****************************************************************************}
  1394. constructor twithsymtable.create(aowner:tdef;asymsearch:TDictionary);
  1395. begin
  1396. inherited create('');
  1397. symtabletype:=withsymtable;
  1398. direct_with:=false;
  1399. withnode:=nil;
  1400. withrefnode:=nil;
  1401. { we don't need the symsearch }
  1402. symsearch.free;
  1403. { set the defaults }
  1404. symsearch:=asymsearch;
  1405. defowner:=aowner;
  1406. end;
  1407. destructor twithsymtable.destroy;
  1408. begin
  1409. symsearch:=nil;
  1410. inherited destroy;
  1411. end;
  1412. procedure twithsymtable.clear;
  1413. begin
  1414. { remove no entry from a withsymtable as it is only a pointer to the
  1415. recorddef or objectdef symtable }
  1416. end;
  1417. function twithsymtable.speedsearch(const s : stringid;speedvalue : cardinal) : tsymentry;
  1418. var
  1419. hp : tsym;
  1420. begin
  1421. hp:=tsym(inherited speedsearch(s, speedvalue));
  1422. { skip private members that can't be seen }
  1423. if assigned(hp) and
  1424. (sp_private in hp.symoptions) and
  1425. (hp.owner.symtabletype=objectsymtable) and
  1426. (hp.owner.defowner.owner.symtabletype=globalsymtable) and
  1427. (hp.owner.defowner.owner.unitid<>0) then
  1428. hp:=nil;
  1429. speedsearch:=hp;
  1430. end;
  1431. {****************************************************************************
  1432. TSTT_ExceptionSymtable
  1433. ****************************************************************************}
  1434. constructor tstt_exceptsymtable.create;
  1435. begin
  1436. inherited create('');
  1437. symtabletype:=stt_exceptsymtable;
  1438. end;
  1439. {*****************************************************************************
  1440. Helper Routines
  1441. *****************************************************************************}
  1442. function findunitsymtable(st:tsymtable):tsymtable;
  1443. begin
  1444. findunitsymtable:=nil;
  1445. repeat
  1446. if not assigned(st) then
  1447. internalerror(5566561);
  1448. case st.symtabletype of
  1449. localsymtable,
  1450. parasymtable,
  1451. staticsymtable :
  1452. break;
  1453. globalsymtable :
  1454. begin
  1455. findunitsymtable:=st;
  1456. break;
  1457. end;
  1458. objectsymtable,
  1459. recordsymtable :
  1460. st:=st.defowner.owner;
  1461. else
  1462. internalerror(5566562);
  1463. end;
  1464. until false;
  1465. end;
  1466. procedure duplicatesym(sym:tsym);
  1467. var
  1468. st : tsymtable;
  1469. begin
  1470. Message1(sym_e_duplicate_id,sym.realname);
  1471. st:=findunitsymtable(sym.owner);
  1472. with sym.fileinfo do
  1473. begin
  1474. if assigned(st) and (st.unitid<>0) then
  1475. Message2(sym_h_duplicate_id_where,'unit '+st.name^,tostr(line))
  1476. else
  1477. Message2(sym_h_duplicate_id_where,current_module.sourcefiles.get_file_name(fileindex),tostr(line));
  1478. end;
  1479. end;
  1480. {*****************************************************************************
  1481. Search
  1482. *****************************************************************************}
  1483. function searchsym(const s : stringid;var srsym:tsym;var srsymtable:tsymtable):boolean;
  1484. var
  1485. speedvalue : cardinal;
  1486. begin
  1487. speedvalue:=getspeedvalue(s);
  1488. srsymtable:=symtablestack;
  1489. while assigned(srsymtable) do
  1490. begin
  1491. srsym:=tsym(srsymtable.speedsearch(s,speedvalue));
  1492. if assigned(srsym) then
  1493. begin
  1494. searchsym:=true;
  1495. exit;
  1496. end
  1497. else
  1498. srsymtable:=srsymtable.next;
  1499. end;
  1500. searchsym:=false;
  1501. end;
  1502. function searchsymonlyin(p : tsymtable;const s : stringid):tsym;
  1503. var
  1504. srsym : tsym;
  1505. begin
  1506. { the caller have to take care if srsym=nil }
  1507. if assigned(p) then
  1508. begin
  1509. srsym:=tsym(p.search(s));
  1510. if assigned(srsym) then
  1511. begin
  1512. searchsymonlyin:=srsym;
  1513. exit;
  1514. end;
  1515. { also check in the local symtbale if it exists }
  1516. if (p=tsymtable(current_module.globalsymtable)) then
  1517. begin
  1518. srsym:=tsym(current_module.localsymtable.search(s));
  1519. if assigned(srsym) then
  1520. begin
  1521. searchsymonlyin:=srsym;
  1522. exit;
  1523. end;
  1524. end
  1525. end;
  1526. searchsymonlyin:=nil;
  1527. end;
  1528. function searchsystype(const s: stringid; var srsym: ttypesym): boolean;
  1529. var
  1530. symowner: tsymtable;
  1531. begin
  1532. if not(cs_compilesystem in aktmoduleswitches) then
  1533. srsym := ttypesym(searchsymonlyin(systemunit,s))
  1534. else
  1535. searchsym(s,srsym,symowner);
  1536. searchsystype :=
  1537. assigned(srsym) and
  1538. (srsym.typ = typesym);
  1539. end;
  1540. function searchsysvar(const s: stringid; var srsym: tvarsym; var symowner: tsymtable): boolean;
  1541. begin
  1542. if not(cs_compilesystem in aktmoduleswitches) then
  1543. begin
  1544. srsym := tvarsym(searchsymonlyin(systemunit,s));
  1545. symowner := systemunit;
  1546. end
  1547. else
  1548. searchsym(s,srsym,symowner);
  1549. searchsysvar :=
  1550. assigned(srsym) and
  1551. (srsym.typ = varsym);
  1552. end;
  1553. function search_class_member(pd : tobjectdef;const s : string):tsym;
  1554. { searches n in symtable of pd and all anchestors }
  1555. var
  1556. speedvalue : cardinal;
  1557. srsym : tsym;
  1558. begin
  1559. speedvalue:=getspeedvalue(s);
  1560. while assigned(pd) do
  1561. begin
  1562. srsym:=tsym(pd.symtable.speedsearch(s,speedvalue));
  1563. if assigned(srsym) then
  1564. begin
  1565. search_class_member:=srsym;
  1566. exit;
  1567. end;
  1568. pd:=pd.childof;
  1569. end;
  1570. search_class_member:=nil;
  1571. end;
  1572. {*****************************************************************************
  1573. Definition Helpers
  1574. *****************************************************************************}
  1575. procedure globaldef(const s : string;var t:ttype);
  1576. var st : string;
  1577. symt : tsymtable;
  1578. srsym : tsym;
  1579. srsymtable : tsymtable;
  1580. begin
  1581. srsym := nil;
  1582. if pos('.',s) > 0 then
  1583. begin
  1584. st := copy(s,1,pos('.',s)-1);
  1585. searchsym(st,srsym,srsymtable);
  1586. st := copy(s,pos('.',s)+1,255);
  1587. if assigned(srsym) then
  1588. begin
  1589. if srsym.typ = unitsym then
  1590. begin
  1591. symt := tunitsym(srsym).unitsymtable;
  1592. srsym := tsym(symt.search(st));
  1593. end else srsym := nil;
  1594. end;
  1595. end else st := s;
  1596. if srsym = nil then
  1597. searchsym(st,srsym,srsymtable);
  1598. if srsym = nil then
  1599. srsym:=searchsymonlyin(systemunit,st);
  1600. if (not assigned(srsym)) or
  1601. (srsym.typ<>typesym) then
  1602. begin
  1603. Message(type_e_type_id_expected);
  1604. t:=generrortype;
  1605. exit;
  1606. end;
  1607. t := ttypesym(srsym).restype;
  1608. end;
  1609. {****************************************************************************
  1610. Object Helpers
  1611. ****************************************************************************}
  1612. var
  1613. _defaultprop : tpropertysym;
  1614. procedure tstoredsymtable.testfordefaultproperty(p : TNamedIndexItem);
  1615. begin
  1616. if (tsym(p).typ=propertysym) and
  1617. (ppo_defaultproperty in tpropertysym(p).propoptions) then
  1618. _defaultprop:=tpropertysym(p);
  1619. end;
  1620. function search_default_property(pd : tobjectdef) : tpropertysym;
  1621. { returns the default property of a class, searches also anchestors }
  1622. begin
  1623. _defaultprop:=nil;
  1624. while assigned(pd) do
  1625. begin
  1626. pd.symtable.foreach({$ifdef FPCPROCVAR}@{$endif}tstoredsymtable(pd.symtable).testfordefaultproperty);
  1627. if assigned(_defaultprop) then
  1628. break;
  1629. pd:=pd.childof;
  1630. end;
  1631. search_default_property:=_defaultprop;
  1632. end;
  1633. {$ifdef UNITALIASES}
  1634. {****************************************************************************
  1635. TUNIT_ALIAS
  1636. ****************************************************************************}
  1637. constructor tunit_alias.create(const n:string);
  1638. var
  1639. i : longint;
  1640. begin
  1641. i:=pos('=',n);
  1642. if i=0 then
  1643. fail;
  1644. inherited createname(Copy(n,1,i-1));
  1645. newname:=stringdup(Copy(n,i+1,255));
  1646. end;
  1647. destructor tunit_alias.destroy;
  1648. begin
  1649. stringdispose(newname);
  1650. inherited destroy;
  1651. end;
  1652. procedure addunitalias(const n:string);
  1653. begin
  1654. unitaliases^.insert(tunit_alias,init(Upper(n))));
  1655. end;
  1656. function getunitalias(const n:string):string;
  1657. var
  1658. p : punit_alias;
  1659. begin
  1660. p:=punit_alias(unitaliases^.search(Upper(n)));
  1661. if assigned(p) then
  1662. getunitalias:=punit_alias(p).newname^
  1663. else
  1664. getunitalias:=n;
  1665. end;
  1666. {$endif UNITALIASES}
  1667. {****************************************************************************
  1668. Symtable Stack
  1669. ****************************************************************************}
  1670. procedure dellexlevel;
  1671. var
  1672. p : tsymtable;
  1673. begin
  1674. p:=symtablestack;
  1675. symtablestack:=p.next;
  1676. { symbol tables of unit interfaces are never disposed }
  1677. { this is handle by the unit unitm }
  1678. if not(p.symtabletype in [globalsymtable,stt_exceptsymtable]) then
  1679. p.free;
  1680. end;
  1681. procedure RestoreUnitSyms;
  1682. var
  1683. p : tsymtable;
  1684. begin
  1685. p:=symtablestack;
  1686. while assigned(p) do
  1687. begin
  1688. if (p.symtabletype=globalsymtable) and
  1689. assigned(tglobalsymtable(p).unitsym) and
  1690. ((tglobalsymtable(p).unitsym.owner=current_module.globalsymtable) or
  1691. (tglobalsymtable(p).unitsym.owner=current_module.localsymtable)) then
  1692. tglobalsymtable(p).unitsym.restoreunitsym;
  1693. p:=p.next;
  1694. end;
  1695. end;
  1696. {$ifdef DEBUG}
  1697. procedure test_symtablestack;
  1698. var
  1699. p : tsymtable;
  1700. i : longint;
  1701. begin
  1702. p:=symtablestack;
  1703. i:=0;
  1704. while assigned(p) do
  1705. begin
  1706. inc(i);
  1707. p:=p.next;
  1708. if i>500 then
  1709. Message(sym_f_internal_error_in_symtablestack);
  1710. end;
  1711. end;
  1712. procedure list_symtablestack;
  1713. var
  1714. p : tsymtable;
  1715. i : longint;
  1716. begin
  1717. p:=symtablestack;
  1718. i:=0;
  1719. while assigned(p) do
  1720. begin
  1721. inc(i);
  1722. writeln(i,' ',p.name^);
  1723. p:=p.next;
  1724. if i>500 then
  1725. Message(sym_f_internal_error_in_symtablestack);
  1726. end;
  1727. end;
  1728. {$endif DEBUG}
  1729. {****************************************************************************
  1730. Init/Done Symtable
  1731. ****************************************************************************}
  1732. procedure InitSymtable;
  1733. var
  1734. token : ttoken;
  1735. begin
  1736. { Reset symbolstack }
  1737. registerdef:=false;
  1738. read_member:=false;
  1739. symtablestack:=nil;
  1740. systemunit:=nil;
  1741. {$ifdef GDB}
  1742. firstglobaldef:=nil;
  1743. lastglobaldef:=nil;
  1744. globaltypecount:=1;
  1745. pglobaltypecount:=@globaltypecount;
  1746. {$endif GDB}
  1747. { create error syms and def }
  1748. generrorsym:=terrorsym.create;
  1749. generrortype.setdef(terrordef.create);
  1750. {$ifdef UNITALIASES}
  1751. { unit aliases }
  1752. unitaliases:=tdictionary.create;
  1753. {$endif}
  1754. for token:=first_overloaded to last_overloaded do
  1755. overloaded_operators[token]:=nil;
  1756. end;
  1757. procedure DoneSymtable;
  1758. begin
  1759. generrorsym.free;
  1760. generrortype.def.free;
  1761. {$ifdef UNITALIASES}
  1762. unitaliases.free;
  1763. {$endif}
  1764. end;
  1765. end.
  1766. {
  1767. $Log$
  1768. Revision 1.49 2001-11-02 23:16:52 peter
  1769. * removed obsolete chainprocsym and test_procsym code
  1770. Revision 1.48 2001/11/02 22:58:08 peter
  1771. * procsym definition rewrite
  1772. Revision 1.47 2001/10/12 20:27:43 jonas
  1773. * fixed crashing bug in unit reference counting
  1774. Revision 1.46 2001/09/30 21:29:47 peter
  1775. * gdb fixes merged
  1776. Revision 1.45 2001/09/19 11:06:03 michael
  1777. * realname updated for some hints
  1778. * realname used for consts,labels
  1779. Revision 1.44 2001/09/04 11:38:55 jonas
  1780. + searchsystype() and searchsystype() functions in symtable
  1781. * changed ninl and nadd to use these functions
  1782. * i386 set comparison functions now return their results in al instead
  1783. of in the flags so that they can be sued as compilerprocs
  1784. - removed all processor specific code from n386add.pas that has to do
  1785. with set handling, it's now all done in nadd.pas
  1786. * fixed fpc_set_contains_sets in genset.inc
  1787. * fpc_set_in_byte is now coded inline in n386set.pas and doesn't use a
  1788. helper anymore
  1789. * some small fixes in compproc.inc/set.inc regarding the declaration of
  1790. internal helper types (fpc_small_set and fpc_normal_set)
  1791. Revision 1.43 2001/08/30 20:13:56 peter
  1792. * rtti/init table updates
  1793. * rttisym for reusable global rtti/init info
  1794. * support published for interfaces
  1795. Revision 1.42 2001/08/26 13:36:51 florian
  1796. * some cg reorganisation
  1797. * some PPC updates
  1798. Revision 1.41 2001/08/19 09:39:29 peter
  1799. * local browser support fixed
  1800. Revision 1.40 2001/08/06 21:40:49 peter
  1801. * funcret moved from tprocinfo to tprocdef
  1802. Revision 1.39 2001/07/29 22:12:58 peter
  1803. * skip private symbols when found in withsymtable
  1804. Revision 1.38 2001/07/01 20:16:18 peter
  1805. * alignmentinfo record added
  1806. * -Oa argument supports more alignment settings that can be specified
  1807. per type: PROC,LOOP,VARMIN,VARMAX,CONSTMIN,CONSTMAX,RECORDMIN
  1808. RECORDMAX,LOCALMIN,LOCALMAX. It is possible to set the mimimum
  1809. required alignment and the maximum usefull alignment. The final
  1810. alignment will be choosen per variable size dependent on these
  1811. settings
  1812. Revision 1.37 2001/06/04 11:53:14 peter
  1813. + varargs directive
  1814. Revision 1.36 2001/06/03 21:57:38 peter
  1815. + hint directive parsing support
  1816. Revision 1.35 2001/05/06 14:49:18 peter
  1817. * ppu object to class rewrite
  1818. * move ppu read and write stuff to fppu
  1819. Revision 1.34 2001/04/18 22:01:59 peter
  1820. * registration of targets and assemblers
  1821. Revision 1.33 2001/04/13 20:05:15 peter
  1822. * better check for globalsymtable
  1823. Revision 1.32 2001/04/13 18:08:37 peter
  1824. * scanner object to class
  1825. Revision 1.31 2001/04/13 01:22:16 peter
  1826. * symtable change to classes
  1827. * range check generation and errors fixed, make cycle DEBUG=1 works
  1828. * memory leaks fixed
  1829. Revision 1.30 2001/04/02 21:20:35 peter
  1830. * resulttype rewrite
  1831. Revision 1.29 2001/03/22 00:10:58 florian
  1832. + basic variant type support in the compiler
  1833. Revision 1.28 2001/03/13 18:45:07 peter
  1834. * fixed some memory leaks
  1835. Revision 1.27 2001/03/11 22:58:51 peter
  1836. * getsym redesign, removed the globals srsym,srsymtable
  1837. Revision 1.26 2001/02/21 19:37:19 peter
  1838. * moved deref to be done after loading of implementation units. prederef
  1839. is still done directly after loading of symbols and definitions.
  1840. Revision 1.25 2001/02/20 21:41:16 peter
  1841. * new fixfilename, findfile for unix. Look first for lowercase, then
  1842. NormalCase and last for UPPERCASE names.
  1843. Revision 1.24 2001/01/08 21:40:27 peter
  1844. * fixed crash with unsupported token overloading
  1845. Revision 1.23 2000/12/25 00:07:30 peter
  1846. + new tlinkedlist class (merge of old tstringqueue,tcontainer and
  1847. tlinkedlist objects)
  1848. Revision 1.22 2000/12/23 19:50:09 peter
  1849. * fixed mem leak with withsymtable
  1850. Revision 1.21 2000/12/10 20:25:32 peter
  1851. * fixed missing typecast
  1852. Revision 1.20 2000/12/10 14:14:51 florian
  1853. * fixed web bug 1203: class fields can be now redefined
  1854. in Delphi mode though I don't like this :/
  1855. Revision 1.19 2000/11/30 22:16:49 florian
  1856. * moved to i386
  1857. Revision 1.18 2000/11/29 00:30:42 florian
  1858. * unused units removed from uses clause
  1859. * some changes for widestrings
  1860. Revision 1.17 2000/11/28 00:28:07 pierre
  1861. * stabs fixing
  1862. Revision 1.1.2.8 2000/11/17 11:14:37 pierre
  1863. * one more class stabs fix
  1864. Revision 1.16 2000/11/12 22:17:47 peter
  1865. * some realname updates for messages
  1866. Revision 1.15 2000/11/06 15:54:15 florian
  1867. * fixed two bugs to get make cycle work, but it's not enough
  1868. Revision 1.14 2000/11/04 14:25:22 florian
  1869. + merged Attila's changes for interfaces, not tested yet
  1870. Revision 1.13 2000/11/01 23:04:38 peter
  1871. * tprocdef.fullprocname added for better casesensitve writing of
  1872. procedures
  1873. Revision 1.12 2000/10/31 22:02:52 peter
  1874. * symtable splitted, no real code changes
  1875. Revision 1.1.2.7 2000/10/16 19:43:04 pierre
  1876. * trying to correct class stabss once more
  1877. Revision 1.11 2000/10/15 07:47:53 peter
  1878. * unit names and procedure names are stored mixed case
  1879. Revision 1.10 2000/10/14 10:14:53 peter
  1880. * moehrendorf oct 2000 rewrite
  1881. Revision 1.9 2000/10/01 19:48:25 peter
  1882. * lot of compile updates for cg11
  1883. Revision 1.8 2000/09/24 15:06:29 peter
  1884. * use defines.inc
  1885. Revision 1.7 2000/08/27 16:11:54 peter
  1886. * moved some util functions from globals,cobjects to cutils
  1887. * splitted files into finput,fmodule
  1888. Revision 1.6 2000/08/21 11:27:45 pierre
  1889. * fix the stabs problems
  1890. Revision 1.5 2000/08/20 14:58:41 peter
  1891. * give fatal if objfpc/delphi mode things are found (merged)
  1892. Revision 1.1.2.6 2000/08/20 14:56:46 peter
  1893. * give fatal if objfpc/delphi mode things are found
  1894. Revision 1.4 2000/08/16 18:33:54 peter
  1895. * splitted namedobjectitem.next into indexnext and listnext so it
  1896. can be used in both lists
  1897. * don't allow "word = word" type definitions (merged)
  1898. Revision 1.3 2000/08/08 19:28:57 peter
  1899. * memdebug/memory patches (merged)
  1900. * only once illegal directive (merged)
  1901. }