source.Emit (ec);
- // HACK: variable is already emitted when source is an initializer
- if (source is NewInitialize) {
- if (leave_copy)
- Emit (ec);
- return;
- }
-
Store (ec);
if (leave_copy)
ig.Emit (OpCodes.Ldloca, builder);
}
+ public override void MutateHoistedGenericType (AnonymousMethodStorey storey)
+ {
+ type = storey.MutateType (type);
+ }
+
public bool PointsToAddress {
get {
return is_address;
if (resolved != this)
return resolved;
}
-
- if (target.eclass == ExprClass.Variable) {
- New n = source as New;
- if (n == null)
- return this;
-
- if (n.HasInitializer) {
- n.SetTargetVariable (target);
- } else if (target_type.IsValueType) {
- n.SetTargetVariable (target);
- return n;
- }
- }
-
+
return this;
}
void Emit (EmitContext ec, bool is_statement)
{
- ((IAssignMethod) target).EmitAssign (ec, source, !is_statement, this is CompoundAssign);
+ IAssignMethod t = (IAssignMethod) target;
+ t.EmitAssign (ec, source, !is_statement, this is CompoundAssign);
}
public override void Emit (EmitContext ec)
// Keep resolved value because field initializers have their own rules
//
ExpressionStatement resolved;
+ IResolveContext rc;
- public FieldInitializer (FieldBuilder field, Expression expression)
- : base (new FieldExpr (field, expression.Location, true), expression, expression.Location)
+ public FieldInitializer (FieldBuilder field, Expression expression, IResolveContext rc)
+ : base (new FieldExpr (field, expression.Location), expression, expression.Location)
{
+ this.rc = rc;
if (!field.IsStatic)
((FieldExpr)target).InstanceExpression = CompilerGeneratedThis.Instance;
}
if (source == null)
return null;
- if (resolved == null)
- resolved = base.DoResolve (ec) as ExpressionStatement;
+ if (resolved == null) {
+ //
+ // Field initializers are tricky for partial classes. They have to
+ // share same costructor (block) but they have they own resolve scope.
+ //
+
+ // TODO: Use ResolveContext only
+ EmitContext f_ec = new EmitContext (rc, rc.DeclContainer, loc, null, TypeManager.void_type, 0, true);
+ f_ec.IsStatic = ec.IsStatic;
+ f_ec.CurrentBlock = ec.CurrentBlock;
+
+ EmitContext.Flags flags = EmitContext.Flags.InFieldInitializer;
+ if (ec.IsInUnsafeScope)
+ flags |= EmitContext.Flags.InUnsafe;
+
+ f_ec.Set (flags);
+
+ resolved = base.DoResolve (f_ec) as ExpressionStatement;
+ }
return resolved;
}
public override void Emit (EmitContext ec)
{
- throw new InternalErrorException ("don't know what to emit");
+ if (RootContext.EvalMode)
+ EmitStatement (ec);
+ else
+ throw new InternalErrorException ("don't know what to emit");
}
public override void EmitStatement (EmitContext ec)
this.op = op;
}
- // !!! What a stupid name
- public class Helper : Expression {
+ public sealed class TargetExpression : Expression {
Expression child;
- public Helper (Expression child)
+ public TargetExpression (Expression child)
{
this.child = child;
this.loc = child.Location;
// into a tree, to guarantee that we do not have side
// effects.
//
- source = new Binary (op, new Helper (target), original_source, true);
+ source = new Binary (op, new TargetExpression (target), original_source, true);
return base.DoResolve (ec);
}
protected override Expression ResolveConversions (EmitContext ec)
{
- // source might have changed to BinaryDelegate
Type target_type = target.Type;
- Type source_type = source.Type;
- Binary b = source as Binary;
- if (b == null)
- return base.ResolveConversions (ec);
-
- // FIXME: Restrict only to predefined operators
//
- // 1. if the source is explicitly convertible to the
- // target_type
+ // 1. the return type is implicitly convertible to the type of target
//
- source = Convert.ExplicitConversion (ec, source, target_type, loc);
- if (source == null){
- original_source.Error_ValueCannotBeConverted (ec, loc, target_type, true);
- return null;
- }
-
- //
- // 2. and the original right side is implicitly convertible to
- // the type of target
- //
- if (Convert.ImplicitConversionExists (ec, original_source, target_type))
+ if (Convert.ImplicitConversionExists (ec, source, target_type)) {
+ source = Convert.ImplicitConversion (ec, source, target_type, loc);
return this;
+ }
//
- // In the spec 2.4 they added: or if type of the target is int
- // and the operator is a shift operator...
+ // Otherwise, if the selected operator is a predefined operator
//
- if (source_type == TypeManager.int32_type && (b.Oper & Binary.Operator.ShiftMask) != 0)
- return this;
+ Binary b = source as Binary;
+ if (b != null) {
+ //
+ // 2a. the operator is a shift operator
+ //
+ // 2b. the return type is explicitly convertible to the type of x, and
+ // y is implicitly convertible to the type of x
+ //
+ if ((b.Oper & Binary.Operator.ShiftMask) != 0 ||
+ Convert.ImplicitConversionExists (ec, original_source, target_type)) {
+ source = Convert.ExplicitConversion (ec, source, target_type, loc);
+ return this;
+ }
+ }
original_source.Error_ValueCannotBeConverted (ec, loc, target_type, false);
return null;