[mcs] Implements C# 7.2 readonly structs
[mono.git] / mcs / mcs / typespec.cs
index 696bde556c820ad00f9d206bac897e80c10ee470..d14e1ead3e317c07b55873ca2e679a7d6d3205a9 100644 (file)
@@ -92,6 +92,12 @@ namespace Mono.CSharp
                        }
                }
 
+               public bool HasNamedTupleElement {
+                       get {
+                               return (state & StateFlags.HasNamedTupleElement) != 0;
+                       }
+               }
+
                //
                // Returns a list of all interfaces including
                // interfaces from base type or base interfaces
@@ -231,6 +237,20 @@ namespace Mono.CSharp
                        }
                }
 
+               public bool IsReadOnly => (modifiers & Modifiers.READONLY) != 0;
+
+               //
+               // Returns true for instances of any System.ValueTuple<......> type
+               //
+               public virtual bool IsTupleType {
+                       get {
+                               return (state & StateFlags.Tuple) != 0;
+                       }
+                       set {
+                               state = value ? state | StateFlags.Tuple : state & ~StateFlags.Tuple;
+                       }
+               }
+
                // TODO: Should probably do
                // IsGenericType -- recursive
                // HasTypeParameter -- non-recursive
@@ -533,7 +553,9 @@ namespace Mono.CSharp
                        if (IsNested) {
                                s = DeclaringType.GetSignatureForError ();
                        } else if (MemberDefinition is AnonymousTypeClass) {
-                               return ((AnonymousTypeClass) MemberDefinition).GetSignatureForError ();
+                               return ((AnonymousTypeClass)MemberDefinition).GetSignatureForError ();
+                       } else if (IsTupleType) {
+                               return FormatTupleSignature ();
                        } else {
                                s = MemberDefinition.Namespace;
                        }
@@ -544,6 +566,21 @@ namespace Mono.CSharp
                        return s + Name + GetTypeNameSignature ();
                }
 
+               string FormatTupleSignature ()
+               {
+                       var sb = new StringBuilder ();
+                       sb.Append ("(");
+                       for (int i = 0; i < TypeArguments.Length; ++i) {
+                               if (i != 0)
+                                       sb.Append (", ");
+
+                               sb.Append (TypeArguments[i].GetSignatureForError ());
+                       }
+                       sb.Append (")");
+
+                       return sb.ToString ();
+               }
+
                public string GetSignatureForErrorIncludingAssemblyName ()
                {
                        var imported = MemberDefinition.DeclaringAssembly as ImportedAssemblyDefinition;
@@ -1432,6 +1469,7 @@ namespace Mono.CSharp
                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");
+               public static readonly InternalType ThrowExpr = new InternalType ("throw expression");
 
                readonly string name;
 
@@ -1573,6 +1611,11 @@ namespace Mono.CSharp
                }
 
                #endregion
+
+               public static bool HasNoType (TypeSpec type)
+               {
+                       return type == AnonymousMethod || type == MethodGroup || type == NullLiteral || type == ThrowExpr;
+               }
        }
 
        //
@@ -1950,10 +1993,11 @@ namespace Mono.CSharp
                }
        }
 
+       [System.Diagnostics.DebuggerDisplay("{DisplayDebugInfo()}")]
        class ReferenceContainer : ElementTypeSpec
        {
                ReferenceContainer (TypeSpec element)
-                       : base (MemberKind.Class, element, null)        // TODO: Kind.Class is most likely wrong
+                       : base (MemberKind.ByRef, element, null)
                {
                }
 
@@ -1963,6 +2007,11 @@ namespace Mono.CSharp
                        }
                }
 
+               string DisplayDebugInfo()
+               {
+                       return "ref " + GetSignatureForError();
+               }
+
                public override MetaType GetMetaInfo ()
                {
                        if (info == null) {
@@ -1972,8 +2021,16 @@ namespace Mono.CSharp
                        return info;
                }
 
+               public override string GetSignatureForError ()
+               {
+                       return Element.GetSignatureForError ();
+               }
+
                public static ReferenceContainer MakeType (ModuleContainer module, TypeSpec element)
                {
+                       if (element.Kind == MemberKind.ByRef)
+                               throw new ArgumentException ();
+
                        ReferenceContainer pc;
                        if (!module.ReferenceTypesCache.TryGetValue (element, out pc)) {
                                pc = new ReferenceContainer (element);