symtable.pas 88 KB

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