Implement XamlNodeQueue, and add couple of missing files.
[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 (RootContext.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 (!RootContext.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 IsNotCLSCompliant ()
707                 {
708                         if ((caching_flags & Flags.HasCompliantAttribute_Undetected) == 0)
709                                 return (caching_flags & Flags.ClsCompliantAttributeFalse) != 0;
710
711                         caching_flags &= ~Flags.HasCompliantAttribute_Undetected;
712
713                         if (OptAttributes != null) {
714                                 Attribute cls_attribute = OptAttributes.Search (Module.PredefinedAttributes.CLSCompliant);
715                                 if (cls_attribute != null) {
716                                         caching_flags |= Flags.HasClsCompliantAttribute;
717                                         if (cls_attribute.GetClsCompliantAttributeValue ())
718                                                 return false;
719
720                                         caching_flags |= Flags.ClsCompliantAttributeFalse;
721                                         return true;
722                                 }
723                         }
724
725                         return false;
726                 }
727
728                 /// <summary>
729                 /// Returns true if MemberCore is explicitly marked with CLSCompliantAttribute
730                 /// </summary>
731                 protected bool HasClsCompliantAttribute {
732                         get {
733                                 if ((caching_flags & Flags.HasCompliantAttribute_Undetected) != 0)
734                                         IsNotCLSCompliant ();
735                                 
736                                 return (caching_flags & Flags.HasClsCompliantAttribute) != 0;
737                         }
738                 }
739
740                 /// <summary>
741                 /// Returns true when a member supports multiple overloads (methods, indexers, etc)
742                 /// </summary>
743                 public virtual bool EnableOverloadChecks (MemberCore overload)
744                 {
745                         return false;
746                 }
747
748                 /// <summary>
749                 /// The main virtual method for CLS-Compliant verifications.
750                 /// The method returns true if member is CLS-Compliant and false if member is not
751                 /// CLS-Compliant which means that CLS-Compliant tests are not necessary. A descendants override it
752                 /// and add their extra verifications.
753                 /// </summary>
754                 protected virtual bool VerifyClsCompliance ()
755                 {
756                         if (HasClsCompliantAttribute) {
757                                 if (!Module.DeclaringAssembly.HasCLSCompliantAttribute) {
758                                         Attribute a = OptAttributes.Search (Module.PredefinedAttributes.CLSCompliant);
759                                         if ((caching_flags & Flags.ClsCompliantAttributeFalse) != 0) {
760                                                 Report.Warning (3021, 2, a.Location,
761                                                         "`{0}' does not need a CLSCompliant attribute because the assembly is not marked as CLS-compliant",
762                                                         GetSignatureForError ());
763                                         } else {
764                                                 Report.Warning (3014, 1, a.Location,
765                                                         "`{0}' cannot be marked as CLS-compliant because the assembly is not marked as CLS-compliant",
766                                                         GetSignatureForError ());
767                                         }
768                                         return false;
769                                 }
770
771                                 if (!IsExposedFromAssembly ()) {
772                                         Attribute a = OptAttributes.Search (Module.PredefinedAttributes.CLSCompliant);
773                                         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 ());
774                                         return false;
775                                 }
776
777                                 if ((caching_flags & Flags.ClsCompliantAttributeFalse) != 0) {
778                                         if (Parent.Kind == MemberKind.Interface && Parent.IsClsComplianceRequired ()) {
779                                                 Report.Warning (3010, 1, Location, "`{0}': CLS-compliant interfaces must have only CLS-compliant members", GetSignatureForError ());
780                                         } else if (Parent.Kind == MemberKind.Class && (ModFlags & Modifiers.ABSTRACT) != 0 && Parent.IsClsComplianceRequired ()) {
781                                                 Report.Warning (3011, 1, Location, "`{0}': only CLS-compliant members can be abstract", GetSignatureForError ());
782                                         }
783
784                                         return false;
785                                 }
786
787                                 if (Parent.Parent != null && !Parent.IsClsComplianceRequired ()) {
788                                         Attribute a = OptAttributes.Search (Module.PredefinedAttributes.CLSCompliant);
789                                         Report.Warning (3018, 1, a.Location, "`{0}' cannot be marked as CLS-compliant because it is a member of non CLS-compliant type `{1}'",
790                                                 GetSignatureForError (), Parent.GetSignatureForError ());
791                                         return false;
792                                 }
793                         } else {
794                                 if (!IsExposedFromAssembly ())
795                                         return false;
796
797                                 if (!Parent.PartialContainer.IsClsComplianceRequired ())
798                                         return false;
799                         }
800
801                         if (member_name.Name [0] == '_') {
802                                 Report.Warning (3008, 1, Location, "Identifier `{0}' is not CLS-compliant", GetSignatureForError () );
803                         }
804
805                         return true;
806                 }
807
808                 //
809                 // Raised (and passed an XmlElement that contains the comment)
810                 // when GenerateDocComment is writing documentation expectedly.
811                 //
812                 internal virtual void OnGenerateDocComment (XmlElement intermediateNode)
813                 {
814                 }
815
816                 //
817                 // Returns a string that represents the signature for this 
818                 // member which should be used in XML documentation.
819                 //
820                 public virtual string GetDocCommentName (DeclSpace ds)
821                 {
822                         if (ds == null || this is DeclSpace)
823                                 return DocCommentHeader + Name;
824                         else
825                                 return String.Concat (DocCommentHeader, ds.Name, ".", Name);
826                 }
827
828                 //
829                 // Generates xml doc comments (if any), and if required,
830                 // handle warning report.
831                 //
832                 internal virtual void GenerateDocComment (DeclSpace ds)
833                 {
834                         try {
835                                 DocUtil.GenerateDocComment (this, ds, Report);
836                         } catch (Exception e) {
837                                 throw new InternalErrorException (this, e);
838                         }
839                 }
840
841                 #region IMemberContext Members
842
843                 public virtual CompilerContext Compiler {
844                         get { return Parent.Compiler; }
845                 }
846
847                 public virtual TypeSpec CurrentType {
848                         get { return Parent.CurrentType; }
849                 }
850
851                 public MemberCore CurrentMemberDefinition {
852                         get { return this; }
853                 }
854
855                 public virtual TypeParameter[] CurrentTypeParameters {
856                         get { return null; }
857                 }
858
859                 public virtual bool HasUnresolvedConstraints {
860                         get { return false; }
861                 }
862
863                 public bool IsObsolete {
864                         get {
865                                 if (GetAttributeObsolete () != null)
866                                         return true;
867
868                                 return Parent == null ? false : Parent.IsObsolete;
869                         }
870                 }
871
872                 public bool IsUnsafe {
873                         get {
874                                 if ((ModFlags & Modifiers.UNSAFE) != 0)
875                                         return true;
876
877                                 return Parent == null ? false : Parent.IsUnsafe;
878                         }
879                 }
880
881                 public bool IsStatic {
882                         get {
883                                 return (ModFlags & Modifiers.STATIC) != 0;
884                         }
885                 }
886
887                 #endregion
888         }
889
890         //
891         // Base member specification. A member specification contains
892         // member details which can alter in the context (e.g. generic instances)
893         //
894         public abstract class MemberSpec
895         {
896                 [Flags]
897                 public enum StateFlags
898                 {
899                         Obsolete_Undetected = 1,        // Obsolete attribute has not been detected yet
900                         Obsolete = 1 << 1,                      // Member has obsolete attribute
901                         CLSCompliant_Undetected = 1 << 2,       // CLSCompliant attribute has not been detected yet
902                         CLSCompliant = 1 << 3,          // Member is CLS Compliant
903                         MissingDependency_Undetected = 1 << 4,
904                         MissingDependency = 1 << 5,
905                         HasDynamicElement = 1 << 6,
906
907                         IsAccessor = 1 << 9,            // Method is an accessor
908                         IsGeneric = 1 << 10,            // Member contains type arguments
909
910                         PendingMetaInflate = 1 << 12,
911                         PendingMakeMethod = 1 << 13,
912                         PendingMemberCacheMembers = 1 << 14,
913                         PendingBaseTypeInflate = 1 << 15,
914                         InterfacesExpanded = 1 << 16,
915                         IsNotRealProperty = 1 << 17,
916                 }
917
918                 protected Modifiers modifiers;
919                 public StateFlags state;
920                 protected IMemberDefinition definition;
921                 public readonly MemberKind Kind;
922                 protected TypeSpec declaringType;
923
924 #if DEBUG
925                 static int counter;
926                 public int ID = counter++;
927 #endif
928
929                 protected MemberSpec (MemberKind kind, TypeSpec declaringType, IMemberDefinition definition, Modifiers modifiers)
930                 {
931                         this.Kind = kind;
932                         this.declaringType = declaringType;
933                         this.definition = definition;
934                         this.modifiers = modifiers;
935
936                         state = StateFlags.Obsolete_Undetected | StateFlags.CLSCompliant_Undetected | StateFlags.MissingDependency_Undetected;
937                 }
938
939                 #region Properties
940
941                 public virtual int Arity {
942                         get {
943                                 return 0;
944                         }
945                 }
946
947                 public TypeSpec DeclaringType {
948                         get {
949                                 return declaringType;
950                         }
951                         set {
952                                 declaringType = value;
953                         }
954                 }
955
956                 public IMemberDefinition MemberDefinition {
957                         get {
958                                 return definition;
959                         }
960                 }
961
962                 public Modifiers Modifiers {
963                         get {
964                                 return modifiers;
965                         }
966                         set {
967                                 modifiers = value;
968                         }
969                 }
970                 
971                 public virtual string Name {
972                         get {
973                                 return definition.Name;
974                         }
975                 }
976
977                 public bool IsAbstract {
978                         get { return (modifiers & Modifiers.ABSTRACT) != 0; }
979                 }
980
981                 public bool IsAccessor {
982                         get {
983                                 return (state & StateFlags.IsAccessor) != 0;
984                         }
985                         set {
986                                 state = value ? state | StateFlags.IsAccessor : state & ~StateFlags.IsAccessor;
987                         }
988                 }
989
990                 //
991                 // Return true when this member is a generic in C# terms
992                 // A nested non-generic type of generic type will return false
993                 //
994                 public bool IsGeneric {
995                         get {
996                                 return (state & StateFlags.IsGeneric) != 0;
997                         }
998                         set {
999                                 state = value ? state | StateFlags.IsGeneric : state & ~StateFlags.IsGeneric;
1000                         }
1001                 }
1002
1003                 public bool IsPrivate {
1004                         get { return (modifiers & Modifiers.PRIVATE) != 0; }
1005                 }
1006
1007                 public bool IsPublic {
1008                         get { return (modifiers & Modifiers.PUBLIC) != 0; }
1009                 }
1010
1011                 public bool IsStatic {
1012                         get { 
1013                                 return (modifiers & Modifiers.STATIC) != 0;
1014                         }
1015                 }
1016
1017                 #endregion
1018
1019                 public virtual ObsoleteAttribute GetAttributeObsolete ()
1020                 {
1021                         if ((state & (StateFlags.Obsolete | StateFlags.Obsolete_Undetected)) == 0)
1022                                 return null;
1023
1024                         state &= ~StateFlags.Obsolete_Undetected;
1025
1026                         var oa = definition.GetAttributeObsolete ();
1027                         if (oa != null)
1028                                 state |= StateFlags.Obsolete;
1029
1030                         return oa;
1031                 }
1032
1033                 //
1034                 // Returns a list of missing dependencies of this member. The list
1035                 // will contain types only but it can have numerous values for members
1036                 // like methods where both return type and all parameters are checked
1037                 //
1038                 public List<MissingType> GetMissingDependencies ()
1039                 {
1040                         if ((state & (StateFlags.MissingDependency | StateFlags.MissingDependency_Undetected)) == 0)
1041                                 return null;
1042
1043                         state &= ~StateFlags.MissingDependency_Undetected;
1044
1045                         var imported = definition as ImportedDefinition;
1046                         List<MissingType> missing;
1047                         if (imported != null) {
1048                                 missing = imported.ResolveMissingDependencies ();
1049                         } else if (this is ElementTypeSpec) {
1050                                 missing = ((ElementTypeSpec) this).Element.GetMissingDependencies ();
1051                         } else {
1052                                 missing = null;
1053                         }
1054
1055                         if (missing != null) {
1056                                 state |= StateFlags.MissingDependency;
1057                         }
1058
1059                         return missing;
1060                 }
1061
1062                 protected virtual bool IsNotCLSCompliant ()
1063                 {
1064                         return MemberDefinition.IsNotCLSCompliant ();
1065                 }
1066
1067                 public virtual string GetSignatureForError ()
1068                 {
1069                         var bf = MemberDefinition as Property.BackingField;
1070                         var name = bf == null ? Name : bf.OriginalName;
1071                         return DeclaringType.GetSignatureForError () + "." + name;
1072                 }
1073
1074                 public virtual MemberSpec InflateMember (TypeParameterInflator inflator)
1075                 {
1076                         var inflated = (MemberSpec) MemberwiseClone ();
1077                         inflated.declaringType = inflator.TypeInstance;
1078                         if (DeclaringType.IsGenericOrParentIsGeneric)
1079                                 inflated.state |= StateFlags.PendingMetaInflate;
1080 #if DEBUG
1081                         inflated.ID += 1000000;
1082 #endif
1083                         return inflated;
1084                 }
1085
1086                 //
1087                 // Is this member accessible from invocationType
1088                 //
1089                 public bool IsAccessible (TypeSpec invocationType)
1090                 {
1091                         var ma = Modifiers & Modifiers.AccessibilityMask;
1092                         if (ma == Modifiers.PUBLIC)
1093                                 return true;
1094
1095                         var parentType = /* this as TypeSpec ?? */ DeclaringType;
1096
1097                         // It's null for module context
1098                         if (invocationType == null)
1099                                 invocationType = InternalType.FakeInternalType;
1100                 
1101                         //
1102                         // If only accessible to the current class or children
1103                         //
1104                         if (ma == Modifiers.PRIVATE)
1105                                 return invocationType.MemberDefinition == parentType.MemberDefinition ||
1106                                         TypeManager.IsNestedChildOf (invocationType, parentType.MemberDefinition);
1107
1108                         if ((ma & Modifiers.INTERNAL) != 0) {
1109                                 bool b;
1110                                 var assembly = invocationType == InternalType.FakeInternalType ?
1111                                         RootContext.ToplevelTypes.DeclaringAssembly :
1112                                         invocationType.MemberDefinition.DeclaringAssembly;
1113
1114                                 if (parentType == null) {
1115                                         b = ((ITypeDefinition) MemberDefinition).IsInternalAsPublic (assembly);
1116                                 } else {
1117                                         b = DeclaringType.MemberDefinition.IsInternalAsPublic (assembly);
1118                                 }
1119
1120                                 if (b || ma == Modifiers.INTERNAL)
1121                                         return b;
1122                         }
1123
1124                         // PROTECTED
1125                         if (!TypeManager.IsNestedFamilyAccessible (invocationType, parentType))
1126                                 return false;
1127
1128                         return true;
1129                 }
1130
1131                 //
1132                 // Returns member CLS compliance based on full member hierarchy
1133                 //
1134                 public bool IsCLSCompliant ()
1135                 {
1136                         if ((state & StateFlags.CLSCompliant_Undetected) != 0) {
1137                                 state &= ~StateFlags.CLSCompliant_Undetected;
1138
1139                                 if (IsNotCLSCompliant ())
1140                                         return false;
1141
1142                                 bool compliant;
1143                                 if (DeclaringType != null) {
1144                                         compliant = DeclaringType.IsCLSCompliant ();
1145                                 } else {
1146                                         compliant = ((ITypeDefinition) MemberDefinition).DeclaringAssembly.IsCLSCompliant;
1147                                 }
1148
1149                                 if (compliant)
1150                                         state |= StateFlags.CLSCompliant;
1151                         }
1152
1153                         return (state & StateFlags.CLSCompliant) != 0;
1154                 }
1155
1156                 public bool IsConditionallyExcluded (Location loc)
1157                 {
1158                         if ((Kind & (MemberKind.Class | MemberKind.Method)) == 0)
1159                                 return false;
1160
1161                         var conditions = MemberDefinition.ConditionalConditions ();
1162                         if (conditions == null)
1163                                 return false;
1164
1165                         foreach (var condition in conditions) {
1166                                 if (loc.CompilationUnit.IsConditionalDefined (condition))
1167                                         return false;
1168                         }
1169
1170                         return true;
1171                 }
1172
1173                 public override string ToString ()
1174                 {
1175                         return GetSignatureForError ();
1176                 }
1177         }
1178
1179         //
1180         // Member details which are same between all member
1181         // specifications
1182         //
1183         public interface IMemberDefinition
1184         {
1185                 string Name { get; }
1186                 bool IsImported { get; }
1187
1188                 string[] ConditionalConditions ();
1189                 ObsoleteAttribute GetAttributeObsolete ();
1190                 bool IsNotCLSCompliant ();
1191                 void SetIsAssigned ();
1192                 void SetIsUsed ();
1193         }
1194
1195         public interface IParametersMember : IInterfaceMemberSpec
1196         {
1197                 AParametersCollection Parameters { get; }
1198         }
1199
1200         public interface IInterfaceMemberSpec
1201         {
1202                 TypeSpec MemberType { get; }
1203         }
1204
1205         //
1206         // Base type container declaration. It exists to handle partial types
1207         // which share same definition (PartialContainer) but have different
1208         // resolve scopes
1209         //
1210         public abstract class DeclSpace : MemberCore {
1211                 /// <summary>
1212                 ///   This points to the actual definition that is being
1213                 ///   created with System.Reflection.Emit
1214                 /// </summary>
1215                 public TypeBuilder TypeBuilder;
1216
1217                 //
1218                 // This is the namespace in which this typecontainer
1219                 // was declared.  We use this to resolve names.
1220                 //
1221                 public NamespaceEntry NamespaceEntry;
1222
1223                 public readonly string Basename;
1224                 
1225                 protected Dictionary<string, MemberCore> defined_names;
1226
1227                 public TypeContainer PartialContainer;          
1228
1229                 protected readonly bool is_generic;
1230                 readonly int count_type_params;
1231                 protected TypeParameter[] type_params;
1232                 TypeParameter[] type_param_list;
1233
1234                 //
1235                 // Whether we are Generic
1236                 //
1237                 public bool IsGeneric {
1238                         get {
1239                                 if (is_generic)
1240                                         return true;
1241                                 else if (Parent != null)
1242                                         return Parent.IsGeneric;
1243                                 else
1244                                         return false;
1245                         }
1246                 }
1247
1248                 static string[] attribute_targets = new string [] { "type" };
1249
1250                 public DeclSpace (NamespaceEntry ns, DeclSpace parent, MemberName name,
1251                                   Attributes attrs)
1252                         : base (parent, name, attrs)
1253                 {
1254                         NamespaceEntry = ns;
1255                         Basename = name.Basename;
1256                         defined_names = new Dictionary<string, MemberCore> ();
1257                         PartialContainer = null;
1258                         if (name.TypeArguments != null) {
1259                                 is_generic = true;
1260                                 count_type_params = name.TypeArguments.Count;
1261                         }
1262                         if (parent != null)
1263                                 count_type_params += parent.count_type_params;
1264                 }
1265
1266                 /// <summary>
1267                 /// Adds the member to defined_names table. It tests for duplications and enclosing name conflicts
1268                 /// </summary>
1269                 protected virtual bool AddToContainer (MemberCore symbol, string name)
1270                 {
1271                         MemberCore mc;
1272                         if (!defined_names.TryGetValue (name, out mc)) {
1273                                 defined_names.Add (name, symbol);
1274                                 return true;
1275                         }
1276
1277                         if (((mc.ModFlags | symbol.ModFlags) & Modifiers.COMPILER_GENERATED) != 0)
1278                                 return true;
1279
1280                         if (symbol.EnableOverloadChecks (mc))
1281                                 return true;
1282
1283                         InterfaceMemberBase im = mc as InterfaceMemberBase;
1284                         if (im != null && im.IsExplicitImpl)
1285                                 return true;
1286
1287                         Report.SymbolRelatedToPreviousError (mc);
1288                         if ((mc.ModFlags & Modifiers.PARTIAL) != 0 && (symbol is ClassOrStruct || symbol is Interface)) {
1289                                 Error_MissingPartialModifier (symbol);
1290                                 return false;
1291                         }
1292
1293                         if (this is ModuleContainer) {
1294                                 Report.Error (101, symbol.Location, 
1295                                         "The namespace `{0}' already contains a definition for `{1}'",
1296                                         ((DeclSpace)symbol).NamespaceEntry.GetSignatureForError (), symbol.MemberName.Name);
1297                         } else if (symbol is TypeParameter) {
1298                                 Report.Error (692, symbol.Location,
1299                                         "Duplicate type parameter `{0}'", symbol.GetSignatureForError ());
1300                         } else {
1301                                 Report.Error (102, symbol.Location,
1302                                               "The type `{0}' already contains a definition for `{1}'",
1303                                               GetSignatureForError (), symbol.MemberName.Name);
1304                         }
1305
1306                         return false;
1307                 }
1308
1309                 protected void RemoveFromContainer (string name)
1310                 {
1311                         defined_names.Remove (name);
1312                 }
1313                 
1314                 /// <summary>
1315                 ///   Returns the MemberCore associated with a given name in the declaration
1316                 ///   space. It doesn't return method based symbols !!
1317                 /// </summary>
1318                 /// 
1319                 public MemberCore GetDefinition (string name)
1320                 {
1321                         MemberCore mc = null;
1322                         defined_names.TryGetValue (name, out mc);
1323                         return mc;
1324                 }
1325         
1326                 // 
1327                 // root_types contains all the types.  All TopLevel types
1328                 // hence have a parent that points to `root_types', that is
1329                 // why there is a non-obvious test down here.
1330                 //
1331                 public bool IsTopLevel {
1332                         get { return (Parent != null && Parent.Parent == null); }
1333                 }
1334
1335                 public virtual bool IsUnmanagedType ()
1336                 {
1337                         return false;
1338                 }
1339
1340                 protected virtual TypeAttributes TypeAttr {
1341                         get { return Module.DefaultCharSetType; }
1342                 }
1343
1344                 /// <remarks>
1345                 ///  Should be overriten by the appropriate declaration space
1346                 /// </remarks>
1347                 public abstract void DefineType ();
1348
1349                 protected void Error_MissingPartialModifier (MemberCore type)
1350                 {
1351                         Report.Error (260, type.Location,
1352                                 "Missing partial modifier on declaration of type `{0}'. Another partial declaration of this type exists",
1353                                 type.GetSignatureForError ());
1354                 }
1355
1356                 public override string GetSignatureForError ()
1357                 {
1358                         return MemberName.GetSignatureForError ();
1359                 }
1360                 
1361                 TypeParameter[] initialize_type_params ()
1362                 {
1363                         if (type_param_list != null)
1364                                 return type_param_list;
1365
1366                         DeclSpace the_parent = Parent;
1367                         if (this is GenericMethod)
1368                                 the_parent = null;
1369
1370                         var list = new List<TypeParameter> ();
1371                         if (the_parent != null && the_parent.IsGeneric) {
1372                                 // FIXME: move generics info out of DeclSpace
1373                                 TypeParameter[] parent_params = the_parent.TypeParameters;
1374                                 list.AddRange (parent_params);
1375                         }
1376  
1377                         int count = type_params != null ? type_params.Length : 0;
1378                         for (int i = 0; i < count; i++) {
1379                                 TypeParameter param = type_params [i];
1380                                 list.Add (param);
1381                                 if (Parent.CurrentTypeParameters != null) {
1382                                         foreach (TypeParameter tp in Parent.CurrentTypeParameters) {
1383                                                 if (tp.Name != param.Name)                              
1384                                                         continue;
1385
1386                                                 Report.SymbolRelatedToPreviousError (tp.Location, null);
1387                                                 Report.Warning (693, 3, param.Location,
1388                                                         "Type parameter `{0}' has the same name as the type parameter from outer type `{1}'",
1389                                                         param.Name, Parent.GetSignatureForError ());
1390                                         }
1391                                 }
1392                         }
1393
1394                         type_param_list = new TypeParameter [list.Count];
1395                         list.CopyTo (type_param_list, 0);
1396                         return type_param_list;
1397                 }
1398
1399                 public virtual void SetParameterInfo (List<Constraints> constraints_list)
1400                 {
1401                         if (!is_generic) {
1402                                 if (constraints_list != null) {
1403                                         Report.Error (
1404                                                 80, Location, "Constraints are not allowed " +
1405                                                 "on non-generic declarations");
1406                                 }
1407
1408                                 return;
1409                         }
1410
1411                         TypeParameterName[] names = MemberName.TypeArguments.GetDeclarations ();
1412                         type_params = new TypeParameter [names.Length];
1413
1414                         //
1415                         // Register all the names
1416                         //
1417                         for (int i = 0; i < type_params.Length; i++) {
1418                                 TypeParameterName name = names [i];
1419
1420                                 Constraints constraints = null;
1421                                 if (constraints_list != null) {
1422                                         int total = constraints_list.Count;
1423                                         for (int ii = 0; ii < total; ++ii) {
1424                                                 Constraints constraints_at = (Constraints)constraints_list[ii];
1425                                                 // TODO: it is used by iterators only
1426                                                 if (constraints_at == null) {
1427                                                         constraints_list.RemoveAt (ii);
1428                                                         --total;
1429                                                         continue;
1430                                                 }
1431                                                 if (constraints_at.TypeParameter.Value == name.Name) {
1432                                                         constraints = constraints_at;
1433                                                         constraints_list.RemoveAt(ii);
1434                                                         break;
1435                                                 }
1436                                         }
1437                                 }
1438
1439                                 Variance variance = name.Variance;
1440                                 if (name.Variance != Variance.None && !(this is Delegate || this is Interface)) {
1441                                         Report.Error (1960, name.Location, "Variant type parameters can only be used with interfaces and delegates");
1442                                         variance = Variance.None;
1443                                 }
1444
1445                                 type_params [i] = new TypeParameter (
1446                                         Parent, i, new MemberName (name.Name, Location), constraints, name.OptAttributes, variance);
1447
1448                                 AddToContainer (type_params [i], name.Name);
1449                         }
1450
1451                         if (constraints_list != null && constraints_list.Count > 0) {
1452                                 foreach (Constraints constraint in constraints_list) {
1453                                         Report.Error(699, constraint.Location, "`{0}': A constraint references nonexistent type parameter `{1}'", 
1454                                                 GetSignatureForError (), constraint.TypeParameter.Value);
1455                                 }
1456                         }
1457                 }
1458
1459                 protected TypeParameter[] TypeParameters {
1460                         get {
1461                                 if (!IsGeneric)
1462                                         throw new InvalidOperationException ();
1463                                 if ((PartialContainer != null) && (PartialContainer != this))
1464                                         return PartialContainer.TypeParameters;
1465                                 if (type_param_list == null)
1466                                         initialize_type_params ();
1467
1468                                 return type_param_list;
1469                         }
1470                 }
1471
1472                 public int CountTypeParameters {
1473                         get {
1474                                 return count_type_params;
1475                         }
1476                 }
1477
1478                 public override string[] ValidAttributeTargets {
1479                         get { return attribute_targets; }
1480                 }
1481
1482                 protected override bool VerifyClsCompliance ()
1483                 {
1484                         if (!base.VerifyClsCompliance ()) {
1485                                 return false;
1486                         }
1487
1488                         if (type_params != null) {
1489                                 foreach (TypeParameter tp in type_params) {
1490                                         tp.VerifyClsCompliance ();
1491                                 }
1492                         }
1493
1494                         return true;
1495                 }
1496         }
1497 }