**** Merged r38695 from MCS ****
authorMartin Baulig <martin@novell.com>
Wed, 26 Jan 2005 07:31:07 +0000 (07:31 -0000)
committerMartin Baulig <martin@novell.com>
Wed, 26 Jan 2005 07:31:07 +0000 (07:31 -0000)
svn path=/trunk/mcs/; revision=39540

mcs/gmcs/ChangeLog
mcs/gmcs/attribute.cs
mcs/gmcs/codegen.cs
mcs/gmcs/decl.cs
mcs/gmcs/doc.cs
mcs/gmcs/ecore.cs
mcs/gmcs/expression.cs
mcs/gmcs/generic.cs
mcs/gmcs/namespace.cs
mcs/gmcs/rootcontext.cs

index d9fbaa8ba60f5da5f2fe099d0adb8021892361ba..c74eac0e0bc5096eee4bd5b4f5375ab1117331c9 100644 (file)
@@ -3,6 +3,37 @@
        * doc.cs
        (DocUtil.emptyParamList): Removed; use `Type.EmptyTypes' instead.
 
+2005-01-11  Raja R Harinath  <rharinath@novell.com>
+
+       Improve standard-compliance of simple name and member access 
+       resolution.  Fixes bugs #52697, #57200, #67520, #69519.
+       * ecore.cs (FullNamedExpression): New abstract base class 
+       for Namespaces and TypeExpressions.
+       (ResolveFlags.SimpleName): Remove.
+       (SimpleName): Remove support for dotted names.
+       (SimpleName.ResolveAsTypeStep): Simplify.  Now just a wrapper to 
+       DeclSpace.FindType and DeclSpace.LookupType.
+       (SimpleName.DoSimpleNameResolve): Remove support for dotted names.
+       (Expression.ExprClassName): Make member function.
+       * expression.cs (MemberAccess.ResolveAsTypeStep): Support LHS being
+       a namespace.  Remove creation of dotted "SimpleName"s.
+       (MemberAccess.DoResolve): Likewise.
+       * decl.cs (DeclSpace.Cache): Make private.
+       (DeclSpace.LookupInterfaceOrClass): Return a FullNamedExpression.
+       (DeclSpace.FindType): Update.
+       (DeclSpace.LookupType): Move here from RootContext.  Return a 
+       FullNamedExpression.
+       * namespace.cs (Namespace): Derive from FullNamedExpression
+       so that it can be part of expression resolution.
+       (Namespace.Lookup): Return an FullNamedExpression.
+       (NamespaceEntry.LookupAlias): Lookup aliases only in current
+       namespace.
+       * rootcontext.cs (NamespaceLookup): Remove.
+       (LookupType): Move to DeclSpace.
+       * attribute.cs (CheckAttributeType): Update.
+       * doc.cs (FindDocumentedType): Remove allowAlias argument.
+       (FindDocumentedTypeNonArray): Likewise.
+
 2005-01-11  Raja R Harinath  <rharinath@novell.com>
 
        Fix cs0509.cs, cs1632.cs.
index 9ff4d9bfbb18ac8686f9856ea0b62e818dbf4666..4d3a2dd48b875f88647bc8fd2d1b6e672cf18c12 100644 (file)
@@ -161,14 +161,20 @@ namespace Mono.CSharp {
                protected virtual Type CheckAttributeType (EmitContext ec)
                {
                        string NameAttribute = Name + "Attribute";
-                       Type t1 = ec.ResolvingTypeTree
+                       FullNamedExpression n1 = ec.ResolvingTypeTree
                                ? ec.DeclSpace.FindType (Location, Name)
-                               : RootContext.LookupType (ec.DeclSpace, Name, true, Location);
+                               : ec.DeclSpace.LookupType (Name, true, Location);
 
                        // FIXME: Shouldn't do this for quoted attributes: [@A]
-                       Type t2 = ec.ResolvingTypeTree
+                       FullNamedExpression n2 = ec.ResolvingTypeTree
                                ? ec.DeclSpace.FindType (Location, NameAttribute)
-                               : RootContext.LookupType (ec.DeclSpace, NameAttribute, true, Location);
+                               : ec.DeclSpace.LookupType (NameAttribute, true, Location);
+
+                       TypeExpr e1 = n1 == null ? null : n1 as TypeExpr;
+                       TypeExpr e2 = n2 == null ? null : n2 as TypeExpr;                       
+
+                       Type t1 = e1 == null ? null : e1.ResolveType (ec);
+                       Type t2 = e2 == null ? null : e2.ResolveType (ec);
 
                        String err0616 = null;
                        if (t1 != null && ! t1.IsSubclassOf (TypeManager.attribute_type)) {
index 36fc47b8cf3c8602613ccaeb4dcc89a695eadf41..7f5d62efb21963cc23558a1e2ba0159949972416 100644 (file)
@@ -435,6 +435,9 @@ namespace Mono.CSharp {
                        DeclSpace = ds;
                        CheckState = RootContext.Checked;
                        ConstantCheckState = true;
+
+                       if ((return_type is TypeBuilder) && return_type.IsGenericTypeDefinition)
+                               throw new Exception ("FUCK");
                        
                        IsStatic = (code_flags & Modifiers.STATIC) != 0;
                        InIterator = (code_flags & Modifiers.METHOD_YIELDS) != 0;
index 9d71ad01cdbc1618f2efaf2728305b4f721b29e9..0287207adbd741c2915a57557b8c3d1e44729eb2 100644 (file)
@@ -526,7 +526,7 @@ namespace Mono.CSharp {
                //
                public NamespaceEntry NamespaceEntry;
 
-               public Hashtable Cache = new Hashtable ();
+               private Hashtable Cache = new Hashtable ();
                
                public string Basename;
                
@@ -642,17 +642,6 @@ namespace Mono.CSharp {
                                in_transit = value;
                        }
                }
-
-               /// <summary>
-               ///   Looks up the alias for the name
-               /// </summary>
-               public IAlias LookupAlias (string name)
-               {
-                       if (NamespaceEntry != null)
-                               return NamespaceEntry.LookupAlias (name);
-                       else
-                               return null;
-               }
                
                // 
                // root_types contains all the types.  All TopLevel types
@@ -723,16 +712,16 @@ namespace Mono.CSharp {
 
                EmitContext type_resolve_ec;
 
-               public Type ResolveNestedType (Type t, Location loc)
+               public FullNamedExpression ResolveNestedType (FullNamedExpression t, Location loc)
                {
-                       TypeContainer tc = TypeManager.LookupTypeContainer (t);
+                       TypeContainer tc = TypeManager.LookupTypeContainer (t.Type);
                        if ((tc != null) && tc.IsGeneric) {
                                if (!IsGeneric) {
-                                       int tnum = TypeManager.GetNumberOfTypeArguments (t);
+                                       int tnum = TypeManager.GetNumberOfTypeArguments (t.Type);
                                        Report.Error (305, loc,
                                                      "Using the generic type `{0}' " +
                                                      "requires {1} type arguments",
-                                                     TypeManager.GetFullName (t), tnum);
+                                                     TypeManager.GetFullName (t.Type), tnum);
                                        return null;
                                }
 
@@ -742,12 +731,8 @@ namespace Mono.CSharp {
                                else
                                        args = TypeParameters;
 
-                               TypeExpr ctype = new ConstructedType (t, args, loc);
-                               ctype = ctype.ResolveAsTypeTerminal (ec);
-                               if (ctype == null)
-                                       return null;
-
-                               t = ctype.Type;
+                               TypeExpr ctype = new ConstructedType (t.Type, args, loc);
+                               return ctype.ResolveAsTypeTerminal (ec);
                        }
 
                        return t;
@@ -997,16 +982,17 @@ namespace Mono.CSharp {
                        return tc.DefineType ();
                }
                
-               Type LookupInterfaceOrClass (string ns, string name, out bool error)
+               FullNamedExpression LookupInterfaceOrClass (string ns, string name, out bool error)
                {
                        DeclSpace parent;
+                       FullNamedExpression result;
                        Type t;
                        object r;
                        
                        error = false;
 
                        if (dh.Lookup (ns, name, out r))
-                               return (Type) r;
+                               return (FullNamedExpression) r;
                        else {
                                if (ns != ""){
                                        if (Namespace.IsNamespace (ns)){
@@ -1019,8 +1005,23 @@ namespace Mono.CSharp {
                        }
                        
                        if (t != null) {
-                               dh.Insert (ns, name, t);
-                               return t;
+                               result = new TypeExpression (t, Location.Null);
+                               dh.Insert (ns, name, result);
+                               return result;
+                       }
+
+                       if (ns != "" && Namespace.IsNamespace (ns)) {
+                               result = Namespace.LookupNamespace (ns, false).Lookup (this, name, Location.Null);
+                               if (result != null) {
+                                       dh.Insert (ns, name, result);
+                                       return result;
+                               }
+                       }
+
+                       if (ns == "" && Namespace.IsNamespace (name)) {
+                               result = Namespace.LookupNamespace (name, false);
+                               dh.Insert (ns, name, result);
+                               return result;
                        }
 
                        //
@@ -1031,7 +1032,10 @@ namespace Mono.CSharp {
                                ns = MakeFQN (ns, name.Substring (0, p));
                                name = name.Substring (p+1);
                        }
-                       
+
+                       if (ns.IndexOf ('+') != -1)
+                               ns = ns.Replace ('+', '.');
+
                        parent = RootContext.Tree.LookupByNamespace (ns, name);
                        if (parent == null) {
                                dh.Insert (ns, name, null);
@@ -1044,8 +1048,9 @@ namespace Mono.CSharp {
                                return null;
                        }
                        
-                       dh.Insert (ns, name, t);
-                       return t;
+                       result = new TypeExpression (t, Location.Null);
+                       dh.Insert (ns, name, result);
+                       return result;
                }
 
                public static void Error_AmbiguousTypeReference (Location loc, string name, string t1, string t2)
@@ -1058,7 +1063,7 @@ namespace Mono.CSharp {
                public Type FindNestedType (Location loc, string name,
                                            out DeclSpace containing_ds)
                {
-                       Type t;
+                       FullNamedExpression t;
                        bool error;
 
                        containing_ds = this;
@@ -1073,8 +1078,8 @@ namespace Mono.CSharp {
                                        if (error)
                                                return null;
 
-                                       if ((t != null) && containing_ds.CheckAccessLevel (t))
-                                               return t;
+                                       if ((t != null) && containing_ds.CheckAccessLevel (t.Type))
+                                               return t.Type;
 
                                        current_type = current_type.BaseType;
                                }
@@ -1096,15 +1101,16 @@ namespace Mono.CSharp {
                ///   during the tree resolution process and potentially define
                ///   recursively the type
                /// </remarks>
-               public Type FindType (Location loc, string name)
+               public FullNamedExpression FindType (Location loc, string name)
                {
-                       Type t;
+                       FullNamedExpression t;
                        bool error;
 
                        //
                        // For the case the type we are looking for is nested within this one
                        // or is in any base class
                        //
+
                        DeclSpace containing_ds = this;
 
                        while (containing_ds != null){
@@ -1118,7 +1124,7 @@ namespace Mono.CSharp {
                                        if (error)
                                                return null;
 
-                                       if ((t != null) && containing_ds.CheckAccessLevel (t))
+                                       if ((t != null) && containing_ds.CheckAccessLevel (t.Type))
                                                return ResolveNestedType (t, loc);
 
                                        current_type = current_type.BaseType;
@@ -1165,34 +1171,27 @@ namespace Mono.CSharp {
                                if (name.IndexOf ('.') > 0)
                                        continue;
 
-                               IAlias alias_value = ns.LookupAlias (name);
-                               if (alias_value != null) {
-                                       t = LookupInterfaceOrClass ("", alias_value.Name, out error);
-                                       if (error)
-                                               return null;
-
-                                       if (t != null)
-                                               return t;
-                               }
+                               t = ns.LookupAlias (name);
+                               if (t != null)
+                                       return t;
 
                                //
                                // Now check the using clause list
                                //
-                               Type match = null;
+                               FullNamedExpression match = null;
                                foreach (Namespace using_ns in ns.GetUsingTable ()) {
                                        match = LookupInterfaceOrClass (using_ns.Name, name, out error);
                                        if (error)
                                                return null;
 
-                                       if (match != null) {
-                                               if (t != null){
-                                                       if (CheckAccessLevel (match)) {
-                                                               Error_AmbiguousTypeReference (loc, name, t.FullName, match.FullName);
-                                                               return null;
-                                                       }
+                                       if ((match != null) && (match is TypeExpr)) {
+                                               Type matched = ((TypeExpr) match).Type;
+                                               if (!CheckAccessLevel (matched))
                                                        continue;
+                                               if (t != null){
+                                                       Error_AmbiguousTypeReference (loc, name, t.FullName, match.FullName);
+                                                       return null;
                                                }
-                                               
                                                t = match;
                                        }
                                }
@@ -1204,6 +1203,76 @@ namespace Mono.CSharp {
                        return null;
                }
 
+               //
+               // Public function used to locate types, this can only
+               // be used after the ResolveTree function has been invoked.
+               //
+               // Returns: Type or null if they type can not be found.
+               //
+               // Come to think of it, this should be a DeclSpace
+               //
+               public FullNamedExpression LookupType (string name, bool silent, Location loc)
+               {
+                       FullNamedExpression e;
+
+                       if (Cache.Contains (name)) {
+                               e = (FullNamedExpression) Cache [name];
+                       } else {
+                               //
+                               // For the case the type we are looking for is nested within this one
+                               // or is in any base class
+                               //
+                               DeclSpace containing_ds = this;
+                               while (containing_ds != null){
+                                       
+                                       // if the member cache has been created, lets use it.
+                                       // the member cache is MUCH faster.
+                                       if (containing_ds.MemberCache != null) {
+                                               Type t = containing_ds.MemberCache.FindNestedType (name);
+                                               if (t == null) {
+                                                       containing_ds = containing_ds.Parent;
+                                                       continue;
+                                               }
+
+                                               e = new TypeExpression (t, Location.Null);
+                                               e = ResolveNestedType (e, Location.Null);
+                                               Cache [name] = e;
+                                               return e;
+                                       }
+                                       
+                                       // no member cache. Do it the hard way -- reflection
+                                       Type current_type = containing_ds.TypeBuilder;
+                                       
+                                       while (current_type != null &&
+                                              current_type != TypeManager.object_type) {
+                                               //
+                                               // nested class
+                                               //
+                                               Type t = TypeManager.LookupType (current_type.FullName + "." + name);
+                                               if (t != null){
+                                                       e = new TypeExpression (t, Location.Null);
+                                                       e = ResolveNestedType (e, Location.Null);
+                                                       Cache [name] = e;
+                                                       return e;
+                                               }
+                                               
+                                               current_type = current_type.BaseType;
+                                       }
+                                       
+                                       containing_ds = containing_ds.Parent;
+                               }
+                               
+                               e = NamespaceEntry.LookupNamespaceOrType (this, name, loc);
+                               if (!silent || e != null)
+                                       Cache [name] = e;
+                       }
+
+                       if (e == null && !silent)
+                               Report.Error (246, loc, "Cannot find type `"+name+"'");
+                       
+                       return e;
+               }
+
                /// <remarks>
                ///   This function is broken and not what you're looking for.  It should only
                ///   be used while the type is still being created since it doesn't use the cache
@@ -2118,6 +2187,22 @@ namespace Mono.CSharp {
                        return copy;
                }
                
+               // find the nested type @name in @this.
+               public Type FindNestedType (string name)
+               {
+                       ArrayList applicable = (ArrayList) member_hash [name];
+                       if (applicable == null)
+                               return null;
+                       
+                       for (int i = applicable.Count-1; i >= 0; i--) {
+                               CacheEntry entry = (CacheEntry) applicable [i];
+                               if ((entry.EntryType & EntryType.NestedType & EntryType.MaskType) != 0)
+                                       return (Type) entry.Member;
+                       }
+                       
+                       return null;
+               }
+               
                //
                // This finds the method or property for us to override. invocationType is the type where
                // the override is going to be declared, name is the name of the method/property, and
index c02c55202820598ae1e0ef27201d8ff4bf1783c2..094cf32a7edb403dfb434dc163709b43933fff4e 100644 (file)
@@ -261,8 +261,7 @@ namespace Mono.CSharp {
                // returns a full runtime type name from a name which might
                // be C# specific type name.
                //
-               private static Type FindDocumentedType (MemberCore mc,
-                       string name, DeclSpace ds, bool allowAlias, string cref)
+               private static Type FindDocumentedType (MemberCore mc, string name, DeclSpace ds, string cref)
                {
                        bool isArray = false;
                        string identifier = name;
@@ -273,16 +272,14 @@ namespace Mono.CSharp {
                                        isArray = true;
                                }
                        }
-                       Type t = FindDocumentedTypeNonArray (mc, identifier,
-                               ds, allowAlias, cref);
+                       Type t = FindDocumentedTypeNonArray (mc, identifier, ds, cref);
                        if (t != null && isArray)
                                t = Array.CreateInstance (t, 0).GetType ();
                        return t;
                }
 
-               private static Type FindDocumentedTypeNonArray (MemberCore mc,
-                       string identifier, DeclSpace ds, bool allowAlias,
-                       string cref)
+               private static Type FindDocumentedTypeNonArray (MemberCore mc, 
+                       string identifier, DeclSpace ds, string cref)
                {
                        switch (identifier) {
                        case "int":
@@ -318,30 +315,23 @@ namespace Mono.CSharp {
                        case "void":
                                return typeof (void);
                        }
-                       if (allowAlias) {
-                               IAlias alias = ds.LookupAlias (identifier);
-                               if (alias != null)
-                                       identifier = alias.Name;
-                       }
-                       Type t = ds.FindType (mc.Location, identifier);
-                       if (t == null)
-                               t = TypeManager.LookupType (identifier);
-                       if (t == null) {
-                               int index = identifier.LastIndexOf ('.');
-                               if (index < 0)
+                       FullNamedExpression e = ds.FindType (mc.Location, identifier);
+                       if (e != null) {
+                               if (!(e is TypeExpr))
                                        return null;
-                               int warn;
-                               Type parent = FindDocumentedType (mc,
-                                       identifier.Substring (0, index),
-                                       ds, allowAlias, cref);
-                               if (parent == null)
-                                       return null;
-                               t = FindDocumentedMember (mc, parent,
-                                       identifier.Substring (index + 1),
-                                       Type.EmptyTypes,
-                                       ds, out warn, cref) as Type;
-                       }
-                       return t;
+                               return ((TypeExpr) e).ResolveType (ds.EmitContext);
+                       }
+                       int index = identifier.LastIndexOf ('.');
+                       if (index < 0)
+                               return null;
+                       int warn;
+                       Type parent = FindDocumentedType (mc, identifier.Substring (0, index), ds, cref);
+                       if (parent == null)
+                               return null;
+                       return FindDocumentedMember (mc, parent,
+                               identifier.Substring (index + 1),
+                               Type.EmptyTypes,
+                               ds, out warn, cref) as Type;
                }
 
                //
@@ -465,7 +455,7 @@ namespace Mono.CSharp {
                                ((PropertyInfo) mi).PropertyType :
                                null;
                        if (returnTypeName != null) {
-                               Type returnType = FindDocumentedType (mc, returnTypeName, ds, true, cref);
+                               Type returnType = FindDocumentedType (mc, returnTypeName, ds, cref);
                                if (returnType == null || returnType != expected) {
                                        warningType = 1581;
                                        Report.Warning (1581, 1, mc.Location, "Invalid return type in XML comment cref attribute '{0}'", cref);
@@ -544,7 +534,7 @@ namespace Mono.CSharp {
                                ArrayList plist = new ArrayList ();
                                for (int i = 0; i < paramList.Length; i++) {
                                        string paramTypeName = paramList [i].Trim (wsChars);
-                                       Type paramType = FindDocumentedType (mc, paramTypeName, ds, true, cref);
+                                       Type paramType = FindDocumentedType (mc, paramTypeName, ds, cref);
                                        if (paramType == null) {
                                                Report.Warning (1580, 1, mc.Location, "Invalid type for parameter '{0}' in XML comment cref attribute '{1}'", i + 1, cref);
                                                return;
@@ -564,7 +554,7 @@ namespace Mono.CSharp {
                                parameters = sb.ToString ();
                        }
 
-                       Type type = FindDocumentedType (mc, name, ds, true, cref);
+                       Type type = FindDocumentedType (mc, name, ds, cref);
                        if (type != null) {
                                xref.SetAttribute ("cref", "T:" + type.FullName.Replace ("+", "."));
                                return; // a type
@@ -580,7 +570,7 @@ namespace Mono.CSharp {
                        if (period > 0) {
                                string typeName = name.Substring (0, period);
                                string memberName = name.Substring (period + 1);
-                               type = FindDocumentedType (mc, typeName, ds, false, cref);
+                               type = FindDocumentedType (mc, typeName, ds, cref);
                                int warnResult;
                                if (type != null) {
                                        MemberInfo mi = FindDocumentedMember (mc, type, memberName, parameterTypes, ds, out warnResult, cref);
index 2ddfafd98e70d159c320faa4c34da2e9cebfe6dd..6289b55a7235a1a3a4e0658b6d781f12dfa05423 100644 (file)
@@ -51,20 +51,15 @@ namespace Mono.CSharp {
                // Returns a method group.
                MethodGroup             = 4,
 
-               // Allows SimpleNames to be returned.
-               // This is used by MemberAccess to construct long names that can not be
-               // partially resolved (namespace-qualified names for example).
-               SimpleName              = 8,
-
                // Mask of all the expression class flags.
-               MaskExprClass           = 15,
+               MaskExprClass           = 7,
 
                // Disable control flow analysis while resolving the expression.
                // This is used when resolving the instance expression of a field expression.
-               DisableFlowAnalysis     = 16,
+               DisableFlowAnalysis     = 8,
 
                // Set if this is resolving the first part of a MemberAccess.
-               Intermediate            = 32
+               Intermediate            = 16
        }
 
        //
@@ -308,11 +303,10 @@ namespace Mono.CSharp {
                }
 
                //
-               // This is used if the expression should be resolved as a type.
-               // the default implementation fails.   Use this method in
-               // those participants in the SimpleName chain system.
+               // This is used if the expression should be resolved as a type or namespace name.
+               // the default implementation fails.   
                //
-               public virtual Expression ResolveAsTypeStep (EmitContext ec)
+               public virtual FullNamedExpression ResolveAsTypeStep (EmitContext ec)
                {
                        return null;
                }
@@ -326,14 +320,23 @@ namespace Mono.CSharp {
                {
                        int errors = Report.Errors;
 
-                       TypeExpr te = ResolveAsTypeStep (ec) as TypeExpr;
+                       FullNamedExpression fne = ResolveAsTypeStep (ec);
 
-                       if ((te == null) || (te.eclass != ExprClass.Type) || (te.Type == null)) {
+                       if (fne == null) {
                                if (errors == Report.Errors)
                                        Report.Error (246, Location, "Cannot find type '{0}'", ToString ());
                                return null;
                        }
 
+                       if (fne.eclass != ExprClass.Type) {
+                               if (errors == Report.Errors)
+                                       Report.Error (118, Location, "'{0}' denotes a '{1}', where a type was expected",
+                                                     fne.FullName, fne.ExprClassName ());
+                               return null;
+                       }
+
+                       TypeExpr te = fne as TypeExpr;
+
                        if (!te.CheckAccessLevel (ec.DeclSpace)) {
                                Report.Error (122, Location, "'{0}' is inaccessible due to its protection level", te.Name);
                                return null;
@@ -369,22 +372,14 @@ namespace Mono.CSharp {
 
                        ec.DoFlowAnalysis = old_do_flow_analysis;
 
-                       if (e == null)
-                               return null;
-
-                       if (e is SimpleName){
-                               SimpleName s = (SimpleName) e;
-
-                               if ((flags & ResolveFlags.SimpleName) == 0) {
-                                       MemberLookupFailed (ec, null, ec.ContainerType, s.Name,
+                       if (e == null) {
+                               if (this is SimpleName)
+                                       MemberLookupFailed (ec, null, ec.ContainerType, ((SimpleName) this).Name, 
                                                            ec.DeclSpace.Name, loc);
-                                       return null;
-                               }
-
-                               return s;
+                               return null;
                        }
 
-                       if ((e is TypeExpr) || (e is ComposedCast)) {
+                       if ((e is TypeExpr) || (e is ComposedCast) || (e is Namespace)) {
                                if ((flags & ResolveFlags.Type) == 0) {
                                        e.Error_UnexpectedKind (flags, loc);
                                        return null;
@@ -395,6 +390,7 @@ namespace Mono.CSharp {
 
                        switch (e.eclass) {
                        case ExprClass.Type:
+                       case ExprClass.Namespace:
                                if ((flags & ResolveFlags.VariableOrValue) == 0) {
                                        e.Error_UnexpectedKind (flags, loc);
                                        return null;
@@ -431,11 +427,12 @@ namespace Mono.CSharp {
                                                     " ExprClass is Invalid after resolve");
                        }
 
-                       if (e.type == null)
+                       if (e.type == null && !(e is Namespace)) {
                                throw new Exception (
                                        "Expression " + e.GetType () +
                                        " did not set its type after Resolve\n" +
                                        "called from: " + this.GetType ());
+                       }
 
                        return e;
                }
@@ -874,9 +871,9 @@ namespace Mono.CSharp {
                        return operator_true;
                }
                
-               static string ExprClassName (ExprClass c)
+               public string ExprClassName ()
                {
-                       switch (c){
+                       switch (eclass){
                        case ExprClass.Invalid:
                                return "Invalid";
                        case ExprClass.Value:
@@ -906,11 +903,7 @@ namespace Mono.CSharp {
                /// </summary>
                public void Error_UnexpectedKind (string expected, Location loc)
                {
-                       string kind = "Unknown";
-                       
-                       kind = ExprClassName (eclass);
-
-                       Report.Error (118, loc, "Expression denotes a `" + kind +
+                       Report.Error (118, loc, "Expression denotes a `" + ExprClassName () +
                               "' where a `" + expected + "' was expected");
                }
 
@@ -929,9 +922,6 @@ namespace Mono.CSharp {
                        if ((flags & ResolveFlags.MethodGroup) != 0)
                                valid.Add ("method group");
 
-                       if ((flags & ResolveFlags.SimpleName) != 0)
-                               valid.Add ("simple name");
-
                        if (valid.Count == 0)
                                valid.Add ("unknown");
 
@@ -944,9 +934,7 @@ namespace Mono.CSharp {
                                sb.Append (valid [i]);
                        }
 
-                       string kind = ExprClassName (eclass);
-
-                       Error (119, "Expression denotes a `" + kind + "' where " +
+                       Error (119, "Expression denotes a `" + ExprClassName () + "' where " +
                               "a `" + sb.ToString () + "' was expected");
                }
                
@@ -2005,54 +1993,17 @@ namespace Mono.CSharp {
        }
        
        /// <summary>
-       ///   SimpleName expressions are initially formed of a single
-       ///   word and it only happens at the beginning of the expression.
+       ///   SimpleName expressions are formed of a single word and only happen at the beginning 
+       ///   of a dotted-name.
        /// </summary>
-       ///
-       /// <remarks>
-       ///   The expression will try to be bound to a Field, a Method
-       ///   group or a Property.  If those fail we pass the name to our
-       ///   caller and the SimpleName is compounded to perform a type
-       ///   lookup.  The idea behind this process is that we want to avoid
-       ///   creating a namespace map from the assemblies, as that requires
-       ///   the GetExportedTypes function to be called and a hashtable to
-       ///   be constructed which reduces startup time.  If later we find
-       ///   that this is slower, we should create a `NamespaceExpr' expression
-       ///   that fully participates in the resolution process. 
-       ///   
-       ///   For example `System.Console.WriteLine' is decomposed into
-       ///   MemberAccess (MemberAccess (SimpleName ("System"), "Console"), "WriteLine")
-       ///   
-       ///   The first SimpleName wont produce a match on its own, so it will
-       ///   be turned into:
-       ///   MemberAccess (SimpleName ("System.Console"), "WriteLine").
-       ///   
-       ///   System.Console will produce a TypeExpr match.
-       ///   
-       ///   The downside of this is that we might be hitting `LookupType' too many
-       ///   times with this scheme.
-       /// </remarks>
        public class SimpleName : Expression {
                public string Name;
                public readonly TypeArguments Arguments;
 
-               //
-               // If true, then we are a simple name, not composed with a ".
-               //
-               bool is_base;
-
-               public SimpleName (string a, string b, Location l)
-               {
-                       Name = String.Concat (a, ".", b);
-                       loc = l;
-                       is_base = false;
-               }
-               
                public SimpleName (string name, Location l)
                {
                        Name = name;
                        loc = l;
-                       is_base = true;
                }
 
                public SimpleName (string name, TypeArguments args, Location l)
@@ -2060,7 +2011,6 @@ namespace Mono.CSharp {
                        Name = name;
                        Arguments = args;
                        loc = l;
-                       is_base = true;
                }
 
                public static void Error_ObjectRefRequired (EmitContext ec, Location l, string name)
@@ -2111,60 +2061,23 @@ namespace Mono.CSharp {
                        return SimpleNameResolve (ec, null, true, intermediate);
                }
 
-               public override Expression ResolveAsTypeStep (EmitContext ec)
+               public override FullNamedExpression ResolveAsTypeStep (EmitContext ec)
                {
                        DeclSpace ds = ec.DeclSpace;
-                       NamespaceEntry ns = ds.NamespaceEntry;
-                       Type t;
-                       IAlias alias_value;
-
-                       //
-                       // Since we are cheating: we only do the Alias lookup for
-                       // namespaces if the name does not include any dots in it
-                       //
-                       if (ns != null && is_base)
-                               alias_value = ns.LookupAlias (Name);
-                       else
-                               alias_value = null;
-
-                       TypeParameterExpr generic_type = ds.LookupGeneric (Name, loc);
-                       if (generic_type != null)
-                               return generic_type.ResolveAsTypeTerminal (ec);
-
-                       if (ec.ResolvingTypeTree){
-                               int errors = Report.Errors;
-                               Type dt = ds.FindType (loc, Name);
-                               
-                               if (Report.Errors != errors)
-                                       return null;
-                               
-                               if (dt != null)
-                                       return new TypeExpression (dt, loc);
-
-                               if (alias_value != null){
-                                       if (alias_value.IsType)
-                                               return alias_value.ResolveAsType (ec);
-                                       if ((t = RootContext.LookupType (ds, alias_value.Name, true, loc)) != null)
-                                               return new TypeExpression (t, loc);
-                               }
-                       }
+                       FullNamedExpression dt;
 
-                       if ((t = RootContext.LookupType (ds, Name, true, loc)) != null)
-                               return new TypeExpression (t, loc);
+                       dt = ds.LookupGeneric (Name, loc);
+                       if (dt != null)
+                               return dt.ResolveAsTypeStep (ec);
 
-                       if (alias_value != null) {
-                               if (alias_value.IsType)
-                                       return alias_value.ResolveAsType (ec);
-                               if ((t = RootContext.LookupType (ds, alias_value.Name, true, loc)) != null)
-                                       return new TypeExpression (t, loc);
-                               
-                               // we have alias value, but it isn't Type, so try if it's namespace
-                               return new SimpleName (alias_value.Name, loc);
-                       }
+                       int errors = Report.Errors;
+                       dt = ec.ResolvingTypeTree 
+                               ? ds.FindType (loc, Name)
+                               : ds.LookupType (Name, true, loc);
+                       if (Report.Errors != errors)
+                               return null;
 
-                       // No match, maybe our parent can compose us
-                       // into something meaningful.
-                       return this;
+                       return dt;
                }
 
                Expression SimpleNameResolve (EmitContext ec, Expression right_side,
@@ -2176,12 +2089,9 @@ namespace Mono.CSharp {
 
                        Block current_block = ec.CurrentBlock;
                        if (current_block != null){
-                               //LocalInfo vi = current_block.GetLocalInfo (Name);
-                               if (is_base &&
-                                   current_block.IsVariableNameUsedInChildBlock(Name)) {
+                               if (current_block.IsVariableNameUsedInChildBlock (Name)) {
                                        Report.Error (135, Location,
-                                                     "'{0}' has a different meaning in a " +
-                                                     "child block", Name);
+                                                     "'{0}' has a different meaning in a child block", Name);
                                        return null;
                                }
                        }
@@ -2260,34 +2170,8 @@ namespace Mono.CSharp {
                        if (e == null && ec.ContainerType != null)
                                e = MemberLookup (ec, ec.ContainerType, Name, loc);
 
-                       if (e == null) {
-                               //
-                               // Since we are cheating (is_base is our hint
-                               // that we are the beginning of the name): we
-                               // only do the Alias lookup for namespaces if
-                               // the name does not include any dots in it
-                               //
-                               NamespaceEntry ns = ec.DeclSpace.NamespaceEntry;
-                               if (is_base && ns != null){
-                                       IAlias alias_value = ns.LookupAlias (Name);
-                                       if (alias_value != null){
-                                               if (alias_value.IsType)
-                                                       return alias_value.ResolveAsType (ec);
-
-                                               Name = alias_value.Name;
-                                               Type t;
-
-                                               if ((t = TypeManager.LookupType (Name)) != null)
-                                                       return new TypeExpression (t, loc);
-                                       
-                                               // No match, maybe our parent can compose us
-                                               // into something meaningful.
-                                               return this;
-                                       }
-                               }
-
+                       if (e == null)
                                return ResolveAsTypeStep (ec);
-                       }
 
                        if (e is TypeExpr)
                                return e;
@@ -2357,12 +2241,22 @@ namespace Mono.CSharp {
                        return Name;
                }
        }
+
+       /// <summary>
+       ///   Represents a namespace or a type.  The name of the class was inspired by
+       ///   section 10.8.1 (Fully Qualified Names).
+       /// </summary>
+       public abstract class FullNamedExpression : Expression {
+               public abstract string FullName {
+                       get;
+               }
+       }
        
        /// <summary>
        ///   Fully resolved expression that evaluates to a type
        /// </summary>
-       public abstract class TypeExpr : Expression, IAlias {
-               override public Expression ResolveAsTypeStep (EmitContext ec)
+       public abstract class TypeExpr : FullNamedExpression {
+               override public FullNamedExpression ResolveAsTypeStep (EmitContext ec)
                {
                        TypeExpr t = DoResolveAsTypeStep (ec);
                        if (t == null)
@@ -2429,6 +2323,15 @@ namespace Mono.CSharp {
 
                protected abstract TypeExpr DoResolveAsTypeStep (EmitContext ec);
 
+               public virtual Type ResolveType (EmitContext ec)
+               {
+                       TypeExpr t = ResolveAsTypeTerminal (ec);
+                       if (t == null)
+                               return null;
+
+                       return t.Type;
+               }
+
                public abstract string Name {
                        get;
                }
@@ -2451,18 +2354,9 @@ namespace Mono.CSharp {
                {
                        return Name;
                }
-
-               bool IAlias.IsType {
-                       get { return true; }
-               }
-
-               TypeExpr IAlias.ResolveAsType (EmitContext ec)
-               {
-                       return ResolveAsTypeTerminal (ec);
-               }
        }
 
-       public class TypeExpression : TypeExpr, IAlias {
+       public class TypeExpression : TypeExpr {
                public TypeExpression (Type t, Location l)
                {
                        Type = t;
@@ -2481,7 +2375,7 @@ namespace Mono.CSharp {
                        }
                }
 
-               string IAlias.Name {
+               public override string FullName {
                        get {
                                return Type.FullName != null ? Type.FullName : Type.Name;
                        }
@@ -2504,10 +2398,12 @@ namespace Mono.CSharp {
                protected override TypeExpr DoResolveAsTypeStep (EmitContext ec)
                {
                        if (type == null) {
-                               type = RootContext.LookupType (
-                                       ec.DeclSpace, name, false, Location.Null);
-                               if (type == null)
+                               FullNamedExpression t = ec.DeclSpace.LookupType (name, false, Location.Null);
+                               if (t == null)
+                                       return null;
+                               if (!(t is TypeExpr))
                                        return null;
+                               type = ((TypeExpr) t).ResolveType (ec);
                        }
 
                        return this;
@@ -2518,6 +2414,12 @@ namespace Mono.CSharp {
                                return name;
                        }
                }
+
+               public override string FullName {
+                       get {
+                               return name;
+                       }
+               }
        }
 
        /// <summary>
@@ -2530,13 +2432,13 @@ namespace Mono.CSharp {
                { }
        }
 
-       public class TypeAliasExpression : TypeExpr, IAlias {
-               IAlias alias;
+       public class TypeAliasExpression : TypeExpr {
+               FullNamedExpression alias;
                TypeExpr texpr;
                TypeArguments args;
                string name;
 
-               public TypeAliasExpression (IAlias alias, TypeArguments args, Location l)
+               public TypeAliasExpression (FullNamedExpression alias, TypeArguments args, Location l)
                {
                        this.alias = alias;
                        this.args = args;
@@ -2544,18 +2446,22 @@ namespace Mono.CSharp {
 
                        eclass = ExprClass.Type;
                        if (args != null)
-                               name = alias.Name + "<" + args.ToString () + ">";
+                               name = alias.FullName + "<" + args.ToString () + ">";
                        else
-                               name = alias.Name;
+                               name = alias.FullName;
                }
 
                public override string Name {
+                       get { return alias.FullName; }
+               }
+
+               public override string FullName {
                        get { return name; }
                }
 
                protected override TypeExpr DoResolveAsTypeStep (EmitContext ec)
                {
-                       texpr = alias.ResolveAsType (ec);
+                       texpr = alias.ResolveAsTypeTerminal (ec);
                        if (texpr == null)
                                return null;
 
index 16f09f1f41f47bd751c9f1d0520282f1d7c7e181..9274f8d2b917e766db72a2ad496739d14bb772b3 100644 (file)
@@ -7215,7 +7215,7 @@ namespace Mono.CSharp {
                        if (sn == null || left == null || left.Type.Name != sn.Name)
                                return false;
 
-                       return RootContext.LookupType (ec.DeclSpace, sn.Name, true, loc) != null;
+                       return ec.DeclSpace.LookupType (sn.Name, true, loc) != null;
                }
                
                // TODO: possible optimalization
@@ -7435,17 +7435,15 @@ namespace Mono.CSharp {
                        if (expr == null)
                                return null;
 
-                       if (expr is SimpleName){
-                               SimpleName child_expr = (SimpleName) expr;
-                               string fqname = DeclSpace.MakeFQN (child_expr.Name, Identifier);
-
-                               Expression new_expr;
-                               if (args != null)
-                                       new_expr = new ConstructedType (fqname, args, loc);
-                               else
-                                       new_expr = new SimpleName (fqname, loc);
-
-                               return new_expr.Resolve (ec, flags);
+                       if (expr is Namespace) {
+                               Namespace ns = (Namespace) expr;
+                               string lookup_id = MemberName.MakeName (Identifier, args);
+                               FullNamedExpression retval = ns.Lookup (ec.DeclSpace, lookup_id, loc);
+                               if ((retval != null) && (args != null))
+                                       retval = new ConstructedType (retval, args, loc).ResolveAsTypeStep (ec);
+                               if (retval == null)
+                                       Report.Error (234, loc, "The type or namespace name `{0}' could not be found in namespace `{1}'", Identifier, ns.FullName);
+                               return retval;
                        }
                                        
                        //
@@ -7523,7 +7521,7 @@ namespace Mono.CSharp {
                        }
 
                        if (member_lookup is TypeExpr) {
-                               if (!(expr is TypeExpr) && !(expr is SimpleName)) {
+                               if (!(expr is TypeExpr)) {
                                        Error (572, "Can't reference type `" + Identifier + "' through an expression; try `" +
                                               member_lookup.Type + "' instead");
                                        return null;
@@ -7575,58 +7573,31 @@ namespace Mono.CSharp {
 
                public override Expression DoResolve (EmitContext ec)
                {
-                       return DoResolve (ec, null, ResolveFlags.VariableOrValue |
-                                         ResolveFlags.SimpleName | ResolveFlags.Type);
+                       return DoResolve (ec, null, ResolveFlags.VariableOrValue | ResolveFlags.Type);
                }
 
                public override Expression DoResolveLValue (EmitContext ec, Expression right_side)
                {
-                       return DoResolve (ec, right_side, ResolveFlags.VariableOrValue |
-                                         ResolveFlags.SimpleName | ResolveFlags.Type);
+                       return DoResolve (ec, right_side, ResolveFlags.VariableOrValue | ResolveFlags.Type);
                }
 
-               public override Expression ResolveAsTypeStep (EmitContext ec)
+               public override FullNamedExpression ResolveAsTypeStep (EmitContext ec)
                {
-                       string fname = null;
-                       MemberAccess full_expr = this;
-                       while (full_expr != null) {
-                               if (fname != null)
-                                       fname = String.Concat (full_expr.Identifier, ".", fname);
-                               else
-                                       fname = full_expr.Identifier;
-
-                               fname = MemberName.MakeName (fname, args);
-
-                               if (full_expr.Expr is SimpleName) {
-                                       string full_name = String.Concat (((SimpleName) full_expr.Expr).Name, ".", fname);
-                                       Type fully_qualified = ec.DeclSpace.FindType (loc, full_name);
-                                       if (fully_qualified != null) {
-                                               if (args == null)
-                                                       return new TypeExpression (fully_qualified, loc);
-
-                                               ConstructedType ctype = new ConstructedType (fully_qualified, args, loc);
-                                               return ctype.ResolveAsTypeStep (ec);
-                                       }
-                               }
-
-                               full_expr = full_expr.Expr as MemberAccess;
-                       }
-
-                       Expression new_expr = expr.ResolveAsTypeStep (ec);
+                       FullNamedExpression new_expr = expr.ResolveAsTypeStep (ec);
 
                        if (new_expr == null)
                                return null;
 
-                       if (new_expr is SimpleName){
-                               SimpleName child_expr = (SimpleName) new_expr;
-                               string fqname = DeclSpace.MakeFQN (child_expr.Name, Identifier);
-                               
-                               if (args != null)
-                                       new_expr = new ConstructedType (fqname, args, loc);
-                               else
-                                       new_expr = new SimpleName (fqname, loc);
+                       string lookup_id = MemberName.MakeName (Identifier, args);
 
-                               return new_expr.ResolveAsTypeStep (ec);
+                       if (new_expr is Namespace) {
+                               Namespace ns = (Namespace) new_expr;
+                               FullNamedExpression retval = ns.Lookup (ec.DeclSpace, lookup_id, loc);
+                               if ((retval != null) && (args != null))
+                                       retval = new ConstructedType (retval, args, loc).ResolveAsTypeStep (ec);
+                               if (retval == null)
+                                       Report.Error (234, loc, "The type or namespace name `{0}' could not be found in namespace `{1}'", Identifier, ns.FullName);
+                               return retval;
                        }
 
                        TypeExpr tnew_expr = new_expr.ResolveAsTypeTerminal (ec);
@@ -7642,18 +7613,20 @@ namespace Mono.CSharp {
                        }
 
                        Expression member_lookup;
-                       string lookup_id;
-                       lookup_id = MemberName.MakeName (Identifier, args);
-                       member_lookup = MemberLookupFinal (
-                               ec, expr_type, expr_type, lookup_id, loc);
-                       if (member_lookup == null)
+                       member_lookup = MemberLookupFinal (ec, expr_type, expr_type, lookup_id, loc);
+                       if (member_lookup == null) {
+                               Report.Error (234, loc, "The type name `{0}' could not be found in type `{1}'", 
+                                             Identifier, new_expr.FullName);
                                return null;
+                       }
 
-                       TypeExpr texpr = member_lookup as TypeExpr;
-                       if (texpr == null)
+                       if (!(member_lookup is TypeExpr)) {
+                               Report.Error (118, loc, "'{0}.{1}' denotes a '{2}', where a type was expected",
+                                             new_expr.FullName, Identifier, member_lookup.ExprClassName ());
                                return null;
+                       }
 
-                       texpr = texpr.ResolveAsTypeTerminal (ec);
+                       TypeExpr texpr = member_lookup.ResolveAsTypeTerminal (ec);
                        if (texpr == null)
                                return null;
 
@@ -7677,6 +7650,9 @@ namespace Mono.CSharp {
                        }
 
                        return texpr;
+
+                       member_lookup = member_lookup.Resolve (ec, ResolveFlags.Type);
+                       return (member_lookup as TypeExpr);
                }
 
                public override void Emit (EmitContext ec)
@@ -8868,7 +8844,9 @@ namespace Mono.CSharp {
                                //
                                // For now, fall back to the full lookup in that case.
                                //
-                               type = RootContext.LookupType (ec.DeclSpace, cname, false, loc);
+                               FullNamedExpression e = ec.DeclSpace.LookupType (cname, false, loc);
+                               if (e is TypeExpr)
+                                       type = ((TypeExpr) e).ResolveType (ec);
                                if (type == null)
                                        return null;
                        }
@@ -8893,6 +8871,12 @@ namespace Mono.CSharp {
                                return left + dim;
                        }
                }
+
+               public override string FullName {
+                       get {
+                               return type.FullName;
+                       }
+               }
        }
 
        //
index 1f9efd39b354043ac26710eec5a7b04621e279d1..b8daaef07f3b643cfec40cb6321e07d8c426a7a2 100644 (file)
@@ -837,6 +837,12 @@ namespace Mono.CSharp {
                        }
                }
 
+               public override string FullName {
+                       get {
+                               return type_parameter.Name;
+                       }
+               }
+
                public TypeParameter TypeParameter {
                        get {
                                return type_parameter;
@@ -1016,6 +1022,16 @@ namespace Mono.CSharp {
                        full_name = name + "<" + args.ToString () + ">";
                }
 
+               public ConstructedType (FullNamedExpression fname, TypeArguments args, Location l)
+               {
+                       loc = l;
+                       this.name = fname.FullName;
+                       this.args = args;
+
+                       eclass = ExprClass.Type;
+                       full_name = name + "<" + args.ToString () + ">";
+               }
+
                protected ConstructedType (TypeArguments args, Location l)
                {
                        loc = l;
@@ -1365,6 +1381,13 @@ namespace Mono.CSharp {
                                return full_name;
                        }
                }
+
+
+               public override string FullName {
+                       get {
+                               return full_name;
+                       }
+               }
        }
 
        public class GenericMethod : DeclSpace
@@ -1429,7 +1452,7 @@ namespace Mono.CSharp {
 
                public override MemberCache MemberCache {
                        get {
-                               throw new Exception ();
+                               return null;
                        }
                }
 
index be26cc164fd5c4df483f3b4299955fb9ecc9227d..ec0a8347be7f965ea04df864df213b262a8c2377 100644 (file)
@@ -13,8 +13,11 @@ namespace Mono.CSharp {
 
        /// <summary>
        ///   Keeps track of the namespaces defined in the C# code.
+       ///
+       ///   This is an Expression to allow it to be referenced in the
+       ///   compiler parse/intermediate tree during name resolution.
        /// </summary>
-       public class Namespace : IAlias {
+       public class Namespace : FullNamedExpression, IAlias {
                static ArrayList all_namespaces = new ArrayList ();
                static Hashtable namespaces_map = new Hashtable ();
                
@@ -31,6 +34,11 @@ namespace Mono.CSharp {
                /// </summary>
                public Namespace (Namespace parent, string name)
                {
+                       // Expression members.
+                       this.eclass = ExprClass.Namespace;
+                       this.Type = null;
+                       this.loc = Location.Null;
+
                        this.parent = parent;
 
                        string pname = parent != null ? parent.Name : "";
@@ -50,6 +58,16 @@ namespace Mono.CSharp {
                        namespaces_map [fullname] = true;
                }
 
+               public override Expression DoResolve (EmitContext ec)
+               {
+                       return this;
+               }
+
+               public override void Emit (EmitContext ec)
+               {
+                       throw new InternalErrorException ("Expression tree referenced namespace " + fullname + " during Emit ()");
+               }
+
                public static bool IsNamespace (string name)
                {
                        return namespaces_map [name] != null;
@@ -88,9 +106,9 @@ namespace Mono.CSharp {
                        return Root.GetNamespace (name, create);
                }
 
-               public IAlias Lookup (DeclSpace ds, string name, Location loc)
+               public FullNamedExpression Lookup (DeclSpace ds, string name, Location loc)
                {
-                       IAlias o = Lookup (name);
+                       IAlias o = (IAlias) defined_names [name];
 
                        Type t;
                        DeclSpace tdecl = o as DeclSpace;
@@ -100,7 +118,7 @@ namespace Mono.CSharp {
                                        return null;
 
                                if ((ds == null) || ds.CheckAccessLevel (t))
-                                       return new TypeExpression (t, loc);
+                                       return new TypeExpression (t, Location.Null);
                        }
 
                        Namespace ns = GetNamespace (name, false);
@@ -111,7 +129,7 @@ namespace Mono.CSharp {
                        if ((t == null) || ((ds != null) && !ds.CheckAccessLevel (t)))
                                return null;
 
-                       return new TypeExpression (t, loc);
+                       return new TypeExpression (t, Location.Null);
                }
 
                public void AddNamespaceEntry (NamespaceEntry entry)
@@ -124,11 +142,6 @@ namespace Mono.CSharp {
                        defined_names.Add (name, o);
                }
 
-               public IAlias Lookup (string name)
-               {
-                       return (IAlias) defined_names [name];
-               }
-
                static public ArrayList UserDefinedNamespaces {
                        get {
                                return all_namespaces;
@@ -144,6 +157,12 @@ namespace Mono.CSharp {
                        }
                }
 
+               public override string FullName {
+                       get {
+                               return fullname;
+                       }
+               }
+
                /// <summary>
                ///   The parent of this namespace, used by the parser to "Pop"
                ///   the current namespace declaration
@@ -228,7 +247,7 @@ namespace Mono.CSharp {
                                if (resolved_ns != null)
                                        return resolved_ns;
 
-                               object resolved = NamespaceEntry.LookupForUsing (Name, Location);
+                               FullNamedExpression resolved = NamespaceEntry.LookupForUsing (Name, Location);
                                resolved_ns = resolved as Namespace;
                                return resolved_ns;
                        }
@@ -248,9 +267,9 @@ namespace Mono.CSharp {
                                Location = loc;
                        }
 
-                       IAlias resolved;
+                       FullNamedExpression resolved;
 
-                       public IAlias Resolve ()
+                       public FullNamedExpression Resolve ()
                        {
                                if (resolved != null)
                                        return resolved;
@@ -266,9 +285,12 @@ namespace Mono.CSharp {
                                if (resolved == null)
                                        return null;
 
-                               if (resolved.IsType)
-                                       resolved = new TypeAliasExpression (
-                                               resolved, Alias.TypeArguments, Location);
+                               if (Alias.TypeArguments == null)
+                                       return resolved;
+
+                               EmitContext ec = RootContext.Tree.Types.EmitContext;
+                               resolved = new TypeAliasExpression (resolved, Alias.TypeArguments, Location);
+                               resolved = resolved.ResolveAsTypeStep (ec);
 
                                return resolved;
                        }
@@ -376,26 +398,13 @@ namespace Mono.CSharp {
                        aliases [name] = new AliasEntry (this, name, alias, loc);
                }
 
-               protected AliasEntry GetAliasEntry (string alias)
+               public FullNamedExpression LookupAlias (string alias)
                {
                        AliasEntry entry = null;
-
                        if (aliases != null)
                                entry = (AliasEntry) aliases [alias];
-                       if (entry == null && Parent != null)
-                               entry = Parent.GetAliasEntry (alias);
 
-                       return entry;
-               }
-
-               public IAlias LookupAlias (string alias)
-               {
-                       AliasEntry entry = GetAliasEntry (alias);
-
-                       if (entry == null)
-                               return null;
-
-                       return entry.Resolve ();
+                       return entry == null ? null : entry.Resolve ();
                }
 
                //
@@ -405,7 +414,7 @@ namespace Mono.CSharp {
                // Section 16.3.2 says that the same rule is applied when resolving the namespace-name
                // in the using-namespace-directive.
                //
-               public IAlias LookupForUsing (string dotted_name, Location loc)
+               public FullNamedExpression LookupForUsing (string dotted_name, Location loc)
                {
                        int pos = dotted_name.IndexOf ('.');
                        string simple_name = dotted_name;
@@ -415,7 +424,7 @@ namespace Mono.CSharp {
                                rest = dotted_name.Substring (pos + 1);
                        }
 
-                       IAlias o = NS.Lookup (null, simple_name, loc);
+                       FullNamedExpression o = NS.Lookup (null, simple_name, loc);
                        if (o == null && ImplicitParent != null)
                                o = ImplicitParent.LookupNamespaceOrType (null, simple_name, loc);
 
@@ -426,16 +435,16 @@ namespace Mono.CSharp {
                        if (ns != null)
                                return ns.Lookup (null, rest, loc);
                        
-                       Type nested = TypeManager.LookupType (o.Name + "." + rest);
+                       Type nested = TypeManager.LookupType (o.FullName + "." + rest);
                        if (nested == null)
                                return null;
 
-                       return new TypeExpression (nested, loc);
+                       return new TypeExpression (nested, Location.Null);
                }
 
-               public IAlias LookupNamespaceOrType (DeclSpace ds, string name, Location loc)
+               public FullNamedExpression LookupNamespaceOrType (DeclSpace ds, string name, Location loc)
                {
-                       IAlias resolved = null;
+                       FullNamedExpression resolved = null;
                        for (NamespaceEntry curr_ns = this; curr_ns != null; curr_ns = curr_ns.ImplicitParent) {
                                if ((resolved = curr_ns.Lookup (ds, name, loc)) != null)
                                        break;
@@ -443,9 +452,9 @@ namespace Mono.CSharp {
                        return resolved;
                }
 
-               private IAlias Lookup (DeclSpace ds, string name, Location loc)
+               private FullNamedExpression Lookup (DeclSpace ds, string name, Location loc)
                {
-                       IAlias o;
+                       FullNamedExpression o;
                        Namespace ns;
 
                        //
@@ -471,11 +480,11 @@ namespace Mono.CSharp {
                                        return o;
                                }
 
-                               Type nested = TypeManager.LookupType (o.Name + "." + last);
+                               Type nested = TypeManager.LookupType (o.FullName + "." + last);
                                if ((nested == null) || ((ds != null) && !ds.CheckAccessLevel (nested)))
                                        return null;
 
-                               return new TypeExpression (nested, loc);
+                               return new TypeExpression (nested, Location.Null);
                        }
 
                        //
@@ -488,12 +497,9 @@ namespace Mono.CSharp {
                        //
                        // Check aliases.
                        //
-                       AliasEntry entry = GetAliasEntry (name);
-                       if (entry != null) {
-                               IAlias alias = entry.Resolve ();
-                               if (alias != null)
-                                       return alias;
-                       }
+                       o = LookupAlias (name);
+                       if (o != null)
+                               return o;
 
                        if (name.IndexOf ('.') > 0)
                                return null;
@@ -501,12 +507,12 @@ namespace Mono.CSharp {
                        //
                        // Check using entries.
                        //
-                       IAlias t = null, match = null;
+                       FullNamedExpression t = null, match = null;
                        foreach (Namespace using_ns in GetUsingTable ()) {
                                match = using_ns.Lookup (ds, name, loc);
-                               if ((match != null) && match.IsType){
+                               if ((match != null) && (match is TypeExpr)) {
                                        if (t != null) {
-                                                       DeclSpace.Error_AmbiguousTypeReference (loc, name, t.Name, match.Name);
+                                               DeclSpace.Error_AmbiguousTypeReference (loc, name, t.FullName, match.FullName);
                                                return null;
                                        } else {
                                                t = match;
@@ -523,9 +529,11 @@ namespace Mono.CSharp {
                {
                        if (namespace_using_table != null)
                                return namespace_using_table;
-                       
-                       if (using_clauses == null)
-                               return new Namespace [0];
+
+                       if (using_clauses == null) {
+                               namespace_using_table = new Namespace [0];
+                               return namespace_using_table;
+                       }
 
                        ArrayList list = new ArrayList (using_clauses.Count);
 
@@ -616,10 +624,6 @@ namespace Mono.CSharp {
                /// </summary>
                public void VerifyUsing ()
                {
-                       TypeContainer dummy = new RootTypes ();
-                       EmitContext ec = new EmitContext (
-                               dummy, Location.Null, null, null, 0, false);
-
                        if (using_clauses != null){
                                foreach (UsingEntry ue in using_clauses){
                                        if (ue.Resolve () != null)
@@ -636,17 +640,12 @@ namespace Mono.CSharp {
 
                        if (aliases != null){
                                foreach (DictionaryEntry de in aliases){
-                                       AliasEntry entry = (AliasEntry) de.Value;
-
-                                       IAlias alias = entry.Resolve ();
-                                       if (alias != null) {
-                                               if (alias.IsType)
-                                                       alias.ResolveAsType (ec);
+                                       AliasEntry alias = (AliasEntry) de.Value;
 
+                                       if (alias.Resolve () != null)
                                                continue;
-                                       }
 
-                                       error246 (entry.Location, entry.Alias.GetTypeName ());
+                                       error246 (alias.Location, alias.Alias.GetTypeName ());
                                }
                        }
                }
index 4be3c39419a1e351aff2e28d9efb766188ccc270..2824da00840d2b489a253daa496655bd89113fc5 100644 (file)
@@ -483,92 +483,6 @@ namespace Mono.CSharp {
                        helper_classes.Add (helper_class);
                }
                
-               static Type NamespaceLookup (DeclSpace ds, string name, int num_type_args, Location loc)
-               {
-                       IAlias result = ds.NamespaceEntry.LookupNamespaceOrType (ds, name, loc);
-                       if (result == null)
-                               return null;
-
-                       if (!result.IsType)
-                               return null;
-
-                       TypeExpr texpr = result.ResolveAsType (ds.EmitContext);
-                       if (texpr == null)
-                               return null;
-
-                       return texpr.Type;
-               }
-               
-               static public Type LookupType (DeclSpace ds, string name, bool silent, Location loc)
-               {
-                       return LookupType (ds, name, silent, 0, loc);
-               }
-
-               //
-               // Public function used to locate types, this can only
-               // be used after the ResolveTree function has been invoked.
-               //
-               // Returns: Type or null if they type can not be found.
-               //
-               // 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)
-               {
-                       Type t;
-
-                       if (ds.Cache.Contains (name)){
-                               t = (Type) ds.Cache [name];
-                               if (t != null)
-                                       return t;
-                       } else {
-                               //
-                               // For the case the type we are looking for is nested within this one
-                               // or is in any base class
-                               //
-                               DeclSpace containing_ds = ds;
-                               while (containing_ds != null){
-                                       Type current_type = containing_ds.TypeBuilder;
-                                       
-                                       while (current_type != null) {
-                                               //
-                                               // nested class
-                                               //
-                                               Type type = TypeManager.LookupType (current_type.FullName + "." + name);
-                                               if (type != null){
-                                                       t = ds.ResolveNestedType (type, loc);
-                                                       ds.Cache [name] = t;
-                                                       return t;
-                                               }
-                                               
-                                               current_type = current_type.BaseType;
-                                       }
-                                       
-                                       containing_ds = containing_ds.Parent;
-                               }
-                               
-                               t = NamespaceLookup (ds, name, num_type_params, loc);
-                               if (!silent || t != null){
-                                       ds.Cache [name] = t;
-                                       return t;
-                               }
-                       }
-
-                       if (!silent)
-                               Report.Error (246, loc, "Cannot find type `"+name+"'");
-                       
-                       return null;
-               }
-
-               // <summary>
-               //   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)
-               {
-                       return LookupType (tc, name, true, loc);
-               }
-
                static void Report1530 (Location loc)
                {
                        Report.Error (1530, loc, "Keyword new not allowed for namespace elements");