symtable.pas 89 KB

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