2 // namespace.cs: Tracks namespaces
5 // Miguel de Icaza (miguel@ximian.com)
6 // Marek Safar (marek.safar@seznam.cz)
8 // Copyright 2001 Ximian, Inc.
9 // Copyright 2003-2008 Novell, Inc.
12 using System.Collections.Generic;
15 namespace Mono.CSharp {
17 public class RootNamespace : Namespace {
19 readonly string alias_name;
20 readonly Dictionary<string, Namespace> all_namespaces;
22 public RootNamespace (string alias_name)
23 : base (null, String.Empty)
25 this.alias_name = alias_name;
27 all_namespaces = new Dictionary<string, Namespace> ();
28 all_namespaces.Add ("", this);
37 public void RegisterNamespace (Namespace child)
40 all_namespaces.Add (child.Name, child);
43 public bool IsNamespace (string name)
45 return all_namespaces.ContainsKey (name);
48 protected void RegisterNamespace (string dotted_name)
50 if (dotted_name != null && dotted_name.Length != 0 && ! IsNamespace (dotted_name))
51 GetNamespace (dotted_name, true);
54 public override string GetSignatureForError ()
56 return alias_name + "::";
60 public class GlobalRootNamespace : RootNamespace
62 public GlobalRootNamespace ()
67 public override void Error_NamespaceDoesNotExist (Location loc, string name, int arity, IMemberContext ctx)
69 ctx.Module.Compiler.Report.Error (400, loc,
70 "The type or namespace name `{0}' could not be found in the global namespace (are you missing an assembly reference?)",
76 /// Keeps track of the namespaces defined in the C# code.
78 /// This is an Expression to allow it to be referenced in the
79 /// compiler parse/intermediate tree during name resolution.
81 public class Namespace : FullNamedExpression {
85 protected Dictionary<string, Namespace> namespaces;
86 protected Dictionary<string, IList<TypeSpec>> types;
87 Dictionary<string, TypeExpr> cached_types;
91 public readonly MemberName MemberName;
94 /// Constructor Takes the current namespace and the
95 /// name. This is bootstrapped with parent == null
98 public Namespace (Namespace parent, string name)
100 // Expression members.
101 this.eclass = ExprClass.Namespace;
102 this.Type = InternalType.FakeInternalType;
103 this.loc = Location.Null;
105 this.parent = parent;
108 this.root = parent.root;
110 this.root = this as RootNamespace;
112 if (this.root == null)
113 throw new InternalErrorException ("Root namespaces must be created using RootNamespace");
115 string pname = parent != null ? parent.fullname : "";
120 fullname = parent.fullname + "." + name;
122 if (fullname == null)
123 throw new InternalErrorException ("Namespace has a null fullname");
125 if (parent != null && parent.MemberName != MemberName.Null)
126 MemberName = new MemberName (parent.MemberName, name);
127 else if (name.Length == 0)
128 MemberName = MemberName.Null;
130 MemberName = new MemberName (name);
132 namespaces = new Dictionary<string, Namespace> ();
133 cached_types = new Dictionary<string, TypeExpr> ();
135 root.RegisterNamespace (this);
141 /// The qualified name of the current namespace
144 get { return fullname; }
148 /// The parent of this namespace, used by the parser to "Pop"
149 /// the current namespace declaration
151 public Namespace Parent {
152 get { return parent; }
157 protected override Expression DoResolve (ResolveContext ec)
162 public virtual void Error_NamespaceDoesNotExist (Location loc, string name, int arity, IMemberContext ctx)
164 FullNamedExpression retval = Lookup (ctx, name, -System.Math.Max (1, arity), loc);
165 if (retval != null) {
166 Error_TypeArgumentsCannotBeUsed (ctx.Module.Compiler.Report, loc, retval.Type, arity);
171 if (arity > 0 && namespaces.TryGetValue (name, out ns)) {
172 ns.Error_TypeArgumentsCannotBeUsed (ctx.Module.Compiler.Report, loc, null, arity);
176 ctx.Module.Compiler.Report.Error (234, loc,
177 "The type or namespace name `{0}' does not exist in the namespace `{1}'. Are you missing an assembly reference?",
178 name, GetSignatureForError ());
181 public override string GetSignatureForError ()
186 public Namespace GetNamespace (string name, bool create)
188 int pos = name.IndexOf ('.');
193 first = name.Substring (0, pos);
197 if (!namespaces.TryGetValue (first, out ns)) {
201 ns = new Namespace (this, first);
202 namespaces.Add (first, ns);
206 ns = ns.GetNamespace (name.Substring (pos + 1), create);
211 public TypeExpr LookupType (IMemberContext ctx, string name, int arity, bool silent, Location loc)
217 if (arity == 0 && cached_types.TryGetValue (name, out te))
220 IList<TypeSpec> found;
221 if (!types.TryGetValue (name, out found))
224 TypeSpec best = null;
225 foreach (var ts in found) {
226 if (ts.Arity == arity) {
232 var pts = best as BuildinTypeSpec;
234 pts = ts as BuildinTypeSpec;
237 ctx.Module.Compiler.Report.SymbolRelatedToPreviousError (best);
238 ctx.Module.Compiler.Report.SymbolRelatedToPreviousError (ts);
240 // TODO: This should use different warning number but we want to be csc compatible
241 ctx.Module.Compiler.Report.Warning (1685, 1, loc,
242 "The predefined type `{0}.{1}' is redefined in the source code. Ignoring the local type definition",
243 pts.Namespace, pts.Name);
248 if (best.MemberDefinition.IsImported && ts.MemberDefinition.IsImported) {
249 ctx.Module.Compiler.Report.SymbolRelatedToPreviousError (best);
250 ctx.Module.Compiler.Report.SymbolRelatedToPreviousError (ts);
252 ctx.Module.Compiler.Report.Warning (1685, 1, loc,
253 "The predefined type `{0}' is defined in multiple assemblies. Using definition from `{1}'",
254 ts.GetSignatureForError (), best.MemberDefinition.DeclaringAssembly.Name);
256 ctx.Module.Compiler.Report.Error (433, loc, "The imported type `{0}' is defined multiple times", ts.GetSignatureForError ());
262 if (best.MemberDefinition.IsImported)
265 if ((best.Modifiers & Modifiers.INTERNAL) != 0 && !best.MemberDefinition.IsInternalAsPublic (RootContext.ToplevelTypes.DeclaringAssembly))
271 if (ts.MemberDefinition.IsImported)
272 ctx.Module.Compiler.Report.SymbolRelatedToPreviousError (ts);
274 ctx.Module.Compiler.Report.Warning (436, 2, loc,
275 "The type `{0}' conflicts with the imported type of same name'. Ignoring the imported type definition",
276 best.GetSignatureForError ());
280 // Lookup for the best candidate with closest arity match
285 } else if (System.Math.Abs (ts.Arity + arity) < System.Math.Abs (best.Arity + arity)) {
294 if ((best.Modifiers & Modifiers.INTERNAL) != 0 && !best.MemberDefinition.IsInternalAsPublic (RootContext.ToplevelTypes.DeclaringAssembly))
297 te = new TypeExpression (best, Location.Null);
299 // TODO MemberCache: Cache more
300 if (arity == 0 && !silent)
301 cached_types.Add (name, te);
306 TypeSpec LookupType (string name, int arity)
311 IList<TypeSpec> found;
312 if (types.TryGetValue (name, out found)) {
313 TypeSpec best = null;
315 foreach (var ts in found) {
316 if (ts.Arity == arity)
320 // Lookup for the best candidate with closest arity match
325 } else if (System.Math.Abs (ts.Arity + arity) < System.Math.Abs (best.Arity + arity)) {
337 public FullNamedExpression Lookup (IMemberContext ctx, string name, int arity, Location loc)
339 if (arity == 0 && namespaces.ContainsKey (name))
340 return namespaces [name];
342 return LookupType (ctx, name, arity, false, loc);
346 // Completes types with the given `prefix'
348 public IEnumerable<string> CompletionGetTypesStartingWith (string prefix)
351 return Enumerable.Empty<string> ();
353 var res = from item in types
354 where item.Key.StartsWith (prefix) && item.Value.Any (l => (l.Modifiers & Modifiers.PUBLIC) != 0)
357 if (namespaces != null)
358 res = res.Concat (from item in namespaces where item.Key.StartsWith (prefix) select item.Key);
364 /// Looks for extension method in this namespace
366 public List<MethodSpec> LookupExtensionMethod (TypeSpec extensionType, TypeContainer invocationContext, string name, int arity)
371 List<MethodSpec> found = null;
373 // TODO: Add per namespace flag when at least 1 type has extension
375 foreach (var tgroup in types.Values) {
376 foreach (var ts in tgroup) {
377 if ((ts.Modifiers & Modifiers.METHOD_EXTENSION) == 0)
380 var res = ts.MemberCache.FindExtensionMethods (invocationContext, extensionType, name, arity);
387 found.AddRange (res);
395 public void AddType (TypeSpec ts)
398 types = new Dictionary<string, IList<TypeSpec>> (64);
402 IList<TypeSpec> existing;
403 if (types.TryGetValue (name, out existing)) {
404 TypeSpec better_type;
406 if (existing.Count == 1) {
408 if (ts.Arity == found.Arity) {
409 better_type = IsImportedTypeOverride (ts, found);
410 if (better_type == found)
413 if (better_type != null) {
414 existing [0] = better_type;
419 existing = new List<TypeSpec> ();
420 existing.Add (found);
421 types[name] = existing;
423 for (int i = 0; i < existing.Count; ++i) {
425 if (ts.Arity != found.Arity)
428 better_type = IsImportedTypeOverride (ts, found);
429 if (better_type == found)
432 if (better_type != null) {
433 existing.RemoveAt (i);
442 types.Add (name, new TypeSpec[] { ts });
447 // We import any types but in the situation there are same types
448 // but one has better visibility (either public or internal with friend)
449 // the less visible type is removed from the namespace cache
451 public static TypeSpec IsImportedTypeOverride (TypeSpec ts, TypeSpec found)
453 var ts_accessible = (ts.Modifiers & Modifiers.PUBLIC) != 0 || ts.MemberDefinition.IsInternalAsPublic (RootContext.ToplevelTypes.DeclaringAssembly);
454 var found_accessible = (found.Modifiers & Modifiers.PUBLIC) != 0 || found.MemberDefinition.IsInternalAsPublic (RootContext.ToplevelTypes.DeclaringAssembly);
456 if (ts_accessible && !found_accessible)
459 // found is better always better for accessible or inaccessible ts
466 public void RemoveDeclSpace (string name)
469 cached_types.Remove (name);
472 public void ReplaceTypeWithPredefined (TypeSpec ts, BuildinTypeSpec pts)
474 var found = types [ts.Name];
475 cached_types.Remove (ts.Name);
476 if (found.Count == 1) {
477 types[ts.Name][0] = pts;
479 throw new NotImplementedException ();
483 public void VerifyClsCompliance ()
485 if (types == null || cls_checked)
490 // TODO: This is quite ugly way to check for CLS compliance at namespace level
492 var locase_types = new Dictionary<string, List<TypeSpec>> (StringComparer.OrdinalIgnoreCase);
493 foreach (var tgroup in types.Values) {
494 foreach (var tm in tgroup) {
495 if ((tm.Modifiers & Modifiers.PUBLIC) == 0 || !tm.IsCLSCompliant ())
498 List<TypeSpec> found;
499 if (!locase_types.TryGetValue (tm.Name, out found)) {
500 found = new List<TypeSpec> ();
501 locase_types.Add (tm.Name, found);
508 foreach (var locase in locase_types.Values) {
509 if (locase.Count < 2)
512 bool all_same = true;
513 foreach (var notcompliant in locase) {
514 all_same = notcompliant.Name == locase[0].Name;
522 TypeContainer compiled = null;
523 foreach (var notcompliant in locase) {
524 if (!notcompliant.MemberDefinition.IsImported) {
525 if (compiled != null)
526 compiled.Compiler.Report.SymbolRelatedToPreviousError (compiled);
528 compiled = notcompliant.MemberDefinition as TypeContainer;
530 compiled.Compiler.Report.SymbolRelatedToPreviousError (notcompliant);
534 compiled.Compiler.Report.Warning (3005, 1, compiled.Location,
535 "Identifier `{0}' differing only in case is not CLS-compliant", compiled.GetSignatureForError ());
541 // Namespace container as created by the parser
543 public class NamespaceEntry : IMemberContext {
545 public class UsingEntry {
546 readonly MemberName name;
549 public UsingEntry (MemberName name)
554 public string GetSignatureForError ()
556 return name.GetSignatureForError ();
559 public Location Location {
560 get { return name.Location; }
563 public MemberName MemberName {
568 get { return GetSignatureForError (); }
571 public Namespace Resolve (IMemberContext rc)
573 if (resolved != null)
576 FullNamedExpression fne = name.GetTypeExpression ().ResolveAsTypeStep (rc, false);
580 resolved = fne as Namespace;
581 if (resolved == null) {
582 rc.Module.Compiler.Report.SymbolRelatedToPreviousError (fne.Type);
583 rc.Module.Compiler.Report.Error (138, Location,
584 "`{0}' is a type not a namespace. A using namespace directive can only be applied to namespaces",
585 GetSignatureForError ());
590 public override string ToString ()
596 public class UsingAliasEntry {
597 public readonly string Alias;
598 public Location Location;
600 public UsingAliasEntry (string alias, Location loc)
606 public virtual FullNamedExpression Resolve (IMemberContext rc, bool local)
608 FullNamedExpression fne = rc.Module.GetRootNamespace (Alias);
610 rc.Module.Compiler.Report.Error (430, Location,
611 "The extern alias `{0}' was not specified in -reference option",
618 public override string ToString ()
625 class LocalUsingAliasEntry : UsingAliasEntry {
626 FullNamedExpression resolved;
629 public LocalUsingAliasEntry (string alias, MemberName name, Location loc)
635 public override FullNamedExpression Resolve (IMemberContext rc, bool local)
637 if (resolved != null || value == null)
643 resolved = value.GetTypeExpression ().ResolveAsTypeStep (rc, false);
644 if (resolved == null) {
649 if (resolved is TypeExpr)
650 resolved = resolved.ResolveAsTypeTerminal (rc, false);
655 public override string ToString ()
657 return String.Format ("{0} = {1}", Alias, value.GetSignatureForError ());
662 NamespaceEntry parent, implicit_parent;
663 CompilationUnit file;
666 // Namespace using import block
667 List<UsingAliasEntry> using_aliases;
668 List<UsingEntry> using_clauses;
669 public bool DeclarationFound;
672 public readonly bool IsImplicit;
673 public readonly TypeContainer SlaveDeclSpace;
674 static readonly Namespace [] empty_namespaces = new Namespace [0];
675 Namespace [] namespace_using_table;
678 static List<NamespaceEntry> entries = new List<NamespaceEntry> ();
680 public static void Reset ()
682 entries = new List<NamespaceEntry> ();
685 public NamespaceEntry (ModuleContainer ctx, NamespaceEntry parent, CompilationUnit file, string name)
688 this.parent = parent;
693 ns = parent.NS.GetNamespace (name, true);
694 else if (name != null)
695 ns = ctx.GlobalRootNamespace.GetNamespace (name, true);
697 ns = ctx.GlobalRootNamespace;
699 SlaveDeclSpace = new RootDeclSpace (ctx, this);
702 private NamespaceEntry (ModuleContainer ctx, NamespaceEntry parent, CompilationUnit file, Namespace ns, bool slave)
705 this.parent = parent;
707 this.IsImplicit = true;
709 this.SlaveDeclSpace = slave ? new RootDeclSpace (ctx, this) : null;
712 public List<UsingEntry> Usings {
714 return using_clauses;
719 // Extracts the using alises and using clauses into a couple of
720 // arrays that might already have the same information; Used by the
723 public void Extract (List<UsingAliasEntry> out_using_aliases, List<UsingEntry> out_using_clauses)
725 if (using_aliases != null){
726 foreach (UsingAliasEntry uae in using_aliases){
727 bool replaced = false;
729 for (int i = 0; i < out_using_aliases.Count; i++){
730 UsingAliasEntry out_uea = (UsingAliasEntry) out_using_aliases [i];
732 if (out_uea.Alias == uae.Alias){
733 out_using_aliases [i] = uae;
739 out_using_aliases.Add (uae);
743 if (using_clauses != null){
744 foreach (UsingEntry ue in using_clauses){
747 foreach (UsingEntry out_ue in out_using_clauses)
748 if (out_ue.Name == ue.Name){
753 out_using_clauses.Add (ue);
759 // According to section 16.3.1 (using-alias-directive), the namespace-or-type-name is
760 // resolved as if the immediately containing namespace body has no using-directives.
762 // Section 16.3.2 says that the same rule is applied when resolving the namespace-name
763 // in the using-namespace-directive.
765 // To implement these rules, the expressions in the using directives are resolved using
766 // the "doppelganger" (ghostly bodiless duplicate).
768 NamespaceEntry doppelganger;
769 NamespaceEntry Doppelganger {
771 if (!IsImplicit && doppelganger == null) {
772 doppelganger = new NamespaceEntry (ctx, ImplicitParent, file, ns, true);
773 doppelganger.using_aliases = using_aliases;
779 public Namespace NS {
783 public NamespaceEntry Parent {
784 get { return parent; }
787 public NamespaceEntry ImplicitParent {
791 if (implicit_parent == null) {
792 implicit_parent = (parent.NS == ns.Parent)
794 : new NamespaceEntry (ctx, parent, file, ns.Parent, false);
796 return implicit_parent;
801 /// Records a new namespace for resolving name references
803 public void AddUsing (MemberName name, Location loc)
805 if (DeclarationFound){
806 Compiler.Report.Error (1529, loc, "A using clause must precede all other namespace elements except extern alias declarations");
809 if (using_clauses == null) {
810 using_clauses = new List<UsingEntry> ();
812 foreach (UsingEntry old_entry in using_clauses) {
813 if (name.Equals (old_entry.MemberName)) {
814 Compiler.Report.SymbolRelatedToPreviousError (old_entry.Location, old_entry.GetSignatureForError ());
815 Compiler.Report.Warning (105, 3, loc, "The using directive for `{0}' appeared previously in this namespace", name.GetSignatureForError ());
821 using_clauses.Add (new UsingEntry (name));
824 public void AddUsingAlias (string alias, MemberName name, Location loc)
826 // TODO: This is parser bussines
827 if (DeclarationFound){
828 Compiler.Report.Error (1529, loc, "A using clause must precede all other namespace elements except extern alias declarations");
831 AddUsingAlias (new LocalUsingAliasEntry (alias, name, loc));
834 public void AddUsingExternalAlias (string alias, Location loc, Report Report)
836 // TODO: Do this in parser
837 bool not_first = using_clauses != null || DeclarationFound;
838 if (using_aliases != null && !not_first) {
839 foreach (UsingAliasEntry uae in using_aliases) {
840 if (uae is LocalUsingAliasEntry) {
848 Report.Error (439, loc, "An extern alias declaration must precede all other elements");
850 if (alias == "global") {
851 Error_GlobalNamespaceRedefined (loc, Report);
855 AddUsingAlias (new UsingAliasEntry (alias, loc));
858 void AddUsingAlias (UsingAliasEntry uae)
860 if (using_aliases == null) {
861 using_aliases = new List<UsingAliasEntry> ();
863 foreach (UsingAliasEntry entry in using_aliases) {
864 if (uae.Alias == entry.Alias) {
865 Compiler.Report.SymbolRelatedToPreviousError (uae.Location, uae.Alias);
866 Compiler.Report.Error (1537, entry.Location, "The using alias `{0}' appeared previously in this namespace",
873 using_aliases.Add (uae);
877 /// Does extension methods look up to find a method which matches name and extensionType.
878 /// Search starts from this namespace and continues hierarchically up to top level.
880 public IList<MethodSpec> LookupExtensionMethod (TypeSpec extensionType, string name, int arity, ref NamespaceEntry scope)
882 List<MethodSpec> candidates = null;
883 foreach (Namespace n in GetUsingTable ()) {
884 var a = n.LookupExtensionMethod (extensionType, RootContext.ToplevelTypes, name, arity);
888 if (candidates == null)
891 candidates.AddRange (a);
895 if (candidates != null)
902 // Inspect parent namespaces in namespace expression
904 Namespace parent_ns = ns.Parent;
906 candidates = parent_ns.LookupExtensionMethod (extensionType, RootContext.ToplevelTypes, name, arity);
907 if (candidates != null)
910 parent_ns = parent_ns.Parent;
911 } while (parent_ns != null);
914 // Continue in parent scope
916 return parent.LookupExtensionMethod (extensionType, name, arity, ref scope);
919 public FullNamedExpression LookupNamespaceOrType (string name, int arity, Location loc, bool ignore_cs0104)
921 // Precondition: Only simple names (no dots) will be looked up with this function.
922 FullNamedExpression resolved = null;
923 for (NamespaceEntry curr_ns = this; curr_ns != null; curr_ns = curr_ns.ImplicitParent) {
924 if ((resolved = curr_ns.Lookup (name, arity, loc, ignore_cs0104)) != null)
931 public IList<string> CompletionGetTypesStartingWith (string prefix)
933 IEnumerable<string> all = Enumerable.Empty<string> ();
935 for (NamespaceEntry curr_ns = this; curr_ns != null; curr_ns = curr_ns.ImplicitParent){
936 foreach (Namespace using_ns in GetUsingTable ()){
937 if (prefix.StartsWith (using_ns.Name)){
938 int ld = prefix.LastIndexOf ('.');
940 string rest = prefix.Substring (ld+1);
942 all = all.Concat (using_ns.CompletionGetTypesStartingWith (rest));
945 all = all.Concat (using_ns.CompletionGetTypesStartingWith (prefix));
949 return all.Distinct ().ToList ();
952 // Looks-up a alias named @name in this and surrounding namespace declarations
953 public FullNamedExpression LookupNamespaceAlias (string name)
955 for (NamespaceEntry n = this; n != null; n = n.ImplicitParent) {
956 if (n.using_aliases == null)
959 foreach (UsingAliasEntry ue in n.using_aliases) {
960 if (ue.Alias == name)
961 return ue.Resolve (Doppelganger ?? this, Doppelganger == null);
968 private FullNamedExpression Lookup (string name, int arity, Location loc, bool ignore_cs0104)
971 // Check whether it's in the namespace.
973 FullNamedExpression fne = ns.Lookup (this, name, arity, loc);
978 if (using_aliases != null && arity == 0) {
979 foreach (UsingAliasEntry ue in using_aliases) {
980 if (ue.Alias == name) {
982 if (Doppelganger != null) {
983 // TODO: Namespace has broken location
984 //Report.SymbolRelatedToPreviousError (fne.Location, null);
985 Compiler.Report.SymbolRelatedToPreviousError (ue.Location, null);
986 Compiler.Report.Error (576, loc,
987 "Namespace `{0}' contains a definition with same name as alias `{1}'",
988 GetSignatureForError (), name);
994 return ue.Resolve (Doppelganger ?? this, Doppelganger == null);
1000 if (!((fne.Type.Modifiers & Modifiers.INTERNAL) != 0 && !fne.Type.MemberDefinition.IsInternalAsPublic (RootContext.ToplevelTypes.DeclaringAssembly)))
1008 // Check using entries.
1010 FullNamedExpression match = null;
1011 foreach (Namespace using_ns in GetUsingTable ()) {
1012 // A using directive imports only types contained in the namespace, it
1013 // does not import any nested namespaces
1014 fne = using_ns.LookupType (this, name, arity, false, loc);
1018 if (match == null) {
1023 // Prefer types over namespaces
1024 var texpr_fne = fne as TypeExpr;
1025 var texpr_match = match as TypeExpr;
1026 if (texpr_fne != null && texpr_match == null) {
1029 } else if (texpr_fne == null) {
1036 // It can be top level accessibility only
1037 var better = Namespace.IsImportedTypeOverride (texpr_match.Type, texpr_fne.Type);
1038 if (better == null) {
1039 Compiler.Report.SymbolRelatedToPreviousError (texpr_match.Type);
1040 Compiler.Report.SymbolRelatedToPreviousError (texpr_fne.Type);
1041 Compiler.Report.Error (104, loc, "`{0}' is an ambiguous reference between `{1}' and `{2}'",
1042 name, texpr_match.GetSignatureForError (), texpr_fne.GetSignatureForError ());
1046 if (better == texpr_fne.Type)
1053 Namespace [] GetUsingTable ()
1055 if (namespace_using_table != null)
1056 return namespace_using_table;
1058 if (using_clauses == null) {
1059 namespace_using_table = empty_namespaces;
1060 return namespace_using_table;
1063 var list = new List<Namespace> (using_clauses.Count);
1065 foreach (UsingEntry ue in using_clauses) {
1066 Namespace using_ns = ue.Resolve (Doppelganger);
1067 if (using_ns == null)
1070 list.Add (using_ns);
1073 namespace_using_table = list.ToArray ();
1074 return namespace_using_table;
1077 static readonly string [] empty_using_list = new string [0];
1079 public int SymbolFileID {
1081 if (symfile_id == 0 && file.SourceFileEntry != null) {
1082 int parent_id = parent == null ? 0 : parent.SymbolFileID;
1084 string [] using_list = empty_using_list;
1085 if (using_clauses != null) {
1086 using_list = new string [using_clauses.Count];
1087 for (int i = 0; i < using_clauses.Count; i++)
1088 using_list [i] = ((UsingEntry) using_clauses [i]).MemberName.GetName ();
1091 symfile_id = SymbolWriter.DefineNamespace (ns.Name, file.CompileUnitEntry, using_list, parent_id);
1097 static void MsgtryRef (string s)
1099 Console.WriteLine (" Try using -r:" + s);
1102 static void MsgtryPkg (string s)
1104 Console.WriteLine (" Try using -pkg:" + s);
1107 public static void Error_GlobalNamespaceRedefined (Location loc, Report Report)
1109 Report.Error (1681, loc, "The global extern alias cannot be redefined");
1112 public static void Error_NamespaceNotFound (Location loc, string name, Report Report)
1114 Report.Error (246, loc, "The type or namespace name `{0}' could not be found. Are you missing a using directive or an assembly reference?",
1118 case "Gtk": case "GtkSharp":
1119 MsgtryPkg ("gtk-sharp");
1122 case "Gdk": case "GdkSharp":
1123 MsgtryPkg ("gdk-sharp");
1126 case "Glade": case "GladeSharp":
1127 MsgtryPkg ("glade-sharp");
1130 case "System.Drawing":
1131 case "System.Web.Services":
1134 case "System.Windows.Forms":
1141 /// Used to validate that all the using clauses are correct
1142 /// after we are finished parsing all the files.
1146 if (using_aliases != null) {
1147 foreach (UsingAliasEntry ue in using_aliases)
1148 ue.Resolve (Doppelganger, Doppelganger == null);
1151 if (using_clauses != null) {
1152 foreach (UsingEntry ue in using_clauses)
1153 ue.Resolve (Doppelganger);
1158 /// Used to validate that all the using clauses are correct
1159 /// after we are finished parsing all the files.
1161 static public void VerifyAllUsing ()
1163 foreach (NamespaceEntry entry in entries)
1164 entry.VerifyUsing ();
1167 public string GetSignatureForError ()
1169 return ns.GetSignatureForError ();
1172 public override string ToString ()
1174 return ns.ToString ();
1177 #region IMemberContext Members
1179 public CompilerContext Compiler {
1180 get { return ctx.Compiler; }
1183 public TypeSpec CurrentType {
1184 get { return SlaveDeclSpace.CurrentType; }
1187 public MemberCore CurrentMemberDefinition {
1188 get { return SlaveDeclSpace.CurrentMemberDefinition; }
1191 public TypeParameter[] CurrentTypeParameters {
1192 get { return SlaveDeclSpace.CurrentTypeParameters; }
1195 // FIXME: It's false for expression types
1196 public bool HasUnresolvedConstraints {
1197 get { return true; }
1200 public bool IsObsolete {
1201 get { return SlaveDeclSpace.IsObsolete; }
1204 public bool IsUnsafe {
1205 get { return SlaveDeclSpace.IsUnsafe; }
1208 public bool IsStatic {
1209 get { return SlaveDeclSpace.IsStatic; }
1212 public ModuleContainer Module {