symtable.pas 67 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126
  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 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. { no, default parameters }
  1126. { lead to constsyms as well (FK) }
  1127. while assigned(sym) do
  1128. begin
  1129. if sym.typ=varsym then
  1130. begin
  1131. l:=sym.getpushsize;
  1132. sym.address:=datasize;
  1133. datasize:=align(datasize+l,dataalignment);
  1134. end;
  1135. sym:=tvarsym(sym.indexnext);
  1136. end;
  1137. end;
  1138. {****************************************************************************
  1139. TAbstractUnitSymtable
  1140. ****************************************************************************}
  1141. constructor tabstractunitsymtable.create(const n : string);
  1142. begin
  1143. inherited create(n);
  1144. symsearch.usehash;
  1145. {$ifdef GDB}
  1146. { reset GDB things }
  1147. prev_dbx_counter := dbx_counter;
  1148. dbx_counter := nil;
  1149. is_stab_written:=false;
  1150. dbx_count := -1;
  1151. {$endif GDB}
  1152. end;
  1153. {$ifdef GDB}
  1154. procedure tabstractunitsymtable.concattypestabto(asmlist : taasmoutput);
  1155. var prev_dbx_count : plongint;
  1156. begin
  1157. if is_stab_written then
  1158. exit;
  1159. if not assigned(name) then
  1160. name := stringdup('Main_program');
  1161. if (symtabletype = globalsymtable) and
  1162. (current_module.globalsymtable<>self) then
  1163. begin
  1164. unitid:=current_module.unitcount;
  1165. inc(current_module.unitcount);
  1166. end;
  1167. asmList.concat(Tai_asm_comment.Create(strpnew('Begin unit '+name^+' has index '+tostr(unitid))));
  1168. if cs_gdb_dbx in aktglobalswitches then
  1169. begin
  1170. if dbx_count_ok then
  1171. begin
  1172. asmList.concat(Tai_asm_comment.Create(strpnew('"repeated" unit '+name^
  1173. +' has index '+tostr(unitid)+' dbx count = '+tostr(dbx_count))));
  1174. asmList.concat(Tai_stabs.Create(strpnew('"'+name^+'",'
  1175. +tostr(N_EXCL)+',0,0,'+tostr(dbx_count))));
  1176. exit;
  1177. end
  1178. else if (current_module.globalsymtable<>self) then
  1179. begin
  1180. prev_dbx_count := dbx_counter;
  1181. dbx_counter := nil;
  1182. do_count_dbx:=false;
  1183. if (symtabletype = globalsymtable) and (unitid<>0) then
  1184. asmList.concat(Tai_stabs.Create(strpnew('"'+name^+'",'+tostr(N_BINCL)+',0,0,0')));
  1185. dbx_counter := @dbx_count;
  1186. dbx_count:=0;
  1187. do_count_dbx:=assigned(dbx_counter);
  1188. end;
  1189. end;
  1190. foreach({$ifdef FPCPROCVAR}@{$endif}concattypestab,asmlist);
  1191. if cs_gdb_dbx in aktglobalswitches then
  1192. begin
  1193. if (current_module.globalsymtable<>self) then
  1194. begin
  1195. dbx_counter := prev_dbx_count;
  1196. do_count_dbx:=false;
  1197. asmList.concat(Tai_asm_comment.Create(strpnew('End unit '+name^
  1198. +' has index '+tostr(unitid))));
  1199. asmList.concat(Tai_stabs.Create(strpnew('"'+name^+'",'
  1200. +tostr(N_EINCL)+',0,0,0')));
  1201. do_count_dbx:=assigned(dbx_counter);
  1202. dbx_count_ok := {true}false;
  1203. end;
  1204. end;
  1205. is_stab_written:=true;
  1206. end;
  1207. {$endif GDB}
  1208. {****************************************************************************
  1209. TStaticSymtable
  1210. ****************************************************************************}
  1211. constructor tstaticsymtable.create(const n : string);
  1212. begin
  1213. inherited create(n);
  1214. symtabletype:=staticsymtable;
  1215. end;
  1216. procedure tstaticsymtable.load(ppufile:tcompilerppufile);
  1217. begin
  1218. aktstaticsymtable:=self;
  1219. next:=symtablestack;
  1220. symtablestack:=self;
  1221. inherited load(ppufile);
  1222. { now we can deref the syms and defs }
  1223. deref;
  1224. { restore symtablestack }
  1225. symtablestack:=next;
  1226. end;
  1227. procedure tstaticsymtable.write(ppufile:tcompilerppufile);
  1228. begin
  1229. aktstaticsymtable:=self;
  1230. inherited write(ppufile);
  1231. end;
  1232. procedure tstaticsymtable.load_references(ppufile:tcompilerppufile;locals:boolean);
  1233. begin
  1234. aktstaticsymtable:=self;
  1235. inherited load_references(ppufile,locals);
  1236. end;
  1237. procedure tstaticsymtable.write_references(ppufile:tcompilerppufile;locals:boolean);
  1238. begin
  1239. aktstaticsymtable:=self;
  1240. inherited write_references(ppufile,locals);
  1241. end;
  1242. procedure tstaticsymtable.insert(sym:tsymentry);
  1243. var
  1244. hsym : tsym;
  1245. begin
  1246. { also check the global symtable }
  1247. if assigned(next) and
  1248. (next.unitid=0) then
  1249. begin
  1250. hsym:=tsym(next.search(sym.name));
  1251. if assigned(hsym) then
  1252. begin
  1253. DuplicateSym(hsym);
  1254. exit;
  1255. end;
  1256. end;
  1257. inherited insert(sym);
  1258. end;
  1259. {****************************************************************************
  1260. TGlobalSymtable
  1261. ****************************************************************************}
  1262. constructor tglobalsymtable.create(const n : string);
  1263. begin
  1264. inherited create(n);
  1265. symtabletype:=globalsymtable;
  1266. unitid:=0;
  1267. unitsym:=nil;
  1268. {$ifdef GDB}
  1269. if cs_gdb_dbx in aktglobalswitches then
  1270. begin
  1271. dbx_count := 0;
  1272. unittypecount:=1;
  1273. pglobaltypecount := @unittypecount;
  1274. {unitid:=current_module.unitcount;}
  1275. debugList.concat(Tai_asm_comment.Create(strpnew('Global '+name^+' has index '+tostr(unitid))));
  1276. debugList.concat(Tai_stabs.Create(strpnew('"'+name^+'",'+tostr(N_BINCL)+',0,0,0')));
  1277. {inc(current_module.unitcount);}
  1278. dbx_count_ok:=false;
  1279. dbx_counter:=@dbx_count;
  1280. do_count_dbx:=true;
  1281. end;
  1282. {$endif GDB}
  1283. end;
  1284. destructor tglobalsymtable.destroy;
  1285. var
  1286. pus : tunitsym;
  1287. begin
  1288. pus:=unitsym;
  1289. while assigned(pus) do
  1290. begin
  1291. unitsym:=pus.prevsym;
  1292. pus.prevsym:=nil;
  1293. pus.unitsymtable:=nil;
  1294. pus:=unitsym;
  1295. end;
  1296. inherited destroy;
  1297. end;
  1298. procedure tglobalsymtable.load(ppufile:tcompilerppufile);
  1299. begin
  1300. {$ifdef GDB}
  1301. if cs_gdb_dbx in aktglobalswitches then
  1302. begin
  1303. UnitTypeCount:=1;
  1304. PglobalTypeCount:=@UnitTypeCount;
  1305. end;
  1306. {$endif GDB}
  1307. symtablelevel:=0;
  1308. {$ifndef NEWMAP}
  1309. current_module.map^[0]:=self;
  1310. {$else NEWMAP}
  1311. current_module.globalsymtable:=self;
  1312. {$endif NEWMAP}
  1313. next:=symtablestack;
  1314. symtablestack:=self;
  1315. inherited load(ppufile);
  1316. { now we can deref the syms and defs }
  1317. deref;
  1318. { restore symtablestack }
  1319. symtablestack:=next;
  1320. {$ifdef NEWMAP}
  1321. { necessary for dependencies }
  1322. current_module.globalsymtable:=nil;
  1323. {$endif NEWMAP}
  1324. end;
  1325. procedure tglobalsymtable.write(ppufile:tcompilerppufile);
  1326. begin
  1327. { write the symtable entries }
  1328. inherited write(ppufile);
  1329. { write dbx count }
  1330. {$ifdef GDB}
  1331. if cs_gdb_dbx in aktglobalswitches then
  1332. begin
  1333. {$IfDef EXTDEBUG}
  1334. writeln('Writing dbx_count ',dbx_count,' in unit ',name^,'.ppu');
  1335. {$ENDIF EXTDEBUG}
  1336. ppufile.do_crc:=false;
  1337. ppufile.putlongint(dbx_count);
  1338. ppufile.writeentry(ibdbxcount);
  1339. ppufile.do_crc:=true;
  1340. end;
  1341. {$endif GDB}
  1342. end;
  1343. procedure tglobalsymtable.insert(sym:tsymentry);
  1344. var
  1345. hsym : tsym;
  1346. begin
  1347. { also check the global symtable }
  1348. if assigned(next) and
  1349. (next.unitid=0) then
  1350. begin
  1351. hsym:=tsym(next.search(sym.name));
  1352. if assigned(hsym) then
  1353. begin
  1354. DuplicateSym(hsym);
  1355. exit;
  1356. end;
  1357. end;
  1358. hsym:=tsym(search(sym.name));
  1359. if assigned(hsym) then
  1360. begin
  1361. { Delphi you can have a symbol with the same name as the
  1362. unit, the unit can then not be accessed anymore using
  1363. <unit>.<id>, so we can hide the symbol }
  1364. if (m_duplicate_names in aktmodeswitches) and
  1365. (hsym.typ=symconst.unitsym) then
  1366. hsym.owner.rename(hsym.name,'hidden'+hsym.name)
  1367. else
  1368. begin
  1369. DuplicateSym(hsym);
  1370. exit;
  1371. end;
  1372. end;
  1373. inherited insert(sym);
  1374. end;
  1375. {$ifdef GDB}
  1376. function tglobalsymtable.getnewtypecount : word;
  1377. begin
  1378. if not (cs_gdb_dbx in aktglobalswitches) then
  1379. getnewtypecount:=inherited getnewtypecount
  1380. else
  1381. begin
  1382. getnewtypecount:=unittypecount;
  1383. inc(unittypecount);
  1384. end;
  1385. end;
  1386. {$endif}
  1387. {****************************************************************************
  1388. TWITHSYMTABLE
  1389. ****************************************************************************}
  1390. constructor twithsymtable.create(aowner:tdef;asymsearch:TDictionary);
  1391. begin
  1392. inherited create('');
  1393. symtabletype:=withsymtable;
  1394. direct_with:=false;
  1395. withnode:=nil;
  1396. withrefnode:=nil;
  1397. { we don't need the symsearch }
  1398. symsearch.free;
  1399. { set the defaults }
  1400. symsearch:=asymsearch;
  1401. defowner:=aowner;
  1402. end;
  1403. destructor twithsymtable.destroy;
  1404. begin
  1405. symsearch:=nil;
  1406. inherited destroy;
  1407. end;
  1408. procedure twithsymtable.clear;
  1409. begin
  1410. { remove no entry from a withsymtable as it is only a pointer to the
  1411. recorddef or objectdef symtable }
  1412. end;
  1413. {****************************************************************************
  1414. TSTT_ExceptionSymtable
  1415. ****************************************************************************}
  1416. constructor tstt_exceptsymtable.create;
  1417. begin
  1418. inherited create('');
  1419. symtabletype:=stt_exceptsymtable;
  1420. end;
  1421. {*****************************************************************************
  1422. Helper Routines
  1423. *****************************************************************************}
  1424. function findunitsymtable(st:tsymtable):tsymtable;
  1425. begin
  1426. findunitsymtable:=nil;
  1427. repeat
  1428. if not assigned(st) then
  1429. internalerror(5566561);
  1430. case st.symtabletype of
  1431. localsymtable,
  1432. parasymtable,
  1433. staticsymtable :
  1434. break;
  1435. globalsymtable :
  1436. begin
  1437. findunitsymtable:=st;
  1438. break;
  1439. end;
  1440. objectsymtable,
  1441. recordsymtable :
  1442. st:=st.defowner.owner;
  1443. else
  1444. internalerror(5566562);
  1445. end;
  1446. until false;
  1447. end;
  1448. procedure duplicatesym(sym:tsym);
  1449. var
  1450. st : tsymtable;
  1451. begin
  1452. Message1(sym_e_duplicate_id,sym.realname);
  1453. st:=findunitsymtable(sym.owner);
  1454. with sym.fileinfo do
  1455. begin
  1456. if assigned(st) and (st.unitid<>0) then
  1457. Message2(sym_h_duplicate_id_where,'unit '+st.name^,tostr(line))
  1458. else
  1459. Message2(sym_h_duplicate_id_where,current_module.sourcefiles.get_file_name(fileindex),tostr(line));
  1460. end;
  1461. end;
  1462. {*****************************************************************************
  1463. Search
  1464. *****************************************************************************}
  1465. function searchsym(const s : stringid;var srsym:tsym;var srsymtable:tsymtable):boolean;
  1466. var
  1467. speedvalue : cardinal;
  1468. begin
  1469. speedvalue:=getspeedvalue(s);
  1470. srsymtable:=symtablestack;
  1471. while assigned(srsymtable) do
  1472. begin
  1473. srsym:=tsym(srsymtable.speedsearch(s,speedvalue));
  1474. if assigned(srsym) and
  1475. tstoredsym(srsym).is_visible_for_proc(aktprocdef) then
  1476. begin
  1477. searchsym:=true;
  1478. exit;
  1479. end
  1480. else
  1481. srsymtable:=srsymtable.next;
  1482. end;
  1483. searchsym:=false;
  1484. end;
  1485. function searchsymonlyin(p : tsymtable;const s : stringid):tsym;
  1486. var
  1487. srsym : tsym;
  1488. begin
  1489. { the caller have to take care if srsym=nil }
  1490. if assigned(p) then
  1491. begin
  1492. srsym:=tsym(p.search(s));
  1493. if assigned(srsym) then
  1494. begin
  1495. searchsymonlyin:=srsym;
  1496. exit;
  1497. end;
  1498. { also check in the local symtbale if it exists }
  1499. if (p=tsymtable(current_module.globalsymtable)) then
  1500. begin
  1501. srsym:=tsym(current_module.localsymtable.search(s));
  1502. if assigned(srsym) then
  1503. begin
  1504. searchsymonlyin:=srsym;
  1505. exit;
  1506. end;
  1507. end
  1508. end;
  1509. searchsymonlyin:=nil;
  1510. end;
  1511. function searchsym_in_class(classh:tobjectdef;const s : stringid):tsym;
  1512. var
  1513. speedvalue : cardinal;
  1514. topclassh : tobjectdef;
  1515. sym : tsym;
  1516. begin
  1517. speedvalue:=getspeedvalue(s);
  1518. { when the class passed is defined in this unit we
  1519. need to use the scope of that class. This is a trick
  1520. that can be used to access protected members in other
  1521. units. At least kylix supports it this way (PFV) }
  1522. if (classh.owner.symtabletype in [globalsymtable,staticsymtable]) and
  1523. (classh.owner.unitid=0) then
  1524. topclassh:=classh
  1525. else
  1526. topclassh:=nil;
  1527. sym:=nil;
  1528. while assigned(classh) do
  1529. begin
  1530. sym:=tsym(classh.symtable.speedsearch(s,speedvalue));
  1531. if assigned(sym) then
  1532. begin
  1533. if assigned(topclassh) then
  1534. begin
  1535. if tstoredsym(sym).is_visible_for_object(topclassh) then
  1536. break;
  1537. end
  1538. else
  1539. begin
  1540. if tstoredsym(sym).is_visible_for_proc(aktprocdef) then
  1541. break;
  1542. end;
  1543. end;
  1544. classh:=classh.childof;
  1545. end;
  1546. searchsym_in_class:=sym;
  1547. end;
  1548. function searchsystype(const s: stringid; var srsym: ttypesym): boolean;
  1549. var
  1550. symowner: tsymtable;
  1551. begin
  1552. if not(cs_compilesystem in aktmoduleswitches) then
  1553. srsym := ttypesym(searchsymonlyin(systemunit,s))
  1554. else
  1555. searchsym(s,srsym,symowner);
  1556. searchsystype :=
  1557. assigned(srsym) and
  1558. (srsym.typ = typesym);
  1559. end;
  1560. function searchsysvar(const s: stringid; var srsym: tvarsym; var symowner: tsymtable): boolean;
  1561. begin
  1562. if not(cs_compilesystem in aktmoduleswitches) then
  1563. begin
  1564. srsym := tvarsym(searchsymonlyin(systemunit,s));
  1565. symowner := systemunit;
  1566. end
  1567. else
  1568. searchsym(s,srsym,symowner);
  1569. searchsysvar :=
  1570. assigned(srsym) and
  1571. (srsym.typ = varsym);
  1572. end;
  1573. function search_class_member(pd : tobjectdef;const s : string):tsym;
  1574. { searches n in symtable of pd and all anchestors }
  1575. var
  1576. speedvalue : cardinal;
  1577. srsym : tsym;
  1578. begin
  1579. speedvalue:=getspeedvalue(s);
  1580. while assigned(pd) do
  1581. begin
  1582. srsym:=tsym(pd.symtable.speedsearch(s,speedvalue));
  1583. if assigned(srsym) then
  1584. begin
  1585. search_class_member:=srsym;
  1586. exit;
  1587. end;
  1588. pd:=pd.childof;
  1589. end;
  1590. search_class_member:=nil;
  1591. end;
  1592. {*****************************************************************************
  1593. Definition Helpers
  1594. *****************************************************************************}
  1595. procedure globaldef(const s : string;var t:ttype);
  1596. var st : string;
  1597. symt : tsymtable;
  1598. srsym : tsym;
  1599. srsymtable : tsymtable;
  1600. begin
  1601. srsym := nil;
  1602. if pos('.',s) > 0 then
  1603. begin
  1604. st := copy(s,1,pos('.',s)-1);
  1605. searchsym(st,srsym,srsymtable);
  1606. st := copy(s,pos('.',s)+1,255);
  1607. if assigned(srsym) then
  1608. begin
  1609. if srsym.typ = unitsym then
  1610. begin
  1611. symt := tunitsym(srsym).unitsymtable;
  1612. srsym := tsym(symt.search(st));
  1613. end else srsym := nil;
  1614. end;
  1615. end else st := s;
  1616. if srsym = nil then
  1617. searchsym(st,srsym,srsymtable);
  1618. if srsym = nil then
  1619. srsym:=searchsymonlyin(systemunit,st);
  1620. if (not assigned(srsym)) or
  1621. (srsym.typ<>typesym) then
  1622. begin
  1623. Message(type_e_type_id_expected);
  1624. t:=generrortype;
  1625. exit;
  1626. end;
  1627. t := ttypesym(srsym).restype;
  1628. end;
  1629. {****************************************************************************
  1630. Object Helpers
  1631. ****************************************************************************}
  1632. var
  1633. _defaultprop : tpropertysym;
  1634. procedure tstoredsymtable.testfordefaultproperty(p : TNamedIndexItem;arg:pointer);
  1635. begin
  1636. if (tsym(p).typ=propertysym) and
  1637. (ppo_defaultproperty in tpropertysym(p).propoptions) then
  1638. _defaultprop:=tpropertysym(p);
  1639. end;
  1640. function search_default_property(pd : tobjectdef) : tpropertysym;
  1641. { returns the default property of a class, searches also anchestors }
  1642. begin
  1643. _defaultprop:=nil;
  1644. while assigned(pd) do
  1645. begin
  1646. pd.symtable.foreach({$ifdef FPCPROCVAR}@{$endif}tstoredsymtable(pd.symtable).testfordefaultproperty,nil);
  1647. if assigned(_defaultprop) then
  1648. break;
  1649. pd:=pd.childof;
  1650. end;
  1651. search_default_property:=_defaultprop;
  1652. end;
  1653. {$ifdef UNITALIASES}
  1654. {****************************************************************************
  1655. TUNIT_ALIAS
  1656. ****************************************************************************}
  1657. constructor tunit_alias.create(const n:string);
  1658. var
  1659. i : longint;
  1660. begin
  1661. i:=pos('=',n);
  1662. if i=0 then
  1663. fail;
  1664. inherited createname(Copy(n,1,i-1));
  1665. newname:=stringdup(Copy(n,i+1,255));
  1666. end;
  1667. destructor tunit_alias.destroy;
  1668. begin
  1669. stringdispose(newname);
  1670. inherited destroy;
  1671. end;
  1672. procedure addunitalias(const n:string);
  1673. begin
  1674. unitaliases^.insert(tunit_alias,init(Upper(n))));
  1675. end;
  1676. function getunitalias(const n:string):string;
  1677. var
  1678. p : punit_alias;
  1679. begin
  1680. p:=punit_alias(unitaliases^.search(Upper(n)));
  1681. if assigned(p) then
  1682. getunitalias:=punit_alias(p).newname^
  1683. else
  1684. getunitalias:=n;
  1685. end;
  1686. {$endif UNITALIASES}
  1687. {****************************************************************************
  1688. Symtable Stack
  1689. ****************************************************************************}
  1690. procedure dellexlevel;
  1691. var
  1692. p : tsymtable;
  1693. begin
  1694. p:=symtablestack;
  1695. symtablestack:=p.next;
  1696. { symbol tables of unit interfaces are never disposed }
  1697. { this is handle by the unit unitm }
  1698. if not(p.symtabletype in [globalsymtable,stt_exceptsymtable]) then
  1699. p.free;
  1700. end;
  1701. procedure RestoreUnitSyms;
  1702. var
  1703. p : tsymtable;
  1704. begin
  1705. p:=symtablestack;
  1706. while assigned(p) do
  1707. begin
  1708. if (p.symtabletype=globalsymtable) and
  1709. assigned(tglobalsymtable(p).unitsym) and
  1710. ((tglobalsymtable(p).unitsym.owner=current_module.globalsymtable) or
  1711. (tglobalsymtable(p).unitsym.owner=current_module.localsymtable)) then
  1712. tglobalsymtable(p).unitsym.restoreunitsym;
  1713. p:=p.next;
  1714. end;
  1715. end;
  1716. {$ifdef DEBUG}
  1717. procedure test_symtablestack;
  1718. var
  1719. p : tsymtable;
  1720. i : longint;
  1721. begin
  1722. p:=symtablestack;
  1723. i:=0;
  1724. while assigned(p) do
  1725. begin
  1726. inc(i);
  1727. p:=p.next;
  1728. if i>500 then
  1729. Message(sym_f_internal_error_in_symtablestack);
  1730. end;
  1731. end;
  1732. procedure list_symtablestack;
  1733. var
  1734. p : tsymtable;
  1735. i : longint;
  1736. begin
  1737. p:=symtablestack;
  1738. i:=0;
  1739. while assigned(p) do
  1740. begin
  1741. inc(i);
  1742. writeln(i,' ',p.name^);
  1743. p:=p.next;
  1744. if i>500 then
  1745. Message(sym_f_internal_error_in_symtablestack);
  1746. end;
  1747. end;
  1748. {$endif DEBUG}
  1749. {****************************************************************************
  1750. Init/Done Symtable
  1751. ****************************************************************************}
  1752. procedure InitSymtable;
  1753. var
  1754. token : ttoken;
  1755. begin
  1756. { Reset symbolstack }
  1757. registerdef:=false;
  1758. read_member:=false;
  1759. symtablestack:=nil;
  1760. systemunit:=nil;
  1761. {$ifdef GDB}
  1762. firstglobaldef:=nil;
  1763. lastglobaldef:=nil;
  1764. globaltypecount:=1;
  1765. pglobaltypecount:=@globaltypecount;
  1766. {$endif GDB}
  1767. { create error syms and def }
  1768. generrorsym:=terrorsym.create;
  1769. generrortype.setdef(terrordef.create);
  1770. {$ifdef UNITALIASES}
  1771. { unit aliases }
  1772. unitaliases:=tdictionary.create;
  1773. {$endif}
  1774. for token:=first_overloaded to last_overloaded do
  1775. overloaded_operators[token]:=nil;
  1776. end;
  1777. procedure DoneSymtable;
  1778. begin
  1779. generrorsym.free;
  1780. generrortype.def.free;
  1781. {$ifdef UNITALIASES}
  1782. unitaliases.free;
  1783. {$endif}
  1784. end;
  1785. end.
  1786. {
  1787. $Log$
  1788. Revision 1.64 2002-07-16 15:34:21 florian
  1789. * exit is now a syssym instead of a keyword
  1790. Revision 1.63 2002/07/15 19:44:53 florian
  1791. * fixed crash with default parameters and stdcall calling convention
  1792. Revision 1.62 2002/07/01 18:46:28 peter
  1793. * internal linker
  1794. * reorganized aasm layer
  1795. Revision 1.61 2002/05/18 13:34:19 peter
  1796. * readded missing revisions
  1797. Revision 1.60 2002/05/16 19:46:45 carl
  1798. + defines.inc -> fpcdefs.inc to avoid conflicts if compiling by hand
  1799. + try to fix temp allocation (still in ifdef)
  1800. + generic constructor calls
  1801. + start of tassembler / tmodulebase class cleanup
  1802. Revision 1.58 2002/05/12 16:53:15 peter
  1803. * moved entry and exitcode to ncgutil and cgobj
  1804. * foreach gets extra argument for passing local data to the
  1805. iterator function
  1806. * -CR checks also class typecasts at runtime by changing them
  1807. into as
  1808. * fixed compiler to cycle with the -CR option
  1809. * fixed stabs with elf writer, finally the global variables can
  1810. be watched
  1811. * removed a lot of routines from cga unit and replaced them by
  1812. calls to cgobj
  1813. * u32bit-s32bit updates for and,or,xor nodes. When one element is
  1814. u32bit then the other is typecasted also to u32bit without giving
  1815. a rangecheck warning/error.
  1816. * fixed pascal calling method with reversing also the high tree in
  1817. the parast, detected by tcalcst3 test
  1818. Revision 1.57 2002/04/04 19:06:05 peter
  1819. * removed unused units
  1820. * use tlocation.size in cg.a_*loc*() routines
  1821. Revision 1.56 2002/03/04 19:10:11 peter
  1822. * removed compiler warnings
  1823. Revision 1.55 2002/02/03 09:30:07 peter
  1824. * more fixes for protected handling
  1825. Revision 1.54 2002/01/29 21:30:25 peter
  1826. * allow also dup id in delphi mode in interfaces
  1827. Revision 1.53 2002/01/29 19:46:00 peter
  1828. * fixed recordsymtable.insert_in() for inserting variant record fields
  1829. to not used symtable.insert() because that also updates alignmentinfo
  1830. which was already set
  1831. Revision 1.52 2002/01/24 18:25:50 peter
  1832. * implicit result variable generation for assembler routines
  1833. * removed m_tp modeswitch, use m_tp7 or not(m_fpc) instead
  1834. }