symtable.pas 102 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216
  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(next) and
  1346. { funcretsym is allowed !! }
  1347. (sym^.typ <> funcretsym) and
  1348. (next^.symtabletype=objectsymtable) then
  1349. begin
  1350. hsym:=search_class_member(pobjectdef(next^.defowner),sym^.name);
  1351. { but private ids can be reused }
  1352. if assigned(hsym) and
  1353. (not(sp_private in hsym^.symoptions) or
  1354. (hsym^.owner^.defowner^.owner^.symtabletype<>unitsymtable)) then
  1355. DuplicateSym(hsym);
  1356. end;
  1357. { check for duplicate field id in inherited classes }
  1358. if (sym^.typ=varsym) and
  1359. (symtabletype=objectsymtable) and
  1360. assigned(defowner) then
  1361. begin
  1362. hsym:=search_class_member(pobjectdef(defowner),sym^.name);
  1363. { but private ids can be reused }
  1364. if assigned(hsym) and
  1365. (not(sp_private in hsym^.symoptions) or
  1366. (hsym^.owner^.defowner^.owner^.symtabletype<>unitsymtable)) then
  1367. DuplicateSym(hsym);
  1368. end;
  1369. { register definition of typesym }
  1370. if (sym^.typ = typesym) and
  1371. assigned(ptypesym(sym)^.definition) then
  1372. begin
  1373. if not(assigned(ptypesym(sym)^.definition^.owner)) and
  1374. (ptypesym(sym)^.definition^.deftype<>errordef) then
  1375. registerdef(ptypesym(sym)^.definition);
  1376. {$ifdef GDB}
  1377. if (cs_debuginfo in aktmoduleswitches) and assigned(debuglist) and
  1378. (symtabletype in [globalsymtable,staticsymtable]) then
  1379. begin
  1380. ptypesym(sym)^.isusedinstab := true;
  1381. sym^.concatstabto(debuglist);
  1382. end;
  1383. {$endif GDB}
  1384. end;
  1385. { insert in index and search hash }
  1386. symindex^.insert(sym);
  1387. symsearch^.insert(sym);
  1388. insert:=sym;
  1389. end;
  1390. function tsymtable.search(const s : stringid) : psym;
  1391. begin
  1392. {search:=psym(symsearch^.search(s));
  1393. this bypasses the ref generation (PM) }
  1394. search:=speedsearch(s,getspeedvalue(s));
  1395. end;
  1396. function tsymtable.speedsearch(const s : stringid;speedvalue : longint) : psym;
  1397. var
  1398. hp : psym;
  1399. begin
  1400. hp:=psym(symsearch^.speedsearch(s,speedvalue));
  1401. if assigned(hp) then
  1402. begin
  1403. { reject non static members in static procedures,
  1404. be carefull aktprocsym^.definition is not allways
  1405. loaded already (PFV) }
  1406. if (symtabletype=objectsymtable) and
  1407. not(sp_static in hp^.symoptions) and
  1408. allow_only_static
  1409. {assigned(aktprocsym) and
  1410. assigned(aktprocsym^.definition) and
  1411. ((aktprocsym^.definition^.options and postaticmethod)<>0)} then
  1412. Message(sym_e_only_static_in_static);
  1413. if (symtabletype=unitsymtable) and
  1414. assigned(punitsymtable(@self)^.unitsym) then
  1415. inc(punitsymtable(@self)^.unitsym^.refs);
  1416. { unitsym are only loaded for browsing PM }
  1417. { this was buggy anyway because we could use }
  1418. { unitsyms from other units in _USES !! }
  1419. if (symtabletype=unitsymtable) and (hp^.typ=unitsym) and
  1420. assigned(current_module) and (current_module^.globalsymtable<>@self) then
  1421. hp:=nil;
  1422. if assigned(hp) and
  1423. (cs_browser in aktmoduleswitches) and make_ref then
  1424. begin
  1425. hp^.lastref:=new(pref,init(hp^.lastref,@tokenpos));
  1426. { for symbols that are in tables without
  1427. browser info or syssyms (PM) }
  1428. if hp^.refcount=0 then
  1429. hp^.defref:=hp^.lastref;
  1430. inc(hp^.refcount);
  1431. end;
  1432. end;
  1433. speedsearch:=hp;
  1434. end;
  1435. function tsymtable.rename(const olds,news : stringid):psym;
  1436. begin
  1437. rename:=psym(symsearch^.rename(olds,news));
  1438. end;
  1439. {***********************************************
  1440. Browser
  1441. ***********************************************}
  1442. procedure tsymtable.load_browser;
  1443. var
  1444. b : byte;
  1445. sym : psym;
  1446. prdef : pdef;
  1447. oldrecsyms : psymtable;
  1448. begin
  1449. if symtabletype in [recordsymtable,objectsymtable,
  1450. parasymtable,localsymtable] then
  1451. begin
  1452. oldrecsyms:=aktrecordsymtable;
  1453. aktrecordsymtable:=@self;
  1454. end;
  1455. if symtabletype=staticppusymtable then
  1456. aktstaticsymtable:=@self;
  1457. b:=current_ppu^.readentry;
  1458. if b <> ibbeginsymtablebrowser then
  1459. Message1(unit_f_ppu_invalid_entry,tostr(b));
  1460. repeat
  1461. b:=current_ppu^.readentry;
  1462. case b of
  1463. ibsymref : begin
  1464. sym:=readsymref;
  1465. resolvesym(sym);
  1466. if assigned(sym) then
  1467. sym^.load_references;
  1468. end;
  1469. ibdefref : begin
  1470. prdef:=readdefref;
  1471. resolvedef(prdef);
  1472. if assigned(prdef) then
  1473. begin
  1474. if prdef^.deftype<>procdef then
  1475. Message(unit_f_ppu_read_error);
  1476. pprocdef(prdef)^.load_references;
  1477. end;
  1478. end;
  1479. ibendsymtablebrowser : break;
  1480. else
  1481. Message1(unit_f_ppu_invalid_entry,tostr(b));
  1482. end;
  1483. until false;
  1484. if symtabletype in [recordsymtable,objectsymtable,
  1485. parasymtable,localsymtable] then
  1486. aktrecordsymtable:=oldrecsyms;
  1487. end;
  1488. procedure tsymtable.write_browser;
  1489. var
  1490. oldrecsyms : psymtable;
  1491. begin
  1492. { symbol numbering for references
  1493. should have been done in write PM
  1494. number_symbols;
  1495. number_defs; }
  1496. if symtabletype in [recordsymtable,objectsymtable,
  1497. parasymtable,localsymtable] then
  1498. begin
  1499. oldrecsyms:=aktrecordsymtable;
  1500. aktrecordsymtable:=@self;
  1501. end;
  1502. current_ppu^.writeentry(ibbeginsymtablebrowser);
  1503. foreach({$ifndef TP}@{$endif}write_refs);
  1504. current_ppu^.writeentry(ibendsymtablebrowser);
  1505. if symtabletype in [recordsymtable,objectsymtable,
  1506. parasymtable,localsymtable] then
  1507. aktrecordsymtable:=oldrecsyms;
  1508. end;
  1509. {$ifdef BrowserLog}
  1510. procedure tsymtable.writebrowserlog;
  1511. begin
  1512. if cs_browser in aktmoduleswitches then
  1513. begin
  1514. if assigned(name) then
  1515. Browserlog.AddLog('---Symtable '+name^)
  1516. else
  1517. begin
  1518. if (symtabletype=recordsymtable) and
  1519. assigned(defowner^.sym) then
  1520. Browserlog.AddLog('---Symtable '+defowner^.sym^.name)
  1521. else
  1522. Browserlog.AddLog('---Symtable with no name');
  1523. end;
  1524. Browserlog.Ident;
  1525. foreach({$ifndef TP}@{$endif}add_to_browserlog);
  1526. browserlog.Unident;
  1527. end;
  1528. end;
  1529. {$endif BrowserLog}
  1530. {***********************************************
  1531. Process all entries
  1532. ***********************************************}
  1533. { checks, if all procsyms and methods are defined }
  1534. procedure tsymtable.check_forwards;
  1535. begin
  1536. foreach({$ifndef TP}@{$endif}check_procsym_forward);
  1537. end;
  1538. procedure tsymtable.checklabels;
  1539. begin
  1540. foreach({$ifndef TP}@{$endif}labeldefined);
  1541. end;
  1542. procedure tsymtable.set_alignment(_alignment : byte);
  1543. var
  1544. sym : pvarsym;
  1545. l : longint;
  1546. begin
  1547. { this can not be done if there is an
  1548. hasharray ! }
  1549. alignment:=_alignment;
  1550. if (symtabletype<>parasymtable) then
  1551. internalerror(1111);
  1552. sym:=pvarsym(symindex^.first);
  1553. datasize:=0;
  1554. { there can be only varsyms }
  1555. while assigned(sym) do
  1556. begin
  1557. l:=sym^.getpushsize;
  1558. sym^.address:=datasize;
  1559. datasize:=align(datasize+l,alignment);
  1560. sym:=pvarsym(sym^.next);
  1561. end;
  1562. end;
  1563. function tsymtable.find_at_offset(l : longint) : pvarsym;
  1564. var
  1565. sym : pvarsym;
  1566. begin
  1567. find_at_offset:=nil;
  1568. { this can not be done if there is an
  1569. hasharray ! }
  1570. if (symtabletype<>parasymtable) then
  1571. internalerror(1111);
  1572. sym:=pvarsym(symindex^.first);
  1573. while assigned(sym) do
  1574. begin
  1575. if sym^.address+address_fixup=l then
  1576. begin
  1577. find_at_offset:=sym;
  1578. exit;
  1579. end;
  1580. sym:=pvarsym(sym^.next);
  1581. end;
  1582. end;
  1583. procedure tsymtable.allunitsused;
  1584. begin
  1585. foreach({$ifndef TP}@{$endif}unitsymbolused);
  1586. end;
  1587. procedure tsymtable.allsymbolsused;
  1588. begin
  1589. foreach({$ifndef TP}@{$endif}varsymbolused);
  1590. end;
  1591. {$ifdef CHAINPROCSYMS}
  1592. procedure tsymtable.chainprocsyms;
  1593. begin
  1594. foreach({$ifndef TP}@{$endif}chainprocsym);
  1595. end;
  1596. {$endif CHAINPROCSYMS}
  1597. {$ifdef GDB}
  1598. procedure tsymtable.concatstabto(asmlist : paasmoutput);
  1599. begin
  1600. asmoutput:=asmlist;
  1601. foreach({$ifndef TP}@{$endif}concatstab);
  1602. end;
  1603. {$endif}
  1604. {****************************************************************************
  1605. TUNITSYMTABLE
  1606. ****************************************************************************}
  1607. constructor tunitsymtable.init(t : tsymtabletype; const n : string);
  1608. begin
  1609. inherited init(t);
  1610. name:=stringdup(upper(n));
  1611. unitid:=0;
  1612. unitsym:=nil;
  1613. symsearch^.usehash;
  1614. { reset GDB things }
  1615. {$ifdef GDB}
  1616. if t = globalsymtable then
  1617. begin
  1618. prev_dbx_counter := dbx_counter;
  1619. dbx_counter := @dbx_count;
  1620. end;
  1621. is_stab_written:=false;
  1622. if cs_gdb_dbx in aktglobalswitches then
  1623. begin
  1624. dbx_count := 0;
  1625. if (symtabletype=globalsymtable) then
  1626. pglobaltypecount := @unittypecount;
  1627. debuglist^.concat(new(pai_stabs,init(strpnew('"'+name^+'",'+tostr(N_BINCL)+',0,0,0'))));
  1628. unitid:=current_module^.unitcount;
  1629. inc(current_module^.unitcount);
  1630. debuglist^.concat(new(pai_asm_comment,init(strpnew('Global '+name^+' has index '+tostr(unitid)))));
  1631. end;
  1632. {$endif GDB}
  1633. end;
  1634. constructor tunitsymtable.loadasunit;
  1635. var
  1636. storeGlobalTypeCount : pword;
  1637. b : byte;
  1638. begin
  1639. unitsym:=nil;
  1640. unitid:=0;
  1641. if (current_module^.flags and uf_has_dbx)<>0 then
  1642. begin
  1643. storeGlobalTypeCount:=PGlobalTypeCount;
  1644. PglobalTypeCount:=@UnitTypeCount;
  1645. end;
  1646. { load symtables }
  1647. inherited load;
  1648. { set the name after because it is set to nil in tsymtable.load !! }
  1649. name:=stringdup(current_module^.modulename^);
  1650. { dbx count }
  1651. {$ifdef GDB}
  1652. if (current_module^.flags and uf_has_dbx)<>0 then
  1653. begin
  1654. b := current_ppu^.readentry;
  1655. if b <> ibdbxcount then
  1656. Message(unit_f_ppu_dbx_count_problem)
  1657. else
  1658. dbx_count := readlong;
  1659. dbx_count_ok := true;
  1660. PGlobalTypeCount:=storeGlobalTypeCount;
  1661. end
  1662. else
  1663. dbx_count := 0;
  1664. is_stab_written:=false;
  1665. {$endif GDB}
  1666. b:=current_ppu^.readentry;
  1667. if b<>ibendimplementation then
  1668. Message1(unit_f_ppu_invalid_entry,tostr(b));
  1669. end;
  1670. destructor tunitsymtable.done;
  1671. var
  1672. pus : punitsym;
  1673. begin
  1674. pus:=unitsym;
  1675. while assigned(pus) do
  1676. begin
  1677. unitsym:=pus^.prevsym;
  1678. pus^.prevsym:=nil;
  1679. pus^.unitsymtable:=nil;
  1680. pus:=unitsym;
  1681. end;
  1682. inherited done;
  1683. end;
  1684. procedure tunitsymtable.load_symtable_refs;
  1685. var
  1686. b : byte;
  1687. unitindex : word;
  1688. begin
  1689. if ((current_module^.flags and uf_local_browser)<>0) then
  1690. begin
  1691. current_module^.localsymtable:=new(punitsymtable,loadas(staticppusymtable));
  1692. psymtable(current_module^.localsymtable)^.name:=
  1693. stringdup('implementation of '+psymtable(current_module^.globalsymtable)^.name^);
  1694. end;
  1695. { load browser }
  1696. if (current_module^.flags and uf_has_browser)<>0 then
  1697. begin
  1698. {if not (cs_browser in aktmoduleswitches) then
  1699. current_ppu^.skipuntilentry(ibendbrowser)
  1700. else }
  1701. begin
  1702. load_browser;
  1703. unitindex:=1;
  1704. while assigned(current_module^.map^[unitindex]) do
  1705. begin
  1706. {each unit wrote one browser entry }
  1707. load_browser;
  1708. inc(unitindex);
  1709. end;
  1710. b:=current_ppu^.readentry;
  1711. if b<>ibendbrowser then
  1712. Message1(unit_f_ppu_invalid_entry,tostr(b));
  1713. end;
  1714. end;
  1715. if ((current_module^.flags and uf_local_browser)<>0) then
  1716. psymtable(current_module^.localsymtable)^.load_browser;
  1717. end;
  1718. procedure tunitsymtable.writeasunit;
  1719. var
  1720. pu : pused_unit;
  1721. begin
  1722. { first the unitname }
  1723. current_ppu^.putstring(name^);
  1724. current_ppu^.writeentry(ibmodulename);
  1725. writesourcefiles;
  1726. writeusedmacros;
  1727. writeusedunit;
  1728. { write the objectfiles and libraries that come for this unit,
  1729. preserve the containers becuase they are still needed to load
  1730. the link.res. All doesn't depend on the crc! It doesn't matter
  1731. if a unit is in a .o or .a file }
  1732. current_ppu^.do_crc:=false;
  1733. writelinkcontainer(current_module^.linkunitofiles,iblinkunitofiles,true);
  1734. writelinkcontainer(current_module^.linkunitstaticlibs,iblinkunitstaticlibs,true);
  1735. writelinkcontainer(current_module^.linkunitsharedlibs,iblinkunitsharedlibs,true);
  1736. writelinkcontainer(current_module^.linkotherofiles,iblinkotherofiles,false);
  1737. writelinkcontainer(current_module^.linkotherstaticlibs,iblinkotherstaticlibs,true);
  1738. writelinkcontainer(current_module^.linkothersharedlibs,iblinkothersharedlibs,true);
  1739. current_ppu^.do_crc:=true;
  1740. current_ppu^.writeentry(ibendinterface);
  1741. { write the symtable entries }
  1742. inherited write;
  1743. { write dbx count }
  1744. {$ifdef GDB}
  1745. if cs_gdb_dbx in aktglobalswitches then
  1746. begin
  1747. {$IfDef EXTDEBUG}
  1748. writeln('Writing dbx_count ',dbx_count,' in unit ',name^,'.ppu');
  1749. {$ENDIF EXTDEBUG}
  1750. current_ppu^.putlongint(dbx_count);
  1751. current_ppu^.writeentry(ibdbxcount);
  1752. end;
  1753. {$endif GDB}
  1754. current_ppu^.writeentry(ibendimplementation);
  1755. { all after doesn't affect crc }
  1756. current_ppu^.do_crc:=false;
  1757. { write static symtable
  1758. needed for local debugging of unit functions }
  1759. if ((current_module^.flags and uf_local_browser)<>0) and
  1760. assigned(current_module^.localsymtable) then
  1761. psymtable(current_module^.localsymtable)^.write;
  1762. { write all browser section }
  1763. if (current_module^.flags and uf_has_browser)<>0 then
  1764. begin
  1765. write_browser;
  1766. pu:=pused_unit(current_module^.used_units.first);
  1767. while assigned(pu) do
  1768. begin
  1769. psymtable(pu^.u^.globalsymtable)^.write_browser;
  1770. pu:=pused_unit(pu^.next);
  1771. end;
  1772. current_ppu^.writeentry(ibendbrowser);
  1773. end;
  1774. if ((current_module^.flags and uf_local_browser)<>0) and
  1775. assigned(current_module^.localsymtable) then
  1776. psymtable(current_module^.localsymtable)^.write_browser;
  1777. { the last entry ibend is written automaticly }
  1778. end;
  1779. function tunitsymtable.getnewtypecount : word;
  1780. begin
  1781. {$ifdef GDB}
  1782. if not (cs_gdb_dbx in aktglobalswitches) then
  1783. getnewtypecount:=tsymtable.getnewtypecount
  1784. else
  1785. {$endif GDB}
  1786. if symtabletype = staticsymtable then
  1787. getnewtypecount:=tsymtable.getnewtypecount
  1788. else
  1789. begin
  1790. getnewtypecount:=unittypecount;
  1791. inc(unittypecount);
  1792. end;
  1793. end;
  1794. {$ifdef GDB}
  1795. procedure tunitsymtable.concattypestabto(asmlist : paasmoutput);
  1796. var prev_dbx_count : plongint;
  1797. begin
  1798. if is_stab_written then exit;
  1799. if not assigned(name) then name := stringdup('Main_program');
  1800. if symtabletype = unitsymtable then
  1801. begin
  1802. unitid:=current_module^.unitcount;
  1803. inc(current_module^.unitcount);
  1804. end;
  1805. asmlist^.concat(new(pai_asm_comment,init(strpnew('Begin unit '+name^
  1806. +' has index '+tostr(unitid)))));
  1807. if cs_gdb_dbx in aktglobalswitches then
  1808. begin
  1809. if dbx_count_ok then
  1810. begin
  1811. asmlist^.insert(new(pai_asm_comment,init(strpnew('"repeated" unit '+name^
  1812. +' has index '+tostr(unitid)))));
  1813. do_count_dbx:=true;
  1814. asmlist^.concat(new(pai_stabs,init(strpnew('"'+name^+'",'
  1815. +tostr(N_EXCL)+',0,0,'+tostr(dbx_count)))));
  1816. exit;
  1817. end;
  1818. prev_dbx_count := dbx_counter;
  1819. dbx_counter := nil;
  1820. if symtabletype = unitsymtable then
  1821. asmlist^.concat(new(pai_stabs,init(strpnew('"'+name^+'",'
  1822. +tostr(N_BINCL)+',0,0,0'))));
  1823. dbx_counter := @dbx_count;
  1824. end;
  1825. asmoutput:=asmlist;
  1826. foreach({$ifndef TP}@{$endif}concattypestab);
  1827. if cs_gdb_dbx in aktglobalswitches then
  1828. begin
  1829. dbx_counter := prev_dbx_count;
  1830. do_count_dbx:=true;
  1831. asmlist^.concat(new(pai_stabs,init(strpnew('"'+name^+'",'
  1832. +tostr(N_EINCL)+',0,0,0'))));
  1833. dbx_count_ok := true;
  1834. end;
  1835. asmlist^.concat(new(pai_asm_comment,init(strpnew('End unit '+name^
  1836. +' has index '+tostr(unitid)))));
  1837. is_stab_written:=true;
  1838. end;
  1839. {$endif}
  1840. {****************************************************************************
  1841. Definitions
  1842. ****************************************************************************}
  1843. {$I symdef.inc}
  1844. {****************************************************************************
  1845. Symbols
  1846. ****************************************************************************}
  1847. {$I symsym.inc}
  1848. {****************************************************************************
  1849. GDB Helpers
  1850. ****************************************************************************}
  1851. {$ifdef GDB}
  1852. function typeglobalnumber(const s : string) : string;
  1853. var st : string;
  1854. symt : psymtable;
  1855. old_make_ref : boolean;
  1856. begin
  1857. old_make_ref:=make_ref;
  1858. make_ref:=false;
  1859. typeglobalnumber := '0';
  1860. srsym := nil;
  1861. if pos('.',s) > 0 then
  1862. begin
  1863. st := copy(s,1,pos('.',s)-1);
  1864. getsym(st,false);
  1865. st := copy(s,pos('.',s)+1,255);
  1866. if assigned(srsym) then
  1867. begin
  1868. if srsym^.typ = unitsym then
  1869. begin
  1870. symt := punitsym(srsym)^.unitsymtable;
  1871. srsym := symt^.search(st);
  1872. end else srsym := nil;
  1873. end;
  1874. end else st := s;
  1875. if srsym = nil then getsym(st,true);
  1876. if srsym^.typ<>typesym then
  1877. begin
  1878. Message(type_e_type_id_expected);
  1879. exit;
  1880. end;
  1881. typeglobalnumber := ptypesym(srsym)^.definition^.numberstring;
  1882. make_ref:=old_make_ref;
  1883. end;
  1884. {$endif GDB}
  1885. {****************************************************************************
  1886. Definition Helpers
  1887. ****************************************************************************}
  1888. procedure reset_global_defs;
  1889. var
  1890. def : pdef;
  1891. {$ifdef debug}
  1892. prevdef : pdef;
  1893. {$endif debug}
  1894. begin
  1895. {$ifdef debug}
  1896. prevdef:=nil;
  1897. {$endif debug}
  1898. {$ifdef GDB}
  1899. pglobaltypecount:=@globaltypecount;
  1900. {$endif GDB}
  1901. def:=firstglobaldef;
  1902. while assigned(def) do
  1903. begin
  1904. {$ifdef GDB}
  1905. if assigned(def^.sym) then
  1906. def^.sym^.isusedinstab:=false;
  1907. def^.is_def_stab_written:=false;
  1908. {$endif GDB}
  1909. {if not current_module^.in_implementation then}
  1910. begin
  1911. { reset rangenr's }
  1912. case def^.deftype of
  1913. orddef : porddef(def)^.rangenr:=0;
  1914. enumdef : penumdef(def)^.rangenr:=0;
  1915. arraydef : parraydef(def)^.rangenr:=0;
  1916. end;
  1917. if def^.deftype<>objectdef then
  1918. def^.has_rtti:=false;
  1919. def^.has_inittable:=false;
  1920. end;
  1921. {$ifdef debug}
  1922. prevdef:=def;
  1923. {$endif debug}
  1924. def:=def^.nextglobal;
  1925. end;
  1926. end;
  1927. {****************************************************************************
  1928. Object Helpers
  1929. ****************************************************************************}
  1930. function search_class_member(pd : pobjectdef;const n : string) : psym;
  1931. { searches n in symtable of pd and all anchestors }
  1932. var
  1933. sym : psym;
  1934. begin
  1935. sym:=nil;
  1936. while assigned(pd) do
  1937. begin
  1938. sym:=pd^.symtable^.search(n);
  1939. if assigned(sym) then
  1940. break;
  1941. pd:=pd^.childof;
  1942. end;
  1943. { this is needed for static methods in do_member_read pexpr unit PM
  1944. caused bug0214 }
  1945. if assigned(sym) then
  1946. begin
  1947. srsymtable:=pd^.symtable;
  1948. end;
  1949. search_class_member:=sym;
  1950. end;
  1951. var
  1952. _defaultprop : ppropertysym;
  1953. procedure testfordefaultproperty(p : pnamedindexobject);
  1954. begin
  1955. if (psym(p)^.typ=propertysym) and
  1956. (ppo_defaultproperty in ppropertysym(p)^.propoptions) then
  1957. _defaultprop:=ppropertysym(p);
  1958. end;
  1959. function search_default_property(pd : pobjectdef) : ppropertysym;
  1960. { returns the default property of a class, searches also anchestors }
  1961. begin
  1962. _defaultprop:=nil;
  1963. while assigned(pd) do
  1964. begin
  1965. pd^.symtable^.foreach({$ifndef TP}@{$endif}testfordefaultproperty);
  1966. if assigned(_defaultprop) then
  1967. break;
  1968. pd:=pd^.childof;
  1969. end;
  1970. search_default_property:=_defaultprop;
  1971. end;
  1972. {****************************************************************************
  1973. Macro's
  1974. ****************************************************************************}
  1975. procedure def_macro(const s : string);
  1976. var
  1977. mac : pmacrosym;
  1978. begin
  1979. mac:=pmacrosym(macros^.search(s));
  1980. if mac=nil then
  1981. begin
  1982. mac:=new(pmacrosym,init(s));
  1983. Message1(parser_m_macro_defined,mac^.name);
  1984. macros^.insert(mac);
  1985. end;
  1986. mac^.defined:=true;
  1987. mac^.defined_at_startup:=true;
  1988. end;
  1989. procedure set_macro(const s : string;value : string);
  1990. var
  1991. mac : pmacrosym;
  1992. begin
  1993. mac:=pmacrosym(macros^.search(s));
  1994. if mac=nil then
  1995. begin
  1996. mac:=new(pmacrosym,init(s));
  1997. macros^.insert(mac);
  1998. end
  1999. else
  2000. begin
  2001. if assigned(mac^.buftext) then
  2002. freemem(mac^.buftext,mac^.buflen);
  2003. end;
  2004. Message2(parser_m_macro_set_to,mac^.name,value);
  2005. mac^.buflen:=length(value);
  2006. getmem(mac^.buftext,mac^.buflen);
  2007. move(value[1],mac^.buftext^,mac^.buflen);
  2008. mac^.defined:=true;
  2009. mac^.defined_at_startup:=true;
  2010. end;
  2011. {****************************************************************************
  2012. Symtable Stack
  2013. ****************************************************************************}
  2014. procedure dellexlevel;
  2015. var
  2016. p : psymtable;
  2017. begin
  2018. p:=symtablestack;
  2019. symtablestack:=p^.next;
  2020. { symbol tables of unit interfaces are never disposed }
  2021. { this is handle by the unit unitm }
  2022. if not(p^.symtabletype in [unitsymtable,globalsymtable,stt_exceptsymtable]) or dispose_global then
  2023. dispose(p,done);
  2024. end;
  2025. {$ifdef DEBUG}
  2026. procedure test_symtablestack;
  2027. var
  2028. p : psymtable;
  2029. i : longint;
  2030. begin
  2031. p:=symtablestack;
  2032. i:=0;
  2033. while assigned(p) do
  2034. begin
  2035. inc(i);
  2036. p:=p^.next;
  2037. if i>500 then
  2038. Message(sym_f_internal_error_in_symtablestack);
  2039. end;
  2040. end;
  2041. procedure list_symtablestack;
  2042. var
  2043. p : psymtable;
  2044. i : longint;
  2045. begin
  2046. p:=symtablestack;
  2047. i:=0;
  2048. while assigned(p) do
  2049. begin
  2050. inc(i);
  2051. writeln(i,' ',p^.name^);
  2052. p:=p^.next;
  2053. if i>500 then
  2054. Message(sym_f_internal_error_in_symtablestack);
  2055. end;
  2056. end;
  2057. {$endif DEBUG}
  2058. {****************************************************************************
  2059. Init/Done Symtable
  2060. ****************************************************************************}
  2061. {$ifndef Delphi}
  2062. {$ifdef tp}
  2063. procedure do_streamerror;
  2064. begin
  2065. if symbolstream.status=-2 then
  2066. WriteLn('Error: Not enough EMS memory')
  2067. else
  2068. WriteLn('Error: EMS Error ',symbolstream.status);
  2069. halt(1);
  2070. end;
  2071. {$endif TP}
  2072. {$endif Delphi}
  2073. procedure InitSymtable;
  2074. begin
  2075. {$ifndef Delphi}
  2076. {$ifdef TP}
  2077. { Allocate stream }
  2078. if use_big then
  2079. begin
  2080. streamerror:=@do_streamerror;
  2081. { symbolstream.init('TMPFILE',stcreate,16000); }
  2082. {$ifndef dpmi}
  2083. symbolstream.init(10000,4000000); {using ems streams}
  2084. {$else}
  2085. symbolstream.init(1000000,16000); {using memory streams}
  2086. {$endif}
  2087. if symbolstream.errorinfo=stiniterror then
  2088. do_streamerror;
  2089. { write something, because pos 0 means nil pointer }
  2090. symbolstream.writestr(@inputfile);
  2091. end;
  2092. {$endif tp}
  2093. {$endif Delphi}
  2094. { Reset symbolstack }
  2095. registerdef:=false;
  2096. read_member:=false;
  2097. symtablestack:=nil;
  2098. systemunit:=nil;
  2099. objpasunit:=nil;
  2100. sroot:=nil;
  2101. {$ifdef GDB}
  2102. firstglobaldef:=nil;
  2103. lastglobaldef:=nil;
  2104. {$endif GDB}
  2105. globaltypecount:=1;
  2106. pglobaltypecount:=@globaltypecount;
  2107. { create error syms and def }
  2108. generrorsym:=new(perrorsym,init);
  2109. generrordef:=new(perrordef,init);
  2110. end;
  2111. procedure DoneSymtable;
  2112. begin
  2113. dispose(generrorsym,done);
  2114. dispose(generrordef,done);
  2115. { unload all symtables
  2116. done with loaded_units
  2117. dispose_global:=true;
  2118. while assigned(symtablestack) do
  2119. dellexlevel; }
  2120. {$ifndef Delphi}
  2121. {$ifdef TP}
  2122. { close the stream }
  2123. if use_big then
  2124. symbolstream.done;
  2125. {$endif}
  2126. {$endif Delphi}
  2127. end;
  2128. end.
  2129. {
  2130. $Log$
  2131. Revision 1.46 1999-09-10 18:48:10 florian
  2132. * some bug fixes (e.g. must_be_valid and procinfo.funcret_is_valid)
  2133. * most things for stored properties fixed
  2134. Revision 1.45 1999/09/08 08:05:44 peter
  2135. * fixed bug 248
  2136. Revision 1.44 1999/08/31 15:46:21 pierre
  2137. * do_crc must be false for all browser stuff
  2138. + tmacrosym defined_at_startup set in def_macro and set_macro
  2139. Revision 1.43 1999/08/27 10:39:24 pierre
  2140. * uf_local_browser made problem when computing interface CRC
  2141. Revision 1.42 1999/08/13 21:33:13 peter
  2142. * support for array constructors extended and more error checking
  2143. Revision 1.41 1999/08/13 14:24:22 pierre
  2144. + stabs for classes and classref working,
  2145. a class still needs an ^ to get that content of it,
  2146. but the class fields inside a class don't result into an
  2147. infinite loop anymore!
  2148. Revision 1.40 1999/08/10 16:25:42 pierre
  2149. * unitid changed to word
  2150. Revision 1.39 1999/08/10 12:33:36 pierre
  2151. * pprocsym defined earlier for use in tprocdef
  2152. Revision 1.38 1999/08/05 16:53:18 peter
  2153. * V_Fatal=1, all other V_ are also increased
  2154. * Check for local procedure when assigning procvar
  2155. * fixed comment parsing because directives
  2156. * oldtp mode directives better supported
  2157. * added some messages to errore.msg
  2158. Revision 1.37 1999/08/04 13:03:09 jonas
  2159. * all tokens now start with an underscore
  2160. * PowerPC compiles!!
  2161. Revision 1.36 1999/08/04 00:23:31 florian
  2162. * renamed i386asm and i386base to cpuasm and cpubase
  2163. Revision 1.35 1999/08/03 22:03:22 peter
  2164. * moved bitmask constants to sets
  2165. * some other type/const renamings
  2166. Revision 1.34 1999/08/03 17:51:45 florian
  2167. * reduced memory usage by factor 2-3 (it
  2168. improved also the speed) by reducing the
  2169. growsize of the symbol tables
  2170. Revision 1.33 1999/08/03 00:03:24 florian
  2171. * added bestrealdef for alpha and powerpc
  2172. Revision 1.32 1999/08/01 23:09:27 michael
  2173. * procbase -> cpubase
  2174. Revision 1.31 1999/08/01 23:04:50 michael
  2175. + Changes for Alpha
  2176. Revision 1.30 1999/07/24 00:13:26 peter
  2177. * also number units for program
  2178. Revision 1.29 1999/07/23 16:05:33 peter
  2179. * alignment is now saved in the symtable
  2180. * C alignment added for records
  2181. * PPU version increased to solve .12 <-> .13 probs
  2182. Revision 1.28 1999/07/23 12:02:20 peter
  2183. * fixed crash in previous commit
  2184. Revision 1.27 1999/07/23 11:37:50 peter
  2185. * error for illegal type reference, instead of 10998
  2186. Revision 1.26 1999/07/22 09:37:58 florian
  2187. + resourcestring implemented
  2188. + start of longstring support
  2189. Revision 1.25 1999/07/18 14:47:34 florian
  2190. * bug 487 fixed, (inc(<property>) isn't allowed)
  2191. * more fixes to compile with Delphi
  2192. Revision 1.24 1999/07/03 00:30:01 peter
  2193. * new link writing to the ppu, one .ppu is needed for all link types,
  2194. static (.o) is now always created also when smartlinking is used
  2195. Revision 1.23 1999/06/28 17:02:44 pierre
  2196. merged from v0-99-12 branch
  2197. Revision 1.21.2.2 1999/06/28 16:59:55 pierre
  2198. * fix to get method reference info
  2199. Revision 1.21.2.1 1999/06/22 16:26:46 pierre
  2200. * local browser stuff corrected
  2201. Revision 1.21 1999/06/08 22:23:50 pierre
  2202. * staticppusymtable was loaded a tsymtable instead of tunitsymtable
  2203. Revision 1.20 1999/06/02 22:44:23 pierre
  2204. * previous wrong log corrected
  2205. Revision 1.19 1999/06/02 22:25:53 pierre
  2206. * changed $ifdef FPC @ into $ifndef TP
  2207. Revision 1.18 1999/06/01 14:45:58 peter
  2208. * @procvar is now always needed for FPC
  2209. Revision 1.17 1999/05/27 19:45:08 peter
  2210. * removed oldasm
  2211. * plabel -> pasmlabel
  2212. * -a switches to source writing automaticly
  2213. * assembler readers OOPed
  2214. * asmsymbol automaticly external
  2215. * jumptables and other label fixes for asm readers
  2216. Revision 1.16 1999/05/23 18:42:16 florian
  2217. * better error recovering in typed constants
  2218. * some problems with arrays of const fixed, some problems
  2219. due my previous
  2220. - the location type of array constructor is now LOC_MEM
  2221. - the pushing of high fixed
  2222. - parameter copying fixed
  2223. - zero temp. allocation removed
  2224. * small problem in the assembler writers fixed:
  2225. ref to nil wasn't written correctly
  2226. Revision 1.15 1999/05/17 23:51:41 peter
  2227. * with temp vars now use a reference with a persistant temp instead
  2228. of setting datasize
  2229. Revision 1.14 1999/05/14 17:52:29 peter
  2230. * new deref code
  2231. Revision 1.13 1999/05/13 21:59:48 peter
  2232. * removed oldppu code
  2233. * warning if objpas is loaded from uses
  2234. * first things for new deref writing
  2235. Revision 1.12 1999/05/10 22:34:59 pierre
  2236. * one more unitsym problem fix
  2237. Revision 1.11 1999/05/10 15:02:51 pierre
  2238. unitsym finally problem fixed
  2239. Revision 1.10 1999/05/09 12:46:26 peter
  2240. + hint where a duplicate sym is already defined
  2241. Revision 1.9 1999/05/08 19:52:40 peter
  2242. + MessagePos() which is enhanced Message() function but also gets the
  2243. position info
  2244. * Removed comp warnings
  2245. Revision 1.8 1999/05/06 21:38:38 peter
  2246. * don't register errordef
  2247. Revision 1.7 1999/05/06 09:05:31 peter
  2248. * generic write_float and str_float
  2249. * fixed constant float conversions
  2250. Revision 1.6 1999/05/05 09:19:16 florian
  2251. * more fixes to get it with delphi running
  2252. Revision 1.5 1999/05/01 13:24:43 peter
  2253. * merged nasm compiler
  2254. * old asm moved to oldasm/
  2255. Revision 1.4 1999/04/29 17:25:37 peter
  2256. * small fix for deref
  2257. Revision 1.3 1999/04/26 18:30:03 peter
  2258. * farpointerdef moved into pointerdef.is_far
  2259. Revision 1.151 1999/04/26 13:31:54 peter
  2260. * release storenumber,double_checksum
  2261. Revision 1.150 1999/04/25 17:36:13 peter
  2262. * typo fix for storenumber
  2263. Revision 1.149 1999/04/21 22:05:28 pierre
  2264. + tsymtable.find_at_offset function
  2265. used by ra386att to give arg name from ebp offset with -vz option
  2266. Revision 1.148 1999/04/21 16:31:44 pierre
  2267. ra386att.pas : commit problem !
  2268. Revision 1.147 1999/04/21 09:43:57 peter
  2269. * storenumber works
  2270. * fixed some typos in double_checksum
  2271. + incompatible types type1 and type2 message (with storenumber)
  2272. Revision 1.146 1999/04/19 09:33:14 pierre
  2273. + added tsymtable.set_alignment(longint) function
  2274. to change the offsets of all function args
  2275. if declared as cdecl or stdcall
  2276. (this must be done after because the cdecl is parsed after
  2277. insertion of the function parameterss into parast symboltable)
  2278. Revision 1.145 1999/04/17 13:16:24 peter
  2279. * fixes for storenumber
  2280. Revision 1.144 1999/04/15 10:01:45 peter
  2281. * small update for storenumber
  2282. Revision 1.143 1999/04/14 09:15:04 peter
  2283. * first things to store the symbol/def number in the ppu
  2284. Revision 1.142 1999/04/08 14:54:10 pierre
  2285. * suppression of val para unused warnings
  2286. Revision 1.141 1999/04/07 15:31:09 pierre
  2287. * all formaldefs are now a sinlge definition
  2288. cformaldef (this was necessary for double_checksum)
  2289. + small part of double_checksum code
  2290. Revision 1.140 1999/03/31 13:55:24 peter
  2291. * assembler inlining working for ag386bin
  2292. Revision 1.139 1999/03/24 23:17:30 peter
  2293. * fixed bugs 212,222,225,227,229,231,233
  2294. Revision 1.138 1999/03/21 22:49:11 florian
  2295. * private ids of objects can be reused in child classes
  2296. if they are in another unit
  2297. Revision 1.137 1999/03/17 22:23:20 florian
  2298. * a FPC compiled compiler checks now also in debug mode in assigned
  2299. if a pointer points to the heap
  2300. * when a symtable is loaded, there is no need to check for duplicate
  2301. symbols. This leads to crashes because defowner isn't assigned
  2302. in this case
  2303. Revision 1.136 1999/03/01 13:45:07 pierre
  2304. + added staticppusymtable symtable type for local browsing
  2305. Revision 1.135 1999/02/23 18:29:28 pierre
  2306. * win32 compilation error fix
  2307. + some work for local browser (not cl=omplete yet)
  2308. Revision 1.134 1999/02/22 15:09:42 florian
  2309. * behaviaor of PROTECTED and PRIVATE fixed, works now like TP/Delphi
  2310. Revision 1.133 1999/02/22 13:07:12 pierre
  2311. + -b and -bl options work !
  2312. + cs_local_browser ($L+) is disabled if cs_browser ($Y+)
  2313. is not enabled when quitting global section
  2314. * local vars and procedures are not yet stored into PPU
  2315. Revision 1.132 1999/02/22 02:15:40 peter
  2316. * updates for ag386bin
  2317. Revision 1.131 1999/02/16 00:44:34 peter
  2318. * tp7 fix, assigned() can only be used on vars, not on functions
  2319. Revision 1.130 1999/02/15 13:13:16 pierre
  2320. * fix for bug0216
  2321. Revision 1.129 1999/02/11 09:46:29 pierre
  2322. * fix for normal method calls inside static methods :
  2323. WARNING there were both parser and codegen errors !!
  2324. added static_call boolean to calln tree
  2325. Revision 1.128 1999/02/09 23:03:05 florian
  2326. * check for duplicate field names in inherited classes/objects
  2327. * bug with self from the mailing list solved (the problem
  2328. was that classes were sometimes pushed wrong)
  2329. Revision 1.127 1999/02/08 11:29:06 pierre
  2330. * fix for bug0214
  2331. several problems where combined
  2332. search_class_member did not set srsymtable
  2333. => in do_member_read the call node got a wrong symtable
  2334. in cg386cal the vmt was pushed twice without chacking if it exists
  2335. now %esi is set to zero and pushed if not vmt
  2336. (not very efficient but should work !)
  2337. Revision 1.126 1999/02/05 08:54:31 pierre
  2338. + linkofiles splitted inot linkofiles and linkunitfiles
  2339. because linkofiles must be stored with directory
  2340. to enabled linking of different objects with same name
  2341. in a different directory
  2342. Revision 1.125 1999/02/03 09:44:33 pierre
  2343. * symbol nubering begins with 1 in number_symbols
  2344. * program tmodule has globalsymtable for its staticsymtable
  2345. (to get it displayed in IDE globals list)
  2346. + list of symbol (browcol) greatly improved for IDE
  2347. Revision 1.124 1999/01/27 12:58:33 pierre
  2348. * unused var warning suppressed for high of open arrays
  2349. Revision 1.123 1999/01/21 16:41:03 pierre
  2350. * fix for constructor inside with statements
  2351. Revision 1.122 1999/01/20 10:16:44 peter
  2352. * don't update crc when writing objs,libs and sources
  2353. Revision 1.121 1999/01/14 21:50:00 peter
  2354. * fixed forwardpointer problem with multiple forwards for the same
  2355. typesym. It now uses a linkedlist instead of a single pointer
  2356. Revision 1.120 1999/01/13 14:29:22 daniel
  2357. * nonextfield repaired
  2358. Revision 1.119 1999/01/12 14:25:38 peter
  2359. + BrowserLog for browser.log generation
  2360. + BrowserCol for browser info in TCollections
  2361. * released all other UseBrowser
  2362. Revision 1.118 1999/01/05 08:20:10 florian
  2363. * mainly problem with invalid case ranges fixed (reported by Jonas)
  2364. Revision 1.117 1998/12/30 22:15:57 peter
  2365. + farpointer type
  2366. * absolutesym now also stores if its far
  2367. Revision 1.116 1998/12/30 13:41:16 peter
  2368. * released valuepara
  2369. Revision 1.115 1998/12/11 00:03:48 peter
  2370. + globtype,tokens,version unit splitted from globals
  2371. Revision 1.114 1998/12/10 09:47:29 florian
  2372. + basic operations with int64/qord (compiler with -dint64)
  2373. + rtti of enumerations extended: names are now written
  2374. Revision 1.113 1998/12/08 10:18:17 peter
  2375. + -gh for heaptrc unit
  2376. Revision 1.112 1998/12/04 10:18:10 florian
  2377. * some stuff for procedures of object added
  2378. * bug with overridden virtual constructors fixed (reported by Italo Gomes)
  2379. Revision 1.111 1998/11/30 16:34:46 pierre
  2380. * corrected problems with rangecheck
  2381. + added needed code for no rangecheck in CRC32 functions in ppu unit
  2382. * enumdef lso need its rangenr reset to zero
  2383. when calling reset_global_defs
  2384. Revision 1.110 1998/11/28 16:20:58 peter
  2385. + support for dll variables
  2386. Revision 1.109 1998/11/27 14:50:49 peter
  2387. + open strings, $P switch support
  2388. Revision 1.108 1998/11/24 23:00:32 peter
  2389. * small crash prevention
  2390. Revision 1.107 1998/11/20 15:36:01 florian
  2391. * problems with rtti fixed, hope it works
  2392. Revision 1.106 1998/11/18 15:44:20 peter
  2393. * VALUEPARA for tp7 compatible value parameters
  2394. Revision 1.105 1998/11/17 10:39:18 peter
  2395. * has_rtti,has_inittable reset
  2396. Revision 1.104 1998/11/16 10:13:52 peter
  2397. * label defines are checked at the end of the proc
  2398. Revision 1.103 1998/11/13 15:40:32 pierre
  2399. + added -Se in Makefile cvstest target
  2400. + lexlevel cleanup
  2401. normal_function_level main_program_level and unit_init_level defined
  2402. * tins_cache grown to A_EMMS (gave range check error in asm readers)
  2403. (test added in code !)
  2404. * -Un option was wrong
  2405. * _FAIL and _SELF only keyword inside
  2406. constructors and methods respectively
  2407. Revision 1.102 1998/11/12 16:43:34 florian
  2408. * functions with ansi strings as result didn't work, solved
  2409. Revision 1.101 1998/11/12 12:55:18 pierre
  2410. * fix for bug0176 and bug0177
  2411. Revision 1.100 1998/11/10 10:09:15 peter
  2412. * va_list -> array of const
  2413. Revision 1.99 1998/11/09 11:44:38 peter
  2414. + va_list for printf support
  2415. Revision 1.98 1998/11/05 23:33:35 peter
  2416. * symtable.done sets vars to nil
  2417. Revision 1.97 1998/11/05 12:03:00 peter
  2418. * released useansistring
  2419. * removed -Sv, its now available in fpc modes
  2420. Revision 1.96 1998/10/28 18:26:19 pierre
  2421. * removed some erros after other errors (introduced by useexcept)
  2422. * stabs works again correctly (for how long !)
  2423. Revision 1.95 1998/10/21 08:40:01 florian
  2424. + ansistring operator +
  2425. + $h and string[n] for n>255 added
  2426. * small problem with TP fixed
  2427. Revision 1.94 1998/10/20 08:07:03 pierre
  2428. * several memory corruptions due to double freemem solved
  2429. => never use p^.loc.location:=p^.left^.loc.location;
  2430. + finally I added now by default
  2431. that ra386dir translates global and unit symbols
  2432. + added a first field in tsymtable and
  2433. a nextsym field in tsym
  2434. (this allows to obtain ordered type info for
  2435. records and objects in gdb !)
  2436. Revision 1.93 1998/10/19 08:55:08 pierre
  2437. * wrong stabs info corrected once again !!
  2438. + variable vmt offset with vmt field only if required
  2439. implemented now !!!
  2440. Revision 1.92 1998/10/16 13:12:56 pierre
  2441. * added vmt_offsets in destructors code also !!!
  2442. * vmt_offset code for m68k
  2443. Revision 1.91 1998/10/16 08:48:38 peter
  2444. * fixed some misplaced $endif GDB
  2445. Revision 1.90 1998/10/15 15:13:32 pierre
  2446. + added oo_hasconstructor and oo_hasdestructor
  2447. for objects options
  2448. Revision 1.89 1998/10/14 13:38:25 peter
  2449. * fixed path with staticlib/objects in ppufiles
  2450. Revision 1.88 1998/10/09 16:36:07 pierre
  2451. * some memory leaks specific to usebrowser define fixed
  2452. * removed tmodule.implsymtable (was like tmodule.localsymtable)
  2453. Revision 1.87 1998/10/09 11:47:57 pierre
  2454. * still more memory leaks fixes !!
  2455. Revision 1.86 1998/10/08 17:17:35 pierre
  2456. * current_module old scanner tagged as invalid if unit is recompiled
  2457. + added ppheap for better info on tracegetmem of heaptrc
  2458. (adds line column and file index)
  2459. * several memory leaks removed ith help of heaptrc !!
  2460. Revision 1.85 1998/10/08 13:48:51 peter
  2461. * fixed memory leaks for do nothing source
  2462. * fixed unit interdependency
  2463. Revision 1.84 1998/10/06 17:16:58 pierre
  2464. * some memory leaks fixed (thanks to Peter for heaptrc !)
  2465. Revision 1.83 1998/09/26 17:45:45 peter
  2466. + idtoken and only one token table
  2467. Revision 1.82 1998/09/25 09:52:57 peter
  2468. + store also datasize and # of symbols in ppu
  2469. * # of defs is now also stored in structs
  2470. Revision 1.81 1998/09/24 23:49:21 peter
  2471. + aktmodeswitches
  2472. Revision 1.80 1998/09/23 12:20:51 pierre
  2473. * main program tmodule had no symtable (crashed browser)
  2474. * unit symbols problem fixed !!
  2475. Revision 1.79 1998/09/23 12:03:57 peter
  2476. * overloading fix for array of const
  2477. Revision 1.78 1998/09/22 17:13:54 pierre
  2478. + browsing updated and developed
  2479. records and objects fields are also stored
  2480. Revision 1.77 1998/09/22 15:37:24 peter
  2481. + array of const start
  2482. Revision 1.76 1998/09/21 10:00:08 peter
  2483. * store number of defs in ppu file
  2484. Revision 1.75 1998/09/21 08:58:31 peter
  2485. + speedsearch, which also needs speedvalue as parameter
  2486. Revision 1.74 1998/09/21 08:45:25 pierre
  2487. + added vmt_offset in tobjectdef.write for fututre use
  2488. (first steps to have objects without vmt if no virtual !!)
  2489. + added fpu_used field for tabstractprocdef :
  2490. sets this level to 2 if the functions return with value in FPU
  2491. (is then set to correct value at parsing of implementation)
  2492. THIS MIGHT refuse some code with FPU expression too complex
  2493. that were accepted before and even in some cases
  2494. that don't overflow in fact
  2495. ( like if f : float; is a forward that finally in implementation
  2496. only uses one fpu register !!)
  2497. Nevertheless I think that it will improve security on
  2498. FPU operations !!
  2499. * most other changes only for UseBrowser code
  2500. (added symtable references for record and objects)
  2501. local switch for refs to args and local of each function
  2502. (static symtable still missing)
  2503. UseBrowser still not stable and probably broken by
  2504. the definition hash array !!
  2505. Revision 1.73 1998/09/20 09:38:47 florian
  2506. * hasharray for defs fixed
  2507. * ansistring code generation corrected (init/final, assignement)
  2508. Revision 1.72 1998/09/19 22:56:18 florian
  2509. + hash table for getdefnr added
  2510. Revision 1.71 1998/09/18 08:01:40 pierre
  2511. + improvement on the usebrowser part
  2512. (does not work correctly for now)
  2513. Revision 1.70 1998/09/09 11:50:57 pierre
  2514. * forward def are not put in record or objects
  2515. + added check for forwards also in record and objects
  2516. * dummy parasymtable for unit initialization removed from
  2517. symtable stack
  2518. Revision 1.69 1998/09/07 23:10:25 florian
  2519. * a lot of stuff fixed regarding rtti and publishing of properties,
  2520. basics should now work
  2521. Revision 1.68 1998/09/07 19:33:26 florian
  2522. + some stuff for property rtti added:
  2523. - NameIndex of the TPropInfo record is now written correctly
  2524. - the DEFAULT/NODEFAULT keyword is supported now
  2525. - the default value and the storedsym/def are now written to
  2526. the PPU fiel
  2527. Revision 1.67 1998/09/07 18:46:14 peter
  2528. * update smartlinking, uses getdatalabel
  2529. * renamed ptree.value vars to value_str,value_real,value_set
  2530. Revision 1.66 1998/09/07 17:37:05 florian
  2531. * first fixes for published properties
  2532. Revision 1.65 1998/09/06 22:42:03 florian
  2533. + rtti genreation for properties added
  2534. Revision 1.64 1998/09/05 22:11:04 florian
  2535. + switch -vb
  2536. * while/repeat loops accept now also word/longbool conditions
  2537. * makebooltojump did an invalid ungetregister32, fixed
  2538. Revision 1.63 1998/09/04 17:34:23 pierre
  2539. * bug with datalabel corrected
  2540. + assembler errors better commented
  2541. * one nested record crash removed
  2542. Revision 1.62 1998/09/04 08:42:10 peter
  2543. * updated some error messages
  2544. Revision 1.61 1998/09/03 16:03:21 florian
  2545. + rtti generation
  2546. * init table generation changed
  2547. Revision 1.60 1998/09/01 17:39:52 peter
  2548. + internal constant functions
  2549. Revision 1.59 1998/09/01 12:53:27 peter
  2550. + aktpackenum
  2551. Revision 1.58 1998/09/01 07:54:26 pierre
  2552. * UseBrowser a little updated (might still be buggy !!)
  2553. * bug in psub.pas in function specifier removed
  2554. * stdcall allowed in interface and in implementation
  2555. (FPC will not yet complain if it is missing in either part
  2556. because stdcall is only a dummy !!)
  2557. Revision 1.57 1998/08/31 12:26:33 peter
  2558. * m68k and palmos updates from surebugfixes
  2559. Revision 1.56 1998/08/21 14:08:55 pierre
  2560. + TEST_FUNCRET now default (old code removed)
  2561. works also for m68k (at least compiles)
  2562. Revision 1.55 1998/08/21 08:43:32 pierre
  2563. * pocdecl and poclearstack are now different
  2564. external must but written as last specification
  2565. Revision 1.54 1998/08/20 09:26:48 pierre
  2566. + funcret setting in underproc testing
  2567. compile with _dTEST_FUNCRET
  2568. Revision 1.53 1998/08/19 18:04:56 peter
  2569. * fixed current_module^.in_implementation flag
  2570. Revision 1.51 1998/08/18 14:17:12 pierre
  2571. * bug about assigning the return value of a function to
  2572. a procvar fixed : warning
  2573. assigning a proc to a procvar need @ in FPC mode !!
  2574. * missing file/line info restored
  2575. Revision 1.50 1998/08/17 10:10:13 peter
  2576. - removed OLDPPU
  2577. Revision 1.49 1998/08/12 19:39:31 peter
  2578. * fixed some crashes
  2579. Revision 1.48 1998/08/10 14:50:32 peter
  2580. + localswitches, moduleswitches, globalswitches splitting
  2581. Revision 1.47 1998/08/10 10:00:19 peter
  2582. * Moved symbolstream to symtable.pas
  2583. Revision 1.46 1998/08/08 10:19:19 florian
  2584. * small fixes to write the extended type correct
  2585. Revision 1.45 1998/08/02 16:42:00 florian
  2586. * on o : tobject do should also work now, the exceptsymtable shouldn't be
  2587. disposed by dellexlevel
  2588. Revision 1.44 1998/07/30 11:18:21 florian
  2589. + first implementation of try ... except on .. do end;
  2590. * limitiation of 65535 bytes parameters for cdecl removed
  2591. Revision 1.43 1998/07/28 21:52:56 florian
  2592. + implementation of raise and try..finally
  2593. + some misc. exception stuff
  2594. Revision 1.42 1998/07/20 10:23:03 florian
  2595. * better ansi string assignement
  2596. Revision 1.41 1998/07/18 22:54:31 florian
  2597. * some ansi/wide/longstring support fixed:
  2598. o parameter passing
  2599. o returning as result from functions
  2600. Revision 1.40 1998/07/14 14:47:09 peter
  2601. * released NEWINPUT
  2602. Revision 1.39 1998/07/10 00:00:06 peter
  2603. * fixed ttypesym bug finally
  2604. * fileinfo in the symtable and better using for unused vars
  2605. Revision 1.38 1998/07/07 11:20:17 peter
  2606. + NEWINPUT for a better inputfile and scanner object
  2607. Revision 1.37 1998/06/24 14:48:42 peter
  2608. * ifdef newppu -> ifndef oldppu
  2609. Revision 1.36 1998/06/17 14:10:19 peter
  2610. * small os2 fixes
  2611. * fixed interdependent units with newppu (remake3 under linux works now)
  2612. Revision 1.35 1998/06/16 08:56:35 peter
  2613. + targetcpu
  2614. * cleaner pmodules for newppu
  2615. Revision 1.34 1998/06/15 15:38:12 pierre
  2616. * small bug in systems.pas corrected
  2617. + operators in different units better hanlded
  2618. Revision 1.33 1998/06/15 14:10:53 daniel
  2619. * File was ruined, fixed.
  2620. Revision 1.31 1998/06/13 00:10:20 peter
  2621. * working browser and newppu
  2622. * some small fixes against crashes which occured in bp7 (but not in
  2623. fpc?!)
  2624. Revision 1.30 1998/06/09 16:01:53 pierre
  2625. + added procedure directive parsing for procvars
  2626. (accepted are popstack cdecl and pascal)
  2627. + added C vars with the following syntax
  2628. var C calias 'true_c_name';(can be followed by external)
  2629. reason is that you must add the Cprefix
  2630. which is target dependent
  2631. Revision 1.29 1998/06/07 15:30:26 florian
  2632. + first working rtti
  2633. + data init/final. for local variables
  2634. Revision 1.28 1998/06/06 09:27:39 peter
  2635. * new depend file generated
  2636. Revision 1.27 1998/06/05 14:37:38 pierre
  2637. * fixes for inline for operators
  2638. * inline procedure more correctly restricted
  2639. Revision 1.26 1998/06/04 23:52:03 peter
  2640. * m68k compiles
  2641. + .def file creation moved to gendef.pas so it could also be used
  2642. for win32
  2643. Revision 1.25 1998/06/04 09:55:48 pierre
  2644. * demangled name of procsym reworked to become independant of the
  2645. mangling scheme
  2646. Revision 1.24 1998/06/03 22:49:04 peter
  2647. + wordbool,longbool
  2648. * rename bis,von -> high,low
  2649. * moved some systemunit loading/creating to psystem.pas
  2650. Revision 1.23 1998/05/28 14:40:30 peter
  2651. * fixes for newppu, remake3 works now with it
  2652. Revision 1.22 1998/05/27 19:45:09 peter
  2653. * symtable.pas splitted into includefiles
  2654. * symtable adapted for $ifndef OLDPPU
  2655. Revision 1.21 1998/05/23 01:21:31 peter
  2656. + aktasmmode, aktoptprocessor, aktoutputformat
  2657. + smartlink per module $SMARTLINK-/+ (like MMX) and moved to aktswitches
  2658. + $LIBNAME to set the library name where the unit will be put in
  2659. * splitted cgi386 a bit (codeseg to large for bp7)
  2660. * nasm, tasm works again. nasm moved to ag386nsm.pas
  2661. Revision 1.20 1998/05/21 19:33:37 peter
  2662. + better procedure directive handling and only one table
  2663. Revision 1.19 1998/05/20 09:42:37 pierre
  2664. + UseTokenInfo now default
  2665. * unit in interface uses and implementation uses gives error now
  2666. * only one error for unknown symbol (uses lastsymknown boolean)
  2667. the problem came from the label code !
  2668. + first inlined procedures and function work
  2669. (warning there might be allowed cases were the result is still wrong !!)
  2670. * UseBrower updated gives a global list of all position of all used symbols
  2671. with switch -gb
  2672. Revision 1.18 1998/05/11 13:07:57 peter
  2673. + $ifndef OLDPPU for the new ppuformat
  2674. + $define GDB not longer required
  2675. * removed all warnings and stripped some log comments
  2676. * no findfirst/findnext anymore to remove smartlink *.o files
  2677. Revision 1.17 1998/05/06 08:38:48 pierre
  2678. * better position info with UseTokenInfo
  2679. UseTokenInfo greatly simplified
  2680. + added check for changed tree after first time firstpass
  2681. (if we could remove all the cases were it happen
  2682. we could skip all firstpass if firstpasscount > 1)
  2683. Only with ExtDebug
  2684. Revision 1.16 1998/05/05 15:24:20 michael
  2685. * Fix to save units with classes.
  2686. Revision 1.15 1998/05/04 17:54:29 peter
  2687. + smartlinking works (only case jumptable left todo)
  2688. * redesign of systems.pas to support assemblers and linkers
  2689. + Unitname is now also in the PPU-file, increased version to 14
  2690. Revision 1.14 1998/05/01 16:38:46 florian
  2691. * handling of private and protected fixed
  2692. + change_keywords_to_tp implemented to remove
  2693. keywords which aren't supported by tp
  2694. * break and continue are now symbols of the system unit
  2695. + widestring, longstring and ansistring type released
  2696. Revision 1.13 1998/05/01 09:01:25 florian
  2697. + correct semantics of private and protected
  2698. * small fix in variable scope:
  2699. a id can be used in a parameter list of a method, even it is used in
  2700. an anchestor class as field id
  2701. Revision 1.12 1998/05/01 07:43:57 florian
  2702. + basics for rtti implemented
  2703. + switch $m (generate rtti for published sections)
  2704. Revision 1.11 1998/04/30 15:59:42 pierre
  2705. * GDB works again better :
  2706. correct type info in one pass
  2707. + UseTokenInfo for better source position
  2708. * fixed one remaining bug in scanner for line counts
  2709. * several little fixes
  2710. Revision 1.10 1998/04/29 10:34:05 pierre
  2711. + added some code for ansistring (not complete nor working yet)
  2712. * corrected operator overloading
  2713. * corrected nasm output
  2714. + started inline procedures
  2715. + added starstarn : use ** for exponentiation (^ gave problems)
  2716. + started UseTokenInfo cond to get accurate positions
  2717. Revision 1.9 1998/04/27 23:10:29 peter
  2718. + new scanner
  2719. * $makelib -> if smartlink
  2720. * small filename fixes pmodule.setfilename
  2721. * moved import from files.pas -> import.pas
  2722. Revision 1.8 1998/04/21 10:16:48 peter
  2723. * patches from strasbourg
  2724. * objects is not used anymore in the fpc compiled version
  2725. Revision 1.7 1998/04/13 22:20:36 florian
  2726. + stricter checking for duplicate id, solves also bug0097
  2727. Revision 1.6 1998/04/13 17:20:43 florian
  2728. * tdef.done much faster implemented
  2729. Revision 1.5 1998/04/10 21:36:56 florian
  2730. + some stuff to support method pointers (procedure of object) added
  2731. (declaration, parameter handling)
  2732. Revision 1.4 1998/04/08 16:58:08 pierre
  2733. * several bugfixes
  2734. ADD ADC and AND are also sign extended
  2735. nasm output OK (program still crashes at end
  2736. and creates wrong assembler files !!)
  2737. procsym types sym in tdef removed !!
  2738. Revision 1.3 1998/04/07 13:19:52 pierre
  2739. * bugfixes for reset_gdb_info
  2740. in MEM parsing for go32v2
  2741. better external symbol creation
  2742. support for rhgdb.exe (lowercase file names)
  2743. Revision 1.2 1998/04/06 13:09:04 daniel
  2744. * Emergency solution for bug in reset_gdb_info.
  2745. }