symtable.pas 101 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189
  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. current_object_option : tsymoptions = [sp_public];
  209. var
  210. { for STAB debugging }
  211. globaltypecount : word;
  212. pglobaltypecount : pword;
  213. registerdef : boolean; { true, when defs should be registered }
  214. defaultsymtablestack, { symtablestack after default units
  215. have been loaded }
  216. symtablestack : psymtable; { linked list of symtables }
  217. srsym : psym; { result of the last search }
  218. srsymtable : psymtable;
  219. lastsrsym : psym; { last sym found in statement }
  220. lastsrsymtable : psymtable;
  221. lastsymknown : boolean;
  222. constsymtable : psymtable; { symtable were the constants can be
  223. inserted }
  224. voidpointerdef : ppointerdef; { pointer for Void-Pointerdef }
  225. charpointerdef : ppointerdef; { pointer for Char-Pointerdef }
  226. voidfarpointerdef : ppointerdef;
  227. cformaldef : pformaldef; { unique formal definition }
  228. voiddef : porddef; { Pointer to Void (procedure) }
  229. cchardef : porddef; { Pointer to Char }
  230. booldef : porddef; { pointer to boolean type }
  231. u8bitdef : porddef; { Pointer to 8-Bit unsigned }
  232. u16bitdef : porddef; { Pointer to 16-Bit unsigned }
  233. u32bitdef : porddef; { Pointer to 32-Bit unsigned }
  234. s32bitdef : porddef; { Pointer to 32-Bit signed }
  235. cu64bitdef : porddef; { pointer to 64 bit unsigned def }
  236. cs64bitdef : porddef; { pointer to 64 bit signed def, }
  237. { calculated by the int unit on i386 }
  238. s32floatdef : pfloatdef; { pointer for realconstn }
  239. s64floatdef : pfloatdef; { pointer for realconstn }
  240. s80floatdef : pfloatdef; { pointer to type of temp. floats }
  241. s32fixeddef : pfloatdef; { pointer to type of temp. fixed }
  242. cshortstringdef : pstringdef; { pointer to type of short string const }
  243. clongstringdef : pstringdef; { pointer to type of long string const }
  244. cansistringdef : pstringdef; { pointer to type of ansi string const }
  245. cwidestringdef : pstringdef; { pointer to type of wide string const }
  246. openshortstringdef : pstringdef; { pointer to type of an open shortstring,
  247. needed for readln() }
  248. openchararraydef : parraydef; { pointer to type of an open array of char,
  249. needed for readln() }
  250. cfiledef : pfiledef; { get the same definition for all file }
  251. { uses for stabs }
  252. firstglobaldef, { linked list of all globals defs }
  253. lastglobaldef : pdef; { used to reset stabs/ranges }
  254. class_tobject : pobjectdef; { pointer to the anchestor of all }
  255. { clases }
  256. pvmtdef : ppointerdef; { type of classrefs }
  257. aktprocsym : pprocsym; { pointer to the symbol for the
  258. currently be parsed procedure }
  259. aktcallprocsym : pprocsym; { pointer to the symbol for the
  260. currently be called procedure,
  261. only set/unset in firstcall }
  262. aktvarsym : pvarsym; { pointer to the symbol for the
  263. currently read var, only used
  264. for variable directives }
  265. procprefix : string; { eindeutige Namen bei geschachtel- }
  266. { ten Unterprogrammen erzeugen }
  267. lexlevel : longint; { level of code }
  268. { 1 for main procedure }
  269. { 2 for normal function or proc }
  270. { higher for locals }
  271. const
  272. main_program_level = 1;
  273. unit_init_level = 1;
  274. normal_function_level = 2;
  275. in_loading : boolean = false;
  276. {$ifdef i386}
  277. bestrealdef : ^pfloatdef = @s80floatdef;
  278. {$endif}
  279. {$ifdef m68k}
  280. bestrealdef : ^pfloatdef = @s64floatdef;
  281. {$endif}
  282. {$ifdef alpha}
  283. bestrealdef : ^pfloatdef = @s64floatdef;
  284. {$endif}
  285. {$ifdef powerpc}
  286. bestrealdef : ^pfloatdef = @s64floatdef;
  287. {$endif}
  288. var
  289. macros : psymtable; { pointer for die Symboltabelle mit }
  290. { Makros }
  291. read_member : boolean; { true, wenn Members aus einer PPU- }
  292. { Datei gelesen werden, d.h. ein }
  293. { varsym seine Adresse einlesen soll }
  294. generrorsym : psym; { Jokersymbol, wenn das richtige }
  295. { Symbol nicht gefunden wird }
  296. generrordef : pdef; { Jokersymbol for eine fehlerhafte }
  297. { Typdefinition }
  298. aktobjectdef : pobjectdef; { used for private functions check !! }
  299. const
  300. { last operator which can be overloaded }
  301. first_overloaded = _PLUS;
  302. last_overloaded = _ASSIGNMENT;
  303. var
  304. overloaded_operators : array[first_overloaded..last_overloaded] of pprocsym;
  305. { unequal is not equal}
  306. const
  307. overloaded_names : array [first_overloaded..last_overloaded] of string[16] =
  308. ('plus','minus','star','slash','equal',
  309. 'greater','lower','greater_or_equal',
  310. 'lower_or_equal','as','is','in','sym_diff',
  311. 'starstar','assign');
  312. {****************************************************************************
  313. Functions
  314. ****************************************************************************}
  315. {*** Misc ***}
  316. function globaldef(const s : string) : pdef;
  317. function findunitsymtable(st:psymtable):psymtable;
  318. procedure duplicatesym(sym:psym);
  319. {*** Search ***}
  320. function search_a_symtable(const symbol:string;symtabletype:tsymtabletype):Psym;
  321. procedure getsym(const s : stringid;notfounderror : boolean);
  322. procedure getsymonlyin(p : psymtable;const s : stringid);
  323. {*** PPU Write/Loading ***}
  324. procedure writeunitas(const s : string;unittable : punitsymtable;only_crc : boolean);
  325. procedure closecurrentppu;
  326. procedure numberunits;
  327. procedure load_interface;
  328. {*** GDB ***}
  329. {$ifdef GDB}
  330. function typeglobalnumber(const s : string) : string;
  331. {$endif}
  332. {*** Definition ***}
  333. procedure reset_global_defs;
  334. {*** Object Helpers ***}
  335. function search_class_member(pd : pobjectdef;const n : string) : psym;
  336. function search_default_property(pd : pobjectdef) : ppropertysym;
  337. {*** Macro ***}
  338. procedure def_macro(const s : string);
  339. procedure set_macro(const s : string;value : string);
  340. {*** symtable stack ***}
  341. procedure dellexlevel;
  342. {$ifdef DEBUG}
  343. procedure test_symtablestack;
  344. procedure list_symtablestack;
  345. {$endif DEBUG}
  346. {*** dispose of a pdefcoll (args of a function) ***}
  347. procedure disposepdefcoll(var para1 : pdefcoll);
  348. {*** Init / Done ***}
  349. procedure InitSymtable;
  350. procedure DoneSymtable;
  351. implementation
  352. uses
  353. version,
  354. types,ppu,
  355. gendef,files
  356. ,tree
  357. ,cresstr
  358. {$ifdef newcg}
  359. ,cgbase
  360. {$else}
  361. ,hcodegen
  362. {$endif}
  363. {$ifdef BrowserLog}
  364. ,browlog
  365. {$endif BrowserLog}
  366. ;
  367. var
  368. aktrecordsymtable : psymtable; { current record read from ppu symtable }
  369. aktstaticsymtable : psymtable; { current static for local ppu symtable }
  370. {$ifdef GDB}
  371. asmoutput : paasmoutput;
  372. {$endif GDB}
  373. {$ifdef TP}
  374. {$ifndef Delphi}
  375. {$ifndef dpmi}
  376. symbolstream : temsstream; { stream which is used to store some info }
  377. {$else}
  378. symbolstream : tmemorystream;
  379. {$endif}
  380. {$endif Delphi}
  381. {$endif}
  382. {to dispose the global symtable of a unit }
  383. const
  384. dispose_global : boolean = false;
  385. memsizeinc = 2048; { for long stabstrings }
  386. tagtypes : Set of tdeftype =
  387. [recorddef,enumdef,
  388. {$IfNDef GDBKnowsStrings}
  389. stringdef,
  390. {$EndIf not GDBKnowsStrings}
  391. {$IfNDef GDBKnowsFiles}
  392. filedef,
  393. {$EndIf not GDBKnowsFiles}
  394. objectdef];
  395. {*****************************************************************************
  396. Helper Routines
  397. *****************************************************************************}
  398. {$ifdef unused}
  399. function demangledparas(s : string) : string;
  400. var
  401. r : string;
  402. l : longint;
  403. begin
  404. demangledparas:='';
  405. r:=',';
  406. { delete leading $$'s }
  407. l:=pos('$$',s);
  408. while l<>0 do
  409. begin
  410. delete(s,1,l+1);
  411. l:=pos('$$',s);
  412. end;
  413. { delete leading _$'s }
  414. l:=pos('_$',s);
  415. while l<>0 do
  416. begin
  417. delete(s,1,l+1);
  418. l:=pos('_$',s);
  419. end;
  420. l:=pos('$',s);
  421. if l=0 then
  422. exit;
  423. delete(s,1,l);
  424. while s<>'' do
  425. begin
  426. l:=pos('$',s);
  427. if l=0 then
  428. l:=length(s)+1;
  429. r:=r+copy(s,1,l-1)+',';
  430. delete(s,1,l);
  431. end;
  432. delete(r,1,1);
  433. delete(r,length(r),1);
  434. demangledparas:=r;
  435. end;
  436. {$endif}
  437. procedure numberunits;
  438. var
  439. counter : longint;
  440. hp : pused_unit;
  441. hp1 : pmodule;
  442. begin
  443. { Reset all numbers to -1 }
  444. hp1:=pmodule(loaded_units.first);
  445. while assigned(hp1) do
  446. begin
  447. if assigned(hp1^.globalsymtable) then
  448. psymtable(hp1^.globalsymtable)^.unitid:=$ffff;
  449. hp1:=pmodule(hp1^.next);
  450. end;
  451. { Our own symtable gets unitid 0, for a program there is
  452. no globalsymtable }
  453. if assigned(current_module^.globalsymtable) then
  454. psymtable(current_module^.globalsymtable)^.unitid:=0;
  455. { number units }
  456. counter:=1;
  457. hp:=pused_unit(current_module^.used_units.first);
  458. while assigned(hp) do
  459. begin
  460. psymtable(hp^.u^.globalsymtable)^.unitid:=counter;
  461. inc(counter);
  462. hp:=pused_unit(hp^.next);
  463. end;
  464. end;
  465. function findunitsymtable(st:psymtable):psymtable;
  466. begin
  467. findunitsymtable:=nil;
  468. repeat
  469. if not assigned(st) then
  470. internalerror(5566561);
  471. case st^.symtabletype of
  472. localsymtable,
  473. parasymtable,
  474. staticsymtable :
  475. break;
  476. globalsymtable,
  477. unitsymtable :
  478. begin
  479. findunitsymtable:=st;
  480. break;
  481. end;
  482. objectsymtable,
  483. recordsymtable :
  484. st:=st^.defowner^.owner;
  485. else
  486. internalerror(5566562);
  487. end;
  488. until false;
  489. end;
  490. procedure setstring(var p : pchar;const s : string);
  491. begin
  492. {$ifndef Delphi}
  493. {$ifdef TP}
  494. if use_big then
  495. begin
  496. p:=pchar(symbolstream.getsize);
  497. symbolstream.seek(longint(p));
  498. symbolstream.writestr(@s);
  499. end
  500. else
  501. {$endif TP}
  502. {$endif Delphi}
  503. p:=strpnew(s);
  504. end;
  505. procedure duplicatesym(sym:psym);
  506. var
  507. st : psymtable;
  508. begin
  509. Message1(sym_e_duplicate_id,sym^.name);
  510. st:=findunitsymtable(sym^.owner);
  511. if assigned(st) then
  512. begin
  513. with sym^.fileinfo do
  514. begin
  515. if st^.unitid=0 then
  516. Message2(sym_h_duplicate_id_where,current_module^.sourcefiles^.get_file_name(fileindex),tostr(line))
  517. else
  518. Message2(sym_h_duplicate_id_where,'unit '+st^.name^,tostr(line));
  519. end;
  520. end;
  521. end;
  522. {****************************************************************************
  523. TRef
  524. ****************************************************************************}
  525. constructor tref.init(ref :pref;pos : pfileposinfo);
  526. begin
  527. nextref:=nil;
  528. if pos<>nil then
  529. posinfo:=pos^;
  530. if assigned(current_module) then
  531. moduleindex:=current_module^.unit_index;
  532. if assigned(ref) then
  533. ref^.nextref:=@self;
  534. is_written:=false;
  535. end;
  536. destructor tref.done;
  537. var
  538. inputfile : pinputfile;
  539. begin
  540. inputfile:=get_source_file(moduleindex,posinfo.fileindex);
  541. if inputfile<>nil then
  542. dec(inputfile^.ref_count);
  543. if assigned(nextref) then
  544. dispose(nextref,done);
  545. nextref:=nil;
  546. end;
  547. {****************************************************************************
  548. TDeref
  549. ****************************************************************************}
  550. constructor tderef.init(typ:tdereftype;i:word);
  551. begin
  552. dereftype:=typ;
  553. index:=i;
  554. next:=nil;
  555. end;
  556. destructor tderef.done;
  557. begin
  558. end;
  559. {*****************************************************************************
  560. PPU Reading Writing
  561. *****************************************************************************}
  562. {$I symppu.inc}
  563. {*****************************************************************************
  564. Definition Helpers
  565. *****************************************************************************}
  566. function globaldef(const s : string) : pdef;
  567. var st : string;
  568. symt : psymtable;
  569. begin
  570. srsym := nil;
  571. if pos('.',s) > 0 then
  572. begin
  573. st := copy(s,1,pos('.',s)-1);
  574. getsym(st,false);
  575. st := copy(s,pos('.',s)+1,255);
  576. if assigned(srsym) then
  577. begin
  578. if srsym^.typ = unitsym then
  579. begin
  580. symt := punitsym(srsym)^.unitsymtable;
  581. srsym := symt^.search(st);
  582. end else srsym := nil;
  583. end;
  584. end else st := s;
  585. if srsym = nil then getsym(st,false);
  586. if srsym = nil then
  587. getsymonlyin(systemunit,st);
  588. if srsym^.typ<>typesym then
  589. begin
  590. Message(type_e_type_id_expected);
  591. exit;
  592. end;
  593. globaldef := ptypesym(srsym)^.definition;
  594. end;
  595. {*****************************************************************************
  596. Symbol / Definition Resolving
  597. *****************************************************************************}
  598. procedure resolvederef(var p:pderef;var st:psymtable;var idx:word);
  599. var
  600. hp : pderef;
  601. pd : pdef;
  602. begin
  603. st:=nil;
  604. idx:=0;
  605. while assigned(p) do
  606. begin
  607. case p^.dereftype of
  608. derefaktrecordindex :
  609. begin
  610. st:=aktrecordsymtable;
  611. idx:=p^.index;
  612. end;
  613. derefaktstaticindex :
  614. begin
  615. st:=aktstaticsymtable;
  616. idx:=p^.index;
  617. end;
  618. derefunit :
  619. begin
  620. {$ifdef NEWMAP}
  621. st:=psymtable(current_module^.map^[p^.index]^.globalsymtable);
  622. {$else NEWMAP}
  623. st:=psymtable(current_module^.map^[p^.index]);
  624. {$endif NEWMAP}
  625. end;
  626. derefrecord :
  627. begin
  628. pd:=st^.getdefnr(p^.index);
  629. case pd^.deftype of
  630. recorddef :
  631. st:=precorddef(pd)^.symtable;
  632. objectdef :
  633. st:=pobjectdef(pd)^.symtable;
  634. else
  635. internalerror(556658);
  636. end;
  637. end;
  638. dereflocal :
  639. begin
  640. pd:=st^.getdefnr(p^.index);
  641. case pd^.deftype of
  642. procdef :
  643. st:=pprocdef(pd)^.localst;
  644. else
  645. internalerror(556658);
  646. end;
  647. end;
  648. derefpara :
  649. begin
  650. pd:=st^.getdefnr(p^.index);
  651. case pd^.deftype of
  652. procdef :
  653. st:=pprocdef(pd)^.parast;
  654. else
  655. internalerror(556658);
  656. end;
  657. end;
  658. derefindex :
  659. begin
  660. idx:=p^.index;
  661. end;
  662. else
  663. internalerror(556658);
  664. end;
  665. hp:=p;
  666. p:=p^.next;
  667. dispose(hp,done);
  668. end;
  669. end;
  670. procedure resolvedef(var def:pdef);
  671. var
  672. st : psymtable;
  673. idx : word;
  674. begin
  675. resolvederef(pderef(def),st,idx);
  676. if assigned(st) then
  677. def:=st^.getdefnr(idx)
  678. else
  679. def:=nil;
  680. end;
  681. procedure resolvesym(var sym:psym);
  682. var
  683. st : psymtable;
  684. idx : word;
  685. begin
  686. resolvederef(pderef(sym),st,idx);
  687. if assigned(st) then
  688. sym:=st^.getsymnr(idx)
  689. else
  690. sym:=nil;
  691. end;
  692. {*****************************************************************************
  693. Symbol Call Back Functions
  694. *****************************************************************************}
  695. procedure derefsym(p : pnamedindexobject);
  696. begin
  697. psym(p)^.deref;
  698. end;
  699. procedure derefsymsdelayed(p : pnamedindexobject);
  700. begin
  701. if psym(p)^.typ in [absolutesym,propertysym] then
  702. psym(p)^.deref;
  703. end;
  704. procedure check_forward(sym : pnamedindexobject);
  705. begin
  706. if psym(sym)^.typ=procsym then
  707. pprocsym(sym)^.check_forward
  708. { check also object method table }
  709. { we needn't to test the def list }
  710. { because each object has to have a type sym }
  711. else
  712. if (psym(sym)^.typ=typesym) and
  713. assigned(ptypesym(sym)^.definition) and
  714. (ptypesym(sym)^.definition^.deftype=objectdef) then
  715. pobjectdef(ptypesym(sym)^.definition)^.check_forwards;
  716. end;
  717. procedure labeldefined(p : pnamedindexobject);
  718. begin
  719. if (psym(p)^.typ=labelsym) and
  720. not(plabelsym(p)^.defined) then
  721. Message1(sym_w_label_not_defined,p^.name);
  722. end;
  723. procedure unitsymbolused(p : pnamedindexobject);
  724. begin
  725. if (psym(p)^.typ=unitsym) and
  726. (punitsym(p)^.refs=0) then
  727. comment(V_info,'Unit '+p^.name+' is not used');
  728. end;
  729. procedure varsymbolused(p : pnamedindexobject);
  730. begin
  731. if (psym(p)^.typ=varsym) and
  732. ((psym(p)^.owner^.symtabletype in [parasymtable,localsymtable,staticsymtable])) then
  733. { unused symbol should be reported only if no }
  734. { error is reported }
  735. { if the symbol is in a register it is used }
  736. { also don't count the value parameters which have local copies }
  737. { also don't claim for high param of open parameters (PM) }
  738. if (pvarsym(p)^.refs=0) and
  739. (Errorcount=0) and
  740. (copy(p^.name,1,3)<>'val') and
  741. (copy(p^.name,1,4)<>'high') then
  742. begin
  743. if (psym(p)^.owner^.symtabletype=parasymtable) or pvarsym(p)^.islocalcopy then
  744. MessagePos1(psym(p)^.fileinfo,sym_h_para_identifier_not_used,p^.name)
  745. else
  746. MessagePos1(psym(p)^.fileinfo,sym_n_local_identifier_not_used,p^.name);
  747. end;
  748. end;
  749. {$ifdef GDB}
  750. procedure concatstab(p : pnamedindexobject);
  751. begin
  752. if psym(p)^.typ <> procsym then
  753. psym(p)^.concatstabto(asmoutput);
  754. end;
  755. procedure concattypestab(p : pnamedindexobject);
  756. begin
  757. if psym(p)^.typ = typesym then
  758. begin
  759. psym(p)^.isstabwritten:=false;
  760. psym(p)^.concatstabto(asmoutput);
  761. end;
  762. end;
  763. procedure forcestabto(asmlist : paasmoutput; pd : pdef);
  764. begin
  765. if not pd^.is_def_stab_written then
  766. begin
  767. if assigned(pd^.sym) then
  768. pd^.sym^.isusedinstab := true;
  769. pd^.concatstabto(asmlist);
  770. end;
  771. end;
  772. {$endif}
  773. {$ifdef CHAINPROCSYMS}
  774. procedure chainprocsym(p : psym);
  775. var
  776. storesymtablestack : psymtable;
  777. begin
  778. if p^.typ=procsym then
  779. begin
  780. storesymtablestack:=symtablestack;
  781. symtablestack:=p^.owner^.next;
  782. while assigned(symtablestack) do
  783. begin
  784. { search for same procsym in other units }
  785. getsym(p^.name,false);
  786. if assigned(srsym) and (srsym^.typ=procsym) then
  787. begin
  788. pprocsym(p)^.nextprocsym:=pprocsym(srsym);
  789. symtablestack:=storesymtablestack;
  790. exit;
  791. end
  792. else if srsym=nil then
  793. symtablestack:=nil
  794. else
  795. symtablestack:=srsymtable^.next;
  796. end;
  797. symtablestack:=storesymtablestack;
  798. end;
  799. end;
  800. {$endif}
  801. procedure write_refs(sym : pnamedindexobject);
  802. 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. {$ifdef GDB}
  2053. firstglobaldef:=nil;
  2054. lastglobaldef:=nil;
  2055. {$endif GDB}
  2056. globaltypecount:=1;
  2057. pglobaltypecount:=@globaltypecount;
  2058. { create error syms and def }
  2059. generrorsym:=new(perrorsym,init);
  2060. generrordef:=new(perrordef,init);
  2061. end;
  2062. procedure DoneSymtable;
  2063. begin
  2064. dispose(generrorsym,done);
  2065. dispose(generrordef,done);
  2066. { unload all symtables
  2067. done with loaded_units
  2068. dispose_global:=true;
  2069. while assigned(symtablestack) do
  2070. dellexlevel; }
  2071. {$ifndef Delphi}
  2072. {$ifdef TP}
  2073. { close the stream }
  2074. if use_big then
  2075. symbolstream.done;
  2076. {$endif}
  2077. {$endif Delphi}
  2078. end;
  2079. end.
  2080. {
  2081. $Log$
  2082. Revision 1.53 1999-10-06 17:39:15 peter
  2083. * fixed stabs writting for forward types
  2084. Revision 1.52 1999/10/03 19:44:42 peter
  2085. * removed objpasunit reference, tvarrec is now searched in systemunit
  2086. where it already was located
  2087. Revision 1.51 1999/10/01 08:02:49 peter
  2088. * forward type declaration rewritten
  2089. Revision 1.50 1999/09/28 20:48:25 florian
  2090. * fixed bug 610
  2091. + added $D- for TP in symtable.pas else it can't be compiled anymore
  2092. (too much symbols :()
  2093. Revision 1.49 1999/09/27 23:44:59 peter
  2094. * procinfo is now a pointer
  2095. * support for result setting in sub procedure
  2096. Revision 1.48 1999/09/12 21:35:38 florian
  2097. * fixed a crash under Linux. Why doesn't have the damned Windows DPMI nil pointer
  2098. protection???
  2099. Revision 1.47 1999/09/12 08:48:09 florian
  2100. * bugs 593 and 607 fixed
  2101. * some other potential bugs with array constructors fixed
  2102. * for classes compiled in $M+ and it's childs, the default access method
  2103. is now published
  2104. * fixed copyright message (it is now 1993-99)
  2105. Revision 1.46 1999/09/10 18:48:10 florian
  2106. * some bug fixes (e.g. must_be_valid and procinfo^.funcret_is_valid)
  2107. * most things for stored properties fixed
  2108. Revision 1.45 1999/09/08 08:05:44 peter
  2109. * fixed bug 248
  2110. Revision 1.44 1999/08/31 15:46:21 pierre
  2111. * do_crc must be false for all browser stuff
  2112. + tmacrosym defined_at_startup set in def_macro and set_macro
  2113. Revision 1.43 1999/08/27 10:39:24 pierre
  2114. * uf_local_browser made problem when computing interface CRC
  2115. Revision 1.42 1999/08/13 21:33:13 peter
  2116. * support for array constructors extended and more error checking
  2117. Revision 1.41 1999/08/13 14:24:22 pierre
  2118. + stabs for classes and classref working,
  2119. a class still needs an ^ to get that content of it,
  2120. but the class fields inside a class don't result into an
  2121. infinite loop anymore!
  2122. Revision 1.40 1999/08/10 16:25:42 pierre
  2123. * unitid changed to word
  2124. Revision 1.39 1999/08/10 12:33:36 pierre
  2125. * pprocsym defined earlier for use in tprocdef
  2126. Revision 1.38 1999/08/05 16:53:18 peter
  2127. * V_Fatal=1, all other V_ are also increased
  2128. * Check for local procedure when assigning procvar
  2129. * fixed comment parsing because directives
  2130. * oldtp mode directives better supported
  2131. * added some messages to errore.msg
  2132. Revision 1.37 1999/08/04 13:03:09 jonas
  2133. * all tokens now start with an underscore
  2134. * PowerPC compiles!!
  2135. Revision 1.36 1999/08/04 00:23:31 florian
  2136. * renamed i386asm and i386base to cpuasm and cpubase
  2137. Revision 1.35 1999/08/03 22:03:22 peter
  2138. * moved bitmask constants to sets
  2139. * some other type/const renamings
  2140. Revision 1.34 1999/08/03 17:51:45 florian
  2141. * reduced memory usage by factor 2-3 (it
  2142. improved also the speed) by reducing the
  2143. growsize of the symbol tables
  2144. Revision 1.33 1999/08/03 00:03:24 florian
  2145. * added bestrealdef for alpha and powerpc
  2146. Revision 1.32 1999/08/01 23:09:27 michael
  2147. * procbase -> cpubase
  2148. Revision 1.31 1999/08/01 23:04:50 michael
  2149. + Changes for Alpha
  2150. Revision 1.30 1999/07/24 00:13:26 peter
  2151. * also number units for program
  2152. Revision 1.29 1999/07/23 16:05:33 peter
  2153. * alignment is now saved in the symtable
  2154. * C alignment added for records
  2155. * PPU version increased to solve .12 <-> .13 probs
  2156. Revision 1.28 1999/07/23 12:02:20 peter
  2157. * fixed crash in previous commit
  2158. Revision 1.27 1999/07/23 11:37:50 peter
  2159. * error for illegal type reference, instead of 10998
  2160. Revision 1.26 1999/07/22 09:37:58 florian
  2161. + resourcestring implemented
  2162. + start of longstring support
  2163. Revision 1.25 1999/07/18 14:47:34 florian
  2164. * bug 487 fixed, (inc(<property>) isn't allowed)
  2165. * more fixes to compile with Delphi
  2166. Revision 1.24 1999/07/03 00:30:01 peter
  2167. * new link writing to the ppu, one .ppu is needed for all link types,
  2168. static (.o) is now always created also when smartlinking is used
  2169. Revision 1.23 1999/06/28 17:02:44 pierre
  2170. merged from v0-99-12 branch
  2171. Revision 1.21.2.2 1999/06/28 16:59:55 pierre
  2172. * fix to get method reference info
  2173. Revision 1.21.2.1 1999/06/22 16:26:46 pierre
  2174. * local browser stuff corrected
  2175. Revision 1.21 1999/06/08 22:23:50 pierre
  2176. * staticppusymtable was loaded a tsymtable instead of tunitsymtable
  2177. Revision 1.20 1999/06/02 22:44:23 pierre
  2178. * previous wrong log corrected
  2179. Revision 1.19 1999/06/02 22:25:53 pierre
  2180. * changed $ifdef FPC @ into $ifndef TP
  2181. Revision 1.18 1999/06/01 14:45:58 peter
  2182. * @procvar is now always needed for FPC
  2183. Revision 1.17 1999/05/27 19:45:08 peter
  2184. * removed oldasm
  2185. * plabel -> pasmlabel
  2186. * -a switches to source writing automaticly
  2187. * assembler readers OOPed
  2188. * asmsymbol automaticly external
  2189. * jumptables and other label fixes for asm readers
  2190. Revision 1.16 1999/05/23 18:42:16 florian
  2191. * better error recovering in typed constants
  2192. * some problems with arrays of const fixed, some problems
  2193. due my previous
  2194. - the location type of array constructor is now LOC_MEM
  2195. - the pushing of high fixed
  2196. - parameter copying fixed
  2197. - zero temp. allocation removed
  2198. * small problem in the assembler writers fixed:
  2199. ref to nil wasn't written correctly
  2200. Revision 1.15 1999/05/17 23:51:41 peter
  2201. * with temp vars now use a reference with a persistant temp instead
  2202. of setting datasize
  2203. Revision 1.14 1999/05/14 17:52:29 peter
  2204. * new deref code
  2205. Revision 1.13 1999/05/13 21:59:48 peter
  2206. * removed oldppu code
  2207. * warning if objpas is loaded from uses
  2208. * first things for new deref writing
  2209. Revision 1.12 1999/05/10 22:34:59 pierre
  2210. * one more unitsym problem fix
  2211. Revision 1.11 1999/05/10 15:02:51 pierre
  2212. unitsym finally problem fixed
  2213. Revision 1.10 1999/05/09 12:46:26 peter
  2214. + hint where a duplicate sym is already defined
  2215. Revision 1.9 1999/05/08 19:52:40 peter
  2216. + MessagePos() which is enhanced Message() function but also gets the
  2217. position info
  2218. * Removed comp warnings
  2219. Revision 1.8 1999/05/06 21:38:38 peter
  2220. * don't register errordef
  2221. Revision 1.7 1999/05/06 09:05:31 peter
  2222. * generic write_float and str_float
  2223. * fixed constant float conversions
  2224. Revision 1.6 1999/05/05 09:19:16 florian
  2225. * more fixes to get it with delphi running
  2226. Revision 1.5 1999/05/01 13:24:43 peter
  2227. * merged nasm compiler
  2228. * old asm moved to oldasm/
  2229. Revision 1.4 1999/04/29 17:25:37 peter
  2230. * small fix for deref
  2231. Revision 1.3 1999/04/26 18:30:03 peter
  2232. * farpointerdef moved into pointerdef.is_far
  2233. Revision 1.151 1999/04/26 13:31:54 peter
  2234. * release storenumber,double_checksum
  2235. Revision 1.150 1999/04/25 17:36:13 peter
  2236. * typo fix for storenumber
  2237. Revision 1.149 1999/04/21 22:05:28 pierre
  2238. + tsymtable.find_at_offset function
  2239. used by ra386att to give arg name from ebp offset with -vz option
  2240. Revision 1.148 1999/04/21 16:31:44 pierre
  2241. ra386att.pas : commit problem !
  2242. Revision 1.147 1999/04/21 09:43:57 peter
  2243. * storenumber works
  2244. * fixed some typos in double_checksum
  2245. + incompatible types type1 and type2 message (with storenumber)
  2246. Revision 1.146 1999/04/19 09:33:14 pierre
  2247. + added tsymtable.set_alignment(longint) function
  2248. to change the offsets of all function args
  2249. if declared as cdecl or stdcall
  2250. (this must be done after because the cdecl is parsed after
  2251. insertion of the function parameterss into parast symboltable)
  2252. Revision 1.145 1999/04/17 13:16:24 peter
  2253. * fixes for storenumber
  2254. Revision 1.144 1999/04/15 10:01:45 peter
  2255. * small update for storenumber
  2256. Revision 1.143 1999/04/14 09:15:04 peter
  2257. * first things to store the symbol/def number in the ppu
  2258. Revision 1.142 1999/04/08 14:54:10 pierre
  2259. * suppression of val para unused warnings
  2260. Revision 1.141 1999/04/07 15:31:09 pierre
  2261. * all formaldefs are now a sinlge definition
  2262. cformaldef (this was necessary for double_checksum)
  2263. + small part of double_checksum code
  2264. Revision 1.140 1999/03/31 13:55:24 peter
  2265. * assembler inlining working for ag386bin
  2266. Revision 1.139 1999/03/24 23:17:30 peter
  2267. * fixed bugs 212,222,225,227,229,231,233
  2268. Revision 1.138 1999/03/21 22:49:11 florian
  2269. * private ids of objects can be reused in child classes
  2270. if they are in another unit
  2271. Revision 1.137 1999/03/17 22:23:20 florian
  2272. * a FPC compiled compiler checks now also in debug mode in assigned
  2273. if a pointer points to the heap
  2274. * when a symtable is loaded, there is no need to check for duplicate
  2275. symbols. This leads to crashes because defowner isn't assigned
  2276. in this case
  2277. Revision 1.136 1999/03/01 13:45:07 pierre
  2278. + added staticppusymtable symtable type for local browsing
  2279. Revision 1.135 1999/02/23 18:29:28 pierre
  2280. * win32 compilation error fix
  2281. + some work for local browser (not cl=omplete yet)
  2282. Revision 1.134 1999/02/22 15:09:42 florian
  2283. * behaviaor of PROTECTED and PRIVATE fixed, works now like TP/Delphi
  2284. Revision 1.133 1999/02/22 13:07:12 pierre
  2285. + -b and -bl options work !
  2286. + cs_local_browser ($L+) is disabled if cs_browser ($Y+)
  2287. is not enabled when quitting global section
  2288. * local vars and procedures are not yet stored into PPU
  2289. Revision 1.132 1999/02/22 02:15:40 peter
  2290. * updates for ag386bin
  2291. Revision 1.131 1999/02/16 00:44:34 peter
  2292. * tp7 fix, assigned() can only be used on vars, not on functions
  2293. Revision 1.130 1999/02/15 13:13:16 pierre
  2294. * fix for bug0216
  2295. Revision 1.129 1999/02/11 09:46:29 pierre
  2296. * fix for normal method calls inside static methods :
  2297. WARNING there were both parser and codegen errors !!
  2298. added static_call boolean to calln tree
  2299. Revision 1.128 1999/02/09 23:03:05 florian
  2300. * check for duplicate field names in inherited classes/objects
  2301. * bug with self from the mailing list solved (the problem
  2302. was that classes were sometimes pushed wrong)
  2303. Revision 1.127 1999/02/08 11:29:06 pierre
  2304. * fix for bug0214
  2305. several problems where combined
  2306. search_class_member did not set srsymtable
  2307. => in do_member_read the call node got a wrong symtable
  2308. in cg386cal the vmt was pushed twice without chacking if it exists
  2309. now %esi is set to zero and pushed if not vmt
  2310. (not very efficient but should work !)
  2311. Revision 1.126 1999/02/05 08:54:31 pierre
  2312. + linkofiles splitted inot linkofiles and linkunitfiles
  2313. because linkofiles must be stored with directory
  2314. to enabled linking of different objects with same name
  2315. in a different directory
  2316. Revision 1.125 1999/02/03 09:44:33 pierre
  2317. * symbol nubering begins with 1 in number_symbols
  2318. * program tmodule has globalsymtable for its staticsymtable
  2319. (to get it displayed in IDE globals list)
  2320. + list of symbol (browcol) greatly improved for IDE
  2321. Revision 1.124 1999/01/27 12:58:33 pierre
  2322. * unused var warning suppressed for high of open arrays
  2323. Revision 1.123 1999/01/21 16:41:03 pierre
  2324. * fix for constructor inside with statements
  2325. Revision 1.122 1999/01/20 10:16:44 peter
  2326. * don't update crc when writing objs,libs and sources
  2327. Revision 1.121 1999/01/14 21:50:00 peter
  2328. * fixed forwardpointer problem with multiple forwards for the same
  2329. typesym. It now uses a linkedlist instead of a single pointer
  2330. Revision 1.120 1999/01/13 14:29:22 daniel
  2331. * nonextfield repaired
  2332. Revision 1.119 1999/01/12 14:25:38 peter
  2333. + BrowserLog for browser.log generation
  2334. + BrowserCol for browser info in TCollections
  2335. * released all other UseBrowser
  2336. Revision 1.118 1999/01/05 08:20:10 florian
  2337. * mainly problem with invalid case ranges fixed (reported by Jonas)
  2338. Revision 1.117 1998/12/30 22:15:57 peter
  2339. + farpointer type
  2340. * absolutesym now also stores if its far
  2341. Revision 1.116 1998/12/30 13:41:16 peter
  2342. * released valuepara
  2343. Revision 1.115 1998/12/11 00:03:48 peter
  2344. + globtype,tokens,version unit splitted from globals
  2345. Revision 1.114 1998/12/10 09:47:29 florian
  2346. + basic operations with int64/qord (compiler with -dint64)
  2347. + rtti of enumerations extended: names are now written
  2348. Revision 1.113 1998/12/08 10:18:17 peter
  2349. + -gh for heaptrc unit
  2350. Revision 1.112 1998/12/04 10:18:10 florian
  2351. * some stuff for procedures of object added
  2352. * bug with overridden virtual constructors fixed (reported by Italo Gomes)
  2353. Revision 1.111 1998/11/30 16:34:46 pierre
  2354. * corrected problems with rangecheck
  2355. + added needed code for no rangecheck in CRC32 functions in ppu unit
  2356. * enumdef lso need its rangenr reset to zero
  2357. when calling reset_global_defs
  2358. Revision 1.110 1998/11/28 16:20:58 peter
  2359. + support for dll variables
  2360. Revision 1.109 1998/11/27 14:50:49 peter
  2361. + open strings, $P switch support
  2362. Revision 1.108 1998/11/24 23:00:32 peter
  2363. * small crash prevention
  2364. Revision 1.107 1998/11/20 15:36:01 florian
  2365. * problems with rtti fixed, hope it works
  2366. Revision 1.106 1998/11/18 15:44:20 peter
  2367. * VALUEPARA for tp7 compatible value parameters
  2368. Revision 1.105 1998/11/17 10:39:18 peter
  2369. * has_rtti,has_inittable reset
  2370. Revision 1.104 1998/11/16 10:13:52 peter
  2371. * label defines are checked at the end of the proc
  2372. Revision 1.103 1998/11/13 15:40:32 pierre
  2373. + added -Se in Makefile cvstest target
  2374. + lexlevel cleanup
  2375. normal_function_level main_program_level and unit_init_level defined
  2376. * tins_cache grown to A_EMMS (gave range check error in asm readers)
  2377. (test added in code !)
  2378. * -Un option was wrong
  2379. * _FAIL and _SELF only keyword inside
  2380. constructors and methods respectively
  2381. Revision 1.102 1998/11/12 16:43:34 florian
  2382. * functions with ansi strings as result didn't work, solved
  2383. Revision 1.101 1998/11/12 12:55:18 pierre
  2384. * fix for bug0176 and bug0177
  2385. Revision 1.100 1998/11/10 10:09:15 peter
  2386. * va_list -> array of const
  2387. Revision 1.99 1998/11/09 11:44:38 peter
  2388. + va_list for printf support
  2389. Revision 1.98 1998/11/05 23:33:35 peter
  2390. * symtable.done sets vars to nil
  2391. Revision 1.97 1998/11/05 12:03:00 peter
  2392. * released useansistring
  2393. * removed -Sv, its now available in fpc modes
  2394. Revision 1.96 1998/10/28 18:26:19 pierre
  2395. * removed some erros after other errors (introduced by useexcept)
  2396. * stabs works again correctly (for how long !)
  2397. Revision 1.95 1998/10/21 08:40:01 florian
  2398. + ansistring operator +
  2399. + $h and string[n] for n>255 added
  2400. * small problem with TP fixed
  2401. Revision 1.94 1998/10/20 08:07:03 pierre
  2402. * several memory corruptions due to double freemem solved
  2403. => never use p^.loc.location:=p^.left^.loc.location;
  2404. + finally I added now by default
  2405. that ra386dir translates global and unit symbols
  2406. + added a first field in tsymtable and
  2407. a nextsym field in tsym
  2408. (this allows to obtain ordered type info for
  2409. records and objects in gdb !)
  2410. Revision 1.93 1998/10/19 08:55:08 pierre
  2411. * wrong stabs info corrected once again !!
  2412. + variable vmt offset with vmt field only if required
  2413. implemented now !!!
  2414. Revision 1.92 1998/10/16 13:12:56 pierre
  2415. * added vmt_offsets in destructors code also !!!
  2416. * vmt_offset code for m68k
  2417. Revision 1.91 1998/10/16 08:48:38 peter
  2418. * fixed some misplaced $endif GDB
  2419. Revision 1.90 1998/10/15 15:13:32 pierre
  2420. + added oo_hasconstructor and oo_hasdestructor
  2421. for objects options
  2422. Revision 1.89 1998/10/14 13:38:25 peter
  2423. * fixed path with staticlib/objects in ppufiles
  2424. Revision 1.88 1998/10/09 16:36:07 pierre
  2425. * some memory leaks specific to usebrowser define fixed
  2426. * removed tmodule.implsymtable (was like tmodule.localsymtable)
  2427. Revision 1.87 1998/10/09 11:47:57 pierre
  2428. * still more memory leaks fixes !!
  2429. Revision 1.86 1998/10/08 17:17:35 pierre
  2430. * current_module old scanner tagged as invalid if unit is recompiled
  2431. + added ppheap for better info on tracegetmem of heaptrc
  2432. (adds line column and file index)
  2433. * several memory leaks removed ith help of heaptrc !!
  2434. Revision 1.85 1998/10/08 13:48:51 peter
  2435. * fixed memory leaks for do nothing source
  2436. * fixed unit interdependency
  2437. Revision 1.84 1998/10/06 17:16:58 pierre
  2438. * some memory leaks fixed (thanks to Peter for heaptrc !)
  2439. Revision 1.83 1998/09/26 17:45:45 peter
  2440. + idtoken and only one token table
  2441. Revision 1.82 1998/09/25 09:52:57 peter
  2442. + store also datasize and # of symbols in ppu
  2443. * # of defs is now also stored in structs
  2444. Revision 1.81 1998/09/24 23:49:21 peter
  2445. + aktmodeswitches
  2446. Revision 1.80 1998/09/23 12:20:51 pierre
  2447. * main program tmodule had no symtable (crashed browser)
  2448. * unit symbols problem fixed !!
  2449. Revision 1.79 1998/09/23 12:03:57 peter
  2450. * overloading fix for array of const
  2451. Revision 1.78 1998/09/22 17:13:54 pierre
  2452. + browsing updated and developed
  2453. records and objects fields are also stored
  2454. Revision 1.77 1998/09/22 15:37:24 peter
  2455. + array of const start
  2456. Revision 1.76 1998/09/21 10:00:08 peter
  2457. * store number of defs in ppu file
  2458. Revision 1.75 1998/09/21 08:58:31 peter
  2459. + speedsearch, which also needs speedvalue as parameter
  2460. Revision 1.74 1998/09/21 08:45:25 pierre
  2461. + added vmt_offset in tobjectdef.write for fututre use
  2462. (first steps to have objects without vmt if no virtual !!)
  2463. + added fpu_used field for tabstractprocdef :
  2464. sets this level to 2 if the functions return with value in FPU
  2465. (is then set to correct value at parsing of implementation)
  2466. THIS MIGHT refuse some code with FPU expression too complex
  2467. that were accepted before and even in some cases
  2468. that don't overflow in fact
  2469. ( like if f : float; is a forward that finally in implementation
  2470. only uses one fpu register !!)
  2471. Nevertheless I think that it will improve security on
  2472. FPU operations !!
  2473. * most other changes only for UseBrowser code
  2474. (added symtable references for record and objects)
  2475. local switch for refs to args and local of each function
  2476. (static symtable still missing)
  2477. UseBrowser still not stable and probably broken by
  2478. the definition hash array !!
  2479. Revision 1.73 1998/09/20 09:38:47 florian
  2480. * hasharray for defs fixed
  2481. * ansistring code generation corrected (init/final, assignement)
  2482. Revision 1.72 1998/09/19 22:56:18 florian
  2483. + hash table for getdefnr added
  2484. Revision 1.71 1998/09/18 08:01:40 pierre
  2485. + improvement on the usebrowser part
  2486. (does not work correctly for now)
  2487. Revision 1.70 1998/09/09 11:50:57 pierre
  2488. * forward def are not put in record or objects
  2489. + added check for forwards also in record and objects
  2490. * dummy parasymtable for unit initialization removed from
  2491. symtable stack
  2492. Revision 1.69 1998/09/07 23:10:25 florian
  2493. * a lot of stuff fixed regarding rtti and publishing of properties,
  2494. basics should now work
  2495. Revision 1.68 1998/09/07 19:33:26 florian
  2496. + some stuff for property rtti added:
  2497. - NameIndex of the TPropInfo record is now written correctly
  2498. - the DEFAULT/NODEFAULT keyword is supported now
  2499. - the default value and the storedsym/def are now written to
  2500. the PPU fiel
  2501. Revision 1.67 1998/09/07 18:46:14 peter
  2502. * update smartlinking, uses getdatalabel
  2503. * renamed ptree.value vars to value_str,value_real,value_set
  2504. Revision 1.66 1998/09/07 17:37:05 florian
  2505. * first fixes for published properties
  2506. Revision 1.65 1998/09/06 22:42:03 florian
  2507. + rtti genreation for properties added
  2508. Revision 1.64 1998/09/05 22:11:04 florian
  2509. + switch -vb
  2510. * while/repeat loops accept now also word/longbool conditions
  2511. * makebooltojump did an invalid ungetregister32, fixed
  2512. Revision 1.63 1998/09/04 17:34:23 pierre
  2513. * bug with datalabel corrected
  2514. + assembler errors better commented
  2515. * one nested record crash removed
  2516. Revision 1.62 1998/09/04 08:42:10 peter
  2517. * updated some error messages
  2518. Revision 1.61 1998/09/03 16:03:21 florian
  2519. + rtti generation
  2520. * init table generation changed
  2521. Revision 1.60 1998/09/01 17:39:52 peter
  2522. + internal constant functions
  2523. Revision 1.59 1998/09/01 12:53:27 peter
  2524. + aktpackenum
  2525. Revision 1.58 1998/09/01 07:54:26 pierre
  2526. * UseBrowser a little updated (might still be buggy !!)
  2527. * bug in psub.pas in function specifier removed
  2528. * stdcall allowed in interface and in implementation
  2529. (FPC will not yet complain if it is missing in either part
  2530. because stdcall is only a dummy !!)
  2531. Revision 1.57 1998/08/31 12:26:33 peter
  2532. * m68k and palmos updates from surebugfixes
  2533. Revision 1.56 1998/08/21 14:08:55 pierre
  2534. + TEST_FUNCRET now default (old code removed)
  2535. works also for m68k (at least compiles)
  2536. Revision 1.55 1998/08/21 08:43:32 pierre
  2537. * pocdecl and poclearstack are now different
  2538. external must but written as last specification
  2539. Revision 1.54 1998/08/20 09:26:48 pierre
  2540. + funcret setting in underproc testing
  2541. compile with _dTEST_FUNCRET
  2542. Revision 1.53 1998/08/19 18:04:56 peter
  2543. * fixed current_module^.in_implementation flag
  2544. Revision 1.51 1998/08/18 14:17:12 pierre
  2545. * bug about assigning the return value of a function to
  2546. a procvar fixed : warning
  2547. assigning a proc to a procvar need @ in FPC mode !!
  2548. * missing file/line info restored
  2549. Revision 1.50 1998/08/17 10:10:13 peter
  2550. - removed OLDPPU
  2551. Revision 1.49 1998/08/12 19:39:31 peter
  2552. * fixed some crashes
  2553. Revision 1.48 1998/08/10 14:50:32 peter
  2554. + localswitches, moduleswitches, globalswitches splitting
  2555. Revision 1.47 1998/08/10 10:00:19 peter
  2556. * Moved symbolstream to symtable.pas
  2557. Revision 1.46 1998/08/08 10:19:19 florian
  2558. * small fixes to write the extended type correct
  2559. Revision 1.45 1998/08/02 16:42:00 florian
  2560. * on o : tobject do should also work now, the exceptsymtable shouldn't be
  2561. disposed by dellexlevel
  2562. Revision 1.44 1998/07/30 11:18:21 florian
  2563. + first implementation of try ... except on .. do end;
  2564. * limitiation of 65535 bytes parameters for cdecl removed
  2565. Revision 1.43 1998/07/28 21:52:56 florian
  2566. + implementation of raise and try..finally
  2567. + some misc. exception stuff
  2568. Revision 1.42 1998/07/20 10:23:03 florian
  2569. * better ansi string assignement
  2570. Revision 1.41 1998/07/18 22:54:31 florian
  2571. * some ansi/wide/longstring support fixed:
  2572. o parameter passing
  2573. o returning as result from functions
  2574. Revision 1.40 1998/07/14 14:47:09 peter
  2575. * released NEWINPUT
  2576. Revision 1.39 1998/07/10 00:00:06 peter
  2577. * fixed ttypesym bug finally
  2578. * fileinfo in the symtable and better using for unused vars
  2579. Revision 1.38 1998/07/07 11:20:17 peter
  2580. + NEWINPUT for a better inputfile and scanner object
  2581. Revision 1.37 1998/06/24 14:48:42 peter
  2582. * ifdef newppu -> ifndef oldppu
  2583. Revision 1.36 1998/06/17 14:10:19 peter
  2584. * small os2 fixes
  2585. * fixed interdependent units with newppu (remake3 under linux works now)
  2586. Revision 1.35 1998/06/16 08:56:35 peter
  2587. + targetcpu
  2588. * cleaner pmodules for newppu
  2589. Revision 1.34 1998/06/15 15:38:12 pierre
  2590. * small bug in systems.pas corrected
  2591. + operators in different units better hanlded
  2592. Revision 1.33 1998/06/15 14:10:53 daniel
  2593. * File was ruined, fixed.
  2594. Revision 1.31 1998/06/13 00:10:20 peter
  2595. * working browser and newppu
  2596. * some small fixes against crashes which occured in bp7 (but not in
  2597. fpc?!)
  2598. Revision 1.30 1998/06/09 16:01:53 pierre
  2599. + added procedure directive parsing for procvars
  2600. (accepted are popstack cdecl and pascal)
  2601. + added C vars with the following syntax
  2602. var C calias 'true_c_name';(can be followed by external)
  2603. reason is that you must add the Cprefix
  2604. which is target dependent
  2605. Revision 1.29 1998/06/07 15:30:26 florian
  2606. + first working rtti
  2607. + data init/final. for local variables
  2608. Revision 1.28 1998/06/06 09:27:39 peter
  2609. * new depend file generated
  2610. Revision 1.27 1998/06/05 14:37:38 pierre
  2611. * fixes for inline for operators
  2612. * inline procedure more correctly restricted
  2613. Revision 1.26 1998/06/04 23:52:03 peter
  2614. * m68k compiles
  2615. + .def file creation moved to gendef.pas so it could also be used
  2616. for win32
  2617. Revision 1.25 1998/06/04 09:55:48 pierre
  2618. * demangled name of procsym reworked to become independant of the
  2619. mangling scheme
  2620. Revision 1.24 1998/06/03 22:49:04 peter
  2621. + wordbool,longbool
  2622. * rename bis,von -> high,low
  2623. * moved some systemunit loading/creating to psystem.pas
  2624. Revision 1.23 1998/05/28 14:40:30 peter
  2625. * fixes for newppu, remake3 works now with it
  2626. Revision 1.22 1998/05/27 19:45:09 peter
  2627. * symtable.pas splitted into includefiles
  2628. * symtable adapted for $ifndef OLDPPU
  2629. Revision 1.21 1998/05/23 01:21:31 peter
  2630. + aktasmmode, aktoptprocessor, aktoutputformat
  2631. + smartlink per module $SMARTLINK-/+ (like MMX) and moved to aktswitches
  2632. + $LIBNAME to set the library name where the unit will be put in
  2633. * splitted cgi386 a bit (codeseg to large for bp7)
  2634. * nasm, tasm works again. nasm moved to ag386nsm.pas
  2635. Revision 1.20 1998/05/21 19:33:37 peter
  2636. + better procedure directive handling and only one table
  2637. Revision 1.19 1998/05/20 09:42:37 pierre
  2638. + UseTokenInfo now default
  2639. * unit in interface uses and implementation uses gives error now
  2640. * only one error for unknown symbol (uses lastsymknown boolean)
  2641. the problem came from the label code !
  2642. + first inlined procedures and function work
  2643. (warning there might be allowed cases were the result is still wrong !!)
  2644. * UseBrower updated gives a global list of all position of all used symbols
  2645. with switch -gb
  2646. Revision 1.18 1998/05/11 13:07:57 peter
  2647. + $ifndef OLDPPU for the new ppuformat
  2648. + $define GDB not longer required
  2649. * removed all warnings and stripped some log comments
  2650. * no findfirst/findnext anymore to remove smartlink *.o files
  2651. Revision 1.17 1998/05/06 08:38:48 pierre
  2652. * better position info with UseTokenInfo
  2653. UseTokenInfo greatly simplified
  2654. + added check for changed tree after first time firstpass
  2655. (if we could remove all the cases were it happen
  2656. we could skip all firstpass if firstpasscount > 1)
  2657. Only with ExtDebug
  2658. Revision 1.16 1998/05/05 15:24:20 michael
  2659. * Fix to save units with classes.
  2660. Revision 1.15 1998/05/04 17:54:29 peter
  2661. + smartlinking works (only case jumptable left todo)
  2662. * redesign of systems.pas to support assemblers and linkers
  2663. + Unitname is now also in the PPU-file, increased version to 14
  2664. Revision 1.14 1998/05/01 16:38:46 florian
  2665. * handling of private and protected fixed
  2666. + change_keywords_to_tp implemented to remove
  2667. keywords which aren't supported by tp
  2668. * break and continue are now symbols of the system unit
  2669. + widestring, longstring and ansistring type released
  2670. Revision 1.13 1998/05/01 09:01:25 florian
  2671. + correct semantics of private and protected
  2672. * small fix in variable scope:
  2673. a id can be used in a parameter list of a method, even it is used in
  2674. an anchestor class as field id
  2675. Revision 1.12 1998/05/01 07:43:57 florian
  2676. + basics for rtti implemented
  2677. + switch $m (generate rtti for published sections)
  2678. Revision 1.11 1998/04/30 15:59:42 pierre
  2679. * GDB works again better :
  2680. correct type info in one pass
  2681. + UseTokenInfo for better source position
  2682. * fixed one remaining bug in scanner for line counts
  2683. * several little fixes
  2684. Revision 1.10 1998/04/29 10:34:05 pierre
  2685. + added some code for ansistring (not complete nor working yet)
  2686. * corrected operator overloading
  2687. * corrected nasm output
  2688. + started inline procedures
  2689. + added starstarn : use ** for exponentiation (^ gave problems)
  2690. + started UseTokenInfo cond to get accurate positions
  2691. Revision 1.9 1998/04/27 23:10:29 peter
  2692. + new scanner
  2693. * $makelib -> if smartlink
  2694. * small filename fixes pmodule.setfilename
  2695. * moved import from files.pas -> import.pas
  2696. Revision 1.8 1998/04/21 10:16:48 peter
  2697. * patches from strasbourg
  2698. * objects is not used anymore in the fpc compiled version
  2699. Revision 1.7 1998/04/13 22:20:36 florian
  2700. + stricter checking for duplicate id, solves also bug0097
  2701. Revision 1.6 1998/04/13 17:20:43 florian
  2702. * tdef.done much faster implemented
  2703. Revision 1.5 1998/04/10 21:36:56 florian
  2704. + some stuff to support method pointers (procedure of object) added
  2705. (declaration, parameter handling)
  2706. Revision 1.4 1998/04/08 16:58:08 pierre
  2707. * several bugfixes
  2708. ADD ADC and AND are also sign extended
  2709. nasm output OK (program still crashes at end
  2710. and creates wrong assembler files !!)
  2711. procsym types sym in tdef removed !!
  2712. Revision 1.3 1998/04/07 13:19:52 pierre
  2713. * bugfixes for reset_gdb_info
  2714. in MEM parsing for go32v2
  2715. better external symbol creation
  2716. support for rhgdb.exe (lowercase file names)
  2717. Revision 1.2 1998/04/06 13:09:04 daniel
  2718. * Emergency solution for bug in reset_gdb_info.
  2719. }