本文整理汇总了C#中Mono.CSharp.Struct类的典型用法代码示例。如果您正苦于以下问题:C# Struct类的具体用法?C# Struct怎么用?C# Struct使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Struct类属于Mono.CSharp命名空间,在下文中一共展示了Struct类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DefineInitializedData
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);
}
示例2: DefineInitializedData
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);
}
示例3: DefineInitializedData
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);
}
示例4: CheckStructCycles
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;
}
示例5: Visit
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);
}
示例6: Visit
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);
}
示例7: Visit
public override void Visit (Struct s)
{
VisitType (s, ClassType.Struct);
}
示例8: Visit
public virtual void Visit (Struct s)
{
VisitTypeDefinition (s);
}
示例9: Visit
public virtual void Visit (Struct s)
{
VisitTypeContainer (s);
}
示例10: Visit
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);
}
示例11: CheckStructCycles
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;
}
示例12: Visit
public virtual void Visit (Struct s)
{
if (!AutoVisit)
VisitTypeContainer (s);
}
示例13: AddStruct
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;
}
示例14: Visit
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);
}