symtable.pas 89 KB

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