symtable.pas 98 KB

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