symtable.pas 102 KB

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