//
//
+using System;
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.Reflection;
+using System.Reflection.Emit;
+using System.Text;
+using SLE = System.Linq.Expressions;
+using System.Linq;
+
namespace Mono.CSharp {
- using System;
- using System.Collections;
- using System.Diagnostics;
- using System.Reflection;
- using System.Reflection.Emit;
- using System.Text;
-
-#if NET_4_0
- using SLE = System.Linq.Expressions;
-#endif
/// <remarks>
/// The ExprClass class contains the is used to pass the
/// nothing).
/// </remarks>
public enum ExprClass : byte {
- Invalid,
+ Unresolved = 0,
Value,
Variable,
// Mask of all the expression class flags.
MaskExprClass = VariableOrValue | Type | MethodGroup | TypeParameter,
- // Disable control flow analysis while resolving the expression.
- // This is used when resolving the instance expression of a field expression.
- DisableFlowAnalysis = 1 << 10,
-
// Set if this is resolving the first part of a MemberAccess.
Intermediate = 1 << 11,
-
- // Disable control flow analysis _of struct_ while resolving the expression.
- // This is used when resolving the instance expression of a field expression.
- DisableStructFlowAnalysis = 1 << 12,
-
}
//
{
}
- public virtual bool GetAttributableValue (ResolveContext ec, Type value_type, out object value)
- {
- Attribute.Error_AttributeArgumentNotValid (ec, loc);
- value = null;
- return false;
- }
-
public virtual string GetSignatureForError ()
{
return TypeManager.CSharpName (type);
}
- public static bool IsAccessorAccessible (Type invocation_type, MethodInfo mi, out bool must_do_cs1540_check)
+ public static bool IsAccessorAccessible (Type invocation_type, MethodSpec mi, out bool must_do_cs1540_check)
{
- MethodAttributes ma = mi.Attributes & MethodAttributes.MemberAccessMask;
+ var ma = mi.Modifiers & Modifiers.AccessibilityMask;
must_do_cs1540_check = false; // by default we do not check for this
- if (ma == MethodAttributes.Public)
+ if (ma == Modifiers.PUBLIC)
return true;
//
// If only accessible to the current class or children
//
- if (ma == MethodAttributes.Private)
+ if (ma == Modifiers.PRIVATE)
return TypeManager.IsPrivateAccessible (invocation_type, mi.DeclaringType) ||
TypeManager.IsNestedChildOf (invocation_type, mi.DeclaringType);
- if (TypeManager.IsThisOrFriendAssembly (invocation_type.Assembly, mi.DeclaringType.Assembly)) {
- if (ma == MethodAttributes.Assembly || ma == MethodAttributes.FamORAssem)
- return true;
- } else {
- if (ma == MethodAttributes.Assembly || ma == MethodAttributes.FamANDAssem)
- return false;
+ if ((ma & Modifiers.INTERNAL) != 0) {
+ var b = TypeManager.IsThisOrFriendAssembly (invocation_type.Assembly, mi.DeclaringType.Assembly);
+ if (b || ma == Modifiers.INTERNAL)
+ return b;
}
// Family and FamANDAssem require that we derive.
/// to a valid type (this is the type of the
/// expression).
/// </remarks>
- public abstract Expression DoResolve (ResolveContext ec);
+ protected abstract Expression DoResolve (ResolveContext rc);
- public virtual Expression DoResolveLValue (ResolveContext ec, Expression right_side)
+ public virtual Expression DoResolveLValue (ResolveContext rc, Expression right_side)
{
return null;
}
}
+ public void Error_ExpressionMustBeConstant (ResolveContext rc, Location loc, string e_name)
+ {
+ rc.Report.Error (133, loc, "The expression being assigned to `{0}' must be constant", e_name);
+ }
+
+ public void Error_ConstantCanBeInitializedWithNullOnly (ResolveContext rc, Type type, Location loc, string name)
+ {
+ rc.Report.Error (134, loc, "A constant `{0}' of reference type `{1}' can only be initialized with null",
+ name, TypeManager.CSharpName (type));
+ }
+
public static void Error_InvalidExpressionStatement (Report Report, Location loc)
{
Report.Error (201, loc, "Only assignment, call, increment, decrement, and new object " +
ec.Report.Error (131, loc, "The left-hand side of an assignment must be a variable, a property or an indexer");
}
- ResolveFlags ExprClassToResolveFlags
- {
+ ResolveFlags ExprClassToResolveFlags {
get {
switch (eclass) {
case ExprClass.Type:
/// </remarks>
public Expression Resolve (ResolveContext ec, ResolveFlags flags)
{
- if ((flags & ResolveFlags.MaskExprClass) == ResolveFlags.Type)
- return ResolveAsTypeStep (ec, false);
-
- bool do_flow_analysis = ec.DoFlowAnalysis;
- bool omit_struct_analysis = ec.OmitStructFlowAnalysis;
- if ((flags & ResolveFlags.DisableFlowAnalysis) != 0)
- do_flow_analysis = false;
- if ((flags & ResolveFlags.DisableStructFlowAnalysis) != 0)
- omit_struct_analysis = true;
+ if (eclass != ExprClass.Unresolved)
+ return this;
Expression e;
- using (ec.WithFlowAnalysis (do_flow_analysis, omit_struct_analysis)) {
- if (this is SimpleName) {
- bool intermediate = (flags & ResolveFlags.Intermediate) == ResolveFlags.Intermediate;
- e = ((SimpleName) this).DoResolve (ec, intermediate);
- } else {
- e = DoResolve (ec);
- }
+ if (this is SimpleName) {
+ e = ((SimpleName) this).DoResolve (ec, (flags & ResolveFlags.Intermediate) != 0);
+ } else {
+ e = DoResolve (ec);
}
if (e == null)
return null;
}
- if (e.type == null && !(e is Namespace)) {
- throw new Exception (
- "Expression " + e.GetType () +
- " did not set its type after Resolve\n" +
- "called from: " + this.GetType ());
- }
+ if (e.type == null)
+ throw new InternalErrorException ("Expression `{0}' didn't set its type in DoResolve", e.GetType ());
return e;
}
/// <summary>
/// Resolves an expression and performs semantic analysis on it.
/// </summary>
- public Expression Resolve (ResolveContext ec)
+ public Expression Resolve (ResolveContext rc)
{
- Expression e = Resolve (ec, ResolveFlags.VariableOrValue | ResolveFlags.MethodGroup);
-
- if (e != null && e.eclass == ExprClass.MethodGroup && RootContext.Version == LanguageVersion.ISO_1) {
- ((MethodGroupExpr) e).ReportUsageError (ec);
- return null;
- }
- return e;
- }
-
- public Constant ResolveAsConstant (ResolveContext ec, MemberCore mc)
- {
- Expression e = Resolve (ec);
- if (e == null)
- return null;
-
- Constant c = e as Constant;
- if (c != null)
- return c;
-
- if (type != null && TypeManager.IsReferenceType (type))
- Const.Error_ConstantCanBeInitializedWithNullOnly (type, loc, mc.GetSignatureForError (), ec.Report);
- else
- Const.Error_ExpressionMustBeConstant (loc, mc.GetSignatureForError (), ec.Report);
-
- return null;
+ return Resolve (rc, ResolveFlags.VariableOrValue | ResolveFlags.MethodGroup);
}
/// <summary>
return null;
}
- if (e.eclass == ExprClass.Invalid)
+ if (e.eclass == ExprClass.Unresolved)
throw new Exception ("Expression " + e + " ExprClass is Invalid after resolve");
if ((e.type == null) && !(e is GenericTypeExpr))
return e;
}
+ public virtual void EncodeAttributeValue (IMemberContext rc, AttributeEncoder enc, Type targetType)
+ {
+ Attribute.Error_AttributeArgumentNotValid (rc, loc);
+ }
+
/// <summary>
/// Emits the code for the expression
/// </summary>
/// </remarks>
public abstract void Emit (EmitContext ec);
+
// Emit code to branch to @target if this expression is equivalent to @on_true.
// The default implementation is to emit the value, and then emit a brtrue or brfalse.
// Subclasses can provide more efficient implementations, but those MUST be equivalent,
protected Expression ()
{
- eclass = ExprClass.Invalid;
- type = null;
}
/// <summary>
public static Expression ExprClassFromMemberInfo (Type container_type, MemberInfo mi, Location loc)
{
if (mi is EventInfo)
- return new EventExpr ((EventInfo) mi, loc);
+ return new EventExpr (Import.CreateEvent ((EventInfo) mi), loc);
else if (mi is FieldInfo) {
FieldInfo fi = (FieldInfo) mi;
- if (fi.IsLiteral || (fi.IsInitOnly && fi.FieldType == TypeManager.decimal_type))
- return new ConstantExpr (fi, loc);
- return new FieldExpr (fi, loc);
+ var spec = Import.CreateField (fi);
+ if (spec is ConstSpec)
+ return new ConstantExpr ((ConstSpec) spec, loc);
+ return new FieldExpr (spec, loc);
} else if (mi is PropertyInfo)
- return new PropertyExpr (container_type, (PropertyInfo) mi, loc);
+ return new PropertyExpr (container_type, Import.CreateProperty ((PropertyInfo) mi), loc);
else if (mi is Type) {
return new TypeExpression ((System.Type) mi, loc);
}
}
// TODO: [Obsolete ("Can be removed")]
- protected static ArrayList almost_matched_members = new ArrayList (4);
+ protected static IList<MemberInfo> almost_matched_members = new List<MemberInfo> (4);
//
// FIXME: Probably implement a cache for (t,name,current_access_set)?
if (mi.Length > 1) {
bool is_interface = qualifier_type != null && qualifier_type.IsInterface;
- ArrayList methods = new ArrayList (2);
- ArrayList non_methods = null;
+ var methods = new List<MethodSpec> (2);
+ List<MemberInfo> non_methods = null;
- foreach (MemberInfo m in mi) {
+ foreach (var m in mi) {
if (m is MethodBase) {
- methods.Add (m);
+ methods.Add (Import.CreateMethod ((MethodBase) m));
continue;
}
if (non_methods == null)
- non_methods = new ArrayList (2);
+ non_methods = new List<MemberInfo> (2);
bool is_candidate = true;
for (int i = 0; i < non_methods.Count; ++i) {
- MemberInfo n_m = (MemberInfo) non_methods [i];
+ MemberInfo n_m = non_methods [i];
if (n_m.DeclaringType.IsInterface && TypeManager.ImplementsInterface (m.DeclaringType, n_m.DeclaringType)) {
non_methods.Remove (n_m);
--i;
}
if (methods.Count == 0 && non_methods != null && non_methods.Count > 1) {
- ctx.Report.SymbolRelatedToPreviousError ((MemberInfo)non_methods [1]);
- ctx.Report.SymbolRelatedToPreviousError ((MemberInfo)non_methods [0]);
+ ctx.Report.SymbolRelatedToPreviousError (non_methods [1]);
+ ctx.Report.SymbolRelatedToPreviousError (non_methods [0]);
ctx.Report.Error (229, loc, "Ambiguity between `{0}' and `{1}'",
- TypeManager.GetFullNameSignature ((MemberInfo)non_methods [1]),
- TypeManager.GetFullNameSignature ((MemberInfo)non_methods [0]));
+ TypeManager.GetFullNameSignature (non_methods [1]),
+ TypeManager.GetFullNameSignature (non_methods [0]));
return null;
}
return ExprClassFromMemberInfo (container_type, (MemberInfo)non_methods [0], loc);
if (non_methods != null && non_methods.Count > 0) {
- MethodBase method = (MethodBase) methods [0];
+ var method = methods [0];
MemberInfo non_method = (MemberInfo) non_methods [0];
if (method.DeclaringType == non_method.DeclaringType) {
// Cannot happen with C# code, but is valid in IL
- ctx.Report.SymbolRelatedToPreviousError (method);
+ ctx.Report.SymbolRelatedToPreviousError (method.MetaInfo);
ctx.Report.SymbolRelatedToPreviousError (non_method);
ctx.Report.Error (229, loc, "Ambiguity between `{0}' and `{1}'",
TypeManager.GetFullNameSignature (non_method),
- TypeManager.CSharpSignature (method));
+ TypeManager.CSharpSignature (method.MetaInfo));
return null;
}
if (is_interface) {
- ctx.Report.SymbolRelatedToPreviousError (method);
+ ctx.Report.SymbolRelatedToPreviousError (method.MetaInfo);
ctx.Report.SymbolRelatedToPreviousError (non_method);
ctx.Report.Warning (467, 2, loc, "Ambiguity between method `{0}' and non-method `{1}'. Using method `{0}'",
- TypeManager.CSharpSignature (method), TypeManager.GetFullNameSignature (non_method));
+ TypeManager.CSharpSignature (method.MetaInfo), TypeManager.GetFullNameSignature (non_method));
}
}
}
if (mi [0] is MethodBase)
- return new MethodGroupExpr (mi, queried_type, loc);
+ return new MethodGroupExpr (mi.Select (l => Import.CreateMethod ((MethodBase) l)).ToArray (), queried_type, loc);
return ExprClassFromMemberInfo (container_type, mi [0], loc);
}
protected virtual Expression Error_MemberLookupFailed (ResolveContext ec, Type type, MemberInfo[] members)
{
+ List<MethodSpec> methods = new List<MethodSpec> ();
for (int i = 0; i < members.Length; ++i) {
if (!(members [i] is MethodBase))
return null;
+
+ methods.Add (Import.CreateMethod (members[i] as MethodBase));
}
// By default propagate the closest candidates upwards
- return new MethodGroupExpr (members, type, loc, true);
+ return new MethodGroupExpr (methods.ToArray (), type, loc, true);
}
protected virtual void Error_NegativeArrayIndex (ResolveContext ec, Location loc)
{
get {
switch (eclass){
- case ExprClass.Invalid:
- return "Invalid";
+ case ExprClass.Unresolved:
+ return "Unresolved";
case ExprClass.Value:
return "value";
case ExprClass.Variable:
{
TypeExpr texpr = TypeManager.expression_type_expr;
if (texpr == null) {
- Type t = TypeManager.CoreLookupType (ec.Compiler, "System.Linq.Expressions", "Expression", Kind.Class, true);
+ Type t = TypeManager.CoreLookupType (ec.Compiler, "System.Linq.Expressions", "Expression", MemberKind.Class, true);
if (t == null)
return null;
return texpr;
}
-#if NET_4_0
//
// Implemented by all expressions which support conversion from
// compiler expression to invokable runtime expression. Used by
{
throw new NotImplementedException ("MakeExpression for " + GetType ());
}
-#endif
public virtual void MutateHoistedGenericType (AnonymousMethodStorey storey)
{
this.child = child;
}
+ public Expression Child {
+ get {
+ return child;
+ }
+ }
+
public override Expression CreateExpressionTree (ResolveContext ec)
{
Arguments args = new Arguments (2);
return CreateExpressionFactoryCall (ec, ec.HasSet (ResolveContext.Options.CheckedScope) ? "ConvertChecked" : "Convert", args);
}
- public override Expression DoResolve (ResolveContext ec)
+ protected override Expression DoResolve (ResolveContext ec)
{
// This should never be invoked, we are born in fully
// initialized state.
child.Emit (ec);
}
- public override bool GetAttributableValue (ResolveContext ec, Type value_type, out object value)
- {
- return child.GetAttributableValue (ec, value_type, out value);
- }
-
-#if NET_4_0
public override SLE.Expression MakeExpression (BuilderContext ctx)
{
return ctx.HasSet (BuilderContext.Options.CheckedScope) ?
SLE.Expression.ConvertChecked (child.MakeExpression (ctx), type) :
SLE.Expression.Convert (child.MakeExpression (ctx), type);
}
-#endif
public override void MutateHoistedGenericType (AnonymousMethodStorey storey)
{
/// </summary>
public class CastFromDecimal : TypeCast
{
- static IDictionary operators;
+ static Dictionary<Type, MethodInfo> operators;
public CastFromDecimal (Expression child, Type return_type)
: base (child, return_type)
public Expression Resolve ()
{
if (operators == null) {
- MemberInfo[] all_oper = TypeManager.MemberLookup (TypeManager.decimal_type,
- TypeManager.decimal_type, TypeManager.decimal_type, MemberTypes.Method,
- BindingFlags.Static | BindingFlags.Public, "op_Explicit", null);
+ MemberInfo[] all_oper = TypeManager.MemberLookup (TypeManager.decimal_type,
+ TypeManager.decimal_type, TypeManager.decimal_type, MemberTypes.Method,
+ BindingFlags.Static | BindingFlags.Public, "op_Explicit", null);
- operators = new System.Collections.Specialized.HybridDictionary ();
+ operators = new Dictionary<Type, MethodInfo> (ReferenceEquality<Type>.Default);
foreach (MethodInfo oper in all_oper) {
AParametersCollection pd = TypeManager.GetParameterData (oper);
if (pd.Types [0] == TypeManager.decimal_type)
}
}
- return operators.Contains (type) ? this : null;
+ return operators.ContainsKey (type) ? this : null;
}
public override void Emit (EmitContext ec)
ILGenerator ig = ec.ig;
child.Emit (ec);
- ig.Emit (OpCodes.Call, (MethodInfo)operators [type]);
+ ig.Emit (OpCodes.Call, operators [type]);
}
}
//
public class EmptyConstantCast : Constant
{
- public readonly Constant child;
+ public Constant child;
- public EmptyConstantCast(Constant child, Type type)
+ public EmptyConstantCast (Constant child, Type type)
: base (child.Location)
{
- eclass = child.eclass;
+ if (child == null)
+ throw new ArgumentNullException ("child");
+
this.child = child;
+ this.eclass = child.eclass;
this.type = type;
}
public override Constant ConvertExplicitly (bool in_checked_context, Type target_type)
{
+ if (child.Type == target_type)
+ return child;
+
// FIXME: check that 'type' can be converted to 'target_type' first
return child.ConvertExplicitly (in_checked_context, target_type);
}
return CreateExpressionFactoryCall (ec, "Convert", args);
}
- public override Constant Increment ()
- {
- return child.Increment ();
- }
-
public override bool IsDefaultValue {
get { return child.IsDefaultValue; }
}
public override bool IsNull {
get { return child.IsNull; }
}
+
+ public override bool IsOneInteger {
+ get { return child.IsOneInteger; }
+ }
public override bool IsZeroInteger {
get { return child.IsZeroInteger; }
}
+
+ protected override Expression DoResolve (ResolveContext rc)
+ {
+ return this;
+ }
public override void Emit (EmitContext ec)
{
child.EmitSideEffect (ec);
}
- public override Constant ConvertImplicitly (Type target_type)
+ public override Constant ConvertImplicitly (ResolveContext rc, Type target_type)
{
// FIXME: Do we need to check user conversions?
if (!Convert.ImplicitStandardConversionExists (this, target_type))
return null;
- return child.ConvertImplicitly (target_type);
+ return child.ConvertImplicitly (rc, target_type);
}
public override void MutateHoistedGenericType (AnonymousMethodStorey storey)
}
}
-
/// <summary>
/// This class is used to wrap literals which belong inside Enums
/// </summary>
- public class EnumConstant : Constant {
+ public class EnumConstant : Constant
+ {
public Constant Child;
- public EnumConstant (Constant child, Type enum_type):
- base (child.Location)
+ public EnumConstant (Constant child, Type enum_type)
+ : base (child.Location)
{
- eclass = child.eclass;
this.Child = child;
- type = enum_type;
+ this.type = enum_type;
}
- protected EnumConstant ()
- : base (Location.Null)
+ protected EnumConstant (Location loc)
+ : base (loc)
{
}
-
- public override Expression DoResolve (ResolveContext ec)
- {
- // This should never be invoked, we are born in fully
- // initialized state.
+ protected override Expression DoResolve (ResolveContext rc)
+ {
+ Child = Child.Resolve (rc);
+ this.eclass = ExprClass.Value;
return this;
}
Child.Emit (ec);
}
+ public override void EncodeAttributeValue (IMemberContext rc, AttributeEncoder enc, Type targetType)
+ {
+ Child.EncodeAttributeValue (rc, enc, Child.Type);
+ }
+
public override void EmitBranchable (EmitContext ec, Label label, bool on_true)
{
Child.EmitBranchable (ec, label, on_true);
Child.EmitSideEffect (ec);
}
- public override bool GetAttributableValue (ResolveContext ec, Type value_type, out object value)
- {
- value = GetTypedValue ();
- return true;
- }
-
public override string GetSignatureForError()
{
return TypeManager.CSharpName (Type);
return Child.AsString ();
}
- public override Constant Increment()
+ public EnumConstant Increment()
{
- return new EnumConstant (Child.Increment (), type);
+ return new EnumConstant (((IntegralConstant) Child).Increment (), type);
}
public override bool IsDefaultValue {
return Child.ConvertExplicitly (in_checked_context, target_type);
}
- public override Constant ConvertImplicitly (Type type)
+ public override Constant ConvertImplicitly (ResolveContext rc, Type type)
{
Type this_type = TypeManager.DropGenericTypeArguments (Type);
type = TypeManager.DropGenericTypeArguments (type);
Type child_type = TypeManager.DropGenericTypeArguments (Child.Type);
if (type.UnderlyingSystemType != child_type)
- Child = Child.ConvertImplicitly (type.UnderlyingSystemType);
+ Child = Child.ConvertImplicitly (rc, type.UnderlyingSystemType);
return this;
}
return null;
}
- return Child.ConvertImplicitly(type);
+ return Child.ConvertImplicitly (rc, type);
}
-
}
/// <summary>
eclass = ExprClass.Value;
}
- public override Expression DoResolve (ResolveContext ec)
+ protected override Expression DoResolve (ResolveContext ec)
{
// This should never be invoked, we are born in fully
// initialized state.
return this;
}
+ public override void EncodeAttributeValue (IMemberContext rc, AttributeEncoder enc, Type targetType)
+ {
+ enc.Encode (child.Type);
+ child.EncodeAttributeValue (rc, enc, child.Type);
+ }
+
public override void Emit (EmitContext ec)
{
base.Emit (ec);
{
}
- public override Expression DoResolve (ResolveContext ec)
+ protected override Expression DoResolve (ResolveContext ec)
{
// This should never be invoked, we are born in fully
// initialized state.
mode = m;
}
- public override Expression DoResolve (ResolveContext ec)
+ protected override Expression DoResolve (ResolveContext ec)
{
// This should never be invoked, we are born in fully
// initialized state.
this.op = op;
}
- public override Expression DoResolve (ResolveContext ec)
+ protected override Expression DoResolve (ResolveContext ec)
{
// This should never be invoked, we are born in fully
// initialized state.
this.orig_expr = orig_expr;
}
- public override Constant ConvertImplicitly (Type target_type)
+ public override Constant ConvertImplicitly (ResolveContext rc, Type target_type)
{
- Constant c = base.ConvertImplicitly (target_type);
+ Constant c = base.ConvertImplicitly (rc, target_type);
if (c != null)
c = new ReducedConstantExpression (c, orig_expr);
+
return c;
}
return orig_expr.CreateExpressionTree (ec);
}
- public override bool GetAttributableValue (ResolveContext ec, Type value_type, out object value)
- {
- //
- // Even if resolved result is a constant original expression was not
- // and attribute accepts constants only
- //
- Attribute.Error_AttributeArgumentNotValid (ec, orig_expr.Location);
- value = null;
- return false;
- }
-
public override Constant ConvertExplicitly (bool in_checked_context, Type target_type)
{
Constant c = base.ConvertExplicitly (in_checked_context, target_type);
return orig_expr.CreateExpressionTree (ec);
}
- public override Expression DoResolve (ResolveContext ec)
+ protected override Expression DoResolve (ResolveContext ec)
{
eclass = stm.eclass;
type = stm.Type;
private ReducedExpression (Expression expr, Expression orig_expr)
{
this.expr = expr;
+ this.eclass = expr.eclass;
+ this.type = expr.Type;
this.orig_expr = orig_expr;
this.loc = orig_expr.Location;
}
+ //
+ // Creates fully resolved expression switcher
+ //
public static Constant Create (Constant expr, Expression original_expr)
{
+ if (expr.eclass == ExprClass.Unresolved)
+ throw new ArgumentException ("Unresolved expression");
+
return new ReducedConstantExpression (expr, original_expr);
}
return new ReducedExpressionStatement (s, orig);
}
+ //
+ // Creates unresolved reduce expression. The original expression has to be
+ // already resolved
+ //
public static Expression Create (Expression expr, Expression original_expr)
{
Constant c = expr as Constant;
if (s != null)
return Create (s, original_expr);
+ if (expr.eclass == ExprClass.Unresolved)
+ throw new ArgumentException ("Unresolved expression");
+
return new ReducedExpression (expr, original_expr);
}
return orig_expr.CreateExpressionTree (ec);
}
- public override Expression DoResolve (ResolveContext ec)
+ protected override Expression DoResolve (ResolveContext ec)
{
- eclass = expr.eclass;
- type = expr.Type;
return this;
}
expr.EmitBranchable (ec, target, on_true);
}
-#if NET_4_0
public override SLE.Expression MakeExpression (BuilderContext ctx)
{
return orig_expr.MakeExpression (ctx);
}
-#endif
public override void MutateHoistedGenericType (AnonymousMethodStorey storey)
{
get { return expr; }
}
- public override Expression DoResolve (ResolveContext ec)
+ protected override Expression DoResolve (ResolveContext ec)
{
expr = expr.Resolve (ec);
if (expr != null) {
/// SimpleName expressions are formed of a single word and only happen at the beginning
/// of a dotted-name.
/// </summary>
- public class SimpleName : ATypeNameExpression {
- bool in_transit;
-
+ public class SimpleName : ATypeNameExpression
+ {
public SimpleName (string name, Location l)
: base (name, l)
{
(mc.LookupNamespaceOrType (Name, loc, /* ignore_cs0104 = */ true) != null);
}
- public override Expression DoResolve (ResolveContext ec)
+ protected override Expression DoResolve (ResolveContext ec)
{
return SimpleNameResolve (ec, null, false);
}
{
return SimpleNameResolve (ec, right_side, false);
}
-
public Expression DoResolve (ResolveContext ec, bool intermediate)
{
if (ec.CurrentTypeDefinition != null) {
Type t = ec.CurrentTypeDefinition.LookupAnyGeneric (Name);
if (t != null) {
- Namespace.Error_InvalidNumberOfTypeArguments (t, loc);
+ Namespace.Error_InvalidNumberOfTypeArguments (ec.Compiler.Report, t, loc);
return;
}
}
Expression SimpleNameResolve (ResolveContext ec, Expression right_side, bool intermediate)
{
- if (in_transit)
- return null;
-
- in_transit = true;
Expression e = DoSimpleNameResolve (ec, right_side, intermediate);
- in_transit = false;
if (e == null)
return null;
if (right_side != null) {
e = e.ResolveLValue (ec, right_side);
} else {
- ResolveFlags rf = ResolveFlags.VariableOrValue;
- if (intermediate)
- rf |= ResolveFlags.DisableFlowAnalysis;
-
- e = e.Resolve (ec, rf);
+ if (intermediate) {
+ using (ec.With (ResolveContext.Options.DoFlowAnalysis, false)) {
+ e = e.Resolve (ec, ResolveFlags.VariableOrValue);
+ }
+ } else {
+ e = e.Resolve (ec, ResolveFlags.VariableOrValue);
+ }
}
if (targs != null && e != null)
//
Type almost_matched_type = null;
- ArrayList almost_matched = null;
+ IList<MemberInfo> almost_matched = null;
for (Type lookup_ds = ec.CurrentType; lookup_ds != null; lookup_ds = lookup_ds.DeclaringType) {
e = MemberLookup (ec.Compiler, ec.CurrentType, lookup_ds, Name, loc);
if (e != null) {
if (almost_matched == null && almost_matched_members.Count > 0) {
almost_matched_type = lookup_ds;
- almost_matched = (ArrayList) almost_matched_members.Clone ();
+ almost_matched = new List<MemberInfo>(almost_matched_members);
}
}
if (e == null) {
if (almost_matched == null && almost_matched_members.Count > 0) {
almost_matched_type = ec.CurrentType;
- almost_matched = (ArrayList) almost_matched_members.Clone ();
+ almost_matched = new List<MemberInfo> (almost_matched_members);
}
e = ResolveAsTypeStep (ec, true);
}
if (RootContext.EvalMode){
FieldInfo fi = Evaluator.LookupField (Name);
if (fi != null)
- return new FieldExpr (fi, loc).Resolve (ec);
+ return new FieldExpr (Import.CreateField (fi), loc).Resolve (ec);
}
if (almost_matched != null)
return (right_side != null)
? me.DoResolveLValue (ec, right_side)
- : me.DoResolve (ec);
+ : me.Resolve (ec);
}
return e;
return t;
}
- override public Expression DoResolve (ResolveContext ec)
+ protected override Expression DoResolve (ResolveContext ec)
{
return ResolveAsTypeTerminal (ec, false);
}
public Expression ExtensionExpression;
Argument extension_argument;
- public ExtensionMethodGroupExpr (ArrayList list, NamespaceEntry n, Type extensionType, Location l)
+ public ExtensionMethodGroupExpr (List<MethodSpec> list, NamespaceEntry n, Type extensionType, Location l)
: base (list, extensionType, l)
{
this.namespace_entry = n;
{
public interface IErrorHandler
{
- bool AmbiguousCall (ResolveContext ec, MethodBase ambiguous);
- bool NoExactMatch (ResolveContext ec, MethodBase method);
+ bool AmbiguousCall (ResolveContext ec, MethodSpec ambiguous);
+ bool NoExactMatch (ResolveContext ec, MethodSpec method);
}
- public IErrorHandler CustomErrorHandler;
- public MethodBase [] Methods;
- MethodBase best_candidate;
+ public IErrorHandler CustomErrorHandler;
+ public MethodSpec [] Methods;
+ MethodSpec best_candidate;
// TODO: make private
public TypeArguments type_arguments;
bool identical_type_name;
Type delegate_type;
Type queried_type;
- public MethodGroupExpr (MemberInfo [] mi, Type type, Location l)
+ public MethodGroupExpr (MethodSpec [] mi, Type type, Location l)
: this (type, l)
{
- Methods = new MethodBase [mi.Length];
+ Methods = new MethodSpec[mi.Length];
mi.CopyTo (Methods, 0);
}
- public MethodGroupExpr (MemberInfo[] mi, Type type, Location l, bool inacessibleCandidatesOnly)
+ public MethodGroupExpr (MethodSpec[] mi, Type type, Location l, bool inacessibleCandidatesOnly)
: this (mi, type, l)
{
has_inaccessible_candidates_only = inacessibleCandidatesOnly;
}
- public MethodGroupExpr (ArrayList list, Type type, Location l)
+ public MethodGroupExpr (List<MethodSpec> list, Type type, Location l)
: this (type, l)
{
try {
- Methods = (MethodBase[])list.ToArray (typeof (MethodBase));
+ Methods = list.ToArray ();
} catch {
- foreach (MemberInfo m in list){
- if (!(m is MethodBase)){
- Console.WriteLine ("Name " + m.Name);
- Console.WriteLine ("Found a: " + m.GetType ().FullName);
- }
- }
+ //foreach (MemberInfo m in list){
+ // if (!(m is MethodBase)){
+ // Console.WriteLine ("Name " + m.Name);
+ // Console.WriteLine ("Found a: " + m.GetType ().FullName);
+ // }
+ //}
throw;
}
}
}
+ public MethodSpec BestCandidate {
+ get {
+ return best_candidate;
+ }
+ }
+
public Type DelegateType {
set {
delegate_type = value;
public override string GetSignatureForError ()
{
if (best_candidate != null)
- return TypeManager.CSharpSignature (best_candidate);
+ return TypeManager.CSharpSignature (best_candidate.MetaInfo);
- return TypeManager.CSharpSignature (Methods [0]);
+ return TypeManager.CSharpSignature (Methods [0].MetaInfo);
}
public override string Name {
if (best_candidate != null)
return !best_candidate.IsStatic;
- foreach (MethodBase mb in Methods)
+ foreach (var mb in Methods)
if (!mb.IsStatic)
return true;
if (best_candidate != null)
return best_candidate.IsStatic;
- foreach (MethodBase mb in Methods)
+ foreach (var mb in Methods)
if (mb.IsStatic)
return true;
return false;
}
}
-
- public static explicit operator ConstructorInfo (MethodGroupExpr mg)
- {
- return (ConstructorInfo)mg.best_candidate;
- }
- public static explicit operator MethodInfo (MethodGroupExpr mg)
+ public static explicit operator MethodSpec (MethodGroupExpr mg)
{
- return (MethodInfo)mg.best_candidate;
+ return mg.best_candidate;
}
//
if (q == TypeManager.ushort_type || q == TypeManager.uint32_type ||
q == TypeManager.uint64_type)
return 1;
+ } else if (p == InternalType.Dynamic) {
+ if (q == TypeManager.object_type)
+ return 2;
}
if (q == TypeManager.int32_type) {
if (p == TypeManager.ushort_type || p == TypeManager.uint32_type ||
p == TypeManager.uint64_type)
return 2;
+ } else if (q == InternalType.Dynamic) {
+ if (p == TypeManager.object_type)
+ return 1;
}
// TODO: this is expensive
/// true if candidate is better than the current best match
/// </remarks>
static bool BetterFunction (ResolveContext ec, Arguments args, int argument_count,
- MethodBase candidate, bool candidate_params,
- MethodBase best, bool best_params)
+ MethodSpec candidate, bool candidate_params,
+ MethodSpec best, bool best_params)
{
- AParametersCollection candidate_pd = TypeManager.GetParameterData (candidate);
- AParametersCollection best_pd = TypeManager.GetParameterData (best);
+ AParametersCollection candidate_pd = candidate.Parameters;
+ AParametersCollection best_pd = best.Parameters;
bool better_at_least_one = false;
bool same = true;
bt = TypeManager.GetElementType (bt);
--b_idx;
}
-
- if (ct.Equals (bt))
+
+ if (TypeManager.IsEqual (ct, bt))
continue;
same = false;
//
// The two methods have equal parameter types. Now apply tie-breaking rules
//
- if (TypeManager.IsGenericMethod (best)) {
- if (!TypeManager.IsGenericMethod (candidate))
+ if (best.IsGenericMethod) {
+ if (!candidate.IsGenericMethod)
return true;
- } else if (TypeManager.IsGenericMethod (candidate)) {
+ } else if (candidate.IsGenericMethod) {
return false;
}
return null;
}
- IMethodData md = TypeManager.GetMethod (best_candidate);
+ IMethodData md = TypeManager.GetMethod (best_candidate.MetaInfo);
if (md != null && md.IsExcluded ())
ec.Report.Error (765, loc,
"Partial methods with only a defining declaration or removed conditional methods cannot be used in an expression tree");
return new TypeOfMethod (best_candidate, loc);
}
- override public Expression DoResolve (ResolveContext ec)
+ protected override Expression DoResolve (ResolveContext ec)
{
+ this.eclass = ExprClass.MethodGroup;
+
if (InstanceExpression != null) {
- InstanceExpression = InstanceExpression.DoResolve (ec);
+ InstanceExpression = InstanceExpression.Resolve (ec);
if (InstanceExpression == null)
return null;
}
Invocation.EmitCall (ec, IsBase, InstanceExpression, best_candidate, arguments, loc);
}
- void Error_AmbiguousCall (ResolveContext ec, MethodBase ambiguous)
+ void Error_AmbiguousCall (ResolveContext ec, MethodSpec ambiguous)
{
if (CustomErrorHandler != null && CustomErrorHandler.AmbiguousCall (ec, ambiguous))
return;
- ec.Report.SymbolRelatedToPreviousError (best_candidate);
+ ec.Report.SymbolRelatedToPreviousError (best_candidate.MetaInfo);
ec.Report.Error (121, loc, "The call is ambiguous between the following methods or properties: `{0}' and `{1}'",
- TypeManager.CSharpSignature (ambiguous), TypeManager.CSharpSignature (best_candidate));
+ TypeManager.CSharpSignature (ambiguous), TypeManager.CSharpSignature (best_candidate.MetaInfo));
}
- protected virtual void Error_InvalidArguments (ResolveContext ec, Location loc, int idx, MethodBase method,
+ protected virtual void Error_InvalidArguments (ResolveContext ec, Location loc, int idx, MethodSpec method,
Argument a, AParametersCollection expected_par, Type paramType)
{
ExtensionMethodGroupExpr emg = this as ExtensionMethodGroupExpr;
if (a is CollectionElementInitializer.ElementInitializerArgument) {
- ec.Report.SymbolRelatedToPreviousError (method);
+ ec.Report.SymbolRelatedToPreviousError (method.MetaInfo);
if ((expected_par.FixedParameters [idx].ModFlags & Parameter.Modifier.ISBYREF) != 0) {
ec.Report.Error (1954, loc, "The best overloaded collection initalizer method `{0}' cannot have 'ref', or `out' modifier",
TypeManager.CSharpSignature (method));
ec.Report.Error (1594, loc, "Delegate `{0}' has some invalid arguments",
TypeManager.CSharpName (method.DeclaringType));
} else {
- ec.Report.SymbolRelatedToPreviousError (method);
+ ec.Report.SymbolRelatedToPreviousError (method.MetaInfo);
if (emg != null) {
ec.Report.Error (1928, loc,
"Type `{0}' does not contain a member `{1}' and the best extension method overload `{2}' has some invalid arguments",
Name, arg_count.ToString ());
}
- protected virtual int GetApplicableParametersCount (MethodBase method, AParametersCollection parameters)
+ protected virtual int GetApplicableParametersCount (MethodSpec method, AParametersCollection parameters)
{
return parameters.Count;
}
/// 0 = the best, int.MaxValue = the worst
///
public int IsApplicable (ResolveContext ec,
- ref Arguments arguments, int arg_count, ref MethodBase method, ref bool params_expanded_form)
+ ref Arguments arguments, int arg_count, ref MethodSpec method, ref bool params_expanded_form)
{
- MethodBase candidate = method;
+ var candidate = method;
- AParametersCollection pd = TypeManager.GetParameterData (candidate);
+ AParametersCollection pd = candidate.Parameters;
int param_count = GetApplicableParametersCount (candidate, pd);
int optional_count = 0;
}
}
- int args_gap = Math.Abs (arg_count - param_count);
+ int args_gap = System.Math.Abs (arg_count - param_count);
if (optional_count != 0) {
if (args_gap > optional_count)
return int.MaxValue - 10000 + args_gap - optional_count;
if (na == null)
break;
- int index = pd.GetParameterIndexByName (na.Name.Value);
+ int index = pd.GetParameterIndexByName (na.Name);
// Named parameter not found or already reordered
if (index <= i)
//
// 1. Handle generic method using type arguments when specified or type inference
//
- if (TypeManager.IsGenericMethod (candidate)) {
+ if (candidate.IsGenericMethod) {
if (type_arguments != null) {
Type [] g_args = candidate.GetGenericArguments ();
if (g_args.Length != type_arguments.Count)
- return int.MaxValue - 20000 + Math.Abs (type_arguments.Count - g_args.Length);
+ return int.MaxValue - 20000 + System.Math.Abs (type_arguments.Count - g_args.Length);
- // TODO: Don't create new method, create Parameters only
- method = ((MethodInfo) candidate).MakeGenericMethod (type_arguments.Arguments);
+ method = candidate.Inflate (type_arguments.Arguments);
candidate = method;
- pd = TypeManager.GetParameterData (candidate);
+ pd = candidate.Parameters;
} else {
int score = TypeManager.InferTypeArguments (ec, arguments, ref candidate);
if (score != 0)
return score - 20000;
- if (TypeManager.IsGenericMethodDefinition (candidate))
+ if (TypeManager.IsGenericMethodDefinition (candidate.MetaInfo))
throw new InternalErrorException ("A generic method `{0}' definition took part in overload resolution",
- TypeManager.CSharpSignature (candidate));
+ TypeManager.CSharpSignature (candidate.MetaInfo));
- pd = TypeManager.GetParameterData (candidate);
+ pd = candidate.Parameters;
}
} else {
if (type_arguments != null)
if (TypeManager.HasElementType (a_type))
a_type = TypeManager.GetElementType (a_type);
- if (a_type != parameter)
+ if (a_type != parameter) {
+ if (TypeManager.IsDynamicType (a_type))
+ return 0;
+
return 2;
+ }
} else {
- if (!Convert.ImplicitConversionExists (ec, argument.Expr, parameter))
+ if (!Convert.ImplicitConversionExists (ec, argument.Expr, parameter)) {
+ if (TypeManager.IsDynamicType (argument.Type))
+ return 0;
+
return 2;
+ }
}
if (arg_mod != param_mod)
if (mg2 == null)
return mg1;
-
- ArrayList all = new ArrayList (mg1.Methods);
- foreach (MethodBase m in mg2.Methods){
- if (!TypeManager.ArrayContainsMethod (mg1.Methods, m, false))
+
+ var all = new List<MethodSpec> (mg1.Methods);
+ foreach (var m in mg2.Methods){
+ if (!TypeManager.ArrayContainsMethod (mg1.Methods.Select (l => l.MetaInfo).ToArray (), m.MetaInfo, false))
all.Add (m);
}
{
base.MutateHoistedGenericType (storey);
- MethodInfo mi = best_candidate as MethodInfo;
- if (mi != null) {
- best_candidate = storey.MutateGenericMethod (mi);
- return;
+ if (best_candidate.IsConstructor) {
+ storey.MutateConstructor (best_candidate);
+ } else {
+ storey.MutateGenericMethod (best_candidate);
}
-
- best_candidate = storey.MutateConstructor ((ConstructorInfo) this);
}
/// <summary>
{
bool method_params = false;
Type applicable_type = null;
- ArrayList candidates = new ArrayList (2);
- ArrayList candidate_overrides = null;
+ var candidates = new List<MethodSpec> (2);
+ List<MethodSpec> candidate_overrides = null;
//
// Used to keep a map between the candidate
//
// false is normal form, true is expanded form
//
- Hashtable candidate_to_form = null;
- Hashtable candidates_expanded = null;
+ Dictionary<MethodSpec, MethodSpec> candidate_to_form = null;
+ Dictionary<MethodSpec, Arguments> candidates_expanded = null;
Arguments candidate_args = Arguments;
int arg_count = Arguments != null ? Arguments.Count : 0;
// with non-C# libraries which change the visibility of overrides (#75636)
//
int j = 0;
+ MethodBase mb = null;
for (int i = 0; i < Methods.Length; ++i) {
- MethodBase m = Methods [i];
+ var m = Methods [i];
+ mb = m.MetaInfo;
if (TypeManager.IsOverride (m)) {
if (candidate_overrides == null)
- candidate_overrides = new ArrayList ();
+ candidate_overrides = new List<MethodSpec> ();
candidate_overrides.Add (m);
- m = TypeManager.TryGetBaseDefinition (m);
+ mb = TypeManager.TryGetBaseDefinition (mb);
+ if (mb != null && Array.Exists (Methods, l => l.MetaInfo == mb))
+ continue;
}
- if (m != null)
- Methods [j++] = m;
+ if (mb != null)
+ Methods [j++] = Import.CreateMethod (mb);
}
nmethods = j;
}
if (params_expanded_form) {
if (candidate_to_form == null)
- candidate_to_form = new PtrHashtable ();
- MethodBase candidate = Methods [i];
+ candidate_to_form = new Dictionary<MethodSpec, MethodSpec> (4, ReferenceEquality<MethodSpec>.Default);
+ var candidate = Methods [i];
candidate_to_form [candidate] = candidate;
}
if (candidate_args != Arguments) {
if (candidates_expanded == null)
- candidates_expanded = new Hashtable (2);
+ candidates_expanded = new Dictionary<MethodSpec, Arguments> (4, ReferenceEquality<MethodSpec>.Default);
candidates_expanded.Add (Methods [i], candidate_args);
candidate_args = Arguments;
if (CustomErrorHandler != null && !has_inaccessible_candidates_only && CustomErrorHandler.NoExactMatch (ec, best_candidate))
return null;
- AParametersCollection pd = TypeManager.GetParameterData (best_candidate);
- bool cand_params = candidate_to_form != null && candidate_to_form.Contains (best_candidate);
- if (arg_count == pd.Count || pd.HasParams) {
- if (TypeManager.IsGenericMethodDefinition (best_candidate)) {
- if (type_arguments == null) {
- ec.Report.Error (411, loc,
- "The type arguments for method `{0}' cannot be inferred from " +
- "the usage. Try specifying the type arguments explicitly",
- TypeManager.CSharpSignature (best_candidate));
- return null;
- }
-
- Type[] g_args = TypeManager.GetGenericArguments (best_candidate);
- if (type_arguments.Count != g_args.Length) {
- ec.Report.SymbolRelatedToPreviousError (best_candidate);
- ec.Report.Error (305, loc, "Using the generic method `{0}' requires `{1}' type argument(s)",
- TypeManager.CSharpSignature (best_candidate),
- g_args.Length.ToString ());
- return null;
- }
- } else {
- if (type_arguments != null && !TypeManager.IsGenericMethod (best_candidate)) {
- Error_TypeArgumentsCannotBeUsed (ec.Report, loc);
- return null;
- }
- }
-
- if (has_inaccessible_candidates_only) {
- if (InstanceExpression != null && type != ec.CurrentType && TypeManager.IsNestedFamilyAccessible (ec.CurrentType, best_candidate.DeclaringType)) {
- // Although a derived class can access protected members of
- // its base class it cannot do so through an instance of the
- // base class (CS1540). If the qualifier_type is a base of the
- // ec.CurrentType and the lookup succeeds with the latter one,
- // then we are in this situation.
- Error_CannotAccessProtected (ec, loc, best_candidate, queried_type, ec.CurrentType);
- } else {
- ec.Report.SymbolRelatedToPreviousError (best_candidate);
- ErrorIsInaccesible (loc, GetSignatureForError (), ec.Report);
- }
- }
-
- if (!VerifyArgumentsCompat (ec, ref Arguments, arg_count, best_candidate, cand_params, may_fail, loc))
- return null;
-
- if (has_inaccessible_candidates_only)
- return null;
-
- throw new InternalErrorException ("VerifyArgumentsCompat didn't find any problem with rejected candidate " + best_candidate);
- }
+ if (NoExactMatch (ec, ref Arguments, candidate_to_form))
+ return null;
}
//
return null;
}
+ if (arg_count != 0 && Arguments.HasDynamic) {
+ best_candidate = null;
+ return this;
+ }
+
if (!is_sorted) {
//
// At this point, applicable_type is _one_ of the most derived types
int j = finalized; // where to put the next finalized candidate
int k = finalized; // where to put the next undiscarded candidate
for (int i = finalized; i < candidate_top; ++i) {
- MethodBase candidate = (MethodBase) candidates [i];
+ var candidate = candidates [i];
Type decl_type = candidate.DeclaringType;
if (decl_type == applicable_type) {
// Now we actually find the best method
//
- best_candidate = (MethodBase) candidates [0];
- method_params = candidate_to_form != null && candidate_to_form.Contains (best_candidate);
+ best_candidate = candidates [0];
+ method_params = candidate_to_form != null && candidate_to_form.ContainsKey (best_candidate);
//
// TODO: Broken inverse order of candidates logic does not work with optional
// parameters used for method overrides and I am not going to fix it for SRE
//
- if (candidates_expanded != null && candidates_expanded.Contains (best_candidate)) {
- candidate_args = (Arguments) candidates_expanded [best_candidate];
+ if (candidates_expanded != null && candidates_expanded.ContainsKey (best_candidate)) {
+ candidate_args = candidates_expanded [best_candidate];
arg_count = candidate_args.Count;
}
for (int ix = 1; ix < candidate_top; ix++) {
- MethodBase candidate = (MethodBase) candidates [ix];
+ var candidate = candidates [ix];
- if (candidate == best_candidate)
+ if (candidate.MetaInfo == best_candidate.MetaInfo)
continue;
- bool cand_params = candidate_to_form != null && candidate_to_form.Contains (candidate);
+ bool cand_params = candidate_to_form != null && candidate_to_form.ContainsKey (candidate);
if (BetterFunction (ec, candidate_args, arg_count,
candidate, cand_params,
// Now check that there are no ambiguities i.e the selected method
// should be better than all the others
//
- MethodBase ambiguous = null;
+ MethodSpec ambiguous = null;
for (int ix = 1; ix < candidate_top; ix++) {
- MethodBase candidate = (MethodBase) candidates [ix];
+ var candidate = candidates [ix];
- if (candidate == best_candidate)
+ if (candidate.MetaInfo == best_candidate.MetaInfo)
continue;
- bool cand_params = candidate_to_form != null && candidate_to_form.Contains (candidate);
+ bool cand_params = candidate_to_form != null && candidate_to_form.ContainsKey (candidate);
if (!BetterFunction (ec, candidate_args, arg_count,
best_candidate, method_params,
candidate, cand_params))
{
if (!may_fail)
- ec.Report.SymbolRelatedToPreviousError (candidate);
+ ec.Report.SymbolRelatedToPreviousError (candidate.MetaInfo);
ambiguous = candidate;
}
}
if (candidate_overrides != null) {
Type[] gen_args = null;
bool gen_override = false;
- if (TypeManager.IsGenericMethod (best_candidate))
- gen_args = TypeManager.GetGenericArguments (best_candidate);
+ if (best_candidate.IsGenericMethod)
+ gen_args = TypeManager.GetGenericArguments (best_candidate.MetaInfo);
- foreach (MethodBase candidate in candidate_overrides) {
- if (TypeManager.IsGenericMethod (candidate)) {
+ foreach (var candidate in candidate_overrides) {
+ if (candidate.IsGenericMethod) {
if (gen_args == null)
continue;
- if (gen_args.Length != TypeManager.GetGenericArguments (candidate).Length)
+ if (gen_args.Length != TypeManager.GetGenericArguments (candidate.MetaInfo).Length)
continue;
} else {
if (gen_args != null)
continue;
}
- if (IsOverride (candidate, best_candidate)) {
+ if (IsOverride (candidate.MetaInfo, best_candidate.MetaInfo)) {
gen_override = true;
best_candidate = candidate;
}
}
if (gen_override && gen_args != null) {
- best_candidate = ((MethodInfo) best_candidate).MakeGenericMethod (gen_args);
+ best_candidate = best_candidate.Inflate (gen_args);
}
}
}
MethodBase the_method = TypeManager.DropGenericMethodArguments (best_candidate);
if (TypeManager.IsGenericMethodDefinition (the_method) &&
- !ConstraintChecker.CheckConstraints (ec, the_method, best_candidate, loc))
+ !ConstraintChecker.CheckConstraints (ec, the_method, best_candidate.MetaInfo, loc))
return null;
//
IMethodData data = TypeManager.GetMethod (the_method);
if (data != null)
- data.SetMemberIsUsed ();
+ data.SetIsUsed ();
Arguments = candidate_args;
return this;
}
+
+ bool NoExactMatch (ResolveContext ec, ref Arguments Arguments, IDictionary<MethodSpec, MethodSpec> candidate_to_form)
+ {
+ AParametersCollection pd = best_candidate.Parameters;
+ int arg_count = Arguments == null ? 0 : Arguments.Count;
+
+ if (arg_count == pd.Count || pd.HasParams) {
+ if (TypeManager.IsGenericMethodDefinition (best_candidate.MetaInfo)) {
+ if (type_arguments == null) {
+ ec.Report.Error (411, loc,
+ "The type arguments for method `{0}' cannot be inferred from " +
+ "the usage. Try specifying the type arguments explicitly",
+ TypeManager.CSharpSignature (best_candidate.MetaInfo));
+ return true;
+ }
+
+ Type[] g_args = TypeManager.GetGenericArguments (best_candidate.MetaInfo);
+ if (type_arguments.Count != g_args.Length) {
+ ec.Report.SymbolRelatedToPreviousError (best_candidate.MetaInfo);
+ ec.Report.Error (305, loc, "Using the generic method `{0}' requires `{1}' type argument(s)",
+ TypeManager.CSharpSignature (best_candidate.MetaInfo),
+ g_args.Length.ToString ());
+ return true;
+ }
+ } else {
+ if (type_arguments != null && !best_candidate.IsGenericMethod) {
+ Error_TypeArgumentsCannotBeUsed (ec.Report, loc);
+ return true;
+ }
+ }
+
+ if (has_inaccessible_candidates_only) {
+ if (InstanceExpression != null && type != ec.CurrentType && TypeManager.IsNestedFamilyAccessible (ec.CurrentType, best_candidate.DeclaringType)) {
+ // Although a derived class can access protected members of
+ // its base class it cannot do so through an instance of the
+ // base class (CS1540). If the qualifier_type is a base of the
+ // ec.CurrentType and the lookup succeeds with the latter one,
+ // then we are in this situation.
+ Error_CannotAccessProtected (ec, loc, best_candidate.MetaInfo, queried_type, ec.CurrentType);
+ } else {
+ ec.Report.SymbolRelatedToPreviousError (best_candidate.MetaInfo);
+ ErrorIsInaccesible (loc, GetSignatureForError (), ec.Report);
+ }
+ }
+
+ bool cand_params = candidate_to_form != null && candidate_to_form.ContainsKey (best_candidate);
+ if (!VerifyArgumentsCompat (ec, ref Arguments, arg_count, best_candidate, cand_params, false, loc))
+ return true;
+
+ if (has_inaccessible_candidates_only)
+ return true;
+ }
+
+ return false;
+ }
public override void SetTypeArguments (ResolveContext ec, TypeArguments ta)
{
}
public bool VerifyArgumentsCompat (ResolveContext ec, ref Arguments arguments,
- int arg_count, MethodBase method,
+ int arg_count, MethodSpec method,
bool chose_params_expanded,
bool may_fail, Location loc)
{
- AParametersCollection pd = TypeManager.GetParameterData (method);
+ AParametersCollection pd = method.Parameters;
int param_count = GetApplicableParametersCount (method, pd);
int errors = ec.Report.Errors;
Type pt = null;
int a_idx = 0, a_pos = 0;
Argument a = null;
- ArrayList params_initializers = null;
- bool has_unsafe_arg = method is MethodInfo ? ((MethodInfo) method).ReturnType.IsPointer : false;
+ ArrayInitializer params_initializers = null;
+ bool has_unsafe_arg = method.ReturnType.IsPointer;
for (; a_idx < arg_count; a_idx++, ++a_pos) {
a = arguments [a_idx];
if (p_mod == Parameter.Modifier.PARAMS) {
if (chose_params_expanded) {
- params_initializers = new ArrayList (arg_count - a_idx);
+ params_initializers = new ArrayInitializer (arg_count - a_idx, a.Expr.Location);
pt = TypeManager.GetElementType (pt);
}
}
} else {
NamedArgument na = a as NamedArgument;
if (na != null) {
- int name_index = pd.GetParameterIndexByName (na.Name.Value);
+ int name_index = pd.GetParameterIndexByName (na.Name);
if (name_index < 0 || name_index >= param_count) {
if (DeclaringType != null && TypeManager.IsDelegateType (DeclaringType)) {
ec.Report.SymbolRelatedToPreviousError (DeclaringType);
- ec.Report.Error (1746, na.Name.Location,
+ ec.Report.Error (1746, na.Location,
"The delegate `{0}' does not contain a parameter named `{1}'",
- TypeManager.CSharpName (DeclaringType), na.Name.Value);
+ TypeManager.CSharpName (DeclaringType), na.Name);
} else {
- ec.Report.SymbolRelatedToPreviousError (best_candidate);
- ec.Report.Error (1739, na.Name.Location,
+ ec.Report.SymbolRelatedToPreviousError (best_candidate.MetaInfo);
+ ec.Report.Error (1739, na.Location,
"The best overloaded method match for `{0}' does not contain a parameter named `{1}'",
- TypeManager.CSharpSignature (method), na.Name.Value);
+ TypeManager.CSharpSignature (method.MetaInfo), na.Name);
}
} else if (arguments[name_index] != a) {
if (DeclaringType != null && TypeManager.IsDelegateType (DeclaringType))
ec.Report.SymbolRelatedToPreviousError (DeclaringType);
else
- ec.Report.SymbolRelatedToPreviousError (best_candidate);
+ ec.Report.SymbolRelatedToPreviousError (best_candidate.MetaInfo);
- ec.Report.Error (1744, na.Name.Location,
+ ec.Report.Error (1744, na.Location,
"Named argument `{0}' cannot be used for a parameter which has positional argument specified",
- na.Name.Value);
+ na.Name);
}
}
}
+ if (TypeManager.IsDynamicType (a.Expr.Type))
+ continue;
+
if (delegate_type != null && !Delegate.IsTypeCovariant (a.Expr, pt))
break;
pt = pd.Types [param_count - 1];
pt = TypeManager.GetElementType (pt);
has_unsafe_arg |= pt.IsPointer;
- params_initializers = new ArrayList (0);
+ params_initializers = new ArrayInitializer (0, loc);
}
//
//
if (params_initializers != null) {
arguments.Add (new Argument (
- new ArrayCreation (new TypeExpression (pt, loc), "[]",
- params_initializers, loc).Resolve (ec)));
+ new ArrayCreation (new TypeExpression (pt, loc), "[]", params_initializers, loc).Resolve (ec)));
arg_count++;
}
public class ConstantExpr : MemberExpr
{
- FieldInfo constant;
+ ConstSpec constant;
- public ConstantExpr (FieldInfo constant, Location loc)
+ public ConstantExpr (ConstSpec constant, Location loc)
{
this.constant = constant;
this.loc = loc;
}
public override bool IsStatic {
- get { return constant.IsStatic; }
+ get { return true; }
}
public override Type DeclaringType {
get { return constant.DeclaringType; }
}
- public override MemberExpr ResolveMemberAccess (ResolveContext ec, Expression left, Location loc, SimpleName original)
- {
- constant = TypeManager.GetGenericFieldDefinition (constant);
-
- IConstant ic = TypeManager.GetConstant (constant);
- if (ic == null) {
- if (constant.IsLiteral) {
- ic = new ExternalConstant (constant);
- } else {
- ic = ExternalConstant.CreateDecimal (constant);
- // HACK: decimal field was not resolved as constant
- if (ic == null)
- return new FieldExpr (constant, loc).ResolveMemberAccess (ec, left, loc, original);
- }
- TypeManager.RegisterConstant (constant, ic);
- }
-
- return base.ResolveMemberAccess (ec, left, loc, original);
- }
-
public override Expression CreateExpressionTree (ResolveContext ec)
{
throw new NotSupportedException ("ET");
}
- public override Expression DoResolve (ResolveContext ec)
+ protected override Expression DoResolve (ResolveContext rc)
{
- IConstant ic = TypeManager.GetConstant (constant);
- if (ic.ResolveValue ()) {
- if (!ec.IsObsolete)
- ic.CheckObsoleteness (loc);
+ constant.MemberDefinition.SetIsUsed ();
+
+ if (!rc.IsObsolete) {
+ var oa = constant.GetObsoleteAttribute ();
+ if (oa != null)
+ AttributeTester.Report_ObsoleteMessage (oa, TypeManager.GetFullNameSignature (constant.MetaInfo), loc, rc.Report);
}
- return ic.CreateConstantReference (loc);
+ // Constants are resolved on-demand
+ var c = constant.Value.Resolve (rc) as Constant;
+
+ // Creates reference expression to the constant value
+ return Constant.CreateConstant (rc, c.Type, c.GetValue (), loc);
}
public override void Emit (EmitContext ec)
public override string GetSignatureForError ()
{
- return TypeManager.GetFullNameSignature (constant);
+ return TypeManager.GetFullNameSignature (constant.MetaInfo);
}
}
/// Fully resolved expression that evaluates to a Field
/// </summary>
public class FieldExpr : MemberExpr, IDynamicAssign, IMemoryLocation, IVariableReference {
- public FieldInfo FieldInfo;
+ protected FieldSpec spec;
readonly Type constructed_generic_type;
VariableInfo variable_info;
{
loc = l;
}
+
+ public FieldExpr (FieldSpec spec, Location loc)
+ {
+ this.spec = spec;
+ this.loc = loc;
+
+ type = TypeManager.TypeToCoreType (spec.FieldType);
+ }
- public FieldExpr (FieldInfo fi, Location l)
+ public FieldExpr (FieldBase fi, Location l)
+ : this (fi.Spec, l)
{
- FieldInfo = fi;
- type = TypeManager.TypeToCoreType (fi.FieldType);
loc = l;
}
- public FieldExpr (FieldInfo fi, Type genericType, Location l)
+ public FieldExpr (Field fi, Type genericType, Location l)
: this (fi, l)
{
if (TypeManager.IsGenericTypeDefinition (genericType))
public override string Name {
get {
- return FieldInfo.Name;
+ return spec.Name;
}
}
public override bool IsInstance {
get {
- return !FieldInfo.IsStatic;
+ return !spec.IsStatic;
}
}
public override bool IsStatic {
get {
- return FieldInfo.IsStatic;
+ return spec.IsStatic;
+ }
+ }
+
+ public FieldSpec Spec {
+ get {
+ return spec;
}
}
public override Type DeclaringType {
get {
- return FieldInfo.DeclaringType;
+ return spec.MetaInfo.DeclaringType;
}
}
public override string GetSignatureForError ()
{
- return TypeManager.GetFullNameSignature (FieldInfo);
+ return TypeManager.GetFullNameSignature (spec.MetaInfo);
}
public VariableInfo VariableInfo {
public override MemberExpr ResolveMemberAccess (ResolveContext ec, Expression left, Location loc,
SimpleName original)
{
- FieldInfo fi = TypeManager.GetGenericFieldDefinition (FieldInfo);
+ FieldInfo fi = TypeManager.GetGenericFieldDefinition (spec.MetaInfo);
Type t = fi.FieldType;
if (t.IsPointer && !ec.IsUnsafe) {
public Expression CreateTypeOfExpression ()
{
- return new TypeOfField (GetConstructedFieldInfo (), loc);
+ return new TypeOfField (Import.CreateField (GetConstructedFieldInfo ()), loc);
}
- override public Expression DoResolve (ResolveContext ec)
+ protected override Expression DoResolve (ResolveContext ec)
{
return DoResolve (ec, false, false);
}
Expression DoResolve (ResolveContext ec, bool lvalue_instance, bool out_access)
{
- if (!FieldInfo.IsStatic){
+ if (!IsStatic){
if (InstanceExpression == null){
//
// This can happen when referencing an instance field using
InstanceExpression = InstanceExpression.ResolveLValue (ec, right_side);
}
} else {
- ResolveFlags rf = ResolveFlags.VariableOrValue | ResolveFlags.DisableFlowAnalysis;
-
- if (InstanceExpression != EmptyExpression.Null)
- InstanceExpression = InstanceExpression.Resolve (ec, rf);
+ if (InstanceExpression != EmptyExpression.Null) {
+ using (ec.With (ResolveContext.Options.DoFlowAnalysis, false)) {
+ InstanceExpression = InstanceExpression.Resolve (ec, ResolveFlags.VariableOrValue);
+ }
+ }
}
if (InstanceExpression == null)
}
}
- // TODO: the code above uses some non-standard multi-resolve rules
- if (eclass != ExprClass.Invalid)
- return this;
-
if (!ec.IsObsolete) {
- FieldBase f = TypeManager.GetField (FieldInfo);
+ FieldBase f = TypeManager.GetField (spec.MetaInfo);
if (f != null) {
f.CheckObsoleteness (loc);
} else {
- ObsoleteAttribute oa = AttributeTester.GetMemberObsoleteAttribute (FieldInfo);
+ ObsoleteAttribute oa = AttributeTester.GetMemberObsoleteAttribute (spec.MetaInfo);
if (oa != null)
- AttributeTester.Report_ObsoleteMessage (oa, TypeManager.GetFullNameSignature (FieldInfo), loc, ec.Report);
+ AttributeTester.Report_ObsoleteMessage (oa, TypeManager.GetFullNameSignature (spec.MetaInfo), loc, ec.Report);
}
}
- IFixedBuffer fb = AttributeTester.GetFixedBuffer (FieldInfo);
+ var fb = spec as FixedFieldSpec;
IVariableReference var = InstanceExpression as IVariableReference;
if (fb != null) {
}
if (InstanceExpression.eclass != ExprClass.Variable) {
- ec.Report.SymbolRelatedToPreviousError (FieldInfo);
+ ec.Report.SymbolRelatedToPreviousError (spec.MetaInfo);
ec.Report.Error (1708, loc, "`{0}': Fixed size buffers can only be accessed through locals or fields",
- TypeManager.GetFullNameSignature (FieldInfo));
+ TypeManager.GetFullNameSignature (spec.MetaInfo));
} else if (var != null && var.IsHoisted) {
AnonymousMethodExpression.Error_AddressOfCapturedVar (ec, var, loc);
}
return this;
VariableInfo vi = var.VariableInfo;
- if (!vi.IsFieldAssigned (ec, FieldInfo.Name, loc))
+ if (!vi.IsFieldAssigned (ec, Name, loc))
return null;
- variable_info = vi.GetSubStruct (FieldInfo.Name);
- eclass = ExprClass.Variable;
+ variable_info = vi.GetSubStruct (Name);
return this;
}
{
IVariableReference var = InstanceExpression as IVariableReference;
if (var != null && var.VariableInfo != null)
- var.VariableInfo.SetFieldAssigned (ec, FieldInfo.Name);
+ var.VariableInfo.SetFieldAssigned (ec, Name);
- bool lvalue_instance = !FieldInfo.IsStatic && TypeManager.IsValueType (FieldInfo.DeclaringType);
+ bool lvalue_instance = !spec.IsStatic && TypeManager.IsValueType (spec.MetaInfo.DeclaringType);
bool out_access = right_side == EmptyExpression.OutAccess.Instance || right_side == EmptyExpression.LValueMemberOutAccess;
Expression e = DoResolve (ec, lvalue_instance, out_access);
if (e == null)
return null;
- FieldBase fb = TypeManager.GetField (FieldInfo);
+ FieldBase fb = TypeManager.GetField (spec.MetaInfo);
if (fb != null) {
fb.SetAssigned ();
}
}
- if (FieldInfo.IsInitOnly) {
+ if (spec.IsReadOnly) {
// InitOnly fields can only be assigned in constructors or initializers
if (!ec.HasAny (ResolveContext.Options.FieldInitializerScope | ResolveContext.Options.ConstructorScope))
return Report_AssignToReadonly (ec, right_side);
Type ctype = ec.CurrentType;
// InitOnly fields cannot be assigned-to in a different constructor from their declaring type
- if (!TypeManager.IsEqual (ctype, FieldInfo.DeclaringType))
+ if (!TypeManager.IsEqual (ctype, DeclaringType))
return Report_AssignToReadonly (ec, right_side);
// static InitOnly fields cannot be assigned-to in an instance constructor
if (IsStatic && !ec.IsStatic)
public override int GetHashCode ()
{
- return FieldInfo.GetHashCode ();
+ return spec.GetHashCode ();
}
public bool IsFixed {
if (fe == null)
return false;
- if (FieldInfo != fe.FieldInfo)
+ if (spec.MetaInfo != fe.spec.MetaInfo)
return false;
if (InstanceExpression == null || fe.InstanceExpression == null)
ILGenerator ig = ec.ig;
bool is_volatile = false;
- FieldBase f = TypeManager.GetField (FieldInfo);
+ var f = TypeManager.GetField (spec.MetaInfo);
if (f != null){
if ((f.ModFlags & Modifiers.VOLATILE) != 0)
is_volatile = true;
- f.SetMemberIsUsed ();
+ f.SetIsUsed ();
}
- if (FieldInfo.IsStatic){
+ if (IsStatic){
if (is_volatile)
ig.Emit (OpCodes.Volatile);
EmitInstance (ec, false);
// Optimization for build-in types
- if (TypeManager.IsStruct (type) && TypeManager.IsEqual (type, ec.MemberContext.CurrentType)) {
+ if (TypeManager.IsStruct (type) && TypeManager.IsEqual (type, ec.MemberContext.CurrentType) && TypeManager.IsEqual (InstanceExpression.Type, type)) {
LoadFromPtr (ig, type);
} else {
- IFixedBuffer ff = AttributeTester.GetFixedBuffer (FieldInfo);
+ var ff = spec as FixedFieldSpec;
if (ff != null) {
ig.Emit (OpCodes.Ldflda, GetConstructedFieldInfo ());
ig.Emit (OpCodes.Ldflda, ff.Element);
if (leave_copy) {
ec.ig.Emit (OpCodes.Dup);
- if (!FieldInfo.IsStatic) {
+ if (!IsStatic) {
temp = new LocalTemporary (this.Type);
temp.Store (ec);
}
public void EmitAssign (EmitContext ec, Expression source, bool leave_copy, bool prepare_for_load)
{
- FieldAttributes fa = FieldInfo.Attributes;
- bool is_static = (fa & FieldAttributes.Static) != 0;
+ //FieldAttributes fa = FieldInfo.Attributes;
+ //bool is_static = (fa & FieldAttributes.Static) != 0;
ILGenerator ig = ec.ig;
prepared = prepare_for_load;
source.Emit (ec);
if (leave_copy) {
ec.ig.Emit (OpCodes.Dup);
- if (!FieldInfo.IsStatic) {
+ if (!IsStatic) {
temp = new LocalTemporary (this.Type);
temp.Store (ec);
}
}
- FieldBase f = TypeManager.GetField (FieldInfo);
+ FieldBase f = TypeManager.GetField (spec.MetaInfo);
if (f != null){
if ((f.ModFlags & Modifiers.VOLATILE) != 0)
ig.Emit (OpCodes.Volatile);
f.SetAssigned ();
}
- if (is_static)
+ if (IsStatic)
ig.Emit (OpCodes.Stsfld, GetConstructedFieldInfo ());
else
ig.Emit (OpCodes.Stfld, GetConstructedFieldInfo ());
public override void EmitSideEffect (EmitContext ec)
{
- FieldBase f = TypeManager.GetField (FieldInfo);
+ FieldBase f = TypeManager.GetField (spec.MetaInfo);
bool is_volatile = f != null && (f.ModFlags & Modifiers.VOLATILE) != 0;
if (is_volatile || is_marshal_by_ref ())
{
ILGenerator ig = ec.ig;
- FieldBase f = TypeManager.GetField (FieldInfo);
+ FieldBase f = TypeManager.GetField (spec.MetaInfo);
if (f != null){
if ((mode & AddressOp.Store) != 0)
f.SetAssigned ();
if ((mode & AddressOp.Load) != 0)
- f.SetMemberIsUsed ();
+ f.SetIsUsed ();
}
//
// get the address of the copy.
//
bool need_copy;
- if (FieldInfo.IsInitOnly){
+ if (spec.IsReadOnly){
need_copy = true;
if (ec.HasSet (EmitContext.Options.ConstructorScope)){
- if (FieldInfo.IsStatic){
+ if (IsStatic){
if (ec.IsStatic)
need_copy = false;
} else
}
- if (FieldInfo.IsStatic){
+ if (IsStatic){
ig.Emit (OpCodes.Ldsflda, GetConstructedFieldInfo ());
} else {
if (!prepared)
FieldInfo GetConstructedFieldInfo ()
{
if (constructed_generic_type == null)
- return FieldInfo;
+ return spec.MetaInfo;
- return TypeBuilder.GetField (constructed_generic_type, FieldInfo);
+ return TypeBuilder.GetField (constructed_generic_type, spec.MetaInfo);
}
-#if NET_4_0
public SLE.Expression MakeAssignExpression (BuilderContext ctx)
{
return MakeExpression (ctx);
public override SLE.Expression MakeExpression (BuilderContext ctx)
{
- return SLE.Expression.Field (InstanceExpression.MakeExpression (ctx), FieldInfo);
+ return SLE.Expression.Field (InstanceExpression.MakeExpression (ctx), spec.MetaInfo);
}
-#endif
public override void MutateHoistedGenericType (AnonymousMethodStorey storey)
{
- FieldInfo = storey.MutateField (FieldInfo);
+ storey.MutateField (spec);
base.MutateHoistedGenericType (storey);
}
}
/// </summary>
public class PropertyExpr : MemberExpr, IDynamicAssign
{
- public readonly PropertyInfo PropertyInfo;
- MethodInfo getter, setter;
+ PropertySpec spec;
+ MethodSpec getter, setter;
bool is_static;
- bool resolved;
TypeArguments targs;
LocalTemporary temp;
bool prepared;
- public PropertyExpr (Type container_type, PropertyInfo pi, Location l)
+ public PropertyExpr (Type container_type, PropertySpec spec, Location l)
{
- PropertyInfo = pi;
- eclass = ExprClass.PropertyAccess;
- is_static = false;
+ this.spec = spec;
loc = l;
- type = TypeManager.TypeToCoreType (pi.PropertyType);
+ type = TypeManager.TypeToCoreType (spec.PropertyType);
ResolveAccessors (container_type);
}
public override string Name {
get {
- return PropertyInfo.Name;
+ return spec.Name;
}
}
public override Type DeclaringType {
get {
- return PropertyInfo.DeclaringType;
+ return spec.DeclaringType;
}
}
public override string GetSignatureForError ()
{
- return TypeManager.GetFullNameSignature (PropertyInfo);
+ return TypeManager.GetFullNameSignature (spec.MetaInfo);
}
void FindAccessors (Type invocation_type)
BindingFlags.Static | BindingFlags.Instance |
BindingFlags.DeclaredOnly;
- Type current = PropertyInfo.DeclaringType;
+ Type current = spec.DeclaringType;
for (; current != null; current = current.BaseType) {
MemberInfo[] group = TypeManager.MemberLookup (
invocation_type, invocation_type, current,
- MemberTypes.Property, flags, PropertyInfo.Name, null);
+ MemberTypes.Property, flags, spec.Name, null);
if (group == null)
continue;
PropertyInfo pi = (PropertyInfo) group [0];
- if (getter == null)
- getter = pi.GetGetMethod (true);
+ if (getter == null) {
+ var m = pi.GetGetMethod (true);
+ if (m != null)
+ getter = Import.CreateMethod (m);
+ }
- if (setter == null)
- setter = pi.GetSetMethod (true);
+ if (setter == null) {
+ var m = pi.GetSetMethod (true);
+ if (m != null)
+ setter = Import.CreateMethod (m);
+ }
- MethodInfo accessor = getter != null ? getter : setter;
+ var accessor = getter != null ? getter : setter;
if (!accessor.IsVirtual)
return;
MethodBase the_getter = TypeManager.DropGenericMethodArguments (getter);
IMethodData md = TypeManager.GetMethod (the_getter);
if (md != null)
- md.SetMemberIsUsed ();
+ md.SetIsUsed ();
is_static = getter.IsStatic;
}
MethodBase the_setter = TypeManager.DropGenericMethodArguments (setter);
IMethodData md = TypeManager.GetMethod (the_setter);
if (md != null)
- md.SetMemberIsUsed ();
+ md.SetIsUsed ();
is_static = setter.IsStatic;
}
}
-#if NET_4_0
public SLE.Expression MakeAssignExpression (BuilderContext ctx)
{
- return SLE.Expression.Property (InstanceExpression.MakeExpression (ctx), setter);
+ return SLE.Expression.Property (InstanceExpression.MakeExpression (ctx), (MethodInfo) setter.MetaInfo);
}
public override SLE.Expression MakeExpression (BuilderContext ctx)
{
- return SLE.Expression.Property (InstanceExpression.MakeExpression (ctx), getter);
+ return SLE.Expression.Property (InstanceExpression.MakeExpression (ctx), (MethodInfo) getter.MetaInfo);
}
-#endif
public override void MutateHoistedGenericType (AnonymousMethodStorey storey)
{
type = storey.MutateType (type);
if (getter != null)
- getter = storey.MutateGenericMethod (getter);
+ storey.MutateGenericMethod (getter);
if (setter != null)
- setter = storey.MutateGenericMethod (setter);
+ storey.MutateGenericMethod (setter);
+ }
+
+ public PropertyInfo PropertyInfo {
+ get {
+ return spec.MetaInfo;
+ }
}
bool InstanceResolve (ResolveContext ec, bool lvalue_instance, bool must_do_cs1540_check)
return false;
}
- InstanceExpression = InstanceExpression.DoResolve (ec);
+ InstanceExpression = InstanceExpression.Resolve (ec);
if (lvalue_instance && InstanceExpression != null)
InstanceExpression = InstanceExpression.ResolveLValue (ec, EmptyExpression.LValueMemberAccess);
!TypeManager.IsInstantiationOfSameGenericType (InstanceExpression.Type, ec.CurrentType) &&
!TypeManager.IsNestedChildOf (ec.CurrentType, InstanceExpression.Type) &&
!TypeManager.IsSubclassOf (InstanceExpression.Type, ec.CurrentType)) {
- ec.Report.SymbolRelatedToPreviousError (PropertyInfo);
- Error_CannotAccessProtected (ec, loc, PropertyInfo, InstanceExpression.Type, ec.CurrentType);
+ ec.Report.SymbolRelatedToPreviousError (spec.MetaInfo);
+ Error_CannotAccessProtected (ec, loc, spec.MetaInfo, InstanceExpression.Type, ec.CurrentType);
return false;
}
return true;
}
- void Error_PropertyNotFound (ResolveContext ec, MethodInfo mi, bool getter)
+ void Error_PropertyNotFound (ResolveContext ec, MethodSpec mi, bool getter)
{
// TODO: correctly we should compare arguments but it will lead to bigger changes
- if (mi is MethodBuilder) {
- Error_TypeDoesNotContainDefinition (ec, loc, PropertyInfo.DeclaringType, Name);
+ if (mi.MetaInfo is MethodBuilder) {
+ Error_TypeDoesNotContainDefinition (ec, loc, spec.DeclaringType, Name);
return;
}
StringBuilder sig = new StringBuilder (TypeManager.CSharpName (mi.DeclaringType));
sig.Append ('.');
- AParametersCollection iparams = TypeManager.GetParameterData (mi);
+ AParametersCollection iparams = mi.Parameters;
sig.Append (getter ? "get_" : "set_");
sig.Append (Name);
sig.Append (iparams.GetSignatureForError ());
- ec.Report.SymbolRelatedToPreviousError (mi);
+ ec.Report.SymbolRelatedToPreviousError (mi.MetaInfo);
ec.Report.Error (1546, loc, "Property `{0}' is not supported by the C# language. Try to call the accessor method `{1}' directly",
Name, sig.ToString ());
}
public bool IsAccessibleFrom (Type invocation_type, bool lvalue)
{
bool dummy;
- MethodInfo accessor = lvalue ? setter : getter;
+ var accessor = lvalue ? setter : getter;
if (accessor == null && lvalue)
accessor = getter;
return accessor != null && IsAccessorAccessible (invocation_type, accessor, out dummy);
return t_name_len > 2 && t_name [t_name_len - 2] == '[';
}
- public override Expression DoResolve (ResolveContext ec)
+ protected override Expression DoResolve (ResolveContext ec)
{
- if (resolved)
- return this;
+ eclass = ExprClass.PropertyAccess;
bool must_do_cs1540_check = false;
ec.Report.DisableReporting ();
if (ex_method_lookup != null) {
ex_method_lookup.ExtensionExpression = InstanceExpression;
ex_method_lookup.SetTypeArguments (ec, targs);
- return ex_method_lookup.DoResolve (ec);
+ return ex_method_lookup.Resolve (ec);
}
}
// Only base will allow this invocation to happen.
//
if (IsBase && getter.IsAbstract) {
- Error_CannotCallAbstractBase (ec, TypeManager.GetFullNameSignature (PropertyInfo));
+ Error_CannotCallAbstractBase (ec, TypeManager.GetFullNameSignature (spec.MetaInfo));
}
- if (PropertyInfo.PropertyType.IsPointer && !ec.IsUnsafe){
+ if (spec.PropertyType.IsPointer && !ec.IsUnsafe){
UnsafeError (ec, loc);
}
if (!ec.IsObsolete) {
- PropertyBase pb = TypeManager.GetProperty (PropertyInfo);
+ PropertyBase pb = TypeManager.GetProperty (spec.MetaInfo);
if (pb != null) {
pb.CheckObsoleteness (loc);
} else {
- ObsoleteAttribute oa = AttributeTester.GetMemberObsoleteAttribute (PropertyInfo);
+ ObsoleteAttribute oa = AttributeTester.GetMemberObsoleteAttribute (spec.MetaInfo);
if (oa != null)
AttributeTester.Report_ObsoleteMessage (oa, GetSignatureForError (), loc, ec.Report);
}
}
- resolved = true;
-
return this;
}
override public Expression DoResolveLValue (ResolveContext ec, Expression right_side)
{
+ eclass = ExprClass.PropertyAccess;
+
if (right_side == EmptyExpression.OutAccess.Instance) {
- if (ec.CurrentBlock.Toplevel.GetParameterReference (PropertyInfo.Name, loc) is MemberAccess) {
+ if (ec.CurrentBlock.Toplevel.GetParameterReference (spec.Name, loc) is MemberAccess) {
ec.Report.Error (1939, loc, "A range variable `{0}' may not be passes as `ref' or `out' parameter",
- PropertyInfo.Name);
+ spec.Name);
} else {
right_side.DoResolveLValue (ec, this);
}
if (getter == null)
return null;
- if (ec.CurrentBlock.Toplevel.GetParameterReference (PropertyInfo.Name, loc) is MemberAccess) {
+ if (ec.CurrentBlock.Toplevel.GetParameterReference (spec.Name, loc) is MemberAccess) {
ec.Report.Error (1947, loc, "A range variable `{0}' cannot be assigned to. Consider using `let' clause to store the value",
- PropertyInfo.Name);
+ spec.Name);
} else {
ec.Report.Error (200, loc, "Property or indexer `{0}' cannot be assigned to (it is read only)",
GetSignatureForError ());
return null;
}
- if (TypeManager.GetParameterData (setter).Count != 1){
+ if (setter.Parameters.Count != 1){
Error_PropertyNotFound (ec, setter, false);
return null;
}
bool must_do_cs1540_check;
if (!IsAccessorAccessible (ec.CurrentType, setter, out must_do_cs1540_check)) {
- PropertyBase.PropertyMethod pm = TypeManager.GetMethod (setter) as PropertyBase.PropertyMethod;
+ PropertyBase.PropertyMethod pm = TypeManager.GetMethod (setter.MetaInfo) as PropertyBase.PropertyMethod;
if (pm != null && pm.HasCustomAccessModifier) {
ec.Report.SymbolRelatedToPreviousError (pm);
ec.Report.Error (272, loc, "The property or indexer `{0}' cannot be used in this context because the set accessor is inaccessible",
TypeManager.CSharpSignature (setter));
}
else {
- ec.Report.SymbolRelatedToPreviousError (setter);
+ ec.Report.SymbolRelatedToPreviousError (setter.MetaInfo);
ErrorIsInaccesible (loc, TypeManager.CSharpSignature (setter), ec.Report);
}
return null;
}
- if (!InstanceResolve (ec, TypeManager.IsStruct (PropertyInfo.DeclaringType), must_do_cs1540_check))
+ if (!InstanceResolve (ec, TypeManager.IsStruct (spec.DeclaringType), must_do_cs1540_check))
return null;
//
// Only base will allow this invocation to happen.
//
if (IsBase && setter.IsAbstract){
- Error_CannotCallAbstractBase (ec, TypeManager.GetFullNameSignature (PropertyInfo));
+ Error_CannotCallAbstractBase (ec, TypeManager.GetFullNameSignature (spec.MetaInfo));
}
- if (PropertyInfo.PropertyType.IsPointer && !ec.IsUnsafe) {
+ if (spec.PropertyType.IsPointer && !ec.IsUnsafe) {
UnsafeError (ec, loc);
}
if (!ec.IsObsolete) {
- PropertyBase pb = TypeManager.GetProperty (PropertyInfo);
+ PropertyBase pb = TypeManager.GetProperty (spec.MetaInfo);
if (pb != null) {
pb.CheckObsoleteness (loc);
} else {
- ObsoleteAttribute oa = AttributeTester.GetMemberObsoleteAttribute (PropertyInfo);
+ ObsoleteAttribute oa = AttributeTester.GetMemberObsoleteAttribute (spec.MetaInfo);
if (oa != null)
AttributeTester.Report_ObsoleteMessage (oa, GetSignatureForError (), loc, ec.Report);
}
}
if (getter != null) {
- if (TypeManager.GetParameterData (getter).Count != 0) {
+ if (!getter.Parameters.IsEmpty) {
Error_PropertyNotFound (ec, getter, true);
return false;
}
if (InstanceExpression != EmptyExpression.Null) {
ec.Report.Error (154, loc, "The property or indexer `{0}' cannot be used in this context because it lacks the `get' accessor",
- TypeManager.GetFullNameSignature (PropertyInfo));
+ TypeManager.GetFullNameSignature (spec.MetaInfo));
return false;
}
}
if (getter != null &&
!IsAccessorAccessible (ec.CurrentType, getter, out must_do_cs1540_check)) {
- PropertyBase.PropertyMethod pm = TypeManager.GetMethod (getter) as PropertyBase.PropertyMethod;
+ PropertyBase.PropertyMethod pm = TypeManager.GetMethod (getter.MetaInfo) as PropertyBase.PropertyMethod;
if (pm != null && pm.HasCustomAccessModifier) {
ec.Report.SymbolRelatedToPreviousError (pm);
ec.Report.Error (271, loc, "The property or indexer `{0}' cannot be used in this context because the get accessor is inaccessible",
- TypeManager.CSharpSignature (getter));
+ TypeManager.CSharpSignature (getter.MetaInfo));
} else {
- ec.Report.SymbolRelatedToPreviousError (getter);
- ErrorIsInaccesible (loc, TypeManager.CSharpSignature (getter), ec.Report);
+ ec.Report.SymbolRelatedToPreviousError (getter.MetaInfo);
+ ErrorIsInaccesible (loc, TypeManager.CSharpSignature (getter.MetaInfo), ec.Report);
}
return false;
/// <summary>
/// Fully resolved expression that evaluates to an Event
/// </summary>
- public class EventExpr : MemberExpr {
- public readonly EventInfo EventInfo;
-
- bool is_static;
- MethodInfo add_accessor, remove_accessor;
+ public class EventExpr : MemberExpr
+ {
+ readonly EventSpec spec;
- public EventExpr (EventInfo ei, Location loc)
+ public EventExpr (EventSpec spec, Location loc)
{
- EventInfo = ei;
+ this.spec = spec;
this.loc = loc;
- eclass = ExprClass.EventAccess;
-
- add_accessor = TypeManager.GetAddMethod (ei);
- remove_accessor = TypeManager.GetRemoveMethod (ei);
- if (add_accessor.IsStatic || remove_accessor.IsStatic)
- is_static = true;
-
- if (EventInfo is MyEventBuilder){
- MyEventBuilder eb = (MyEventBuilder) EventInfo;
- type = eb.EventType;
- eb.SetUsed ();
- } else
- type = EventInfo.EventHandlerType;
}
public override string Name {
get {
- return EventInfo.Name;
+ return spec.Name;
}
}
public override bool IsInstance {
get {
- return !is_static;
+ return !spec.IsStatic;
}
}
public override bool IsStatic {
get {
- return is_static;
+ return spec.IsStatic;
}
}
public override Type DeclaringType {
get {
- return EventInfo.DeclaringType;
+ return spec.DeclaringType;
}
}
// If the event is local to this class, we transform ourselves into a FieldExpr
//
- if (EventInfo.DeclaringType == ec.CurrentType ||
- TypeManager.IsNestedChildOf(ec.CurrentType, EventInfo.DeclaringType)) {
+ if (spec.DeclaringType == ec.CurrentType ||
+ TypeManager.IsNestedChildOf(ec.CurrentType, spec.DeclaringType)) {
// TODO: Breaks dynamic binder as currect context fields are imported and not compiled
- EventField mi = TypeManager.GetEventField (EventInfo);
+ EventField mi = TypeManager.GetEventField (spec.MetaInfo).MemberDefinition as EventField;
- if (mi != null) {
+ if (mi != null && mi.HasBackingField) {
+ mi.SetIsUsed ();
if (!ec.IsObsolete)
mi.CheckObsoleteness (loc);
if ((mi.ModFlags & (Modifiers.ABSTRACT | Modifiers.EXTERN)) != 0 && !ec.HasSet (ResolveContext.Options.CompoundAssignmentScope))
Error_AssignmentEventOnly (ec);
- FieldExpr ml = new FieldExpr (mi.BackingField.FieldBuilder, loc);
+ FieldExpr ml = new FieldExpr (mi.BackingField, loc);
InstanceExpression = null;
bool InstanceResolve (ResolveContext ec, bool must_do_cs1540_check)
{
- if (is_static) {
+ if (IsStatic) {
InstanceExpression = null;
return true;
}
return false;
}
- InstanceExpression = InstanceExpression.DoResolve (ec);
+ InstanceExpression = InstanceExpression.Resolve (ec);
if (InstanceExpression == null)
return false;
- if (IsBase && add_accessor.IsAbstract) {
- Error_CannotCallAbstractBase (ec, TypeManager.CSharpSignature(add_accessor));
+ if (IsBase && spec.IsAbstract) {
+ Error_CannotCallAbstractBase (ec, TypeManager.CSharpSignature(spec.MetaInfo));
return false;
}
!TypeManager.IsInstantiationOfSameGenericType (InstanceExpression.Type, ec.CurrentType) &&
!TypeManager.IsNestedChildOf (ec.CurrentType, InstanceExpression.Type) &&
!TypeManager.IsSubclassOf (InstanceExpression.Type, ec.CurrentType)) {
- ec.Report.SymbolRelatedToPreviousError (EventInfo);
- ErrorIsInaccesible (loc, TypeManager.CSharpSignature (EventInfo), ec.Report);
+ ec.Report.SymbolRelatedToPreviousError (spec.MetaInfo);
+ ErrorIsInaccesible (loc, TypeManager.CSharpSignature (spec.MetaInfo), ec.Report);
return false;
}
public bool IsAccessibleFrom (Type invocation_type)
{
bool dummy;
- return IsAccessorAccessible (invocation_type, add_accessor, out dummy) &&
- IsAccessorAccessible (invocation_type, remove_accessor, out dummy);
+ return IsAccessorAccessible (invocation_type, spec.AccessorAdd, out dummy) &&
+ IsAccessorAccessible (invocation_type, spec.AccessorRemove, out dummy);
}
public override Expression CreateExpressionTree (ResolveContext ec)
return null;
}
- public override Expression DoResolve (ResolveContext ec)
+ protected override Expression DoResolve (ResolveContext ec)
{
+ eclass = ExprClass.EventAccess;
+
bool must_do_cs1540_check;
- if (!(IsAccessorAccessible (ec.CurrentType, add_accessor, out must_do_cs1540_check) &&
- IsAccessorAccessible (ec.CurrentType, remove_accessor, out must_do_cs1540_check))) {
- ec.Report.SymbolRelatedToPreviousError (EventInfo);
- ErrorIsInaccesible (loc, TypeManager.CSharpSignature (EventInfo), ec.Report);
+ if (!(IsAccessorAccessible (ec.CurrentType, spec.AccessorAdd, out must_do_cs1540_check) &&
+ IsAccessorAccessible (ec.CurrentType, spec.AccessorRemove, out must_do_cs1540_check))) {
+ ec.Report.SymbolRelatedToPreviousError (spec.MetaInfo);
+ ErrorIsInaccesible (loc, TypeManager.CSharpSignature (spec.MetaInfo), ec.Report);
return null;
}
}
if (!ec.IsObsolete) {
- EventField ev = TypeManager.GetEventField (EventInfo);
- if (ev != null) {
- ev.CheckObsoleteness (loc);
- } else {
- ObsoleteAttribute oa = AttributeTester.GetMemberObsoleteAttribute (EventInfo);
- if (oa != null)
- AttributeTester.Report_ObsoleteMessage (oa, GetSignatureForError (), loc, ec.Report);
- }
+ var oa = spec.GetObsoleteAttribute ();
+ if (oa != null)
+ AttributeTester.Report_ObsoleteMessage (oa, GetSignatureForError (), loc, ec.Report);
}
+
+ spec.MemberDefinition.SetIsUsed ();
+ type = spec.EventType;
return this;
}
{
ec.Report.Error (70, loc,
"The event `{0}' can only appear on the left hand side of += or -= when used outside of the type `{1}'",
- GetSignatureForError (), TypeManager.CSharpName (EventInfo.DeclaringType));
+ GetSignatureForError (), TypeManager.CSharpName (spec.DeclaringType));
}
public override string GetSignatureForError ()
{
- return TypeManager.CSharpSignature (EventInfo);
+ return TypeManager.CSharpSignature (spec.MetaInfo);
}
public void EmitAddOrRemove (EmitContext ec, bool is_add, Expression source)
{
Arguments args = new Arguments (1);
args.Add (new Argument (source));
- Invocation.EmitCall (ec, IsBase, InstanceExpression, is_add ? add_accessor : remove_accessor, args, loc);
+ Invocation.EmitCall (ec, IsBase, InstanceExpression,
+ is_add ? spec.AccessorAdd : spec.AccessorRemove,
+ args, loc);
}
}
{
this.type = type;
this.loc = loc;
- eclass = ExprClass.Variable;
}
public override Expression CreateExpressionTree (ResolveContext ec)
throw new NotSupportedException ("ET");
}
- public override Expression DoResolve (ResolveContext ec)
+ protected override Expression DoResolve (ResolveContext ec)
{
- if (li != null)
- return this;
+ eclass = ExprClass.Variable;
TypeExpr te = new TypeExpression (type, loc);
li = ec.CurrentBlock.AddTemporaryVariable (te, loc);
public override Expression DoResolveLValue (ResolveContext ec, Expression right_side)
{
- return DoResolve (ec);
+ return Resolve (ec);
}
public override void Emit (EmitContext ec)
class VarExpr : SimpleName
{
// Used for error reporting only
- ArrayList initializer;
+ int initializers_count;
public VarExpr (Location loc)
: base ("var", loc)
{
+ initializers_count = 1;
}
- public ArrayList VariableInitializer {
+ public int VariableInitializersCount {
set {
- this.initializer = value;
+ this.initializers_count = value;
}
}
if (RootContext.Version < LanguageVersion.V_3)
rc.Compiler.Report.FeatureIsNotAvailable (loc, "implicitly typed local variable");
- if (initializer == null)
+ if (initializers_count == 1)
return null;
- if (initializer.Count > 1) {
- Location loc_init = ((CSharpParser.VariableDeclaration) initializer[1]).Location;
- rc.Compiler.Report.Error (819, loc_init, "An implicitly typed local variable declaration cannot include multiple declarators");
- initializer = null;
+ if (initializers_count > 1) {
+ rc.Compiler.Report.Error (819, loc, "An implicitly typed local variable declaration cannot include multiple declarators");
+ initializers_count = 1;
return null;
}
- Expression variable_initializer = ((CSharpParser.VariableDeclaration) initializer[0]).expression_or_array_initializer;
- if (variable_initializer == null) {
+ if (initializers_count == 0) {
+ initializers_count = 1;
rc.Compiler.Report.Error (818, loc, "An implicitly typed local variable declarator must include an initializer");
return null;
}