Author: martin
Date: 2005-04-18 10:43:02 -0400 (Mon, 18 Apr 2005)
New Revision: 43221

Modified:
   trunk/mcs/gmcs/ChangeLog
   trunk/mcs/gmcs/class.cs
   trunk/mcs/gmcs/ecore.cs
   trunk/mcs/gmcs/expression.cs
Log:
**** Merged r42373 from MCS ****


Modified: trunk/mcs/gmcs/ChangeLog
===================================================================
--- trunk/mcs/gmcs/ChangeLog    2005-04-18 14:24:19 UTC (rev 43220)
+++ trunk/mcs/gmcs/ChangeLog    2005-04-18 14:43:02 UTC (rev 43221)
@@ -1,3 +1,21 @@
+2005-03-30  Raja R Harinath  <[EMAIL PROTECTED]>
+
+       * ecore.cs (MemberExpr): New class.  Convert from interface
+       IMemberExpr.
+       (MemberExpr.ResolveMemberAccess): Refactor and move here from
+       MemberAccess.ResolveMemberAccess.  Tighten up pre-conditions and
+       error checks.
+       (MethodGroupExpr, FieldExpr, PropertyExpr, EventExpr): Update.
+       (MethodGroupExpr.IsExplicitImpl): Remove.
+       (Expression.GetFieldFromEvent): Remove.
+       (SimpleName.MemberStaticCheck): Remove.
+       (SimpleName.DoSimpleNameResolve): Update to changes.
+       * expression.cs (MemberAccess.ResolveMemberAccess): Refactor.
+       (MemberAccess.IdenticalNameAndTypeName): Remove.
+       (MemberAccess.error176): Move to MemberExpr.
+       (MemberAccess.DoResolve): Update to changes.
+       (BaseAccess.DoResolve): Likewise.
+
 2005-03-30  Marek Safar  <[EMAIL PROTECTED]>
 
        C# 2.0 Conditional attribute class implementation

Modified: trunk/mcs/gmcs/class.cs
===================================================================
--- trunk/mcs/gmcs/class.cs     2005-04-18 14:24:19 UTC (rev 43220)
+++ trunk/mcs/gmcs/class.cs     2005-04-18 14:43:02 UTC (rev 43221)
@@ -862,7 +862,6 @@
                                Location l = f.Location;
                                FieldExpr fe = new FieldExpr (f.FieldBuilder, 
l);
                                fe.InstanceExpression = instance_expr;
-                               fe.IsFieldInitializer = true;
 
                                ExpressionStatement a = new Assign (fe, e, l);
 

Modified: trunk/mcs/gmcs/ecore.cs
===================================================================
--- trunk/mcs/gmcs/ecore.cs     2005-04-18 14:24:19 UTC (rev 43220)
+++ trunk/mcs/gmcs/ecore.cs     2005-04-18 14:43:02 UTC (rev 43221)
@@ -118,49 +118,6 @@
                bool VerifyFixed (bool is_expression);
        }
 
-       /// <summary>
-       ///   This interface denotes an expression which evaluates to a member
-       ///   of a struct or a class.
-       /// </summary>
-       public interface IMemberExpr
-       {
-               /// <summary>
-               ///   The name of this member.
-               /// </summary>
-               string Name {
-                       get;
-               }
-
-               /// <summary>
-               ///   Whether this is an instance member.
-               /// </summary>
-               bool IsInstance {
-                       get;
-               }
-
-               /// <summary>
-               ///   Whether this is a static member.
-               /// </summary>
-               bool IsStatic {
-                       get;
-               }
-
-               /// <summary>
-               ///   The type which declares this member.
-               /// </summary>
-               Type DeclaringType {
-                       get;
-               }
-
-               /// <summary>
-               ///   The instance expression associated with this member, if 
it's a
-               ///   non-static member.
-               /// </summary>
-               Expression InstanceExpression {
-                       get; set;
-               }
-       }
-
        /// <remarks>
        ///   Base class for expressions
        /// </remarks>
@@ -807,13 +764,6 @@
                }
                }
 
-               static public MemberInfo GetFieldFromEvent (EventExpr 
event_expr)
-               {
-                       EventInfo ei = event_expr.EventInfo;
-
-                       return TypeManager.GetPrivateFieldOfEvent (ei);
-               }
-               
                /// <summary>
                ///   Returns an expression that can be used to invoke operator 
true
                ///   on the expression if it exists.
@@ -2097,26 +2047,7 @@
                                resolved_to.Type.Name == Name &&
                                (ec.DeclSpace.LookupType (Name, loc, /* 
ignore_cs0104 = */ true) != null);
                }
-               
-               //
-               // Checks whether we are trying to access an instance
-               // property, method or field from a static body.
-               //
-               Expression MemberStaticCheck (EmitContext ec, Expression e, 
bool intermediate)
-               {
-                       if (e is IMemberExpr){
-                               IMemberExpr member = (IMemberExpr) e;
-                               
-                               if (!member.IsStatic &&
-                                   (!intermediate || !IdenticalNameAndTypeName 
(ec, e, loc))) {
-                                       Error_ObjectRefRequired (ec, loc, Name);
-                                       return null;
-                               }
-                       }
 
-                       return e;
-               }
-
                public override Expression DoResolve (EmitContext ec)
                {
                        return SimpleNameResolve (ec, null, false);
@@ -2338,12 +2269,17 @@
                        if (e is TypeExpr)
                                return e;
 
-                       if (e is IMemberExpr) {
-                               e = MemberAccess.ResolveMemberAccess (ec, e, 
null, loc, this);
+                       if (e is MemberExpr) {
+                               MemberExpr me = (MemberExpr) e;
+                               Expression left = (ec.IsStatic || 
ec.IsFieldInitializer)
+                                       ? (Expression) new TypeExpression 
(ec.ContainerType, loc)
+                                       : (Expression) ec.GetThis (loc);
+                       
+                               e = me.ResolveMemberAccess (ec, left, loc, 
(intermediate ? this : null), true);
                                if (e == null)
                                        return null;
 
-                               IMemberExpr me = e as IMemberExpr;
+                               me = e as MemberExpr;
                                if (me == null)
                                        return e;
 
@@ -2357,8 +2293,8 @@
 
                                // This fails if ResolveMemberAccess() was 
unable to decide whether
                                // it's a field or a type of the same name.
-                               
-                               if (!me.IsStatic && (me.InstanceExpression == 
null))
+                               if (!me.IsStatic && me.InstanceExpression == 
null && 
+                                   (intermediate && IdenticalNameAndTypeName 
(ec, e, loc)))
                                        return e;
 
                                if (!me.IsStatic &&
@@ -2373,14 +2309,11 @@
                                }
 
                                return (right_side != null)
-                                       ? e.DoResolveLValue (ec, right_side)
-                                       : e.DoResolve (ec);
+                                       ? me.DoResolveLValue (ec, right_side)
+                                       : me.DoResolve (ec);
                        }
 
-                       if (ec.IsStatic || ec.IsFieldInitializer){
-                               return MemberStaticCheck (ec, e, intermediate);
-                       } else
-                               return e;
+                       return e;
                }
                
                public override void Emit (EmitContext ec)
@@ -2681,14 +2614,97 @@
        }
 
        /// <summary>
+       ///   This class denotes an expression which evaluates to a member
+       ///   of a struct or a class.
+       /// </summary>
+       public abstract class MemberExpr : Expression
+       {
+               /// <summary>
+               ///   The name of this member.
+               /// </summary>
+               public abstract string Name {
+                       get;
+               }
+
+               /// <summary>
+               ///   Whether this is an instance member.
+               /// </summary>
+               public abstract bool IsInstance {
+                       get;
+               }
+
+               /// <summary>
+               ///   Whether this is a static member.
+               /// </summary>
+               public abstract bool IsStatic {
+                       get;
+               }
+
+               /// <summary>
+               ///   The type which declares this member.
+               /// </summary>
+               public abstract Type DeclaringType {
+                       get;
+               }
+
+               /// <summary>
+               ///   The instance expression associated with this member, if 
it's a
+               ///   non-static member.
+               /// </summary>
+               public Expression InstanceExpression;
+
+               public static void error176 (Location loc, string name)
+               {
+                       Report.Error (176, loc, "Static member `" + name + "' 
cannot be accessed " +
+                                     "with an instance reference, qualify with 
a type name instead");
+               }
+
+
+               // TODO: possible optimalization
+               // Cache resolved constant result in FieldBuilder <-> 
expression map
+               public virtual Expression ResolveMemberAccess (EmitContext ec, 
Expression left, Location loc,
+                                                               SimpleName 
original, bool left_is_inferred)
+               {
+                       //
+                       // Precondition:
+                       //   original == null || original.Resolve (...) === 
(left_is_inferred ? this : left)
+                       //
+
+                       if (left is TypeExpr) {
+                               if (!IsStatic) {
+                                       if ((ec.IsFieldInitializer || 
ec.IsStatic) && left_is_inferred &&
+                                           original != null && 
original.IdenticalNameAndTypeName (ec, this, loc))
+                                               return this;
+
+                                       SimpleName.Error_ObjectRefRequired (ec, 
loc, Name);
+                                       return null;
+                               }
+
+                               return this;
+                       }
+                               
+                       if (!IsInstance) {
+                               if (left_is_inferred ||
+                                   (original != null && 
original.IdenticalNameAndTypeName (ec, left, loc)))
+                                       return this;
+
+                               error176 (loc, Name);
+                               return null;
+                       }
+
+                       InstanceExpression = left;
+
+                       return this;
+               }
+       }
+
+       /// <summary>
        ///   MethodGroup Expression.
        ///  
        ///   This is a fully resolved expression that evaluates to a type
        /// </summary>
-       public class MethodGroupExpr : Expression, IMemberExpr {
+       public class MethodGroupExpr : MemberExpr {
                public MethodBase [] Methods;
-               Expression instance_expression = null;
-               bool is_explicit_impl = false;
                bool has_type_arguments = false;
                bool identical_type_name = false;
                bool is_base;
@@ -2723,7 +2739,7 @@
                        type = TypeManager.object_type;
                }
 
-               public Type DeclaringType {
+               public override Type DeclaringType {
                        get {
                                 //
                                 // We assume that the top-level type is in the 
end
@@ -2732,30 +2748,7 @@
                                 //return Methods [0].DeclaringType;
                        }
                }
-               
-               //
-               // `A method group may have associated an instance expression' 
-               // 
-               public Expression InstanceExpression {
-                       get {
-                               return instance_expression;
-                       }
 
-                       set {
-                               instance_expression = value;
-                       }
-               }
-
-               public bool IsExplicitImpl {
-                       get {
-                               return is_explicit_impl;
-                       }
-
-                       set {
-                               is_explicit_impl = value;
-                       }
-               }
-
                public bool HasTypeArguments {
                        get {
                                return has_type_arguments;
@@ -2785,14 +2778,14 @@
                        }
                }
 
-               public string Name {
+               public override string Name {
                        get {
                                //return Methods [0].Name;
                                 return Methods [Methods.Length - 1].Name;
                        }
                }
 
-               public bool IsInstance {
+               public override bool IsInstance {
                        get {
                                foreach (MethodBase mb in Methods)
                                        if (!mb.IsStatic)
@@ -2802,7 +2795,7 @@
                        }
                }
 
-               public bool IsStatic {
+               public override bool IsStatic {
                        get {
                                foreach (MethodBase mb in Methods)
                                        if (mb.IsStatic)
@@ -2811,15 +2804,26 @@
                                return false;
                        }
                }
+
+               public override Expression ResolveMemberAccess (EmitContext ec, 
Expression left, Location loc,
+                                                                SimpleName 
original, bool left_is_inferred)
+               {
+                       if (!left_is_inferred &&
+                           !(left is TypeExpr) &&
+                           original != null && 
original.IdenticalNameAndTypeName (ec, left, loc))
+                               IdenticalTypeName = true;
+
+                       return base.ResolveMemberAccess (ec, left, loc, 
original, left_is_inferred);
+               }
                
                override public Expression DoResolve (EmitContext ec)
                {
                        if (!IsInstance)
-                               instance_expression = null;
+                               InstanceExpression = null;
 
-                       if (instance_expression != null) {
-                               instance_expression = 
instance_expression.DoResolve (ec);
-                               if (instance_expression == null)
+                       if (InstanceExpression != null) {
+                               InstanceExpression = 
InstanceExpression.DoResolve (ec);
+                               if (InstanceExpression == null)
                                        return null;
                        }
 
@@ -2926,9 +2930,8 @@
        /// <summary>
        ///   Fully resolved expression that evaluates to a Field
        /// </summary>
-       public class FieldExpr : Expression, IAssignMethod, IMemoryLocation, 
IMemberExpr, IVariable {
+       public class FieldExpr : MemberExpr, IAssignMethod, IMemoryLocation, 
IVariable {
                public readonly FieldInfo FieldInfo;
-               Expression instance_expr;
                VariableInfo variable_info;
                
                LocalTemporary temp;
@@ -2943,60 +2946,130 @@
                        loc = l;
                }
 
-               public string Name {
+               public override string Name {
                        get {
                                return FieldInfo.Name;
                        }
                }
 
-               public bool IsInstance {
+               public override bool IsInstance {
                        get {
                                return !FieldInfo.IsStatic;
                        }
                }
 
-               public bool IsStatic {
+               public override bool IsStatic {
                        get {
                                return FieldInfo.IsStatic;
                        }
                }
 
-               public Type DeclaringType {
+               public override Type DeclaringType {
                        get {
                                return FieldInfo.DeclaringType;
                        }
                }
 
-               public Expression InstanceExpression {
+               public VariableInfo VariableInfo {
                        get {
-                               return instance_expr;
+                               return variable_info;
                        }
-
-                       set {
-                               instance_expr = value;
-                       }
                }
 
-               public bool IsFieldInitializer {
-                       get {
-                               return is_field_initializer;
+               public override Expression ResolveMemberAccess (EmitContext ec, 
Expression left, Location loc,
+                                                               SimpleName 
original, bool left_is_inferred)
+               {
+                       bool left_is_type = left is TypeExpr;
+
+                       FieldInfo fi = FieldInfo.Mono_GetGenericFieldDefinition 
();
+
+                       Type decl_type = fi.DeclaringType;
+                       
+                       bool is_emitted = fi is FieldBuilder;
+                       Type t = fi.FieldType;
+                       
+                       if (is_emitted) {
+                               Const c = TypeManager.LookupConstant 
((FieldBuilder) fi);
+                               
+                               if (c != null) {
+                                       object o;
+                                       if (!c.LookupConstantValue (out o))
+                                               return null;
+
+                                       object real_value = ((Constant) 
c.Expr).GetValue ();
+
+                                       Expression exp = Constantify 
(real_value, t);
+                                       
+                                       if (!left_is_inferred && !left_is_type 
&& 
+                                           (original == null || 
!original.IdenticalNameAndTypeName (ec, left, loc))) {
+                                               
Report.SymbolRelatedToPreviousError (c);
+                                               error176 (loc, 
c.GetSignatureForError ());
+                                               return null;
+                                       }
+                                       
+                                       return exp;
+                               }
                        }
+                       
+                       // IsInitOnly is because of MS compatibility, I don't 
know why but they emit decimal constant as InitOnly
+                       if (fi.IsInitOnly && !is_emitted && t == 
TypeManager.decimal_type) {
+                               object[] attrs = fi.GetCustomAttributes 
(TypeManager.decimal_constant_attribute_type, false);
+                               if (attrs.Length == 1)
+                                       return new DecimalConstant 
(((System.Runtime.CompilerServices.DecimalConstantAttribute) attrs [0]).Value);
+                       }
+                       
+                       if (fi.IsLiteral) {
+                               object o;
 
-                       set {
-                               is_field_initializer = value;
+                               if (is_emitted)
+                                       o = TypeManager.GetValue 
((FieldBuilder) fi);
+                               else
+                                       o = fi.GetValue (fi);
+                               
+                               if (decl_type.IsSubclassOf 
(TypeManager.enum_type)) {
+                                       if (!left_is_inferred && !left_is_type 
&&
+                                           (original == null || 
!original.IdenticalNameAndTypeName (ec, left, loc))) {
+                                               error176 (loc, fi.Name);
+                                               return null;
+                                       }                                       
+                                       
+                                       Expression enum_member = MemberLookup (
+                                              ec, decl_type, "value__", 
MemberTypes.Field,
+                                              AllBindingFlags | 
BindingFlags.NonPublic, loc); 
+                                       
+                                       Enum en = TypeManager.LookupEnum 
(decl_type);
+                                       
+                                       Constant c;
+                                       if (en != null)
+                                               c = Constantify (o, 
en.UnderlyingType);
+                                       else 
+                                               c = Constantify (o, 
enum_member.Type);
+                                       
+                                       return new EnumConstant (c, decl_type);
+                               }
+                               
+                               Expression exp = Constantify (o, t);
+                               
+                               if (!left_is_inferred && !left_is_type) {
+                                       error176 (loc, fi.Name);
+                                       return null;
+                               }
+                               
+                               return exp;
                        }
-               }
+                       
+                       if (t.IsPointer && !ec.InUnsafe) {
+                               UnsafeError (loc);
+                               return null;
+                       }
 
-               public VariableInfo VariableInfo {
-                       get {
-                               return variable_info;
-                       }
+                       return base.ResolveMemberAccess (ec, left, loc, 
original, left_is_inferred);
                }
 
                override public Expression DoResolve (EmitContext ec)
                {
                        if (!FieldInfo.IsStatic){
-                               if (instance_expr == null){
+                               if (InstanceExpression == null){
                                        //
                                        // This can happen when referencing an 
instance field using
                                        // a fully qualified type expression: 
TypeName.InstanceField = xxx
@@ -3008,9 +3081,9 @@
                                // Resolve the field's instance expression 
while flow analysis is turned
                                // off: when accessing a field "a.b", we must 
check whether the field
                                // "a.b" is initialized, not whether the whole 
struct "a" is initialized.
-                               instance_expr = instance_expr.Resolve (ec, 
ResolveFlags.VariableOrValue |
+                               InstanceExpression = InstanceExpression.Resolve 
(ec, ResolveFlags.VariableOrValue |
                                                                       
ResolveFlags.DisableFlowAnalysis);
-                               if (instance_expr == null)
+                               if (InstanceExpression == null)
                                        return null;
                        }
 
@@ -3038,7 +3111,7 @@
                        }
                        
                        // If the instance expression is a local variable or 
parameter.
-                       IVariable var = instance_expr as IVariable;
+                       IVariable var = InstanceExpression as IVariable;
                        if ((var == null) || (var.VariableInfo == null))
                                return this;
 
@@ -3066,7 +3139,7 @@
                
                override public Expression DoResolveLValue (EmitContext ec, 
Expression right_side)
                {
-                       IVariable var = instance_expr as IVariable;
+                       IVariable var = InstanceExpression as IVariable;
                        if ((var != null) && (var.VariableInfo != null))
                                var.VariableInfo.SetFieldAssigned (ec, 
FieldInfo.Name);
 
@@ -3075,7 +3148,7 @@
                        if (e == null)
                                return null;
 
-                       if (!FieldInfo.IsStatic && 
(instance_expr.Type.IsValueType && !(instance_expr is IMemoryLocation))) {
+                       if (!FieldInfo.IsStatic && 
(InstanceExpression.Type.IsValueType && !(InstanceExpression is 
IMemoryLocation))) {
                                // FIXME: Provide better error reporting.
                                Error (1612, "Cannot modify expression because 
it is not a variable.");
                                return null;
@@ -3122,7 +3195,7 @@
 
                public bool VerifyFixed (bool is_expression)
                {
-                       IVariable variable = instance_expr as IVariable;
+                       IVariable variable = InstanceExpression as IVariable;
                        if ((variable == null) || !variable.VerifyFixed (true))
                                return false;
 
@@ -3250,22 +3323,22 @@
                        // This happens in cases like 'string String', 'int 
Int32', etc.
                        // where the "IdenticalTypeAndName" mechanism is fooled.
                        //
-                       if (instance_expr == null) {
+                       if (InstanceExpression == null) {
                                SimpleName.Error_ObjectRefRequired (ec, loc, 
FieldInfo.Name);
                                return;
                        }
 
-                       if (instance_expr.Type.IsValueType) {
-                               if (instance_expr is IMemoryLocation) {
-                                       ((IMemoryLocation) 
instance_expr).AddressOf (ec, AddressOp.LoadStore);
+                       if (InstanceExpression.Type.IsValueType) {
+                               if (InstanceExpression is IMemoryLocation) {
+                                       ((IMemoryLocation) 
InstanceExpression).AddressOf (ec, AddressOp.LoadStore);
                                } else {
-                                       LocalTemporary t = new LocalTemporary 
(ec, instance_expr.Type);
-                                       instance_expr.Emit (ec);
+                                       LocalTemporary t = new LocalTemporary 
(ec, InstanceExpression.Type);
+                                       InstanceExpression.Emit (ec);
                                        t.Store (ec);
                                        t.AddressOf (ec, AddressOp.Store);
                                }
                        } else
-                               instance_expr.Emit (ec);
+                               InstanceExpression.Emit (ec);
                }
 
                public override void Emit (EmitContext ec)
@@ -3349,7 +3422,7 @@
        ///   This is not an LValue because we need to re-write the expression, 
we
        ///   can not take data from the stack and store it.  
        /// </summary>
-       public class PropertyExpr : Expression, IAssignMethod, IMemberExpr {
+       public class PropertyExpr : MemberExpr, IAssignMethod {
                public readonly PropertyInfo PropertyInfo;
 
                //
@@ -3359,7 +3432,6 @@
                MethodInfo getter, setter;
                bool is_static;
                
-               Expression instance_expr;
                LocalTemporary temp;
                bool prepared;
 
@@ -3377,43 +3449,30 @@
                        ResolveAccessors (ec);
                }
 
-               public string Name {
+               public override string Name {
                        get {
                                return PropertyInfo.Name;
                        }
                }
 
-               public bool IsInstance {
+               public override bool IsInstance {
                        get {
                                return !is_static;
                        }
                }
 
-               public bool IsStatic {
+               public override bool IsStatic {
                        get {
                                return is_static;
                        }
                }
                
-               public Type DeclaringType {
+               public override Type DeclaringType {
                        get {
                                return PropertyInfo.DeclaringType;
                        }
                }
 
-               //
-               // The instance expression associated with this expression
-               //
-               public Expression InstanceExpression {
-                       set {
-                               instance_expr = value;
-                       }
-
-                       get {
-                               return instance_expr;
-                       }
-               }
-
                public bool VerifyAssignable ()
                {
                        if (setter == null) {
@@ -3481,26 +3540,26 @@
 
                bool InstanceResolve (EmitContext ec, bool must_do_cs1540_check)
                {
-                       if ((instance_expr == null) && ec.IsStatic && 
!is_static) {
+                       if ((InstanceExpression == null) && ec.IsStatic && 
!is_static) {
                                SimpleName.Error_ObjectRefRequired (ec, loc, 
PropertyInfo.Name);
                                return false;
                        }
 
-                       if (instance_expr != null) {
-                               instance_expr = instance_expr.DoResolve (ec);
-                               if (instance_expr == null)
+                       if (InstanceExpression != null) {
+                               InstanceExpression = 
InstanceExpression.DoResolve (ec);
+                               if (InstanceExpression == null)
                                        return false;
 
-                               instance_expr.CheckMarshallByRefAccess 
(ec.ContainerType);
+                               InstanceExpression.CheckMarshallByRefAccess 
(ec.ContainerType);
                        }
 
-                       if (must_do_cs1540_check && (instance_expr != null)) {
-                               if ((instance_expr.Type != ec.ContainerType) &&
-                                   ec.ContainerType.IsSubclassOf 
(instance_expr.Type)) {
+                       if (must_do_cs1540_check && (InstanceExpression != 
null)) {
+                               if ((InstanceExpression.Type != 
ec.ContainerType) &&
+                                   ec.ContainerType.IsSubclassOf 
(InstanceExpression.Type)) {
                                        Report.Error (1540, loc, "Cannot access 
protected member `" +
                                                      
PropertyInfo.DeclaringType + "." + PropertyInfo.Name + 
                                                      "' via a qualifier of 
type `" +
-                                                     TypeManager.CSharpName 
(instance_expr.Type) +
+                                                     TypeManager.CSharpName 
(InstanceExpression.Type) +
                                                      "'; the qualifier must be 
of type `" +
                                                      TypeManager.CSharpName 
(ec.ContainerType) +
                                                      "' (or derived from it)");
@@ -3629,7 +3688,7 @@
                        //
                        // Check that we are not making changes to a temporary 
memory location
                        //
-                       if (instance_expr != null && 
instance_expr.Type.IsValueType && !(instance_expr is IMemoryLocation)) {
+                       if (InstanceExpression != null && 
InstanceExpression.Type.IsValueType && !(InstanceExpression is 
IMemoryLocation)) {
                                // FIXME: Provide better error reporting.
                                Error (1612, "Cannot modify expression because 
it is not a variable.");
                                return null;
@@ -3655,22 +3714,22 @@
                        // This happens in cases like 'string String', 'int 
Int32', etc.
                        // where the "IdenticalTypeAndName" mechanism is fooled.
                        //
-                       if (instance_expr == null) {
+                       if (InstanceExpression == null) {
                                SimpleName.Error_ObjectRefRequired (ec, loc, 
PropertyInfo.Name);
                                return;
                        }
 
-                       if (instance_expr.Type.IsValueType) {
-                               if (instance_expr is IMemoryLocation) {
-                                       ((IMemoryLocation) 
instance_expr).AddressOf (ec, AddressOp.LoadStore);
+                       if (InstanceExpression.Type.IsValueType) {
+                               if (InstanceExpression is IMemoryLocation) {
+                                       ((IMemoryLocation) 
InstanceExpression).AddressOf (ec, AddressOp.LoadStore);
                                } else {
-                                       LocalTemporary t = new LocalTemporary 
(ec, instance_expr.Type);
-                                       instance_expr.Emit (ec);
+                                       LocalTemporary t = new LocalTemporary 
(ec, InstanceExpression.Type);
+                                       InstanceExpression.Emit (ec);
                                        t.Store (ec);
                                        t.AddressOf (ec, AddressOp.Store);
                                }
                        } else
-                               instance_expr.Emit (ec);
+                               InstanceExpression.Emit (ec);
                        
                        if (prepared)
                                ec.ig.Emit (OpCodes.Dup);
@@ -3687,7 +3746,7 @@
                        //
                        if ((getter == TypeManager.system_int_array_get_length) 
||
                            (getter == TypeManager.int_array_get_length)){
-                               Type iet = instance_expr.Type;
+                               Type iet = InstanceExpression.Type;
 
                                //
                                // System.Array.Length can be called, but the 
Type does not
@@ -3743,9 +3802,8 @@
        /// <summary>
        ///   Fully resolved expression that evaluates to an Event
        /// </summary>
-       public class EventExpr : Expression, IMemberExpr {
+       public class EventExpr : MemberExpr {
                public readonly EventInfo EventInfo;
-               Expression instance_expr;
 
                bool is_static;
                MethodInfo add_accessor, remove_accessor;
@@ -3770,50 +3828,69 @@
                                type = EventInfo.EventHandlerType;
                }
 
-               public string Name {
+               public override string Name {
                        get {
                                return EventInfo.Name;
                        }
                }
 
-               public bool IsInstance {
+               public override bool IsInstance {
                        get {
                                return !is_static;
                        }
                }
 
-               public bool IsStatic {
+               public override bool IsStatic {
                        get {
                                return is_static;
                        }
                }
 
-               public Type DeclaringType {
+               public override Type DeclaringType {
                        get {
                                return EventInfo.DeclaringType;
                        }
                }
 
-               public Expression InstanceExpression {
-                       get {
-                               return instance_expr;
+               public override Expression ResolveMemberAccess (EmitContext ec, 
Expression left, Location loc,
+                                                                SimpleName 
original, bool left_is_inferred)
+               {
+                       //
+                       // If the event is local to this class, we transform 
ourselves into a FieldExpr
+                       //
+
+                       if (EventInfo.DeclaringType == ec.ContainerType ||
+                           TypeManager.IsNestedChildOf(ec.ContainerType, 
EventInfo.DeclaringType)) {
+                               MemberInfo mi = 
TypeManager.GetPrivateFieldOfEvent (EventInfo);
+
+                               if (mi != null) {
+                                       MemberExpr ml = (MemberExpr) 
ExprClassFromMemberInfo (ec, mi, loc);
+
+                                       if (ml == null) {
+                                               Report.Error (-200, loc, 
"Internal error!!");
+                                               return null;
+                                       }
+                               
+                                       InstanceExpression = left_is_inferred ? 
null : left;
+                               
+                                       return ml.ResolveMemberAccess (ec, 
left, loc, original, left_is_inferred);
+                               }
                        }
 
-                       set {
-                               instance_expr = value;
-                       }
+                       return base.ResolveMemberAccess (ec, left, loc, 
original, left_is_inferred);
                }
 
+
                bool InstanceResolve (EmitContext ec, bool must_do_cs1540_check)
                {
-                       if ((instance_expr == null) && ec.IsStatic && 
!is_static) {
+                       if ((InstanceExpression == null) && ec.IsStatic && 
!is_static) {
                                SimpleName.Error_ObjectRefRequired (ec, loc, 
EventInfo.Name);
                                return false;
                        }
 
-                       if (instance_expr != null) {
-                               instance_expr = instance_expr.DoResolve (ec);
-                               if (instance_expr == null)
+                       if (InstanceExpression != null) {
+                               InstanceExpression = 
InstanceExpression.DoResolve (ec);
+                               if (InstanceExpression == null)
                                        return false;
                        }
 
@@ -3821,9 +3898,9 @@
                        // This is using the same mechanism as the CS1540 check 
in PropertyExpr.
                        // However, in the Event case, we reported a CS0122 
instead.
                        //
-                       if (must_do_cs1540_check && (instance_expr != null)) {
-                               if ((instance_expr.Type != ec.ContainerType) &&
-                                       ec.ContainerType.IsSubclassOf 
(instance_expr.Type)) {
+                       if (must_do_cs1540_check && (InstanceExpression != 
null)) {
+                               if ((InstanceExpression.Type != 
ec.ContainerType) &&
+                                       ec.ContainerType.IsSubclassOf 
(InstanceExpression.Type)) {
                                        Report.Error (122, loc, "'{0}' is 
inaccessible due to its protection level",
                                                DeclaringType.Name + "." + 
EventInfo.Name);
 
@@ -3841,9 +3918,9 @@
 
                public override Expression DoResolve (EmitContext ec)
                {
-                       if (instance_expr != null) {
-                               instance_expr = instance_expr.DoResolve (ec);
-                               if (instance_expr == null)
+                       if (InstanceExpression != null) {
+                               InstanceExpression = 
InstanceExpression.DoResolve (ec);
+                               if (InstanceExpression == null)
                                        return null;
                        }
 
@@ -3864,7 +3941,7 @@
 
                public override void Emit (EmitContext ec)
                {
-                       if (instance_expr is This)
+                       if (InstanceExpression is This)
                                Report.Error (79, loc, "The event `{0}' can 
only appear on the left hand side of += or -=, try calling the actual 
delegate", Name);
                        else
                                Report.Error (70, loc, "The event `{0}' can 
only appear on the left hand side of += or -= "+
@@ -3883,10 +3960,10 @@
                        
                        if (source_del.IsAddition)
                                Invocation.EmitCall (
-                                       ec, false, IsStatic, instance_expr, 
add_accessor, args, loc);
+                                       ec, false, IsStatic, 
InstanceExpression, add_accessor, args, loc);
                        else
                                Invocation.EmitCall (
-                                       ec, false, IsStatic, instance_expr, 
remove_accessor, args, loc);
+                                       ec, false, IsStatic, 
InstanceExpression, remove_accessor, args, loc);
                }
        }
 }      

Modified: trunk/mcs/gmcs/expression.cs
===================================================================
--- trunk/mcs/gmcs/expression.cs        2005-04-18 14:24:19 UTC (rev 43220)
+++ trunk/mcs/gmcs/expression.cs        2005-04-18 14:43:02 UTC (rev 43221)
@@ -4278,8 +4278,8 @@
                        if (Expr == null)
                                return false;
 
-                       if (Expr is IMemberExpr) {
-                               IMemberExpr me = Expr as IMemberExpr;
+                       if (Expr is MemberExpr) {
+                               MemberExpr me = Expr as MemberExpr;
 
                                //
                                // This can happen with the following code:
@@ -5347,7 +5347,7 @@
                        MethodInfo mi = method as MethodInfo;
                        if (mi != null) {
                                type = TypeManager.TypeToCoreType 
(mi.ReturnType);
-                               if (!mi.IsStatic && !mg.IsExplicitImpl && 
(mg.InstanceExpression == null)) {
+                               if (!mi.IsStatic && mg.InstanceExpression == 
null) {
                                        SimpleName.Error_ObjectRefRequired (ec, 
loc, mi.Name);
                                        return null;
                                }
@@ -5357,7 +5357,7 @@
                                        if (mg.IdenticalTypeName)
                                                mg.InstanceExpression = null;
                                        else {
-                                               MemberAccess.error176 (loc, 
mi.Name);
+                                               MemberExpr.error176 (loc, 
mi.Name);
                                                return null;
                                        }
                                }
@@ -7403,227 +7403,6 @@
                        }
                }
 
-               public static void error176 (Location loc, string name)
-               {
-                       Report.Error (176, loc, "Static member `" +
-                                     name + "' cannot be accessed " +
-                                     "with an instance reference, qualify with 
a " +
-                                     "type name instead");
-               }
-
-               public static bool IdenticalNameAndTypeName (EmitContext ec, 
Expression left_original, Expression left, Location loc)
-               {
-                       SimpleName sn = left_original as SimpleName;
-                       return sn != null && sn.IdenticalNameAndTypeName (ec, 
left, loc);
-               }
-               
-               // TODO: possible optimalization
-               // Cache resolved constant result in FieldBuilder <-> expresion 
map
-               public static Expression ResolveMemberAccess (EmitContext ec, 
Expression member_lookup,
-                                                             Expression left, 
Location loc,
-                                                             Expression 
left_original)
-               {
-                       bool left_is_type, left_is_explicit;
-
-                       // If `left' is null, then we're called from 
SimpleNameResolve and this is
-                       // a member in the currently defining class.
-                       if (left == null) {
-                               left_is_type = ec.IsStatic || 
ec.IsFieldInitializer;
-                               left_is_explicit = false;
-
-                               // Implicitly default to `this' unless we're 
static.
-                               if (!ec.IsStatic && !ec.IsFieldInitializer && 
!ec.InEnumContext)
-                                       left = ec.GetThis (loc);
-                       } else {
-                               left_is_type = left is TypeExpr;
-                               left_is_explicit = true;
-                       }
-
-                       if (member_lookup is FieldExpr){
-                               FieldExpr fe = (FieldExpr) member_lookup;
-                               FieldInfo fi = 
fe.FieldInfo.Mono_GetGenericFieldDefinition ();
-                               Type decl_type = fi.DeclaringType;
-
-                               bool is_emitted = fi is FieldBuilder;
-                               Type t = fi.FieldType;
-
-                               if (is_emitted) {
-                                       Const c = TypeManager.LookupConstant 
((FieldBuilder) fi);
-                                       
-                                       if (c != null) {
-                                               object o;
-                                               if (!c.LookupConstantValue (out 
o))
-                                                       return null;
-
-                                               object real_value = ((Constant) 
c.Expr).GetValue ();
-
-                                               Expression exp = Constantify 
(real_value, t);
-
-                                               if (left_is_explicit && 
!left_is_type && !IdenticalNameAndTypeName (ec, left_original, left, loc)) {
-                                                       
Report.SymbolRelatedToPreviousError (c);
-                                                       error176 (loc, 
c.GetSignatureForError ());
-                                                       return null;
-                                               }
-                                       
-                                               return exp;
-                                       }
-                               }
-
-                               // IsInitOnly is because of MS compatibility, I 
don't know why but they emit decimal constant as InitOnly
-                               if (fi.IsInitOnly && !is_emitted && t == 
TypeManager.decimal_type) {
-                                       object[] attrs = fi.GetCustomAttributes 
(TypeManager.decimal_constant_attribute_type, false);
-                                       if (attrs.Length == 1)
-                                               return new DecimalConstant 
(((System.Runtime.CompilerServices.DecimalConstantAttribute) attrs [0]).Value);
-                               }
-
-                               if (fi.IsLiteral) {
-                                       object o;
-
-                                       if (is_emitted)
-                                               o = TypeManager.GetValue 
((FieldBuilder) fi);
-                                       else
-                                               o = fi.GetValue (fi);
-                                       
-                                       if (decl_type.IsSubclassOf 
(TypeManager.enum_type)) {
-                                               if (left_is_explicit && 
!left_is_type &&
-                                                   !IdenticalNameAndTypeName 
(ec, left_original, member_lookup, loc)) {
-                                                       error176 (loc, 
fe.FieldInfo.Name);
-                                                       return null;
-                                               }                               
        
-                                               
-                                               Expression enum_member = 
MemberLookup (
-                                                       ec, decl_type, 
"value__", MemberTypes.Field,
-                                                       AllBindingFlags | 
BindingFlags.NonPublic, loc); 
-
-                                               Enum en = 
TypeManager.LookupEnum (decl_type);
-
-                                               Constant c;
-                                               if (en != null)
-                                                       c = Constantify (o, 
en.UnderlyingType);
-                                               else 
-                                                       c = Constantify (o, 
enum_member.Type);
-                                               
-                                               return new EnumConstant (c, 
decl_type);
-                                       }
-                                       
-                                       Expression exp = Constantify (o, t);
-
-                                       if (left_is_explicit && !left_is_type) {
-                                               error176 (loc, 
fe.FieldInfo.Name);
-                                               return null;
-                                       }
-                                       
-                                       return exp;
-                               }
-
-                               if (t.IsPointer && !ec.InUnsafe){
-                                       UnsafeError (loc);
-                                       return null;
-                               }
-                       }
-
-                       if (member_lookup is EventExpr) {
-                               EventExpr ee = (EventExpr) member_lookup;
-                               
-                               //
-                               // If the event is local to this class, we 
transform ourselves into
-                               // a FieldExpr
-                               //
-
-                               if (ee.EventInfo.DeclaringType == 
ec.ContainerType ||
-                                   
TypeManager.IsNestedChildOf(ec.ContainerType, ee.EventInfo.DeclaringType)) {
-                                       MemberInfo mi = GetFieldFromEvent (ee);
-
-                                       if (mi == null) {
-                                               //
-                                               // If this happens, then we 
have an event with its own
-                                               // accessors and private field 
etc so there's no need
-                                               // to transform ourselves.
-                                               //
-                                               ee.InstanceExpression = left;
-                                               return ee;
-                                       }
-
-                                       Expression ml = ExprClassFromMemberInfo 
(ec, mi, loc);
-                                       
-                                       if (ml == null) {
-                                               Report.Error (-200, loc, 
"Internal error!!");
-                                               return null;
-                                       }
-
-                                       if (!left_is_explicit)
-                                               left = null;
-                                       
-                                       ee.InstanceExpression = left;
-
-                                       return ResolveMemberAccess (ec, ml, 
left, loc, left_original);
-                               }
-                       }
-
-                       if (member_lookup is IMemberExpr) {
-                               IMemberExpr me = (IMemberExpr) member_lookup;
-                               MethodGroupExpr mg = me as MethodGroupExpr;
-
-                               if (left_is_type){
-                                       if ((mg != null) && left_is_explicit && 
left.Type.IsInterface)
-                                               mg.IsExplicitImpl = 
left_is_explicit;
-
-                                       if (!me.IsStatic){
-                                               if ((ec.IsFieldInitializer || 
ec.IsStatic) &&
-                                                   IdenticalNameAndTypeName 
(ec, left_original, member_lookup, loc))
-                                                       return member_lookup;
-
-                                               
SimpleName.Error_ObjectRefRequired (ec, loc, me.Name);
-                                               return null;
-                                       }
-
-                               } else {
-                                       if (!me.IsInstance){
-                                               if (IdenticalNameAndTypeName 
(ec, left_original, left, loc))
-                                                       return member_lookup;
-
-                                               if (left_is_explicit) {
-                                                       error176 (loc, me.Name);
-                                                       return null;
-                                               }
-                                       }
-
-                                       //
-                                       // Since we can not check for instance 
objects in SimpleName,
-                                       // becaue of the rule that allows types 
and variables to share
-                                       // the name (as long as they can be 
de-ambiguated later, see 
-                                       // IdenticalNameAndTypeName), we have 
to check whether left 
-                                       // is an instance variable in a static 
context
-                                       //
-                                       // However, if the left-hand value is 
explicitly given, then
-                                       // it is already our instance 
expression, so we aren't in
-                                       // static context.
-                                       //
-
-                                       if (ec.IsStatic && !left_is_explicit && 
left is IMemberExpr){
-                                               IMemberExpr mexp = 
(IMemberExpr) left;
-
-                                               if (!mexp.IsStatic){
-                                                       
SimpleName.Error_ObjectRefRequired (ec, loc, mexp.Name);
-                                                       return null;
-                                               }
-                                       }
-
-                                       if ((mg != null) && 
IdenticalNameAndTypeName (ec, left_original, left, loc))
-                                               mg.IdenticalTypeName = true;
-
-                                       me.InstanceExpression = left;
-                               }
-
-                               return member_lookup;
-                       }
-
-                       Console.WriteLine ("Left is: " + left);
-                       Report.Error (-100, loc, "Support for [" + 
member_lookup + "] is not present yet");
-                       Environment.Exit (1);
-                       return null;
-               }
-               
                public virtual Expression DoResolve (EmitContext ec, Expression 
right_side,
                                                     ResolveFlags flags)
                {
@@ -7637,7 +7416,7 @@
                        // definite assignment check on the actual field and 
not on the whole struct.
                        //
 
-                       Expression original = expr;
+                       SimpleName original = expr as SimpleName;
                        expr = expr.Resolve (ec, flags | 
ResolveFlags.Intermediate | ResolveFlags.DisableFlowAnalysis);
                        if (expr == null)
                                return null;
@@ -7727,7 +7506,7 @@
 
                        if (member_lookup is TypeExpr) {
                                if (!(expr is TypeExpr) && 
-                                   !IdenticalNameAndTypeName (ec, original, 
expr, loc)) {
+                                   (original == null || 
!original.IdenticalNameAndTypeName (ec, expr, loc))) {
                                        Error (572, "Can't reference type `" + 
Identifier + "' through an expression; try `" +
                                               member_lookup.Type + "' 
instead");
                                        return null;
@@ -7736,25 +7515,8 @@
                                return member_lookup;
                        }
 
-                       if (args != null) {
-                               string full_name = expr_type + "." + Identifier;
-
-                               if (member_lookup is FieldExpr) {
-                                       Report.Error (307, loc, "The field 
`{0}' cannot " +
-                                                     "be used with type 
arguments", full_name);
-                                       return null;
-                               } else if (member_lookup is EventExpr) {
-                                       Report.Error (307, loc, "The event 
`{0}' cannot " +
-                                                     "be used with type 
arguments", full_name);
-                                       return null;
-                               } else if (member_lookup is PropertyExpr) {
-                                       Report.Error (307, loc, "The property 
`{0}' cannot " +
-                                                     "be used with type 
arguments", full_name);
-                                       return null;
-                               }
-                       }
-                       
-                       member_lookup = ResolveMemberAccess (ec, member_lookup, 
expr, loc, original);
+                       MemberExpr me = (MemberExpr) member_lookup;
+                       member_lookup = me.ResolveMemberAccess (ec, expr, loc, 
original, false);
                        if (member_lookup == null)
                                return null;
 
@@ -8843,7 +8605,6 @@
                        Expression member_lookup;
                        Type current_type = ec.ContainerType;
                        Type base_type = current_type.BaseType;
-                       Expression e;
 
                        if (ec.IsStatic){
                                Error (1511, "Keyword base is not allowed in 
static method");
@@ -8869,10 +8630,12 @@
                                left = new TypeExpression (base_type, loc);
                        else
                                left = ec.GetThis (loc);
+
+                       MemberExpr me = (MemberExpr) member_lookup;
                        
-                       e = MemberAccess.ResolveMemberAccess (ec, 
member_lookup, left, loc, null);
+                       Expression e = me.ResolveMemberAccess (ec, left, loc, 
null, false);
 
-                       if (e is PropertyExpr){
+                       if (e is PropertyExpr) {
                                PropertyExpr pe = (PropertyExpr) e;
 
                                pe.IsBase = true;

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to