-2004-10-10 Miguel de Icaza <miguel@ximian.com>
-
- * expression.cs (MemberAccess.ResolveMemberAccess): When looking
- up a constant, do not use the "Const" object after LookupConstant,
- instead use the result that is returned in the `out' parameter
- that already has the GetValue done. Fixes the corlib regression,
- and removes duplicated code.
-
-2004-10-09 Miguel de Icaza <miguel@ximian.com>
-
- * const.cs (ConvertExpressionToConstant): Refactor code that does
- the Expression to Constant checking. This can be used in other
- places in the compiler that need to go from an Expression that
- wraps a Constant (like the casts) to a Constant.
-
- * ecore.cs (Expression.ConvertIntLiteral): If we got enumerations,
- unfold those into the underlying types before testing for the
- ImplicitConversions, as that code wont cope with casts from
- enumerations to constants.
-
- * statement.cs (SwitchLabel.ResolveAndReduce): Reuse
- ConvertExpressionToConstant.
-
2004-10-07 Raja R Harinath <rharinath@novell.com>
More DeclSpace.ResolveType avoidance.
return retval;
}
-
- static void ReportConstantError (Location loc, string opt_name)
- {
- if (opt_name != null)
- Report.Error (133, loc, String.Format ("The expression being assigned to `{0}' must be constant"));
- else
- Report.Error (150, loc, "A constant value is expected");
- }
-
- public static Constant ConvertExpressionToConstant (Expression expr, Location loc, bool show_errors, string opt_name)
- {
- Constant ce = expr as Constant;
- if (ce == null){
- UnCheckedExpr un_expr = expr as UnCheckedExpr;
- CheckedExpr ch_expr = expr as CheckedExpr;
- EmptyCast ec_expr = expr as EmptyCast;
-
- if ((un_expr != null) && (un_expr.Expr is Constant))
- expr = un_expr.Expr;
- else if ((ch_expr != null) && (ch_expr.Expr is Constant))
- expr = ch_expr.Expr;
- else if ((ec_expr != null) && (ec_expr.Child is Constant))
- expr = ec_expr.Child;
- else if (expr is ArrayCreation){
- if (show_errors)
- Report.Error (133, loc, "Arrays can not be constant");
- } else {
- if (show_errors)
- ReportConstantError (loc, opt_name);
- return null;
- }
-
- ce = expr as Constant;
- if (ce == null){
- if (show_errors)
- ReportConstantError (loc, opt_name);
- }
- }
- return ce;
- }
/// <summary>
/// Looks up the value of a constant field. Defines it if it hasn't
Expression real_expr = Expr;
- Constant ce = ConvertExpressionToConstant (Expr, Location, errors == Report.Errors, null);
+ Constant ce = Expr as Constant;
if (ce == null){
- value = null;
- return false;
+ UnCheckedExpr un_expr = Expr as UnCheckedExpr;
+ CheckedExpr ch_expr = Expr as CheckedExpr;
+ EmptyCast ec_expr = Expr as EmptyCast;
+
+ if ((un_expr != null) && (un_expr.Expr is Constant))
+ Expr = un_expr.Expr;
+ else if ((ch_expr != null) && (ch_expr.Expr is Constant))
+ Expr = ch_expr.Expr;
+ else if ((ec_expr != null) && (ec_expr.Child is Constant))
+ Expr = ec_expr.Child;
+ else if (Expr is ArrayCreation){
+ Report.Error (133, Location, "Arrays can not be constant");
+ } else {
+ if (errors == Report.Errors)
+ Report.Error (150, Location, "A constant value is expected");
+ value = null;
+ return false;
+ }
+
+ ce = Expr as Constant;
}
-
+
if (MemberType != real_expr.Type) {
ce = ChangeType (Location, ce, MemberType);
if (ce == null){
/// </summary>
public static object ConvertIntLiteral (Constant c, Type target_type, Location loc)
{
- if (TypeManager.IsEnumType (target_type))
- target_type = TypeManager.EnumToUnderlying (target_type);
-
- //
- // Make into one of the literals we handle, we dont really care
- // about this value as we will just return a few limited types
- //
- if (c is EnumConstant)
- c = ((EnumConstant)c).WidenToCompilerConstant ();
-
if (!Convert.ImplicitStandardConversionExists (c, target_type)){
Convert.Error_CannotImplicitConversion (loc, c.Type, target_type);
return null;
if (c.Type == target_type)
return ((Constant) c).GetValue ();
+ //
+ // Make into one of the literals we handle, we dont really care
+ // about this value as we will just return a few limited types
+ //
+ if (c is EnumConstant)
+ c = ((EnumConstant)c).WidenToCompilerConstant ();
if (c is IntConstant){
int v = ((IntConstant) c).Value;
return null;
}
expr = Convert.ExplicitConversion (ec, expr, type, loc);
-
return expr;
}
if (!c.LookupConstantValue (out o))
return null;
- return Constantify (o, fi.FieldType);
+ object real_value = ((Constant) c.Expr).GetValue ();
+
+ return Constantify (real_value, fi.FieldType);
}
}
if (e == null)
return false;
- Expression ee = e as Constant;
- if (ee == null)
- ee = Const.ConvertExpressionToConstant (e, loc, true, null);
- if (ee == null){
+ if (!(e is Constant)){
Report.Error (150, loc, "A constant value is expected, got: " + e);
return false;
}
- e = ee;
if (e is StringConstant || e is NullLiteral){
if (required_type == TypeManager.string_type){