symtable.pas 96 KB

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