symtable.pas 88 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896
  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. if assigned(hsym) and
  1612. { delphi allows to reuse the names of properties }
  1613. { in parameter lists of methods }
  1614. not(
  1615. (hsym^.typ<>propertysym) or
  1616. (m_delphi in aktmodeswitches)
  1617. ) and
  1618. { also private ids can be reused }
  1619. (not(sp_private in hsym^.symoptions) or
  1620. (hsym^.owner^.defowner^.owner^.symtabletype<>unitsymtable)) then
  1621. DuplicateSym(hsym);
  1622. end;
  1623. { check for duplicate field id in inherited classes }
  1624. if (sym^.typ=varsym) and
  1625. (symtabletype=objectsymtable) and
  1626. assigned(defowner) then
  1627. begin
  1628. hsym:=search_class_member(pobjectdef(defowner),sym^.name);
  1629. { but private ids can be reused }
  1630. if assigned(hsym) and
  1631. (not(sp_private in hsym^.symoptions) or
  1632. (hsym^.owner^.defowner^.owner^.symtabletype<>unitsymtable)) then
  1633. DuplicateSym(hsym);
  1634. end;
  1635. { register definition of typesym }
  1636. if (sym^.typ = typesym) and
  1637. assigned(ptypesym(sym)^.restype.def) then
  1638. begin
  1639. if not(assigned(ptypesym(sym)^.restype.def^.owner)) and
  1640. (ptypesym(sym)^.restype.def^.deftype<>errordef) then
  1641. registerdef(ptypesym(sym)^.restype.def);
  1642. {$ifdef GDB}
  1643. if (cs_debuginfo in aktmoduleswitches) and assigned(debuglist) and
  1644. (symtabletype in [globalsymtable,staticsymtable]) then
  1645. begin
  1646. ptypesym(sym)^.isusedinstab := true;
  1647. sym^.concatstabto(debuglist);
  1648. end;
  1649. {$endif GDB}
  1650. end;
  1651. { insert in index and search hash }
  1652. symindex^.insert(sym);
  1653. symsearch^.insert(sym);
  1654. insert:=sym;
  1655. end;
  1656. function tsymtable.search(const s : stringid) : psym;
  1657. begin
  1658. {search:=psym(symsearch^.search(s));
  1659. this bypasses the ref generation (PM) }
  1660. search:=speedsearch(s,getspeedvalue(s));
  1661. end;
  1662. function tsymtable.speedsearch(const s : stringid;speedvalue : longint) : psym;
  1663. var
  1664. hp : psym;
  1665. newref : pref;
  1666. begin
  1667. hp:=psym(symsearch^.speedsearch(s,speedvalue));
  1668. if assigned(hp) then
  1669. begin
  1670. { reject non static members in static procedures,
  1671. be carefull aktprocsym^.definition is not allways
  1672. loaded already (PFV) }
  1673. if (symtabletype=objectsymtable) and
  1674. not(sp_static in hp^.symoptions) and
  1675. allow_only_static
  1676. {assigned(aktprocsym) and
  1677. assigned(aktprocsym^.definition) and
  1678. ((aktprocsym^.definition^.options and postaticmethod)<>0)} then
  1679. Message(sym_e_only_static_in_static);
  1680. if (symtabletype=unitsymtable) and
  1681. assigned(punitsymtable(@self)^.unitsym) then
  1682. inc(punitsymtable(@self)^.unitsym^.refs);
  1683. { unitsym are only loaded for browsing PM }
  1684. { this was buggy anyway because we could use }
  1685. { unitsyms from other units in _USES !! }
  1686. {if (symtabletype=unitsymtable) and (hp^.typ=unitsym) and
  1687. assigned(current_module) and (current_module^.globalsymtable<>@self) then
  1688. hp:=nil;}
  1689. if assigned(hp) and
  1690. (cs_browser in aktmoduleswitches) and make_ref then
  1691. begin
  1692. new(newref,init(hp^.lastref,@tokenpos));
  1693. { for symbols that are in tables without
  1694. browser info or syssyms (PM) }
  1695. if hp^.refcount=0 then
  1696. begin
  1697. hp^.defref:=newref;
  1698. hp^.lastref:=newref;
  1699. end
  1700. else
  1701. if resolving_forward and assigned(hp^.defref) then
  1702. { put it as second reference }
  1703. begin
  1704. newref^.nextref:=hp^.defref^.nextref;
  1705. hp^.defref^.nextref:=newref;
  1706. hp^.lastref^.nextref:=nil;
  1707. end
  1708. else
  1709. hp^.lastref:=newref;
  1710. inc(hp^.refcount);
  1711. end;
  1712. if assigned(hp) and make_ref then
  1713. begin
  1714. inc(hp^.refs);
  1715. end;
  1716. end;
  1717. speedsearch:=hp;
  1718. end;
  1719. function tsymtable.rename(const olds,news : stringid):psym;
  1720. begin
  1721. rename:=psym(symsearch^.rename(olds,news));
  1722. end;
  1723. {***********************************************
  1724. Browser
  1725. ***********************************************}
  1726. procedure tsymtable.load_browser;
  1727. var
  1728. b : byte;
  1729. sym : psym;
  1730. prdef : pdef;
  1731. oldrecsyms : psymtable;
  1732. begin
  1733. if symtabletype in [recordsymtable,objectsymtable] then
  1734. begin
  1735. oldrecsyms:=aktrecordsymtable;
  1736. aktrecordsymtable:=@self;
  1737. end;
  1738. if symtabletype in [parasymtable,localsymtable] then
  1739. begin
  1740. oldrecsyms:=aktlocalsymtable;
  1741. aktlocalsymtable:=@self;
  1742. end;
  1743. if symtabletype=staticppusymtable then
  1744. aktstaticsymtable:=@self;
  1745. b:=current_ppu^.readentry;
  1746. if b <> ibbeginsymtablebrowser then
  1747. Message1(unit_f_ppu_invalid_entry,tostr(b));
  1748. repeat
  1749. b:=current_ppu^.readentry;
  1750. case b of
  1751. ibsymref : begin
  1752. sym:=readsymref;
  1753. resolvesym(sym);
  1754. if assigned(sym) then
  1755. sym^.load_references;
  1756. end;
  1757. ibdefref : begin
  1758. prdef:=readdefref;
  1759. resolvedef(prdef);
  1760. if assigned(prdef) then
  1761. begin
  1762. if prdef^.deftype<>procdef then
  1763. Message(unit_f_ppu_read_error);
  1764. pprocdef(prdef)^.load_references;
  1765. end;
  1766. end;
  1767. ibendsymtablebrowser : break;
  1768. else
  1769. Message1(unit_f_ppu_invalid_entry,tostr(b));
  1770. end;
  1771. until false;
  1772. if symtabletype in [recordsymtable,objectsymtable] then
  1773. aktrecordsymtable:=oldrecsyms;
  1774. if symtabletype in [parasymtable,localsymtable] then
  1775. aktlocalsymtable:=oldrecsyms;
  1776. end;
  1777. procedure tsymtable.write_browser;
  1778. var
  1779. oldrecsyms : psymtable;
  1780. begin
  1781. { symbol numbering for references
  1782. should have been done in write PM
  1783. number_symbols;
  1784. number_defs; }
  1785. if symtabletype in [recordsymtable,objectsymtable] then
  1786. begin
  1787. oldrecsyms:=aktrecordsymtable;
  1788. aktrecordsymtable:=@self;
  1789. end;
  1790. if symtabletype in [parasymtable,localsymtable] then
  1791. begin
  1792. oldrecsyms:=aktlocalsymtable;
  1793. aktlocalsymtable:=@self;
  1794. end;
  1795. current_ppu^.writeentry(ibbeginsymtablebrowser);
  1796. foreach({$ifndef TP}@{$endif}write_refs);
  1797. current_ppu^.writeentry(ibendsymtablebrowser);
  1798. if symtabletype in [recordsymtable,objectsymtable] then
  1799. aktrecordsymtable:=oldrecsyms;
  1800. if symtabletype in [parasymtable,localsymtable] then
  1801. aktlocalsymtable:=oldrecsyms;
  1802. end;
  1803. {$ifdef BrowserLog}
  1804. procedure tsymtable.writebrowserlog;
  1805. begin
  1806. if cs_browser in aktmoduleswitches then
  1807. begin
  1808. if assigned(name) then
  1809. Browserlog.AddLog('---Symtable '+name^)
  1810. else
  1811. begin
  1812. if (symtabletype=recordsymtable) and
  1813. assigned(defowner^.typesym) then
  1814. Browserlog.AddLog('---Symtable '+defowner^.typesym^.name)
  1815. else
  1816. Browserlog.AddLog('---Symtable with no name');
  1817. end;
  1818. Browserlog.Ident;
  1819. foreach({$ifndef TP}@{$endif}add_to_browserlog);
  1820. browserlog.Unident;
  1821. end;
  1822. end;
  1823. {$endif BrowserLog}
  1824. {***********************************************
  1825. Process all entries
  1826. ***********************************************}
  1827. { checks, if all procsyms and methods are defined }
  1828. procedure tsymtable.check_forwards;
  1829. begin
  1830. foreach({$ifndef TP}@{$endif}check_forward);
  1831. end;
  1832. procedure tsymtable.checklabels;
  1833. begin
  1834. foreach({$ifndef TP}@{$endif}labeldefined);
  1835. end;
  1836. procedure tsymtable.set_alignment(_alignment : byte);
  1837. var
  1838. sym : pvarsym;
  1839. l : longint;
  1840. begin
  1841. { this can not be done if there is an
  1842. hasharray ! }
  1843. alignment:=_alignment;
  1844. if (symtabletype<>parasymtable) then
  1845. internalerror(1111);
  1846. sym:=pvarsym(symindex^.first);
  1847. datasize:=0;
  1848. { there can be only varsyms }
  1849. while assigned(sym) do
  1850. begin
  1851. l:=sym^.getpushsize;
  1852. sym^.address:=datasize;
  1853. datasize:=align(datasize+l,alignment);
  1854. sym:=pvarsym(sym^.next);
  1855. end;
  1856. end;
  1857. function tsymtable.find_at_offset(l : longint) : pvarsym;
  1858. var
  1859. sym : pvarsym;
  1860. begin
  1861. find_at_offset:=nil;
  1862. { this can not be done if there is an
  1863. hasharray ! }
  1864. if (symtabletype<>parasymtable) then
  1865. internalerror(1111);
  1866. sym:=pvarsym(symindex^.first);
  1867. while assigned(sym) do
  1868. begin
  1869. if sym^.address+address_fixup=l then
  1870. begin
  1871. find_at_offset:=sym;
  1872. exit;
  1873. end;
  1874. sym:=pvarsym(sym^.next);
  1875. end;
  1876. end;
  1877. procedure tsymtable.allunitsused;
  1878. begin
  1879. foreach({$ifndef TP}@{$endif}unitsymbolused);
  1880. end;
  1881. procedure tsymtable.allsymbolsused;
  1882. begin
  1883. foreach({$ifndef TP}@{$endif}varsymbolused);
  1884. end;
  1885. procedure tsymtable.allprivatesused;
  1886. begin
  1887. foreach({$ifndef TP}@{$endif}objectprivatesymbolused);
  1888. end;
  1889. {$ifdef CHAINPROCSYMS}
  1890. procedure tsymtable.chainprocsyms;
  1891. begin
  1892. foreach({$ifndef TP}@{$endif}chainprocsym);
  1893. end;
  1894. {$endif CHAINPROCSYMS}
  1895. {$ifdef GDB}
  1896. procedure tsymtable.concatstabto(asmlist : paasmoutput);
  1897. begin
  1898. asmoutput:=asmlist;
  1899. if symtabletype in [inlineparasymtable,inlinelocalsymtable] then
  1900. foreach({$ifndef TP}@{$endif}resetstab);
  1901. foreach({$ifndef TP}@{$endif}concatstab);
  1902. end;
  1903. {$endif}
  1904. {****************************************************************************
  1905. TUNITSYMTABLE
  1906. ****************************************************************************}
  1907. constructor tunitsymtable.init(t : tsymtabletype; const n : string);
  1908. begin
  1909. inherited init(t);
  1910. name:=stringdup(upper(n));
  1911. unitid:=0;
  1912. unitsym:=nil;
  1913. symsearch^.usehash;
  1914. { reset GDB things }
  1915. {$ifdef GDB}
  1916. if (t = globalsymtable) then
  1917. begin
  1918. prev_dbx_counter := dbx_counter;
  1919. dbx_counter := nil;
  1920. end;
  1921. is_stab_written:=false;
  1922. dbx_count := -1;
  1923. if cs_gdb_dbx in aktglobalswitches then
  1924. begin
  1925. dbx_count := 0;
  1926. unittypecount:=1;
  1927. if (symtabletype=globalsymtable) then
  1928. pglobaltypecount := @unittypecount;
  1929. unitid:=current_module^.unitcount;
  1930. debuglist^.concat(new(pai_asm_comment,init(strpnew('Global '+name^+' has index '+tostr(unitid)))));
  1931. debuglist^.concat(new(pai_stabs,init(strpnew('"'+name^+'",'+tostr(N_BINCL)+',0,0,0'))));
  1932. inc(current_module^.unitcount);
  1933. dbx_count_ok:=false;
  1934. dbx_counter:=@dbx_count;
  1935. do_count_dbx:=true;
  1936. end;
  1937. {$endif GDB}
  1938. end;
  1939. constructor tunitsymtable.loadasunit;
  1940. var
  1941. storeGlobalTypeCount : pword;
  1942. b : byte;
  1943. begin
  1944. unitsym:=nil;
  1945. unitid:=0;
  1946. {$ifdef GDB}
  1947. if cs_gdb_dbx in aktglobalswitches then
  1948. begin
  1949. UnitTypeCount:=1;
  1950. storeGlobalTypeCount:=PGlobalTypeCount;
  1951. PglobalTypeCount:=@UnitTypeCount;
  1952. end;
  1953. {$endif GDB}
  1954. { load symtables }
  1955. inherited loadas(unitsymtable);
  1956. { set the name after because it is set to nil in tsymtable.load !! }
  1957. name:=stringdup(current_module^.modulename^);
  1958. { dbx count }
  1959. {$ifdef GDB}
  1960. if (current_module^.flags and uf_has_dbx)<>0 then
  1961. begin
  1962. b := current_ppu^.readentry;
  1963. if b <> ibdbxcount then
  1964. Message(unit_f_ppu_dbx_count_problem)
  1965. else
  1966. dbx_count := readlong;
  1967. dbx_count_ok := true;
  1968. end
  1969. else
  1970. begin
  1971. dbx_count := -1;
  1972. dbx_count_ok:=false;
  1973. end;
  1974. if cs_gdb_dbx in aktglobalswitches then
  1975. PGlobalTypeCount:=storeGlobalTypeCount;
  1976. is_stab_written:=false;
  1977. {$endif GDB}
  1978. b:=current_ppu^.readentry;
  1979. if b<>ibendimplementation then
  1980. Message1(unit_f_ppu_invalid_entry,tostr(b));
  1981. end;
  1982. destructor tunitsymtable.done;
  1983. var
  1984. pus : punitsym;
  1985. begin
  1986. pus:=unitsym;
  1987. while assigned(pus) do
  1988. begin
  1989. unitsym:=pus^.prevsym;
  1990. pus^.prevsym:=nil;
  1991. pus^.unitsymtable:=nil;
  1992. pus:=unitsym;
  1993. end;
  1994. inherited done;
  1995. end;
  1996. procedure tunitsymtable.load_symtable_refs;
  1997. var
  1998. b : byte;
  1999. unitindex : word;
  2000. begin
  2001. if ((current_module^.flags and uf_local_browser)<>0) then
  2002. begin
  2003. current_module^.localsymtable:=new(punitsymtable,loadas(staticppusymtable));
  2004. psymtable(current_module^.localsymtable)^.name:=
  2005. stringdup('implementation of '+psymtable(current_module^.globalsymtable)^.name^);
  2006. end;
  2007. { load browser }
  2008. if (current_module^.flags and uf_has_browser)<>0 then
  2009. begin
  2010. {if not (cs_browser in aktmoduleswitches) then
  2011. current_ppu^.skipuntilentry(ibendbrowser)
  2012. else }
  2013. begin
  2014. load_browser;
  2015. unitindex:=1;
  2016. while assigned(current_module^.map^[unitindex]) do
  2017. begin
  2018. {each unit wrote one browser entry }
  2019. load_browser;
  2020. inc(unitindex);
  2021. end;
  2022. b:=current_ppu^.readentry;
  2023. if b<>ibendbrowser then
  2024. Message1(unit_f_ppu_invalid_entry,tostr(b));
  2025. end;
  2026. end;
  2027. if ((current_module^.flags and uf_local_browser)<>0) then
  2028. psymtable(current_module^.localsymtable)^.load_browser;
  2029. end;
  2030. procedure tunitsymtable.writeasunit;
  2031. var
  2032. pu : pused_unit;
  2033. begin
  2034. { first the unitname }
  2035. current_ppu^.putstring(name^);
  2036. current_ppu^.writeentry(ibmodulename);
  2037. writesourcefiles;
  2038. writeusedmacros;
  2039. writeusedunit;
  2040. { write the objectfiles and libraries that come for this unit,
  2041. preserve the containers becuase they are still needed to load
  2042. the link.res. All doesn't depend on the crc! It doesn't matter
  2043. if a unit is in a .o or .a file }
  2044. current_ppu^.do_crc:=false;
  2045. writelinkcontainer(current_module^.linkunitofiles,iblinkunitofiles,true);
  2046. writelinkcontainer(current_module^.linkunitstaticlibs,iblinkunitstaticlibs,true);
  2047. writelinkcontainer(current_module^.linkunitsharedlibs,iblinkunitsharedlibs,true);
  2048. writelinkcontainer(current_module^.linkotherofiles,iblinkotherofiles,false);
  2049. writelinkcontainer(current_module^.linkotherstaticlibs,iblinkotherstaticlibs,true);
  2050. writelinkcontainer(current_module^.linkothersharedlibs,iblinkothersharedlibs,true);
  2051. current_ppu^.do_crc:=true;
  2052. current_ppu^.writeentry(ibendinterface);
  2053. { write the symtable entries }
  2054. inherited writeas;
  2055. { all after doesn't affect crc }
  2056. current_ppu^.do_crc:=false;
  2057. { write dbx count }
  2058. {$ifdef GDB}
  2059. if cs_gdb_dbx in aktglobalswitches then
  2060. begin
  2061. {$IfDef EXTDEBUG}
  2062. writeln('Writing dbx_count ',dbx_count,' in unit ',name^,'.ppu');
  2063. {$ENDIF EXTDEBUG}
  2064. current_ppu^.putlongint(dbx_count);
  2065. current_ppu^.writeentry(ibdbxcount);
  2066. end;
  2067. {$endif GDB}
  2068. current_ppu^.writeentry(ibendimplementation);
  2069. { write static symtable
  2070. needed for local debugging of unit functions }
  2071. if ((current_module^.flags and uf_local_browser)<>0) and
  2072. assigned(current_module^.localsymtable) then
  2073. psymtable(current_module^.localsymtable)^.writeas;
  2074. { write all browser section }
  2075. if (current_module^.flags and uf_has_browser)<>0 then
  2076. begin
  2077. write_browser;
  2078. pu:=pused_unit(current_module^.used_units.first);
  2079. while assigned(pu) do
  2080. begin
  2081. psymtable(pu^.u^.globalsymtable)^.write_browser;
  2082. pu:=pused_unit(pu^.next);
  2083. end;
  2084. current_ppu^.writeentry(ibendbrowser);
  2085. end;
  2086. if ((current_module^.flags and uf_local_browser)<>0) and
  2087. assigned(current_module^.localsymtable) then
  2088. psymtable(current_module^.localsymtable)^.write_browser;
  2089. { the last entry ibend is written automaticly }
  2090. end;
  2091. function tunitsymtable.getnewtypecount : word;
  2092. begin
  2093. {$ifdef GDB}
  2094. if not (cs_gdb_dbx in aktglobalswitches) then
  2095. getnewtypecount:=tsymtable.getnewtypecount
  2096. else
  2097. {$endif GDB}
  2098. if symtabletype = staticsymtable then
  2099. getnewtypecount:=tsymtable.getnewtypecount
  2100. else
  2101. begin
  2102. getnewtypecount:=unittypecount;
  2103. inc(unittypecount);
  2104. end;
  2105. end;
  2106. {$ifdef GDB}
  2107. procedure tunitsymtable.concattypestabto(asmlist : paasmoutput);
  2108. var prev_dbx_count : plongint;
  2109. begin
  2110. if is_stab_written then exit;
  2111. if not assigned(name) then name := stringdup('Main_program');
  2112. if (symtabletype = unitsymtable) and
  2113. (current_module^.globalsymtable<>@Self) then
  2114. begin
  2115. unitid:=current_module^.unitcount;
  2116. inc(current_module^.unitcount);
  2117. end;
  2118. asmlist^.concat(new(pai_asm_comment,init(strpnew('Begin unit '+name^
  2119. +' has index '+tostr(unitid)))));
  2120. if cs_gdb_dbx in aktglobalswitches then
  2121. begin
  2122. if dbx_count_ok then
  2123. begin
  2124. asmlist^.concat(new(pai_asm_comment,init(strpnew('"repeated" unit '+name^
  2125. +' has index '+tostr(unitid)+' dbx count = '+tostr(dbx_count)))));
  2126. asmlist^.concat(new(pai_stabs,init(strpnew('"'+name^+'",'
  2127. +tostr(N_EXCL)+',0,0,'+tostr(dbx_count)))));
  2128. exit;
  2129. end
  2130. else if (current_module^.globalsymtable<>@Self) then
  2131. begin
  2132. prev_dbx_count := dbx_counter;
  2133. dbx_counter := nil;
  2134. do_count_dbx:=false;
  2135. if symtabletype = unitsymtable then
  2136. asmlist^.concat(new(pai_stabs,init(strpnew('"'+name^+'",'
  2137. +tostr(N_BINCL)+',0,0,0'))));
  2138. dbx_counter := @dbx_count;
  2139. dbx_count:=0;
  2140. do_count_dbx:=assigned(dbx_counter);
  2141. end;
  2142. end;
  2143. asmoutput:=asmlist;
  2144. foreach({$ifndef TP}@{$endif}concattypestab);
  2145. if cs_gdb_dbx in aktglobalswitches then
  2146. begin
  2147. if (current_module^.globalsymtable<>@Self) then
  2148. begin
  2149. dbx_counter := prev_dbx_count;
  2150. do_count_dbx:=false;
  2151. asmlist^.concat(new(pai_asm_comment,init(strpnew('End unit '+name^
  2152. +' has index '+tostr(unitid)))));
  2153. asmlist^.concat(new(pai_stabs,init(strpnew('"'+name^+'",'
  2154. +tostr(N_EINCL)+',0,0,0'))));
  2155. do_count_dbx:=assigned(dbx_counter);
  2156. dbx_count_ok := true;
  2157. end;
  2158. end;
  2159. is_stab_written:=true;
  2160. end;
  2161. {$endif}
  2162. {****************************************************************************
  2163. Definitions
  2164. ****************************************************************************}
  2165. {$I symdef.inc}
  2166. {****************************************************************************
  2167. Symbols
  2168. ****************************************************************************}
  2169. {$I symsym.inc}
  2170. {****************************************************************************
  2171. GDB Helpers
  2172. ****************************************************************************}
  2173. {$ifdef GDB}
  2174. function typeglobalnumber(const s : string) : string;
  2175. var st : string;
  2176. symt : psymtable;
  2177. old_make_ref : boolean;
  2178. begin
  2179. old_make_ref:=make_ref;
  2180. make_ref:=false;
  2181. typeglobalnumber := '0';
  2182. srsym := nil;
  2183. if pos('.',s) > 0 then
  2184. begin
  2185. st := copy(s,1,pos('.',s)-1);
  2186. getsym(st,false);
  2187. st := copy(s,pos('.',s)+1,255);
  2188. if assigned(srsym) then
  2189. begin
  2190. if srsym^.typ = unitsym then
  2191. begin
  2192. symt := punitsym(srsym)^.unitsymtable;
  2193. srsym := symt^.search(st);
  2194. end else srsym := nil;
  2195. end;
  2196. end else st := s;
  2197. if srsym = nil then getsym(st,true);
  2198. if srsym^.typ<>typesym then
  2199. begin
  2200. Message(type_e_type_id_expected);
  2201. exit;
  2202. end;
  2203. typeglobalnumber := ptypesym(srsym)^.restype.def^.numberstring;
  2204. make_ref:=old_make_ref;
  2205. end;
  2206. {$endif GDB}
  2207. {****************************************************************************
  2208. Definition Helpers
  2209. ****************************************************************************}
  2210. procedure reset_global_defs;
  2211. var
  2212. def : pdef;
  2213. {$ifdef debug}
  2214. prevdef : pdef;
  2215. {$endif debug}
  2216. begin
  2217. {$ifdef debug}
  2218. prevdef:=nil;
  2219. {$endif debug}
  2220. {$ifdef GDB}
  2221. pglobaltypecount:=@globaltypecount;
  2222. {$endif GDB}
  2223. def:=firstglobaldef;
  2224. while assigned(def) do
  2225. begin
  2226. {$ifdef GDB}
  2227. if assigned(def^.typesym) then
  2228. def^.typesym^.isusedinstab:=false;
  2229. def^.is_def_stab_written:=false;
  2230. {$endif GDB}
  2231. {if not current_module^.in_implementation then}
  2232. begin
  2233. { reset rangenr's }
  2234. case def^.deftype of
  2235. orddef : porddef(def)^.rangenr:=0;
  2236. enumdef : penumdef(def)^.rangenr:=0;
  2237. arraydef : parraydef(def)^.rangenr:=0;
  2238. end;
  2239. if def^.deftype<>objectdef then
  2240. def^.has_rtti:=false;
  2241. def^.has_inittable:=false;
  2242. end;
  2243. {$ifdef debug}
  2244. prevdef:=def;
  2245. {$endif debug}
  2246. def:=def^.nextglobal;
  2247. end;
  2248. end;
  2249. {****************************************************************************
  2250. Object Helpers
  2251. ****************************************************************************}
  2252. function search_class_member(pd : pobjectdef;const n : string) : psym;
  2253. { searches n in symtable of pd and all anchestors }
  2254. var
  2255. sym : psym;
  2256. begin
  2257. sym:=nil;
  2258. while assigned(pd) do
  2259. begin
  2260. sym:=pd^.symtable^.search(n);
  2261. if assigned(sym) then
  2262. break;
  2263. pd:=pd^.childof;
  2264. end;
  2265. { this is needed for static methods in do_member_read pexpr unit PM
  2266. caused bug0214 }
  2267. if assigned(sym) then
  2268. begin
  2269. srsymtable:=pd^.symtable;
  2270. end;
  2271. search_class_member:=sym;
  2272. end;
  2273. var
  2274. _defaultprop : ppropertysym;
  2275. procedure testfordefaultproperty(p : pnamedindexobject);
  2276. begin
  2277. if (psym(p)^.typ=propertysym) and
  2278. (ppo_defaultproperty in ppropertysym(p)^.propoptions) then
  2279. _defaultprop:=ppropertysym(p);
  2280. end;
  2281. function search_default_property(pd : pobjectdef) : ppropertysym;
  2282. { returns the default property of a class, searches also anchestors }
  2283. begin
  2284. _defaultprop:=nil;
  2285. while assigned(pd) do
  2286. begin
  2287. pd^.symtable^.foreach({$ifndef TP}@{$endif}testfordefaultproperty);
  2288. if assigned(_defaultprop) then
  2289. break;
  2290. pd:=pd^.childof;
  2291. end;
  2292. search_default_property:=_defaultprop;
  2293. end;
  2294. {****************************************************************************
  2295. Macro's
  2296. ****************************************************************************}
  2297. procedure def_macro(const s : string);
  2298. var
  2299. mac : pmacrosym;
  2300. begin
  2301. mac:=pmacrosym(macros^.search(s));
  2302. if mac=nil then
  2303. begin
  2304. mac:=new(pmacrosym,init(s));
  2305. Message1(parser_m_macro_defined,mac^.name);
  2306. macros^.insert(mac);
  2307. end;
  2308. mac^.defined:=true;
  2309. mac^.defined_at_startup:=true;
  2310. end;
  2311. procedure set_macro(const s : string;value : string);
  2312. var
  2313. mac : pmacrosym;
  2314. begin
  2315. mac:=pmacrosym(macros^.search(s));
  2316. if mac=nil then
  2317. begin
  2318. mac:=new(pmacrosym,init(s));
  2319. macros^.insert(mac);
  2320. end
  2321. else
  2322. begin
  2323. if assigned(mac^.buftext) then
  2324. freemem(mac^.buftext,mac^.buflen);
  2325. end;
  2326. Message2(parser_m_macro_set_to,mac^.name,value);
  2327. mac^.buflen:=length(value);
  2328. getmem(mac^.buftext,mac^.buflen);
  2329. move(value[1],mac^.buftext^,mac^.buflen);
  2330. mac^.defined:=true;
  2331. mac^.defined_at_startup:=true;
  2332. end;
  2333. {$ifdef UNITALIASES}
  2334. {****************************************************************************
  2335. TUNIT_ALIAS
  2336. ****************************************************************************}
  2337. constructor tunit_alias.init(const n:string);
  2338. var
  2339. i : longint;
  2340. begin
  2341. i:=pos('=',n);
  2342. if i=0 then
  2343. fail;
  2344. inherited initname(Copy(n,1,i-1));
  2345. newname:=stringdup(Copy(n,i+1,255));
  2346. end;
  2347. destructor tunit_alias.done;
  2348. begin
  2349. stringdispose(newname);
  2350. inherited done;
  2351. end;
  2352. procedure addunitalias(const n:string);
  2353. begin
  2354. unitaliases^.insert(new(punit_alias,init(Upper(n))));
  2355. end;
  2356. function getunitalias(const n:string):string;
  2357. var
  2358. p : punit_alias;
  2359. begin
  2360. p:=punit_alias(unitaliases^.search(Upper(n)));
  2361. if assigned(p) then
  2362. getunitalias:=punit_alias(p)^.newname^
  2363. else
  2364. getunitalias:=n;
  2365. end;
  2366. {$endif UNITALIASES}
  2367. {****************************************************************************
  2368. Symtable Stack
  2369. ****************************************************************************}
  2370. procedure dellexlevel;
  2371. var
  2372. p : psymtable;
  2373. begin
  2374. p:=symtablestack;
  2375. symtablestack:=p^.next;
  2376. { symbol tables of unit interfaces are never disposed }
  2377. { this is handle by the unit unitm }
  2378. if not(p^.symtabletype in [unitsymtable,globalsymtable,stt_exceptsymtable]) or dispose_global then
  2379. dispose(p,done);
  2380. end;
  2381. {$ifdef DEBUG}
  2382. procedure test_symtablestack;
  2383. var
  2384. p : psymtable;
  2385. i : longint;
  2386. begin
  2387. p:=symtablestack;
  2388. i:=0;
  2389. while assigned(p) do
  2390. begin
  2391. inc(i);
  2392. p:=p^.next;
  2393. if i>500 then
  2394. Message(sym_f_internal_error_in_symtablestack);
  2395. end;
  2396. end;
  2397. procedure list_symtablestack;
  2398. var
  2399. p : psymtable;
  2400. i : longint;
  2401. begin
  2402. p:=symtablestack;
  2403. i:=0;
  2404. while assigned(p) do
  2405. begin
  2406. inc(i);
  2407. writeln(i,' ',p^.name^);
  2408. p:=p^.next;
  2409. if i>500 then
  2410. Message(sym_f_internal_error_in_symtablestack);
  2411. end;
  2412. end;
  2413. {$endif DEBUG}
  2414. {****************************************************************************
  2415. Init/Done Symtable
  2416. ****************************************************************************}
  2417. {$ifndef Delphi}
  2418. {$ifdef tp}
  2419. procedure do_streamerror;
  2420. begin
  2421. if symbolstream.status=-2 then
  2422. WriteLn('Error: Not enough EMS memory')
  2423. else
  2424. WriteLn('Error: EMS Error ',symbolstream.status);
  2425. halt(1);
  2426. end;
  2427. {$endif TP}
  2428. {$endif Delphi}
  2429. procedure InitSymtable;
  2430. begin
  2431. {$ifndef Delphi}
  2432. {$ifdef TP}
  2433. { Allocate stream }
  2434. if use_big then
  2435. begin
  2436. streamerror:=@do_streamerror;
  2437. { symbolstream.init('TMPFILE',stcreate,16000); }
  2438. {$ifndef dpmi}
  2439. symbolstream.init(10000,4000000); {using ems streams}
  2440. {$else}
  2441. symbolstream.init(1000000,16000); {using memory streams}
  2442. {$endif}
  2443. if symbolstream.errorinfo=stiniterror then
  2444. do_streamerror;
  2445. { write something, because pos 0 means nil pointer }
  2446. symbolstream.writestr(@inputfile);
  2447. end;
  2448. {$endif tp}
  2449. {$endif Delphi}
  2450. { Reset symbolstack }
  2451. registerdef:=false;
  2452. read_member:=false;
  2453. symtablestack:=nil;
  2454. systemunit:=nil;
  2455. {$ifdef GDB}
  2456. firstglobaldef:=nil;
  2457. lastglobaldef:=nil;
  2458. {$endif GDB}
  2459. globaltypecount:=1;
  2460. pglobaltypecount:=@globaltypecount;
  2461. { create error syms and def }
  2462. generrorsym:=new(perrorsym,init);
  2463. generrordef:=new(perrordef,init);
  2464. {$ifdef UNITALIASES}
  2465. { unit aliases }
  2466. unitaliases:=new(pdictionary,init);
  2467. {$endif}
  2468. for token:=first_overloaded to last_overloaded do
  2469. overloaded_operators[token]:=nil;
  2470. end;
  2471. procedure DoneSymtable;
  2472. begin
  2473. dispose(generrorsym,done);
  2474. dispose(generrordef,done);
  2475. {$ifdef UNITALIASES}
  2476. dispose(unitaliases,done);
  2477. {$endif}
  2478. {$ifndef Delphi}
  2479. {$ifdef TP}
  2480. { close the stream }
  2481. if use_big then
  2482. symbolstream.done;
  2483. {$endif}
  2484. {$endif Delphi}
  2485. end;
  2486. end.
  2487. {
  2488. $Log$
  2489. Revision 1.81 2000-03-20 09:34:33 florian
  2490. * in delphi mode: method parameters can now have the same name as parameters
  2491. Revision 1.80 2000/03/01 13:56:31 pierre
  2492. * fix for bug 840
  2493. Revision 1.79 2000/03/01 00:03:10 pierre
  2494. * fixes for locals in inlined procedures
  2495. fix for bug797
  2496. + stabs generation for inlined paras and locals
  2497. Revision 1.78 2000/02/20 20:49:45 florian
  2498. * newcg is compiling
  2499. * fixed the dup id problem reported by Paul Y.
  2500. Revision 1.77 2000/02/11 13:53:49 pierre
  2501. * avoid stack overflow in tref.done (bug 846)
  2502. Revision 1.76 2000/02/09 13:23:05 peter
  2503. * log truncated
  2504. Revision 1.75 2000/01/12 10:38:18 peter
  2505. * smartlinking fixes for binary writer
  2506. * release alignreg code and moved instruction writing align to cpuasm,
  2507. but it doesn't use the specified register yet
  2508. Revision 1.74 2000/01/09 00:37:56 pierre
  2509. * avoid testing object types that are simple aliases for unused privates
  2510. Revision 1.73 2000/01/07 01:14:41 peter
  2511. * updated copyright to 2000
  2512. Revision 1.72 2000/01/03 19:26:04 peter
  2513. * fixed resolving of ttypesym which are reference from object/record
  2514. fields.
  2515. Revision 1.71 1999/12/18 14:55:21 florian
  2516. * very basic widestring support
  2517. Revision 1.70 1999/12/02 11:28:27 peter
  2518. * moved verbose to implementation uses
  2519. Revision 1.69 1999/12/01 22:32:35 pierre
  2520. * give info of original duplicated symbol more often
  2521. Revision 1.68 1999/11/30 10:40:56 peter
  2522. + ttype, tsymlist
  2523. Revision 1.67 1999/11/24 11:41:05 pierre
  2524. * defaultsymtablestack is now restored after parser.compile
  2525. Revision 1.66 1999/11/22 00:23:09 pierre
  2526. * also complain about unused functions in program
  2527. Revision 1.65 1999/11/19 14:49:15 pierre
  2528. * avoid certain wrong notes/hints
  2529. Revision 1.64 1999/11/18 15:34:48 pierre
  2530. * Notes/Hints for local syms changed to
  2531. Set_varstate function
  2532. Revision 1.63 1999/11/17 17:05:06 pierre
  2533. * Notes/hints changes
  2534. Revision 1.62 1999/11/15 22:00:48 peter
  2535. * labels used but not defined give error instead of warning, the warning
  2536. is now only with declared but not defined and not used.
  2537. Revision 1.61 1999/11/15 17:52:59 pierre
  2538. + one field added for ttoken record for operator
  2539. linking the id to the corresponding operator token that
  2540. can now now all be overloaded
  2541. * overloaded operators are resetted to nil in InitSymtable
  2542. (bug when trying to compile a uint that overloads operators twice)
  2543. Revision 1.60 1999/11/09 23:35:50 pierre
  2544. + better reference pos for forward defs
  2545. Revision 1.59 1999/11/06 16:21:57 jonas
  2546. + search optimial register to use in alignment code (compile with
  2547. -dalignreg, -dalignregdebug to see chosen register in
  2548. assembler code). Still needs support in ag386bin.
  2549. Revision 1.58 1999/11/06 14:34:28 peter
  2550. * truncated log to 20 revs
  2551. Revision 1.57 1999/11/05 17:18:03 pierre
  2552. * local browsing works at first level
  2553. ie for function defined in interface or implementation
  2554. not yet for functions inside other functions
  2555. Revision 1.56 1999/11/04 23:13:25 peter
  2556. * moved unit alias support into ifdef
  2557. }