2 // namespace.cs: Tracks namespaces
5 // Miguel de Icaza (miguel@ximian.com)
6 // Marek Safar (marek.safar@seznam.cz)
8 // (C) 2001 Ximian, Inc.
11 using System.Collections;
12 using System.Collections.Specialized;
13 using System.Reflection;
15 namespace Mono.CSharp {
17 public class RootNamespace : Namespace {
18 static MethodInfo get_namespaces_method;
21 Assembly referenced_assembly;
23 Hashtable all_namespaces;
25 static Hashtable root_namespaces;
26 public static GlobalRootNamespace Global;
28 static RootNamespace ()
30 get_namespaces_method = typeof (Assembly).GetMethod ("GetNamespaces", BindingFlags.Instance | BindingFlags.NonPublic);
35 public static void Reset ()
37 root_namespaces = new Hashtable ();
38 Global = new GlobalRootNamespace ();
39 root_namespaces ["global"] = Global;
42 protected RootNamespace (string alias_name, Assembly assembly)
43 : base (null, String.Empty)
45 this.alias_name = alias_name;
46 referenced_assembly = assembly;
48 all_namespaces = new Hashtable ();
49 all_namespaces.Add ("", this);
51 if (referenced_assembly != null)
52 ComputeNamespaces (this.referenced_assembly);
55 public static void DefineRootNamespace (string name, Assembly assembly)
57 if (name == "global") {
58 NamespaceEntry.Error_GlobalNamespaceRedefined (Location.Null);
61 RootNamespace retval = GetRootNamespace (name);
62 if (retval == null || retval.referenced_assembly != assembly)
63 root_namespaces [name] = new RootNamespace (name, assembly);
66 public static RootNamespace GetRootNamespace (string name)
68 return (RootNamespace) root_namespaces [name];
71 public virtual Type LookupTypeReflection (string name, Location loc)
73 return GetTypeInAssembly (referenced_assembly, name);
76 public void RegisterNamespace (Namespace child)
79 all_namespaces.Add (child.Name, child);
82 public bool IsNamespace (string name)
84 return all_namespaces.Contains (name);
87 protected void RegisterNamespace (string dotted_name)
89 if (dotted_name != null && dotted_name.Length != 0 && ! IsNamespace (dotted_name))
90 GetNamespace (dotted_name, true);
93 void RegisterExtensionMethodClass (Type t)
95 string n = t.Namespace;
96 Namespace ns = n == null ? Global : (Namespace)all_namespaces [n];
98 ns = GetNamespace (n, true);
100 ns.RegisterExternalExtensionMethodClass (t);
103 protected void ComputeNamespaces (Assembly assembly)
105 // How to test whether attribute exists without loading the assembly :-(
107 const string SystemCore = "System.Core, Version=2.1.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";
109 const string SystemCore = "System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";
111 if (TypeManager.extension_attribute_type == null &&
112 assembly.FullName == SystemCore) {
113 TypeManager.extension_attribute_type = assembly.GetType("System.Runtime.CompilerServices.ExtensionAttribute");
116 bool contains_extension_methods = TypeManager.extension_attribute_type != null &&
117 assembly.IsDefined(TypeManager.extension_attribute_type, false);
119 if (get_namespaces_method != null && !contains_extension_methods) {
120 string [] namespaces = (string []) get_namespaces_method.Invoke (assembly, null);
121 foreach (string ns in namespaces)
122 RegisterNamespace (ns);
126 foreach (Type t in assembly.GetExportedTypes ()) {
127 if ((t.Attributes & Class.StaticClassAttribute) == Class.StaticClassAttribute &&
128 contains_extension_methods && t.IsDefined (TypeManager.extension_attribute_type, false))
129 RegisterExtensionMethodClass (t);
131 RegisterNamespace (t.Namespace);
135 protected static Type GetTypeInAssembly (Assembly assembly, string name)
137 Type t = assembly.GetType (name);
142 throw new InternalErrorException ("Use GetPointerType() to get a pointer");
144 TypeAttributes ta = t.Attributes & TypeAttributes.VisibilityMask;
145 if (ta == TypeAttributes.NestedPrivate)
148 if ((ta == TypeAttributes.NotPublic ||
149 ta == TypeAttributes.NestedAssembly ||
150 ta == TypeAttributes.NestedFamANDAssem) &&
151 !TypeManager.IsFriendAssembly (t.Assembly))
157 public override string ToString ()
159 return String.Format ("RootNamespace ({0}::)", alias_name);
162 public override string GetSignatureForError ()
164 return alias_name + "::";
168 public class GlobalRootNamespace : RootNamespace {
169 Assembly [] assemblies;
172 public GlobalRootNamespace ()
173 : base ("global", null)
175 assemblies = new Assembly [0];
178 public Assembly [] Assemblies {
179 get { return assemblies; }
182 public Module [] Modules {
183 get { return modules; }
186 public void AddAssemblyReference (Assembly a)
188 foreach (Assembly assembly in assemblies) {
193 int top = assemblies.Length;
194 Assembly [] n = new Assembly [top + 1];
195 assemblies.CopyTo (n, 0);
199 ComputeNamespaces (a);
202 public void AddModuleReference (Module m)
204 int top = modules != null ? modules.Length : 0;
205 Module [] n = new Module [top + 1];
207 modules.CopyTo (n, 0);
211 if (m == CodeGen.Module.Builder)
214 foreach (Type t in m.GetTypes ())
215 RegisterNamespace (t.Namespace);
218 public override void Error_NamespaceDoesNotExist(DeclSpace ds, Location loc, string name)
220 Report.Error (400, loc, "The type or namespace name `{0}' could not be found in the global namespace (are you missing an assembly reference?)",
224 public override Type LookupTypeReflection (string name, Location loc)
226 Type found_type = null;
228 foreach (Assembly a in assemblies) {
229 Type t = GetTypeInAssembly (a, name);
233 if (found_type == null) {
238 Report.SymbolRelatedToPreviousError (found_type);
239 Report.SymbolRelatedToPreviousError (t);
240 Report.Error (433, loc, "The imported type `{0}' is defined multiple times", name);
245 if (modules != null) {
246 foreach (Module module in modules) {
247 Type t = module.GetType (name);
251 if (found_type == null) {
256 Report.SymbolRelatedToPreviousError (found_type);
258 DeclSpace ds = TypeManager.LookupDeclSpace (t);
259 Report.Warning (1685, 1, ds.Location, "The type `{0}' conflicts with the predefined type `{1}' and will be ignored",
260 ds.GetSignatureForError (), TypeManager.CSharpName (found_type));
263 Report.SymbolRelatedToPreviousError (t);
264 Report.Warning (436, 2, loc, "The type `{0}' conflicts with the imported type `{1}'. Ignoring the imported type definition",
265 TypeManager.CSharpName (t), TypeManager.CSharpName (found_type));
275 /// Keeps track of the namespaces defined in the C# code.
277 /// This is an Expression to allow it to be referenced in the
278 /// compiler parse/intermediate tree during name resolution.
280 public class Namespace : FullNamedExpression {
284 IDictionary namespaces;
285 IDictionary declspaces;
286 Hashtable cached_types;
288 ArrayList external_exmethod_classes;
290 public readonly MemberName MemberName;
293 /// Constructor Takes the current namespace and the
294 /// name. This is bootstrapped with parent == null
297 public Namespace (Namespace parent, string name)
299 // Expression members.
300 this.eclass = ExprClass.Namespace;
301 this.Type = typeof (Namespace);
302 this.loc = Location.Null;
304 this.parent = parent;
307 this.root = parent.root;
309 this.root = this as RootNamespace;
311 if (this.root == null)
312 throw new InternalErrorException ("Root namespaces must be created using RootNamespace");
314 string pname = parent != null ? parent.Name : "";
319 fullname = parent.Name + "." + name;
321 if (fullname == null)
322 throw new InternalErrorException ("Namespace has a null fullname");
324 if (parent != null && parent.MemberName != MemberName.Null)
325 MemberName = new MemberName (parent.MemberName, name);
326 else if (name.Length == 0)
327 MemberName = MemberName.Null;
329 MemberName = new MemberName (name);
331 namespaces = new HybridDictionary ();
332 cached_types = new Hashtable ();
334 root.RegisterNamespace (this);
337 public override Expression DoResolve (EmitContext ec)
342 public virtual void Error_NamespaceDoesNotExist (DeclSpace ds, Location loc, string name)
344 if (name.IndexOf ('`') > 0) {
345 FullNamedExpression retval = Lookup (ds, SimpleName.RemoveGenericArity (name), loc);
346 if (retval != null) {
347 Error_TypeArgumentsCannotBeUsed (retval.Type, loc, "type");
351 Type t = LookForAnyGenericType (name);
353 Error_InvalidNumberOfTypeArguments (t, loc);
358 Report.Error (234, loc, "The type or namespace name `{0}' does not exist in the namespace `{1}'. Are you missing an assembly reference?",
362 public static void Error_InvalidNumberOfTypeArguments (Type t, Location loc)
364 Report.SymbolRelatedToPreviousError (t);
365 Report.Error (305, loc, "Using the generic type `{0}' requires `{1}' type argument(s)",
366 TypeManager.CSharpName(t), TypeManager.GetNumberOfTypeArguments(t).ToString());
369 public static void Error_TypeArgumentsCannotBeUsed(Type t, Location loc, string symbol)
371 Report.SymbolRelatedToPreviousError(t);
372 Report.Error(308, loc, "The non-generic {0} `{1}' cannot be used with the type arguments",
373 symbol, TypeManager.CSharpName(t));
376 public override void Emit (EmitContext ec)
378 throw new InternalErrorException ("Expression tree referenced namespace " + fullname + " during Emit ()");
381 public override string GetSignatureForError ()
386 public Namespace GetNamespace (string name, bool create)
388 int pos = name.IndexOf ('.');
393 first = name.Substring (0, pos);
397 ns = (Namespace) namespaces [first];
402 ns = new Namespace (this, first);
403 namespaces.Add (first, ns);
407 ns = ns.GetNamespace (name.Substring (pos + 1), create);
412 TypeExpr LookupType (string name, Location loc)
414 if (cached_types.Contains (name))
415 return cached_types [name] as TypeExpr;
418 if (declspaces != null) {
419 DeclSpace tdecl = declspaces [name] as DeclSpace;
422 // Note that this is not:
424 // t = tdecl.DefineType ()
426 // This is to make it somewhat more useful when a DefineType
427 // fails due to problems in nested types (more useful in the sense
428 // of fewer misleading error messages)
431 t = tdecl.TypeBuilder;
434 string lookup = t != null ? t.FullName : (fullname.Length == 0 ? name : fullname + "." + name);
435 Type rt = root.LookupTypeReflection (lookup, loc);
437 // HACK: loc.IsNull when the type is core type
438 if (t == null || (rt != null && loc.IsNull))
441 TypeExpr te = t == null ? null : new TypeExpression (t, Location.Null);
442 cached_types [name] = te;
447 /// Used for better error reporting only
449 public Type LookForAnyGenericType (string typeName)
451 if (declspaces == null)
454 typeName = SimpleName.RemoveGenericArity (typeName);
456 foreach (DictionaryEntry de in declspaces) {
457 string type_item = (string) de.Key;
458 int pos = type_item.LastIndexOf ('`');
459 if (pos == typeName.Length && String.Compare (typeName, 0, type_item, 0, pos) == 0)
460 return ((DeclSpace) de.Value).TypeBuilder;
465 public FullNamedExpression Lookup (DeclSpace ds, string name, Location loc)
467 if (namespaces.Contains (name))
468 return (Namespace) namespaces [name];
470 return LookupType (name, loc);
473 public void RegisterExternalExtensionMethodClass (Type type)
475 if (external_exmethod_classes == null)
476 external_exmethod_classes = new ArrayList ();
478 external_exmethod_classes.Add (type);
482 /// Looks for extension method in this namespace
484 public ArrayList LookupExtensionMethod (Type extensionType, ClassOrStruct currentClass, string name, NamespaceEntry ns)
486 ArrayList found = null;
488 if (declspaces != null) {
489 IEnumerator e = declspaces.Values.GetEnumerator ();
491 while (e.MoveNext ()) {
492 Class c = e.Current as Class;
496 if (!c.IsStaticClass)
499 ArrayList res = c.MemberCache.FindExtensionMethods (extensionType, name, c != currentClass);
506 found.AddRange (res);
510 if (external_exmethod_classes == null)
513 foreach (Type t in external_exmethod_classes) {
514 MemberCache m = TypeHandle.GetMemberCache (t);
515 ArrayList res = m.FindExtensionMethods (extensionType, name, true);
522 found.AddRange (res);
528 public void AddDeclSpace (string name, DeclSpace ds)
530 if (declspaces == null)
531 declspaces = new HybridDictionary ();
532 declspaces.Add (name, ds);
536 /// The qualified name of the current namespace
539 get { return fullname; }
542 public override string FullName {
543 get { return fullname; }
547 /// The parent of this namespace, used by the parser to "Pop"
548 /// the current namespace declaration
550 public Namespace Parent {
551 get { return parent; }
554 public override string ToString ()
556 return String.Format ("Namespace ({0})", Name);
560 public class NamespaceEntry {
562 NamespaceEntry parent, implicit_parent;
566 ArrayList using_clauses;
567 public bool DeclarationFound = false;
570 public readonly DeclSpace SlaveDeclSpace;
572 ListDictionary extern_aliases;
574 static ArrayList entries = new ArrayList ();
576 public static void Reset ()
578 entries = new ArrayList ();
582 // This class holds the location where a using definition is
583 // done, and whether it has been used by the program or not.
585 // We use this to flag using clauses for namespaces that do not
588 public class UsingEntry : IResolveContext {
589 public readonly MemberName Name;
590 readonly NamespaceEntry NamespaceEntry;
591 readonly Location Location;
593 public UsingEntry (NamespaceEntry entry, MemberName name, Location loc)
596 NamespaceEntry = entry;
600 internal Namespace resolved;
602 public Namespace Resolve ()
604 if (resolved != null)
607 FullNamedExpression fne = Name.GetTypeExpression ().ResolveAsTypeStep (this, false);
609 Error_NamespaceNotFound (Location, Name.ToString ());
613 resolved = fne as Namespace;
614 if (resolved == null) {
615 Report.SymbolRelatedToPreviousError (fne.Type);
616 Report.Error (138, Location,
617 "`{0}' is a type not a namespace. A using namespace directive can only be applied to namespaces", Name.ToString ());
622 DeclSpace IResolveContext.DeclContainer {
623 get { return NamespaceEntry.SlaveDeclSpace; }
626 DeclSpace IResolveContext.GenericDeclContainer {
627 get { return NamespaceEntry.SlaveDeclSpace; }
630 bool IResolveContext.IsInObsoleteScope {
631 get { return false; }
633 bool IResolveContext.IsInUnsafeScope {
634 get { return false; }
638 public abstract class AliasEntry {
639 public readonly string Name;
640 public readonly NamespaceEntry NamespaceEntry;
641 public readonly Location Location;
643 protected AliasEntry (NamespaceEntry entry, string name, Location loc)
646 NamespaceEntry = entry;
650 protected FullNamedExpression resolved;
653 public FullNamedExpression Resolve ()
655 if (resolved != null || error)
657 resolved = DoResolve ();
658 if (resolved == null)
663 protected abstract FullNamedExpression DoResolve ();
666 public class LocalAliasEntry : AliasEntry, IResolveContext {
667 public readonly Expression Alias;
669 public LocalAliasEntry (NamespaceEntry entry, string name, MemberName alias, Location loc) :
670 base (entry, name, loc)
672 Alias = alias.GetTypeExpression ();
675 protected override FullNamedExpression DoResolve ()
677 resolved = Alias.ResolveAsTypeStep (this, false);
678 if (resolved == null)
681 if (resolved.Type != null) {
682 TypeAttributes attr = resolved.Type.Attributes & TypeAttributes.VisibilityMask;
683 if (attr == TypeAttributes.NestedPrivate || attr == TypeAttributes.NestedFamily ||
684 ((attr == TypeAttributes.NestedFamORAssem || attr == TypeAttributes.NestedAssembly) &&
685 TypeManager.LookupDeclSpace (resolved.Type) == null)) {
686 Expression.ErrorIsInaccesible (Alias.Location, Alias.ToString ());
694 DeclSpace IResolveContext.DeclContainer {
695 get { return NamespaceEntry.SlaveDeclSpace; }
698 DeclSpace IResolveContext.GenericDeclContainer {
699 get { return NamespaceEntry.SlaveDeclSpace; }
702 bool IResolveContext.IsInObsoleteScope {
703 get { return false; }
705 bool IResolveContext.IsInUnsafeScope {
706 get { return false; }
710 public class ExternAliasEntry : AliasEntry {
711 public ExternAliasEntry (NamespaceEntry entry, string name, Location loc) :
712 base (entry, name, loc)
716 protected override FullNamedExpression DoResolve ()
718 resolved = RootNamespace.GetRootNamespace (Name);
719 if (resolved == null)
720 Report.Error (430, Location, "The extern alias '" + Name +
721 "' was not specified in a /reference option");
727 public NamespaceEntry (NamespaceEntry parent, SourceFile file, string name)
729 this.parent = parent;
732 this.ID = entries.Count;
735 ns = parent.NS.GetNamespace (name, true);
736 else if (name != null)
737 ns = RootNamespace.Global.GetNamespace (name, true);
739 ns = RootNamespace.Global;
740 SlaveDeclSpace = new RootDeclSpace (this);
743 private NamespaceEntry (NamespaceEntry parent, SourceFile file, Namespace ns, bool slave)
745 this.parent = parent;
747 // no need to add self to 'entries', since we don't have any aliases or using entries.
749 this.IsImplicit = true;
751 this.SlaveDeclSpace = slave ? new RootDeclSpace (this) : null;
755 // According to section 16.3.1 (using-alias-directive), the namespace-or-type-name is
756 // resolved as if the immediately containing namespace body has no using-directives.
758 // Section 16.3.2 says that the same rule is applied when resolving the namespace-name
759 // in the using-namespace-directive.
761 // To implement these rules, the expressions in the using directives are resolved using
762 // the "doppelganger" (ghostly bodiless duplicate).
764 NamespaceEntry doppelganger;
765 NamespaceEntry Doppelganger {
767 if (!IsImplicit && doppelganger == null)
768 doppelganger = new NamespaceEntry (ImplicitParent, file, ns, true);
773 public readonly int ID;
774 public readonly bool IsImplicit;
776 public Namespace NS {
780 public NamespaceEntry Parent {
781 get { return parent; }
784 public NamespaceEntry ImplicitParent {
788 if (implicit_parent == null) {
789 implicit_parent = (parent.NS == ns.Parent)
791 : new NamespaceEntry (parent, file, ns.Parent, false);
793 return implicit_parent;
798 /// Records a new namespace for resolving name references
800 public void Using (MemberName name, Location loc)
802 if (DeclarationFound){
803 Report.Error (1529, loc, "A using clause must precede all other namespace elements except extern alias declarations");
809 if (name.Equals (ns.MemberName))
812 if (using_clauses == null)
813 using_clauses = new ArrayList ();
815 foreach (UsingEntry old_entry in using_clauses) {
816 if (name.Equals (old_entry.Name)) {
817 Report.Warning (105, 3, loc, "The using directive for `{0}' appeared previously in this namespace", name.GetName ());
822 UsingEntry ue = new UsingEntry (Doppelganger, name, loc);
823 using_clauses.Add (ue);
826 public void UsingAlias (string name, MemberName alias, Location loc)
828 if (DeclarationFound){
829 Report.Error (1529, loc, "A using clause must precede all other namespace elements except extern alias declarations");
836 aliases = new Hashtable ();
838 if (aliases.Contains (name)) {
839 AliasEntry ae = (AliasEntry) aliases [name];
840 Report.SymbolRelatedToPreviousError (ae.Location, ae.Name);
841 Report.Error (1537, loc, "The using alias `{0}' appeared previously in this namespace", name);
845 if (RootContext.Version != LanguageVersion.ISO_1 && name == "global")
846 Report.Warning (440, 2, loc, "An alias named `global' will not be used when resolving 'global::';" +
847 " the global namespace will be used instead");
849 // FIXME: get correct error number. See if the above check can be merged
850 if (extern_aliases != null && extern_aliases.Contains (name)) {
851 AliasEntry ae = (AliasEntry) extern_aliases [name];
852 Report.SymbolRelatedToPreviousError (ae.Location, ae.Name);
853 Report.Error (1537, loc, "The using alias `{0}' appeared previously in this namespace", name);
857 aliases [name] = new LocalAliasEntry (Doppelganger, name, alias, loc);
860 public void UsingExternalAlias (string name, Location loc)
862 if (UsingFound || DeclarationFound) {
863 Report.Error (439, loc, "An extern alias declaration must precede all other elements");
867 // Share the extern_aliases field with the Doppelganger
868 if (extern_aliases == null) {
869 extern_aliases = new ListDictionary ();
870 Doppelganger.extern_aliases = extern_aliases;
873 if (extern_aliases.Contains (name)) {
874 AliasEntry ae = (AliasEntry) extern_aliases [name];
875 Report.SymbolRelatedToPreviousError (ae.Location, ae.Name);
876 Report.Error (1537, loc, "The using alias `{0}' appeared previously in this namespace", name);
880 if (name == "global") {
881 Error_GlobalNamespaceRedefined (loc);
885 // Register the alias in aliases and extern_aliases, since we need both of them
886 // to keep things simple (different resolution scenarios)
887 ExternAliasEntry alias = new ExternAliasEntry (Doppelganger, name, loc);
888 extern_aliases [name] = alias;
892 /// Does extension methods look up to find a method which matches name and extensionType.
893 /// Search starts from this namespace and continues hierarchically up to top level.
895 public ExtensionMethodGroupExpr LookupExtensionMethod (Type extensionType, ClassOrStruct currentClass, string name)
897 ArrayList candidates = null;
898 if (currentClass != null) {
899 candidates = ns.LookupExtensionMethod (extensionType, currentClass, name, this);
900 if (candidates != null)
901 return new ExtensionMethodGroupExpr (candidates, this, extensionType, Location.Null);
904 foreach (Namespace n in GetUsingTable ()) {
905 ArrayList a = n.LookupExtensionMethod (extensionType, null, name, this);
909 if (candidates == null)
912 candidates.AddRange (a);
915 if (candidates != null)
916 return new ExtensionMethodGroupExpr (candidates, parent, extensionType, Location.Null);
921 return parent.LookupExtensionMethod (extensionType, currentClass, name);
924 public FullNamedExpression LookupNamespaceOrType (DeclSpace ds, string name, Location loc, bool ignore_cs0104)
926 // Precondition: Only simple names (no dots) will be looked up with this function.
927 FullNamedExpression resolved = null;
928 for (NamespaceEntry curr_ns = this; curr_ns != null; curr_ns = curr_ns.ImplicitParent) {
929 if ((resolved = curr_ns.Lookup (ds, name, loc, ignore_cs0104)) != null)
935 static void Error_AmbiguousTypeReference (Location loc, string name, FullNamedExpression t1, FullNamedExpression t2)
937 Report.SymbolRelatedToPreviousError (t1.Type);
938 Report.SymbolRelatedToPreviousError (t2.Type);
939 Report.Error (104, loc, "`{0}' is an ambiguous reference between `{1}' and `{2}'",
940 name, t1.FullName, t2.FullName);
943 // Looks-up a alias named @name in this and surrounding namespace declarations
944 public FullNamedExpression LookupAlias (string name)
946 AliasEntry entry = null;
947 for (NamespaceEntry n = this; n != null; n = n.ImplicitParent) {
948 if (n.extern_aliases != null && (entry = n.extern_aliases [name] as AliasEntry) != null)
950 if (n.aliases != null && (entry = n.aliases [name] as AliasEntry) != null)
953 return entry == null ? null : entry.Resolve ();
956 private FullNamedExpression Lookup (DeclSpace ds, string name, Location loc, bool ignore_cs0104)
959 // Check whether it's in the namespace.
961 FullNamedExpression fne = ns.Lookup (ds, name, loc);
965 if (extern_aliases != null) {
966 AliasEntry entry = extern_aliases [name] as AliasEntry;
968 return entry.Resolve ();
977 if (aliases != null) {
978 AliasEntry entry = aliases [name] as AliasEntry;
980 return entry.Resolve ();
984 // Check using entries.
986 FullNamedExpression match = null;
987 foreach (Namespace using_ns in GetUsingTable ()) {
988 match = using_ns.Lookup (ds, name, loc);
989 if (match == null || !(match is TypeExpr))
993 Error_AmbiguousTypeReference (loc, name, fne, match);
1002 // Our cached computation.
1003 static readonly Namespace [] empty_namespaces = new Namespace [0];
1004 Namespace [] namespace_using_table;
1005 Namespace [] GetUsingTable ()
1007 if (namespace_using_table != null)
1008 return namespace_using_table;
1010 if (using_clauses == null) {
1011 namespace_using_table = empty_namespaces;
1012 return namespace_using_table;
1015 ArrayList list = new ArrayList (using_clauses.Count);
1017 foreach (UsingEntry ue in using_clauses) {
1018 Namespace using_ns = ue.Resolve ();
1019 if (using_ns == null)
1022 list.Add (using_ns);
1025 namespace_using_table = new Namespace [list.Count];
1026 list.CopyTo (namespace_using_table, 0);
1027 return namespace_using_table;
1030 static readonly string [] empty_using_list = new string [0];
1032 public int SymbolFileID {
1034 if (symfile_id == 0 && file.SourceFileEntry != null) {
1035 int parent_id = parent == null ? 0 : parent.SymbolFileID;
1037 string [] using_list = empty_using_list;
1038 if (using_clauses != null) {
1039 using_list = new string [using_clauses.Count];
1040 for (int i = 0; i < using_clauses.Count; i++)
1041 using_list [i] = ((UsingEntry) using_clauses [i]).Name.ToString ();
1044 symfile_id = CodeGen.SymbolWriter.DefineNamespace (ns.Name, file.SourceFileEntry, using_list, parent_id);
1050 static void MsgtryRef (string s)
1052 Console.WriteLine (" Try using -r:" + s);
1055 static void MsgtryPkg (string s)
1057 Console.WriteLine (" Try using -pkg:" + s);
1060 public static void Error_GlobalNamespaceRedefined (Location loc)
1062 Report.Error (1681, loc, "You cannot redefine the global extern alias");
1065 public static void Error_NamespaceNotFound (Location loc, string name)
1067 Report.Error (246, loc, "The type or namespace name `{0}' could not be found. Are you missing a using directive or an assembly reference?",
1071 case "Gtk": case "GtkSharp":
1072 MsgtryPkg ("gtk-sharp");
1075 case "Gdk": case "GdkSharp":
1076 MsgtryPkg ("gdk-sharp");
1079 case "Glade": case "GladeSharp":
1080 MsgtryPkg ("glade-sharp");
1083 case "System.Drawing":
1084 case "System.Web.Services":
1087 case "System.Windows.Forms":
1094 /// Used to validate that all the using clauses are correct
1095 /// after we are finished parsing all the files.
1099 if (extern_aliases != null) {
1100 foreach (DictionaryEntry de in extern_aliases)
1101 ((AliasEntry) de.Value).Resolve ();
1104 if (using_clauses != null) {
1105 foreach (UsingEntry ue in using_clauses)
1109 if (aliases != null) {
1110 foreach (DictionaryEntry de in aliases)
1111 ((AliasEntry) de.Value).Resolve ();
1116 /// Used to validate that all the using clauses are correct
1117 /// after we are finished parsing all the files.
1119 static public void VerifyAllUsing ()
1121 foreach (NamespaceEntry entry in entries)
1122 entry.VerifyUsing ();
1125 public string GetSignatureForError ()
1127 return ns.GetSignatureForError ();
1130 public override string ToString ()
1132 return ns.ToString ();