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 ()
69 // Namespace cache for imported and compiled namespaces
71 // This is an Expression to allow it to be referenced in the
72 // compiler parse/intermediate tree during name resolution.
74 public class Namespace : FullNamedExpression
78 protected Dictionary<string, Namespace> namespaces;
79 protected Dictionary<string, IList<TypeSpec>> types;
80 Dictionary<string, TypeExpr> cached_types;
84 public readonly MemberName MemberName;
87 /// Constructor Takes the current namespace and the
88 /// name. This is bootstrapped with parent == null
91 public Namespace (Namespace parent, string name)
93 // Expression members.
94 this.eclass = ExprClass.Namespace;
95 this.Type = InternalType.Namespace;
96 this.loc = Location.Null;
101 this.root = parent.root;
103 this.root = this as RootNamespace;
105 if (this.root == null)
106 throw new InternalErrorException ("Root namespaces must be created using RootNamespace");
108 string pname = parent != null ? parent.fullname : "";
113 fullname = parent.fullname + "." + name;
115 if (fullname == null)
116 throw new InternalErrorException ("Namespace has a null fullname");
118 if (parent != null && parent.MemberName != MemberName.Null)
119 MemberName = new MemberName (parent.MemberName, name);
120 else if (name.Length == 0)
121 MemberName = MemberName.Null;
123 MemberName = new MemberName (name);
125 namespaces = new Dictionary<string, Namespace> ();
126 cached_types = new Dictionary<string, TypeExpr> ();
128 root.RegisterNamespace (this);
134 /// The qualified name of the current namespace
137 get { return fullname; }
141 /// The parent of this namespace, used by the parser to "Pop"
142 /// the current namespace declaration
144 public Namespace Parent {
145 get { return parent; }
150 protected override Expression DoResolve (ResolveContext ec)
155 public void Error_NamespaceDoesNotExist (IMemberContext ctx, string name, int arity, Location loc)
157 var retval = LookupType (ctx, name, arity, LookupMode.IgnoreAccessibility, loc);
158 if (retval != null) {
159 ctx.Module.Compiler.Report.SymbolRelatedToPreviousError (retval.Type);
160 ErrorIsInaccesible (ctx, retval.GetSignatureForError (), loc);
164 retval = LookupType (ctx, name, -System.Math.Max (1, arity), LookupMode.Probing, loc);
165 if (retval != null) {
166 Error_TypeArgumentsCannotBeUsed (ctx, retval.Type, arity, loc);
171 if (arity > 0 && namespaces.TryGetValue (name, out ns)) {
172 ns.Error_TypeArgumentsCannotBeUsed (ctx, null, arity, loc);
176 if (this is GlobalRootNamespace) {
177 ctx.Module.Compiler.Report.Error (400, loc,
178 "The type or namespace name `{0}' could not be found in the global namespace (are you missing an assembly reference?)",
181 ctx.Module.Compiler.Report.Error (234, loc,
182 "The type or namespace name `{0}' does not exist in the namespace `{1}'. Are you missing an assembly reference?",
183 name, GetSignatureForError ());
187 public override string GetSignatureForError ()
192 public Namespace GetNamespace (string name, bool create)
194 int pos = name.IndexOf ('.');
199 first = name.Substring (0, pos);
203 if (!namespaces.TryGetValue (first, out ns)) {
207 ns = new Namespace (this, first);
208 namespaces.Add (first, ns);
212 ns = ns.GetNamespace (name.Substring (pos + 1), create);
217 public IList<TypeSpec> GetAllTypes (string name)
219 IList<TypeSpec> found;
220 if (types == null || !types.TryGetValue (name, out found))
226 public TypeExpr LookupType (IMemberContext ctx, string name, int arity, LookupMode mode, Location loc)
232 if (arity == 0 && cached_types.TryGetValue (name, out te))
235 IList<TypeSpec> found;
236 if (!types.TryGetValue (name, out found))
239 TypeSpec best = null;
240 foreach (var ts in found) {
241 if (ts.Arity == arity) {
243 if ((ts.Modifiers & Modifiers.INTERNAL) != 0 && !ts.MemberDefinition.IsInternalAsPublic (ctx.Module.DeclaringAssembly) && mode != LookupMode.IgnoreAccessibility)
250 if (best.MemberDefinition.IsImported && ts.MemberDefinition.IsImported) {
251 if (mode == LookupMode.Normal) {
252 ctx.Module.Compiler.Report.SymbolRelatedToPreviousError (best);
253 ctx.Module.Compiler.Report.SymbolRelatedToPreviousError (ts);
254 ctx.Module.Compiler.Report.Error (433, loc, "The imported type `{0}' is defined multiple times", ts.GetSignatureForError ());
259 if (best.MemberDefinition.IsImported)
262 if ((best.Modifiers & Modifiers.INTERNAL) != 0 && !best.MemberDefinition.IsInternalAsPublic (ctx.Module.DeclaringAssembly))
265 if (mode != LookupMode.Normal)
268 if (ts.MemberDefinition.IsImported)
269 ctx.Module.Compiler.Report.SymbolRelatedToPreviousError (ts);
271 ctx.Module.Compiler.Report.Warning (436, 2, loc,
272 "The type `{0}' conflicts with the imported type of same name'. Ignoring the imported type definition",
273 best.GetSignatureForError ());
277 // Lookup for the best candidate with the closest arity match
282 } else if (System.Math.Abs (ts.Arity + arity) < System.Math.Abs (best.Arity + arity)) {
291 te = new TypeExpression (best, Location.Null);
293 // TODO MemberCache: Cache more
294 if (arity == 0 && mode == LookupMode.Normal)
295 cached_types.Add (name, te);
300 TypeSpec LookupType (string name, int arity)
305 IList<TypeSpec> found;
306 if (types.TryGetValue (name, out found)) {
307 TypeSpec best = null;
309 foreach (var ts in found) {
310 if (ts.Arity == arity)
314 // Lookup for the best candidate with closest arity match
319 } else if (System.Math.Abs (ts.Arity + arity) < System.Math.Abs (best.Arity + arity)) {
331 public FullNamedExpression LookupTypeOrNamespace (IMemberContext ctx, string name, int arity, LookupMode mode, Location loc)
333 var texpr = LookupType (ctx, name, arity, mode, loc);
336 if (arity == 0 && namespaces.TryGetValue (name, out ns)) {
340 if (mode != LookupMode.Probing) {
341 ctx.Module.Compiler.Report.SymbolRelatedToPreviousError (texpr.Type);
342 // ctx.Module.Compiler.Report.SymbolRelatedToPreviousError (ns.loc, "");
343 ctx.Module.Compiler.Report.Warning (437, 2, loc,
344 "The type `{0}' conflicts with the imported namespace `{1}'. Using the definition found in the source file",
345 texpr.GetSignatureForError (), ns.GetSignatureForError ());
348 if (texpr.Type.MemberDefinition.IsImported)
356 // Completes types with the given `prefix'
358 public IEnumerable<string> CompletionGetTypesStartingWith (string prefix)
361 return Enumerable.Empty<string> ();
363 var res = from item in types
364 where item.Key.StartsWith (prefix) && item.Value.Any (l => (l.Modifiers & Modifiers.PUBLIC) != 0)
367 if (namespaces != null)
368 res = res.Concat (from item in namespaces where item.Key.StartsWith (prefix) select item.Key);
374 // Looks for extension method in this namespace
376 public List<MethodSpec> LookupExtensionMethod (IMemberContext invocationContext, TypeSpec extensionType, string name, int arity)
381 List<MethodSpec> found = null;
383 // TODO: Add per namespace flag when at least 1 type has extension
385 foreach (var tgroup in types.Values) {
386 foreach (var ts in tgroup) {
387 if ((ts.Modifiers & Modifiers.METHOD_EXTENSION) == 0)
390 var res = ts.MemberCache.FindExtensionMethods (invocationContext, extensionType, name, arity);
397 found.AddRange (res);
406 // Extension methods look up for dotted namespace names
408 public IList<MethodSpec> LookupExtensionMethod (IMemberContext invocationContext, TypeSpec extensionType, string name, int arity, out Namespace scope)
411 // Inspect parent namespaces in namespace expression
415 var candidates = scope.LookupExtensionMethod (invocationContext, extensionType, name, arity);
416 if (candidates != null)
419 scope = scope.Parent;
420 } while (scope != null);
425 public void AddType (ModuleContainer module, TypeSpec ts)
428 types = new Dictionary<string, IList<TypeSpec>> (64);
432 IList<TypeSpec> existing;
433 if (types.TryGetValue (name, out existing)) {
434 TypeSpec better_type;
436 if (existing.Count == 1) {
438 if (ts.Arity == found.Arity) {
439 better_type = IsImportedTypeOverride (module, ts, found);
440 if (better_type == found)
443 if (better_type != null) {
444 existing [0] = better_type;
449 existing = new List<TypeSpec> ();
450 existing.Add (found);
451 types[name] = existing;
453 for (int i = 0; i < existing.Count; ++i) {
455 if (ts.Arity != found.Arity)
458 better_type = IsImportedTypeOverride (module, ts, found);
459 if (better_type == found)
462 if (better_type != null) {
463 existing.RemoveAt (i);
472 types.Add (name, new TypeSpec[] { ts });
477 // We import any types but in the situation there are same types
478 // but one has better visibility (either public or internal with friend)
479 // the less visible type is removed from the namespace cache
481 public static TypeSpec IsImportedTypeOverride (ModuleContainer module, TypeSpec ts, TypeSpec found)
483 var ts_accessible = (ts.Modifiers & Modifiers.PUBLIC) != 0 || ts.MemberDefinition.IsInternalAsPublic (module.DeclaringAssembly);
484 var found_accessible = (found.Modifiers & Modifiers.PUBLIC) != 0 || found.MemberDefinition.IsInternalAsPublic (module.DeclaringAssembly);
486 if (ts_accessible && !found_accessible)
489 // found is better always better for accessible or inaccessible ts
496 public void RemoveDeclSpace (string name)
499 cached_types.Remove (name);
502 public override FullNamedExpression ResolveAsTypeOrNamespace (IMemberContext mc)
507 public void SetBuiltinType (BuiltinTypeSpec pts)
509 var found = types[pts.Name];
510 cached_types.Remove (pts.Name);
511 if (found.Count == 1) {
512 types[pts.Name][0] = pts;
514 throw new NotImplementedException ();
518 public void VerifyClsCompliance ()
520 if (types == null || cls_checked)
525 // TODO: This is quite ugly way to check for CLS compliance at namespace level
527 var locase_types = new Dictionary<string, List<TypeSpec>> (StringComparer.OrdinalIgnoreCase);
528 foreach (var tgroup in types.Values) {
529 foreach (var tm in tgroup) {
530 if ((tm.Modifiers & Modifiers.PUBLIC) == 0 || !tm.IsCLSCompliant ())
533 List<TypeSpec> found;
534 if (!locase_types.TryGetValue (tm.Name, out found)) {
535 found = new List<TypeSpec> ();
536 locase_types.Add (tm.Name, found);
543 foreach (var locase in locase_types.Values) {
544 if (locase.Count < 2)
547 bool all_same = true;
548 foreach (var notcompliant in locase) {
549 all_same = notcompliant.Name == locase[0].Name;
557 TypeContainer compiled = null;
558 foreach (var notcompliant in locase) {
559 if (!notcompliant.MemberDefinition.IsImported) {
560 if (compiled != null)
561 compiled.Compiler.Report.SymbolRelatedToPreviousError (compiled);
563 compiled = notcompliant.MemberDefinition as TypeContainer;
565 compiled.Compiler.Report.SymbolRelatedToPreviousError (notcompliant);
569 compiled.Compiler.Report.Warning (3005, 1, compiled.Location,
570 "Identifier `{0}' differing only in case is not CLS-compliant", compiled.GetSignatureForError ());
576 // Namespace block as created by the parser
578 public class NamespaceContainer : IMemberContext, ITypesContainer
582 readonly ModuleContainer module;
583 readonly NamespaceContainer parent;
584 readonly CompilationSourceFile file;
585 readonly Location loc;
587 NamespaceContainer implicit_parent;
590 // Namespace using import block
591 List<NamespaceUsingAlias> using_aliases;
592 List<NamespaceUsing> using_clauses;
593 public bool DeclarationFound;
598 public readonly bool IsImplicit;
599 public readonly TypeContainer SlaveDeclSpace;
600 static readonly Namespace [] empty_namespaces = new Namespace [0];
601 static readonly string[] empty_using_list = new string[0];
603 Namespace [] namespace_using_table;
605 public NamespaceContainer (MemberName name, ModuleContainer module, NamespaceContainer parent, CompilationSourceFile sourceFile)
607 this.module = module;
608 this.parent = parent;
609 this.file = sourceFile;
610 this.loc = name == null ? Location.Null : name.Location;
613 ns = parent.NS.GetNamespace (name.GetName (), true);
614 else if (name != null)
615 ns = module.GlobalRootNamespace.GetNamespace (name.GetName (), true);
617 ns = module.GlobalRootNamespace;
619 SlaveDeclSpace = new RootDeclSpace (module, this);
622 private NamespaceContainer (ModuleContainer module, NamespaceContainer parent, CompilationSourceFile file, Namespace ns, bool slave)
624 this.module = module;
625 this.parent = parent;
627 this.IsImplicit = true;
629 this.SlaveDeclSpace = slave ? new RootDeclSpace (module, this) : null;
634 public Location Location {
640 public MemberName MemberName {
642 return ns.MemberName;
646 public CompilationSourceFile SourceFile {
652 public List<NamespaceUsing> Usings {
654 return using_clauses;
661 // Extracts the using alises and using clauses into a couple of
662 // arrays that might already have the same information; Used by the
665 public void Extract (List<NamespaceUsingAlias> out_using_aliases, List<NamespaceUsing> out_using_clauses)
667 if (using_aliases != null){
668 foreach (NamespaceUsingAlias uae in using_aliases){
669 bool replaced = false;
671 for (int i = 0; i < out_using_aliases.Count; i++){
672 NamespaceUsingAlias out_uea = (NamespaceUsingAlias) out_using_aliases [i];
674 if (out_uea.Alias == uae.Alias){
675 out_using_aliases [i] = uae;
681 out_using_aliases.Add (uae);
685 if (using_clauses != null){
686 foreach (NamespaceUsing ue in using_clauses){
689 foreach (NamespaceUsing out_ue in out_using_clauses)
690 if (out_ue.Name == ue.Name){
695 out_using_clauses.Add (ue);
701 // According to section 16.3.1 (using-alias-directive), the namespace-or-type-name is
702 // resolved as if the immediately containing namespace body has no using-directives.
704 // Section 16.3.2 says that the same rule is applied when resolving the namespace-name
705 // in the using-namespace-directive.
707 // To implement these rules, the expressions in the using directives are resolved using
708 // the "doppelganger" (ghostly bodiless duplicate).
710 NamespaceContainer doppelganger;
711 NamespaceContainer Doppelganger {
713 if (!IsImplicit && doppelganger == null) {
714 doppelganger = new NamespaceContainer (module, ImplicitParent, file, ns, true);
715 doppelganger.using_aliases = using_aliases;
721 public Namespace NS {
725 public NamespaceContainer Parent {
726 get { return parent; }
729 public NamespaceContainer ImplicitParent {
733 if (implicit_parent == null) {
734 implicit_parent = (parent.NS == ns.Parent)
736 : new NamespaceContainer (module, parent, file, ns.Parent, false);
738 return implicit_parent;
743 /// Records a new namespace for resolving name references
745 public void AddUsing (MemberName name, Location loc)
747 if (DeclarationFound){
748 Compiler.Report.Error (1529, loc, "A using clause must precede all other namespace elements except extern alias declarations");
751 if (using_clauses == null) {
752 using_clauses = new List<NamespaceUsing> ();
754 foreach (NamespaceUsing old_entry in using_clauses) {
755 if (name.Equals (old_entry.MemberName)) {
756 Compiler.Report.SymbolRelatedToPreviousError (old_entry.Location, old_entry.GetSignatureForError ());
757 Compiler.Report.Warning (105, 3, loc, "The using directive for `{0}' appeared previously in this namespace", name.GetSignatureForError ());
763 using_clauses.Add (new NamespaceUsing (name));
766 public void AddUsingAlias (string alias, MemberName name, Location loc)
768 if (DeclarationFound){
769 Compiler.Report.Error (1529, loc, "A using clause must precede all other namespace elements except extern alias declarations");
772 AddUsingAlias (new LocalUsingAliasEntry (alias, name, loc));
775 public void AddUsingExternalAlias (string alias, Location loc, Report Report)
777 bool not_first = using_clauses != null || DeclarationFound;
778 if (using_aliases != null && !not_first) {
779 foreach (NamespaceUsingAlias uae in using_aliases) {
780 if (uae is LocalUsingAliasEntry) {
788 Report.Error (439, loc, "An extern alias declaration must precede all other elements");
790 if (alias == "global") {
791 Error_GlobalNamespaceRedefined (loc, Report);
795 AddUsingAlias (new NamespaceUsingAlias (alias, loc));
798 void AddUsingAlias (NamespaceUsingAlias uae)
800 if (using_aliases == null) {
801 using_aliases = new List<NamespaceUsingAlias> ();
803 foreach (NamespaceUsingAlias entry in using_aliases) {
804 if (uae.Alias == entry.Alias) {
805 Compiler.Report.SymbolRelatedToPreviousError (uae.Location, uae.Alias);
806 Compiler.Report.Error (1537, entry.Location, "The using alias `{0}' appeared previously in this namespace",
813 using_aliases.Add (uae);
817 // Does extension methods look up to find a method which matches name and extensionType.
818 // Search starts from this namespace and continues hierarchically up to top level.
820 public ExtensionMethodCandidates LookupExtensionMethod (TypeSpec extensionType, string name, int arity)
822 List<MethodSpec> candidates = null;
823 foreach (Namespace n in GetUsingTable ()) {
824 var a = n.LookupExtensionMethod (this, extensionType, name, arity);
828 if (candidates == null)
831 candidates.AddRange (a);
834 if (candidates != null)
835 return new ExtensionMethodCandidates (candidates, this);
841 var ns_candidates = ns.Parent.LookupExtensionMethod (this, extensionType, name, arity, out ns_scope);
842 if (ns_candidates != null)
843 return new ExtensionMethodCandidates (ns_candidates, this, ns_scope);
846 // Continue in parent container
848 return parent.LookupExtensionMethod (extensionType, name, arity);
851 public FullNamedExpression LookupNamespaceOrType (string name, int arity, LookupMode mode, Location loc)
853 // Precondition: Only simple names (no dots) will be looked up with this function.
854 FullNamedExpression resolved = null;
855 for (NamespaceContainer curr_ns = this; curr_ns != null; curr_ns = curr_ns.ImplicitParent) {
856 if ((resolved = curr_ns.Lookup (name, arity, mode, loc)) != null)
863 public IList<string> CompletionGetTypesStartingWith (string prefix)
865 IEnumerable<string> all = Enumerable.Empty<string> ();
867 for (NamespaceContainer curr_ns = this; curr_ns != null; curr_ns = curr_ns.ImplicitParent){
868 foreach (Namespace using_ns in GetUsingTable ()){
869 if (prefix.StartsWith (using_ns.Name)){
870 int ld = prefix.LastIndexOf ('.');
872 string rest = prefix.Substring (ld+1);
874 all = all.Concat (using_ns.CompletionGetTypesStartingWith (rest));
877 all = all.Concat (using_ns.CompletionGetTypesStartingWith (prefix));
881 return all.Distinct ().ToList ();
884 // Looks-up a alias named @name in this and surrounding namespace declarations
885 public FullNamedExpression LookupNamespaceAlias (string name)
887 for (NamespaceContainer n = this; n != null; n = n.ImplicitParent) {
888 if (n.using_aliases == null)
891 foreach (NamespaceUsingAlias ue in n.using_aliases) {
892 if (ue.Alias == name)
893 return ue.Resolve (Doppelganger ?? this, Doppelganger == null);
900 FullNamedExpression Lookup (string name, int arity, LookupMode mode, Location loc)
903 // Check whether it's in the namespace.
905 FullNamedExpression fne = ns.LookupTypeOrNamespace (this, name, arity, mode, loc);
910 if (using_aliases != null && arity == 0) {
911 foreach (NamespaceUsingAlias ue in using_aliases) {
912 if (ue.Alias == name) {
914 if (Doppelganger != null) {
915 if (mode == LookupMode.Normal) {
916 // TODO: Namespace has broken location
917 //Report.SymbolRelatedToPreviousError (fne.Location, null);
918 Compiler.Report.SymbolRelatedToPreviousError (ue.Location, null);
919 Compiler.Report.Error (576, loc,
920 "Namespace `{0}' contains a definition with same name as alias `{1}'",
921 GetSignatureForError (), name);
928 return ue.Resolve (Doppelganger ?? this, Doppelganger == null);
940 // Check using entries.
942 FullNamedExpression match = null;
943 foreach (Namespace using_ns in GetUsingTable ()) {
944 // A using directive imports only types contained in the namespace, it
945 // does not import any nested namespaces
946 fne = using_ns.LookupType (this, name, arity, mode, loc);
955 // Prefer types over namespaces
956 var texpr_fne = fne as TypeExpr;
957 var texpr_match = match as TypeExpr;
958 if (texpr_fne != null && texpr_match == null) {
961 } else if (texpr_fne == null) {
965 // It can be top level accessibility only
966 var better = Namespace.IsImportedTypeOverride (module, texpr_match.Type, texpr_fne.Type);
967 if (better == null) {
968 if (mode == LookupMode.Normal) {
969 Compiler.Report.SymbolRelatedToPreviousError (texpr_match.Type);
970 Compiler.Report.SymbolRelatedToPreviousError (texpr_fne.Type);
971 Compiler.Report.Error (104, loc, "`{0}' is an ambiguous reference between `{1}' and `{2}'",
972 name, texpr_match.GetSignatureForError (), texpr_fne.GetSignatureForError ());
978 if (better == texpr_fne.Type)
985 Namespace [] GetUsingTable ()
987 if (namespace_using_table != null)
988 return namespace_using_table;
990 if (using_clauses == null) {
991 namespace_using_table = empty_namespaces;
992 return namespace_using_table;
995 var list = new List<Namespace> (using_clauses.Count);
997 foreach (NamespaceUsing ue in using_clauses) {
998 Namespace using_ns = ue.Resolve (Doppelganger);
999 if (using_ns == null)
1002 list.Add (using_ns);
1005 namespace_using_table = list.ToArray ();
1006 return namespace_using_table;
1009 public int SymbolFileID {
1011 if (symfile_id == 0 && file.SourceFileEntry != null) {
1012 int parent_id = parent == null ? 0 : parent.SymbolFileID;
1014 string [] using_list = empty_using_list;
1015 if (using_clauses != null) {
1016 using_list = new string [using_clauses.Count];
1017 for (int i = 0; i < using_clauses.Count; i++)
1018 using_list [i] = ((NamespaceUsing) using_clauses [i]).MemberName.GetName ();
1021 symfile_id = SymbolWriter.DefineNamespace (ns.Name, file.CompileUnitEntry, using_list, parent_id);
1027 static void MsgtryRef (string s)
1029 Console.WriteLine (" Try using -r:" + s);
1032 static void MsgtryPkg (string s)
1034 Console.WriteLine (" Try using -pkg:" + s);
1037 public static void Error_GlobalNamespaceRedefined (Location loc, Report Report)
1039 Report.Error (1681, loc, "The global extern alias cannot be redefined");
1042 public static void Error_NamespaceNotFound (Location loc, string name, Report Report)
1044 Report.Error (246, loc, "The type or namespace name `{0}' could not be found. Are you missing a using directive or an assembly reference?",
1048 case "Gtk": case "GtkSharp":
1049 MsgtryPkg ("gtk-sharp-2.0");
1052 case "Gdk": case "GdkSharp":
1053 MsgtryPkg ("gdk-sharp-2.0");
1056 case "Glade": case "GladeSharp":
1057 MsgtryPkg ("glade-sharp-2.0");
1060 case "System.Drawing":
1061 case "System.Web.Services":
1064 case "System.Windows.Forms":
1071 /// Used to validate that all the using clauses are correct
1072 /// after we are finished parsing all the files.
1074 public void Resolve ()
1081 if (using_aliases != null) {
1082 foreach (NamespaceUsingAlias ue in using_aliases)
1083 ue.Resolve (Doppelganger, Doppelganger == null);
1086 if (using_clauses != null) {
1087 foreach (NamespaceUsing ue in using_clauses)
1088 ue.Resolve (Doppelganger);
1095 public string GetSignatureForError ()
1097 return ns.GetSignatureForError ();
1100 #region IMemberContext Members
1102 CompilerContext Compiler {
1103 get { return module.Compiler; }
1106 public TypeSpec CurrentType {
1107 get { return SlaveDeclSpace.CurrentType; }
1110 public MemberCore CurrentMemberDefinition {
1111 get { return SlaveDeclSpace.CurrentMemberDefinition; }
1114 public TypeParameter[] CurrentTypeParameters {
1115 get { return SlaveDeclSpace.CurrentTypeParameters; }
1118 public bool IsObsolete {
1119 get { return SlaveDeclSpace.IsObsolete; }
1122 public bool IsUnsafe {
1123 get { return SlaveDeclSpace.IsUnsafe; }
1126 public bool IsStatic {
1127 get { return SlaveDeclSpace.IsStatic; }
1130 public ModuleContainer Module {
1131 get { return module; }
1137 public class NamespaceUsing
1139 readonly MemberName name;
1142 public NamespaceUsing (MemberName name)
1147 public string GetSignatureForError ()
1149 return name.GetSignatureForError ();
1152 public Location Location
1154 get { return name.Location; }
1157 public MemberName MemberName
1159 get { return name; }
1164 get { return GetSignatureForError (); }
1167 public Namespace Resolve (IMemberContext rc)
1169 if (resolved != null)
1172 FullNamedExpression fne = name.GetTypeExpression ().ResolveAsTypeOrNamespace (rc);
1176 resolved = fne as Namespace;
1177 if (resolved == null) {
1178 rc.Module.Compiler.Report.SymbolRelatedToPreviousError (fne.Type);
1179 rc.Module.Compiler.Report.Error (138, Location,
1180 "`{0}' is a type not a namespace. A using namespace directive can only be applied to namespaces",
1181 GetSignatureForError ());
1187 public class NamespaceUsingAlias
1189 public readonly string Alias;
1190 public Location Location;
1192 public NamespaceUsingAlias (string alias, Location loc)
1195 this.Location = loc;
1198 public virtual FullNamedExpression Resolve (IMemberContext rc, bool local)
1200 FullNamedExpression fne = rc.Module.GetRootNamespace (Alias);
1202 rc.Module.Compiler.Report.Error (430, Location,
1203 "The extern alias `{0}' was not specified in -reference option",
1211 class LocalUsingAliasEntry : NamespaceUsingAlias
1213 FullNamedExpression resolved;
1216 public LocalUsingAliasEntry (string alias, MemberName name, Location loc)
1222 public override FullNamedExpression Resolve (IMemberContext rc, bool local)
1224 if (resolved != null || value == null)
1230 resolved = value.GetTypeExpression ().ResolveAsTypeOrNamespace (rc);
1231 if (resolved == null) {