示例#1
0
        /// <summary>
        ///   Defines the constant in the @parent
        /// </summary>
        public override bool Define()
        {
            if (!base.Define())
            {
                return(false);
            }

            if (!member_type.IsConstantCompatible)
            {
                Error_InvalidConstantType(member_type, Location, Report);
            }

            FieldAttributes field_attr = FieldAttributes.Static | ModifiersExtensions.FieldAttr(ModFlags);

            // Decimals cannot be emitted into the constant blob.  So, convert to 'readonly'.
            if (member_type.BuiltinType == BuiltinTypeSpec.Type.Decimal)
            {
                field_attr |= FieldAttributes.InitOnly;
            }
            else
            {
                field_attr |= FieldAttributes.Literal;
            }

            FieldBuilder = Parent.TypeBuilder.DefineField(Name, MemberType.GetMetaInfo(), field_attr);
            spec         = new ConstSpec(Parent.Definition, this, MemberType, FieldBuilder, ModFlags, initializer);

            Parent.MemberCache.AddMember(spec);

            if ((field_attr & FieldAttributes.InitOnly) != 0)
            {
                Parent.PartialContainer.RegisterFieldForInitialization(this,
                                                                       new FieldInitializer(this, initializer, Location));
            }

            if (declarators != null)
            {
                var t = new TypeExpression(MemberType, TypeExpression.Location);
                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;
                    c.Define();
                    Parent.PartialContainer.Members.Add(c);
                }
            }

            return(true);
        }
示例#2
0
        public override bool Define()
        {
            if (!ResolveMemberType())
            {
                return(false);
            }

            const FieldAttributes attr = FieldAttributes.Public | FieldAttributes.Static | FieldAttributes.Literal;

            FieldBuilder = Parent.TypeBuilder.DefineField(Name, MemberType.GetMetaInfo(), attr);
            spec         = new ConstSpec(Parent.Definition, this, MemberType, FieldBuilder, ModFlags, initializer);

            Parent.MemberCache.AddMember(spec);
            return(true);
        }
示例#3
0
		/// <summary>
		///   Defines the constant in the @parent
		/// </summary>
		public override bool Define ()
		{
			if (!base.Define ())
				return false;

			if (!member_type.IsConstantCompatible) {
				Error_InvalidConstantType (member_type, Location, Report);
			}

			FieldAttributes field_attr = FieldAttributes.Static | ModifiersExtensions.FieldAttr (ModFlags);
			// Decimals cannot be emitted into the constant blob.  So, convert to 'readonly'.
			if (member_type.BuiltinType == BuiltinTypeSpec.Type.Decimal) {
				field_attr |= FieldAttributes.InitOnly;
			} else {
				field_attr |= FieldAttributes.Literal;
			}

			FieldBuilder = Parent.TypeBuilder.DefineField (Name, MemberType.GetMetaInfo (), field_attr);
			spec = new ConstSpec (Parent.Definition, this, MemberType, FieldBuilder, ModFlags, initializer);

			Parent.MemberCache.AddMember (spec);

			if ((field_attr & FieldAttributes.InitOnly) != 0)
				Parent.PartialContainer.RegisterFieldForInitialization (this,
					new FieldInitializer (this, initializer, Location));

			if (declarators != null) {
				var t = new TypeExpression (MemberType, TypeExpression.Location);
				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;
					c.Define ();
					Parent.PartialContainer.Members.Add (c);
				}
			}

			return true;
		}
示例#4
0
		public override bool Define ()
		{
			if (!ResolveMemberType ())
				return false;

			const FieldAttributes attr = FieldAttributes.Public | FieldAttributes.Static | FieldAttributes.Literal;
			FieldBuilder = Parent.TypeBuilder.DefineField (Name, MemberType.GetMetaInfo (), attr);
			spec = new ConstSpec (Parent.Definition, this, MemberType, FieldBuilder, ModFlags, initializer);

			Parent.MemberCache.AddMember (spec);
			return true;
		}