compose sample
[mono.git] / mcs / mbas / expression.cs
index fc024f9e84e860724382112346efd28655f322d6..9d4e36f72f9c9d14cfa368b517fc4b14719c8ea0 100644 (file)
@@ -9,7 +9,7 @@
 //
 #define USE_OLD
 
-namespace Mono.CSharp {
+namespace Mono.MonoBASIC {
        using System;
        using System.Collections;
        using System.Reflection;
@@ -143,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>
@@ -484,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;
                }
 
@@ -692,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>
@@ -781,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;
                }
 
@@ -1074,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) + "'");
                                }
                        }
 
@@ -1113,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)
@@ -1130,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;
                        
                        }
@@ -1647,8 +1647,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)
                                + "'");
                }
 
@@ -1814,8 +1814,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 ()
@@ -2752,8 +2752,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;
                                        }
@@ -2765,8 +2765,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;
                                }
                        }
@@ -3422,7 +3422,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);
@@ -4052,8 +4052,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;
                                }
 
@@ -4525,8 +4525,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;
                        }
                        
@@ -4742,7 +4742,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)
@@ -5566,7 +5566,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;
                        }
                        
@@ -5692,12 +5692,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);
@@ -5770,10 +5774,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;
-                                               }
+                                               }*/
                                        }
 
                                        //
@@ -5839,35 +5843,13 @@ namespace Mono.CSharp {
                                return new_expr.Resolve (ec, flags);
                        }
                                        
-                       //
-                       // 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;
                        }
 
@@ -5888,7 +5870,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) &&
@@ -5908,21 +5890,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;
@@ -5933,7 +5929,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
@@ -6601,7 +6596,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;
                }
@@ -6705,7 +6700,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;
                        }
@@ -6762,8 +6757,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;
                        }