symtable.pas 101 KB

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