symtable.pas 73 KB

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