2005-11-24 Chris Toshok <toshok@ximian.com>
[mono.git] / mcs / mcs / namespace.cs
1 //
2 // namespace.cs: Tracks namespaces
3 //
4 // Author:
5 //   Miguel de Icaza (miguel@ximian.com)
6 //
7 // (C) 2001 Ximian, Inc.
8 //
9 using System;
10 using System.Collections;
11 using System.Collections.Specialized;
12 using System.Reflection;
13
14 namespace Mono.CSharp {
15
16         public class RootNamespace : Namespace {
17                 static MethodInfo get_namespaces_method;
18
19                 string alias_name;
20                 Assembly referenced_assembly;
21
22                 Hashtable all_namespaces;
23
24                 static Hashtable root_namespaces;
25                 public static GlobalRootNamespace Global;
26                 
27                 static RootNamespace ()
28                 {
29                         get_namespaces_method = typeof (Assembly).GetMethod ("GetNamespaces", BindingFlags.Instance | BindingFlags.NonPublic);
30
31                         Reset ();
32                 }
33
34                 public static void Reset ()
35                 {
36                         root_namespaces = new Hashtable ();
37                         Global = new GlobalRootNamespace ();
38                         root_namespaces ["global"] = Global;
39                 }
40
41                 protected RootNamespace (string alias_name, Assembly assembly)
42                         : base (null, String.Empty)
43                 {
44                         this.alias_name = alias_name;
45                         referenced_assembly = assembly;
46
47                         all_namespaces = new Hashtable ();
48                         all_namespaces.Add ("", this);
49
50                         if (referenced_assembly != null)
51                                 ComputeNamespaces (this.referenced_assembly);
52                 }
53
54                 public static void DefineRootNamespace (string name, Assembly assembly)
55                 {
56                         if (name == "global") {
57                                 // FIXME: Add proper error number
58                                 Report.Error (-42, "Cannot define an external alias named `global'");
59                                 return;
60                         }
61                         RootNamespace retval = GetRootNamespace (name);
62                         if (retval == null || retval.referenced_assembly != assembly)
63                                 root_namespaces [name] = new RootNamespace (name, assembly);
64                 }
65
66                 public static RootNamespace GetRootNamespace (string name)
67                 {
68                         return (RootNamespace) root_namespaces [name];
69                 }
70
71                 public virtual Type LookupTypeReflection (string name, Location loc)
72                 {
73                         return GetTypeInAssembly (referenced_assembly, name);
74                 }
75
76                 public void RegisterNamespace (Namespace child)
77                 {
78                         if (child != this)
79                                 all_namespaces.Add (child.Name, child);
80                 }
81
82                 public bool IsNamespace (string name)
83                 {
84                         return all_namespaces.Contains (name);
85                 }
86
87                 protected void EnsureNamespace (string dotted_name)
88                 {
89                         if (dotted_name != null && dotted_name != "" && ! IsNamespace (dotted_name))
90                                 GetNamespace (dotted_name, true);
91                 }
92
93                 protected void ComputeNamespaces (Assembly assembly)
94                 {
95                         if (get_namespaces_method != null) {
96                                 string [] namespaces = (string []) get_namespaces_method.Invoke (assembly, null);
97                                 foreach (string ns in namespaces)
98                                         EnsureNamespace (ns);
99                                 return;
100                         }
101
102                         foreach (Type t in assembly.GetExportedTypes ())
103                                 EnsureNamespace (t.Namespace);
104                 }
105                 
106                 protected static Type GetTypeInAssembly (Assembly assembly, string name)
107                 {
108                         Type t = assembly.GetType (name);
109                         if (t == null)
110                                 return null;
111
112                         if (t.IsPointer)
113                                 throw new InternalErrorException ("Use GetPointerType() to get a pointer");
114                         
115                         TypeAttributes ta = t.Attributes & TypeAttributes.VisibilityMask;
116                         if (ta == TypeAttributes.NotPublic ||
117                             ta == TypeAttributes.NestedPrivate ||
118                             ta == TypeAttributes.NestedAssembly ||
119                             ta == TypeAttributes.NestedFamANDAssem)
120                                 return null;
121
122                         return t;
123                 }
124
125                 public override string ToString ()
126                 {
127                         return String.Format ("RootNamespace ({0}::)", alias_name);
128                 }
129
130                 public override string GetSignatureForError ()
131                 {
132                         return alias_name + "::";
133                 }
134         }
135
136         public class GlobalRootNamespace : RootNamespace {
137                 Assembly [] assemblies;
138                 Module [] modules;
139
140                 public GlobalRootNamespace ()
141                         : base ("global", null)
142                 {
143                         assemblies = new Assembly [0];
144                 }
145
146                 public Assembly [] Assemblies {
147                         get { return assemblies; }
148                 }
149
150                 public Module [] Modules {
151                         get { return modules; }
152                 }
153
154                 public void AddAssemblyReference (Assembly a)
155                 {
156                         foreach (Assembly assembly in assemblies) {
157                                 if (a == assembly)
158                                         return;
159                         }
160
161                         int top = assemblies.Length;
162                         Assembly [] n = new Assembly [top + 1];
163                         assemblies.CopyTo (n, 0);
164                         n [top] = a;
165                         assemblies = n;
166
167                         ComputeNamespaces (a);
168                 }
169
170                 public void AddModuleReference (Module m)
171                 {
172                         int top = modules != null ? modules.Length : 0;
173                         Module [] n = new Module [top + 1];
174                         if (modules != null)
175                                 modules.CopyTo (n, 0);
176                         n [top] = m;
177                         modules = n;
178
179                         if (m == CodeGen.Module.Builder)
180                                 return;
181
182                         foreach (Type t in m.GetTypes ())
183                                 EnsureNamespace (t.Namespace);
184                 }
185
186                 public override Type LookupTypeReflection (string name, Location loc)
187                 {
188                         Type found_type = null;
189                 
190                         foreach (Assembly a in assemblies) {
191                                 Type t = GetTypeInAssembly (a, name);
192                                 if (t == null)
193                                         continue;
194                                         
195                                 if (found_type == null) {
196                                         found_type = t;
197                                         continue;
198                                 }
199
200                                 Report.SymbolRelatedToPreviousError (found_type);
201                                 Report.SymbolRelatedToPreviousError (t);
202                                 Report.Error (433, loc, "The imported type `{0}' is defined multiple times", name);
203                                         
204                                 return found_type;
205                         }
206
207                         if (modules != null) {
208                                 foreach (Module module in modules) {
209                                         Type t = module.GetType (name);
210                                         if (t == null)
211                                                 continue;
212
213                                         if (found_type == null) {
214                                                 found_type = t;
215                                                 continue;
216                                         }
217                                         
218                                         Report.SymbolRelatedToPreviousError (t);
219                                         Report.SymbolRelatedToPreviousError (found_type);
220                                         Report.Warning (436, 2, loc, "Ignoring imported type `{0}' since the current assembly already has a declaration with the same name",
221                                                 TypeManager.CSharpName (t));
222                                         return t;
223                                 }
224                         }
225
226                         return found_type;
227                 }
228         }
229
230         /// <summary>
231         ///   Keeps track of the namespaces defined in the C# code.
232         ///
233         ///   This is an Expression to allow it to be referenced in the
234         ///   compiler parse/intermediate tree during name resolution.
235         /// </summary>
236         public class Namespace : FullNamedExpression {
237                 
238                 Namespace parent;
239                 string fullname;
240                 Hashtable namespaces;
241                 IDictionary declspaces;
242                 Hashtable cached_types;
243                 RootNamespace root;
244
245                 public readonly MemberName MemberName;
246
247                 /// <summary>
248                 ///   Constructor Takes the current namespace and the
249                 ///   name.  This is bootstrapped with parent == null
250                 ///   and name = ""
251                 /// </summary>
252                 public Namespace (Namespace parent, string name)
253                 {
254                         // Expression members.
255                         this.eclass = ExprClass.Namespace;
256                         this.Type = null;
257                         this.loc = Location.Null;
258
259                         this.parent = parent;
260
261                         if (parent != null)
262                                 this.root = parent.root;
263                         else
264                                 this.root = this as RootNamespace;
265
266                         if (this.root == null)
267                                 throw new InternalErrorException ("Root namespaces must be created using RootNamespace");
268                         
269                         string pname = parent != null ? parent.Name : "";
270                                 
271                         if (pname == "")
272                                 fullname = name;
273                         else
274                                 fullname = parent.Name + "." + name;
275
276                         if (fullname == null)
277                                 throw new InternalErrorException ("Namespace has a null fullname");
278
279                         if (parent != null && parent.MemberName != MemberName.Null)
280                                 MemberName = new MemberName (parent.MemberName, name);
281                         else if (name == "")
282                                 MemberName = MemberName.Null;
283                         else
284                                 MemberName = new MemberName (name);
285
286                         namespaces = new Hashtable ();
287                         cached_types = new Hashtable ();
288
289                         root.RegisterNamespace (this);
290                 }
291
292                 public override Expression DoResolve (EmitContext ec)
293                 {
294                         return this;
295                 }
296
297                 public override void Emit (EmitContext ec)
298                 {
299                         throw new InternalErrorException ("Expression tree referenced namespace " + fullname + " during Emit ()");
300                 }
301
302                 public override string GetSignatureForError ()
303                 {
304                         return Name;
305                 }
306                 
307                 public Namespace GetNamespace (string name, bool create)
308                 {
309                         int pos = name.IndexOf ('.');
310
311                         Namespace ns;
312                         string first;
313                         if (pos >= 0)
314                                 first = name.Substring (0, pos);
315                         else
316                                 first = name;
317
318                         ns = (Namespace) namespaces [first];
319                         if (ns == null) {
320                                 if (!create)
321                                         return null;
322
323                                 ns = new Namespace (this, first);
324                                 namespaces.Add (first, ns);
325                         }
326
327                         if (pos >= 0)
328                                 ns = ns.GetNamespace (name.Substring (pos + 1), create);
329
330                         return ns;
331                 }
332
333                 TypeExpr LookupType (string name, Location loc)
334                 {
335                         if (cached_types.Contains (name))
336                                 return cached_types [name] as TypeExpr;
337
338                         Type t = null;
339                         if (declspaces != null) {
340                                 DeclSpace tdecl = declspaces [name] as DeclSpace;
341                                 if (tdecl != null) {
342                                         //
343                                         // Note that this is not:
344                                         //
345                                         //   t = tdecl.DefineType ()
346                                         //
347                                         // This is to make it somewhat more useful when a DefineType
348                                         // fails due to problems in nested types (more useful in the sense
349                                         // of fewer misleading error messages)
350                                         //
351                                         tdecl.DefineType ();
352                                         t = tdecl.TypeBuilder;
353                                 }
354                         }
355                         string lookup = t != null ? t.FullName : (fullname == "" ? name : fullname + "." + name);
356                         Type rt = root.LookupTypeReflection (lookup, loc);
357                         if (t == null)
358                                 t = rt;
359
360                         TypeExpr te = t == null ? null : new TypeExpression (t, Location.Null);
361                         cached_types [name] = te;
362                         return te;
363                 }
364
365                 public FullNamedExpression Lookup (DeclSpace ds, string name, Location loc)
366                 {
367                         if (namespaces.Contains (name))
368                                 return (Namespace) namespaces [name];
369
370                         TypeExpr te = LookupType (name, loc);
371                         if (te == null || !ds.CheckAccessLevel (te.Type))
372                                 return null;
373
374                         return te;
375                 }
376
377                 public void AddDeclSpace (string name, DeclSpace ds)
378                 {
379                         if (declspaces == null)
380                                 declspaces = new HybridDictionary ();
381                         declspaces.Add (name, ds);
382                 }
383
384                 /// <summary>
385                 ///   The qualified name of the current namespace
386                 /// </summary>
387                 public string Name {
388                         get { return fullname; }
389                 }
390
391                 public override string FullName {
392                         get { return fullname; }
393                 }
394
395                 /// <summary>
396                 ///   The parent of this namespace, used by the parser to "Pop"
397                 ///   the current namespace declaration
398                 /// </summary>
399                 public Namespace Parent {
400                         get { return parent; }
401                 }
402
403                 public override string ToString ()
404                 {
405                         return String.Format ("Namespace ({0})", Name);
406                 }
407         }
408
409         public class NamespaceEntry {
410                 Namespace ns;
411                 NamespaceEntry parent, implicit_parent;
412                 SourceFile file;
413                 int symfile_id;
414                 Hashtable aliases;
415                 ArrayList using_clauses;
416                 public bool DeclarationFound = false;
417                 public bool UsingFound = false;
418
419                 static ArrayList entries = new ArrayList ();
420
421                 public static void Reset ()
422                 {
423                         entries = new ArrayList ();
424                 }
425
426                 //
427                 // This class holds the location where a using definition is
428                 // done, and whether it has been used by the program or not.
429                 //
430                 // We use this to flag using clauses for namespaces that do not
431                 // exist.
432                 //
433                 public class UsingEntry {
434                         public readonly MemberName Name;
435                         readonly Expression Expr;
436                         readonly NamespaceEntry NamespaceEntry;
437                         readonly Location Location;
438                         
439                         public UsingEntry (NamespaceEntry entry, MemberName name, Location loc)
440                         {
441                                 Name = name;
442                                 Expr = name.GetTypeExpression ();
443                                 NamespaceEntry = entry;
444                                 Location = loc;
445                         }
446
447                         internal Namespace resolved;
448
449                         public Namespace Resolve ()
450                         {
451                                 if (resolved != null)
452                                         return resolved;
453
454                                 DeclSpace root = RootContext.Tree.Types;
455                                 root.NamespaceEntry = NamespaceEntry;
456                                 FullNamedExpression fne = Expr.ResolveAsTypeStep (root.EmitContext, false);
457                                 root.NamespaceEntry = null;
458
459                                 if (fne == null) {
460                                         Error_NamespaceNotFound (Location, Name.ToString ());
461                                         return null;
462                                 }
463
464                                 resolved = fne as Namespace;
465                                 if (resolved == null) {
466                                         Report.Error (138, Location,
467                                                 "`{0} is a type not a namespace. A using namespace directive can only be applied to namespaces", Name.ToString ());
468                                 }
469                                 return resolved;
470                         }
471                 }
472
473                 public abstract class AliasEntry {
474                         public readonly string Name;
475                         public readonly NamespaceEntry NamespaceEntry;
476                         public readonly Location Location;
477                         
478                         protected AliasEntry (NamespaceEntry entry, string name, Location loc)
479                         {
480                                 Name = name;
481                                 NamespaceEntry = entry;
482                                 Location = loc;
483                         }
484                         
485                         protected FullNamedExpression resolved;
486                         bool error;
487
488                         public FullNamedExpression Resolve ()
489                         {
490                                 if (resolved != null || error)
491                                         return resolved;
492                                 resolved = DoResolve ();
493                                 if (resolved == null)
494                                         error = true;
495                                 return resolved;
496                         }
497
498                         protected abstract FullNamedExpression DoResolve ();
499                 }
500
501                 public class LocalAliasEntry : AliasEntry
502                 {
503                         public readonly Expression Alias;
504                         
505                         public LocalAliasEntry (NamespaceEntry entry, string name, MemberName alias, Location loc) :
506                                 base (entry, name, loc)
507                         {
508                                 Alias = alias.GetTypeExpression ();
509                         }
510
511                         protected override FullNamedExpression DoResolve ()
512                         {
513                                 DeclSpace root = RootContext.Tree.Types;
514                                 root.NamespaceEntry = NamespaceEntry;
515                                 resolved = Alias.ResolveAsTypeStep (root.EmitContext, false);
516                                 root.NamespaceEntry = null;
517
518                                 if (resolved == null)
519                                         Error_NamespaceNotFound (Location, Alias.ToString ());
520                                 return resolved;
521                         }
522                 }
523
524                 public class ExternAliasEntry : AliasEntry 
525                 {
526                         public ExternAliasEntry (NamespaceEntry entry, string name, Location loc) :
527                                 base (entry, name, loc)
528                         {
529                         }
530
531                         protected override FullNamedExpression DoResolve ()
532                         {
533                                 resolved = RootNamespace.GetRootNamespace (Name);
534                                 if (resolved == null)
535                                         Report.Error (430, Location, "The extern alias '" + Name +
536                                                                         "' was not specified in a /reference option");
537
538                                 return resolved;
539                         }
540                 }
541
542                 public NamespaceEntry (NamespaceEntry parent, SourceFile file, string name, Location loc)
543                 {
544                         this.parent = parent;
545                         this.file = file;
546                         this.IsImplicit = false;
547                         entries.Add (this);
548                         this.ID = entries.Count;
549
550                         if (parent != null)
551                                 ns = parent.NS.GetNamespace (name, true);
552                         else if (name != null)
553                                 ns = RootNamespace.Global.GetNamespace (name, true);
554                         else
555                                 ns = RootNamespace.Global;
556                 }
557
558                 private NamespaceEntry (NamespaceEntry parent, SourceFile file, Namespace ns)
559                 {
560                         this.parent = parent;
561                         this.file = file;
562                         // no need to add self to 'entries', since we don't have any aliases or using entries.
563                         this.ID = -1;
564                         this.IsImplicit = true;
565                         this.ns = ns;
566                 }
567
568                 //
569                 // According to section 16.3.1 (using-alias-directive), the namespace-or-type-name is
570                 // resolved as if the immediately containing namespace body has no using-directives.
571                 //
572                 // Section 16.3.2 says that the same rule is applied when resolving the namespace-name
573                 // in the using-namespace-directive.
574                 //
575                 // To implement these rules, the expressions in the using directives are resolved using 
576                 // the "doppelganger" (ghostly bodiless duplicate).
577                 //
578                 NamespaceEntry doppelganger;
579                 NamespaceEntry Doppelganger {
580                         get {
581                                 if (!IsImplicit && doppelganger == null)
582                                         doppelganger = new NamespaceEntry (ImplicitParent, file, ns);
583                                 return doppelganger;
584                         }
585                 }
586
587                 public readonly int ID;
588                 public readonly bool IsImplicit;
589
590                 public Namespace NS {
591                         get { return ns; }
592                 }
593
594                 public NamespaceEntry Parent {
595                         get { return parent; }
596                 }
597
598                 public NamespaceEntry ImplicitParent {
599                         get {
600                                 if (parent == null)
601                                         return null;
602                                 if (implicit_parent == null) {
603                                         implicit_parent = (parent.NS == ns.Parent)
604                                                 ? parent
605                                                 : new NamespaceEntry (parent, file, ns.Parent);
606                                 }
607                                 return implicit_parent;
608                         }
609                 }
610
611                 /// <summary>
612                 ///   Records a new namespace for resolving name references
613                 /// </summary>
614                 public void Using (MemberName name, Location loc)
615                 {
616                         if (DeclarationFound){
617                                 Report.Error (1529, loc, "A using clause must precede all other namespace elements except extern alias declarations");
618                                 return;
619                         }
620
621                         if (name.Equals (ns.MemberName))
622                                 return;
623                         
624                         if (using_clauses == null)
625                                 using_clauses = new ArrayList ();
626
627                         foreach (UsingEntry old_entry in using_clauses) {
628                                 if (name.Equals (old_entry.Name)) {
629                                         Report.Warning (105, 3, loc, "The using directive for `{0}' appeared previously in this namespace", name.GetName ());
630                                         return;
631                                 }
632                         }
633
634                         UsingEntry ue = new UsingEntry (Doppelganger, name, loc);
635                         using_clauses.Add (ue);
636                 }
637
638                 public void UsingAlias (string name, MemberName alias, Location loc)
639                 {
640                         if (DeclarationFound){
641                                 Report.Error (1529, loc, "A using clause must precede all other namespace elements except extern alias declarations");
642                                 return;
643                         }
644
645                         if (aliases == null)
646                                 aliases = new Hashtable ();
647
648                         if (aliases.Contains (name)) {
649                                 AliasEntry ae = (AliasEntry)aliases [name];
650                                 Report.SymbolRelatedToPreviousError (ae.Location, ae.Name);
651                                 Report.Error (1537, loc, "The using alias `" + name +
652                                               "' appeared previously in this namespace");
653                                 return;
654                         }
655
656                         if (RootContext.Version == LanguageVersion.Default &&
657                             name == "global" && RootContext.WarningLevel >= 2)
658                                 Report.Warning (440, 2, loc, "An alias named `global' will not be used when resolving 'global::';" +
659                                         " the global namespace will be used instead");
660
661                         aliases [name] = new LocalAliasEntry (Doppelganger, name, alias, loc);
662                 }
663
664                 public void UsingExternalAlias (string name, Location loc)
665                 {
666                         if (UsingFound || DeclarationFound) {
667                                 Report.Error (439, loc, "An extern alias declaration must precede all other elements");
668                                 return;
669                         }
670                         
671                         if (aliases == null)
672                                 aliases = new Hashtable ();
673                         
674                         if (aliases.Contains (name)) {
675                                 AliasEntry ae = (AliasEntry) aliases [name];
676                                 Report.SymbolRelatedToPreviousError (ae.Location, ae.Name);
677                                 Report.Error (1537, loc, "The using alias `" + name +
678                                               "' appeared previously in this namespace");
679                                 return;
680                         }
681
682                         if (name == "global") {
683                                 Report.Error (1681, loc, "You cannot redefine the global extern alias");
684                                 return;
685                         }
686
687                         aliases [name] = new ExternAliasEntry (Doppelganger, name, loc);
688                 }
689
690                 public FullNamedExpression LookupNamespaceOrType (DeclSpace ds, string name, Location loc, bool ignore_cs0104)
691                 {
692                         // Precondition: Only simple names (no dots) will be looked up with this function.
693                         FullNamedExpression resolved = null;
694                         for (NamespaceEntry curr_ns = this; curr_ns != null; curr_ns = curr_ns.ImplicitParent) {
695                                 if ((resolved = curr_ns.Lookup (ds, name, loc, ignore_cs0104)) != null)
696                                         break;
697                         }
698                         return resolved;
699                 }
700
701                 static void Error_AmbiguousTypeReference (Location loc, string name, FullNamedExpression t1, FullNamedExpression t2)
702                 {
703                         Report.Error (104, loc, "`{0}' is an ambiguous reference between `{1}' and `{2}'",
704                                 name, t1.FullName, t2.FullName);
705                 }
706
707                 // Looks-up a alias named @name in this and surrounding namespace declarations
708                 public FullNamedExpression LookupAlias (string name)
709                 {
710                         AliasEntry entry = null;
711                         // We use Parent rather than ImplicitParent since we know implicit namespace declarations
712                         // cannot have using entries.
713                         for (NamespaceEntry n = this; n != null; n = n.Parent) {
714                                 if (n.aliases == null)
715                                         continue;
716                                 entry = n.aliases [name] as AliasEntry;
717                                 if (entry != null)
718                                         return entry.Resolve ();
719                         }
720                         return null;
721                 }
722
723                 private FullNamedExpression Lookup (DeclSpace ds, string name, Location loc, bool ignore_cs0104)
724                 {
725                         //
726                         // Check whether it's in the namespace.
727                         //
728                         FullNamedExpression fne = NS.Lookup (ds, name, loc);
729                         if (fne != null)
730                                 return fne;
731
732                         if (IsImplicit)
733                                 return null;
734
735                         //
736                         // Check aliases.
737                         //
738                         if (aliases != null) {
739                                 AliasEntry entry = aliases [name] as AliasEntry;
740                                 if (entry != null)
741                                         return entry.Resolve ();
742                         }
743
744                         //
745                         // Check using entries.
746                         //
747                         FullNamedExpression match = null;
748                         foreach (Namespace using_ns in GetUsingTable ()) {
749                                 match = using_ns.Lookup (ds, name, loc);
750                                 if (match == null || !(match is TypeExpr))
751                                         continue;
752                                 if (fne != null) {
753                                         if (!ignore_cs0104)
754                                                 Error_AmbiguousTypeReference (loc, name, fne, match);
755                                         return null;
756                                 }
757                                 fne = match;
758                         }
759
760                         return fne;
761                 }
762
763                 // Our cached computation.
764                 readonly Namespace [] empty_namespaces = new Namespace [0];
765                 Namespace [] namespace_using_table;
766                 Namespace [] GetUsingTable ()
767                 {
768                         if (namespace_using_table != null)
769                                 return namespace_using_table;
770
771                         if (using_clauses == null) {
772                                 namespace_using_table = empty_namespaces;
773                                 return namespace_using_table;
774                         }
775
776                         ArrayList list = new ArrayList (using_clauses.Count);
777
778                         foreach (UsingEntry ue in using_clauses) {
779                                 Namespace using_ns = ue.Resolve ();
780                                 if (using_ns == null)
781                                         continue;
782
783                                 list.Add (using_ns);
784                         }
785
786                         namespace_using_table = new Namespace [list.Count];
787                         list.CopyTo (namespace_using_table, 0);
788                         return namespace_using_table;
789                 }
790
791                 readonly string [] empty_using_list = new string [0];
792
793                 public int SymbolFileID {
794                         get {
795                                 if (symfile_id == 0 && file.SourceFileEntry != null) {
796                                         int parent_id = parent == null ? 0 : parent.SymbolFileID;
797
798                                         string [] using_list = empty_using_list;
799                                         if (using_clauses != null) {
800                                                 using_list = new string [using_clauses.Count];
801                                                 for (int i = 0; i < using_clauses.Count; i++)
802                                                         using_list [i] = ((UsingEntry) using_clauses [i]).Name.ToString ();
803                                         }
804
805                                         symfile_id = CodeGen.SymbolWriter.DefineNamespace (ns.Name, file.SourceFileEntry, using_list, parent_id);
806                                 }
807                                 return symfile_id;
808                         }
809                 }
810
811                 static void MsgtryRef (string s)
812                 {
813                         Console.WriteLine ("    Try using -r:" + s);
814                 }
815
816                 static void MsgtryPkg (string s)
817                 {
818                         Console.WriteLine ("    Try using -pkg:" + s);
819                 }
820
821                 public static void Error_NamespaceNotFound (Location loc, string name)
822                 {
823                         Report.Error (246, loc, "The type or namespace name `{0}' could not be found. Are you missing a using directive or an assembly reference?",
824                                 name);
825
826                         switch (name) {
827                         case "Gtk": case "GtkSharp":
828                                 MsgtryPkg ("gtk-sharp");
829                                 break;
830
831                         case "Gdk": case "GdkSharp":
832                                 MsgtryPkg ("gdk-sharp");
833                                 break;
834
835                         case "Glade": case "GladeSharp":
836                                 MsgtryPkg ("glade-sharp");
837                                 break;
838
839                         case "System.Drawing":
840                         case "System.Web.Services":
841                         case "System.Web":
842                         case "System.Data":
843                         case "System.Windows.Forms":
844                                 MsgtryRef (name);
845                                 break;
846                         }
847                 }
848
849                 /// <summary>
850                 ///   Used to validate that all the using clauses are correct
851                 ///   after we are finished parsing all the files.  
852                 /// </summary>
853                 void VerifyUsing ()
854                 {
855                         if (using_clauses != null) {
856                                 foreach (UsingEntry ue in using_clauses)
857                                         ue.Resolve ();
858                         }
859
860                         if (aliases != null) {
861                                 foreach (DictionaryEntry de in aliases)
862                                         ((AliasEntry) de.Value).Resolve ();
863                         }
864                 }
865
866                 /// <summary>
867                 ///   Used to validate that all the using clauses are correct
868                 ///   after we are finished parsing all the files.  
869                 /// </summary>
870                 static public void VerifyAllUsing ()
871                 {
872                         foreach (NamespaceEntry entry in entries)
873                                 entry.VerifyUsing ();
874                 }
875
876                 public string GetSignatureForError ()
877                 {
878                         return ns.GetSignatureForError ();
879                 }
880
881                 public override string ToString ()
882                 {
883                         return ns.ToString ();
884                 }
885         }
886 }