symtable.pas 72 KB

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