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