return c;
}
+ public override bool ContainsEmitWithAwait ()
+ {
+ return false;
+ }
+
public virtual Constant ConvertImplicitly (TypeSpec type)
{
if (this.type == type)
if (t.IsNullableType)
return Nullable.LiftedNull.Create (t, loc);
- if (TypeManager.IsReferenceType (t))
+ if (TypeSpec.IsReferenceType (t))
return new NullConstant (t, loc);
}
{
Arguments args = new Arguments (2);
args.Add (new Argument (this));
- args.Add (new Argument (new TypeOf (new TypeExpression (type, loc), loc)));
+ args.Add (new Argument (new TypeOf (type, loc)));
return CreateExpressionFactoryCall (ec, "Constant", args);
}
public virtual bool IsOneInteger {
get { return false; }
- }
+ }
+
+ public override bool IsSideEffectFree {
+ get {
+ return true;
+ }
+ }
//
// Returns true iff 1) the stack type of this is one of Object,
public override void Emit (EmitContext ec)
{
if (Value)
- ec.Emit (OpCodes.Ldc_I4_1);
+ ec.EmitInt (1);
else
- ec.Emit (OpCodes.Ldc_I4_0);
+ ec.EmitInt (0);
}
public override bool IsDefaultValue {
public override void Emit (EmitContext ec)
{
if (Value == null) {
- ec.Emit (OpCodes.Ldnull);
+ ec.EmitNull ();
return;
}
public override void EncodeAttributeValue (IMemberContext rc, AttributeEncoder enc, TypeSpec targetType)
{
- // Type it as string cast
- if (targetType.BuiltinType == BuiltinTypeSpec.Type.Object)
+ switch (targetType.BuiltinType) {
+ case BuiltinTypeSpec.Type.Object:
+ // Type it as string cast
enc.Encode (rc.Module.Compiler.BuiltinTypes.String);
-
- var ac = targetType as ArrayContainer;
- if (ac != null) {
- if (ac.Rank != 1 || ac.Element.IsArray)
- base.EncodeAttributeValue (rc, enc, targetType);
- else
- enc.Encode (uint.MaxValue);
- } else {
+ goto case BuiltinTypeSpec.Type.String;
+ case BuiltinTypeSpec.Type.String:
+ case BuiltinTypeSpec.Type.Type:
enc.Encode (byte.MaxValue);
+ return;
+ default:
+ var ac = targetType as ArrayContainer;
+ if (ac != null && ac.Rank == 1 && !ac.Element.IsArray) {
+ enc.Encode (uint.MaxValue);
+ return;
+ }
+
+ break;
}
+
+ base.EncodeAttributeValue (rc, enc, targetType);
}
public override void Emit (EmitContext ec)
{
- ec.Emit (OpCodes.Ldnull);
+ ec.EmitNull ();
// Only to make verifier happy
if (type.IsGenericParameter)
if (!IsLiteral && !Convert.ImplicitStandardConversionExists (this, targetType))
return null;
- if (TypeManager.IsReferenceType (targetType))
+ if (TypeSpec.IsReferenceType (targetType))
return new NullConstant (targetType, loc);
if (targetType.IsNullableType)
//
// Emits null pointer
//
- ec.Emit (OpCodes.Ldc_I4_0);
+ ec.EmitInt (0);
ec.Emit (OpCodes.Conv_U);
}
}
/// used by BitwiseAnd to ensure that the second expression is invoked
/// regardless of the value of the left side.
/// </summary>
- public class SideEffectConstant : Constant {
+ public class SideEffectConstant : Constant
+ {
public readonly Constant value;
Expression side_effect;
this.side_effect = side_effect;
}
+ public override bool IsSideEffectFree {
+ get {
+ return false;
+ }
+ }
+
public override object GetValue ()
{
return value.GetValue ();