//
// Author:
// Miguel de Icaza (miguel@ximian.com)
+// Marek Safar (marek.safar@seznam.cz)
//
// (C) 2001 Ximian, Inc.
//
protected void EnsureNamespace (string dotted_name)
{
- if (dotted_name != null && dotted_name != "" && ! IsNamespace (dotted_name))
+ if (dotted_name != null && dotted_name.Length != 0 && ! IsNamespace (dotted_name))
GetNamespace (dotted_name, true);
}
if (t.IsPointer)
throw new InternalErrorException ("Use GetPointerType() to get a pointer");
-
+
TypeAttributes ta = t.Attributes & TypeAttributes.VisibilityMask;
- if (ta == TypeAttributes.NotPublic ||
- ta == TypeAttributes.NestedPrivate ||
- ta == TypeAttributes.NestedAssembly ||
- ta == TypeAttributes.NestedFamANDAssem)
+ if (ta == TypeAttributes.NestedPrivate)
+ return null;
+
+ if ((ta == TypeAttributes.NotPublic ||
+ ta == TypeAttributes.NestedAssembly ||
+ ta == TypeAttributes.NestedFamANDAssem) &&
+ !TypeManager.IsFriendAssembly (t.Assembly))
return null;
return t;
EnsureNamespace (t.Namespace);
}
+ public override void Error_NamespaceDoesNotExist(DeclSpace ds, Location loc, string name)
+ {
+ Report.Error (400, loc, "The type or namespace name `{0}' could not be found in the global namespace (are you missing an assembly reference?)",
+ name);
+ }
+
public override Type LookupTypeReflection (string name, Location loc)
{
Type found_type = null;
found_type = t;
continue;
}
-
- Report.SymbolRelatedToPreviousError (t);
+
Report.SymbolRelatedToPreviousError (found_type);
- Report.Warning (436, 2, loc, "Ignoring imported type `{0}' since the current assembly already has a declaration with the same name",
- TypeManager.CSharpName (t));
+ if (loc.IsNull) {
+ DeclSpace ds = TypeManager.LookupDeclSpace (t);
+ Report.Warning (1685, 1, ds.Location, "The type `{0}' conflicts with the predefined type `{1}' and will be ignored",
+ ds.GetSignatureForError (), TypeManager.CSharpName (found_type));
+ return found_type;
+ }
+ Report.SymbolRelatedToPreviousError (t);
+ Report.Warning (436, 2, loc, "The type `{0}' conflicts with the imported type `{1}'. Ignoring the imported type definition",
+ TypeManager.CSharpName (t), TypeManager.CSharpName (found_type));
return t;
}
}
{
// Expression members.
this.eclass = ExprClass.Namespace;
- this.Type = null;
+ this.Type = typeof (Namespace);
this.loc = Location.Null;
this.parent = parent;
if (parent != null && parent.MemberName != MemberName.Null)
MemberName = new MemberName (parent.MemberName, name);
- else if (name == "")
+ else if (name.Length == 0)
MemberName = MemberName.Null;
else
MemberName = new MemberName (name);
return this;
}
+ public virtual void Error_NamespaceDoesNotExist (DeclSpace ds, Location loc, string name)
+ {
+ if (name.IndexOf ('`') > 0) {
+ FullNamedExpression retval = Lookup (ds, SimpleName.RemoveGenericArity (name), loc);
+ if (retval != null) {
+ Error_TypeArgumentsCannotBeUsed (retval.Type, loc, "type");
+ return;
+ }
+ } else {
+ Type t = LookForAnyGenericType (name);
+ if (t != null) {
+ Error_InvalidNumberOfTypeArguments (t, loc);
+ return;
+ }
+ }
+
+ Report.Error (234, loc, "The type or namespace name `{0}' does not exist in the namespace `{1}'. Are you missing an assembly reference?",
+ name, FullName);
+ }
+
+ public static void Error_InvalidNumberOfTypeArguments (Type t, Location loc)
+ {
+ Report.SymbolRelatedToPreviousError (t);
+ Report.Error (305, loc, "Using the generic type `{0}' requires `{1}' type argument(s)",
+ TypeManager.CSharpName(t), TypeManager.GetNumberOfTypeArguments(t).ToString());
+ }
+
+ public static void Error_TypeArgumentsCannotBeUsed(Type t, Location loc, string symbol)
+ {
+ Report.SymbolRelatedToPreviousError(t);
+ Report.Error(308, loc, "The non-generic {0} `{1}' cannot be used with the type argument(s)",
+ symbol, TypeManager.CSharpName(t));
+ }
+
public override void Emit (EmitContext ec)
{
throw new InternalErrorException ("Expression tree referenced namespace " + fullname + " during Emit ()");
t = tdecl.TypeBuilder;
}
}
- string lookup = t != null ? t.FullName : (fullname == "" ? name : fullname + "." + name);
+ string lookup = t != null ? t.FullName : (fullname.Length == 0 ? name : fullname + "." + name);
Type rt = root.LookupTypeReflection (lookup, loc);
- if (t == null)
+
+ // HACK: loc.IsNull when the type is core type
+ if (t == null || (rt != null && loc.IsNull))
t = rt;
TypeExpr te = t == null ? null : new TypeExpression (t, Location.Null);
return te;
}
+ ///
+ /// Used for better error reporting only
+ ///
+ public Type LookForAnyGenericType (string typeName)
+ {
+ if (declspaces == null)
+ return null;
+
+ typeName = SimpleName.RemoveGenericArity (typeName);
+
+ foreach (DictionaryEntry de in declspaces) {
+ string type_item = (string) de.Key;
+ int pos = type_item.LastIndexOf ('`');
+ if (pos == typeName.Length && String.Compare (typeName, 0, type_item, 0, pos) == 0)
+ return ((DeclSpace) de.Value).TypeBuilder;
+ }
+ return null;
+ }
+
public FullNamedExpression Lookup (DeclSpace ds, string name, Location loc)
{
if (namespaces.Contains (name))
public bool DeclarationFound = false;
bool UsingFound;
+ public readonly DeclSpace SlaveDeclSpace;
+
ListDictionary extern_aliases;
static ArrayList entries = new ArrayList ();
// We use this to flag using clauses for namespaces that do not
// exist.
//
- public class UsingEntry {
+ public class UsingEntry : IResolveContext {
public readonly MemberName Name;
readonly Expression Expr;
readonly NamespaceEntry NamespaceEntry;
if (resolved != null)
return resolved;
- DeclSpace root = RootContext.Tree.Types;
- root.NamespaceEntry = NamespaceEntry;
- FullNamedExpression fne = Expr.ResolveAsTypeStep (root, false);
- root.NamespaceEntry = null;
-
+ FullNamedExpression fne = Expr.ResolveAsTypeStep (this, false);
if (fne == null) {
Error_NamespaceNotFound (Location, Name.ToString ());
return null;
resolved = fne as Namespace;
if (resolved == null) {
Report.Error (138, Location,
- "`{0} is a type not a namespace. A using namespace directive can only be applied to namespaces", Name.ToString ());
+ "`{0}' is a type not a namespace. A using namespace directive can only be applied to namespaces", Name.ToString ());
}
return resolved;
}
+
+ DeclSpace IResolveContext.DeclContainer {
+ get { return NamespaceEntry.SlaveDeclSpace; }
+ }
+
+ DeclSpace IResolveContext.GenericDeclContainer {
+ get { return NamespaceEntry.SlaveDeclSpace; }
+ }
+
+ bool IResolveContext.IsInObsoleteScope {
+ get { return false; }
+ }
+ bool IResolveContext.IsInUnsafeScope {
+ get { return false; }
+ }
}
public abstract class AliasEntry {
protected abstract FullNamedExpression DoResolve ();
}
- public class LocalAliasEntry : AliasEntry
- {
+ public class LocalAliasEntry : AliasEntry, IResolveContext {
public readonly Expression Alias;
public LocalAliasEntry (NamespaceEntry entry, string name, MemberName alias, Location loc) :
protected override FullNamedExpression DoResolve ()
{
- DeclSpace root = RootContext.Tree.Types;
- root.NamespaceEntry = NamespaceEntry;
- resolved = Alias.ResolveAsTypeStep (root, false);
- root.NamespaceEntry = null;
-
+ resolved = Alias.ResolveAsTypeStep (this, false);
if (resolved == null)
- Error_NamespaceNotFound (Location, Alias.ToString ());
+ return null;
+
+ if (resolved.Type != null) {
+ TypeAttributes attr = resolved.Type.Attributes & TypeAttributes.VisibilityMask;
+ if (attr == TypeAttributes.NestedPrivate || attr == TypeAttributes.NestedFamily ||
+ ((attr == TypeAttributes.NestedFamORAssem || attr == TypeAttributes.NestedAssembly) &&
+ TypeManager.LookupDeclSpace (resolved.Type) == null)) {
+ Expression.ErrorIsInaccesible (Alias.Location, Alias.ToString ());
+ return null;
+ }
+ }
+
return resolved;
}
+
+ DeclSpace IResolveContext.DeclContainer {
+ get { return NamespaceEntry.SlaveDeclSpace; }
+ }
+
+ DeclSpace IResolveContext.GenericDeclContainer {
+ get { return NamespaceEntry.SlaveDeclSpace; }
+ }
+
+ bool IResolveContext.IsInObsoleteScope {
+ get { return false; }
+ }
+ bool IResolveContext.IsInUnsafeScope {
+ get { return false; }
+ }
}
- public class ExternAliasEntry : AliasEntry
- {
+ public class ExternAliasEntry : AliasEntry {
public ExternAliasEntry (NamespaceEntry entry, string name, Location loc) :
base (entry, name, loc)
{
}
}
- public NamespaceEntry (NamespaceEntry parent, SourceFile file, string name, Location loc)
+ public NamespaceEntry (NamespaceEntry parent, SourceFile file, string name)
{
this.parent = parent;
this.file = file;
ns = RootNamespace.Global.GetNamespace (name, true);
else
ns = RootNamespace.Global;
+ SlaveDeclSpace = new RootDeclSpace (this);
}
- private NamespaceEntry (NamespaceEntry parent, SourceFile file, Namespace ns)
+ private NamespaceEntry (NamespaceEntry parent, SourceFile file, Namespace ns, bool slave)
{
this.parent = parent;
this.file = file;
this.ID = -1;
this.IsImplicit = true;
this.ns = ns;
+ this.SlaveDeclSpace = slave ? new RootDeclSpace (this) : null;
}
//
NamespaceEntry Doppelganger {
get {
if (!IsImplicit && doppelganger == null)
- doppelganger = new NamespaceEntry (ImplicitParent, file, ns);
+ doppelganger = new NamespaceEntry (ImplicitParent, file, ns, true);
return doppelganger;
}
}
if (implicit_parent == null) {
implicit_parent = (parent.NS == ns.Parent)
? parent
- : new NamespaceEntry (parent, file, ns.Parent);
+ : new NamespaceEntry (parent, file, ns.Parent, false);
}
return implicit_parent;
}