symtable.pas 87 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870
  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. {$ifdef TP}
  19. {$N+,E+,F+,L-}
  20. {$endif}
  21. unit symtable;
  22. interface
  23. uses
  24. {$ifdef TP}
  25. {$ifndef Delphi}
  26. objects,
  27. {$endif Delphi}
  28. {$endif}
  29. strings,cobjects,
  30. globtype,globals,tokens,systems,
  31. symconst,
  32. aasm
  33. ,cpubase
  34. ,cpuinfo
  35. {$ifdef GDB}
  36. ,gdb
  37. {$endif}
  38. ;
  39. {************************************************
  40. Some internal constants
  41. ************************************************}
  42. const
  43. hasharraysize = 256;
  44. {$ifdef TP}
  45. indexgrowsize = 16;
  46. {$else}
  47. indexgrowsize = 64;
  48. {$endif}
  49. {************************************************
  50. Needed forward pointers
  51. ************************************************}
  52. type
  53. { needed for owner (table) of symbol }
  54. psymtable = ^tsymtable;
  55. punitsymtable = ^tunitsymtable;
  56. { needed for names by the definitions }
  57. psym = ^tsym;
  58. pdef = ^tdef;
  59. ptypesym = ^ttypesym;
  60. penumsym = ^tenumsym;
  61. pprocsym = ^tprocsym;
  62. pref = ^tref;
  63. tref = object
  64. nextref : pref;
  65. posinfo : tfileposinfo;
  66. moduleindex : word;
  67. is_written : boolean;
  68. constructor init(ref:pref;pos:pfileposinfo);
  69. procedure freechain;
  70. destructor done; virtual;
  71. end;
  72. { Deref entry options }
  73. tdereftype = (derefnil,derefaktrecordindex,derefaktstaticindex,
  74. derefunit,derefrecord,derefindex,
  75. dereflocal,derefpara,derefaktlocal);
  76. pderef = ^tderef;
  77. tderef = object
  78. dereftype : tdereftype;
  79. index : word;
  80. next : pderef;
  81. constructor init(typ:tdereftype;i:word);
  82. destructor done;
  83. end;
  84. ttype = object
  85. def : pdef;
  86. sym : psym;
  87. procedure reset;
  88. procedure setdef(p:pdef);
  89. procedure setsym(p:psym);
  90. procedure load;
  91. procedure write;
  92. procedure resolve;
  93. end;
  94. psymlistitem = ^tsymlistitem;
  95. tsymlistitem = record
  96. sym : psym;
  97. next : psymlistitem;
  98. end;
  99. psymlist = ^tsymlist;
  100. tsymlist = object
  101. def : pdef;
  102. firstsym,
  103. lastsym : psymlistitem;
  104. constructor init;
  105. constructor load;
  106. destructor done;
  107. function empty:boolean;
  108. procedure setdef(p:pdef);
  109. procedure addsym(p:psym);
  110. procedure clear;
  111. function getcopy:psymlist;
  112. procedure resolve;
  113. procedure write;
  114. end;
  115. psymtableentry = ^tsymtableentry;
  116. tsymtableentry = object(tnamedindexobject)
  117. owner : psymtable;
  118. end;
  119. {************************************************
  120. TDef
  121. ************************************************}
  122. {$i symdefh.inc}
  123. {************************************************
  124. TSym
  125. ************************************************}
  126. {$i symsymh.inc}
  127. {************************************************
  128. TSymtable
  129. ************************************************}
  130. tsymtabletype = (invalidsymtable,withsymtable,staticsymtable,
  131. globalsymtable,unitsymtable,
  132. objectsymtable,recordsymtable,
  133. macrosymtable,localsymtable,
  134. parasymtable,inlineparasymtable,
  135. inlinelocalsymtable,stt_exceptsymtable,
  136. { only used for PPU reading of static part
  137. of a unit }
  138. staticppusymtable);
  139. tcallback = procedure(p : psym);
  140. tsearchhasharray = array[0..hasharraysize-1] of psym;
  141. psearchhasharray = ^tsearchhasharray;
  142. tsymtable = object
  143. symtabletype : tsymtabletype;
  144. { each symtable gets a number }
  145. unitid : word{integer give range check errors PM};
  146. name : pstring;
  147. datasize : longint;
  148. dataalignment : longint;
  149. symindex,
  150. defindex : pindexarray;
  151. symsearch : pdictionary;
  152. next : psymtable;
  153. defowner : pdef; { for records and objects }
  154. { alignment used in this symtable }
  155. alignment : longint;
  156. { only used for parameter symtable to determine the offset relative }
  157. { to the frame pointer and for local inline }
  158. address_fixup : longint;
  159. { this saves all definition to allow a proper clean up }
  160. { separate lexlevel from symtable type }
  161. symtablelevel : byte;
  162. constructor init(t : tsymtabletype);
  163. destructor done;virtual;
  164. { access }
  165. function getdefnr(l : longint) : pdef;
  166. function getsymnr(l : longint) : psym;
  167. { load/write }
  168. constructor loadas(typ : tsymtabletype);
  169. procedure writeas;
  170. procedure loaddefs;
  171. procedure loadsyms;
  172. procedure writedefs;
  173. procedure writesyms;
  174. procedure deref;
  175. procedure clear;
  176. function rename(const olds,news : stringid):psym;
  177. procedure foreach(proc2call : tnamedindexcallback);
  178. function insert(sym : psym):psym;
  179. function search(const s : stringid) : psym;
  180. function speedsearch(const s : stringid;speedvalue : longint) : psym;
  181. procedure registerdef(p : pdef);
  182. procedure allsymbolsused;
  183. procedure allprivatesused;
  184. procedure allunitsused;
  185. procedure check_forwards;
  186. procedure checklabels;
  187. { change alignment for args only parasymtable }
  188. procedure set_alignment(_alignment : byte);
  189. { find arg having offset only parasymtable }
  190. function find_at_offset(l : longint) : pvarsym;
  191. {$ifdef CHAINPROCSYMS}
  192. procedure chainprocsyms;
  193. {$endif CHAINPROCSYMS}
  194. procedure load_browser;
  195. procedure write_browser;
  196. {$ifdef BrowserLog}
  197. procedure writebrowserlog;
  198. {$endif BrowserLog}
  199. {$ifdef GDB}
  200. procedure concatstabto(asmlist : paasmoutput);virtual;
  201. {$endif GDB}
  202. function getnewtypecount : word; virtual;
  203. end;
  204. tunitsymtable = object(tsymtable)
  205. unittypecount : word;
  206. unitsym : punitsym;
  207. {$ifdef GDB}
  208. dbx_count : longint;
  209. prev_dbx_counter : plongint;
  210. dbx_count_ok : boolean;
  211. is_stab_written : boolean;
  212. {$endif GDB}
  213. constructor init(t : tsymtabletype;const n : string);
  214. constructor loadasunit;
  215. destructor done;virtual;
  216. procedure writeasunit;
  217. {$ifdef GDB}
  218. procedure concattypestabto(asmlist : paasmoutput);
  219. {$endif GDB}
  220. procedure load_symtable_refs;
  221. function getnewtypecount : word; virtual;
  222. end;
  223. pwithsymtable = ^twithsymtable;
  224. twithsymtable = object(tsymtable)
  225. { used for withsymtable for allowing constructors }
  226. direct_with : boolean;
  227. { in fact it is a ptree }
  228. withnode : pointer;
  229. { ptree to load of direct with var }
  230. { already usable before firstwith
  231. needed for firstpass of function parameters PM }
  232. withrefnode : pointer;
  233. constructor init;
  234. destructor done;virtual;
  235. end;
  236. {****************************************************************************
  237. Var / Consts
  238. ****************************************************************************}
  239. const
  240. systemunit : punitsymtable = nil; { pointer to the system unit }
  241. current_object_option : tsymoptions = [sp_public];
  242. var
  243. { for STAB debugging }
  244. globaltypecount : word;
  245. pglobaltypecount : pword;
  246. registerdef : boolean; { true, when defs should be registered }
  247. defaultsymtablestack, { symtablestack after default units
  248. have been loaded }
  249. symtablestack : psymtable; { linked list of symtables }
  250. srsym : psym; { result of the last search }
  251. srsymtable : psymtable;
  252. lastsrsym : psym; { last sym found in statement }
  253. lastsrsymtable : psymtable;
  254. lastsymknown : boolean;
  255. constsymtable : psymtable; { symtable were the constants can be
  256. inserted }
  257. voidpointerdef : ppointerdef; { pointer for Void-Pointerdef }
  258. charpointerdef : ppointerdef; { pointer for Char-Pointerdef }
  259. voidfarpointerdef : ppointerdef;
  260. cformaldef : pformaldef; { unique formal definition }
  261. voiddef : porddef; { Pointer to Void (procedure) }
  262. cchardef : porddef; { Pointer to Char }
  263. cwidechardef : porddef; { Pointer to WideChar }
  264. booldef : porddef; { pointer to boolean type }
  265. u8bitdef : porddef; { Pointer to 8-Bit unsigned }
  266. u16bitdef : porddef; { Pointer to 16-Bit unsigned }
  267. u32bitdef : porddef; { Pointer to 32-Bit unsigned }
  268. s32bitdef : porddef; { Pointer to 32-Bit signed }
  269. cu64bitdef : porddef; { pointer to 64 bit unsigned def }
  270. cs64bitdef : porddef; { pointer to 64 bit signed def, }
  271. { calculated by the int unit on i386 }
  272. s32floatdef : pfloatdef; { pointer for realconstn }
  273. s64floatdef : pfloatdef; { pointer for realconstn }
  274. s80floatdef : pfloatdef; { pointer to type of temp. floats }
  275. s32fixeddef : pfloatdef; { pointer to type of temp. fixed }
  276. cshortstringdef : pstringdef; { pointer to type of short string const }
  277. clongstringdef : pstringdef; { pointer to type of long string const }
  278. cansistringdef : pstringdef; { pointer to type of ansi string const }
  279. cwidestringdef : pstringdef; { pointer to type of wide string const }
  280. openshortstringdef : pstringdef; { pointer to type of an open shortstring,
  281. needed for readln() }
  282. openchararraydef : parraydef; { pointer to type of an open array of char,
  283. needed for readln() }
  284. cfiledef : pfiledef; { get the same definition for all file }
  285. { uses for stabs }
  286. firstglobaldef, { linked list of all globals defs }
  287. lastglobaldef : pdef; { used to reset stabs/ranges }
  288. class_tobject : pobjectdef; { pointer to the anchestor of all }
  289. { clases }
  290. pvmtdef : ppointerdef; { type of classrefs }
  291. aktprocsym : pprocsym; { pointer to the symbol for the
  292. currently be parsed procedure }
  293. aktcallprocsym : pprocsym; { pointer to the symbol for the
  294. currently be called procedure,
  295. only set/unset in firstcall }
  296. aktvarsym : pvarsym; { pointer to the symbol for the
  297. currently read var, only used
  298. for variable directives }
  299. procprefix : string; { eindeutige Namen bei geschachtel- }
  300. { ten Unterprogrammen erzeugen }
  301. lexlevel : longint; { level of code }
  302. { 1 for main procedure }
  303. { 2 for normal function or proc }
  304. { higher for locals }
  305. const
  306. main_program_level = 1;
  307. unit_init_level = 1;
  308. normal_function_level = 2;
  309. in_loading : boolean = false;
  310. {$ifdef i386}
  311. bestrealdef : ^pfloatdef = @s80floatdef;
  312. {$endif}
  313. {$ifdef m68k}
  314. bestrealdef : ^pfloatdef = @s64floatdef;
  315. {$endif}
  316. {$ifdef alpha}
  317. bestrealdef : ^pfloatdef = @s64floatdef;
  318. {$endif}
  319. {$ifdef powerpc}
  320. bestrealdef : ^pfloatdef = @s64floatdef;
  321. {$endif}
  322. var
  323. macros : psymtable; { pointer for die Symboltabelle mit }
  324. { Makros }
  325. read_member : boolean; { true, wenn Members aus einer PPU- }
  326. { Datei gelesen werden, d.h. ein }
  327. { varsym seine Adresse einlesen soll }
  328. generrorsym : psym; { Jokersymbol, wenn das richtige }
  329. { Symbol nicht gefunden wird }
  330. generrordef : pdef; { Jokersymbol for eine fehlerhafte }
  331. { Typdefinition }
  332. aktobjectdef : pobjectdef; { used for private functions check !! }
  333. const
  334. { last operator which can be overloaded }
  335. first_overloaded = _PLUS;
  336. last_overloaded = _ASSIGNMENT;
  337. var
  338. overloaded_operators : array[first_overloaded..last_overloaded] of pprocsym;
  339. { unequal is not equal}
  340. const
  341. overloaded_names : array [first_overloaded..last_overloaded] of string[16] =
  342. ('plus','minus','star','slash','equal',
  343. 'greater','lower','greater_or_equal',
  344. 'lower_or_equal',
  345. 'sym_diff','starstar',
  346. 'as','is','in','or',
  347. 'and','div','mod','shl','shr','xor',
  348. 'assign');
  349. {$ifdef UNITALIASES}
  350. type
  351. punit_alias = ^tunit_alias;
  352. tunit_alias = object(tnamedindexobject)
  353. newname : pstring;
  354. constructor init(const n:string);
  355. destructor done;virtual;
  356. end;
  357. var
  358. unitaliases : pdictionary;
  359. procedure addunitalias(const n:string);
  360. function getunitalias(const n:string):string;
  361. {$endif UNITALIASES}
  362. {****************************************************************************
  363. Functions
  364. ****************************************************************************}
  365. {*** Misc ***}
  366. function globaldef(const s : string) : pdef;
  367. function findunitsymtable(st:psymtable):psymtable;
  368. procedure duplicatesym(sym:psym);
  369. {*** Search ***}
  370. function search_a_symtable(const symbol:string;symtabletype:tsymtabletype):Psym;
  371. procedure getsym(const s : stringid;notfounderror : boolean);
  372. procedure getsymonlyin(p : psymtable;const s : stringid);
  373. {*** PPU Write/Loading ***}
  374. procedure writeunitas(const s : string;unittable : punitsymtable;only_crc : boolean);
  375. procedure closecurrentppu;
  376. procedure numberunits;
  377. procedure load_interface;
  378. {*** GDB ***}
  379. {$ifdef GDB}
  380. function typeglobalnumber(const s : string) : string;
  381. {$endif}
  382. {*** Definition ***}
  383. procedure reset_global_defs;
  384. {*** Object Helpers ***}
  385. function search_class_member(pd : pobjectdef;const n : string) : psym;
  386. function search_default_property(pd : pobjectdef) : ppropertysym;
  387. {*** Macro ***}
  388. procedure def_macro(const s : string);
  389. procedure set_macro(const s : string;value : string);
  390. {*** symtable stack ***}
  391. procedure dellexlevel;
  392. {$ifdef DEBUG}
  393. procedure test_symtablestack;
  394. procedure list_symtablestack;
  395. {$endif DEBUG}
  396. {*** Init / Done ***}
  397. procedure InitSymtable;
  398. procedure DoneSymtable;
  399. implementation
  400. uses
  401. version,verbose,
  402. types,ppu,
  403. gendef,files
  404. ,tree
  405. ,cresstr
  406. {$ifdef newcg}
  407. ,cgbase
  408. {$else}
  409. ,hcodegen
  410. {$endif}
  411. {$ifdef BrowserLog}
  412. ,browlog
  413. {$endif BrowserLog}
  414. ,cpuasm
  415. ;
  416. var
  417. aktrecordsymtable : psymtable; { current record read from ppu symtable }
  418. aktstaticsymtable : psymtable; { current static for local ppu symtable }
  419. aktlocalsymtable : psymtable; { current proc local for local ppu symtable }
  420. {$ifdef GDB}
  421. asmoutput : paasmoutput;
  422. {$endif GDB}
  423. {$ifdef TP}
  424. {$ifndef Delphi}
  425. {$ifndef dpmi}
  426. symbolstream : temsstream; { stream which is used to store some info }
  427. {$else}
  428. symbolstream : tmemorystream;
  429. {$endif}
  430. {$endif Delphi}
  431. {$endif}
  432. {to dispose the global symtable of a unit }
  433. const
  434. dispose_global : boolean = false;
  435. memsizeinc = 2048; { for long stabstrings }
  436. tagtypes : Set of tdeftype =
  437. [recorddef,enumdef,
  438. {$IfNDef GDBKnowsStrings}
  439. stringdef,
  440. {$EndIf not GDBKnowsStrings}
  441. {$IfNDef GDBKnowsFiles}
  442. filedef,
  443. {$EndIf not GDBKnowsFiles}
  444. objectdef];
  445. {*****************************************************************************
  446. Helper Routines
  447. *****************************************************************************}
  448. {$ifdef unused}
  449. function demangledparas(s : string) : string;
  450. var
  451. r : string;
  452. l : longint;
  453. begin
  454. demangledparas:='';
  455. r:=',';
  456. { delete leading $$'s }
  457. l:=pos('$$',s);
  458. while l<>0 do
  459. begin
  460. delete(s,1,l+1);
  461. l:=pos('$$',s);
  462. end;
  463. { delete leading _$'s }
  464. l:=pos('_$',s);
  465. while l<>0 do
  466. begin
  467. delete(s,1,l+1);
  468. l:=pos('_$',s);
  469. end;
  470. l:=pos('$',s);
  471. if l=0 then
  472. exit;
  473. delete(s,1,l);
  474. while s<>'' do
  475. begin
  476. l:=pos('$',s);
  477. if l=0 then
  478. l:=length(s)+1;
  479. r:=r+copy(s,1,l-1)+',';
  480. delete(s,1,l);
  481. end;
  482. delete(r,1,1);
  483. delete(r,length(r),1);
  484. demangledparas:=r;
  485. end;
  486. {$endif}
  487. procedure numberunits;
  488. var
  489. counter : longint;
  490. hp : pused_unit;
  491. hp1 : pmodule;
  492. begin
  493. { Reset all numbers to -1 }
  494. hp1:=pmodule(loaded_units.first);
  495. while assigned(hp1) do
  496. begin
  497. if assigned(hp1^.globalsymtable) then
  498. psymtable(hp1^.globalsymtable)^.unitid:=$ffff;
  499. hp1:=pmodule(hp1^.next);
  500. end;
  501. { Our own symtable gets unitid 0, for a program there is
  502. no globalsymtable }
  503. if assigned(current_module^.globalsymtable) then
  504. psymtable(current_module^.globalsymtable)^.unitid:=0;
  505. { number units }
  506. counter:=1;
  507. hp:=pused_unit(current_module^.used_units.first);
  508. while assigned(hp) do
  509. begin
  510. psymtable(hp^.u^.globalsymtable)^.unitid:=counter;
  511. inc(counter);
  512. hp:=pused_unit(hp^.next);
  513. end;
  514. end;
  515. function findunitsymtable(st:psymtable):psymtable;
  516. begin
  517. findunitsymtable:=nil;
  518. repeat
  519. if not assigned(st) then
  520. internalerror(5566561);
  521. case st^.symtabletype of
  522. localsymtable,
  523. parasymtable,
  524. staticsymtable :
  525. break;
  526. globalsymtable,
  527. unitsymtable :
  528. begin
  529. findunitsymtable:=st;
  530. break;
  531. end;
  532. objectsymtable,
  533. recordsymtable :
  534. st:=st^.defowner^.owner;
  535. else
  536. internalerror(5566562);
  537. end;
  538. until false;
  539. end;
  540. procedure setstring(var p : pchar;const s : string);
  541. begin
  542. {$ifndef Delphi}
  543. {$ifdef TP}
  544. if use_big then
  545. begin
  546. p:=pchar(symbolstream.getsize);
  547. symbolstream.seek(longint(p));
  548. symbolstream.writestr(@s);
  549. end
  550. else
  551. {$endif TP}
  552. {$endif Delphi}
  553. p:=strpnew(s);
  554. end;
  555. procedure duplicatesym(sym:psym);
  556. var
  557. st : psymtable;
  558. begin
  559. Message1(sym_e_duplicate_id,sym^.name);
  560. st:=findunitsymtable(sym^.owner);
  561. with sym^.fileinfo do
  562. begin
  563. if assigned(st) and (st^.unitid<>0) then
  564. Message2(sym_h_duplicate_id_where,'unit '+st^.name^,tostr(line))
  565. else
  566. Message2(sym_h_duplicate_id_where,current_module^.sourcefiles^.get_file_name(fileindex),tostr(line));
  567. end;
  568. end;
  569. {*****************************************************************************
  570. PPU Reading Writing
  571. *****************************************************************************}
  572. {$I symppu.inc}
  573. {****************************************************************************
  574. TDeref
  575. ****************************************************************************}
  576. constructor tderef.init(typ:tdereftype;i:word);
  577. begin
  578. dereftype:=typ;
  579. index:=i;
  580. next:=nil;
  581. end;
  582. destructor tderef.done;
  583. begin
  584. end;
  585. {*****************************************************************************
  586. Symbol / Definition Resolving
  587. *****************************************************************************}
  588. procedure resolvederef(var p:pderef;var st:psymtable;var idx:word);
  589. var
  590. hp : pderef;
  591. pd : pdef;
  592. begin
  593. st:=nil;
  594. idx:=0;
  595. while assigned(p) do
  596. begin
  597. case p^.dereftype of
  598. derefaktrecordindex :
  599. begin
  600. st:=aktrecordsymtable;
  601. idx:=p^.index;
  602. end;
  603. derefaktstaticindex :
  604. begin
  605. st:=aktstaticsymtable;
  606. idx:=p^.index;
  607. end;
  608. derefaktlocal :
  609. begin
  610. st:=aktlocalsymtable;
  611. idx:=p^.index;
  612. end;
  613. derefunit :
  614. begin
  615. {$ifdef NEWMAP}
  616. st:=psymtable(current_module^.map^[p^.index]^.globalsymtable);
  617. {$else NEWMAP}
  618. st:=psymtable(current_module^.map^[p^.index]);
  619. {$endif NEWMAP}
  620. end;
  621. derefrecord :
  622. begin
  623. pd:=st^.getdefnr(p^.index);
  624. case pd^.deftype of
  625. recorddef :
  626. st:=precorddef(pd)^.symtable;
  627. objectdef :
  628. st:=pobjectdef(pd)^.symtable;
  629. else
  630. internalerror(556658);
  631. end;
  632. end;
  633. dereflocal :
  634. begin
  635. pd:=st^.getdefnr(p^.index);
  636. case pd^.deftype of
  637. procdef :
  638. st:=pprocdef(pd)^.localst;
  639. else
  640. internalerror(556658);
  641. end;
  642. end;
  643. derefpara :
  644. begin
  645. pd:=st^.getdefnr(p^.index);
  646. case pd^.deftype of
  647. procdef :
  648. st:=pprocdef(pd)^.parast;
  649. else
  650. internalerror(556658);
  651. end;
  652. end;
  653. derefindex :
  654. begin
  655. idx:=p^.index;
  656. end;
  657. else
  658. internalerror(556658);
  659. end;
  660. hp:=p;
  661. p:=p^.next;
  662. dispose(hp,done);
  663. end;
  664. end;
  665. procedure resolvedef(var def:pdef);
  666. var
  667. st : psymtable;
  668. idx : word;
  669. begin
  670. resolvederef(pderef(def),st,idx);
  671. if assigned(st) then
  672. def:=st^.getdefnr(idx)
  673. else
  674. def:=nil;
  675. end;
  676. procedure resolvesym(var sym:psym);
  677. var
  678. st : psymtable;
  679. idx : word;
  680. begin
  681. resolvederef(pderef(sym),st,idx);
  682. if assigned(st) then
  683. sym:=st^.getsymnr(idx)
  684. else
  685. sym:=nil;
  686. end;
  687. {****************************************************************************
  688. TRef
  689. ****************************************************************************}
  690. constructor tref.init(ref :pref;pos : pfileposinfo);
  691. begin
  692. nextref:=nil;
  693. if pos<>nil then
  694. posinfo:=pos^;
  695. if assigned(current_module) then
  696. moduleindex:=current_module^.unit_index;
  697. if assigned(ref) then
  698. ref^.nextref:=@self;
  699. is_written:=false;
  700. end;
  701. procedure tref.freechain;
  702. var
  703. p,q : pref;
  704. begin
  705. p:=nextref;
  706. nextref:=nil;
  707. while assigned(p) do
  708. begin
  709. q:=p^.nextref;
  710. dispose(p,done);
  711. p:=q;
  712. end;
  713. end;
  714. destructor tref.done;
  715. var
  716. inputfile : pinputfile;
  717. begin
  718. inputfile:=get_source_file(moduleindex,posinfo.fileindex);
  719. if inputfile<>nil then
  720. dec(inputfile^.ref_count);
  721. nextref:=nil;
  722. end;
  723. {****************************************************************************
  724. TType
  725. ****************************************************************************}
  726. procedure ttype.reset;
  727. begin
  728. def:=nil;
  729. sym:=nil;
  730. end;
  731. procedure ttype.setdef(p:pdef);
  732. begin
  733. def:=p;
  734. sym:=nil;
  735. end;
  736. procedure ttype.setsym(p:psym);
  737. begin
  738. sym:=p;
  739. case p^.typ of
  740. typesym :
  741. def:=ptypesym(p)^.restype.def;
  742. propertysym :
  743. def:=ppropertysym(p)^.proptype.def;
  744. else
  745. internalerror(1234005);
  746. end;
  747. end;
  748. procedure ttype.load;
  749. begin
  750. def:=pdef(readderef);
  751. sym:=psym(readderef);
  752. end;
  753. procedure ttype.write;
  754. begin
  755. if assigned(sym) then
  756. begin
  757. writederef(nil);
  758. writederef(sym);
  759. end
  760. else
  761. begin
  762. writederef(def);
  763. writederef(nil);
  764. end;
  765. end;
  766. procedure ttype.resolve;
  767. begin
  768. if assigned(sym) then
  769. begin
  770. resolvesym(sym);
  771. setsym(sym);
  772. end
  773. else
  774. resolvedef(def);
  775. end;
  776. {****************************************************************************
  777. TSymList
  778. ****************************************************************************}
  779. constructor tsymlist.init;
  780. begin
  781. def:=nil; { needed for procedures }
  782. firstsym:=nil;
  783. lastsym:=nil;
  784. end;
  785. constructor tsymlist.load;
  786. var
  787. sym : psym;
  788. begin
  789. def:=readdefref;
  790. firstsym:=nil;
  791. lastsym:=nil;
  792. repeat
  793. sym:=readsymref;
  794. if sym=nil then
  795. break;
  796. addsym(sym);
  797. until false;
  798. end;
  799. destructor tsymlist.done;
  800. begin
  801. clear;
  802. end;
  803. function tsymlist.empty:boolean;
  804. begin
  805. empty:=(firstsym=nil);
  806. end;
  807. procedure tsymlist.clear;
  808. var
  809. hp : psymlistitem;
  810. begin
  811. while assigned(firstsym) do
  812. begin
  813. hp:=firstsym;
  814. firstsym:=firstsym^.next;
  815. dispose(hp);
  816. end;
  817. firstsym:=nil;
  818. lastsym:=nil;
  819. def:=nil;
  820. end;
  821. procedure tsymlist.setdef(p:pdef);
  822. begin
  823. def:=p;
  824. end;
  825. procedure tsymlist.addsym(p:psym);
  826. var
  827. hp : psymlistitem;
  828. begin
  829. if not assigned(p) then
  830. exit;
  831. new(hp);
  832. hp^.sym:=p;
  833. hp^.next:=nil;
  834. if assigned(lastsym) then
  835. lastsym^.next:=hp
  836. else
  837. firstsym:=hp;
  838. lastsym:=hp;
  839. end;
  840. function tsymlist.getcopy:psymlist;
  841. var
  842. hp : psymlist;
  843. hp2 : psymlistitem;
  844. begin
  845. new(hp,init);
  846. hp^.def:=def;
  847. hp2:=firstsym;
  848. while assigned(hp2) do
  849. begin
  850. hp^.addsym(hp2^.sym);
  851. hp2:=hp2^.next;
  852. end;
  853. getcopy:=hp;
  854. end;
  855. procedure tsymlist.write;
  856. var
  857. hp : psymlistitem;
  858. begin
  859. writederef(def);
  860. hp:=firstsym;
  861. while assigned(hp) do
  862. begin
  863. writederef(hp^.sym);
  864. hp:=hp^.next;
  865. end;
  866. writederef(nil);
  867. end;
  868. procedure tsymlist.resolve;
  869. var
  870. hp : psymlistitem;
  871. begin
  872. resolvedef(def);
  873. hp:=firstsym;
  874. while assigned(hp) do
  875. begin
  876. resolvesym(hp^.sym);
  877. hp:=hp^.next;
  878. end;
  879. end;
  880. {*****************************************************************************
  881. Definition Helpers
  882. *****************************************************************************}
  883. function globaldef(const s : string) : pdef;
  884. var st : string;
  885. symt : psymtable;
  886. begin
  887. srsym := nil;
  888. if pos('.',s) > 0 then
  889. begin
  890. st := copy(s,1,pos('.',s)-1);
  891. getsym(st,false);
  892. st := copy(s,pos('.',s)+1,255);
  893. if assigned(srsym) then
  894. begin
  895. if srsym^.typ = unitsym then
  896. begin
  897. symt := punitsym(srsym)^.unitsymtable;
  898. srsym := symt^.search(st);
  899. end else srsym := nil;
  900. end;
  901. end else st := s;
  902. if srsym = nil then getsym(st,false);
  903. if srsym = nil then
  904. getsymonlyin(systemunit,st);
  905. if srsym^.typ<>typesym then
  906. begin
  907. Message(type_e_type_id_expected);
  908. exit;
  909. end;
  910. globaldef := ptypesym(srsym)^.restype.def;
  911. end;
  912. {*****************************************************************************
  913. Symbol Call Back Functions
  914. *****************************************************************************}
  915. procedure derefsym(p : pnamedindexobject);
  916. begin
  917. psym(p)^.deref;
  918. end;
  919. procedure check_forward(sym : pnamedindexobject);
  920. begin
  921. if psym(sym)^.typ=procsym then
  922. pprocsym(sym)^.check_forward
  923. { check also object method table }
  924. { we needn't to test the def list }
  925. { because each object has to have a type sym }
  926. else
  927. if (psym(sym)^.typ=typesym) and
  928. assigned(ptypesym(sym)^.restype.def) and
  929. (ptypesym(sym)^.restype.def^.deftype=objectdef) then
  930. pobjectdef(ptypesym(sym)^.restype.def)^.check_forwards;
  931. end;
  932. procedure labeldefined(p : pnamedindexobject);
  933. begin
  934. if (psym(p)^.typ=labelsym) and
  935. not(plabelsym(p)^.defined) then
  936. begin
  937. if plabelsym(p)^.used then
  938. Message1(sym_e_label_used_and_not_defined,p^.name)
  939. else
  940. Message1(sym_w_label_not_defined,p^.name);
  941. end;
  942. end;
  943. procedure unitsymbolused(p : pnamedindexobject);
  944. begin
  945. if (psym(p)^.typ=unitsym) and
  946. (punitsym(p)^.refs=0) then
  947. comment(V_info,'Unit '+p^.name+' is not used');
  948. end;
  949. procedure varsymbolused(p : pnamedindexobject);
  950. begin
  951. if (psym(p)^.typ=varsym) and
  952. ((psym(p)^.owner^.symtabletype in
  953. [parasymtable,localsymtable,objectsymtable,staticsymtable])) then
  954. begin
  955. { unused symbol should be reported only if no }
  956. { error is reported }
  957. { if the symbol is in a register it is used }
  958. { also don't count the value parameters which have local copies }
  959. { also don't claim for high param of open parameters (PM) }
  960. if (Errorcount<>0) or
  961. (copy(p^.name,1,3)='val') or
  962. (copy(p^.name,1,4)='high') then
  963. exit;
  964. if (pvarsym(p)^.refs=0) then
  965. begin
  966. if (psym(p)^.owner^.symtabletype=parasymtable) or (vo_is_local_copy in pvarsym(p)^.varoptions) then
  967. begin
  968. MessagePos1(psym(p)^.fileinfo,sym_h_para_identifier_not_used,p^.name);
  969. end
  970. else if (psym(p)^.owner^.symtabletype=objectsymtable) then
  971. MessagePos2(psym(p)^.fileinfo,sym_n_private_identifier_not_used,psym(p)^.owner^.name^,p^.name)
  972. else
  973. MessagePos1(psym(p)^.fileinfo,sym_n_local_identifier_not_used,p^.name);
  974. end
  975. else if pvarsym(p)^.varstate=vs_assigned then
  976. begin
  977. if (psym(p)^.owner^.symtabletype=parasymtable) then
  978. begin
  979. if (pvarsym(p)^.varspez<>vs_var) then
  980. MessagePos1(psym(p)^.fileinfo,sym_h_para_identifier_only_set,p^.name)
  981. end
  982. else if (vo_is_local_copy in pvarsym(p)^.varoptions) then
  983. begin
  984. if (pvarsym(p)^.varspez<>vs_var) then
  985. MessagePos1(psym(p)^.fileinfo,sym_h_para_identifier_only_set,p^.name);
  986. end
  987. else if (psym(p)^.owner^.symtabletype=objectsymtable) then
  988. MessagePos2(psym(p)^.fileinfo,sym_n_private_identifier_only_set,psym(p)^.owner^.name^,p^.name)
  989. else if (psym(p)^.owner^.symtabletype<>parasymtable) then
  990. MessagePos1(psym(p)^.fileinfo,sym_n_local_identifier_only_set,p^.name);
  991. end;
  992. end
  993. else if ((psym(p)^.owner^.symtabletype in
  994. [objectsymtable,parasymtable,localsymtable,staticsymtable])) then
  995. begin
  996. if (Errorcount<>0) then
  997. exit;
  998. { do not claim for inherited private fields !! }
  999. if (psym(p)^.refs=0) and (psym(p)^.owner^.symtabletype=objectsymtable) then
  1000. MessagePos2(psym(p)^.fileinfo,sym_n_private_method_not_used,psym(p)^.owner^.name^,p^.name)
  1001. { units references are problematic }
  1002. else if (psym(p)^.refs=0) and not(psym(p)^.typ in [funcretsym,enumsym,unitsym]) then
  1003. if (psym(p)^.typ<>procsym) or not (pprocsym(p)^.is_global) or
  1004. { all program functions are declared global
  1005. but unused should still be signaled PM }
  1006. ((psym(p)^.owner^.symtabletype=staticsymtable) and
  1007. not current_module^.is_unit) then
  1008. MessagePos2(psym(p)^.fileinfo,sym_h_local_symbol_not_used,SymTypeName[psym(p)^.typ],p^.name);
  1009. end;
  1010. end;
  1011. procedure TestPrivate(p : pnamedindexobject);
  1012. begin
  1013. if sp_private in psym(p)^.symoptions then
  1014. varsymbolused(p);
  1015. end;
  1016. procedure objectprivatesymbolused(p : pnamedindexobject);
  1017. begin
  1018. {
  1019. Don't test simple object aliases PM
  1020. }
  1021. if (psym(p)^.typ=typesym) and
  1022. (ptypesym(p)^.restype.def^.deftype=objectdef) and
  1023. (ptypesym(p)^.restype.def^.typesym=ptypesym(p)) then
  1024. pobjectdef(ptypesym(p)^.restype.def)^.symtable^.foreach(
  1025. {$ifndef TP}@{$endif}TestPrivate);
  1026. end;
  1027. {$ifdef GDB}
  1028. procedure concatstab(p : pnamedindexobject);
  1029. begin
  1030. if psym(p)^.typ <> procsym then
  1031. psym(p)^.concatstabto(asmoutput);
  1032. end;
  1033. procedure concattypestab(p : pnamedindexobject);
  1034. begin
  1035. if psym(p)^.typ = typesym then
  1036. begin
  1037. psym(p)^.isstabwritten:=false;
  1038. psym(p)^.concatstabto(asmoutput);
  1039. end;
  1040. end;
  1041. procedure forcestabto(asmlist : paasmoutput; pd : pdef);
  1042. begin
  1043. if not pd^.is_def_stab_written then
  1044. begin
  1045. if assigned(pd^.typesym) then
  1046. pd^.typesym^.isusedinstab := true;
  1047. pd^.concatstabto(asmlist);
  1048. end;
  1049. end;
  1050. {$endif}
  1051. {$ifdef CHAINPROCSYMS}
  1052. procedure chainprocsym(p : psym);
  1053. var
  1054. storesymtablestack : psymtable;
  1055. begin
  1056. if p^.typ=procsym then
  1057. begin
  1058. storesymtablestack:=symtablestack;
  1059. symtablestack:=p^.owner^.next;
  1060. while assigned(symtablestack) do
  1061. begin
  1062. { search for same procsym in other units }
  1063. getsym(p^.name,false);
  1064. if assigned(srsym) and (srsym^.typ=procsym) then
  1065. begin
  1066. pprocsym(p)^.nextprocsym:=pprocsym(srsym);
  1067. symtablestack:=storesymtablestack;
  1068. exit;
  1069. end
  1070. else if srsym=nil then
  1071. symtablestack:=nil
  1072. else
  1073. symtablestack:=srsymtable^.next;
  1074. end;
  1075. symtablestack:=storesymtablestack;
  1076. end;
  1077. end;
  1078. {$endif}
  1079. procedure write_refs(sym : pnamedindexobject);
  1080. begin
  1081. psym(sym)^.write_references;
  1082. end;
  1083. {$ifdef BrowserLog}
  1084. procedure add_to_browserlog(sym : pnamedindexobject);
  1085. begin
  1086. psym(sym)^.add_to_browserlog;
  1087. end;
  1088. {$endif UseBrowser}
  1089. {*****************************************************************************
  1090. Search Symtables for Syms
  1091. *****************************************************************************}
  1092. procedure getsym(const s : stringid;notfounderror : boolean);
  1093. var
  1094. speedvalue : longint;
  1095. begin
  1096. speedvalue:=getspeedvalue(s);
  1097. lastsrsym:=nil;
  1098. srsymtable:=symtablestack;
  1099. while assigned(srsymtable) do
  1100. begin
  1101. srsym:=srsymtable^.speedsearch(s,speedvalue);
  1102. if assigned(srsym) then
  1103. exit
  1104. else
  1105. srsymtable:=srsymtable^.next;
  1106. end;
  1107. if notfounderror then
  1108. begin
  1109. Message1(sym_e_id_not_found,s);
  1110. srsym:=generrorsym;
  1111. end
  1112. else
  1113. srsym:=nil;
  1114. end;
  1115. procedure getsymonlyin(p : psymtable;const s : stringid);
  1116. begin
  1117. { the caller have to take care if srsym=nil (FK) }
  1118. srsym:=nil;
  1119. if assigned(p) then
  1120. begin
  1121. srsymtable:=p;
  1122. srsym:=srsymtable^.search(s);
  1123. if assigned(srsym) then
  1124. exit
  1125. else
  1126. begin
  1127. if (punitsymtable(srsymtable)=punitsymtable(current_module^.globalsymtable)) then
  1128. begin
  1129. getsymonlyin(psymtable(current_module^.localsymtable),s);
  1130. if assigned(srsym) then
  1131. srsymtable:=psymtable(current_module^.localsymtable)
  1132. else
  1133. Message1(sym_e_id_not_found,s);
  1134. end
  1135. else
  1136. Message1(sym_e_id_not_found,s);
  1137. end;
  1138. end;
  1139. end;
  1140. function search_a_symtable(const symbol:string;symtabletype:tsymtabletype):Psym;
  1141. {Search for a symbol in a specified symbol table. Returns nil if
  1142. the symtable is not found, and also if the symbol cannot be found
  1143. in the desired symtable }
  1144. var hsymtab:Psymtable;
  1145. res:Psym;
  1146. begin
  1147. res:=nil;
  1148. hsymtab:=symtablestack;
  1149. while (hsymtab<>nil) and (hsymtab^.symtabletype<>symtabletype) do
  1150. hsymtab:=hsymtab^.next;
  1151. if hsymtab<>nil then
  1152. {We found the desired symtable. Now check if the symbol we
  1153. search for is defined in it }
  1154. res:=hsymtab^.search(symbol);
  1155. search_a_symtable:=res;
  1156. end;
  1157. {****************************************************************************
  1158. TSYMTABLE
  1159. ****************************************************************************}
  1160. constructor tsymtable.init(t : tsymtabletype);
  1161. begin
  1162. symtabletype:=t;
  1163. symtablelevel:=0;
  1164. defowner:=nil;
  1165. unitid:=0;
  1166. next:=nil;
  1167. name:=nil;
  1168. address_fixup:=0;
  1169. datasize:=0;
  1170. dataalignment:=1;
  1171. new(symindex,init(indexgrowsize));
  1172. new(defindex,init(indexgrowsize));
  1173. if symtabletype<>withsymtable then
  1174. begin
  1175. new(symsearch,init);
  1176. symsearch^.noclear:=true;
  1177. end
  1178. else
  1179. symsearch:=nil;
  1180. alignment:=def_alignment;
  1181. end;
  1182. destructor tsymtable.done;
  1183. begin
  1184. stringdispose(name);
  1185. dispose(symindex,done);
  1186. dispose(defindex,done);
  1187. { symsearch can already be disposed or set to nil for withsymtable }
  1188. if assigned(symsearch) then
  1189. begin
  1190. dispose(symsearch,done);
  1191. symsearch:=nil;
  1192. end;
  1193. end;
  1194. constructor twithsymtable.init;
  1195. begin
  1196. inherited init(withsymtable);
  1197. direct_with:=false;
  1198. withnode:=nil;
  1199. withrefnode:=nil;
  1200. end;
  1201. destructor twithsymtable.done;
  1202. begin
  1203. symsearch:=nil;
  1204. inherited done;
  1205. end;
  1206. {***********************************************
  1207. Helpers
  1208. ***********************************************}
  1209. function tsymtable.getnewtypecount : word;
  1210. begin
  1211. getnewtypecount:=pglobaltypecount^;
  1212. inc(pglobaltypecount^);
  1213. end;
  1214. procedure tsymtable.registerdef(p : pdef);
  1215. begin
  1216. defindex^.insert(p);
  1217. { set def owner and indexnb }
  1218. p^.owner:=@self;
  1219. end;
  1220. procedure order_overloads(p : Pnamedindexobject);
  1221. begin
  1222. if psym(p)^.typ=procsym then
  1223. pprocsym(p)^.order_overloaded;
  1224. end;
  1225. procedure tsymtable.foreach(proc2call : tnamedindexcallback);
  1226. begin
  1227. symindex^.foreach(proc2call);
  1228. end;
  1229. {***********************************************
  1230. LOAD / WRITE SYMTABLE FROM PPU
  1231. ***********************************************}
  1232. procedure tsymtable.loaddefs;
  1233. var
  1234. hp : pdef;
  1235. b : byte;
  1236. begin
  1237. { load start of definition section, which holds the amount of defs }
  1238. if current_ppu^.readentry<>ibstartdefs then
  1239. Message(unit_f_ppu_read_error);
  1240. current_ppu^.getlongint;
  1241. { read definitions }
  1242. repeat
  1243. b:=current_ppu^.readentry;
  1244. case b of
  1245. ibpointerdef : hp:=new(ppointerdef,load);
  1246. ibarraydef : hp:=new(parraydef,load);
  1247. iborddef : hp:=new(porddef,load);
  1248. ibfloatdef : hp:=new(pfloatdef,load);
  1249. ibprocdef : hp:=new(pprocdef,load);
  1250. ibshortstringdef : hp:=new(pstringdef,shortload);
  1251. iblongstringdef : hp:=new(pstringdef,longload);
  1252. ibansistringdef : hp:=new(pstringdef,ansiload);
  1253. ibwidestringdef : hp:=new(pstringdef,wideload);
  1254. ibrecorddef : hp:=new(precorddef,load);
  1255. ibobjectdef : hp:=new(pobjectdef,load);
  1256. ibenumdef : hp:=new(penumdef,load);
  1257. ibsetdef : hp:=new(psetdef,load);
  1258. ibprocvardef : hp:=new(pprocvardef,load);
  1259. ibfiledef : hp:=new(pfiledef,load);
  1260. ibclassrefdef : hp:=new(pclassrefdef,load);
  1261. ibformaldef : hp:=new(pformaldef,load);
  1262. ibenddefs : break;
  1263. ibend : Message(unit_f_ppu_read_error);
  1264. else
  1265. Message1(unit_f_ppu_invalid_entry,tostr(b));
  1266. end;
  1267. hp^.owner:=@self;
  1268. defindex^.insert(hp);
  1269. until false;
  1270. end;
  1271. procedure tsymtable.loadsyms;
  1272. var
  1273. b : byte;
  1274. sym : psym;
  1275. begin
  1276. { load start of definition section, which holds the amount of defs }
  1277. if current_ppu^.readentry<>ibstartsyms then
  1278. Message(unit_f_ppu_read_error);
  1279. { skip amount of symbols, not used currently }
  1280. current_ppu^.getlongint;
  1281. { load datasize,dataalignment of this symboltable }
  1282. datasize:=current_ppu^.getlongint;
  1283. dataalignment:=current_ppu^.getlongint;
  1284. { now read the symbols }
  1285. repeat
  1286. b:=current_ppu^.readentry;
  1287. case b of
  1288. ibtypesym : sym:=new(ptypesym,load);
  1289. ibprocsym : sym:=new(pprocsym,load);
  1290. ibconstsym : sym:=new(pconstsym,load);
  1291. ibvarsym : sym:=new(pvarsym,load);
  1292. ibfuncretsym : sym:=new(pfuncretsym,load);
  1293. ibabsolutesym : sym:=new(pabsolutesym,load);
  1294. ibenumsym : sym:=new(penumsym,load);
  1295. ibtypedconstsym : sym:=new(ptypedconstsym,load);
  1296. ibpropertysym : sym:=new(ppropertysym,load);
  1297. ibunitsym : sym:=new(punitsym,load);
  1298. iblabelsym : sym:=new(plabelsym,load);
  1299. ibsyssym : sym:=new(psyssym,load);
  1300. ibendsyms : break;
  1301. ibend : Message(unit_f_ppu_read_error);
  1302. else
  1303. Message1(unit_f_ppu_invalid_entry,tostr(b));
  1304. end;
  1305. sym^.owner:=@self;
  1306. symindex^.insert(sym);
  1307. symsearch^.insert(sym);
  1308. until false;
  1309. end;
  1310. procedure tsymtable.writedefs;
  1311. var
  1312. pd : pdef;
  1313. begin
  1314. { each definition get a number, write then the amount of defs to the
  1315. ibstartdef entry }
  1316. current_ppu^.putlongint(defindex^.count);
  1317. current_ppu^.writeentry(ibstartdefs);
  1318. { now write the definition }
  1319. pd:=pdef(defindex^.first);
  1320. while assigned(pd) do
  1321. begin
  1322. pd^.write;
  1323. pd:=pdef(pd^.next);
  1324. end;
  1325. { write end of definitions }
  1326. current_ppu^.writeentry(ibenddefs);
  1327. end;
  1328. procedure tsymtable.writesyms;
  1329. var
  1330. pd : psym;
  1331. begin
  1332. { each definition get a number, write then the amount of syms and the
  1333. datasize to the ibsymdef entry }
  1334. current_ppu^.putlongint(symindex^.count);
  1335. current_ppu^.putlongint(datasize);
  1336. current_ppu^.putlongint(dataalignment);
  1337. current_ppu^.writeentry(ibstartsyms);
  1338. { foreach is used to write all symbols }
  1339. pd:=psym(symindex^.first);
  1340. while assigned(pd) do
  1341. begin
  1342. pd^.write;
  1343. pd:=psym(pd^.next);
  1344. end;
  1345. { end of symbols }
  1346. current_ppu^.writeentry(ibendsyms);
  1347. end;
  1348. procedure tsymtable.deref;
  1349. var
  1350. hp : pdef;
  1351. hs : psym;
  1352. begin
  1353. { first deref the ttypesyms }
  1354. hs:=psym(symindex^.first);
  1355. while assigned(hs) do
  1356. begin
  1357. hs^.prederef;
  1358. hs:=psym(hs^.next);
  1359. end;
  1360. { deref the definitions }
  1361. hp:=pdef(defindex^.first);
  1362. while assigned(hp) do
  1363. begin
  1364. hp^.deref;
  1365. hp:=pdef(hp^.next);
  1366. end;
  1367. { deref the symbols }
  1368. hs:=psym(symindex^.first);
  1369. while assigned(hs) do
  1370. begin
  1371. hs^.deref;
  1372. hs:=psym(hs^.next);
  1373. end;
  1374. end;
  1375. constructor tsymtable.loadas(typ : tsymtabletype);
  1376. var
  1377. storesymtable : psymtable;
  1378. st_loading : boolean;
  1379. begin
  1380. st_loading:=in_loading;
  1381. in_loading:=true;
  1382. symtabletype:=typ;
  1383. new(symindex,init(indexgrowsize));
  1384. new(defindex,init(indexgrowsize));
  1385. new(symsearch,init);
  1386. symsearch^.noclear:=true;
  1387. { reset }
  1388. defowner:=nil;
  1389. name:=nil;
  1390. alignment:=def_alignment;
  1391. datasize:=0;
  1392. address_fixup:= 0;
  1393. unitid:=0;
  1394. { setup symtabletype specific things }
  1395. case typ of
  1396. unitsymtable :
  1397. begin
  1398. symtablelevel:=0;
  1399. {$ifndef NEWMAP}
  1400. current_module^.map^[0]:=@self;
  1401. {$else NEWMAP}
  1402. current_module^.globalsymtable:=@self;
  1403. {$endif NEWMAP}
  1404. end;
  1405. recordsymtable,
  1406. objectsymtable :
  1407. begin
  1408. storesymtable:=aktrecordsymtable;
  1409. aktrecordsymtable:=@self;
  1410. end;
  1411. parasymtable,
  1412. localsymtable :
  1413. begin
  1414. storesymtable:=aktlocalsymtable;
  1415. aktlocalsymtable:=@self;
  1416. end;
  1417. { used for local browser }
  1418. staticppusymtable :
  1419. begin
  1420. aktstaticsymtable:=@self;
  1421. symsearch^.usehash;
  1422. end;
  1423. end;
  1424. { we need the correct symtable for registering }
  1425. if not (typ in [localsymtable,parasymtable,recordsymtable,objectsymtable]) then
  1426. begin
  1427. next:=symtablestack;
  1428. symtablestack:=@self;
  1429. end;
  1430. { load definitions }
  1431. loaddefs;
  1432. { load symbols }
  1433. loadsyms;
  1434. if not (typ in [localsymtable,parasymtable,recordsymtable,objectsymtable]) then
  1435. begin
  1436. { now we can deref the syms and defs }
  1437. deref;
  1438. { restore symtablestack }
  1439. symtablestack:=next;
  1440. end;
  1441. case typ of
  1442. unitsymtable :
  1443. begin
  1444. {$ifdef NEWMAP}
  1445. { necessary for dependencies }
  1446. current_module^.globalsymtable:=nil;
  1447. {$endif NEWMAP}
  1448. end;
  1449. recordsymtable,
  1450. objectsymtable :
  1451. aktrecordsymtable:=storesymtable;
  1452. localsymtable,
  1453. parasymtable :
  1454. aktlocalsymtable:=storesymtable;
  1455. end;
  1456. in_loading:=st_loading;
  1457. end;
  1458. procedure tsymtable.writeas;
  1459. var
  1460. oldtyp : byte;
  1461. storesymtable : psymtable;
  1462. begin
  1463. storesymtable:=aktrecordsymtable;
  1464. case symtabletype of
  1465. recordsymtable,
  1466. objectsymtable :
  1467. begin
  1468. storesymtable:=aktrecordsymtable;
  1469. aktrecordsymtable:=@self;
  1470. oldtyp:=current_ppu^.entrytyp;
  1471. current_ppu^.entrytyp:=subentryid;
  1472. end;
  1473. parasymtable,
  1474. localsymtable :
  1475. begin
  1476. storesymtable:=aktlocalsymtable;
  1477. aktlocalsymtable:=@self;
  1478. end;
  1479. end;
  1480. { order procsym overloads }
  1481. foreach({$ifndef TP}@{$endif}Order_overloads);
  1482. { write definitions }
  1483. writedefs;
  1484. { write symbols }
  1485. writesyms;
  1486. case symtabletype of
  1487. recordsymtable,
  1488. objectsymtable :
  1489. begin
  1490. current_ppu^.entrytyp:=oldtyp;
  1491. aktrecordsymtable:=storesymtable;
  1492. end;
  1493. localsymtable,
  1494. parasymtable :
  1495. aktlocalsymtable:=storesymtable;
  1496. end;
  1497. end;
  1498. {***********************************************
  1499. Get Symbol / Def by Number
  1500. ***********************************************}
  1501. function tsymtable.getsymnr(l : longint) : psym;
  1502. var
  1503. hp : psym;
  1504. begin
  1505. hp:=psym(symindex^.search(l));
  1506. if hp=nil then
  1507. internalerror(10999);
  1508. getsymnr:=hp;
  1509. end;
  1510. function tsymtable.getdefnr(l : longint) : pdef;
  1511. var
  1512. hp : pdef;
  1513. begin
  1514. hp:=pdef(defindex^.search(l));
  1515. if hp=nil then
  1516. internalerror(10998);
  1517. getdefnr:=hp;
  1518. end;
  1519. {***********************************************
  1520. Table Access
  1521. ***********************************************}
  1522. procedure tsymtable.clear;
  1523. begin
  1524. { remove no entry from a withsymtable as it is only a pointer to the
  1525. recorddef or objectdef symtable }
  1526. if symtabletype=withsymtable then
  1527. exit;
  1528. symindex^.clear;
  1529. defindex^.clear;
  1530. end;
  1531. function tsymtable.insert(sym:psym):psym;
  1532. var
  1533. hp : psymtable;
  1534. hsym : psym;
  1535. begin
  1536. { set owner and sym indexnb }
  1537. sym^.owner:=@self;
  1538. {$ifdef CHAINPROCSYMS}
  1539. { set the nextprocsym field }
  1540. if sym^.typ=procsym then
  1541. chainprocsym(sym);
  1542. {$endif CHAINPROCSYMS}
  1543. { writes the symbol in data segment if required }
  1544. { also sets the datasize of owner }
  1545. if not in_loading then
  1546. sym^.insert_in_data;
  1547. if (symtabletype in [staticsymtable,globalsymtable]) then
  1548. begin
  1549. hp:=symtablestack;
  1550. while assigned(hp) do
  1551. begin
  1552. if hp^.symtabletype in [staticsymtable,globalsymtable] then
  1553. begin
  1554. hsym:=hp^.search(sym^.name);
  1555. if assigned(hsym) then
  1556. DuplicateSym(hsym);
  1557. end;
  1558. hp:=hp^.next;
  1559. end;
  1560. end;
  1561. { check the current symtable }
  1562. hsym:=search(sym^.name);
  1563. if assigned(hsym) then
  1564. DuplicateSym(hsym);
  1565. { check for duplicate id in local and parasymtable symtable }
  1566. if (symtabletype=localsymtable) then
  1567. { to be on the save side: }
  1568. begin
  1569. if assigned(next) and
  1570. (next^.symtabletype=parasymtable) then
  1571. begin
  1572. hsym:=next^.search(sym^.name);
  1573. if assigned(hsym) then
  1574. DuplicateSym(hsym);
  1575. end
  1576. else if (current_module^.flags and uf_local_browser)=0 then
  1577. internalerror(43789);
  1578. end;
  1579. { check for duplicate id in local symtable of methods }
  1580. if (symtabletype=localsymtable) and
  1581. assigned(next) and
  1582. assigned(next^.next) and
  1583. { funcretsym is allowed !! }
  1584. (sym^.typ <> funcretsym) and
  1585. (next^.next^.symtabletype=objectsymtable) then
  1586. begin
  1587. hsym:=search_class_member(pobjectdef(next^.next^.defowner),sym^.name);
  1588. { but private ids can be reused }
  1589. if assigned(hsym) and
  1590. (not(sp_private in hsym^.symoptions) or
  1591. (hsym^.owner^.defowner^.owner^.symtabletype<>unitsymtable)) then
  1592. DuplicateSym(hsym);
  1593. end;
  1594. { check for duplicate id in para symtable of methods }
  1595. if (symtabletype=parasymtable) and
  1596. assigned(procinfo^._class) and
  1597. { but not in nested procedures !}
  1598. (not(assigned(procinfo^.parent)) or
  1599. (assigned(procinfo^.parent) and
  1600. not(assigned(procinfo^.parent^._class)))
  1601. ) and
  1602. { funcretsym is allowed !! }
  1603. (sym^.typ <> funcretsym) then
  1604. begin
  1605. hsym:=search_class_member(procinfo^._class,sym^.name);
  1606. { but private ids can be reused }
  1607. if assigned(hsym) and
  1608. (not(sp_private in hsym^.symoptions) or
  1609. (hsym^.owner^.defowner^.owner^.symtabletype<>unitsymtable)) then
  1610. DuplicateSym(hsym);
  1611. end;
  1612. { check for duplicate field id in inherited classes }
  1613. if (sym^.typ=varsym) and
  1614. (symtabletype=objectsymtable) and
  1615. assigned(defowner) then
  1616. begin
  1617. hsym:=search_class_member(pobjectdef(defowner),sym^.name);
  1618. { but private ids can be reused }
  1619. if assigned(hsym) and
  1620. (not(sp_private in hsym^.symoptions) or
  1621. (hsym^.owner^.defowner^.owner^.symtabletype<>unitsymtable)) then
  1622. DuplicateSym(hsym);
  1623. end;
  1624. { register definition of typesym }
  1625. if (sym^.typ = typesym) and
  1626. assigned(ptypesym(sym)^.restype.def) then
  1627. begin
  1628. if not(assigned(ptypesym(sym)^.restype.def^.owner)) and
  1629. (ptypesym(sym)^.restype.def^.deftype<>errordef) then
  1630. registerdef(ptypesym(sym)^.restype.def);
  1631. {$ifdef GDB}
  1632. if (cs_debuginfo in aktmoduleswitches) and assigned(debuglist) and
  1633. (symtabletype in [globalsymtable,staticsymtable]) then
  1634. begin
  1635. ptypesym(sym)^.isusedinstab := true;
  1636. sym^.concatstabto(debuglist);
  1637. end;
  1638. {$endif GDB}
  1639. end;
  1640. { insert in index and search hash }
  1641. symindex^.insert(sym);
  1642. symsearch^.insert(sym);
  1643. insert:=sym;
  1644. end;
  1645. function tsymtable.search(const s : stringid) : psym;
  1646. begin
  1647. {search:=psym(symsearch^.search(s));
  1648. this bypasses the ref generation (PM) }
  1649. search:=speedsearch(s,getspeedvalue(s));
  1650. end;
  1651. function tsymtable.speedsearch(const s : stringid;speedvalue : longint) : psym;
  1652. var
  1653. hp : psym;
  1654. newref : pref;
  1655. begin
  1656. hp:=psym(symsearch^.speedsearch(s,speedvalue));
  1657. if assigned(hp) then
  1658. begin
  1659. { reject non static members in static procedures,
  1660. be carefull aktprocsym^.definition is not allways
  1661. loaded already (PFV) }
  1662. if (symtabletype=objectsymtable) and
  1663. not(sp_static in hp^.symoptions) and
  1664. allow_only_static
  1665. {assigned(aktprocsym) and
  1666. assigned(aktprocsym^.definition) and
  1667. ((aktprocsym^.definition^.options and postaticmethod)<>0)} then
  1668. Message(sym_e_only_static_in_static);
  1669. if (symtabletype=unitsymtable) and
  1670. assigned(punitsymtable(@self)^.unitsym) then
  1671. inc(punitsymtable(@self)^.unitsym^.refs);
  1672. { unitsym are only loaded for browsing PM }
  1673. { this was buggy anyway because we could use }
  1674. { unitsyms from other units in _USES !! }
  1675. if (symtabletype=unitsymtable) and (hp^.typ=unitsym) and
  1676. assigned(current_module) and (current_module^.globalsymtable<>@self) then
  1677. hp:=nil;
  1678. if assigned(hp) and
  1679. (cs_browser in aktmoduleswitches) and make_ref then
  1680. begin
  1681. new(newref,init(hp^.lastref,@tokenpos));
  1682. { for symbols that are in tables without
  1683. browser info or syssyms (PM) }
  1684. if hp^.refcount=0 then
  1685. begin
  1686. hp^.defref:=newref;
  1687. hp^.lastref:=newref;
  1688. end
  1689. else
  1690. if resolving_forward and assigned(hp^.defref) then
  1691. { put it as second reference }
  1692. begin
  1693. newref^.nextref:=hp^.defref^.nextref;
  1694. hp^.defref^.nextref:=newref;
  1695. hp^.lastref^.nextref:=nil;
  1696. end
  1697. else
  1698. hp^.lastref:=newref;
  1699. inc(hp^.refcount);
  1700. end;
  1701. if assigned(hp) and make_ref then
  1702. begin
  1703. inc(hp^.refs);
  1704. end;
  1705. end;
  1706. speedsearch:=hp;
  1707. end;
  1708. function tsymtable.rename(const olds,news : stringid):psym;
  1709. begin
  1710. rename:=psym(symsearch^.rename(olds,news));
  1711. end;
  1712. {***********************************************
  1713. Browser
  1714. ***********************************************}
  1715. procedure tsymtable.load_browser;
  1716. var
  1717. b : byte;
  1718. sym : psym;
  1719. prdef : pdef;
  1720. oldrecsyms : psymtable;
  1721. begin
  1722. if symtabletype in [recordsymtable,objectsymtable] then
  1723. begin
  1724. oldrecsyms:=aktrecordsymtable;
  1725. aktrecordsymtable:=@self;
  1726. end;
  1727. if symtabletype in [parasymtable,localsymtable] then
  1728. begin
  1729. oldrecsyms:=aktlocalsymtable;
  1730. aktlocalsymtable:=@self;
  1731. end;
  1732. if symtabletype=staticppusymtable then
  1733. aktstaticsymtable:=@self;
  1734. b:=current_ppu^.readentry;
  1735. if b <> ibbeginsymtablebrowser then
  1736. Message1(unit_f_ppu_invalid_entry,tostr(b));
  1737. repeat
  1738. b:=current_ppu^.readentry;
  1739. case b of
  1740. ibsymref : begin
  1741. sym:=readsymref;
  1742. resolvesym(sym);
  1743. if assigned(sym) then
  1744. sym^.load_references;
  1745. end;
  1746. ibdefref : begin
  1747. prdef:=readdefref;
  1748. resolvedef(prdef);
  1749. if assigned(prdef) then
  1750. begin
  1751. if prdef^.deftype<>procdef then
  1752. Message(unit_f_ppu_read_error);
  1753. pprocdef(prdef)^.load_references;
  1754. end;
  1755. end;
  1756. ibendsymtablebrowser : break;
  1757. else
  1758. Message1(unit_f_ppu_invalid_entry,tostr(b));
  1759. end;
  1760. until false;
  1761. if symtabletype in [recordsymtable,objectsymtable] then
  1762. aktrecordsymtable:=oldrecsyms;
  1763. if symtabletype in [parasymtable,localsymtable] then
  1764. aktlocalsymtable:=oldrecsyms;
  1765. end;
  1766. procedure tsymtable.write_browser;
  1767. var
  1768. oldrecsyms : psymtable;
  1769. begin
  1770. { symbol numbering for references
  1771. should have been done in write PM
  1772. number_symbols;
  1773. number_defs; }
  1774. if symtabletype in [recordsymtable,objectsymtable] then
  1775. begin
  1776. oldrecsyms:=aktrecordsymtable;
  1777. aktrecordsymtable:=@self;
  1778. end;
  1779. if symtabletype in [parasymtable,localsymtable] then
  1780. begin
  1781. oldrecsyms:=aktlocalsymtable;
  1782. aktlocalsymtable:=@self;
  1783. end;
  1784. current_ppu^.writeentry(ibbeginsymtablebrowser);
  1785. foreach({$ifndef TP}@{$endif}write_refs);
  1786. current_ppu^.writeentry(ibendsymtablebrowser);
  1787. if symtabletype in [recordsymtable,objectsymtable] then
  1788. aktrecordsymtable:=oldrecsyms;
  1789. if symtabletype in [parasymtable,localsymtable] then
  1790. aktlocalsymtable:=oldrecsyms;
  1791. end;
  1792. {$ifdef BrowserLog}
  1793. procedure tsymtable.writebrowserlog;
  1794. begin
  1795. if cs_browser in aktmoduleswitches then
  1796. begin
  1797. if assigned(name) then
  1798. Browserlog.AddLog('---Symtable '+name^)
  1799. else
  1800. begin
  1801. if (symtabletype=recordsymtable) and
  1802. assigned(defowner^.typesym) then
  1803. Browserlog.AddLog('---Symtable '+defowner^.typesym^.name)
  1804. else
  1805. Browserlog.AddLog('---Symtable with no name');
  1806. end;
  1807. Browserlog.Ident;
  1808. foreach({$ifndef TP}@{$endif}add_to_browserlog);
  1809. browserlog.Unident;
  1810. end;
  1811. end;
  1812. {$endif BrowserLog}
  1813. {***********************************************
  1814. Process all entries
  1815. ***********************************************}
  1816. { checks, if all procsyms and methods are defined }
  1817. procedure tsymtable.check_forwards;
  1818. begin
  1819. foreach({$ifndef TP}@{$endif}check_forward);
  1820. end;
  1821. procedure tsymtable.checklabels;
  1822. begin
  1823. foreach({$ifndef TP}@{$endif}labeldefined);
  1824. end;
  1825. procedure tsymtable.set_alignment(_alignment : byte);
  1826. var
  1827. sym : pvarsym;
  1828. l : longint;
  1829. begin
  1830. { this can not be done if there is an
  1831. hasharray ! }
  1832. alignment:=_alignment;
  1833. if (symtabletype<>parasymtable) then
  1834. internalerror(1111);
  1835. sym:=pvarsym(symindex^.first);
  1836. datasize:=0;
  1837. { there can be only varsyms }
  1838. while assigned(sym) do
  1839. begin
  1840. l:=sym^.getpushsize;
  1841. sym^.address:=datasize;
  1842. datasize:=align(datasize+l,alignment);
  1843. sym:=pvarsym(sym^.next);
  1844. end;
  1845. end;
  1846. function tsymtable.find_at_offset(l : longint) : pvarsym;
  1847. var
  1848. sym : pvarsym;
  1849. begin
  1850. find_at_offset:=nil;
  1851. { this can not be done if there is an
  1852. hasharray ! }
  1853. if (symtabletype<>parasymtable) then
  1854. internalerror(1111);
  1855. sym:=pvarsym(symindex^.first);
  1856. while assigned(sym) do
  1857. begin
  1858. if sym^.address+address_fixup=l then
  1859. begin
  1860. find_at_offset:=sym;
  1861. exit;
  1862. end;
  1863. sym:=pvarsym(sym^.next);
  1864. end;
  1865. end;
  1866. procedure tsymtable.allunitsused;
  1867. begin
  1868. foreach({$ifndef TP}@{$endif}unitsymbolused);
  1869. end;
  1870. procedure tsymtable.allsymbolsused;
  1871. begin
  1872. foreach({$ifndef TP}@{$endif}varsymbolused);
  1873. end;
  1874. procedure tsymtable.allprivatesused;
  1875. begin
  1876. foreach({$ifndef TP}@{$endif}objectprivatesymbolused);
  1877. end;
  1878. {$ifdef CHAINPROCSYMS}
  1879. procedure tsymtable.chainprocsyms;
  1880. begin
  1881. foreach({$ifndef TP}@{$endif}chainprocsym);
  1882. end;
  1883. {$endif CHAINPROCSYMS}
  1884. {$ifdef GDB}
  1885. procedure tsymtable.concatstabto(asmlist : paasmoutput);
  1886. begin
  1887. asmoutput:=asmlist;
  1888. foreach({$ifndef TP}@{$endif}concatstab);
  1889. end;
  1890. {$endif}
  1891. {****************************************************************************
  1892. TUNITSYMTABLE
  1893. ****************************************************************************}
  1894. constructor tunitsymtable.init(t : tsymtabletype; const n : string);
  1895. begin
  1896. inherited init(t);
  1897. name:=stringdup(upper(n));
  1898. unitid:=0;
  1899. unitsym:=nil;
  1900. symsearch^.usehash;
  1901. { reset GDB things }
  1902. {$ifdef GDB}
  1903. if (t = globalsymtable) then
  1904. begin
  1905. prev_dbx_counter := dbx_counter;
  1906. dbx_counter := nil;
  1907. end;
  1908. is_stab_written:=false;
  1909. dbx_count := -1;
  1910. if cs_gdb_dbx in aktglobalswitches then
  1911. begin
  1912. dbx_count := 0;
  1913. unittypecount:=1;
  1914. if (symtabletype=globalsymtable) then
  1915. pglobaltypecount := @unittypecount;
  1916. unitid:=current_module^.unitcount;
  1917. debuglist^.concat(new(pai_asm_comment,init(strpnew('Global '+name^+' has index '+tostr(unitid)))));
  1918. debuglist^.concat(new(pai_stabs,init(strpnew('"'+name^+'",'+tostr(N_BINCL)+',0,0,0'))));
  1919. inc(current_module^.unitcount);
  1920. dbx_count_ok:=false;
  1921. dbx_counter:=@dbx_count;
  1922. do_count_dbx:=true;
  1923. end;
  1924. {$endif GDB}
  1925. end;
  1926. constructor tunitsymtable.loadasunit;
  1927. var
  1928. storeGlobalTypeCount : pword;
  1929. b : byte;
  1930. begin
  1931. unitsym:=nil;
  1932. unitid:=0;
  1933. {$ifdef GDB}
  1934. if cs_gdb_dbx in aktglobalswitches then
  1935. begin
  1936. UnitTypeCount:=1;
  1937. storeGlobalTypeCount:=PGlobalTypeCount;
  1938. PglobalTypeCount:=@UnitTypeCount;
  1939. end;
  1940. {$endif GDB}
  1941. { load symtables }
  1942. inherited loadas(unitsymtable);
  1943. { set the name after because it is set to nil in tsymtable.load !! }
  1944. name:=stringdup(current_module^.modulename^);
  1945. { dbx count }
  1946. {$ifdef GDB}
  1947. if (current_module^.flags and uf_has_dbx)<>0 then
  1948. begin
  1949. b := current_ppu^.readentry;
  1950. if b <> ibdbxcount then
  1951. Message(unit_f_ppu_dbx_count_problem)
  1952. else
  1953. dbx_count := readlong;
  1954. dbx_count_ok := true;
  1955. end
  1956. else
  1957. begin
  1958. dbx_count := -1;
  1959. dbx_count_ok:=false;
  1960. end;
  1961. if cs_gdb_dbx in aktglobalswitches then
  1962. PGlobalTypeCount:=storeGlobalTypeCount;
  1963. is_stab_written:=false;
  1964. {$endif GDB}
  1965. b:=current_ppu^.readentry;
  1966. if b<>ibendimplementation then
  1967. Message1(unit_f_ppu_invalid_entry,tostr(b));
  1968. end;
  1969. destructor tunitsymtable.done;
  1970. var
  1971. pus : punitsym;
  1972. begin
  1973. pus:=unitsym;
  1974. while assigned(pus) do
  1975. begin
  1976. unitsym:=pus^.prevsym;
  1977. pus^.prevsym:=nil;
  1978. pus^.unitsymtable:=nil;
  1979. pus:=unitsym;
  1980. end;
  1981. inherited done;
  1982. end;
  1983. procedure tunitsymtable.load_symtable_refs;
  1984. var
  1985. b : byte;
  1986. unitindex : word;
  1987. begin
  1988. if ((current_module^.flags and uf_local_browser)<>0) then
  1989. begin
  1990. current_module^.localsymtable:=new(punitsymtable,loadas(staticppusymtable));
  1991. psymtable(current_module^.localsymtable)^.name:=
  1992. stringdup('implementation of '+psymtable(current_module^.globalsymtable)^.name^);
  1993. end;
  1994. { load browser }
  1995. if (current_module^.flags and uf_has_browser)<>0 then
  1996. begin
  1997. {if not (cs_browser in aktmoduleswitches) then
  1998. current_ppu^.skipuntilentry(ibendbrowser)
  1999. else }
  2000. begin
  2001. load_browser;
  2002. unitindex:=1;
  2003. while assigned(current_module^.map^[unitindex]) do
  2004. begin
  2005. {each unit wrote one browser entry }
  2006. load_browser;
  2007. inc(unitindex);
  2008. end;
  2009. b:=current_ppu^.readentry;
  2010. if b<>ibendbrowser then
  2011. Message1(unit_f_ppu_invalid_entry,tostr(b));
  2012. end;
  2013. end;
  2014. if ((current_module^.flags and uf_local_browser)<>0) then
  2015. psymtable(current_module^.localsymtable)^.load_browser;
  2016. end;
  2017. procedure tunitsymtable.writeasunit;
  2018. var
  2019. pu : pused_unit;
  2020. begin
  2021. { first the unitname }
  2022. current_ppu^.putstring(name^);
  2023. current_ppu^.writeentry(ibmodulename);
  2024. writesourcefiles;
  2025. writeusedmacros;
  2026. writeusedunit;
  2027. { write the objectfiles and libraries that come for this unit,
  2028. preserve the containers becuase they are still needed to load
  2029. the link.res. All doesn't depend on the crc! It doesn't matter
  2030. if a unit is in a .o or .a file }
  2031. current_ppu^.do_crc:=false;
  2032. writelinkcontainer(current_module^.linkunitofiles,iblinkunitofiles,true);
  2033. writelinkcontainer(current_module^.linkunitstaticlibs,iblinkunitstaticlibs,true);
  2034. writelinkcontainer(current_module^.linkunitsharedlibs,iblinkunitsharedlibs,true);
  2035. writelinkcontainer(current_module^.linkotherofiles,iblinkotherofiles,false);
  2036. writelinkcontainer(current_module^.linkotherstaticlibs,iblinkotherstaticlibs,true);
  2037. writelinkcontainer(current_module^.linkothersharedlibs,iblinkothersharedlibs,true);
  2038. current_ppu^.do_crc:=true;
  2039. current_ppu^.writeentry(ibendinterface);
  2040. { write the symtable entries }
  2041. inherited writeas;
  2042. { all after doesn't affect crc }
  2043. current_ppu^.do_crc:=false;
  2044. { write dbx count }
  2045. {$ifdef GDB}
  2046. if cs_gdb_dbx in aktglobalswitches then
  2047. begin
  2048. {$IfDef EXTDEBUG}
  2049. writeln('Writing dbx_count ',dbx_count,' in unit ',name^,'.ppu');
  2050. {$ENDIF EXTDEBUG}
  2051. current_ppu^.putlongint(dbx_count);
  2052. current_ppu^.writeentry(ibdbxcount);
  2053. end;
  2054. {$endif GDB}
  2055. current_ppu^.writeentry(ibendimplementation);
  2056. { write static symtable
  2057. needed for local debugging of unit functions }
  2058. if ((current_module^.flags and uf_local_browser)<>0) and
  2059. assigned(current_module^.localsymtable) then
  2060. psymtable(current_module^.localsymtable)^.writeas;
  2061. { write all browser section }
  2062. if (current_module^.flags and uf_has_browser)<>0 then
  2063. begin
  2064. write_browser;
  2065. pu:=pused_unit(current_module^.used_units.first);
  2066. while assigned(pu) do
  2067. begin
  2068. psymtable(pu^.u^.globalsymtable)^.write_browser;
  2069. pu:=pused_unit(pu^.next);
  2070. end;
  2071. current_ppu^.writeentry(ibendbrowser);
  2072. end;
  2073. if ((current_module^.flags and uf_local_browser)<>0) and
  2074. assigned(current_module^.localsymtable) then
  2075. psymtable(current_module^.localsymtable)^.write_browser;
  2076. { the last entry ibend is written automaticly }
  2077. end;
  2078. function tunitsymtable.getnewtypecount : word;
  2079. begin
  2080. {$ifdef GDB}
  2081. if not (cs_gdb_dbx in aktglobalswitches) then
  2082. getnewtypecount:=tsymtable.getnewtypecount
  2083. else
  2084. {$endif GDB}
  2085. if symtabletype = staticsymtable then
  2086. getnewtypecount:=tsymtable.getnewtypecount
  2087. else
  2088. begin
  2089. getnewtypecount:=unittypecount;
  2090. inc(unittypecount);
  2091. end;
  2092. end;
  2093. {$ifdef GDB}
  2094. procedure tunitsymtable.concattypestabto(asmlist : paasmoutput);
  2095. var prev_dbx_count : plongint;
  2096. begin
  2097. if is_stab_written then exit;
  2098. if not assigned(name) then name := stringdup('Main_program');
  2099. if (symtabletype = unitsymtable) and
  2100. (current_module^.globalsymtable<>@Self) then
  2101. begin
  2102. unitid:=current_module^.unitcount;
  2103. inc(current_module^.unitcount);
  2104. end;
  2105. asmlist^.concat(new(pai_asm_comment,init(strpnew('Begin unit '+name^
  2106. +' has index '+tostr(unitid)))));
  2107. if cs_gdb_dbx in aktglobalswitches then
  2108. begin
  2109. if dbx_count_ok then
  2110. begin
  2111. asmlist^.concat(new(pai_asm_comment,init(strpnew('"repeated" unit '+name^
  2112. +' has index '+tostr(unitid)+' dbx count = '+tostr(dbx_count)))));
  2113. asmlist^.concat(new(pai_stabs,init(strpnew('"'+name^+'",'
  2114. +tostr(N_EXCL)+',0,0,'+tostr(dbx_count)))));
  2115. exit;
  2116. end
  2117. else if (current_module^.globalsymtable<>@Self) then
  2118. begin
  2119. prev_dbx_count := dbx_counter;
  2120. dbx_counter := nil;
  2121. do_count_dbx:=false;
  2122. if symtabletype = unitsymtable then
  2123. asmlist^.concat(new(pai_stabs,init(strpnew('"'+name^+'",'
  2124. +tostr(N_BINCL)+',0,0,0'))));
  2125. dbx_counter := @dbx_count;
  2126. dbx_count:=0;
  2127. do_count_dbx:=assigned(dbx_counter);
  2128. end;
  2129. end;
  2130. asmoutput:=asmlist;
  2131. foreach({$ifndef TP}@{$endif}concattypestab);
  2132. if cs_gdb_dbx in aktglobalswitches then
  2133. begin
  2134. if (current_module^.globalsymtable<>@Self) then
  2135. begin
  2136. dbx_counter := prev_dbx_count;
  2137. do_count_dbx:=false;
  2138. asmlist^.concat(new(pai_asm_comment,init(strpnew('End unit '+name^
  2139. +' has index '+tostr(unitid)))));
  2140. asmlist^.concat(new(pai_stabs,init(strpnew('"'+name^+'",'
  2141. +tostr(N_EINCL)+',0,0,0'))));
  2142. do_count_dbx:=assigned(dbx_counter);
  2143. dbx_count_ok := true;
  2144. end;
  2145. end;
  2146. is_stab_written:=true;
  2147. end;
  2148. {$endif}
  2149. {****************************************************************************
  2150. Definitions
  2151. ****************************************************************************}
  2152. {$I symdef.inc}
  2153. {****************************************************************************
  2154. Symbols
  2155. ****************************************************************************}
  2156. {$I symsym.inc}
  2157. {****************************************************************************
  2158. GDB Helpers
  2159. ****************************************************************************}
  2160. {$ifdef GDB}
  2161. function typeglobalnumber(const s : string) : string;
  2162. var st : string;
  2163. symt : psymtable;
  2164. old_make_ref : boolean;
  2165. begin
  2166. old_make_ref:=make_ref;
  2167. make_ref:=false;
  2168. typeglobalnumber := '0';
  2169. srsym := nil;
  2170. if pos('.',s) > 0 then
  2171. begin
  2172. st := copy(s,1,pos('.',s)-1);
  2173. getsym(st,false);
  2174. st := copy(s,pos('.',s)+1,255);
  2175. if assigned(srsym) then
  2176. begin
  2177. if srsym^.typ = unitsym then
  2178. begin
  2179. symt := punitsym(srsym)^.unitsymtable;
  2180. srsym := symt^.search(st);
  2181. end else srsym := nil;
  2182. end;
  2183. end else st := s;
  2184. if srsym = nil then getsym(st,true);
  2185. if srsym^.typ<>typesym then
  2186. begin
  2187. Message(type_e_type_id_expected);
  2188. exit;
  2189. end;
  2190. typeglobalnumber := ptypesym(srsym)^.restype.def^.numberstring;
  2191. make_ref:=old_make_ref;
  2192. end;
  2193. {$endif GDB}
  2194. {****************************************************************************
  2195. Definition Helpers
  2196. ****************************************************************************}
  2197. procedure reset_global_defs;
  2198. var
  2199. def : pdef;
  2200. {$ifdef debug}
  2201. prevdef : pdef;
  2202. {$endif debug}
  2203. begin
  2204. {$ifdef debug}
  2205. prevdef:=nil;
  2206. {$endif debug}
  2207. {$ifdef GDB}
  2208. pglobaltypecount:=@globaltypecount;
  2209. {$endif GDB}
  2210. def:=firstglobaldef;
  2211. while assigned(def) do
  2212. begin
  2213. {$ifdef GDB}
  2214. if assigned(def^.typesym) then
  2215. def^.typesym^.isusedinstab:=false;
  2216. def^.is_def_stab_written:=false;
  2217. {$endif GDB}
  2218. {if not current_module^.in_implementation then}
  2219. begin
  2220. { reset rangenr's }
  2221. case def^.deftype of
  2222. orddef : porddef(def)^.rangenr:=0;
  2223. enumdef : penumdef(def)^.rangenr:=0;
  2224. arraydef : parraydef(def)^.rangenr:=0;
  2225. end;
  2226. if def^.deftype<>objectdef then
  2227. def^.has_rtti:=false;
  2228. def^.has_inittable:=false;
  2229. end;
  2230. {$ifdef debug}
  2231. prevdef:=def;
  2232. {$endif debug}
  2233. def:=def^.nextglobal;
  2234. end;
  2235. end;
  2236. {****************************************************************************
  2237. Object Helpers
  2238. ****************************************************************************}
  2239. function search_class_member(pd : pobjectdef;const n : string) : psym;
  2240. { searches n in symtable of pd and all anchestors }
  2241. var
  2242. sym : psym;
  2243. begin
  2244. sym:=nil;
  2245. while assigned(pd) do
  2246. begin
  2247. sym:=pd^.symtable^.search(n);
  2248. if assigned(sym) then
  2249. break;
  2250. pd:=pd^.childof;
  2251. end;
  2252. { this is needed for static methods in do_member_read pexpr unit PM
  2253. caused bug0214 }
  2254. if assigned(sym) then
  2255. begin
  2256. srsymtable:=pd^.symtable;
  2257. end;
  2258. search_class_member:=sym;
  2259. end;
  2260. var
  2261. _defaultprop : ppropertysym;
  2262. procedure testfordefaultproperty(p : pnamedindexobject);
  2263. begin
  2264. if (psym(p)^.typ=propertysym) and
  2265. (ppo_defaultproperty in ppropertysym(p)^.propoptions) then
  2266. _defaultprop:=ppropertysym(p);
  2267. end;
  2268. function search_default_property(pd : pobjectdef) : ppropertysym;
  2269. { returns the default property of a class, searches also anchestors }
  2270. begin
  2271. _defaultprop:=nil;
  2272. while assigned(pd) do
  2273. begin
  2274. pd^.symtable^.foreach({$ifndef TP}@{$endif}testfordefaultproperty);
  2275. if assigned(_defaultprop) then
  2276. break;
  2277. pd:=pd^.childof;
  2278. end;
  2279. search_default_property:=_defaultprop;
  2280. end;
  2281. {****************************************************************************
  2282. Macro's
  2283. ****************************************************************************}
  2284. procedure def_macro(const s : string);
  2285. var
  2286. mac : pmacrosym;
  2287. begin
  2288. mac:=pmacrosym(macros^.search(s));
  2289. if mac=nil then
  2290. begin
  2291. mac:=new(pmacrosym,init(s));
  2292. Message1(parser_m_macro_defined,mac^.name);
  2293. macros^.insert(mac);
  2294. end;
  2295. mac^.defined:=true;
  2296. mac^.defined_at_startup:=true;
  2297. end;
  2298. procedure set_macro(const s : string;value : string);
  2299. var
  2300. mac : pmacrosym;
  2301. begin
  2302. mac:=pmacrosym(macros^.search(s));
  2303. if mac=nil then
  2304. begin
  2305. mac:=new(pmacrosym,init(s));
  2306. macros^.insert(mac);
  2307. end
  2308. else
  2309. begin
  2310. if assigned(mac^.buftext) then
  2311. freemem(mac^.buftext,mac^.buflen);
  2312. end;
  2313. Message2(parser_m_macro_set_to,mac^.name,value);
  2314. mac^.buflen:=length(value);
  2315. getmem(mac^.buftext,mac^.buflen);
  2316. move(value[1],mac^.buftext^,mac^.buflen);
  2317. mac^.defined:=true;
  2318. mac^.defined_at_startup:=true;
  2319. end;
  2320. {$ifdef UNITALIASES}
  2321. {****************************************************************************
  2322. TUNIT_ALIAS
  2323. ****************************************************************************}
  2324. constructor tunit_alias.init(const n:string);
  2325. var
  2326. i : longint;
  2327. begin
  2328. i:=pos('=',n);
  2329. if i=0 then
  2330. fail;
  2331. inherited initname(Copy(n,1,i-1));
  2332. newname:=stringdup(Copy(n,i+1,255));
  2333. end;
  2334. destructor tunit_alias.done;
  2335. begin
  2336. stringdispose(newname);
  2337. inherited done;
  2338. end;
  2339. procedure addunitalias(const n:string);
  2340. begin
  2341. unitaliases^.insert(new(punit_alias,init(Upper(n))));
  2342. end;
  2343. function getunitalias(const n:string):string;
  2344. var
  2345. p : punit_alias;
  2346. begin
  2347. p:=punit_alias(unitaliases^.search(Upper(n)));
  2348. if assigned(p) then
  2349. getunitalias:=punit_alias(p)^.newname^
  2350. else
  2351. getunitalias:=n;
  2352. end;
  2353. {$endif UNITALIASES}
  2354. {****************************************************************************
  2355. Symtable Stack
  2356. ****************************************************************************}
  2357. procedure dellexlevel;
  2358. var
  2359. p : psymtable;
  2360. begin
  2361. p:=symtablestack;
  2362. symtablestack:=p^.next;
  2363. { symbol tables of unit interfaces are never disposed }
  2364. { this is handle by the unit unitm }
  2365. if not(p^.symtabletype in [unitsymtable,globalsymtable,stt_exceptsymtable]) or dispose_global then
  2366. dispose(p,done);
  2367. end;
  2368. {$ifdef DEBUG}
  2369. procedure test_symtablestack;
  2370. var
  2371. p : psymtable;
  2372. i : longint;
  2373. begin
  2374. p:=symtablestack;
  2375. i:=0;
  2376. while assigned(p) do
  2377. begin
  2378. inc(i);
  2379. p:=p^.next;
  2380. if i>500 then
  2381. Message(sym_f_internal_error_in_symtablestack);
  2382. end;
  2383. end;
  2384. procedure list_symtablestack;
  2385. var
  2386. p : psymtable;
  2387. i : longint;
  2388. begin
  2389. p:=symtablestack;
  2390. i:=0;
  2391. while assigned(p) do
  2392. begin
  2393. inc(i);
  2394. writeln(i,' ',p^.name^);
  2395. p:=p^.next;
  2396. if i>500 then
  2397. Message(sym_f_internal_error_in_symtablestack);
  2398. end;
  2399. end;
  2400. {$endif DEBUG}
  2401. {****************************************************************************
  2402. Init/Done Symtable
  2403. ****************************************************************************}
  2404. {$ifndef Delphi}
  2405. {$ifdef tp}
  2406. procedure do_streamerror;
  2407. begin
  2408. if symbolstream.status=-2 then
  2409. WriteLn('Error: Not enough EMS memory')
  2410. else
  2411. WriteLn('Error: EMS Error ',symbolstream.status);
  2412. halt(1);
  2413. end;
  2414. {$endif TP}
  2415. {$endif Delphi}
  2416. procedure InitSymtable;
  2417. begin
  2418. {$ifndef Delphi}
  2419. {$ifdef TP}
  2420. { Allocate stream }
  2421. if use_big then
  2422. begin
  2423. streamerror:=@do_streamerror;
  2424. { symbolstream.init('TMPFILE',stcreate,16000); }
  2425. {$ifndef dpmi}
  2426. symbolstream.init(10000,4000000); {using ems streams}
  2427. {$else}
  2428. symbolstream.init(1000000,16000); {using memory streams}
  2429. {$endif}
  2430. if symbolstream.errorinfo=stiniterror then
  2431. do_streamerror;
  2432. { write something, because pos 0 means nil pointer }
  2433. symbolstream.writestr(@inputfile);
  2434. end;
  2435. {$endif tp}
  2436. {$endif Delphi}
  2437. { Reset symbolstack }
  2438. registerdef:=false;
  2439. read_member:=false;
  2440. symtablestack:=nil;
  2441. systemunit:=nil;
  2442. {$ifdef GDB}
  2443. firstglobaldef:=nil;
  2444. lastglobaldef:=nil;
  2445. {$endif GDB}
  2446. globaltypecount:=1;
  2447. pglobaltypecount:=@globaltypecount;
  2448. { create error syms and def }
  2449. generrorsym:=new(perrorsym,init);
  2450. generrordef:=new(perrordef,init);
  2451. {$ifdef UNITALIASES}
  2452. { unit aliases }
  2453. unitaliases:=new(pdictionary,init);
  2454. {$endif}
  2455. for token:=first_overloaded to last_overloaded do
  2456. overloaded_operators[token]:=nil;
  2457. end;
  2458. procedure DoneSymtable;
  2459. begin
  2460. dispose(generrorsym,done);
  2461. dispose(generrordef,done);
  2462. {$ifdef UNITALIASES}
  2463. dispose(unitaliases,done);
  2464. {$endif}
  2465. {$ifndef Delphi}
  2466. {$ifdef TP}
  2467. { close the stream }
  2468. if use_big then
  2469. symbolstream.done;
  2470. {$endif}
  2471. {$endif Delphi}
  2472. end;
  2473. end.
  2474. {
  2475. $Log$
  2476. Revision 1.78 2000-02-20 20:49:45 florian
  2477. * newcg is compiling
  2478. * fixed the dup id problem reported by Paul Y.
  2479. Revision 1.77 2000/02/11 13:53:49 pierre
  2480. * avoid stack overflow in tref.done (bug 846)
  2481. Revision 1.76 2000/02/09 13:23:05 peter
  2482. * log truncated
  2483. Revision 1.75 2000/01/12 10:38:18 peter
  2484. * smartlinking fixes for binary writer
  2485. * release alignreg code and moved instruction writing align to cpuasm,
  2486. but it doesn't use the specified register yet
  2487. Revision 1.74 2000/01/09 00:37:56 pierre
  2488. * avoid testing object types that are simple aliases for unused privates
  2489. Revision 1.73 2000/01/07 01:14:41 peter
  2490. * updated copyright to 2000
  2491. Revision 1.72 2000/01/03 19:26:04 peter
  2492. * fixed resolving of ttypesym which are reference from object/record
  2493. fields.
  2494. Revision 1.71 1999/12/18 14:55:21 florian
  2495. * very basic widestring support
  2496. Revision 1.70 1999/12/02 11:28:27 peter
  2497. * moved verbose to implementation uses
  2498. Revision 1.69 1999/12/01 22:32:35 pierre
  2499. * give info of original duplicated symbol more often
  2500. Revision 1.68 1999/11/30 10:40:56 peter
  2501. + ttype, tsymlist
  2502. Revision 1.67 1999/11/24 11:41:05 pierre
  2503. * defaultsymtablestack is now restored after parser.compile
  2504. Revision 1.66 1999/11/22 00:23:09 pierre
  2505. * also complain about unused functions in program
  2506. Revision 1.65 1999/11/19 14:49:15 pierre
  2507. * avoid certain wrong notes/hints
  2508. Revision 1.64 1999/11/18 15:34:48 pierre
  2509. * Notes/Hints for local syms changed to
  2510. Set_varstate function
  2511. Revision 1.63 1999/11/17 17:05:06 pierre
  2512. * Notes/hints changes
  2513. Revision 1.62 1999/11/15 22:00:48 peter
  2514. * labels used but not defined give error instead of warning, the warning
  2515. is now only with declared but not defined and not used.
  2516. Revision 1.61 1999/11/15 17:52:59 pierre
  2517. + one field added for ttoken record for operator
  2518. linking the id to the corresponding operator token that
  2519. can now now all be overloaded
  2520. * overloaded operators are resetted to nil in InitSymtable
  2521. (bug when trying to compile a uint that overloads operators twice)
  2522. Revision 1.60 1999/11/09 23:35:50 pierre
  2523. + better reference pos for forward defs
  2524. Revision 1.59 1999/11/06 16:21:57 jonas
  2525. + search optimial register to use in alignment code (compile with
  2526. -dalignreg, -dalignregdebug to see chosen register in
  2527. assembler code). Still needs support in ag386bin.
  2528. Revision 1.58 1999/11/06 14:34:28 peter
  2529. * truncated log to 20 revs
  2530. Revision 1.57 1999/11/05 17:18:03 pierre
  2531. * local browsing works at first level
  2532. ie for function defined in interface or implementation
  2533. not yet for functions inside other functions
  2534. Revision 1.56 1999/11/04 23:13:25 peter
  2535. * moved unit alias support into ifdef
  2536. }