public override bool Define() { if (!base.Define()) { return(false); } if (!BuiltinTypeSpec.IsPrimitiveType(MemberType)) { Report.Error(1663, Location, "`{0}': Fixed size buffers type must be one of the following: bool, byte, short, int, long, char, sbyte, ushort, uint, ulong, float or double", GetSignatureForError()); } else if (declarators != null) { var t = new TypeExpression(MemberType, TypeExpression.Location); foreach (var d in declarators) { var f = new FixedField(Parent, t, ModFlags, new MemberName(d.Name.Value, d.Name.Location), OptAttributes); f.initializer = d.Initializer; ((ConstInitializer)f.initializer).Name = d.Name.Value; f.Define(); Parent.PartialContainer.Members.Add(f); } } // Create nested fixed buffer container string name = String.Format("<{0}>__FixedBuffer{1}", Name, GlobalCounter++); fixed_buffer_type = Parent.TypeBuilder.DefineNestedType(name, TypeAttributes.NestedPublic | TypeAttributes.Sealed | TypeAttributes.BeforeFieldInit, Compiler.BuiltinTypes.ValueType.GetMetaInfo()); var ffield = fixed_buffer_type.DefineField(FixedElementName, MemberType.GetMetaInfo(), FieldAttributes.Public); FieldBuilder = Parent.TypeBuilder.DefineField(Name, fixed_buffer_type, ModifiersExtensions.FieldAttr(ModFlags)); var element_spec = new FieldSpec(null, this, MemberType, ffield, ModFlags); spec = new FixedFieldSpec(Module, Parent.Definition, this, FieldBuilder, element_spec, ModFlags); Parent.MemberCache.AddMember(spec); return(true); }
public override void Visit (FixedField f) { var location = LocationsBag.GetMemberLocation (f); int locationIdx = 0; var newField = new FixedFieldDeclaration (); AddAttributeSection (newField, f); AddModifiers (newField, location); if (location != null && location.Count > 0) newField.AddChild (new CSharpTokenNode (Convert (location [locationIdx++]), FixedFieldDeclaration.FixedKeywordRole), FixedFieldDeclaration.FixedKeywordRole); if (f.TypeExpression != null) newField.AddChild (ConvertToType (f.TypeExpression), Roles.Type); var variable = new FixedVariableInitializer (); variable.AddChild (Identifier.Create (f.MemberName.Name, Convert (f.MemberName.Location)), Roles.Identifier); if (f.Initializer != null && !f.Initializer.IsNull) { var bracketLocations = LocationsBag.GetLocations (f.Initializer); if (bracketLocations != null && bracketLocations.Count > 1) variable.AddChild (new CSharpTokenNode (Convert (bracketLocations [0]), Roles.LBracket), Roles.LBracket); variable.AddChild ((Expression)f.Initializer.Accept (this), Roles.Expression); if (bracketLocations != null && bracketLocations.Count > 1) variable.AddChild (new CSharpTokenNode (Convert (bracketLocations [0]), Roles.RBracket), Roles.RBracket); } newField.AddChild (variable, FixedFieldDeclaration.VariableRole); 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 FixedVariableInitializer (); variable.AddChild (Identifier.Create (decl.Name.Value, Convert (decl.Name.Location)), Roles.Identifier); if (!decl.Initializer.IsNull) { var bracketLocations = LocationsBag.GetLocations (f.Initializer); if (bracketLocations != null && bracketLocations.Count > 1) variable.AddChild (new CSharpTokenNode (Convert (bracketLocations [0]), Roles.LBracket), Roles.LBracket); variable.AddChild ((Expression)decl.Initializer.Accept (this), Roles.Expression); if (bracketLocations != null && bracketLocations.Count > 1) variable.AddChild (new CSharpTokenNode (Convert (bracketLocations [0]), Roles.RBracket), Roles.RBracket); } newField.AddChild (variable, FixedFieldDeclaration.VariableRole); } } if (location != null && location.Count > locationIdx) newField.AddChild (new CSharpTokenNode (Convert (location [locationIdx]), Roles.Semicolon), Roles.Semicolon); typeStack.Peek ().AddChild (newField, Roles.TypeMemberRole); }
public override bool Define () { if (!base.Define ()) return false; if (!BuiltinTypeSpec.IsPrimitiveType (MemberType)) { Report.Error (1663, Location, "`{0}': Fixed size buffers type must be one of the following: bool, byte, short, int, long, char, sbyte, ushort, uint, ulong, float or double", GetSignatureForError ()); } else if (declarators != null) { var t = new TypeExpression (MemberType, TypeExpression.Location); foreach (var d in declarators) { var f = new FixedField (Parent, t, ModFlags, new MemberName (d.Name.Value, d.Name.Location), OptAttributes); f.initializer = d.Initializer; ((ConstInitializer) f.initializer).Name = d.Name.Value; f.Define (); Parent.PartialContainer.Members.Add (f); } } // Create nested fixed buffer container string name = String.Format ("<{0}>__FixedBuffer{1}", Name, GlobalCounter++); fixed_buffer_type = Parent.TypeBuilder.DefineNestedType (name, TypeAttributes.NestedPublic | TypeAttributes.Sealed | TypeAttributes.BeforeFieldInit, Compiler.BuiltinTypes.ValueType.GetMetaInfo ()); var ffield = fixed_buffer_type.DefineField (FixedElementName, MemberType.GetMetaInfo (), FieldAttributes.Public); FieldBuilder = Parent.TypeBuilder.DefineField (Name, fixed_buffer_type, ModifiersExtensions.FieldAttr (ModFlags)); var element_spec = new FieldSpec (null, this, MemberType, ffield, ModFlags); spec = new FixedFieldSpec (Parent.Definition, this, FieldBuilder, element_spec, ModFlags); Parent.MemberCache.AddMember (spec); return true; }
public virtual void Visit (FixedField f) { }
public virtual void Visit(FixedField f) { }