[mcs] C# 7 tuple (foundation only).
[mono.git] / mcs / mcs / typemanager.cs
index 870b7be2a754773b25c721b29e0fb28b38d4315c..b6aff14e1c025195c5ec8425d623610361c19ae9 100644 (file)
@@ -73,7 +73,6 @@ namespace Mono.CSharp
                public readonly TypeSpec[] OperatorsUnaryMutator;
 
                public readonly TypeSpec[] BinaryPromotionsTypes;
-               public readonly TypeSpec[] SwitchUserTypes;
 
                readonly BuiltinTypeSpec[] types;
 
@@ -125,7 +124,6 @@ namespace Mono.CSharp
                        OperatorsUnaryMutator = UnaryMutator.CreatePredefinedOperatorsTable (this);
 
                        BinaryPromotionsTypes = ConstantFold.CreateBinaryPromotionsTypes (this);
-                       SwitchUserTypes = Switch.CreateSwitchUserTypes (this);
 
                        types = new BuiltinTypeSpec[] {
                                Object, ValueType, Attribute,
@@ -200,6 +198,9 @@ namespace Mono.CSharp
                public readonly PredefinedType SecurityAction;
                public readonly PredefinedType Dictionary;
                public readonly PredefinedType Hashtable;
+               public readonly PredefinedType Array;
+
+               public readonly TypeSpec[] SwitchUserTypes;
 
                //
                // C# 3.0
@@ -234,6 +235,14 @@ namespace Mono.CSharp
                public readonly PredefinedType INotifyCompletion;
                public readonly PredefinedType ICriticalNotifyCompletion;
 
+               // C# 6.0
+               public readonly PredefinedType IFormattable;
+               public readonly PredefinedType FormattableString;
+               public readonly PredefinedType FormattableStringFactory;
+
+               // C# 7.0
+               public readonly PredefinedType[] Tuples;
+
                public PredefinedTypes (ModuleContainer module)
                {
                        TypedReference = new PredefinedType (module, MemberKind.Struct, "System", "TypedReference");
@@ -262,6 +271,7 @@ namespace Mono.CSharp
                        SecurityAction = new PredefinedType (module, MemberKind.Enum, "System.Security.Permissions", "SecurityAction");
                        Dictionary = new PredefinedType (module, MemberKind.Class, "System.Collections.Generic", "Dictionary", 2);
                        Hashtable = new PredefinedType (module, MemberKind.Class, "System.Collections", "Hashtable");
+                       Array = new PredefinedType (module, MemberKind.Class, "System", "Array");
 
                        Expression = new PredefinedType (module, MemberKind.Class, "System.Linq.Expressions", "Expression");
                        ExpressionGeneric = new PredefinedType (module, MemberKind.Class, "System.Linq.Expressions", "Expression", 1);
@@ -287,6 +297,10 @@ namespace Mono.CSharp
                        INotifyCompletion = new PredefinedType (module, MemberKind.Interface, "System.Runtime.CompilerServices", "INotifyCompletion");
                        ICriticalNotifyCompletion = new PredefinedType (module, MemberKind.Interface, "System.Runtime.CompilerServices", "ICriticalNotifyCompletion");
 
+                       IFormattable = new PredefinedType (module, MemberKind.Interface, "System", "IFormattable");
+                       FormattableString = new PredefinedType (module, MemberKind.Class, "System", "FormattableString");
+                       FormattableStringFactory = new PredefinedType (module, MemberKind.Class, "System.Runtime.CompilerServices", "FormattableStringFactory");
+
                        //
                        // Define types which are used for comparison. It does not matter
                        // if they don't exist as no error report is needed
@@ -321,12 +335,26 @@ namespace Mono.CSharp
                        Task.Define ();
                        if (TaskGeneric.Define ())
                                TaskGeneric.TypeSpec.IsGenericTask = true;
+
+                       SwitchUserTypes = Switch.CreateSwitchUserTypes (module, Nullable.TypeSpec);
+
+                       IFormattable.Define ();
+                       FormattableString.Define ();
+
+                       Tuples = new PredefinedType [8];
+                       for (int i = 0; i < Tuples.Length; i++) {
+                               var pt = new PredefinedType (module, MemberKind.Struct, "System", "ValueTuple", i + 1);
+                               Tuples [i] = pt;
+                               if (pt.Define ())
+                                       pt.TypeSpec.IsTupleType = true;
+                       }
                }
        }
 
        class PredefinedMembers
        {
                public readonly PredefinedMember<MethodSpec> ActivatorCreateInstance;
+               public readonly PredefinedMember<MethodSpec> ArrayEmpty;
                public readonly PredefinedMember<MethodSpec> AsyncTaskMethodBuilderCreate;
                public readonly PredefinedMember<MethodSpec> AsyncTaskMethodBuilderStart;
                public readonly PredefinedMember<MethodSpec> AsyncTaskMethodBuilderSetResult;
@@ -371,6 +399,7 @@ namespace Mono.CSharp
                public readonly PredefinedMember<MethodSpec> FixedBufferAttributeCtor;
                public readonly PredefinedMember<MethodSpec> MethodInfoGetMethodFromHandle;
                public readonly PredefinedMember<MethodSpec> MethodInfoGetMethodFromHandle2;
+               public readonly PredefinedMember<MethodSpec> MethodInfoCreateDelegate;
                public readonly PredefinedMember<MethodSpec> MonitorEnter;
                public readonly PredefinedMember<MethodSpec> MonitorEnter_v4;
                public readonly PredefinedMember<MethodSpec> MonitorExit;
@@ -385,6 +414,7 @@ namespace Mono.CSharp
                public readonly PredefinedMember<FieldSpec> StructLayoutCharSet;
                public readonly PredefinedMember<FieldSpec> StructLayoutSize;
                public readonly PredefinedMember<MethodSpec> TypeGetTypeFromHandle;
+               public readonly PredefinedMember<MethodSpec> TupleElementNamesAttributeCtor;
 
                public PredefinedMembers (ModuleContainer module)
                {
@@ -397,6 +427,9 @@ namespace Mono.CSharp
                        ActivatorCreateInstance = new PredefinedMember<MethodSpec> (module, types.Activator,
                                MemberFilter.Method ("CreateInstance", 1, ParametersCompiled.EmptyReadOnlyParameters, null));
 
+                       ArrayEmpty = new PredefinedMember<MethodSpec> (module, types.Array,
+                               MemberFilter.Method ("Empty", 1, ParametersCompiled.EmptyReadOnlyParameters, null));
+
                        AsyncTaskMethodBuilderCreate = new PredefinedMember<MethodSpec> (module, types.AsyncTaskMethodBuilder,
                                MemberFilter.Method ("Create", 0, ParametersCompiled.EmptyReadOnlyParameters, types.AsyncTaskMethodBuilder.TypeSpec));
 
@@ -646,6 +679,10 @@ namespace Mono.CSharp
                        MethodInfoGetMethodFromHandle2 = new PredefinedMember<MethodSpec> (module, types.MethodBase,
                                "GetMethodFromHandle", MemberKind.Method, types.RuntimeMethodHandle, new PredefinedType (btypes.RuntimeTypeHandle));
 
+                       MethodInfoCreateDelegate = new PredefinedMember<MethodSpec> (module, types.MethodInfo,
+                                                                                    "CreateDelegate", MemberKind.Method,
+                                                                                    new PredefinedType (btypes.Type), new PredefinedType (btypes.Object));
+
                        MonitorEnter = new PredefinedMember<MethodSpec> (module, types.Monitor, "Enter", btypes.Object);
 
                        MonitorEnter_v4 = new PredefinedMember<MethodSpec> (module, types.Monitor,
@@ -690,6 +727,10 @@ namespace Mono.CSharp
                                MemberFilter.Field ("Size", btypes.Int));
 
                        TypeGetTypeFromHandle = new PredefinedMember<MethodSpec> (module, btypes.Type, "GetTypeFromHandle", btypes.RuntimeTypeHandle);
+
+                       TupleElementNamesAttributeCtor = new PredefinedMember<MethodSpec> (module, atypes.TupleElementNames,
+                               MemberFilter.Constructor (ParametersCompiled.CreateFullyResolved (
+                                       ArrayContainer.MakeType (module, btypes.String))));
                }
        }