symtable.pas 67 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123
  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. { already got a procsym, only add defs of the current procsym }
  772. Tprocsym(srsym).concat_procdefs_to(overloaded_operators[t]);
  773. symtablestack:=srsym.owner.next;
  774. end
  775. else
  776. begin
  777. symtablestack:=nil;
  778. end;
  779. { search for same procsym in other units }
  780. end;
  781. symtablestack:=self;
  782. end;
  783. make_ref:=true;
  784. symtablestack:=storesymtablestack;
  785. end;
  786. {***********************************************
  787. Process all entries
  788. ***********************************************}
  789. { checks, if all procsyms and methods are defined }
  790. procedure tstoredsymtable.check_forwards;
  791. begin
  792. foreach({$ifdef FPCPROCVAR}@{$endif}check_forward,nil);
  793. end;
  794. procedure tstoredsymtable.checklabels;
  795. begin
  796. foreach({$ifdef FPCPROCVAR}@{$endif}labeldefined,nil);
  797. end;
  798. procedure tstoredsymtable.allunitsused;
  799. begin
  800. foreach({$ifdef FPCPROCVAR}@{$endif}unitsymbolused,nil);
  801. end;
  802. procedure tstoredsymtable.allsymbolsused;
  803. begin
  804. foreach({$ifdef FPCPROCVAR}@{$endif}varsymbolused,nil);
  805. end;
  806. procedure tstoredsymtable.allprivatesused;
  807. begin
  808. foreach({$ifdef FPCPROCVAR}@{$endif}objectprivatesymbolused,nil);
  809. end;
  810. procedure tstoredsymtable.unchain_overloaded;
  811. begin
  812. foreach({$ifdef FPCPROCVAR}@{$endif}unchain_overloads,nil);
  813. end;
  814. {$ifdef GDB}
  815. procedure tstoredsymtable.concatstabto(asmlist : taasmoutput);
  816. begin
  817. if symtabletype in [inlineparasymtable,inlinelocalsymtable] then
  818. foreach({$ifdef FPCPROCVAR}@{$endif}resetstab,nil);
  819. foreach({$ifdef FPCPROCVAR}@{$endif}concatstab,asmlist);
  820. end;
  821. {$endif}
  822. { returns true, if p contains data which needs init/final code }
  823. function tstoredsymtable.needs_init_final : boolean;
  824. begin
  825. b_needs_init_final:=false;
  826. foreach({$ifdef FPCPROCVAR}@{$endif}_needs_init_final,nil);
  827. needs_init_final:=b_needs_init_final;
  828. end;
  829. {****************************************************************************
  830. TAbstractRecordSymtable
  831. ****************************************************************************}
  832. procedure tabstractrecordsymtable.load(ppufile:tcompilerppufile);
  833. var
  834. storesymtable : tsymtable;
  835. begin
  836. storesymtable:=aktrecordsymtable;
  837. aktrecordsymtable:=self;
  838. inherited load(ppufile);
  839. aktrecordsymtable:=storesymtable;
  840. end;
  841. procedure tabstractrecordsymtable.write(ppufile:tcompilerppufile);
  842. var
  843. oldtyp : byte;
  844. storesymtable : tsymtable;
  845. begin
  846. storesymtable:=aktrecordsymtable;
  847. aktrecordsymtable:=self;
  848. oldtyp:=ppufile.entrytyp;
  849. ppufile.entrytyp:=subentryid;
  850. inherited write(ppufile);
  851. ppufile.entrytyp:=oldtyp;
  852. aktrecordsymtable:=storesymtable;
  853. end;
  854. procedure tabstractrecordsymtable.load_references(ppufile:tcompilerppufile;locals:boolean);
  855. var
  856. storesymtable : tsymtable;
  857. begin
  858. storesymtable:=aktrecordsymtable;
  859. aktrecordsymtable:=self;
  860. inherited load_references(ppufile,locals);
  861. aktrecordsymtable:=storesymtable;
  862. end;
  863. procedure tabstractrecordsymtable.write_references(ppufile:tcompilerppufile;locals:boolean);
  864. var
  865. storesymtable : tsymtable;
  866. begin
  867. storesymtable:=aktrecordsymtable;
  868. aktrecordsymtable:=self;
  869. inherited write_references(ppufile,locals);
  870. aktrecordsymtable:=storesymtable;
  871. end;
  872. procedure TStoredSymtable._needs_init_final(p : tnamedindexitem;arg:pointer);
  873. begin
  874. if (not b_needs_init_final) and
  875. (tsym(p).typ=varsym) and
  876. assigned(tvarsym(p).vartype.def) and
  877. not is_class(tvarsym(p).vartype.def) and
  878. tstoreddef(tvarsym(p).vartype.def).needs_inittable then
  879. b_needs_init_final:=true;
  880. end;
  881. {****************************************************************************
  882. TRecordSymtable
  883. ****************************************************************************}
  884. constructor trecordsymtable.create;
  885. begin
  886. inherited create('');
  887. symtabletype:=recordsymtable;
  888. end;
  889. { this procedure is reserved for inserting case variant into
  890. a record symtable }
  891. { the offset is the location of the start of the variant
  892. and datasize and dataalignment corresponds to
  893. the complete size (see code in pdecl unit) PM }
  894. procedure trecordsymtable.insert_in(tsymt : tsymtable;offset : longint);
  895. var
  896. ps,nps : tvarsym;
  897. pd,npd : tdef;
  898. storesize,storealign : longint;
  899. begin
  900. storesize:=tsymt.datasize;
  901. storealign:=tsymt.dataalignment;
  902. tsymt.datasize:=offset;
  903. ps:=tvarsym(symindex.first);
  904. while assigned(ps) do
  905. begin
  906. nps:=tvarsym(ps.indexnext);
  907. { remove from current symtable }
  908. symindex.deleteindex(ps);
  909. ps.left:=nil;
  910. ps.right:=nil;
  911. { add to symt }
  912. ps.owner:=tsymt;
  913. tsymt.datasize:=ps.address+offset;
  914. tsymt.symindex.insert(ps);
  915. tsymt.symsearch.insert(ps);
  916. { update address }
  917. ps.address:=tsymt.datasize;
  918. { next }
  919. ps:=nps;
  920. end;
  921. pd:=tdef(defindex.first);
  922. while assigned(pd) do
  923. begin
  924. npd:=tdef(pd.indexnext);
  925. defindex.deleteindex(pd);
  926. pd.left:=nil;
  927. pd.right:=nil;
  928. tsymt.registerdef(pd);
  929. pd:=npd;
  930. end;
  931. tsymt.datasize:=storesize;
  932. tsymt.dataalignment:=storealign;
  933. end;
  934. {****************************************************************************
  935. TObjectSymtable
  936. ****************************************************************************}
  937. constructor tobjectsymtable.create(const n:string);
  938. begin
  939. inherited create(n);
  940. symtabletype:=objectsymtable;
  941. end;
  942. procedure tobjectsymtable.insert(sym:tsymentry);
  943. var
  944. hsym : tsym;
  945. begin
  946. { check for duplicate field id in inherited classes }
  947. if (sym.typ=varsym) and
  948. assigned(defowner) and
  949. (
  950. not(m_delphi in aktmodeswitches) or
  951. is_object(tdef(defowner))
  952. ) then
  953. begin
  954. { but private ids can be reused }
  955. hsym:=search_class_member(tobjectdef(defowner),sym.name);
  956. if assigned(hsym) and
  957. tstoredsym(hsym).is_visible_for_object(tobjectdef(defowner)) then
  958. begin
  959. DuplicateSym(hsym);
  960. exit;
  961. end;
  962. end;
  963. inherited insert(sym);
  964. end;
  965. {****************************************************************************
  966. TAbstractLocalSymtable
  967. ****************************************************************************}
  968. procedure tabstractlocalsymtable.load(ppufile:tcompilerppufile);
  969. var
  970. storesymtable : tsymtable;
  971. begin
  972. storesymtable:=aktlocalsymtable;
  973. aktlocalsymtable:=self;
  974. inherited load(ppufile);
  975. aktlocalsymtable:=storesymtable;
  976. end;
  977. procedure tabstractlocalsymtable.write(ppufile:tcompilerppufile);
  978. var
  979. oldtyp : byte;
  980. storesymtable : tsymtable;
  981. begin
  982. storesymtable:=aktlocalsymtable;
  983. aktlocalsymtable:=self;
  984. oldtyp:=ppufile.entrytyp;
  985. ppufile.entrytyp:=subentryid;
  986. { write definitions }
  987. writedefs(ppufile);
  988. { write symbols }
  989. writesyms(ppufile);
  990. ppufile.entrytyp:=oldtyp;
  991. aktlocalsymtable:=storesymtable;
  992. end;
  993. procedure tabstractlocalsymtable.load_references(ppufile:tcompilerppufile;locals:boolean);
  994. var
  995. storesymtable : tsymtable;
  996. begin
  997. storesymtable:=aktlocalsymtable;
  998. aktlocalsymtable:=self;
  999. inherited load_references(ppufile,locals);
  1000. aktlocalsymtable:=storesymtable;
  1001. end;
  1002. procedure tabstractlocalsymtable.write_references(ppufile:tcompilerppufile;locals:boolean);
  1003. var
  1004. storesymtable : tsymtable;
  1005. begin
  1006. storesymtable:=aktlocalsymtable;
  1007. aktlocalsymtable:=self;
  1008. inherited write_references(ppufile,locals);
  1009. aktlocalsymtable:=storesymtable;
  1010. end;
  1011. {****************************************************************************
  1012. TLocalSymtable
  1013. ****************************************************************************}
  1014. constructor tlocalsymtable.create;
  1015. begin
  1016. inherited create('');
  1017. symtabletype:=localsymtable;
  1018. end;
  1019. procedure tlocalsymtable.insert(sym:tsymentry);
  1020. var
  1021. hsym : tsym;
  1022. begin
  1023. if assigned(next) then
  1024. begin
  1025. if (next.symtabletype=parasymtable) then
  1026. begin
  1027. hsym:=tsym(next.search(sym.name));
  1028. if assigned(hsym) then
  1029. begin
  1030. { a parameter and the function can have the same
  1031. name in TP and Delphi, but RESULT not }
  1032. if (m_duplicate_names in aktmodeswitches) and
  1033. (sym.typ=funcretsym) and
  1034. not((m_result in aktmodeswitches) and
  1035. (sym.name='RESULT')) then
  1036. sym.name:='hidden'+sym.name
  1037. else
  1038. begin
  1039. DuplicateSym(hsym);
  1040. exit;
  1041. end;
  1042. end;
  1043. end;
  1044. { check for duplicate id in local symtable of methods }
  1045. if assigned(next.next) and
  1046. { funcretsym is allowed !! }
  1047. (sym.typ <> funcretsym) and
  1048. (next.next.symtabletype=objectsymtable) then
  1049. begin
  1050. hsym:=search_class_member(tobjectdef(next.next.defowner),sym.name);
  1051. if assigned(hsym) and
  1052. { private ids can be reused }
  1053. (not(sp_private in hsym.symoptions) or
  1054. (hsym.owner.defowner.owner.symtabletype<>globalsymtable)) then
  1055. begin
  1056. { delphi allows to reuse the names in a class, but not
  1057. in object (tp7 compatible) }
  1058. if not((m_delphi in aktmodeswitches) and
  1059. is_class(tdef(next.next.defowner))) then
  1060. begin
  1061. DuplicateSym(hsym);
  1062. exit;
  1063. end;
  1064. end;
  1065. end;
  1066. end;
  1067. inherited insert(sym);
  1068. end;
  1069. {****************************************************************************
  1070. TParaSymtable
  1071. ****************************************************************************}
  1072. constructor tparasymtable.create;
  1073. begin
  1074. inherited create('');
  1075. symtabletype:=parasymtable;
  1076. dataalignment:=aktalignment.paraalign;
  1077. end;
  1078. procedure tparasymtable.insert(sym:tsymentry);
  1079. var
  1080. hsym : tsym;
  1081. begin
  1082. { check for duplicate id in para symtable of methods }
  1083. if assigned(procinfo^._class) and
  1084. { but not in nested procedures !}
  1085. (not(assigned(procinfo^.parent)) or
  1086. (assigned(procinfo^.parent) and
  1087. not(assigned(procinfo^.parent^._class)))
  1088. ) and
  1089. { funcretsym is allowed !! }
  1090. (sym.typ<>funcretsym) then
  1091. begin
  1092. hsym:=search_class_member(procinfo^._class,sym.name);
  1093. { private ids can be reused }
  1094. if assigned(hsym) and
  1095. tstoredsym(hsym).is_visible_for_object(procinfo^._class) then
  1096. begin
  1097. { delphi allows to reuse the names in a class, but not
  1098. in object (tp7 compatible) }
  1099. if not((m_delphi in aktmodeswitches) and
  1100. is_class_or_interface(procinfo^._class)) then
  1101. begin
  1102. DuplicateSym(hsym);
  1103. exit;
  1104. end;
  1105. end;
  1106. end;
  1107. inherited insert(sym);
  1108. end;
  1109. procedure tparasymtable.set_alignment(_alignment : longint);
  1110. var
  1111. sym : tvarsym;
  1112. l : longint;
  1113. begin
  1114. dataalignment:=_alignment;
  1115. sym:=tvarsym(symindex.first);
  1116. datasize:=0;
  1117. { there can be only varsyms }
  1118. { no, default parameters }
  1119. { lead to constsyms as well (FK) }
  1120. while assigned(sym) do
  1121. begin
  1122. if sym.typ=varsym then
  1123. begin
  1124. l:=sym.getpushsize;
  1125. sym.address:=datasize;
  1126. datasize:=align(datasize+l,dataalignment);
  1127. end;
  1128. sym:=tvarsym(sym.indexnext);
  1129. end;
  1130. end;
  1131. {****************************************************************************
  1132. TAbstractUnitSymtable
  1133. ****************************************************************************}
  1134. constructor tabstractunitsymtable.create(const n : string);
  1135. begin
  1136. inherited create(n);
  1137. symsearch.usehash;
  1138. {$ifdef GDB}
  1139. { reset GDB things }
  1140. prev_dbx_counter := dbx_counter;
  1141. dbx_counter := nil;
  1142. is_stab_written:=false;
  1143. dbx_count := -1;
  1144. {$endif GDB}
  1145. end;
  1146. {$ifdef GDB}
  1147. procedure tabstractunitsymtable.concattypestabto(asmlist : taasmoutput);
  1148. var prev_dbx_count : plongint;
  1149. begin
  1150. if is_stab_written then
  1151. exit;
  1152. if not assigned(name) then
  1153. name := stringdup('Main_program');
  1154. if (symtabletype = globalsymtable) and
  1155. (current_module.globalsymtable<>self) then
  1156. begin
  1157. unitid:=current_module.unitcount;
  1158. inc(current_module.unitcount);
  1159. end;
  1160. asmList.concat(Tai_asm_comment.Create(strpnew('Begin unit '+name^+' has index '+tostr(unitid))));
  1161. if cs_gdb_dbx in aktglobalswitches then
  1162. begin
  1163. if dbx_count_ok then
  1164. begin
  1165. asmList.concat(Tai_asm_comment.Create(strpnew('"repeated" unit '+name^
  1166. +' has index '+tostr(unitid)+' dbx count = '+tostr(dbx_count))));
  1167. asmList.concat(Tai_stabs.Create(strpnew('"'+name^+'",'
  1168. +tostr(N_EXCL)+',0,0,'+tostr(dbx_count))));
  1169. exit;
  1170. end
  1171. else if (current_module.globalsymtable<>self) then
  1172. begin
  1173. prev_dbx_count := dbx_counter;
  1174. dbx_counter := nil;
  1175. do_count_dbx:=false;
  1176. if (symtabletype = globalsymtable) and (unitid<>0) then
  1177. asmList.concat(Tai_stabs.Create(strpnew('"'+name^+'",'+tostr(N_BINCL)+',0,0,0')));
  1178. dbx_counter := @dbx_count;
  1179. dbx_count:=0;
  1180. do_count_dbx:=assigned(dbx_counter);
  1181. end;
  1182. end;
  1183. foreach({$ifdef FPCPROCVAR}@{$endif}concattypestab,asmlist);
  1184. if cs_gdb_dbx in aktglobalswitches then
  1185. begin
  1186. if (current_module.globalsymtable<>self) then
  1187. begin
  1188. dbx_counter := prev_dbx_count;
  1189. do_count_dbx:=false;
  1190. asmList.concat(Tai_asm_comment.Create(strpnew('End unit '+name^
  1191. +' has index '+tostr(unitid))));
  1192. asmList.concat(Tai_stabs.Create(strpnew('"'+name^+'",'
  1193. +tostr(N_EINCL)+',0,0,0')));
  1194. do_count_dbx:=assigned(dbx_counter);
  1195. dbx_count_ok := {true}false;
  1196. end;
  1197. end;
  1198. is_stab_written:=true;
  1199. end;
  1200. {$endif GDB}
  1201. {****************************************************************************
  1202. TStaticSymtable
  1203. ****************************************************************************}
  1204. constructor tstaticsymtable.create(const n : string);
  1205. begin
  1206. inherited create(n);
  1207. symtabletype:=staticsymtable;
  1208. end;
  1209. procedure tstaticsymtable.load(ppufile:tcompilerppufile);
  1210. begin
  1211. aktstaticsymtable:=self;
  1212. next:=symtablestack;
  1213. symtablestack:=self;
  1214. inherited load(ppufile);
  1215. { now we can deref the syms and defs }
  1216. deref;
  1217. { restore symtablestack }
  1218. symtablestack:=next;
  1219. end;
  1220. procedure tstaticsymtable.write(ppufile:tcompilerppufile);
  1221. begin
  1222. aktstaticsymtable:=self;
  1223. inherited write(ppufile);
  1224. end;
  1225. procedure tstaticsymtable.load_references(ppufile:tcompilerppufile;locals:boolean);
  1226. begin
  1227. aktstaticsymtable:=self;
  1228. inherited load_references(ppufile,locals);
  1229. end;
  1230. procedure tstaticsymtable.write_references(ppufile:tcompilerppufile;locals:boolean);
  1231. begin
  1232. aktstaticsymtable:=self;
  1233. inherited write_references(ppufile,locals);
  1234. end;
  1235. procedure tstaticsymtable.insert(sym:tsymentry);
  1236. var
  1237. hsym : tsym;
  1238. begin
  1239. { also check the global symtable }
  1240. if assigned(next) and
  1241. (next.unitid=0) then
  1242. begin
  1243. hsym:=tsym(next.search(sym.name));
  1244. if assigned(hsym) then
  1245. begin
  1246. DuplicateSym(hsym);
  1247. exit;
  1248. end;
  1249. end;
  1250. inherited insert(sym);
  1251. end;
  1252. {****************************************************************************
  1253. TGlobalSymtable
  1254. ****************************************************************************}
  1255. constructor tglobalsymtable.create(const n : string);
  1256. begin
  1257. inherited create(n);
  1258. symtabletype:=globalsymtable;
  1259. unitid:=0;
  1260. unitsym:=nil;
  1261. {$ifdef GDB}
  1262. if cs_gdb_dbx in aktglobalswitches then
  1263. begin
  1264. dbx_count := 0;
  1265. unittypecount:=1;
  1266. pglobaltypecount := @unittypecount;
  1267. {unitid:=current_module.unitcount;}
  1268. debugList.concat(Tai_asm_comment.Create(strpnew('Global '+name^+' has index '+tostr(unitid))));
  1269. debugList.concat(Tai_stabs.Create(strpnew('"'+name^+'",'+tostr(N_BINCL)+',0,0,0')));
  1270. {inc(current_module.unitcount);}
  1271. dbx_count_ok:=false;
  1272. dbx_counter:=@dbx_count;
  1273. do_count_dbx:=true;
  1274. end;
  1275. {$endif GDB}
  1276. end;
  1277. destructor tglobalsymtable.destroy;
  1278. var
  1279. pus : tunitsym;
  1280. begin
  1281. pus:=unitsym;
  1282. while assigned(pus) do
  1283. begin
  1284. unitsym:=pus.prevsym;
  1285. pus.prevsym:=nil;
  1286. pus.unitsymtable:=nil;
  1287. pus:=unitsym;
  1288. end;
  1289. inherited destroy;
  1290. end;
  1291. procedure tglobalsymtable.load(ppufile:tcompilerppufile);
  1292. begin
  1293. {$ifdef GDB}
  1294. if cs_gdb_dbx in aktglobalswitches then
  1295. begin
  1296. UnitTypeCount:=1;
  1297. PglobalTypeCount:=@UnitTypeCount;
  1298. end;
  1299. {$endif GDB}
  1300. symtablelevel:=0;
  1301. {$ifndef NEWMAP}
  1302. current_module.map^[0]:=self;
  1303. {$else NEWMAP}
  1304. current_module.globalsymtable:=self;
  1305. {$endif NEWMAP}
  1306. next:=symtablestack;
  1307. symtablestack:=self;
  1308. inherited load(ppufile);
  1309. { now we can deref the syms and defs }
  1310. deref;
  1311. { restore symtablestack }
  1312. symtablestack:=next;
  1313. {$ifdef NEWMAP}
  1314. { necessary for dependencies }
  1315. current_module.globalsymtable:=nil;
  1316. {$endif NEWMAP}
  1317. end;
  1318. procedure tglobalsymtable.write(ppufile:tcompilerppufile);
  1319. begin
  1320. { write the symtable entries }
  1321. inherited write(ppufile);
  1322. { write dbx count }
  1323. {$ifdef GDB}
  1324. if cs_gdb_dbx in aktglobalswitches then
  1325. begin
  1326. {$IfDef EXTDEBUG}
  1327. writeln('Writing dbx_count ',dbx_count,' in unit ',name^,'.ppu');
  1328. {$ENDIF EXTDEBUG}
  1329. ppufile.do_crc:=false;
  1330. ppufile.putlongint(dbx_count);
  1331. ppufile.writeentry(ibdbxcount);
  1332. ppufile.do_crc:=true;
  1333. end;
  1334. {$endif GDB}
  1335. end;
  1336. procedure tglobalsymtable.insert(sym:tsymentry);
  1337. var
  1338. hsym : tsym;
  1339. begin
  1340. { also check the global symtable }
  1341. if assigned(next) and
  1342. (next.unitid=0) then
  1343. begin
  1344. hsym:=tsym(next.search(sym.name));
  1345. if assigned(hsym) then
  1346. begin
  1347. DuplicateSym(hsym);
  1348. exit;
  1349. end;
  1350. end;
  1351. hsym:=tsym(search(sym.name));
  1352. if assigned(hsym) then
  1353. begin
  1354. { Delphi you can have a symbol with the same name as the
  1355. unit, the unit can then not be accessed anymore using
  1356. <unit>.<id>, so we can hide the symbol }
  1357. if (m_duplicate_names in aktmodeswitches) and
  1358. (hsym.typ=symconst.unitsym) then
  1359. hsym.owner.rename(hsym.name,'hidden'+hsym.name)
  1360. else
  1361. begin
  1362. DuplicateSym(hsym);
  1363. exit;
  1364. end;
  1365. end;
  1366. inherited insert(sym);
  1367. end;
  1368. {$ifdef GDB}
  1369. function tglobalsymtable.getnewtypecount : word;
  1370. begin
  1371. if not (cs_gdb_dbx in aktglobalswitches) then
  1372. getnewtypecount:=inherited getnewtypecount
  1373. else
  1374. begin
  1375. getnewtypecount:=unittypecount;
  1376. inc(unittypecount);
  1377. end;
  1378. end;
  1379. {$endif}
  1380. {****************************************************************************
  1381. TWITHSYMTABLE
  1382. ****************************************************************************}
  1383. constructor twithsymtable.create(aowner:tdef;asymsearch:TDictionary);
  1384. begin
  1385. inherited create('');
  1386. symtabletype:=withsymtable;
  1387. direct_with:=false;
  1388. withnode:=nil;
  1389. withrefnode:=nil;
  1390. { we don't need the symsearch }
  1391. symsearch.free;
  1392. { set the defaults }
  1393. symsearch:=asymsearch;
  1394. defowner:=aowner;
  1395. end;
  1396. destructor twithsymtable.destroy;
  1397. begin
  1398. symsearch:=nil;
  1399. inherited destroy;
  1400. end;
  1401. procedure twithsymtable.clear;
  1402. begin
  1403. { remove no entry from a withsymtable as it is only a pointer to the
  1404. recorddef or objectdef symtable }
  1405. end;
  1406. {****************************************************************************
  1407. TSTT_ExceptionSymtable
  1408. ****************************************************************************}
  1409. constructor tstt_exceptsymtable.create;
  1410. begin
  1411. inherited create('');
  1412. symtabletype:=stt_exceptsymtable;
  1413. end;
  1414. {*****************************************************************************
  1415. Helper Routines
  1416. *****************************************************************************}
  1417. function findunitsymtable(st:tsymtable):tsymtable;
  1418. begin
  1419. findunitsymtable:=nil;
  1420. repeat
  1421. if not assigned(st) then
  1422. internalerror(5566561);
  1423. case st.symtabletype of
  1424. localsymtable,
  1425. parasymtable,
  1426. staticsymtable :
  1427. break;
  1428. globalsymtable :
  1429. begin
  1430. findunitsymtable:=st;
  1431. break;
  1432. end;
  1433. objectsymtable,
  1434. recordsymtable :
  1435. st:=st.defowner.owner;
  1436. else
  1437. internalerror(5566562);
  1438. end;
  1439. until false;
  1440. end;
  1441. procedure duplicatesym(sym:tsym);
  1442. var
  1443. st : tsymtable;
  1444. begin
  1445. Message1(sym_e_duplicate_id,sym.realname);
  1446. st:=findunitsymtable(sym.owner);
  1447. with sym.fileinfo do
  1448. begin
  1449. if assigned(st) and (st.unitid<>0) then
  1450. Message2(sym_h_duplicate_id_where,'unit '+st.name^,tostr(line))
  1451. else
  1452. Message2(sym_h_duplicate_id_where,current_module.sourcefiles.get_file_name(fileindex),tostr(line));
  1453. end;
  1454. end;
  1455. {*****************************************************************************
  1456. Search
  1457. *****************************************************************************}
  1458. function searchsym(const s : stringid;var srsym:tsym;var srsymtable:tsymtable):boolean;
  1459. var
  1460. speedvalue : cardinal;
  1461. begin
  1462. speedvalue:=getspeedvalue(s);
  1463. srsymtable:=symtablestack;
  1464. while assigned(srsymtable) do
  1465. begin
  1466. srsym:=tsym(srsymtable.speedsearch(s,speedvalue));
  1467. if assigned(srsym) and
  1468. tstoredsym(srsym).is_visible_for_proc(aktprocdef) then
  1469. begin
  1470. searchsym:=true;
  1471. exit;
  1472. end
  1473. else
  1474. srsymtable:=srsymtable.next;
  1475. end;
  1476. searchsym:=false;
  1477. end;
  1478. function searchsymonlyin(p : tsymtable;const s : stringid):tsym;
  1479. var
  1480. srsym : tsym;
  1481. begin
  1482. { the caller have to take care if srsym=nil }
  1483. if assigned(p) then
  1484. begin
  1485. srsym:=tsym(p.search(s));
  1486. if assigned(srsym) then
  1487. begin
  1488. searchsymonlyin:=srsym;
  1489. exit;
  1490. end;
  1491. { also check in the local symtbale if it exists }
  1492. if (p=tsymtable(current_module.globalsymtable)) then
  1493. begin
  1494. srsym:=tsym(current_module.localsymtable.search(s));
  1495. if assigned(srsym) then
  1496. begin
  1497. searchsymonlyin:=srsym;
  1498. exit;
  1499. end;
  1500. end
  1501. end;
  1502. searchsymonlyin:=nil;
  1503. end;
  1504. function searchsym_in_class(classh:tobjectdef;const s : stringid):tsym;
  1505. var
  1506. speedvalue : cardinal;
  1507. topclassh : tobjectdef;
  1508. sym : tsym;
  1509. begin
  1510. speedvalue:=getspeedvalue(s);
  1511. { when the class passed is defined in this unit we
  1512. need to use the scope of that class. This is a trick
  1513. that can be used to access protected members in other
  1514. units. At least kylix supports it this way (PFV) }
  1515. if (classh.owner.symtabletype in [globalsymtable,staticsymtable]) and
  1516. (classh.owner.unitid=0) then
  1517. topclassh:=classh
  1518. else
  1519. topclassh:=nil;
  1520. sym:=nil;
  1521. while assigned(classh) do
  1522. begin
  1523. sym:=tsym(classh.symtable.speedsearch(s,speedvalue));
  1524. if assigned(sym) then
  1525. begin
  1526. if assigned(topclassh) then
  1527. begin
  1528. if tstoredsym(sym).is_visible_for_object(topclassh) then
  1529. break;
  1530. end
  1531. else
  1532. begin
  1533. if tstoredsym(sym).is_visible_for_proc(aktprocdef) then
  1534. break;
  1535. end;
  1536. end;
  1537. classh:=classh.childof;
  1538. end;
  1539. searchsym_in_class:=sym;
  1540. end;
  1541. function searchsystype(const s: stringid; var srsym: ttypesym): boolean;
  1542. var
  1543. symowner: tsymtable;
  1544. begin
  1545. if not(cs_compilesystem in aktmoduleswitches) then
  1546. srsym := ttypesym(searchsymonlyin(systemunit,s))
  1547. else
  1548. searchsym(s,srsym,symowner);
  1549. searchsystype :=
  1550. assigned(srsym) and
  1551. (srsym.typ = typesym);
  1552. end;
  1553. function searchsysvar(const s: stringid; var srsym: tvarsym; var symowner: tsymtable): boolean;
  1554. begin
  1555. if not(cs_compilesystem in aktmoduleswitches) then
  1556. begin
  1557. srsym := tvarsym(searchsymonlyin(systemunit,s));
  1558. symowner := systemunit;
  1559. end
  1560. else
  1561. searchsym(s,srsym,symowner);
  1562. searchsysvar :=
  1563. assigned(srsym) and
  1564. (srsym.typ = varsym);
  1565. end;
  1566. function search_class_member(pd : tobjectdef;const s : string):tsym;
  1567. { searches n in symtable of pd and all anchestors }
  1568. var
  1569. speedvalue : cardinal;
  1570. srsym : tsym;
  1571. begin
  1572. speedvalue:=getspeedvalue(s);
  1573. while assigned(pd) do
  1574. begin
  1575. srsym:=tsym(pd.symtable.speedsearch(s,speedvalue));
  1576. if assigned(srsym) then
  1577. begin
  1578. search_class_member:=srsym;
  1579. exit;
  1580. end;
  1581. pd:=pd.childof;
  1582. end;
  1583. search_class_member:=nil;
  1584. end;
  1585. {*****************************************************************************
  1586. Definition Helpers
  1587. *****************************************************************************}
  1588. procedure globaldef(const s : string;var t:ttype);
  1589. var st : string;
  1590. symt : tsymtable;
  1591. srsym : tsym;
  1592. srsymtable : tsymtable;
  1593. begin
  1594. srsym := nil;
  1595. if pos('.',s) > 0 then
  1596. begin
  1597. st := copy(s,1,pos('.',s)-1);
  1598. searchsym(st,srsym,srsymtable);
  1599. st := copy(s,pos('.',s)+1,255);
  1600. if assigned(srsym) then
  1601. begin
  1602. if srsym.typ = unitsym then
  1603. begin
  1604. symt := tunitsym(srsym).unitsymtable;
  1605. srsym := tsym(symt.search(st));
  1606. end else srsym := nil;
  1607. end;
  1608. end else st := s;
  1609. if srsym = nil then
  1610. searchsym(st,srsym,srsymtable);
  1611. if srsym = nil then
  1612. srsym:=searchsymonlyin(systemunit,st);
  1613. if (not assigned(srsym)) or
  1614. (srsym.typ<>typesym) then
  1615. begin
  1616. Message(type_e_type_id_expected);
  1617. t:=generrortype;
  1618. exit;
  1619. end;
  1620. t := ttypesym(srsym).restype;
  1621. end;
  1622. {****************************************************************************
  1623. Object Helpers
  1624. ****************************************************************************}
  1625. var
  1626. _defaultprop : tpropertysym;
  1627. procedure tstoredsymtable.testfordefaultproperty(p : TNamedIndexItem;arg:pointer);
  1628. begin
  1629. if (tsym(p).typ=propertysym) and
  1630. (ppo_defaultproperty in tpropertysym(p).propoptions) then
  1631. _defaultprop:=tpropertysym(p);
  1632. end;
  1633. function search_default_property(pd : tobjectdef) : tpropertysym;
  1634. { returns the default property of a class, searches also anchestors }
  1635. begin
  1636. _defaultprop:=nil;
  1637. while assigned(pd) do
  1638. begin
  1639. pd.symtable.foreach({$ifdef FPCPROCVAR}@{$endif}tstoredsymtable(pd.symtable).testfordefaultproperty,nil);
  1640. if assigned(_defaultprop) then
  1641. break;
  1642. pd:=pd.childof;
  1643. end;
  1644. search_default_property:=_defaultprop;
  1645. end;
  1646. {$ifdef UNITALIASES}
  1647. {****************************************************************************
  1648. TUNIT_ALIAS
  1649. ****************************************************************************}
  1650. constructor tunit_alias.create(const n:string);
  1651. var
  1652. i : longint;
  1653. begin
  1654. i:=pos('=',n);
  1655. if i=0 then
  1656. fail;
  1657. inherited createname(Copy(n,1,i-1));
  1658. newname:=stringdup(Copy(n,i+1,255));
  1659. end;
  1660. destructor tunit_alias.destroy;
  1661. begin
  1662. stringdispose(newname);
  1663. inherited destroy;
  1664. end;
  1665. procedure addunitalias(const n:string);
  1666. begin
  1667. unitaliases^.insert(tunit_alias,init(Upper(n))));
  1668. end;
  1669. function getunitalias(const n:string):string;
  1670. var
  1671. p : punit_alias;
  1672. begin
  1673. p:=punit_alias(unitaliases^.search(Upper(n)));
  1674. if assigned(p) then
  1675. getunitalias:=punit_alias(p).newname^
  1676. else
  1677. getunitalias:=n;
  1678. end;
  1679. {$endif UNITALIASES}
  1680. {****************************************************************************
  1681. Symtable Stack
  1682. ****************************************************************************}
  1683. procedure dellexlevel;
  1684. var
  1685. p : tsymtable;
  1686. begin
  1687. p:=symtablestack;
  1688. symtablestack:=p.next;
  1689. { symbol tables of unit interfaces are never disposed }
  1690. { this is handle by the unit unitm }
  1691. if not(p.symtabletype in [globalsymtable,stt_exceptsymtable]) then
  1692. p.free;
  1693. end;
  1694. procedure RestoreUnitSyms;
  1695. var
  1696. p : tsymtable;
  1697. begin
  1698. p:=symtablestack;
  1699. while assigned(p) do
  1700. begin
  1701. if (p.symtabletype=globalsymtable) and
  1702. assigned(tglobalsymtable(p).unitsym) and
  1703. ((tglobalsymtable(p).unitsym.owner=current_module.globalsymtable) or
  1704. (tglobalsymtable(p).unitsym.owner=current_module.localsymtable)) then
  1705. tglobalsymtable(p).unitsym.restoreunitsym;
  1706. p:=p.next;
  1707. end;
  1708. end;
  1709. {$ifdef DEBUG}
  1710. procedure test_symtablestack;
  1711. var
  1712. p : tsymtable;
  1713. i : longint;
  1714. begin
  1715. p:=symtablestack;
  1716. i:=0;
  1717. while assigned(p) do
  1718. begin
  1719. inc(i);
  1720. p:=p.next;
  1721. if i>500 then
  1722. Message(sym_f_internal_error_in_symtablestack);
  1723. end;
  1724. end;
  1725. procedure list_symtablestack;
  1726. var
  1727. p : tsymtable;
  1728. i : longint;
  1729. begin
  1730. p:=symtablestack;
  1731. i:=0;
  1732. while assigned(p) do
  1733. begin
  1734. inc(i);
  1735. writeln(i,' ',p.name^);
  1736. p:=p.next;
  1737. if i>500 then
  1738. Message(sym_f_internal_error_in_symtablestack);
  1739. end;
  1740. end;
  1741. {$endif DEBUG}
  1742. {****************************************************************************
  1743. Init/Done Symtable
  1744. ****************************************************************************}
  1745. procedure InitSymtable;
  1746. var
  1747. token : ttoken;
  1748. begin
  1749. { Reset symbolstack }
  1750. registerdef:=false;
  1751. read_member:=false;
  1752. symtablestack:=nil;
  1753. systemunit:=nil;
  1754. {$ifdef GDB}
  1755. firstglobaldef:=nil;
  1756. lastglobaldef:=nil;
  1757. globaltypecount:=1;
  1758. pglobaltypecount:=@globaltypecount;
  1759. {$endif GDB}
  1760. { create error syms and def }
  1761. generrorsym:=terrorsym.create;
  1762. generrortype.setdef(terrordef.create);
  1763. {$ifdef UNITALIASES}
  1764. { unit aliases }
  1765. unitaliases:=tdictionary.create;
  1766. {$endif}
  1767. for token:=first_overloaded to last_overloaded do
  1768. overloaded_operators[token]:=nil;
  1769. end;
  1770. procedure DoneSymtable;
  1771. begin
  1772. generrorsym.free;
  1773. generrortype.def.free;
  1774. {$ifdef UNITALIASES}
  1775. unitaliases.free;
  1776. {$endif}
  1777. end;
  1778. end.
  1779. {
  1780. $Log$
  1781. Revision 1.65 2002-07-23 09:51:27 daniel
  1782. * Tried to make Tprocsym.defs protected. I didn't succeed but the cleanups
  1783. are worth comitting.
  1784. Revision 1.64 2002/07/16 15:34:21 florian
  1785. * exit is now a syssym instead of a keyword
  1786. Revision 1.63 2002/07/15 19:44:53 florian
  1787. * fixed crash with default parameters and stdcall calling convention
  1788. Revision 1.62 2002/07/01 18:46:28 peter
  1789. * internal linker
  1790. * reorganized aasm layer
  1791. Revision 1.61 2002/05/18 13:34:19 peter
  1792. * readded missing revisions
  1793. Revision 1.60 2002/05/16 19:46:45 carl
  1794. + defines.inc -> fpcdefs.inc to avoid conflicts if compiling by hand
  1795. + try to fix temp allocation (still in ifdef)
  1796. + generic constructor calls
  1797. + start of tassembler / tmodulebase class cleanup
  1798. Revision 1.58 2002/05/12 16:53:15 peter
  1799. * moved entry and exitcode to ncgutil and cgobj
  1800. * foreach gets extra argument for passing local data to the
  1801. iterator function
  1802. * -CR checks also class typecasts at runtime by changing them
  1803. into as
  1804. * fixed compiler to cycle with the -CR option
  1805. * fixed stabs with elf writer, finally the global variables can
  1806. be watched
  1807. * removed a lot of routines from cga unit and replaced them by
  1808. calls to cgobj
  1809. * u32bit-s32bit updates for and,or,xor nodes. When one element is
  1810. u32bit then the other is typecasted also to u32bit without giving
  1811. a rangecheck warning/error.
  1812. * fixed pascal calling method with reversing also the high tree in
  1813. the parast, detected by tcalcst3 test
  1814. Revision 1.57 2002/04/04 19:06:05 peter
  1815. * removed unused units
  1816. * use tlocation.size in cg.a_*loc*() routines
  1817. Revision 1.56 2002/03/04 19:10:11 peter
  1818. * removed compiler warnings
  1819. Revision 1.55 2002/02/03 09:30:07 peter
  1820. * more fixes for protected handling
  1821. Revision 1.54 2002/01/29 21:30:25 peter
  1822. * allow also dup id in delphi mode in interfaces
  1823. Revision 1.53 2002/01/29 19:46:00 peter
  1824. * fixed recordsymtable.insert_in() for inserting variant record fields
  1825. to not used symtable.insert() because that also updates alignmentinfo
  1826. which was already set
  1827. Revision 1.52 2002/01/24 18:25:50 peter
  1828. * implicit result variable generation for assembler routines
  1829. * removed m_tp modeswitch, use m_tp7 or not(m_fpc) instead
  1830. }