2004-04-02 Martin Baulig <martin@ximian.com>
authorMartin Baulig <martin@novell.com>
Fri, 2 Apr 2004 20:58:18 +0000 (20:58 -0000)
committerMartin Baulig <martin@novell.com>
Fri, 2 Apr 2004 20:58:18 +0000 (20:58 -0000)
* ecore.cs (IAlias): New public interface.
(TypeExpr, TypeExpression): Implement IAlias.
(TypeAliasExpression): New public class.

* namespace.cs (Namespace): Implement IAlias.
(Namespace.Lookup): Return an IAlias instead on an object.
(Namespace.DefineName): Take an IAlias instead of an object.
(NamespaceEntry.AliasEntry.Resolve): Return an IAlias instead of
an object.
(NamespaceEntry.UsingAlias): Take a Membername instead of an
Expression.
(NamespaceEntry.LookupAlias): Return an IAlias instead on an
object.
(NamespaceEntry.Lookup): Likewise.

* rootcontext.cs (RootContext.LookupType): Return a TypeExpr
instead of a Type.

* decl.cs (DeclSpace): Implement IAlias.
(DeclSpace.LookupAlias): Return an IAlias instead of a string.

* generic.cs (ConstructedType): Improved error checking.

svn path=/trunk/mcs/; revision=24980

mcs/gmcs/ChangeLog
mcs/gmcs/attribute.cs
mcs/gmcs/class.cs
mcs/gmcs/cs-parser.jay
mcs/gmcs/decl.cs
mcs/gmcs/ecore.cs
mcs/gmcs/expression.cs
mcs/gmcs/generic.cs
mcs/gmcs/namespace.cs
mcs/gmcs/rootcontext.cs

index 076b5f1d7c1bbc85775d014d3d8be82bce5985d4..85cf7717f45436a6e1fac8d4f9d24d79fe173f21 100755 (executable)
@@ -1,3 +1,28 @@
+2004-04-02  Martin Baulig  <martin@ximian.com>
+
+       * ecore.cs (IAlias): New public interface.
+       (TypeExpr, TypeExpression): Implement IAlias.
+       (TypeAliasExpression): New public class.
+
+       * namespace.cs (Namespace): Implement IAlias.
+       (Namespace.Lookup): Return an IAlias instead on an object.
+       (Namespace.DefineName): Take an IAlias instead of an object.
+       (NamespaceEntry.AliasEntry.Resolve): Return an IAlias instead of
+       an object.
+       (NamespaceEntry.UsingAlias): Take a Membername instead of an
+       Expression.
+       (NamespaceEntry.LookupAlias): Return an IAlias instead on an
+       object.
+       (NamespaceEntry.Lookup): Likewise.
+
+       * rootcontext.cs (RootContext.LookupType): Return a TypeExpr
+       instead of a Type.      
+
+       * decl.cs (DeclSpace): Implement IAlias.
+       (DeclSpace.LookupAlias): Return an IAlias instead of a string.
+
+       * generic.cs (ConstructedType): Improved error checking.
+
 2004-04-02  Martin Baulig  <martin@ximian.com>
 
        * convert.cs: Added type parameter conversions.
@@ -6,7 +31,7 @@
        (UnboxCast.Emit): Emit an `unbox.any' for type params.
        (ClassCast.Emit): If the source type is a type parameter, box it.
        If the target type is a type parameter, emit an `unbox.any'
-       instead of a `classcast'.       
+       instead of a `classcast'.1      
 
 2004-04-01  Martin Baulig  <martin@ximian.com>
 
index 069f525600b14feaa5313e888fb442f457e46d84..00a938cf736d622140ccbd79fe43e79176c9a9bb 100644 (file)
@@ -1,4 +1,4 @@
-// -*- coding: dos -*-
+// -*- coding: dos -*-\r
 //\r
 // attribute.cs: Attribute Handler\r
 //\r
@@ -87,19 +87,19 @@ namespace Mono.CSharp {
                 ///   Tries to resolve the type of the attribute. Flags an error if it can't.\r
                 /// </summary>\r
                private Type CheckAttributeType (EmitContext ec) {\r
-                       Type t;\r
+                       TypeExpr t;\r
                        bool isattributeclass = true;\r
                        \r
                        t = RootContext.LookupType (ec.DeclSpace, Name, true, Location);\r
                        if (t != null) {\r
-                               isattributeclass = t.IsSubclassOf (TypeManager.attribute_type);\r
+                               isattributeclass = t.IsAttribute;\r
                                if (isattributeclass)\r
-                                       return t;\r
+                                       return t.ResolveType (ec);\r
                        }\r
                        t = RootContext.LookupType (ec.DeclSpace, Name + "Attribute", true, Location);\r
                        if (t != null) {\r
-                               if (t.IsSubclassOf (TypeManager.attribute_type))\r
-                                       return t;\r
+                               if (t.IsAttribute)\r
+                                       return t.ResolveType (ec);\r
                        }\r
                        if (!isattributeclass) {\r
                                Report.Error (616, Location, "'" + Name + "': is not an attribute class");\r
@@ -632,21 +632,21 @@ namespace Mono.CSharp {
                                else\r
                                        return false;\r
                        } else if (element is Property || element is Indexer ||\r
-                                  element is Accessor) {
+                                  element is Accessor) {\r
                                if ((targets & AttributeTargets.Property) != 0)\r
                                        return true;\r
                                else\r
                                        return false;\r
-                       } else if (element is AssemblyClass){
+                       } else if (element is AssemblyClass){\r
                                if ((targets & AttributeTargets.Assembly) != 0)\r
                                        return true;\r
                                else\r
                                        return false;\r
-                       } else if (element is ModuleClass){
-                               if ((targets & AttributeTargets.Module) != 0)
-                                       return true;
-                               else
-                                       return false;
+                       } else if (element is ModuleClass){\r
+                               if ((targets & AttributeTargets.Module) != 0)\r
+                                       return true;\r
+                               else\r
+                                       return false;\r
                        }\r
 \r
                        return false;\r
@@ -872,15 +872,15 @@ namespace Mono.CSharp {
                                                return;\r
                                        }\r
 \r
-                                       if (kind is IAttributeSupport) {
-                                               if (attr_type == TypeManager.methodimpl_attr_type && a.ImplOptions == MethodImplOptions.InternalCall) {
-                                                       ((MethodBuilder) builder).SetImplementationFlags (MethodImplAttributes.InternalCall | MethodImplAttributes.Runtime);
-                                               } 
-                                               else {
-                                                       IAttributeSupport attributeSupport = kind as IAttributeSupport;
-                                                       attributeSupport.SetCustomAttribute (cb);
-                                               }
-                                       }
+                                       if (kind is IAttributeSupport) {\r
+                                               if (attr_type == TypeManager.methodimpl_attr_type && a.ImplOptions == MethodImplOptions.InternalCall) {\r
+                                                       ((MethodBuilder) builder).SetImplementationFlags (MethodImplAttributes.InternalCall | MethodImplAttributes.Runtime);\r
+                                               } \r
+                                               else {\r
+                                                       IAttributeSupport attributeSupport = kind as IAttributeSupport;\r
+                                                       attributeSupport.SetCustomAttribute (cb);\r
+                                               }\r
+                                       }\r
                                        else if (kind is Method || kind is Operator || kind is Accessor) {\r
                                                if (attr_type == TypeManager.methodimpl_attr_type) {\r
                                                        if (a.ImplOptions == MethodImplOptions.InternalCall)\r
@@ -909,15 +909,15 @@ namespace Mono.CSharp {
                                                        ((FieldBuilder) builder).SetCustomAttribute (cb);\r
                                                }\r
                                        } else if (kind is Property || kind is Indexer) {\r
-
-                                                if (builder is PropertyBuilder) 
+\r
+                                                if (builder is PropertyBuilder) \r
                                                ((PropertyBuilder) builder).SetCustomAttribute (cb);\r
-                                                //
-                                                // This is for the case we are setting attributes on
-                                                // the get and set accessors
-                                                //
-                                                else if (builder is MethodBuilder)
-                                                        ((MethodBuilder) builder).SetCustomAttribute (cb);
+                                                //\r
+                                                // This is for the case we are setting attributes on\r
+                                                // the get and set accessors\r
+                                                //\r
+                                                else if (builder is MethodBuilder)\r
+                                                        ((MethodBuilder) builder).SetCustomAttribute (cb);\r
                                        } else if (kind is Event) {\r
                                                ((MyEventBuilder) builder).SetCustomAttribute (cb);\r
                                        } else if (kind is ParameterBuilder) {\r
@@ -1220,8 +1220,8 @@ namespace Mono.CSharp {
                        return false;\r
                }\r
        }\r
-
-       public interface IAttributeSupport {
-               void SetCustomAttribute (CustomAttributeBuilder customBuilder);
-       }
+\r
+       public interface IAttributeSupport {\r
+               void SetCustomAttribute (CustomAttributeBuilder customBuilder);\r
+       }\r
 }\r
index 766f4f4a1d649cf99b2e14203fe028d9d5c88671..95fc8ea49a15551e4bc04288d9d6529d1d74cb66 100755 (executable)
@@ -1181,7 +1181,7 @@ namespace Mono.CSharp {
                        Class pclass = Parent as Class;
                        if (pclass != null) {
                                string pname = null;
-                               Type ptype = null;
+                               TypeExpr ptype = null;
                                Type t = pclass.TypeBuilder.BaseType;
                                while ((t != null) && (ptype == null)) {
                                        pname = t.FullName + "." + Basename;
index b688cca5078a504be1eeb61e9acb74acd454ba86..fd9cf8939c0bce366c8cc737b749663ab502f18c 100755 (executable)
@@ -321,8 +321,7 @@ using_alias_directive
        : USING IDENTIFIER ASSIGN 
          namespace_or_type_name SEMICOLON
          {
-               Expression expr = ((MemberName) $4).GetTypeExpression (lexer.Location);
-               current_namespace.UsingAlias ((string) $2, expr, lexer.Location);
+               current_namespace.UsingAlias ((string) $2, (MemberName) $4, lexer.Location);
          }
        | USING error {
                CheckIdentifierToken (yyToken);
index 9505b1f40a996eb3c98af2602204f75c9545d85d..257d5d5bea4ffe476a63963a4303ca5252eac87e 100755 (executable)
@@ -51,6 +51,15 @@ namespace Mono.CSharp {
                                return Name;
                }
 
+               public int CountTypeArguments {
+                       get {
+                               if (TypeArguments == null)
+                                       return 0;
+                               else
+                                       return TypeArguments.Count;
+                       }
+               }
+
                public string GetFullName ()
                {
                        string full_name;
@@ -183,7 +192,7 @@ namespace Mono.CSharp {
        ///   provides the common foundation for managing those name
        ///   spaces.
        /// </remarks>
-       public abstract class DeclSpace : MemberCore {
+       public abstract class DeclSpace : MemberCore, IAlias {
                /// <summary>
                ///   This points to the actual definition that is being
                ///   created with System.Reflection.Emit
@@ -364,7 +373,7 @@ namespace Mono.CSharp {
                /// <summary>
                ///   Looks up the alias for the name
                /// </summary>
-               public string LookupAlias (string name)
+               public IAlias LookupAlias (string name)
                {
                        if (NamespaceEntry != null)
                                return NamespaceEntry.LookupAlias (name);
@@ -808,11 +817,11 @@ namespace Mono.CSharp {
                        return t;
                }
 
-               public static void Error_AmbiguousTypeReference (Location loc, string name, Type t1, Type t2)
+               public static void Error_AmbiguousTypeReference (Location loc, string name, string t1, string t2)
                {
                        Report.Error (104, loc,
-                                     String.Format ("`{0}' is an ambiguous reference ({1} or {2}) ", name,
-                                                    t1.FullName, t2.FullName));
+                                     "`{0}' is an ambiguous reference ({1} or {2})",
+                                     name, t1, t2);
                }
 
                public Type FindNestedType (Location loc, string name,
@@ -937,7 +946,7 @@ namespace Mono.CSharp {
                                            TypeManager.CheckGeneric (match, num_type_args)) {
                                                if (t != null){
                                                        if (CheckAccessLevel (match)) {
-                                                               Error_AmbiguousTypeReference (loc, name, t, match);
+                                                               Error_AmbiguousTypeReference (loc, name, t.FullName, match.FullName);
                                                                return null;
                                                        }
                                                        continue;
@@ -1145,6 +1154,27 @@ namespace Mono.CSharp {
 
                        return null;
                }
+
+               bool IAlias.IsType {
+                       get { return true; }
+               }
+
+               string IAlias.Name {
+                       get { return Name; }
+               }
+
+               TypeExpr IAlias.Type
+               {
+                       get {
+                               if (TypeBuilder == null)
+                                       throw new InvalidOperationException ();
+
+                               if (CurrentType != null)
+                                       return CurrentType;
+
+                               return new TypeExpression (TypeBuilder, Location);
+                       }
+               }
        }
 
        /// <summary>
index 857ce268e16e284de07f1dfe9f20198384d9b9d1..ab5e4f4c34ca8f4e6bcde976206df821d8bf18ec 100755 (executable)
@@ -92,6 +92,25 @@ namespace Mono.CSharp {
                void AddressOf (EmitContext ec, AddressOp mode);
        }
 
+       /// <summary>
+       ///   We are either a namespace or a type.
+       ///   If we're a type, `IsType' is true and we may use `Type' to get
+       ///   a TypeExpr representing that type.
+       /// </summary>
+       public interface IAlias {
+               bool IsType {
+                       get;
+               }
+
+               string Name {
+                       get;
+               }
+
+               TypeExpr Type {
+                       get;
+               }
+       }
+
        /// <summary>
        ///   This interface is implemented by variables
        /// </summary>
@@ -2012,8 +2031,8 @@ namespace Mono.CSharp {
                {
                        DeclSpace ds = ec.DeclSpace;
                        NamespaceEntry ns = ds.NamespaceEntry;
-                       Type t;
-                       string alias_value;
+                       TypeExpr t;
+                       IAlias alias_value;
 
                        //
                        // Since we are cheating: we only do the Alias lookup for
@@ -2039,8 +2058,10 @@ namespace Mono.CSharp {
                                        return new TypeExpression (dt, loc);
 
                                if (alias_value != null){
-                                       if ((t = RootContext.LookupType (ds, alias_value, true, NumTypeArguments, loc)) != null)
-                                               return new TypeExpression (t, loc);
+                                       if (alias_value.IsType)
+                                               return alias_value.Type;
+                                       if ((t = RootContext.LookupType (ds, alias_value.Name, true, NumTypeArguments, loc)) != null)
+                                               return t;
                                }
                        }
 
@@ -2048,11 +2069,13 @@ namespace Mono.CSharp {
                        // First, the using aliases
                        //
                        if (alias_value != null){
-                               if ((t = RootContext.LookupType (ds, alias_value, true, loc)) != null)
-                                       return new TypeExpression (t, loc);
+                               if (alias_value.IsType)
+                                       return alias_value.Type;
+                               if ((t = RootContext.LookupType (ds, alias_value.Name, true, loc)) != null)
+                                       return t;
                                
                                // we have alias value, but it isn't Type, so try if it's namespace
-                               return new SimpleName (alias_value, loc);
+                               return new SimpleName (alias_value.Name, loc);
                        }
 
                        //
@@ -2061,7 +2084,7 @@ namespace Mono.CSharp {
                        //
 
                        if ((t = RootContext.LookupType (ds, Name, true, NumTypeArguments, loc)) != null)
-                               return new TypeExpression (t, loc);
+                               return t;
                                
                        // No match, maybe our parent can compose us
                        // into something meaningful.
@@ -2154,9 +2177,12 @@ namespace Mono.CSharp {
                                //
                                NamespaceEntry ns = ec.DeclSpace.NamespaceEntry;
                                if (is_base && ns != null){
-                                       string alias_value = ns.LookupAlias (Name);
+                                       IAlias alias_value = ns.LookupAlias (Name);
                                        if (alias_value != null){
-                                               Name = alias_value;
+                                               if (alias_value.IsType)
+                                                       return alias_value.Type;
+
+                                               Name = alias_value.Name;
                                                Type t;
 
                                                if ((t = TypeManager.LookupType (Name)) != null)
@@ -2235,7 +2261,7 @@ namespace Mono.CSharp {
        /// <summary>
        ///   Fully resolved expression that evaluates to a type
        /// </summary>
-       public abstract class TypeExpr : Expression {
+       public abstract class TypeExpr : Expression, IAlias {
                override public Expression ResolveAsTypeStep (EmitContext ec)
                {
                        TypeExpr t = DoResolveAsTypeStep (ec);
@@ -2333,9 +2359,19 @@ namespace Mono.CSharp {
                {
                        return Name;
                }
+
+               bool IAlias.IsType {
+                       get { return true; }
+               }
+
+               TypeExpr IAlias.Type {
+                       get {
+                               return this;
+                       }
+               }
        }
 
-       public class TypeExpression : TypeExpr {
+       public class TypeExpression : TypeExpr, IAlias {
                public TypeExpression (Type t, Location l)
                {
                        Type = t;
@@ -2353,6 +2389,12 @@ namespace Mono.CSharp {
                                return Type.ToString ();
                        }
                }
+
+               string IAlias.Name {
+                       get {
+                               return Type.FullName;
+                       }
+               }
        }
 
        /// <summary>
@@ -2370,8 +2412,17 @@ namespace Mono.CSharp {
 
                public override TypeExpr DoResolveAsTypeStep (EmitContext ec)
                {
-                       if (type == null)
-                               type = RootContext.LookupType (ec.DeclSpace, name, false, Location.Null);
+                       if (type == null) {
+                               TypeExpr texpr = RootContext.LookupType (
+                                       ec.DeclSpace, name, false, Location.Null);
+                               if (texpr == null)
+                                       return null;
+
+                               type = texpr.ResolveType (ec);
+                               if (type == null)
+                                       return null;
+                       }
+
                        return this;
                }
 
@@ -2382,6 +2433,99 @@ namespace Mono.CSharp {
                }
        }
 
+       public class TypeAliasExpression : TypeExpr, IAlias {
+               TypeExpr texpr;
+               TypeArguments args;
+               string name;
+
+               public TypeAliasExpression (TypeExpr texpr, TypeArguments args, Location l)
+               {
+                       this.texpr = texpr;
+                       this.args = args;
+                       loc = texpr.Location;
+
+                       eclass = ExprClass.Type;
+                       if (args != null)
+                               name = texpr.Name + "<" + args.ToString () + ">";
+                       else
+                               name = texpr.Name;
+               }
+
+               public override string Name {
+                       get { return name; }
+               }
+
+               public override TypeExpr DoResolveAsTypeStep (EmitContext ec)
+               {
+                       Type type = texpr.ResolveType (ec);
+                       if (type == null)
+                               return null;
+
+                       int num_args = TypeManager.GetNumberOfTypeArguments (type);
+
+                       if (args != null) {
+                               if (num_args == 0) {
+                                       Report.Error (308, loc,
+                                                     "The non-generic type `{0}' cannot " +
+                                                     "be used with type arguments.",
+                                                     TypeManager.CSharpName (type));
+                                       return null;
+                               }
+
+                               ConstructedType ctype = new ConstructedType (type, args, loc);
+                               return ctype.ResolveAsTypeTerminal (ec);
+                       } else if (num_args > 0) {
+                               Report.Error (305, loc,
+                                             "Using the generic type `{0}' " +
+                                             "requires {1} type arguments",
+                                             TypeManager.GetFullName (type), num_args);
+                               return null;
+                       }
+
+                       return new TypeExpression (type, loc);
+               }
+
+               public override Type ResolveType (EmitContext ec)
+               {
+                       TypeExpr t = ResolveAsTypeTerminal (ec);
+                       if (t == null)
+                               return null;
+
+                       type = t.ResolveType (ec);
+                       return type;
+               }
+
+               public override bool CheckAccessLevel (DeclSpace ds)
+               {
+                       return texpr.CheckAccessLevel (ds);
+               }
+
+               public override bool AsAccessible (DeclSpace ds, int flags)
+               {
+                       return texpr.AsAccessible (ds, flags);
+               }
+
+               public override bool IsClass {
+                       get { return texpr.IsClass; }
+               }
+
+               public override bool IsValueType {
+                       get { return texpr.IsValueType; }
+               }
+
+               public override bool IsInterface {
+                       get { return texpr.IsInterface; }
+               }
+
+               public override bool IsSealed {
+                       get { return texpr.IsSealed; }
+               }
+
+               public override bool IsAttribute {
+                       get { return texpr.IsAttribute; }
+               }
+       }
+
        /// <summary>
        ///   MethodGroup Expression.
        ///  
index 41caacb7dd9662adad8262a213e62dedc4f41e4b..d87c0b33d2962e410fd98f40f8cddf515156ed1f 100755 (executable)
@@ -6970,7 +6970,7 @@ namespace Mono.CSharp {
 
                        SimpleName sn = (SimpleName) left_original;
 
-                       Type t = RootContext.LookupType (ec.DeclSpace, sn.Name, true, loc);
+                       TypeExpr t = RootContext.LookupType (ec.DeclSpace, sn.Name, true, loc);
                        if (t != null)
                                return true;
 
@@ -8446,9 +8446,13 @@ namespace Mono.CSharp {
                                //
                                // For now, fall back to the full lookup in that case.
                                //
-                               type = RootContext.LookupType (
+                               TypeExpr texpr = RootContext.LookupType (
                                        ec.DeclSpace, cname, false, loc);
 
+                               if (texpr == null)
+                                       return null;
+
+                               type = texpr.ResolveType (ec);
                                if (type == null)
                                        return null;
                        }
index 23076a505ff6e17d29ae1da5e8be4318eeb34e2c..b8da9ae1eb26c09ad9e60338ae463952be21395d 100644 (file)
@@ -587,6 +587,9 @@ namespace Mono.CSharp {
                                return this;
                        }
 
+                       Type t;
+                       int num_args;
+
                        SimpleName sn = new SimpleName (name, args.Count, loc);
                        TypeExpr resolved = sn.ResolveAsTypeTerminal (ec);
                        if (resolved == null) {
@@ -599,8 +602,8 @@ namespace Mono.CSharp {
                                        return null;
                                }
 
-                               Type t = resolved.Type;
-                               int num_args = TypeManager.GetNumberOfTypeArguments (t);
+                               t = resolved.Type;
+                               num_args = TypeManager.GetNumberOfTypeArguments (t);
 
                                if (num_args == 0) {
                                        Report.Error (308, loc,
@@ -617,12 +620,22 @@ namespace Mono.CSharp {
                                return null;
                        }
 
-                       if (resolved.Type == null)
-                               throw new InternalErrorException (
-                                       "Failed to resolve constructed type `{0}'",
-                                       full_name);
+                       t = resolved.Type;
+                       if (t == null) {
+                               Report.Error (246, loc, "Cannot find type `{0}'", full_name);
+                               return null;
+                       }
+
+                       num_args = TypeManager.GetNumberOfTypeArguments (t);
+                       if (num_args == 0) {
+                               Report.Error (308, loc,
+                                             "The non-generic type `{0}' cannot " +
+                                             "be used with type arguments.",
+                                             TypeManager.CSharpName (t));
+                               return null;
+                       }
 
-                       gt = resolved.Type.GetGenericTypeDefinition ();
+                       gt = t.GetGenericTypeDefinition ();
                        return this;
                }
 
@@ -643,9 +656,11 @@ namespace Mono.CSharp {
                        atypes = args.Arguments;
 
                        if (atypes.Length != gen_params.Length) {
-                               Report.Error (-217, loc, "Generic type `{0}' takes {1} " +
-                                             "type parameters, but specified {2}.", gt.Name,
-                                             gen_params.Length, atypes.Length);
+                               Report.Error (305, loc,
+                                             "Using the generic type `{0}' " +
+                                             "requires {1} type arguments",
+                                             TypeManager.GetFullName (gt),
+                                             gen_params.Length);
                                return null;
                        }
 
index a810e9aeddacbe3ddb98ac0b6a32393de344b122..57be10bfc074bf894539758ad449364e28500559 100755 (executable)
@@ -14,7 +14,7 @@ namespace Mono.CSharp {
        /// <summary>
        ///   Keeps track of the namespaces defined in the C# code.
        /// </summary>
-       public class Namespace {
+       public class Namespace : IAlias {
                static ArrayList all_namespaces = new ArrayList ();
                static Hashtable namespaces_map = new Hashtable ();
                
@@ -88,9 +88,9 @@ namespace Mono.CSharp {
                        return Root.GetNamespace (name, create);
                }
 
-               public object Lookup (DeclSpace ds, string name)
+               public IAlias Lookup (DeclSpace ds, string name, Location loc)
                {
-                       object o = Lookup (name);
+                       IAlias o = Lookup (name);
 
                        Type t;
                        DeclSpace tdecl = o as DeclSpace;
@@ -98,7 +98,7 @@ namespace Mono.CSharp {
                                t = tdecl.DefineType ();
 
                                if ((ds == null) || ds.CheckAccessLevel (t))
-                                       return t;
+                                       return new TypeExpression (t, loc);
                        }
 
                        Namespace ns = GetNamespace (name, false);
@@ -109,7 +109,7 @@ namespace Mono.CSharp {
                        if ((t == null) || ((ds != null) && !ds.CheckAccessLevel (t)))
                                return null;
 
-                       return t;
+                       return new TypeExpression (t, loc);
                }
 
                public void AddNamespaceEntry (NamespaceEntry entry)
@@ -117,14 +117,14 @@ namespace Mono.CSharp {
                        entries.Add (entry);
                }
 
-               public void DefineName (string name, object o)
+               public void DefineName (string name, IAlias o)
                {
                        defined_names.Add (name, o);
                }
 
-               public object Lookup (string name)
+               public IAlias Lookup (string name)
                {
-                       return defined_names [name];
+                       return (IAlias) defined_names [name];
                }
 
                static public ArrayList UserDefinedNamespaces {
@@ -179,6 +179,16 @@ namespace Mono.CSharp {
                        else
                                return String.Format ("Namespace ({0})", Name);
                }
+
+               bool IAlias.IsType {
+                       get { return false; }
+               }
+
+               TypeExpr IAlias.Type {
+                       get {
+                               throw new InvalidOperationException ();
+                       }
+               }
        }
 
        public class NamespaceEntry
@@ -231,11 +241,11 @@ namespace Mono.CSharp {
 
                public class AliasEntry {
                        public readonly string Name;
-                       public readonly Expression Alias;
+                       public readonly MemberName Alias;
                        public readonly NamespaceEntry NamespaceEntry;
                        public readonly Location Location;
                        
-                       public AliasEntry (NamespaceEntry entry, string name, Expression alias, Location loc)
+                       public AliasEntry (NamespaceEntry entry, string name, MemberName alias, Location loc)
                        {
                                Name = name;
                                Alias = alias;
@@ -243,9 +253,9 @@ namespace Mono.CSharp {
                                Location = loc;
                        }
 
-                       object resolved;
+                       IAlias resolved;
 
-                       public object Resolve ()
+                       public IAlias Resolve ()
                        {
                                if (resolved != null)
                                        return resolved;
@@ -257,14 +267,23 @@ namespace Mono.CSharp {
                                // this will fail with `using A = Stack<int>'
                                //
                                
-                               string alias = Alias.ToString ();
+                               string alias = Alias.GetMemberName ();
                                while ((curr_ns != null) && (resolved == null)) {
-                                       resolved = curr_ns.Lookup (null, alias, Location);
+                                       resolved = curr_ns.Lookup (
+                                               null, alias, Alias.CountTypeArguments,
+                                               Location);
 
                                        if (resolved == null)
                                                curr_ns = curr_ns.Parent;
                                }
 
+                               if (resolved == null)
+                                       return null;
+
+                               if (resolved.IsType)
+                                       resolved = new TypeAliasExpression (
+                                               resolved.Type, Alias.TypeArguments, Location);
+
                                return resolved;
                        }
                }
@@ -319,7 +338,7 @@ namespace Mono.CSharp {
                        }
                }
 
-               public void DefineName (string name, object o)
+               public void DefineName (string name, IAlias o)
                {
                        ns.DefineName (name, o);
                }
@@ -352,18 +371,18 @@ namespace Mono.CSharp {
                        using_clauses.Add (ue);
                }
 
-               public void UsingAlias (string alias, Expression namespace_or_type, Location loc)
+               public void UsingAlias (string name, MemberName alias, Location loc)
                {
                        if (aliases == null)
                                aliases = new Hashtable ();
-                       
-                       if (aliases.Contains (alias)){
-                               Report.Error (1537, loc, "The using alias `" + alias +
+
+                       if (aliases.Contains (name)){
+                               Report.Error (1537, loc, "The using alias `" + name +
                                              "' appeared previously in this namespace");
                                return;
                        }
 
-                       aliases [alias] = new AliasEntry (this, alias, namespace_or_type, loc);
+                       aliases [name] = new AliasEntry (this, name, alias, loc);
                }
 
                protected AliasEntry GetAliasEntry (string alias)
@@ -378,25 +397,20 @@ namespace Mono.CSharp {
                        return entry;
                }
 
-               public string LookupAlias (string alias)
+               public IAlias LookupAlias (string alias)
                {
                        AliasEntry entry = GetAliasEntry (alias);
 
                        if (entry == null)
                                return null;
 
-                       object resolved = entry.Resolve ();
-                       if (resolved == null)
-                               return null;
-                       else if (resolved is Namespace)
-                               return ((Namespace) resolved).Name;
-                       else
-                               return ((Type) resolved).FullName;
+                       return entry.Resolve ();
                }
 
-               public object Lookup (DeclSpace ds, string name, Location loc)
+               public IAlias Lookup (DeclSpace ds, string name, int num_type_params,
+                                     Location loc)
                {
-                       object o;
+                       IAlias o;
                        Namespace ns;
 
                        //
@@ -407,25 +421,27 @@ namespace Mono.CSharp {
                                string first = name.Substring (0, pos);
                                string last = name.Substring (pos + 1);
 
-                               o = Lookup (ds, first, loc);
+                               o = Lookup (ds, first, 0, loc);
                                if (o == null)
                                        return null;
 
                                ns = o as Namespace;
-                               if (ns != null)
-                                       return ns.Lookup (ds, last);
+                               if (ns != null) {
+                                       o = ns.Lookup (ds, last, loc);
+                                       return o;
+                               }
 
-                               Type nested = TypeManager.LookupType ((((Type) o).Name + "." + last));
+                               Type nested = TypeManager.LookupType (o.Name + "." + last);
                                if ((nested == null) || ((ds != null) && !ds.CheckAccessLevel (nested)))
                                        return null;
 
-                               return nested;
+                               return new TypeExpression (nested, loc);
                        }
 
                        //
                        // Check whether it's a namespace.
                        //
-                       o = NS.Lookup (ds, name);
+                       o = NS.Lookup (ds, name, loc);
                        if (o != null)
                                return o;
 
@@ -434,20 +450,20 @@ namespace Mono.CSharp {
                        //
                        AliasEntry entry = GetAliasEntry (name);
                        if (entry != null) {
-                               o = entry.Resolve ();
-                               if (o != null)
-                                       return o;
+                               IAlias alias = entry.Resolve ();
+                               if (alias != null)
+                                       return alias;
                        }
 
                        //
                        // Check using entries.
                        //
-                       Type t = null, match = null;
+                       IAlias t = null, match = null;
                        foreach (Namespace using_ns in GetUsingTable ()) {
-                               match = using_ns.Lookup (ds, name) as Type;
-                               if (match != null){
+                               match = using_ns.Lookup (ds, name, loc);
+                               if ((match != null) && match.IsType){
                                        if (t != null) {
-                                               DeclSpace.Error_AmbiguousTypeReference (loc, name, t, match);
+                                               DeclSpace.Error_AmbiguousTypeReference (loc, name, t.Name, match.Name);
                                                return null;
                                        } else {
                                                t = match;
index 7f74cd5fb4477c6a90c25baa5307f74e8a00bd79..45469a4dd09c2374f9202ec2da819287a31671bf 100755 (executable)
@@ -470,33 +470,29 @@ namespace Mono.CSharp {
                        return ns.Substring (0, i);
                }
 
-               static Type NamespaceLookup (DeclSpace ds, string name,
-                                            int num_type_args, Location loc)
+               static TypeExpr NamespaceLookup (DeclSpace ds, string name,
+                                                int num_type_args, Location loc)
                {
                        //
                        // Try in the current namespace and all its implicit parents
                        //
                        for (NamespaceEntry ns = ds.NamespaceEntry; ns != null; ns = ns.ImplicitParent) {
-                               object result = ns.Lookup (ds, name, loc);
+                               IAlias result = ns.Lookup (ds, name, num_type_args, loc);
+
                                if (result == null)
                                        continue;
 
-                               Type t = result as Type;
-                               if (t != null) {
-                                       if (TypeManager.CheckGeneric (t, num_type_args))
-                                               return t;
-                                       else
-                                               continue;
-                               }
+                               if (!result.IsType)
+                                       return null;
 
-                               return null;
+                               return result.Type;
                        }
 
                        return null;
                }
                
-               static public Type LookupType (DeclSpace ds, string name, bool silent,
-                                              Location loc)
+               static public TypeExpr LookupType (DeclSpace ds, string name, bool silent,
+                                                  Location loc)
                {
                        return LookupType (ds, name, silent, 0, loc);
                }
@@ -509,13 +505,13 @@ namespace Mono.CSharp {
                //
                // Come to think of it, this should be a DeclSpace
                //
-               static public Type LookupType (DeclSpace ds, string name, bool silent,
-                                              int num_type_params, Location loc)
+               static public TypeExpr LookupType (DeclSpace ds, string name, bool silent,
+                                                  int num_type_params, Location loc)
                {
-                       Type t;
+                       TypeExpr t;
 
                        if (ds.Cache.Contains (name)){
-                               t = (Type) ds.Cache [name];
+                               t = (TypeExpr) ds.Cache [name];
                                if (t != null)
                                        return t;
                        } else {
@@ -531,8 +527,9 @@ namespace Mono.CSharp {
                                                //
                                                // nested class
                                                //
-                                               t = TypeManager.LookupType (current_type.FullName + "." + name);
-                                               if (t != null){
+                                               Type type = TypeManager.LookupType (current_type.FullName + "." + name);
+                                               if (type != null){
+                                                       t = new TypeExpression (type, loc);
                                                        ds.Cache [name] = t;
                                                        return t;
                                                }
@@ -560,7 +557,7 @@ namespace Mono.CSharp {
                //   This is the silent version of LookupType, you can use this
                //   to `probe' for a type
                // </summary>
-               static public Type LookupType (TypeContainer tc, string name, Location loc)
+               static public TypeExpr LookupType (TypeContainer tc, string name, Location loc)
                {
                        return LookupType (tc, name, true, loc);
                }