2009-07-10 Marek Safar <marek.safar@gmail.com>
authorMarek Safar <marek.safar@gmail.com>
Fri, 10 Jul 2009 11:39:24 +0000 (11:39 -0000)
committerMarek Safar <marek.safar@gmail.com>
Fri, 10 Jul 2009 11:39:24 +0000 (11:39 -0000)
* typemanager.cs, lambda.cs, parameter.cs, convert.cs, anonymous.cs,
expression.cs, literal.cs, ecore.cs, complete.cs: Moved internal
types to new class.

* support.cs: New dynamic type wrapper.

svn path=/trunk/mcs/; revision=137686

mcs/mcs/ChangeLog
mcs/mcs/anonymous.cs
mcs/mcs/complete.cs
mcs/mcs/convert.cs
mcs/mcs/ecore.cs
mcs/mcs/expression.cs
mcs/mcs/lambda.cs
mcs/mcs/literal.cs
mcs/mcs/parameter.cs
mcs/mcs/support.cs
mcs/mcs/typemanager.cs

index fe5a6d7288af5ff90dd4e607e0731a379c00741e..7923b98e0e29b6993c32ec52893aa71ac8afe8dd 100644 (file)
@@ -1,3 +1,11 @@
+2009-07-10  Marek Safar  <marek.safar@gmail.com>
+
+       * typemanager.cs, lambda.cs, parameter.cs, convert.cs, anonymous.cs,
+       expression.cs, literal.cs, ecore.cs, complete.cs: Moved internal
+       types to new class.
+       
+       * support.cs: New dynamic type wrapper.
+
 2009-07-08  Marek Safar  <marek.safar@gmail.com>
 
        * ecore.cs, cs-parser.jay: Better error reporting for implicitly
index 4a4980a03e8d67b9e31b31bffda06c9dd51d9c08..e98f07b4887f2049643ce3270dd01b2a20d072b4 100644 (file)
@@ -1129,7 +1129,7 @@ namespace Mono.CSharp {
                        // anywhere', we depend on special conversion
                        // rules.
                        // 
-                       type = TypeManager.anonymous_method_type;
+                       type = InternalType.AnonymousMethod;
 
                        if ((Parameters != null) && !Parameters.Resolve (ec))
                                return null;
index 199fc274ddd038e394a709236ef524306c7d8044..9ff1d96690d07eb73a845ff1da331111abb318f7 100644 (file)
@@ -142,7 +142,7 @@ namespace Mono.CSharp {
                                return null;
 
                        Type expr_type = expr_resolved.Type;
-                       if (expr_type.IsPointer || expr_type == TypeManager.void_type || expr_type == TypeManager.null_type || expr_type == TypeManager.anonymous_method_type) {
+                       if (expr_type.IsPointer || expr_type == TypeManager.void_type || expr_type == TypeManager.null_type || expr_type == InternalType.AnonymousMethod) {
                                Unary.Error_OperatorCannotBeApplied (loc, ".", expr_type);
                                return null;
                        }
index a6b8a1f8223aed7aad0e85e9c152ae64f4fe072a..52cee4969fc47122d5a81f7e87403786d7d5fc0e 100644 (file)
@@ -281,7 +281,7 @@ namespace Mono.CSharp {
 
                        // from the null type to any reference-type.
                        if (expr_type == TypeManager.null_type)
-                               return target_type != TypeManager.anonymous_method_type;
+                               return target_type != InternalType.AnonymousMethod;
 
                        if (TypeManager.IsGenericParameter (expr_type))
                                return ImplicitTypeParameterConversion (expr, target_type) != null;
@@ -656,7 +656,7 @@ namespace Mono.CSharp {
                        if (ImplicitStandardConversionExists (expr, target_type))
                                return true;
 
-                       if (expr.Type == TypeManager.anonymous_method_type) {
+                       if (expr.Type == InternalType.AnonymousMethod) {
                                if (!TypeManager.IsDelegateType (target_type) &&
                                        TypeManager.DropGenericTypeArguments (target_type) != TypeManager.expression_type)
                                        return false;
@@ -779,7 +779,7 @@ namespace Mono.CSharp {
                                return true;
 
                        // Conversion from __arglist to System.ArgIterator
-                       if (expr_type == typeof (ArglistAccess))
+                       if (expr_type == InternalType.Arglist)
                                return target_type == TypeManager.arg_iterator_type;
 
                        return false;
@@ -1224,7 +1224,7 @@ namespace Mono.CSharp {
                        Expression e;
 
                        if (expr_type.Equals (target_type)) {
-                               if (expr_type != TypeManager.null_type && expr_type != TypeManager.anonymous_method_type)
+                               if (expr_type != TypeManager.null_type && expr_type != InternalType.AnonymousMethod)
                                        return expr;
                                return null;
                        }
@@ -1293,14 +1293,14 @@ namespace Mono.CSharp {
                                        return EmptyCast.Create (new NullPointer (loc), target_type);
                        }
 
-                       if (expr_type == TypeManager.anonymous_method_type){
+                       if (expr_type == InternalType.AnonymousMethod){
                                AnonymousMethodExpression ame = (AnonymousMethodExpression) expr;
                                Expression am = ame.Compatible (ec, target_type);
                                if (am != null)
                                        return am.DoResolve (ec);
                        }
 
-                       if (expr_type == typeof (ArglistAccess) && target_type == TypeManager.arg_iterator_type)
+                       if (expr_type == InternalType.Arglist && target_type == TypeManager.arg_iterator_type)
                                return expr;
 
                        return null;
index 656aedba067ddaa2b78f724bb9cb9e301da6fe8b..0913f3656f3435095cd098397f5e9ac628480adc 100644 (file)
@@ -370,7 +370,7 @@ namespace Mono.CSharp {
                protected void Error_ValueCannotBeConvertedCore (EmitContext ec, Location loc, Type target, bool expl)
                {
                        // The error was already reported as CS1660
-                       if (type == TypeManager.anonymous_method_type)
+                       if (type == InternalType.AnonymousMethod)
                                return;
 
                        if (TypeManager.IsGenericParameter (Type) && TypeManager.IsGenericParameter (target) && type.Name == target.Name) {
@@ -3234,7 +3234,7 @@ namespace Mono.CSharp {
                {
                        this.loc = loc;
                        eclass = ExprClass.MethodGroup;
-                       this.type = typeof (MethodGroupExpr);
+                       this.type = InternalType.MethodGroup;
                        queried_type = type;
                }
 
@@ -3315,7 +3315,7 @@ namespace Mono.CSharp {
                static int BetterExpressionConversion (EmitContext ec, Argument a, Type p, Type q)
                {
                        Type argument_type = TypeManager.TypeToCoreType (a.Type);
-                       if (argument_type == TypeManager.anonymous_method_type && RootContext.Version > LanguageVersion.ISO_2) {
+                       if (argument_type == InternalType.AnonymousMethod && RootContext.Version > LanguageVersion.ISO_2) {
                                //
                                // Uwrap delegate from Expression<T>
                                //
@@ -5935,7 +5935,7 @@ namespace Mono.CSharp {
        /// Handles `var' contextual keyword; var becomes a keyword only
        /// if no type called var exists in a variable scope
        /// 
-       public class VarExpr : SimpleName
+       class VarExpr : SimpleName
        {
                // Used for error reporting only
                ArrayList initializer;
@@ -5957,7 +5957,7 @@ namespace Mono.CSharp {
                                throw new InternalErrorException ("An implicitly typed local variable could not be redefined");
                        
                        type = right_side.Type;
-                       if (type == TypeManager.null_type || type == TypeManager.void_type || type == TypeManager.anonymous_method_type) {
+                       if (type == TypeManager.null_type || type == TypeManager.void_type || type == InternalType.AnonymousMethod) {
                                Report.Error (815, loc, "An implicitly typed local variable declaration cannot be initialized with `{0}'",
                                              right_side.GetSignatureForError ());
                                return false;
@@ -5969,7 +5969,10 @@ namespace Mono.CSharp {
 
                protected override void Error_TypeOrNamespaceNotFound (IResolveContext ec)
                {
-                       Report.Error (825, loc, "The contextual keyword `var' may only appear within a local variable declaration");
+                       if (RootContext.Version < LanguageVersion.V_3)
+                               base.Error_TypeOrNamespaceNotFound (ec);
+                       else
+                               Report.Error (825, loc, "The contextual keyword `var' may only appear within a local variable declaration");
                }
 
                public override TypeExpr ResolveAsContextualType (IResolveContext rc, bool silent)
index 6a0fd0da50801cd463cb04c4416df387b53f5c7f..cf8209b33f3a8e3cb1648490c745517ea4b6b090 100644 (file)
@@ -1150,7 +1150,7 @@ namespace Mono.CSharp {
                                return null;
                        }
 
-                       if (expr.Type == TypeManager.anonymous_method_type) {
+                       if (expr.Type == InternalType.AnonymousMethod) {
                                Report.Error (837, loc, "The `{0}' operator cannot be applied to a lambda expression or anonymous method",
                                        OperatorName);
                                return null;
@@ -2613,13 +2613,13 @@ namespace Mono.CSharp {
                        bool is_equality = (oper & Operator.EqualityMask) != 0;
                        if (!TypeManager.IsEqual (l, r) && !TypeManager.IsVariantOf (r, l)) {
                                Expression tmp;
-                               if (right.eclass == ExprClass.MethodGroup || (r == TypeManager.anonymous_method_type && !is_equality)) {
+                               if (right.eclass == ExprClass.MethodGroup || (r == InternalType.AnonymousMethod && !is_equality)) {
                                        tmp = Convert.ImplicitConversionRequired (ec, right, l, loc);
                                        if (tmp == null)
                                                return null;
                                        right = tmp;
                                        r = right.Type;
-                               } else if (left.eclass == ExprClass.MethodGroup || (l == TypeManager.anonymous_method_type && !is_equality)) {
+                               } else if (left.eclass == ExprClass.MethodGroup || (l == InternalType.AnonymousMethod && !is_equality)) {
                                        tmp = Convert.ImplicitConversionRequired (ec, left, r, loc);
                                        if (tmp == null)
                                                return null;
@@ -2839,7 +2839,7 @@ namespace Mono.CSharp {
                                        return null;
                                }
 
-                               if (l == TypeManager.anonymous_method_type)
+                               if (l == InternalType.AnonymousMethod)
                                        return null;
 
                                if (TypeManager.IsValueType (l))
@@ -6243,7 +6243,7 @@ namespace Mono.CSharp {
                                return null;
 
                        if (array_element_type == null || array_element_type == TypeManager.null_type ||
-                               array_element_type == TypeManager.void_type || array_element_type == TypeManager.anonymous_method_type ||
+                               array_element_type == TypeManager.void_type || array_element_type == InternalType.AnonymousMethod ||
                                arguments.Count != dimensions) {
                                Error_NoBestType ();
                                return null;
@@ -6633,7 +6633,7 @@ namespace Mono.CSharp {
                public override Expression DoResolve (EmitContext ec)
                {
                        eclass = ExprClass.Variable;
-                       type = typeof (ArglistAccess);
+                       type = InternalType.Arglist;
                        if (Arguments != null)
                                Arguments.Resolve (ec);
 
@@ -7128,7 +7128,7 @@ namespace Mono.CSharp {
 
                        Type expr_type = expr_resolved.Type;
                        if (expr_type.IsPointer || expr_type == TypeManager.void_type ||
-                               expr_type == TypeManager.null_type || expr_type == TypeManager.anonymous_method_type) {
+                               expr_type == TypeManager.null_type || expr_type == InternalType.AnonymousMethod) {
                                Unary.Error_OperatorCannotBeApplied (loc, ".", expr_type);
                                return null;
                        }
@@ -9557,7 +9557,7 @@ namespace Mono.CSharp {
 
                        type = e.Type;
                        if (type == TypeManager.void_type || type == TypeManager.null_type ||
-                               type == TypeManager.anonymous_method_type || type.IsPointer) {
+                               type == InternalType.AnonymousMethod || type.IsPointer) {
                                Error_InvalidInitializer (e.GetSignatureForError ());
                                return null;
                        }
index 916860bf6e2fe327a87b5f7d0f8e30df4b5bf19d..81108fa7533b7cbbd5e2915f2399a52816e2231e 100644 (file)
@@ -111,7 +111,7 @@ namespace Mono.CSharp {
                        }
 
                        eclass = ExprClass.Value;
-                       type = TypeManager.anonymous_method_type;                                               
+                       type = InternalType.AnonymousMethod;
                        return this;
                }
 
index 1565dda2daf6e624114cec017f5b0fe6996ee9e4..b23d0004c0e692572c3b89bf037eff9faf679c39 100644 (file)
@@ -119,7 +119,7 @@ namespace Mono.CSharp {
                        }
 
                        // Exlude internal compiler types
-                       if (targetType == TypeManager.anonymous_method_type)
+                       if (targetType == InternalType.AnonymousMethod)
                                return null;
 
                        if (type != TypeManager.null_type && !Convert.ImplicitStandardConversionExists (this, targetType))
index 7cb860fe782167b0f04f18f0a0a790b7ccad6122..bfef2d87ca652e9c8a8739597d1990afad4429c4 100644 (file)
@@ -206,7 +206,7 @@ namespace Mono.CSharp {
 
                public override Type Resolve (IResolveContext ec)
                {
-                       return typeof (ArglistAccess);
+                       return InternalType.Arglist;
                }
 
                public override string GetSignatureForError ()
@@ -975,7 +975,7 @@ namespace Mono.CSharp {
 
                        if (varargs != 0) {
                                par [par.Length - 1] = new ArglistParameter (Location.Null);
-                               types [types.Length - 1] = typeof (ArglistAccess);
+                               types [types.Length - 1] = InternalType.Arglist;
                        }
 
                        return method != null ?
index b31507195d77b7604c1adb14513bfdf3d6566d64..fd14019cc46fc06ed5480f8f6a3e70d9697fc80a 100644 (file)
@@ -407,6 +407,189 @@ namespace Mono.CSharp {
                }
        }
 
+       class DynamicType : Type
+       {
+               public override Assembly Assembly {
+                       get { throw new NotImplementedException (); }
+               }
+
+               public override string AssemblyQualifiedName {
+                       get { throw new NotImplementedException (); }
+               }
+
+               public override Type BaseType {
+                       get { return null; }
+               }
+
+               public override string FullName {
+                       get { return UnderlyingSystemType.FullName; }
+               }
+
+               public override Guid GUID {
+                       get { throw new NotImplementedException (); }
+               }
+
+               protected override TypeAttributes GetAttributeFlagsImpl ()
+               {
+                       return UnderlyingSystemType.Attributes;
+               }
+
+               protected override ConstructorInfo GetConstructorImpl (BindingFlags bindingAttr, Binder binder, CallingConventions callConvention, Type[] types, ParameterModifier[] modifiers)
+               {
+                       throw new NotImplementedException ();
+               }
+
+               public override ConstructorInfo[] GetConstructors (BindingFlags bindingAttr)
+               {
+                       throw new NotImplementedException ();
+               }
+
+               public override Type GetElementType ()
+               {
+                       throw new NotImplementedException ();
+               }
+
+               public override EventInfo GetEvent (string name, BindingFlags bindingAttr)
+               {
+                       throw new NotImplementedException ();
+               }
+
+               public override EventInfo[] GetEvents (BindingFlags bindingAttr)
+               {
+                       throw new NotImplementedException ();
+               }
+
+               public override FieldInfo GetField (string name, BindingFlags bindingAttr)
+               {
+                       throw new NotImplementedException ();
+               }
+
+               public override FieldInfo[] GetFields (BindingFlags bindingAttr)
+               {
+                       throw new NotImplementedException ();
+               }
+
+               public override Type GetInterface (string name, bool ignoreCase)
+               {
+                       throw new NotImplementedException ();
+               }
+
+               public override Type[] GetInterfaces ()
+               {
+                       throw new NotImplementedException ();
+               }
+
+               public override MemberInfo[] GetMembers (BindingFlags bindingAttr)
+               {
+                       throw new NotImplementedException ();
+               }
+
+               protected override MethodInfo GetMethodImpl (string name, BindingFlags bindingAttr, Binder binder, CallingConventions callConvention, Type[] types, ParameterModifier[] modifiers)
+               {
+                       throw new NotImplementedException ();
+               }
+
+               public override MethodInfo[] GetMethods (BindingFlags bindingAttr)
+               {
+                       throw new NotImplementedException ();
+               }
+
+               public override Type GetNestedType (string name, BindingFlags bindingAttr)
+               {
+                       throw new NotImplementedException ();
+               }
+
+               public override Type[] GetNestedTypes (BindingFlags bindingAttr)
+               {
+                       throw new NotImplementedException ();
+               }
+
+               public override PropertyInfo[] GetProperties (BindingFlags bindingAttr)
+               {
+                       throw new NotImplementedException ();
+               }
+
+               protected override PropertyInfo GetPropertyImpl (string name, BindingFlags bindingAttr, Binder binder, Type returnType, Type[] types, ParameterModifier[] modifiers)
+               {
+                       throw new NotImplementedException ();
+               }
+
+               protected override bool HasElementTypeImpl ()
+               {
+                       throw new NotImplementedException ();
+               }
+
+               public override object InvokeMember (string name, BindingFlags invokeAttr, Binder binder, object target, object[] args, ParameterModifier[] modifiers, System.Globalization.CultureInfo culture, string[] namedParameters)
+               {
+                       throw new NotImplementedException ();
+               }
+
+               protected override bool IsArrayImpl ()
+               {
+                       return false;
+               }
+
+               protected override bool IsByRefImpl ()
+               {
+                       return false;
+               }
+
+               protected override bool IsCOMObjectImpl ()
+               {
+                       return false;
+               }
+
+               protected override bool IsPointerImpl ()
+               {
+                       return false;
+               }
+
+               protected override bool IsPrimitiveImpl ()
+               {
+                       return false;
+               }
+
+               public override Module Module {
+                       get { return UnderlyingSystemType.Module; }
+               }
+
+               public override string Namespace {
+                       get { throw new NotImplementedException (); }
+               }
+
+               public override Type UnderlyingSystemType {
+                       get { return TypeManager.object_type; }
+               }
+
+               public override object[] GetCustomAttributes (Type attributeType, bool inherit)
+               {
+                       return new object [0];
+               }
+
+               public override object[] GetCustomAttributes (bool inherit)
+               {
+                       return new object [0];
+               }
+
+               public override bool IsDefined (Type attributeType, bool inherit)
+               {
+                       throw new NotImplementedException ();
+               }
+
+               public override string Name {
+                       get { return UnderlyingSystemType.Name; }
+               }
+
+               public override string ToString ()
+               {
+                       return GetType ().ToString ();
+               }
+
+               public override RuntimeTypeHandle TypeHandle {
+                       get { return UnderlyingSystemType.TypeHandle; }
+               }
+       }
+
        public class UnixUtils {
                [System.Runtime.InteropServices.DllImport ("libc", EntryPoint="isatty")]
                extern static int _isatty (int fd);
index 678fe7e727df2b8e4fafe4275bf23cc78aaaa90b..31e7f67dcab5dd7db8bcfe248ff90d08ed31c834 100644 (file)
@@ -71,7 +71,6 @@ namespace Mono.CSharp {
        static public Type void_ptr_type;
        static public Type exception_type;
 
-       static public Type anonymous_method_type;
        static public Type typed_reference_type;
        static public Type arg_iterator_type;
        static public Type mbr_type;
@@ -965,7 +964,6 @@ namespace Mono.CSharp {
                //
                // These are only used for compare purposes
                //
-               anonymous_method_type = typeof (AnonymousMethodBody);
                null_type = typeof (NullLiteral);
                
                void_ptr_type = GetPointerType (void_type);
@@ -2463,7 +2461,7 @@ namespace Mono.CSharp {
                                return a.FullName == b.FullName;
 
                        // Some types are never equal
-                       if (a == TypeManager.null_type || a == TypeManager.anonymous_method_type)
+                       if (a == TypeManager.null_type || a == InternalType.AnonymousMethod)
                                return false;
 
                        return true;
@@ -3187,6 +3185,14 @@ namespace Mono.CSharp {
        
 }
 
+       class InternalType
+       {
+               public static readonly Type AnonymousMethod = typeof (AnonymousMethodBody);
+               public static readonly Type Arglist = typeof (ArglistAccess);
+               public static readonly Type Dynamic = new DynamicType ();
+               public static readonly Type MethodGroup = typeof (MethodGroupExpr);
+       }
+
 /// <summary>
 ///   There is exactly one instance of this class per type.
 /// </summary>