symtable.pas 103 KB

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