symtable.pas 68 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146
  1. {
  2. $Id$
  3. Copyright (c) 1998-2002 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. aasmbase,aasmtai
  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 derefobjectdata;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;arg:pointer);
  82. end;
  83. tabstractrecordsymtable = class(tstoredsymtable)
  84. public
  85. procedure load(ppufile:tcompilerppufile);override;
  86. procedure write(ppufile:tcompilerppufile);override;
  87. procedure load_references(ppufile:tcompilerppufile;locals:boolean);override;
  88. procedure write_references(ppufile:tcompilerppufile;locals:boolean);override;
  89. end;
  90. trecordsymtable = class(tabstractrecordsymtable)
  91. public
  92. constructor create;
  93. procedure insert_in(tsymt : tsymtable;offset : longint);
  94. end;
  95. tobjectsymtable = class(tabstractrecordsymtable)
  96. public
  97. constructor create(const n:string);
  98. procedure insert(sym : tsymentry);override;
  99. end;
  100. tabstractlocalsymtable = class(tstoredsymtable)
  101. public
  102. procedure load(ppufile:tcompilerppufile);override;
  103. procedure write(ppufile:tcompilerppufile);override;
  104. procedure load_references(ppufile:tcompilerppufile;locals:boolean);override;
  105. procedure write_references(ppufile:tcompilerppufile;locals:boolean);override;
  106. end;
  107. tlocalsymtable = class(tabstractlocalsymtable)
  108. public
  109. constructor create;
  110. procedure insert(sym : tsymentry);override;
  111. end;
  112. tparasymtable = class(tabstractlocalsymtable)
  113. public
  114. constructor create;
  115. procedure insert(sym : tsymentry);override;
  116. { change alignment for args only parasymtable }
  117. procedure set_alignment(_alignment : longint);
  118. end;
  119. tabstractunitsymtable = class(tstoredsymtable)
  120. public
  121. {$ifdef GDB}
  122. dbx_count : longint;
  123. prev_dbx_counter : plongint;
  124. dbx_count_ok : boolean;
  125. is_stab_written : boolean;
  126. {$endif GDB}
  127. constructor create(const n : string);
  128. {$ifdef GDB}
  129. procedure concattypestabto(asmlist : taasmoutput);
  130. {$endif GDB}
  131. end;
  132. tglobalsymtable = class(tabstractunitsymtable)
  133. public
  134. unittypecount : word;
  135. unitsym : tunitsym;
  136. constructor create(const n : string);
  137. destructor destroy;override;
  138. procedure load(ppufile:tcompilerppufile);override;
  139. procedure write(ppufile:tcompilerppufile);override;
  140. procedure insert(sym : tsymentry);override;
  141. {$ifdef GDB}
  142. function getnewtypecount : word; override;
  143. {$endif}
  144. end;
  145. tstaticsymtable = class(tabstractunitsymtable)
  146. public
  147. constructor create(const n : string);
  148. procedure load(ppufile:tcompilerppufile);override;
  149. procedure write(ppufile:tcompilerppufile);override;
  150. procedure load_references(ppufile:tcompilerppufile;locals:boolean);override;
  151. procedure write_references(ppufile:tcompilerppufile;locals:boolean);override;
  152. procedure insert(sym : tsymentry);override;
  153. end;
  154. twithsymtable = class(tsymtable)
  155. direct_with : boolean;
  156. { in fact it is a tnode }
  157. withnode : pointer;
  158. { tnode to load of direct with var }
  159. { already usable before firstwith
  160. needed for firstpass of function parameters PM }
  161. withrefnode : pointer;
  162. constructor create(aowner:tdef;asymsearch:TDictionary);
  163. destructor destroy;override;
  164. procedure clear;override;
  165. end;
  166. tstt_exceptsymtable = class(tsymtable)
  167. public
  168. constructor create;
  169. end;
  170. var
  171. constsymtable : tsymtable; { symtable were the constants can be inserted }
  172. systemunit : tglobalsymtable; { pointer to the system unit }
  173. read_member : boolean; { reading members of an symtable }
  174. lexlevel : longint; { level of code }
  175. { 1 for main procedure }
  176. { 2 for normal function or proc }
  177. { higher for locals }
  178. {****************************************************************************
  179. Functions
  180. ****************************************************************************}
  181. {*** Misc ***}
  182. procedure globaldef(const s : string;var t:ttype);
  183. function findunitsymtable(st:tsymtable):tsymtable;
  184. procedure duplicatesym(sym:tsym);
  185. {*** Search ***}
  186. function searchsym(const s : stringid;var srsym:tsym;var srsymtable:tsymtable):boolean;
  187. function searchsymonlyin(p : tsymtable;const s : stringid):tsym;
  188. function searchsym_in_class(classh:tobjectdef;const s : stringid):tsym;
  189. function searchsystype(const s: stringid; var srsym: ttypesym): boolean;
  190. function searchsysvar(const s: stringid; var srsym: tvarsym; var symowner: tsymtable): boolean;
  191. function search_class_member(pd : tobjectdef;const s : string):tsym;
  192. {*** Object Helpers ***}
  193. function search_default_property(pd : tobjectdef) : tpropertysym;
  194. {*** symtable stack ***}
  195. procedure dellexlevel;
  196. procedure RestoreUnitSyms;
  197. {$ifdef DEBUG}
  198. procedure test_symtablestack;
  199. procedure list_symtablestack;
  200. {$endif DEBUG}
  201. {$ifdef UNITALIASES}
  202. type
  203. punit_alias = ^tunit_alias;
  204. tunit_alias = object(TNamedIndexItem)
  205. newname : pstring;
  206. constructor init(const n:string);
  207. destructor done;virtual;
  208. end;
  209. var
  210. unitaliases : pdictionary;
  211. procedure addunitalias(const n:string);
  212. function getunitalias(const n:string):string;
  213. {$endif UNITALIASES}
  214. {*** Init / Done ***}
  215. procedure InitSymtable;
  216. procedure DoneSymtable;
  217. type
  218. toverloaded_operators = array[NOTOKEN..last_overloaded] of tprocsym;
  219. var
  220. overloaded_operators : toverloaded_operators;
  221. { unequal is not equal}
  222. const
  223. overloaded_names : array [NOTOKEN..last_overloaded] of string[16] =
  224. ('error',
  225. 'plus','minus','star','slash','equal',
  226. 'greater','lower','greater_or_equal',
  227. 'lower_or_equal',
  228. 'sym_diff','starstar',
  229. 'as','is','in','or',
  230. 'and','div','mod','not','shl','shr','xor',
  231. 'assign');
  232. implementation
  233. uses
  234. { global }
  235. verbose,globals,
  236. { target }
  237. systems,
  238. { module }
  239. 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(pointer(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(pointer(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.derefobjectdata;
  476. var
  477. hp : tdef;
  478. begin
  479. hp:=tdef(defindex.first);
  480. while assigned(hp) do
  481. begin
  482. hp.derefobjectdata;
  483. hp:=tdef(hp.indexnext);
  484. end;
  485. end;
  486. procedure tstoredsymtable.insert(sym:tsymentry);
  487. var
  488. hsym : tsym;
  489. begin
  490. { set owner and sym indexnb }
  491. sym.owner:=self;
  492. { writes the symbol in data segment if required }
  493. { also sets the datasize of owner }
  494. if not in_loading then
  495. tstoredsym(sym).insert_in_data;
  496. { check the current symtable }
  497. hsym:=tsym(search(sym.name));
  498. if assigned(hsym) then
  499. begin
  500. { in TP and Delphi you can have a local with the
  501. same name as the function, the function is then hidden for
  502. the user. (Under delphi it can still be accessed using result),
  503. but don't allow hiding of RESULT }
  504. if (m_duplicate_names in aktmodeswitches) and
  505. (hsym.typ=funcretsym) and
  506. not((m_result in aktmodeswitches) and
  507. (hsym.name='RESULT')) then
  508. hsym.owner.rename(hsym.name,'hidden'+hsym.name)
  509. else
  510. begin
  511. DuplicateSym(hsym);
  512. exit;
  513. end;
  514. end;
  515. { register definition of typesym }
  516. if (sym.typ = typesym) and
  517. assigned(ttypesym(sym).restype.def) then
  518. begin
  519. if not(assigned(ttypesym(sym).restype.def.owner)) and
  520. (ttypesym(sym).restype.def.deftype<>errordef) then
  521. registerdef(ttypesym(sym).restype.def);
  522. {$ifdef GDB}
  523. if (cs_debuginfo in aktmoduleswitches) and assigned(debuglist) and
  524. (symtabletype in [globalsymtable,staticsymtable]) then
  525. begin
  526. ttypesym(sym).isusedinstab := true;
  527. {sym.concatstabto(debuglist);}
  528. end;
  529. {$endif GDB}
  530. end;
  531. { insert in index and search hash }
  532. symindex.insert(sym);
  533. symsearch.insert(sym);
  534. end;
  535. function tstoredsymtable.speedsearch(const s : stringid;speedvalue : cardinal) : tsymentry;
  536. var
  537. hp : tstoredsym;
  538. newref : tref;
  539. begin
  540. hp:=tstoredsym(inherited speedsearch(s,speedvalue));
  541. if assigned(hp) then
  542. begin
  543. { reject non static members in static procedures }
  544. if (symtabletype=objectsymtable) and
  545. not(sp_static in hp.symoptions) and
  546. allow_only_static then
  547. Message(sym_e_only_static_in_static);
  548. { unit uses count }
  549. if (unitid<>0) and
  550. (symtabletype = globalsymtable) and
  551. assigned(tglobalsymtable(self).unitsym) then
  552. inc(tglobalsymtable(self).unitsym.refs);
  553. {$ifdef GDB}
  554. { if it is a type, we need the stabs of this type
  555. this might be the cause of the class debug problems
  556. as TCHILDCLASS.Create did not generate appropriate
  557. stabs debug info if TCHILDCLASS wasn't used anywhere else PM }
  558. if (cs_debuginfo in aktmoduleswitches) and
  559. (hp.typ=typesym) and
  560. make_ref then
  561. begin
  562. if assigned(ttypesym(hp).restype.def) then
  563. tstoreddef(ttypesym(hp).restype.def).numberstring
  564. else
  565. ttypesym(hp).isusedinstab:=true;
  566. end;
  567. {$endif GDB}
  568. { unitsym are only loaded for browsing PM }
  569. { this was buggy anyway because we could use }
  570. { unitsyms from other units in _USES !! }
  571. {if (symtabletype=unitsymtable) and (hp.typ=unitsym) and
  572. assigned(current_module) and (current_module.globalsymtable<>.load) then
  573. hp:=nil;}
  574. if assigned(hp) and
  575. make_ref and
  576. (cs_browser in aktmoduleswitches) then
  577. begin
  578. newref:=tref.create(hp.lastref,@akttokenpos);
  579. { for symbols that are in tables without
  580. browser info or syssyms (PM) }
  581. if hp.refcount=0 then
  582. begin
  583. hp.defref:=newref;
  584. hp.lastref:=newref;
  585. end
  586. else
  587. if resolving_forward and assigned(hp.defref) then
  588. { put it as second reference }
  589. begin
  590. newref.nextref:=hp.defref.nextref;
  591. hp.defref.nextref:=newref;
  592. hp.lastref.nextref:=nil;
  593. end
  594. else
  595. hp.lastref:=newref;
  596. inc(hp.refcount);
  597. end;
  598. if assigned(hp) and make_ref then
  599. begin
  600. inc(hp.refs);
  601. end;
  602. end;
  603. speedsearch:=hp;
  604. end;
  605. {**************************************
  606. Callbacks
  607. **************************************}
  608. procedure TStoredSymtable.check_forward(sym : TNamedIndexItem;arg:pointer);
  609. begin
  610. if tsym(sym).typ=procsym then
  611. tprocsym(sym).check_forward
  612. { check also object method table }
  613. { we needn't to test the def list }
  614. { because each object has to have a type sym }
  615. else
  616. if (tsym(sym).typ=typesym) and
  617. assigned(ttypesym(sym).restype.def) and
  618. (ttypesym(sym).restype.def.deftype=objectdef) then
  619. tobjectdef(ttypesym(sym).restype.def).check_forwards;
  620. end;
  621. procedure TStoredSymtable.labeldefined(p : TNamedIndexItem;arg:pointer);
  622. begin
  623. if (tsym(p).typ=labelsym) and
  624. not(tlabelsym(p).defined) then
  625. begin
  626. if tlabelsym(p).used then
  627. Message1(sym_e_label_used_and_not_defined,tlabelsym(p).realname)
  628. else
  629. Message1(sym_w_label_not_defined,tlabelsym(p).realname);
  630. end;
  631. end;
  632. procedure TStoredSymtable.unitsymbolused(p : TNamedIndexItem;arg:pointer);
  633. begin
  634. if (tsym(p).typ=unitsym) and
  635. (tunitsym(p).refs=0) and
  636. { do not claim for unit name itself !! }
  637. assigned(tunitsym(p).unitsymtable) and
  638. (tunitsym(p).unitsymtable.symtabletype=globalsymtable) then
  639. MessagePos2(tsym(p).fileinfo,sym_n_unit_not_used,p.name,current_module.modulename^);
  640. end;
  641. procedure TStoredSymtable.varsymbolused(p : TNamedIndexItem;arg:pointer);
  642. begin
  643. if (tsym(p).typ=varsym) and
  644. ((tsym(p).owner.symtabletype in
  645. [parasymtable,localsymtable,objectsymtable,staticsymtable])) then
  646. begin
  647. { unused symbol should be reported only if no }
  648. { error is reported }
  649. { if the symbol is in a register it is used }
  650. { also don't count the value parameters which have local copies }
  651. { also don't claim for high param of open parameters (PM) }
  652. if (Errorcount<>0) or
  653. (copy(p.name,1,3)='val') or
  654. (copy(p.name,1,4)='high') then
  655. exit;
  656. if (tvarsym(p).refs=0) then
  657. begin
  658. if (tsym(p).owner.symtabletype=parasymtable) or (vo_is_local_copy in tvarsym(p).varoptions) then
  659. begin
  660. MessagePos1(tsym(p).fileinfo,sym_h_para_identifier_not_used,tsym(p).realname);
  661. end
  662. else if (tsym(p).owner.symtabletype=objectsymtable) then
  663. MessagePos2(tsym(p).fileinfo,sym_n_private_identifier_not_used,tsym(p).owner.realname^,tsym(p).realname)
  664. else
  665. MessagePos1(tsym(p).fileinfo,sym_n_local_identifier_not_used,tsym(p).realname);
  666. end
  667. else if tvarsym(p).varstate=vs_assigned then
  668. begin
  669. if (tsym(p).owner.symtabletype=parasymtable) then
  670. begin
  671. if not(tvarsym(p).varspez in [vs_var,vs_out]) then
  672. MessagePos1(tsym(p).fileinfo,sym_h_para_identifier_only_set,tsym(p).realname)
  673. end
  674. else if (vo_is_local_copy in tvarsym(p).varoptions) then
  675. begin
  676. if not(tvarsym(p).varspez in [vs_var,vs_out]) then
  677. MessagePos1(tsym(p).fileinfo,sym_h_para_identifier_only_set,tsym(p).realname);
  678. end
  679. else if (tsym(p).owner.symtabletype=objectsymtable) then
  680. MessagePos2(tsym(p).fileinfo,sym_n_private_identifier_only_set,tsym(p).owner.realname^,tsym(p).realname)
  681. else if (tsym(p).owner.symtabletype<>parasymtable) then
  682. if not (vo_is_exported in tvarsym(p).varoptions) then
  683. MessagePos1(tsym(p).fileinfo,sym_n_local_identifier_only_set,tsym(p).realname);
  684. end;
  685. end
  686. else if ((tsym(p).owner.symtabletype in
  687. [objectsymtable,parasymtable,localsymtable,staticsymtable])) then
  688. begin
  689. if (Errorcount<>0) then
  690. exit;
  691. { do not claim for inherited private fields !! }
  692. if (tstoredsym(p).refs=0) and (tsym(p).owner.symtabletype=objectsymtable) then
  693. MessagePos2(tsym(p).fileinfo,sym_n_private_method_not_used,tsym(p).owner.realname^,tsym(p).realname)
  694. { units references are problematic }
  695. else if (tstoredsym(p).refs=0) and not(tsym(p).typ in [funcretsym,enumsym,unitsym]) then
  696. if (tsym(p).typ<>procsym) or not (tprocsym(p).is_global) or
  697. { all program functions are declared global
  698. but unused should still be signaled PM }
  699. ((tsym(p).owner.symtabletype=staticsymtable) and
  700. not current_module.is_unit) then
  701. MessagePos2(tsym(p).fileinfo,sym_h_local_symbol_not_used,SymTypeName[tsym(p).typ],tsym(p).realname);
  702. end;
  703. end;
  704. procedure TStoredSymtable.TestPrivate(p : TNamedIndexItem;arg:pointer);
  705. begin
  706. if sp_private in tsym(p).symoptions then
  707. varsymbolused(p,arg);
  708. end;
  709. procedure TStoredSymtable.objectprivatesymbolused(p : TNamedIndexItem;arg:pointer);
  710. begin
  711. {
  712. Don't test simple object aliases PM
  713. }
  714. if (tsym(p).typ=typesym) and
  715. (ttypesym(p).restype.def.deftype=objectdef) and
  716. (ttypesym(p).restype.def.typesym=tsym(p)) then
  717. tobjectdef(ttypesym(p).restype.def).symtable.foreach({$ifdef FPCPROCVAR}@{$endif}TestPrivate,nil);
  718. end;
  719. procedure tstoredsymtable.unchain_overloads(p : TNamedIndexItem;arg:pointer);
  720. begin
  721. if tsym(p).typ=procsym then
  722. tprocsym(p).unchain_overload;
  723. end;
  724. {$ifdef GDB}
  725. procedure TStoredSymtable.concatstab(p : TNamedIndexItem;arg:pointer);
  726. begin
  727. if tsym(p).typ <> procsym then
  728. tstoredsym(p).concatstabto(TAAsmOutput(arg));
  729. end;
  730. procedure TStoredSymtable.resetstab(p : TNamedIndexItem;arg:pointer);
  731. begin
  732. if tsym(p).typ <> procsym then
  733. tstoredsym(p).isstabwritten:=false;
  734. end;
  735. procedure TStoredSymtable.concattypestab(p : TNamedIndexItem;arg:pointer);
  736. begin
  737. if tsym(p).typ = typesym then
  738. begin
  739. tstoredsym(p).isstabwritten:=false;
  740. tstoredsym(p).concatstabto(TAAsmOutput(arg));
  741. end;
  742. end;
  743. function tstoredsymtable.getnewtypecount : word;
  744. begin
  745. getnewtypecount:=pglobaltypecount^;
  746. inc(pglobaltypecount^);
  747. end;
  748. {$endif GDB}
  749. procedure tstoredsymtable.chainoperators;
  750. var
  751. pd : pprocdeflist;
  752. t : ttoken;
  753. srsym : tsym;
  754. srsymtable,
  755. storesymtablestack : tsymtable;
  756. begin
  757. storesymtablestack:=symtablestack;
  758. symtablestack:=self;
  759. make_ref:=false;
  760. for t:=first_overloaded to last_overloaded do
  761. begin
  762. overloaded_operators[t]:=nil;
  763. { each operator has a unique lowercased internal name PM }
  764. while assigned(symtablestack) do
  765. begin
  766. searchsym(overloaded_names[t],srsym,srsymtable);
  767. if not assigned(srsym) then
  768. begin
  769. if (t=_STARSTAR) then
  770. begin
  771. symtablestack:=systemunit;
  772. searchsym('POWER',srsym,srsymtable);
  773. end;
  774. end;
  775. if assigned(srsym) then
  776. begin
  777. if (srsym.typ<>procsym) then
  778. internalerror(12344321);
  779. { use this procsym as start ? }
  780. if not assigned(overloaded_operators[t]) then
  781. overloaded_operators[t]:=tprocsym(srsym)
  782. else
  783. { already got a procsym, only add defs of the current procsym }
  784. Tprocsym(srsym).concat_procdefs_to(overloaded_operators[t]);
  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,nil);
  805. end;
  806. procedure tstoredsymtable.checklabels;
  807. begin
  808. foreach({$ifdef FPCPROCVAR}@{$endif}labeldefined,nil);
  809. end;
  810. procedure tstoredsymtable.allunitsused;
  811. begin
  812. foreach({$ifdef FPCPROCVAR}@{$endif}unitsymbolused,nil);
  813. end;
  814. procedure tstoredsymtable.allsymbolsused;
  815. begin
  816. foreach({$ifdef FPCPROCVAR}@{$endif}varsymbolused,nil);
  817. end;
  818. procedure tstoredsymtable.allprivatesused;
  819. begin
  820. foreach({$ifdef FPCPROCVAR}@{$endif}objectprivatesymbolused,nil);
  821. end;
  822. procedure tstoredsymtable.unchain_overloaded;
  823. begin
  824. foreach({$ifdef FPCPROCVAR}@{$endif}unchain_overloads,nil);
  825. end;
  826. {$ifdef GDB}
  827. procedure tstoredsymtable.concatstabto(asmlist : taasmoutput);
  828. begin
  829. if symtabletype in [inlineparasymtable,inlinelocalsymtable] then
  830. foreach({$ifdef FPCPROCVAR}@{$endif}resetstab,nil);
  831. foreach({$ifdef FPCPROCVAR}@{$endif}concatstab,asmlist);
  832. end;
  833. {$endif}
  834. { returns true, if p contains data which needs init/final code }
  835. function tstoredsymtable.needs_init_final : boolean;
  836. begin
  837. b_needs_init_final:=false;
  838. foreach({$ifdef FPCPROCVAR}@{$endif}_needs_init_final,nil);
  839. needs_init_final:=b_needs_init_final;
  840. end;
  841. {****************************************************************************
  842. TAbstractRecordSymtable
  843. ****************************************************************************}
  844. procedure tabstractrecordsymtable.load(ppufile:tcompilerppufile);
  845. var
  846. storesymtable : tsymtable;
  847. begin
  848. storesymtable:=aktrecordsymtable;
  849. aktrecordsymtable:=self;
  850. inherited load(ppufile);
  851. aktrecordsymtable:=storesymtable;
  852. end;
  853. procedure tabstractrecordsymtable.write(ppufile:tcompilerppufile);
  854. var
  855. oldtyp : byte;
  856. storesymtable : tsymtable;
  857. begin
  858. storesymtable:=aktrecordsymtable;
  859. aktrecordsymtable:=self;
  860. oldtyp:=ppufile.entrytyp;
  861. ppufile.entrytyp:=subentryid;
  862. inherited write(ppufile);
  863. ppufile.entrytyp:=oldtyp;
  864. aktrecordsymtable:=storesymtable;
  865. end;
  866. procedure tabstractrecordsymtable.load_references(ppufile:tcompilerppufile;locals:boolean);
  867. var
  868. storesymtable : tsymtable;
  869. begin
  870. storesymtable:=aktrecordsymtable;
  871. aktrecordsymtable:=self;
  872. inherited load_references(ppufile,locals);
  873. aktrecordsymtable:=storesymtable;
  874. end;
  875. procedure tabstractrecordsymtable.write_references(ppufile:tcompilerppufile;locals:boolean);
  876. var
  877. storesymtable : tsymtable;
  878. begin
  879. storesymtable:=aktrecordsymtable;
  880. aktrecordsymtable:=self;
  881. inherited write_references(ppufile,locals);
  882. aktrecordsymtable:=storesymtable;
  883. end;
  884. procedure TStoredSymtable._needs_init_final(p : tnamedindexitem;arg:pointer);
  885. begin
  886. if (not b_needs_init_final) and
  887. (tsym(p).typ=varsym) and
  888. assigned(tvarsym(p).vartype.def) and
  889. not is_class(tvarsym(p).vartype.def) and
  890. tstoreddef(tvarsym(p).vartype.def).needs_inittable then
  891. b_needs_init_final:=true;
  892. end;
  893. {****************************************************************************
  894. TRecordSymtable
  895. ****************************************************************************}
  896. constructor trecordsymtable.create;
  897. begin
  898. inherited create('');
  899. symtabletype:=recordsymtable;
  900. end;
  901. { this procedure is reserved for inserting case variant into
  902. a record symtable }
  903. { the offset is the location of the start of the variant
  904. and datasize and dataalignment corresponds to
  905. the complete size (see code in pdecl unit) PM }
  906. procedure trecordsymtable.insert_in(tsymt : tsymtable;offset : longint);
  907. var
  908. ps,nps : tvarsym;
  909. pd,npd : tdef;
  910. storesize,storealign : longint;
  911. begin
  912. storesize:=tsymt.datasize;
  913. storealign:=tsymt.dataalignment;
  914. tsymt.datasize:=offset;
  915. ps:=tvarsym(symindex.first);
  916. while assigned(ps) do
  917. begin
  918. nps:=tvarsym(ps.indexnext);
  919. { remove from current symtable }
  920. symindex.deleteindex(ps);
  921. ps.left:=nil;
  922. ps.right:=nil;
  923. { add to symt }
  924. ps.owner:=tsymt;
  925. tsymt.datasize:=ps.address+offset;
  926. tsymt.symindex.insert(ps);
  927. tsymt.symsearch.insert(ps);
  928. { update address }
  929. ps.address:=tsymt.datasize;
  930. { next }
  931. ps:=nps;
  932. end;
  933. pd:=tdef(defindex.first);
  934. while assigned(pd) do
  935. begin
  936. npd:=tdef(pd.indexnext);
  937. defindex.deleteindex(pd);
  938. pd.left:=nil;
  939. pd.right:=nil;
  940. tsymt.registerdef(pd);
  941. pd:=npd;
  942. end;
  943. tsymt.datasize:=storesize;
  944. tsymt.dataalignment:=storealign;
  945. end;
  946. {****************************************************************************
  947. TObjectSymtable
  948. ****************************************************************************}
  949. constructor tobjectsymtable.create(const n:string);
  950. begin
  951. inherited create(n);
  952. symtabletype:=objectsymtable;
  953. end;
  954. procedure tobjectsymtable.insert(sym:tsymentry);
  955. var
  956. hsym : tsym;
  957. begin
  958. { check for duplicate field id in inherited classes }
  959. if (sym.typ=varsym) and
  960. assigned(defowner) and
  961. (
  962. not(m_delphi in aktmodeswitches) or
  963. is_object(tdef(defowner))
  964. ) then
  965. begin
  966. { but private ids can be reused }
  967. hsym:=search_class_member(tobjectdef(defowner),sym.name);
  968. if assigned(hsym) and
  969. tstoredsym(hsym).is_visible_for_object(tobjectdef(defowner)) then
  970. begin
  971. DuplicateSym(hsym);
  972. exit;
  973. end;
  974. end;
  975. inherited insert(sym);
  976. end;
  977. {****************************************************************************
  978. TAbstractLocalSymtable
  979. ****************************************************************************}
  980. procedure tabstractlocalsymtable.load(ppufile:tcompilerppufile);
  981. var
  982. storesymtable : tsymtable;
  983. begin
  984. storesymtable:=aktlocalsymtable;
  985. aktlocalsymtable:=self;
  986. inherited load(ppufile);
  987. aktlocalsymtable:=storesymtable;
  988. end;
  989. procedure tabstractlocalsymtable.write(ppufile:tcompilerppufile);
  990. var
  991. oldtyp : byte;
  992. storesymtable : tsymtable;
  993. begin
  994. storesymtable:=aktlocalsymtable;
  995. aktlocalsymtable:=self;
  996. oldtyp:=ppufile.entrytyp;
  997. ppufile.entrytyp:=subentryid;
  998. { write definitions }
  999. writedefs(ppufile);
  1000. { write symbols }
  1001. writesyms(ppufile);
  1002. ppufile.entrytyp:=oldtyp;
  1003. aktlocalsymtable:=storesymtable;
  1004. end;
  1005. procedure tabstractlocalsymtable.load_references(ppufile:tcompilerppufile;locals:boolean);
  1006. var
  1007. storesymtable : tsymtable;
  1008. begin
  1009. storesymtable:=aktlocalsymtable;
  1010. aktlocalsymtable:=self;
  1011. inherited load_references(ppufile,locals);
  1012. aktlocalsymtable:=storesymtable;
  1013. end;
  1014. procedure tabstractlocalsymtable.write_references(ppufile:tcompilerppufile;locals:boolean);
  1015. var
  1016. storesymtable : tsymtable;
  1017. begin
  1018. storesymtable:=aktlocalsymtable;
  1019. aktlocalsymtable:=self;
  1020. inherited write_references(ppufile,locals);
  1021. aktlocalsymtable:=storesymtable;
  1022. end;
  1023. {****************************************************************************
  1024. TLocalSymtable
  1025. ****************************************************************************}
  1026. constructor tlocalsymtable.create;
  1027. begin
  1028. inherited create('');
  1029. symtabletype:=localsymtable;
  1030. end;
  1031. procedure tlocalsymtable.insert(sym:tsymentry);
  1032. var
  1033. hsym : tsym;
  1034. begin
  1035. if assigned(next) then
  1036. begin
  1037. if (next.symtabletype=parasymtable) then
  1038. begin
  1039. hsym:=tsym(next.search(sym.name));
  1040. if assigned(hsym) then
  1041. begin
  1042. { a parameter and the function can have the same
  1043. name in TP and Delphi, but RESULT not }
  1044. if (m_duplicate_names in aktmodeswitches) and
  1045. (sym.typ=funcretsym) and
  1046. not((m_result in aktmodeswitches) and
  1047. (sym.name='RESULT')) then
  1048. sym.name:='hidden'+sym.name
  1049. else
  1050. begin
  1051. DuplicateSym(hsym);
  1052. exit;
  1053. end;
  1054. end;
  1055. end;
  1056. { check for duplicate id in local symtable of methods }
  1057. if assigned(next.next) and
  1058. { funcretsym is allowed !! }
  1059. (sym.typ <> funcretsym) and
  1060. (next.next.symtabletype=objectsymtable) then
  1061. begin
  1062. hsym:=search_class_member(tobjectdef(next.next.defowner),sym.name);
  1063. if assigned(hsym) and
  1064. { private ids can be reused }
  1065. (not(sp_private in hsym.symoptions) or
  1066. (hsym.owner.defowner.owner.symtabletype<>globalsymtable)) then
  1067. begin
  1068. { delphi allows to reuse the names in a class, but not
  1069. in object (tp7 compatible) }
  1070. if not((m_delphi in aktmodeswitches) and
  1071. is_class(tdef(next.next.defowner))) then
  1072. begin
  1073. DuplicateSym(hsym);
  1074. exit;
  1075. end;
  1076. end;
  1077. end;
  1078. end;
  1079. inherited insert(sym);
  1080. end;
  1081. {****************************************************************************
  1082. TParaSymtable
  1083. ****************************************************************************}
  1084. constructor tparasymtable.create;
  1085. begin
  1086. inherited create('');
  1087. symtabletype:=parasymtable;
  1088. dataalignment:=aktalignment.paraalign;
  1089. end;
  1090. procedure tparasymtable.insert(sym:tsymentry);
  1091. var
  1092. hsym : tsym;
  1093. begin
  1094. { check for duplicate id in para symtable of methods }
  1095. if assigned(procinfo^._class) and
  1096. { but not in nested procedures !}
  1097. (not(assigned(procinfo^.parent)) or
  1098. (assigned(procinfo^.parent) and
  1099. not(assigned(procinfo^.parent^._class)))
  1100. ) and
  1101. { funcretsym is allowed !! }
  1102. (sym.typ<>funcretsym) then
  1103. begin
  1104. hsym:=search_class_member(procinfo^._class,sym.name);
  1105. { private ids can be reused }
  1106. if assigned(hsym) and
  1107. tstoredsym(hsym).is_visible_for_object(procinfo^._class) then
  1108. begin
  1109. { delphi allows to reuse the names in a class, but not
  1110. in object (tp7 compatible) }
  1111. if not((m_delphi in aktmodeswitches) and
  1112. is_class_or_interface(procinfo^._class)) then
  1113. begin
  1114. DuplicateSym(hsym);
  1115. exit;
  1116. end;
  1117. end;
  1118. end;
  1119. inherited insert(sym);
  1120. end;
  1121. procedure tparasymtable.set_alignment(_alignment : longint);
  1122. var
  1123. sym : tvarsym;
  1124. l : longint;
  1125. begin
  1126. dataalignment:=_alignment;
  1127. sym:=tvarsym(symindex.first);
  1128. datasize:=0;
  1129. { there can be only varsyms }
  1130. { no, default parameters }
  1131. { lead to constsyms as well (FK) }
  1132. while assigned(sym) do
  1133. begin
  1134. if sym.typ=varsym then
  1135. begin
  1136. l:=sym.getpushsize;
  1137. sym.address:=datasize;
  1138. datasize:=align(datasize+l,dataalignment);
  1139. end;
  1140. sym:=tvarsym(sym.indexnext);
  1141. end;
  1142. end;
  1143. {****************************************************************************
  1144. TAbstractUnitSymtable
  1145. ****************************************************************************}
  1146. constructor tabstractunitsymtable.create(const n : string);
  1147. begin
  1148. inherited create(n);
  1149. symsearch.usehash;
  1150. {$ifdef GDB}
  1151. { reset GDB things }
  1152. prev_dbx_counter := dbx_counter;
  1153. dbx_counter := nil;
  1154. is_stab_written:=false;
  1155. dbx_count := -1;
  1156. {$endif GDB}
  1157. end;
  1158. {$ifdef GDB}
  1159. procedure tabstractunitsymtable.concattypestabto(asmlist : taasmoutput);
  1160. var prev_dbx_count : plongint;
  1161. begin
  1162. if is_stab_written then
  1163. exit;
  1164. if not assigned(name) then
  1165. name := stringdup('Main_program');
  1166. if (symtabletype = globalsymtable) and
  1167. (current_module.globalsymtable<>self) then
  1168. begin
  1169. unitid:=current_module.unitcount;
  1170. inc(current_module.unitcount);
  1171. end;
  1172. asmList.concat(Tai_asm_comment.Create(strpnew('Begin unit '+name^+' has index '+tostr(unitid))));
  1173. if cs_gdb_dbx in aktglobalswitches then
  1174. begin
  1175. if dbx_count_ok then
  1176. begin
  1177. asmList.concat(Tai_asm_comment.Create(strpnew('"repeated" unit '+name^
  1178. +' has index '+tostr(unitid)+' dbx count = '+tostr(dbx_count))));
  1179. asmList.concat(Tai_stabs.Create(strpnew('"'+name^+'",'
  1180. +tostr(N_EXCL)+',0,0,'+tostr(dbx_count))));
  1181. exit;
  1182. end
  1183. else if (current_module.globalsymtable<>self) then
  1184. begin
  1185. prev_dbx_count := dbx_counter;
  1186. dbx_counter := nil;
  1187. do_count_dbx:=false;
  1188. if (symtabletype = globalsymtable) and (unitid<>0) then
  1189. asmList.concat(Tai_stabs.Create(strpnew('"'+name^+'",'+tostr(N_BINCL)+',0,0,0')));
  1190. dbx_counter := @dbx_count;
  1191. dbx_count:=0;
  1192. do_count_dbx:=assigned(dbx_counter);
  1193. end;
  1194. end;
  1195. foreach({$ifdef FPCPROCVAR}@{$endif}concattypestab,asmlist);
  1196. if cs_gdb_dbx in aktglobalswitches then
  1197. begin
  1198. if (current_module.globalsymtable<>self) then
  1199. begin
  1200. dbx_counter := prev_dbx_count;
  1201. do_count_dbx:=false;
  1202. asmList.concat(Tai_asm_comment.Create(strpnew('End unit '+name^
  1203. +' has index '+tostr(unitid))));
  1204. asmList.concat(Tai_stabs.Create(strpnew('"'+name^+'",'
  1205. +tostr(N_EINCL)+',0,0,0')));
  1206. do_count_dbx:=assigned(dbx_counter);
  1207. dbx_count_ok := {true}false;
  1208. end;
  1209. end;
  1210. is_stab_written:=true;
  1211. end;
  1212. {$endif GDB}
  1213. {****************************************************************************
  1214. TStaticSymtable
  1215. ****************************************************************************}
  1216. constructor tstaticsymtable.create(const n : string);
  1217. begin
  1218. inherited create(n);
  1219. symtabletype:=staticsymtable;
  1220. end;
  1221. procedure tstaticsymtable.load(ppufile:tcompilerppufile);
  1222. begin
  1223. aktstaticsymtable:=self;
  1224. next:=symtablestack;
  1225. symtablestack:=self;
  1226. inherited load(ppufile);
  1227. { now we can deref the syms and defs }
  1228. deref;
  1229. { restore symtablestack }
  1230. symtablestack:=next;
  1231. end;
  1232. procedure tstaticsymtable.write(ppufile:tcompilerppufile);
  1233. begin
  1234. aktstaticsymtable:=self;
  1235. inherited write(ppufile);
  1236. end;
  1237. procedure tstaticsymtable.load_references(ppufile:tcompilerppufile;locals:boolean);
  1238. begin
  1239. aktstaticsymtable:=self;
  1240. inherited load_references(ppufile,locals);
  1241. end;
  1242. procedure tstaticsymtable.write_references(ppufile:tcompilerppufile;locals:boolean);
  1243. begin
  1244. aktstaticsymtable:=self;
  1245. inherited write_references(ppufile,locals);
  1246. end;
  1247. procedure tstaticsymtable.insert(sym:tsymentry);
  1248. var
  1249. hsym : tsym;
  1250. begin
  1251. { also check the global symtable }
  1252. if assigned(next) and
  1253. (next.unitid=0) then
  1254. begin
  1255. hsym:=tsym(next.search(sym.name));
  1256. if assigned(hsym) then
  1257. begin
  1258. DuplicateSym(hsym);
  1259. exit;
  1260. end;
  1261. end;
  1262. inherited insert(sym);
  1263. end;
  1264. {****************************************************************************
  1265. TGlobalSymtable
  1266. ****************************************************************************}
  1267. constructor tglobalsymtable.create(const n : string);
  1268. begin
  1269. inherited create(n);
  1270. symtabletype:=globalsymtable;
  1271. unitid:=0;
  1272. unitsym:=nil;
  1273. {$ifdef GDB}
  1274. if cs_gdb_dbx in aktglobalswitches then
  1275. begin
  1276. dbx_count := 0;
  1277. unittypecount:=1;
  1278. pglobaltypecount := @unittypecount;
  1279. {unitid:=current_module.unitcount;}
  1280. debugList.concat(Tai_asm_comment.Create(strpnew('Global '+name^+' has index '+tostr(unitid))));
  1281. debugList.concat(Tai_stabs.Create(strpnew('"'+name^+'",'+tostr(N_BINCL)+',0,0,0')));
  1282. {inc(current_module.unitcount);}
  1283. dbx_count_ok:=false;
  1284. dbx_counter:=@dbx_count;
  1285. do_count_dbx:=true;
  1286. end;
  1287. {$endif GDB}
  1288. end;
  1289. destructor tglobalsymtable.destroy;
  1290. var
  1291. pus : tunitsym;
  1292. begin
  1293. pus:=unitsym;
  1294. while assigned(pus) do
  1295. begin
  1296. unitsym:=pus.prevsym;
  1297. pus.prevsym:=nil;
  1298. pus.unitsymtable:=nil;
  1299. pus:=unitsym;
  1300. end;
  1301. inherited destroy;
  1302. end;
  1303. procedure tglobalsymtable.load(ppufile:tcompilerppufile);
  1304. begin
  1305. {$ifdef GDB}
  1306. if cs_gdb_dbx in aktglobalswitches then
  1307. begin
  1308. UnitTypeCount:=1;
  1309. PglobalTypeCount:=@UnitTypeCount;
  1310. end;
  1311. {$endif GDB}
  1312. symtablelevel:=0;
  1313. {$ifndef NEWMAP}
  1314. current_module.map^[0]:=self;
  1315. {$else NEWMAP}
  1316. current_module.globalsymtable:=self;
  1317. {$endif NEWMAP}
  1318. next:=symtablestack;
  1319. symtablestack:=self;
  1320. inherited load(ppufile);
  1321. { now we can deref the syms and defs }
  1322. deref;
  1323. { restore symtablestack }
  1324. symtablestack:=next;
  1325. {$ifdef NEWMAP}
  1326. { necessary for dependencies }
  1327. current_module.globalsymtable:=nil;
  1328. {$endif NEWMAP}
  1329. end;
  1330. procedure tglobalsymtable.write(ppufile:tcompilerppufile);
  1331. begin
  1332. { write the symtable entries }
  1333. inherited write(ppufile);
  1334. { write dbx count }
  1335. {$ifdef GDB}
  1336. if cs_gdb_dbx in aktglobalswitches then
  1337. begin
  1338. {$IfDef EXTDEBUG}
  1339. writeln('Writing dbx_count ',dbx_count,' in unit ',name^,'.ppu');
  1340. {$ENDIF EXTDEBUG}
  1341. ppufile.do_crc:=false;
  1342. ppufile.putlongint(dbx_count);
  1343. ppufile.writeentry(ibdbxcount);
  1344. ppufile.do_crc:=true;
  1345. end;
  1346. {$endif GDB}
  1347. end;
  1348. procedure tglobalsymtable.insert(sym:tsymentry);
  1349. var
  1350. hsym : tsym;
  1351. begin
  1352. { also check the global symtable }
  1353. if assigned(next) and
  1354. (next.unitid=0) then
  1355. begin
  1356. hsym:=tsym(next.search(sym.name));
  1357. if assigned(hsym) then
  1358. begin
  1359. DuplicateSym(hsym);
  1360. exit;
  1361. end;
  1362. end;
  1363. hsym:=tsym(search(sym.name));
  1364. if assigned(hsym) then
  1365. begin
  1366. { Delphi you can have a symbol with the same name as the
  1367. unit, the unit can then not be accessed anymore using
  1368. <unit>.<id>, so we can hide the symbol }
  1369. if (m_duplicate_names in aktmodeswitches) and
  1370. (hsym.typ=symconst.unitsym) then
  1371. hsym.owner.rename(hsym.name,'hidden'+hsym.name)
  1372. else
  1373. begin
  1374. DuplicateSym(hsym);
  1375. exit;
  1376. end;
  1377. end;
  1378. inherited insert(sym);
  1379. end;
  1380. {$ifdef GDB}
  1381. function tglobalsymtable.getnewtypecount : word;
  1382. begin
  1383. if not (cs_gdb_dbx in aktglobalswitches) then
  1384. getnewtypecount:=inherited getnewtypecount
  1385. else
  1386. begin
  1387. getnewtypecount:=unittypecount;
  1388. inc(unittypecount);
  1389. end;
  1390. end;
  1391. {$endif}
  1392. {****************************************************************************
  1393. TWITHSYMTABLE
  1394. ****************************************************************************}
  1395. constructor twithsymtable.create(aowner:tdef;asymsearch:TDictionary);
  1396. begin
  1397. inherited create('');
  1398. symtabletype:=withsymtable;
  1399. direct_with:=false;
  1400. withnode:=nil;
  1401. withrefnode:=nil;
  1402. { we don't need the symsearch }
  1403. symsearch.free;
  1404. { set the defaults }
  1405. symsearch:=asymsearch;
  1406. defowner:=aowner;
  1407. end;
  1408. destructor twithsymtable.destroy;
  1409. begin
  1410. symsearch:=nil;
  1411. inherited destroy;
  1412. end;
  1413. procedure twithsymtable.clear;
  1414. begin
  1415. { remove no entry from a withsymtable as it is only a pointer to the
  1416. recorddef or objectdef symtable }
  1417. end;
  1418. {****************************************************************************
  1419. TSTT_ExceptionSymtable
  1420. ****************************************************************************}
  1421. constructor tstt_exceptsymtable.create;
  1422. begin
  1423. inherited create('');
  1424. symtabletype:=stt_exceptsymtable;
  1425. end;
  1426. {*****************************************************************************
  1427. Helper Routines
  1428. *****************************************************************************}
  1429. function findunitsymtable(st:tsymtable):tsymtable;
  1430. begin
  1431. findunitsymtable:=nil;
  1432. repeat
  1433. if not assigned(st) then
  1434. internalerror(5566561);
  1435. case st.symtabletype of
  1436. localsymtable,
  1437. parasymtable,
  1438. staticsymtable :
  1439. break;
  1440. globalsymtable :
  1441. begin
  1442. findunitsymtable:=st;
  1443. break;
  1444. end;
  1445. objectsymtable,
  1446. recordsymtable :
  1447. st:=st.defowner.owner;
  1448. else
  1449. internalerror(5566562);
  1450. end;
  1451. until false;
  1452. end;
  1453. procedure duplicatesym(sym:tsym);
  1454. var
  1455. st : tsymtable;
  1456. begin
  1457. Message1(sym_e_duplicate_id,sym.realname);
  1458. st:=findunitsymtable(sym.owner);
  1459. with sym.fileinfo do
  1460. begin
  1461. if assigned(st) and (st.unitid<>0) then
  1462. Message2(sym_h_duplicate_id_where,'unit '+st.name^,tostr(line))
  1463. else
  1464. Message2(sym_h_duplicate_id_where,current_module.sourcefiles.get_file_name(fileindex),tostr(line));
  1465. end;
  1466. end;
  1467. {*****************************************************************************
  1468. Search
  1469. *****************************************************************************}
  1470. function searchsym(const s : stringid;var srsym:tsym;var srsymtable:tsymtable):boolean;
  1471. var
  1472. speedvalue : cardinal;
  1473. begin
  1474. speedvalue:=getspeedvalue(s);
  1475. srsymtable:=symtablestack;
  1476. while assigned(srsymtable) do
  1477. begin
  1478. srsym:=tsym(srsymtable.speedsearch(s,speedvalue));
  1479. if assigned(srsym) and
  1480. tstoredsym(srsym).is_visible_for_proc(aktprocdef) then
  1481. begin
  1482. searchsym:=true;
  1483. exit;
  1484. end
  1485. else
  1486. srsymtable:=srsymtable.next;
  1487. end;
  1488. searchsym:=false;
  1489. end;
  1490. function searchsymonlyin(p : tsymtable;const s : stringid):tsym;
  1491. var
  1492. srsym : tsym;
  1493. begin
  1494. { the caller have to take care if srsym=nil }
  1495. if assigned(p) then
  1496. begin
  1497. srsym:=tsym(p.search(s));
  1498. if assigned(srsym) then
  1499. begin
  1500. searchsymonlyin:=srsym;
  1501. exit;
  1502. end;
  1503. { also check in the local symtbale if it exists }
  1504. if (p=tsymtable(current_module.globalsymtable)) then
  1505. begin
  1506. srsym:=tsym(current_module.localsymtable.search(s));
  1507. if assigned(srsym) then
  1508. begin
  1509. searchsymonlyin:=srsym;
  1510. exit;
  1511. end;
  1512. end
  1513. end;
  1514. searchsymonlyin:=nil;
  1515. end;
  1516. function searchsym_in_class(classh:tobjectdef;const s : stringid):tsym;
  1517. var
  1518. speedvalue : cardinal;
  1519. topclassh : tobjectdef;
  1520. sym : tsym;
  1521. begin
  1522. speedvalue:=getspeedvalue(s);
  1523. { when the class passed is defined in this unit we
  1524. need to use the scope of that class. This is a trick
  1525. that can be used to access protected members in other
  1526. units. At least kylix supports it this way (PFV) }
  1527. if (classh.owner.symtabletype in [globalsymtable,staticsymtable]) and
  1528. (classh.owner.unitid=0) then
  1529. topclassh:=classh
  1530. else
  1531. topclassh:=nil;
  1532. sym:=nil;
  1533. while assigned(classh) do
  1534. begin
  1535. sym:=tsym(classh.symtable.speedsearch(s,speedvalue));
  1536. if assigned(sym) then
  1537. begin
  1538. if assigned(topclassh) then
  1539. begin
  1540. if tstoredsym(sym).is_visible_for_object(topclassh) then
  1541. break;
  1542. end
  1543. else
  1544. begin
  1545. if tstoredsym(sym).is_visible_for_proc(aktprocdef) then
  1546. break;
  1547. end;
  1548. end;
  1549. classh:=classh.childof;
  1550. end;
  1551. searchsym_in_class:=sym;
  1552. end;
  1553. function searchsystype(const s: stringid; var srsym: ttypesym): boolean;
  1554. var
  1555. symowner: tsymtable;
  1556. begin
  1557. if not(cs_compilesystem in aktmoduleswitches) then
  1558. srsym := ttypesym(searchsymonlyin(systemunit,s))
  1559. else
  1560. searchsym(s,srsym,symowner);
  1561. searchsystype :=
  1562. assigned(srsym) and
  1563. (srsym.typ = typesym);
  1564. end;
  1565. function searchsysvar(const s: stringid; var srsym: tvarsym; var symowner: tsymtable): boolean;
  1566. begin
  1567. if not(cs_compilesystem in aktmoduleswitches) then
  1568. begin
  1569. srsym := tvarsym(searchsymonlyin(systemunit,s));
  1570. symowner := systemunit;
  1571. end
  1572. else
  1573. searchsym(s,srsym,symowner);
  1574. searchsysvar :=
  1575. assigned(srsym) and
  1576. (srsym.typ = varsym);
  1577. end;
  1578. function search_class_member(pd : tobjectdef;const s : string):tsym;
  1579. { searches n in symtable of pd and all anchestors }
  1580. var
  1581. speedvalue : cardinal;
  1582. srsym : tsym;
  1583. begin
  1584. speedvalue:=getspeedvalue(s);
  1585. while assigned(pd) do
  1586. begin
  1587. srsym:=tsym(pd.symtable.speedsearch(s,speedvalue));
  1588. if assigned(srsym) then
  1589. begin
  1590. search_class_member:=srsym;
  1591. exit;
  1592. end;
  1593. pd:=pd.childof;
  1594. end;
  1595. search_class_member:=nil;
  1596. end;
  1597. {*****************************************************************************
  1598. Definition Helpers
  1599. *****************************************************************************}
  1600. procedure globaldef(const s : string;var t:ttype);
  1601. var st : string;
  1602. symt : tsymtable;
  1603. srsym : tsym;
  1604. srsymtable : tsymtable;
  1605. begin
  1606. srsym := nil;
  1607. if pos('.',s) > 0 then
  1608. begin
  1609. st := copy(s,1,pos('.',s)-1);
  1610. searchsym(st,srsym,srsymtable);
  1611. st := copy(s,pos('.',s)+1,255);
  1612. if assigned(srsym) then
  1613. begin
  1614. if srsym.typ = unitsym then
  1615. begin
  1616. symt := tunitsym(srsym).unitsymtable;
  1617. srsym := tsym(symt.search(st));
  1618. end else srsym := nil;
  1619. end;
  1620. end else st := s;
  1621. if srsym = nil then
  1622. searchsym(st,srsym,srsymtable);
  1623. if srsym = nil then
  1624. srsym:=searchsymonlyin(systemunit,st);
  1625. if (not assigned(srsym)) or
  1626. (srsym.typ<>typesym) then
  1627. begin
  1628. Message(type_e_type_id_expected);
  1629. t:=generrortype;
  1630. exit;
  1631. end;
  1632. t := ttypesym(srsym).restype;
  1633. end;
  1634. {****************************************************************************
  1635. Object Helpers
  1636. ****************************************************************************}
  1637. var
  1638. _defaultprop : tpropertysym;
  1639. procedure tstoredsymtable.testfordefaultproperty(p : TNamedIndexItem;arg:pointer);
  1640. begin
  1641. if (tsym(p).typ=propertysym) and
  1642. (ppo_defaultproperty in tpropertysym(p).propoptions) then
  1643. _defaultprop:=tpropertysym(p);
  1644. end;
  1645. function search_default_property(pd : tobjectdef) : tpropertysym;
  1646. { returns the default property of a class, searches also anchestors }
  1647. begin
  1648. _defaultprop:=nil;
  1649. while assigned(pd) do
  1650. begin
  1651. pd.symtable.foreach({$ifdef FPCPROCVAR}@{$endif}tstoredsymtable(pd.symtable).testfordefaultproperty,nil);
  1652. if assigned(_defaultprop) then
  1653. break;
  1654. pd:=pd.childof;
  1655. end;
  1656. search_default_property:=_defaultprop;
  1657. end;
  1658. {$ifdef UNITALIASES}
  1659. {****************************************************************************
  1660. TUNIT_ALIAS
  1661. ****************************************************************************}
  1662. constructor tunit_alias.create(const n:string);
  1663. var
  1664. i : longint;
  1665. begin
  1666. i:=pos('=',n);
  1667. if i=0 then
  1668. fail;
  1669. inherited createname(Copy(n,1,i-1));
  1670. newname:=stringdup(Copy(n,i+1,255));
  1671. end;
  1672. destructor tunit_alias.destroy;
  1673. begin
  1674. stringdispose(newname);
  1675. inherited destroy;
  1676. end;
  1677. procedure addunitalias(const n:string);
  1678. begin
  1679. unitaliases^.insert(tunit_alias,init(Upper(n))));
  1680. end;
  1681. function getunitalias(const n:string):string;
  1682. var
  1683. p : punit_alias;
  1684. begin
  1685. p:=punit_alias(unitaliases^.search(Upper(n)));
  1686. if assigned(p) then
  1687. getunitalias:=punit_alias(p).newname^
  1688. else
  1689. getunitalias:=n;
  1690. end;
  1691. {$endif UNITALIASES}
  1692. {****************************************************************************
  1693. Symtable Stack
  1694. ****************************************************************************}
  1695. procedure dellexlevel;
  1696. var
  1697. p : tsymtable;
  1698. begin
  1699. p:=symtablestack;
  1700. symtablestack:=p.next;
  1701. { symbol tables of unit interfaces are never disposed }
  1702. { this is handle by the unit unitm }
  1703. if not(p.symtabletype in [globalsymtable,stt_exceptsymtable]) then
  1704. p.free;
  1705. end;
  1706. procedure RestoreUnitSyms;
  1707. var
  1708. p : tsymtable;
  1709. begin
  1710. p:=symtablestack;
  1711. while assigned(p) do
  1712. begin
  1713. if (p.symtabletype=globalsymtable) and
  1714. assigned(tglobalsymtable(p).unitsym) and
  1715. ((tglobalsymtable(p).unitsym.owner=current_module.globalsymtable) or
  1716. (tglobalsymtable(p).unitsym.owner=current_module.localsymtable)) then
  1717. tglobalsymtable(p).unitsym.restoreunitsym;
  1718. p:=p.next;
  1719. end;
  1720. end;
  1721. {$ifdef DEBUG}
  1722. procedure test_symtablestack;
  1723. var
  1724. p : tsymtable;
  1725. i : longint;
  1726. begin
  1727. p:=symtablestack;
  1728. i:=0;
  1729. while assigned(p) do
  1730. begin
  1731. inc(i);
  1732. p:=p.next;
  1733. if i>500 then
  1734. Message(sym_f_internal_error_in_symtablestack);
  1735. end;
  1736. end;
  1737. procedure list_symtablestack;
  1738. var
  1739. p : tsymtable;
  1740. i : longint;
  1741. begin
  1742. p:=symtablestack;
  1743. i:=0;
  1744. while assigned(p) do
  1745. begin
  1746. inc(i);
  1747. writeln(i,' ',p.name^);
  1748. p:=p.next;
  1749. if i>500 then
  1750. Message(sym_f_internal_error_in_symtablestack);
  1751. end;
  1752. end;
  1753. {$endif DEBUG}
  1754. {****************************************************************************
  1755. Init/Done Symtable
  1756. ****************************************************************************}
  1757. procedure InitSymtable;
  1758. var
  1759. token : ttoken;
  1760. begin
  1761. { Reset symbolstack }
  1762. registerdef:=false;
  1763. read_member:=false;
  1764. symtablestack:=nil;
  1765. systemunit:=nil;
  1766. {$ifdef GDB}
  1767. firstglobaldef:=nil;
  1768. lastglobaldef:=nil;
  1769. globaltypecount:=1;
  1770. pglobaltypecount:=@globaltypecount;
  1771. {$endif GDB}
  1772. { create error syms and def }
  1773. generrorsym:=terrorsym.create;
  1774. generrortype.setdef(terrordef.create);
  1775. {$ifdef UNITALIASES}
  1776. { unit aliases }
  1777. unitaliases:=tdictionary.create;
  1778. {$endif}
  1779. for token:=first_overloaded to last_overloaded do
  1780. overloaded_operators[token]:=nil;
  1781. end;
  1782. procedure DoneSymtable;
  1783. begin
  1784. generrorsym.free;
  1785. generrortype.def.free;
  1786. {$ifdef UNITALIASES}
  1787. unitaliases.free;
  1788. {$endif}
  1789. end;
  1790. end.
  1791. {
  1792. $Log$
  1793. Revision 1.66 2002-08-11 13:24:15 peter
  1794. * saving of asmsymbols in ppu supported
  1795. * asmsymbollist global is removed and moved into a new class
  1796. tasmlibrarydata that will hold the info of a .a file which
  1797. corresponds with a single module. Added librarydata to tmodule
  1798. to keep the library info stored for the module. In the future the
  1799. objectfiles will also be stored to the tasmlibrarydata class
  1800. * all getlabel/newasmsymbol and friends are moved to the new class
  1801. Revision 1.65 2002/07/23 09:51:27 daniel
  1802. * Tried to make Tprocsym.defs protected. I didn't succeed but the cleanups
  1803. are worth comitting.
  1804. Revision 1.64 2002/07/16 15:34:21 florian
  1805. * exit is now a syssym instead of a keyword
  1806. Revision 1.63 2002/07/15 19:44:53 florian
  1807. * fixed crash with default parameters and stdcall calling convention
  1808. Revision 1.62 2002/07/01 18:46:28 peter
  1809. * internal linker
  1810. * reorganized aasm layer
  1811. Revision 1.61 2002/05/18 13:34:19 peter
  1812. * readded missing revisions
  1813. Revision 1.60 2002/05/16 19:46:45 carl
  1814. + defines.inc -> fpcdefs.inc to avoid conflicts if compiling by hand
  1815. + try to fix temp allocation (still in ifdef)
  1816. + generic constructor calls
  1817. + start of tassembler / tmodulebase class cleanup
  1818. Revision 1.58 2002/05/12 16:53:15 peter
  1819. * moved entry and exitcode to ncgutil and cgobj
  1820. * foreach gets extra argument for passing local data to the
  1821. iterator function
  1822. * -CR checks also class typecasts at runtime by changing them
  1823. into as
  1824. * fixed compiler to cycle with the -CR option
  1825. * fixed stabs with elf writer, finally the global variables can
  1826. be watched
  1827. * removed a lot of routines from cga unit and replaced them by
  1828. calls to cgobj
  1829. * u32bit-s32bit updates for and,or,xor nodes. When one element is
  1830. u32bit then the other is typecasted also to u32bit without giving
  1831. a rangecheck warning/error.
  1832. * fixed pascal calling method with reversing also the high tree in
  1833. the parast, detected by tcalcst3 test
  1834. Revision 1.57 2002/04/04 19:06:05 peter
  1835. * removed unused units
  1836. * use tlocation.size in cg.a_*loc*() routines
  1837. Revision 1.56 2002/03/04 19:10:11 peter
  1838. * removed compiler warnings
  1839. Revision 1.55 2002/02/03 09:30:07 peter
  1840. * more fixes for protected handling
  1841. Revision 1.54 2002/01/29 21:30:25 peter
  1842. * allow also dup id in delphi mode in interfaces
  1843. Revision 1.53 2002/01/29 19:46:00 peter
  1844. * fixed recordsymtable.insert_in() for inserting variant record fields
  1845. to not used symtable.insert() because that also updates alignmentinfo
  1846. which was already set
  1847. Revision 1.52 2002/01/24 18:25:50 peter
  1848. * implicit result variable generation for assembler routines
  1849. * removed m_tp modeswitch, use m_tp7 or not(m_fpc) instead
  1850. }