symtable.pas 97 KB

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