symtable.pas 99 KB

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