using System;
using System.Collections;
namespace CIR {
//
// Keeps track of the namespaces defined in the C# code.
//
public class Namespace {
Namespace parent;
string name;
ArrayList using_clauses;
bool decl_found = false;
//
// Constructor Takes the current namespace and the
// name. This is bootstrapped with parent == null
// and name = ""
//
public Namespace (Namespace parent, string name)
{
this.name = name;
this.parent = parent;
}
//
// The qualified name of the current namespace
//
public string Name {
get {
string pname = parent != null ? parent.Name : "";
if (pname == "")
return name;
else
return parent.Name + "." + name;
}
}
//
// The parent of this namespace, used by the parser to "Pop"
// the current namespace declaration
//
public Namespace Parent {
get {
return parent;
}
}
//
// When a declaration is found in a namespace,
// we call this function, to emit an error if the
// program attempts to use a using clause afterwards
//
public void DeclarationFound ()
{
decl_found = true;
}
//
// Records a new namespace for resolving name references
//
public void Using (string ns)
{
if (decl_found){
CSharpParser.error (1529, "A using clause must precede all other namespace elements");
return;
}
if (using_clauses == null)
using_clauses = new ArrayList ();
using_clauses.Add (ns);
}
public ArrayList UsingTable {
get {
return using_clauses;
}
}
//
// Used to validate that all the using clauses are correct
// after we are finished parsing all the files
//
public void VerifyUsing ()
{
foreach (DictionaryEntry de in using_clauses){
if (de.Value == null){
string name = (string) de.Key;
CSharpParser.error (234, "The type or namespace `" +
name + "' does not exist in the " +
"class or namespace `" + name + "'");
}
}
}
}
}