public Expression Expr;
Expression enum_conversion;
- public Unary (Operator op, Expression expr)
+ public Unary (Operator op, Expression expr, Location loc)
{
Oper = op;
Expr = expr;
- loc = expr.Location;
+ this.loc = loc;
}
// <summary>
}
if (TypeManager.IsNullableType (Expr.Type))
- return new Nullable.LiftedUnaryOperator (Oper, Expr).Resolve (ec);
+ return new Nullable.LiftedUnaryOperator (Oper, Expr, loc).Resolve (ec);
//
// Attempt to use a constant folding operation.
// Holds the real operation
Expression operation;
- public UnaryMutator (Mode m, Expression e)
+ public UnaryMutator (Mode m, Expression e, Location loc)
{
mode = m;
- loc = e.Location;
+ this.loc = loc;
expr = e;
}
// 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 = new Binary (op, operation, one, loc);
operation = operation.Resolve (ec);
if (operation != null && operation.Type != type)
operation = Convert.ExplicitNumericConversion (operation, type);
/// </summary>
public class Binary : Expression, IDynamicBinder
{
-
protected class PredefinedOperator {
protected readonly Type left;
protected readonly Type right;
if (left == TypeManager.decimal_type)
return b.ResolveUserOperator (ec, b.left.Type, b.right.Type);
- var c = b.right as IntegralConstant;
+ var c = b.right as Constant;
if (c != null) {
if (c.IsDefaultValue && (b.oper == Operator.Addition || b.oper == Operator.BitwiseOr || b.oper == Operator.Subtraction))
- return ReducedExpression.Create (b.left, b);
+ return ReducedExpression.Create (b.left, b).Resolve (ec);
+ if ((b.oper == Operator.Multiply || b.oper == Operator.Division) && c.IsOneInteger)
+ return ReducedExpression.Create (b.left, b).Resolve (ec);
return b;
}
- c = b.left as IntegralConstant;
+ c = b.left as Constant;
if (c != null) {
if (c.IsDefaultValue && (b.oper == Operator.Addition || b.oper == Operator.BitwiseOr))
- return ReducedExpression.Create (b.right, b);
+ return ReducedExpression.Create (b.right, b).Resolve (ec);
+ if (b.oper == Operator.Multiply && c.IsOneInteger)
+ return ReducedExpression.Create (b.right, b).Resolve (ec);
return b;
}
// b = b.left >> b.right & (0x1f|0x3f)
//
b.right = new Binary (Operator.BitwiseAnd,
- b.right, new IntConstant (right_mask, b.right.Location)).Resolve (ec);
+ b.right, new IntConstant (right_mask, b.right.Location), b.loc).Resolve (ec);
//
// Expression tree representation does not use & mask
static PredefinedOperator [] standard_operators;
static PredefinedOperator [] pointer_operators;
- public Binary (Operator oper, Expression left, Expression right, bool isCompound)
- : this (oper, left, right)
+ public Binary (Operator oper, Expression left, Expression right, bool isCompound, Location loc)
+ : this (oper, left, right, loc)
{
this.is_compound = isCompound;
}
- public Binary (Operator oper, Expression left, Expression right)
+ public Binary (Operator oper, Expression left, Expression right, Location loc)
{
this.oper = oper;
this.left = left;
this.right = right;
- this.loc = left.Location;
+ this.loc = loc;
}
public Operator Oper {
public static void Error_OperatorCannotBeApplied (ResolveContext ec, Expression left, Expression right, Operator oper, Location loc)
{
- new Binary (oper, left, right).Error_OperatorCannotBeApplied (ec, left, right);
+ new Binary (oper, left, right, loc).Error_OperatorCannotBeApplied (ec, left, right);
}
public static void Error_OperatorCannotBeApplied (ResolveContext ec, Expression left, Expression right, string oper, Location loc)
public Expression CreateCallSiteBinder (ResolveContext ec, Arguments args)
{
- Arguments binder_args = new Arguments (3);
+ Arguments binder_args = new Arguments (4);
MemberAccess sle = new MemberAccess (new MemberAccess (
new QualifiedAliasMember (QualifiedAliasMember.GlobalAlias, "System", loc), "Linq", loc), "Expressions", 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 TypeOf (new TypeExpression (ec.CurrentType, loc), loc)));
binder_args.Add (new Argument (new ImplicitlyTypedArrayCreation ("[]", args.CreateDynamicBinderArguments (ec), loc)));
return new Invocation (DynamicExpressionStatement.GetBinder ("BinaryOperation", loc), binder_args);
left.Emit (ec);
- Constant right_const = right as Constant;
+ var right_const = right as Constant;
if (right_const != null) {
//
// Optimize 0-based arithmetic
if (right_const.IsDefaultValue)
return;
- if (size != 0) {
- // 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).Resolve (rc), right_const, loc);
- if (right == null)
- return;
- } else {
- ig.Emit (OpCodes.Sizeof, element);
- right = EmptyExpression.Null;
- }
+ if (size != 0)
+ right = new IntConstant (size, right.Location);
+ else
+ right = new SizeOf (new TypeExpression (element, right.Location), right.Location);
+
+ // TODO: Should be the checks resolve context sensitive?
+ ResolveContext rc = new ResolveContext (ec.MemberContext, ResolveContext.Options.UnsafeScope);
+ right = new Binary (Binary.Operator.Multiply, right, right_const, loc).Resolve (rc);
+ if (right == null)
+ return;
}
right.Emit (ec);
// Check if both can convert implicitly to each other's type
//
if (Convert.ImplicitConversion (ec, false_expr, true_type, loc) != null) {
- ec.Report.Error (172, loc,
+ ec.Report.Error (172, true_expr.Location,
"Type of conditional expression cannot be determined as `{0}' and `{1}' convert implicitly to each other",
TypeManager.CSharpName (true_type), TypeManager.CSharpName (false_type));
return null;
} else if ((conv = Convert.ImplicitConversion (ec, false_expr, true_type, loc)) != null) {
false_expr = conv;
} else {
- ec.Report.Error (173, loc,
+ ec.Report.Error (173, true_expr.Location,
"Type of conditional expression cannot be determined because there is no implicit conversion between `{0}' and `{1}'",
TypeManager.CSharpName (true_type), TypeManager.CSharpName (false_type));
return null;
if (c != null){
bool is_false = c.IsDefaultValue;
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);
+ return ReducedExpression.Create (is_false ? false_expr : true_expr, this).Resolve (ec);
}
return this;
}
if (TypeManager.activator_create_instance == null) {
- Type activator_type = TypeManager.CoreLookupType (ec.Compiler, "System", "Activator", Kind.Class, true);
+ Type activator_type = TypeManager.CoreLookupType (ec.Compiler, "System", "Activator", MemberKind.Class, true);
if (activator_type != null) {
TypeManager.activator_create_instance = TypeManager.GetPredefinedMethod (
activator_type, "CreateInstance", loc, Type.EmptyTypes);
public override void MutateHoistedGenericType (AnonymousMethodStorey storey)
{
- typearg = storey.MutateType (typearg);
+ if (!TypeManager.IsGenericTypeDefinition (typearg))
+ typearg = storey.MutateType (typearg);
}
public Type TypeArgument {
if (member.IsConstructor) {
type = TypeManager.ctorinfo_type;
if (type == null)
- type = TypeManager.ctorinfo_type = TypeManager.CoreLookupType (ec.Compiler, "System.Reflection", "ConstructorInfo", Kind.Class, true);
+ type = TypeManager.ctorinfo_type = TypeManager.CoreLookupType (ec.Compiler, "System.Reflection", "ConstructorInfo", MemberKind.Class, true);
} else {
type = TypeManager.methodinfo_type;
if (type == null)
- type = TypeManager.methodinfo_type = TypeManager.CoreLookupType (ec.Compiler, "System.Reflection", "MethodInfo", Kind.Class, true);
+ type = TypeManager.methodinfo_type = TypeManager.CoreLookupType (ec.Compiler, "System.Reflection", "MethodInfo", MemberKind.Class, true);
}
return base.DoResolve (ec);
var mi = is_generic ? TypeFromHandleGeneric : TypeFromHandle;
if (mi == null) {
- Type t = TypeManager.CoreLookupType (ec.Compiler, "System.Reflection", TypeName, Kind.Class, true);
- Type handle_type = TypeManager.CoreLookupType (ec.Compiler, "System", RuntimeHandleName, Kind.Class, true);
+ Type t = TypeManager.CoreLookupType (ec.Compiler, "System.Reflection", TypeName, MemberKind.Class, true);
+ Type handle_type = TypeManager.CoreLookupType (ec.Compiler, "System", RuntimeHandleName, MemberKind.Class, true);
if (t == null || handle_type == null)
return null;
protected override Expression DoResolve (ResolveContext ec)
{
if (TypeManager.fieldinfo_type == null)
- TypeManager.fieldinfo_type = TypeManager.CoreLookupType (ec.Compiler, "System.Reflection", TypeName, Kind.Class, true);
+ TypeManager.fieldinfo_type = TypeManager.CoreLookupType (ec.Compiler, "System.Reflection", TypeName, MemberKind.Class, true);
type = TypeManager.fieldinfo_type;
return base.DoResolve (ec);
}
instance_expr.CheckMarshalByRefAccess (ec);
+
+ if (must_do_cs1540_check && (instance_expr != EmptyExpression.Null) &&
+ !TypeManager.IsInstantiationOfSameGenericType (instance_expr.Type, ec.CurrentType) &&
+ !TypeManager.IsNestedChildOf (ec.CurrentType, instance_expr.Type) &&
+ !TypeManager.IsSubclassOf (instance_expr.Type, ec.CurrentType)) {
+ ec.Report.SymbolRelatedToPreviousError (accessor.MetaInfo);
+ Error_CannotAccessProtected (ec, loc, accessor.MetaInfo, instance_expr.Type, ec.CurrentType);
+ return null;
+ }
+
eclass = ExprClass.IndexerAccess;
return this;
}