symtable.pas 89 KB

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