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