symtable.pas 89 KB

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