[xbuild] Set ProjectFile and TargetName metadata on target outputs.
[mono.git] / mcs / mcs / constant.cs
index 73108a2d924c4939f72c3e85f2a730be0c815877..d16e844d5920ddbed58d104da25055d308b45be7 100644 (file)
@@ -147,7 +147,7 @@ namespace Mono.CSharp {
                        }
 
                        if (v == null) {
-                               if (TypeManager.IsNullableType (t))
+                               if (t.IsNullableType)
                                        return Nullable.LiftedNull.Create (t, loc);
 
                                if (TypeManager.IsReferenceType (t))
@@ -1800,35 +1800,31 @@ namespace Mono.CSharp {
 
                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;
                                }
                        }
@@ -1843,16 +1839,10 @@ namespace Mono.CSharp {
                        // 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 {
@@ -1960,11 +1950,9 @@ namespace Mono.CSharp {
                        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;
                                        }
                                }
@@ -2020,7 +2008,7 @@ namespace Mono.CSharp {
 
                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));
@@ -2033,7 +2021,7 @@ namespace Mono.CSharp {
                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;
@@ -2052,7 +2040,7 @@ namespace Mono.CSharp {
                        ec.Emit (OpCodes.Ldnull);
 
                        // Only to make verifier happy
-                       if (TypeManager.IsGenericParameter (type))
+                       if (type.IsGenericParameter)
                                ec.Emit (OpCodes.Unbox_Any, type);
                }
 
@@ -2066,13 +2054,13 @@ namespace Mono.CSharp {
                {
                        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))
@@ -2081,7 +2069,7 @@ namespace Mono.CSharp {
                        if (TypeManager.IsReferenceType (targetType))
                                return new NullConstant (targetType, loc);
 
-                       if (TypeManager.IsNullableType (targetType))
+                       if (targetType.IsNullableType)
                                return Nullable.LiftedNull.Create (targetType, loc);
 
                        return null;
@@ -2129,6 +2117,33 @@ namespace Mono.CSharp {
                }
        }
 
+
+       //
+       // 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