2004-08-07 Anirban Bhattacharjee <banirban@novell.com>
[mono.git] / mcs / mbas / expression.cs
index c00598ba5febadf5f9f17bb6bdb6e83587a98af7..492632b2dd384ea85e1069a058b9794a4ce18f9b 100644 (file)
@@ -9,13 +9,12 @@
 //
 #define USE_OLD
 
-namespace Mono.CSharp {
+namespace Mono.MonoBASIC {
        using System;
        using System.Collections;
        using System.Reflection;
        using System.Reflection.Emit;
        using System.Text;
-       using Mono.MonoBASIC;
 
        /// <summary>
        ///   This is just a helper class, it is generated by Unary, UnaryMutator
@@ -144,7 +143,7 @@ namespace Mono.CSharp {
                        Error (
                                23, "Operator " + OperName (Oper) +
                                " cannot be applied to operand of type '" +
-                               TypeManager.CSharpName (t) + "'");
+                               TypeManager.MonoBASIC_Name (t) + "'");
                }
 
                /// <remarks>
@@ -485,7 +484,7 @@ namespace Mono.CSharp {
                        }
 
                        Error (187, "No such operator '" + OperName (Oper) + "' defined for type '" +
-                              TypeManager.CSharpName (expr_type) + "'");
+                              TypeManager.MonoBASIC_Name (expr_type) + "'");
                        return null;
                }
 
@@ -693,7 +692,7 @@ namespace Mono.CSharp {
                        Error (
                                23, "Operator " + OperName (mode) + 
                                " cannot be applied to operand of type '" +
-                               TypeManager.CSharpName (t) + "'");
+                               TypeManager.MonoBASIC_Name (t) + "'");
                }
 
                /// <summary>
@@ -782,7 +781,7 @@ namespace Mono.CSharp {
                        }
 
                        Error (187, "No such operator '" + OperName (mode) + "' defined for type '" +
-                              TypeManager.CSharpName (expr_type) + "'");
+                              TypeManager.MonoBASIC_Name (expr_type) + "'");
                        return null;
                }
 
@@ -1075,13 +1074,13 @@ namespace Mono.CSharp {
                                        Warning (
                                                183,
                                                "The expression is always of type '" +
-                                               TypeManager.CSharpName (probe_type) + "'");
+                                               TypeManager.MonoBASIC_Name (probe_type) + "'");
                                else if (warning_never_matches){
                                        if (!(probe_type.IsInterface || expr.Type.IsInterface))
                                                Warning (
                                                        184,
                                                        "The expression is never of type '" +
-                                                       TypeManager.CSharpName (probe_type) + "'");
+                                                       TypeManager.MonoBASIC_Name (probe_type) + "'");
                                }
                        }
 
@@ -1114,8 +1113,8 @@ namespace Mono.CSharp {
                {
                        Report.Error (
                                39, loc, "as operator can not convert from '" +
-                               TypeManager.CSharpName (source) + "' to '" +
-                               TypeManager.CSharpName (target) + "'");
+                               TypeManager.MonoBASIC_Name (source) + "' to '" +
+                               TypeManager.MonoBASIC_Name (target) + "'");
                }
                
                public override Expression DoResolve (EmitContext ec)
@@ -1131,7 +1130,7 @@ namespace Mono.CSharp {
 
                        if (TypeManager.IsValueType (probe_type)){
                                Report.Error (77, loc, "The as operator should be used with a reference type only (" +
-                                             TypeManager.CSharpName (probe_type) + " is a value type");
+                                             TypeManager.MonoBASIC_Name (probe_type) + " is a value type)");
                                return null;
                        
                        }
@@ -1162,12 +1161,14 @@ namespace Mono.CSharp {
        public class Cast : Expression {
                Expression target_type;
                Expression expr;
+               bool runtime_cast;
                        
                public Cast (Expression cast_type, Expression expr, Location loc)
                {
                        this.target_type = cast_type;
                        this.expr = expr;
                        this.loc = loc;
+                       runtime_cast = false;
                }
 
                public Expression TargetType {
@@ -1185,6 +1186,16 @@ namespace Mono.CSharp {
                        }
                }
 
+               public bool IsRuntimeCast\r
+               {
+                       get {
+                               return runtime_cast;
+                       }
+                       set{
+                               runtime_cast = value;
+                       }
+               }
+
                /// <summary>
                ///   Attempts to do a compile-time folding of a constant cast.
                /// </summary>
@@ -1463,7 +1474,7 @@ namespace Mono.CSharp {
                        int errors = Report.Errors;
 
                        type = ec.DeclSpace.ResolveType (target_type, false, Location);
-                       
+
                        if (type == null)
                                return null;
 
@@ -1476,7 +1487,7 @@ namespace Mono.CSharp {
                                        return e;
                        }
                        
-                       expr = ConvertExplicit (ec, expr, type, loc);
+                       expr = ConvertExplicit (ec, expr, type, runtime_cast, loc);
                        return expr;
                }
 
@@ -1648,8 +1659,8 @@ namespace Mono.CSharp {
                        Report.Error (
                                34, loc, "Operator '" + OperName (oper) 
                                + "' is ambiguous on operands of type '"
-                               + TypeManager.CSharpName (l) + "' "
-                               + "and '" + TypeManager.CSharpName (r)
+                               + TypeManager.MonoBASIC_Name (l) + "' "
+                               + "and '" + TypeManager.MonoBASIC_Name (r)
                                + "'");
                }
 
@@ -1815,8 +1826,8 @@ namespace Mono.CSharp {
                {
                        Report.Error (19, loc,
                               "Operator " + name + " cannot be applied to operands of type '" +
-                              TypeManager.CSharpName (l) + "' and '" +
-                              TypeManager.CSharpName (r) + "'");
+                              TypeManager.MonoBASIC_Name (l) + "' and '" +
+                              TypeManager.MonoBASIC_Name (r) + "'");
                }
                
                void Error_OperatorCannotBeApplied ()
@@ -2753,8 +2764,8 @@ namespace Mono.CSharp {
                                        if (ConvertImplicit (ec, falseExpr, true_type, loc) != null){
                                                Error (172,
                                                       "Can not compute type of conditional expression " +
-                                                      "as '" + TypeManager.CSharpName (trueExpr.Type) +
-                                                      "' and '" + TypeManager.CSharpName (falseExpr.Type) +
+                                                      "as '" + TypeManager.MonoBASIC_Name (trueExpr.Type) +
+                                                      "' and '" + TypeManager.MonoBASIC_Name (falseExpr.Type) +
                                                       "' convert implicitly to each other");
                                                return null;
                                        }
@@ -2766,8 +2777,8 @@ namespace Mono.CSharp {
                                } else {
                                        Error (173, "The type of the conditional expression can " +
                                               "not be computed because there is no implicit conversion" +
-                                              " from '" + TypeManager.CSharpName (trueExpr.Type) + "'" +
-                                              " and '" + TypeManager.CSharpName (falseExpr.Type) + "'");
+                                              " from '" + TypeManager.MonoBASIC_Name (trueExpr.Type) + "'" +
+                                              " and '" + TypeManager.MonoBASIC_Name (falseExpr.Type) + "'");
                                        return null;
                                }
                        }
@@ -3423,7 +3434,7 @@ namespace Mono.CSharp {
                        string ret_type = "";
 
                        if (mb is MethodInfo)
-                               ret_type = TypeManager.CSharpName (((MethodInfo) mb).ReturnType) + " ";
+                               ret_type = TypeManager.MonoBASIC_Name (((MethodInfo) mb).ReturnType) + " ";
                        
                        StringBuilder sb = new StringBuilder (ret_type + mb.Name);
                        ParameterData pd = GetParameterData (mb);
@@ -3574,8 +3585,8 @@ namespace Mono.CSharp {
                                ~(Parameter.Modifier.OUT | Parameter.Modifier.REF);
 
                        if (a_mod == p_mod || (a_mod == Parameter.Modifier.NONE && p_mod == Parameter.Modifier.PARAMS)) {
-                               if (a_mod == Parameter.Modifier.NONE)
-                               if (! (ImplicitConversionExists (ec, a.Expr, ptype) || RuntimeConversionExists (ec, a.Expr, ptype)) )
+                               if (a_mod == Parameter.Modifier.NONE)   
+                                       if (! (ImplicitConversionExists (ec, a.Expr, ptype) || RuntimeConversionExists (ec, a.Expr, ptype)) )
                                                return false;
                                
                                if ((a_mod & Parameter.Modifier.ISBYREF) != 0) {
@@ -3588,8 +3599,7 @@ namespace Mono.CSharp {
                                                return false;
                                }
                        } else
-                               return false;           
-                               
+                               return false;                                   
                        return true;                                    
                }
                
@@ -3609,13 +3619,11 @@ namespace Mono.CSharp {
 
                        ParameterData pd = GetParameterData (candidate);
                        Parameters ps = GetFullParameters (candidate);
-                       
                        if (ps == null) {
                                ps_count = 0;
                                po_count = 0;
                        }
-                       else
-                       {
+                       else {
                                ps_count = ps.CountStandardParams();                    
                                po_count = ps.CountOptionalParams();
                        }
@@ -3626,8 +3634,7 @@ namespace Mono.CSharp {
                                if (arg_count != pd.Count)
                                        return false;
                        }
-                       else
-                       {
+                       else {
                                if ((arg_count < ps_count) || (arg_count > pd_count))
                                        return false;   
                        }       
@@ -3637,33 +3644,59 @@ namespace Mono.CSharp {
                                        i--;
 
                                        Argument a = (Argument) arguments [i];
-                                       if (a.ArgType == Argument.AType.NoArg)
-                                       {
+                                       if (a.ArgType == Argument.AType.NoArg) {
                                                Parameter p = (Parameter) ps.FixedParameters[i];
                                                a = new Argument (p.ParameterInitializer, Argument.AType.Expression);
                                                param_type = p.ParameterInitializer.Type;
                                        }
-                                       else 
-                                       {
+                                       else {
                                                param_type = pd.ParameterType (i);
+                                               Parameter.Modifier mod;
                                                if (ps != null) {
                                                        Parameter p = (Parameter) ps.FixedParameters[i];
-                                                       
-                                                       if ((p.ModFlags & Parameter.Modifier.REF) != 0) 
-                                                       {
-                                                               a = new Argument (a.Expr, Argument.AType.Ref);
-                                                               if (!a.Resolve(ec,Location.Null))
+                                                       bool IsDelegate = TypeManager.IsDelegateType (param_type);
+
+                                                       if (IsDelegate) {       
+                                                               if (a.ArgType == Argument.AType.AddressOf) {
+                                                                       a = new Argument ((Expression) a.Expr, Argument.AType.Expression);
+                                                                       ArrayList args = new ArrayList();
+                                                                       args.Add (a);
+                                                                       string param_name = pd.ParameterDesc(i).Replace('+', '.');
+                                                                       Expression pname = MonoBASIC.Parser.DecomposeQI (param_name, Location.Null);
+
+
+                                                                       New temp_new = new New ((Expression)pname, args, Location.Null);
+                                                                       Expression del_temp = temp_new.DoResolve(ec);
+
+                                                                       if (del_temp == null)
+                                                                               return false;
+
+                                                                       a = new Argument (del_temp, Argument.AType.Expression);
+                                                                       if (!a.Resolve(ec, Location.Null))\r
+                                                                               return false;
+                                                               }
+                                                       }
+                                                       else {
+                                                               if (a.ArgType == Argument.AType.AddressOf)
                                                                        return false;
                                                        }
+
+                                                       mod = p.ModFlags;
+                                               } else
+                                                       mod = pd.ParameterModifier (i);
+
+                                               if ((mod & Parameter.Modifier.REF) != 0) {
+                                                       a = new Argument (a.Expr, Argument.AType.Ref);
+                                                       if (!a.Resolve(ec,Location.Null))
+                                                               return false;
                                                }
                                        }       
-       
+\r
                                        if (!CheckParameterAgainstArgument (ec, pd, i, a, param_type))
                                                return (false);
                                }
                        }
-                       else
-                       {
+                       else {
                                // If we have no arguments AND the first parameter is optional
                                // we must check for a candidate (the loop above wouldn't)      
                                if (po_count > 0) {
@@ -3686,6 +3719,7 @@ namespace Mono.CSharp {
                        }
                        // We've found a candidate, so we exchange the dummy NoArg arguments
                        // with new arguments containing the default value for that parameter
+
                        ArrayList newarglist = new ArrayList();
                        for (int i = 0; i < arg_count; i++) {
                                Argument a = (Argument) arguments [i];
@@ -3697,19 +3731,44 @@ namespace Mono.CSharp {
                                if (a.ArgType == Argument.AType.NoArg){
                                        a = new Argument (p.ParameterInitializer, Argument.AType.Expression);
                                        a.Resolve(ec, Location.Null);
-                               }               
-                               
-                               if ((p != null) && ((p.ModFlags & Parameter.Modifier.REF) != 0))
-                               {
+                               }
+
+                               // ToDo - This part is getting resolved second time within this function
+                               // This is a costly operation
+                               // The earlier resoved result should be used here.
+                               // Has to be done during compiler optimization.
+                               if (a.ArgType == Argument.AType.AddressOf) {
+                                       param_type = pd.ParameterType (i);
+                                       bool IsDelegate = TypeManager.IsDelegateType (param_type);
+
+                                       a = new Argument ((Expression) a.Expr, Argument.AType.Expression);
+                                       ArrayList args = new ArrayList();
+                                       args.Add (a);
+                                       string param_name = pd.ParameterDesc(i).Replace('+', '.');
+                                       Expression pname = MonoBASIC.Parser.DecomposeQI (param_name, Location.Null);
+                                                               
+                                       New temp_new = new New ((Expression)pname, args, Location.Null);
+                                       Expression del_temp = temp_new.DoResolve(ec);
+
+                                       if (del_temp == null)
+                                               return false;
+
+                                       a = new Argument (del_temp, Argument.AType.Expression);
+                                       if (!a.Resolve(ec, Location.Null))\r
+                                               return false;
+                               }
+
+                               if ((p != null) && ((p.ModFlags & Parameter.Modifier.REF) != 0)) {
+                                       a.ArgType = Argument.AType.Ref;
+                                       a.Resolve(ec, Location.Null);
+                               } else if ((pd.ParameterModifier (i) & Parameter.Modifier.REF) != 0) {
                                        a.ArgType = Argument.AType.Ref;
                                        a.Resolve(ec, Location.Null);
                                }       
                                newarglist.Add(a);
                                int n = pd_count - arg_count;
-                               if (n > 0) 
-                               {
-                                       for (int x = 0; x < n; x++) 
-                                       {
+                               if (n > 0) {
+                                       for (int x = 0; x < n; x++) {
                                                Parameter op = (Parameter) ps.FixedParameters[x + arg_count];
                                                Argument b = new Argument (op.ParameterInitializer, Argument.AType.Expression);
                                                b.Resolve(ec, Location.Null);
@@ -3910,12 +3969,16 @@ namespace Mono.CSharp {
                        for (int j = 0; j < argument_count; j++) {
                                Argument a = (Argument) Arguments [j];
                                Expression a_expr = a.Expr;
-                               Type parameter_type = pd.ParameterType (j);
-                               
+                               Type parameter_type = pd.ParameterType(j);
+                                       
+                               if (parameter_type == null)
+                               {
+                                       Error_WrongNumArguments(loc, (InvokingProperty == null)?((delegate_type == null)?FullMethodDesc (method):delegate_type.ToString ()):InvokingProperty, argument_count);
+                                       return false;   
+                               }
                                if (pd.ParameterModifier (j) == Parameter.Modifier.PARAMS &&
-                                   chose_params_expanded)
+                               chose_params_expanded)
                                        parameter_type = TypeManager.TypeToCoreType (parameter_type.GetElementType ());
-
                                if (a.Type != parameter_type){
                                        Expression conv;
                                        
@@ -3992,7 +4055,7 @@ namespace Mono.CSharp {
                        // trigger the invocation
                        //
                        Expression expr_to_return = null;
-               
+
                        if (expr is BaseAccess)
                                is_base = true;
 
@@ -4036,7 +4099,8 @@ namespace Mono.CSharp {
                                {
                                        if ((a.ArgType == Argument.AType.NoArg) && (!(expr is MethodGroupExpr)))
                                                Report.Error (999, "This item cannot have empty arguments");
-                                       
+
+                       
                                        if (!a.Resolve (ec, loc))
                                                return null;                            
                                }
@@ -4049,8 +4113,8 @@ namespace Mono.CSharp {
 
                                if (method == null)
                                {
-                                       Error (-6,
-                                               "Could not find any applicable function for this argument list");
+                                       Error (30455,
+                                               "Could not find any applicable function to invoke for this argument list");
                                        return null;
                                }
 
@@ -4097,10 +4161,13 @@ namespace Mono.CSharp {
                                        expr_to_return = pe.DoResolve (ec);
                                        expr_to_return.eclass = ExprClass.PropertyAccess;
                                }
+                               else
+                               {
+                                       throw new Exception("Error resolving Property Access expression\n" + pe.ToString());
+                               }
                        }
 
                        if (expr is FieldExpr || expr is LocalVariableReference || expr is ParameterReference) {
-                               
                                if (expr.Type.IsArray) {
                                        // If we are here, expr must be an ArrayAccess
                                        ArrayList idxs = new ArrayList();
@@ -4118,73 +4185,43 @@ namespace Mono.CSharp {
                                        // We can't resolve now, but we
                                        // have to try to access the array with a call
                                        // to LateIndexGet/Set in the runtime
-                                       Expression late_bound_call_expr;
+                                       Expression lig_call_expr;
 
                                        if (!is_left_hand)
-                                               late_bound_call_expr = Parser.DecomposeQI
-                                                       ("Microsoft.VisualBasic." +
-                                                        "CompilerServices.LateBinding." + 
-                                                        "LateIndexGet", Location.Null);
+                                               lig_call_expr = Mono.MonoBASIC.Parser.DecomposeQI("Microsoft.VisualBasic.CompilerServices.LateBinding.LateIndexGet", Location.Null);
                                        else
-                                               late_bound_call_expr = Parser.DecomposeQI
-                                                       ("Microsoft.VisualBasic." +
-                                                        "CompilerServices.LateBinding." + 
-                                                        "LateIndexSet", Location.Null);        
-                                       
+                                               lig_call_expr = Mono.MonoBASIC.Parser.DecomposeQI("Microsoft.VisualBasic.CompilerServices.LateBinding.LateIndexSet", Location.Null);
                                        Expression obj_type = Mono.MonoBASIC.Parser.DecomposeQI("System.Object", Location.Null);
                                        ArrayList adims = new ArrayList();
 
                                        ArrayList ainit = new ArrayList();
                                        foreach (Argument a in Arguments)
                                                ainit.Add ((Expression) a.Expr);
-                                       
-                                       if (!is_left_hand)
-                                               adims.Add ((Expression) new IntLiteral (Arguments.Count));
-                                       else
-                                       {
-                                               // We allocate one extra argument for the value 
-                                               // our late-bound target will be set to
-                                               adims.Add ((Expression) new IntLiteral (Arguments.Count + 1));
-                                               // This is only a placeholder to avoid an error
-                                               // to be flagged by the ArrayCreation process
-                                               ainit.Add ((Expression) NullLiteral.Null);      
-                                       }
+
+                                       adims.Add ((Expression) new IntLiteral (Arguments.Count));
 
                                        Expression oace = new ArrayCreation (obj_type, adims, "", ainit, Location.Null);
 
-                                       // Arguments passed to LateIndexGet
                                        ArrayList args = new ArrayList();
-                                       
-                                       // An array of basetype Object 
-                                       // containing the indices of the element being accessed
-                                       // or the arguments passed to the late-bound member
                                        args.Add (new Argument(expr, Argument.AType.Expression));
-                                       
-                                       // Our Expression
                                        args.Add (new Argument(oace, Argument.AType.Expression));
-                                       
-                                       // null
                                        args.Add (new Argument(NullLiteral.Null, Argument.AType.Expression));
 
-                                       Expression late_bound_call = new Invocation (late_bound_call_expr, args, Location.Null);
-                                       // If we're on the left hand side of an assignment
-                                       // we must return the unresolved expression
-                                       // in order to be able to modify the argument list
-                                       //if (!is_left_hand) {
-                                               expr_to_return = late_bound_call.Resolve(ec);
-                                               expr_to_return.eclass = ExprClass.Variable;
-                                       /*}
-                                       else
-                                       {
-                                               expr_to_return = late_bound_call;
-                                               expr_to_return.eclass = ExprClass.Variable;
-                                       }*/
+                                       Expression lig_call = new Invocation (lig_call_expr, args, Location.Null);
+                                       expr_to_return = lig_call.Resolve(ec);
+                                       expr_to_return.eclass = ExprClass.Variable;
                                }
                        }
 
                        return expr_to_return;
                }
 
+        static void Error_WrongNumArguments (Location loc, String name, int arg_count)
+        {
+            Report.Error (1501, loc, "No overload for method `" + name + "' takes `" +
+                                      arg_count + "' arguments");
+        }
+
                // <summary>
                //   Emits the list of arguments as an array
                // </summary>
@@ -4489,6 +4526,7 @@ namespace Mono.CSharp {
                //
                Expression value_target;
                bool value_target_set = false;
+               public bool isDelegate = false;
                
                public New (Expression requested_type, ArrayList arguments, Location l)
                {
@@ -4537,7 +4575,16 @@ namespace Mono.CSharp {
                
                public override Expression DoResolve (EmitContext ec)
                {
-                       type = ec.DeclSpace.ResolveType (RequestedType, false, loc);
+                       if (this.isDelegate) {
+                               // if its a delegate resolve the type of RequestedType first
+                               Expression dtype = RequestedType.Resolve(ec);
+                               string ts = (dtype.Type.ToString()).Replace ('+','.');
+                               dtype = Mono.MonoBASIC.Parser.DecomposeQI (ts, Location.Null);
+
+                               type = ec.DeclSpace.ResolveType (dtype, false, loc);
+                       }
+                       else
+                               type = ec.DeclSpace.ResolveType (RequestedType, false, loc);
                        
                        if (type == null)
                                return null;
@@ -4549,8 +4596,8 @@ namespace Mono.CSharp {
 
                        if (type.IsInterface || type.IsAbstract){
                                Error (
-                                       144, "It is not possible to create instances of interfaces " +
-                                       "or abstract classes");
+                                       30376, "It is not possible to create instances of Interfaces " +
+                                       "or classes marked as MustInherit");
                                return null;
                        }
                        
@@ -4689,7 +4736,7 @@ namespace Mono.CSharp {
        /// </remarks>
        public class ArrayCreation : ExpressionStatement {
                Expression requested_base_type;
-               public ArrayList initializers;
+               ArrayList initializers;
 
                //
                // The list of Argument types.
@@ -4766,7 +4813,7 @@ namespace Mono.CSharp {
 
                void Error_IncorrectArrayInitializer ()
                {
-                       Error (178, "Incorrectly structured array initializer");
+                       Error (30567, "Incorrectly structured array initializer");
                }
                
                public bool CheckIndices (EmitContext ec, ArrayList probe, int idx, bool specified_dims)
@@ -5590,7 +5637,7 @@ namespace Mono.CSharp {
                                return null;
 
                        if (!TypeManager.IsUnmanagedType (type_queried)){
-                               Report.Error (208, "Cannot take the size of an unmanaged type (" + TypeManager.CSharpName (type_queried) + ")");
+                               Report.Error (208, "Cannot take the size of an unmanaged type (" + TypeManager.MonoBASIC_Name (type_queried) + ")");
                                return null;
                        }
                        
@@ -5621,7 +5668,7 @@ namespace Mono.CSharp {
                public MemberAccess (Expression expr, string id, Location l)
                {
                        this.expr = expr;
-                       Identifier = (id == "New" ? ".ctor" : id);
+                       Identifier = id;
                        loc = l;
                }
 
@@ -5716,12 +5763,16 @@ namespace Mono.CSharp {
                                                Enum en = TypeManager.LookupEnum (decl_type);
 
                                                Constant c;
-                                               if (en != null)
+                                               if (en != null) {
                                                        c = Constantify (o, en.UnderlyingType);
-                                               else 
+                                                       return new EnumConstant (c, en.UnderlyingType);
+                                               }
+                                               else {
                                                        c = Constantify (o, enum_member.Type);
+                                                       return new EnumConstant (c, enum_member.Type);
+                                               }
+                                               
                                                
-                                               return new EnumConstant (c, decl_type);
                                        }
                                        
                                        Expression exp = Constantify (o, t);
@@ -5794,10 +5845,10 @@ namespace Mono.CSharp {
                                                if (IdenticalNameAndTypeName (ec, left_original, loc))
                                                        return member_lookup;
 
-                                               if (left_is_explicit) {
+                                               /*if (left_is_explicit) {
                                                        error176 (loc, me.Name);
                                                        return null;
-                                               }
+                                               }*/
                                        }
 
                                        //
@@ -5857,41 +5908,22 @@ namespace Mono.CSharp {
 
                        if (expr is SimpleName){
                                SimpleName child_expr = (SimpleName) expr;
-                               
+
                                Expression new_expr = new SimpleName (child_expr.Name + "." + Identifier, loc);
 
-                               return new_expr.Resolve (ec, flags);
+                               if ((flags & ResolveFlags.MaskExprClass) == ResolveFlags.Type)
+                                       return new_expr.Resolve (ec, flags);
+                               else
+                                       return new_expr.Resolve (ec, flags | ResolveFlags.MethodGroup | ResolveFlags.VariableOrValue);
                        }
                                        
-                       //
-                       // TODO: I mailed Ravi about this, and apparently we can get rid
-                       // of this and put it in the right place.
-                       // 
-                       // Handle enums here when they are in transit.
-                       // Note that we cannot afford to hit MemberLookup in this case because
-                       // it will fail to find any members at all
-                       //
-
                        int errors = Report.Errors;
                        
                        Type expr_type = expr.Type;
-                       if ((expr is TypeExpr) && (expr_type.IsSubclassOf (TypeManager.enum_type))){
-                               
-                               Enum en = TypeManager.LookupEnum (expr_type);
-                               
-                               if (en != null) {
-                                       object value = en.LookupEnumValue (ec, Identifier, loc);
-
-                                       if (value != null){
-                                               Constant c = Constantify (value, en.UnderlyingType);
-                                               return new EnumConstant (c, expr_type);
-                                       }
-                               }
-                       }
 
                        if (expr_type.IsPointer){
                                Error (23, "The '.' operator can not be applied to pointer operands (" +
-                                      TypeManager.CSharpName (expr_type) + ")");
+                                      TypeManager.MonoBASIC_Name (expr_type) + ")");
                                return null;
                        }
 
@@ -5902,7 +5934,7 @@ namespace Mono.CSharp {
                                // Error has already been reported.
                                if (errors < Report.Errors)
                                        return null;
-
+                               
                                //
                                // Try looking the member up from the same type, if we find
                                // it, we know that the error was due to limited visibility
@@ -5912,7 +5944,7 @@ namespace Mono.CSharp {
                                        BindingFlags.NonPublic, Identifier);
                                        
                                if (lookup == null)
-                                       Error (117, "'" + expr_type + "' does not contain a definition for '" + Identifier + "'");
+                                       Error (30456, "'" + expr_type + "' does not contain a definition for '" + Identifier + "'");
                                else
                                {
                                        if ((expr_type != ec.ContainerType) &&
@@ -5932,21 +5964,35 @@ namespace Mono.CSharp {
                                                if (lookup != null)
                                                        Error (1540, "Cannot access protected member '" +
                                                       expr_type + "." + Identifier + "' " +
-                                                      "via a qualifier of type '" + TypeManager.CSharpName (expr_type) + "'; the " +
-                                                      "qualifier must be of type '" + TypeManager.CSharpName (ec.ContainerType) + "' " +
+                                                      "via a qualifier of type '" + TypeManager.MonoBASIC_Name (expr_type) + "'; the " +
+                                                      "qualifier must be of type '" + TypeManager.MonoBASIC_Name (ec.ContainerType) + "' " +
                                                       "(or derived from it)");
                                                else
-                                                       Error (122, "'" + expr_type + "." + Identifier + "' " +
+                                                       Error (30390, "'" + expr_type + "." + Identifier + "' " +
                                                       "is inaccessible because of its protection level");
                                        } else
-                                               Error (122, "'" + expr_type + "." + Identifier + "' " +
+                                               Error (30390, "'" + expr_type + "." + Identifier + "' " +
                                               "is inaccessible because of its protection level");
                                }  
                                return null;
                        }
 
+                       if ((expr is TypeExpr) && (expr_type.IsSubclassOf (TypeManager.enum_type)))     {
+                               Enum en = TypeManager.LookupEnum (expr_type);
+                               
+                               if (en != null) {
+                                       object value = en.LookupEnumValue (ec, Identifier, loc);
+                                       expr_type = TypeManager.int32_type;
+                                       if (value != null) {
+                                               Constant c = Constantify (value, en.UnderlyingType);
+                                               return new EnumConstant (c, en.UnderlyingType);
+                                       }
+                               }
+                       }
+
                        if (member_lookup is TypeExpr){
                                member_lookup.Resolve (ec, ResolveFlags.Type);
+
                                return member_lookup;
                        } else if ((flags & ResolveFlags.MaskExprClass) == ResolveFlags.Type)
                                return null;
@@ -5957,7 +6003,6 @@ namespace Mono.CSharp {
 
                        // The following DoResolve/DoResolveLValue will do the definite assignment
                        // check.
-
                        if (right_side != null)
                                member_lookup = member_lookup.DoResolveLValue (ec, right_side);
                        else
@@ -6625,7 +6670,7 @@ namespace Mono.CSharp {
                        }
 
                        Report.Error (21, loc,
-                                     "Type '" + TypeManager.CSharpName (lookup_type) +
+                                     "Type '" + TypeManager.MonoBASIC_Name (lookup_type) +
                                      "' does not have any indexers defined");
                        return null;
                }
@@ -6729,7 +6774,7 @@ namespace Mono.CSharp {
                        }
                        
                        if (set == null){
-                               Error (200, "indexer X.this [" + TypeManager.CSharpName (right_type) +
+                               Error (200, "indexer X.this [" + TypeManager.MonoBASIC_Name (right_type) +
                                       "] lacks a 'set' accessor");
                                return null;
                        }
@@ -6778,7 +6823,7 @@ namespace Mono.CSharp {
                                Error (1511, "Keyword MyBase is not allowed in static method");
                                return null;
                        }
-
+                       
                        if (member == "New")
                                member = ".ctor";
                        
@@ -6786,8 +6831,8 @@ namespace Mono.CSharp {
                                                      AllMemberTypes, AllBindingFlags, loc);
 
                        if (member_lookup == null) {
-                               Error (117,
-                                             TypeManager.CSharpName (base_type) + " does not " +
+                               Error (30456,
+                                             TypeManager.MonoBASIC_Name (base_type) + " does not " +
                                              "contain a definition for '" + member + "'");
                                return null;
                        }