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 :-(
106 const string SystemCore = "System.Core, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";
107 if (TypeManager.extension_attribute_type == null &&
108 assembly.FullName == SystemCore) {
109 TypeManager.extension_attribute_type = assembly.GetType("System.Runtime.CompilerServices.ExtensionAttribute");
112 bool contains_extension_methods = TypeManager.extension_attribute_type != null &&
113 assembly.IsDefined(TypeManager.extension_attribute_type, false);
115 if (get_namespaces_method != null && !contains_extension_methods) {
116 string [] namespaces = (string []) get_namespaces_method.Invoke (assembly, null);
117 foreach (string ns in namespaces)
118 RegisterNamespace (ns);
122 foreach (Type t in assembly.GetExportedTypes ()) {
123 if ((t.Attributes & Class.StaticClassAttribute) == Class.StaticClassAttribute &&
124 contains_extension_methods && t.IsDefined (TypeManager.extension_attribute_type, false))
125 RegisterExtensionMethodClass (t);
127 RegisterNamespace (t.Namespace);
131 protected static Type GetTypeInAssembly (Assembly assembly, string name)
133 Type t = assembly.GetType (name);
138 throw new InternalErrorException ("Use GetPointerType() to get a pointer");
140 TypeAttributes ta = t.Attributes & TypeAttributes.VisibilityMask;
141 if (ta == TypeAttributes.NestedPrivate)
144 if ((ta == TypeAttributes.NotPublic ||
145 ta == TypeAttributes.NestedAssembly ||
146 ta == TypeAttributes.NestedFamANDAssem) &&
147 !TypeManager.IsFriendAssembly (t.Assembly))
153 public override string ToString ()
155 return String.Format ("RootNamespace ({0}::)", alias_name);
158 public override string GetSignatureForError ()
160 return alias_name + "::";
164 public class GlobalRootNamespace : RootNamespace {
165 Assembly [] assemblies;
168 public GlobalRootNamespace ()
169 : base ("global", null)
171 assemblies = new Assembly [0];
174 public Assembly [] Assemblies {
175 get { return assemblies; }
178 public Module [] Modules {
179 get { return modules; }
182 public void AddAssemblyReference (Assembly a)
184 foreach (Assembly assembly in assemblies) {
189 int top = assemblies.Length;
190 Assembly [] n = new Assembly [top + 1];
191 assemblies.CopyTo (n, 0);
195 ComputeNamespaces (a);
198 public void AddModuleReference (Module m)
200 int top = modules != null ? modules.Length : 0;
201 Module [] n = new Module [top + 1];
203 modules.CopyTo (n, 0);
207 if (m == CodeGen.Module.Builder)
210 foreach (Type t in m.GetTypes ())
211 RegisterNamespace (t.Namespace);
214 public override void Error_NamespaceDoesNotExist(DeclSpace ds, Location loc, string name)
216 Report.Error (400, loc, "The type or namespace name `{0}' could not be found in the global namespace (are you missing an assembly reference?)",
220 public override Type LookupTypeReflection (string name, Location loc)
222 Type found_type = null;
224 foreach (Assembly a in assemblies) {
225 Type t = GetTypeInAssembly (a, name);
229 if (found_type == null) {
234 Report.SymbolRelatedToPreviousError (found_type);
235 Report.SymbolRelatedToPreviousError (t);
236 Report.Error (433, loc, "The imported type `{0}' is defined multiple times", name);
241 if (modules != null) {
242 foreach (Module module in modules) {
243 Type t = module.GetType (name);
247 if (found_type == null) {
252 Report.SymbolRelatedToPreviousError (found_type);
254 DeclSpace ds = TypeManager.LookupDeclSpace (t);
255 Report.Warning (1685, 1, ds.Location, "The type `{0}' conflicts with the predefined type `{1}' and will be ignored",
256 ds.GetSignatureForError (), TypeManager.CSharpName (found_type));
259 Report.SymbolRelatedToPreviousError (t);
260 Report.Warning (436, 2, loc, "The type `{0}' conflicts with the imported type `{1}'. Ignoring the imported type definition",
261 TypeManager.CSharpName (t), TypeManager.CSharpName (found_type));
271 /// Keeps track of the namespaces defined in the C# code.
273 /// This is an Expression to allow it to be referenced in the
274 /// compiler parse/intermediate tree during name resolution.
276 public class Namespace : FullNamedExpression {
280 IDictionary namespaces;
281 IDictionary declspaces;
282 Hashtable cached_types;
284 ArrayList external_exmethod_classes;
286 public readonly MemberName MemberName;
289 /// Constructor Takes the current namespace and the
290 /// name. This is bootstrapped with parent == null
293 public Namespace (Namespace parent, string name)
295 // Expression members.
296 this.eclass = ExprClass.Namespace;
297 this.Type = typeof (Namespace);
298 this.loc = Location.Null;
300 this.parent = parent;
303 this.root = parent.root;
305 this.root = this as RootNamespace;
307 if (this.root == null)
308 throw new InternalErrorException ("Root namespaces must be created using RootNamespace");
310 string pname = parent != null ? parent.Name : "";
315 fullname = parent.Name + "." + name;
317 if (fullname == null)
318 throw new InternalErrorException ("Namespace has a null fullname");
320 if (parent != null && parent.MemberName != MemberName.Null)
321 MemberName = new MemberName (parent.MemberName, name);
322 else if (name.Length == 0)
323 MemberName = MemberName.Null;
325 MemberName = new MemberName (name);
327 namespaces = new HybridDictionary ();
328 cached_types = new Hashtable ();
330 root.RegisterNamespace (this);
333 public override Expression DoResolve (EmitContext ec)
338 public virtual void Error_NamespaceDoesNotExist (DeclSpace ds, Location loc, string name)
340 if (name.IndexOf ('`') > 0) {
341 FullNamedExpression retval = Lookup (ds, SimpleName.RemoveGenericArity (name), loc);
342 if (retval != null) {
343 Error_TypeArgumentsCannotBeUsed (retval.Type, loc, "type");
347 Type t = LookForAnyGenericType (name);
349 Error_InvalidNumberOfTypeArguments (t, loc);
354 Report.Error (234, loc, "The type or namespace name `{0}' does not exist in the namespace `{1}'. Are you missing an assembly reference?",
358 public static void Error_InvalidNumberOfTypeArguments (Type t, Location loc)
360 Report.SymbolRelatedToPreviousError (t);
361 Report.Error (305, loc, "Using the generic type `{0}' requires `{1}' type argument(s)",
362 TypeManager.CSharpName(t), TypeManager.GetNumberOfTypeArguments(t).ToString());
365 public static void Error_TypeArgumentsCannotBeUsed(Type t, Location loc, string symbol)
367 Report.SymbolRelatedToPreviousError(t);
368 Report.Error(308, loc, "The non-generic {0} `{1}' cannot be used with the type argument(s)",
369 symbol, TypeManager.CSharpName(t));
372 public override void Emit (EmitContext ec)
374 throw new InternalErrorException ("Expression tree referenced namespace " + fullname + " during Emit ()");
377 public override string GetSignatureForError ()
382 public Namespace GetNamespace (string name, bool create)
384 int pos = name.IndexOf ('.');
389 first = name.Substring (0, pos);
393 ns = (Namespace) namespaces [first];
398 ns = new Namespace (this, first);
399 namespaces.Add (first, ns);
403 ns = ns.GetNamespace (name.Substring (pos + 1), create);
408 TypeExpr LookupType (string name, Location loc)
410 if (cached_types.Contains (name))
411 return cached_types [name] as TypeExpr;
414 if (declspaces != null) {
415 DeclSpace tdecl = declspaces [name] as DeclSpace;
418 // Note that this is not:
420 // t = tdecl.DefineType ()
422 // This is to make it somewhat more useful when a DefineType
423 // fails due to problems in nested types (more useful in the sense
424 // of fewer misleading error messages)
427 t = tdecl.TypeBuilder;
430 string lookup = t != null ? t.FullName : (fullname.Length == 0 ? name : fullname + "." + name);
431 Type rt = root.LookupTypeReflection (lookup, loc);
433 // HACK: loc.IsNull when the type is core type
434 if (t == null || (rt != null && loc.IsNull))
437 TypeExpr te = t == null ? null : new TypeExpression (t, Location.Null);
438 cached_types [name] = te;
443 /// Used for better error reporting only
445 public Type LookForAnyGenericType (string typeName)
447 if (declspaces == null)
450 typeName = SimpleName.RemoveGenericArity (typeName);
452 foreach (DictionaryEntry de in declspaces) {
453 string type_item = (string) de.Key;
454 int pos = type_item.LastIndexOf ('`');
455 if (pos == typeName.Length && String.Compare (typeName, 0, type_item, 0, pos) == 0)
456 return ((DeclSpace) de.Value).TypeBuilder;
461 public FullNamedExpression Lookup (DeclSpace ds, string name, Location loc)
463 if (namespaces.Contains (name))
464 return (Namespace) namespaces [name];
466 return LookupType (name, loc);
469 public void RegisterExternalExtensionMethodClass (Type type)
471 if (external_exmethod_classes == null)
472 external_exmethod_classes = new ArrayList ();
474 external_exmethod_classes.Add (type);
478 /// Looks for extension method in this namespace
480 public ArrayList LookupExtensionMethod (Type extensionType, ClassOrStruct currentClass, string name, NamespaceEntry ns)
482 ArrayList found = null;
484 if (declspaces != null) {
485 IEnumerator e = declspaces.Values.GetEnumerator ();
487 while (e.MoveNext ()) {
488 Class c = e.Current as Class;
492 if (!c.IsStaticClass)
495 ArrayList res = c.MemberCache.FindExtensionMethods (extensionType, name, c != currentClass);
502 found.AddRange (res);
506 if (external_exmethod_classes == null)
509 foreach (Type t in external_exmethod_classes) {
510 MemberCache m = TypeHandle.GetMemberCache (t);
511 ArrayList res = m.FindExtensionMethods (extensionType, name, true);
518 found.AddRange (res);
524 public void AddDeclSpace (string name, DeclSpace ds)
526 if (declspaces == null)
527 declspaces = new HybridDictionary ();
528 declspaces.Add (name, ds);
532 /// The qualified name of the current namespace
535 get { return fullname; }
538 public override string FullName {
539 get { return fullname; }
543 /// The parent of this namespace, used by the parser to "Pop"
544 /// the current namespace declaration
546 public Namespace Parent {
547 get { return parent; }
550 public override string ToString ()
552 return String.Format ("Namespace ({0})", Name);
556 public class NamespaceEntry {
558 NamespaceEntry parent, implicit_parent;
562 ArrayList using_clauses;
563 public bool DeclarationFound = false;
566 public readonly DeclSpace SlaveDeclSpace;
568 ListDictionary extern_aliases;
570 static ArrayList entries = new ArrayList ();
572 public static void Reset ()
574 entries = new ArrayList ();
578 // This class holds the location where a using definition is
579 // done, and whether it has been used by the program or not.
581 // We use this to flag using clauses for namespaces that do not
584 public class UsingEntry : IResolveContext {
585 public readonly MemberName Name;
586 readonly NamespaceEntry NamespaceEntry;
587 readonly Location Location;
589 public UsingEntry (NamespaceEntry entry, MemberName name, Location loc)
592 NamespaceEntry = entry;
596 internal Namespace resolved;
598 public Namespace Resolve ()
600 if (resolved != null)
603 FullNamedExpression fne = Name.GetTypeExpression ().ResolveAsTypeStep (this, false);
605 Error_NamespaceNotFound (Location, Name.ToString ());
609 resolved = fne as Namespace;
610 if (resolved == null) {
611 Report.SymbolRelatedToPreviousError (fne.Type);
612 Report.Error (138, Location,
613 "`{0}' is a type not a namespace. A using namespace directive can only be applied to namespaces", Name.ToString ());
618 DeclSpace IResolveContext.DeclContainer {
619 get { return NamespaceEntry.SlaveDeclSpace; }
622 DeclSpace IResolveContext.GenericDeclContainer {
623 get { return NamespaceEntry.SlaveDeclSpace; }
626 bool IResolveContext.IsInObsoleteScope {
627 get { return false; }
629 bool IResolveContext.IsInUnsafeScope {
630 get { return false; }
634 public abstract class AliasEntry {
635 public readonly string Name;
636 public readonly NamespaceEntry NamespaceEntry;
637 public readonly Location Location;
639 protected AliasEntry (NamespaceEntry entry, string name, Location loc)
642 NamespaceEntry = entry;
646 protected FullNamedExpression resolved;
649 public FullNamedExpression Resolve ()
651 if (resolved != null || error)
653 resolved = DoResolve ();
654 if (resolved == null)
659 protected abstract FullNamedExpression DoResolve ();
662 public class LocalAliasEntry : AliasEntry, IResolveContext {
663 public readonly Expression Alias;
665 public LocalAliasEntry (NamespaceEntry entry, string name, MemberName alias, Location loc) :
666 base (entry, name, loc)
668 Alias = alias.GetTypeExpression ();
671 protected override FullNamedExpression DoResolve ()
673 resolved = Alias.ResolveAsTypeStep (this, false);
674 if (resolved == null)
677 if (resolved.Type != null) {
678 TypeAttributes attr = resolved.Type.Attributes & TypeAttributes.VisibilityMask;
679 if (attr == TypeAttributes.NestedPrivate || attr == TypeAttributes.NestedFamily ||
680 ((attr == TypeAttributes.NestedFamORAssem || attr == TypeAttributes.NestedAssembly) &&
681 TypeManager.LookupDeclSpace (resolved.Type) == null)) {
682 Expression.ErrorIsInaccesible (Alias.Location, Alias.ToString ());
690 DeclSpace IResolveContext.DeclContainer {
691 get { return NamespaceEntry.SlaveDeclSpace; }
694 DeclSpace IResolveContext.GenericDeclContainer {
695 get { return NamespaceEntry.SlaveDeclSpace; }
698 bool IResolveContext.IsInObsoleteScope {
699 get { return false; }
701 bool IResolveContext.IsInUnsafeScope {
702 get { return false; }
706 public class ExternAliasEntry : AliasEntry {
707 public ExternAliasEntry (NamespaceEntry entry, string name, Location loc) :
708 base (entry, name, loc)
712 protected override FullNamedExpression DoResolve ()
714 resolved = RootNamespace.GetRootNamespace (Name);
715 if (resolved == null)
716 Report.Error (430, Location, "The extern alias '" + Name +
717 "' was not specified in a /reference option");
723 public NamespaceEntry (NamespaceEntry parent, SourceFile file, string name)
725 this.parent = parent;
728 this.ID = entries.Count;
731 ns = parent.NS.GetNamespace (name, true);
732 else if (name != null)
733 ns = RootNamespace.Global.GetNamespace (name, true);
735 ns = RootNamespace.Global;
736 SlaveDeclSpace = new RootDeclSpace (this);
739 private NamespaceEntry (NamespaceEntry parent, SourceFile file, Namespace ns, bool slave)
741 this.parent = parent;
743 // no need to add self to 'entries', since we don't have any aliases or using entries.
745 this.IsImplicit = true;
747 this.SlaveDeclSpace = slave ? new RootDeclSpace (this) : null;
751 // According to section 16.3.1 (using-alias-directive), the namespace-or-type-name is
752 // resolved as if the immediately containing namespace body has no using-directives.
754 // Section 16.3.2 says that the same rule is applied when resolving the namespace-name
755 // in the using-namespace-directive.
757 // To implement these rules, the expressions in the using directives are resolved using
758 // the "doppelganger" (ghostly bodiless duplicate).
760 NamespaceEntry doppelganger;
761 NamespaceEntry Doppelganger {
763 if (!IsImplicit && doppelganger == null)
764 doppelganger = new NamespaceEntry (ImplicitParent, file, ns, true);
769 public readonly int ID;
770 public readonly bool IsImplicit;
772 public Namespace NS {
776 public NamespaceEntry Parent {
777 get { return parent; }
780 public NamespaceEntry ImplicitParent {
784 if (implicit_parent == null) {
785 implicit_parent = (parent.NS == ns.Parent)
787 : new NamespaceEntry (parent, file, ns.Parent, false);
789 return implicit_parent;
794 /// Records a new namespace for resolving name references
796 public void Using (MemberName name, Location loc)
798 if (DeclarationFound){
799 Report.Error (1529, loc, "A using clause must precede all other namespace elements except extern alias declarations");
805 if (name.Equals (ns.MemberName))
808 if (using_clauses == null)
809 using_clauses = new ArrayList ();
811 foreach (UsingEntry old_entry in using_clauses) {
812 if (name.Equals (old_entry.Name)) {
813 Report.Warning (105, 3, loc, "The using directive for `{0}' appeared previously in this namespace", name.GetName ());
818 UsingEntry ue = new UsingEntry (Doppelganger, name, loc);
819 using_clauses.Add (ue);
822 public void UsingAlias (string name, MemberName alias, Location loc)
824 if (DeclarationFound){
825 Report.Error (1529, loc, "A using clause must precede all other namespace elements except extern alias declarations");
832 aliases = new Hashtable ();
834 if (aliases.Contains (name)) {
835 AliasEntry ae = (AliasEntry) aliases [name];
836 Report.SymbolRelatedToPreviousError (ae.Location, ae.Name);
837 Report.Error (1537, loc, "The using alias `{0}' appeared previously in this namespace", name);
841 if (RootContext.Version == LanguageVersion.Default &&
842 name == "global" && RootContext.WarningLevel >= 2)
843 Report.Warning (440, 2, loc, "An alias named `global' will not be used when resolving 'global::';" +
844 " the global namespace will be used instead");
846 // FIXME: get correct error number. See if the above check can be merged
847 if (extern_aliases != null && extern_aliases.Contains (name)) {
848 AliasEntry ae = (AliasEntry) extern_aliases [name];
849 Report.SymbolRelatedToPreviousError (ae.Location, ae.Name);
850 Report.Error (1537, loc, "The using alias `{0}' appeared previously in this namespace", name);
854 aliases [name] = new LocalAliasEntry (Doppelganger, name, alias, loc);
857 public void UsingExternalAlias (string name, Location loc)
859 if (UsingFound || DeclarationFound) {
860 Report.Error (439, loc, "An extern alias declaration must precede all other elements");
864 // Share the extern_aliases field with the Doppelganger
865 if (extern_aliases == null) {
866 extern_aliases = new ListDictionary ();
867 Doppelganger.extern_aliases = extern_aliases;
870 if (extern_aliases.Contains (name)) {
871 AliasEntry ae = (AliasEntry) extern_aliases [name];
872 Report.SymbolRelatedToPreviousError (ae.Location, ae.Name);
873 Report.Error (1537, loc, "The using alias `{0}' appeared previously in this namespace", name);
877 if (name == "global") {
878 Error_GlobalNamespaceRedefined (loc);
882 // Register the alias in aliases and extern_aliases, since we need both of them
883 // to keep things simple (different resolution scenarios)
884 ExternAliasEntry alias = new ExternAliasEntry (Doppelganger, name, loc);
885 extern_aliases [name] = alias;
889 /// Does extension methods look up to find a method which matches name and extensionType.
890 /// Search starts from this namespace and continues hierarchically up to top level.
892 public ExtensionMethodGroupExpr LookupExtensionMethod (Type extensionType, ClassOrStruct currentClass, string name)
894 ArrayList candidates = null;
895 if (currentClass != null) {
896 candidates = ns.LookupExtensionMethod (extensionType, currentClass, name, this);
897 if (candidates != null)
898 return new ExtensionMethodGroupExpr (candidates, this, extensionType, Location.Null);
901 foreach (Namespace n in GetUsingTable ()) {
902 ArrayList a = n.LookupExtensionMethod (extensionType, null, name, this);
906 if (candidates == null)
909 candidates.AddRange (a);
912 if (candidates != null)
913 return new ExtensionMethodGroupExpr (candidates, parent, extensionType, Location.Null);
918 return parent.LookupExtensionMethod (extensionType, currentClass, name);
921 public FullNamedExpression LookupNamespaceOrType (DeclSpace ds, string name, Location loc, bool ignore_cs0104)
923 // Precondition: Only simple names (no dots) will be looked up with this function.
924 FullNamedExpression resolved = null;
925 for (NamespaceEntry curr_ns = this; curr_ns != null; curr_ns = curr_ns.ImplicitParent) {
926 if ((resolved = curr_ns.Lookup (ds, name, loc, ignore_cs0104)) != null)
932 static void Error_AmbiguousTypeReference (Location loc, string name, FullNamedExpression t1, FullNamedExpression t2)
934 Report.Error (104, loc, "`{0}' is an ambiguous reference between `{1}' and `{2}'",
935 name, t1.FullName, t2.FullName);
938 // Looks-up a alias named @name in this and surrounding namespace declarations
939 public FullNamedExpression LookupAlias (string name)
941 AliasEntry entry = null;
942 for (NamespaceEntry n = this; n != null; n = n.ImplicitParent) {
943 if (n.extern_aliases != null && (entry = n.extern_aliases [name] as AliasEntry) != null)
945 if (n.aliases != null && (entry = n.aliases [name] as AliasEntry) != null)
948 return entry == null ? null : entry.Resolve ();
951 private FullNamedExpression Lookup (DeclSpace ds, string name, Location loc, bool ignore_cs0104)
954 // Check whether it's in the namespace.
956 FullNamedExpression fne = ns.Lookup (ds, name, loc);
960 if (extern_aliases != null) {
961 AliasEntry entry = extern_aliases [name] as AliasEntry;
963 return entry.Resolve ();
972 if (aliases != null) {
973 AliasEntry entry = aliases [name] as AliasEntry;
975 return entry.Resolve ();
979 // Check using entries.
981 FullNamedExpression match = null;
982 foreach (Namespace using_ns in GetUsingTable ()) {
983 match = using_ns.Lookup (ds, name, loc);
984 if (match == null || !(match is TypeExpr))
988 Error_AmbiguousTypeReference (loc, name, fne, match);
997 // Our cached computation.
998 static readonly Namespace [] empty_namespaces = new Namespace [0];
999 Namespace [] namespace_using_table;
1000 Namespace [] GetUsingTable ()
1002 if (namespace_using_table != null)
1003 return namespace_using_table;
1005 if (using_clauses == null) {
1006 namespace_using_table = empty_namespaces;
1007 return namespace_using_table;
1010 ArrayList list = new ArrayList (using_clauses.Count);
1012 foreach (UsingEntry ue in using_clauses) {
1013 Namespace using_ns = ue.Resolve ();
1014 if (using_ns == null)
1017 list.Add (using_ns);
1020 namespace_using_table = new Namespace [list.Count];
1021 list.CopyTo (namespace_using_table, 0);
1022 return namespace_using_table;
1025 static readonly string [] empty_using_list = new string [0];
1027 public int SymbolFileID {
1029 if (symfile_id == 0 && file.SourceFileEntry != null) {
1030 int parent_id = parent == null ? 0 : parent.SymbolFileID;
1032 string [] using_list = empty_using_list;
1033 if (using_clauses != null) {
1034 using_list = new string [using_clauses.Count];
1035 for (int i = 0; i < using_clauses.Count; i++)
1036 using_list [i] = ((UsingEntry) using_clauses [i]).Name.ToString ();
1039 symfile_id = CodeGen.SymbolWriter.DefineNamespace (ns.Name, file.SourceFileEntry, using_list, parent_id);
1045 static void MsgtryRef (string s)
1047 Console.WriteLine (" Try using -r:" + s);
1050 static void MsgtryPkg (string s)
1052 Console.WriteLine (" Try using -pkg:" + s);
1055 public static void Error_GlobalNamespaceRedefined (Location loc)
1057 Report.Error (1681, loc, "You cannot redefine the global extern alias");
1060 public static void Error_NamespaceNotFound (Location loc, string name)
1062 Report.Error (246, loc, "The type or namespace name `{0}' could not be found. Are you missing a using directive or an assembly reference?",
1066 case "Gtk": case "GtkSharp":
1067 MsgtryPkg ("gtk-sharp");
1070 case "Gdk": case "GdkSharp":
1071 MsgtryPkg ("gdk-sharp");
1074 case "Glade": case "GladeSharp":
1075 MsgtryPkg ("glade-sharp");
1078 case "System.Drawing":
1079 case "System.Web.Services":
1082 case "System.Windows.Forms":
1089 /// Used to validate that all the using clauses are correct
1090 /// after we are finished parsing all the files.
1094 if (extern_aliases != null) {
1095 foreach (DictionaryEntry de in extern_aliases)
1096 ((AliasEntry) de.Value).Resolve ();
1099 if (using_clauses != null) {
1100 foreach (UsingEntry ue in using_clauses)
1104 if (aliases != null) {
1105 foreach (DictionaryEntry de in aliases)
1106 ((AliasEntry) de.Value).Resolve ();
1111 /// Used to validate that all the using clauses are correct
1112 /// after we are finished parsing all the files.
1114 static public void VerifyAllUsing ()
1116 foreach (NamespaceEntry entry in entries)
1117 entry.VerifyUsing ();
1120 public string GetSignatureForError ()
1122 return ns.GetSignatureForError ();
1125 public override string ToString ()
1127 return ns.ToString ();