symtable.pas 89 KB

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