// Miguel de Icaza (miguel@ximian.com)
// Marek Safar (marek.safar@seznam.cz)
//
-// (C) 2001 Ximian, Inc.
+// Copyright 2001 Ximian, Inc.
//
//
// Notice that during parsing we create objects of type Literal, but the
public override Expression CreateExpressionTree (EmitContext ec)
{
+ // HACK: change type to be object
type = TypeManager.object_type;
return base.CreateExpressionTree (ec);
}
}
}
- public override Constant ConvertImplicitly (Type targetType)
+ public override Constant ConvertExplicitly (bool inCheckedContext, Type targetType)
{
if (targetType.IsPointer)
- return new EmptyConstantCast (NullPointer.Null, targetType);
+ return new EmptyConstantCast (new NullPointer (loc), targetType);
+
+ // Exlude internal compiler types
+ if (targetType == TypeManager.anonymous_method_type)
+ return null;
if (TypeManager.IsReferenceType (targetType))
return new EmptyConstantCast (this, targetType);
return null;
}
+ public override Constant ConvertImplicitly (Type targetType)
+ {
+ //
+ // Null literal is of object type
+ //
+ if (targetType == TypeManager.object_type)
+ return this;
+
+ return ConvertExplicitly (false, targetType);
+ }
+
public override object GetValue ()
{
return null;
get { return true; }
}
- public override bool IsNegative
- {
+ public override bool IsLiteral {
+ get { return true; }
+ }
+
+ public override bool IsNegative {
get { return false; }
}
get { return true; }
}
- public override bool IsZeroInteger
- {
+ public override bool IsZeroInteger {
get { return true; }
}
-
- public override Constant ConvertExplicitly(bool inCheckedContext, Type target_type)
- {
- if (!TypeManager.IsValueType (target_type))
- return new EmptyConstantCast (this, target_type);
-
- return null;
- }
}
//
// A null literal in a pointer context
//
public class NullPointer : NullLiteral {
- public static readonly NullLiteral Null = new NullPointer ();
-
- private NullPointer ():
- base (Location.Null)
+ public NullPointer (Location loc):
+ base (loc)
{
type = TypeManager.object_type;
}
{
ILGenerator ig = ec.ig;
- // TODO: why not use Ldnull instead ?
+ //
+ // Emits null pointer
+ //
ig.Emit (OpCodes.Ldc_I4_0);
ig.Emit (OpCodes.Conv_U);
}
type = TypeManager.bool_type;
return this;
}
+
+ public override bool IsLiteral {
+ get { return true; }
+ }
}
public class CharLiteral : CharConstant {
type = TypeManager.char_type;
return this;
}
+
+ public override bool IsLiteral {
+ get { return true; }
+ }
}
public class IntLiteral : IntConstant {
return base.ConvertImplicitly (type);
}
+ public override bool IsLiteral {
+ get { return true; }
+ }
}
public class UIntLiteral : UIntConstant {
type = TypeManager.uint32_type;
return this;
}
+
+ public override bool IsLiteral {
+ get { return true; }
+ }
}
public class LongLiteral : LongConstant {
public override Expression DoResolve (EmitContext ec)
{
type = TypeManager.int64_type;
-
return this;
}
+
+ public override bool IsLiteral {
+ get { return true; }
+ }
}
public class ULongLiteral : ULongConstant {
type = TypeManager.uint64_type;
return this;
}
+
+ public override bool IsLiteral {
+ get { return true; }
+ }
}
public class FloatLiteral : FloatConstant {
type = TypeManager.float_type;
return this;
}
+
+ public override bool IsLiteral {
+ get { return true; }
+ }
+
}
public class DoubleLiteral : DoubleConstant {
"Literal of type double cannot be implicitly converted to type `{0}'. Add suffix `{1}' to create a literal of this type",
type, suffix);
}
+
+ public override bool IsLiteral {
+ get { return true; }
+ }
+
}
public class DecimalLiteral : DecimalConstant {
type = TypeManager.decimal_type;
return this;
}
+
+ public override bool IsLiteral {
+ get { return true; }
+ }
}
public class StringLiteral : StringConstant {
return this;
}
+
+ public override bool IsLiteral {
+ get { return true; }
+ }
+
}
}