symtable.pas 89 KB

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