symtable.pas 100 KB

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