symtable.pas 97 KB

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