namespace Mono.CSharp {
using System;
using System.Collections;
+ using System.Collections.Generic;
using System.Reflection;
using System.Reflection.Emit;
using System.Text;
+#if NET_4_0
+ using System.Linq;
+ using SLE = System.Linq.Expressions;
+#endif
+
//
// This is an user operator expression, automatically created during
// resolve phase
//
public class UserOperatorCall : Expression {
- public delegate Expression ExpressionTreeExpression (EmitContext ec, MethodGroupExpr mg);
+ public delegate Expression ExpressionTreeExpression (ResolveContext ec, MethodGroupExpr mg);
protected readonly Arguments arguments;
protected readonly MethodGroupExpr mg;
this.loc = loc;
}
- public override Expression CreateExpressionTree (EmitContext ec)
+ public override Expression CreateExpressionTree (ResolveContext ec)
{
if (expr_tree != null)
return expr_tree (ec, mg);
new NullLiteral (loc),
mg.CreateExpressionTree (ec));
- return CreateExpressionFactoryCall ("Call", args);
+ return CreateExpressionFactoryCall (ec, "Call", args);
}
protected override void CloneTo (CloneContext context, Expression target)
// Nothing to clone
}
- public override Expression DoResolve (EmitContext ec)
+ public override Expression DoResolve (ResolveContext ec)
{
//
// We are born fully resolved
mg.EmitCall (ec, arguments);
}
+#if NET_4_0
+ public override SLE.Expression MakeExpression (BuilderContext ctx)
+ {
+ return SLE.Expression.Call ((MethodInfo) mg, Arguments.MakeExpression (arguments, ctx));
+ }
+#endif
+
public MethodGroupExpr Method {
get { return mg; }
}
}
}
- public class ParenthesizedExpression : Expression
+ public class ParenthesizedExpression : ShimExpression
{
- public Expression Expr;
-
public ParenthesizedExpression (Expression expr)
+ : base (expr)
{
- Expr = expr;
loc = expr.Location;
}
- public override Expression CreateExpressionTree (EmitContext ec)
- {
- throw new NotSupportedException ("ET");
- }
-
- public override Expression DoResolve (EmitContext ec)
- {
- Expr = Expr.Resolve (ec);
- return Expr;
- }
-
- public override Expression DoResolveLValue (EmitContext ec, Expression right_side)
- {
- return Expr.DoResolveLValue (ec, right_side);
- }
-
- public override void Emit (EmitContext ec)
+ public override Expression DoResolve (ResolveContext ec)
{
- throw new Exception ("Should not happen");
+ return expr.Resolve (ec);
}
- protected override void CloneTo (CloneContext clonectx, Expression t)
+ public override Expression DoResolveLValue (ResolveContext ec, Expression right_side)
{
- ParenthesizedExpression target = (ParenthesizedExpression) t;
-
- target.Expr = Expr.Clone (clonectx);
+ return expr.DoResolveLValue (ec, right_side);
}
}
// This routine will attempt to simplify the unary expression when the
// argument is a constant.
// </summary>
- Constant TryReduceConstant (EmitContext ec, Constant e)
+ Constant TryReduceConstant (ResolveContext ec, Constant e)
{
if (e is EmptyConstantCast)
return TryReduceConstant (ec, ((EmptyConstantCast) e).child);
int value = ((IntConstant)e).Value;
if (value == int.MinValue) {
if (ec.ConstantCheckState) {
- ConstantFold.Error_CompileTimeOverflow (loc);
+ ConstantFold.Error_CompileTimeOverflow (ec, loc);
return null;
}
return e;
long value = ((LongConstant)e).Value;
if (value == long.MinValue) {
if (ec.ConstantCheckState) {
- ConstantFold.Error_CompileTimeOverflow (loc);
+ ConstantFold.Error_CompileTimeOverflow (ec, loc);
return null;
}
return e;
throw new Exception ("Can not constant fold: " + Oper.ToString());
}
- protected Expression ResolveOperator (EmitContext ec, Expression expr)
+ protected Expression ResolveOperator (ResolveContext ec, Expression expr)
{
eclass = ExprClass.Value;
return ResolveUserType (ec, expr);
}
- protected virtual Expression ResolveEnumOperator (EmitContext ec, Expression expr)
+ protected virtual Expression ResolveEnumOperator (ResolveContext ec, Expression expr)
{
Type underlying_type = TypeManager.GetEnumUnderlyingType (expr.Type);
Expression best_expr = ResolvePrimitivePredefinedType (EmptyCast.Create (expr, underlying_type));
return EmptyCast.Create (this, type);
}
- public override Expression CreateExpressionTree (EmitContext ec)
+ public override Expression CreateExpressionTree (ResolveContext ec)
{
return CreateExpressionTree (ec, null);
}
- Expression CreateExpressionTree (EmitContext ec, MethodGroupExpr user_op)
+ Expression CreateExpressionTree (ResolveContext ec, MethodGroupExpr user_op)
{
string method_name;
switch (Oper) {
case Operator.AddressOf:
- Error_PointerInsideExpressionTree ();
+ Error_PointerInsideExpressionTree (ec);
return null;
case Operator.UnaryNegation:
- if (ec.CheckState && user_op == null && !IsFloat (type))
+ if (ec.HasSet (ResolveContext.Options.CheckedScope) && user_op == null && !IsFloat (type))
method_name = "NegateChecked";
else
method_name = "Negate";
args.Add (new Argument (Expr.CreateExpressionTree (ec)));
if (user_op != null)
args.Add (new Argument (user_op.CreateExpressionTree (ec)));
- return CreateExpressionFactoryCall (method_name, args);
+ return CreateExpressionFactoryCall (ec, method_name, args);
}
static void CreatePredefinedOperatorsTable ()
return expr;
}
- public override Expression DoResolve (EmitContext ec)
+ public override Expression DoResolve (ResolveContext ec)
{
if (Oper == Operator.AddressOf) {
return ResolveAddressOf (ec);
if (TypeManager.IsDynamicType (Expr.Type)) {
Arguments args = new Arguments (1);
args.Add (new Argument (Expr));
- return new DynamicUnaryConversion (GetOperatorExpressionTypeName (), args, loc).DoResolve (ec);
+ return new DynamicUnaryConversion (GetOperatorExpressionTypeName (), args, loc).Resolve (ec);
}
if (TypeManager.IsNullableType (Expr.Type))
Expression expr = ResolveOperator (ec, Expr);
if (expr == null)
- Error_OperatorCannotBeApplied (loc, OperName (Oper), Expr.Type);
+ Error_OperatorCannotBeApplied (ec, loc, OperName (Oper), Expr.Type);
//
// Reduce unary operator on predefined types
return expr;
}
- public override Expression DoResolveLValue (EmitContext ec, Expression right)
+ public override Expression DoResolveLValue (ResolveContext ec, Expression right)
{
return null;
}
break;
case Operator.UnaryNegation:
- if (ec.CheckState && !IsFloat (type)) {
+ if (ec.HasSet (EmitContext.Options.CheckedScope) && !IsFloat (type)) {
ig.Emit (OpCodes.Ldc_I4_0);
if (type == TypeManager.int64_type)
ig.Emit (OpCodes.Conv_U8);
Expr.EmitSideEffect (ec);
}
- public static void Error_OperatorCannotBeApplied (Location loc, string oper, Type t)
+ public static void Error_OperatorCannotBeApplied (ResolveContext ec, Location loc, string oper, Type t)
{
- Report.Error (23, loc, "The `{0}' operator cannot be applied to operand of type `{1}'",
+ ec.Report.Error (23, loc, "The `{0}' operator cannot be applied to operand of type `{1}'",
oper, TypeManager.CSharpName (t));
}
throw new NotImplementedException (oper.ToString ());
}
+#if NET_4_0
+ public override SLE.Expression MakeExpression (BuilderContext ctx)
+ {
+ var expr = Expr.MakeExpression (ctx);
+ bool is_checked = ctx.HasSet (BuilderContext.Options.CheckedScope);
+
+ switch (Oper) {
+ case Operator.UnaryNegation:
+ return is_checked ? SLE.Expression.NegateChecked (expr) : SLE.Expression.Negate (expr);
+ case Operator.LogicalNot:
+ return SLE.Expression.Not (expr);
+ case Operator.OnesComplement:
+ return SLE.Expression.OnesComplement (expr);
+ default:
+ throw new NotImplementedException (Oper.ToString ());
+ }
+ }
+#endif
+
public override void MutateHoistedGenericType (AnonymousMethodStorey storey)
{
type = storey.MutateType (type);
Expr.MutateHoistedGenericType (storey);
}
- Expression ResolveAddressOf (EmitContext ec)
+ Expression ResolveAddressOf (ResolveContext ec)
{
- if (!ec.InUnsafe)
- UnsafeError (loc);
+ if (!ec.IsUnsafe)
+ UnsafeError (ec, loc);
Expr = Expr.DoResolveLValue (ec, EmptyExpression.UnaryAddress);
if (Expr == null || Expr.eclass != ExprClass.Variable) {
- Error (211, "Cannot take the address of the given expression");
+ ec.Report.Error (211, loc, "Cannot take the address of the given expression");
return null;
}
vr.SetHasAddressTaken ();
if (vr.IsHoisted) {
- AnonymousMethodExpression.Error_AddressOfCapturedVar (vr, loc);
+ AnonymousMethodExpression.Error_AddressOfCapturedVar (ec, vr, loc);
}
} else {
IFixedExpression fe = Expr as IFixedExpression;
is_fixed = fe != null && fe.IsFixed;
}
- if (!is_fixed && !ec.InFixedInitializer) {
- Error (212, "You can only take the address of unfixed expression inside of a fixed statement initializer");
+ if (!is_fixed && !ec.HasSet (ResolveContext.Options.FixedInitializerScope)) {
+ ec.Report.Error (212, loc, "You can only take the address of unfixed expression inside of a fixed statement initializer");
}
type = TypeManager.GetPointerType (Expr.Type);
//
// Perform user-operator overload resolution
//
- protected virtual Expression ResolveUserOperator (EmitContext ec, Expression expr)
+ protected virtual Expression ResolveUserOperator (ResolveContext ec, Expression expr)
{
CSharp.Operator.OpType op_type;
switch (Oper) {
}
string op_name = CSharp.Operator.GetMetadataName (op_type);
- MethodGroupExpr user_op = MemberLookup (ec.CurrentType, expr.Type, op_name, MemberTypes.Method, AllBindingFlags, expr.Location) as MethodGroupExpr;
+ MethodGroupExpr user_op = MemberLookup (ec.Compiler, ec.CurrentType, expr.Type, op_name, MemberTypes.Method, AllBindingFlags, expr.Location) as MethodGroupExpr;
if (user_op == null)
return null;
//
// Unary user type overload resolution
//
- Expression ResolveUserType (EmitContext ec, Expression expr)
+ Expression ResolveUserType (ResolveContext ec, Expression expr)
{
Expression best_expr = ResolveUserOperator (ec, expr);
if (best_expr != null)
Type[] predefined = predefined_operators [(int) Oper];
foreach (Type t in predefined) {
- Expression oper_expr = Convert.UserDefinedConversion (ec, expr, t, expr.Location, false);
+ Expression oper_expr = Convert.UserDefinedConversion (ec, expr, t, expr.Location, false, false);
if (oper_expr == null)
continue;
int result = MethodGroupExpr.BetterTypeConversion (ec, best_expr.Type, t);
if (result == 0) {
- Report.Error (35, loc, "Operator `{0}' is ambiguous on an operand of type `{1}'",
+ ec.Report.Error (35, loc, "Operator `{0}' is ambiguous on an operand of type `{1}'",
OperName (Oper), TypeManager.CSharpName (expr.Type));
break;
}
loc = l;
}
- public override Expression CreateExpressionTree (EmitContext ec)
+ public override Expression CreateExpressionTree (ResolveContext ec)
{
- Error_PointerInsideExpressionTree ();
+ Error_PointerInsideExpressionTree (ec);
return null;
}
expr.Emit (ec);
}
- public override Expression DoResolveLValue (EmitContext ec, Expression right_side)
+ public override Expression DoResolveLValue (ResolveContext ec, Expression right_side)
{
return DoResolve (ec);
}
- public override Expression DoResolve (EmitContext ec)
+ public override Expression DoResolve (ResolveContext ec)
{
expr = expr.Resolve (ec);
if (expr == null)
return null;
- if (!ec.InUnsafe)
- UnsafeError (loc);
+ if (!ec.IsUnsafe)
+ UnsafeError (ec, loc);
if (!expr.Type.IsPointer) {
- Error (193, "The * or -> operator must be applied to a pointer");
+ ec.Report.Error (193, loc, "The * or -> operator must be applied to a pointer");
return null;
}
if (expr.Type == TypeManager.void_ptr_type) {
- Error (242, "The operation in question is undefined on void pointers");
+ ec.Report.Error (242, loc, "The operation in question is undefined on void pointers");
return null;
}
}
Mode mode;
- bool is_expr = false;
- bool recurse = false;
+ bool is_expr, recurse;
Expression expr;
- //
- // This is expensive for the simplest case.
- //
- UserOperatorCall method;
+ // Holds the real operation
+ Expression operation;
public UnaryMutator (Mode m, Expression e)
{
expr = e;
}
- static string OperName (Mode mode)
- {
- return (mode == Mode.PreIncrement || mode == Mode.PostIncrement) ?
- "++" : "--";
- }
-
- /// <summary>
- /// Returns whether an object of type `t' can be incremented
- /// or decremented with add/sub (ie, basically whether we can
- /// use pre-post incr-decr operations on it, but it is not a
- /// System.Decimal, which we require operator overloading to catch)
- /// </summary>
- static bool IsIncrementableNumber (Type t)
- {
- return (t == TypeManager.sbyte_type) ||
- (t == TypeManager.byte_type) ||
- (t == TypeManager.short_type) ||
- (t == TypeManager.ushort_type) ||
- (t == TypeManager.int32_type) ||
- (t == TypeManager.uint32_type) ||
- (t == TypeManager.int64_type) ||
- (t == TypeManager.uint64_type) ||
- (t == TypeManager.char_type) ||
- (TypeManager.IsSubclassOf (t, TypeManager.enum_type)) ||
- (t == TypeManager.float_type) ||
- (t == TypeManager.double_type) ||
- (t.IsPointer && t != TypeManager.void_ptr_type);
- }
-
- Expression ResolveOperator (EmitContext ec)
- {
- type = expr.Type;
-
- //
- // The operand of the prefix/postfix increment decrement operators
- // should be an expression that is classified as a variable,
- // a property access or an indexer access
- //
- if (expr.eclass == ExprClass.Variable || expr.eclass == ExprClass.IndexerAccess || expr.eclass == ExprClass.PropertyAccess) {
- expr = expr.ResolveLValue (ec, expr);
- } else {
- Report.Error (1059, loc, "The operand of an increment or decrement operator must be a variable, property or indexer");
- }
-
- //
- // Step 1: Perform Operator Overload location
- //
- MethodGroupExpr mg;
- string op_name;
-
- if (mode == Mode.PreIncrement || mode == Mode.PostIncrement)
- op_name = Operator.GetMetadataName (Operator.OpType.Increment);
- else
- op_name = Operator.GetMetadataName (Operator.OpType.Decrement);
-
- mg = MemberLookup (ec.CurrentType, type, op_name, MemberTypes.Method, AllBindingFlags, loc) as MethodGroupExpr;
-
- if (mg != null) {
- Arguments args = new Arguments (1);
- args.Add (new Argument (expr));
- mg = mg.OverloadResolve (ec, ref args, false, loc);
- if (mg == null)
- return null;
-
- method = new UserOperatorCall (mg, args, null, loc);
- Convert.ImplicitConversionRequired (ec, method, type, loc);
- return this;
- }
-
- if (!IsIncrementableNumber (type)) {
- Error (187, "No such operator '" + OperName (mode) + "' defined for type '" +
- TypeManager.CSharpName (type) + "'");
- return null;
- }
-
- return this;
- }
-
- public override Expression CreateExpressionTree (EmitContext ec)
+ public override Expression CreateExpressionTree (ResolveContext ec)
{
return new SimpleAssign (this, this).CreateExpressionTree (ec);
}
- public override Expression DoResolve (EmitContext ec)
+ public override Expression DoResolve (ResolveContext ec)
{
expr = expr.Resolve (ec);
if (TypeManager.IsDynamicType (expr.Type)) {
Arguments args = new Arguments (1);
args.Add (new Argument (expr));
- return new DynamicUnaryConversion (GetOperatorExpressionTypeName (), args, loc).DoResolve (ec);
+ return new DynamicUnaryConversion (GetOperatorExpressionTypeName (), args, loc).Resolve (ec);
}
eclass = ExprClass.Value;
return ResolveOperator (ec);
}
- //
- // Loads the proper "1" into the stack based on the type, then it emits the
- // opcode for the operation requested
- //
- void LoadOneAndEmitOp (EmitContext ec, Type t)
- {
- //
- // Measure if getting the typecode and using that is more/less efficient
- // that comparing types. t.GetTypeCode() is an internal call.
- //
- ILGenerator ig = ec.ig;
-
- if (t == TypeManager.uint64_type || t == TypeManager.int64_type)
- LongConstant.EmitLong (ig, 1);
- else if (t == TypeManager.double_type)
- ig.Emit (OpCodes.Ldc_R8, 1.0);
- else if (t == TypeManager.float_type)
- ig.Emit (OpCodes.Ldc_R4, 1.0F);
- else if (t.IsPointer){
- Type et = TypeManager.GetElementType (t);
- int n = GetTypeSize (et);
-
- if (n == 0)
- ig.Emit (OpCodes.Sizeof, et);
- else {
- IntConstant.EmitInt (ig, n);
- ig.Emit (OpCodes.Conv_I);
- }
- } else
- ig.Emit (OpCodes.Ldc_I4_1);
-
- //
- // Now emit the operation
- //
-
- Binary.Operator op = (mode & Mode.IsDecrement) != 0 ? Binary.Operator.Subtraction : Binary.Operator.Addition;
- Binary.EmitOperatorOpcode (ec, op, t);
-
- if (t == TypeManager.sbyte_type){
- if (ec.CheckState)
- ig.Emit (OpCodes.Conv_Ovf_I1);
- else
- ig.Emit (OpCodes.Conv_I1);
- } else if (t == TypeManager.byte_type){
- if (ec.CheckState)
- ig.Emit (OpCodes.Conv_Ovf_U1);
- else
- ig.Emit (OpCodes.Conv_U1);
- } else if (t == TypeManager.short_type){
- if (ec.CheckState)
- ig.Emit (OpCodes.Conv_Ovf_I2);
- else
- ig.Emit (OpCodes.Conv_I2);
- } else if (t == TypeManager.ushort_type || t == TypeManager.char_type){
- if (ec.CheckState)
- ig.Emit (OpCodes.Conv_Ovf_U2);
- else
- ig.Emit (OpCodes.Conv_U2);
- }
-
- }
-
void EmitCode (EmitContext ec, bool is_expr)
{
recurse = true;
//
if (recurse) {
((IAssignMethod) expr).Emit (ec, is_expr && (mode == Mode.PostIncrement || mode == Mode.PostDecrement));
- if (method == null)
- LoadOneAndEmitOp (ec, expr.Type);
- else
- ec.ig.Emit (OpCodes.Call, (MethodInfo)method.Method);
+
+ operation.Emit (ec);
+
recurse = false;
return;
}
//
string GetOperatorExpressionTypeName ()
{
- if ((mode & Mode.IsDecrement) != 0)
- return "Decrement";
+ return IsDecrement ? "Decrement" : "Increment";
+ }
+
+ bool IsDecrement {
+ get { return (mode & Mode.IsDecrement) != 0; }
+ }
- return "Increment";
+ //
+ // Returns whether an object of type `t' can be incremented
+ // or decremented with add/sub (ie, basically whether we can
+ // use pre-post incr-decr operations on it, but it is not a
+ // System.Decimal, which we require operator overloading to catch)
+ //
+ static bool IsPredefinedOperator (Type t)
+ {
+ return (TypeManager.IsPrimitiveType (t) && t != TypeManager.bool_type) ||
+ TypeManager.IsEnumType (t) ||
+ t.IsPointer && t != TypeManager.void_ptr_type;
}
+#if NET_4_0
+ public override SLE.Expression MakeExpression (BuilderContext ctx)
+ {
+ var target = ((RuntimeValueExpression) expr).MetaObject.Expression;
+ var source = SLE.Expression.Convert (operation.MakeExpression (ctx), target.Type);
+ return SLE.Expression.Assign (target, source);
+ }
+#endif
+
protected override void CloneTo (CloneContext clonectx, Expression t)
{
UnaryMutator target = (UnaryMutator) t;
target.expr = expr.Clone (clonectx);
}
+
+ Expression ResolveOperator (ResolveContext ec)
+ {
+ type = expr.Type;
+
+ if (expr is RuntimeValueExpression) {
+ operation = expr;
+ } else {
+ // Use itself at the top of the stack
+ operation = new EmptyExpression (type);
+ }
+
+ //
+ // The operand of the prefix/postfix increment decrement operators
+ // should be an expression that is classified as a variable,
+ // a property access or an indexer access
+ //
+ if (expr.eclass == ExprClass.Variable || expr.eclass == ExprClass.IndexerAccess || expr.eclass == ExprClass.PropertyAccess) {
+ expr = expr.ResolveLValue (ec, expr);
+ } else {
+ ec.Report.Error (1059, loc, "The operand of an increment or decrement operator must be a variable, property or indexer");
+ }
+
+ //
+ // 1. Check predefined types
+ //
+ if (IsPredefinedOperator (type)) {
+ // TODO: Move to IntConstant once I get rid of int32_type
+ var one = new IntConstant (1, loc);
+
+ // TODO: Cache this based on type when using EmptyExpression in
+ // context cache
+ Binary.Operator op = IsDecrement ? Binary.Operator.Subtraction : Binary.Operator.Addition;
+ operation = new Binary (op, operation, one);
+ operation = operation.Resolve (ec);
+ if (operation.Type != type)
+ operation = Convert.ExplicitNumericConversion (operation, type);
+
+ return this;
+ }
+
+ //
+ // Step 2: Perform Operator Overload location
+ //
+ MethodGroupExpr mg;
+ string op_name;
+
+ if (IsDecrement)
+ op_name = Operator.GetMetadataName (Operator.OpType.Decrement);
+ else
+ op_name = Operator.GetMetadataName (Operator.OpType.Increment);
+
+ mg = MemberLookup (ec.Compiler, ec.CurrentType, type, op_name, MemberTypes.Method, AllBindingFlags, loc) as MethodGroupExpr;
+
+ if (mg != null) {
+ Arguments args = new Arguments (1);
+ args.Add (new Argument (expr));
+ mg = mg.OverloadResolve (ec, ref args, false, loc);
+ if (mg == null)
+ return null;
+
+ args[0].Expr = operation;
+ operation = new UserOperatorCall (mg, args, null, loc);
+ operation = Convert.ImplicitConversionRequired (ec, operation, type, loc);
+ return this;
+ }
+
+ string name = IsDecrement ?
+ Operator.GetName (Operator.OpType.Decrement) :
+ Operator.GetName (Operator.OpType.Increment);
+
+ Unary.Error_OperatorCannotBeApplied (ec, loc, name, type);
+ return null;
+ }
}
/// <summary>
}
}
- public override Expression DoResolve (EmitContext ec)
+ public override Expression DoResolve (ResolveContext ec)
{
probe_type_expr = ProbeType.ResolveAsTypeTerminal (ec, false);
if (probe_type_expr == null)
return null;
if ((probe_type_expr.Type.Attributes & Class.StaticClassAttribute) == Class.StaticClassAttribute) {
- Report.Error (-244, loc, "The `{0}' operator cannot be applied to an operand of a static type",
+ ec.Report.Error (-244, loc, "The `{0}' operator cannot be applied to an operand of a static type",
OperatorName);
}
if (expr.Type.IsPointer || probe_type_expr.Type.IsPointer) {
- Report.Error (244, loc, "The `{0}' operator cannot be applied to an operand of pointer type",
+ ec.Report.Error (244, loc, "The `{0}' operator cannot be applied to an operand of pointer type",
OperatorName);
return null;
}
if (expr.Type == InternalType.AnonymousMethod) {
- Report.Error (837, loc, "The `{0}' operator cannot be applied to a lambda expression or anonymous method",
+ ec.Report.Error (837, loc, "The `{0}' operator cannot be applied to a lambda expression or anonymous method",
OperatorName);
return null;
}
{
}
- public override Expression CreateExpressionTree (EmitContext ec)
+ public override Expression CreateExpressionTree (ResolveContext ec)
{
Arguments args = Arguments.CreateForExpressionTree (ec, null,
expr.CreateExpressionTree (ec),
new TypeOf (probe_type_expr, loc));
- return CreateExpressionFactoryCall ("TypeIs", args);
+ return CreateExpressionFactoryCall (ec, "TypeIs", args);
}
public override void Emit (EmitContext ec)
ig.Emit (on_true ? OpCodes.Brtrue : OpCodes.Brfalse, target);
}
- Expression CreateConstantResult (bool result)
+ Expression CreateConstantResult (ResolveContext ec, bool result)
{
if (result)
- Report.Warning (183, 1, loc, "The given expression is always of the provided (`{0}') type",
+ ec.Report.Warning (183, 1, loc, "The given expression is always of the provided (`{0}') type",
TypeManager.CSharpName (probe_type_expr.Type));
else
- Report.Warning (184, 1, loc, "The given expression is never of the provided (`{0}') type",
+ ec.Report.Warning (184, 1, loc, "The given expression is never of the provided (`{0}') type",
TypeManager.CSharpName (probe_type_expr.Type));
return ReducedExpression.Create (new BoolConstant (result, loc), this);
}
- public override Expression DoResolve (EmitContext ec)
+ public override Expression DoResolve (ResolveContext ec)
{
if (base.DoResolve (ec) == null)
return null;
// type or a nullable type and the value of E is null, the result is false
//
if (expr.IsNull || expr.eclass == ExprClass.MethodGroup)
- return CreateConstantResult (false);
+ return CreateConstantResult (ec, false);
if (TypeManager.IsNullableType (d) && !TypeManager.ContainsGenericParameters (d)) {
d = TypeManager.TypeToCoreType (TypeManager.GetTypeArguments (d) [0]);
//
// The result is true if D and T are the same value types
//
- return CreateConstantResult (true);
+ return CreateConstantResult (ec, true);
}
if (TypeManager.IsGenericParameter (d))
- return ResolveGenericParameter (t, d);
+ return ResolveGenericParameter (ec, t, d);
//
// An unboxing conversion exists
return this;
} else {
if (TypeManager.IsGenericParameter (t))
- return ResolveGenericParameter (d, t);
+ return ResolveGenericParameter (ec, d, t);
if (TypeManager.IsStruct (d)) {
bool temp;
if (Convert.ImplicitBoxingConversionExists (expr, t, out temp))
- return CreateConstantResult (true);
+ return CreateConstantResult (ec, true);
} else {
if (TypeManager.IsGenericParameter (d))
- return ResolveGenericParameter (t, d);
+ return ResolveGenericParameter (ec, t, d);
if (TypeManager.ContainsGenericParameters (d))
return this;
}
}
- return CreateConstantResult (false);
+ return CreateConstantResult (ec, false);
}
- Expression ResolveGenericParameter (Type d, Type t)
+ Expression ResolveGenericParameter (ResolveContext ec, Type d, Type t)
{
GenericConstraints constraints = TypeManager.GetTypeParameterConstraints (t);
if (constraints != null) {
if (constraints.IsReferenceType && TypeManager.IsStruct (d))
- return CreateConstantResult (false);
-
- if (constraints.IsValueType && !TypeManager.IsStruct (d))
- return CreateConstantResult (TypeManager.IsEqual (d, t));
+ return CreateConstantResult (ec, false);
}
- if (TypeManager.IsGenericParameter (expr.Type))
+ if (TypeManager.IsGenericParameter (expr.Type)) {
+ if (constraints != null && constraints.IsValueType && expr.Type == t)
+ return CreateConstantResult (ec, true);
+
expr = new BoxedCast (expr, d);
+ }
return this;
}
{
}
- public override Expression CreateExpressionTree (EmitContext ec)
+ public override Expression CreateExpressionTree (ResolveContext ec)
{
Arguments args = Arguments.CreateForExpressionTree (ec, null,
expr.CreateExpressionTree (ec),
new TypeOf (probe_type_expr, loc));
- return CreateExpressionFactoryCall ("TypeAs", args);
+ return CreateExpressionFactoryCall (ec, "TypeAs", args);
}
public override void Emit (EmitContext ec)
if (do_isinst)
ig.Emit (OpCodes.Isinst, type);
-#if GMCS_SOURCE
if (TypeManager.IsGenericParameter (type) || TypeManager.IsNullableType (type))
ig.Emit (OpCodes.Unbox_Any, type);
-#endif
}
- public override Expression DoResolve (EmitContext ec)
+ public override Expression DoResolve (ResolveContext ec)
{
// Because expr is modified
if (eclass != ExprClass.Invalid)
if (!TypeManager.IsReferenceType (type) && !TypeManager.IsNullableType (type)) {
if (TypeManager.IsGenericParameter (type)) {
- Report.Error (413, loc,
+ ec.Report.Error (413, loc,
"The `as' operator cannot be used with a non-reference type parameter `{0}'. Consider adding `class' or a reference type constraint",
probe_type_expr.GetSignatureForError ());
} else {
- Report.Error (77, loc,
+ ec.Report.Error (77, loc,
"The `as' operator cannot be used with a non-nullable value type `{0}'",
TypeManager.CSharpName (type));
}
}
if (expr.IsNull && TypeManager.IsNullableType (type)) {
- return Nullable.LiftedNull.CreateFromExpression (this);
+ return Nullable.LiftedNull.CreateFromExpression (ec, this);
}
Expression e = Convert.ImplicitConversion (ec, expr, type, loc);
return this;
}
- Report.Error (39, loc, "Cannot convert type `{0}' to `{1}' via a built-in conversion",
+ ec.Report.Error (39, loc, "Cannot convert type `{0}' to `{1}' via a built-in conversion",
TypeManager.CSharpName (etype), TypeManager.CSharpName (type));
return null;
base.MutateHoistedGenericType (storey);
}
- public override bool GetAttributableValue (EmitContext ec, Type value_type, out object value)
+ public override bool GetAttributableValue (ResolveContext ec, Type value_type, out object value)
{
return expr.GetAttributableValue (ec, value_type, out value);
}
/// FIXME: Cast expressions have an unusual set of parsing
/// rules, we need to figure those out.
/// </summary>
- public class Cast : Expression {
+ public class Cast : ShimExpression {
Expression target_type;
- Expression expr;
public Cast (Expression cast_type, Expression expr)
: this (cast_type, expr, cast_type.Location)
}
public Cast (Expression cast_type, Expression expr, Location loc)
+ : base (expr)
{
this.target_type = cast_type;
- this.expr = expr;
this.loc = loc;
}
get { return target_type; }
}
- public Expression Expr {
- get { return expr; }
- }
-
- public override Expression CreateExpressionTree (EmitContext ec)
- {
- throw new NotSupportedException ("ET");
- }
-
- public override Expression DoResolve (EmitContext ec)
+ public override Expression DoResolve (ResolveContext ec)
{
expr = expr.Resolve (ec);
if (expr == null)
type = target.Type;
if (type.IsAbstract && type.IsSealed) {
- Report.Error (716, loc, "Cannot convert to static type `{0}'", TypeManager.CSharpName (type));
+ ec.Report.Error (716, loc, "Cannot convert to static type `{0}'", TypeManager.CSharpName (type));
return null;
}
return c;
}
- if (type.IsPointer && !ec.InUnsafe) {
- UnsafeError (loc);
+ if (type.IsPointer && !ec.IsUnsafe) {
+ UnsafeError (ec, loc);
} else if (TypeManager.IsDynamicType (expr.Type)) {
Arguments arg = new Arguments (1);
arg.Add (new Argument (expr));
- return new DynamicConversion (type, true, arg, loc).Resolve (ec);
+ return new DynamicConversion (type, CSharpBinderFlags.ConvertExplicit, arg, loc).Resolve (ec);
}
expr = Convert.ExplicitConversion (ec, expr, type, loc);
return expr;
}
- public override void Emit (EmitContext ec)
- {
- throw new Exception ("Should not happen");
- }
-
protected override void CloneTo (CloneContext clonectx, Expression t)
{
Cast target = (Cast) t;
target.expr = expr.Clone (clonectx);
}
}
+
+ public class ImplicitCast : ShimExpression
+ {
+ bool arrayAccess;
+
+ public ImplicitCast (Expression expr, Type target, bool arrayAccess)
+ : base (expr)
+ {
+ this.loc = expr.Location;
+ this.type = target;
+ this.arrayAccess = arrayAccess;
+ }
+
+ public override Expression DoResolve (ResolveContext ec)
+ {
+ expr = expr.Resolve (ec);
+ if (expr == null)
+ return null;
+
+ if (arrayAccess)
+ expr = ConvertExpressionToArrayIndex (ec, expr);
+ else
+ expr = Convert.ImplicitConversionRequired (ec, expr, type, loc);
+
+ return expr;
+ }
+ }
//
// C# 2.0 Default value expression
{
}
- public override void Error_ValueCannotBeConverted (EmitContext ec, Location loc, Type t, bool expl)
+ public override void Error_ValueCannotBeConverted (ResolveContext ec, Location loc, Type t, bool expl)
{
Error_ValueCannotBeConvertedCore (ec, loc, t, expl);
}
this.loc = loc;
}
- public override Expression CreateExpressionTree (EmitContext ec)
+ public override Expression CreateExpressionTree (ResolveContext ec)
{
Arguments args = new Arguments (2);
args.Add (new Argument (this));
args.Add (new Argument (new TypeOf (new TypeExpression (type, loc), loc)));
- return CreateExpressionFactoryCall ("Constant", args);
+ return CreateExpressionFactoryCall (ec, "Constant", args);
}
- public override Expression DoResolve (EmitContext ec)
+ public override Expression DoResolve (ResolveContext ec)
{
TypeExpr texpr = expr.ResolveAsTypeTerminal (ec, false);
if (texpr == null)
type = texpr.Type;
if ((type.Attributes & Class.StaticClassAttribute) == Class.StaticClassAttribute) {
- Report.Error (-244, loc, "The `default value' operator cannot be applied to an operand of a static type");
+ ec.Report.Error (-244, loc, "The `default value' operator cannot be applied to an operand of a static type");
}
if (type.IsPointer)
this.ReturnType = return_type;
}
- public virtual Expression ConvertResult (EmitContext ec, Binary b)
+ public virtual Expression ConvertResult (ResolveContext ec, Binary b)
{
b.type = ReturnType;
return left == ltype && ltype == rtype;
}
- public virtual bool IsApplicable (EmitContext ec, Expression lexpr, Expression rexpr)
+ public virtual bool IsApplicable (ResolveContext ec, Expression lexpr, Expression rexpr)
{
if (TypeManager.IsEqual (left, lexpr.Type) &&
TypeManager.IsEqual (right, rexpr.Type))
Convert.ImplicitConversionExists (ec, rexpr, right);
}
- public PredefinedOperator ResolveBetterOperator (EmitContext ec, PredefinedOperator best_operator)
+ public PredefinedOperator ResolveBetterOperator (ResolveContext ec, PredefinedOperator best_operator)
{
int result = 0;
if (left != null && best_operator.left != null) {
ReturnType = TypeManager.string_type;
}
- public override Expression ConvertResult (EmitContext ec, Binary b)
+ public override Expression ConvertResult (ResolveContext ec, Binary b)
{
//
// Use original expression for nullable arguments
{
}
- public override Expression ConvertResult (EmitContext ec, Binary b)
+ public override Expression ConvertResult (ResolveContext ec, Binary b)
{
b.left = Convert.ImplicitConversion (ec, b.left, left, b.left.Location);
- Expression expr_tree_expr = EmptyCast.Create (b.right, TypeManager.int32_type);
+ Expression expr_tree_expr = Convert.ImplicitConversion (ec, b.right, TypeManager.int32_type, b.right.Location);
int right_mask = left == TypeManager.int32_type || left == TypeManager.uint32_type ? 0x1f : 0x3f;
{
}
- public override bool IsApplicable (EmitContext ec, Expression lexpr, Expression rexpr)
+ public override bool IsApplicable (ResolveContext ec, Expression lexpr, Expression rexpr)
{
if (left == null) {
if (!lexpr.Type.IsPointer)
return true;
}
- public override Expression ConvertResult (EmitContext ec, Binary b)
+ public override Expression ConvertResult (ResolveContext ec, Binary b)
{
if (left != null) {
b.left = EmptyCast.Create (b.left, left);
return s;
}
- public static void Error_OperatorCannotBeApplied (Expression left, Expression right, Operator oper, Location loc)
+ public static void Error_OperatorCannotBeApplied (ResolveContext ec, Expression left, Expression right, Operator oper, Location loc)
{
- new Binary (oper, left, right).Error_OperatorCannotBeApplied (left, right);
+ new Binary (oper, left, right).Error_OperatorCannotBeApplied (ec, left, right);
}
- public static void Error_OperatorCannotBeApplied (Expression left, Expression right, string oper, Location loc)
+ public static void Error_OperatorCannotBeApplied (ResolveContext ec, Expression left, Expression right, string oper, Location loc)
{
string l, r;
l = TypeManager.CSharpName (left.Type);
r = TypeManager.CSharpName (right.Type);
- Report.Error (19, loc, "Operator `{0}' cannot be applied to operands of type `{1}' and `{2}'",
+ ec.Report.Error (19, loc, "Operator `{0}' cannot be applied to operands of type `{1}' and `{2}'",
oper, l, r);
}
- protected void Error_OperatorCannotBeApplied (Expression left, Expression right)
+ protected void Error_OperatorCannotBeApplied (ResolveContext ec, Expression left, Expression right)
{
- Error_OperatorCannotBeApplied (left, right, OperName (oper), loc);
+ Error_OperatorCannotBeApplied (ec, left, right, OperName (oper), loc);
}
//
switch (oper){
case Operator.Multiply:
- if (ec.CheckState){
+ if (ec.HasSet (EmitContext.Options.CheckedScope)) {
if (l == TypeManager.int32_type || l == TypeManager.int64_type)
opcode = OpCodes.Mul_Ovf;
else if (!IsFloat (l))
break;
case Operator.Addition:
- if (ec.CheckState){
+ if (ec.HasSet (EmitContext.Options.CheckedScope)) {
if (l == TypeManager.int32_type || l == TypeManager.int64_type)
opcode = OpCodes.Add_Ovf;
else if (!IsFloat (l))
break;
case Operator.Subtraction:
- if (ec.CheckState){
+ if (ec.HasSet (EmitContext.Options.CheckedScope)) {
if (l == TypeManager.int32_type || l == TypeManager.int64_type)
opcode = OpCodes.Sub_Ovf;
else if (!IsFloat (l))
return t == TypeManager.float_type || t == TypeManager.double_type;
}
- Expression ResolveOperator (EmitContext ec)
+ Expression ResolveOperator (ResolveContext ec)
{
Type l = left.Type;
Type r = right.Type;
// at least one of 'left' or 'right' is an enumeration constant (EnumConstant or SideEffectConstant or ...)
// if 'left' is not an enumeration constant, create one from the type of 'right'
- Constant EnumLiftUp (EmitContext ec, Constant left, Constant right, Location loc)
+ Constant EnumLiftUp (ResolveContext ec, Constant left, Constant right, Location loc)
{
switch (oper) {
case Operator.BitwiseOr:
break;
return left;
}
- Error_OperatorCannotBeApplied (this.left, this.right);
+ Error_OperatorCannotBeApplied (ec, this.left, this.right);
return null;
}
//
// The `|' operator used on types which were extended is dangerous
//
- void CheckBitwiseOrOnSignExtended ()
+ void CheckBitwiseOrOnSignExtended (ResolveContext ec)
{
OpcodeCast lcast = left as OpcodeCast;
if (lcast != null) {
// FIXME: consider constants
- Report.Warning (675, 3, loc,
+ ec.Report.Warning (675, 3, loc,
"The operator `|' used on the sign-extended type `{0}'. Consider casting to a smaller unsigned type first",
TypeManager.CSharpName (lcast != null ? lcast.UnderlyingType : rcast.UnderlyingType));
}
//
// 7.2.6.2 Binary numeric promotions
//
- public bool DoBinaryOperatorPromotion (EmitContext ec)
+ public bool DoBinaryOperatorPromotion (ResolveContext ec)
{
Type ltype = left.Type;
Type rtype = right.Type;
return true;
}
- public override Expression DoResolve (EmitContext ec)
+ public override Expression DoResolve (ResolveContext ec)
{
if (left == null)
return null;
return null;
if (left.eclass == ExprClass.Type) {
- Report.Error (75, loc, "To cast a negative value, you must enclose the value in parentheses");
+ ec.Report.Error (75, loc, "To cast a negative value, you must enclose the value in parentheses");
return null;
}
} else
// FIXME: resolve right expression as unreachable
// right.Resolve (ec);
- Report.Warning (429, 4, loc, "Unreachable expression code detected");
+ ec.Report.Warning (429, 4, loc, "Unreachable expression code detected");
return left;
}
Constant rc = right as Constant;
// The conversion rules are ignored in enum context but why
- if (!ec.InEnumContext && lc != null && rc != null && (TypeManager.IsEnumType (left.Type) || TypeManager.IsEnumType (right.Type))) {
+ if (!ec.HasSet (ResolveContext.Options.EnumScope) && lc != null && rc != null && (TypeManager.IsEnumType (left.Type) || TypeManager.IsEnumType (right.Type))) {
lc = EnumLiftUp (ec, lc, rc, loc);
if (lc != null)
rc = EnumLiftUp (ec, rc, lc, loc);
}
if (rc != null && lc != null) {
- int prev_e = Report.Errors;
+ int prev_e = ec.Report.Errors;
Expression e = ConstantFold.BinaryFold (
ec, oper, lc, rc, loc);
- if (e != null || Report.Errors != prev_e)
+ if (e != null || ec.Report.Errors != prev_e)
return e;
} else if ((oper == Operator.BitwiseAnd || oper == Operator.LogicalAnd) && !TypeManager.IsDynamicType (left.Type) &&
- ((lc != null && lc.IsDefaultValue) || (rc != null && rc.IsDefaultValue))) {
+ ((lc != null && lc.IsDefaultValue && !(lc is NullLiteral)) || (rc != null && rc.IsDefaultValue && !(rc is NullLiteral)))) {
if ((ResolveOperator (ec)) == null) {
- Error_OperatorCannotBeApplied (left, right);
+ Error_OperatorCannotBeApplied (ec, left, right);
return null;
}
// Comparison warnings
if ((oper & Operator.ComparisonMask) != 0) {
if (left.Equals (right)) {
- Report.Warning (1718, 3, loc, "A comparison made to same variable. Did you mean to compare something else?");
+ ec.Report.Warning (1718, 3, loc, "A comparison made to same variable. Did you mean to compare something else?");
}
- CheckUselessComparison (lc, right.Type);
- CheckUselessComparison (rc, left.Type);
+ CheckUselessComparison (ec, lc, right.Type);
+ CheckUselessComparison (ec, rc, left.Type);
}
if (TypeManager.IsDynamicType (left.Type) || TypeManager.IsDynamicType (right.Type)) {
return DoResolveCore (ec, left, right);
}
- protected Expression DoResolveCore (EmitContext ec, Expression left_orig, Expression right_orig)
+ protected Expression DoResolveCore (ResolveContext ec, Expression left_orig, Expression right_orig)
{
Expression expr = ResolveOperator (ec);
if (expr == null)
- Error_OperatorCannotBeApplied (left_orig, right_orig);
+ Error_OperatorCannotBeApplied (ec, left_orig, right_orig);
if (left == null || right == null)
throw new InternalErrorException ("Invalid conversion");
if (oper == Operator.BitwiseOr)
- CheckBitwiseOrOnSignExtended ();
+ CheckBitwiseOrOnSignExtended (ec);
return expr;
}
+#if NET_4_0
+ public override SLE.Expression MakeExpression (BuilderContext ctx)
+ {
+ var le = left.MakeExpression (ctx);
+ var re = right.MakeExpression (ctx);
+ bool is_checked = ctx.HasSet (BuilderContext.Options.CheckedScope);
+
+ switch (oper) {
+ case Operator.Addition:
+ return is_checked ? SLE.Expression.AddChecked (le, re) : SLE.Expression.Add (le, re);
+ case Operator.BitwiseAnd:
+ return SLE.Expression.And (le, re);
+ case Operator.BitwiseOr:
+ return SLE.Expression.Or (le, re);
+ case Operator.Division:
+ return SLE.Expression.Divide (le, re);
+ case Operator.Equality:
+ return SLE.Expression.Equal (le, re);
+ case Operator.ExclusiveOr:
+ return SLE.Expression.ExclusiveOr (le, re);
+ case Operator.GreaterThan:
+ return SLE.Expression.GreaterThan (le, re);
+ case Operator.GreaterThanOrEqual:
+ return SLE.Expression.GreaterThanOrEqual (le, re);
+ case Operator.Inequality:
+ return SLE.Expression.NotEqual (le, re);
+ case Operator.LeftShift:
+ return SLE.Expression.LeftShift (le, re);
+ case Operator.LessThan:
+ return SLE.Expression.LessThan (le, re);
+ case Operator.LessThanOrEqual:
+ return SLE.Expression.LessThanOrEqual (le, re);
+ case Operator.LogicalAnd:
+ return SLE.Expression.AndAlso (le, re);
+ case Operator.LogicalOr:
+ return SLE.Expression.OrElse (le, re);
+ case Operator.Modulus:
+ return SLE.Expression.Modulo (le, re);
+ case Operator.Multiply:
+ return is_checked ? SLE.Expression.MultiplyChecked (le, re) : SLE.Expression.Multiply (le, re);
+ case Operator.RightShift:
+ return SLE.Expression.RightShift (le, re);
+ case Operator.Subtraction:
+ return is_checked ? SLE.Expression.SubtractChecked (le, re) : SLE.Expression.Subtract (le, re);
+ default:
+ throw new NotImplementedException (oper.ToString ());
+ }
+ }
+#endif
+
public override void MutateHoistedGenericType (AnonymousMethodStorey storey)
{
left.MutateHoistedGenericType (storey);
// bool operator == (D x, D y)
// bool operator != (D x, D y)
//
- Expression ResolveOperatorDelegate (EmitContext ec, Type l, Type r)
+ Expression ResolveOperatorDelegate (ResolveContext ec, Type l, Type r)
{
bool is_equality = (oper & Operator.EqualityMask) != 0;
if (!TypeManager.IsEqual (l, r) && !TypeManager.IsVariantOf (r, l)) {
//
// Enumeration operators
//
- Expression ResolveOperatorEnum (EmitContext ec, bool lenum, bool renum, Type ltype, Type rtype)
+ Expression ResolveOperatorEnum (ResolveContext ec, bool lenum, bool renum, Type ltype, Type rtype)
{
//
// bool operator == (E x, E y);
// E operator + (E e, U x)
//
if (!((oper & (Operator.ComparisonMask | Operator.BitwiseMask)) != 0 ||
- (oper == Operator.Subtraction && lenum) || (oper == Operator.Addition && lenum != renum)))
+ (oper == Operator.Subtraction && lenum) ||
+ (oper == Operator.Addition && (lenum != renum || type != null)))) // type != null for lifted null
return null;
Expression ltemp = left;
Type underlying_type;
Expression expr;
- if ((oper & Operator.ComparisonMask | Operator.BitwiseMask) != 0) {
+ if ((oper & (Operator.ComparisonMask | Operator.BitwiseMask)) != 0) {
if (renum) {
expr = Convert.ImplicitConversion (ec, left, rtype, loc);
if (expr != null) {
return expr;
//
- // TODO: Need to corectly implemented Coumpound Assigment for all operators
// Section: 7.16.2
//
- if (Convert.ImplicitConversionExists (ec, left, rtype))
+
+ //
+ // If the return type of the selected operator is implicitly convertible to the type of x
+ //
+ if (Convert.ImplicitConversionExists (ec, expr, ltype))
return expr;
- if (!Convert.ImplicitConversionExists (ec, ltemp, rtype))
+ //
+ // Otherwise, if the selected operator is a predefined operator, if the return type of the
+ // selected operator is explicitly convertible to the type of x, and if y is implicitly
+ // convertible to the type of x or the operator is a shift operator, then the operation
+ // is evaluated as x = (T)(x op y), where T is the type of x
+ //
+ expr = Convert.ExplicitConversion (ec, expr, ltype, loc);
+ if (expr == null)
return null;
- expr = Convert.ExplicitConversion (ec, expr, rtype, loc);
- return expr;
+ if (Convert.ImplicitConversionExists (ec, ltemp, ltype))
+ return expr;
+
+ return null;
}
//
// 7.9.6 Reference type equality operators
//
- Binary ResolveOperatorEqualityRerefence (EmitContext ec, Type l, Type r)
+ Binary ResolveOperatorEqualityRerefence (ResolveContext ec, Type l, Type r)
{
//
// operator != (object a, object b)
if (lgen) {
if (!TypeManager.IsReferenceType (l))
return null;
- left = new BoxedCast (left, TypeManager.object_type);
+
+ l = TypeManager.object_type;
+ left = new BoxedCast (left, l);
} else if (l.IsInterface) {
l = TypeManager.object_type;
} else if (TypeManager.IsStruct (l)) {
if (rgen) {
if (!TypeManager.IsReferenceType (r))
return null;
- right = new BoxedCast (right, TypeManager.object_type);
+
+ r = TypeManager.object_type;
+ right = new BoxedCast (right, r);
} else if (r.IsInterface) {
r = TypeManager.object_type;
} else if (TypeManager.IsStruct (r)) {
//
if (Convert.ImplicitReferenceConversionExists (left, r)) {
if (l == TypeManager.string_type)
- Report.Warning (253, 2, loc, ref_comparison, "right");
+ ec.Report.Warning (253, 2, loc, ref_comparison, "right");
return this;
}
if (Convert.ImplicitReferenceConversionExists (right, l)) {
if (r == TypeManager.string_type)
- Report.Warning (252, 2, loc, ref_comparison, "left");
+ ec.Report.Warning (252, 2, loc, ref_comparison, "left");
return this;
}
}
- Expression ResolveOperatorPointer (EmitContext ec, Type l, Type r)
+ Expression ResolveOperatorPointer (ResolveContext ec, Type l, Type r)
{
//
// bool operator == (void* x, void* y);
//
// Build-in operators method overloading
//
- protected virtual Expression ResolveOperatorPredefined (EmitContext ec, PredefinedOperator [] operators, bool primitives_only, Type enum_type)
+ protected virtual Expression ResolveOperatorPredefined (ResolveContext ec, PredefinedOperator [] operators, bool primitives_only, Type enum_type)
{
PredefinedOperator best_operator = null;
Type l = left.Type;
best_operator = po.ResolveBetterOperator (ec, best_operator);
if (best_operator == null) {
- Report.Error (34, loc, "Operator `{0}' is ambiguous on operands of type `{1}' and `{2}'",
- OperName (oper), left.GetSignatureForError (), right.GetSignatureForError ());
+ ec.Report.Error (34, loc, "Operator `{0}' is ambiguous on operands of type `{1}' and `{2}'",
+ OperName (oper), TypeManager.CSharpName (l), TypeManager.CSharpName (r));
best_operator = po;
break;
//
// Performs user-operator overloading
//
- protected virtual Expression ResolveUserOperator (EmitContext ec, Type l, Type r)
+ protected virtual Expression ResolveUserOperator (ResolveContext ec, Type l, Type r)
{
Operator user_oper;
if (oper == Operator.LogicalAnd)
string op = GetOperatorMetadataName (user_oper);
- MethodGroupExpr left_operators = MemberLookup (ec.CurrentType, l, op, MemberTypes.Method, AllBindingFlags, loc) as MethodGroupExpr;
+ MethodGroupExpr left_operators = MemberLookup (ec.Compiler, ec.CurrentType, l, op, MemberTypes.Method, AllBindingFlags, loc) as MethodGroupExpr;
MethodGroupExpr right_operators = null;
if (!TypeManager.IsEqual (r, l)) {
- right_operators = MemberLookup (ec.CurrentType, r, op, MemberTypes.Method, AllBindingFlags, loc) as MethodGroupExpr;
+ right_operators = MemberLookup (ec.Compiler, ec.CurrentType, r, op, MemberTypes.Method, AllBindingFlags, loc) as MethodGroupExpr;
if (right_operators == null && left_operators == null)
return null;
} else if (left_operators == null) {
return oper_expr;
}
- public override TypeExpr ResolveAsTypeTerminal (IResolveContext ec, bool silent)
+ public override TypeExpr ResolveAsTypeTerminal (IMemberContext ec, bool silent)
{
return null;
}
- private void CheckUselessComparison (Constant c, Type type)
+ private void CheckUselessComparison (ResolveContext ec, Constant c, Type type)
{
if (c == null || !IsTypeIntegral (type)
|| c is StringConstant
type == TypeManager.uint32_type ||
type == TypeManager.int64_type ||
type == TypeManager.char_type)
- WarnUselessComparison (type);
+ WarnUselessComparison (ec, type);
return;
}
value = (long) uvalue;
return;
if (IsValueOutOfRange (value, type))
- WarnUselessComparison (type);
+ WarnUselessComparison (ec, type);
}
static bool IsValueOutOfRange (long value, Type type)
type == TypeManager.char_type;
}
- private void WarnUselessComparison (Type type)
+ private void WarnUselessComparison (ResolveContext ec, Type type)
{
- Report.Warning (652, 2, loc, "A comparison between a constant and a variable is useless. The constant is out of the range of the variable type `{0}'",
+ ec.Report.Warning (652, 2, loc, "A comparison between a constant and a variable is useless. The constant is out of the range of the variable type `{0}'",
TypeManager.CSharpName (type));
}
public override void EmitSideEffect (EmitContext ec)
{
if ((oper & Operator.LogicalMask) != 0 ||
- (ec.CheckState && (oper == Operator.Multiply || oper == Operator.Addition || oper == Operator.Subtraction))) {
+ (ec.HasSet (EmitContext.Options.CheckedScope) && (oper == Operator.Multiply || oper == Operator.Addition || oper == Operator.Subtraction))) {
base.EmitSideEffect (ec);
} else {
left.EmitSideEffect (ec);
target.right = right.Clone (clonectx);
}
- public Expression CreateCallSiteBinder (EmitContext ec, Arguments args)
+ public Expression CreateCallSiteBinder (ResolveContext ec, Arguments args)
{
- Arguments binder_args = new Arguments (4);
+ Arguments binder_args = new Arguments (3);
MemberAccess sle = new MemberAccess (new MemberAccess (
new QualifiedAliasMember (QualifiedAliasMember.GlobalAlias, "System", loc), "Linq", loc), "Expressions", loc);
- MemberAccess binder = DynamicExpressionStatement.GetBinderNamespace (loc);
+ CSharpBinderFlags flags = 0;
+ if (ec.HasSet (ResolveContext.Options.CheckedScope))
+ flags = CSharpBinderFlags.CheckedContext;
- binder_args.Add (new Argument (new MemberAccess (new MemberAccess (sle, "ExpressionType", loc), GetOperatorExpressionTypeName (), loc)));
- binder_args.Add (new Argument (new BoolLiteral (ec.CheckState, loc)));
+ if ((oper & Operator.LogicalMask) != 0)
+ flags |= CSharpBinderFlags.BinaryOperationLogical;
- bool member_access = left is DynamicMemberBinder || right is DynamicMemberBinder;
- binder_args.Add (new Argument (new BoolLiteral (member_access, loc)));
+ binder_args.Add (new Argument (new EnumConstant (new IntLiteral ((int) flags, loc), TypeManager.binder_flags)));
+ binder_args.Add (new Argument (new MemberAccess (new MemberAccess (sle, "ExpressionType", loc), GetOperatorExpressionTypeName (), loc)));
binder_args.Add (new Argument (new ImplicitlyTypedArrayCreation ("[]", args.CreateDynamicBinderArguments (), loc)));
- return new New (new MemberAccess (binder, "CSharpBinaryOperationBinder", loc), binder_args, loc);
+ return new Invocation (DynamicExpressionStatement.GetBinder ("BinaryOperation", loc), binder_args);
}
- public override Expression CreateExpressionTree (EmitContext ec)
+ public override Expression CreateExpressionTree (ResolveContext ec)
{
return CreateExpressionTree (ec, null);
}
- Expression CreateExpressionTree (EmitContext ec, MethodGroupExpr method)
+ Expression CreateExpressionTree (ResolveContext ec, MethodGroupExpr method)
{
string method_name;
bool lift_arg = false;
switch (oper) {
case Operator.Addition:
- if (method == null && ec.CheckState && !IsFloat (type))
+ if (method == null && ec.HasSet (ResolveContext.Options.CheckedScope) && !IsFloat (type))
method_name = "AddChecked";
else
method_name = "Add";
method_name = "Modulo";
break;
case Operator.Multiply:
- if (method == null && ec.CheckState && !IsFloat (type))
+ if (method == null && ec.HasSet (ResolveContext.Options.CheckedScope) && !IsFloat (type))
method_name = "MultiplyChecked";
else
method_name = "Multiply";
method_name = "RightShift";
break;
case Operator.Subtraction:
- if (method == null && ec.CheckState && !IsFloat (type))
+ if (method == null && ec.HasSet (ResolveContext.Options.CheckedScope) && !IsFloat (type))
method_name = "SubtractChecked";
else
method_name = "Subtract";
args.Add (new Argument (method.CreateExpressionTree (ec)));
}
- return CreateExpressionFactoryCall (method_name, args);
+ return CreateExpressionFactoryCall (ec, method_name, args);
}
}
Append (right);
}
- public override Expression CreateExpressionTree (EmitContext ec)
+ public override Expression CreateExpressionTree (ResolveContext ec)
{
Argument arg = arguments [0];
return CreateExpressionAddCall (ec, arg, arg.CreateExpressionTree (ec), 1);
//
// Creates nested calls tree from an array of arguments used for IL emit
//
- Expression CreateExpressionAddCall (EmitContext ec, Argument left, Expression left_etree, int pos)
+ Expression CreateExpressionAddCall (ResolveContext ec, Argument left, Expression left_etree, int pos)
{
Arguments concat_args = new Arguments (2);
Arguments add_args = new Arguments (3);
add_args.Add (new Argument (method.CreateExpressionTree (ec)));
- Expression expr = CreateExpressionFactoryCall ("Add", add_args);
+ Expression expr = CreateExpressionFactoryCall (ec, "Add", add_args);
if (++pos == arguments.Count)
return expr;
return CreateExpressionAddCall (ec, left, expr, pos);
}
- public override Expression DoResolve (EmitContext ec)
+ public override Expression DoResolve (ResolveContext ec)
{
return this;
}
public override void Emit (EmitContext ec)
{
Expression concat = new Invocation (CreateConcatMemberExpression (), arguments, true);
- concat = concat.Resolve (ec);
+ concat = concat.Resolve (new ResolveContext (ec.MemberContext));
if (concat != null)
concat.Emit (ec);
}
+
+#if NET_4_0
+ public override SLE.Expression MakeExpression (BuilderContext ctx)
+ {
+ if (arguments.Count != 2)
+ throw new NotImplementedException ("arguments.Count != 2");
+
+ var concat = TypeManager.string_type.GetMethod ("Concat", new[] { typeof (object), typeof (object) });
+ return SLE.Expression.Add (arguments[0].Expr.MakeExpression (ctx), arguments[1].Expr.MakeExpression (ctx), concat);
+ }
+#endif
public override void MutateHoistedGenericType (AnonymousMethodStorey storey)
{
this.is_and = is_and;
}
- public override Expression DoResolve (EmitContext ec)
+ public override Expression DoResolve (ResolveContext ec)
{
MethodInfo method = (MethodInfo)mg;
type = TypeManager.TypeToCoreType (method.ReturnType);
AParametersCollection pd = TypeManager.GetParameterData (method);
if (!TypeManager.IsEqual (type, type) || !TypeManager.IsEqual (type, pd.Types [0]) || !TypeManager.IsEqual (type, pd.Types [1])) {
- Report.Error (217, loc,
+ ec.Report.Error (217, loc,
"A user-defined operator `{0}' must have parameters and return values of the same type in order to be applicable as a short circuit operator",
TypeManager.CSharpSignature (method));
return null;
Expression op_true = GetOperatorTrue (ec, left_dup, loc);
Expression op_false = GetOperatorFalse (ec, left_dup, loc);
if (op_true == null || op_false == null) {
- Report.Error (218, loc,
+ ec.Report.Error (218, loc,
"The type `{0}' must have operator `true' and operator `false' defined when `{1}' is used as a short circuit operator",
TypeManager.CSharpName (type), TypeManager.CSharpSignature (method));
return null;
this.op = op;
}
- public override Expression CreateExpressionTree (EmitContext ec)
+ public override Expression CreateExpressionTree (ResolveContext ec)
{
- Error_PointerInsideExpressionTree ();
+ Error_PointerInsideExpressionTree (ec);
return null;
}
- public override Expression DoResolve (EmitContext ec)
+ public override Expression DoResolve (ResolveContext ec)
{
eclass = ExprClass.Variable;
if (left.Type == TypeManager.void_ptr_type) {
- Error (242, "The operation in question is undefined on void pointers");
+ ec.Report.Error (242, loc, "The operation in question is undefined on void pointers");
return null;
}
return;
if (size != 0) {
- right = ConstantFold.BinaryFold (ec, Binary.Operator.Multiply, new IntConstant (size, right.Location), right_const, loc);
+ // TODO: Should be the checks resolve context sensitive?
+ ResolveContext rc = new ResolveContext (ec.MemberContext);
+ right = ConstantFold.BinaryFold (rc, Binary.Operator.Multiply, new IntConstant (size, right.Location), right_const, loc);
if (right == null)
return;
} else {
}
}
}
+
+ //
+ // A boolean-expression is an expression that yields a result
+ // of type bool
+ //
+ public class BooleanExpression : ShimExpression
+ {
+ public BooleanExpression (Expression expr)
+ : base (expr)
+ {
+ this.loc = expr.Location;
+ }
+
+ public override Expression CreateExpressionTree (ResolveContext ec)
+ {
+ // TODO: We should emit IsTrue (v4) instead of direct user operator
+ // call but that would break csc compatibility
+ return base.CreateExpressionTree (ec);
+ }
+
+ public override Expression DoResolve (ResolveContext ec)
+ {
+ // A boolean-expression is required to be of a type
+ // that can be implicitly converted to bool or of
+ // a type that implements operator true
+
+ expr = expr.Resolve (ec);
+ if (expr == null)
+ return null;
+
+ Assign ass = expr as Assign;
+ if (ass != null && ass.Source is Constant) {
+ ec.Report.Warning (665, 3, loc,
+ "Assignment in conditional expression is always constant. Did you mean to use `==' instead ?");
+ }
+
+ if (expr.Type == TypeManager.bool_type)
+ return expr;
+
+ if (TypeManager.IsDynamicType (expr.Type)) {
+ Arguments args = new Arguments (1);
+ args.Add (new Argument (expr));
+ return new DynamicUnaryConversion ("IsTrue", args, loc).Resolve (ec);
+ }
+
+ type = TypeManager.bool_type;
+ Expression converted = Convert.ImplicitConversion (ec, expr, type, loc);
+ if (converted != null)
+ return converted;
+
+ //
+ // If no implicit conversion to bool exists, try using `operator true'
+ //
+ converted = GetOperatorTrue (ec, expr, loc);
+ if (converted == null) {
+ expr.Error_ValueCannotBeConverted (ec, loc, type, false);
+ return null;
+ }
+
+ return converted;
+ }
+ }
/// <summary>
/// Implements the ternary conditional operator (?:)
/// </summary>
public class Conditional : Expression {
Expression expr, true_expr, false_expr;
-
- public Conditional (Expression expr, Expression true_expr, Expression false_expr)
+
+ public Conditional (BooleanExpression expr, Expression true_expr, Expression false_expr)
{
this.expr = expr;
this.true_expr = true_expr;
}
}
- public override Expression CreateExpressionTree (EmitContext ec)
+ public override Expression CreateExpressionTree (ResolveContext ec)
{
Arguments args = new Arguments (3);
args.Add (new Argument (expr.CreateExpressionTree (ec)));
args.Add (new Argument (true_expr.CreateExpressionTree (ec)));
args.Add (new Argument (false_expr.CreateExpressionTree (ec)));
- return CreateExpressionFactoryCall ("Condition", args);
+ return CreateExpressionFactoryCall (ec, "Condition", args);
}
- public override Expression DoResolve (EmitContext ec)
+ public override Expression DoResolve (ResolveContext ec)
{
- expr = Expression.ResolveBoolean (ec, expr, loc);
-
- Assign ass = expr as Assign;
- if (ass != null && ass.Source is Constant) {
- Report.Warning (665, 3, loc, "Assignment in conditional expression is always constant; did you mean to use == instead of = ?");
- }
-
+ expr = expr.Resolve (ec);
true_expr = true_expr.Resolve (ec);
false_expr = false_expr.Resolve (ec);
// Check if both can convert implicitl to each other's type
//
if (Convert.ImplicitConversion (ec, false_expr, true_type, loc) != null) {
- Error (172,
+ ec.Report.Error (172, loc,
"Can not compute type of conditional expression " +
"as `" + TypeManager.CSharpName (true_expr.Type) +
"' and `" + TypeManager.CSharpName (false_expr.Type) +
} else if ((conv = Convert.ImplicitConversion (ec, false_expr, true_type, loc)) != null) {
false_expr = conv;
} else {
- Report.Error (173, loc,
+ ec.Report.Error (173, loc,
"Type of conditional expression cannot be determined because there is no implicit conversion between `{0}' and `{1}'",
- true_expr.GetSignatureForError (), false_expr.GetSignatureForError ());
+ TypeManager.CSharpName (true_type), TypeManager.CSharpName (false_type));
return null;
}
}
Constant c = expr as Constant;
if (c != null){
bool is_false = c.IsDefaultValue;
- Report.Warning (429, 4, is_false ? true_expr.Location : false_expr.Location, "Unreachable expression code detected");
+ ec.Report.Warning (429, 4, is_false ? true_expr.Location : false_expr.Location, "Unreachable expression code detected");
return ReducedExpression.Create (is_false ? false_expr : true_expr, this).Resolve (ec);
}
type = storey.MutateType (type);
}
- public override TypeExpr ResolveAsTypeTerminal (IResolveContext ec, bool silent)
+ public override TypeExpr ResolveAsTypeTerminal (IMemberContext ec, bool silent)
{
return null;
}
LocalTemporary temp;
#region Abstract
- public abstract HoistedVariable GetHoistedVariable (EmitContext ec);
+ public abstract HoistedVariable GetHoistedVariable (AnonymousExpression ae);
public abstract bool IsFixed { get; }
public abstract bool IsRef { get; }
public abstract string Name { get; }
Variable.EmitAddressOf (ec);
}
+ public HoistedVariable GetHoistedVariable (ResolveContext rc)
+ {
+ return GetHoistedVariable (rc.CurrentAnonymousMethod);
+ }
+
+ public HoistedVariable GetHoistedVariable (EmitContext ec)
+ {
+ return GetHoistedVariable (ec.CurrentAnonymousMethod);
+ }
+
+ public override string GetSignatureForError ()
+ {
+ return Name;
+ }
+
public override void Emit (EmitContext ec)
{
Emit (ec, false);
}
public bool IsHoisted {
- get { return GetHoistedVariable (null) != null; }
+ get { return GetHoistedVariable ((AnonymousExpression) null) != null; }
}
public override void MutateHoistedGenericType (AnonymousMethodStorey storey)
get { return local_info.VariableInfo; }
}
- public override HoistedVariable GetHoistedVariable (EmitContext ec)
+ public override HoistedVariable GetHoistedVariable (AnonymousExpression ae)
{
return local_info.HoistedVariableReference;
}
get { return name; }
}
- public bool VerifyAssigned (EmitContext ec)
+ public bool VerifyAssigned (ResolveContext ec)
{
VariableInfo variable_info = local_info.VariableInfo;
return variable_info == null || variable_info.IsAssigned (ec, loc);
local_info.AddressTaken = true;
}
- public override Expression CreateExpressionTree (EmitContext ec)
+ public override Expression CreateExpressionTree (ResolveContext ec)
{
HoistedVariable hv = GetHoistedVariable (ec);
if (hv != null)
Arguments arg = new Arguments (1);
arg.Add (new Argument (this));
- return CreateExpressionFactoryCall ("Constant", arg);
+ return CreateExpressionFactoryCall (ec, "Constant", arg);
}
- Expression DoResolveBase (EmitContext ec)
+ Expression DoResolveBase (ResolveContext ec)
{
type = local_info.VariableType;
//
if (ec.MustCaptureVariable (local_info)) {
if (local_info.AddressTaken)
- AnonymousMethodExpression.Error_AddressOfCapturedVar (this, loc);
+ AnonymousMethodExpression.Error_AddressOfCapturedVar (ec, this, loc);
if (ec.IsVariableCapturingRequired) {
AnonymousMethodStorey storey = local_info.Block.Explicit.CreateAnonymousMethodStorey (ec);
return this;
}
- public override Expression DoResolve (EmitContext ec)
+ public override Expression DoResolve (ResolveContext ec)
{
if (resolved)
return this;
if (type == null && local_info.Type is VarExpr) {
local_info.VariableType = TypeManager.object_type;
- Error_VariableIsUsedBeforeItIsDeclared (Name);
+ Error_VariableIsUsedBeforeItIsDeclared (ec.Report, Name);
return null;
}
return DoResolveBase (ec);
}
- public override Expression DoResolveLValue (EmitContext ec, Expression right_side)
+ public override Expression DoResolveLValue (ResolveContext ec, Expression right_side)
{
ResolveLocalInfo ();
} else {
code = 1656; msg = "Cannot assign to `{0}' because it is a `{1}'";
}
- Report.Error (code, loc, msg, Name, local_info.GetReadOnlyContext ());
+ ec.Report.Error (code, loc, msg, Name, local_info.GetReadOnlyContext ());
} else if (VariableInfo != null) {
VariableInfo.SetAssigned (ec);
}
get { return pi.Parameter.ModFlags == Parameter.Modifier.OUT; }
}
- public override HoistedVariable GetHoistedVariable (EmitContext ec)
+ public override HoistedVariable GetHoistedVariable (AnonymousExpression ae)
{
return pi.Parameter.HoistedVariableReference;
}
get { return Parameter; }
}
- public bool IsAssigned (EmitContext ec, Location loc)
+ public bool IsAssigned (ResolveContext ec, Location loc)
{
// HACK: Variables are not captured in probing mode
if (ec.IsInProbingMode)
if (!ec.DoFlowAnalysis || !HasOutModifier || ec.CurrentBranching.IsAssigned (VariableInfo))
return true;
- Report.Error (269, loc, "Use of unassigned out parameter `{0}'", Name);
+ ec.Report.Error (269, loc, "Use of unassigned out parameter `{0}'", Name);
return false;
}
Parameter.HasAddressTaken = true;
}
- void SetAssigned (EmitContext ec)
+ void SetAssigned (ResolveContext ec)
{
if (HasOutModifier && ec.DoFlowAnalysis)
ec.CurrentBranching.SetAssigned (VariableInfo);
}
- bool DoResolveBase (EmitContext ec)
+ bool DoResolveBase (ResolveContext ec)
{
type = pi.ParameterType;
eclass = ExprClass.Variable;
return true;
if (IsRef) {
- Report.Error (1628, loc,
+ ec.Report.Error (1628, loc,
"Parameter `{0}' cannot be used inside `{1}' when using `ref' or `out' modifier",
Name, am.ContainerType);
}
}
if (pi.Parameter.HasAddressTaken)
- AnonymousMethodExpression.Error_AddressOfCapturedVar (this, loc);
+ AnonymousMethodExpression.Error_AddressOfCapturedVar (ec, this, loc);
if (ec.IsVariableCapturingRequired) {
AnonymousMethodStorey storey = pi.Block.CreateAnonymousMethodStorey (ec);
// Nothing to clone
}
- public override Expression CreateExpressionTree (EmitContext ec)
+ public override Expression CreateExpressionTree (ResolveContext ec)
{
HoistedVariable hv = GetHoistedVariable (ec);
if (hv != null)
// the type as it is expected, but when we generate the code, we generate
// the alternate kind of code.
//
- public override Expression DoResolve (EmitContext ec)
+ public override Expression DoResolve (ResolveContext ec)
{
if (!DoResolveBase (ec))
return null;
return this;
}
- override public Expression DoResolveLValue (EmitContext ec, Expression right_side)
+ override public Expression DoResolveLValue (ResolveContext ec, Expression right_side)
{
if (!DoResolveBase (ec))
return null;
this.arguments_resolved = arguments_resolved;
}
- public override Expression CreateExpressionTree (EmitContext ec)
+ public override Expression CreateExpressionTree (ResolveContext ec)
{
Arguments args;
if (TypeManager.DropGenericTypeArguments (type) == TypeManager.expression_type) {
args = new Arguments (1);
args.Add (new Argument (this));
- return CreateExpressionFactoryCall ("Quote", args);
+ return CreateExpressionFactoryCall (ec, "Quote", args);
}
Expression instance = mg.IsInstance ?
mg.CreateExpressionTree (ec));
if (mg.IsBase)
- MemberExpr.Error_BaseAccessInExpressionTree (loc);
+ MemberExpr.Error_BaseAccessInExpressionTree (ec, loc);
- return CreateExpressionFactoryCall ("Call", args);
+ return CreateExpressionFactoryCall (ec, "Call", args);
}
- public override Expression DoResolve (EmitContext ec)
+ public override Expression DoResolve (ResolveContext ec)
{
// Don't resolve already resolved expression
if (eclass != ExprClass.Invalid)
expr = null;
} else {
if (mg.IsBase) {
- Report.Error (1971, loc,
+ ec.Report.Error (1971, loc,
"The base call to method `{0}' cannot be dynamically dispatched. Consider casting the dynamic arguments or eliminating the base access",
mg.Name);
return null;
MemberExpr me = expr_resolved as MemberExpr;
if (me == null) {
- expr_resolved.Error_UnexpectedKind (ResolveFlags.MethodGroup, loc);
+ expr_resolved.Error_UnexpectedKind (ec, ResolveFlags.MethodGroup, loc);
return null;
}
mg = ec.LookupExtensionMethod (me.Type, me.Name, loc);
if (mg == null) {
- Report.Error (1955, loc, "The member `{0}' cannot be used as method or delegate",
+ ec.Report.Error (1955, loc, "The member `{0}' cannot be used as method or delegate",
expr_resolved.GetSignatureForError ());
return null;
}
mg.IdenticalTypeName) {
mg.InstanceExpression = null;
} else {
- MemberExpr.error176 (loc, mg.GetSignatureForError ());
+ MemberExpr.error176 (ec, loc, mg.GetSignatureForError ());
return null;
}
} else {
}
}
}
-
- if (type.IsPointer){
- if (!ec.InUnsafe){
- UnsafeError (loc);
- return null;
- }
- }
-
+
//
// Only base will allow this invocation to happen.
//
if (mg.IsBase && method.IsAbstract){
- Error_CannotCallAbstractBase (TypeManager.CSharpSignature (method));
+ Error_CannotCallAbstractBase (ec, TypeManager.CSharpSignature (method));
return null;
}
if (arguments == null && method.DeclaringType == TypeManager.object_type && method.Name == Destructor.MetadataName) {
if (mg.IsBase)
- Report.Error (250, loc, "Do not directly call your base class Finalize method. It is called automatically from your destructor");
+ ec.Report.Error (250, loc, "Do not directly call your base class Finalize method. It is called automatically from your destructor");
else
- Report.Error (245, loc, "Destructors and object.Finalize cannot be called directly. Consider calling IDisposable.Dispose if available");
+ ec.Report.Error (245, loc, "Destructors and object.Finalize cannot be called directly. Consider calling IDisposable.Dispose if available");
return null;
}
- IsSpecialMethodInvocation (method, loc);
+ IsSpecialMethodInvocation (ec, method, loc);
if (mg.InstanceExpression != null)
mg.InstanceExpression.CheckMarshalByRefAccess (ec);
return this;
}
- protected virtual MethodGroupExpr DoResolveOverload (EmitContext ec)
+ protected virtual MethodGroupExpr DoResolveOverload (ResolveContext ec)
{
return mg.OverloadResolve (ec, ref arguments, false, loc);
}
- public static bool IsSpecialMethodInvocation (MethodBase method, Location loc)
+ public static bool IsSpecialMethodInvocation (ResolveContext ec, MethodBase method, Location loc)
{
if (!TypeManager.IsSpecialMethod (method))
return false;
- Report.SymbolRelatedToPreviousError (method);
- Report.Error (571, loc, "`{0}': cannot explicitly call operator or accessor",
+ ec.Report.SymbolRelatedToPreviousError (method);
+ ec.Report.Error (571, loc, "`{0}': cannot explicitly call operator or accessor",
TypeManager.CSharpSignature (method, true));
return true;
return false;
method = TypeManager.DropGenericMethodArguments (method);
- if (method.DeclaringType.Module == RootContext.ToplevelTypes.Builder) {
+ if (TypeManager.IsBeingCompiled (method)) {
IMethodData md = TypeManager.GetMethod (method);
if (md != null)
return md.IsExcluded ();
} else {
call_op = OpCodes.Callvirt;
-#if GMCS_SOURCE
if ((instance_expr != null) && (instance_expr.Type.IsGenericParameter))
ig.Emit (OpCodes.Constrained, instance_expr.Type);
-#endif
}
if ((method.CallingConvention & CallingConventions.VarArgs) != 0) {
target.expr = expr.Clone (clonectx);
}
- public override void MutateHoistedGenericType (AnonymousMethodStorey storey)
- {
- mg.MutateHoistedGenericType (storey);
- type = storey.MutateType (type);
- if (arguments != null) {
- arguments.MutateHoistedGenericType (storey);
- }
- }
- }
-/*
- //
- // It's either a cast or delegate invocation
- //
- public class InvocationOrCast : ExpressionStatement
- {
- Expression expr;
- Expression argument;
-
- public InvocationOrCast (Expression expr, Expression argument)
- {
- this.expr = expr;
- this.argument = argument;
- this.loc = expr.Location;
- }
-
- public override Expression CreateExpressionTree (EmitContext ec)
+#if NET_4_0
+ public override SLE.Expression MakeExpression (BuilderContext ctx)
{
- throw new NotSupportedException ("ET");
+ return MakeExpression (ctx, mg.InstanceExpression, (MethodInfo) mg, arguments);
}
- public override Expression DoResolve (EmitContext ec)
+ public static SLE.Expression MakeExpression (BuilderContext ctx, Expression instance, MethodInfo mi, Arguments args)
{
- Expression e = ResolveCore (ec);
- if (e == null)
- return null;
+ var instance_expr = instance == null ? null : instance.MakeExpression (ctx);
+ SLE.Expression expr = SLE.Expression.Call (instance_expr, mi,
+ Arguments.MakeExpression (args, ctx));
- return e.Resolve (ec);
- }
-
- Expression ResolveCore (EmitContext ec)
- {
- //
- // First try to resolve it as a cast.
- //
- TypeExpr te = expr.ResolveAsBaseTerminal (ec, true);
- if (te != null) {
- return new Cast (te, argument, loc);
+ if (mi.ReturnType == typeof (void)) {
+ expr = SLE.Expression.Block (
+ expr,
+ SLE.Expression.Default (typeof (object)));
}
- //
- // This can either be a type or a delegate invocation.
- // Let's just resolve it and see what we'll get.
- //
- expr = expr.Resolve (ec, ResolveFlags.Type | ResolveFlags.VariableOrValue);
- if (expr == null)
- return null;
-
- //
- // Ok, so it's a Cast.
- //
- if (expr.eclass == ExprClass.Type || expr.eclass == ExprClass.TypeParameter) {
- return new Cast (expr, argument, loc);
- }
-
- if (expr.eclass == ExprClass.Namespace) {
- expr.Error_UnexpectedKind (null, "type", loc);
- return null;
- }
-
- //
- // It's a delegate invocation.
- //
- if (!TypeManager.IsDelegateType (expr.Type)) {
- Error (149, "Method name expected");
- return null;
- }
-
- ArrayList args = new ArrayList (1);
- args.Add (new Argument (argument, Argument.AType.Expression));
- return new DelegateInvocation (expr, args, loc);
+ return expr;
}
+#endif
- public override ExpressionStatement ResolveStatement (EmitContext ec)
+ public override void MutateHoistedGenericType (AnonymousMethodStorey storey)
{
- Expression e = ResolveCore (ec);
- if (e == null)
- return null;
-
- ExpressionStatement s = e as ExpressionStatement;
- if (s == null) {
- Error_InvalidExpressionStatement ();
- return null;
+ mg.MutateHoistedGenericType (storey);
+ type = storey.MutateType (type);
+ if (arguments != null) {
+ arguments.MutateHoistedGenericType (storey);
}
-
- return s.ResolveStatement (ec);
- }
-
- public override void Emit (EmitContext ec)
- {
- throw new Exception ("Cannot happen");
- }
-
- public override void EmitStatement (EmitContext ec)
- {
- throw new Exception ("Cannot happen");
- }
-
- protected override void CloneTo (CloneContext clonectx, Expression t)
- {
- InvocationOrCast target = (InvocationOrCast) t;
-
- target.expr = expr.Clone (clonectx);
- target.argument = argument.Clone (clonectx);
}
}
-*/
/// <summary>
/// Implements the new expression
// [ComImport, CoClass] attributes and must be treated
// specially
//
- public Expression CheckComImport (EmitContext ec)
+ public Expression CheckComImport (ResolveContext ec)
{
if (!type.IsInterface)
return null;
return cast.Resolve (ec);
}
- public override Expression CreateExpressionTree (EmitContext ec)
+ public override Expression CreateExpressionTree (ResolveContext ec)
{
Arguments args;
if (method == null) {
method.CreateExpressionTree (ec));
}
- return CreateExpressionFactoryCall ("New", args);
+ return CreateExpressionFactoryCall (ec, "New", args);
}
- public override Expression DoResolve (EmitContext ec)
+ public override Expression DoResolve (ResolveContext ec)
{
//
// The New DoResolve might be called twice when initializing field
type = texpr.Type;
if (type.IsPointer) {
- Report.Error (1919, loc, "Unsafe type `{0}' cannot be used in an object creation expression",
+ ec.Report.Error (1919, loc, "Unsafe type `{0}' cannot be used in an object creation expression",
TypeManager.CSharpName (type));
return null;
}
GenericConstraints gc = TypeManager.GetTypeParameterConstraints (type);
if ((gc == null) || (!gc.HasConstructorConstraint && !gc.IsValueType)) {
- Error (304, String.Format (
- "Cannot create an instance of the " +
- "variable type '{0}' because it " +
- "doesn't have the new() constraint",
- type));
+ ec.Report.Error (304, loc,
+ "Cannot create an instance of the variable type '{0}' because it doesn't have the new() constraint",
+ TypeManager.CSharpName (type));
return null;
}
if ((Arguments != null) && (Arguments.Count != 0)) {
- Error (417, String.Format (
- "`{0}': cannot provide arguments " +
- "when creating an instance of a " +
- "variable type.", type));
+ ec.Report.Error (417, loc,
+ "`{0}': cannot provide arguments when creating an instance of a variable type",
+ TypeManager.CSharpName (type));
return null;
}
if (TypeManager.activator_create_instance == null) {
- Type activator_type = TypeManager.CoreLookupType ("System", "Activator", Kind.Class, true);
+ Type activator_type = TypeManager.CoreLookupType (ec.Compiler, "System", "Activator", Kind.Class, true);
if (activator_type != null) {
TypeManager.activator_create_instance = TypeManager.GetPredefinedMethod (
activator_type, "CreateInstance", loc, Type.EmptyTypes);
}
if (type.IsAbstract && type.IsSealed) {
- Report.SymbolRelatedToPreviousError (type);
- Report.Error (712, loc, "Cannot create an instance of the static class `{0}'", TypeManager.CSharpName (type));
+ ec.Report.SymbolRelatedToPreviousError (type);
+ ec.Report.Error (712, loc, "Cannot create an instance of the static class `{0}'", TypeManager.CSharpName (type));
return null;
}
return RequestedType;
}
- Report.SymbolRelatedToPreviousError (type);
- Report.Error (144, loc, "Cannot create an instance of the abstract class or interface `{0}'", TypeManager.CSharpName (type));
+ ec.Report.SymbolRelatedToPreviousError (type);
+ ec.Report.Error (144, loc, "Cannot create an instance of the abstract class or interface `{0}'", TypeManager.CSharpName (type));
return null;
}
method = ml as MethodGroupExpr;
if (method == null) {
- ml.Error_UnexpectedKind (ec.DeclContainer, "method group", loc);
+ ml.Error_UnexpectedKind (ec, ResolveFlags.MethodGroup, loc);
return null;
}
bool DoEmitTypeParameter (EmitContext ec)
{
-#if GMCS_SOURCE
ILGenerator ig = ec.ig;
-// IMemoryLocation ml;
MethodInfo ci = TypeManager.activator_create_instance.MakeGenericMethod (
new Type [] { type });
ig.Emit (OpCodes.Call, ci);
ig.MarkLabel (label_end);
return true;
-#else
- throw new InternalErrorException ();
-#endif
}
//
ConstructorInfo ci = (ConstructorInfo) method;
#if MS_COMPATIBLE
- if (TypeManager.IsGenericType (type))
+ if (TypeManager.IsGenericType (type) && type.IsGenericTypeDefinition)
ci = TypeBuilder.GetConstructor (type, ci);
#endif
int num_arguments = 0;
protected int dimensions;
protected readonly string rank;
+ Expression first_emit;
+ LocalTemporary first_emit_temp;
- protected ArrayList array_data;
+ protected List<Expression> array_data;
IDictionary bounds;
expect_initializers = true;
}
- public static void Error_IncorrectArrayInitializer (Location loc)
- {
- Report.Error (178, loc, "Invalid rank specifier: expected `,' or `]'");
- }
-
- protected override void Error_NegativeArrayIndex (Location loc)
+ protected override void Error_NegativeArrayIndex (ResolveContext ec, Location loc)
{
- Report.Error (248, loc, "Cannot create an array with a negative size");
+ ec.Report.Error (248, loc, "Cannot create an array with a negative size");
}
- bool CheckIndices (EmitContext ec, ArrayList probe, int idx, bool specified_dims, int child_bounds)
+ bool CheckIndices (ResolveContext ec, ArrayList probe, int idx, bool specified_dims, int child_bounds)
{
if (specified_dims) {
Expression a = (Expression) arguments [idx];
}
if (c == null) {
- Report.Error (150, a.Location, "A constant value is expected");
+ ec.Report.Error (150, a.Location, "A constant value is expected");
return false;
}
int value = (int) c.GetValue ();
if (value != probe.Count) {
- Report.Error (847, loc, "An array initializer of length `{0}' was expected", value);
+ ec.Report.Error (847, loc, "An array initializer of length `{0}' was expected", value);
return false;
}
if (o is ArrayList) {
ArrayList sub_probe = o as ArrayList;
if (idx + 1 >= dimensions){
- Error (623, "Array initializers can only be used in a variable or field initializer. Try using a new expression instead");
+ ec.Report.Error (623, loc, "Array initializers can only be used in a variable or field initializer. Try using a new expression instead");
return false;
}
if (!ret)
return false;
} else if (child_bounds > 1) {
- Report.Error (846, ((Expression) o).Location, "A nested array initializer was expected");
+ ec.Report.Error (846, ((Expression) o).Location, "A nested array initializer was expected");
} else {
Expression element = ResolveArrayElement (ec, (Expression) o);
if (element == null)
return true;
}
- public override Expression CreateExpressionTree (EmitContext ec)
+ public override Expression CreateExpressionTree (ResolveContext ec)
{
Arguments args;
if (array_data == null) {
args = new Arguments (arguments.Count + 1);
args.Add (new Argument (new TypeOf (new TypeExpression (array_element_type, loc), loc)));
- foreach (Expression a in arguments) {
- if (arguments.Count == 1) {
- Constant c = a as Constant;
- if (c.IsDefaultValue)
- return CreateExpressionFactoryCall ("NewArrayInit", args);
- }
+ foreach (Expression a in arguments)
args.Add (new Argument (a.CreateExpressionTree (ec)));
- }
- return CreateExpressionFactoryCall ("NewArrayBounds", args);
+ return CreateExpressionFactoryCall (ec, "NewArrayBounds", args);
}
if (dimensions > 1) {
- Report.Error (838, loc, "An expression tree cannot contain a multidimensional array initializer");
+ ec.Report.Error (838, loc, "An expression tree cannot contain a multidimensional array initializer");
return null;
}
args.Add (new Argument (new TypeOf (new TypeExpression (array_element_type, loc), loc)));
if (array_data != null) {
for (int i = 0; i < array_data.Count; ++i) {
- Expression e = (Expression) array_data [i];
+ Expression e = array_data [i];
if (e == null)
e = Convert.ImplicitConversion (ec, (Expression) initializers [i], array_element_type, loc);
}
}
- return CreateExpressionFactoryCall ("NewArrayInit", args);
+ return CreateExpressionFactoryCall (ec, "NewArrayInit", args);
}
public void UpdateIndices ()
return;
}
}
-
}
- Expression first_emit;
- LocalTemporary first_emit_temp;
-
- protected virtual Expression ResolveArrayElement (EmitContext ec, Expression element)
+ protected virtual Expression ResolveArrayElement (ResolveContext ec, Expression element)
{
element = element.Resolve (ec);
if (element == null)
ec, element, array_element_type, loc);
}
- protected bool ResolveInitializers (EmitContext ec)
+ protected bool ResolveInitializers (ResolveContext ec)
{
if (initializers == null) {
return !expect_initializers;
// We use this to store all the date values in the order in which we
// will need to store them in the byte blob later
//
- array_data = new ArrayList ();
+ array_data = new List<Expression> ();
bounds = new System.Collections.Specialized.HybridDictionary ();
if (arguments != null)
//
// Resolved the type of the array
//
- bool ResolveArrayType (EmitContext ec)
+ bool ResolveArrayType (ResolveContext ec)
{
if (requested_base_type == null) {
- Report.Error (622, loc, "Can only use array initializer expressions to assign to array types. Try using a new expression instead");
+ ec.Report.Error (622, loc, "Can only use array initializer expressions to assign to array types. Try using a new expression instead");
return false;
}
if (requested_base_type is VarExpr) {
- Report.Error (820, loc, "An implicitly typed local variable declarator cannot use an array initializer");
+ ec.Report.Error (820, loc, "An implicitly typed local variable declarator cannot use an array initializer");
return false;
}
return true;
}
- public override Expression DoResolve (EmitContext ec)
+ public override Expression DoResolve (ResolveContext ec)
{
if (type != null)
return this;
arg_types);
if (mi == null) {
- Report.Error (-6, "New invocation: Can not find a constructor for " +
+ RootContext.ToplevelTypes.Compiler.Report.Error (-6, "New invocation: Can not find a constructor for " +
"this argument list");
return null;
}
byte [] element;
int count = array_data.Count;
- if (TypeManager.IsEnumType (array_element_type))
- array_element_type = TypeManager.GetEnumUnderlyingType (array_element_type);
-
- factor = GetTypeSize (array_element_type);
+ Type element_type = array_element_type;
+ if (TypeManager.IsEnumType (element_type))
+ element_type = TypeManager.GetEnumUnderlyingType (element_type);
+
+ factor = GetTypeSize (element_type);
if (factor == 0)
- throw new Exception ("unrecognized type in MakeByteBlob: " + array_element_type);
+ throw new Exception ("unrecognized type in MakeByteBlob: " + element_type);
data = new byte [(count * factor + 3) & ~3];
int idx = 0;
continue;
}
- if (array_element_type == TypeManager.int64_type){
+ if (element_type == TypeManager.int64_type){
if (!(v is Expression)){
long val = (long) v;
val = (val >> 8);
}
}
- } else if (array_element_type == TypeManager.uint64_type){
+ } else if (element_type == TypeManager.uint64_type){
if (!(v is Expression)){
ulong val = (ulong) v;
val = (val >> 8);
}
}
- } else if (array_element_type == TypeManager.float_type) {
+ } else if (element_type == TypeManager.float_type) {
if (!(v is Expression)){
element = BitConverter.GetBytes ((float) v);
if (!BitConverter.IsLittleEndian)
System.Array.Reverse (data, idx, 4);
}
- } else if (array_element_type == TypeManager.double_type) {
+ } else if (element_type == TypeManager.double_type) {
if (!(v is Expression)){
element = BitConverter.GetBytes ((double) v);
if (!BitConverter.IsLittleEndian)
System.Array.Reverse (data, idx, 8);
}
- } else if (array_element_type == TypeManager.char_type){
+ } else if (element_type == TypeManager.char_type){
if (!(v is Expression)){
int val = (int) ((char) v);
data [idx] = (byte) (val & 0xff);
data [idx+1] = (byte) (val >> 8);
}
- } else if (array_element_type == TypeManager.short_type){
+ } else if (element_type == TypeManager.short_type){
if (!(v is Expression)){
int val = (int) ((short) v);
data [idx] = (byte) (val & 0xff);
data [idx+1] = (byte) (val >> 8);
}
- } else if (array_element_type == TypeManager.ushort_type){
+ } else if (element_type == TypeManager.ushort_type){
if (!(v is Expression)){
int val = (int) ((ushort) v);
data [idx] = (byte) (val & 0xff);
data [idx+1] = (byte) (val >> 8);
}
- } else if (array_element_type == TypeManager.int32_type) {
+ } else if (element_type == TypeManager.int32_type) {
if (!(v is Expression)){
int val = (int) v;
data [idx+2] = (byte) ((val >> 16) & 0xff);
data [idx+3] = (byte) (val >> 24);
}
- } else if (array_element_type == TypeManager.uint32_type) {
+ } else if (element_type == TypeManager.uint32_type) {
if (!(v is Expression)){
uint val = (uint) v;
data [idx+2] = (byte) ((val >> 16) & 0xff);
data [idx+3] = (byte) (val >> 24);
}
- } else if (array_element_type == TypeManager.sbyte_type) {
+ } else if (element_type == TypeManager.sbyte_type) {
if (!(v is Expression)){
sbyte val = (sbyte) v;
data [idx] = (byte) val;
}
- } else if (array_element_type == TypeManager.byte_type) {
+ } else if (element_type == TypeManager.byte_type) {
if (!(v is Expression)){
byte val = (byte) v;
data [idx] = (byte) val;
}
- } else if (array_element_type == TypeManager.bool_type) {
+ } else if (element_type == TypeManager.bool_type) {
if (!(v is Expression)){
bool val = (bool) v;
data [idx] = (byte) (val ? 1 : 0);
}
- } else if (array_element_type == TypeManager.decimal_type){
+ } else if (element_type == TypeManager.decimal_type){
if (!(v is Expression)){
int [] bits = Decimal.GetBits ((decimal) v);
int p = idx;
data [p++] = (byte) (nbits [j] >> 24);
}
}
- } else
- throw new Exception ("Unrecognized type in MakeByteBlob: " + array_element_type);
+ } else {
+ throw new Exception ("Unrecognized type in MakeByteBlob: " + element_type);
+ }
- idx += factor;
+ idx += factor;
}
return data;
}
+#if NET_4_0
+ public override SLE.Expression MakeExpression (BuilderContext ctx)
+ {
+ var initializers = new SLE.Expression [array_data.Count];
+ for (var i = 0; i < initializers.Length; i++) {
+ if (array_data [i] == null)
+ initializers [i] = SLE.Expression.Default (array_element_type);
+ else
+ initializers [i] = array_data [i].MakeExpression (ctx);
+ }
+
+ return SLE.Expression.NewArrayInit (array_element_type, initializers);
+ }
+#endif
+
public override void MutateHoistedGenericType (AnonymousMethodStorey storey)
{
array_element_type = storey.MutateType (array_element_type);
e.Emit (ec);
if (arguments.Count == 1)
- ig.Emit (OpCodes.Newarr, array_element_type);
+ ig.Emit (OpCodes.Newarr, TypeManager.TypeToReflectionType (array_element_type));
else {
ig.Emit (OpCodes.Newobj, GetArrayMethod (arguments.Count));
}
// the static initializer will initialize at least 25% of array values.
// NOTE: const_initializers_count does not contain default constant values.
if (const_initializers_count >= 4 && const_initializers_count * 4 > (array_data.Count) &&
- TypeManager.IsPrimitiveType (array_element_type)) {
+ (TypeManager.IsPrimitiveType (array_element_type) || TypeManager.IsEnumType (array_element_type))) {
EmitStaticInitializers (ec);
if (!only_constant_initializers)
first_emit_temp.Release (ec);
}
- public override bool GetAttributableValue (EmitContext ec, Type value_type, out object value)
+ public override bool GetAttributableValue (ResolveContext ec, Type value_type, out object value)
{
if (arguments.Count != 1) {
- // Report.Error (-211, Location, "attribute can not encode multi-dimensional arrays");
+ // ec.Report.Error (-211, Location, "attribute can not encode multi-dimensional arrays");
return base.GetAttributableValue (ec, null, out value);
}
if (array_data == null) {
- Constant c = (Constant) arguments [0];
- if (c.IsDefaultValue) {
+ Expression arg = (Expression) arguments[0];
+ object arg_value;
+ if (arg.GetAttributableValue (ec, arg.Type, out arg_value) && arg_value is int && (int)arg_value == 0) {
value = Array.CreateInstance (array_element_type, 0);
return true;
}
- // Report.Error (-212, Location, "array should be initialized when passing it to an attribute");
+
+ // ec.Report.Error (-212, Location, "array should be initialized when passing it to an attribute");
return base.GetAttributableValue (ec, null, out value);
}
{
public ImplicitlyTypedArrayCreation (string rank, ArrayList initializers, Location loc)
: base (null, rank, initializers, loc)
- {
- if (RootContext.Version <= LanguageVersion.ISO_2)
- Report.FeatureIsNotAvailable (loc, "implicitly typed arrays");
-
+ {
if (rank.Length > 2) {
while (rank [++dimensions] == ',');
} else {
}
}
- public override Expression DoResolve (EmitContext ec)
+ public override Expression DoResolve (ResolveContext ec)
{
if (type != null)
return this;
if (array_element_type == null || array_element_type == TypeManager.null_type ||
array_element_type == TypeManager.void_type || array_element_type == InternalType.AnonymousMethod ||
+ array_element_type == InternalType.MethodGroup ||
arguments.Count != dimensions) {
- Error_NoBestType ();
+ Error_NoBestType (ec);
return null;
}
return this;
}
- void Error_NoBestType ()
+ void Error_NoBestType (ResolveContext ec)
{
- Report.Error (826, loc,
+ ec.Report.Error (826, loc,
"The type of an implicitly typed array cannot be inferred from the initializer. Try specifying array type explicitly");
}
//
// Converts static initializer only
//
- void UnifyInitializerElement (EmitContext ec)
+ void UnifyInitializerElement (ResolveContext ec)
{
for (int i = 0; i < array_data.Count; ++i) {
Expression e = (Expression)array_data[i];
}
}
- protected override Expression ResolveArrayElement (EmitContext ec, Expression element)
+ protected override Expression ResolveArrayElement (ResolveContext ec, Expression element)
{
element = element.Resolve (ec);
if (element == null)
return element;
}
- Error_NoBestType ();
+ Error_NoBestType (ec);
return null;
}
}
this.type = type;
}
- public override Expression DoResolve (EmitContext ec)
+ public override Expression DoResolve (ResolveContext ec)
{
eclass = ExprClass.Variable;
if (type == null)
type = ec.CurrentType;
+
+ is_struct = type.IsValueType;
return this;
}
- public override HoistedVariable GetHoistedVariable (EmitContext ec)
+ public override HoistedVariable GetHoistedVariable (AnonymousExpression ae)
{
return null;
}
Block block;
VariableInfo variable_info;
- bool is_struct;
+ protected bool is_struct;
public This (Block block, Location loc)
{
get { return false; }
}
- public override HoistedVariable GetHoistedVariable (EmitContext ec)
+ public override HoistedVariable GetHoistedVariable (AnonymousExpression ae)
{
- // Is null when probing IsHoisted
- if (ec == null)
+ if (ae == null)
return null;
- if (ec.CurrentAnonymousMethod == null)
- return null;
-
- AnonymousMethodStorey storey = ec.CurrentAnonymousMethod.Storey;
+ AnonymousMethodStorey storey = ae.Storey;
while (storey != null) {
AnonymousMethodStorey temp = storey.Parent as AnonymousMethodStorey;
if (temp == null)
get { return ThisVariable.Instance; }
}
- public static bool IsThisAvailable (EmitContext ec)
+ public static bool IsThisAvailable (ResolveContext ec)
{
- if (ec.IsStatic || ec.IsInFieldInitializer)
+ if (ec.IsStatic || ec.HasAny (ResolveContext.Options.FieldInitializerScope | ResolveContext.Options.BaseInitializer | ResolveContext.Options.ConstantScope))
return false;
if (ec.CurrentAnonymousMethod == null)
return true;
}
- public bool ResolveBase (EmitContext ec)
+ public bool ResolveBase (ResolveContext ec)
{
if (eclass != ExprClass.Invalid)
return true;
type = ec.CurrentType;
if (!IsThisAvailable (ec)) {
- if (ec.IsStatic) {
- Error (26, "Keyword `this' is not valid in a static property, static method, or static field initializer");
- } else {
- Report.Error (1673, loc,
+ if (ec.IsStatic && !ec.HasSet (ResolveContext.Options.ConstantScope)) {
+ ec.Report.Error (26, loc, "Keyword `this' is not valid in a static property, static method, or static field initializer");
+ } else if (ec.CurrentAnonymousMethod != null) {
+ ec.Report.Error (1673, loc,
"Anonymous methods inside structs cannot access instance members of `this'. " +
"Consider copying `this' to a local variable outside the anonymous method and using the local instead");
+ } else {
+ ec.Report.Error (27, loc, "Keyword `this' is not available in the current context");
}
}
//
// Called from Invocation to check if the invocation is correct
//
- public override void CheckMarshalByRefAccess (EmitContext ec)
+ public override void CheckMarshalByRefAccess (ResolveContext ec)
{
if ((variable_info != null) && !(TypeManager.IsStruct (type) && ec.OmitStructFlowAnalysis) &&
!variable_info.IsAssigned (ec)) {
- Error (188, "The `this' object cannot be used before all of its " +
- "fields are assigned to");
+ ec.Report.Error (188, loc,
+ "The `this' object cannot be used before all of its fields are assigned to");
variable_info.SetAssigned (ec);
}
}
- public override Expression CreateExpressionTree (EmitContext ec)
+ public override Expression CreateExpressionTree (ResolveContext ec)
{
Arguments args = new Arguments (1);
args.Add (new Argument (this));
// Use typeless constant for ldarg.0 to save some
// space and avoid problems with anonymous stories
- return CreateExpressionFactoryCall ("Constant", args);
+ return CreateExpressionFactoryCall (ec, "Constant", args);
}
- public override Expression DoResolve (EmitContext ec)
+ public override Expression DoResolve (ResolveContext ec)
{
- if (!ResolveBase (ec))
- return null;
-
-
- if (ec.IsInFieldInitializer) {
- Error (27, "Keyword `this' is not available in the current context");
- return null;
- }
-
+ ResolveBase (ec);
return this;
}
- override public Expression DoResolveLValue (EmitContext ec, Expression right_side)
+ override public Expression DoResolveLValue (ResolveContext ec, Expression right_side)
{
if (!ResolveBase (ec))
return null;
if (ec.CurrentType.IsClass){
if (right_side == EmptyExpression.UnaryAddress)
- Report.Error (459, loc, "Cannot take the address of `this' because it is read-only");
+ ec.Report.Error (459, loc, "Cannot take the address of `this' because it is read-only");
else if (right_side == EmptyExpression.OutAccess)
- Report.Error (1605, loc, "Cannot pass `this' as a ref or out argument because it is read-only");
+ ec.Report.Error (1605, loc, "Cannot pass `this' as a ref or out argument because it is read-only");
else
- Report.Error (1604, loc, "Cannot assign to `this' because it is read-only");
+ ec.Report.Error (1604, loc, "Cannot assign to `this' because it is read-only");
}
return this;
this.loc = loc;
}
- public override Expression CreateExpressionTree (EmitContext ec)
+ public override Expression CreateExpressionTree (ResolveContext ec)
{
throw new NotSupportedException ("ET");
}
- public override Expression DoResolve (EmitContext ec)
+ public override Expression DoResolve (ResolveContext ec)
{
eclass = ExprClass.Variable;
type = TypeManager.runtime_argument_handle_type;
- if (ec.IsInFieldInitializer || !ec.CurrentBlock.Toplevel.Parameters.HasArglist)
- {
- Error (190, "The __arglist construct is valid only within " +
- "a variable argument method");
- return this;
+ if (ec.HasSet (ResolveContext.Options.FieldInitializerScope) || !ec.CurrentBlock.Toplevel.Parameters.HasArglist) {
+ ec.Report.Error (190, loc,
+ "The __arglist construct is valid only within a variable argument method");
}
return this;
}
}
- public override Expression CreateExpressionTree (EmitContext ec)
+ public override Expression CreateExpressionTree (ResolveContext ec)
{
- Report.Error (1952, loc, "An expression tree cannot contain a method with variable arguments");
+ ec.Report.Error (1952, loc, "An expression tree cannot contain a method with variable arguments");
return null;
}
- public override Expression DoResolve (EmitContext ec)
+ public override Expression DoResolve (ResolveContext ec)
{
eclass = ExprClass.Variable;
type = InternalType.Arglist;
loc = l;
}
- public override Expression CreateExpressionTree (EmitContext ec)
+ public override Expression CreateExpressionTree (ResolveContext ec)
{
Arguments args = new Arguments (2);
args.Add (new Argument (this));
args.Add (new Argument (new TypeOf (new TypeExpression (type, loc), loc)));
- return CreateExpressionFactoryCall ("Constant", args);
+ return CreateExpressionFactoryCall (ec, "Constant", args);
}
- public override Expression DoResolve (EmitContext ec)
+ public override Expression DoResolve (ResolveContext ec)
{
if (eclass != ExprClass.Invalid)
return this;
typearg = texpr.Type;
if (typearg == TypeManager.void_type) {
- Report.Error (673, loc, "System.Void cannot be used from C#. Use typeof (void) to get the void type object");
- } else if (typearg.IsPointer && !ec.InUnsafe){
- UnsafeError (loc);
+ ec.Report.Error (673, loc, "System.Void cannot be used from C#. Use typeof (void) to get the void type object");
+ } else if (typearg.IsPointer && !ec.IsUnsafe){
+ UnsafeError (ec, loc);
} else if (texpr is DynamicTypeExpr) {
- Report.Error (1962, QueriedType.Location,
+ ec.Report.Error (1962, QueriedType.Location,
"The typeof operator cannot be used on the dynamic type");
}
ec.ig.Emit (OpCodes.Call, TypeManager.system_type_get_type_from_handle);
}
- public override bool GetAttributableValue (EmitContext ec, Type value_type, out object value)
+ public override bool GetAttributableValue (ResolveContext ec, Type value_type, out object value)
{
if (TypeManager.ContainsGenericParameters (typearg) &&
!TypeManager.IsGenericTypeDefinition (typearg)) {
- Report.SymbolRelatedToPreviousError (typearg);
- Report.Error (416, loc, "`{0}': an attribute argument cannot use type parameters",
+ ec.Report.SymbolRelatedToPreviousError (typearg);
+ ec.Report.Error (416, loc, "`{0}': an attribute argument cannot use type parameters",
TypeManager.CSharpName (typearg));
value = null;
return false;
loc = l;
}
- public override Expression DoResolve (EmitContext ec)
+ public override Expression DoResolve (ResolveContext ec)
{
type = TypeManager.type_type;
typearg = TypeManager.void_type;
{
}
- public override Expression DoResolve (EmitContext ec)
+ public override Expression DoResolve (ResolveContext ec)
{
if (member is MethodInfo) {
type = TypeManager.methodinfo_type;
if (type == null)
- type = TypeManager.methodinfo_type = TypeManager.CoreLookupType ("System.Reflection", "MethodInfo", Kind.Class, true);
+ type = TypeManager.methodinfo_type = TypeManager.CoreLookupType (ec.Compiler, "System.Reflection", "MethodInfo", Kind.Class, true);
} else {
type = TypeManager.ctorinfo_type;
if (type == null)
- type = TypeManager.ctorinfo_type = TypeManager.CoreLookupType ("System.Reflection", "ConstructorInfo", Kind.Class, true);
+ type = TypeManager.ctorinfo_type = TypeManager.CoreLookupType (ec.Compiler, "System.Reflection", "ConstructorInfo", Kind.Class, true);
}
return base.DoResolve (ec);
this.loc = loc;
}
- public override Expression CreateExpressionTree (EmitContext ec)
+ public override Expression CreateExpressionTree (ResolveContext ec)
{
Arguments args = new Arguments (2);
args.Add (new Argument (this));
args.Add (new Argument (new TypeOf (new TypeExpression (type, loc), loc)));
- return CreateExpressionFactoryCall ("Constant", args);
+ return CreateExpressionFactoryCall (ec, "Constant", args);
}
- public override Expression DoResolve (EmitContext ec)
+ public override Expression DoResolve (ResolveContext ec)
{
bool is_generic = TypeManager.IsGenericType (member.DeclaringType);
MethodInfo mi = is_generic ? TypeFromHandleGeneric : TypeFromHandle;
if (mi == null) {
- Type t = TypeManager.CoreLookupType ("System.Reflection", TypeName, Kind.Class, true);
- Type handle_type = TypeManager.CoreLookupType ("System", RuntimeHandleName, Kind.Class, true);
+ Type t = TypeManager.CoreLookupType (ec.Compiler, "System.Reflection", TypeName, Kind.Class, true);
+ Type handle_type = TypeManager.CoreLookupType (ec.Compiler, "System", RuntimeHandleName, Kind.Class, true);
if (t == null || handle_type == null)
return null;
{
}
- public override Expression DoResolve (EmitContext ec)
+ public override Expression DoResolve (ResolveContext ec)
{
if (TypeManager.fieldinfo_type == null)
- TypeManager.fieldinfo_type = TypeManager.CoreLookupType ("System.Reflection", TypeName, Kind.Class, true);
+ TypeManager.fieldinfo_type = TypeManager.CoreLookupType (ec.Compiler, "System.Reflection", TypeName, Kind.Class, true);
type = TypeManager.fieldinfo_type;
return base.DoResolve (ec);
loc = l;
}
- public override Expression CreateExpressionTree (EmitContext ec)
+ public override Expression CreateExpressionTree (ResolveContext ec)
{
- Error_PointerInsideExpressionTree ();
+ Error_PointerInsideExpressionTree (ec);
return null;
}
- public override Expression DoResolve (EmitContext ec)
+ public override Expression DoResolve (ResolveContext ec)
{
TypeExpr texpr = QueriedType.ResolveAsTypeTerminal (ec, false);
if (texpr == null)
return null;
}
- if (!ec.InUnsafe) {
- Report.Error (233, loc,
+ if (!ec.IsUnsafe) {
+ ec.Report.Error (233, loc,
"`{0}' does not have a predefined size, therefore sizeof can only be used in an unsafe context (consider using System.Runtime.InteropServices.Marshal.SizeOf)",
TypeManager.CSharpName (type_queried));
}
public override void Emit (EmitContext ec)
{
- int size = GetTypeSize (type_queried);
-
- if (size == 0)
- ec.ig.Emit (OpCodes.Sizeof, type_queried);
- else
- IntConstant.EmitInt (ec.ig, size);
+ ec.ig.Emit (OpCodes.Sizeof, type_queried);
}
protected override void CloneTo (CloneContext clonectx, Expression t)
this.alias = alias;
}
- public override FullNamedExpression ResolveAsTypeStep (IResolveContext ec, bool silent)
+ public override FullNamedExpression ResolveAsTypeStep (IMemberContext ec, bool silent)
{
if (alias == GlobalAlias) {
expr = GlobalRootNamespace.Instance;
return base.ResolveAsTypeStep (ec, silent);
}
- int errors = Report.Errors;
- // TODO: Implement ec.Namespace
-
- expr = ec.DeclContainer.NamespaceEntry.LookupAlias (alias);
+ int errors = ec.Compiler.Report.Errors;
+ expr = ec.LookupNamespaceAlias (alias);
if (expr == null) {
- if (errors == Report.Errors)
- Report.Error (432, loc, "Alias `{0}' not found", alias);
+ if (errors == ec.Compiler.Report.Errors)
+ ec.Compiler.Report.Error (432, loc, "Alias `{0}' not found", alias);
return null;
}
if (expr.eclass == ExprClass.Type) {
if (!silent) {
- Report.Error (431, loc,
+ ec.Compiler.Report.Error (431, loc,
"Alias `{0}' cannot be used with '::' since it denotes a type. Consider replacing '::' with '.'", alias);
}
return null;
return fne;
}
- public override Expression DoResolve (EmitContext ec)
+ public override Expression DoResolve (ResolveContext ec)
{
return ResolveAsTypeStep (ec, false);
}
- protected override void Error_IdentifierNotFound (IResolveContext rc, FullNamedExpression expr_type, string identifier)
+ protected override void Error_IdentifierNotFound (IMemberContext rc, FullNamedExpression expr_type, string identifier)
{
- Report.Error (687, loc,
+ rc.Compiler.Report.Error (687, loc,
"A namespace alias qualifier `{0}' did not resolve to a namespace or a type",
GetSignatureForError ());
}
this.expr = expr;
}
- Expression DoResolve (EmitContext ec, Expression right_side)
+ Expression DoResolve (ResolveContext ec, Expression right_side)
{
if (type != null)
throw new Exception ();
Namespace ns = expr_resolved as Namespace;
if (ns != null) {
- FullNamedExpression retval = ns.Lookup (LookupIdentifier, loc);
+ FullNamedExpression retval = ns.Lookup (ec.Compiler, LookupIdentifier, loc);
if (retval == null)
- ns.Error_NamespaceDoesNotExist (loc, LookupIdentifier);
+ ns.Error_NamespaceDoesNotExist (loc, LookupIdentifier, ec.Report);
else if (targs != null)
retval = new GenericTypeExpr (retval.Type, targs, loc).ResolveAsTypeStep (ec, false);
if (expr_type.IsPointer || expr_type == TypeManager.void_type ||
expr_type == TypeManager.null_type || expr_type == InternalType.AnonymousMethod) {
- Unary.Error_OperatorCannotBeApplied (loc, ".", expr_type);
+ Unary.Error_OperatorCannotBeApplied (ec, loc, ".", expr_type);
return null;
}
Constant c = expr_resolved as Constant;
if (c != null && c.GetValue () == null) {
- Report.Warning (1720, 1, loc, "Expression will always cause a `{0}'",
+ ec.Report.Warning (1720, 1, loc, "Expression will always cause a `{0}'",
"System.NullReferenceException");
}
}
Expression member_lookup;
- member_lookup = MemberLookup (
+ member_lookup = MemberLookup (ec.Compiler,
ec.CurrentType, expr_type, expr_type, Name, loc);
if (member_lookup == null && targs != null) {
- member_lookup = MemberLookup (
+ member_lookup = MemberLookup (ec.Compiler,
ec.CurrentType, expr_type, expr_type, LookupIdentifier, loc);
}
ex_method_lookup.ExtensionExpression = expr_resolved;
if (targs != null) {
- ex_method_lookup.SetTypeArguments (targs);
+ ex_method_lookup.SetTypeArguments (ec, targs);
}
return ex_method_lookup.DoResolve (ec);
}
expr = expr_resolved;
- member_lookup = Error_MemberLookupFailed (
+ member_lookup = Error_MemberLookupFailed (ec,
ec.CurrentType, expr_type, expr_type, Name, null,
AllMemberTypes, AllBindingFlags);
if (member_lookup == null)
if (texpr != null) {
if (!(expr_resolved is TypeExpr) &&
(original == null || !original.IdenticalNameAndTypeName (ec, expr_resolved, loc))) {
- Report.Error (572, loc, "`{0}': cannot reference a type through an expression; try `{1}' instead",
+ ec.Report.Error (572, loc, "`{0}': cannot reference a type through an expression; try `{1}' instead",
Name, member_lookup.GetSignatureForError ());
return null;
}
- if (!texpr.CheckAccessLevel (ec.DeclContainer)) {
- Report.SymbolRelatedToPreviousError (member_lookup.Type);
- ErrorIsInaccesible (loc, TypeManager.CSharpName (member_lookup.Type));
+ if (!texpr.CheckAccessLevel (ec.MemberContext)) {
+ ec.Report.SymbolRelatedToPreviousError (member_lookup.Type);
+ ErrorIsInaccesible (loc, TypeManager.CSharpName (member_lookup.Type), ec.Report);
return null;
}
//
// See gtest-172-lib.cs and gtest-172.cs for an example.
//
- ct = new GenericTypeExpr (
- member_lookup.Type, ct.TypeArguments, loc);
+
+ TypeArguments nested_targs;
+ if (HasTypeArguments) {
+ nested_targs = ct.TypeArguments.Clone ();
+ nested_targs.Add (targs);
+ } else {
+ nested_targs = ct.TypeArguments;
+ }
+
+ ct = new GenericTypeExpr (member_lookup.Type, nested_targs, loc);
return ct.ResolveAsTypeStep (ec, false);
}
return null;
if (targs != null) {
- me.SetTypeArguments (targs);
+ me.SetTypeArguments (ec, targs);
}
if (original != null && !TypeManager.IsValueType (expr_type)) {
return me.DoResolve (ec);
}
- public override Expression DoResolve (EmitContext ec)
+ public override Expression DoResolve (ResolveContext ec)
{
return DoResolve (ec, null);
}
- public override Expression DoResolveLValue (EmitContext ec, Expression right_side)
+ public override Expression DoResolveLValue (ResolveContext ec, Expression right_side)
{
return DoResolve (ec, right_side);
}
- public override FullNamedExpression ResolveAsTypeStep (IResolveContext ec, bool silent)
+ public override FullNamedExpression ResolveAsTypeStep (IMemberContext ec, bool silent)
{
return ResolveNamespaceOrType (ec, silent);
}
- public FullNamedExpression ResolveNamespaceOrType (IResolveContext rc, bool silent)
+ public FullNamedExpression ResolveNamespaceOrType (IMemberContext rc, bool silent)
{
FullNamedExpression expr_resolved = expr.ResolveAsTypeStep (rc, silent);
Namespace ns = expr_resolved as Namespace;
if (ns != null) {
- FullNamedExpression retval = ns.Lookup (LookupIdentifier, loc);
+ FullNamedExpression retval = ns.Lookup (rc.Compiler, LookupIdentifier, loc);
if (retval == null && !silent)
- ns.Error_NamespaceDoesNotExist (loc, LookupIdentifier);
+ ns.Error_NamespaceDoesNotExist (loc, LookupIdentifier, rc.Compiler.Report);
else if (targs != null)
retval = new GenericTypeExpr (retval.Type, targs, loc).ResolveAsTypeStep (rc, silent);
Type expr_type = tnew_expr.Type;
if (TypeManager.IsGenericParameter (expr_type)) {
- Report.Error (704, loc, "A nested type cannot be specified through a type parameter `{0}'",
+ rc.Compiler.Report.Error (704, loc, "A nested type cannot be specified through a type parameter `{0}'",
tnew_expr.GetSignatureForError ());
return null;
}
- Expression member_lookup = MemberLookup (
- rc.DeclContainer.TypeBuilder, expr_type, expr_type, LookupIdentifier,
+ Expression member_lookup = MemberLookup (rc.Compiler,
+ rc.CurrentType, expr_type, expr_type, LookupIdentifier,
MemberTypes.NestedType, BindingFlags.Public | BindingFlags.NonPublic, loc);
if (member_lookup == null) {
if (silent)
return texpr;
}
- protected virtual void Error_IdentifierNotFound (IResolveContext rc, FullNamedExpression expr_type, string identifier)
+ protected virtual void Error_IdentifierNotFound (IMemberContext rc, FullNamedExpression expr_type, string identifier)
{
- Expression member_lookup = MemberLookup (
- rc.DeclContainer.TypeBuilder, expr_type.Type, expr_type.Type, SimpleName.RemoveGenericArity (identifier),
+ Expression member_lookup = MemberLookup (rc.Compiler,
+ rc.CurrentType, expr_type.Type, expr_type.Type, SimpleName.RemoveGenericArity (identifier),
MemberTypes.NestedType, BindingFlags.Public | BindingFlags.NonPublic, loc);
if (member_lookup != null) {
if (expr_type == null)
return;
- Namespace.Error_TypeArgumentsCannotBeUsed (expr_type, loc);
+ expr_type.Error_TypeArgumentsCannotBeUsed (rc.Compiler.Report, loc);
return;
}
- member_lookup = MemberLookup (
- rc.DeclContainer.TypeBuilder, expr_type.Type, expr_type.Type, identifier,
+ member_lookup = MemberLookup (rc.Compiler,
+ rc.CurrentType, expr_type.Type, expr_type.Type, identifier,
MemberTypes.All, BindingFlags.Public | BindingFlags.NonPublic, loc);
if (member_lookup == null) {
- Report.Error (426, loc, "The nested type `{0}' does not exist in the type `{1}'",
+ rc.Compiler.Report.Error (426, loc, "The nested type `{0}' does not exist in the type `{1}'",
Name, expr_type.GetSignatureForError ());
} else {
// TODO: Report.SymbolRelatedToPreviousError
- member_lookup.Error_UnexpectedKind (null, "type", loc);
+ member_lookup.Error_UnexpectedKind (rc.Compiler.Report, null, "type", loc);
}
}
- protected override void Error_TypeDoesNotContainDefinition (Type type, string name)
+ protected override void Error_TypeDoesNotContainDefinition (ResolveContext ec, Type type, string name)
{
if (RootContext.Version > LanguageVersion.ISO_2 &&
((expr.eclass & (ExprClass.Value | ExprClass.Variable)) != 0)) {
- Report.Error (1061, loc, "Type `{0}' does not contain a definition for `{1}' and no " +
+ ec.Report.Error (1061, loc, "Type `{0}' does not contain a definition for `{1}' and no " +
"extension method `{1}' of type `{0}' could be found " +
"(are you missing a using directive or an assembly reference?)",
TypeManager.CSharpName (type), name);
return;
}
- base.Error_TypeDoesNotContainDefinition (type, name);
+ base.Error_TypeDoesNotContainDefinition (ec, type, name);
}
public override string GetSignatureForError ()
loc = l;
}
- public override Expression CreateExpressionTree (EmitContext ec)
+ public override Expression CreateExpressionTree (ResolveContext ec)
{
- using (ec.With (EmitContext.Flags.AllCheckStateFlags, true))
+ using (ec.With (ResolveContext.Options.AllCheckStateFlags, true))
return Expr.CreateExpressionTree (ec);
}
- public override Expression DoResolve (EmitContext ec)
+ public override Expression DoResolve (ResolveContext ec)
{
- using (ec.With (EmitContext.Flags.AllCheckStateFlags, true))
+ using (ec.With (ResolveContext.Options.AllCheckStateFlags, true))
Expr = Expr.Resolve (ec);
if (Expr == null)
public override void Emit (EmitContext ec)
{
- using (ec.With (EmitContext.Flags.AllCheckStateFlags, true))
+ using (ec.With (EmitContext.Options.AllCheckStateFlags, true))
Expr.Emit (ec);
}
public override void EmitBranchable (EmitContext ec, Label target, bool on_true)
{
- using (ec.With (EmitContext.Flags.AllCheckStateFlags, true))
+ using (ec.With (EmitContext.Options.AllCheckStateFlags, true))
Expr.EmitBranchable (ec, target, on_true);
}
+#if NET_4_0
+ public override SLE.Expression MakeExpression (BuilderContext ctx)
+ {
+ using (ctx.With (BuilderContext.Options.AllCheckStateFlags, true)) {
+ return Expr.MakeExpression (ctx);
+ }
+ }
+#endif
+
public override void MutateHoistedGenericType (AnonymousMethodStorey storey)
{
Expr.MutateHoistedGenericType (storey);
loc = l;
}
- public override Expression CreateExpressionTree (EmitContext ec)
+ public override Expression CreateExpressionTree (ResolveContext ec)
{
- using (ec.With (EmitContext.Flags.AllCheckStateFlags, false))
+ using (ec.With (ResolveContext.Options.AllCheckStateFlags, false))
return Expr.CreateExpressionTree (ec);
}
- public override Expression DoResolve (EmitContext ec)
+ public override Expression DoResolve (ResolveContext ec)
{
- using (ec.With (EmitContext.Flags.AllCheckStateFlags, false))
+ using (ec.With (ResolveContext.Options.AllCheckStateFlags, false))
Expr = Expr.Resolve (ec);
if (Expr == null)
public override void Emit (EmitContext ec)
{
- using (ec.With (EmitContext.Flags.AllCheckStateFlags, false))
+ using (ec.With (EmitContext.Options.AllCheckStateFlags, false))
Expr.Emit (ec);
}
public override void EmitBranchable (EmitContext ec, Label target, bool on_true)
{
- using (ec.With (EmitContext.Flags.AllCheckStateFlags, false))
+ using (ec.With (EmitContext.Options.AllCheckStateFlags, false))
Expr.EmitBranchable (ec, target, on_true);
}
this.Arguments = args;
}
- public override Expression CreateExpressionTree (EmitContext ec)
+ public override Expression CreateExpressionTree (ResolveContext ec)
{
Arguments args = Arguments.CreateForExpressionTree (ec, Arguments,
Expr.CreateExpressionTree (ec));
- return CreateExpressionFactoryCall ("ArrayIndex", args);
+ return CreateExpressionFactoryCall (ec, "ArrayIndex", args);
}
- Expression MakePointerAccess (EmitContext ec, Type t)
+ Expression MakePointerAccess (ResolveContext ec, Type t)
{
if (Arguments.Count != 1){
- Error (196, "A pointer must be indexed by only one value");
+ ec.Report.Error (196, loc, "A pointer must be indexed by only one value");
return null;
}
if (Arguments [0] is NamedArgument)
- Error_NamedArgument ((NamedArgument) Arguments[0]);
+ Error_NamedArgument ((NamedArgument) Arguments[0], ec.Report);
Expression p = new PointerArithmetic (Binary.Operator.Addition, Expr, Arguments [0].Expr.Resolve (ec), t, loc);
return new Indirection (p, loc).Resolve (ec);
}
- public override Expression DoResolve (EmitContext ec)
+ public override Expression DoResolve (ResolveContext ec)
{
Expr = Expr.Resolve (ec);
if (Expr == null)
Type t = Expr.Type;
if (t == TypeManager.array_type){
- Report.Error (21, loc, "Cannot apply indexing with [] to an expression of type `System.Array'");
+ ec.Report.Error (21, loc, "Cannot apply indexing with [] to an expression of type `System.Array'");
return null;
}
return (new IndexerAccess (this, loc)).Resolve (ec);
}
- public override Expression DoResolveLValue (EmitContext ec, Expression right_side)
+ public override Expression DoResolveLValue (ResolveContext ec, Expression right_side)
{
Expr = Expr.Resolve (ec);
if (Expr == null)
throw new Exception ("Should never be reached");
}
- public static void Error_NamedArgument (NamedArgument na)
+ public static void Error_NamedArgument (NamedArgument na, Report Report)
{
Report.Error (1742, na.Name.Location, "An element access expression cannot use named argument");
}
/// <summary>
/// Implements array access
/// </summary>
- public class ArrayAccess : Expression, IAssignMethod, IMemoryLocation {
+ public class ArrayAccess : Expression, IDynamicAssign, IMemoryLocation {
//
// Points to our "data" repository
//
loc = l;
}
- public override Expression CreateExpressionTree (EmitContext ec)
+ public override Expression CreateExpressionTree (ResolveContext ec)
{
return ea.CreateExpressionTree (ec);
}
- public override Expression DoResolveLValue (EmitContext ec, Expression right_side)
+ public override Expression DoResolveLValue (ResolveContext ec, Expression right_side)
{
return DoResolve (ec);
}
- public override Expression DoResolve (EmitContext ec)
+ public override Expression DoResolve (ResolveContext ec)
{
#if false
ExprClass eclass = ea.Expr.eclass;
Type t = ea.Expr.Type;
int rank = ea.Arguments.Count;
if (t.GetArrayRank () != rank) {
- Report.Error (22, ea.Location, "Wrong number of indexes `{0}' inside [], expected `{1}'",
+ ec.Report.Error (22, ea.Location, "Wrong number of indexes `{0}' inside [], expected `{1}'",
ea.Arguments.Count.ToString (), t.GetArrayRank ().ToString ());
return null;
}
type = TypeManager.GetElementType (t);
- if (type.IsPointer && !ec.InUnsafe) {
- UnsafeError (ea.Location);
+ if (type.IsPointer && !ec.IsUnsafe) {
+ UnsafeError (ec, ea.Location);
}
foreach (Argument a in ea.Arguments) {
if (a is NamedArgument)
- ElementAccess.Error_NamedArgument ((NamedArgument) a);
+ ElementAccess.Error_NamedArgument ((NamedArgument) a, ec.Report);
a.Expr = ConvertExpressionToArrayIndex (ec, a.Expr);
}
} else if (TypeManager.IsStruct (type)){
ig.Emit (OpCodes.Ldelema, type);
ig.Emit (OpCodes.Ldobj, type);
-#if GMCS_SOURCE
} else if (type.IsGenericParameter) {
ig.Emit (OpCodes.Ldelem, type);
-#endif
} else if (type.IsPointer)
ig.Emit (OpCodes.Ldelem_I);
else
ig.Emit (OpCodes.Ldelem_Ref);
}
- protected override void Error_NegativeArrayIndex (Location loc)
+ protected override void Error_NegativeArrayIndex (ResolveContext ec, Location loc)
{
- Report.Warning (251, 2, loc, "Indexing an array with a negative index (array indices always start at zero)");
+ ec.Report.Warning (251, 2, loc, "Indexing an array with a negative index (array indices always start at zero)");
}
/// <summary>
/// </summary>
static public OpCode GetStoreOpcode (Type t, out bool is_stobj, out bool has_type_arg)
{
- //Console.WriteLine (new System.Diagnostics.StackTrace ());
has_type_arg = false; is_stobj = false;
t = TypeManager.TypeToCoreType (t);
if (TypeManager.IsEnumType (t))
has_type_arg = true;
is_stobj = true;
return OpCodes.Stobj;
-#if GMCS_SOURCE
} else if (t.IsGenericParameter) {
has_type_arg = true;
return OpCodes.Stelem;
-#endif
-
} else if (t.IsPointer)
return OpCodes.Stelem_I;
else
}
}
+#if NET_4_0
+ public SLE.Expression MakeAssignExpression (BuilderContext ctx)
+ {
+ return SLE.Expression.ArrayAccess (
+ ea.Expr.MakeExpression (ctx),
+ Arguments.MakeExpression (ea.Arguments, ctx));
+ }
+
+ public override SLE.Expression MakeExpression (BuilderContext ctx)
+ {
+ return SLE.Expression.ArrayIndex (
+ ea.Expr.MakeExpression (ctx),
+ Arguments.MakeExpression (ea.Arguments, ctx));
+ }
+#endif
+
public override void MutateHoistedGenericType (AnonymousMethodStorey storey)
{
type = storey.MutateType (type);
/// <summary>
/// Expressions that represent an indexer call.
/// </summary>
- public class IndexerAccess : Expression, IAssignMethod
+ public class IndexerAccess : Expression, IDynamicAssign
{
class IndexerMethodGroupExpr : MethodGroupExpr
{
return isSet ? "set" : "get";
}
- public override Expression CreateExpressionTree (EmitContext ec)
+ public override Expression CreateExpressionTree (ResolveContext ec)
{
Arguments args = Arguments.CreateForExpressionTree (ec, arguments,
instance_expr.CreateExpressionTree (ec),
new TypeOfMethod (get, loc));
- return CreateExpressionFactoryCall ("Call", args);
+ return CreateExpressionFactoryCall (ec, "Call", args);
}
- protected virtual void CommonResolve (EmitContext ec)
+ protected virtual void CommonResolve (ResolveContext ec)
{
indexer_type = instance_expr.Type;
current_type = ec.CurrentType;
}
- public override Expression DoResolve (EmitContext ec)
+ public override Expression DoResolve (ResolveContext ec)
{
return ResolveAccessor (ec, null);
}
- public override Expression DoResolveLValue (EmitContext ec, Expression right_side)
+ public override Expression DoResolveLValue (ResolveContext ec, Expression right_side)
{
if (right_side == EmptyExpression.OutAccess) {
- Report.Error (206, loc, "A property or indexer `{0}' may not be passed as an out or ref parameter",
- GetSignatureForError ());
+ ec.Report.Error (206, loc,
+ "A property or indexer may not be passed as an out or ref parameter");
return null;
}
return ResolveAccessor (ec, right_side);
}
- Expression ResolveAccessor (EmitContext ec, Expression right_side)
+ Expression ResolveAccessor (ResolveContext ec, Expression right_side)
{
CommonResolve (ec);
int additional = right_side == null ? 1 : 2;
Arguments args = new Arguments (arguments.Count + additional);
if (is_base_indexer) {
- Report.Error (1972, loc, "The indexer base access cannot be dynamically dispatched. Consider casting the dynamic arguments or eliminating the base access");
+ ec.Report.Error (1972, loc, "The indexer base access cannot be dynamically dispatched. Consider casting the dynamic arguments or eliminating the base access");
} else {
args.Add (new Argument (instance_expr));
}
Indexers ilist = Indexers.GetIndexersForType (current_type, indexer_type);
if (ilist.Methods == null) {
- Report.Error (21, loc, "Cannot apply indexing with [] to an expression of type `{0}'",
+ ec.Report.Error (21, loc, "Cannot apply indexing with [] to an expression of type `{0}'",
TypeManager.CSharpName (indexer_type));
return null;
}
}
type = TypeManager.TypeToCoreType (pi.PropertyType);
- if (type.IsPointer && !ec.InUnsafe)
- UnsafeError (loc);
+ if (type.IsPointer && !ec.IsUnsafe)
+ UnsafeError (ec, loc);
MethodInfo accessor;
if (right_side == null) {
} else {
accessor = set = pi.GetSetMethod (true);
if (accessor == null && pi.GetGetMethod (true) != null) {
- Report.SymbolRelatedToPreviousError (pi);
- Report.Error (200, loc, "The read only property or indexer `{0}' cannot be assigned to",
+ ec.Report.SymbolRelatedToPreviousError (pi);
+ ec.Report.Error (200, loc, "The read only property or indexer `{0}' cannot be assigned to",
TypeManager.GetFullNameSignature (pi));
return null;
}
}
if (accessor == null) {
- Report.SymbolRelatedToPreviousError (pi);
- Report.Error (154, loc, "The property or indexer `{0}' cannot be used in this context because it lacks a `{1}' accessor",
+ ec.Report.SymbolRelatedToPreviousError (pi);
+ ec.Report.Error (154, loc, "The property or indexer `{0}' cannot be used in this context because it lacks a `{1}' accessor",
TypeManager.GetFullNameSignature (pi), GetAccessorName (right_side != null));
return null;
}
// Only base will allow this invocation to happen.
//
if (accessor.IsAbstract && this is BaseIndexerAccess) {
- Error_CannotCallAbstractBase (TypeManager.GetFullNameSignature (pi));
+ Error_CannotCallAbstractBase (ec, TypeManager.GetFullNameSignature (pi));
}
bool must_do_cs1540_check;
if (set != null && get != null &&
(set.Attributes & MethodAttributes.MemberAccessMask) != (get.Attributes & MethodAttributes.MemberAccessMask)) {
- Report.SymbolRelatedToPreviousError (accessor);
- Report.Error (271, loc, "The property or indexer `{0}' cannot be used in this context because a `{1}' accessor is inaccessible",
+ ec.Report.SymbolRelatedToPreviousError (accessor);
+ ec.Report.Error (271, loc, "The property or indexer `{0}' cannot be used in this context because a `{1}' accessor is inaccessible",
TypeManager.GetFullNameSignature (pi), GetAccessorName (right_side != null));
} else {
- Report.SymbolRelatedToPreviousError (pi);
- ErrorIsInaccesible (loc, TypeManager.GetFullNameSignature (pi));
+ ec.Report.SymbolRelatedToPreviousError (pi);
+ ErrorIsInaccesible (loc, TypeManager.GetFullNameSignature (pi), ec.Report);
}
}
eclass = ExprClass.IndexerAccess;
return this;
}
+
+ public override void Emit (EmitContext ec)
+ {
+ Emit (ec, false);
+ }
public void Emit (EmitContext ec, bool leave_copy)
{
}
}
- public override void Emit (EmitContext ec)
+ public override string GetSignatureForError ()
{
- Emit (ec, false);
+ return TypeManager.CSharpSignature (get != null ? get : set, false);
}
- public override string GetSignatureForError ()
+#if NET_4_0
+ public SLE.Expression MakeAssignExpression (BuilderContext ctx)
{
- return TypeManager.CSharpSignature (get != null ? get : set, false);
+ var value = new[] { set_expr.MakeExpression (ctx) };
+ var args = Arguments.MakeExpression (arguments, ctx).Concat (value);
+
+ return SLE.Expression.Block (
+ SLE.Expression.Call (instance_expr.MakeExpression (ctx), set, args),
+ value [0]);
+ }
+
+ public override SLE.Expression MakeExpression (BuilderContext ctx)
+ {
+ var args = Arguments.MakeExpression (arguments, ctx);
+ return SLE.Expression.Call (instance_expr.MakeExpression (ctx), get, args);
}
+#endif
public override void MutateHoistedGenericType (AnonymousMethodStorey storey)
{
this.args = args;
}
- public override Expression CreateExpressionTree (EmitContext ec)
+ public override Expression CreateExpressionTree (ResolveContext ec)
{
throw new NotSupportedException ("ET");
}
- public override Expression DoResolve (EmitContext ec)
+ public override Expression DoResolve (ResolveContext ec)
{
Expression c = CommonResolve (ec);
return c;
}
- public override Expression DoResolveLValue (EmitContext ec, Expression right_side)
+ public override Expression DoResolveLValue (ResolveContext ec, Expression right_side)
{
Expression c = CommonResolve (ec);
return c;
}
- Expression CommonResolve (EmitContext ec)
+ Expression CommonResolve (ResolveContext ec)
{
Expression member_lookup;
Type current_type = ec.CurrentType;
if (!This.IsThisAvailable (ec)) {
if (ec.IsStatic) {
- Error (1511, "Keyword `base' is not available in a static method");
+ ec.Report.Error (1511, loc, "Keyword `base' is not available in a static method");
} else {
- Error (1512, "Keyword `base' is not available in the current context");
+ ec.Report.Error (1512, loc, "Keyword `base' is not available in the current context");
}
return null;
}
- member_lookup = MemberLookup (ec.CurrentType, null, base_type, Identifier,
+ member_lookup = MemberLookup (ec.Compiler, ec.CurrentType, null, base_type, Identifier,
AllMemberTypes, AllBindingFlags, loc);
if (member_lookup == null) {
- Error_MemberLookupFailed (ec.CurrentType, base_type, base_type, Identifier,
+ Error_MemberLookupFailed (ec, ec.CurrentType, base_type, base_type, Identifier,
null, AllMemberTypes, AllBindingFlags);
return null;
}
else
left = ec.GetThis (loc);
- MemberExpr me = (MemberExpr) member_lookup;
+ MemberExpr me = member_lookup as MemberExpr;
+ if (me == null){
+ if (member_lookup is TypeExpression){
+ ec.Report.Error (582, loc, "{0}: Can not reference a type through an expression, try `{1}' instead",
+ Identifier, member_lookup.GetSignatureForError ());
+ } else {
+ ec.Report.Error (582, loc, "{0}: Can not reference a {1} through an expression",
+ Identifier, member_lookup.ExprClassName);
+ }
+
+ return null;
+ }
+
me = me.ResolveMemberAccess (ec, left, loc, null);
if (me == null)
return null;
me.IsBase = true;
if (args != null) {
args.Resolve (ec);
- me.SetTypeArguments (args);
+ me.SetTypeArguments (ec, args);
}
return me;
this.arguments = args;
}
- protected override void CommonResolve (EmitContext ec)
+ protected override void CommonResolve (ResolveContext ec)
{
instance_expr = ec.GetThis (loc);
indexer_type = current_type;
}
- public override Expression CreateExpressionTree (EmitContext ec)
+ public override Expression CreateExpressionTree (ResolveContext ec)
{
- MemberExpr.Error_BaseAccessInExpressionTree (loc);
+ MemberExpr.Error_BaseAccessInExpressionTree (ec, loc);
return base.CreateExpressionTree (ec);
}
}
loc = Location.Null;
}
- public override Expression CreateExpressionTree (EmitContext ec)
+ public override Expression CreateExpressionTree (ResolveContext ec)
{
throw new NotSupportedException ("ET");
}
- public override Expression DoResolve (EmitContext ec)
+ public override Expression DoResolve (ResolveContext ec)
{
return this;
}
loc = Location.Null;
}
- public override Expression CreateExpressionTree (EmitContext ec)
+ public override Expression CreateExpressionTree (ResolveContext ec)
{
return null;
}
// Do nothing
}
- public override Expression DoResolve (EmitContext ec)
+ public override Expression DoResolve (ResolveContext ec)
{
type = TypeManager.object_type;
return this;
}
}
- public override Expression CreateExpressionTree (EmitContext ec)
+ public override Expression CreateExpressionTree (ResolveContext ec)
{
Arguments args = new Arguments (3);
args.Add (new Argument (source.CreateExpressionTree (ec)));
args.Add (new Argument (new TypeOf (new TypeExpression (type, loc), loc)));
args.Add (new Argument (new TypeOfMethod (method, loc)));
- return CreateExpressionFactoryCall ("Convert", args);
+ return CreateExpressionFactoryCall (ec, "Convert", args);
}
- public override Expression DoResolve (EmitContext ec)
+ public override Expression DoResolve (ResolveContext ec)
{
ObsoleteAttribute oa = AttributeTester.GetMethodObsoleteAttribute (method);
if (oa != null)
- AttributeTester.Report_ObsoleteMessage (oa, GetSignatureForError (), loc);
+ AttributeTester.Report_ObsoleteMessage (oa, GetSignatureForError (), loc, ec.Report);
eclass = ExprClass.Value;
return this;
return TypeManager.CSharpSignature (method);
}
+#if NET_4_0
+ public override SLE.Expression MakeExpression (BuilderContext ctx)
+ {
+ return SLE.Expression.Convert (source.MakeExpression (ctx), type, method);
+ }
+#endif
+
public override void MutateHoistedGenericType (AnonymousMethodStorey storey)
{
source.MutateHoistedGenericType (storey);
loc = l;
}
- protected override TypeExpr DoResolveAsTypeStep (IResolveContext ec)
+ protected override TypeExpr DoResolveAsTypeStep (IMemberContext ec)
{
TypeExpr lexpr = left.ResolveAsTypeTerminal (ec, false);
if (lexpr == null)
if (dim.Length != 0 && dim [0] == '[') {
if (TypeManager.IsSpecialType (ltype)) {
- Report.Error (611, loc, "Array elements cannot be of type `{0}'", TypeManager.CSharpName (ltype));
+ ec.Compiler.Report.Error (611, loc, "Array elements cannot be of type `{0}'", TypeManager.CSharpName (ltype));
return null;
}
if ((ltype.Attributes & Class.StaticClassAttribute) == Class.StaticClassAttribute) {
- Report.SymbolRelatedToPreviousError (ltype);
- Report.Error (719, loc, "Array elements cannot be of static type `{0}'",
+ ec.Compiler.Report.SymbolRelatedToPreviousError (ltype);
+ ec.Compiler.Report.Error (719, loc, "Array elements cannot be of static type `{0}'",
TypeManager.CSharpName (ltype));
}
}
if (type == null)
throw new InternalErrorException ("Couldn't create computed type " + ltype + dim);
- if (type.IsPointer && !ec.IsInUnsafeScope){
- UnsafeError (loc);
+ if (type.IsPointer && !ec.IsUnsafe){
+ UnsafeError (ec.Compiler.Report, loc);
}
eclass = ExprClass.Type;
return left.GetSignatureForError () + dim;
}
- public override TypeExpr ResolveAsTypeTerminal (IResolveContext ec, bool silent)
+ public override TypeExpr ResolveAsTypeTerminal (IMemberContext ec, bool silent)
{
return ResolveAsBaseTerminal (ec, silent);
}
eclass = ExprClass.Value;
}
- public override Expression CreateExpressionTree (EmitContext ec)
+ public override Expression CreateExpressionTree (ResolveContext ec)
{
- Error_PointerInsideExpressionTree ();
+ Error_PointerInsideExpressionTree (ec);
return null;
}
array.Emit (ec);
}
- public override Expression DoResolve (EmitContext ec)
+ public override Expression DoResolve (ResolveContext ec)
{
//
// We are born fully resolved
public class ArrayIndexCast : TypeCast
{
public ArrayIndexCast (Expression expr)
- : base (expr, expr.Type)
+ : base (expr, TypeManager.int32_type)
{
+ if (expr.Type == TypeManager.int32_type)
+ throw new ArgumentException ("unnecessary array index conversion");
}
- public override Expression CreateExpressionTree (EmitContext ec)
+ public override Expression CreateExpressionTree (ResolveContext ec)
{
- Arguments args = new Arguments (2);
- args.Add (new Argument (child.CreateExpressionTree (ec)));
- args.Add (new Argument (new TypeOf (new TypeExpression (TypeManager.int32_type, loc), loc)));
- return CreateExpressionFactoryCall ("ConvertChecked", args);
+ using (ec.Set (ResolveContext.Options.CheckedScope)) {
+ return base.CreateExpressionTree (ec);
+ }
}
public override void Emit (EmitContext ec)
{
child.Emit (ec);
-
- if (type == TypeManager.int32_type)
- return;
- if (type == TypeManager.uint32_type)
+ var expr_type = child.Type;
+
+ if (expr_type == TypeManager.uint32_type)
ec.ig.Emit (OpCodes.Conv_U);
- else if (type == TypeManager.int64_type)
+ else if (expr_type == TypeManager.int64_type)
ec.ig.Emit (OpCodes.Conv_Ovf_I);
- else if (type == TypeManager.uint64_type)
+ else if (expr_type == TypeManager.uint64_type)
ec.ig.Emit (OpCodes.Conv_Ovf_I_Un);
else
throw new InternalErrorException ("Cannot emit cast to unknown array element type", type);
}
+
+ public override bool GetAttributableValue (ResolveContext ec, Type value_type, out object value)
+ {
+ return child.GetAttributableValue (ec, value_type, out value);
+ }
}
//
loc = l;
}
- public override Expression CreateExpressionTree (EmitContext ec)
+ public override Expression CreateExpressionTree (ResolveContext ec)
{
throw new NotSupportedException ("ET");
}
- public override Expression DoResolve (EmitContext ec)
+ public override Expression DoResolve (ResolveContext ec)
{
count = count.Resolve (ec);
if (count == null)
Constant c = count as Constant;
if (c != null && c.IsNegative) {
- Report.Error (247, loc, "Cannot use a negative size with stackalloc");
- return null;
+ ec.Report.Error (247, loc, "Cannot use a negative size with stackalloc");
}
- if (ec.InCatch || ec.InFinally) {
- Error (255, "Cannot use stackalloc in finally or catch");
- return null;
+ if (ec.HasAny (ResolveContext.Options.CatchScope | ResolveContext.Options.FinallyScope)) {
+ ec.Report.Error (255, loc, "Cannot use stackalloc in finally or catch");
}
TypeExpr texpr = t.ResolveAsTypeTerminal (ec, false);
target.source = source.Clone (clonectx);
}
- public override Expression CreateExpressionTree (EmitContext ec)
+ public override Expression CreateExpressionTree (ResolveContext ec)
{
Arguments args = new Arguments (2);
FieldExpr fe = target as FieldExpr;
args.Add (new Argument (((PropertyExpr)target).CreateSetterTypeOfExpression ()));
args.Add (new Argument (source.CreateExpressionTree (ec)));
- return CreateExpressionFactoryCall (
+ return CreateExpressionFactoryCall (ec,
source is CollectionOrObjectInitializers ? "ListBind" : "Bind",
args);
}
- public override Expression DoResolve (EmitContext ec)
+ public override Expression DoResolve (ResolveContext ec)
{
if (source == null)
return EmptyExpressionStatement.Instance;
return expr;
}
- protected override Expression Error_MemberLookupFailed (Type type, MemberInfo[] members)
+ protected override Expression Error_MemberLookupFailed (ResolveContext ec, Type type, MemberInfo[] members)
{
MemberInfo member = members [0];
if (member.MemberType != MemberTypes.Property && member.MemberType != MemberTypes.Field)
- Report.Error (1913, loc, "Member `{0}' cannot be initialized. An object " +
+ ec.Report.Error (1913, loc, "Member `{0}' cannot be initialized. An object " +
"initializer may only be used for fields, or properties", TypeManager.GetFullNameSignature (member));
else
- Report.Error (1914, loc, " Static field or property `{0}' cannot be assigned in an object initializer",
+ ec.Report.Error (1914, loc, " Static field or property `{0}' cannot be assigned in an object initializer",
TypeManager.GetFullNameSignature (member));
return null;
{
}
- protected override void Error_TypeDoesNotContainDefinition (Type type, string name)
+ protected override void Error_TypeDoesNotContainDefinition (ResolveContext ec, Type type, string name)
{
if (TypeManager.HasElementType (type))
return;
- base.Error_TypeDoesNotContainDefinition (type, name);
+ base.Error_TypeDoesNotContainDefinition (ec, type, name);
}
}
this.loc = loc;
}
- public override Expression CreateExpressionTree (EmitContext ec)
+ public override Expression CreateExpressionTree (ResolveContext ec)
{
Arguments args = new Arguments (2);
args.Add (new Argument (mg.CreateExpressionTree (ec)));
expr_initializers.Add (a.CreateExpressionTree (ec));
args.Add (new Argument (new ArrayCreation (
- CreateExpressionTypeExpression (loc), "[]", expr_initializers, loc)));
- return CreateExpressionFactoryCall ("ElementInit", args);
+ CreateExpressionTypeExpression (ec, loc), "[]", expr_initializers, loc)));
+ return CreateExpressionFactoryCall (ec, "ElementInit", args);
}
protected override void CloneTo (CloneContext clonectx, Expression t)
target.arguments = arguments.Clone (clonectx);
}
- public override Expression DoResolve (EmitContext ec)
+ public override Expression DoResolve (ResolveContext ec)
{
if (eclass != ExprClass.Invalid)
return this;
t.initializers.Add (e.Clone (clonectx));
}
- public override Expression CreateExpressionTree (EmitContext ec)
+ public override Expression CreateExpressionTree (ResolveContext ec)
{
ArrayList expr_initializers = new ArrayList (initializers.Count);
foreach (Expression e in initializers) {
return new ImplicitlyTypedArrayCreation ("[]", expr_initializers, loc);
}
- public override Expression DoResolve (EmitContext ec)
+ public override Expression DoResolve (ResolveContext ec)
{
if (eclass != ExprClass.Invalid)
return this;
throw new InternalErrorException ("This line should never be reached");
} else {
if (!TypeManager.ImplementsInterface (ec.CurrentInitializerVariable.Type, TypeManager.ienumerable_type)) {
- Report.Error (1922, loc, "A field or property `{0}' cannot be initialized with a collection " +
+ ec.Report.Error (1922, loc, "A field or property `{0}' cannot be initialized with a collection " +
"object initializer because type `{1}' does not implement `{2}' interface",
ec.CurrentInitializerVariable.GetSignatureForError (),
TypeManager.CSharpName (ec.CurrentInitializerVariable.Type),
}
} else {
if (is_collection_initialization != (element_initializer == null)) {
- Report.Error (747, initializer.Location, "Inconsistent `{0}' member declaration",
+ ec.Report.Error (747, initializer.Location, "Inconsistent `{0}' member declaration",
is_collection_initialization ? "collection initializer" : "object initializer");
continue;
}
if (!is_collection_initialization) {
if (element_names.Contains (element_initializer.Name)) {
- Report.Error (1912, element_initializer.Location,
+ ec.Report.Error (1912, element_initializer.Location,
"An object initializer includes more than one member `{0}' initialization",
element_initializer.Name);
} else {
type = ec.CurrentInitializerVariable.Type;
if (is_collection_initialization) {
if (TypeManager.HasElementType (type)) {
- Report.Error (1925, loc, "Cannot initialize object of type `{0}' with a collection initializer",
+ ec.Report.Error (1925, loc, "Cannot initialize object of type `{0}' with a collection initializer",
TypeManager.CSharpName (type));
}
}
this.new_instance = newInstance;
}
- public override Expression CreateExpressionTree (EmitContext ec)
+ public override Expression CreateExpressionTree (ResolveContext ec)
{
// Should not be reached
throw new NotSupportedException ("ET");
}
- public override Expression DoResolve (EmitContext ec)
+ public override Expression DoResolve (ResolveContext ec)
{
return this;
}
- public override Expression DoResolveLValue (EmitContext ec, Expression right_side)
+ public override Expression DoResolveLValue (ResolveContext ec, Expression right_side)
{
return this;
}
target.initializers = (CollectionOrObjectInitializers) initializers.Clone (clonectx);
}
- public override Expression CreateExpressionTree (EmitContext ec)
+ public override Expression CreateExpressionTree (ResolveContext ec)
{
Arguments args = new Arguments (2);
args.Add (new Argument (base.CreateExpressionTree (ec)));
if (!initializers.IsEmpty)
args.Add (new Argument (initializers.CreateExpressionTree (ec)));
- return CreateExpressionFactoryCall (
+ return CreateExpressionFactoryCall (ec,
initializers.IsCollectionInitializer ? "ListInit" : "MemberInit",
args);
}
- public override Expression DoResolve (EmitContext ec)
+ public override Expression DoResolve (ResolveContext ec)
{
if (eclass != ExprClass.Invalid)
return this;
t.parameters.Add (atp.Clone (clonectx));
}
- AnonymousTypeClass CreateAnonymousType (ArrayList parameters)
+ AnonymousTypeClass CreateAnonymousType (ResolveContext ec, ArrayList parameters)
{
- AnonymousTypeClass type = parent.Module.GetAnonymousType (parameters);
+ AnonymousTypeClass type = parent.Module.Compiled.GetAnonymousType (parameters);
if (type != null)
return type;
- type = AnonymousTypeClass.Create (parent, parameters, loc);
+ type = AnonymousTypeClass.Create (ec.Compiler, parent, parameters, loc);
if (type == null)
return null;
type.DefineType ();
type.Define ();
type.EmitType ();
- if (Report.Errors == 0)
+ if (ec.Report.Errors == 0)
type.CloseType ();
- parent.Module.AddAnonymousType (type);
+ parent.Module.Compiled.AddAnonymousType (type);
return type;
}
- public override Expression CreateExpressionTree (EmitContext ec)
+ public override Expression CreateExpressionTree (ResolveContext ec)
{
throw new NotSupportedException ("ET");
}
- public override Expression DoResolve (EmitContext ec)
+ public override Expression DoResolve (ResolveContext ec)
{
AnonymousTypeClass anonymous_type;
- if (!ec.IsAnonymousMethodAllowed) {
- Report.Error (836, loc, "Anonymous types cannot be used in this expression");
+ if (ec.HasSet (ResolveContext.Options.ConstantScope)) {
+ ec.Report.Error (836, loc, "Anonymous types cannot be used in this expression");
return null;
}
if (parameters == null) {
- anonymous_type = CreateAnonymousType (EmptyParameters);
+ anonymous_type = CreateAnonymousType (ec, EmptyParameters);
return new New (new TypeExpression (anonymous_type.TypeBuilder, loc),
null, loc).Resolve (ec);
}
if (error)
return null;
- anonymous_type = CreateAnonymousType (parameters);
+ anonymous_type = CreateAnonymousType (ec, parameters);
if (anonymous_type == null)
return null;
}
}
- public class AnonymousTypeParameter : Expression
+ public class AnonymousTypeParameter : ShimExpression
{
public readonly string Name;
- Expression initializer;
public AnonymousTypeParameter (Expression initializer, string name, Location loc)
+ : base (initializer)
{
this.Name = name;
this.loc = loc;
- this.initializer = initializer;
}
public AnonymousTypeParameter (Parameter parameter)
+ : base (new SimpleName (parameter.Name, parameter.Location))
{
this.Name = parameter.Name;
this.loc = parameter.Location;
- this.initializer = new SimpleName (Name, loc);
}
- protected override void CloneTo (CloneContext clonectx, Expression target)
- {
- AnonymousTypeParameter t = (AnonymousTypeParameter) target;
- t.initializer = initializer.Clone (clonectx);
- }
-
- public override Expression CreateExpressionTree (EmitContext ec)
- {
- throw new NotSupportedException ("ET");
- }
-
public override bool Equals (object o)
{
AnonymousTypeParameter other = o as AnonymousTypeParameter;
return Name.GetHashCode ();
}
- public override Expression DoResolve (EmitContext ec)
+ public override Expression DoResolve (ResolveContext ec)
{
- Expression e = initializer.Resolve (ec);
+ Expression e = expr.Resolve (ec);
if (e == null)
return null;
if (e.eclass == ExprClass.MethodGroup) {
- Error_InvalidInitializer (e.ExprClassName);
+ Error_InvalidInitializer (ec, e.ExprClassName);
return null;
}
type = e.Type;
if (type == TypeManager.void_type || type == TypeManager.null_type ||
type == InternalType.AnonymousMethod || type.IsPointer) {
- Error_InvalidInitializer (e.GetSignatureForError ());
+ Error_InvalidInitializer (ec, e.GetSignatureForError ());
return null;
}
return e;
}
- protected virtual void Error_InvalidInitializer (string initializer)
+ protected virtual void Error_InvalidInitializer (ResolveContext ec, string initializer)
{
- Report.Error (828, loc, "An anonymous type property `{0}' cannot be initialized with `{1}'",
+ ec.Report.Error (828, loc, "An anonymous type property `{0}' cannot be initialized with `{1}'",
Name, initializer);
}
-
- public override void Emit (EmitContext ec)
- {
- throw new InternalErrorException ("Should not be reached");
- }
}
}