symtable.pas 89 KB

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