symtable.pas 100 KB

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