[bcl] Add .NET 4.7 reference assemblies (#4791)
[mono.git] / mcs / mcs / typespec.cs
index 2657956a2f540821f0d0b6332483790ef391a7ef..696bde556c820ad00f9d206bac897e80c10ee470 100644 (file)
@@ -109,7 +109,6 @@ namespace Mono.CSharp
                                        var imported = MemberDefinition as ImportedTypeDefinition;
                                        if (imported != null && Kind != MemberKind.MissingType)
                                                imported.DefineInterfaces (this);
-
                                }
 
                                return ifaces;
@@ -211,7 +210,7 @@ namespace Mono.CSharp
                //
                // Returns true for instances of IList<T>, IEnumerable<T>, ICollection<T>
                //
-               public virtual bool IsGenericIterateInterface {
+               public virtual bool IsArrayGenericInterface {
                        get {
                                return false;
                        }
@@ -295,6 +294,12 @@ namespace Mono.CSharp
                        }
                }
 
+               public bool IsStructOrEnum {
+                       get {
+                               return (Kind & (MemberKind.Struct | MemberKind.Enum)) != 0;
+                       }
+               }
+
                public bool IsTypeBuilder {
                        get {
 #if STATIC
@@ -321,6 +326,9 @@ namespace Mono.CSharp
                                if (Kind == MemberKind.Void)
                                        return true;
 
+                               if (Kind == MemberKind.TypeParameter)
+                                       return false;
+
                                if (IsNested && DeclaringType.IsGenericOrParentIsGeneric)
                                        return false;
 
@@ -375,7 +383,7 @@ namespace Mono.CSharp
                                throw new InternalErrorException ("Modifying expanded interface list");
 
                        if (ifaces == null) {
-                               ifaces = new List<TypeSpec> () { iface };
+                               ifaces = new List<TypeSpec> { iface };
                                return true;
                        }
 
@@ -481,17 +489,22 @@ namespace Mono.CSharp
                //
                // Text representation of type used by documentation writer
                //
-               public override string GetSignatureForDocumentation ()
+               public sealed override string GetSignatureForDocumentation ()
+               {
+                       return GetSignatureForDocumentation (false);
+               }
+
+               public virtual string GetSignatureForDocumentation (bool explicitName)
                {
                        StringBuilder sb = new StringBuilder ();
                        if (IsNested) {
-                               sb.Append (DeclaringType.GetSignatureForDocumentation ());
-                       } else {
-                               sb.Append (MemberDefinition.Namespace);
+                               sb.Append (DeclaringType.GetSignatureForDocumentation (explicitName));
+                       } else if (MemberDefinition.Namespace != null) {
+                               sb.Append (explicitName ? MemberDefinition.Namespace.Replace ('.', '#') : MemberDefinition.Namespace);
                        }
 
                        if (sb.Length != 0)
-                               sb.Append (".");
+                               sb.Append (explicitName ? "#" : ".");
 
                        sb.Append (Name);
                        if (Arity > 0) {
@@ -501,7 +514,7 @@ namespace Mono.CSharp
                                        if (i > 0)
                                            sb.Append (",");
 
-                                       sb.Append (TypeArguments[i].GetSignatureForDocumentation ());
+                                               sb.Append (TypeArguments[i].GetSignatureForDocumentation (explicitName));
                                    }
                                    sb.Append ("}");
                                } else {
@@ -513,33 +526,6 @@ namespace Mono.CSharp
                        return sb.ToString ();
                }
 
-               public string GetExplicitNameSignatureForDocumentation ()
-               {
-                       StringBuilder sb = new StringBuilder ();
-                       if (IsNested) {
-                               sb.Append (DeclaringType.GetExplicitNameSignatureForDocumentation ());
-                       } else if (MemberDefinition.Namespace != null) {
-                               sb.Append (MemberDefinition.Namespace.Replace ('.', '#'));
-                       }
-
-                       if (sb.Length != 0)
-                               sb.Append ("#");
-
-                       sb.Append (Name);
-                       if (Arity > 0) {
-                               sb.Append ("{");
-                               for (int i = 0; i < Arity; ++i) {
-                                       if (i > 0)
-                                               sb.Append (",");
-
-                                       sb.Append (TypeArguments[i].GetExplicitNameSignatureForDocumentation ());
-                               }
-                               sb.Append ("}");
-                       }
-
-                       return sb.ToString ();
-               }
-
                public override string GetSignatureForError ()
                {
                        string s;
@@ -560,7 +546,15 @@ namespace Mono.CSharp
 
                public string GetSignatureForErrorIncludingAssemblyName ()
                {
-                       return string.Format ("{0} [{1}]", GetSignatureForError (), MemberDefinition.DeclaringAssembly.FullName);
+                       var imported = MemberDefinition.DeclaringAssembly as ImportedAssemblyDefinition;
+
+                       var location = imported != null ?
+                               System.IO.Path.GetFullPath (imported.Location) :
+                           ((MemberCore)MemberDefinition).Location.NameFullPath;
+
+                       return string.Format ("{0} [{1} -- {2}]", GetSignatureForError (),
+                                                                 MemberDefinition.DeclaringAssembly.FullName,
+                                                                 location);
                }
 
                protected virtual string GetTypeNameSignature ()
@@ -642,6 +636,7 @@ namespace Mono.CSharp
                        case MemberKind.Struct:
                        case MemberKind.Enum:
                        case MemberKind.Void:
+                       case MemberKind.PointerType:
                                return false;
                        case MemberKind.InternalCompilerType:
                                //
@@ -653,6 +648,20 @@ namespace Mono.CSharp
                        }
                }
 
+               public static bool IsNonNullableValueType (TypeSpec t)
+               {
+                       switch (t.Kind) {
+                       case MemberKind.TypeParameter:
+                               return ((TypeParameterSpec) t).IsValueType;
+                       case MemberKind.Struct:
+                               return !t.IsNullableType;
+                       case MemberKind.Enum:
+                               return true;
+                       default:
+                               return false;
+                       }
+               }
+
                public static bool IsValueType (TypeSpec t)
                {
                        switch (t.Kind) {
@@ -724,22 +733,22 @@ namespace Mono.CSharp
                        return this;
                }
 
-               public override List<TypeSpec> ResolveMissingDependencies ()
+               public override List<MissingTypeSpecReference> ResolveMissingDependencies (MemberSpec caller)
                {
-                       List<TypeSpec> missing = null;
+                       List<MissingTypeSpecReference> missing = null;
 
                        if (Kind == MemberKind.MissingType) {
-                               missing = new List<TypeSpec> ();
-                               missing.Add (this);
+                               missing = new List<MissingTypeSpecReference> ();
+                               missing.Add (new MissingTypeSpecReference (this, caller));
                                return missing;
                        }
 
                        foreach (var targ in TypeArguments) {
                                if (targ.Kind == MemberKind.MissingType) {
                                        if (missing == null)
-                                               missing = new List<TypeSpec> ();
+                                               missing = new List<MissingTypeSpecReference> ();
 
-                                       missing.Add (targ);
+                                       missing.Add (new MissingTypeSpecReference (targ, caller));
                                }
                        }
 
@@ -747,19 +756,19 @@ namespace Mono.CSharp
                                foreach (var iface in Interfaces) {
                                        if (iface.Kind == MemberKind.MissingType) {
                                                if (missing == null)
-                                                       missing = new List<TypeSpec> ();
+                                                       missing = new List<MissingTypeSpecReference> ();
 
-                                               missing.Add (iface);
+                                               missing.Add (new MissingTypeSpecReference (iface, caller));
                                        }
                                }
                        }
 
                        if (MemberDefinition.TypeParametersCount > 0) {
                                foreach (var tp in MemberDefinition.TypeParameters) {
-                                       var tp_missing = tp.GetMissingDependencies ();
+                                       var tp_missing = tp.GetMissingDependencies (this);
                                        if (tp_missing != null) {
                                                if (missing == null)
-                                                       missing = new List<TypeSpec> ();
+                                                       missing = new List<MissingTypeSpecReference> ();
 
                                                missing.AddRange (tp_missing);
                                        }
@@ -769,7 +778,7 @@ namespace Mono.CSharp
                        if (missing != null || BaseType == null)
                                return missing;
 
-                       return BaseType.ResolveMissingDependencies ();
+                       return BaseType.ResolveMissingDependencies (this);
                }
 
                public void SetMetaInfo (MetaType info)
@@ -784,6 +793,31 @@ namespace Mono.CSharp
                {
                        modifiers |= Modifiers.METHOD_EXTENSION;
                }
+
+               public void UpdateInflatedInstancesBaseType ()
+               {
+                       //
+                       // When nested class has a partial part the situation where parent type
+                       // is inflated before its base type is defined can occur. In such case
+                       // all inflated (should be only 1) instansted need to be updated
+                       //
+                       // partial class A<T> {
+                       //   partial class B : A<int> { }
+                       // }
+                       //
+                       // partial class A<T> : X {}
+                       //
+                       if (inflated_instances == null)
+                               return;
+
+                       foreach (var inflated in inflated_instances) {
+                               //
+                               // Don't need to inflate possible generic type because for now the method
+                               // is always used from within the nested type
+                               //
+                               inflated.Value.BaseType = base_type;
+                       }
+               }
        }
 
        //
@@ -1211,6 +1245,9 @@ namespace Mono.CSharp
                                                return false;
                                }
 
+                               if (a.IsNested && b.IsNested)
+                                       return IsEqual (a.DeclaringType, b.DeclaringType);
+
                                return true;
                        }
 
@@ -1374,6 +1411,7 @@ namespace Mono.CSharp
                bool IsPartial { get; }
                bool IsComImport { get; }
                bool IsTypeForwarder { get; }
+               bool IsCyclicTypeForwarder { get; }
                int TypeParametersCount { get; }
                TypeParameterSpec[] TypeParameters { get; }
 
@@ -1393,6 +1431,7 @@ namespace Mono.CSharp
                public static readonly InternalType FakeInternalType = new InternalType ("<fake$type>");
                public static readonly InternalType Namespace = new InternalType ("<namespace>");
                public static readonly InternalType ErrorType = new InternalType ("<error>");
+               public static readonly InternalType VarOutType = new InternalType ("var out");
 
                readonly string name;
 
@@ -1445,6 +1484,12 @@ namespace Mono.CSharp
                        }
                }
 
+               bool ITypeDefinition.IsCyclicTypeForwarder {
+                       get {
+                               return false;
+                       }
+               }
+
                public override string Name {
                        get {
                                return name;
@@ -1557,6 +1602,12 @@ namespace Mono.CSharp
 
                public TypeSpec Element { get; private set; }
 
+               public override IList<TypeSpec> Interfaces {
+                       set {
+                               throw new NotSupportedException ();
+                       }
+               }
+
                bool ITypeDefinition.IsComImport {
                        get {
                                return false;
@@ -1575,6 +1626,12 @@ namespace Mono.CSharp
                        }
                }
 
+               bool ITypeDefinition.IsCyclicTypeForwarder {
+                       get {
+                               return false;
+                       }
+               }
+
                public override string Name {
                        get {
                                throw new NotSupportedException ();
@@ -1583,6 +1640,11 @@ namespace Mono.CSharp
 
                #endregion
 
+               public override void CheckObsoleteness (IMemberContext mc, Location loc)
+               {
+                       Element.CheckObsoleteness (mc, loc);
+               }
+
                public override ObsoleteAttribute GetAttributeObsolete ()
                {
                        return Element.GetAttributeObsolete ();
@@ -1593,9 +1655,9 @@ namespace Mono.CSharp
                        return null;
                }
 
-               public override string GetSignatureForDocumentation ()
+               public override string GetSignatureForDocumentation (bool explicitName)
                {
-                       return Element.GetSignatureForDocumentation () + GetPostfixSignature ();
+                       return Element.GetSignatureForDocumentation (explicitName) + GetPostfixSignature ();
                }
 
                public override string GetSignatureForError ()
@@ -1720,13 +1782,19 @@ namespace Mono.CSharp
                readonly int rank;
                readonly ModuleContainer module;
 
-               private ArrayContainer (ModuleContainer module, TypeSpec element, int rank)
+               ArrayContainer (ModuleContainer module, TypeSpec element, int rank)
                        : base (MemberKind.ArrayType, element, null)
                {
                        this.module = module;
                        this.rank = rank;
                }
 
+               public override IList<TypeSpec> Interfaces {
+                       get {
+                               return BaseType.Interfaces;
+                       }
+               }
+
                public int Rank {
                        get {
                                return rank;
@@ -1828,29 +1896,33 @@ namespace Mono.CSharp
                        return sb.ToString ();
                }
 
-               public override string GetSignatureForDocumentation ()
+               public override string GetSignatureForDocumentation (bool explicitName)
                {
                        StringBuilder sb = new StringBuilder ();
-                       GetElementSignatureForDocumentation (sb);
+                       GetElementSignatureForDocumentation (sb, explicitName);
                        return sb.ToString ();
                }
 
-               void GetElementSignatureForDocumentation (StringBuilder sb)
+               void GetElementSignatureForDocumentation (StringBuilder sb, bool explicitName)
                {
                        var ac = Element as ArrayContainer;
                        if (ac == null)
-                               sb.Append (Element.GetSignatureForDocumentation ());
+                               sb.Append (Element.GetSignatureForDocumentation (explicitName));
                        else
-                               ac.GetElementSignatureForDocumentation (sb);
+                               ac.GetElementSignatureForDocumentation (sb, explicitName);
 
-                       sb.Append ("[");
-                       for (int i = 1; i < rank; i++) {
-                               if (i == 1)
-                                       sb.Append ("0:");
+                       if (explicitName) {
+                               sb.Append (GetPostfixSignature (rank));
+                       } else {
+                               sb.Append ("[");
+                               for (int i = 1; i < rank; i++) {
+                                       if (i == 1)
+                                               sb.Append ("0:");
 
-                               sb.Append (",0:");
+                                       sb.Append (",0:");
+                               }
+                               sb.Append ("]");
                        }
-                       sb.Append ("]");
                }
 
                public static ArrayContainer MakeType (ModuleContainer module, TypeSpec element)
@@ -1865,22 +1937,32 @@ namespace Mono.CSharp
                        if (!module.ArrayTypesCache.TryGetValue (key, out ac)) {
                                ac = new ArrayContainer (module, element, rank);
                                ac.BaseType = module.Compiler.BuiltinTypes.Array;
-                               ac.Interfaces = ac.BaseType.Interfaces;
 
                                module.ArrayTypesCache.Add (key, ac);
                        }
 
                        return ac;
                }
+
+               public override List<MissingTypeSpecReference> ResolveMissingDependencies (MemberSpec caller)
+               {
+                       return Element.ResolveMissingDependencies (caller);
+               }
        }
 
        class ReferenceContainer : ElementTypeSpec
        {
-               private ReferenceContainer (TypeSpec element)
+               ReferenceContainer (TypeSpec element)
                        : base (MemberKind.Class, element, null)        // TODO: Kind.Class is most likely wrong
                {
                }
 
+               public override IList<TypeSpec> Interfaces {
+                       get {
+                               return null;
+                       }
+               }
+
                public override MetaType GetMetaInfo ()
                {
                        if (info == null) {
@@ -1911,6 +1993,12 @@ namespace Mono.CSharp
                        state &= ~StateFlags.CLSCompliant_Undetected;
                }
 
+               public override IList<TypeSpec> Interfaces {
+                       get {
+                               return null;
+                       }
+               }
+
                public override MetaType GetMetaInfo ()
                {
                        if (info == null) {
@@ -1936,4 +2024,16 @@ namespace Mono.CSharp
                        return pc;
                }
        }
+
+       public class MissingTypeSpecReference
+       {
+               public MissingTypeSpecReference (TypeSpec type, MemberSpec caller)
+               {
+                       Type = type;
+                       Caller = caller;
+               }
+
+               public TypeSpec Type { get; private set; }
+               public MemberSpec Caller { get; private set; }
+       }
 }