symtable.pas 95 KB

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