+2003-08-26 Martin Baulig <martin@ximian.com>
+
+ * decl.cs (MemberCore): Moved WarningNotHiding(),
+ Error_CannotChangeAccessModifiers() and CheckMethodAgainstBase()
+ into MemberBase.
+ (AdditionResult): Make this nested in DeclSpace.
+ (DeclSpace.ctor): The .ctor now takes an additional NamespaceEntry
+ argument; call NamespaceEntry.Define() unless we're nested in a
+ class or struct.
+
+ * namespace.cs (Namespace.DefineName): New public function. This
+ is called from DeclSpace's .ctor to add
+ (Namespace.Lookup): Include DeclSpaces in the lookup.
+
+ * class.cs (Operator): Derive from MemberBase, not MemberCore.
+
+ * const.cs (Const): Derive from MemberBase, not MemberCore.
+
2003-08-25 Martin Baulig <martin@ximian.com>
* convert.cs (Convert.ExplicitReferenceConversion): When
//
public string IndexerName;
- public TypeContainer (TypeContainer parent, string name, Location l)
- : base (parent, name, l)
+ public TypeContainer (NamespaceEntry ns, TypeContainer parent, string name, Location l)
+ : base (ns, parent, name, l)
{
string n;
types = new ArrayList ();
if (idx < 0){
if (RootContext.WarningLevel >= 4){
if ((mc.ModFlags & Modifiers.NEW) != 0)
- Warning_KewywordNewNotRequired (mc.Location, mc);
+ Warning_KeywordNewNotRequired (mc.Location, mc);
}
} else if (mc is MethodCore)
((MethodCore) mc).OverridesSomething = true;
mi.ReflectedType.Name + "." + mi.Name + "'");
}
- public void Warning_KewywordNewNotRequired (Location l, MemberCore mc)
+ public void Warning_KeywordNewNotRequired (Location l, MemberCore mc)
{
Report.Warning (
109, l, "The member " + MakeName (mc.Name) + " does not hide an " +
Modifiers.SEALED |
Modifiers.UNSAFE;
- public Class (TypeContainer parent, string name, int mod, Attributes attrs, Location l)
- : base (parent, name, l)
+ public Class (NamespaceEntry ns, TypeContainer parent, string name, int mod, Attributes attrs, Location l)
+ : base (ns, parent, name, l)
{
int accmods;
Modifiers.UNSAFE |
Modifiers.PRIVATE;
- public Struct (TypeContainer parent, string name, int mod, Attributes attrs, Location l)
- : base (parent, name, l)
+ public Struct (NamespaceEntry ns, TypeContainer parent, string name, int mod, Attributes attrs, Location l)
+ : base (ns, parent, name, l)
{
int accmods;
public MethodCore (Expression type, int mod, int allowed_mod, string name,
Attributes attrs, Parameters parameters, Location loc)
- : base (type, mod, allowed_mod, name, attrs, loc)
+ : base (type, mod, allowed_mod, Modifiers.PRIVATE, name, attrs, loc)
{
Parameters = parameters;
}
//
// The constructor is only exposed to our children
//
- protected MemberBase (Expression type, int mod, int allowed_mod, string name,
+ protected MemberBase (Expression type, int mod, int allowed_mod, int def_mod, string name,
Attributes attrs, Location loc)
: base (name, loc)
{
Type = type;
- ModFlags = Modifiers.Check (allowed_mod, mod, Modifiers.PRIVATE, loc);
+ ModFlags = Modifiers.Check (allowed_mod, mod, def_mod, loc);
OptAttributes = attrs;
}
return true;
}
+ protected void WarningNotHiding (TypeContainer parent)
+ {
+ Report.Warning (
+ 109, Location,
+ "The member " + parent.MakeName (Name) + " does not hide an " +
+ "inherited member. The keyword new is not required");
+
+ }
+
+ void Error_CannotChangeAccessModifiers (TypeContainer parent, MethodInfo parent_method,
+ string name)
+ {
+ //
+ // FIXME: report the old/new permissions?
+ //
+ Report.Error (
+ 507, Location, parent.MakeName (Name) +
+ ": can't change the access modifiers when overriding inherited " +
+ "member `" + name + "'");
+ }
+
+ //
+ // Performs various checks on the MethodInfo `mb' regarding the modifier flags
+ // that have been defined.
+ //
+ // `name' is the user visible name for reporting errors (this is used to
+ // provide the right name regarding method names and properties)
+ //
+ protected bool CheckMethodAgainstBase (TypeContainer parent, MethodAttributes my_attrs,
+ MethodInfo mb, string name)
+ {
+ bool ok = true;
+
+ if ((ModFlags & Modifiers.OVERRIDE) != 0){
+ if (!(mb.IsAbstract || mb.IsVirtual)){
+ Report.Error (
+ 506, Location, parent.MakeName (Name) +
+ ": cannot override inherited member `" +
+ name + "' because it is not " +
+ "virtual, abstract or override");
+ ok = false;
+ }
+
+ // Now we check that the overriden method is not final
+
+ if (mb.IsFinal) {
+ // This happens when implementing interface methods.
+ if (mb.IsHideBySig && mb.IsVirtual) {
+ Report.Error (
+ 506, Location, parent.MakeName (Name) +
+ ": cannot override inherited member `" +
+ name + "' because it is not " +
+ "virtual, abstract or override");
+ } else
+ Report.Error (239, Location, parent.MakeName (Name) + " : cannot " +
+ "override inherited member `" + name +
+ "' because it is sealed.");
+ ok = false;
+ }
+ //
+ // Check that the permissions are not being changed
+ //
+ MethodAttributes thisp = my_attrs & MethodAttributes.MemberAccessMask;
+ MethodAttributes parentp = mb.Attributes & MethodAttributes.MemberAccessMask;
+
+ //
+ // special case for "protected internal"
+ //
+
+ if ((parentp & MethodAttributes.FamORAssem) == MethodAttributes.FamORAssem){
+ //
+ // when overriding protected internal, the method can be declared
+ // protected internal only within the same assembly
+ //
+
+ if ((thisp & MethodAttributes.FamORAssem) == MethodAttributes.FamORAssem){
+ if (parent.TypeBuilder.Assembly != mb.DeclaringType.Assembly){
+ //
+ // assemblies differ - report an error
+ //
+
+ Error_CannotChangeAccessModifiers (parent, mb, name);
+ ok = false;
+ } else if (thisp != parentp) {
+ //
+ // same assembly, but other attributes differ - report an error
+ //
+
+ Error_CannotChangeAccessModifiers (parent, mb, name);
+ ok = false;
+ };
+ } else if ((thisp & MethodAttributes.Family) != MethodAttributes.Family) {
+ //
+ // if it's not "protected internal", it must be "protected"
+ //
+
+ Error_CannotChangeAccessModifiers (parent, mb, name);
+ ok = false;
+ } else if (parent.TypeBuilder.Assembly == mb.DeclaringType.Assembly) {
+ //
+ // protected within the same assembly - an error
+ //
+ Error_CannotChangeAccessModifiers (parent, mb, name);
+ ok = false;
+ } else if ((thisp & ~(MethodAttributes.Family | MethodAttributes.FamORAssem)) !=
+ (parentp & ~(MethodAttributes.Family | MethodAttributes.FamORAssem))) {
+ //
+ // protected ok, but other attributes differ - report an error
+ //
+ Error_CannotChangeAccessModifiers (parent, mb, name);
+ ok = false;
+ }
+ } else {
+ if (thisp != parentp){
+ Error_CannotChangeAccessModifiers (parent, mb, name);
+ ok = false;
+ }
+ }
+ }
+
+ if (mb.IsVirtual || mb.IsAbstract){
+ if ((ModFlags & (Modifiers.NEW | Modifiers.OVERRIDE)) == 0){
+ if (Name != "Finalize"){
+ Report.Warning (
+ 114, 2, Location, parent.MakeName (Name) +
+ " hides inherited member `" + name +
+ "'. To make the current member override that " +
+ "implementation, add the override keyword, " +
+ "otherwise use the new keyword");
+ ModFlags |= Modifiers.NEW;
+ }
+ }
+ } else {
+ if ((ModFlags & (Modifiers.NEW | Modifiers.OVERRIDE)) == 0){
+ if (Name != "Finalize"){
+ Report.Warning (
+ 108, 1, Location, "The keyword new is required on " +
+ parent.MakeName (Name) + " because it hides " +
+ "inherited member `" + name + "'");
+ ModFlags |= Modifiers.NEW;
+ }
+ }
+ }
+
+ return ok;
+ }
+
protected virtual bool CheckParameters (TypeContainer container, Type [] parameters)
{
bool error = false;
//
protected FieldBase (Expression type, int mod, int allowed_mod, string name,
object init, Attributes attrs, Location loc)
- : base (type, mod, allowed_mod, name, attrs, loc)
+ : base (type, mod, allowed_mod, Modifiers.PRIVATE, name, attrs, loc)
{
this.init = init;
}
}
}
- public class Operator : MemberCore {
+ public class Operator : MemberBase {
const int AllowedModifiers =
Modifiers.PUBLIC |
public readonly Expression FirstArgType, SecondArgType;
public readonly string FirstArgName, SecondArgName;
public Block Block;
- public Attributes OptAttributes;
public MethodBuilder OperatorMethodBuilder;
public string MethodName;
public Method OperatorMethod;
- public Operator (OpType type, Expression ret_type, int flags,
+ public Operator (OpType type, Expression ret_type, int mod_flags,
Expression arg1type, string arg1name,
Expression arg2type, string arg2name,
Block block, Attributes attrs, Location loc)
- : base ("", loc)
+ : base (ret_type, mod_flags, AllowedModifiers, Modifiers.PUBLIC, "", attrs, loc)
{
OperatorType = type;
ReturnType = ret_type;
- ModFlags = Modifiers.Check (AllowedModifiers, flags, Modifiers.PUBLIC, loc);
FirstArgType = arg1type;
FirstArgName = arg1name;
SecondArgType = arg2type;
SecondArgName = arg2name;
Block = block;
- OptAttributes = attrs;
}
string Prototype (TypeContainer container)
using System.Reflection.Emit;
using System.Collections;
- public class Const : MemberCore {
+ public class Const : MemberBase {
public Expression ConstantType;
public Expression Expr;
- public Attributes OptAttributes;
public FieldBuilder FieldBuilder;
EmitContext const_ec;
public Const (Expression constant_type, string name, Expression expr, int mod_flags,
Attributes attrs, Location loc)
- : base (name, loc)
+ : base (constant_type, mod_flags, AllowedModifiers, Modifiers.PRIVATE, name, attrs, loc)
{
ConstantType = constant_type;
Name = name;
Expr = expr;
- ModFlags = Modifiers.Check (AllowedModifiers, mod_flags, Modifiers.PRIVATE, loc);
- OptAttributes = attrs;
}
public FieldAttributes FieldAttr {
if (ptype != null) {
MemberList list = TypeContainer.FindMembers (
ptype, MemberTypes.Field, BindingFlags.Public,
- Type.FilterName, Name);
+ System.Type.FilterName, Name);
if (list.Count == 0)
if ((ModFlags & Modifiers.NEW) != 0)
+ " Expected class, delegate, enum, interface, or struct");
}
- current_namespace = RootContext.Tree.RecordNamespace (current_namespace, file, (string) $3);
+ current_namespace = RootContext.Tree.RecordNamespace (current_namespace, file, (string) $3, lexer.Location);
}
namespace_body opt_semicolon
{
Struct new_struct;
string full_struct_name = MakeName ((string) $4);
- new_struct = new Struct (current_container, full_struct_name, (int) $2,
- (Attributes) $1, lexer.Location);
+ new_struct = new Struct (current_namespace, current_container, full_struct_name,
+ (int) $2, (Attributes) $1, lexer.Location);
current_container = new_struct;
- current_container.NamespaceEntry = current_namespace;
RootContext.Tree.RecordDecl (full_struct_name, new_struct);
}
opt_class_base
Interface new_interface;
string full_interface_name = MakeName ((string) $4);
- new_interface = new Interface (current_container, full_interface_name, (int) $2,
- (Attributes) $1, lexer.Location);
+ new_interface = new Interface (current_namespace, current_container, full_interface_name,
+ (int) $2, (Attributes) $1, lexer.Location);
if (current_interface != null) {
Location l = lexer.Location;
Report.Error (-2, l, "Internal compiler error: interface inside interface");
}
current_interface = new_interface;
- new_interface.NamespaceEntry = current_namespace;
RootContext.Tree.RecordDecl (full_interface_name, new_interface);
}
opt_interface_base
Location enum_location = lexer.Location;
string full_name = MakeName ((string) $4);
- Enum e = new Enum (current_container, (Expression) $5, (int) $2, full_name,
- (Attributes) $1, enum_location);
+ Enum e = new Enum (current_namespace, current_container, (Expression) $5, (int) $2,
+ full_name, (Attributes) $1, enum_location);
foreach (VariableDeclaration ev in (ArrayList) $6) {
Location loc = (Location) ev.Location;
ev.identifier, loc);
}
- e.NamespaceEntry = current_namespace;
-
CheckDef (current_container.AddEnum (e), full_name, enum_location);
RootContext.Tree.RecordDecl (full_name, e);
SEMICOLON
{
Location l = lexer.Location;
- Delegate del = new Delegate (current_container, (Expression) $4, (int) $2,
- MakeName ((string) $5), (Parameters) $7,
+ Delegate del = new Delegate (current_namespace, current_container, (Expression) $4,
+ (int) $2, MakeName ((string) $5), (Parameters) $7,
(Attributes) $1, l);
- del.NamespaceEntry = current_namespace;
CheckDef (current_container.AddDelegate (del), del.Name, l);
}
| opt_attributes
{
Location l = lexer.Location;
Delegate del = new Delegate (
- current_container,
+ current_namespace, current_container,
TypeManager.system_void_expr, (int) $2, MakeName ((string) $5),
(Parameters) $7, (Attributes) $1, l);
- del.NamespaceEntry = current_namespace;
CheckDef (current_container.AddDelegate (del), del.Name, l);
}
;
name = MakeName ((string) $4);
- new_class = new Class (current_container, name, (int) $2,
+ new_class = new Class (current_namespace, current_container, name, (int) $2,
(Attributes) $1, lexer.Location);
current_container = new_class;
- current_container.NamespaceEntry = current_namespace;
RootContext.Tree.RecordDecl (name, new_class);
}
opt_class_base
string
MakeName (string class_name)
{
- string ns = current_namespace.Name;
+ string ns = current_namespace.FullName;
string container_name = current_container.Name;
if (container_name == ""){
// in the current declaration space
// </summary>
void
-CheckDef (AdditionResult result, string name, Location l)
+CheckDef (DeclSpace.AdditionResult result, string name, Location l)
{
- if (result == AdditionResult.Success)
+ if (result == DeclSpace.AdditionResult.Success)
return;
switch (result){
- case AdditionResult.NameExists:
+ case DeclSpace.AdditionResult.NameExists:
Report.Error (102, l, "The container `" + current_container.Name +
"' already contains a definition for `"+
name + "'");
// This is handled only for static Constructors, because
// in reality we handle these by the semantic analysis later
//
- case AdditionResult.MethodExists:
+ case DeclSpace.AdditionResult.MethodExists:
Report.Error (
111, l, "Class `"+current_container.Name+
"' already defines a member called '" +
name + "' with the same parameter types (more than one default constructor)");
break;
- case AdditionResult.EnclosingClash:
+ case DeclSpace.AdditionResult.EnclosingClash:
Report.Error (542, l, "Member names cannot be the same as their enclosing type");
break;
- case AdditionResult.NotAConstructor:
+ case DeclSpace.AdditionResult.NotAConstructor:
Report.Error (1520, l, "Class, struct, or interface method must have a return type");
break;
- case AdditionResult.Error:
+ case DeclSpace.AdditionResult.Error:
// Error has already been reported.
break;
}
{
if (result)
return;
- CheckDef (AdditionResult.NameExists, name, l);
+ CheckDef (DeclSpace.AdditionResult.NameExists, name, l);
}
Expression DecomposeQI (string name, Location loc)
public CSharpParser (SeekableStreamReader reader, SourceFile file, ArrayList defines)
{
- current_namespace = new NamespaceEntry (null, file, null);
+ current_namespace = new NamespaceEntry (null, file, null, Location.Null);
this.name = file.Name;
this.file = file;
current_container = RootContext.Tree.Types;
// Please do not remove this, it is used during debugging
// of the grammar
//
+ Console.WriteLine (e);
Report.Error (-25, lexer.Location, "Parsing error");
if (Driver.parser_verbose)
Console.WriteLine (e);
Location = loc;
}
- protected void WarningNotHiding (TypeContainer parent)
- {
- Report.Warning (
- 109, Location,
- "The member " + parent.MakeName (Name) + " does not hide an " +
- "inherited member. The keyword new is not required");
-
- }
-
- void Error_CannotChangeAccessModifiers (TypeContainer parent, MethodInfo parent_method,
- string name)
- {
- //
- // FIXME: report the old/new permissions?
- //
- Report.Error (
- 507, Location, parent.MakeName (Name) +
- ": can't change the access modifiers when overriding inherited " +
- "member `" + name + "'");
- }
-
- //
- // Performs various checks on the MethodInfo `mb' regarding the modifier flags
- // that have been defined.
- //
- // `name' is the user visible name for reporting errors (this is used to
- // provide the right name regarding method names and properties)
- //
- protected bool CheckMethodAgainstBase (TypeContainer parent, MethodAttributes my_attrs,
- MethodInfo mb, string name)
- {
- bool ok = true;
-
- if ((ModFlags & Modifiers.OVERRIDE) != 0){
- if (!(mb.IsAbstract || mb.IsVirtual)){
- Report.Error (
- 506, Location, parent.MakeName (Name) +
- ": cannot override inherited member `" +
- name + "' because it is not " +
- "virtual, abstract or override");
- ok = false;
- }
-
- // Now we check that the overriden method is not final
-
- if (mb.IsFinal) {
- // This happens when implementing interface methods.
- if (mb.IsHideBySig && mb.IsVirtual) {
- Report.Error (
- 506, Location, parent.MakeName (Name) +
- ": cannot override inherited member `" +
- name + "' because it is not " +
- "virtual, abstract or override");
- } else
- Report.Error (239, Location, parent.MakeName (Name) + " : cannot " +
- "override inherited member `" + name +
- "' because it is sealed.");
- ok = false;
- }
- //
- // Check that the permissions are not being changed
- //
- MethodAttributes thisp = my_attrs & MethodAttributes.MemberAccessMask;
- MethodAttributes parentp = mb.Attributes & MethodAttributes.MemberAccessMask;
-
- //
- // special case for "protected internal"
- //
-
- if ((parentp & MethodAttributes.FamORAssem) == MethodAttributes.FamORAssem){
- //
- // when overriding protected internal, the method can be declared
- // protected internal only within the same assembly
- //
-
- if ((thisp & MethodAttributes.FamORAssem) == MethodAttributes.FamORAssem){
- if (parent.TypeBuilder.Assembly != mb.DeclaringType.Assembly){
- //
- // assemblies differ - report an error
- //
-
- Error_CannotChangeAccessModifiers (parent, mb, name);
- ok = false;
- } else if (thisp != parentp) {
- //
- // same assembly, but other attributes differ - report an error
- //
-
- Error_CannotChangeAccessModifiers (parent, mb, name);
- ok = false;
- };
- } else if ((thisp & MethodAttributes.Family) != MethodAttributes.Family) {
- //
- // if it's not "protected internal", it must be "protected"
- //
-
- Error_CannotChangeAccessModifiers (parent, mb, name);
- ok = false;
- } else if (parent.TypeBuilder.Assembly == mb.DeclaringType.Assembly) {
- //
- // protected within the same assembly - an error
- //
- Error_CannotChangeAccessModifiers (parent, mb, name);
- ok = false;
- } else if ((thisp & ~(MethodAttributes.Family | MethodAttributes.FamORAssem)) !=
- (parentp & ~(MethodAttributes.Family | MethodAttributes.FamORAssem))) {
- //
- // protected ok, but other attributes differ - report an error
- //
- Error_CannotChangeAccessModifiers (parent, mb, name);
- ok = false;
- }
- } else {
- if (thisp != parentp){
- Error_CannotChangeAccessModifiers (parent, mb, name);
- ok = false;
- }
- }
- }
-
- if (mb.IsVirtual || mb.IsAbstract){
- if ((ModFlags & (Modifiers.NEW | Modifiers.OVERRIDE)) == 0){
- if (Name != "Finalize"){
- Report.Warning (
- 114, 2, Location, parent.MakeName (Name) +
- " hides inherited member `" + name +
- "'. To make the current member override that " +
- "implementation, add the override keyword, " +
- "otherwise use the new keyword");
- ModFlags |= Modifiers.NEW;
- }
- }
- } else {
- if ((ModFlags & (Modifiers.NEW | Modifiers.OVERRIDE)) == 0){
- if (Name != "Finalize"){
- Report.Warning (
- 108, 1, Location, "The keyword new is required on " +
- parent.MakeName (Name) + " because it hides " +
- "inherited member `" + name + "'");
- ModFlags |= Modifiers.NEW;
- }
- }
- }
-
- return ok;
- }
-
public abstract bool Define (TypeContainer parent);
//
}
}
- //
- // FIXME: This is temporary outside DeclSpace, because I have to fix a bug
- // in MCS that makes it fail the lookup for the enum
- //
+ /// <summary>
+ /// Base class for structs, classes, enumerations and interfaces.
+ /// </summary>
+ /// <remarks>
+ /// They all create new declaration spaces. This
+ /// provides the common foundation for managing those name
+ /// spaces.
+ /// </remarks>
+ public abstract class DeclSpace : MemberCore {
+ /// <summary>
+ /// this points to the actual definition that is being
+ /// created with System.Reflection.Emit
+ /// </summary>
+ public TypeBuilder TypeBuilder;
+
+ /// <summary>
+ /// This variable tracks whether we have Closed the type
+ /// </summary>
+ public bool Created = false;
+
+ //
+ // This is the namespace in which this typecontainer
+ // was declared. We use this to resolve names.
+ //
+ public NamespaceEntry NamespaceEntry;
+
+ public Hashtable Cache = new Hashtable ();
+
+ public string Basename;
+
+ /// <summary>
+ /// defined_names is used for toplevel objects
+ /// </summary>
+ protected Hashtable defined_names;
+
+ TypeContainer parent;
+
+ public DeclSpace (NamespaceEntry ns, TypeContainer parent, string name, Location l)
+ : base (name, l)
+ {
+ NamespaceEntry = ns;
+ Basename = name.Substring (1 + name.LastIndexOf ('.'));
+ defined_names = new Hashtable ();
+ this.parent = parent;
+
+ if ((NamespaceEntry != null) && (parent == RootContext.Tree.Types))
+ NamespaceEntry.DefineName (Basename, this);
+ }
/// <summary>
/// The result value from adding an declaration into
Error
}
- /// <summary>
- /// Base class for structs, classes, enumerations and interfaces.
- /// </summary>
- /// <remarks>
- /// They all create new declaration spaces. This
- /// provides the common foundation for managing those name
- /// spaces.
- /// </remarks>
- public abstract class DeclSpace : MemberCore {
- /// <summary>
- /// this points to the actual definition that is being
- /// created with System.Reflection.Emit
- /// </summary>
- public TypeBuilder TypeBuilder;
-
- /// <summary>
- /// This variable tracks whether we have Closed the type
- /// </summary>
- public bool Created = false;
-
- //
- // This is the namespace in which this typecontainer
- // was declared. We use this to resolve names.
- //
- public NamespaceEntry NamespaceEntry;
-
- public Hashtable Cache = new Hashtable ();
-
- public string Basename;
-
- /// <summary>
- /// defined_names is used for toplevel objects
- /// </summary>
- protected Hashtable defined_names;
-
- TypeContainer parent;
-
- public DeclSpace (TypeContainer parent, string name, Location l)
- : base (name, l)
- {
- Basename = name.Substring (1 + name.LastIndexOf ('.'));
- defined_names = new Hashtable ();
- this.parent = parent;
- }
-
/// <summary>
/// Returns a status code based purely on the name
/// of the member being added
// Attempt to lookup the class on our namespace and all it's implicit parents
//
for (NamespaceEntry ns = NamespaceEntry; ns != null; ns = ns.ImplicitParent) {
- t = LookupInterfaceOrClass (ns.Name, name, out error);
+ t = LookupInterfaceOrClass (ns.FullName, name, out error);
if (error)
return null;
for (NamespaceEntry ns = NamespaceEntry; ns != null; ns = ns.Parent){
- t = LookupInterfaceOrClass (ns.Name, name, out error);
+ t = LookupInterfaceOrClass (ns.FullName, name, out error);
if (error)
return null;
Modifiers.UNSAFE |\r
Modifiers.PRIVATE;\r
\r
- public Delegate (TypeContainer parent, Expression type, int mod_flags,\r
- string name, Parameters param_list,\r
+ public Delegate (NamespaceEntry ns, TypeContainer parent, Expression type,\r
+ int mod_flags, string name, Parameters param_list,\r
Attributes attrs, Location l)\r
- : base (parent, name, l)\r
+ : base (ns, parent, name, l)\r
{\r
this.ReturnType = type;\r
ModFlags = Modifiers.Check (AllowedModifiers, mod_flags,\r
Modifiers.INTERNAL |
Modifiers.PRIVATE;
- public Enum (TypeContainer parent, Expression type, int mod_flags, string name, Attributes attrs, Location l)
- : base (parent, name, l)
+ public Enum (NamespaceEntry ns, TypeContainer parent, Expression type, int mod_flags,
+ string name, Attributes attrs, Location l)
+ : base (ns, parent, name, l)
{
this.BaseType = type;
ModFlags = Modifiers.Check (AllowedModifiers, mod_flags,
Modifiers.UNSAFE |
Modifiers.PRIVATE;
- public Interface (TypeContainer parent, string name, int mod, Attributes attrs, Location l)
- : base (parent, name, l)
+ public Interface (NamespaceEntry ns, TypeContainer parent, string name, int mod,
+ Attributes attrs, Location l)
+ : base (ns, parent, name, l)
{
ModFlags = Modifiers.Check (AllowedModifiers, mod, Modifiers.PRIVATE, l);
OptAttributes = attrs;
string name, fullname;
ArrayList entries;
Hashtable namespaces;
+ Hashtable defined_names;
/// <summary>
/// Constructor Takes the current namespace and the
entries = new ArrayList ();
namespaces = new Hashtable ();
+ defined_names = new Hashtable ();
all_namespaces.Add (this);
if (namespaces_map.Contains (fullname))
public object Lookup (DeclSpace ds, string name)
{
+ object o = Lookup (name);
+
+ Type t;
+ DeclSpace tdecl = o as DeclSpace;
+ if (tdecl != null) {
+ t = tdecl.DefineType ();
+
+ if ((ds == null) || ds.CheckAccessLevel (t))
+ return t;
+ }
+
Namespace ns = GetNamespace (name, false);
if (ns != null)
return ns;
- Type t = TypeManager.LookupType (DeclSpace.MakeFQN (fullname, name));
+ t = TypeManager.LookupType (DeclSpace.MakeFQN (fullname, name));
if ((t == null) || ((ds != null) && !ds.CheckAccessLevel (t)))
return null;
entries.Add (entry);
}
+ public void DefineName (string name, object o)
+ {
+ defined_names.Add (name, o);
+ }
+
+ public object Lookup (string name)
+ {
+ return defined_names [name];
+ }
+
static public ArrayList UserDefinedNamespaces {
get {
return all_namespaces;
}
}
- public NamespaceEntry (NamespaceEntry parent, SourceFile file, string name)
- : this (parent, file, name, false)
+ public NamespaceEntry (NamespaceEntry parent, SourceFile file, string name, Location loc)
+ : this (parent, file, name, false, loc)
{ }
- protected NamespaceEntry (NamespaceEntry parent, SourceFile file, string name, bool is_implicit)
+ protected NamespaceEntry (NamespaceEntry parent, SourceFile file, string name, bool is_implicit, Location loc)
{
this.parent = parent;
this.file = file;
ns.AddNamespaceEntry (this);
if ((parent != null) && (parent.NS != ns.Parent))
- implicit_parent = new NamespaceEntry (parent, file, ns.Parent.Name, true);
+ implicit_parent = new NamespaceEntry (parent, file, ns.Parent.Name, true, loc);
else
implicit_parent = parent;
+
+ this.FullName = ns.Name;
}
static int next_id = 0;
+ public readonly string FullName;
public readonly int ID;
public readonly bool IsImplicit;
- public string Name {
- get {
- return ns.Name;
- }
- }
-
public Namespace NS {
get {
return ns;
}
}
+ public void DefineName (string name, object o)
+ {
+ ns.DefineName (name, o);
+ }
+
/// <summary>
/// Records a new namespace for resolving name references
/// </summary>
return;
}
- if (ns == Name)
+ if (ns == FullName)
return;
if (using_clauses == null)
if (NS == Namespace.Root)
return "NamespaceEntry (<root>)";
else
- return String.Format ("NamespaceEntry ({0},{1},{2})", Name, IsImplicit, ID);
+ return String.Format ("NamespaceEntry ({0},{1},{2})", FullName, IsImplicit, ID);
}
}
}
//
if (global_attributes.Count > 0){
AssemblyBuilder ab = CodeGen.AssemblyBuilder;
- TypeContainer dummy = new TypeContainer (null, "", new Location (-1));
+ TypeContainer dummy = new TypeContainer (null, null, "", new Location (-1));
EmitContext temp_ec = new EmitContext (
dummy, Mono.CSharp.Location.Null, null, null, 0, false);
public Tree ()
{
- root_types = new TypeContainer (null, "", new Location (-1));
+ root_types = new TypeContainer (null, null, "", new Location (-1));
decls = new Hashtable ();
namespaces = new Hashtable ();
return (DeclSpace) res;
}
- public NamespaceEntry RecordNamespace (NamespaceEntry parent, SourceFile file, string name)
+ public NamespaceEntry RecordNamespace (NamespaceEntry parent, SourceFile file, string name, Location loc)
{
- NamespaceEntry ns = new NamespaceEntry (parent, file, name);
+ NamespaceEntry ns = new NamespaceEntry (parent, file, name, loc);
if (namespaces.Contains (file)){
Hashtable ns_ns = (Hashtable) namespaces [file];
- if (ns_ns.Contains (ns.Name))
- return (NamespaceEntry) ns_ns [ns.Name];
- ns_ns.Add (ns.Name, ns);
+ if (ns_ns.Contains (ns.FullName))
+ return (NamespaceEntry) ns_ns [ns.FullName];
+ ns_ns.Add (ns.FullName, ns);
} else {
Hashtable new_table = new Hashtable ();
namespaces [file] = new_table;
- new_table.Add (ns.Name, ns);
+ new_table.Add (ns.FullName, ns);
}
return ns;