public FieldSpec DefineInitializedData (byte[] data, Location loc) { Struct size_type; if (!size_types.TryGetValue (data.Length, out size_type)) { // // Build common type for this data length. We cannot use // DefineInitializedData because it creates public type, // and its name is not unique among modules // size_type = new Struct (this, new MemberName ("$ArrayType=" + data.Length, loc), Modifiers.PRIVATE | Modifiers.COMPILER_GENERATED, null); size_type.CreateContainer (); size_type.DefineContainer (); size_types.Add (data.Length, size_type); // It has to work even if StructLayoutAttribute does not exist size_type.TypeBuilder.__SetLayout (1, data.Length); } var name = "$field-" + fields.ToString ("X"); ++fields; const Modifiers fmod = Modifiers.STATIC | Modifiers.INTERNAL; var fbuilder = TypeBuilder.DefineField (name, size_type.CurrentType.GetMetaInfo (), ModifiersExtensions.FieldAttr (fmod) | FieldAttributes.HasFieldRVA); fbuilder.__SetDataAndRVA (data); return new FieldSpec (CurrentType, null, size_type.CurrentType, fbuilder, fmod); }
public FieldSpec DefineInitializedData (byte[] data, Location loc) { Struct size_type; if (!size_types.TryGetValue (data.Length, out size_type)) { // // Build common type for this data length. We cannot use // DefineInitializedData because it creates public type, // and its name is not unique among modules // size_type = new Struct (null, this, new MemberName ("$ArrayType=" + data.Length, Location), Modifiers.PRIVATE | Modifiers.COMPILER_GENERATED, null); size_type.CreateType (); size_type.DefineType (); size_types.Add (data.Length, size_type); var pa = Module.PredefinedAttributes.StructLayout; if (pa.Constructor != null || pa.ResolveConstructor (Location, TypeManager.short_type)) { var argsEncoded = new AttributeEncoder (false); argsEncoded.Encode ((short) LayoutKind.Explicit); var field_size = pa.GetField ("Size", TypeManager.int32_type, Location); var pack = pa.GetField ("Pack", TypeManager.int32_type, Location); if (field_size != null) { argsEncoded.EncodeNamedArguments ( new[] { field_size, pack }, new[] { new IntConstant ((int) data.Length, Location), new IntConstant (1, Location) } ); } pa.EmitAttribute (size_type.TypeBuilder, argsEncoded); } } var name = "$field-" + fields.ToString ("X"); ++fields; const Modifiers fmod = Modifiers.STATIC | Modifiers.INTERNAL; var fbuilder = TypeBuilder.DefineField (name, size_type.CurrentType.GetMetaInfo (), ModifiersExtensions.FieldAttr (fmod) | FieldAttributes.HasFieldRVA); #if STATIC fbuilder.__SetDataAndRVA (data); #else if (set_data == null) set_data = typeof (FieldBuilder).GetMethod ("SetRVAData", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance); try { set_data.Invoke (fbuilder, new object[] { data }); } catch { Report.RuntimeMissingSupport (loc, "SetRVAData"); } #endif return new FieldSpec (CurrentType, null, size_type.CurrentType, fbuilder, fmod); }
public FieldSpec DefineInitializedData (byte[] data, Location loc) { Struct size_type; if (!size_types.TryGetValue (data.Length, out size_type)) { // // Build common type for this data length. We cannot use // DefineInitializedData because it creates public type, // and its name is not unique among modules // size_type = new Struct (null, this, new MemberName ("$ArrayType=" + data.Length, Location), Modifiers.PRIVATE | Modifiers.COMPILER_GENERATED, null); size_type.CreateType (); size_type.DefineType (); size_types.Add (data.Length, size_type); var pa = Module.PredefinedAttributes.StructLayout; if (pa.Constructor != null || pa.ResolveConstructor (Location, Compiler.BuildinTypes.Short)) { var argsEncoded = new AttributeEncoder (); argsEncoded.Encode ((short) LayoutKind.Explicit); var field_size = pa.GetField ("Size", Compiler.BuildinTypes.Int, Location); var pack = pa.GetField ("Pack", Compiler.BuildinTypes.Int, Location); if (field_size != null) { argsEncoded.EncodeNamedArguments ( new[] { field_size, pack }, new[] { new IntConstant (Compiler.BuildinTypes, (int) data.Length, Location), new IntConstant (Compiler.BuildinTypes, 1, Location) } ); } pa.EmitAttribute (size_type.TypeBuilder, argsEncoded); } } var name = "$field-" + fields.ToString ("X"); ++fields; const Modifiers fmod = Modifiers.STATIC | Modifiers.INTERNAL; var fbuilder = TypeBuilder.DefineField (name, size_type.CurrentType.GetMetaInfo (), ModifiersExtensions.FieldAttr (fmod) | FieldAttributes.HasFieldRVA); fbuilder.__SetDataAndRVA (data); return new FieldSpec (CurrentType, null, size_type.CurrentType, fbuilder, fmod); }
bool CheckStructCycles (Struct s) { if (s.Fields == null) return true; if (s.InTransit) return false; s.InTransit = true; foreach (FieldBase field in s.Fields) { TypeSpec ftype = field.Spec.MemberType; if (!ftype.IsStruct) continue; if (ftype is BuiltinTypeSpec) continue; foreach (var targ in ftype.TypeArguments) { if (!CheckFieldTypeCycle (targ)) { Report.Error (523, field.Location, "Struct member `{0}' of type `{1}' causes a cycle in the struct layout", field.GetSignatureForError (), ftype.GetSignatureForError ()); break; } } // // Static fields of exactly same type are allowed // if (field.IsStatic && ftype == s.CurrentType) continue; if (!CheckFieldTypeCycle (ftype)) { Report.Error (523, field.Location, "Struct member `{0}' of type `{1}' causes a cycle in the struct layout", field.GetSignatureForError (), ftype.GetSignatureForError ()); break; } } s.InTransit = false; return true; }
public override void Visit (Struct s) { TypeDeclaration newType = new TypeDeclaration (); newType.ClassType = MonoDevelop.Projects.Dom.ClassType.Struct; var location = LocationsBag.GetMemberLocation (s); AddModifiers (newType, location); if (location != null) newType.AddChild (new CSharpTokenNode (Convert (location[0]), "struct".Length), TypeDeclaration.TypeKeyword); newType.AddChild (new Identifier (s.Name, Convert (s.MemberName.Location)), AbstractNode.Roles.Identifier); if (s.MemberName.TypeArguments != null) { var typeArgLocation = LocationsBag.GetLocations (s.MemberName); if (typeArgLocation != null) newType.AddChild (new CSharpTokenNode (Convert (typeArgLocation[0]), 1), MemberReferenceExpression.Roles.LChevron); // AddTypeArguments (newType, typeArgLocation, s.MemberName.TypeArguments); if (typeArgLocation != null) newType.AddChild (new CSharpTokenNode (Convert (typeArgLocation[1]), 1), MemberReferenceExpression.Roles.RChevron); AddConstraints (newType, s); } if (location != null) newType.AddChild (new CSharpTokenNode (Convert (location[1]), 1), AbstractCSharpNode.Roles.LBrace); typeStack.Push (newType); base.Visit (s); if (location != null) newType.AddChild (new CSharpTokenNode (Convert (location[2]), 1), AbstractCSharpNode.Roles.RBrace); typeStack.Pop (); AddType (newType); }
public override void Visit(Struct s) { var newType = new TypeDeclaration(); newType.ClassType = ClassType.Struct; AddAttributeSection(newType, s); var location = LocationsBag.GetMemberLocation(s); AddModifiers(newType, location); int curLoc = 0; if (location != null && location.Count > 0) newType.AddChild(new CSharpTokenNode(Convert(location [curLoc++]), Roles.StructKeyword), Roles.StructKeyword); newType.AddChild(Identifier.Create(s.MemberName.Name, Convert(s.MemberName.Location)), Roles.Identifier); AddTypeParameters(newType, s.MemberName); if (s.TypeBaseExpressions != null) { if (location != null && curLoc < location.Count) newType.AddChild(new CSharpTokenNode(Convert(location [curLoc++]), Roles.Colon), Roles.Colon); var commaLocations = LocationsBag.GetLocations(s.TypeBaseExpressions); int i = 0; foreach (var baseTypes in s.TypeBaseExpressions) { newType.AddChild(ConvertToType(baseTypes), Roles.BaseType); if (commaLocations != null && i < commaLocations.Count) { newType.AddChild(new CSharpTokenNode(Convert(commaLocations [i]), Roles.Comma), Roles.Comma); i++; } } } AddConstraints(newType, s.CurrentTypeParameters); if (location != null && curLoc < location.Count) newType.AddChild(new CSharpTokenNode(Convert(location [curLoc++]), Roles.LBrace), Roles.LBrace); typeStack.Push(newType); base.Visit(s); if (location != null && location.Count > 2) { if (location != null && curLoc < location.Count) newType.AddChild(new CSharpTokenNode(Convert(location [curLoc++]), Roles.RBrace), Roles.RBrace); if (location != null && curLoc < location.Count) newType.AddChild(new CSharpTokenNode(Convert(location [curLoc++]), Roles.Semicolon), Roles.Semicolon); } else { // parser error, set end node to max value. newType.AddChild(new ErrorNode(), Roles.Error); } typeStack.Pop(); AddType(newType); }
public override void Visit (Struct s) { VisitType (s, ClassType.Struct); }
public virtual void Visit (Struct s) { VisitTypeDefinition (s); }
public virtual void Visit (Struct s) { VisitTypeContainer (s); }
public override void Visit (Struct s) { TypeDeclaration newType = new TypeDeclaration (); newType.ClassType = ClassType.Struct; AddAttributeSection (newType, s); var location = LocationsBag.GetMemberLocation (s); AddModifiers (newType, location); if (location != null) newType.AddChild (new CSharpTokenNode (Convert (location[0]), "struct".Length), TypeDeclaration.Roles.Keyword); newType.AddChild (Identifier.Create (s.MemberName.Name, Convert (s.MemberName.Location)), AstNode.Roles.Identifier); if (s.MemberName.TypeArguments != null) { var typeArgLocation = LocationsBag.GetLocations (s.MemberName); if (typeArgLocation != null) newType.AddChild (new CSharpTokenNode (Convert (typeArgLocation[0]), 1), TypeDeclaration.Roles.LChevron); AddTypeParameters (newType, typeArgLocation, s.MemberName.TypeArguments); if (typeArgLocation != null) newType.AddChild (new CSharpTokenNode (Convert (typeArgLocation[1]), 1), TypeDeclaration.Roles.RChevron); AddConstraints (newType, s); } if (s.TypeBaseExpressions != null) { foreach (var baseTypes in s.TypeBaseExpressions) { newType.AddChild (ConvertToType (baseTypes), TypeDeclaration.BaseTypeRole); } } if (location != null && location.Count > 1) newType.AddChild (new CSharpTokenNode (Convert (location[1]), 1), AstNode.Roles.LBrace); typeStack.Push (newType); base.Visit (s); if (location != null && location.Count > 2) { newType.AddChild (new CSharpTokenNode (Convert (location[2]), 1), AstNode.Roles.RBrace); } else { // parser error, set end node to max value. newType.AddChild (new ErrorNode (), AstNode.Roles.Error); } typeStack.Pop (); AddType (newType); }
bool CheckStructCycles (Struct s) { if (s.Fields == null) return true; if (s.InTransit) return false; s.InTransit = true; foreach (FieldBase field in s.Fields) { TypeSpec ftype = field.Spec.MemberType; if (!ftype.IsStruct) continue; if (ftype is PredefinedTypeSpec) continue; foreach (var targ in ftype.TypeArguments) { if (!CheckFieldTypeCycle (targ)) { Report.Error (523, field.Location, "Struct member `{0}' of type `{1}' causes a cycle in the struct layout", field.GetSignatureForError (), ftype.GetSignatureForError ()); break; } } if ((field.IsStatic && (!ftype.IsGeneric || ftype == CurrentType))) continue; if (!CheckFieldTypeCycle (ftype)) { Report.Error (523, field.Location, "Struct member `{0}' of type `{1}' causes a cycle in the struct layout", field.GetSignatureForError (), ftype.GetSignatureForError ()); break; } } s.InTransit = false; return true; }
public virtual void Visit (Struct s) { if (!AutoVisit) VisitTypeContainer (s); }
public AdditionResult AddStruct (Struct s) { AdditionResult res; if ((res = IsValid (s.Basename)) != AdditionResult.Success) return res; DefineName (s.Name, s); types.Add (s); return AdditionResult.Success; }
public override void Visit (Struct s) { TypeDeclaration newType = new TypeDeclaration (); newType.ClassType = ClassType.Struct; var location = LocationsBag.GetMemberLocation (s); AddModifiers (newType, location); if (location != null) newType.AddChild (new CSharpTokenNode (Convert (location[0]), "struct".Length), TypeDeclaration.Roles.Keyword); newType.AddChild (new Identifier (s.Basename, Convert (s.MemberName.Location)), AstNode.Roles.Identifier); if (s.MemberName.TypeArguments != null) { var typeArgLocation = LocationsBag.GetLocations (s.MemberName); if (typeArgLocation != null) newType.AddChild (new CSharpTokenNode (Convert (typeArgLocation[0]), 1), TypeDeclaration.Roles.LChevron); AddTypeParameters (newType, typeArgLocation, s.MemberName.TypeArguments); if (typeArgLocation != null) newType.AddChild (new CSharpTokenNode (Convert (typeArgLocation[1]), 1), TypeDeclaration.Roles.RChevron); AddConstraints (newType, s); } if (location != null && location.Count > 1) newType.AddChild (new CSharpTokenNode (Convert (location[1]), 1), AstNode.Roles.LBrace); typeStack.Push (newType); base.Visit (s); if (location != null && location.Count > 2) newType.AddChild (new CSharpTokenNode (Convert (location[2]), 1), AstNode.Roles.RBrace); typeStack.Pop (); AddType (newType); }
public virtual void Visit(Struct s) { VisitTypeDefinition(s); }
public virtual void Visit(Struct s) { VisitTypeContainer(s); }