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