symtable.pas 98 KB

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