symtable.pas 95 KB

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