symtable.pas 89 KB

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