Backported my MemberName changes from GMCS into MCS.
- we are now using a special `MemberName' class instead of using
strings; in GMCS, the `MemberName' also contains the type
arguments.
- changed the grammar rules a bit:
* the old `member_name' is now a `namespace_or_type_name':
The rule is that we use `namespace_or_type_name' everywhere
where we expect either a "member name" (GetEnumerator) or a
"member name" with an explicit interface name
(IEnumerable.GetEnumerator).
In GMCS, the explicit interface name may include type arguments
(IEnumerable<T>.GetEnumerator).
* we use `member_name' instead of just `IDENTIFIER' for
"member names":
The rule is that we use `member_name' wherever a member may
have type parameters in GMCS.
* decl.cs (MemberName): New public class.
(MemberCore.MemberName): New public readonly field.
(MemberCore.ctor): Take a `MemberName' argument, not a string.
(DeclSpace): Likewise.
* delegate.cs (Delegate.ctor): Take a MemberName, not a string.
* enum.cs (Enum.ctor): Likewise.
* namespace.cs (AliasEntry.Alias): Changed type from Expression to
MemberName.
(AliasEntry.ctor): Take a MemberName, not an Expression.
(AliasEntry.UsingAlias): Likewise.
* class.cs (TypeContainer.ctor): Take a MemberName, not a string.
(IMethodData.MemberName): Changed type from string to MemberName.
(MemberBase.ExplicitInterfaceName): Likewise.
(AbstractPropertyEventMethod.SetupName): Make this private.
(AbstractPropertyEventMethod.ctor): Added `string prefix'
argument; compute the member name here.
(AbstractPropertyEventMethod.UpdateName): Recompute the name based
on the `member.MemberName' and the `prefix'.
* cs-parser.jay (attribute_name): Use `namespace_or_type_name',
not `type_name'.
(struct_declaration): Use `member_name' instead of `IDENTIFIER';
thus, we get a `MemberName' instead of a `string'. These
declarations may have type parameters in GMCS.
(interface_method_declaration, delegate_declaration): Likewise.
(class_declaration, interface_declaration): Likewise.
(method_header): Use `namespace_or_type_name' instead of
`member_name'. We may be an explicit interface implementation.
(property_declaration, event_declaration): Likewise.
(member_name): This is now just an `IDENTIFIER', not a
`namespace_or_type_name'.
(type_name, interface_type): Removed.
(namespace_or_type_name): Return a MemberName, not an Expression.
(primary_expression): Use `member_name' instead of `IDENTIFIER';
call GetTypeExpression() on the MemberName to get an expression.
(IndexerDeclaration.interface_type): Changed type from string to
MemberName.
(MakeName): Operate on MemberName's instead of string's.
svn path=/trunk/mcs/; revision=33810
+2004-09-10 Martin Baulig <martin@ximian.com>
+
+ Backported my MemberName changes from GMCS into MCS.
+
+ - we are now using a special `MemberName' class instead of using
+ strings; in GMCS, the `MemberName' also contains the type
+ arguments.
+
+ - changed the grammar rules a bit:
+ * the old `member_name' is now a `namespace_or_type_name':
+ The rule is that we use `namespace_or_type_name' everywhere
+ where we expect either a "member name" (GetEnumerator) or a
+ "member name" with an explicit interface name
+ (IEnumerable.GetEnumerator).
+ In GMCS, the explicit interface name may include type arguments
+ (IEnumerable<T>.GetEnumerator).
+ * we use `member_name' instead of just `IDENTIFIER' for
+ "member names":
+ The rule is that we use `member_name' wherever a member may
+ have type parameters in GMCS.
+
+ * decl.cs (MemberName): New public class.
+ (MemberCore.MemberName): New public readonly field.
+ (MemberCore.ctor): Take a `MemberName' argument, not a string.
+ (DeclSpace): Likewise.
+
+ * delegate.cs (Delegate.ctor): Take a MemberName, not a string.
+ * enum.cs (Enum.ctor): Likewise.
+
+ * namespace.cs (AliasEntry.Alias): Changed type from Expression to
+ MemberName.
+ (AliasEntry.ctor): Take a MemberName, not an Expression.
+ (AliasEntry.UsingAlias): Likewise.
+
+ * class.cs (TypeContainer.ctor): Take a MemberName, not a string.
+ (IMethodData.MemberName): Changed type from string to MemberName.
+ (MemberBase.ExplicitInterfaceName): Likewise.
+ (AbstractPropertyEventMethod.SetupName): Make this private.
+ (AbstractPropertyEventMethod.ctor): Added `string prefix'
+ argument; compute the member name here.
+ (AbstractPropertyEventMethod.UpdateName): Recompute the name based
+ on the `member.MemberName' and the `prefix'.
+
+ * cs-parser.jay (attribute_name): Use `namespace_or_type_name',
+ not `type_name'.
+ (struct_declaration): Use `member_name' instead of `IDENTIFIER';
+ thus, we get a `MemberName' instead of a `string'. These
+ declarations may have type parameters in GMCS.
+ (interface_method_declaration, delegate_declaration): Likewise.
+ (class_declaration, interface_declaration): Likewise.
+ (method_header): Use `namespace_or_type_name' instead of
+ `member_name'. We may be an explicit interface implementation.
+ (property_declaration, event_declaration): Likewise.
+ (member_name): This is now just an `IDENTIFIER', not a
+ `namespace_or_type_name'.
+ (type_name, interface_type): Removed.
+ (namespace_or_type_name): Return a MemberName, not an Expression.
+ (primary_expression): Use `member_name' instead of `IDENTIFIER';
+ call GetTypeExpression() on the MemberName to get an expression.
+ (IndexerDeclaration.interface_type): Changed type from string to
+ MemberName.
+ (MakeName): Operate on MemberName's instead of string's.
+
2004-09-13 Raja R Harinath <rharinath@novell.com>
Fix bug #55770.
public const string DefaultIndexerName = "Item";
- public TypeContainer (NamespaceEntry ns, TypeContainer parent, string name,
+ public TypeContainer (NamespaceEntry ns, TypeContainer parent, MemberName name,
Attributes attrs, Kind kind, Location l)
: base (ns, parent, name, attrs, l)
{
public readonly TypeAttributes DefaultTypeAttributes;
static PartialContainer Create (NamespaceEntry ns, TypeContainer parent,
- string name, int mod_flags, Kind kind,
+ MemberName name, int mod_flags, Kind kind,
Location loc)
{
PartialContainer pc;
- DeclSpace ds = (DeclSpace) RootContext.Tree.Decls [name];
+ string full_name = name.GetName (true);
+ DeclSpace ds = (DeclSpace) RootContext.Tree.Decls [full_name];
if (ds != null) {
pc = ds as PartialContainer;
}
pc = new PartialContainer (ns, parent, name, mod_flags, kind, loc);
- RootContext.Tree.RecordDecl (name, pc);
+ RootContext.Tree.RecordDecl (full_name, pc);
parent.AddType (pc);
pc.Register ();
return pc;
}
public static ClassPart CreatePart (NamespaceEntry ns, TypeContainer parent,
- string name, int mod, Attributes attrs,
+ MemberName name, int mod, Attributes attrs,
Kind kind, Location loc)
{
PartialContainer pc = Create (ns, parent, name, mod, kind, loc);
}
protected PartialContainer (NamespaceEntry ns, TypeContainer parent,
- string name, int mod, Kind kind, Location l)
+ MemberName name, int mod, Kind kind, Location l)
: base (ns, parent, name, null, kind, l)
{
this.Namespace = ns.NS;
public ClassPart (NamespaceEntry ns, PartialContainer parent,
int mod, Attributes attrs, Kind kind, Location l)
- : base (ns, parent.Parent, parent.Name, attrs, kind, l)
+ : base (ns, parent.Parent, parent.MemberName, attrs, kind, l)
{
this.PartialContainer = parent;
this.IsPartial = true;
bool hasExplicitLayout = false;
public ClassOrStruct (NamespaceEntry ns, TypeContainer parent,
- string name, Attributes attrs, Kind kind,
+ MemberName name, Attributes attrs, Kind kind,
Location l)
: base (ns, parent, name, attrs, kind, l)
{
/// Class handles static classes declaration
/// </summary>
public sealed class StaticClass: Class {
- public StaticClass (NamespaceEntry ns, TypeContainer parent, string name, int mod,
+ public StaticClass (NamespaceEntry ns, TypeContainer parent, MemberName name, int mod,
Attributes attrs, Location l)
: base (ns, parent, name, mod & ~Modifiers.STATIC, attrs, l)
{
// Information in the case we are an attribute type
AttributeUsageAttribute attribute_usage;
- public Class (NamespaceEntry ns, TypeContainer parent, string name, int mod,
+ public Class (NamespaceEntry ns, TypeContainer parent, MemberName name, int mod,
Attributes attrs, Location l)
: base (ns, parent, name, attrs, Kind.Class, l)
{
Modifiers.UNSAFE |
Modifiers.PRIVATE;
- public Struct (NamespaceEntry ns, TypeContainer parent, string name,
+ public Struct (NamespaceEntry ns, TypeContainer parent, MemberName name,
int mod, Attributes attrs, Location l)
: base (ns, parent, name, attrs, Kind.Struct, l)
{
Modifiers.UNSAFE |
Modifiers.PRIVATE;
- public Interface (NamespaceEntry ns, TypeContainer parent, string name, int mod,
+ public Interface (NamespaceEntry ns, TypeContainer parent, MemberName name, int mod,
Attributes attrs, Location l)
: base (ns, parent, name, attrs, Kind.Interface, l)
{
static string[] attribute_targets = new string [] { "method", "return" };
public MethodCore (TypeContainer parent, Expression type, int mod,
- int allowed_mod, bool is_interface, string name,
+ int allowed_mod, bool is_interface, MemberName name,
Attributes attrs, Parameters parameters, Location loc)
: base (parent, type, mod, allowed_mod, Modifiers.PRIVATE, name,
attrs, loc)
// return_type can be "null" for VOID values.
//
public Method (TypeContainer ds, Expression return_type, int mod, bool is_iface,
- string name, Parameters parameters, Attributes attrs, Location l)
+ MemberName name, Parameters parameters, Attributes attrs,
+ Location l)
: base (ds, return_type, mod,
is_iface ? AllowedInterfaceModifiers : AllowedModifiers,
is_iface, name, attrs, parameters, l)
}
}
- public string MethodName {
+ public MemberName MethodName {
get {
- return Name;
+ return MemberName;
}
}
//
public Constructor (TypeContainer ds, string name, int mod, Parameters args,
ConstructorInitializer init, Location l)
- : base (ds, null, mod, AllowedModifiers, false, name, null, args, l)
+ : base (ds, null, mod, AllowedModifiers, false, new MemberName (name),
+ null, args, l)
{
Initializer = init;
}
}
}
- public string MethodName {
+ public MemberName MethodName {
get {
- return Name;
+ return MemberName;
}
}
{
CallingConventions CallingConventions { get; }
Location Location { get; }
- string MethodName { get; }
+ MemberName MethodName { get; }
Type[] ParameterTypes { get; }
Type ReturnType { get; }
{
MethodInfo implementing = null;
- string method_name = method.MethodName;
- string name;
- if (member.IsExplicitImpl) {
- name = method_name.Remove (0, member.InterfaceType.FullName.Length + 1);
- } else {
- name = method_name;
- }
+ string method_name = method.MethodName.GetFullName ();
+ string name = method.MethodName.Name;
Type[] ParameterTypes = method.ParameterTypes;
public class Destructor : Method {
- public Destructor (TypeContainer ds, Expression return_type, int mod, string name,
- Parameters parameters, Attributes attrs, Location l)
- : base (ds, return_type, mod, false, name, parameters, attrs, l)
+ public Destructor (TypeContainer ds, Expression return_type, int mod,
+ string name, Parameters parameters, Attributes attrs,
+ Location l)
+ : base (ds, return_type, mod, false, new MemberName (name),
+ parameters, attrs, l)
{ }
public override void ApplyAttributeBuilder(Attribute a, CustomAttributeBuilder cb)
//
// The name of the interface we are explicitly implementing
//
- public string ExplicitInterfaceName = null;
+ public MemberName ExplicitInterfaceName = null;
//
// Whether this is an interface member.
// The constructor is only exposed to our children
//
protected MemberBase (TypeContainer parent, Expression type, int mod,
- int allowed_mod, int def_mod, string name,
+ int allowed_mod, int def_mod, MemberName name,
Attributes attrs, Location loc)
: base (parent, name, attrs, loc)
{
ModFlags = Modifiers.Check (allowed_mod, mod, def_mod, loc);
// Check for explicit interface implementation
- int pos = Name.LastIndexOf ('.');
- if (pos != -1) {
- ExplicitInterfaceName = Name.Substring (0, pos);
- ShortName = Name.Substring (pos + 1);
+ if (MemberName.Left != null) {
+ ExplicitInterfaceName = MemberName.Left;
+ ShortName = MemberName.Name;
IsExplicitImpl = true;
} else
ShortName = Name;
protected virtual bool DoDefine ()
{
if (Name == null)
- Name = "this";
+ throw new InternalErrorException ();
if (IsInterface) {
ModFlags = Modifiers.PUBLIC |
return false;
if (IsExplicitImpl) {
- int errors = Report.Errors;
-
- InterfaceType = Parent.FindType (
- Location, ExplicitInterfaceName);
-
- if (Report.Errors != errors)
- return false;
- else if (InterfaceType == null) {
- Report.Error (246, Location, "Can not find type `{0}'",
- ExplicitInterfaceName);
- return false;
- }
-
+ InterfaceType = Parent.ResolveType (
+ ExplicitInterfaceName.GetTypeExpression (Location),
+ false, Location);
if (InterfaceType == null)
return false;
return false;
}
+#if FIXME
// Compute the full name that we need to export.
if (InterfaceType.FullName != ExplicitInterfaceName) {
ExplicitInterfaceName = InterfaceType.FullName;
UpdateMemberName ();
}
+#endif
if (!Parent.VerifyImplements (InterfaceType, ShortName, Name, Location))
return false;
/// </summary>
protected virtual void UpdateMemberName ()
{
- if (IsExplicitImpl)
- Name = String.Concat (ExplicitInterfaceName, ".", ShortName);
- else
- Name = ShortName;
+ MemberName.Name = ShortName;
}
public override string GetSignatureForError (TypeContainer tc)
// The constructor is only exposed to our children
//
protected FieldBase (TypeContainer parent, Expression type, int mod,
- int allowed_mod, string name, object init,
+ int allowed_mod, MemberName name, object init,
Attributes attrs, Location loc)
: base (parent, type, mod, allowed_mod, Modifiers.PRIVATE,
name, attrs, loc)
public Field (TypeContainer parent, Expression type, int mod, string name,
Object expr_or_array_init, Attributes attrs, Location loc)
- : base (parent, type, mod, AllowedModifiers, name, expr_or_array_init,
- attrs, loc)
+ : base (parent, type, mod, AllowedModifiers, new MemberName (name),
+ expr_or_array_init, attrs, loc)
{
}
// Field says whether accessor will be emited or not
public readonly bool IsDummy;
+ protected readonly string prefix;
+
ReturnParameter return_attributes;
- public AbstractPropertyEventMethod (string name, Location loc):
- base (null, name, null, loc)
+ public AbstractPropertyEventMethod (MemberBase member, string prefix)
+ : base (null, SetupName (prefix, member), null, member.Location)
{
+ this.prefix = prefix;
IsDummy = true;
}
- public AbstractPropertyEventMethod (Accessor accessor, string name):
- base (null, name, accessor.Attributes, accessor.Location)
+ public AbstractPropertyEventMethod (MemberBase member, Accessor accessor,
+ string prefix)
+ : base (null, SetupName (prefix, member),
+ accessor.Attributes, accessor.Location)
{
+ this.prefix = prefix;
this.block = accessor.Block;
}
- protected static string SetupName (string prefix, MemberBase member)
+ static MemberName SetupName (string prefix, MemberBase member)
{
- if (member.IsExplicitImpl) {
- return String.Concat (member.ExplicitInterfaceName, '.', prefix, member.ShortName);
- }
-
- return String.Concat (prefix, member.Name);
+ MemberName name = member.MemberName.Clone ();
+ name.Name = prefix + member.ShortName;
+ return name;
}
public void UpdateName (MemberBase member)
{
- int start = Name.LastIndexOf ('.');
- start++;
- string prefix = Name.Substring (start, (Name.LastIndexOf ('_') + 1) - start);
- base.Name = SetupName (prefix, member);
+ MemberName.Name = prefix + member.ShortName;
}
#region IMethodData Members
return false;
}
- public string MethodName {
+ public MemberName MethodName {
get {
- return Name;
+ return MemberName;
}
}
{
protected readonly MethodCore method;
- public PropertyMethod (MethodCore method, string prefix):
- base (SetupName (prefix, method), method.Location)
+ public PropertyMethod (MethodCore method, string prefix)
+ : base (method, prefix)
{
this.method = method;
}
- public PropertyMethod (MethodCore method, Accessor accessor, string prefix):
- base (accessor, SetupName (prefix, method))
+ public PropertyMethod (MethodCore method, Accessor accessor,
+ string prefix)
+ : base (method, accessor, prefix)
{
this.method = method;
}
protected EmitContext ec;
public PropertyBase (TypeContainer ds, Expression type, int mod_flags,
- int allowed_mod, bool is_iface, string name,
+ int allowed_mod, bool is_iface, MemberName name,
Parameters parameters, Attributes attrs,
Location loc)
: base (ds, type, mod_flags, allowed_mod, is_iface, name,
Modifiers.NEW;
public Property (TypeContainer ds, Expression type, int mod, bool is_iface,
- string name, Attributes attrs, Accessor get_block,
+ MemberName name, Attributes attrs, Accessor get_block,
Accessor set_block, Location loc)
: base (ds, type, mod,
is_iface ? AllowedInterfaceModifiers : AllowedModifiers,
static string[] attribute_targets = new string [] { "event", "property" };
public EventProperty (TypeContainer parent, Expression type, int mod_flags,
- bool is_iface, string name, Object init,
+ bool is_iface, MemberName name, Object init,
Attributes attrs, Accessor add, Accessor remove,
Location loc)
: base (parent, type, mod_flags, is_iface, name, init, attrs, loc)
static string[] attribute_targets = new string [] { "event", "field", "method" };
public EventField (TypeContainer parent, Expression type, int mod_flags,
- bool is_iface, string name, Object init,
+ bool is_iface, MemberName name, Object init,
Attributes attrs, Location loc)
: base (parent, type, mod_flags, is_iface, name, init, attrs, loc)
{
static string[] attribute_targets = new string [] { "method", "param", "return" };
- public DelegateMethod (Event method, string prefix):
- base (SetupName (prefix, method), method.Location)
+ public DelegateMethod (Event method, string prefix)
+ : base (method, prefix)
{
this.method = method;
}
- public DelegateMethod (Event method, Accessor accessor, string prefix):
- base (accessor, SetupName (prefix, method))
+ public DelegateMethod (Event method, Accessor accessor, string prefix)
+ : base (method, accessor, prefix)
{
this.method = method;
}
public MethodBuilder AddBuilder, RemoveBuilder;
public Event (TypeContainer parent, Expression type, int mod_flags,
- bool is_iface, string name, Object init, Attributes attrs,
+ bool is_iface, MemberName name, Object init, Attributes attrs,
Location loc)
: base (parent, type, mod_flags,
is_iface ? AllowedInterfaceModifiers : AllowedModifiers,
Modifiers.NEW;
- public Indexer (TypeContainer ds, Expression type, string int_type, int mod,
+ public Indexer (TypeContainer ds, Expression type, MemberName name, int mod,
bool is_iface, Parameters parameters, Attributes attrs,
Accessor get_block, Accessor set_block, Location loc)
: base (ds, type, mod,
is_iface ? AllowedInterfaceModifiers : AllowedModifiers,
- is_iface, int_type, parameters, attrs, loc)
+ is_iface, name, parameters, attrs, loc)
{
if (get_block == null)
Get = new GetIndexerMethod (this);
public Operator (TypeContainer parent, OpType type, Expression ret_type,
int mod_flags, Parameters parameters,
Block block, Attributes attrs, Location loc)
- : base (parent, ret_type, mod_flags, AllowedModifiers, false, "op_" + type,
- attrs, parameters, loc)
+ : base (parent, ret_type, mod_flags, AllowedModifiers, false,
+ new MemberName ("op_" + type), attrs, parameters, loc)
{
OperatorType = type;
Block = block;
return false;
OperatorMethod = new Method (
- Parent, Type, ModFlags, false, Name,
- Parameters,
- OptAttributes, Location);
+ Parent, Type, ModFlags, false, MemberName,
+ Parameters, OptAttributes, Location);
OperatorMethod.Block = Block;
OperatorMethod.IsOperator = true;
public Const (TypeContainer parent, Expression constant_type, string name,
Expression expr, int mod_flags, Attributes attrs, Location loc)
- : base (parent, constant_type, mod_flags, AllowedModifiers, name,
- null, attrs, loc)
+ : base (parent, constant_type, mod_flags, AllowedModifiers,
+ new MemberName (name), null, attrs, loc)
{
Expr = expr;
}
: USING IDENTIFIER ASSIGN
namespace_or_type_name SEMICOLON
{
- current_namespace.UsingAlias ((string) $2, (Expression) $4, lexer.Location);
+ current_namespace.UsingAlias ((string) $2, (MemberName) $4, lexer.Location);
}
| USING error {
CheckIdentifierToken (yyToken);
Report.Error(1518, Lexer.Location, "Attributes cannot be applied to namespaces."
+ " Expected class, delegate, enum, interface, or struct");
}
-
- if (current_namespace.Parent != null && $3 is MemberAccess) {
- // Cannot use qualified namespace names in nested namespace declarations
- Report.Error (134, lexer.Location, "Cannot use qualified namespace names in nested namespace declarations");
+
+ MemberName name = (MemberName) $3;
+
+ if ((current_namespace.Parent != null) && (name.Left != null)) {
+ Report.Error (134, lexer.Location,
+ "Cannot use qualified namespace names in nested " +
+ "namespace declarations");
}
current_namespace = new NamespaceEntry (
- current_namespace, file, $3.ToString (), lexer.Location);
+ current_namespace, file, name.GetName (false), lexer.Location);
}
namespace_body opt_semicolon
{
;
namespace_name
- : namespace_or_type_name { $$ = ($1).ToString (); }
+ : namespace_or_type_name {
+ MemberName name = (MemberName) $1;
+
+ $$ = name.GetName (false);
+ }
;
namespace_body
;
attribute_name
- : type_name { /* reserved attribute name or identifier: 17.4 */ }
+ : namespace_or_type_name { /* reserved attribute name or identifier: 17.4 */ }
;
opt_attribute_arguments
: opt_attributes
opt_modifiers
opt_partial
- STRUCT IDENTIFIER
+ STRUCT member_name
{
- string name = MakeName ((string) $5);
+ MemberName name = MakeName ((MemberName) $5);
bool partial = (bool) $3;
if (partial) {
(Attributes) $1, lexer.Location);
current_container = current_class;
- RootContext.Tree.RecordDecl (name, current_class);
+ RootContext.Tree.RecordDecl (name.GetName (true), current_class);
}
}
opt_class_base
method_header
: opt_attributes
opt_modifiers
- type
- member_name
+ type namespace_or_type_name
OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
{
+ MemberName name = (MemberName) $4;
+
Method method = new Method (current_class, (Expression) $3, (int) $2,
- false, (string) $4, (Parameters) $6,
- (Attributes) $1, lexer.Location);
+ false, name, (Parameters) $6, (Attributes) $1,
+ lexer.Location);
current_local_parameters = (Parameters) $6;
}
| opt_attributes
opt_modifiers
- VOID
- member_name
+ VOID namespace_or_type_name
OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
{
+ MemberName name = (MemberName) $4;
+
Method method = new Method (current_class, TypeManager.system_void_expr,
- (int) $2, false, (string) $4, (Parameters) $6,
+ (int) $2, false, name, (Parameters) $6,
(Attributes) $1, lexer.Location);
current_local_parameters = (Parameters) $6;
| opt_attributes
opt_modifiers
type
- modifiers member_name OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
+ modifiers namespace_or_type_name OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
{
Report.Error (1585, lexer.Location,
String.Format ("Modifier {0} should appear before type",
Modifiers.Name ((int) $4)));
+ MemberName name = (MemberName) $4;
+
Method method = new Method (current_class, TypeManager.system_void_expr,
- 0, false, (string) $5, (Parameters) $7,
- (Attributes) $1, lexer.Location);
+ 0, false, name, (Parameters) $7, (Attributes) $1,
+ lexer.Location);
current_local_parameters = (Parameters) $7;
$$ = method;
}
;
-member_name
- : namespace_or_type_name { $$ = ($1).ToString (); }
- ;
-
property_declaration
: opt_attributes
opt_modifiers
- type member_name
+ type namespace_or_type_name
OPEN_BRACE
{
implicit_value_parameter_type = (Expression) $3;
Accessor set_block = (Accessor) pair.Second;
Location loc = (Location) $6;
+ MemberName name = (MemberName) $4;
+
prop = new Property (current_class, (Expression) $3, (int) $2, false,
- (string) $4, (Attributes) $1, get_block, set_block, loc);
+ name, (Attributes) $1, get_block, set_block, loc);
if (SimpleIteratorContainer.Simple.Yields)
prop.SetYields ();
: opt_attributes
opt_modifiers
opt_partial
- INTERFACE IDENTIFIER
+ INTERFACE member_name
{
- string name = MakeName ((string) $5);
+ MemberName name = MakeName ((MemberName) $5);
bool partial = (bool) $3;
if (partial) {
(Attributes) $1, lexer.Location);
current_container = current_class;
- RootContext.Tree.RecordDecl (name, current_class);
+ RootContext.Tree.RecordDecl (name.GetName (true), current_class);
}
}
opt_class_base
;
interface_method_declaration
- : opt_attributes opt_new type IDENTIFIER
+ : opt_attributes opt_new type namespace_or_type_name
OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
SEMICOLON
{
+ MemberName name = (MemberName) $4;
+
$$ = new Method (current_class, (Expression) $3, (int) $2, true,
- (string) $4, (Parameters) $6, (Attributes) $1,
- lexer.Location);
+ name, (Parameters) $6, (Attributes) $1, lexer.Location);
}
- | opt_attributes opt_new VOID IDENTIFIER
+ | opt_attributes opt_new VOID namespace_or_type_name
OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
SEMICOLON
{
+ MemberName name = (MemberName) $4;
+
$$ = new Method (current_class, TypeManager.system_void_expr, (int) $2,
- true, (string) $4, (Parameters) $6, (Attributes) $1,
- lexer.Location);
+ true, name, (Parameters) $6, (Attributes) $1, lexer.Location);
}
;
InterfaceAccessorInfo pinfo = (InterfaceAccessorInfo) $7;
$$ = new Property (current_class, (Expression) $3, (int) $2, true,
- (string) $4, (Attributes) $1, pinfo.Get, pinfo.Set,
- lexer.Location);
+ new MemberName ((string) $4), (Attributes) $1,
+ pinfo.Get, pinfo.Set, lexer.Location);
}
| opt_attributes
opt_new
interface_event_declaration
: opt_attributes opt_new EVENT type IDENTIFIER SEMICOLON
{
- $$ = new EventField (current_class, (Expression) $4, (int) $2, true, (string) $5, null,
- (Attributes) $1, lexer.Location);
+ $$ = new EventField (current_class, (Expression) $4, (int) $2, true,
+ new MemberName ((string) $5), null,
+ (Attributes) $1, lexer.Location);
}
| opt_attributes opt_new EVENT type error {
CheckIdentifierToken (yyToken);
{
InterfaceAccessorInfo info = (InterfaceAccessorInfo) $10;
- $$ = new Indexer (current_class, (Expression) $3, TypeContainer.DefaultIndexerName, (int) $2, true,
- (Parameters) $6, (Attributes) $1, info.Get, info.Set,
- lexer.Location);
+ $$ = new Indexer (current_class, (Expression) $3,
+ new MemberName (TypeContainer.DefaultIndexerName),
+ (int) $2, true, (Parameters) $6, (Attributes) $1,
+ info.Get, info.Set, lexer.Location);
}
;
{
foreach (VariableDeclaration var in (ArrayList) $5) {
- Event e = new EventField (current_class, (Expression) $4, (int) $2, false, var.identifier,
- var.expression_or_array_initializer,
- (Attributes) $1, lexer.Location);
+ MemberName name = new MemberName (var.identifier);
+
+ Event e = new EventField (
+ current_class, (Expression) $4, (int) $2, false, name,
+ var.expression_or_array_initializer, (Attributes) $1,
+ lexer.Location);
current_container.AddEvent (e);
}
| opt_attributes
opt_modifiers
- EVENT type member_name
+ EVENT type namespace_or_type_name
OPEN_BRACE
{
implicit_value_parameter_type = (Expression) $4;
} else {
Pair pair = (Pair) $8;
- Event e = new EventProperty (current_class, (Expression) $4, (int) $2, false, (string) $5,
- null, (Attributes) $1, (Accessor) pair.First, (Accessor) pair.Second,
- loc);
+ MemberName name = (MemberName) $5;
+
+ Event e = new EventProperty (
+ current_class, (Expression) $4, (int) $2, false, name, null,
+ (Attributes) $1, (Accessor) pair.First, (Accessor) pair.Second,
+ loc);
current_container.AddEvent (e);
implicit_value_parameter_type = null;
Pair pair = (Pair) $6;
Accessor get_block = (Accessor) pair.First;
Accessor set_block = (Accessor) pair.Second;
- string name = decl.interface_type;
- if (name != null)
- name += ".";
- name += TypeContainer.DefaultIndexerName;
+
+ MemberName name;
+ if (decl.interface_type != null)
+ name = new MemberName (decl.interface_type,
+ TypeContainer.DefaultIndexerName);
+ else
+ name = new MemberName (TypeContainer.DefaultIndexerName);
indexer = new Indexer (current_class, decl.type, name,
(int) $2, false, decl.param_list, (Attributes) $1,
} else if (pars.FixedParameters == null && pars.ArrayParameter == null){
Report.Error (1551, lexer.Location, "Indexers must have at least one parameter");
}
- $$ = new IndexerDeclaration ((Expression) $1, $2.ToString (), pars);
+ MemberName name = (MemberName) $2;
+ $$ = new IndexerDeclaration ((Expression) $1, name, pars);
}
;
{
Location enum_location = lexer.Location;
- string full_name = MakeName ((string) $4);
+ MemberName full_name = MakeName (new MemberName ((string) $4));
Enum e = new Enum (current_namespace, current_container, (Expression) $5, (int) $2,
full_name, (Attributes) $1, enum_location);
ev.Location, ev.OptAttributes);
}
+ string name = full_name.GetName (false);
current_container.AddEnum (e);
- RootContext.Tree.RecordDecl (full_name, e);
+ RootContext.Tree.RecordDecl (name, e);
}
;
delegate_declaration
: opt_attributes
opt_modifiers
- DELEGATE type
- IDENTIFIER OPEN_PARENS
- opt_formal_parameter_list
- CLOSE_PARENS
+ DELEGATE type member_name
+ OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
SEMICOLON
{
Location l = lexer.Location;
- string name = MakeName ((string) $5);
+ MemberName name = MakeName ((MemberName) $5);
Delegate del = new Delegate (current_namespace, current_container, (Expression) $4,
(int) $2, name, (Parameters) $7, (Attributes) $1, l);
current_container.AddDelegate (del);
- RootContext.Tree.RecordDecl (name, del);
+ RootContext.Tree.RecordDecl (name.GetName (false), del);
}
| opt_attributes
opt_modifiers
- DELEGATE VOID
- IDENTIFIER OPEN_PARENS
- opt_formal_parameter_list
- CLOSE_PARENS
+ DELEGATE VOID member_name
+ OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
SEMICOLON
{
Location l = lexer.Location;
- string name = MakeName ((string) $5);
+ MemberName name = MakeName ((MemberName) $5);
Delegate del = new Delegate (
current_namespace, current_container,
TypeManager.system_void_expr, (int) $2, name,
(Parameters) $7, (Attributes) $1, l);
current_container.AddDelegate (del);
- RootContext.Tree.RecordDecl (name, del);
+ RootContext.Tree.RecordDecl (name.GetName (false), del);
}
;
-type_name
- : namespace_or_type_name
+namespace_or_type_name
+ : member_name
+ | namespace_or_type_name DOT IDENTIFIER {
+ $$ = new MemberName ((MemberName) $1, (string) $3);
+ }
;
-namespace_or_type_name
- : IDENTIFIER { $$ = new SimpleName ((string) $1, lexer.Location);}
- | namespace_or_type_name DOT IDENTIFIER {
- $$ = new MemberAccess ((Expression) $1, (string) $3, lexer.Location);
+member_name
+ : IDENTIFIER {
+ $$ = new MemberName ((string) $1);
}
;
* gets rid of a shift/reduce couple
*/
type
- : type_name { /* class_type */
- /*
- This does interfaces, delegates, struct_types, class_types,
- parent classes, and more! 4.2
- */
+ : namespace_or_type_name
+ {
+ $$ = ((MemberName) $1).GetTypeExpression (lexer.Location);
}
| builtin_types
| array_type
| VOID { $$ = TypeManager.system_void_expr; }
;
-interface_type
- : type_name
- ;
-
array_type
: type rank_specifiers
{
// 7.5.1: Literals
}
- | IDENTIFIER { $$ = new SimpleName ((string) $1, lexer.Location); }
+ | member_name
+ {
+ $$ = ((MemberName) $1).GetTypeExpression (lexer.Location);
+ }
| parenthesized_expression
| member_access
| invocation_expression
: opt_attributes
opt_modifiers
opt_partial
- CLASS IDENTIFIER
+ CLASS member_name
{
- string name = MakeName ((string) $5);
+ MemberName name = MakeName ((MemberName) $5);
bool partial = (bool) $3;
int mod_flags = (int) $2;
(Attributes) $1, lexer.Location);
}
current_container = current_class;
- RootContext.Tree.RecordDecl (name, current_class);
+ RootContext.Tree.RecordDecl (name.GetName (false), current_class);
}
}
opt_class_base
// </summary>
public class IndexerDeclaration {
public Expression type;
- public string interface_type;
+ public MemberName interface_type;
public Parameters param_list;
- public IndexerDeclaration (Expression type, string interface_type, Parameters param_list)
+ public IndexerDeclaration (Expression type, MemberName interface_type,
+ Parameters param_list)
{
this.type = type;
this.interface_type = interface_type;
// Given the @class_name name, it creates a fully qualified name
// based on the containing declaration space
// </summary>
-string
-MakeName (string class_name)
+MemberName
+MakeName (MemberName class_name)
{
string ns = current_namespace.FullName;
- string container_name = current_container.Name;
- if (container_name == ""){
+ if (current_container.Name == ""){
if (ns != "")
- return ns + "." + class_name;
+ return new MemberName (new MemberName (ns), class_name);
else
return class_name;
- } else
- return container_name + "." + class_name;
+ } else {
+ return new MemberName (current_container.MemberName, class_name);
+ }
}
Block declare_local_variables (Expression type, ArrayList variable_declarators, Location loc)
namespace Mono.CSharp {
+ public class MemberName {
+ public string Name;
+ public readonly MemberName Left;
+
+ public static readonly MemberName Null = new MemberName ("");
+
+ public MemberName (string name)
+ {
+ this.Name = name;
+ }
+
+ public MemberName (MemberName left, string name)
+ : this (name)
+ {
+ this.Left = left;
+ }
+
+ public MemberName (MemberName left, MemberName right)
+ : this (left, right.Name)
+ {
+ }
+
+ public string GetName (bool is_generic)
+ {
+ string name = is_generic ? Basename : Name;
+ if (Left != null)
+ return Left.GetName (is_generic) + "." + name;
+ else
+ return name;
+ }
+
+ public string GetFullName ()
+ {
+ if (Left != null)
+ return Left.GetFullName () + "." + Name;
+ else
+ return Name;
+ }
+
+ public string GetTypeName ()
+ {
+ if (Left != null)
+ return Left.GetTypeName () + "." + Name;
+ else
+ return Name;
+ }
+
+ public Expression GetTypeExpression (Location loc)
+ {
+ if (Left != null) {
+ Expression lexpr = Left.GetTypeExpression (loc);
+
+ return new MemberAccess (lexpr, Name, loc);
+ } else {
+ return new SimpleName (Name, loc);
+ }
+ }
+
+ public MemberName Clone ()
+ {
+ if (Left != null)
+ return new MemberName (Left.Clone (), Name);
+ else
+ return new MemberName (Name);
+ }
+
+ public string Basename {
+ get {
+ return Name;
+ }
+ }
+
+ public override string ToString ()
+ {
+ return GetFullName ();
+ }
+ }
+
/// <summary>
/// Base representation for members. This is used to keep track
/// of Name, Location and Modifier flags, and handling Attributes.
/// <summary>
/// Public name
/// </summary>
- public string Name;
+ public string Name {
+ get {
+ // !(this is GenericMethod) && !(this is Method)
+ return MemberName.GetName (false);
+ }
+ }
+
+ public readonly MemberName MemberName;
/// <summary>
/// Modifier flags that the user specified in the source code
/// </summary>
internal Flags caching_flags;
- public MemberCore (TypeContainer parent, string name, Attributes attrs,
+ public MemberCore (TypeContainer parent, MemberName name, Attributes attrs,
Location loc)
: base (attrs)
{
Parent = parent;
- Name = name;
+ MemberName = name;
Location = loc;
caching_flags = Flags.Obsolete_Undetected | Flags.ClsCompliance_Undetected | Flags.HasCompliantAttribute_Undetected | Flags.Excluded_Undetected;
}
static string[] attribute_targets = new string [] { "type" };
- public DeclSpace (NamespaceEntry ns, TypeContainer parent, string name, Attributes attrs, Location l)
+ public DeclSpace (NamespaceEntry ns, TypeContainer parent, MemberName name,
+ Attributes attrs, Location l)
: base (parent, name, attrs, l)
{
NamespaceEntry = ns;
- Basename = name.Substring (1 + name.LastIndexOf ('.'));
+ Basename = name.Name;
defined_names = new Hashtable ();
}
public void RecordDecl ()
{
if ((NamespaceEntry != null) && (Parent == RootContext.Tree.Types))
- NamespaceEntry.DefineName (Basename, this);
+ NamespaceEntry.DefineName (MemberName.Basename, this);
}
/// <summary>
Modifiers.PRIVATE;
public Delegate (NamespaceEntry ns, TypeContainer parent, Expression type,
- int mod_flags, string name, Parameters param_list,
+ int mod_flags, MemberName name, Parameters param_list,
Attributes attrs, Location l)
: base (ns, parent, name, attrs, l)
public FieldBuilder builder;
internal readonly Expression Type;
- public EnumMember (Enum parent_enum, Expression expr, string name, Location loc, Attributes attrs):
- base (null, name, attrs, loc)
+ public EnumMember (Enum parent_enum, Expression expr, string name,
+ Location loc, Attributes attrs):
+ base (null, new MemberName (name), attrs, loc)
{
this.parent_enum = parent_enum;
this.ModFlags = parent_enum.ModFlags;
Modifiers.INTERNAL |
Modifiers.PRIVATE;
- public Enum (NamespaceEntry ns, TypeContainer parent, Expression type, int mod_flags,
- string name, Attributes attrs, Location l)
+ public Enum (NamespaceEntry ns, TypeContainer parent, Expression type,
+ int mod_flags, MemberName name, Attributes attrs, Location l)
: base (ns, parent, name, attrs, l)
{
this.BaseType = type;
point.Define (ig);
}
- private static string MakeProxyName (string name)
+ private static MemberName MakeProxyName (string name)
{
int pos = name.LastIndexOf ('.');
if (pos > 0)
name = name.Substring (pos + 1);
- return "<" + name + ">__" + (proxy_count++);
+ return new MemberName ("<" + name + ">__" + (proxy_count++));
}
//
void Define_Current ()
{
+ MemberName left = new MemberName ("System.Collections.IEnumerator");
+ MemberName name = new MemberName (left, "Current");
+
Block get_block = new Block (null);
get_block.AddStatement (new If (
Accessor getter = new Accessor (get_block, null, Location);
Property current = new Property (
- this, iterator_type_expr, Modifiers.PUBLIC,
- false, "Current", null, getter, null, Location);
+ this, iterator_type_expr, 0,
+ false, name, null, getter, null, Location);
AddProperty (current);
}
{
Method move_next = new Method (
this, TypeManager.system_boolean_expr,
- Modifiers.PUBLIC, false, "MoveNext",
+ Modifiers.PUBLIC, false, new MemberName ("MoveNext"),
Parameters.EmptyReadOnlyParameters, null,
Location.Null);
AddMethod (move_next);
void Define_GetEnumerator ()
{
+ MemberName left = new MemberName ("System.Collections.IEnumerable");
+ MemberName name = new MemberName (left, "GetEnumerator");
+
Method get_enumerator = new Method (
this,
new TypeExpression (TypeManager.ienumerator_type, Location),
- Modifiers.PUBLIC, false, "GetEnumerator",
+ 0, false, name,
Parameters.EmptyReadOnlyParameters, null,
Location.Null);
AddMethod (get_enumerator);
{
Method reset = new Method (
this, TypeManager.system_void_expr, Modifiers.PUBLIC,
- false, "Reset", Parameters.EmptyReadOnlyParameters,
- null, Location);
+ false, new MemberName ("Reset"),
+ Parameters.EmptyReadOnlyParameters, null, Location);
AddMethod (reset);
reset.Block = new Block (null);
{
dispose = new Method (
this, TypeManager.system_void_expr, Modifiers.PUBLIC,
- false, "Dispose", Parameters.EmptyReadOnlyParameters,
- null, Location);
+ false, new MemberName ("Dispose"),
+ Parameters.EmptyReadOnlyParameters, null, Location);
AddMethod (dispose);
dispose.Block = new Block (null);
public class AliasEntry {
public readonly string Name;
- public readonly Expression Alias;
+ public readonly MemberName Alias;
public readonly NamespaceEntry NamespaceEntry;
public readonly Location Location;
- public AliasEntry (NamespaceEntry entry, string name, Expression alias, Location loc)
+ public AliasEntry (NamespaceEntry entry, string name, MemberName alias, Location loc)
{
Name = name;
Alias = alias;
using_clauses.Add (ue);
}
- public void UsingAlias (string alias, Expression namespace_or_type, Location loc)
+ public void UsingAlias (string name, MemberName alias, Location loc)
{
if (DeclarationFound){
Report.Error (1529, loc, "A using clause must precede all other namespace elements");
if (aliases == null)
aliases = new Hashtable ();
- if (aliases.Contains (alias)){
- Report.Error (1537, loc, "The using alias `" + alias +
+ if (aliases.Contains (name)){
+ Report.Error (1537, loc, "The using alias `" + name +
"' appeared previously in this namespace");
return;
}
- aliases [alias] = new AliasEntry (this, alias, namespace_or_type, loc);
+ aliases [name] = new AliasEntry (this, name, alias, loc);
}
protected AliasEntry GetAliasEntry (string alias)
public class RootTypes : TypeContainer
{
public RootTypes ()
- : base (null, null, "", null, Kind.Root, new Location (-1))
+ : base (null, null, MemberName.Null, null, Kind.Root,
+ new Location (-1))
{ }
public override void Register ()