if (source == null) {
ok = false;
- source = EmptyExpression.Null;
+ source = ErrorExpression.Instance;
}
target = target.ResolveLValue (ec, source);
return this;
}
-#if NET_4_0 || MONODROID
+#if NET_4_0 || MOBILE_DYNAMIC
public override System.Linq.Expressions.Expression MakeExpression (BuilderContext ctx)
{
var tassign = target as IDynamicAssign;
Emit (ec, true);
}
+ public override void FlowAnalysis (FlowAnalysisContext fc)
+ {
+ source.FlowAnalysis (fc);
+
+ if (target is ArrayAccess || target is IndexerExpr || target is PropertyExpr)
+ target.FlowAnalysis (fc);
+ }
+
protected override void CloneTo (CloneContext clonectx, Expression t)
{
Assign _target = (Assign) t;
return this;
}
+
+ public override void FlowAnalysis (FlowAnalysisContext fc)
+ {
+ base.FlowAnalysis (fc);
+
+ var vr = target as VariableReference;
+ if (vr != null) {
+ if (vr.VariableInfo != null)
+ fc.SetVariableAssigned (vr.VariableInfo);
+
+ return;
+ }
+
+ var fe = target as FieldExpr;
+ if (fe != null) {
+ fe.SetFieldAssigned (fc);
+ return;
+ }
+ }
+
+ public override void MarkReachable (Reachability rc)
+ {
+ var es = source as ExpressionStatement;
+ if (es != null)
+ es.MarkReachable (rc);
+ }
}
public class RuntimeExplicitAssign : Assign
// share same constructor (block) for expression trees resolve but
// they have they own resolve scope
//
- sealed class FieldInitializerContext : ResolveContext
+ sealed class FieldInitializerContext : BlockContext
{
- ExplicitBlock ctor_block;
+ readonly ExplicitBlock ctor_block;
- public FieldInitializerContext (IMemberContext mc, ResolveContext constructorContext)
- : base (mc, Options.FieldInitializerScope | Options.ConstructorScope)
+ public FieldInitializerContext (IMemberContext mc, BlockContext constructorContext)
+ : base (mc, null, constructorContext.ReturnType)
{
+ flags |= Options.FieldInitializerScope | Options.ConstructorScope;
this.ctor_block = constructorContext.CurrentBlock.Explicit;
+
+ if (ctor_block.IsCompilerGenerated)
+ CurrentBlock = ctor_block;
}
public override ExplicitBlock ConstructorBlock {
- get {
- return ctor_block;
- }
+ get {
+ return ctor_block;
+ }
}
}
((FieldExpr)target).InstanceExpression = new CompilerGeneratedThis (mc.CurrentType, expression.Location);
}
+ public int AssignmentOffset { get; private set; }
+
+ public FieldBase Field {
+ get {
+ return mc;
+ }
+ }
+
public override Location StartLocation {
get {
return loc;
}
}
- protected override Expression DoResolve (ResolveContext ec)
+ protected override Expression DoResolve (ResolveContext rc)
{
// Field initializer can be resolved (fail) many times
if (source == null)
return null;
if (resolved == null) {
- var ctx = new FieldInitializerContext (mc, ec);
+ var bc = (BlockContext) rc;
+ var ctx = new FieldInitializerContext (mc, bc);
resolved = base.DoResolve (ctx) as ExpressionStatement;
+ AssignmentOffset = ctx.AssignmentInfoOffset - bc.AssignmentInfoOffset;
}
return resolved;
else
base.EmitStatement (ec);
}
+
+ public override void FlowAnalysis (FlowAnalysisContext fc)
+ {
+ source.FlowAnalysis (fc);
+ ((FieldExpr) target).SetFieldAssigned (fc);
+ }
public bool IsDefaultInitializer {
get {
}
}
+ class PrimaryConstructorAssign : SimpleAssign
+ {
+ readonly Field field;
+ readonly Parameter parameter;
+
+ public PrimaryConstructorAssign (Field field, Parameter parameter)
+ : base (null, null, parameter.Location)
+ {
+ this.field = field;
+ this.parameter = parameter;
+ }
+
+ protected override Expression DoResolve (ResolveContext rc)
+ {
+ target = new FieldExpr (field, loc);
+ source = rc.CurrentBlock.ParametersBlock.GetParameterInfo (parameter).CreateReferenceExpression (rc, loc);
+ return base.DoResolve (rc);
+ }
+
+ public override void EmitStatement (EmitContext ec)
+ {
+ using (ec.With (BuilderContext.Options.OmitDebugInfo, true)) {
+ base.EmitStatement (ec);
+ }
+ }
+ }
+
//
// This class is used for compound assignments.
//
return base.DoResolve (ec);
}
+ public override void FlowAnalysis (FlowAnalysisContext fc)
+ {
+ target.FlowAnalysis (fc);
+ source.FlowAnalysis (fc);
+ }
+
protected override Expression ResolveConversions (ResolveContext ec)
{
//
// Otherwise, if the selected operator is a predefined operator
//
Binary b = source as Binary;
- if (b == null && source is ReducedExpression)
- b = ((ReducedExpression) source).OriginalExpression as Binary;
+ if (b == null) {
+ if (source is ReducedExpression)
+ b = ((ReducedExpression) source).OriginalExpression as Binary;
+ else if (source is ReducedExpression.ReducedConstantExpression) {
+ b = ((ReducedExpression.ReducedConstantExpression) source).OriginalExpression as Binary;
+ } else if (source is Nullable.LiftedBinaryOperator) {
+ var po = ((Nullable.LiftedBinaryOperator) source);
+ if (po.UserOperator == null)
+ b = po.Binary;
+ } else if (source is TypeCast) {
+ b = ((TypeCast) source).Child as Binary;
+ }
+ }
if (b != null) {
//