[xbuild] Fix bug #676671. Raise AnyEvent .
[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 // Dual licensed under the terms of the MIT X11 or GNU GPL
8 //
9 // Copyright 2001 Ximian, Inc (http://www.ximian.com)
10 // Copyright 2004-2008 Novell, Inc
11 //
12 //
13
14 using System;
15 using System.Collections.Generic;
16
17 #if NET_2_1
18 using XmlElement = System.Object;
19 #else
20 using System.Xml;
21 #endif
22
23 #if STATIC
24 using IKVM.Reflection;
25 using IKVM.Reflection.Emit;
26 #else
27 using System.Reflection;
28 using System.Reflection.Emit;
29 #endif
30
31 namespace Mono.CSharp {
32
33         //
34         // Better name would be DottenName
35         //
36         public class MemberName {
37                 public readonly string Name;
38                 public TypeArguments TypeArguments;
39
40                 public readonly MemberName Left;
41                 public readonly Location Location;
42
43                 public static readonly MemberName Null = new MemberName ("");
44
45                 bool is_double_colon;
46
47                 private MemberName (MemberName left, string name, bool is_double_colon,
48                                     Location loc)
49                 {
50                         this.Name = name;
51                         this.Location = loc;
52                         this.is_double_colon = is_double_colon;
53                         this.Left = left;
54                 }
55
56                 private MemberName (MemberName left, string name, bool is_double_colon,
57                                     TypeArguments args, Location loc)
58                         : this (left, name, is_double_colon, loc)
59                 {
60                         if (args != null && args.Count > 0)
61                                 this.TypeArguments = args;
62                 }
63
64                 public MemberName (string name)
65                         : this (name, Location.Null)
66                 { }
67
68                 public MemberName (string name, Location loc)
69                         : this (null, name, false, loc)
70                 { }
71
72                 public MemberName (string name, TypeArguments args, Location loc)
73                         : this (null, name, false, args, loc)
74                 { }
75
76                 public MemberName (MemberName left, string name)
77                         : this (left, name, left != null ? left.Location : Location.Null)
78                 { }
79
80                 public MemberName (MemberName left, string name, Location loc)
81                         : this (left, name, false, loc)
82                 { }
83
84                 public MemberName (MemberName left, string name, TypeArguments args, Location loc)
85                         : this (left, name, false, args, loc)
86                 { }
87
88                 public MemberName (string alias, string name, TypeArguments args, Location loc)
89                         : this (new MemberName (alias, loc), name, true, args, loc)
90                 { }
91
92                 public MemberName (MemberName left, MemberName right)
93                         : this (left, right, right.Location)
94                 { }
95
96                 public MemberName (MemberName left, MemberName right, Location loc)
97                         : this (null, right.Name, false, right.TypeArguments, loc)
98                 {
99                         if (right.is_double_colon)
100                                 throw new InternalErrorException ("Cannot append double_colon member name");
101                         this.Left = (right.Left == null) ? left : new MemberName (left, right.Left);
102                 }
103
104                 // TODO: Remove
105                 public string GetName ()
106                 {
107                         return GetName (false);
108                 }
109
110                 public int Arity {
111                         get {
112                                 return TypeArguments == null ? 0 : TypeArguments.Count;
113                         }
114                 }
115
116                 public bool IsGeneric {
117                         get {
118                                 if (TypeArguments != null)
119                                         return true;
120                                 else if (Left != null)
121                                         return Left.IsGeneric;
122                                 else
123                                         return false;
124                         }
125                 }
126
127                 public string GetName (bool is_generic)
128                 {
129                         string name = is_generic ? Basename : Name;
130                         if (Left != null)
131                                 return Left.GetName (is_generic) + (is_double_colon ? "::" : ".") + name;
132
133                         return name;
134                 }
135
136                 public ATypeNameExpression GetTypeExpression ()
137                 {
138                         if (Left == null) {
139                                 if (TypeArguments != null)
140                                         return new SimpleName (Name, TypeArguments, Location);
141                                 
142                                 return new SimpleName (Name, Location);
143                         }
144
145                         if (is_double_colon) {
146                                 if (Left.Left != null)
147                                         throw new InternalErrorException ("The left side of a :: should be an identifier");
148                                 return new QualifiedAliasMember (Left.Name, Name, TypeArguments, Location);
149                         }
150
151                         Expression lexpr = Left.GetTypeExpression ();
152                         return new MemberAccess (lexpr, Name, TypeArguments, Location);
153                 }
154
155                 public MemberName Clone ()
156                 {
157                         MemberName left_clone = Left == null ? null : Left.Clone ();
158                         return new MemberName (left_clone, Name, is_double_colon, TypeArguments, Location);
159                 }
160
161                 public string Basename {
162                         get {
163                                 if (TypeArguments != null)
164                                         return MakeName (Name, TypeArguments);
165                                 return Name;
166                         }
167                 }
168
169                 public string GetSignatureForError ()
170                 {
171                         string append = TypeArguments == null ? "" : "<" + TypeArguments.GetSignatureForError () + ">";
172                         if (Left == null)
173                                 return Name + append;
174                         string connect = is_double_colon ? "::" : ".";
175                         return Left.GetSignatureForError () + connect + Name + append;
176                 }
177
178                 public override bool Equals (object other)
179                 {
180                         return Equals (other as MemberName);
181                 }
182
183                 public bool Equals (MemberName other)
184                 {
185                         if (this == other)
186                                 return true;
187                         if (other == null || Name != other.Name)
188                                 return false;
189                         if (is_double_colon != other.is_double_colon)
190                                 return false;
191
192                         if ((TypeArguments != null) &&
193                             (other.TypeArguments == null || TypeArguments.Count != other.TypeArguments.Count))
194                                 return false;
195
196                         if ((TypeArguments == null) && (other.TypeArguments != null))
197                                 return false;
198
199                         if (Left == null)
200                                 return other.Left == null;
201
202                         return Left.Equals (other.Left);
203                 }
204
205                 public override int GetHashCode ()
206                 {
207                         int hash = Name.GetHashCode ();
208                         for (MemberName n = Left; n != null; n = n.Left)
209                                 hash ^= n.Name.GetHashCode ();
210                         if (is_double_colon)
211                                 hash ^= 0xbadc01d;
212
213                         if (TypeArguments != null)
214                                 hash ^= TypeArguments.Count << 5;
215
216                         return hash & 0x7FFFFFFF;
217                 }
218
219                 public int CountTypeArguments {
220                         get {
221                                 if (TypeArguments != null)
222                                         return TypeArguments.Count;
223                                 else if (Left != null)
224                                         return Left.CountTypeArguments; 
225                                 else
226                                         return 0;
227                         }
228                 }
229
230                 public static string MakeName (string name, TypeArguments args)
231                 {
232                         if (args == null)
233                                 return name;
234
235                         return name + "`" + args.Count;
236                 }
237
238                 public static string MakeName (string name, int count)
239                 {
240                         return name + "`" + count;
241                 }
242         }
243
244         public class SimpleMemberName
245         {
246                 public string Value;
247                 public Location Location;
248
249                 public SimpleMemberName (string name, Location loc)
250                 {
251                         this.Value = name;
252                         this.Location = loc;
253                 }
254         }
255
256         /// <summary>
257         ///   Base representation for members.  This is used to keep track
258         ///   of Name, Location and Modifier flags, and handling Attributes.
259         /// </summary>
260         [System.Diagnostics.DebuggerDisplay ("{GetSignatureForError()}")]
261         public abstract class MemberCore : Attributable, IMemberContext, IMemberDefinition
262         {
263                 /// <summary>
264                 ///   Public name
265                 /// </summary>
266
267                 protected string cached_name;
268                 // TODO: Remove in favor of MemberName
269                 public string Name {
270                         get {
271                                 if (cached_name == null)
272                                         cached_name = MemberName.GetName (!(this is GenericMethod) && !(this is Method));
273                                 return cached_name;
274                         }
275                 }
276
277                 string IMemberDefinition.Name {
278                         get {
279                                 return member_name.Name;
280                         }
281                 }
282
283                 // Is not readonly because of IndexerName attribute
284                 private MemberName member_name;
285                 public MemberName MemberName {
286                         get { return member_name; }
287                 }
288
289                 /// <summary>
290                 ///   Modifier flags that the user specified in the source code
291                 /// </summary>
292                 private Modifiers mod_flags;
293                 public Modifiers ModFlags {
294                         set {
295                                 mod_flags = value;
296                                 if ((value & Modifiers.COMPILER_GENERATED) != 0)
297                                         caching_flags = Flags.IsUsed | Flags.IsAssigned;
298                         }
299                         get {
300                                 return mod_flags;
301                         }
302                 }
303
304                 public virtual ModuleContainer Module {
305                         get {
306                                 return Parent.Module;
307                         }
308                 }
309
310                 public /*readonly*/ TypeContainer Parent;
311
312                 /// <summary>
313                 ///   Location where this declaration happens
314                 /// </summary>
315                 public Location Location {
316                         get { return member_name.Location; }
317                 }
318
319                 /// <summary>
320                 ///   XML documentation comment
321                 /// </summary>
322                 protected string comment;
323
324                 /// <summary>
325                 ///   Represents header string for documentation comment 
326                 ///   for each member types.
327                 /// </summary>
328                 public abstract string DocCommentHeader { get; }
329
330                 [Flags]
331                 public enum Flags {
332                         Obsolete_Undetected = 1,                // Obsolete attribute has not been detected yet
333                         Obsolete = 1 << 1,                      // Type has obsolete attribute
334                         ClsCompliance_Undetected = 1 << 2,      // CLS Compliance has not been detected yet
335                         ClsCompliant = 1 << 3,                  // Type is CLS Compliant
336                         CloseTypeCreated = 1 << 4,              // Tracks whether we have Closed the type
337                         HasCompliantAttribute_Undetected = 1 << 5,      // Presence of CLSCompliantAttribute has not been detected
338                         HasClsCompliantAttribute = 1 << 6,                      // Type has CLSCompliantAttribute
339                         ClsCompliantAttributeFalse = 1 << 7,                    // Member has CLSCompliant(false)
340                         Excluded_Undetected = 1 << 8,           // Conditional attribute has not been detected yet
341                         Excluded = 1 << 9,                                      // Method is conditional
342                         MethodOverloadsExist = 1 << 10,         // Test for duplication must be performed
343                         IsUsed = 1 << 11,
344                         IsAssigned = 1 << 12,                           // Field is assigned
345                         HasExplicitLayout       = 1 << 13,
346                         PartialDefinitionExists = 1 << 14,      // Set when corresponding partial method definition exists
347                         HasStructLayout         = 1 << 15                       // Has StructLayoutAttribute
348                 }
349
350                 /// <summary>
351                 ///   MemberCore flags at first detected then cached
352                 /// </summary>
353                 internal Flags caching_flags;
354
355                 public MemberCore (DeclSpace parent, MemberName name, Attributes attrs)
356                 {
357                         this.Parent = parent as TypeContainer;
358                         member_name = name;
359                         caching_flags = Flags.Obsolete_Undetected | Flags.ClsCompliance_Undetected | Flags.HasCompliantAttribute_Undetected | Flags.Excluded_Undetected;
360                         AddAttributes (attrs, this);
361                 }
362
363                 protected virtual void SetMemberName (MemberName new_name)
364                 {
365                         member_name = new_name;
366                         cached_name = null;
367                 }
368
369                 protected bool CheckAbstractAndExtern (bool has_block)
370                 {
371                         if (Parent.PartialContainer.Kind == MemberKind.Interface)
372                                 return true;
373
374                         if (has_block) {
375                                 if ((ModFlags & Modifiers.EXTERN) != 0) {
376                                         Report.Error (179, Location, "`{0}' cannot declare a body because it is marked extern",
377                                                 GetSignatureForError ());
378                                         return false;
379                                 }
380
381                                 if ((ModFlags & Modifiers.ABSTRACT) != 0) {
382                                         Report.Error (500, Location, "`{0}' cannot declare a body because it is marked abstract",
383                                                 GetSignatureForError ());
384                                         return false;
385                                 }
386                         } else {
387                                 if ((ModFlags & (Modifiers.ABSTRACT | Modifiers.EXTERN | Modifiers.PARTIAL)) == 0 && !(Parent is Delegate)) {
388                                         if (Compiler.Settings.Version >= LanguageVersion.V_3) {
389                                                 Property.PropertyMethod pm = this as Property.PropertyMethod;
390                                                 if (pm is Indexer.GetIndexerMethod || pm is Indexer.SetIndexerMethod)
391                                                         pm = null;
392
393                                                 if (pm != null && pm.Property.AccessorSecond == null) {
394                                                         Report.Error (840, Location,
395                                                                 "`{0}' must have a body because it is not marked abstract or extern. The property can be automatically implemented when you define both accessors",
396                                                                 GetSignatureForError ());
397                                                         return false;
398                                                 }
399                                         }
400
401                                         Report.Error (501, Location, "`{0}' must have a body because it is not marked abstract, extern, or partial",
402                                                       GetSignatureForError ());
403                                         return false;
404                                 }
405                         }
406
407                         return true;
408                 }
409
410                 protected void CheckProtectedModifier ()
411                 {
412                         if ((ModFlags & Modifiers.PROTECTED) == 0)
413                                 return;
414
415                         if (Parent.PartialContainer.Kind == MemberKind.Struct) {
416                                 Report.Error (666, Location, "`{0}': Structs cannot contain protected members",
417                                         GetSignatureForError ());
418                                 return;
419                         }
420
421                         if ((Parent.ModFlags & Modifiers.STATIC) != 0) {
422                                 Report.Error (1057, Location, "`{0}': Static classes cannot contain protected members",
423                                         GetSignatureForError ());
424                                 return;
425                         }
426
427                         if ((Parent.ModFlags & Modifiers.SEALED) != 0 && (ModFlags & Modifiers.OVERRIDE) == 0 &&
428                                 !(this is Destructor)) {
429                                 Report.Warning (628, 4, Location, "`{0}': new protected member declared in sealed class",
430                                         GetSignatureForError ());
431                                 return;
432                         }
433                 }
434
435                 public abstract bool Define ();
436
437                 public virtual string DocComment {
438                         get {
439                                 return comment;
440                         }
441                         set {
442                                 comment = value;
443                         }
444                 }
445
446                 // 
447                 // Returns full member name for error message
448                 //
449                 public virtual string GetSignatureForError ()
450                 {
451                         if (Parent == null || Parent.Parent == null)
452                                 return member_name.GetSignatureForError ();
453
454                         return Parent.GetSignatureForError () + "." + member_name.GetSignatureForError ();
455                 }
456
457                 /// <summary>
458                 /// Base Emit method. This is also entry point for CLS-Compliant verification.
459                 /// </summary>
460                 public virtual void Emit ()
461                 {
462                         if (!Compiler.Settings.VerifyClsCompliance)
463                                 return;
464
465                         VerifyClsCompliance ();
466                 }
467
468                 public bool IsCompilerGenerated {
469                         get     {
470                                 if ((mod_flags & Modifiers.COMPILER_GENERATED) != 0)
471                                         return true;
472
473                                 return Parent == null ? false : Parent.IsCompilerGenerated;
474                         }
475                 }
476
477                 public bool IsImported {
478                         get {
479                                 return false;
480                         }
481                 }
482
483                 public virtual bool IsUsed {
484                         get {
485                                 return (caching_flags & Flags.IsUsed) != 0;
486                         }
487                 }
488
489                 protected Report Report {
490                         get {
491                                 return Compiler.Report;
492                         }
493                 }
494
495                 public void SetIsUsed ()
496                 {
497                         caching_flags |= Flags.IsUsed;
498                 }
499
500                 public void SetIsAssigned ()
501                 {
502                         caching_flags |= Flags.IsAssigned;
503                 }
504
505                 /// <summary>
506                 /// Returns instance of ObsoleteAttribute for this MemberCore
507                 /// </summary>
508                 public virtual ObsoleteAttribute GetAttributeObsolete ()
509                 {
510                         if ((caching_flags & (Flags.Obsolete_Undetected | Flags.Obsolete)) == 0)
511                                 return null;
512
513                         caching_flags &= ~Flags.Obsolete_Undetected;
514
515                         if (OptAttributes == null)
516                                 return null;
517
518                         Attribute obsolete_attr = OptAttributes.Search (Module.PredefinedAttributes.Obsolete);
519                         if (obsolete_attr == null)
520                                 return null;
521
522                         caching_flags |= Flags.Obsolete;
523
524                         ObsoleteAttribute obsolete = obsolete_attr.GetObsoleteAttribute ();
525                         if (obsolete == null)
526                                 return null;
527
528                         return obsolete;
529                 }
530
531                 /// <summary>
532                 /// Checks for ObsoleteAttribute presence. It's used for testing of all non-types elements
533                 /// </summary>
534                 public virtual void CheckObsoleteness (Location loc)
535                 {
536                         ObsoleteAttribute oa = GetAttributeObsolete ();
537                         if (oa != null)
538                                 AttributeTester.Report_ObsoleteMessage (oa, GetSignatureForError (), loc, Report);
539                 }
540
541                 //
542                 // Checks whether the type P is as accessible as this member
543                 //
544                 public bool IsAccessibleAs (TypeSpec p)
545                 {
546                         //
547                         // if M is private, its accessibility is the same as this declspace.
548                         // we already know that P is accessible to T before this method, so we
549                         // may return true.
550                         //
551                         if ((mod_flags & Modifiers.PRIVATE) != 0)
552                                 return true;
553
554                         while (TypeManager.HasElementType (p))
555                                 p = TypeManager.GetElementType (p);
556
557                         if (p.IsGenericParameter)
558                                 return true;
559
560                         for (TypeSpec p_parent; p != null; p = p_parent) {
561                                 p_parent = p.DeclaringType;
562
563                                 if (p.IsGeneric) {
564                                         foreach (TypeSpec t in p.TypeArguments) {
565                                                 if (!IsAccessibleAs (t))
566                                                         return false;
567                                         }
568                                 }
569
570                                 var pAccess = p.Modifiers & Modifiers.AccessibilityMask;
571                                 if (pAccess == Modifiers.PUBLIC)
572                                         continue;
573
574                                 bool same_access_restrictions = false;
575                                 for (MemberCore mc = this; !same_access_restrictions && mc != null && mc.Parent != null; mc = mc.Parent) {
576                                         var al = mc.ModFlags & Modifiers.AccessibilityMask;
577                                         switch (pAccess) {
578                                         case Modifiers.INTERNAL:
579                                                 if (al == Modifiers.PRIVATE || al == Modifiers.INTERNAL)
580                                                         same_access_restrictions = p.MemberDefinition.IsInternalAsPublic (mc.Module.DeclaringAssembly);
581                                                 
582                                                 break;
583
584                                         case Modifiers.PROTECTED:
585                                                 if (al == Modifiers.PROTECTED) {
586                                                         same_access_restrictions = mc.Parent.IsBaseTypeDefinition (p_parent);
587                                                         break;
588                                                 }
589
590                                                 if (al == Modifiers.PRIVATE) {
591                                                         //
592                                                         // When type is private and any of its parents derives from
593                                                         // protected type then the type is accessible
594                                                         //
595                                                         while (mc.Parent != null) {
596                                                                 if (mc.Parent.IsBaseTypeDefinition (p_parent))
597                                                                         same_access_restrictions = true;
598                                                                 mc = mc.Parent; 
599                                                         }
600                                                 }
601                                                 
602                                                 break;
603
604                                         case Modifiers.PROTECTED | Modifiers.INTERNAL:
605                                                 if (al == Modifiers.INTERNAL)
606                                                         same_access_restrictions = p.MemberDefinition.IsInternalAsPublic (mc.Module.DeclaringAssembly);
607                                                 else if (al == (Modifiers.PROTECTED | Modifiers.INTERNAL))
608                                                         same_access_restrictions = mc.Parent.IsBaseTypeDefinition (p_parent) && p.MemberDefinition.IsInternalAsPublic (mc.Module.DeclaringAssembly);
609                                                 else
610                                                         goto case Modifiers.PROTECTED;
611
612                                                 break;
613
614                                         case Modifiers.PRIVATE:
615                                                 //
616                                                 // Both are private and share same parent
617                                                 //
618                                                 if (al == Modifiers.PRIVATE) {
619                                                         var decl = mc.Parent;
620                                                         do {
621                                                                 same_access_restrictions = decl.CurrentType == p_parent;
622                                                         } while (!same_access_restrictions && !decl.IsTopLevel && (decl = decl.Parent) != null);
623                                                 }
624                                                 
625                                                 break;
626                                                 
627                                         default:
628                                                 throw new InternalErrorException (al.ToString ());
629                                         }
630                                 }
631                                 
632                                 if (!same_access_restrictions)
633                                         return false;
634                         }
635
636                         return true;
637                 }
638
639                 /// <summary>
640                 /// Analyze whether CLS-Compliant verification must be execute for this MemberCore.
641                 /// </summary>
642                 public override bool IsClsComplianceRequired ()
643                 {
644                         if ((caching_flags & Flags.ClsCompliance_Undetected) == 0)
645                                 return (caching_flags & Flags.ClsCompliant) != 0;
646
647                         caching_flags &= ~Flags.ClsCompliance_Undetected;
648
649                         if (HasClsCompliantAttribute) {
650                                 if ((caching_flags & Flags.ClsCompliantAttributeFalse) != 0)
651                                         return false;
652
653                                 caching_flags |= Flags.ClsCompliant;
654                                 return true;
655                         }
656
657                         if (Parent.PartialContainer.IsClsComplianceRequired ()) {
658                                 caching_flags |= Flags.ClsCompliant;
659                                 return true;
660                         }
661
662                         return false;
663                 }
664
665                 public virtual string[] ConditionalConditions ()
666                 {
667                         return null;
668                 }
669
670                 /// <summary>
671                 /// Returns true when MemberCore is exposed from assembly.
672                 /// </summary>
673                 public bool IsExposedFromAssembly ()
674                 {
675                         if ((ModFlags & (Modifiers.PUBLIC | Modifiers.PROTECTED)) == 0)
676                                 return false;
677                         
678                         DeclSpace parentContainer = Parent.PartialContainer;
679                         while (parentContainer != null && parentContainer.ModFlags != 0) {
680                                 if ((parentContainer.ModFlags & (Modifiers.PUBLIC | Modifiers.PROTECTED)) == 0)
681                                         return false;
682                                 parentContainer = parentContainer.Parent;
683                         }
684                         return true;
685                 }
686
687                 public virtual IList<MethodSpec> LookupExtensionMethod (TypeSpec extensionType, string name, int arity, ref NamespaceEntry scope)
688                 {
689                         return Parent.LookupExtensionMethod (extensionType, name, arity, ref scope);
690                 }
691
692                 public virtual FullNamedExpression LookupNamespaceAlias (string name)
693                 {
694                         return Parent.NamespaceEntry.LookupNamespaceAlias (name);
695                 }
696
697                 public virtual FullNamedExpression LookupNamespaceOrType (string name, int arity, Location loc, bool ignore_cs0104)
698                 {
699                         return Parent.LookupNamespaceOrType (name, arity, loc, ignore_cs0104);
700                 }
701
702                 /// <summary>
703                 /// Goes through class hierarchy and gets value of first found CLSCompliantAttribute.
704                 /// If no is attribute exists then assembly CLSCompliantAttribute is returned.
705                 /// </summary>
706                 public bool? CLSAttributeValue {
707                         get {
708                                 if ((caching_flags & Flags.HasCompliantAttribute_Undetected) == 0) {
709                                         if ((caching_flags & Flags.HasClsCompliantAttribute) == 0)
710                                                 return null;
711
712                                         return (caching_flags & Flags.ClsCompliantAttributeFalse) == 0;
713                                 }
714
715                                 caching_flags &= ~Flags.HasCompliantAttribute_Undetected;
716
717                                 if (OptAttributes != null) {
718                                         Attribute cls_attribute = OptAttributes.Search (Module.PredefinedAttributes.CLSCompliant);
719                                         if (cls_attribute != null) {
720                                                 caching_flags |= Flags.HasClsCompliantAttribute;
721                                                 if (cls_attribute.GetClsCompliantAttributeValue ())
722                                                         return true;
723
724                                                 caching_flags |= Flags.ClsCompliantAttributeFalse;
725                                                 return false;
726                                         }
727                                 }
728
729                                 return null;
730                         }
731                 }
732
733                 /// <summary>
734                 /// Returns true if MemberCore is explicitly marked with CLSCompliantAttribute
735                 /// </summary>
736                 protected bool HasClsCompliantAttribute {
737                         get {
738                                 return CLSAttributeValue.HasValue;
739                         }
740                 }
741
742                 /// <summary>
743                 /// Returns true when a member supports multiple overloads (methods, indexers, etc)
744                 /// </summary>
745                 public virtual bool EnableOverloadChecks (MemberCore overload)
746                 {
747                         return false;
748                 }
749
750                 /// <summary>
751                 /// The main virtual method for CLS-Compliant verifications.
752                 /// The method returns true if member is CLS-Compliant and false if member is not
753                 /// CLS-Compliant which means that CLS-Compliant tests are not necessary. A descendants override it
754                 /// and add their extra verifications.
755                 /// </summary>
756                 protected virtual bool VerifyClsCompliance ()
757                 {
758                         if (HasClsCompliantAttribute) {
759                                 if (!Module.DeclaringAssembly.HasCLSCompliantAttribute) {
760                                         Attribute a = OptAttributes.Search (Module.PredefinedAttributes.CLSCompliant);
761                                         if ((caching_flags & Flags.ClsCompliantAttributeFalse) != 0) {
762                                                 Report.Warning (3021, 2, a.Location,
763                                                         "`{0}' does not need a CLSCompliant attribute because the assembly is not marked as CLS-compliant",
764                                                         GetSignatureForError ());
765                                         } else {
766                                                 Report.Warning (3014, 1, a.Location,
767                                                         "`{0}' cannot be marked as CLS-compliant because the assembly is not marked as CLS-compliant",
768                                                         GetSignatureForError ());
769                                         }
770                                         return false;
771                                 }
772
773                                 if (!IsExposedFromAssembly ()) {
774                                         Attribute a = OptAttributes.Search (Module.PredefinedAttributes.CLSCompliant);
775                                         Report.Warning (3019, 2, a.Location, "CLS compliance checking will not be performed on `{0}' because it is not visible from outside this assembly", GetSignatureForError ());
776                                         return false;
777                                 }
778
779                                 if ((caching_flags & Flags.ClsCompliantAttributeFalse) != 0) {
780                                         if (Parent.Kind == MemberKind.Interface && Parent.IsClsComplianceRequired ()) {
781                                                 Report.Warning (3010, 1, Location, "`{0}': CLS-compliant interfaces must have only CLS-compliant members", GetSignatureForError ());
782                                         } else if (Parent.Kind == MemberKind.Class && (ModFlags & Modifiers.ABSTRACT) != 0 && Parent.IsClsComplianceRequired ()) {
783                                                 Report.Warning (3011, 1, Location, "`{0}': only CLS-compliant members can be abstract", GetSignatureForError ());
784                                         }
785
786                                         return false;
787                                 }
788
789                                 if (Parent.Parent != null && !Parent.IsClsComplianceRequired ()) {
790                                         Attribute a = OptAttributes.Search (Module.PredefinedAttributes.CLSCompliant);
791                                         Report.Warning (3018, 1, a.Location, "`{0}' cannot be marked as CLS-compliant because it is a member of non CLS-compliant type `{1}'",
792                                                 GetSignatureForError (), Parent.GetSignatureForError ());
793                                         return false;
794                                 }
795                         } else {
796                                 if (!IsExposedFromAssembly ())
797                                         return false;
798
799                                 if (!Parent.PartialContainer.IsClsComplianceRequired ())
800                                         return false;
801                         }
802
803                         if (member_name.Name [0] == '_') {
804                                 Report.Warning (3008, 1, Location, "Identifier `{0}' is not CLS-compliant", GetSignatureForError () );
805                         }
806
807                         return true;
808                 }
809
810                 //
811                 // Raised (and passed an XmlElement that contains the comment)
812                 // when GenerateDocComment is writing documentation expectedly.
813                 //
814                 internal virtual void OnGenerateDocComment (XmlElement intermediateNode)
815                 {
816                 }
817
818                 //
819                 // Returns a string that represents the signature for this 
820                 // member which should be used in XML documentation.
821                 //
822                 public virtual string GetDocCommentName (DeclSpace ds)
823                 {
824                         if (ds == null || this is DeclSpace)
825                                 return DocCommentHeader + Name;
826                         else
827                                 return String.Concat (DocCommentHeader, ds.Name, ".", Name);
828                 }
829
830                 //
831                 // Generates xml doc comments (if any), and if required,
832                 // handle warning report.
833                 //
834                 internal virtual void GenerateDocComment (DeclSpace ds)
835                 {
836                         try {
837                                 DocUtil.GenerateDocComment (this, ds, Report);
838                         } catch (Exception e) {
839                                 throw new InternalErrorException (this, e);
840                         }
841                 }
842
843                 #region IMemberContext Members
844
845                 public virtual CompilerContext Compiler {
846                         get { return Parent.Compiler; }
847                 }
848
849                 public virtual TypeSpec CurrentType {
850                         get { return Parent.CurrentType; }
851                 }
852
853                 public MemberCore CurrentMemberDefinition {
854                         get { return this; }
855                 }
856
857                 public virtual TypeParameter[] CurrentTypeParameters {
858                         get { return null; }
859                 }
860
861                 public virtual bool HasUnresolvedConstraints {
862                         get { return false; }
863                 }
864
865                 public bool IsObsolete {
866                         get {
867                                 if (GetAttributeObsolete () != null)
868                                         return true;
869
870                                 return Parent == null ? false : Parent.IsObsolete;
871                         }
872                 }
873
874                 public bool IsUnsafe {
875                         get {
876                                 if ((ModFlags & Modifiers.UNSAFE) != 0)
877                                         return true;
878
879                                 return Parent == null ? false : Parent.IsUnsafe;
880                         }
881                 }
882
883                 public bool IsStatic {
884                         get {
885                                 return (ModFlags & Modifiers.STATIC) != 0;
886                         }
887                 }
888
889                 #endregion
890         }
891
892         //
893         // Base member specification. A member specification contains
894         // member details which can alter in the context (e.g. generic instances)
895         //
896         public abstract class MemberSpec
897         {
898                 [Flags]
899                 public enum StateFlags
900                 {
901                         Obsolete_Undetected = 1,        // Obsolete attribute has not been detected yet
902                         Obsolete = 1 << 1,                      // Member has obsolete attribute
903                         CLSCompliant_Undetected = 1 << 2,       // CLSCompliant attribute has not been detected yet
904                         CLSCompliant = 1 << 3,          // Member is CLS Compliant
905                         MissingDependency_Undetected = 1 << 4,
906                         MissingDependency = 1 << 5,
907                         HasDynamicElement = 1 << 6,
908
909                         IsAccessor = 1 << 9,            // Method is an accessor
910                         IsGeneric = 1 << 10,            // Member contains type arguments
911
912                         PendingMetaInflate = 1 << 12,
913                         PendingMakeMethod = 1 << 13,
914                         PendingMemberCacheMembers = 1 << 14,
915                         PendingBaseTypeInflate = 1 << 15,
916                         InterfacesExpanded = 1 << 16,
917                         IsNotRealProperty = 1 << 17,
918                 }
919
920                 protected Modifiers modifiers;
921                 public StateFlags state;
922                 protected IMemberDefinition definition;
923                 public readonly MemberKind Kind;
924                 protected TypeSpec declaringType;
925
926 #if DEBUG
927                 static int counter;
928                 public int ID = counter++;
929 #endif
930
931                 protected MemberSpec (MemberKind kind, TypeSpec declaringType, IMemberDefinition definition, Modifiers modifiers)
932                 {
933                         this.Kind = kind;
934                         this.declaringType = declaringType;
935                         this.definition = definition;
936                         this.modifiers = modifiers;
937
938                         state = StateFlags.Obsolete_Undetected | StateFlags.CLSCompliant_Undetected | StateFlags.MissingDependency_Undetected;
939                 }
940
941                 #region Properties
942
943                 public virtual int Arity {
944                         get {
945                                 return 0;
946                         }
947                 }
948
949                 public TypeSpec DeclaringType {
950                         get {
951                                 return declaringType;
952                         }
953                         set {
954                                 declaringType = value;
955                         }
956                 }
957
958                 public IMemberDefinition MemberDefinition {
959                         get {
960                                 return definition;
961                         }
962                 }
963
964                 public Modifiers Modifiers {
965                         get {
966                                 return modifiers;
967                         }
968                         set {
969                                 modifiers = value;
970                         }
971                 }
972                 
973                 public virtual string Name {
974                         get {
975                                 return definition.Name;
976                         }
977                 }
978
979                 public bool IsAbstract {
980                         get { return (modifiers & Modifiers.ABSTRACT) != 0; }
981                 }
982
983                 public bool IsAccessor {
984                         get {
985                                 return (state & StateFlags.IsAccessor) != 0;
986                         }
987                         set {
988                                 state = value ? state | StateFlags.IsAccessor : state & ~StateFlags.IsAccessor;
989                         }
990                 }
991
992                 //
993                 // Return true when this member is a generic in C# terms
994                 // A nested non-generic type of generic type will return false
995                 //
996                 public bool IsGeneric {
997                         get {
998                                 return (state & StateFlags.IsGeneric) != 0;
999                         }
1000                         set {
1001                                 state = value ? state | StateFlags.IsGeneric : state & ~StateFlags.IsGeneric;
1002                         }
1003                 }
1004
1005                 public bool IsPrivate {
1006                         get { return (modifiers & Modifiers.PRIVATE) != 0; }
1007                 }
1008
1009                 public bool IsPublic {
1010                         get { return (modifiers & Modifiers.PUBLIC) != 0; }
1011                 }
1012
1013                 public bool IsStatic {
1014                         get { 
1015                                 return (modifiers & Modifiers.STATIC) != 0;
1016                         }
1017                 }
1018
1019                 #endregion
1020
1021                 public virtual ObsoleteAttribute GetAttributeObsolete ()
1022                 {
1023                         if ((state & (StateFlags.Obsolete | StateFlags.Obsolete_Undetected)) == 0)
1024                                 return null;
1025
1026                         state &= ~StateFlags.Obsolete_Undetected;
1027
1028                         var oa = definition.GetAttributeObsolete ();
1029                         if (oa != null)
1030                                 state |= StateFlags.Obsolete;
1031
1032                         return oa;
1033                 }
1034
1035                 //
1036                 // Returns a list of missing dependencies of this member. The list
1037                 // will contain types only but it can have numerous values for members
1038                 // like methods where both return type and all parameters are checked
1039                 //
1040                 public List<TypeSpec> GetMissingDependencies ()
1041                 {
1042                         if ((state & (StateFlags.MissingDependency | StateFlags.MissingDependency_Undetected)) == 0)
1043                                 return null;
1044
1045                         state &= ~StateFlags.MissingDependency_Undetected;
1046
1047                         var imported = definition as ImportedDefinition;
1048                         List<TypeSpec> missing;
1049                         if (imported != null) {
1050                                 missing = ResolveMissingDependencies ();
1051                         } else if (this is ElementTypeSpec) {
1052                                 missing = ((ElementTypeSpec) this).Element.GetMissingDependencies ();
1053                         } else {
1054                                 missing = null;
1055                         }
1056
1057                         if (missing != null) {
1058                                 state |= StateFlags.MissingDependency;
1059                         }
1060
1061                         return missing;
1062                 }
1063
1064                 public abstract List<TypeSpec> ResolveMissingDependencies ();
1065
1066                 protected virtual bool IsNotCLSCompliant (out bool attrValue)
1067                 {
1068                         var cls = MemberDefinition.CLSAttributeValue;
1069                         attrValue = cls ?? false;
1070                         return cls == false;
1071                 }
1072
1073                 public virtual string GetSignatureForError ()
1074                 {
1075                         var bf = MemberDefinition as Property.BackingField;
1076                         var name = bf == null ? Name : bf.OriginalName;
1077                         return DeclaringType.GetSignatureForError () + "." + name;
1078                 }
1079
1080                 public virtual MemberSpec InflateMember (TypeParameterInflator inflator)
1081                 {
1082                         var inflated = (MemberSpec) MemberwiseClone ();
1083                         inflated.declaringType = inflator.TypeInstance;
1084                         if (DeclaringType.IsGenericOrParentIsGeneric)
1085                                 inflated.state |= StateFlags.PendingMetaInflate;
1086 #if DEBUG
1087                         inflated.ID += 1000000;
1088 #endif
1089                         return inflated;
1090                 }
1091
1092                 //
1093                 // Is this member accessible from invocationType
1094                 //
1095                 public bool IsAccessible (TypeSpec invocationType)
1096                 {
1097                         var ma = Modifiers & Modifiers.AccessibilityMask;
1098                         if (ma == Modifiers.PUBLIC)
1099                                 return true;
1100
1101                         var parentType = /* this as TypeSpec ?? */ DeclaringType;
1102
1103                         // It's null for module context
1104                         if (invocationType == null)
1105                                 invocationType = InternalType.FakeInternalType;
1106                 
1107                         //
1108                         // If only accessible to the current class or children
1109                         //
1110                         if (ma == Modifiers.PRIVATE)
1111                                 return invocationType.MemberDefinition == parentType.MemberDefinition ||
1112                                         TypeManager.IsNestedChildOf (invocationType, parentType.MemberDefinition);
1113
1114                         if ((ma & Modifiers.INTERNAL) != 0) {
1115                                 bool b;
1116                                 var assembly = invocationType == InternalType.FakeInternalType ?
1117                                         RootContext.ToplevelTypes.DeclaringAssembly :
1118                                         invocationType.MemberDefinition.DeclaringAssembly;
1119
1120                                 if (parentType == null) {
1121                                         b = ((ITypeDefinition) MemberDefinition).IsInternalAsPublic (assembly);
1122                                 } else {
1123                                         b = DeclaringType.MemberDefinition.IsInternalAsPublic (assembly);
1124                                 }
1125
1126                                 if (b || ma == Modifiers.INTERNAL)
1127                                         return b;
1128                         }
1129
1130                         // PROTECTED
1131                         if (!TypeManager.IsNestedFamilyAccessible (invocationType, parentType))
1132                                 return false;
1133
1134                         return true;
1135                 }
1136
1137                 //
1138                 // Returns member CLS compliance based on full member hierarchy
1139                 //
1140                 public bool IsCLSCompliant ()
1141                 {
1142                         if ((state & StateFlags.CLSCompliant_Undetected) != 0) {
1143                                 state &= ~StateFlags.CLSCompliant_Undetected;
1144
1145                                 bool compliant;
1146                                 if (IsNotCLSCompliant (out compliant))
1147                                         return false;
1148
1149                                 if (!compliant) {
1150                                         if (DeclaringType != null) {
1151                                                 compliant = DeclaringType.IsCLSCompliant ();
1152                                         } else {
1153                                                 compliant = ((ITypeDefinition) MemberDefinition).DeclaringAssembly.IsCLSCompliant;
1154                                         }
1155                                 }
1156
1157                                 if (compliant)
1158                                         state |= StateFlags.CLSCompliant;
1159                         }
1160
1161                         return (state & StateFlags.CLSCompliant) != 0;
1162                 }
1163
1164                 public bool IsConditionallyExcluded (Location loc)
1165                 {
1166                         if ((Kind & (MemberKind.Class | MemberKind.Method)) == 0)
1167                                 return false;
1168
1169                         var conditions = MemberDefinition.ConditionalConditions ();
1170                         if (conditions == null)
1171                                 return false;
1172
1173                         foreach (var condition in conditions) {
1174                                 if (loc.CompilationUnit.IsConditionalDefined (condition))
1175                                         return false;
1176                         }
1177
1178                         return true;
1179                 }
1180
1181                 public override string ToString ()
1182                 {
1183                         return GetSignatureForError ();
1184                 }
1185         }
1186
1187         //
1188         // Member details which are same between all member
1189         // specifications
1190         //
1191         public interface IMemberDefinition
1192         {
1193                 bool? CLSAttributeValue { get; }
1194                 string Name { get; }
1195                 bool IsImported { get; }
1196
1197                 string[] ConditionalConditions ();
1198                 ObsoleteAttribute GetAttributeObsolete ();
1199                 void SetIsAssigned ();
1200                 void SetIsUsed ();
1201         }
1202
1203         public interface IParametersMember : IInterfaceMemberSpec
1204         {
1205                 AParametersCollection Parameters { get; }
1206         }
1207
1208         public interface IInterfaceMemberSpec
1209         {
1210                 TypeSpec MemberType { get; }
1211         }
1212
1213         //
1214         // Base type container declaration. It exists to handle partial types
1215         // which share same definition (PartialContainer) but have different
1216         // resolve scopes
1217         //
1218         public abstract class DeclSpace : MemberCore {
1219                 /// <summary>
1220                 ///   This points to the actual definition that is being
1221                 ///   created with System.Reflection.Emit
1222                 /// </summary>
1223                 public TypeBuilder TypeBuilder;
1224
1225                 //
1226                 // This is the namespace in which this typecontainer
1227                 // was declared.  We use this to resolve names.
1228                 //
1229                 public NamespaceEntry NamespaceEntry;
1230
1231                 public readonly string Basename;
1232                 
1233                 protected Dictionary<string, MemberCore> defined_names;
1234
1235                 public TypeContainer PartialContainer;          
1236
1237                 protected readonly bool is_generic;
1238                 readonly int count_type_params;
1239                 protected TypeParameter[] type_params;
1240                 TypeParameter[] type_param_list;
1241
1242                 //
1243                 // Whether we are Generic
1244                 //
1245                 public bool IsGeneric {
1246                         get {
1247                                 if (is_generic)
1248                                         return true;
1249                                 else if (Parent != null)
1250                                         return Parent.IsGeneric;
1251                                 else
1252                                         return false;
1253                         }
1254                 }
1255
1256                 static string[] attribute_targets = new string [] { "type" };
1257
1258                 public DeclSpace (NamespaceEntry ns, DeclSpace parent, MemberName name,
1259                                   Attributes attrs)
1260                         : base (parent, name, attrs)
1261                 {
1262                         NamespaceEntry = ns;
1263                         Basename = name.Basename;
1264                         defined_names = new Dictionary<string, MemberCore> ();
1265                         PartialContainer = null;
1266                         if (name.TypeArguments != null) {
1267                                 is_generic = true;
1268                                 count_type_params = name.TypeArguments.Count;
1269                         }
1270                         if (parent != null)
1271                                 count_type_params += parent.count_type_params;
1272                 }
1273
1274                 /// <summary>
1275                 /// Adds the member to defined_names table. It tests for duplications and enclosing name conflicts
1276                 /// </summary>
1277                 protected virtual bool AddToContainer (MemberCore symbol, string name)
1278                 {
1279                         MemberCore mc;
1280                         if (!defined_names.TryGetValue (name, out mc)) {
1281                                 defined_names.Add (name, symbol);
1282                                 return true;
1283                         }
1284
1285                         if (((mc.ModFlags | symbol.ModFlags) & Modifiers.COMPILER_GENERATED) != 0)
1286                                 return true;
1287
1288                         if (symbol.EnableOverloadChecks (mc))
1289                                 return true;
1290
1291                         InterfaceMemberBase im = mc as InterfaceMemberBase;
1292                         if (im != null && im.IsExplicitImpl)
1293                                 return true;
1294
1295                         Report.SymbolRelatedToPreviousError (mc);
1296                         if ((mc.ModFlags & Modifiers.PARTIAL) != 0 && (symbol is ClassOrStruct || symbol is Interface)) {
1297                                 Error_MissingPartialModifier (symbol);
1298                                 return false;
1299                         }
1300
1301                         if (this is ModuleContainer) {
1302                                 Report.Error (101, symbol.Location, 
1303                                         "The namespace `{0}' already contains a definition for `{1}'",
1304                                         ((DeclSpace)symbol).NamespaceEntry.GetSignatureForError (), symbol.MemberName.Name);
1305                         } else if (symbol is TypeParameter) {
1306                                 Report.Error (692, symbol.Location,
1307                                         "Duplicate type parameter `{0}'", symbol.GetSignatureForError ());
1308                         } else {
1309                                 Report.Error (102, symbol.Location,
1310                                               "The type `{0}' already contains a definition for `{1}'",
1311                                               GetSignatureForError (), symbol.MemberName.Name);
1312                         }
1313
1314                         return false;
1315                 }
1316
1317                 protected void RemoveFromContainer (string name)
1318                 {
1319                         defined_names.Remove (name);
1320                 }
1321                 
1322                 /// <summary>
1323                 ///   Returns the MemberCore associated with a given name in the declaration
1324                 ///   space. It doesn't return method based symbols !!
1325                 /// </summary>
1326                 /// 
1327                 public MemberCore GetDefinition (string name)
1328                 {
1329                         MemberCore mc = null;
1330                         defined_names.TryGetValue (name, out mc);
1331                         return mc;
1332                 }
1333         
1334                 // 
1335                 // root_types contains all the types.  All TopLevel types
1336                 // hence have a parent that points to `root_types', that is
1337                 // why there is a non-obvious test down here.
1338                 //
1339                 public bool IsTopLevel {
1340                         get { return (Parent != null && Parent.Parent == null); }
1341                 }
1342
1343                 public virtual bool IsUnmanagedType ()
1344                 {
1345                         return false;
1346                 }
1347
1348                 protected abstract TypeAttributes TypeAttr { get; }
1349
1350                 /// <remarks>
1351                 ///  Should be overriten by the appropriate declaration space
1352                 /// </remarks>
1353                 public abstract void DefineType ();
1354
1355                 protected void Error_MissingPartialModifier (MemberCore type)
1356                 {
1357                         Report.Error (260, type.Location,
1358                                 "Missing partial modifier on declaration of type `{0}'. Another partial declaration of this type exists",
1359                                 type.GetSignatureForError ());
1360                 }
1361
1362                 public override string GetSignatureForError ()
1363                 {
1364                         return MemberName.GetSignatureForError ();
1365                 }
1366                 
1367                 TypeParameter[] initialize_type_params ()
1368                 {
1369                         if (type_param_list != null)
1370                                 return type_param_list;
1371
1372                         DeclSpace the_parent = Parent;
1373                         if (this is GenericMethod)
1374                                 the_parent = null;
1375
1376                         var list = new List<TypeParameter> ();
1377                         if (the_parent != null && the_parent.IsGeneric) {
1378                                 // FIXME: move generics info out of DeclSpace
1379                                 TypeParameter[] parent_params = the_parent.TypeParameters;
1380                                 list.AddRange (parent_params);
1381                         }
1382  
1383                         int count = type_params != null ? type_params.Length : 0;
1384                         for (int i = 0; i < count; i++) {
1385                                 TypeParameter param = type_params [i];
1386                                 list.Add (param);
1387                                 if (Parent.CurrentTypeParameters != null) {
1388                                         foreach (TypeParameter tp in Parent.CurrentTypeParameters) {
1389                                                 if (tp.Name != param.Name)                              
1390                                                         continue;
1391
1392                                                 Report.SymbolRelatedToPreviousError (tp.Location, null);
1393                                                 Report.Warning (693, 3, param.Location,
1394                                                         "Type parameter `{0}' has the same name as the type parameter from outer type `{1}'",
1395                                                         param.Name, Parent.GetSignatureForError ());
1396                                         }
1397                                 }
1398                         }
1399
1400                         type_param_list = new TypeParameter [list.Count];
1401                         list.CopyTo (type_param_list, 0);
1402                         return type_param_list;
1403                 }
1404
1405                 public virtual void SetParameterInfo (List<Constraints> constraints_list)
1406                 {
1407                         if (!is_generic) {
1408                                 if (constraints_list != null) {
1409                                         Report.Error (
1410                                                 80, Location, "Constraints are not allowed " +
1411                                                 "on non-generic declarations");
1412                                 }
1413
1414                                 return;
1415                         }
1416
1417                         TypeParameterName[] names = MemberName.TypeArguments.GetDeclarations ();
1418                         type_params = new TypeParameter [names.Length];
1419
1420                         //
1421                         // Register all the names
1422                         //
1423                         for (int i = 0; i < type_params.Length; i++) {
1424                                 TypeParameterName name = names [i];
1425
1426                                 Constraints constraints = null;
1427                                 if (constraints_list != null) {
1428                                         int total = constraints_list.Count;
1429                                         for (int ii = 0; ii < total; ++ii) {
1430                                                 Constraints constraints_at = (Constraints)constraints_list[ii];
1431                                                 // TODO: it is used by iterators only
1432                                                 if (constraints_at == null) {
1433                                                         constraints_list.RemoveAt (ii);
1434                                                         --total;
1435                                                         continue;
1436                                                 }
1437                                                 if (constraints_at.TypeParameter.Value == name.Name) {
1438                                                         constraints = constraints_at;
1439                                                         constraints_list.RemoveAt(ii);
1440                                                         break;
1441                                                 }
1442                                         }
1443                                 }
1444
1445                                 Variance variance = name.Variance;
1446                                 if (name.Variance != Variance.None && !(this is Delegate || this is Interface)) {
1447                                         Report.Error (1960, name.Location, "Variant type parameters can only be used with interfaces and delegates");
1448                                         variance = Variance.None;
1449                                 }
1450
1451                                 type_params [i] = new TypeParameter (
1452                                         Parent, i, new MemberName (name.Name, Location), constraints, name.OptAttributes, variance);
1453
1454                                 AddToContainer (type_params [i], name.Name);
1455                         }
1456
1457                         if (constraints_list != null && constraints_list.Count > 0) {
1458                                 foreach (Constraints constraint in constraints_list) {
1459                                         Report.Error(699, constraint.Location, "`{0}': A constraint references nonexistent type parameter `{1}'", 
1460                                                 GetSignatureForError (), constraint.TypeParameter.Value);
1461                                 }
1462                         }
1463                 }
1464
1465                 protected TypeParameter[] TypeParameters {
1466                         get {
1467                                 if (!IsGeneric)
1468                                         throw new InvalidOperationException ();
1469                                 if ((PartialContainer != null) && (PartialContainer != this))
1470                                         return PartialContainer.TypeParameters;
1471                                 if (type_param_list == null)
1472                                         initialize_type_params ();
1473
1474                                 return type_param_list;
1475                         }
1476                 }
1477
1478                 public int CountTypeParameters {
1479                         get {
1480                                 return count_type_params;
1481                         }
1482                 }
1483
1484                 public override string[] ValidAttributeTargets {
1485                         get { return attribute_targets; }
1486                 }
1487
1488                 protected override bool VerifyClsCompliance ()
1489                 {
1490                         if (!base.VerifyClsCompliance ()) {
1491                                 return false;
1492                         }
1493
1494                         if (type_params != null) {
1495                                 foreach (TypeParameter tp in type_params) {
1496                                         tp.VerifyClsCompliance ();
1497                                 }
1498                         }
1499
1500                         return true;
1501                 }
1502         }
1503 }