symtable.pas 101 KB

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