symtable.pas 89 KB

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