(DISTFILES): Comment out a few missing files.
[mono-project.git] / mcs / mbas / sourcebeingcompiled.cs
blob5e324191caf5dfec18128012caf5286f100ecb18
1 //
2 // sourcebeingcompiled.cs: Tracks once-per-source things
3 //
4 // Author:
5 // Rafael Teixeira (rafaelteixeirabr@hotmail.com)
6 //
7 // (C) 2004 Rafael Teixeira.
8 //
10 using System;
11 using System.Collections;
12 using Mono.Languages;
14 namespace Mono.MonoBASIC {
16 /// <summary>
17 /// Keeps track of the once-per-source things in the VB.NET code.
18 /// </summary>
19 public class SourceBeingCompiled {
21 Hashtable imports_clauses;
22 Hashtable aliases;
25 // This class holds the location where a using definition is
26 // done, and whether it has been used by the program or not.
28 // We use this to flag using clauses for namespaces that do not
29 // exist.
31 public class ImportsEntry {
32 public string Name;
33 public bool Used;
34 public Location Location;
36 public ImportsEntry (string name, Location loc)
38 Name = name;
39 Location = loc;
40 Used = false;
44 public SourceBeingCompiled () { }
46 /// <summary>
47 /// Initializes the list of preimported namespaces
48 /// </summary>
49 public void InitializeImports (ArrayList ImportsList)
51 foreach(string preImportedNamespace in ImportsList)
52 this.Imports(preImportedNamespace, Location.Null);
55 /// <summary>
56 /// Records a new namespace for resolving name references
57 /// </summary>
58 public void Imports (string ns, Location loc)
60 if (imports_clauses == null)
61 imports_clauses = new CaseInsensitiveHashtable ();
63 ImportsEntry ue = new ImportsEntry (ns, loc);
64 imports_clauses [ns] = ue;
67 public ICollection ImportsTable {
68 get {
69 return imports_clauses.Values;
73 public string[] GetNamespacesInScope(string currentNamespace)
75 ArrayList list = new ArrayList();
76 foreach(ImportsEntry ie in ImportsTable)
77 list.Add(ie.Name);
78 list.Add(currentNamespace);
79 return (string[])list.ToArray(typeof(string));
83 public void ImportsWithAlias (string alias, string namespace_or_type, Location loc)
85 if (aliases == null)
86 aliases = new CaseInsensitiveHashtable ();
88 if (aliases.Contains (alias)){
89 Report.Error (1537, loc, "The Imports clause with alias '" + alias +
90 "' appeared previously in this namespace");
91 return;
94 aliases [alias] = namespace_or_type;
97 public string LookupAlias (string alias)
99 string value = null;
101 if (aliases != null)
102 value = (string) (aliases [alias]);
104 return value;
107 /// <summary>
108 /// Used to validate that all the using clauses are correct
109 /// after we are finished parsing all the files.
110 /// </summary>
111 public void VerifyImports ()
113 ArrayList unused = new ArrayList ();
115 foreach (ImportsEntry ue in ImportsTable) {
116 if (ue.Used)
117 continue;
118 unused.Add (ue);
122 // If we have unused imports aliases, load all namespaces and check
123 // whether it is unused, or it was missing
125 /* FIXME: why is happening a ghostly NullReferenceException inside TypeManager.GetNamespaces ()?
127 if (unused.Count > 0) {
128 CaseInsensitiveHashtable namespaces = TypeManager.GetNamespaces ();
130 foreach (ImportsEntry ue in unused) {
131 if (namespaces.Contains (ue.Name)){
132 Report.Warning (6024, ue.Location, "Unused namespace in 'Imports' declaration");
133 continue;
136 Report.Error (246, ue.Location, "The namespace '" + ue.Name +
137 "' can not be found (missing assembly reference?)");