X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mcs%2Fmcs%2Fattribute.cs;h=4fbc993a55a882591eb2192cfbe79fa163027afe;hb=e2b2d181084848f3c5dde2788370db1b79893c69;hp=2ba91e68062b321ad1effe6c1885c3e4f2ca70bb;hpb=b41e14f39f27d3b66922a8bc99fc8911cf906ce6;p=mono.git diff --git a/mcs/mcs/attribute.cs b/mcs/mcs/attribute.cs index 2ba91e68062..4fbc993a55a 100644 --- a/mcs/mcs/attribute.cs +++ b/mcs/mcs/attribute.cs @@ -8,6 +8,7 @@ // // Copyright 2001-2003 Ximian, Inc (http://www.ximian.com) // Copyright 2003-2008 Novell, Inc. +// Copyright 2011 Xamarin Inc // using System; @@ -83,18 +84,19 @@ namespace Mono.CSharp { public abstract string[] ValidAttributeTargets { get; } }; - public class Attribute : Expression + public class Attribute { public readonly string ExplicitTarget; public AttributeTargets Target; readonly ATypeNameExpression expression; - Arguments PosArguments; - Arguments NamedArguments; + Arguments pos_args, named_args; bool resolve_error; bool arg_resolved; readonly bool nameEscaped; + readonly Location loc; + public TypeSpec Type; // // An attribute can be attached to multiple targets (e.g. multiple fields) @@ -116,14 +118,44 @@ namespace Mono.CSharp { { this.expression = expr; if (args != null) { - PosArguments = args[0]; - NamedArguments = args[1]; + pos_args = args[0]; + named_args = args[1]; } this.loc = loc; ExplicitTarget = target; this.nameEscaped = nameEscaped; } + public Location Location { + get { + return loc; + } + } + + public Arguments NamedArguments { + get { + return named_args; + } + } + + public Arguments PositionalArguments { + get { + return pos_args; + } + } + + public bool ResolveError { + get { + return resolve_error; + } + } + + public ATypeNameExpression TypeExpression { + get { + return expression; + } + } + void AddModuleCharSet (ResolveContext rc) { const string dll_import_char_set = "CharSet"; @@ -139,7 +171,7 @@ namespace Mono.CSharp { } if (NamedArguments == null) - NamedArguments = new Arguments (1); + named_args = new Arguments (1); var value = Constant.CreateConstant (rc.Module.PredefinedTypes.CharSet.TypeSpec, rc.Module.DefaultCharSet, Location); NamedArguments.Add (new NamedArgument (dll_import_char_set, loc, value)); @@ -148,8 +180,8 @@ namespace Mono.CSharp { public Attribute Clone () { Attribute a = new Attribute (ExplicitTarget, expression, null, loc, nameEscaped); - a.PosArguments = PosArguments; - a.NamedArguments = NamedArguments; + a.pos_args = pos_args; + a.named_args = NamedArguments; return a; } @@ -250,10 +282,10 @@ namespace Mono.CSharp { /// /// Tries to resolve the type of the attribute. Flags an error if it can't, and complain is true. /// - void ResolveAttributeType () + void ResolveAttributeType (bool comparisonOnly) { SessionReportPrinter resolve_printer = new SessionReportPrinter (); - ReportPrinter prev_recorder = context.Module.Compiler.Report.SetPrinter (resolve_printer); + ReportPrinter prev_recorder = Report.SetPrinter (resolve_printer); bool t1_is_attr = false; bool t2_is_attr = false; @@ -285,9 +317,12 @@ namespace Mono.CSharp { } if (t1_is_attr && t2_is_attr && t1 != t2) { - Report.Error (1614, Location, "`{0}' is ambiguous between `{1}' and `{2}'. Use either `@{0}' or `{0}Attribute'", - GetSignatureForError (), expression.GetSignatureForError (), expanded.GetSignatureForError ()); - resolve_error = true; + if (!comparisonOnly) { + Report.Error (1614, Location, "`{0}' is ambiguous between `{1}' and `{2}'. Use either `@{0}' or `{0}Attribute'", + GetSignatureForError (), expression.GetSignatureForError (), expanded.GetSignatureForError ()); + resolve_error = true; + } + return; } @@ -301,6 +336,9 @@ namespace Mono.CSharp { return; } + if (comparisonOnly) + return; + resolve_error = true; if (t1 != null) { @@ -320,14 +358,14 @@ namespace Mono.CSharp { resolve_printer.Merge (prev_recorder); } - public TypeSpec ResolveType () + public TypeSpec ResolveTypeForComparison () { if (Type == null && !resolve_error) - ResolveAttributeType (); + ResolveAttributeType (true); return Type; } - public override string GetSignatureForError () + public string GetSignatureForError () { if (Type != null) return TypeManager.CSharpName (Type); @@ -338,7 +376,7 @@ namespace Mono.CSharp { public bool HasSecurityAttribute { get { PredefinedAttribute pa = context.Module.PredefinedAttributes.Security; - return pa.IsDefined && TypeSpec.IsBaseClass (type, pa.TypeSpec, false); + return pa.IsDefined && TypeSpec.IsBaseClass (Type, pa.TypeSpec, false); } } @@ -399,7 +437,7 @@ namespace Mono.CSharp { arg_resolved = true; if (Type == null) { - ResolveAttributeType (); + ResolveAttributeType (false); if (Type == null) return null; } @@ -418,14 +456,14 @@ namespace Mono.CSharp { MethodSpec ctor; // Try if the attribute is simple and has been resolved before - if (PosArguments != null || !context.Module.AttributeConstructorCache.TryGetValue (Type, out ctor)) { + if (pos_args != null || !context.Module.AttributeConstructorCache.TryGetValue (Type, out ctor)) { rc = CreateResolveContext (); ctor = ResolveConstructor (rc); if (ctor == null) { return null; } - if (PosArguments == null && ctor.Parameters.IsEmpty) + if (pos_args == null && ctor.Parameters.IsEmpty) context.Module.AttributeConstructorCache.Add (Type, ctor); } @@ -454,16 +492,16 @@ namespace Mono.CSharp { MethodSpec ResolveConstructor (ResolveContext ec) { - if (PosArguments != null) { + if (pos_args != null) { bool dynamic; - PosArguments.Resolve (ec, out dynamic); + pos_args.Resolve (ec, out dynamic); if (dynamic) { Error_AttributeArgumentIsDynamic (ec.MemberContext, loc); return null; } } - return ConstructorLookup (ec, Type, ref PosArguments, loc); + return Expression.ConstructorLookup (ec, Type, ref pos_args, loc); } bool ResolveNamedArguments (ResolveContext ec) @@ -484,10 +522,10 @@ namespace Mono.CSharp { a.Resolve (ec); - Expression member = Expression.MemberLookup (ec, false, Type, name, 0, MemberLookupRestrictions.ExactArity, loc); + Expression member = Expression.MemberLookup (ec, false, Type, name, 0, Expression.MemberLookupRestrictions.ExactArity, loc); if (member == null) { - member = Expression.MemberLookup (ec, true, Type, name, 0, MemberLookupRestrictions.ExactArity, loc); + member = Expression.MemberLookup (ec, true, Type, name, 0, Expression.MemberLookupRestrictions.ExactArity, loc); if (member != null) { // TODO: ec.Report.SymbolRelatedToPreviousError (member); @@ -623,7 +661,7 @@ namespace Mono.CSharp { if (resolve_error) return DefaultUsageAttribute; - AttributeUsageAttribute usage_attribute = new AttributeUsageAttribute ((AttributeTargets)((Constant) PosArguments [0].Expr).GetValue ()); + AttributeUsageAttribute usage_attribute = new AttributeUsageAttribute ((AttributeTargets) ((Constant) pos_args[0].Expr).GetValue ()); var field = GetNamedValue ("AllowMultiple") as BoolConstant; if (field != null) @@ -646,10 +684,10 @@ namespace Mono.CSharp { // But because a lot of attribute class code must be rewritten will be better to wait... Resolve (); - if (resolve_error || PosArguments.Count != 1 || !(PosArguments [0].Expr is Constant)) + if (resolve_error || pos_args.Count != 1 || !(pos_args[0].Expr is Constant)) return null; - return ((Constant) PosArguments [0].Expr).GetValue () as string; + return ((Constant) pos_args[0].Expr).GetValue () as string; } /// @@ -665,7 +703,7 @@ namespace Mono.CSharp { if (resolve_error) return null; - return ((Constant) PosArguments[0].Expr).GetValue () as string; + return ((Constant) pos_args[0].Expr).GetValue () as string; } /// @@ -675,7 +713,7 @@ namespace Mono.CSharp { { if (!arg_resolved) { // corlib only case when obsolete is used before is resolved - var c = type.MemberDefinition as Class; + var c = Type.MemberDefinition as Class; if (c != null && !c.HasMembersDefined) c.Define (); @@ -687,14 +725,14 @@ namespace Mono.CSharp { if (resolve_error) return null; - if (PosArguments == null) + if (pos_args == null) return new ObsoleteAttribute (); - string msg = ((Constant) PosArguments[0].Expr).GetValue () as string; - if (PosArguments.Count == 1) + string msg = ((Constant) pos_args[0].Expr).GetValue () as string; + if (pos_args.Count == 1) return new ObsoleteAttribute (msg); - return new ObsoleteAttribute (msg, ((BoolConstant) PosArguments[1].Expr).Value); + return new ObsoleteAttribute (msg, ((BoolConstant) pos_args[1].Expr).Value); } /// @@ -712,7 +750,7 @@ namespace Mono.CSharp { if (resolve_error) return false; - return ((BoolConstant) PosArguments[0].Expr).Value; + return ((BoolConstant) pos_args[0].Expr).Value; } public TypeSpec GetCoClassAttributeValue () @@ -798,7 +836,7 @@ namespace Mono.CSharp { System.Security.Permissions.SecurityAction GetSecurityActionValue () { - return (SecurityAction) ((Constant) PosArguments[0].Expr).GetValue (); + return (SecurityAction) ((Constant) pos_args[0].Expr).GetValue (); } /// @@ -808,9 +846,9 @@ namespace Mono.CSharp { public void ExtractSecurityPermissionSet (MethodSpec ctor, ref SecurityType permissions) { #if STATIC - object[] values = new object [PosArguments.Count]; + object[] values = new object[pos_args.Count]; for (int i = 0; i < values.Length; ++i) - values [i] = ((Constant) PosArguments [i].Expr).GetValue (); + values[i] = ((Constant) pos_args[i].Expr).GetValue (); PropertyInfo[] prop; object[] prop_values; @@ -851,7 +889,7 @@ namespace Mono.CSharp { public CharSet GetCharSetValue () { - return (CharSet)System.Enum.Parse (typeof (CharSet), ((Constant) PosArguments [0].Expr).GetValue ().ToString ()); + return (CharSet) System.Enum.Parse (typeof (CharSet), ((Constant) pos_args[0].Expr).GetValue ().ToString ()); } public bool HasField (string fieldName) @@ -871,16 +909,21 @@ namespace Mono.CSharp { // Returns true for MethodImplAttribute with MethodImplOptions.InternalCall value // public bool IsInternalCall () + { + return (GetMethodImplOptions () & MethodImplOptions.InternalCall) != 0; + } + + public MethodImplOptions GetMethodImplOptions () { MethodImplOptions options = 0; - if (PosArguments.Count == 1) { - options = (MethodImplOptions) System.Enum.Parse (typeof (MethodImplOptions), ((Constant) PosArguments[0].Expr).GetValue ().ToString ()); + if (pos_args.Count == 1) { + options = (MethodImplOptions) System.Enum.Parse (typeof (MethodImplOptions), ((Constant) pos_args[0].Expr).GetValue ().ToString ()); } else if (HasField ("Value")) { var named = GetNamedValue ("Value"); options = (MethodImplOptions) System.Enum.Parse (typeof (MethodImplOptions), named.GetValue ().ToString ()); } - return (options & MethodImplOptions.InternalCall) != 0; + return options; } // @@ -888,19 +931,19 @@ namespace Mono.CSharp { // public bool IsExplicitLayoutKind () { - if (PosArguments == null || PosArguments.Count != 1) + if (pos_args == null || pos_args.Count != 1) return false; - var value = (LayoutKind) System.Enum.Parse (typeof (LayoutKind), ((Constant) PosArguments[0].Expr).GetValue ().ToString ()); + var value = (LayoutKind) System.Enum.Parse (typeof (LayoutKind), ((Constant) pos_args[0].Expr).GetValue ().ToString ()); return value == LayoutKind.Explicit; } public Expression GetParameterDefaultValue () { - if (PosArguments == null) + if (pos_args == null) return null; - return PosArguments[0].Expr; + return pos_args[0].Expr; } public override bool Equals (object obj) @@ -914,7 +957,7 @@ namespace Mono.CSharp { public override int GetHashCode () { - return type.GetHashCode () ^ Target.GetHashCode (); + return Type.GetHashCode () ^ Target.GetHashCode (); } /// @@ -937,20 +980,20 @@ namespace Mono.CSharp { } byte[] cdata; - if (PosArguments == null && named_values == null) { + if (pos_args == null && named_values == null) { cdata = AttributeEncoder.Empty; } else { AttributeEncoder encoder = new AttributeEncoder (); - if (PosArguments != null) { + if (pos_args != null) { var param_types = ctor.Parameters.Types; - for (int j = 0; j < PosArguments.Count; ++j) { + for (int j = 0; j < pos_args.Count; ++j) { var pt = param_types[j]; - var arg_expr = PosArguments[j].Expr; + var arg_expr = pos_args[j].Expr; if (j == 0) { if ((Type == predefined.IndexerName || Type == predefined.Conditional) && arg_expr is Constant) { string v = ((Constant) arg_expr).GetValue () as string; - if (!Tokenizer.IsValidIdentifier (v) || Tokenizer.IsKeyword (v)) { + if (!Tokenizer.IsValidIdentifier (v) || (Type == predefined.IndexerName && Tokenizer.IsKeyword (v))) { context.Module.Compiler.Report.Error (633, arg_expr.Location, "The argument to the `{0}' attribute must be a valid identifier", GetSignatureForError ()); return; @@ -970,17 +1013,17 @@ namespace Mono.CSharp { "System.AttributeUsage"); } } else if (Type == predefined.MarshalAs) { - if (PosArguments.Count == 1) { - var u_type = (UnmanagedType) System.Enum.Parse (typeof (UnmanagedType), ((Constant) PosArguments[0].Expr).GetValue ().ToString ()); + if (pos_args.Count == 1) { + var u_type = (UnmanagedType) System.Enum.Parse (typeof (UnmanagedType), ((Constant) pos_args[0].Expr).GetValue ().ToString ()); if (u_type == UnmanagedType.ByValArray && !(Owner is FieldBase)) { Error_AttributeEmitError ("Specified unmanaged type is only valid on fields"); } } } else if (Type == predefined.DllImport) { - if (PosArguments.Count == 1 && PosArguments[0].Expr is Constant) { - var value = ((Constant) PosArguments[0].Expr).GetValue () as string; + if (pos_args.Count == 1 && pos_args[0].Expr is Constant) { + var value = ((Constant) pos_args[0].Expr).GetValue () as string; if (string.IsNullOrEmpty (value)) - Error_AttributeEmitError ("DllName cannot be empty"); + Error_AttributeEmitError ("DllName cannot be empty or null"); } } else if (Type == predefined.MethodImpl && pt.BuiltinType == BuiltinTypeSpec.Type.Short && !System.Enum.IsDefined (typeof (MethodImplOptions), ((Constant) arg_expr).GetValue ().ToString ())) { @@ -1041,8 +1084,8 @@ namespace Mono.CSharp { // Here we are testing attribute arguments for array usage (error 3016) if (Owner.IsClsComplianceRequired ()) { - if (PosArguments != null) - PosArguments.CheckArrayAsAttribute (context.Module.Compiler); + if (pos_args != null) + pos_args.CheckArrayAsAttribute (context.Module.Compiler); if (NamedArguments == null) return; @@ -1053,10 +1096,10 @@ namespace Mono.CSharp { private Expression GetValue () { - if (PosArguments == null || PosArguments.Count < 1) + if (pos_args == null || pos_args.Count < 1) return null; - return PosArguments [0].Expr; + return pos_args[0].Expr; } public string GetString () @@ -1082,21 +1125,6 @@ namespace Mono.CSharp { return null; return e.TypeArgument; } - - public override Expression CreateExpressionTree (ResolveContext ec) - { - throw new NotSupportedException ("ET"); - } - - protected override Expression DoResolve (ResolveContext ec) - { - throw new NotImplementedException (); - } - - public override void Emit (EmitContext ec) - { - throw new NotImplementedException (); - } } public class Attributes @@ -1177,6 +1205,16 @@ namespace Mono.CSharp { } } + public bool HasResolveError() + { + foreach (var a in Attrs) { + if (a.ResolveError) + return true; + } + + return false; + } + public Attribute Search (PredefinedAttribute t) { return Search (null, t); @@ -1188,7 +1226,7 @@ namespace Mono.CSharp { if (explicitTarget != null && a.ExplicitTarget != explicitTarget) continue; - if (a.ResolveType () == t) + if (a.ResolveTypeForComparison () == t) return a; } return null; @@ -1202,7 +1240,7 @@ namespace Mono.CSharp { List ar = null; foreach (Attribute a in Attrs) { - if (a.ResolveType () == t) { + if (a.ResolveTypeForComparison () == t) { if (ar == null) ar = new List (Attrs.Count); ar.Add (a); @@ -1441,6 +1479,12 @@ namespace Mono.CSharp { Encode (type.MemberDefinition.IsImported ? old_type.AssemblyQualifiedName : old_type.FullName); } + public void EncodeTypeName (TypeContainer type) + { + Encode (type.GetSignatureForMetadata ()); + } + + // // Encodes single property named argument per call // @@ -1527,56 +1571,6 @@ namespace Mono.CSharp { /// static class AttributeTester { - public enum Result { - Ok, - RefOutArrayError, - ArrayArrayError - } - - /// - /// Returns true if parameters of two compared methods are CLS-Compliant. - /// It tests differing only in ref or out, or in array rank. - /// - public static Result AreOverloadedMethodParamsClsCompliant (AParametersCollection pa, AParametersCollection pb) - { - TypeSpec [] types_a = pa.Types; - TypeSpec [] types_b = pb.Types; - if (types_a == null || types_b == null) - return Result.Ok; - - if (types_a.Length != types_b.Length) - return Result.Ok; - - Result result = Result.Ok; - for (int i = 0; i < types_b.Length; ++i) { - TypeSpec aType = types_a [i]; - TypeSpec bType = types_b [i]; - - var ac_a = aType as ArrayContainer; - var ac_b = aType as ArrayContainer; - - if (ac_a != null && ac_b != null) { - if (ac_a.Rank != ac_b.Rank && ac_a.Element == ac_b.Element) { - result = Result.RefOutArrayError; - continue; - } - - if (ac_a.Element.IsArray || ac_b.Element.IsArray) { - result = Result.ArrayArrayError; - continue; - } - } - - if (aType != bType) - return Result.Ok; - - const Parameter.Modifier out_ref_mod = (Parameter.Modifier.OUTMASK | Parameter.Modifier.REFMASK); - if ((pa.FixedParameters[i].ModFlags & out_ref_mod) != (pb.FixedParameters[i].ModFlags & out_ref_mod)) - result = Result.RefOutArrayError; - } - return result; - } - /// /// Common method for Obsolete error/warning reporting. /// @@ -1636,6 +1630,7 @@ namespace Mono.CSharp { public readonly PredefinedAttribute DebuggerHidden; public readonly PredefinedAttribute UnsafeValueType; public readonly PredefinedAttribute UnmanagedFunctionPointer; + public readonly PredefinedDebuggerBrowsableAttribute DebuggerBrowsable; // New in .NET 3.5 public readonly PredefinedAttribute Extension; @@ -1643,6 +1638,10 @@ namespace Mono.CSharp { // New in .NET 4.0 public readonly PredefinedDynamicAttribute Dynamic; + // New in .NET 4.5 + public readonly PredefinedStateMachineAttribute AsyncStateMachine; + public readonly PredefinedStateMachineAttribute IteratorStateMachine; + // // Optional types which are used as types and for member lookup // @@ -1650,6 +1649,9 @@ namespace Mono.CSharp { public readonly PredefinedDecimalAttribute DecimalConstant; public readonly PredefinedAttribute StructLayout; public readonly PredefinedAttribute FieldOffset; + public readonly PredefinedAttribute CallerMemberNameAttribute; + public readonly PredefinedAttribute CallerLineNumberAttribute; + public readonly PredefinedAttribute CallerFilePathAttribute; public PredefinedAttributes (ModuleContainer module) { @@ -1690,6 +1692,7 @@ namespace Mono.CSharp { DebuggerHidden = new PredefinedAttribute (module, "System.Diagnostics", "DebuggerHiddenAttribute"); UnsafeValueType = new PredefinedAttribute (module, "System.Runtime.CompilerServices", "UnsafeValueTypeAttribute"); UnmanagedFunctionPointer = new PredefinedAttribute (module, "System.Runtime.InteropServices", "UnmanagedFunctionPointerAttribute"); + DebuggerBrowsable = new PredefinedDebuggerBrowsableAttribute (module, "System.Diagnostics", "DebuggerBrowsableAttribute"); Extension = new PredefinedAttribute (module, "System.Runtime.CompilerServices", "ExtensionAttribute"); @@ -1700,6 +1703,15 @@ namespace Mono.CSharp { StructLayout = new PredefinedAttribute (module, "System.Runtime.InteropServices", "StructLayoutAttribute"); FieldOffset = new PredefinedAttribute (module, "System.Runtime.InteropServices", "FieldOffsetAttribute"); + AsyncStateMachine = new PredefinedStateMachineAttribute (module, "System.Runtime.CompilerServices", "AsyncStateMachineAttribute"); + IteratorStateMachine = new PredefinedStateMachineAttribute (module, "System.Runtime.CompilerServices", "IteratorStateMachineAttribute") { + IsIterator = true + }; + + CallerMemberNameAttribute = new PredefinedAttribute (module, "System.Runtime.CompilerServices", "CallerMemberNameAttribute"); + CallerLineNumberAttribute = new PredefinedAttribute (module, "System.Runtime.CompilerServices", "CallerLineNumberAttribute"); + CallerFilePathAttribute = new PredefinedAttribute (module, "System.Runtime.CompilerServices", "CallerFilePathAttribute"); + // TODO: Should define only attributes which are used for comparison const System.Reflection.BindingFlags all_fields = System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.DeclaredOnly; @@ -1773,22 +1785,12 @@ namespace Mono.CSharp { builder.SetCustomAttribute (GetCtorMetaInfo (), AttributeEncoder.Empty); } - public void EmitAttribute (FieldBuilder builder, AttributeEncoder argsEncoded) - { - builder.SetCustomAttribute (GetCtorMetaInfo (), argsEncoded.ToArray ()); - } - public void EmitAttribute (TypeBuilder builder) { if (ResolveBuilder ()) builder.SetCustomAttribute (GetCtorMetaInfo (), AttributeEncoder.Empty); } - public void EmitAttribute (TypeBuilder builder, AttributeEncoder argsEncoded) - { - builder.SetCustomAttribute (GetCtorMetaInfo (), argsEncoded.ToArray ()); - } - public void EmitAttribute (AssemblyBuilder builder) { if (ResolveBuilder ()) @@ -1807,11 +1809,6 @@ namespace Mono.CSharp { builder.SetCustomAttribute (GetCtorMetaInfo (), AttributeEncoder.Empty); } - public void EmitAttribute (ParameterBuilder builder, AttributeEncoder argsEncoded) - { - builder.SetCustomAttribute (GetCtorMetaInfo (), argsEncoded.ToArray ()); - } - ConstructorInfo GetCtorMetaInfo () { return (ConstructorInfo) ctor.GetMetaInfo (); @@ -1833,6 +1830,27 @@ namespace Mono.CSharp { } } + public class PredefinedDebuggerBrowsableAttribute : PredefinedAttribute + { + public PredefinedDebuggerBrowsableAttribute (ModuleContainer module, string ns, string name) + : base (module, ns, name) + { + } + + public void EmitAttribute (FieldBuilder builder, System.Diagnostics.DebuggerBrowsableState state) + { + var ctor = module.PredefinedMembers.DebuggerBrowsableAttributeCtor.Get (); + if (ctor == null) + return; + + AttributeEncoder encoder = new AttributeEncoder (); + encoder.Encode ((int) state); + encoder.EncodeEmptyNamedArguments (); + + builder.SetCustomAttribute ((ConstructorInfo) ctor.GetMetaInfo (), encoder.ToArray ()); + } + } + public class PredefinedDecimalAttribute : PredefinedAttribute { public PredefinedDecimalAttribute (ModuleContainer module, string ns, string name) @@ -1877,6 +1895,34 @@ namespace Mono.CSharp { } } + public class PredefinedStateMachineAttribute : PredefinedAttribute + { + public PredefinedStateMachineAttribute (ModuleContainer module, string ns, string name) + : base (module, ns, name) + { + } + + public bool IsIterator { get; set; } + + public void EmitAttribute (MethodBuilder builder, StateMachine type) + { + var predefined_ctor = IsIterator ? + module.PredefinedMembers.IteratorStateMachineAttributeCtor : + module.PredefinedMembers.AsyncStateMachineAttributeCtor; + + var ctor = predefined_ctor.Get (); + + if (ctor == null) + return; + + AttributeEncoder encoder = new AttributeEncoder (); + encoder.EncodeTypeName (type); + encoder.EncodeEmptyNamedArguments (); + + builder.SetCustomAttribute ((ConstructorInfo) ctor.GetMetaInfo (), encoder.ToArray ()); + } + } + public class PredefinedDynamicAttribute : PredefinedAttribute { MethodSpec tctor;