}
if (v == null) {
- if (TypeManager.IsNullableType (t))
+ if (t.IsNullableType)
return Nullable.LiftedNull.Create (t, loc);
if (TypeManager.IsReferenceType (t))
public override void Emit (EmitContext ec)
{
+ MethodSpec m;
+
int [] words = decimal.GetBits (Value);
int power = (words [3] >> 16) & 0xff;
if (power == 0) {
if (Value <= int.MaxValue && Value >= int.MinValue) {
- if (TypeManager.void_decimal_ctor_int_arg == null) {
- TypeManager.void_decimal_ctor_int_arg = TypeManager.GetPredefinedConstructor (
- type, loc, ec.BuildinTypes.Int);
-
- if (TypeManager.void_decimal_ctor_int_arg == null)
- return;
+ m = ec.Module.PredefinedMembers.DecimalCtorInt.Resolve (loc);
+ if (m == null) {
+ return;
}
ec.EmitInt ((int) Value);
- ec.Emit (OpCodes.Newobj, TypeManager.void_decimal_ctor_int_arg);
+ ec.Emit (OpCodes.Newobj, m);
return;
}
if (Value <= long.MaxValue && Value >= long.MinValue) {
- if (TypeManager.void_decimal_ctor_long_arg == null) {
- TypeManager.void_decimal_ctor_long_arg = TypeManager.GetPredefinedConstructor (
- type, loc, ec.BuildinTypes.Long);
-
- if (TypeManager.void_decimal_ctor_long_arg == null)
- return;
+ m = ec.Module.PredefinedMembers.DecimalCtorLong.Resolve (loc);
+ if (m == null) {
+ return;
}
ec.EmitLong ((long) Value);
- ec.Emit (OpCodes.Newobj, TypeManager.void_decimal_ctor_long_arg);
+ ec.Emit (OpCodes.Newobj, m);
return;
}
}
// power
ec.EmitInt (power);
- if (TypeManager.void_decimal_ctor_five_args == null) {
- TypeManager.void_decimal_ctor_five_args = TypeManager.GetPredefinedConstructor (
- type, loc, ec.BuildinTypes.Int, ec.BuildinTypes.Int,
- ec.BuildinTypes.Int, ec.BuildinTypes.Bool, ec.BuildinTypes.Byte);
-
- if (TypeManager.void_decimal_ctor_five_args == null)
- return;
+ m = ec.Module.PredefinedMembers.DecimalCtor.Resolve (loc);
+ if (m != null) {
+ ec.Emit (OpCodes.Newobj, m);
}
-
- ec.Emit (OpCodes.Newobj, TypeManager.void_decimal_ctor_five_args);
}
public override bool IsDefaultValue {
if (Value.Length == 0 && ec.Module.Compiler.Settings.Optimize) {
var string_type = ec.BuildinTypes.String;
if (ec.CurrentType != string_type) {
- if (TypeManager.string_empty == null)
- TypeManager.string_empty = TypeManager.GetPredefinedField (string_type, "Empty", loc, string_type);
-
- if (TypeManager.string_empty != null) {
- ec.Emit (OpCodes.Ldsfld, TypeManager.string_empty);
+ var m = ec.Module.PredefinedMembers.StringEmpty.Get ();
+ if (m != null) {
+ ec.Emit (OpCodes.Ldsfld, m);
return;
}
}
public override Expression CreateExpressionTree (ResolveContext ec)
{
- if (type == InternalType.Null || type.BuildinType == BuildinTypeSpec.Type.Object) {
+ if (type == InternalType.NullLiteral || type.BuildinType == BuildinTypeSpec.Type.Object) {
// Optimized version, also avoids referencing literal internal type
Arguments args = new Arguments (1);
args.Add (new Argument (this));
public override void EncodeAttributeValue (IMemberContext rc, AttributeEncoder enc, TypeSpec targetType)
{
// Type it as string cast
- if (targetType.BuildinType == BuildinTypeSpec.Type.Object || targetType == InternalType.Null)
+ if (targetType.BuildinType == BuildinTypeSpec.Type.Object)
enc.Encode (rc.Module.Compiler.BuildinTypes.String);
var ac = targetType as ArrayContainer;
ec.Emit (OpCodes.Ldnull);
// Only to make verifier happy
- if (TypeManager.IsGenericParameter (type))
+ if (type.IsGenericParameter)
ec.Emit (OpCodes.Unbox_Any, type);
}
{
if (targetType.IsPointer) {
if (IsLiteral || this is NullPointer)
- return new EmptyConstantCast (new NullPointer (loc), targetType);
+ return new NullPointer (targetType, loc);
return null;
}
// Exlude internal compiler types
- if (targetType.Kind == MemberKind.InternalCompilerType && targetType.BuildinType != BuildinTypeSpec.Type.Dynamic && targetType != InternalType.Null)
+ if (targetType.Kind == MemberKind.InternalCompilerType && targetType.BuildinType != BuildinTypeSpec.Type.Dynamic)
return null;
if (!IsLiteral && !Convert.ImplicitStandardConversionExists (this, targetType))
if (TypeManager.IsReferenceType (targetType))
return new NullConstant (targetType, loc);
- if (TypeManager.IsNullableType (targetType))
+ if (targetType.IsNullableType)
return Nullable.LiftedNull.Create (targetType, loc);
return null;
}
}
+
+ //
+ // A null constant in a pointer context
+ //
+ class NullPointer : NullConstant
+ {
+ public NullPointer (TypeSpec type, Location loc)
+ : base (type, loc)
+ {
+ }
+
+ public override Expression CreateExpressionTree (ResolveContext ec)
+ {
+ Error_PointerInsideExpressionTree (ec);
+ return base.CreateExpressionTree (ec);
+ }
+
+ public override void Emit (EmitContext ec)
+ {
+ //
+ // Emits null pointer
+ //
+ ec.Emit (OpCodes.Ldc_I4_0);
+ ec.Emit (OpCodes.Conv_U);
+ }
+ }
+
/// <summary>
/// The value is constant, but when emitted has a side effect. This is
/// used by BitwiseAnd to ensure that the second expression is invoked