symtable.pas 91 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784
  1. {
  2. $Id$
  3. Copyright (c) 1998-2002 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. unit symtable;
  19. {$i fpcdefs.inc}
  20. interface
  21. uses
  22. { common }
  23. cutils,cclasses,
  24. { global }
  25. cpuinfo,globtype,tokens,
  26. { symtable }
  27. symconst,symbase,symtype,symdef,symsym,
  28. { ppu }
  29. ppu,
  30. { assembler }
  31. aasmtai
  32. ;
  33. {****************************************************************************
  34. Symtable types
  35. ****************************************************************************}
  36. type
  37. tstoredsymtable = class(tsymtable)
  38. private
  39. b_needs_init_final : boolean;
  40. procedure _needs_init_final(p : tnamedindexitem;arg:pointer);
  41. procedure check_forward(sym : TNamedIndexItem;arg:pointer);
  42. procedure labeldefined(p : TNamedIndexItem;arg:pointer);
  43. procedure varsymbolused(p : TNamedIndexItem;arg:pointer);
  44. procedure TestPrivate(p : TNamedIndexItem;arg:pointer);
  45. procedure objectprivatesymbolused(p : TNamedIndexItem;arg:pointer);
  46. {$ifdef GDB}
  47. private
  48. procedure concatstab(p : TNamedIndexItem;arg:pointer);
  49. procedure resetstab(p : TNamedIndexItem;arg:pointer);
  50. procedure concattypestab(p : TNamedIndexItem;arg:pointer);
  51. {$endif}
  52. procedure unchain_overloads(p : TNamedIndexItem;arg:pointer);
  53. procedure loaddefs(ppufile:tcompilerppufile);
  54. procedure loadsyms(ppufile:tcompilerppufile);
  55. procedure reset_def(def:Tnamedindexitem;arg:pointer);
  56. procedure writedefs(ppufile:tcompilerppufile);
  57. procedure writesyms(ppufile:tcompilerppufile);
  58. public
  59. { load/write }
  60. procedure ppuload(ppufile:tcompilerppufile);virtual;
  61. procedure ppuwrite(ppufile:tcompilerppufile);virtual;
  62. procedure load_references(ppufile:tcompilerppufile;locals:boolean);virtual;
  63. procedure write_references(ppufile:tcompilerppufile;locals:boolean);virtual;
  64. procedure buildderef;virtual;
  65. procedure buildderefimpl;virtual;
  66. procedure deref;virtual;
  67. procedure derefimpl;virtual;
  68. procedure insert(sym : tsymentry);override;
  69. procedure reset_all_defs;virtual;
  70. function speedsearch(const s : stringid;speedvalue : cardinal) : tsymentry;override;
  71. procedure allsymbolsused;
  72. procedure allprivatesused;
  73. procedure check_forwards;
  74. procedure checklabels;
  75. function needs_init_final : boolean;
  76. procedure unchain_overloaded;
  77. {$ifdef GDB}
  78. procedure concatstabto(asmlist : taasmoutput);virtual;
  79. function getnewtypecount : word; override;
  80. {$endif GDB}
  81. procedure testfordefaultproperty(p : TNamedIndexItem;arg:pointer);
  82. end;
  83. tabstractrecordsymtable = class(tstoredsymtable)
  84. public
  85. datasize : longint;
  86. usefieldalignment, { alignment to use for fields (PACKRECORDS value), -1 is C style }
  87. recordalignment, { alignment required when inserting this record }
  88. fieldalignment : shortint; { alignment current alignment used when fields are inserted }
  89. constructor create(const n:string;usealign:shortint);
  90. procedure ppuload(ppufile:tcompilerppufile);override;
  91. procedure ppuwrite(ppufile:tcompilerppufile);override;
  92. procedure load_references(ppufile:tcompilerppufile;locals:boolean);override;
  93. procedure write_references(ppufile:tcompilerppufile;locals:boolean);override;
  94. procedure insertfield(sym:tvarsym;addsym:boolean);
  95. procedure addalignmentpadding;
  96. end;
  97. trecordsymtable = class(tabstractrecordsymtable)
  98. public
  99. constructor create(usealign:shortint);
  100. procedure insertunionst(unionst : trecordsymtable;offset : longint);
  101. end;
  102. tobjectsymtable = class(tabstractrecordsymtable)
  103. public
  104. constructor create(const n:string;usealign:shortint);
  105. procedure insert(sym : tsymentry);override;
  106. end;
  107. tabstractlocalsymtable = class(tstoredsymtable)
  108. public
  109. procedure ppuwrite(ppufile:tcompilerppufile);override;
  110. end;
  111. tlocalsymtable = class(tabstractlocalsymtable)
  112. public
  113. constructor create(level:byte);
  114. procedure insert(sym : tsymentry);override;
  115. end;
  116. tparasymtable = class(tabstractlocalsymtable)
  117. public
  118. constructor create(level:byte);
  119. procedure insert(sym : tsymentry);override;
  120. end;
  121. tabstractunitsymtable = class(tstoredsymtable)
  122. public
  123. {$ifdef GDB}
  124. dbx_count : longint;
  125. prev_dbx_counter : plongint;
  126. dbx_count_ok : boolean;
  127. is_stab_written : boolean;
  128. {$endif GDB}
  129. constructor create(const n : string);
  130. {$ifdef GDB}
  131. procedure concattypestabto(asmlist : taasmoutput);
  132. {$endif GDB}
  133. end;
  134. tglobalsymtable = class(tabstractunitsymtable)
  135. public
  136. unittypecount : word;
  137. constructor create(const n : string);
  138. procedure ppuload(ppufile:tcompilerppufile);override;
  139. procedure ppuwrite(ppufile:tcompilerppufile);override;
  140. procedure load_references(ppufile:tcompilerppufile;locals:boolean);override;
  141. procedure write_references(ppufile:tcompilerppufile;locals:boolean);override;
  142. procedure insert(sym : tsymentry);override;
  143. {$ifdef GDB}
  144. function getnewtypecount : word; override;
  145. {$endif}
  146. end;
  147. tstaticsymtable = class(tabstractunitsymtable)
  148. public
  149. constructor create(const n : string);
  150. procedure ppuload(ppufile:tcompilerppufile);override;
  151. procedure ppuwrite(ppufile:tcompilerppufile);override;
  152. procedure load_references(ppufile:tcompilerppufile;locals:boolean);override;
  153. procedure write_references(ppufile:tcompilerppufile;locals:boolean);override;
  154. procedure insert(sym : tsymentry);override;
  155. end;
  156. twithsymtable = class(tsymtable)
  157. withrefnode : pointer; { tnode }
  158. constructor create(aowner:tdef;asymsearch:TDictionary;refnode:pointer{tnode});
  159. destructor destroy;override;
  160. procedure clear;override;
  161. end;
  162. tstt_exceptsymtable = class(tsymtable)
  163. public
  164. constructor create;
  165. end;
  166. var
  167. constsymtable : tsymtable; { symtable were the constants can be inserted }
  168. systemunit : tglobalsymtable; { pointer to the system unit }
  169. {****************************************************************************
  170. Functions
  171. ****************************************************************************}
  172. {*** Misc ***}
  173. procedure globaldef(const s : string;var t:ttype);
  174. function findunitsymtable(st:tsymtable):tsymtable;
  175. procedure duplicatesym(sym:tsym);
  176. procedure incompatibletypes(def1,def2:tdef);
  177. {*** Search ***}
  178. function searchsym(const s : stringid;var srsym:tsym;var srsymtable:tsymtable):boolean;
  179. function searchsym_type(const s : stringid;var srsym:tsym;var srsymtable:tsymtable):boolean;
  180. function searchsymonlyin(p : tsymtable;const s : stringid):tsym;
  181. function searchsym_in_class(classh:tobjectdef;const s : stringid):tsym;
  182. function searchsym_in_class_by_msgint(classh:tobjectdef;i:longint):tsym;
  183. function searchsym_in_class_by_msgstr(classh:tobjectdef;const s:string):tsym;
  184. function searchsystype(const s: stringid; var srsym: ttypesym): boolean;
  185. function searchsysvar(const s: stringid; var srsym: tvarsym; var symowner: tsymtable): boolean;
  186. function search_class_member(pd : tobjectdef;const s : string):tsym;
  187. function search_assignment_operator(from_def,to_def:Tdef):Tprocdef;
  188. function search_unary_operator(op:Ttoken;def:Tdef):Tprocdef;
  189. function search_binary_operator(op:Ttoken;def1,def2:Tdef):Tprocdef;
  190. {*** Object Helpers ***}
  191. procedure search_class_overloads(aprocsym : tprocsym);
  192. function search_default_property(pd : tobjectdef) : tpropertysym;
  193. procedure reset_all_defs;
  194. {*** symtable stack ***}
  195. {$ifdef DEBUG}
  196. procedure test_symtablestack;
  197. procedure list_symtablestack;
  198. {$endif DEBUG}
  199. {$ifdef UNITALIASES}
  200. type
  201. punit_alias = ^tunit_alias;
  202. tunit_alias = object(TNamedIndexItem)
  203. newname : pstring;
  204. constructor init(const n:string);
  205. destructor done;virtual;
  206. end;
  207. var
  208. unitaliases : pdictionary;
  209. procedure addunitalias(const n:string);
  210. function getunitalias(const n:string):string;
  211. {$endif UNITALIASES}
  212. {*** Init / Done ***}
  213. procedure InitSymtable;
  214. procedure DoneSymtable;
  215. const
  216. overloaded_names : array [NOTOKEN..last_overloaded] of string[16] =
  217. ('error',
  218. 'plus','minus','star','slash','equal',
  219. 'greater','lower','greater_or_equal',
  220. 'lower_or_equal',
  221. 'sym_diff','starstar',
  222. 'as','is','in','or',
  223. 'and','div','mod','not','shl','shr','xor',
  224. 'assign');
  225. implementation
  226. uses
  227. { global }
  228. verbose,globals,
  229. { target }
  230. systems,
  231. { symtable }
  232. symutil,defcmp,
  233. { module }
  234. fmodule,
  235. {$ifdef GDB}
  236. gdb,
  237. {$endif GDB}
  238. { codegen }
  239. procinfo
  240. ;
  241. {*****************************************************************************
  242. TStoredSymtable
  243. *****************************************************************************}
  244. procedure tstoredsymtable.ppuload(ppufile:tcompilerppufile);
  245. begin
  246. { load definitions }
  247. loaddefs(ppufile);
  248. { load symbols }
  249. loadsyms(ppufile);
  250. end;
  251. procedure tstoredsymtable.ppuwrite(ppufile:tcompilerppufile);
  252. begin
  253. { write definitions }
  254. writedefs(ppufile);
  255. { write symbols }
  256. writesyms(ppufile);
  257. end;
  258. procedure tstoredsymtable.loaddefs(ppufile:tcompilerppufile);
  259. var
  260. hp : tdef;
  261. b : byte;
  262. begin
  263. { load start of definition section, which holds the amount of defs }
  264. if ppufile.readentry<>ibstartdefs then
  265. Message(unit_f_ppu_read_error);
  266. ppufile.getlongint;
  267. { read definitions }
  268. repeat
  269. b:=ppufile.readentry;
  270. case b of
  271. ibpointerdef : hp:=tpointerdef.ppuload(ppufile);
  272. ibarraydef : hp:=tarraydef.ppuload(ppufile);
  273. iborddef : hp:=torddef.ppuload(ppufile);
  274. ibfloatdef : hp:=tfloatdef.ppuload(ppufile);
  275. ibprocdef : hp:=tprocdef.ppuload(ppufile);
  276. ibshortstringdef : hp:=tstringdef.loadshort(ppufile);
  277. iblongstringdef : hp:=tstringdef.loadlong(ppufile);
  278. ibansistringdef : hp:=tstringdef.loadansi(ppufile);
  279. ibwidestringdef : hp:=tstringdef.loadwide(ppufile);
  280. ibrecorddef : hp:=trecorddef.ppuload(ppufile);
  281. ibobjectdef : hp:=tobjectdef.ppuload(ppufile);
  282. ibenumdef : hp:=tenumdef.ppuload(ppufile);
  283. ibsetdef : hp:=tsetdef.ppuload(ppufile);
  284. ibprocvardef : hp:=tprocvardef.ppuload(ppufile);
  285. ibfiledef : hp:=tfiledef.ppuload(ppufile);
  286. ibclassrefdef : hp:=tclassrefdef.ppuload(ppufile);
  287. ibformaldef : hp:=tformaldef.ppuload(ppufile);
  288. ibvariantdef : hp:=tvariantdef.ppuload(ppufile);
  289. ibenddefs : break;
  290. ibend : Message(unit_f_ppu_read_error);
  291. else
  292. Message1(unit_f_ppu_invalid_entry,tostr(b));
  293. end;
  294. hp.owner:=self;
  295. defindex.insert(hp);
  296. until false;
  297. end;
  298. procedure tstoredsymtable.loadsyms(ppufile:tcompilerppufile);
  299. var
  300. b : byte;
  301. sym : tsym;
  302. begin
  303. { load start of definition section, which holds the amount of defs }
  304. if ppufile.readentry<>ibstartsyms then
  305. Message(unit_f_ppu_read_error);
  306. { skip amount of symbols, not used currently }
  307. ppufile.getlongint;
  308. { now read the symbols }
  309. repeat
  310. b:=ppufile.readentry;
  311. case b of
  312. ibtypesym : sym:=ttypesym.ppuload(ppufile);
  313. ibprocsym : sym:=tprocsym.ppuload(ppufile);
  314. ibconstsym : sym:=tconstsym.ppuload(ppufile);
  315. ibvarsym : sym:=tvarsym.ppuload(ppufile);
  316. ibabsolutesym : sym:=tabsolutesym.ppuload(ppufile);
  317. ibenumsym : sym:=tenumsym.ppuload(ppufile);
  318. ibtypedconstsym : sym:=ttypedconstsym.ppuload(ppufile);
  319. ibpropertysym : sym:=tpropertysym.ppuload(ppufile);
  320. ibunitsym : sym:=tunitsym.ppuload(ppufile);
  321. iblabelsym : sym:=tlabelsym.ppuload(ppufile);
  322. ibsyssym : sym:=tsyssym.ppuload(ppufile);
  323. ibrttisym : sym:=trttisym.ppuload(ppufile);
  324. ibendsyms : break;
  325. ibend : Message(unit_f_ppu_read_error);
  326. else
  327. Message1(unit_f_ppu_invalid_entry,tostr(b));
  328. end;
  329. sym.owner:=self;
  330. symindex.insert(sym);
  331. symsearch.insert(sym);
  332. until false;
  333. end;
  334. procedure tstoredsymtable.writedefs(ppufile:tcompilerppufile);
  335. var
  336. pd : tstoreddef;
  337. begin
  338. { each definition get a number, write then the amount of defs to the
  339. ibstartdef entry }
  340. ppufile.putlongint(defindex.count);
  341. ppufile.writeentry(ibstartdefs);
  342. { now write the definition }
  343. pd:=tstoreddef(defindex.first);
  344. while assigned(pd) do
  345. begin
  346. pd.ppuwrite(ppufile);
  347. pd:=tstoreddef(pd.indexnext);
  348. end;
  349. { write end of definitions }
  350. ppufile.writeentry(ibenddefs);
  351. end;
  352. procedure tstoredsymtable.writesyms(ppufile:tcompilerppufile);
  353. var
  354. pd : Tsym;
  355. begin
  356. { each definition get a number, write then the amount of syms and the
  357. datasize to the ibsymdef entry }
  358. ppufile.putlongint(symindex.count);
  359. ppufile.writeentry(ibstartsyms);
  360. { foreach is used to write all symbols }
  361. pd:=Tsym(symindex.first);
  362. while assigned(pd) do
  363. begin
  364. pd.ppuwrite(ppufile);
  365. pd:=Tsym(pd.indexnext);
  366. end;
  367. { end of symbols }
  368. ppufile.writeentry(ibendsyms);
  369. end;
  370. procedure tstoredsymtable.load_references(ppufile:tcompilerppufile;locals:boolean);
  371. var
  372. b : byte;
  373. d : tderef;
  374. sym : Tsym;
  375. prdef : tstoreddef;
  376. begin
  377. b:=ppufile.readentry;
  378. if b <> ibbeginsymtablebrowser then
  379. Message1(unit_f_ppu_invalid_entry,tostr(b));
  380. repeat
  381. b:=ppufile.readentry;
  382. case b of
  383. ibsymref :
  384. begin
  385. ppufile.getderef(d);
  386. sym:=Tsym(d.resolve);
  387. if assigned(sym) then
  388. sym.load_references(ppufile,locals);
  389. end;
  390. ibdefref :
  391. begin
  392. ppufile.getderef(d);
  393. prdef:=tstoreddef(d.resolve);
  394. if assigned(prdef) then
  395. begin
  396. if prdef.deftype<>procdef then
  397. Message(unit_f_ppu_read_error);
  398. tprocdef(prdef).load_references(ppufile,locals);
  399. end;
  400. end;
  401. ibendsymtablebrowser :
  402. break;
  403. else
  404. Message1(unit_f_ppu_invalid_entry,tostr(b));
  405. end;
  406. until false;
  407. end;
  408. procedure tstoredsymtable.write_references(ppufile:tcompilerppufile;locals:boolean);
  409. var
  410. pd : Tsym;
  411. begin
  412. ppufile.writeentry(ibbeginsymtablebrowser);
  413. { write all symbols }
  414. pd:=Tsym(symindex.first);
  415. while assigned(pd) do
  416. begin
  417. pd.write_references(ppufile,locals);
  418. pd:=Tsym(pd.indexnext);
  419. end;
  420. ppufile.writeentry(ibendsymtablebrowser);
  421. end;
  422. procedure tstoredsymtable.buildderef;
  423. var
  424. hp : tdef;
  425. hs : tsym;
  426. begin
  427. { interface definitions }
  428. hp:=tdef(defindex.first);
  429. while assigned(hp) do
  430. begin
  431. hp.buildderef;
  432. hp:=tdef(hp.indexnext);
  433. end;
  434. { interface symbols }
  435. hs:=tsym(symindex.first);
  436. while assigned(hs) do
  437. begin
  438. hs.buildderef;
  439. hs:=tsym(hs.indexnext);
  440. end;
  441. end;
  442. procedure tstoredsymtable.buildderefimpl;
  443. var
  444. hp : tdef;
  445. begin
  446. { definitions }
  447. hp:=tdef(defindex.first);
  448. while assigned(hp) do
  449. begin
  450. hp.buildderefimpl;
  451. hp:=tdef(hp.indexnext);
  452. end;
  453. end;
  454. procedure tstoredsymtable.deref;
  455. var
  456. hp : tdef;
  457. hs : tsym;
  458. begin
  459. { first deref the interface ttype symbols. This is needs
  460. to be done before the interface defs are derefed, because
  461. the interface defs can contain references to the type symbols
  462. which then already need to contain a resolved restype field (PFV) }
  463. hs:=tsym(symindex.first);
  464. while assigned(hs) do
  465. begin
  466. if hs.typ=typesym then
  467. hs.deref;
  468. hs:=tsym(hs.indexnext);
  469. end;
  470. { deref the interface definitions }
  471. hp:=tdef(defindex.first);
  472. while assigned(hp) do
  473. begin
  474. hp.deref;
  475. hp:=tdef(hp.indexnext);
  476. end;
  477. { deref the interface symbols }
  478. hs:=tsym(symindex.first);
  479. while assigned(hs) do
  480. begin
  481. if hs.typ<>typesym then
  482. hs.deref;
  483. hs:=tsym(hs.indexnext);
  484. end;
  485. end;
  486. procedure tstoredsymtable.derefimpl;
  487. var
  488. hp : tdef;
  489. begin
  490. { definitions }
  491. hp:=tdef(defindex.first);
  492. while assigned(hp) do
  493. begin
  494. hp.derefimpl;
  495. hp:=tdef(hp.indexnext);
  496. end;
  497. end;
  498. procedure tstoredsymtable.insert(sym:tsymentry);
  499. var
  500. hsym : tsym;
  501. begin
  502. { set owner and sym indexnb }
  503. sym.owner:=self;
  504. { check the current symtable }
  505. hsym:=tsym(search(sym.name));
  506. if assigned(hsym) then
  507. begin
  508. { in TP and Delphi you can have a local with the
  509. same name as the function, the function is then hidden for
  510. the user. (Under delphi it can still be accessed using result),
  511. but don't allow hiding of RESULT }
  512. if (m_duplicate_names in aktmodeswitches) and
  513. (sym.typ in [varsym,absolutesym]) and
  514. (vo_is_funcret in tvarsym(sym).varoptions) and
  515. not((m_result in aktmodeswitches) and
  516. (vo_is_result in tvarsym(sym).varoptions)) then
  517. sym.name:='hidden'+sym.name
  518. else
  519. begin
  520. DuplicateSym(hsym);
  521. exit;
  522. end;
  523. end;
  524. { register definition of typesym }
  525. if (sym.typ = typesym) and
  526. assigned(ttypesym(sym).restype.def) then
  527. begin
  528. if not(assigned(ttypesym(sym).restype.def.owner)) and
  529. (ttypesym(sym).restype.def.deftype<>errordef) then
  530. registerdef(ttypesym(sym).restype.def);
  531. {$ifdef GDB}
  532. if (cs_debuginfo in aktmoduleswitches) and assigned(debuglist) and
  533. (symtabletype in [globalsymtable,staticsymtable]) then
  534. begin
  535. ttypesym(sym).isusedinstab := true;
  536. {sym.concatstabto(debuglist);}
  537. end;
  538. {$endif GDB}
  539. end;
  540. { insert in index and search hash }
  541. symindex.insert(sym);
  542. symsearch.insert(sym);
  543. end;
  544. function tstoredsymtable.speedsearch(const s : stringid;speedvalue : cardinal) : tsymentry;
  545. var
  546. hp : Tsym;
  547. newref : tref;
  548. begin
  549. hp:=Tsym(inherited speedsearch(s,speedvalue));
  550. if assigned(hp) then
  551. begin
  552. { reject non static members in static procedures }
  553. if (symtabletype=objectsymtable) and
  554. not(sp_static in hp.symoptions) and
  555. allow_only_static then
  556. Message(sym_e_only_static_in_static);
  557. { unit uses count }
  558. if (unitid<>0) and
  559. (symtabletype = globalsymtable) and
  560. assigned(current_module) and
  561. (unitid<current_module.mapsize) and
  562. assigned(current_module.map[unitid].unitsym) then
  563. inc(current_module.map[unitid].unitsym.refs);
  564. {$ifdef GDB}
  565. { if it is a type, we need the stabs of this type
  566. this might be the cause of the class debug problems
  567. as TCHILDCLASS.Create did not generate appropriate
  568. stabs debug info if TCHILDCLASS wasn't used anywhere else PM }
  569. if (cs_debuginfo in aktmoduleswitches) and
  570. (hp.typ=typesym) and make_ref then
  571. begin
  572. if assigned(ttypesym(hp).restype.def) then
  573. tstoreddef(ttypesym(hp).restype.def).numberstring
  574. else
  575. ttypesym(hp).isusedinstab:=true;
  576. end;
  577. {$endif GDB}
  578. { unitsym are only loaded for browsing PM }
  579. { this was buggy anyway because we could use }
  580. { unitsyms from other units in _USES !! }
  581. {if (symtabletype=unitsymtable) and (hp.typ=unitsym) and
  582. assigned(current_module) and (current_module.globalsymtable<>.load) then
  583. hp:=nil;}
  584. if make_ref and (cs_browser in aktmoduleswitches) then
  585. begin
  586. newref:=tref.create(hp.lastref,@akttokenpos);
  587. { for symbols that are in tables without browser info or syssyms }
  588. if hp.refcount=0 then
  589. begin
  590. hp.defref:=newref;
  591. hp.lastref:=newref;
  592. end
  593. else
  594. if resolving_forward and assigned(hp.defref) then
  595. { put it as second reference }
  596. begin
  597. newref.nextref:=hp.defref.nextref;
  598. hp.defref.nextref:=newref;
  599. hp.lastref.nextref:=nil;
  600. end
  601. else
  602. hp.lastref:=newref;
  603. inc(hp.refcount);
  604. end;
  605. if make_ref then
  606. inc(hp.refs);
  607. end; { value was not found }
  608. speedsearch:=hp;
  609. end;
  610. {**************************************
  611. Callbacks
  612. **************************************}
  613. procedure TStoredSymtable.check_forward(sym : TNamedIndexItem;arg:pointer);
  614. begin
  615. if tsym(sym).typ=procsym then
  616. tprocsym(sym).check_forward
  617. { check also object method table }
  618. { we needn't to test the def list }
  619. { because each object has to have a type sym }
  620. else
  621. if (tsym(sym).typ=typesym) and
  622. assigned(ttypesym(sym).restype.def) and
  623. (ttypesym(sym).restype.def.deftype=objectdef) then
  624. tobjectdef(ttypesym(sym).restype.def).check_forwards;
  625. end;
  626. procedure TStoredSymtable.labeldefined(p : TNamedIndexItem;arg:pointer);
  627. begin
  628. if (tsym(p).typ=labelsym) and
  629. not(tlabelsym(p).defined) then
  630. begin
  631. if tlabelsym(p).used then
  632. Message1(sym_e_label_used_and_not_defined,tlabelsym(p).realname)
  633. else
  634. Message1(sym_w_label_not_defined,tlabelsym(p).realname);
  635. end;
  636. end;
  637. procedure TStoredSymtable.varsymbolused(p : TNamedIndexItem;arg:pointer);
  638. begin
  639. if (tsym(p).typ=varsym) and
  640. ((tsym(p).owner.symtabletype in
  641. [parasymtable,localsymtable,objectsymtable,staticsymtable])) then
  642. begin
  643. { unused symbol should be reported only if no }
  644. { error is reported }
  645. { if the symbol is in a register it is used }
  646. { also don't count the value parameters which have local copies }
  647. { also don't claim for high param of open parameters (PM) }
  648. if (Errorcount<>0) or
  649. (assigned(tvarsym(p).paraitem) and
  650. tvarsym(p).paraitem.is_hidden) then
  651. exit;
  652. if (tvarsym(p).refs=0) then
  653. begin
  654. if (vo_is_funcret in tvarsym(p).varoptions) then
  655. begin
  656. { don't warn about the result of constructors }
  657. if (tsym(p).owner.symtabletype<>localsymtable) or
  658. (tprocdef(tsym(p).owner.defowner).proctypeoption<>potype_constructor) then
  659. MessagePos(tsym(p).fileinfo,sym_w_function_result_not_set)
  660. end
  661. else if (tsym(p).owner.symtabletype=parasymtable) then
  662. MessagePos1(tsym(p).fileinfo,sym_h_para_identifier_not_used,tsym(p).realname)
  663. else if (tsym(p).owner.symtabletype=objectsymtable) then
  664. MessagePos2(tsym(p).fileinfo,sym_n_private_identifier_not_used,tsym(p).owner.realname^,tsym(p).realname)
  665. else
  666. MessagePos1(tsym(p).fileinfo,sym_n_local_identifier_not_used,tsym(p).realname);
  667. end
  668. else if tvarsym(p).varstate=vs_assigned then
  669. begin
  670. if (tsym(p).owner.symtabletype=parasymtable) then
  671. begin
  672. if not(tvarsym(p).varspez in [vs_var,vs_out]) and
  673. not(vo_is_funcret in tvarsym(p).varoptions) then
  674. MessagePos1(tsym(p).fileinfo,sym_h_para_identifier_only_set,tsym(p).realname)
  675. end
  676. else if (tsym(p).owner.symtabletype=objectsymtable) then
  677. MessagePos2(tsym(p).fileinfo,sym_n_private_identifier_only_set,tsym(p).owner.realname^,tsym(p).realname)
  678. else if not(vo_is_exported in tvarsym(p).varoptions) and
  679. not(vo_is_funcret in tvarsym(p).varoptions) then
  680. MessagePos1(tsym(p).fileinfo,sym_n_local_identifier_only_set,tsym(p).realname);
  681. end;
  682. end
  683. else if ((tsym(p).owner.symtabletype in
  684. [objectsymtable,parasymtable,localsymtable,staticsymtable])) then
  685. begin
  686. if (Errorcount<>0) or
  687. (copy(p.name,1,3)='def') then
  688. exit;
  689. { do not claim for inherited private fields !! }
  690. if (Tsym(p).refs=0) and (tsym(p).owner.symtabletype=objectsymtable) then
  691. MessagePos2(tsym(p).fileinfo,sym_n_private_method_not_used,tsym(p).owner.realname^,tsym(p).realname)
  692. { units references are problematic }
  693. else
  694. begin
  695. if (Tsym(p).refs=0) and
  696. not(tsym(p).typ in [enumsym,unitsym]) and
  697. not(is_funcret_sym(tsym(p))) and
  698. (
  699. (tsym(p).typ<>procsym) or
  700. {$ifdef GDB}
  701. not (tprocsym(p).is_global) or
  702. {$endif GDB}
  703. { all program functions are declared global
  704. but unused should still be signaled PM }
  705. ((tsym(p).owner.symtabletype=staticsymtable) and
  706. not current_module.is_unit)
  707. ) then
  708. MessagePos2(tsym(p).fileinfo,sym_h_local_symbol_not_used,SymTypeName[tsym(p).typ],tsym(p).realname);
  709. end;
  710. end;
  711. end;
  712. procedure TStoredSymtable.TestPrivate(p : TNamedIndexItem;arg:pointer);
  713. begin
  714. if sp_private in tsym(p).symoptions then
  715. varsymbolused(p,arg);
  716. end;
  717. procedure TStoredSymtable.objectprivatesymbolused(p : TNamedIndexItem;arg:pointer);
  718. begin
  719. {
  720. Don't test simple object aliases PM
  721. }
  722. if (tsym(p).typ=typesym) and
  723. (ttypesym(p).restype.def.deftype=objectdef) and
  724. (ttypesym(p).restype.def.typesym=tsym(p)) then
  725. tobjectdef(ttypesym(p).restype.def).symtable.foreach({$ifdef FPCPROCVAR}@{$endif}TestPrivate,nil);
  726. end;
  727. procedure tstoredsymtable.unchain_overloads(p : TNamedIndexItem;arg:pointer);
  728. begin
  729. if tsym(p).typ=procsym then
  730. tprocsym(p).unchain_overload;
  731. end;
  732. procedure Tstoredsymtable.reset_def(def:Tnamedindexitem;arg:pointer);
  733. begin
  734. Tstoreddef(def).reset;
  735. end;
  736. {$ifdef GDB}
  737. procedure TStoredSymtable.concatstab(p : TNamedIndexItem;arg:pointer);
  738. var stabstr:Pchar;
  739. ao:Taasmoutput;
  740. begin
  741. if Tsym(p).typ<>procsym then
  742. begin
  743. ao:=Taasmoutput(arg);
  744. if not Tsym(p).isstabwritten then
  745. begin
  746. stabstr:=Tsym(p).stabstring;
  747. if stabstr<>nil then
  748. ao.concat(Tai_stabs.create(stabstr));
  749. Tsym(p).isstabwritten:=true;
  750. end;
  751. end;
  752. end;
  753. procedure TStoredSymtable.resetstab(p : TNamedIndexItem;arg:pointer);
  754. begin
  755. if tsym(p).typ <> procsym then
  756. Tstoredsym(p).isstabwritten:=false;
  757. end;
  758. procedure TStoredSymtable.concattypestab(p : TNamedIndexItem;arg:pointer);
  759. var stabstr:Pchar;
  760. ao:Taasmoutput;
  761. begin
  762. if Tsym(p).typ=typesym then
  763. begin
  764. ao:=Taasmoutput(arg);
  765. if Ttypesym(p).restype.def.typesym=p then
  766. Tstoreddef(Ttypesym(p).restype.def).concatstabto(ao)
  767. else
  768. begin
  769. Tsym(p).isstabwritten:=false;
  770. stabstr:=Tsym(p).stabstring;
  771. if stabstr<>nil then
  772. ao.concat(Tai_stabs.create(stabstr));
  773. Tsym(p).isstabwritten:=true;
  774. end;
  775. end;
  776. end;
  777. function tstoredsymtable.getnewtypecount : word;
  778. begin
  779. getnewtypecount:=pglobaltypecount^;
  780. inc(pglobaltypecount^);
  781. end;
  782. {$endif GDB}
  783. {***********************************************
  784. Process all entries
  785. ***********************************************}
  786. procedure Tstoredsymtable.reset_all_defs;
  787. begin
  788. defindex.foreach(@reset_def,nil);
  789. end;
  790. { checks, if all procsyms and methods are defined }
  791. procedure tstoredsymtable.check_forwards;
  792. begin
  793. foreach({$ifdef FPCPROCVAR}@{$endif}check_forward,nil);
  794. end;
  795. procedure tstoredsymtable.checklabels;
  796. begin
  797. foreach({$ifdef FPCPROCVAR}@{$endif}labeldefined,nil);
  798. end;
  799. procedure tstoredsymtable.allsymbolsused;
  800. begin
  801. foreach({$ifdef FPCPROCVAR}@{$endif}varsymbolused,nil);
  802. end;
  803. procedure tstoredsymtable.allprivatesused;
  804. begin
  805. foreach({$ifdef FPCPROCVAR}@{$endif}objectprivatesymbolused,nil);
  806. end;
  807. procedure tstoredsymtable.unchain_overloaded;
  808. begin
  809. foreach({$ifdef FPCPROCVAR}@{$endif}unchain_overloads,nil);
  810. end;
  811. {$ifdef GDB}
  812. procedure tstoredsymtable.concatstabto(asmlist : taasmoutput);
  813. begin
  814. foreach({$ifdef FPCPROCVAR}@{$endif}concatstab,asmlist);
  815. end;
  816. {$endif}
  817. procedure TStoredSymtable._needs_init_final(p : tnamedindexitem;arg:pointer);
  818. begin
  819. if b_needs_init_final then
  820. exit;
  821. case tsym(p).typ of
  822. varsym :
  823. begin
  824. if not(is_class(tvarsym(p).vartype.def)) and
  825. tstoreddef(tvarsym(p).vartype.def).needs_inittable then
  826. b_needs_init_final:=true;
  827. end;
  828. typedconstsym :
  829. begin
  830. if ttypedconstsym(p).is_writable and
  831. tstoreddef(ttypedconstsym(p).typedconsttype.def).needs_inittable then
  832. b_needs_init_final:=true;
  833. end;
  834. end;
  835. end;
  836. { returns true, if p contains data which needs init/final code }
  837. function tstoredsymtable.needs_init_final : boolean;
  838. begin
  839. b_needs_init_final:=false;
  840. foreach({$ifdef FPCPROCVAR}@{$endif}_needs_init_final,nil);
  841. needs_init_final:=b_needs_init_final;
  842. end;
  843. {****************************************************************************
  844. TAbstractRecordSymtable
  845. ****************************************************************************}
  846. constructor tabstractrecordsymtable.create(const n:string;usealign:shortint);
  847. begin
  848. inherited create(n);
  849. datasize:=0;
  850. recordalignment:=1;
  851. usefieldalignment:=usealign;
  852. { recordalign -1 means C record packing, that starts
  853. with an alignment of 1 }
  854. if usealign=-1 then
  855. fieldalignment:=1
  856. else
  857. fieldalignment:=usealign;
  858. end;
  859. procedure tabstractrecordsymtable.ppuload(ppufile:tcompilerppufile);
  860. var
  861. storesymtable : tsymtable;
  862. begin
  863. storesymtable:=aktrecordsymtable;
  864. aktrecordsymtable:=self;
  865. inherited ppuload(ppufile);
  866. aktrecordsymtable:=storesymtable;
  867. end;
  868. procedure tabstractrecordsymtable.ppuwrite(ppufile:tcompilerppufile);
  869. var
  870. oldtyp : byte;
  871. storesymtable : tsymtable;
  872. begin
  873. storesymtable:=aktrecordsymtable;
  874. aktrecordsymtable:=self;
  875. oldtyp:=ppufile.entrytyp;
  876. ppufile.entrytyp:=subentryid;
  877. inherited ppuwrite(ppufile);
  878. ppufile.entrytyp:=oldtyp;
  879. aktrecordsymtable:=storesymtable;
  880. end;
  881. procedure tabstractrecordsymtable.load_references(ppufile:tcompilerppufile;locals:boolean);
  882. var
  883. storesymtable : tsymtable;
  884. begin
  885. storesymtable:=aktrecordsymtable;
  886. aktrecordsymtable:=self;
  887. inherited load_references(ppufile,locals);
  888. aktrecordsymtable:=storesymtable;
  889. end;
  890. procedure tabstractrecordsymtable.write_references(ppufile:tcompilerppufile;locals:boolean);
  891. var
  892. storesymtable : tsymtable;
  893. begin
  894. storesymtable:=aktrecordsymtable;
  895. aktrecordsymtable:=self;
  896. inherited write_references(ppufile,locals);
  897. aktrecordsymtable:=storesymtable;
  898. end;
  899. procedure tabstractrecordsymtable.insertfield(sym : tvarsym;addsym:boolean);
  900. var
  901. l,
  902. varalignrecord,
  903. varalignfield,
  904. varalign : longint;
  905. vardef : tdef;
  906. begin
  907. if addsym then
  908. insert(sym);
  909. { this symbol can't be loaded to a register }
  910. exclude(tvarsym(sym).varoptions,vo_regable);
  911. exclude(tvarsym(sym).varoptions,vo_fpuregable);
  912. { Calculate field offset }
  913. l:=tvarsym(sym).getvaluesize;
  914. vardef:=tvarsym(sym).vartype.def;
  915. varalign:=vardef.alignment;
  916. { Calc the alignment size for C style records }
  917. if (usefieldalignment=-1) then
  918. begin
  919. if (varalign>4) and
  920. ((varalign mod 4)<>0) and
  921. (vardef.deftype=arraydef) then
  922. Message1(sym_w_wrong_C_pack,vardef.typename);
  923. if varalign=0 then
  924. varalign:=l;
  925. if (fieldalignment<aktalignment.maxCrecordalign) then
  926. begin
  927. if (varalign>16) and (fieldalignment<32) then
  928. fieldalignment:=32
  929. else if (varalign>12) and (fieldalignment<16) then
  930. fieldalignment:=16
  931. { 12 is needed for long double }
  932. else if (varalign>8) and (fieldalignment<12) then
  933. fieldalignment:=12
  934. else if (varalign>4) and (fieldalignment<8) then
  935. fieldalignment:=8
  936. else if (varalign>2) and (fieldalignment<4) then
  937. fieldalignment:=4
  938. else if (varalign>1) and (fieldalignment<2) then
  939. fieldalignment:=2;
  940. end;
  941. fieldalignment:=min(fieldalignment,aktalignment.maxCrecordalign);
  942. end;
  943. if varalign=0 then
  944. varalign:=size_2_align(l);
  945. varalignfield:=used_align(varalign,aktalignment.recordalignmin,fieldalignment);
  946. tvarsym(sym).fieldoffset:=align(datasize,varalignfield);
  947. datasize:=tvarsym(sym).fieldoffset+l;
  948. { Calc alignment needed for this record }
  949. varalignrecord:=used_align(varalign,aktalignment.recordalignmin,aktalignment.recordalignmax);
  950. recordalignment:=max(recordalignment,varalignrecord);
  951. end;
  952. procedure tabstractrecordsymtable.addalignmentpadding;
  953. var
  954. padalign : shortint;
  955. begin
  956. { make the record size aligned correctly so it can be
  957. used as elements in an array. For C records we
  958. use the fieldalignment, because that is updated with the
  959. used alignment. For normal records we use minimum from
  960. recordalginment or fieldalignment. This is required to
  961. be able to override the natural alignment with 'packed' }
  962. if usefieldalignment=-1 then
  963. padalign:=fieldalignment
  964. else
  965. padalign:=min(fieldalignment,recordalignment);
  966. datasize:=align(datasize,padalign);
  967. end;
  968. {****************************************************************************
  969. TRecordSymtable
  970. ****************************************************************************}
  971. constructor trecordsymtable.create(usealign:shortint);
  972. begin
  973. inherited create('',usealign);
  974. symtabletype:=recordsymtable;
  975. end;
  976. { this procedure is reserved for inserting case variant into
  977. a record symtable }
  978. { the offset is the location of the start of the variant
  979. and datasize and dataalignment corresponds to
  980. the complete size (see code in pdecl unit) PM }
  981. procedure trecordsymtable.insertunionst(unionst : trecordsymtable;offset : longint);
  982. var
  983. ps,nps : tvarsym;
  984. pd,npd : tdef;
  985. varalignrecord,varalign,
  986. storesize,storealign : longint;
  987. begin
  988. storesize:=datasize;
  989. storealign:=fieldalignment;
  990. datasize:=offset;
  991. ps:=tvarsym(unionst.symindex.first);
  992. while assigned(ps) do
  993. begin
  994. nps:=tvarsym(ps.indexnext);
  995. { remove from current symtable }
  996. unionst.symindex.deleteindex(ps);
  997. ps.left:=nil;
  998. ps.right:=nil;
  999. { add to this record }
  1000. ps.owner:=self;
  1001. datasize:=ps.fieldoffset+offset;
  1002. symindex.insert(ps);
  1003. symsearch.insert(ps);
  1004. { update address }
  1005. ps.fieldoffset:=datasize;
  1006. { update alignment of this record }
  1007. varalign:=ps.vartype.def.alignment;
  1008. if varalign=0 then
  1009. varalign:=size_2_align(ps.getvaluesize);
  1010. varalignrecord:=used_align(varalign,aktalignment.recordalignmin,aktalignment.recordalignmax);
  1011. recordalignment:=max(recordalignment,varalignrecord);
  1012. { next }
  1013. ps:=nps;
  1014. end;
  1015. pd:=tdef(unionst.defindex.first);
  1016. while assigned(pd) do
  1017. begin
  1018. npd:=tdef(pd.indexnext);
  1019. unionst.defindex.deleteindex(pd);
  1020. pd.left:=nil;
  1021. pd.right:=nil;
  1022. registerdef(pd);
  1023. pd:=npd;
  1024. end;
  1025. datasize:=storesize;
  1026. fieldalignment:=storealign;
  1027. end;
  1028. {****************************************************************************
  1029. TObjectSymtable
  1030. ****************************************************************************}
  1031. constructor tobjectsymtable.create(const n:string;usealign:shortint);
  1032. begin
  1033. inherited create(n,usealign);
  1034. symtabletype:=objectsymtable;
  1035. end;
  1036. procedure tobjectsymtable.insert(sym:tsymentry);
  1037. var
  1038. hsym : tsym;
  1039. begin
  1040. { check for duplicate field id in inherited classes }
  1041. if (sym.typ=varsym) and
  1042. assigned(defowner) and
  1043. (
  1044. not(m_delphi in aktmodeswitches) or
  1045. is_object(tdef(defowner))
  1046. ) then
  1047. begin
  1048. { but private ids can be reused }
  1049. hsym:=search_class_member(tobjectdef(defowner),sym.name);
  1050. if assigned(hsym) and
  1051. Tsym(hsym).is_visible_for_object(tobjectdef(defowner)) then
  1052. begin
  1053. DuplicateSym(hsym);
  1054. exit;
  1055. end;
  1056. end;
  1057. inherited insert(sym);
  1058. end;
  1059. {****************************************************************************
  1060. TAbstractLocalSymtable
  1061. ****************************************************************************}
  1062. procedure tabstractlocalsymtable.ppuwrite(ppufile:tcompilerppufile);
  1063. var
  1064. oldtyp : byte;
  1065. begin
  1066. oldtyp:=ppufile.entrytyp;
  1067. ppufile.entrytyp:=subentryid;
  1068. { write definitions }
  1069. writedefs(ppufile);
  1070. { write symbols }
  1071. writesyms(ppufile);
  1072. ppufile.entrytyp:=oldtyp;
  1073. end;
  1074. {****************************************************************************
  1075. TLocalSymtable
  1076. ****************************************************************************}
  1077. constructor tlocalsymtable.create(level:byte);
  1078. begin
  1079. inherited create('');
  1080. symtabletype:=localsymtable;
  1081. symtablelevel:=level;
  1082. end;
  1083. procedure tlocalsymtable.insert(sym:tsymentry);
  1084. var
  1085. hsym : tsym;
  1086. begin
  1087. { need to hide function result? }
  1088. hsym:=tsym(search(sym.name));
  1089. if assigned(hsym) then
  1090. begin
  1091. { a local and the function can have the same
  1092. name in TP and Delphi, but RESULT not }
  1093. if (m_duplicate_names in aktmodeswitches) and
  1094. (hsym.typ in [absolutesym,varsym]) and
  1095. (vo_is_funcret in tvarsym(hsym).varoptions) and
  1096. not((m_result in aktmodeswitches) and
  1097. (vo_is_result in tvarsym(hsym).varoptions)) then
  1098. hsym.owner.rename(hsym.name,'hidden'+hsym.name)
  1099. else
  1100. begin
  1101. DuplicateSym(hsym);
  1102. exit;
  1103. end;
  1104. end;
  1105. if assigned(next) and
  1106. (next.symtabletype=parasymtable) then
  1107. begin
  1108. { check para symtable }
  1109. hsym:=tsym(next.search(sym.name));
  1110. if assigned(hsym) then
  1111. begin
  1112. { a local and the function can have the same
  1113. name in TP and Delphi, but RESULT not }
  1114. if (m_duplicate_names in aktmodeswitches) and
  1115. (sym.typ in [absolutesym,varsym]) and
  1116. (vo_is_funcret in tvarsym(sym).varoptions) and
  1117. not((m_result in aktmodeswitches) and
  1118. (vo_is_result in tvarsym(sym).varoptions)) then
  1119. sym.name:='hidden'+sym.name
  1120. else
  1121. begin
  1122. DuplicateSym(hsym);
  1123. exit;
  1124. end;
  1125. end;
  1126. { check for duplicate id in local symtable of methods }
  1127. if assigned(next.next) and
  1128. { funcretsym is allowed !! }
  1129. (not is_funcret_sym(sym)) and
  1130. (next.next.symtabletype=objectsymtable) then
  1131. begin
  1132. hsym:=search_class_member(tobjectdef(next.next.defowner),sym.name);
  1133. if assigned(hsym) and
  1134. { private ids can be reused }
  1135. (not(sp_private in hsym.symoptions) or
  1136. (hsym.owner.defowner.owner.symtabletype<>globalsymtable)) then
  1137. begin
  1138. { delphi allows to reuse the names in a class, but not
  1139. in object (tp7 compatible) }
  1140. if not((m_delphi in aktmodeswitches) and
  1141. is_class(tdef(next.next.defowner))) then
  1142. begin
  1143. DuplicateSym(hsym);
  1144. exit;
  1145. end;
  1146. end;
  1147. end;
  1148. end;
  1149. inherited insert(sym);
  1150. end;
  1151. {****************************************************************************
  1152. TParaSymtable
  1153. ****************************************************************************}
  1154. constructor tparasymtable.create(level:byte);
  1155. begin
  1156. inherited create('');
  1157. symtabletype:=parasymtable;
  1158. symtablelevel:=level;
  1159. end;
  1160. procedure tparasymtable.insert(sym:tsymentry);
  1161. var
  1162. hsym : tsym;
  1163. begin
  1164. { check for duplicate id in para symtable of methods }
  1165. if assigned(next) and
  1166. (next.symtabletype=objectsymtable) and
  1167. { funcretsym is allowed }
  1168. (not is_funcret_sym(sym)) then
  1169. begin
  1170. hsym:=search_class_member(tobjectdef(next.defowner),sym.name);
  1171. { private ids can be reused }
  1172. if assigned(hsym) and
  1173. Tsym(hsym).is_visible_for_object(tobjectdef(next.defowner)) then
  1174. begin
  1175. { delphi allows to reuse the names in a class, but not
  1176. in object (tp7 compatible) }
  1177. if not((m_delphi in aktmodeswitches) and
  1178. is_class_or_interface(tobjectdef(next.defowner))) then
  1179. begin
  1180. DuplicateSym(hsym);
  1181. exit;
  1182. end;
  1183. end;
  1184. end;
  1185. inherited insert(sym);
  1186. end;
  1187. {****************************************************************************
  1188. TAbstractUnitSymtable
  1189. ****************************************************************************}
  1190. constructor tabstractunitsymtable.create(const n : string);
  1191. begin
  1192. inherited create(n);
  1193. symsearch.usehash;
  1194. {$ifdef GDB}
  1195. { reset GDB things }
  1196. prev_dbx_counter := dbx_counter;
  1197. dbx_counter := nil;
  1198. is_stab_written:=false;
  1199. dbx_count := -1;
  1200. {$endif GDB}
  1201. end;
  1202. {$ifdef GDB}
  1203. procedure tabstractunitsymtable.concattypestabto(asmlist : taasmoutput);
  1204. var prev_dbx_count : plongint;
  1205. begin
  1206. if is_stab_written then
  1207. exit;
  1208. if not assigned(name) then
  1209. name := stringdup('Main_program');
  1210. {if (symtabletype = globalsymtable) and
  1211. (current_module.globalsymtable<>self) then
  1212. begin
  1213. unitid:=current_module.unitcount;
  1214. inc(current_module.unitcount);
  1215. end;}
  1216. asmList.concat(tai_comment.Create(strpnew('Begin unit '+name^+' has index '+tostr(unitid))));
  1217. if cs_gdb_dbx in aktglobalswitches then
  1218. begin
  1219. if dbx_count_ok then
  1220. begin
  1221. asmList.concat(tai_comment.Create(strpnew('"repeated" unit '+name^
  1222. +' has index '+tostr(unitid)+' dbx count = '+tostr(dbx_count))));
  1223. asmList.concat(Tai_stabs.Create(strpnew('"'+name^+'",'
  1224. +tostr(N_EXCL)+',0,0,'+tostr(dbx_count))));
  1225. exit;
  1226. end
  1227. else if (current_module.globalsymtable<>self) then
  1228. begin
  1229. prev_dbx_count := dbx_counter;
  1230. dbx_counter := nil;
  1231. do_count_dbx:=false;
  1232. if (symtabletype = globalsymtable) and (unitid<>0) then
  1233. asmList.concat(Tai_stabs.Create(strpnew('"'+name^+'",'+tostr(N_BINCL)+',0,0,0')));
  1234. dbx_counter := @dbx_count;
  1235. dbx_count:=0;
  1236. do_count_dbx:=assigned(dbx_counter);
  1237. end;
  1238. end;
  1239. foreach({$ifdef FPCPROCVAR}@{$endif}concattypestab,asmlist);
  1240. if cs_gdb_dbx in aktglobalswitches then
  1241. begin
  1242. if (current_module.globalsymtable<>self) then
  1243. begin
  1244. dbx_counter := prev_dbx_count;
  1245. do_count_dbx:=false;
  1246. asmList.concat(tai_comment.Create(strpnew('End unit '+name^
  1247. +' has index '+tostr(unitid))));
  1248. asmList.concat(Tai_stabs.Create(strpnew('"'+name^+'",'
  1249. +tostr(N_EINCL)+',0,0,0')));
  1250. do_count_dbx:=assigned(dbx_counter);
  1251. dbx_count_ok := {true}false;
  1252. end;
  1253. end;
  1254. is_stab_written:=true;
  1255. end;
  1256. {$endif GDB}
  1257. {****************************************************************************
  1258. TStaticSymtable
  1259. ****************************************************************************}
  1260. constructor tstaticsymtable.create(const n : string);
  1261. begin
  1262. inherited create(n);
  1263. symtabletype:=staticsymtable;
  1264. symtablelevel:=main_program_level;
  1265. end;
  1266. procedure tstaticsymtable.ppuload(ppufile:tcompilerppufile);
  1267. begin
  1268. aktstaticsymtable:=self;
  1269. next:=symtablestack;
  1270. symtablestack:=self;
  1271. inherited ppuload(ppufile);
  1272. { now we can deref the syms and defs }
  1273. deref;
  1274. { restore symtablestack }
  1275. symtablestack:=next;
  1276. end;
  1277. procedure tstaticsymtable.ppuwrite(ppufile:tcompilerppufile);
  1278. begin
  1279. aktstaticsymtable:=self;
  1280. inherited ppuwrite(ppufile);
  1281. end;
  1282. procedure tstaticsymtable.load_references(ppufile:tcompilerppufile;locals:boolean);
  1283. begin
  1284. aktstaticsymtable:=self;
  1285. inherited load_references(ppufile,locals);
  1286. end;
  1287. procedure tstaticsymtable.write_references(ppufile:tcompilerppufile;locals:boolean);
  1288. begin
  1289. aktstaticsymtable:=self;
  1290. inherited write_references(ppufile,locals);
  1291. end;
  1292. procedure tstaticsymtable.insert(sym:tsymentry);
  1293. var
  1294. hsym : tsym;
  1295. begin
  1296. { also check the global symtable }
  1297. if assigned(next) and
  1298. (next.unitid=0) then
  1299. begin
  1300. hsym:=tsym(next.search(sym.name));
  1301. if assigned(hsym) then
  1302. begin
  1303. { Delphi you can have a symbol with the same name as the
  1304. unit, the unit can then not be accessed anymore using
  1305. <unit>.<id>, so we can hide the symbol }
  1306. if (m_duplicate_names in aktmodeswitches) and
  1307. (hsym.typ=symconst.unitsym) then
  1308. hsym.owner.rename(hsym.name,'hidden'+hsym.name)
  1309. else
  1310. begin
  1311. DuplicateSym(hsym);
  1312. exit;
  1313. end;
  1314. end;
  1315. end;
  1316. inherited insert(sym);
  1317. end;
  1318. {****************************************************************************
  1319. TGlobalSymtable
  1320. ****************************************************************************}
  1321. constructor tglobalsymtable.create(const n : string);
  1322. begin
  1323. inherited create(n);
  1324. symtabletype:=globalsymtable;
  1325. symtablelevel:=main_program_level;
  1326. unitid:=0;
  1327. {$ifdef GDB}
  1328. if cs_gdb_dbx in aktglobalswitches then
  1329. begin
  1330. dbx_count := 0;
  1331. unittypecount:=1;
  1332. pglobaltypecount := @unittypecount;
  1333. {unitid:=current_module.unitcount;}
  1334. debugList.concat(tai_comment.Create(strpnew('Global '+name^+' has index '+tostr(unitid))));
  1335. debugList.concat(Tai_stabs.Create(strpnew('"'+name^+'",'+tostr(N_BINCL)+',0,0,0')));
  1336. {inc(current_module.unitcount);}
  1337. { we can't use dbx_vcount, because we don't know
  1338. if the object file will be loaded before or afeter PM }
  1339. dbx_count_ok:=false;
  1340. dbx_counter:=@dbx_count;
  1341. do_count_dbx:=true;
  1342. end;
  1343. {$endif GDB}
  1344. end;
  1345. procedure tglobalsymtable.ppuload(ppufile:tcompilerppufile);
  1346. {$ifdef GDB}
  1347. var
  1348. b : byte;
  1349. {$endif GDB}
  1350. begin
  1351. {$ifdef GDB}
  1352. if cs_gdb_dbx in aktglobalswitches then
  1353. begin
  1354. UnitTypeCount:=1;
  1355. PglobalTypeCount:=@UnitTypeCount;
  1356. end;
  1357. {$endif GDB}
  1358. aktglobalsymtable:=self;
  1359. next:=symtablestack;
  1360. symtablestack:=self;
  1361. inherited ppuload(ppufile);
  1362. { now we can deref the syms and defs }
  1363. deref;
  1364. { restore symtablestack }
  1365. symtablestack:=next;
  1366. { read dbx count }
  1367. {$ifdef GDB}
  1368. if (current_module.flags and uf_has_dbx)<>0 then
  1369. begin
  1370. b:=ppufile.readentry;
  1371. if b<>ibdbxcount then
  1372. Message(unit_f_ppu_dbx_count_problem)
  1373. else
  1374. dbx_count:=ppufile.getlongint;
  1375. {$IfDef EXTDEBUG}
  1376. writeln('Read dbx_count ',dbx_count,' in unit ',name^,'.ppu');
  1377. {$ENDIF EXTDEBUG}
  1378. { we can't use dbx_vcount, because we don't know
  1379. if the object file will be loaded before or afeter PM }
  1380. dbx_count_ok := {true}false;
  1381. end
  1382. else
  1383. begin
  1384. dbx_count:=-1;
  1385. dbx_count_ok:=false;
  1386. end;
  1387. {$endif GDB}
  1388. end;
  1389. procedure tglobalsymtable.ppuwrite(ppufile:tcompilerppufile);
  1390. begin
  1391. aktglobalsymtable:=self;
  1392. { write the symtable entries }
  1393. inherited ppuwrite(ppufile);
  1394. { write dbx count }
  1395. {$ifdef GDB}
  1396. if cs_gdb_dbx in aktglobalswitches then
  1397. begin
  1398. {$IfDef EXTDEBUG}
  1399. writeln('Writing dbx_count ',dbx_count,' in unit ',name^,'.ppu');
  1400. {$ENDIF EXTDEBUG}
  1401. ppufile.do_crc:=false;
  1402. ppufile.putlongint(dbx_count);
  1403. ppufile.writeentry(ibdbxcount);
  1404. ppufile.do_crc:=true;
  1405. end;
  1406. {$endif GDB}
  1407. end;
  1408. procedure tglobalsymtable.load_references(ppufile:tcompilerppufile;locals:boolean);
  1409. begin
  1410. aktglobalsymtable:=self;
  1411. inherited load_references(ppufile,locals);
  1412. end;
  1413. procedure tglobalsymtable.write_references(ppufile:tcompilerppufile;locals:boolean);
  1414. begin
  1415. aktglobalsymtable:=self;
  1416. inherited write_references(ppufile,locals);
  1417. end;
  1418. procedure tglobalsymtable.insert(sym:tsymentry);
  1419. var
  1420. hsym : tsym;
  1421. begin
  1422. { also check the global symtable }
  1423. if assigned(next) and
  1424. (next.unitid=0) then
  1425. begin
  1426. hsym:=tsym(next.search(sym.name));
  1427. if assigned(hsym) then
  1428. begin
  1429. { Delphi you can have a symbol with the same name as the
  1430. unit, the unit can then not be accessed anymore using
  1431. <unit>.<id>, so we can hide the symbol }
  1432. if (m_duplicate_names in aktmodeswitches) and
  1433. (hsym.typ=symconst.unitsym) then
  1434. hsym.owner.rename(hsym.name,'hidden'+hsym.name)
  1435. else
  1436. begin
  1437. DuplicateSym(hsym);
  1438. exit;
  1439. end;
  1440. end;
  1441. end;
  1442. hsym:=tsym(search(sym.name));
  1443. if assigned(hsym) then
  1444. begin
  1445. { Delphi you can have a symbol with the same name as the
  1446. unit, the unit can then not be accessed anymore using
  1447. <unit>.<id>, so we can hide the symbol }
  1448. if (m_duplicate_names in aktmodeswitches) and
  1449. (hsym.typ=symconst.unitsym) then
  1450. hsym.owner.rename(hsym.name,'hidden'+hsym.name)
  1451. else
  1452. begin
  1453. DuplicateSym(hsym);
  1454. exit;
  1455. end;
  1456. end;
  1457. inherited insert(sym);
  1458. end;
  1459. {$ifdef GDB}
  1460. function tglobalsymtable.getnewtypecount : word;
  1461. begin
  1462. if not (cs_gdb_dbx in aktglobalswitches) then
  1463. getnewtypecount:=inherited getnewtypecount
  1464. else
  1465. begin
  1466. getnewtypecount:=unittypecount;
  1467. inc(unittypecount);
  1468. end;
  1469. end;
  1470. {$endif}
  1471. {****************************************************************************
  1472. TWITHSYMTABLE
  1473. ****************************************************************************}
  1474. constructor twithsymtable.create(aowner:tdef;asymsearch:TDictionary;refnode:pointer{tnode});
  1475. begin
  1476. inherited create('');
  1477. symtabletype:=withsymtable;
  1478. withrefnode:=refnode;
  1479. { we don't need the symsearch }
  1480. symsearch.free;
  1481. { set the defaults }
  1482. symsearch:=asymsearch;
  1483. defowner:=aowner;
  1484. end;
  1485. destructor twithsymtable.destroy;
  1486. begin
  1487. tobject(withrefnode).free;
  1488. symsearch:=nil;
  1489. inherited destroy;
  1490. end;
  1491. procedure twithsymtable.clear;
  1492. begin
  1493. { remove no entry from a withsymtable as it is only a pointer to the
  1494. recorddef or objectdef symtable }
  1495. end;
  1496. {****************************************************************************
  1497. TSTT_ExceptionSymtable
  1498. ****************************************************************************}
  1499. constructor tstt_exceptsymtable.create;
  1500. begin
  1501. inherited create('');
  1502. symtabletype:=stt_exceptsymtable;
  1503. end;
  1504. {*****************************************************************************
  1505. Helper Routines
  1506. *****************************************************************************}
  1507. function findunitsymtable(st:tsymtable):tsymtable;
  1508. begin
  1509. findunitsymtable:=nil;
  1510. repeat
  1511. if not assigned(st) then
  1512. internalerror(5566561);
  1513. case st.symtabletype of
  1514. localsymtable,
  1515. parasymtable,
  1516. staticsymtable :
  1517. exit;
  1518. globalsymtable :
  1519. begin
  1520. findunitsymtable:=st;
  1521. exit;
  1522. end;
  1523. objectsymtable :
  1524. st:=st.defowner.owner;
  1525. recordsymtable :
  1526. begin
  1527. { don't continue when the current
  1528. symtable is used for variant records }
  1529. if trecorddef(st.defowner).isunion then
  1530. begin
  1531. findunitsymtable:=nil;
  1532. exit;
  1533. end
  1534. else
  1535. st:=st.defowner.owner;
  1536. end;
  1537. else
  1538. internalerror(5566562);
  1539. end;
  1540. until false;
  1541. end;
  1542. procedure duplicatesym(sym:tsym);
  1543. var
  1544. st : tsymtable;
  1545. begin
  1546. Message1(sym_e_duplicate_id,sym.realname);
  1547. st:=findunitsymtable(sym.owner);
  1548. with sym.fileinfo do
  1549. begin
  1550. if assigned(st) and (st.unitid<>0) then
  1551. Message2(sym_h_duplicate_id_where,'unit '+st.name^,tostr(line))
  1552. else
  1553. Message2(sym_h_duplicate_id_where,current_module.sourcefiles.get_file_name(fileindex),tostr(line));
  1554. end;
  1555. end;
  1556. procedure incompatibletypes(def1,def2:tdef);
  1557. var
  1558. s1,s2 : string;
  1559. begin
  1560. s1:=def1.typename;
  1561. s2:=def2.typename;
  1562. { When the names are the same try to include the unit name }
  1563. if upper(s1)=upper(s2) then
  1564. begin
  1565. if (def1.owner.symtabletype in [globalsymtable,staticsymtable]) then
  1566. s1:=def1.owner.realname^+'.'+s1;
  1567. if (def2.owner.symtabletype in [globalsymtable,staticsymtable]) then
  1568. s2:=def2.owner.realname^+'.'+s2;
  1569. end;
  1570. if def2.deftype<>errordef then
  1571. CGMessage2(type_e_incompatible_types,s1,s2);
  1572. end;
  1573. {*****************************************************************************
  1574. Search
  1575. *****************************************************************************}
  1576. function searchsym(const s : stringid;var srsym:tsym;var srsymtable:tsymtable):boolean;
  1577. var
  1578. speedvalue : cardinal;
  1579. begin
  1580. speedvalue:=getspeedvalue(s);
  1581. srsymtable:=symtablestack;
  1582. while assigned(srsymtable) do
  1583. begin
  1584. srsym:=tsym(srsymtable.speedsearch(s,speedvalue));
  1585. if assigned(srsym) and
  1586. (not assigned(current_procinfo) or
  1587. Tsym(srsym).is_visible_for_object(current_procinfo.procdef._class)) then
  1588. begin
  1589. searchsym:=true;
  1590. exit;
  1591. end
  1592. else
  1593. srsymtable:=srsymtable.next;
  1594. end;
  1595. searchsym:=false;
  1596. end;
  1597. function searchsym_type(const s : stringid;var srsym:tsym;var srsymtable:tsymtable):boolean;
  1598. var
  1599. speedvalue : cardinal;
  1600. begin
  1601. speedvalue:=getspeedvalue(s);
  1602. srsymtable:=symtablestack;
  1603. while assigned(srsymtable) do
  1604. begin
  1605. {
  1606. It is not possible to have type defintions in:
  1607. records
  1608. objects
  1609. parameters
  1610. }
  1611. if not(srsymtable.symtabletype in [recordsymtable,objectsymtable,parasymtable]) then
  1612. begin
  1613. srsym:=tsym(srsymtable.speedsearch(s,speedvalue));
  1614. if assigned(srsym) and
  1615. (not assigned(current_procinfo) or
  1616. Tsym(srsym).is_visible_for_object(current_procinfo.procdef._class)) then
  1617. begin
  1618. result:=true;
  1619. exit;
  1620. end
  1621. end;
  1622. srsymtable:=srsymtable.next;
  1623. end;
  1624. result:=false;
  1625. end;
  1626. function searchsymonlyin(p : tsymtable;const s : stringid):tsym;
  1627. var
  1628. srsym : tsym;
  1629. begin
  1630. { the caller have to take care if srsym=nil }
  1631. if assigned(p) then
  1632. begin
  1633. srsym:=tsym(p.search(s));
  1634. if assigned(srsym) then
  1635. begin
  1636. searchsymonlyin:=srsym;
  1637. exit;
  1638. end;
  1639. { also check in the local symtbale if it exists }
  1640. if (p=tsymtable(current_module.globalsymtable)) then
  1641. begin
  1642. srsym:=tsym(current_module.localsymtable.search(s));
  1643. if assigned(srsym) then
  1644. begin
  1645. searchsymonlyin:=srsym;
  1646. exit;
  1647. end;
  1648. end
  1649. end;
  1650. searchsymonlyin:=nil;
  1651. end;
  1652. function searchsym_in_class(classh:tobjectdef;const s : stringid):tsym;
  1653. var
  1654. speedvalue : cardinal;
  1655. topclassh : tobjectdef;
  1656. sym : tsym;
  1657. begin
  1658. speedvalue:=getspeedvalue(s);
  1659. { when the class passed is defined in this unit we
  1660. need to use the scope of that class. This is a trick
  1661. that can be used to access protected members in other
  1662. units. At least kylix supports it this way (PFV) }
  1663. if assigned(classh) and
  1664. (classh.owner.symtabletype in [globalsymtable,staticsymtable]) and
  1665. (classh.owner.unitid=0) then
  1666. topclassh:=classh
  1667. else
  1668. begin
  1669. if assigned(current_procinfo) then
  1670. topclassh:=current_procinfo.procdef._class
  1671. else
  1672. topclassh:=nil;
  1673. end;
  1674. sym:=nil;
  1675. while assigned(classh) do
  1676. begin
  1677. sym:=tsym(classh.symtable.speedsearch(s,speedvalue));
  1678. if assigned(sym) and
  1679. Tsym(sym).is_visible_for_object(topclassh) then
  1680. break;
  1681. classh:=classh.childof;
  1682. end;
  1683. searchsym_in_class:=sym;
  1684. end;
  1685. function searchsym_in_class_by_msgint(classh:tobjectdef;i:longint):tsym;
  1686. var
  1687. topclassh : tobjectdef;
  1688. def : tdef;
  1689. sym : tsym;
  1690. begin
  1691. { when the class passed is defined in this unit we
  1692. need to use the scope of that class. This is a trick
  1693. that can be used to access protected members in other
  1694. units. At least kylix supports it this way (PFV) }
  1695. if assigned(classh) and
  1696. (classh.owner.symtabletype in [globalsymtable,staticsymtable]) and
  1697. (classh.owner.unitid=0) then
  1698. topclassh:=classh
  1699. else
  1700. begin
  1701. if assigned(current_procinfo) then
  1702. topclassh:=current_procinfo.procdef._class
  1703. else
  1704. topclassh:=nil;
  1705. end;
  1706. sym:=nil;
  1707. def:=nil;
  1708. while assigned(classh) do
  1709. begin
  1710. def:=tdef(classh.symtable.defindex.first);
  1711. while assigned(def) do
  1712. begin
  1713. if (def.deftype=procdef) and
  1714. (po_msgint in tprocdef(def).procoptions) and
  1715. (tprocdef(def).messageinf.i=i) then
  1716. begin
  1717. sym:=tprocdef(def).procsym;
  1718. if assigned(topclassh) then
  1719. begin
  1720. if tprocdef(def).is_visible_for_object(topclassh) then
  1721. break;
  1722. end
  1723. else
  1724. break;
  1725. end;
  1726. def:=tdef(def.indexnext);
  1727. end;
  1728. if assigned(sym) then
  1729. break;
  1730. classh:=classh.childof;
  1731. end;
  1732. searchsym_in_class_by_msgint:=sym;
  1733. end;
  1734. function searchsym_in_class_by_msgstr(classh:tobjectdef;const s:string):tsym;
  1735. var
  1736. topclassh : tobjectdef;
  1737. def : tdef;
  1738. sym : tsym;
  1739. begin
  1740. { when the class passed is defined in this unit we
  1741. need to use the scope of that class. This is a trick
  1742. that can be used to access protected members in other
  1743. units. At least kylix supports it this way (PFV) }
  1744. if assigned(classh) and
  1745. (classh.owner.symtabletype in [globalsymtable,staticsymtable]) and
  1746. (classh.owner.unitid=0) then
  1747. topclassh:=classh
  1748. else
  1749. begin
  1750. if assigned(current_procinfo) then
  1751. topclassh:=current_procinfo.procdef._class
  1752. else
  1753. topclassh:=nil;
  1754. end;
  1755. sym:=nil;
  1756. def:=nil;
  1757. while assigned(classh) do
  1758. begin
  1759. def:=tdef(classh.symtable.defindex.first);
  1760. while assigned(def) do
  1761. begin
  1762. if (def.deftype=procdef) and
  1763. (po_msgstr in tprocdef(def).procoptions) and
  1764. (tprocdef(def).messageinf.str=s) then
  1765. begin
  1766. sym:=tprocdef(def).procsym;
  1767. if assigned(topclassh) then
  1768. begin
  1769. if tprocdef(def).is_visible_for_object(topclassh) then
  1770. break;
  1771. end
  1772. else
  1773. break;
  1774. end;
  1775. def:=tdef(def.indexnext);
  1776. end;
  1777. if assigned(sym) then
  1778. break;
  1779. classh:=classh.childof;
  1780. end;
  1781. searchsym_in_class_by_msgstr:=sym;
  1782. end;
  1783. function search_assignment_operator(from_def,to_def:Tdef):Tprocdef;
  1784. var st:Tsymtable;
  1785. sym:Tprocsym;
  1786. sv:cardinal;
  1787. begin
  1788. st:=symtablestack;
  1789. sv:=getspeedvalue('assign');
  1790. while st<>nil do
  1791. begin
  1792. sym:=Tprocsym(st.speedsearch('assign',sv));
  1793. if sym<>nil then
  1794. begin
  1795. if sym.typ<>procsym then
  1796. internalerror(200402031);
  1797. search_assignment_operator:=sym.search_procdef_assignment_operator(from_def,to_def);
  1798. if search_assignment_operator<>nil then
  1799. break;
  1800. end;
  1801. st:=st.next;
  1802. end;
  1803. end;
  1804. function search_unary_operator(op:Ttoken;def:Tdef):Tprocdef;
  1805. var st:Tsymtable;
  1806. sym:Tprocsym;
  1807. sv:cardinal;
  1808. begin
  1809. st:=symtablestack;
  1810. sv:=getspeedvalue(overloaded_names[op]);
  1811. while st<>nil do
  1812. begin
  1813. sym:=Tprocsym(st.speedsearch(overloaded_names[op],sv));
  1814. if sym<>nil then
  1815. begin
  1816. if sym.typ<>procsym then
  1817. internalerror(200402031);
  1818. search_unary_operator:=sym.search_procdef_unary_operator(def);
  1819. if search_unary_operator<>nil then
  1820. break;
  1821. end;
  1822. st:=st.next;
  1823. end;
  1824. end;
  1825. function search_binary_operator(op:Ttoken;def1,def2:Tdef):Tprocdef;
  1826. var st:Tsymtable;
  1827. sym:Tprocsym;
  1828. sv:cardinal;
  1829. begin
  1830. st:=symtablestack;
  1831. sv:=getspeedvalue(overloaded_names[op]);
  1832. while st<>nil do
  1833. begin
  1834. sym:=Tprocsym(st.speedsearch(overloaded_names[op],sv));
  1835. if sym<>nil then
  1836. begin
  1837. if sym.typ<>procsym then
  1838. internalerror(200402031);
  1839. search_binary_operator:=sym.search_procdef_binary_operator(def1,def2);
  1840. if search_binary_operator<>nil then
  1841. break;
  1842. end;
  1843. st:=st.next;
  1844. end;
  1845. end;
  1846. function searchsystype(const s: stringid; var srsym: ttypesym): boolean;
  1847. var
  1848. symowner: tsymtable;
  1849. begin
  1850. if not(cs_compilesystem in aktmoduleswitches) then
  1851. srsym := ttypesym(searchsymonlyin(systemunit,s))
  1852. else
  1853. searchsym(s,tsym(srsym),symowner);
  1854. searchsystype :=
  1855. assigned(srsym) and
  1856. (srsym.typ = typesym);
  1857. end;
  1858. function searchsysvar(const s: stringid; var srsym: tvarsym; var symowner: tsymtable): boolean;
  1859. begin
  1860. if not(cs_compilesystem in aktmoduleswitches) then
  1861. begin
  1862. srsym := tvarsym(searchsymonlyin(systemunit,s));
  1863. symowner := systemunit;
  1864. end
  1865. else
  1866. searchsym(s,tsym(srsym),symowner);
  1867. searchsysvar :=
  1868. assigned(srsym) and
  1869. (srsym.typ = varsym);
  1870. end;
  1871. function search_class_member(pd : tobjectdef;const s : string):tsym;
  1872. { searches n in symtable of pd and all anchestors }
  1873. var
  1874. speedvalue : cardinal;
  1875. srsym : tsym;
  1876. begin
  1877. speedvalue:=getspeedvalue(s);
  1878. while assigned(pd) do
  1879. begin
  1880. srsym:=tsym(pd.symtable.speedsearch(s,speedvalue));
  1881. if assigned(srsym) then
  1882. begin
  1883. search_class_member:=srsym;
  1884. exit;
  1885. end;
  1886. pd:=pd.childof;
  1887. end;
  1888. search_class_member:=nil;
  1889. end;
  1890. procedure reset_all_defs;
  1891. var st:Tsymtable;
  1892. begin
  1893. st:=symtablestack;
  1894. while st<>nil do
  1895. begin
  1896. Tstoredsymtable(st).reset_all_defs;
  1897. st:=st.next;
  1898. end;
  1899. end;
  1900. {*****************************************************************************
  1901. Definition Helpers
  1902. *****************************************************************************}
  1903. procedure globaldef(const s : string;var t:ttype);
  1904. var st : string;
  1905. symt : tsymtable;
  1906. srsym : tsym;
  1907. srsymtable : tsymtable;
  1908. begin
  1909. srsym := nil;
  1910. if pos('.',s) > 0 then
  1911. begin
  1912. st := copy(s,1,pos('.',s)-1);
  1913. searchsym(st,srsym,srsymtable);
  1914. st := copy(s,pos('.',s)+1,255);
  1915. if assigned(srsym) then
  1916. begin
  1917. if srsym.typ = unitsym then
  1918. begin
  1919. symt := tunitsym(srsym).unitsymtable;
  1920. srsym := tsym(symt.search(st));
  1921. end else srsym := nil;
  1922. end;
  1923. end else st := s;
  1924. if srsym = nil then
  1925. searchsym(st,srsym,srsymtable);
  1926. if srsym = nil then
  1927. srsym:=searchsymonlyin(systemunit,st);
  1928. if (not assigned(srsym)) or
  1929. (srsym.typ<>typesym) then
  1930. begin
  1931. Message(type_e_type_id_expected);
  1932. t:=generrortype;
  1933. exit;
  1934. end;
  1935. t := ttypesym(srsym).restype;
  1936. end;
  1937. {****************************************************************************
  1938. Object Helpers
  1939. ****************************************************************************}
  1940. procedure search_class_overloads(aprocsym : tprocsym);
  1941. { searches n in symtable of pd and all anchestors }
  1942. var
  1943. speedvalue : cardinal;
  1944. srsym : tprocsym;
  1945. s : string;
  1946. objdef : tobjectdef;
  1947. begin
  1948. if aprocsym.overloadchecked then
  1949. exit;
  1950. aprocsym.overloadchecked:=true;
  1951. if (aprocsym.owner.symtabletype<>objectsymtable) then
  1952. internalerror(200111021);
  1953. objdef:=tobjectdef(aprocsym.owner.defowner);
  1954. { we start in the parent }
  1955. if not assigned(objdef.childof) then
  1956. exit;
  1957. objdef:=objdef.childof;
  1958. s:=aprocsym.name;
  1959. speedvalue:=getspeedvalue(s);
  1960. while assigned(objdef) do
  1961. begin
  1962. srsym:=tprocsym(objdef.symtable.speedsearch(s,speedvalue));
  1963. if assigned(srsym) then
  1964. begin
  1965. if (srsym.typ<>procsym) then
  1966. internalerror(200111022);
  1967. if srsym.is_visible_for_object(tobjectdef(aprocsym.owner.defowner)) then
  1968. begin
  1969. srsym.add_para_match_to(Aprocsym,[cpo_ignorehidden,cpo_allowdefaults]);
  1970. { we can stop if the overloads were already added
  1971. for the found symbol }
  1972. if srsym.overloadchecked then
  1973. break;
  1974. end;
  1975. end;
  1976. { next parent }
  1977. objdef:=objdef.childof;
  1978. end;
  1979. end;
  1980. procedure tstoredsymtable.testfordefaultproperty(p : TNamedIndexItem;arg:pointer);
  1981. begin
  1982. if (tsym(p).typ=propertysym) and
  1983. (ppo_defaultproperty in tpropertysym(p).propoptions) then
  1984. ppointer(arg)^:=p;
  1985. end;
  1986. function search_default_property(pd : tobjectdef) : tpropertysym;
  1987. { returns the default property of a class, searches also anchestors }
  1988. var
  1989. _defaultprop : tpropertysym;
  1990. begin
  1991. _defaultprop:=nil;
  1992. while assigned(pd) do
  1993. begin
  1994. pd.symtable.foreach({$ifdef FPCPROCVAR}@{$endif}tstoredsymtable(pd.symtable).testfordefaultproperty,@_defaultprop);
  1995. if assigned(_defaultprop) then
  1996. break;
  1997. pd:=pd.childof;
  1998. end;
  1999. search_default_property:=_defaultprop;
  2000. end;
  2001. {$ifdef UNITALIASES}
  2002. {****************************************************************************
  2003. TUNIT_ALIAS
  2004. ****************************************************************************}
  2005. constructor tunit_alias.create(const n:string);
  2006. var
  2007. i : longint;
  2008. begin
  2009. i:=pos('=',n);
  2010. if i=0 then
  2011. fail;
  2012. inherited createname(Copy(n,1,i-1));
  2013. newname:=stringdup(Copy(n,i+1,255));
  2014. end;
  2015. destructor tunit_alias.destroy;
  2016. begin
  2017. stringdispose(newname);
  2018. inherited destroy;
  2019. end;
  2020. procedure addunitalias(const n:string);
  2021. begin
  2022. unitaliases^.insert(tunit_alias,init(Upper(n))));
  2023. end;
  2024. function getunitalias(const n:string):string;
  2025. var
  2026. p : punit_alias;
  2027. begin
  2028. p:=punit_alias(unitaliases^.search(Upper(n)));
  2029. if assigned(p) then
  2030. getunitalias:=punit_alias(p).newname^
  2031. else
  2032. getunitalias:=n;
  2033. end;
  2034. {$endif UNITALIASES}
  2035. {****************************************************************************
  2036. Symtable Stack
  2037. ****************************************************************************}
  2038. {$ifdef DEBUG}
  2039. procedure test_symtablestack;
  2040. var
  2041. p : tsymtable;
  2042. i : longint;
  2043. begin
  2044. p:=symtablestack;
  2045. i:=0;
  2046. while assigned(p) do
  2047. begin
  2048. inc(i);
  2049. p:=p.next;
  2050. if i>500 then
  2051. Message(sym_f_internal_error_in_symtablestack);
  2052. end;
  2053. end;
  2054. procedure list_symtablestack;
  2055. var
  2056. p : tsymtable;
  2057. i : longint;
  2058. begin
  2059. p:=symtablestack;
  2060. i:=0;
  2061. while assigned(p) do
  2062. begin
  2063. inc(i);
  2064. writeln(i,' ',p.name^);
  2065. p:=p.next;
  2066. if i>500 then
  2067. Message(sym_f_internal_error_in_symtablestack);
  2068. end;
  2069. end;
  2070. {$endif DEBUG}
  2071. {****************************************************************************
  2072. Init/Done Symtable
  2073. ****************************************************************************}
  2074. procedure InitSymtable;
  2075. var
  2076. token : ttoken;
  2077. begin
  2078. { Reset symbolstack }
  2079. registerdef:=false;
  2080. symtablestack:=nil;
  2081. systemunit:=nil;
  2082. {$ifdef GDB}
  2083. globaltypecount:=1;
  2084. pglobaltypecount:=@globaltypecount;
  2085. {$endif GDB}
  2086. { defs for internal use }
  2087. voidprocdef:=tprocdef.create(unknown_level);
  2088. { create error syms and def }
  2089. generrorsym:=terrorsym.create;
  2090. generrortype.setdef(terrordef.create);
  2091. {$ifdef UNITALIASES}
  2092. { unit aliases }
  2093. unitaliases:=tdictionary.create;
  2094. {$endif}
  2095. end;
  2096. procedure DoneSymtable;
  2097. begin
  2098. voidprocdef.free;
  2099. generrorsym.free;
  2100. generrortype.def.free;
  2101. {$ifdef UNITALIASES}
  2102. unitaliases.free;
  2103. {$endif}
  2104. end;
  2105. end.
  2106. {
  2107. $Log$
  2108. Revision 1.136 2004-02-11 19:59:06 peter
  2109. * fix compilation without GDB
  2110. Revision 1.135 2004/02/06 22:37:00 daniel
  2111. * Removed not very usefull nextglobal & previousglobal fields from
  2112. Tstoreddef, saving 78 kb of memory
  2113. Revision 1.134 2004/02/04 22:15:16 daniel
  2114. * Rtti generation moved to ncgutil
  2115. * Assmtai usage of symsym removed
  2116. * operator overloading cleanup up
  2117. Revision 1.133 2004/01/31 22:48:31 daniel
  2118. * Fix stabs generation problem reported by Jonas
  2119. Revision 1.132 2004/01/31 18:40:15 daniel
  2120. * Last steps before removal of aasmtai dependency in symsym can be
  2121. accomplished.
  2122. Revision 1.131 2004/01/30 14:33:06 florian
  2123. * fixed more alignment issues
  2124. Revision 1.130 2004/01/30 13:42:03 florian
  2125. * fixed more alignment issues
  2126. Revision 1.129 2004/01/29 16:51:29 peter
  2127. * fixed alignment calculation for variant records
  2128. * fixed alignment padding of records
  2129. Revision 1.128 2004/01/28 22:16:31 peter
  2130. * more record alignment fixes
  2131. Revision 1.127 2004/01/28 20:30:18 peter
  2132. * record alignment splitted in fieldalignment and recordalignment,
  2133. the latter is used when this record is inserted in another record.
  2134. Revision 1.126 2004/01/26 16:12:28 daniel
  2135. * reginfo now also only allocated during register allocation
  2136. * third round of gdb cleanups: kick out most of concatstabto
  2137. Revision 1.125 2004/01/15 15:16:18 daniel
  2138. * Some minor stuff
  2139. * Managed to eliminate speed effects of string compression
  2140. Revision 1.124 2004/01/11 23:56:20 daniel
  2141. * Experiment: Compress strings to save memory
  2142. Did not save a single byte of mem; clearly the core size is boosted by
  2143. temporary memory usage...
  2144. Revision 1.123 2003/11/10 22:02:52 peter
  2145. * cross unit inlining fixed
  2146. Revision 1.122 2003/11/08 17:08:44 florian
  2147. * fixed strange error message about expecting erroneous types,
  2148. usually this is caused by other errors so it isn't important
  2149. Revision 1.121 2003/10/30 16:23:13 peter
  2150. * don't search for overloads in parents for constructors
  2151. Revision 1.120 2003/10/23 14:44:07 peter
  2152. * splitted buildderef and buildderefimpl to fix interface crc
  2153. calculation
  2154. Revision 1.119 2003/10/22 20:40:00 peter
  2155. * write derefdata in a separate ppu entry
  2156. Revision 1.118 2003/10/22 15:22:33 peter
  2157. * fixed unitsym-globalsymtable relation so the uses of a unit
  2158. is counted correctly
  2159. Revision 1.117 2003/10/21 18:16:13 peter
  2160. * IncompatibleTypes() added that will include unit names when
  2161. the typenames are the same
  2162. Revision 1.116 2003/10/17 14:38:32 peter
  2163. * 64k registers supported
  2164. * fixed some memory leaks
  2165. Revision 1.115 2003/10/13 14:05:12 peter
  2166. * removed is_visible_for_proc
  2167. * search also for class overloads when finding interface
  2168. implementations
  2169. Revision 1.114 2003/10/07 15:17:07 peter
  2170. * inline supported again, LOC_REFERENCEs are used to pass the
  2171. parameters
  2172. * inlineparasymtable,inlinelocalsymtable removed
  2173. * exitlabel inserting fixed
  2174. Revision 1.113 2003/10/03 14:43:29 peter
  2175. * don't report unused hidden parameters
  2176. Revision 1.112 2003/10/02 21:13:46 peter
  2177. * protected visibility fixes
  2178. Revision 1.111 2003/10/01 19:05:33 peter
  2179. * searchsym_type to search for type definitions. It ignores
  2180. records,objects and parameters
  2181. Revision 1.110 2003/09/23 17:56:06 peter
  2182. * locals and paras are allocated in the code generation
  2183. * tvarsym.localloc contains the location of para/local when
  2184. generating code for the current procedure
  2185. Revision 1.109 2003/08/23 22:31:08 peter
  2186. * unchain operators before adding to overloaded list
  2187. Revision 1.108 2003/06/25 18:31:23 peter
  2188. * sym,def resolving partly rewritten to support also parent objects
  2189. not directly available through the uses clause
  2190. Revision 1.107 2003/06/13 21:19:31 peter
  2191. * current_procdef removed, use current_procinfo.procdef instead
  2192. Revision 1.106 2003/06/09 18:26:27 peter
  2193. * para can be the same as function name in delphi
  2194. Revision 1.105 2003/06/08 11:40:00 peter
  2195. * check parast when inserting in localst
  2196. Revision 1.104 2003/06/07 20:26:32 peter
  2197. * re-resolving added instead of reloading from ppu
  2198. * tderef object added to store deref info for resolving
  2199. Revision 1.103 2003/05/25 11:34:17 peter
  2200. * methodpointer self pushing fixed
  2201. Revision 1.102 2003/05/23 14:27:35 peter
  2202. * remove some unit dependencies
  2203. * current_procinfo changes to store more info
  2204. Revision 1.101 2003/05/16 14:32:58 peter
  2205. * fix dup check for hiding the result varsym in localst, the result
  2206. sym was already in the localst when adding the locals
  2207. Revision 1.100 2003/05/15 18:58:53 peter
  2208. * removed selfpointer_offset, vmtpointer_offset
  2209. * tvarsym.adjusted_address
  2210. * address in localsymtable is now in the real direction
  2211. * removed some obsolete globals
  2212. Revision 1.99 2003/05/13 15:17:13 peter
  2213. * fix crash with hiding function result. The function result is now
  2214. inserted as last so the symbol that we are going to insert is the
  2215. result and needs to be renamed instead of the already existing
  2216. symbol
  2217. Revision 1.98 2003/05/11 14:45:12 peter
  2218. * tloadnode does not support objectsymtable,withsymtable anymore
  2219. * withnode cleanup
  2220. * direct with rewritten to use temprefnode
  2221. Revision 1.97 2003/04/27 11:21:34 peter
  2222. * aktprocdef renamed to current_procinfo.procdef
  2223. * procinfo renamed to current_procinfo
  2224. * procinfo will now be stored in current_module so it can be
  2225. cleaned up properly
  2226. * gen_main_procsym changed to create_main_proc and release_main_proc
  2227. to also generate a tprocinfo structure
  2228. * fixed unit implicit initfinal
  2229. Revision 1.96 2003/04/27 07:29:51 peter
  2230. * current_procinfo.procdef cleanup, current_procdef is now always nil when parsing
  2231. a new procdef declaration
  2232. * aktprocsym removed
  2233. * lexlevel removed, use symtable.symtablelevel instead
  2234. * implicit init/final code uses the normal genentry/genexit
  2235. * funcret state checking updated for new funcret handling
  2236. Revision 1.95 2003/04/26 00:33:07 peter
  2237. * vo_is_result flag added for the special RESULT symbol
  2238. Revision 1.94 2003/04/25 20:59:35 peter
  2239. * removed funcretn,funcretsym, function result is now in varsym
  2240. and aliases for result and function name are added using absolutesym
  2241. * vs_hidden parameter for funcret passed in parameter
  2242. * vs_hidden fixes
  2243. * writenode changed to printnode and released from extdebug
  2244. * -vp option added to generate a tree.log with the nodetree
  2245. * nicer printnode for statements, callnode
  2246. Revision 1.93 2003/04/16 07:53:11 jonas
  2247. * calculation of parameter and resultlocation offsets now depends on
  2248. tg.direction instead of if(n)def powerpc
  2249. Revision 1.92 2003/04/05 21:09:32 jonas
  2250. * several ppc/generic result offset related fixes. The "normal" result
  2251. offset seems now to be calculated correctly and a lot of duplicate
  2252. calculations have been removed. Nested functions accessing the parent's
  2253. function result don't work at all though :(
  2254. Revision 1.91 2003/03/17 18:56:49 peter
  2255. * ignore hints for default parameter values
  2256. Revision 1.90 2003/03/17 16:54:41 peter
  2257. * support DefaultHandler and anonymous inheritance fixed
  2258. for message methods
  2259. Revision 1.89 2002/12/29 14:57:50 peter
  2260. * unit loading changed to first register units and load them
  2261. afterwards. This is needed to support uses xxx in yyy correctly
  2262. * unit dependency check fixed
  2263. Revision 1.88 2002/12/27 18:07:45 peter
  2264. * fix crashes when searching symbols
  2265. Revision 1.87 2002/12/25 01:26:56 peter
  2266. * duplicate procsym-unitsym fix
  2267. Revision 1.86 2002/12/21 13:07:34 peter
  2268. * type redefine fix for tb0437
  2269. Revision 1.85 2002/12/07 14:27:10 carl
  2270. * 3% memory optimization
  2271. * changed some types
  2272. + added type checking with different size for call node and for
  2273. parameters
  2274. Revision 1.84 2002/12/06 17:51:11 peter
  2275. * merged cdecl and array fixes
  2276. Revision 1.83 2002/11/30 11:12:48 carl
  2277. + checking for symbols used with hint directives is done mostly in pexpr
  2278. only now
  2279. Revision 1.82 2002/11/29 22:31:20 carl
  2280. + unimplemented hint directive added
  2281. * hint directive parsing implemented
  2282. * warning on these directives
  2283. Revision 1.81 2002/11/27 20:04:09 peter
  2284. * tvarsym.get_push_size replaced by paramanager.push_size
  2285. Revision 1.80 2002/11/22 22:45:49 carl
  2286. + small optimization for speed
  2287. Revision 1.79 2002/11/19 16:26:33 pierre
  2288. * correct a stabs generation problem that lead to use errordef in stabs
  2289. Revision 1.78 2002/11/18 17:32:00 peter
  2290. * pass proccalloption to ret_in_xxx and push_xxx functions
  2291. Revision 1.77 2002/11/15 01:58:54 peter
  2292. * merged changes from 1.0.7 up to 04-11
  2293. - -V option for generating bug report tracing
  2294. - more tracing for option parsing
  2295. - errors for cdecl and high()
  2296. - win32 import stabs
  2297. - win32 records<=8 are returned in eax:edx (turned off by default)
  2298. - heaptrc update
  2299. - more info for temp management in .s file with EXTDEBUG
  2300. Revision 1.76 2002/11/09 15:29:28 carl
  2301. + bss / constant alignment fixes
  2302. * avoid incrementing address/datasize in local symtable for const's
  2303. Revision 1.75 2002/10/14 19:44:43 peter
  2304. * threadvars need 4 bytes extra for storing the threadvar index
  2305. Revision 1.74 2002/10/06 19:41:31 peter
  2306. * Add finalization of typed consts
  2307. * Finalization of globals in the main program
  2308. Revision 1.73 2002/10/05 12:43:29 carl
  2309. * fixes for Delphi 6 compilation
  2310. (warning : Some features do not work under Delphi)
  2311. Revision 1.72 2002/09/09 19:41:46 peter
  2312. * real fix internalerror for dup ids in union sym
  2313. Revision 1.71 2002/09/09 17:34:16 peter
  2314. * tdicationary.replace added to replace and item in a dictionary. This
  2315. is only allowed for the same name
  2316. * varsyms are inserted in symtable before the types are parsed. This
  2317. fixes the long standing "var longint : longint" bug
  2318. - consume_idlist and idstringlist removed. The loops are inserted
  2319. at the callers place and uses the symtable for duplicate id checking
  2320. Revision 1.70 2002/09/05 19:29:45 peter
  2321. * memdebug enhancements
  2322. Revision 1.69 2002/08/25 19:25:21 peter
  2323. * sym.insert_in_data removed
  2324. * symtable.insertvardata/insertconstdata added
  2325. * removed insert_in_data call from symtable.insert, it needs to be
  2326. called separatly. This allows to deref the address calculation
  2327. * procedures now calculate the parast addresses after the procedure
  2328. directives are parsed. This fixes the cdecl parast problem
  2329. * push_addr_param has an extra argument that specifies if cdecl is used
  2330. or not
  2331. Revision 1.68 2002/08/18 20:06:27 peter
  2332. * inlining is now also allowed in interface
  2333. * renamed write/load to ppuwrite/ppuload
  2334. * tnode storing in ppu
  2335. * nld,ncon,nbas are already updated for storing in ppu
  2336. Revision 1.67 2002/08/17 09:23:43 florian
  2337. * first part of procinfo rewrite
  2338. Revision 1.66 2002/08/11 13:24:15 peter
  2339. * saving of asmsymbols in ppu supported
  2340. * asmsymbollist global is removed and moved into a new class
  2341. tasmlibrarydata that will hold the info of a .a file which
  2342. corresponds with a single module. Added librarydata to tmodule
  2343. to keep the library info stored for the module. In the future the
  2344. objectfiles will also be stored to the tasmlibrarydata class
  2345. * all getlabel/newasmsymbol and friends are moved to the new class
  2346. Revision 1.65 2002/07/23 09:51:27 daniel
  2347. * Tried to make Tprocsym.defs protected. I didn't succeed but the cleanups
  2348. are worth comitting.
  2349. Revision 1.64 2002/07/16 15:34:21 florian
  2350. * exit is now a syssym instead of a keyword
  2351. Revision 1.63 2002/07/15 19:44:53 florian
  2352. * fixed crash with default parameters and stdcall calling convention
  2353. Revision 1.62 2002/07/01 18:46:28 peter
  2354. * internal linker
  2355. * reorganized aasm layer
  2356. Revision 1.61 2002/05/18 13:34:19 peter
  2357. * readded missing revisions
  2358. Revision 1.60 2002/05/16 19:46:45 carl
  2359. + defines.inc -> fpcdefs.inc to avoid conflicts if compiling by hand
  2360. + try to fix temp allocation (still in ifdef)
  2361. + generic constructor calls
  2362. + start of tassembler / tmodulebase class cleanup
  2363. Revision 1.58 2002/05/12 16:53:15 peter
  2364. * moved entry and exitcode to ncgutil and cgobj
  2365. * foreach gets extra argument for passing local data to the
  2366. iterator function
  2367. * -CR checks also class typecasts at runtime by changing them
  2368. into as
  2369. * fixed compiler to cycle with the -CR option
  2370. * fixed stabs with elf writer, finally the global variables can
  2371. be watched
  2372. * removed a lot of routines from cga unit and replaced them by
  2373. calls to cgobj
  2374. * u32bit-s32bit updates for and,or,xor nodes. When one element is
  2375. u32bit then the other is typecasted also to u32bit without giving
  2376. a rangecheck warning/error.
  2377. * fixed pascal calling method with reversing also the high tree in
  2378. the parast, detected by tcalcst3 test
  2379. Revision 1.57 2002/04/04 19:06:05 peter
  2380. * removed unused units
  2381. * use tlocation.size in cg.a_*loc*() routines
  2382. Revision 1.56 2002/03/04 19:10:11 peter
  2383. * removed compiler warnings
  2384. Revision 1.55 2002/02/03 09:30:07 peter
  2385. * more fixes for protected handling
  2386. Revision 1.54 2002/01/29 21:30:25 peter
  2387. * allow also dup id in delphi mode in interfaces
  2388. Revision 1.53 2002/01/29 19:46:00 peter
  2389. * fixed recordsymtable.insert_in() for inserting variant record fields
  2390. to not used symtable.insert() because that also updates alignmentinfo
  2391. which was already set
  2392. Revision 1.52 2002/01/24 18:25:50 peter
  2393. * implicit result variable generation for assembler routines
  2394. * removed m_tp modeswitch, use m_tp7 or not(m_fpc) instead
  2395. }