updated browser capabilities file
[mono.git] / mcs / gmcs / generic.cs
index 32d12c7a738c30369fe326d6de8a2c566c661b8f..b26083f895cd59c2f8715c0efa27bcd31f0e2ace 100644 (file)
@@ -245,6 +245,11 @@ namespace Mono.CSharp {
                        args.Add (type);
                }
 
+               public void Add (TypeArguments new_args)
+               {
+                       args.AddRange (new_args.args);
+               }
+
                public Type[] Arguments {
                        get {
                                return atypes;
@@ -309,14 +314,43 @@ namespace Mono.CSharp {
                        loc = l;
                        this.name = name;
                        this.args = args;
+
                        eclass = ExprClass.Type;
+                       full_name = name + "<" + args.ToString () + ">";
+               }
 
+               public ConstructedType (string name, TypeParameter[] type_params, Location l)
+               {
+                       loc = l;
+                       this.name = name;
+
+                       args = new TypeArguments ();
+                       foreach (TypeParameter type_param in type_params)
+                               args.Add (new TypeParameterExpr (type_param, l));
+
+                       eclass = ExprClass.Type;
                        full_name = name + "<" + args.ToString () + ">";
                }
 
+               public ConstructedType (Type t, TypeParameter[] type_params, Location l)
+                       : this (t.Name, type_params, l)
+               {
+                       gt = t.GetGenericTypeDefinition ();
+               }
+
+               public ConstructedType (Type t, TypeArguments args, Location l)
+                       : this (t.Name, args, l)
+               {
+                       gt = t.GetGenericTypeDefinition ();
+               }
+
+               public TypeArguments TypeArguments {
+                       get { return args; }
+               }
+
                protected bool CheckConstraints (int index)
                {
-                       Type atype = args.Arguments [index];
+                       Type atype = atypes [index];
                        Type ptype = gen_params [index];
 
                        //// FIXME
@@ -351,6 +385,9 @@ namespace Mono.CSharp {
 
                public override TypeExpr DoResolveAsTypeStep (EmitContext ec)
                {
+                       if (gt != null)
+                               return this;
+
                        //
                        // First, resolve the generic type.
                        //
@@ -371,6 +408,11 @@ namespace Mono.CSharp {
 
                public override Type ResolveType (EmitContext ec)
                {
+                       if (type != null)
+                               return type;
+                       if (DoResolveAsTypeStep (ec) == null)
+                               return null;
+
                        //
                        // Resolve the arguments.
                        //
@@ -381,7 +423,29 @@ namespace Mono.CSharp {
                        }
 
                        gen_params = gt.GetGenericArguments ();
-                       atypes = args.Arguments;
+
+                       DeclSpace decl = ec.DeclSpace, parent = null;
+                       while (decl != null) {
+                               if (TypeManager.IsNestedChildOf (gt, decl.TypeBuilder)) {
+                                       parent = decl;
+                                       break;
+                               }
+                               decl = decl.Parent;
+                       }
+
+                       if (parent != null) {
+                               TypeParameter[] pparams = parent.TypeParameters;
+
+                               atypes = new Type [args.Arguments.Length + pparams.Length];
+                               for (int i = 0; i < pparams.Length; i++) {
+                                       TypeParameter pparam = pparams [i];
+                                       if (pparam.Type == null)
+                                               throw new Exception ();
+                                       atypes [i] = pparam.Type;
+                               }
+                               args.Arguments.CopyTo (atypes, pparams.Length);
+                       } else
+                               atypes = args.Arguments;
 
                        if (atypes.Length != gen_params.Length) {
                                Report.Error (-217, loc, "Generic type `{0}' takes {1} " +
@@ -402,6 +466,11 @@ namespace Mono.CSharp {
                        return type;
                }
 
+               public Expression GetMemberAccess (TypeExpr current_type)
+               {
+                       return new GenericMemberAccess (current_type, name, args, loc);
+               }
+
                public override bool CheckAccessLevel (DeclSpace ds)
                {
                        return ds.CheckAccessLevel (gt);
@@ -443,8 +512,9 @@ namespace Mono.CSharp {
 
        public class GenericMethod : DeclSpace
        {
-               public GenericMethod (NamespaceEntry ns, TypeContainer parent, string name, Location l)
-                       : base (ns, parent, name, l)
+               public GenericMethod (NamespaceEntry ns, TypeContainer parent, string name,
+                                     Attributes attrs, Location l)
+                       : base (ns, parent, name, attrs, l)
                { }
 
                public override TypeBuilder DefineType ()
@@ -539,6 +609,28 @@ namespace Mono.CSharp {
                        new_mg.InstanceExpression = mg.InstanceExpression;
                        return new_mg;
                }
+
+               public override Expression ResolveAsTypeStep (EmitContext ec)
+               {
+                       ConstructedType cexpr = expr as ConstructedType;
+                       if (cexpr == null)
+                               throw new Exception ();
+
+                       expr = base.ResolveAsTypeStep (ec);
+                       if (expr == null)
+                               return null;
+
+                       Type t = ((TypeExpr) expr).ResolveType (ec);
+                       if (t == null)
+                               return null;
+
+                       TypeArguments new_args = new TypeArguments ();
+                       new_args.Add (cexpr.TypeArguments);
+                       new_args.Add (args);
+
+                       ConstructedType ctype = new ConstructedType (t, new_args, loc);
+                       return ctype.ResolveAsTypeStep (ec);
+               }
        }
 
        public class DefaultValueExpression : Expression