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)
471 public void ReplaceTypeWithPredefined (TypeSpec ts, BuildinTypeSpec pts)
473 var found = types [ts.Name];
474 cached_types.Remove (ts.Name);
475 if (found.Count == 1) {
476 types[ts.Name][0] = pts;
478 throw new NotImplementedException ();
482 public void VerifyClsCompliance ()
484 if (types == null || cls_checked)
489 // TODO: This is quite ugly way to check for CLS compliance at namespace level
491 var locase_types = new Dictionary<string, List<TypeSpec>> (StringComparer.OrdinalIgnoreCase);
492 foreach (var tgroup in types.Values) {
493 foreach (var tm in tgroup) {
494 if ((tm.Modifiers & Modifiers.PUBLIC) == 0 || !tm.IsCLSCompliant ())
497 List<TypeSpec> found;
498 if (!locase_types.TryGetValue (tm.Name, out found)) {
499 found = new List<TypeSpec> ();
500 locase_types.Add (tm.Name, found);
507 foreach (var locase in locase_types.Values) {
508 if (locase.Count < 2)
511 bool all_same = true;
512 foreach (var notcompliant in locase) {
513 all_same = notcompliant.Name == locase[0].Name;
521 TypeContainer compiled = null;
522 foreach (var notcompliant in locase) {
523 if (!notcompliant.MemberDefinition.IsImported) {
524 if (compiled != null)
525 compiled.Compiler.Report.SymbolRelatedToPreviousError (compiled);
527 compiled = notcompliant.MemberDefinition as TypeContainer;
529 compiled.Compiler.Report.SymbolRelatedToPreviousError (notcompliant);
533 compiled.Compiler.Report.Warning (3005, 1, compiled.Location,
534 "Identifier `{0}' differing only in case is not CLS-compliant", compiled.GetSignatureForError ());
540 // Namespace container as created by the parser
542 public class NamespaceEntry : IMemberContext {
544 public class UsingEntry {
545 readonly MemberName name;
548 public UsingEntry (MemberName name)
553 public string GetSignatureForError ()
555 return name.GetSignatureForError ();
558 public Location Location {
559 get { return name.Location; }
562 public MemberName MemberName {
567 get { return GetSignatureForError (); }
570 public Namespace Resolve (IMemberContext rc)
572 if (resolved != null)
575 FullNamedExpression fne = name.GetTypeExpression ().ResolveAsTypeStep (rc, false);
579 resolved = fne as Namespace;
580 if (resolved == null) {
581 rc.Module.Compiler.Report.SymbolRelatedToPreviousError (fne.Type);
582 rc.Module.Compiler.Report.Error (138, Location,
583 "`{0}' is a type not a namespace. A using namespace directive can only be applied to namespaces",
584 GetSignatureForError ());
589 public override string ToString ()
595 public class UsingAliasEntry {
596 public readonly string Alias;
597 public Location Location;
599 public UsingAliasEntry (string alias, Location loc)
605 public virtual FullNamedExpression Resolve (IMemberContext rc, bool local)
607 FullNamedExpression fne = rc.Module.GetRootNamespace (Alias);
609 rc.Module.Compiler.Report.Error (430, Location,
610 "The extern alias `{0}' was not specified in -reference option",
617 public override string ToString ()
624 class LocalUsingAliasEntry : UsingAliasEntry {
625 FullNamedExpression resolved;
628 public LocalUsingAliasEntry (string alias, MemberName name, Location loc)
634 public override FullNamedExpression Resolve (IMemberContext rc, bool local)
636 if (resolved != null || value == null)
642 resolved = value.GetTypeExpression ().ResolveAsTypeStep (rc, false);
643 if (resolved == null) {
648 if (resolved is TypeExpr)
649 resolved = resolved.ResolveAsTypeTerminal (rc, false);
654 public override string ToString ()
656 return String.Format ("{0} = {1}", Alias, value.GetSignatureForError ());
661 NamespaceEntry parent, implicit_parent;
662 CompilationUnit file;
665 // Namespace using import block
666 List<UsingAliasEntry> using_aliases;
667 List<UsingEntry> using_clauses;
668 public bool DeclarationFound;
671 public readonly bool IsImplicit;
672 public readonly DeclSpace SlaveDeclSpace;
673 static readonly Namespace [] empty_namespaces = new Namespace [0];
674 Namespace [] namespace_using_table;
677 static List<NamespaceEntry> entries = new List<NamespaceEntry> ();
679 public static void Reset ()
681 entries = new List<NamespaceEntry> ();
684 public NamespaceEntry (ModuleContainer ctx, NamespaceEntry parent, CompilationUnit file, string name)
687 this.parent = parent;
692 ns = parent.NS.GetNamespace (name, true);
693 else if (name != null)
694 ns = ctx.GlobalRootNamespace.GetNamespace (name, true);
696 ns = ctx.GlobalRootNamespace;
698 SlaveDeclSpace = new RootDeclSpace (this);
701 private NamespaceEntry (ModuleContainer ctx, NamespaceEntry parent, CompilationUnit file, Namespace ns, bool slave)
704 this.parent = parent;
706 this.IsImplicit = true;
708 this.SlaveDeclSpace = slave ? new RootDeclSpace (this) : null;
712 // Populates the Namespace with some using declarations, used by the
715 public void Populate (List<UsingAliasEntry> source_using_aliases, List<UsingEntry> source_using_clauses)
717 foreach (UsingAliasEntry uae in source_using_aliases){
718 if (using_aliases == null)
719 using_aliases = new List<UsingAliasEntry> ();
721 using_aliases.Add (uae);
724 foreach (UsingEntry ue in source_using_clauses){
725 if (using_clauses == null)
726 using_clauses = new List<UsingEntry> ();
728 using_clauses.Add (ue);
733 // Extracts the using alises and using clauses into a couple of
734 // arrays that might already have the same information; Used by the
737 public void Extract (List<UsingAliasEntry> out_using_aliases, List<UsingEntry> out_using_clauses)
739 if (using_aliases != null){
740 foreach (UsingAliasEntry uae in using_aliases){
741 bool replaced = false;
743 for (int i = 0; i < out_using_aliases.Count; i++){
744 UsingAliasEntry out_uea = (UsingAliasEntry) out_using_aliases [i];
746 if (out_uea.Alias == uae.Alias){
747 out_using_aliases [i] = uae;
753 out_using_aliases.Add (uae);
757 if (using_clauses != null){
758 foreach (UsingEntry ue in using_clauses){
761 foreach (UsingEntry out_ue in out_using_clauses)
762 if (out_ue.Name == ue.Name){
767 out_using_clauses.Add (ue);
773 // According to section 16.3.1 (using-alias-directive), the namespace-or-type-name is
774 // resolved as if the immediately containing namespace body has no using-directives.
776 // Section 16.3.2 says that the same rule is applied when resolving the namespace-name
777 // in the using-namespace-directive.
779 // To implement these rules, the expressions in the using directives are resolved using
780 // the "doppelganger" (ghostly bodiless duplicate).
782 NamespaceEntry doppelganger;
783 NamespaceEntry Doppelganger {
785 if (!IsImplicit && doppelganger == null) {
786 doppelganger = new NamespaceEntry (ctx, ImplicitParent, file, ns, true);
787 doppelganger.using_aliases = using_aliases;
793 public Namespace NS {
797 public NamespaceEntry Parent {
798 get { return parent; }
801 public NamespaceEntry ImplicitParent {
805 if (implicit_parent == null) {
806 implicit_parent = (parent.NS == ns.Parent)
808 : new NamespaceEntry (ctx, parent, file, ns.Parent, false);
810 return implicit_parent;
815 /// Records a new namespace for resolving name references
817 public void AddUsing (MemberName name, Location loc)
819 if (DeclarationFound){
820 Compiler.Report.Error (1529, loc, "A using clause must precede all other namespace elements except extern alias declarations");
823 if (using_clauses == null) {
824 using_clauses = new List<UsingEntry> ();
826 foreach (UsingEntry old_entry in using_clauses) {
827 if (name.Equals (old_entry.MemberName)) {
828 Compiler.Report.SymbolRelatedToPreviousError (old_entry.Location, old_entry.GetSignatureForError ());
829 Compiler.Report.Warning (105, 3, loc, "The using directive for `{0}' appeared previously in this namespace", name.GetSignatureForError ());
835 using_clauses.Add (new UsingEntry (name));
838 public void AddUsingAlias (string alias, MemberName name, Location loc)
840 // TODO: This is parser bussines
841 if (DeclarationFound){
842 Compiler.Report.Error (1529, loc, "A using clause must precede all other namespace elements except extern alias declarations");
845 if (RootContext.Version != LanguageVersion.ISO_1 && alias == "global")
846 Compiler.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 AddUsingAlias (new LocalUsingAliasEntry (alias, name, loc));
852 public void AddUsingExternalAlias (string alias, Location loc, Report Report)
854 // TODO: Do this in parser
855 bool not_first = using_clauses != null || DeclarationFound;
856 if (using_aliases != null && !not_first) {
857 foreach (UsingAliasEntry uae in using_aliases) {
858 if (uae is LocalUsingAliasEntry) {
866 Report.Error (439, loc, "An extern alias declaration must precede all other elements");
868 if (alias == "global") {
869 Error_GlobalNamespaceRedefined (loc, Report);
873 AddUsingAlias (new UsingAliasEntry (alias, loc));
876 void AddUsingAlias (UsingAliasEntry uae)
878 if (using_aliases == null) {
879 using_aliases = new List<UsingAliasEntry> ();
881 foreach (UsingAliasEntry entry in using_aliases) {
882 if (uae.Alias == entry.Alias) {
883 Compiler.Report.SymbolRelatedToPreviousError (uae.Location, uae.Alias);
884 Compiler.Report.Error (1537, entry.Location, "The using alias `{0}' appeared previously in this namespace",
891 using_aliases.Add (uae);
895 /// Does extension methods look up to find a method which matches name and extensionType.
896 /// Search starts from this namespace and continues hierarchically up to top level.
898 public IList<MethodSpec> LookupExtensionMethod (TypeSpec extensionType, string name, int arity, ref NamespaceEntry scope)
900 List<MethodSpec> candidates = null;
901 foreach (Namespace n in GetUsingTable ()) {
902 var a = n.LookupExtensionMethod (extensionType, RootContext.ToplevelTypes, name, arity);
906 if (candidates == null)
909 candidates.AddRange (a);
913 if (candidates != null)
920 // Inspect parent namespaces in namespace expression
922 Namespace parent_ns = ns.Parent;
924 candidates = parent_ns.LookupExtensionMethod (extensionType, RootContext.ToplevelTypes, name, arity);
925 if (candidates != null)
928 parent_ns = parent_ns.Parent;
929 } while (parent_ns != null);
932 // Continue in parent scope
934 return parent.LookupExtensionMethod (extensionType, name, arity, ref scope);
937 public FullNamedExpression LookupNamespaceOrType (string name, int arity, Location loc, bool ignore_cs0104)
939 // Precondition: Only simple names (no dots) will be looked up with this function.
940 FullNamedExpression resolved = null;
941 for (NamespaceEntry curr_ns = this; curr_ns != null; curr_ns = curr_ns.ImplicitParent) {
942 if ((resolved = curr_ns.Lookup (name, arity, loc, ignore_cs0104)) != null)
949 public IList<string> CompletionGetTypesStartingWith (string prefix)
951 IEnumerable<string> all = Enumerable.Empty<string> ();
953 for (NamespaceEntry curr_ns = this; curr_ns != null; curr_ns = curr_ns.ImplicitParent){
954 foreach (Namespace using_ns in GetUsingTable ()){
955 if (prefix.StartsWith (using_ns.Name)){
956 int ld = prefix.LastIndexOf ('.');
958 string rest = prefix.Substring (ld+1);
960 all = all.Concat (using_ns.CompletionGetTypesStartingWith (rest));
963 all = all.Concat (using_ns.CompletionGetTypesStartingWith (prefix));
967 return all.Distinct ().ToList ();
970 // Looks-up a alias named @name in this and surrounding namespace declarations
971 public FullNamedExpression LookupNamespaceAlias (string name)
973 for (NamespaceEntry n = this; n != null; n = n.ImplicitParent) {
974 if (n.using_aliases == null)
977 foreach (UsingAliasEntry ue in n.using_aliases) {
978 if (ue.Alias == name)
979 return ue.Resolve (Doppelganger ?? this, Doppelganger == null);
986 private FullNamedExpression Lookup (string name, int arity, Location loc, bool ignore_cs0104)
989 // Check whether it's in the namespace.
991 FullNamedExpression fne = ns.Lookup (this, name, arity, loc);
996 if (using_aliases != null && arity == 0) {
997 foreach (UsingAliasEntry ue in using_aliases) {
998 if (ue.Alias == name) {
1000 if (Doppelganger != null) {
1001 // TODO: Namespace has broken location
1002 //Report.SymbolRelatedToPreviousError (fne.Location, null);
1003 Compiler.Report.SymbolRelatedToPreviousError (ue.Location, null);
1004 Compiler.Report.Error (576, loc,
1005 "Namespace `{0}' contains a definition with same name as alias `{1}'",
1006 GetSignatureForError (), name);
1012 return ue.Resolve (Doppelganger ?? this, Doppelganger == null);
1018 if (!((fne.Type.Modifiers & Modifiers.INTERNAL) != 0 && !fne.Type.MemberDefinition.IsInternalAsPublic (RootContext.ToplevelTypes.DeclaringAssembly)))
1026 // Check using entries.
1028 FullNamedExpression match = null;
1029 foreach (Namespace using_ns in GetUsingTable ()) {
1030 // A using directive imports only types contained in the namespace, it
1031 // does not import any nested namespaces
1032 fne = using_ns.LookupType (this, name, arity, false, loc);
1036 if (match == null) {
1041 // Prefer types over namespaces
1042 var texpr_fne = fne as TypeExpr;
1043 var texpr_match = match as TypeExpr;
1044 if (texpr_fne != null && texpr_match == null) {
1047 } else if (texpr_fne == null) {
1054 // It can be top level accessibility only
1055 var better = Namespace.IsImportedTypeOverride (texpr_match.Type, texpr_fne.Type);
1056 if (better == null) {
1057 Compiler.Report.SymbolRelatedToPreviousError (texpr_match.Type);
1058 Compiler.Report.SymbolRelatedToPreviousError (texpr_fne.Type);
1059 Compiler.Report.Error (104, loc, "`{0}' is an ambiguous reference between `{1}' and `{2}'",
1060 name, texpr_match.GetSignatureForError (), texpr_fne.GetSignatureForError ());
1064 if (better == texpr_fne.Type)
1071 Namespace [] GetUsingTable ()
1073 if (namespace_using_table != null)
1074 return namespace_using_table;
1076 if (using_clauses == null) {
1077 namespace_using_table = empty_namespaces;
1078 return namespace_using_table;
1081 var list = new List<Namespace> (using_clauses.Count);
1083 foreach (UsingEntry ue in using_clauses) {
1084 Namespace using_ns = ue.Resolve (Doppelganger);
1085 if (using_ns == null)
1088 list.Add (using_ns);
1091 namespace_using_table = list.ToArray ();
1092 return namespace_using_table;
1095 static readonly string [] empty_using_list = new string [0];
1097 public int SymbolFileID {
1099 if (symfile_id == 0 && file.SourceFileEntry != null) {
1100 int parent_id = parent == null ? 0 : parent.SymbolFileID;
1102 string [] using_list = empty_using_list;
1103 if (using_clauses != null) {
1104 using_list = new string [using_clauses.Count];
1105 for (int i = 0; i < using_clauses.Count; i++)
1106 using_list [i] = ((UsingEntry) using_clauses [i]).MemberName.GetName ();
1109 symfile_id = SymbolWriter.DefineNamespace (ns.Name, file.CompileUnitEntry, using_list, parent_id);
1115 static void MsgtryRef (string s)
1117 Console.WriteLine (" Try using -r:" + s);
1120 static void MsgtryPkg (string s)
1122 Console.WriteLine (" Try using -pkg:" + s);
1125 public static void Error_GlobalNamespaceRedefined (Location loc, Report Report)
1127 Report.Error (1681, loc, "The global extern alias cannot be redefined");
1130 public static void Error_NamespaceNotFound (Location loc, string name, Report Report)
1132 Report.Error (246, loc, "The type or namespace name `{0}' could not be found. Are you missing a using directive or an assembly reference?",
1136 case "Gtk": case "GtkSharp":
1137 MsgtryPkg ("gtk-sharp");
1140 case "Gdk": case "GdkSharp":
1141 MsgtryPkg ("gdk-sharp");
1144 case "Glade": case "GladeSharp":
1145 MsgtryPkg ("glade-sharp");
1148 case "System.Drawing":
1149 case "System.Web.Services":
1152 case "System.Windows.Forms":
1159 /// Used to validate that all the using clauses are correct
1160 /// after we are finished parsing all the files.
1164 if (using_aliases != null) {
1165 foreach (UsingAliasEntry ue in using_aliases)
1166 ue.Resolve (Doppelganger, Doppelganger == null);
1169 if (using_clauses != null) {
1170 foreach (UsingEntry ue in using_clauses)
1171 ue.Resolve (Doppelganger);
1176 /// Used to validate that all the using clauses are correct
1177 /// after we are finished parsing all the files.
1179 static public void VerifyAllUsing ()
1181 foreach (NamespaceEntry entry in entries)
1182 entry.VerifyUsing ();
1185 public string GetSignatureForError ()
1187 return ns.GetSignatureForError ();
1190 public override string ToString ()
1192 return ns.ToString ();
1195 #region IMemberContext Members
1197 public CompilerContext Compiler {
1198 get { return ctx.Compiler; }
1201 public TypeSpec CurrentType {
1202 get { return SlaveDeclSpace.CurrentType; }
1205 public MemberCore CurrentMemberDefinition {
1206 get { return SlaveDeclSpace.CurrentMemberDefinition; }
1209 public TypeParameter[] CurrentTypeParameters {
1210 get { return SlaveDeclSpace.CurrentTypeParameters; }
1213 // FIXME: It's false for expression types
1214 public bool HasUnresolvedConstraints {
1215 get { return true; }
1218 public bool IsObsolete {
1219 get { return SlaveDeclSpace.IsObsolete; }
1222 public bool IsUnsafe {
1223 get { return SlaveDeclSpace.IsUnsafe; }
1226 public bool IsStatic {
1227 get { return SlaveDeclSpace.IsStatic; }
1230 public ModuleContainer Module {