}
- public abstract class NullConstant : Constant
+ public class NullConstant : Constant
{
public NullConstant (Location loc):
base (loc)
{
eclass = ExprClass.Value;
+ type = TypeManager.null_type;
}
override public string AsString ()
{
ec.ig.Emit(OpCodes.Ldnull);
}
+
+ public override string ExprClassName {
+ get {
+ return GetSignatureForError ();
+ }
+ }
public override string GetSignatureForError ()
{
get { return false; }
}
+ public override bool IsNull {
+ get { return true; }
+ }
+
public override bool IsZeroInteger
{
get { return true; }
}
- public override Constant Reduce(bool inCheckedContext, Type target_type)
+ public override Constant ConvertExplicitly(bool inCheckedContext, Type target_type)
{
if (!TypeManager.IsValueType (target_type))
return new EmptyConstantCast (this, target_type);
return null;
}
- public override Constant ToType(Type targetType)
+ public override Constant ConvertImplicitly (Type targetType)
{
if (!TypeManager.IsValueType (targetType))
return new EmptyConstantCast (this, targetType);
{
}
- public override void Error_ValueCannotBeConverted (Location loc, Type target, bool expl)
+ public override void Error_ValueCannotBeConverted (EmitContext ec, Location loc, Type target, bool expl)
{
- base.Error_ValueCannotBeConverted(loc, target, expl);
+ base.Error_ValueCannotBeConverted (ec, loc, target, expl);
}
}
return this;
}
- public override void Error_ValueCannotBeConverted (Location loc, Type t, bool expl)
+ public override void Error_ValueCannotBeConverted (EmitContext ec, Location loc, Type t, bool expl)
{
if (TypeManager.IsGenericParameter (t)) {
Report.Error(403, loc,
- "Cannot convert null to the type parameter `{0}' becaues it could be a value " +
+ "Cannot convert null to the type parameter `{0}' because it could be a value " +
"type. Consider using `default ({0})' instead", t.Name);
} else {
Report.Error(37, loc, "Cannot convert null to `{0}' because it is a value type",
}
}
- public override Constant ToType (Type targetType)
+ public override Constant ConvertImplicitly (Type targetType)
{
if (targetType.IsPointer)
return new EmptyConstantCast (NullPointer.Null, targetType);
if (gc != null && gc.IsReferenceType)
return new EmptyConstantCast (this, targetType);
- Error_ValueCannotBeConverted (loc, targetType, false);
return null;
}
- return base.ToType(targetType);
+ return base.ConvertImplicitly(targetType);
}
}
// A null literal in a pointer context
//
public class NullPointer : NullLiteral {
- public static readonly NullLiteral Null;
-
- static NullPointer ()
- {
- Null = new NullPointer ();
- }
+ public static readonly NullLiteral Null = new NullPointer ();
private NullPointer ():
base (Location.Null)
type = TypeManager.int32_type;
return this;
}
+
+ public override Constant ConvertImplicitly (Type type)
+ {
+ ///
+ /// The 0 literal can be converted to an enum value,
+ ///
+ if (Value == 0 && TypeManager.IsEnumType (type)) {
+ Constant c = ConvertImplicitly (TypeManager.EnumToUnderlying (type));
+ if (c == null)
+ return null;
+
+ return new EnumConstant (c, type);
+ }
+ return base.ConvertImplicitly (type);
+ }
+
}
public class UIntLiteral : UIntConstant {
return this;
}
- public override void Error_ValueCannotBeConverted (Location loc, Type target, bool expl)
+ public override void Error_ValueCannotBeConverted (EmitContext ec, Location loc, Type target, bool expl)
{
if (target == TypeManager.float_type) {
Error_664 (loc, "float", "f");
return;
}
- base.Error_ValueCannotBeConverted (loc, target, expl);
+ base.Error_ValueCannotBeConverted (ec, loc, target, expl);
}
static void Error_664 (Location loc, string type, string suffix)