Exemple #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);
        }
Exemple #2
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;
		}
Exemple #3
0
 public virtual void Visit(Const c)
 {
 }
Exemple #4
0
			public override void Visit(Const c)
			{
				var location = LocationsBag.GetMemberLocation(c);
				
				var newField = new FieldDeclaration();
				AddAttributeSection(newField, c);
				AddModifiers(newField, location);
				if (location != null)
					newField.AddChild(new CSharpModifierToken(Convert(location [0]), Modifiers.Const), EntityDeclaration.ModifierRole);
				newField.AddChild(ConvertToType(c.TypeExpression), Roles.Type);
				
				var variable = new VariableInitializer();
				variable.AddChild(Identifier.Create(c.MemberName.Name, Convert(c.MemberName.Location)), Roles.Identifier);
				
				if (c.Initializer != null) {
					variable.AddChild(new CSharpTokenNode(Convert(c.Initializer.Location), Roles.Assign), Roles.Assign);
					variable.AddChild((Expression)c.Initializer.Accept(this), Roles.Expression);
				}
				newField.AddChild(variable, Roles.Variable);
				if (c.Declarators != null) {
					foreach (var decl in c.Declarators) {
						var declLoc = LocationsBag.GetLocations(decl);
						if (declLoc != null)
							newField.AddChild(new CSharpTokenNode(Convert(declLoc [0]), Roles.Comma), Roles.Comma);
						
						variable = new VariableInitializer();
						variable.AddChild(Identifier.Create(decl.Name.Value, Convert(decl.Name.Location)), Roles.Identifier);
						if (decl.Initializer != null) {
							variable.AddChild(new CSharpTokenNode(Convert(decl.Initializer.Location), Roles.Assign), Roles.Assign);
							variable.AddChild((Expression)decl.Initializer.Accept(this), Roles.Expression);
						}
						newField.AddChild(variable, Roles.Variable);
					}
				}
				if (location != null)
					newField.AddChild(new CSharpTokenNode(Convert(location [1]), Roles.Semicolon), Roles.Semicolon);
				
				typeStack.Peek().AddChild(newField, Roles.TypeMemberRole);

				
			}
Exemple #5
0
		public virtual void Visit (Const c)
		{
		}