* ImportTest.cs (Add1): Fix test on windows.
[mono.git] / mcs / mcs / attribute.cs
index 95ba58d7b5aada6f444a9904cfac9577a78f1940..caaad5513bbc523c2d85925cb0c82a09cd5471b4 100644 (file)
@@ -12,8 +12,7 @@
 
 using System;
 using System.Diagnostics;
-using System.Collections;
-using System.Collections.Specialized;
+using System.Collections.Generic;
 using System.Reflection;
 using System.Reflection.Emit;
 using System.Runtime.InteropServices;
@@ -109,9 +108,9 @@ namespace Mono.CSharp {
                object [] prop_values_arr;
                object [] pos_values;
 
-               static PtrHashtable usage_attr_cache;
+               static Dictionary<Type, AttributeUsageAttribute> usage_attr_cache;
                // Cache for parameter-less attributes
-               static PtrHashtable att_cache;
+               static Dictionary<Type, CustomAttributeBuilder> att_cache;
 
                public Attribute (string target, ATypeNameExpression expr, Arguments[] args, Location loc, bool nameEscaped)
                {
@@ -140,8 +139,8 @@ namespace Mono.CSharp {
 
                public static void Reset ()
                {
-                       usage_attr_cache = new PtrHashtable ();
-                       att_cache = new PtrHashtable ();
+                       usage_attr_cache = new Dictionary<Type, AttributeUsageAttribute> (ReferenceEquality<Type>.Default);
+                       att_cache = new Dictionary<Type, CustomAttributeBuilder> (ReferenceEquality<Type>.Default);
                }
 
                //
@@ -172,17 +171,17 @@ namespace Mono.CSharp {
 
                static void Error_InvalidNamedArgument (ResolveContext rc, NamedArgument name)
                {
-                       rc.Report.Error (617, name.Name.Location, "`{0}' is not a valid named attribute argument. Named attribute arguments " +
+                       rc.Report.Error (617, name.Location, "`{0}' is not a valid named attribute argument. Named attribute arguments " +
                                      "must be fields which are not readonly, static, const or read-write properties which are " +
                                      "public and not static",
-                             name.Name.Value);
+                             name.Name);
                }
 
                static void Error_InvalidNamedArgumentType (ResolveContext rc, NamedArgument name)
                {
-                       rc.Report.Error (655, name.Name.Location,
+                       rc.Report.Error (655, name.Location,
                                "`{0}' is not a valid named attribute argument because it is not a valid attribute parameter type",
-                               name.Name.Value);
+                               name.Name);
                }
 
                public static void Error_AttributeArgumentNotValid (ResolveContext rc, Location loc)
@@ -344,7 +343,7 @@ namespace Mono.CSharp {
                        get { return expression.Name; }
                }
 
-               void ApplyModuleCharSet ()
+               void ApplyModuleCharSet (ResolveContext rc)
                {
                        if (Type != PredefinedAttributes.Get.DllImport)
                                return;
@@ -357,16 +356,16 @@ namespace Mono.CSharp {
                                NamedArguments = new Arguments (1);
                        } else {
                                foreach (NamedArgument a in NamedArguments) {
-                                       if (a.Name.Value == CharSetEnumMember)
+                                       if (a.Name == CharSetEnumMember)
                                                return;
                                }
                        }
                        
-                       NamedArguments.Add (new NamedArgument (new LocatedToken (loc, CharSetEnumMember),
-                               Constant.CreateConstant (typeof (CharSet), RootContext.ToplevelTypes.DefaultCharSet, Location)));
+                       NamedArguments.Add (new NamedArgument (CharSetEnumMember, loc,
+                               Constant.CreateConstant (rc, typeof (CharSet), RootContext.ToplevelTypes.DefaultCharSet, Location)));
                }
 
-               Report Report {
+               public Report Report {
                        get { return context.Compiler.Report; }
                }
 
@@ -393,16 +392,16 @@ namespace Mono.CSharp {
                                AttributeTester.Report_ObsoleteMessage (obsolete_attr, TypeManager.CSharpName (Type), Location, Report);
                        }
 
+                       CustomAttributeBuilder cb;
                        if (PosArguments == null && NamedArguments == null) {
-                               object o = att_cache [Type];
-                               if (o != null) {
+                               if (att_cache.TryGetValue (Type, out cb)) {
                                        resolve_error = false;
-                                       return (CustomAttributeBuilder)o;
+                                       return cb;
                                }
                        }
 
                        ResolveContext rc = new ResolveContext (context, ResolveContext.Options.ConstantScope);
-                       ConstructorInfo ctor = ResolveConstructor (rc);
+                       var ctor = ResolveConstructor (rc);
                        if (ctor == null) {
                                if (Type is TypeBuilder && 
                                    TypeManager.LookupDeclSpace (Type).MemberCache == null)
@@ -412,16 +411,16 @@ namespace Mono.CSharp {
                                return null;
                        }
 
-                       ApplyModuleCharSet ();
+                       ApplyModuleCharSet (rc);
 
-                       CustomAttributeBuilder cb;
                        try {
+                               var ctor_meta = (ConstructorInfo) ctor.MetaInfo;
                                // SRE does not allow private ctor but we want to report all source code errors
-                               if (ctor.IsPrivate)
+                               if (ctor.MetaInfo.IsPrivate)
                                        return null;
 
                                if (NamedArguments == null) {
-                                       cb = new CustomAttributeBuilder (ctor, pos_values);
+                                       cb = new CustomAttributeBuilder (ctor_meta, pos_values);
 
                                        if (pos_values.Length == 0)
                                                att_cache.Add (Type, cb);
@@ -434,7 +433,7 @@ namespace Mono.CSharp {
                                        return null;
                                }
 
-                               cb = new CustomAttributeBuilder (ctor, pos_values,
+                               cb = new CustomAttributeBuilder (ctor_meta, pos_values,
                                                prop_info_arr, prop_values_arr,
                                                field_info_arr, field_values_arr);
 
@@ -447,7 +446,7 @@ namespace Mono.CSharp {
                        }
                }
 
-               protected virtual ConstructorInfo ResolveConstructor (ResolveContext ec)
+               protected virtual MethodSpec ResolveConstructor (ResolveContext ec)
                {
                        if (PosArguments != null) {
                                bool dynamic;
@@ -470,14 +469,12 @@ namespace Mono.CSharp {
                        if (mg == null)
                                return null;
                        
-                       ConstructorInfo constructor = (ConstructorInfo)mg;
+                       var constructor = (MethodSpec) mg;
                        if (PosArguments == null) {
                                pos_values = EmptyObject;
                                return constructor;
                        }
 
-                       AParametersCollection pd = TypeManager.GetParameterData (constructor);
-
                        if (!PosArguments.GetAttributableValue (ec, out pos_values))
                                return null;
 
@@ -509,7 +506,7 @@ namespace Mono.CSharp {
                        }
 
                        if (Type == pa.MethodImpl && pos_values.Length == 1 &&
-                               pd.Types [0] == TypeManager.short_type &&
+                               constructor.Parameters.Types [0] == TypeManager.short_type &&
                                !System.Enum.IsDefined (typeof (MethodImplOptions), pos_values [0].ToString ())) {
                                Error_AttributeEmitError ("Incorrect argument value.");
                                return null;
@@ -522,17 +519,17 @@ namespace Mono.CSharp {
                {
                        int named_arg_count = NamedArguments.Count;
 
-                       ArrayList field_infos = new ArrayList (named_arg_count);
-                       ArrayList prop_infos  = new ArrayList (named_arg_count);
-                       ArrayList field_values = new ArrayList (named_arg_count);
-                       ArrayList prop_values = new ArrayList (named_arg_count);
+                       var field_infos = new List<FieldInfo> (named_arg_count);
+                       var prop_infos  = new List<PropertyInfo> (named_arg_count);
+                       var field_values = new List<object> (named_arg_count);
+                       var prop_values = new List<object> (named_arg_count);
 
-                       ArrayList seen_names = new ArrayList (named_arg_count);
+                       var seen_names = new List<string> (named_arg_count);
                        
                        foreach (NamedArgument a in NamedArguments) {
-                               string name = a.Name.Value;
+                               string name = a.Name;
                                if (seen_names.Contains (name)) {
-                                       ec.Report.Error (643, a.Name.Location, "Duplicate named attribute `{0}' argument", name);
+                                       ec.Report.Error (643, a.Location, "Duplicate named attribute `{0}' argument", name);
                                        continue;
                                }                       
        
@@ -599,15 +596,15 @@ namespace Mono.CSharp {
                                        prop_infos.Add (pi);
                                        
                                } else {
-                                       FieldInfo fi = ((FieldExpr) member).FieldInfo;
+                                       var fi = ((FieldExpr) member).Spec;
 
-                                       if (fi.IsInitOnly || fi.IsStatic) {
+                                       if (fi.IsReadOnly || fi.IsStatic) {
                                                Error_InvalidNamedArgument (ec, a);
                                                return false;
                                        }
 
                                        if (!IsValidArgumentType (member.Type)) {
-                                               ec.Report.SymbolRelatedToPreviousError (fi);
+                                               ec.Report.SymbolRelatedToPreviousError (fi.MetaInfo);
                                                Error_InvalidNamedArgumentType (ec, a);
                                                return false;
                                        }
@@ -616,14 +613,14 @@ namespace Mono.CSharp {
                                        if (!a.Expr.GetAttributableValue (ec, member.Type, out value))
                                                return false;
 
-                                       FieldBase fb = TypeManager.GetField (fi);
+                                       FieldBase fb = TypeManager.GetField (fi.MetaInfo);
                                        if (fb != null)
                                                obsolete_attr = fb.GetObsoleteAttribute ();
                                        else
-                                               obsolete_attr = AttributeTester.GetMemberObsoleteAttribute (fi);
+                                               obsolete_attr = AttributeTester.GetMemberObsoleteAttribute (fi.MetaInfo);
 
-                                       field_values.Add (value);                                       
-                                       field_infos.Add (fi);
+                                       field_values.Add (value);
+                                       field_infos.Add (fi.MetaInfo);
                                }
 
                                if (obsolete_attr != null && !context.IsObsolete)
@@ -705,8 +702,8 @@ namespace Mono.CSharp {
                /// </summary>
                static AttributeUsageAttribute GetAttributeUsage (Type type)
                {
-                       AttributeUsageAttribute ua = usage_attr_cache [type] as AttributeUsageAttribute;
-                       if (ua != null)
+                       AttributeUsageAttribute ua;
+                       if (usage_attr_cache.TryGetValue (type, out ua))
                                return ua;
 
                        Class attr_class = TypeManager.LookupClass (type);
@@ -854,7 +851,7 @@ namespace Mono.CSharp {
                        }
 
                        // TODO: we can skip the first item
-                       if (((IList) valid_targets).Contains (ExplicitTarget)) {
+                       if (Array.Exists (valid_targets, i => i == ExplicitTarget)) {
                                switch (ExplicitTarget) {
                                case "return": Target = AttributeTargets.ReturnValue; return true;
                                case "param": Target = AttributeTargets.Parameter; return true;
@@ -919,7 +916,7 @@ namespace Mono.CSharp {
                /// Creates instance of SecurityAttribute class and add result of CreatePermission method to permission table.
                /// </summary>
                /// <returns></returns>
-               public void ExtractSecurityPermissionSet (ListDictionary permissions)
+               public void ExtractSecurityPermissionSet (Dictionary<SecurityAction, PermissionSet> permissions)
                {
                        Type orig_assembly_type = null;
 
@@ -998,8 +995,8 @@ namespace Mono.CSharp {
                                }
                        }
 
-                       PermissionSet ps = (PermissionSet)permissions [action];
-                       if (ps == null) {
+                       PermissionSet ps;
+                       if (!permissions.TryGetValue (action, out ps)) {
                                if (sa is PermissionSetAttribute)
                                        ps = new PermissionSet (sa.Unrestricted ? PermissionState.Unrestricted : PermissionState.None);
                                else
@@ -1186,13 +1183,13 @@ namespace Mono.CSharp {
 
                public override int GetHashCode ()
                {
-                       return base.GetHashCode ();
+                       return type.GetHashCode () ^ Target.GetHashCode ();
                }
 
                /// <summary>
                /// Emit attribute for Attributable symbol
                /// </summary>
-               public void Emit (ListDictionary allEmitted)
+               public void Emit (Dictionary<Attribute, List<Attribute>> allEmitted)
                {
                        CustomAttributeBuilder cb = Resolve ();
                        if (cb == null)
@@ -1217,10 +1214,10 @@ namespace Mono.CSharp {
                        }
 
                        if (!usage_attr.AllowMultiple && allEmitted != null) {
-                               if (allEmitted.Contains (this)) {
-                                       ArrayList a = allEmitted [this] as ArrayList;
+                               if (allEmitted.ContainsKey (this)) {
+                                       var a = allEmitted [this];
                                        if (a == null) {
-                                               a = new ArrayList (2);
+                                               a = new List<Attribute> (2);
                                                allEmitted [this] = a;
                                        }
                                        a.Add (this);
@@ -1281,7 +1278,7 @@ namespace Mono.CSharp {
                        throw new NotSupportedException ("ET");
                }
 
-               public override Expression DoResolve (ResolveContext ec)
+               protected override Expression DoResolve (ResolveContext ec)
                {
                        throw new NotImplementedException ();
                }
@@ -1359,7 +1356,7 @@ namespace Mono.CSharp {
                        }
                }
 
-               protected override ConstructorInfo ResolveConstructor (ResolveContext ec)
+               protected override MethodSpec ResolveConstructor (ResolveContext ec)
                {
                        try {
                                Enter ();
@@ -1383,20 +1380,20 @@ namespace Mono.CSharp {
        }
 
        public class Attributes {
-               public readonly ArrayList Attrs;
+               public readonly List<Attribute> Attrs;
 
                public Attributes (Attribute a)
                {
-                       Attrs = new ArrayList ();
+                       Attrs = new List<Attribute> ();
                        Attrs.Add (a);
                }
 
-               public Attributes (ArrayList attrs)
+               public Attributes (List<Attribute> attrs)
                {
                        Attrs = attrs;
                }
 
-               public void AddAttributes (ArrayList attrs)
+               public void AddAttributes (List<Attribute> attrs)
                {
                        Attrs.AddRange (attrs);
                }
@@ -1409,7 +1406,7 @@ namespace Mono.CSharp {
 
                public Attributes Clone ()
                {
-                       ArrayList al = new ArrayList (Attrs.Count);
+                       var al = new List<Attribute> (Attrs.Count);
                        foreach (Attribute a in Attrs)
                                al.Add (a.Clone ());
 
@@ -1442,24 +1439,24 @@ namespace Mono.CSharp {
                /// </summary>
                public Attribute[] SearchMulti (PredefinedAttribute t)
                {
-                       ArrayList ar = null;
+                       List<Attribute> ar = null;
 
                        foreach (Attribute a in Attrs) {
                                if (a.ResolveType () == t) {
                                        if (ar == null)
-                                               ar = new ArrayList ();
+                                               ar = new List<Attribute> (Attrs.Count);
                                        ar.Add (a);
                                }
                        }
 
-                       return ar == null ? null : ar.ToArray (typeof (Attribute)) as Attribute[];
+                       return ar == null ? null : ar.ToArray ();
                }
 
                public void Emit ()
                {
                        CheckTargets ();
 
-                       ListDictionary ld = Attrs.Count > 1 ? new ListDictionary () : null;
+                       Dictionary<Attribute, List<Attribute>> ld = Attrs.Count > 1 ? new Dictionary<Attribute, List<Attribute>> () : null;
 
                        foreach (Attribute a in Attrs)
                                a.Emit (ld);
@@ -1467,16 +1464,16 @@ namespace Mono.CSharp {
                        if (ld == null || ld.Count == 0)
                                return;
 
-                       foreach (DictionaryEntry d in ld) {
+                       foreach (var d in ld) {
                                if (d.Value == null)
                                        continue;
 
-                               Report report = RootContext.ToplevelTypes.Compiler.Report;
-                               foreach (Attribute collision in (ArrayList)d.Value)
-                                       report.SymbolRelatedToPreviousError (collision.Location, "");
+                               Attribute a = d.Key;
 
-                               Attribute a = (Attribute)d.Key;
-                               report.Error (579, a.Location, "The attribute `{0}' cannot be applied multiple times",
+                               foreach (Attribute collision in d.Value)
+                                       a.Report.SymbolRelatedToPreviousError (collision.Location, "");
+
+                               a.Report.Error (579, a.Location, "The attribute `{0}' cannot be applied multiple times",
                                        a.GetSignatureForError ());
                        }
                }
@@ -1492,14 +1489,11 @@ namespace Mono.CSharp {
        /// </summary>
        sealed class AttributeTester
        {
-               static PtrHashtable analyzed_types;
-               static PtrHashtable analyzed_types_obsolete;
-               static PtrHashtable analyzed_member_obsolete;
-               static PtrHashtable analyzed_method_excluded;
-               static PtrHashtable fixed_buffer_cache;
-
-               static object TRUE = new object ();
-               static object FALSE = new object ();
+               static Dictionary<Type, bool> analyzed_types;
+               static Dictionary<Type, ObsoleteAttribute> analyzed_types_obsolete;
+               static Dictionary<MemberInfo, ObsoleteAttribute> analyzed_member_obsolete;
+               static Dictionary<MethodBase, bool> analyzed_method_excluded;
+//             static Dictionary<FieldInfo, IFixedBuffer> fixed_buffer_cache;
 
                static AttributeTester ()
                {
@@ -1512,11 +1506,11 @@ namespace Mono.CSharp {
 
                public static void Reset ()
                {
-                       analyzed_types = new PtrHashtable ();
-                       analyzed_types_obsolete = new PtrHashtable ();
-                       analyzed_member_obsolete = new PtrHashtable ();
-                       analyzed_method_excluded = new PtrHashtable ();
-                       fixed_buffer_cache = new PtrHashtable ();
+                       analyzed_types = new Dictionary<Type, bool> (ReferenceEquality<Type>.Default);
+                       analyzed_types_obsolete = new Dictionary<Type, ObsoleteAttribute> (ReferenceEquality<Type>.Default);
+                       analyzed_member_obsolete = new Dictionary<MemberInfo, ObsoleteAttribute> (ReferenceEquality<MemberInfo>.Default);
+                       analyzed_method_excluded = new Dictionary<MethodBase, bool> (ReferenceEquality<MethodBase>.Default);
+//                     fixed_buffer_cache = new Dictionary<FieldInfo, IFixedBuffer> (ReferenceEquality<FieldInfo>.Default);
                }
 
                public enum Result {
@@ -1576,16 +1570,15 @@ namespace Mono.CSharp {
                        if (type == null)
                                return true;
 
-                       object type_compliance = analyzed_types[type];
-                       if (type_compliance != null)
-                               return type_compliance == TRUE;
+                       bool result;
+                       if (analyzed_types.TryGetValue (type, out result))
+                               return result;
 
                        if (type.IsPointer) {
-                               analyzed_types.Add (type, FALSE);
+                               analyzed_types.Add (type, false);
                                return false;
                        }
 
-                       bool result;
                        if (type.IsArray) {
                                result = IsClsCompliant (TypeManager.GetElementType (type));
                        } else if (TypeManager.IsNullableType (type)) {
@@ -1593,48 +1586,9 @@ namespace Mono.CSharp {
                        } else {
                                result = AnalyzeTypeCompliance (type);
                        }
-                       analyzed_types.Add (type, result ? TRUE : FALSE);
+                       analyzed_types.Add (type, result);
                        return result;
                }        
-        
-               /// <summary>
-               /// Returns IFixedBuffer implementation if field is fixed buffer else null.
-               /// </summary>
-               public static IFixedBuffer GetFixedBuffer (FieldInfo fi)
-               {
-                       // Fixed buffer helper type is generated as value type
-                       if (TypeManager.IsReferenceType (fi.FieldType))
-                               return null;
-
-                       FieldBase fb = TypeManager.GetField (fi);
-                       if (fb != null) {
-                               return fb as IFixedBuffer;
-                       }
-                       
-                       if (TypeManager.GetConstant (fi) != null)
-                               return null;
-
-                       object o = fixed_buffer_cache [fi];
-                       if (o == null) {
-                               PredefinedAttribute pa = PredefinedAttributes.Get.FixedBuffer;
-                               if (!pa.IsDefined)
-                                       return null;
-
-                               if (!fi.IsDefined (pa.Type, false)) {
-                                       fixed_buffer_cache.Add (fi, FALSE);
-                                       return null;
-                               }
-                               
-                               IFixedBuffer iff = new FixedFieldExternal (fi);
-                               fixed_buffer_cache.Add (fi, iff);
-                               return iff;
-                       }
-
-                       if (o == FALSE)
-                               return null;
-
-                       return (IFixedBuffer)o;
-               }
 
                public static void VerifyModulesClsCompliance (CompilerContext ctx)
                {
@@ -1702,14 +1656,10 @@ namespace Mono.CSharp {
                /// </summary>
                public static ObsoleteAttribute GetObsoleteAttribute (Type type)
                {
-                       object type_obsolete = analyzed_types_obsolete [type];
-                       if (type_obsolete == FALSE)
-                               return null;
+                       ObsoleteAttribute result;
+                       if (analyzed_types_obsolete.TryGetValue (type, out result))
+                               return result;
 
-                       if (type_obsolete != null)
-                               return (ObsoleteAttribute)type_obsolete;
-
-                       ObsoleteAttribute result = null;
                        if (TypeManager.HasElementType (type)) {
                                result = GetObsoleteAttribute (TypeManager.GetElementType (type));
                        } else if (TypeManager.IsGenericParameter (type))
@@ -1733,7 +1683,7 @@ namespace Mono.CSharp {
                        }
 
                        // Cannot use .Add because of corlib bootstrap
-                       analyzed_types_obsolete [type] = result == null ? FALSE : result;
+                       analyzed_types_obsolete [type] = result;
                        return result;
                }
 
@@ -1766,12 +1716,9 @@ namespace Mono.CSharp {
                /// </summary>
                public static ObsoleteAttribute GetMemberObsoleteAttribute (MemberInfo mi)
                {
-                       object type_obsolete = analyzed_member_obsolete [mi];
-                       if (type_obsolete == FALSE)
-                               return null;
-
-                       if (type_obsolete != null)
-                               return (ObsoleteAttribute)type_obsolete;
+                       ObsoleteAttribute oa;
+                       if (analyzed_member_obsolete.TryGetValue (mi, out oa))
+                               return oa;
 
                        if ((mi.DeclaringType is TypeBuilder) || TypeManager.IsGenericType (mi.DeclaringType))
                                return null;
@@ -1780,9 +1727,8 @@ namespace Mono.CSharp {
                        if (!pa.IsDefined)
                                return null;
 
-                       ObsoleteAttribute oa = System.Attribute.GetCustomAttribute (mi, pa.Type, false)
-                               as ObsoleteAttribute;
-                       analyzed_member_obsolete.Add (mi, oa == null ? FALSE : oa);
+                       oa = System.Attribute.GetCustomAttribute (mi, pa.Type, false) as ObsoleteAttribute;
+                       analyzed_member_obsolete.Add (mi, oa);
                        return oa;
                }
 
@@ -1805,9 +1751,9 @@ namespace Mono.CSharp {
 
                public static bool IsConditionalMethodExcluded (MethodBase mb, Location loc)
                {
-                       object excluded = analyzed_method_excluded [mb];
-                       if (excluded != null)
-                               return excluded == TRUE ? true : false;
+                       bool excluded;
+                       if (analyzed_method_excluded.TryGetValue (mb, out excluded))
+                               return excluded;
 
                        PredefinedAttribute pa = PredefinedAttributes.Get.Conditional;
                        if (!pa.IsDefined)
@@ -1816,18 +1762,18 @@ namespace Mono.CSharp {
                        ConditionalAttribute[] attrs = mb.GetCustomAttributes (pa.Type, true)
                                as ConditionalAttribute[];
                        if (attrs.Length == 0) {
-                               analyzed_method_excluded.Add (mb, FALSE);
+                               analyzed_method_excluded.Add (mb, false);
                                return false;
                        }
 
                        foreach (ConditionalAttribute a in attrs) {
                                if (loc.CompilationUnit.IsConditionalDefined (a.ConditionString)) {
-                                       analyzed_method_excluded.Add (mb, FALSE);
+                                       analyzed_method_excluded.Add (mb, false);
                                        return false;
                                }
                        }
 
-                       analyzed_method_excluded.Add (mb, TRUE);
+                       analyzed_method_excluded.Add (mb, true);
                        return true;
                }
 
@@ -1923,6 +1869,7 @@ namespace Mono.CSharp {
 
                // New in .NET 4.0
                public readonly PredefinedAttribute Dynamic;
+               public readonly PredefinedAttribute DynamicTransform;   // DynamicAttribute with transform arguments
 
                //
                // Optional types which are used as types and for member lookup
@@ -1970,6 +1917,7 @@ namespace Mono.CSharp {
                        Extension = new PredefinedAttribute ("System.Runtime.CompilerServices", "ExtensionAttribute");
 
                        Dynamic = new PredefinedAttribute ("System.Runtime.CompilerServices", "DynamicAttribute");
+                       DynamicTransform = new PredefinedAttribute ("System.Runtime.CompilerServices", "DynamicAttribute");
 
                        DefaultMember = new PredefinedAttribute ("System.Reflection", "DefaultMemberAttribute");
                        DecimalConstant = new PredefinedAttribute ("System.Runtime.CompilerServices", "DecimalConstantAttribute");
@@ -1977,10 +1925,10 @@ namespace Mono.CSharp {
                        FieldOffset = new PredefinedAttribute ("System.Runtime.InteropServices", "FieldOffsetAttribute");
                }
 
-               public void Initialize ()
+               public void Initialize (CompilerContext ctx)
                {
                        foreach (FieldInfo fi in GetType ().GetFields (BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly)) {
-                               ((PredefinedAttribute) fi.GetValue (this)).Resolve (true);
+                               ((PredefinedAttribute) fi.GetValue (this)).Initialize (ctx, true);
                        }
                }
 
@@ -1996,6 +1944,7 @@ namespace Mono.CSharp {
                CustomAttributeBuilder cab;
                ConstructorInfo ctor;
                readonly string ns, name;
+               CompilerContext compiler;
 
                static readonly Type NotFound = typeof (PredefinedAttribute);
 
@@ -2080,6 +2029,12 @@ namespace Mono.CSharp {
                        get { return type != null && type != NotFound; }
                }
 
+               public void Initialize (CompilerContext ctx, bool canFail)
+               {
+                       this.compiler = ctx;
+                       Resolve (canFail);
+               }
+
                public bool Resolve (bool canFail)
                {
                        if (type != null) {
@@ -2089,7 +2044,7 @@ namespace Mono.CSharp {
                                        return false;
                        }
 
-                       type = TypeManager.CoreLookupType (RootContext.ToplevelTypes.Compiler, ns, name, Kind.Class, !canFail);
+                       type = TypeManager.CoreLookupType (compiler, ns, name, MemberKind.Class, !canFail);
                        if (type == null) {
                                type = NotFound;
                                return false;