Namespace parent;
string name;
+ SourceFile file;
+ int symfile_id;
ArrayList using_clauses;
Hashtable aliases;
public bool DeclarationFound = false;
//
public class UsingEntry {
public string Name;
- public bool Used;
public Location Location;
public UsingEntry (string name, Location loc)
{
Name = name;
Location = loc;
- Used = false;
}
}
/// name. This is bootstrapped with parent == null
/// and name = ""
/// </summary>
- public Namespace (Namespace parent, string name)
+ public Namespace (Namespace parent, SourceFile file, string name)
{
this.name = name;
+ this.file = file;
this.parent = parent;
all_namespaces.Add (this);
}
+ static public ArrayList UserDefinedNamespaces {
+ get {
+ return all_namespaces;
+ }
+ }
+
/// <summary>
/// The qualified name of the current namespace
/// </summary>
if (pname == "")
return name;
else
- return parent.Name + "." + name;
+ return String.Concat (parent.Name, ".", name);
}
}
}
}
+ public int SymbolFileID {
+ get {
+ return symfile_id;
+ }
+ }
+
/// <summary>
/// Records a new namespace for resolving name references
/// </summary>
return;
}
+ if (ns == Name)
+ return;
+
if (using_clauses == null)
using_clauses = new ArrayList ();
+ foreach (UsingEntry old_entry in using_clauses){
+ if (old_entry.Name == ns){
+ Report.Warning (105, loc, "The using directive for '" + ns +
+ "' appeared previously in this namespace");
+ return;
+ }
+ }
+
UsingEntry ue = new UsingEntry (ns, loc);
using_clauses.Add (ue);
}
return value;
}
+ void DefineNamespace (SymbolWriter symwriter)
+ {
+ if (symfile_id != 0)
+ return;
+ if (parent != null)
+ parent.DefineNamespace (symwriter);
+
+ string[] using_list;
+ if (using_clauses != null) {
+ using_list = new string [using_clauses.Count];
+ for (int i = 0; i < using_clauses.Count; i++)
+ using_list [i] = ((UsingEntry) using_clauses [i]).Name;
+ } else {
+ using_list = new string [0];
+ }
+
+ int parent_id = parent != null ? parent.symfile_id : 0;
+ symfile_id = symwriter.DefineNamespace (name, file, using_list, parent_id);
+ }
+
+ public static void DefineNamespaces (SymbolWriter symwriter)
+ {
+ foreach (Namespace ns in all_namespaces)
+ ns.DefineNamespace (symwriter);
+ }
+
/// <summary>
/// Used to validate that all the using clauses are correct
/// after we are finished parsing all the files.
/// </summary>
- public static bool VerifyUsing ()
+ public static void VerifyUsing ()
{
- ArrayList unused = new ArrayList ();
- int errors = 0;
-
foreach (Namespace ns in all_namespaces){
ArrayList uses = ns.UsingTable;
- if (uses == null)
- continue;
-
- foreach (UsingEntry ue in uses){
- if (ue.Used)
- continue;
- unused.Add (ue);
- }
- }
- //
- // If we have unused using aliases, load all namespaces and check
- // whether it is unused, or it was missing
- //
- if (unused.Count > 0){
- Hashtable namespaces = TypeManager.GetNamespaces ();
-
- foreach (UsingEntry ue in unused){
- if (namespaces.Contains (ue.Name)){
- Report.Warning (6024, ue.Location, "Unused namespace in `using' declaration");
- continue;
+ if (uses != null){
+ foreach (UsingEntry ue in uses){
+ if (TypeManager.IsNamespace (ue.Name))
+ continue;
+
+ Report.Error (246, ue.Location, "The namespace `" + ue.Name +
+ "' can not be found (missing assembly reference?)");
}
+ }
- errors++;
- Report.Error (246, ue.Location, "The namespace `" + ue.Name +
- "' can not be found (missing assembly reference?)");
+ if (ns.aliases != null){
+ foreach (DictionaryEntry de in ns.aliases){
+ string value = (string) de.Value;
+
+ if (TypeManager.IsNamespace (value))
+ continue;
+ if (TypeManager.LookupTypeDirect (value) != null)
+ continue;
+
+ Report.Error (246, String.Format (
+ "The type or namespace `{0}' could not be found (missing assembly reference?)",
+ value));
+ }
}
}
-
- return errors == 0;
}
-
}
}