2 // sourcebeingcompiled.cs: Tracks once-per-source things
5 // Rafael Teixeira (rafaelteixeirabr@hotmail.com)
7 // (C) 2004 Rafael Teixeira.
11 using System
.Collections
;
14 namespace Mono
.MonoBASIC
{
17 /// Keeps track of the once-per-source things in the VB.NET code.
19 public class SourceBeingCompiled
{
21 Hashtable imports_clauses
;
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
31 public class ImportsEntry
{
34 public Location Location
;
36 public ImportsEntry (string name
, Location loc
)
44 public SourceBeingCompiled () { }
47 /// Initializes the list of preimported namespaces
49 public void InitializeImports (ArrayList ImportsList
)
51 foreach(string preImportedNamespace
in ImportsList
)
52 this.Imports(preImportedNamespace
, Location
.Null
);
56 /// Records a new namespace for resolving name references
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
{
69 return imports_clauses
.Values
;
73 public string[] GetNamespacesInScope(string currentNamespace
)
75 ArrayList list
= new ArrayList();
76 foreach(ImportsEntry ie
in ImportsTable
)
78 list
.Add(currentNamespace
);
79 return (string[])list
.ToArray(typeof(string));
83 public void ImportsWithAlias (string alias, string namespace_or_type
, Location loc
)
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");
94 aliases
[alias] = namespace_or_type
;
97 public string LookupAlias (string alias)
102 value = (string) (aliases
[alias]);
108 /// Used to validate that all the using clauses are correct
109 /// after we are finished parsing all the files.
111 public void VerifyImports ()
113 ArrayList unused
= new ArrayList ();
115 foreach (ImportsEntry ue
in ImportsTable
) {
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");
136 Report.Error (246, ue.Location, "The namespace '" + ue.Name +
137 "' can not be found (missing assembly reference?)");