symtable.pas 98 KB

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