68ae5e1386abb36256f7fe452911e7273cb004b1
[mono.git] / mcs / mcs / decl.cs
1 //
2 // decl.cs: Declaration base class for structs, classes, enums and interfaces.
3 //
4 // Author: Miguel de Icaza (miguel@gnu.org)
5 //         Marek Safar (marek.safar@seznam.cz)
6 //
7 // Licensed under the terms of the GNU GPL
8 //
9 // (C) 2001 Ximian, Inc (http://www.ximian.com)
10 // (C) 2004 Novell, Inc
11 //
12 // TODO: Move the method verification stuff from the class.cs and interface.cs here
13 //
14
15 using System;
16 using System.Collections;
17 using System.Globalization;
18 using System.Reflection.Emit;
19 using System.Reflection;
20
21 #if BOOTSTRAP_WITH_OLDLIB
22 using XmlElement = System.Object;
23 #else
24 using System.Xml;
25 #endif
26
27 namespace Mono.CSharp {
28
29         public class MemberName {
30                 public readonly string Name;
31                 public readonly TypeArguments TypeArguments;
32
33                 public readonly MemberName Left;
34                 public readonly Location Location;
35
36                 public static readonly MemberName Null = new MemberName ("");
37
38                 bool is_double_colon;
39
40                 private MemberName (MemberName left, string name, bool is_double_colon,
41                                     Location loc)
42                 {
43                         this.Name = name;
44                         this.Location = loc;
45                         this.is_double_colon = is_double_colon;
46                         this.Left = left;
47                 }
48
49                 private MemberName (MemberName left, string name, bool is_double_colon,
50                                     TypeArguments args, Location loc)
51                         : this (left, name, is_double_colon, loc)
52                 {
53                         this.TypeArguments = args;
54                 }
55
56                 public MemberName (string name)
57                         : this (name, Location.Null)
58                 { }
59
60                 public MemberName (string name, Location loc)
61                         : this (null, name, false, loc)
62                 { }
63
64                 public MemberName (string name, TypeArguments args, Location loc)
65                         : this (null, name, false, args, loc)
66                 { }
67
68                 public MemberName (MemberName left, string name)
69                         : this (left, name, left != null ? left.Location : Location.Null)
70                 { }
71
72                 public MemberName (MemberName left, string name, Location loc)
73                         : this (left, name, false, loc)
74                 { }
75
76                 public MemberName (MemberName left, string name, TypeArguments args, Location loc)
77                         : this (left, name, false, args, loc)
78                 { }
79
80                 public MemberName (string alias, string name, Location loc)
81                         : this (new MemberName (alias, loc), name, true, loc)
82                 { }
83
84                 public MemberName (MemberName left, MemberName right)
85                         : this (left, right, right.Location)
86                 { }
87
88                 public MemberName (MemberName left, MemberName right, Location loc)
89                         : this (null, right.Name, false, right.TypeArguments, loc)
90                 {
91                         if (right.is_double_colon)
92                                 throw new InternalErrorException ("Cannot append double_colon member name");
93                         this.Left = (right.Left == null) ? left : new MemberName (left, right.Left);
94                 }
95
96                 public string GetName ()
97                 {
98                         return GetName (false);
99                 }
100
101                 public bool IsGeneric {
102                         get {
103                                 if (TypeArguments != null)
104                                         return true;
105                                 else if (Left != null)
106                                         return Left.IsGeneric;
107                                 else
108                                         return false;
109                         }
110                 }
111
112                 public string GetName (bool is_generic)
113                 {
114                         string name = is_generic ? Basename : Name;
115                         string connect = is_double_colon ? "::" : ".";
116                         if (Left != null)
117                                 return Left.GetName (is_generic) + connect + name;
118                         else
119                                 return name;
120                 }
121
122                 public string GetTypeName ()
123                 {
124                         string connect = is_double_colon ? "::" : ".";
125                         if (Left != null)
126                                 return Left.GetTypeName () + connect + Name;
127                         else
128                                 return Name;
129                 }
130
131                 public Expression GetTypeExpression ()
132                 {
133                         if (Left == null)
134                                 return new SimpleName (Name, Location);
135                         if (is_double_colon) {
136                                 if (Left.Left != null)
137                                         throw new InternalErrorException ("The left side of a :: should be an identifier");
138                                 return new QualifiedAliasMember (Left.Name, Name, Location);
139                         }
140
141                         Expression lexpr = Left.GetTypeExpression ();
142                         return new MemberAccess (lexpr, Name);
143                 }
144
145                 public MemberName Clone ()
146                 {
147                         MemberName left_clone = Left == null ? null : Left.Clone ();
148                         return new MemberName (left_clone, Name, is_double_colon, TypeArguments, Location);
149                 }
150
151                 public string Basename {
152                         get {
153                                 if (TypeArguments != null)
154                                         return MakeName (Name, TypeArguments);
155                                 else
156                                         return Name;
157                         }
158                 }
159
160                 public string FullName {
161                         get {
162                                 if (TypeArguments != null)
163                                         return Name + "<" + TypeArguments + ">";
164                                 else
165                                         return Name;
166                         }
167                 }
168
169                 public string MethodName {
170                         get {
171                                 string connect = is_double_colon ? "::" : ".";
172                                 if (Left != null)
173                                         return Left.FullName + connect + Name;
174                                 else
175                                         return Name;
176                         }
177                 }
178
179                 public override string ToString ()
180                 {
181                         string connect = is_double_colon ? "::" : ".";
182                         if (Left != null)
183                                 return Left.FullName + connect + FullName;
184                         else
185                                 return FullName;
186                 }
187
188                 public override bool Equals (object other)
189                 {
190                         return Equals (other as MemberName);
191                 }
192
193                 public bool Equals (MemberName other)
194                 {
195                         if (this == other)
196                                 return true;
197                         if (other == null || Name != other.Name)
198                                 return false;
199                         if (is_double_colon != other.is_double_colon)
200                                 return false;
201
202                         if ((TypeArguments != null) &&
203                             (other.TypeArguments == null || TypeArguments.Count != other.TypeArguments.Count))
204                                 return false;
205
206                         if ((TypeArguments == null) && (other.TypeArguments != null))
207                                 return false;
208
209                         if (Left == null)
210                                 return other.Left == null;
211
212                         return Left.Equals (other.Left);
213                 }
214
215                 public override int GetHashCode ()
216                 {
217                         int hash = Name.GetHashCode ();
218                         for (MemberName n = Left; n != null; n = n.Left)
219                                 hash ^= n.Name.GetHashCode ();
220                         if (is_double_colon)
221                                 hash ^= 0xbadc01d;
222
223                         if (TypeArguments != null)
224                                 hash ^= TypeArguments.Count << 5;
225
226                         return hash & 0x7FFFFFFF;
227                 }
228
229                 public int CountTypeArguments {
230                         get {
231                                 if (TypeArguments == null)
232                                         return 0;
233                                 else
234                                         return TypeArguments.Count;
235                         }
236                 }
237
238                 public static string MakeName (string name, TypeArguments args)
239                 {
240                         if (args == null)
241                                 return name;
242                         else
243                                 return name + "`" + args.Count;
244                 }
245
246                 public static string MakeName (string name, int count)
247                 {
248                         return name + "`" + count;
249                 }
250
251                 protected bool IsUnbound {
252                         get {
253                                 if ((Left != null) && Left.IsUnbound)
254                                         return true;
255                                 else if (TypeArguments == null)
256                                         return false;
257                                 else
258                                         return TypeArguments.IsUnbound;
259                         }
260                 }
261
262                 protected bool CheckUnbound (Location loc)
263                 {
264                         if ((Left != null) && !Left.CheckUnbound (loc))
265                                 return false;
266                         if ((TypeArguments != null) && !TypeArguments.IsUnbound) {
267                                 Report.Error (1031, loc, "Type expected");
268                                 return false;
269                         }
270
271                         return true;
272                 }
273         }
274
275         /// <summary>
276         ///   Base representation for members.  This is used to keep track
277         ///   of Name, Location and Modifier flags, and handling Attributes.
278         /// </summary>
279         public abstract class MemberCore : Attributable, IResolveContext {
280                 /// <summary>
281                 ///   Public name
282                 /// </summary>
283
284                 protected string cached_name;
285                 public string Name {
286                         get {
287                                 if (cached_name == null)
288                                         cached_name = MemberName.GetName (false);
289                                 return cached_name;
290                         }
291                 }
292
293                 // Is not readonly because of IndexerName attribute
294                 private MemberName member_name;
295                 public MemberName MemberName {
296                         get { return member_name; }
297                 }
298
299                 /// <summary>
300                 ///   Modifier flags that the user specified in the source code
301                 /// </summary>
302                 public int ModFlags;
303
304                 public readonly DeclSpace Parent;
305
306                 /// <summary>
307                 ///   Location where this declaration happens
308                 /// </summary>
309                 public Location Location {
310                         get { return member_name.Location; }
311                 }
312
313                 /// <summary>
314                 ///   XML documentation comment
315                 /// </summary>
316                 protected string comment;
317
318                 /// <summary>
319                 ///   Represents header string for documentation comment 
320                 ///   for each member types.
321                 /// </summary>
322                 public abstract string DocCommentHeader { get; }
323
324                 [Flags]
325                 public enum Flags {
326                         Obsolete_Undetected = 1,                // Obsolete attribute has not been detected yet
327                         Obsolete = 1 << 1,                      // Type has obsolete attribute
328                         ClsCompliance_Undetected = 1 << 2,      // CLS Compliance has not been detected yet
329                         ClsCompliant = 1 << 3,                  // Type is CLS Compliant
330                         CloseTypeCreated = 1 << 4,              // Tracks whether we have Closed the type
331                         HasCompliantAttribute_Undetected = 1 << 5,      // Presence of CLSCompliantAttribute has not been detected
332                         HasClsCompliantAttribute = 1 << 6,                      // Type has CLSCompliantAttribute
333                         ClsCompliantAttributeTrue = 1 << 7,                     // Type has CLSCompliant (true)
334                         Excluded_Undetected = 1 << 8,           // Conditional attribute has not been detected yet
335                         Excluded = 1 << 9,                                      // Method is conditional
336                         TestMethodDuplication = 1 << 10,                // Test for duplication must be performed
337                         IsUsed = 1 << 11,
338                         IsAssigned = 1 << 12,                           // Field is assigned
339                         HasExplicitLayout       = 1 << 13
340                 }
341
342                 /// <summary>
343                 ///   MemberCore flags at first detected then cached
344                 /// </summary>
345                 internal Flags caching_flags;
346
347                 public MemberCore (DeclSpace parent, MemberName name, Attributes attrs)
348                         : base (attrs)
349                 {
350                         this.Parent = parent;
351                         member_name = name;
352                         caching_flags = Flags.Obsolete_Undetected | Flags.ClsCompliance_Undetected | Flags.HasCompliantAttribute_Undetected | Flags.Excluded_Undetected;
353                 }
354
355                 protected virtual void SetMemberName (MemberName new_name)
356                 {
357                         member_name = new_name;
358                         cached_name = null;
359                 }
360
361                 public abstract bool Define ();
362
363                 public virtual string DocComment {
364                         get {
365                                 return comment;
366                         }
367                         set {
368                                 comment = value;
369                         }
370                 }
371
372                 // 
373                 // Returns full member name for error message
374                 //
375                 public virtual string GetSignatureForError ()
376                 {
377                         if (Parent == null || Parent.Parent == null)
378                                 return member_name.ToString ();
379
380                         return String.Concat (Parent.GetSignatureForError (), '.', member_name.ToString ());
381                 }
382
383                 /// <summary>
384                 /// Base Emit method. This is also entry point for CLS-Compliant verification.
385                 /// </summary>
386                 public virtual void Emit ()
387                 {
388                         if (!RootContext.VerifyClsCompliance)
389                                 return;
390
391                         VerifyClsCompliance ();
392                 }
393
394                 public virtual bool IsUsed {
395                         get { return (caching_flags & Flags.IsUsed) != 0; }
396                 }
397
398                 public void SetMemberIsUsed ()
399                 {
400                         caching_flags |= Flags.IsUsed;
401                 }
402
403                 /// <summary>
404                 /// Returns instance of ObsoleteAttribute for this MemberCore
405                 /// </summary>
406                 public virtual ObsoleteAttribute GetObsoleteAttribute ()
407                 {
408                         // ((flags & (Flags.Obsolete_Undetected | Flags.Obsolete)) == 0) is slower, but why ?
409                         if ((caching_flags & Flags.Obsolete_Undetected) == 0 && (caching_flags & Flags.Obsolete) == 0) {
410                                 return null;
411                         }
412
413                         caching_flags &= ~Flags.Obsolete_Undetected;
414
415                         if (OptAttributes == null)
416                                 return null;
417
418                         Attribute obsolete_attr = OptAttributes.Search (
419                                 TypeManager.obsolete_attribute_type);
420                         if (obsolete_attr == null)
421                                 return null;
422
423                         ObsoleteAttribute obsolete = obsolete_attr.GetObsoleteAttribute ();
424                         if (obsolete == null)
425                                 return null;
426
427                         caching_flags |= Flags.Obsolete;
428                         return obsolete;
429                 }
430
431                 /// <summary>
432                 /// Checks for ObsoleteAttribute presence. It's used for testing of all non-types elements
433                 /// </summary>
434                 public virtual void CheckObsoleteness (Location loc)
435                 {
436                         if (Parent != null)
437                                 Parent.CheckObsoleteness (loc);
438
439                         ObsoleteAttribute oa = GetObsoleteAttribute ();
440                         if (oa == null) {
441                                 return;
442                         }
443
444                         AttributeTester.Report_ObsoleteMessage (oa, GetSignatureForError (), loc);
445                 }
446
447                 /// <summary>
448                 /// Analyze whether CLS-Compliant verification must be execute for this MemberCore.
449                 /// </summary>
450                 public override bool IsClsComplianceRequired ()
451                 {
452                         if ((caching_flags & Flags.ClsCompliance_Undetected) == 0)
453                                 return (caching_flags & Flags.ClsCompliant) != 0;
454
455                         if (GetClsCompliantAttributeValue () && IsExposedFromAssembly ()) {
456                                 caching_flags &= ~Flags.ClsCompliance_Undetected;
457                                 caching_flags |= Flags.ClsCompliant;
458                                 return true;
459                         }
460
461                         caching_flags &= ~Flags.ClsCompliance_Undetected;
462                         return false;
463                 }
464
465                 /// <summary>
466                 /// Returns true when MemberCore is exposed from assembly.
467                 /// </summary>
468                 public bool IsExposedFromAssembly ()
469                 {
470                         if ((ModFlags & (Modifiers.PUBLIC | Modifiers.PROTECTED)) == 0)
471                                 return false;
472                         
473                         DeclSpace parentContainer = Parent;
474                         while (parentContainer != null && parentContainer.ModFlags != 0) {
475                                 if ((parentContainer.ModFlags & (Modifiers.PUBLIC | Modifiers.PROTECTED)) == 0)
476                                         return false;
477                                 parentContainer = parentContainer.Parent;
478                         }
479                         return true;
480                 }
481
482                 /// <summary>
483                 /// Goes through class hierarchy and gets value of first found CLSCompliantAttribute.
484                 /// If no is attribute exists then assembly CLSCompliantAttribute is returned.
485                 /// </summary>
486                 public virtual bool GetClsCompliantAttributeValue ()
487                 {
488                         if ((caching_flags & Flags.HasCompliantAttribute_Undetected) == 0)
489                                 return (caching_flags & Flags.ClsCompliantAttributeTrue) != 0;
490
491                         caching_flags &= ~Flags.HasCompliantAttribute_Undetected;
492
493                         if (OptAttributes != null) {
494                                 Attribute cls_attribute = OptAttributes.Search (
495                                         TypeManager.cls_compliant_attribute_type);
496                                 if (cls_attribute != null) {
497                                         caching_flags |= Flags.HasClsCompliantAttribute;
498                                         bool value = cls_attribute.GetClsCompliantAttributeValue ();
499                                         if (value)
500                                                 caching_flags |= Flags.ClsCompliantAttributeTrue;
501                                         return value;
502                                 }
503                         }
504
505                         if (Parent.GetClsCompliantAttributeValue ()) {
506                                 caching_flags |= Flags.ClsCompliantAttributeTrue;
507                                 return true;
508                         }
509                         return false;
510                 }
511
512                 /// <summary>
513                 /// Returns true if MemberCore is explicitly marked with CLSCompliantAttribute
514                 /// </summary>
515                 protected bool HasClsCompliantAttribute {
516                         get {
517                                 return (caching_flags & Flags.HasClsCompliantAttribute) != 0;
518                         }
519                 }
520
521                 /// <summary>
522                 /// It helps to handle error 102 & 111 detection
523                 /// </summary>
524                 public virtual bool MarkForDuplicationCheck ()
525                 {
526                         return false;
527                 }
528
529                 /// <summary>
530                 /// The main virtual method for CLS-Compliant verifications.
531                 /// The method returns true if member is CLS-Compliant and false if member is not
532                 /// CLS-Compliant which means that CLS-Compliant tests are not necessary. A descendants override it
533                 /// and add their extra verifications.
534                 /// </summary>
535                 protected virtual bool VerifyClsCompliance ()
536                 {
537                         if (!IsClsComplianceRequired ()) {
538                                 if (HasClsCompliantAttribute && RootContext.WarningLevel >= 2) {
539                                         if (!IsExposedFromAssembly ())
540                                                 Report.Warning (3019, 2, Location, "CLS compliance checking will not be performed on `{0}' because it is not visible from outside this assembly", GetSignatureForError ());
541                                         if (!CodeGen.Assembly.IsClsCompliant)
542                                                 Report.Warning (3021, 2, Location, "`{0}' does not need a CLSCompliant attribute because the assembly is not marked as CLS-compliant", GetSignatureForError ());
543                                 }
544                                 return false;
545                         }
546
547                         if (!CodeGen.Assembly.IsClsCompliant) {
548                                 if (HasClsCompliantAttribute) {
549                                         Report.Error (3014, Location,
550                                                 "`{0}' cannot be marked as CLS-compliant because the assembly is not marked as CLS-compliant",
551                                                 GetSignatureForError ());
552                                 }
553                                 return false;
554                         }
555
556                         if (member_name.Name [0] == '_') {
557                                 Report.Error (3008, Location, "Identifier `{0}' is not CLS-compliant", GetSignatureForError () );
558                         }
559                         return true;
560                 }
561
562                 //
563                 // Raised (and passed an XmlElement that contains the comment)
564                 // when GenerateDocComment is writing documentation expectedly.
565                 //
566                 internal virtual void OnGenerateDocComment (XmlElement intermediateNode)
567                 {
568                 }
569
570                 //
571                 // Returns a string that represents the signature for this 
572                 // member which should be used in XML documentation.
573                 //
574                 public virtual string GetDocCommentName (DeclSpace ds)
575                 {
576                         if (ds == null || this is DeclSpace)
577                                 return DocCommentHeader + Name;
578                         else
579                                 return String.Concat (DocCommentHeader, ds.Name, ".", Name);
580                 }
581
582                 //
583                 // Generates xml doc comments (if any), and if required,
584                 // handle warning report.
585                 //
586                 internal virtual void GenerateDocComment (DeclSpace ds)
587                 {
588                         DocUtil.GenerateDocComment (this, ds);
589                 }
590
591                 public override IResolveContext ResolveContext {
592                         get { return this; }
593                 }
594
595                 #region IResolveContext Members
596
597                 public DeclSpace DeclContainer {
598                         get { return Parent; }
599                 }
600
601                 public virtual DeclSpace GenericDeclContainer {
602                         get { return DeclContainer; }
603                 }
604
605                 public bool IsInObsoleteScope {
606                         get {
607                                 if (GetObsoleteAttribute () != null)
608                                         return true;
609
610                                 return Parent == null ? false : Parent.IsInObsoleteScope;
611                         }
612                 }
613
614                 public bool IsInUnsafeScope {
615                         get {
616                                 if ((ModFlags & Modifiers.UNSAFE) != 0)
617                                         return true;
618
619                                 return Parent == null ? false : Parent.IsInUnsafeScope;
620                         }
621                 }
622
623                 #endregion
624         }
625
626         /// <summary>
627         ///   Base class for structs, classes, enumerations and interfaces.  
628         /// </summary>
629         /// <remarks>
630         ///   They all create new declaration spaces.  This
631         ///   provides the common foundation for managing those name
632         ///   spaces.
633         /// </remarks>
634         public abstract class DeclSpace : MemberCore {
635
636                 /// <summary>
637                 ///   This points to the actual definition that is being
638                 ///   created with System.Reflection.Emit
639                 /// </summary>
640                 public TypeBuilder TypeBuilder;
641
642                 //
643                 // This is the namespace in which this typecontainer
644                 // was declared.  We use this to resolve names.
645                 //
646                 public NamespaceEntry NamespaceEntry;
647
648                 private Hashtable Cache = new Hashtable ();
649                 
650                 public string Basename;
651                 
652                 protected Hashtable defined_names;
653
654                 public TypeContainer PartialContainer;          
655
656                 //
657                 // Whether we are Generic
658                 //
659                 public bool IsGeneric {
660                         get { return false; }
661                 }
662
663                 static string[] attribute_targets = new string [] { "type" };
664
665                 public DeclSpace (NamespaceEntry ns, DeclSpace parent, MemberName name,
666                                   Attributes attrs)
667                         : base (parent, name, attrs)
668                 {
669                         NamespaceEntry = ns;
670                         Basename = name.Name;
671                         defined_names = new Hashtable ();
672                         PartialContainer = null;
673                 }
674
675                 public override DeclSpace GenericDeclContainer {
676                         get { return this; }
677                 }
678
679                 /// <summary>
680                 /// Adds the member to defined_names table. It tests for duplications and enclosing name conflicts
681                 /// </summary>
682                 protected virtual bool AddToContainer (MemberCore symbol, string name)
683                 {
684                         MemberCore mc = (MemberCore) defined_names [name];
685
686                         if (mc == null) {
687                                 defined_names.Add (name, symbol);
688                                 return true;
689                         }
690
691                         if (symbol.MarkForDuplicationCheck () && mc.MarkForDuplicationCheck ())
692                                 return true;
693
694                         Report.SymbolRelatedToPreviousError (mc);
695                         if ((mc.ModFlags & Modifiers.PARTIAL) != 0 && (symbol is ClassOrStruct || symbol is Interface)) {
696                                 Error_MissingPartialModifier (symbol);
697                                 return false;
698                         }
699
700                         if (this is RootTypes) {
701                                 Report.Error (101, symbol.Location, 
702                                         "The namespace `{0}' already contains a definition for `{1}'",
703                                         ((DeclSpace)symbol).NamespaceEntry.GetSignatureForError (), symbol.MemberName.Name);
704                         } else {
705                                 Report.Error (102, symbol.Location,
706                                               "The type `{0}' already contains a definition for `{1}'",
707                                               GetSignatureForError (), symbol.MemberName.Name);
708                         }
709
710                         return false;
711                 }
712
713                 /// <summary>
714                 ///   Returns the MemberCore associated with a given name in the declaration
715                 ///   space. It doesn't return method based symbols !!
716                 /// </summary>
717                 /// 
718                 public MemberCore GetDefinition (string name)
719                 {
720                         return (MemberCore)defined_names [name];
721                 }
722                 
723                 // 
724                 // root_types contains all the types.  All TopLevel types
725                 // hence have a parent that points to `root_types', that is
726                 // why there is a non-obvious test down here.
727                 //
728                 public bool IsTopLevel {
729                         get { return (Parent != null && Parent.Parent == null); }
730                 }
731
732                 public virtual void CloseType ()
733                 {
734                         if ((caching_flags & Flags.CloseTypeCreated) == 0){
735                                 try {
736                                         TypeBuilder.CreateType ();
737                                 } catch {
738                                         //
739                                         // The try/catch is needed because
740                                         // nested enumerations fail to load when they
741                                         // are defined.
742                                         //
743                                         // Even if this is the right order (enumerations
744                                         // declared after types).
745                                         //
746                                         // Note that this still creates the type and
747                                         // it is possible to save it
748                                 }
749                                 caching_flags |= Flags.CloseTypeCreated;
750                         }
751                 }
752
753                 protected virtual TypeAttributes TypeAttr {
754                         get { return CodeGen.Module.DefaultCharSetType; }
755                 }
756
757                 /// <remarks>
758                 ///  Should be overriten by the appropriate declaration space
759                 /// </remarks>
760                 public abstract TypeBuilder DefineType ();
761                 
762                 /// <summary>
763                 ///   Define all members, but don't apply any attributes or do anything which may
764                 ///   access not-yet-defined classes.  This method also creates the MemberCache.
765                 /// </summary>
766                 public virtual bool DefineMembers ()
767                 {
768                         if (((ModFlags & Modifiers.NEW) != 0) && IsTopLevel) {
769                                 Report.Error (1530, Location, "Keyword `new' is not allowed on namespace elements");
770                                 return false;
771                         }
772                         return true;
773                 }
774
775                 protected void Error_MissingPartialModifier (MemberCore type)
776                 {
777                         Report.Error (260, type.Location,
778                                 "Missing partial modifier on declaration of type `{0}'. Another partial declaration of this type exists",
779                                 type.GetSignatureForError ());
780                 }
781
782                 public override string GetSignatureForError ()
783                 {       
784                         // Parent.GetSignatureForError
785                         return Name;
786                 }
787                 
788                 public bool CheckAccessLevel (Type check_type)
789                 {
790                         if (check_type == TypeBuilder)
791                                 return true;
792                         
793                         TypeAttributes check_attr = check_type.Attributes & TypeAttributes.VisibilityMask;
794
795                         //
796                         // Broken Microsoft runtime, return public for arrays, no matter what 
797                         // the accessibility is for their underlying class, and they return 
798                         // NonPublic visibility for pointers
799                         //
800                         if (check_type.IsArray || check_type.IsPointer)
801                                 return CheckAccessLevel (TypeManager.GetElementType (check_type));
802
803                         if (TypeBuilder == null)
804                                 // FIXME: TypeBuilder will be null when invoked by Class.GetNormalBases().
805                                 //        However, this is invoked again later -- so safe to return true.
806                                 //        May also be null when resolving top-level attributes.
807                                 return true;
808
809                         switch (check_attr){
810                         case TypeAttributes.Public:
811                                 return true;
812
813                         case TypeAttributes.NotPublic:
814                                 //
815                                 // This test should probably use the declaringtype.
816                                 //
817                                 return check_type.Assembly == TypeBuilder.Assembly;
818                                 
819                         case TypeAttributes.NestedPublic:
820                                 return true;
821
822                         case TypeAttributes.NestedPrivate:
823                                 return NestedAccessible (check_type);
824
825                         case TypeAttributes.NestedFamily:
826                                 return FamilyAccessible (check_type);
827
828                         case TypeAttributes.NestedFamANDAssem:
829                                 return (check_type.Assembly == TypeBuilder.Assembly) &&
830                                         FamilyAccessible (check_type);
831
832                         case TypeAttributes.NestedFamORAssem:
833                                 return (check_type.Assembly == TypeBuilder.Assembly) ||
834                                         FamilyAccessible (check_type);
835
836                         case TypeAttributes.NestedAssembly:
837                                 return check_type.Assembly == TypeBuilder.Assembly;
838                         }
839
840                         Console.WriteLine ("HERE: " + check_attr);
841                         return false;
842
843                 }
844
845                 protected bool NestedAccessible (Type check_type)
846                 {
847                         Type declaring = check_type.DeclaringType;
848                         return TypeBuilder == declaring ||
849                                 TypeManager.IsNestedChildOf (TypeBuilder, declaring);
850                 }
851
852                 protected bool FamilyAccessible (Type check_type)
853                 {
854                         Type declaring = check_type.DeclaringType;
855                         return TypeManager.IsNestedFamilyAccessible (TypeBuilder, declaring);
856                 }
857
858                 // Access level of a type.
859                 const int X = 1;
860                 enum AccessLevel { // Each column represents `is this scope larger or equal to Blah scope'
861                         // Public    Assembly   Protected
862                         Protected           = (0 << 0) | (0 << 1) | (X << 2),
863                         Public              = (X << 0) | (X << 1) | (X << 2),
864                         Private             = (0 << 0) | (0 << 1) | (0 << 2),
865                         Internal            = (0 << 0) | (X << 1) | (0 << 2),
866                         ProtectedOrInternal = (0 << 0) | (X << 1) | (X << 2),
867                 }
868                 
869                 static AccessLevel GetAccessLevelFromModifiers (int flags)
870                 {
871                         if ((flags & Modifiers.INTERNAL) != 0) {
872                                 
873                                 if ((flags & Modifiers.PROTECTED) != 0)
874                                         return AccessLevel.ProtectedOrInternal;
875                                 else
876                                         return AccessLevel.Internal;
877                                 
878                         } else if ((flags & Modifiers.PROTECTED) != 0)
879                                 return AccessLevel.Protected;
880                         
881                         else if ((flags & Modifiers.PRIVATE) != 0)
882                                 return AccessLevel.Private;
883                         
884                         else
885                                 return AccessLevel.Public;
886                 }
887
888                 // What is the effective access level of this?
889                 // TODO: Cache this?
890                 AccessLevel EffectiveAccessLevel {
891                         get {
892                                 AccessLevel myAccess = GetAccessLevelFromModifiers (ModFlags);
893                                 if (!IsTopLevel && (Parent != null))
894                                         return myAccess & Parent.EffectiveAccessLevel;
895                                 return myAccess;
896                         }
897                 }
898
899                 // Return the access level for type `t'
900                 static AccessLevel TypeEffectiveAccessLevel (Type t)
901                 {
902                         if (t.IsPublic)
903                                 return AccessLevel.Public;
904                         if (t.IsNestedPrivate)
905                                 return AccessLevel.Private;
906                         if (t.IsNotPublic)
907                                 return AccessLevel.Internal;
908                         
909                         // By now, it must be nested
910                         AccessLevel parentLevel = TypeEffectiveAccessLevel (t.DeclaringType);
911                         
912                         if (t.IsNestedPublic)
913                                 return parentLevel;
914                         if (t.IsNestedAssembly)
915                                 return parentLevel & AccessLevel.Internal;
916                         if (t.IsNestedFamily)
917                                 return parentLevel & AccessLevel.Protected;
918                         if (t.IsNestedFamORAssem)
919                                 return parentLevel & AccessLevel.ProtectedOrInternal;
920                         if (t.IsNestedFamANDAssem)
921                                 throw new NotImplementedException ("NestedFamANDAssem not implemented, cant make this kind of type from c# anyways");
922                         
923                         // nested private is taken care of
924                         
925                         throw new Exception ("I give up, what are you?");
926                 }
927
928                 //
929                 // This answers `is the type P, as accessible as a member M which has the
930                 // accessability @flags which is declared as a nested member of the type T, this declspace'
931                 //
932                 public bool AsAccessible (Type p, int flags)
933                 {
934                         //
935                         // 1) if M is private, its accessability is the same as this declspace.
936                         // we already know that P is accessible to T before this method, so we
937                         // may return true.
938                         //
939                         
940                         if ((flags & Modifiers.PRIVATE) != 0)
941                                 return true;
942                         
943                         while (p.IsArray || p.IsPointer || p.IsByRef)
944                                 p = TypeManager.GetElementType (p);
945                         
946                         AccessLevel pAccess = TypeEffectiveAccessLevel (p);
947                         AccessLevel mAccess = this.EffectiveAccessLevel &
948                                 GetAccessLevelFromModifiers (flags);
949                         
950                         // for every place from which we can access M, we must
951                         // be able to access P as well. So, we want
952                         // For every bit in M and P, M_i -> P_1 == true
953                         // or, ~ (M -> P) == 0 <-> ~ ( ~M | P) == 0
954                         
955                         return ~ (~ mAccess | pAccess) == 0;
956                 }
957
958                 private Type LookupNestedTypeInHierarchy (string name)
959                 {
960                         // if the member cache has been created, lets use it.
961                         // the member cache is MUCH faster.
962                         if (MemberCache != null)
963                                 return MemberCache.FindNestedType (name);
964
965                         // no member cache. Do it the hard way -- reflection
966                         Type t = null;
967                         for (Type current_type = TypeBuilder;
968                              current_type != null && current_type != TypeManager.object_type;
969                              current_type = current_type.BaseType) {
970                                 if (current_type is TypeBuilder) {
971                                         TypeContainer tc = current_type == TypeBuilder
972                                                 ? PartialContainer
973                                                 : TypeManager.LookupTypeContainer (current_type);
974                                         if (tc != null)
975                                                 t = tc.FindNestedType (name);
976                                 } else {
977                                         t = TypeManager.GetNestedType (current_type, name);
978                                 }
979
980                                 if (t != null && CheckAccessLevel (t))
981                                         return t;
982                         }
983
984                         return null;
985                 }
986
987                 //
988                 // Public function used to locate types.
989                 //
990                 // Set 'ignore_cs0104' to true if you want to ignore cs0104 errors.
991                 //
992                 // Returns: Type or null if they type can not be found.
993                 //
994                 public FullNamedExpression LookupType (string name, Location loc, bool ignore_cs0104)
995                 {
996                         if (Cache.Contains (name))
997                                 return (FullNamedExpression) Cache [name];
998
999                         FullNamedExpression e;
1000                         Type t = LookupNestedTypeInHierarchy (name);
1001                         if (t != null)
1002                                 e = new TypeExpression (t, Location.Null);
1003                         else if (Parent != null)
1004                                 e = Parent.LookupType (name, loc, ignore_cs0104);
1005                         else
1006                                 e = NamespaceEntry.LookupNamespaceOrType (this, name, loc, ignore_cs0104);
1007
1008                         Cache [name] = e;
1009                         return e;
1010                 }
1011
1012                 /// <remarks>
1013                 ///   This function is broken and not what you're looking for.  It should only
1014                 ///   be used while the type is still being created since it doesn't use the cache
1015                 ///   and relies on the filter doing the member name check.
1016                 /// </remarks>
1017                 public abstract MemberList FindMembers (MemberTypes mt, BindingFlags bf,
1018                                                         MemberFilter filter, object criteria);
1019
1020                 /// <remarks>
1021                 ///   If we have a MemberCache, return it.  This property may return null if the
1022                 ///   class doesn't have a member cache or while it's still being created.
1023                 /// </remarks>
1024                 public abstract MemberCache MemberCache {
1025                         get;
1026                 }
1027
1028                 public override void ApplyAttributeBuilder (Attribute a, CustomAttributeBuilder cb)
1029                 {
1030                         if (a.Type == TypeManager.required_attr_type) {
1031                                 Report.Error (1608, a.Location, "The RequiredAttribute attribute is not permitted on C# types");
1032                                 return;
1033                         }
1034                         TypeBuilder.SetCustomAttribute (cb);
1035                 }
1036
1037                 public override string[] ValidAttributeTargets {
1038                         get { return attribute_targets; }
1039                 }
1040
1041                 protected override bool VerifyClsCompliance ()
1042                 {
1043                         if (!base.VerifyClsCompliance ()) {
1044                                 return false;
1045                         }
1046
1047                         IDictionary cache = TypeManager.AllClsTopLevelTypes;
1048                         string lcase = Name.ToLower (System.Globalization.CultureInfo.InvariantCulture);
1049                         if (!cache.Contains (lcase)) {
1050                                 cache.Add (lcase, this);
1051                                 return true;
1052                         }
1053
1054                         object val = cache [lcase];
1055                         if (val == null) {
1056                                 Type t = AttributeTester.GetImportedIgnoreCaseClsType (lcase);
1057                                 if (t == null)
1058                                         return true;
1059                                 Report.SymbolRelatedToPreviousError (t);
1060                         }
1061                         else {
1062                                 Report.SymbolRelatedToPreviousError ((DeclSpace)val);
1063                         }
1064                         Report.Error (3005, Location, "Identifier `{0}' differing only in case is not CLS-compliant", GetSignatureForError ());
1065                         return true;
1066                 }
1067         }
1068
1069         /// <summary>
1070         ///   This is a readonly list of MemberInfo's.      
1071         /// </summary>
1072         public class MemberList : IList {
1073                 public readonly IList List;
1074                 int count;
1075
1076                 /// <summary>
1077                 ///   Create a new MemberList from the given IList.
1078                 /// </summary>
1079                 public MemberList (IList list)
1080                 {
1081                         if (list != null)
1082                                 this.List = list;
1083                         else
1084                                 this.List = new ArrayList ();
1085                         count = List.Count;
1086                 }
1087
1088                 /// <summary>
1089                 ///   Concatenate the ILists `first' and `second' to a new MemberList.
1090                 /// </summary>
1091                 public MemberList (IList first, IList second)
1092                 {
1093                         ArrayList list = new ArrayList ();
1094                         list.AddRange (first);
1095                         list.AddRange (second);
1096                         count = list.Count;
1097                         List = list;
1098                 }
1099
1100                 public static readonly MemberList Empty = new MemberList (new ArrayList ());
1101
1102                 /// <summary>
1103                 ///   Cast the MemberList into a MemberInfo[] array.
1104                 /// </summary>
1105                 /// <remarks>
1106                 ///   This is an expensive operation, only use it if it's really necessary.
1107                 /// </remarks>
1108                 public static explicit operator MemberInfo [] (MemberList list)
1109                 {
1110                         Timer.StartTimer (TimerType.MiscTimer);
1111                         MemberInfo [] result = new MemberInfo [list.Count];
1112                         list.CopyTo (result, 0);
1113                         Timer.StopTimer (TimerType.MiscTimer);
1114                         return result;
1115                 }
1116
1117                 // ICollection
1118
1119                 public int Count {
1120                         get {
1121                                 return count;
1122                         }
1123                 }
1124
1125                 public bool IsSynchronized {
1126                         get {
1127                                 return List.IsSynchronized;
1128                         }
1129                 }
1130
1131                 public object SyncRoot {
1132                         get {
1133                                 return List.SyncRoot;
1134                         }
1135                 }
1136
1137                 public void CopyTo (Array array, int index)
1138                 {
1139                         List.CopyTo (array, index);
1140                 }
1141
1142                 // IEnumerable
1143
1144                 public IEnumerator GetEnumerator ()
1145                 {
1146                         return List.GetEnumerator ();
1147                 }
1148
1149                 // IList
1150
1151                 public bool IsFixedSize {
1152                         get {
1153                                 return true;
1154                         }
1155                 }
1156
1157                 public bool IsReadOnly {
1158                         get {
1159                                 return true;
1160                         }
1161                 }
1162
1163                 object IList.this [int index] {
1164                         get {
1165                                 return List [index];
1166                         }
1167
1168                         set {
1169                                 throw new NotSupportedException ();
1170                         }
1171                 }
1172
1173                 // FIXME: try to find out whether we can avoid the cast in this indexer.
1174                 public MemberInfo this [int index] {
1175                         get {
1176                                 return (MemberInfo) List [index];
1177                         }
1178                 }
1179
1180                 public int Add (object value)
1181                 {
1182                         throw new NotSupportedException ();
1183                 }
1184
1185                 public void Clear ()
1186                 {
1187                         throw new NotSupportedException ();
1188                 }
1189
1190                 public bool Contains (object value)
1191                 {
1192                         return List.Contains (value);
1193                 }
1194
1195                 public int IndexOf (object value)
1196                 {
1197                         return List.IndexOf (value);
1198                 }
1199
1200                 public void Insert (int index, object value)
1201                 {
1202                         throw new NotSupportedException ();
1203                 }
1204
1205                 public void Remove (object value)
1206                 {
1207                         throw new NotSupportedException ();
1208                 }
1209
1210                 public void RemoveAt (int index)
1211                 {
1212                         throw new NotSupportedException ();
1213                 }
1214         }
1215
1216         /// <summary>
1217         ///   This interface is used to get all members of a class when creating the
1218         ///   member cache.  It must be implemented by all DeclSpace derivatives which
1219         ///   want to support the member cache and by TypeHandle to get caching of
1220         ///   non-dynamic types.
1221         /// </summary>
1222         public interface IMemberContainer {
1223                 /// <summary>
1224                 ///   The name of the IMemberContainer.  This is only used for
1225                 ///   debugging purposes.
1226                 /// </summary>
1227                 string Name {
1228                         get;
1229                 }
1230
1231                 /// <summary>
1232                 ///   The type of this IMemberContainer.
1233                 /// </summary>
1234                 Type Type {
1235                         get;
1236                 }
1237
1238                 /// <summary>
1239                 ///   Returns the IMemberContainer of the base class or null if this
1240                 ///   is an interface or TypeManger.object_type.
1241                 ///   This is used when creating the member cache for a class to get all
1242                 ///   members from the base class.
1243                 /// </summary>
1244                 MemberCache BaseCache {
1245                         get;
1246                 }
1247
1248                 /// <summary>
1249                 ///   Whether this is an interface.
1250                 /// </summary>
1251                 bool IsInterface {
1252                         get;
1253                 }
1254
1255                 /// <summary>
1256                 ///   Returns all members of this class with the corresponding MemberTypes
1257                 ///   and BindingFlags.
1258                 /// </summary>
1259                 /// <remarks>
1260                 ///   When implementing this method, make sure not to return any inherited
1261                 ///   members and check the MemberTypes and BindingFlags properly.
1262                 ///   Unfortunately, System.Reflection is lame and doesn't provide a way to
1263                 ///   get the BindingFlags (static/non-static,public/non-public) in the
1264                 ///   MemberInfo class, but the cache needs this information.  That's why
1265                 ///   this method is called multiple times with different BindingFlags.
1266                 /// </remarks>
1267                 MemberList GetMembers (MemberTypes mt, BindingFlags bf);
1268
1269                 /// <summary>
1270                 ///   Return the container's member cache.
1271                 /// </summary>
1272                 MemberCache MemberCache {
1273                         get;
1274                 }
1275         }
1276
1277         /// <summary>
1278         ///   The MemberCache is used by dynamic and non-dynamic types to speed up
1279         ///   member lookups.  It has a member name based hash table; it maps each member
1280         ///   name to a list of CacheEntry objects.  Each CacheEntry contains a MemberInfo
1281         ///   and the BindingFlags that were initially used to get it.  The cache contains
1282         ///   all members of the current class and all inherited members.  If this cache is
1283         ///   for an interface types, it also contains all inherited members.
1284         ///
1285         ///   There are two ways to get a MemberCache:
1286         ///   * if this is a dynamic type, lookup the corresponding DeclSpace and then
1287         ///     use the DeclSpace.MemberCache property.
1288         ///   * if this not a dynamic type, call TypeHandle.GetTypeHandle() to get a
1289         ///     TypeHandle instance for the type and then use TypeHandle.MemberCache.
1290         /// </summary>
1291         public class MemberCache {
1292                 public readonly IMemberContainer Container;
1293                 protected Hashtable member_hash;
1294                 protected Hashtable method_hash;
1295
1296                 /// <summary>
1297                 ///   Create a new MemberCache for the given IMemberContainer `container'.
1298                 /// </summary>
1299                 public MemberCache (IMemberContainer container)
1300                 {
1301                         this.Container = container;
1302
1303                         Timer.IncrementCounter (CounterType.MemberCache);
1304                         Timer.StartTimer (TimerType.CacheInit);
1305
1306                         // If we have a base class (we have a base class unless we're
1307                         // TypeManager.object_type), we deep-copy its MemberCache here.
1308                         if (Container.BaseCache != null)
1309                                 member_hash = SetupCache (Container.BaseCache);
1310                         else
1311                                 member_hash = new Hashtable ();
1312
1313                         // If this is neither a dynamic type nor an interface, create a special
1314                         // method cache with all declared and inherited methods.
1315                         Type type = container.Type;
1316                         if (!(type is TypeBuilder) && !type.IsInterface &&
1317                             (Container.BaseCache == null || Container.BaseCache.method_hash != null)) {
1318                                 method_hash = new Hashtable ();
1319                                 AddMethods (type);
1320                         }
1321
1322                         // Add all members from the current class.
1323                         AddMembers (Container);
1324
1325                         Timer.StopTimer (TimerType.CacheInit);
1326                 }
1327
1328                 public MemberCache (Type[] ifaces)
1329                 {
1330                         //
1331                         // The members of this cache all belong to other caches.  
1332                         // So, 'Container' will not be used.
1333                         //
1334                         this.Container = null;
1335
1336                         member_hash = new Hashtable ();
1337                         if (ifaces == null)
1338                                 return;
1339
1340                         foreach (Type itype in ifaces)
1341                                 AddCacheContents (TypeManager.LookupMemberCache (itype));
1342                 }
1343
1344                 /// <summary>
1345                 ///   Bootstrap this member cache by doing a deep-copy of our base.
1346                 /// </summary>
1347                 static Hashtable SetupCache (MemberCache base_class)
1348                 {
1349                         Hashtable hash = new Hashtable ();
1350
1351                         if (base_class == null)
1352                                 return hash;
1353
1354                         IDictionaryEnumerator it = base_class.member_hash.GetEnumerator ();
1355                         while (it.MoveNext ()) {
1356                                 hash [it.Key] = ((ArrayList) it.Value).Clone ();
1357                          }
1358                                 
1359                         return hash;
1360                 }
1361
1362                 /// <summary>
1363                 ///   Add the contents of `cache' to the member_hash.
1364                 /// </summary>
1365                 void AddCacheContents (MemberCache cache)
1366                 {
1367                         IDictionaryEnumerator it = cache.member_hash.GetEnumerator ();
1368                         while (it.MoveNext ()) {
1369                                 ArrayList list = (ArrayList) member_hash [it.Key];
1370                                 if (list == null)
1371                                         member_hash [it.Key] = list = new ArrayList ();
1372
1373                                 ArrayList entries = (ArrayList) it.Value;
1374                                 for (int i = entries.Count-1; i >= 0; i--) {
1375                                         CacheEntry entry = (CacheEntry) entries [i];
1376
1377                                         if (entry.Container != cache.Container)
1378                                                 break;
1379                                         list.Add (entry);
1380                                 }
1381                         }
1382                 }
1383
1384                 /// <summary>
1385                 ///   Add all members from class `container' to the cache.
1386                 /// </summary>
1387                 void AddMembers (IMemberContainer container)
1388                 {
1389                         // We need to call AddMembers() with a single member type at a time
1390                         // to get the member type part of CacheEntry.EntryType right.
1391                         if (!container.IsInterface) {
1392                                 AddMembers (MemberTypes.Constructor, container);
1393                                 AddMembers (MemberTypes.Field, container);
1394                         }
1395                         AddMembers (MemberTypes.Method, container);
1396                         AddMembers (MemberTypes.Property, container);
1397                         AddMembers (MemberTypes.Event, container);
1398                         // Nested types are returned by both Static and Instance searches.
1399                         AddMembers (MemberTypes.NestedType,
1400                                     BindingFlags.Static | BindingFlags.Public, container);
1401                         AddMembers (MemberTypes.NestedType,
1402                                     BindingFlags.Static | BindingFlags.NonPublic, container);
1403                 }
1404
1405                 void AddMembers (MemberTypes mt, IMemberContainer container)
1406                 {
1407                         AddMembers (mt, BindingFlags.Static | BindingFlags.Public, container);
1408                         AddMembers (mt, BindingFlags.Static | BindingFlags.NonPublic, container);
1409                         AddMembers (mt, BindingFlags.Instance | BindingFlags.Public, container);
1410                         AddMembers (mt, BindingFlags.Instance | BindingFlags.NonPublic, container);
1411                 }
1412
1413                 /// <summary>
1414                 ///   Add all members from class `container' with the requested MemberTypes and
1415                 ///   BindingFlags to the cache.  This method is called multiple times with different
1416                 ///   MemberTypes and BindingFlags.
1417                 /// </summary>
1418                 void AddMembers (MemberTypes mt, BindingFlags bf, IMemberContainer container)
1419                 {
1420                         MemberList members = container.GetMembers (mt, bf);
1421
1422                         foreach (MemberInfo member in members) {
1423                                 string name = member.Name;
1424
1425                                 // We use a name-based hash table of ArrayList's.
1426                                 ArrayList list = (ArrayList) member_hash [name];
1427                                 if (list == null) {
1428                                         list = new ArrayList ();
1429                                         member_hash.Add (name, list);
1430                                 }
1431
1432                                 // When this method is called for the current class, the list will
1433                                 // already contain all inherited members from our base classes.
1434                                 // We cannot add new members in front of the list since this'd be an
1435                                 // expensive operation, that's why the list is sorted in reverse order
1436                                 // (ie. members from the current class are coming last).
1437                                 list.Add (new CacheEntry (container, member, mt, bf));
1438                         }
1439                 }
1440
1441                 /// <summary>
1442                 ///   Add all declared and inherited methods from class `type' to the method cache.
1443                 /// </summary>
1444                 void AddMethods (Type type)
1445                 {
1446                         AddMethods (BindingFlags.Static | BindingFlags.Public |
1447                                     BindingFlags.FlattenHierarchy, type);
1448                         AddMethods (BindingFlags.Static | BindingFlags.NonPublic |
1449                                     BindingFlags.FlattenHierarchy, type);
1450                         AddMethods (BindingFlags.Instance | BindingFlags.Public, type);
1451                         AddMethods (BindingFlags.Instance | BindingFlags.NonPublic, type);
1452                 }
1453
1454                 static ArrayList overrides = new ArrayList ();
1455
1456                 void AddMethods (BindingFlags bf, Type type)
1457                 {
1458                         MethodBase [] members = type.GetMethods (bf);
1459
1460                         Array.Reverse (members);
1461
1462                         foreach (MethodBase member in members) {
1463                                 string name = member.Name;
1464
1465                                 // We use a name-based hash table of ArrayList's.
1466                                 ArrayList list = (ArrayList) method_hash [name];
1467                                 if (list == null) {
1468                                         list = new ArrayList ();
1469                                         method_hash.Add (name, list);
1470                                 }
1471
1472                                 MethodInfo curr = (MethodInfo) member;
1473                                 while (curr.IsVirtual && (curr.Attributes & MethodAttributes.NewSlot) == 0) {
1474                                         MethodInfo base_method = curr.GetBaseDefinition ();
1475
1476                                         if (base_method == curr)
1477                                                 // Not every virtual function needs to have a NewSlot flag.
1478                                                 break;
1479
1480                                         overrides.Add (curr);
1481                                         list.Add (new CacheEntry (null, base_method, MemberTypes.Method, bf));
1482                                         curr = base_method;
1483                                 }
1484
1485                                 if (overrides.Count > 0) {
1486                                         for (int i = 0; i < overrides.Count; ++i)
1487                                                 TypeManager.RegisterOverride ((MethodBase) overrides [i], curr);
1488                                         overrides.Clear ();
1489                                 }
1490
1491                                 // Unfortunately, the elements returned by Type.GetMethods() aren't
1492                                 // sorted so we need to do this check for every member.
1493                                 BindingFlags new_bf = bf;
1494                                 if (member.DeclaringType == type)
1495                                         new_bf |= BindingFlags.DeclaredOnly;
1496
1497                                 list.Add (new CacheEntry (Container, member, MemberTypes.Method, new_bf));
1498                         }
1499                 }
1500
1501                 /// <summary>
1502                 ///   Compute and return a appropriate `EntryType' magic number for the given
1503                 ///   MemberTypes and BindingFlags.
1504                 /// </summary>
1505                 protected static EntryType GetEntryType (MemberTypes mt, BindingFlags bf)
1506                 {
1507                         EntryType type = EntryType.None;
1508
1509                         if ((mt & MemberTypes.Constructor) != 0)
1510                                 type |= EntryType.Constructor;
1511                         if ((mt & MemberTypes.Event) != 0)
1512                                 type |= EntryType.Event;
1513                         if ((mt & MemberTypes.Field) != 0)
1514                                 type |= EntryType.Field;
1515                         if ((mt & MemberTypes.Method) != 0)
1516                                 type |= EntryType.Method;
1517                         if ((mt & MemberTypes.Property) != 0)
1518                                 type |= EntryType.Property;
1519                         // Nested types are returned by static and instance searches.
1520                         if ((mt & MemberTypes.NestedType) != 0)
1521                                 type |= EntryType.NestedType | EntryType.Static | EntryType.Instance;
1522
1523                         if ((bf & BindingFlags.Instance) != 0)
1524                                 type |= EntryType.Instance;
1525                         if ((bf & BindingFlags.Static) != 0)
1526                                 type |= EntryType.Static;
1527                         if ((bf & BindingFlags.Public) != 0)
1528                                 type |= EntryType.Public;
1529                         if ((bf & BindingFlags.NonPublic) != 0)
1530                                 type |= EntryType.NonPublic;
1531                         if ((bf & BindingFlags.DeclaredOnly) != 0)
1532                                 type |= EntryType.Declared;
1533
1534                         return type;
1535                 }
1536
1537                 /// <summary>
1538                 ///   The `MemberTypes' enumeration type is a [Flags] type which means that it may
1539                 ///   denote multiple member types.  Returns true if the given flags value denotes a
1540                 ///   single member types.
1541                 /// </summary>
1542                 public static bool IsSingleMemberType (MemberTypes mt)
1543                 {
1544                         switch (mt) {
1545                         case MemberTypes.Constructor:
1546                         case MemberTypes.Event:
1547                         case MemberTypes.Field:
1548                         case MemberTypes.Method:
1549                         case MemberTypes.Property:
1550                         case MemberTypes.NestedType:
1551                                 return true;
1552
1553                         default:
1554                                 return false;
1555                         }
1556                 }
1557
1558                 /// <summary>
1559                 ///   We encode the MemberTypes and BindingFlags of each members in a "magic"
1560                 ///   number to speed up the searching process.
1561                 /// </summary>
1562                 [Flags]
1563                 protected enum EntryType {
1564                         None            = 0x000,
1565
1566                         Instance        = 0x001,
1567                         Static          = 0x002,
1568                         MaskStatic      = Instance|Static,
1569
1570                         Public          = 0x004,
1571                         NonPublic       = 0x008,
1572                         MaskProtection  = Public|NonPublic,
1573
1574                         Declared        = 0x010,
1575
1576                         Constructor     = 0x020,
1577                         Event           = 0x040,
1578                         Field           = 0x080,
1579                         Method          = 0x100,
1580                         Property        = 0x200,
1581                         NestedType      = 0x400,
1582
1583                         MaskType        = Constructor|Event|Field|Method|Property|NestedType
1584                 }
1585
1586                 protected class CacheEntry {
1587                         public readonly IMemberContainer Container;
1588                         public readonly EntryType EntryType;
1589                         public readonly MemberInfo Member;
1590
1591                         public CacheEntry (IMemberContainer container, MemberInfo member,
1592                                            MemberTypes mt, BindingFlags bf)
1593                         {
1594                                 this.Container = container;
1595                                 this.Member = member;
1596                                 this.EntryType = GetEntryType (mt, bf);
1597                         }
1598
1599                         public override string ToString ()
1600                         {
1601                                 return String.Format ("CacheEntry ({0}:{1}:{2})", Container.Name,
1602                                                       EntryType, Member);
1603                         }
1604                 }
1605
1606                 /// <summary>
1607                 ///   This is called each time we're walking up one level in the class hierarchy
1608                 ///   and checks whether we can abort the search since we've already found what
1609                 ///   we were looking for.
1610                 /// </summary>
1611                 protected bool DoneSearching (ArrayList list)
1612                 {
1613                         //
1614                         // We've found exactly one member in the current class and it's not
1615                         // a method or constructor.
1616                         //
1617                         if (list.Count == 1 && !(list [0] is MethodBase))
1618                                 return true;
1619
1620                         //
1621                         // Multiple properties: we query those just to find out the indexer
1622                         // name
1623                         //
1624                         if ((list.Count > 0) && (list [0] is PropertyInfo))
1625                                 return true;
1626
1627                         return false;
1628                 }
1629
1630                 /// <summary>
1631                 ///   Looks up members with name `name'.  If you provide an optional
1632                 ///   filter function, it'll only be called with members matching the
1633                 ///   requested member name.
1634                 ///
1635                 ///   This method will try to use the cache to do the lookup if possible.
1636                 ///
1637                 ///   Unlike other FindMembers implementations, this method will always
1638                 ///   check all inherited members - even when called on an interface type.
1639                 ///
1640                 ///   If you know that you're only looking for methods, you should use
1641                 ///   MemberTypes.Method alone since this speeds up the lookup a bit.
1642                 ///   When doing a method-only search, it'll try to use a special method
1643                 ///   cache (unless it's a dynamic type or an interface) and the returned
1644                 ///   MemberInfo's will have the correct ReflectedType for inherited methods.
1645                 ///   The lookup process will automatically restart itself in method-only
1646                 ///   search mode if it discovers that it's about to return methods.
1647                 /// </summary>
1648                 ArrayList global = new ArrayList ();
1649                 bool using_global = false;
1650                 
1651                 static MemberInfo [] emptyMemberInfo = new MemberInfo [0];
1652                 
1653                 public MemberInfo [] FindMembers (MemberTypes mt, BindingFlags bf, string name,
1654                                                   MemberFilter filter, object criteria)
1655                 {
1656                         if (using_global)
1657                                 throw new Exception ();
1658                         
1659                         bool declared_only = (bf & BindingFlags.DeclaredOnly) != 0;
1660                         bool method_search = mt == MemberTypes.Method;
1661                         // If we have a method cache and we aren't already doing a method-only search,
1662                         // then we restart a method search if the first match is a method.
1663                         bool do_method_search = !method_search && (method_hash != null);
1664
1665                         ArrayList applicable;
1666
1667                         // If this is a method-only search, we try to use the method cache if
1668                         // possible; a lookup in the method cache will return a MemberInfo with
1669                         // the correct ReflectedType for inherited methods.
1670                         
1671                         if (method_search && (method_hash != null))
1672                                 applicable = (ArrayList) method_hash [name];
1673                         else
1674                                 applicable = (ArrayList) member_hash [name];
1675
1676                         if (applicable == null)
1677                                 return emptyMemberInfo;
1678
1679                         //
1680                         // 32  slots gives 53 rss/54 size
1681                         // 2/4 slots gives 55 rss
1682                         //
1683                         // Strange: from 25,000 calls, only 1,800
1684                         // are above 2.  Why does this impact it?
1685                         //
1686                         global.Clear ();
1687                         using_global = true;
1688
1689                         Timer.StartTimer (TimerType.CachedLookup);
1690
1691                         EntryType type = GetEntryType (mt, bf);
1692
1693                         IMemberContainer current = Container;
1694
1695                         bool do_interface_search = current.IsInterface;
1696
1697                         // `applicable' is a list of all members with the given member name `name'
1698                         // in the current class and all its base classes.  The list is sorted in
1699                         // reverse order due to the way how the cache is initialy created (to speed
1700                         // things up, we're doing a deep-copy of our base).
1701
1702                         for (int i = applicable.Count-1; i >= 0; i--) {
1703                                 CacheEntry entry = (CacheEntry) applicable [i];
1704
1705                                 // This happens each time we're walking one level up in the class
1706                                 // hierarchy.  If we're doing a DeclaredOnly search, we must abort
1707                                 // the first time this happens (this may already happen in the first
1708                                 // iteration of this loop if there are no members with the name we're
1709                                 // looking for in the current class).
1710                                 if (entry.Container != current) {
1711                                         if (declared_only)
1712                                                 break;
1713
1714                                         if (!do_interface_search && DoneSearching (global))
1715                                                 break;
1716
1717                                         current = entry.Container;
1718                                 }
1719
1720                                 // Is the member of the correct type ?
1721                                 if ((entry.EntryType & type & EntryType.MaskType) == 0)
1722                                         continue;
1723
1724                                 // Is the member static/non-static ?
1725                                 if ((entry.EntryType & type & EntryType.MaskStatic) == 0)
1726                                         continue;
1727
1728                                 // Apply the filter to it.
1729                                 if (filter (entry.Member, criteria)) {
1730                                         if ((entry.EntryType & EntryType.MaskType) != EntryType.Method) {
1731                                                 do_method_search = false;
1732                                         }
1733                                         
1734                                         // Because interfaces support multiple inheritance we have to be sure that
1735                                         // base member is from same interface, so only top level member will be returned
1736                                         if (do_interface_search && global.Count > 0) {
1737                                                 bool member_already_exists = false;
1738
1739                                                 foreach (MemberInfo mi in global) {
1740                                                         if (mi is MethodBase)
1741                                                                 continue;
1742
1743                                                         if (IsInterfaceBaseInterface (TypeManager.GetInterfaces (mi.DeclaringType), entry.Member.DeclaringType)) {
1744                                                                 member_already_exists = true;
1745                                                                 break;
1746                                                         }
1747                                                 }
1748                                                 if (member_already_exists)
1749                                                         continue;
1750                                         }
1751
1752                                         global.Add (entry.Member);
1753                                 }
1754                         }
1755
1756                         Timer.StopTimer (TimerType.CachedLookup);
1757
1758                         // If we have a method cache and we aren't already doing a method-only
1759                         // search, we restart in method-only search mode if the first match is
1760                         // a method.  This ensures that we return a MemberInfo with the correct
1761                         // ReflectedType for inherited methods.
1762                         if (do_method_search && (global.Count > 0)){
1763                                 using_global = false;
1764
1765                                 return FindMembers (MemberTypes.Method, bf, name, filter, criteria);
1766                         }
1767
1768                         using_global = false;
1769                         MemberInfo [] copy = new MemberInfo [global.Count];
1770                         global.CopyTo (copy);
1771                         return copy;
1772                 }
1773
1774                 /// <summary>
1775                 /// Returns true if iterface exists in any base interfaces (ifaces)
1776                 /// </summary>
1777                 static bool IsInterfaceBaseInterface (Type[] ifaces, Type ifaceToFind)
1778                 {
1779                         foreach (Type iface in ifaces) {
1780                                 if (iface == ifaceToFind)
1781                                         return true;
1782
1783                                 Type[] base_ifaces = TypeManager.GetInterfaces (iface);
1784                                 if (base_ifaces.Length > 0 && IsInterfaceBaseInterface (base_ifaces, ifaceToFind))
1785                                         return true;
1786                         }
1787                         return false;
1788                 }
1789                 
1790                 // find the nested type @name in @this.
1791                 public Type FindNestedType (string name)
1792                 {
1793                         ArrayList applicable = (ArrayList) member_hash [name];
1794                         if (applicable == null)
1795                                 return null;
1796                         
1797                         for (int i = applicable.Count-1; i >= 0; i--) {
1798                                 CacheEntry entry = (CacheEntry) applicable [i];
1799                                 if ((entry.EntryType & EntryType.NestedType & EntryType.MaskType) != 0)
1800                                         return (Type) entry.Member;
1801                         }
1802                         
1803                         return null;
1804                 }
1805                 
1806                 //
1807                 // This finds the method or property for us to override. invocationType is the type where
1808                 // the override is going to be declared, name is the name of the method/property, and
1809                 // paramTypes is the parameters, if any to the method or property
1810                 //
1811                 // Because the MemberCache holds members from this class and all the base classes,
1812                 // we can avoid tons of reflection stuff.
1813                 //
1814                 public MemberInfo FindMemberToOverride (Type invocationType, string name, Type [] paramTypes, bool is_property)
1815                 {
1816                         ArrayList applicable;
1817                         if (method_hash != null && !is_property)
1818                                 applicable = (ArrayList) method_hash [name];
1819                         else
1820                                 applicable = (ArrayList) member_hash [name];
1821                         
1822                         if (applicable == null)
1823                                 return null;
1824                         //
1825                         // Walk the chain of methods, starting from the top.
1826                         //
1827                         for (int i = applicable.Count - 1; i >= 0; i--) {
1828                                 CacheEntry entry = (CacheEntry) applicable [i];
1829                                 
1830                                 if ((entry.EntryType & (is_property ? (EntryType.Property | EntryType.Field) : EntryType.Method)) == 0)
1831                                         continue;
1832
1833                                 PropertyInfo pi = null;
1834                                 MethodInfo mi = null;
1835                                 FieldInfo fi = null;
1836                                 Type [] cmpAttrs = null;
1837                                 
1838                                 if (is_property) {
1839                                         if ((entry.EntryType & EntryType.Field) != 0) {
1840                                                 fi = (FieldInfo)entry.Member;
1841
1842                                                 // TODO: For this case we ignore member type
1843                                                 //fb = TypeManager.GetField (fi);
1844                                                 //cmpAttrs = new Type[] { fb.MemberType };
1845                                         } else {
1846                                                 pi = (PropertyInfo) entry.Member;
1847                                                 cmpAttrs = TypeManager.GetArgumentTypes (pi);
1848                                         }
1849                                 } else {
1850                                         mi = (MethodInfo) entry.Member;
1851                                         cmpAttrs = TypeManager.GetParameterData (mi).Types;
1852                                 }
1853
1854                                 if (fi != null) {
1855                                         // TODO: Almost duplicate !
1856                                         // Check visibility
1857                                         switch (fi.Attributes & FieldAttributes.FieldAccessMask) {
1858                                                 case FieldAttributes.Private:
1859                                                         //
1860                                                         // A private method is Ok if we are a nested subtype.
1861                                                         // The spec actually is not very clear about this, see bug 52458.
1862                                                         //
1863                                                         if (invocationType != entry.Container.Type &
1864                                                                 TypeManager.IsNestedChildOf (invocationType, entry.Container.Type))
1865                                                                 continue;
1866
1867                                                         break;
1868                                                 case FieldAttributes.FamANDAssem:
1869                                                 case FieldAttributes.Assembly:
1870                                                         //
1871                                                         // Check for assembly methods
1872                                                         //
1873                                                         if (mi.DeclaringType.Assembly != CodeGen.Assembly.Builder)
1874                                                                 continue;
1875                                                         break;
1876                                         }
1877                                         return entry.Member;
1878                                 }
1879
1880                                 //
1881                                 // Check the arguments
1882                                 //
1883                                 if (cmpAttrs.Length != paramTypes.Length)
1884                                         continue;
1885         
1886                                 for (int j = cmpAttrs.Length - 1; j >= 0; j --)
1887                                         if (paramTypes [j] != cmpAttrs [j])
1888                                                 goto next;
1889                                 
1890                                 //
1891                                 // get one of the methods because this has the visibility info.
1892                                 //
1893                                 if (is_property) {
1894                                         mi = pi.GetGetMethod (true);
1895                                         if (mi == null)
1896                                                 mi = pi.GetSetMethod (true);
1897                                 }
1898                                 
1899                                 //
1900                                 // Check visibility
1901                                 //
1902                                 switch (mi.Attributes & MethodAttributes.MemberAccessMask) {
1903                                 case MethodAttributes.Private:
1904                                         //
1905                                         // A private method is Ok if we are a nested subtype.
1906                                         // The spec actually is not very clear about this, see bug 52458.
1907                                         //
1908                                         if (invocationType == entry.Container.Type ||
1909                                             TypeManager.IsNestedChildOf (invocationType, entry.Container.Type))
1910                                                 return entry.Member;
1911                                         
1912                                         break;
1913                                 case MethodAttributes.FamANDAssem:
1914                                 case MethodAttributes.Assembly:
1915                                         //
1916                                         // Check for assembly methods
1917                                         //
1918                                         if (mi.DeclaringType.Assembly == CodeGen.Assembly.Builder)
1919                                                 return entry.Member;
1920                                         
1921                                         break;
1922                                 default:
1923                                         //
1924                                         // A protected method is ok, because we are overriding.
1925                                         // public is always ok.
1926                                         //
1927                                         return entry.Member;
1928                                 }
1929                         next:
1930                                 ;
1931                         }
1932                         
1933                         return null;
1934                 }
1935
1936                 /// <summary>
1937                 /// The method is looking for conflict with inherited symbols (errors CS0108, CS0109).
1938                 /// We handle two cases. The first is for types without parameters (events, field, properties).
1939                 /// The second are methods, indexers and this is why ignore_complex_types is here.
1940                 /// The latest param is temporary hack. See DoDefineMembers method for more info.
1941                 /// </summary>
1942                 public MemberInfo FindMemberWithSameName (string name, bool ignore_complex_types, MemberInfo ignore_member)
1943                 {
1944                         ArrayList applicable = null;
1945  
1946                         if (method_hash != null)
1947                                 applicable = (ArrayList) method_hash [name];
1948  
1949                         if (applicable != null) {
1950                                 for (int i = applicable.Count - 1; i >= 0; i--) {
1951                                         CacheEntry entry = (CacheEntry) applicable [i];
1952                                         if ((entry.EntryType & EntryType.Public) != 0)
1953                                                 return entry.Member;
1954                                 }
1955                         }
1956  
1957                         if (member_hash == null)
1958                                 return null;
1959                         applicable = (ArrayList) member_hash [name];
1960                         
1961                         if (applicable != null) {
1962                                 for (int i = applicable.Count - 1; i >= 0; i--) {
1963                                         CacheEntry entry = (CacheEntry) applicable [i];
1964                                         if ((entry.EntryType & EntryType.Public) != 0 & entry.Member != ignore_member) {
1965                                                 if (ignore_complex_types) {
1966                                                         if ((entry.EntryType & EntryType.Method) != 0)
1967                                                                 continue;
1968  
1969                                                         // Does exist easier way how to detect indexer ?
1970                                                         if ((entry.EntryType & EntryType.Property) != 0) {
1971                                                                 Type[] arg_types = TypeManager.GetArgumentTypes ((PropertyInfo)entry.Member);
1972                                                                 if (arg_types.Length > 0)
1973                                                                         continue;
1974                                                         }
1975                                                 }
1976                                                 return entry.Member;
1977                                         }
1978                                 }
1979                         }
1980                         return null;
1981                 }
1982
1983                 Hashtable locase_table;
1984  
1985                 /// <summary>
1986                 /// Builds low-case table for CLS Compliance test
1987                 /// </summary>
1988                 public Hashtable GetPublicMembers ()
1989                 {
1990                         if (locase_table != null)
1991                                 return locase_table;
1992  
1993                         locase_table = new Hashtable ();
1994                         foreach (DictionaryEntry entry in member_hash) {
1995                                 ArrayList members = (ArrayList)entry.Value;
1996                                 for (int ii = 0; ii < members.Count; ++ii) {
1997                                         CacheEntry member_entry = (CacheEntry) members [ii];
1998  
1999                                         if ((member_entry.EntryType & EntryType.Public) == 0)
2000                                                 continue;
2001  
2002                                         // TODO: Does anyone know easier way how to detect that member is internal ?
2003                                         switch (member_entry.EntryType & EntryType.MaskType) {
2004                                                 case EntryType.Constructor:
2005                                                         continue;
2006  
2007                                                 case EntryType.Field:
2008                                                         if ((((FieldInfo)member_entry.Member).Attributes & (FieldAttributes.Assembly | FieldAttributes.Public)) == FieldAttributes.Assembly)
2009                                                                 continue;
2010                                                         break;
2011  
2012                                                 case EntryType.Method:
2013                                                         if ((((MethodInfo)member_entry.Member).Attributes & (MethodAttributes.Assembly | MethodAttributes.Public)) == MethodAttributes.Assembly)
2014                                                                 continue;
2015                                                         break;
2016  
2017                                                 case EntryType.Property:
2018                                                         PropertyInfo pi = (PropertyInfo)member_entry.Member;
2019                                                         if (pi.GetSetMethod () == null && pi.GetGetMethod () == null)
2020                                                                 continue;
2021                                                         break;
2022  
2023                                                 case EntryType.Event:
2024                                                         EventInfo ei = (EventInfo)member_entry.Member;
2025                                                         MethodInfo mi = ei.GetAddMethod ();
2026                                                         if ((mi.Attributes & (MethodAttributes.Assembly | MethodAttributes.Public)) == MethodAttributes.Assembly)
2027                                                                 continue;
2028                                                         break;
2029                                         }
2030                                         string lcase = ((string)entry.Key).ToLower (System.Globalization.CultureInfo.InvariantCulture);
2031                                         locase_table [lcase] = member_entry.Member;
2032                                         break;
2033                                 }
2034                         }
2035                         return locase_table;
2036                 }
2037  
2038                 public Hashtable Members {
2039                         get {
2040                                 return member_hash;
2041                         }
2042                 }
2043  
2044                 /// <summary>
2045                 /// Cls compliance check whether methods or constructors parameters differing only in ref or out, or in array rank
2046                 /// </summary>
2047                 /// 
2048                 // TODO: refactor as method is always 'this'
2049                 public static void VerifyClsParameterConflict (ArrayList al, MethodCore method, MemberInfo this_builder)
2050                 {
2051                         EntryType tested_type = (method is Constructor ? EntryType.Constructor : EntryType.Method) | EntryType.Public;
2052  
2053                         for (int i = 0; i < al.Count; ++i) {
2054                                 MemberCache.CacheEntry entry = (MemberCache.CacheEntry) al [i];
2055                 
2056                                 // skip itself
2057                                 if (entry.Member == this_builder)
2058                                         continue;
2059                 
2060                                 if ((entry.EntryType & tested_type) != tested_type)
2061                                         continue;
2062                 
2063                                 MethodBase method_to_compare = (MethodBase)entry.Member;
2064                                 AttributeTester.Result result = AttributeTester.AreOverloadedMethodParamsClsCompliant (
2065                                         method.ParameterTypes, TypeManager.GetParameterData (method_to_compare).Types);
2066
2067                                 if (result == AttributeTester.Result.Ok)
2068                                         continue;
2069
2070                                 IMethodData md = TypeManager.GetMethod (method_to_compare);
2071
2072                                 // TODO: now we are ignoring CLSCompliance(false) on method from other assembly which is buggy.
2073                                 // However it is exactly what csc does.
2074                                 if (md != null && !md.IsClsComplianceRequired ())
2075                                         continue;
2076                 
2077                                 Report.SymbolRelatedToPreviousError (entry.Member);
2078                                 switch (result) {
2079                                         case AttributeTester.Result.RefOutArrayError:
2080                                                 Report.Error (3006, method.Location, "Overloaded method `{0}' differing only in ref or out, or in array rank, is not CLS-compliant", method.GetSignatureForError ());
2081                                                 continue;
2082                                         case AttributeTester.Result.ArrayArrayError:
2083                                                 Report.Error (3007, method.Location, "Overloaded method `{0}' differing only by unnamed array types is not CLS-compliant", method.GetSignatureForError ());
2084                                                 continue;
2085                                 }
2086
2087                                 throw new NotImplementedException (result.ToString ());
2088                         }
2089                 }
2090         }
2091 }