X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mcs%2Fmcs%2Fconst.cs;h=7d149aae26ce24758c2c19e1f58d12f6e46468d8;hb=dbb4fd470011e716f821f8f63544dc21df14f829;hp=ec4634a0fe6b2e52ebb62e9fa8e7ca0d9690244d;hpb=029d67e3e22a8cdcc3363fb35aa6f3d1aa413cb1;p=mono.git diff --git a/mcs/mcs/const.cs b/mcs/mcs/const.cs index ec4634a0fe6..7d149aae26c 100644 --- a/mcs/mcs/const.cs +++ b/mcs/mcs/const.cs @@ -9,22 +9,24 @@ // Copyright 2003-2008 Novell, Inc. // -using System; +#if STATIC +using IKVM.Reflection; +#else using System.Reflection; -using System.Reflection.Emit; +#endif namespace Mono.CSharp { public class Const : FieldBase { - public const Modifiers AllowedModifiers = + const Modifiers AllowedModifiers = Modifiers.NEW | Modifiers.PUBLIC | Modifiers.PROTECTED | Modifiers.INTERNAL | Modifiers.PRIVATE; - public Const (DeclSpace parent, FullNamedExpression type, Modifiers mod_flags, MemberName name, Attributes attrs) + public Const (TypeDefinition parent, FullNamedExpression type, Modifiers mod_flags, MemberName name, Attributes attrs) : base (parent, type, mod_flags, AllowedModifiers, name, attrs) { ModFlags |= Modifiers.STATIC; @@ -44,7 +46,7 @@ namespace Mono.CSharp { FieldAttributes field_attr = FieldAttributes.Static | ModifiersExtensions.FieldAttr (ModFlags); // Decimals cannot be emitted into the constant blob. So, convert to 'readonly'. - if (member_type == TypeManager.decimal_type) { + if (member_type.BuiltinType == BuiltinTypeSpec.Type.Decimal) { field_attr |= FieldAttributes.InitOnly; } else { field_attr |= FieldAttributes.Literal; @@ -57,16 +59,16 @@ namespace Mono.CSharp { if ((field_attr & FieldAttributes.InitOnly) != 0) Parent.PartialContainer.RegisterFieldForInitialization (this, - new FieldInitializer (spec, initializer, this)); + new FieldInitializer (this, initializer, Location)); if (declarators != null) { var t = new TypeExpression (MemberType, TypeExpression.Location); - int index = Parent.PartialContainer.Constants.IndexOf (this); foreach (var d in declarators) { var c = new Const (Parent, t, ModFlags & ~Modifiers.STATIC, new MemberName (d.Name.Value, d.Name.Location), OptAttributes); c.initializer = d.Initializer; ((ConstInitializer) c.initializer).Name = d.Name.Value; - Parent.PartialContainer.Constants.Insert (++index, c); + c.Define (); + Parent.PartialContainer.Members.Add (c); } } @@ -85,34 +87,15 @@ namespace Mono.CSharp { public override void Emit () { var c = ((ConstSpec) spec).Value as Constant; - if (c.Type == TypeManager.decimal_type) { - FieldBuilder.SetCustomAttribute (CreateDecimalConstantAttribute (c, Compiler.PredefinedAttributes)); + if (c.Type.BuiltinType == BuiltinTypeSpec.Type.Decimal) { + Module.PredefinedAttributes.DecimalConstant.EmitAttribute (FieldBuilder, (decimal) c.GetValue (), c.Location); } else { - FieldBuilder.SetConstant (c.GetTypedValue ()); + FieldBuilder.SetConstant (c.GetValue ()); } base.Emit (); } - public static CustomAttributeBuilder CreateDecimalConstantAttribute (Constant c, PredefinedAttributes pa) - { - PredefinedAttribute attr = pa.DecimalConstant; - if (attr.Constructor == null && - !attr.ResolveConstructor (c.Location, TypeManager.byte_type, TypeManager.byte_type, - TypeManager.uint32_type, TypeManager.uint32_type, TypeManager.uint32_type)) - return null; - - Decimal d = (Decimal) c.GetValue (); - int [] bits = Decimal.GetBits (d); - object [] args = new object [] { - (byte) (bits [3] >> 16), - (byte) (bits [3] >> 31), - (uint) bits [2], (uint) bits [1], (uint) bits [0] - }; - - return new CustomAttributeBuilder (attr.Constructor, args); - } - public static void Error_InvalidConstantType (TypeSpec t, Location loc, Report Report) { if (t.IsGenericParameter) { @@ -212,12 +195,12 @@ namespace Mono.CSharp { c = field.ConvertInitializer (rc, c); if (c == null) { - if (TypeManager.IsReferenceType (field.MemberType)) + if (TypeSpec.IsReferenceType (field.MemberType)) Error_ConstantCanBeInitializedWithNullOnly (rc, field.MemberType, expr.Location, GetSignatureForError ()); else if (!(expr is Constant)) Error_ExpressionMustBeConstant (rc, expr.Location, GetSignatureForError ()); else - expr.Error_ValueCannotBeConverted (rc, expr.Location, field.MemberType, false); + expr.Error_ValueCannotBeConverted (rc, field.MemberType, false); } expr = c; @@ -240,5 +223,10 @@ namespace Mono.CSharp { return field.Parent.GetSignatureForError () + "." + Name; } + + public override object Accept (StructuralVisitor visitor) + { + return visitor.Visit (this); + } } }