this.loc = loc;
}
- /// <remarks>
- /// This is different from ToString in that ToString
- /// is supposed to be there for debugging purposes,
- /// and is not guaranteed to be useful for anything else,
- /// AsString() will provide something that can be used
- /// for round-tripping C# code. Maybe it can be used
- /// for IL assembly as well.
- /// </remarks>
- public abstract string AsString ();
-
override public string ToString ()
{
- return this.GetType ().Name + " (" + AsString () + ")";
+ return this.GetType ().Name + " (" + GetValueAsLiteral () + ")";
}
/// <summary>
/// </summary>
public abstract object GetValue ();
+ public abstract string GetValueAsLiteral ();
+
#if !STATIC
//
// Returns an object value which is typed to contant type
(TypeManager.IsPrimitiveType (target) || type == TypeManager.decimal_type) &&
(TypeManager.IsPrimitiveType (type) || type == TypeManager.decimal_type)) {
ec.Report.Error (31, loc, "Constant value `{0}' cannot be converted to a `{1}'",
- AsString (), TypeManager.CSharpName (target));
+ GetValueAsLiteral (), TypeManager.CSharpName (target));
} else {
base.Error_ValueCannotBeConverted (ec, loc, target, expl);
}
return TryReduce (ec, target_type);
}
catch (OverflowException) {
- if (ec.ConstantCheckState) {
- ec.Report.Error (221, loc, "Constant value `{0}' cannot be converted to a `{1}' (use `unchecked' syntax to override)",
- GetValue ().ToString (), TypeManager.CSharpName (target_type));
+ if (ec.ConstantCheckState && Type.BuildinType != BuildinTypeSpec.Type.Decimal) {
+ ec.Report.Error (221, loc,
+ "Constant value `{0}' cannot be converted to a `{1}' (use `unchecked' syntax to override)",
+ GetValueAsLiteral (), target_type.GetSignatureForError ());
} else {
Error_ValueCannotBeConverted (ec, loc, target_type, false);
}
GetValue ().ToString (), TypeManager.CSharpName (target));
}
}
+
+ public override string GetValueAsLiteral ()
+ {
+ return GetValue ().ToString ();
+ }
public abstract Constant Increment ();
}
Value = val;
}
- override public string AsString ()
- {
- return Value ? "true" : "false";
- }
-
protected override Expression DoResolve (ResolveContext ec)
{
type = TypeManager.bool_type;
return (object) Value;
}
+ public override string GetValueAsLiteral ()
+ {
+ return Value ? "true" : "false";
+ }
+
public override void EncodeAttributeValue (IMemberContext rc, AttributeEncoder enc, TypeSpec targetType)
{
enc.Encode (Value);
ec.EmitInt (Value);
}
- public override string AsString ()
- {
- return Value.ToString ();
- }
-
protected override Expression DoResolve (ResolveContext ec)
{
type = TypeManager.byte_type;
return c.ToString ();
}
- public override string AsString ()
+ public override object GetValue ()
{
- return "\"" + descape (Value) + "\"";
+ return Value;
}
- public override object GetValue ()
+ public override string GetValueAsLiteral ()
{
- return Value;
+ return "\"" + descape (Value) + "\"";
}
public override bool IsDefaultValue {
ec.EmitInt (Value);
}
- public override string AsString ()
- {
- return Value.ToString ();
- }
-
public override object GetValue ()
{
return Value;
ec.EmitInt (Value);
}
- public override string AsString ()
- {
- return Value.ToString ();
- }
-
public override object GetValue ()
{
return Value;
ec.EmitInt (Value);
}
- public override string AsString ()
- {
- return Value.ToString ();
- }
-
public override object GetValue ()
{
return Value;
ec.EmitInt (Value);
}
- public override string AsString ()
- {
- return Value.ToString ();
- }
-
public override object GetValue ()
{
return Value;
ec.EmitInt (unchecked ((int) Value));
}
- public override string AsString ()
- {
- return Value.ToString ();
- }
-
public override object GetValue ()
{
return Value;
{
if (target_type == TypeManager.byte_type) {
if (in_checked_context){
- if (Value < Char.MinValue || Value > Char.MaxValue)
+ if (Value < 0 || Value > byte.MaxValue)
throw new OverflowException ();
}
return new ByteConstant ((byte) Value, Location);
ec.EmitLong (Value);
}
- public override string AsString ()
- {
- return Value.ToString ();
- }
-
public override object GetValue ()
{
return Value;
ec.EmitLong (unchecked ((long) Value));
}
- public override string AsString ()
- {
- return Value.ToString ();
- }
-
public override object GetValue ()
{
return Value;
ec.Emit (OpCodes.Ldc_R4, Value);
}
- public override string AsString ()
+ public override object GetValue ()
{
- return Value.ToString ();
+ return Value;
}
- public override object GetValue ()
+ public override string GetValueAsLiteral ()
{
- return Value;
+ return Value.ToString ();
}
public override bool IsDefaultValue {
ec.Emit (OpCodes.Ldc_R8, Value);
}
- public override string AsString ()
+ public override object GetValue ()
{
- return Value.ToString ();
+ return Value;
}
- public override object GetValue ()
+ public override string GetValueAsLiteral ()
{
- return Value;
+ return Value.ToString ();
}
public override bool IsDefaultValue {
Value = d;
}
- override public string AsString ()
- {
- return Value.ToString () + "M";
- }
-
protected override Expression DoResolve (ResolveContext rc)
{
type = TypeManager.decimal_type;
public override object GetValue ()
{
- return (object) Value;
+ return Value;
+ }
+
+ public override string GetValueAsLiteral ()
+ {
+ return Value.ToString () + "M";
}
public override void Emit (EmitContext ec)
Value = s;
}
- // FIXME: Escape the string.
- override public string AsString ()
- {
- return "\"" + Value + "\"";
- }
-
protected override Expression DoResolve (ResolveContext rc)
{
type = TypeManager.string_type;
{
return Value;
}
+
+ public override string GetValueAsLiteral ()
+ {
+ // FIXME: Escape the string.
+ return "\"" + Value + "\"";
+ }
public override void Emit (EmitContext ec)
{
this.type = type;
}
- public override string AsString ()
- {
- return GetSignatureForError ();
- }
-
public override Expression CreateExpressionTree (ResolveContext ec)
{
if (type == InternalType.Null || type == TypeManager.object_type) {
}
}
- public override string GetSignatureForError ()
- {
- return "null";
- }
-
public override Constant ConvertExplicitly (bool inCheckedContext, TypeSpec targetType)
{
if (targetType.IsPointer) {
return ConvertExplicitly (false, targetType);
}
+ public override string GetSignatureForError ()
+ {
+ return "null";
+ }
+
public override object GetValue ()
{
return null;
}
+ public override string GetValueAsLiteral ()
+ {
+ return GetSignatureForError ();
+ }
+
public override bool IsDefaultValue {
get { return true; }
}
this.side_effect = side_effect;
}
- public override string AsString ()
- {
- return value.AsString ();
- }
-
protected override Expression DoResolve (ResolveContext rc)
{
value = value.Resolve (rc);
return value.GetValue ();
}
+ public override string GetValueAsLiteral ()
+ {
+ return value.GetValueAsLiteral ();
+ }
+
public override void Emit (EmitContext ec)
{
side_effect.EmitSideEffect (ec);