{
ILGenerator ig = ec.ig;
+ if (builder == null)
+ throw new InternalErrorException ("Emit without Store, or after Release");
+
ig.Emit (OpCodes.Ldloc, builder);
// we need to copy from the pointer
if (is_address)
{
this.is_embedded = true;
}
+
+ public override Expression CreateExpressionTree (EmitContext ec)
+ {
+ Report.Error (832, loc, "An expression tree cannot contain an assignment operator");
+ return null;
+ }
protected virtual Assign GetEmbeddedAssign (Location loc)
{
source = embedded = ((Assign) source).GetEmbeddedAssign (loc);
real_source = source = source.Resolve (ec);
+
if (source == null) {
// Ensure that we don't propagate the error as spurious "uninitialized variable" errors.
target = target.ResolveLValue (ec, EmptyExpression.Null, Location);
// local variable as source.
if (embedded != null)
source = (embedded.temp != null) ? embedded.temp : embedded.source;
-
+
target = target.ResolveLValue (ec, source, Location);
if (target == null)
return null;
-
+
bool same_assignment = (embedded != null) ? embedded.Target.Equals(target) : source.Equals (target);
if (same_assignment) {
Report.Warning (1717, 3, loc, "Assignment made to same variable; did you mean to assign something else?");
}
if (!(target is IAssignMethod) && (target.eclass != ExprClass.EventAccess)) {
- Report.Error (131, loc,
- "Left hand of an assignment must be a variable, " +
- "a property or an indexer");
+ Error_ValueAssignment (loc);
return null;
}
}
- if (target_type == source_type){
- if (source is New && target_type.IsValueType &&
- (target.eclass != ExprClass.IndexerAccess) && (target.eclass != ExprClass.PropertyAccess)){
- New n = (New) source;
+ if (target_type == source_type) {
+ if (target.eclass == ExprClass.Variable) {
+ New n = source as New;
+ if (n == null)
+ return this;
- if (n.SetValueTypeVariable (target))
+ if (n.HasInitializer) {
+ n.SetTargetVariable (target);
+ } else if (target_type.IsValueType) {
+ n.SetTargetVariable (target);
return n;
- else
- return null;
+ }
}
return this;
source = Convert.ExplicitConversion (ec, source, target_type, loc);
if (source == null){
- a.original_source.Error_ValueCannotBeConverted (loc, target_type, true);
+ a.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.ImplicitStandardConversionExists (a.original_source, target_type))
+ if (Convert.ImplicitConversionExists (ec, a.original_source, target_type))
return this;
//
(b.Oper == Binary.Operator.LeftShift || b.Oper == Binary.Operator.RightShift))
return this;
- a.original_source.Error_ValueCannotBeConverted (loc, target_type, false);
+ a.original_source.Error_ValueCannotBeConverted (ec, loc, target_type, false);
return null;
}
}
{
Emit (ec, true);
}
+
+ protected override void CloneTo (CloneContext clonectx, Expression t)
+ {
+ Assign _target = (Assign) t;
+
+ _target.target = target.Clone (clonectx);
+ _target.source = source.Clone (clonectx);
+ }
+ }
+
+
+ // This class implements fields and events class initializers
+ public class FieldInitializer : Assign
+ {
+ //
+ // Keep resolved value because field initializers have their own rules
+ //
+ ExpressionStatement resolved;
+
+ public FieldInitializer (FieldBuilder field, Expression expression)
+ : base (new FieldExpr (field, expression.Location, true), expression)
+ {
+ if (!field.IsStatic)
+ ((FieldExpr)target).InstanceExpression = CompilerGeneratedThis.Instance;
+ }
+
+ public override Expression DoResolve (EmitContext ec)
+ {
+ // Field initializer can be resolved (fail) many times
+ if (Source == null)
+ return null;
+
+ if (resolved == null)
+ resolved = base.DoResolve (ec) as ExpressionStatement;
+
+ return resolved;
+ }
+
+ public override void EmitStatement (EmitContext ec)
+ {
+ if (resolved == null)
+ return;
+
+ if (resolved != this)
+ resolved.EmitStatement (ec);
+ else
+ base.EmitStatement (ec);
+ }
+
+ public bool IsComplexInitializer {
+ get {
+ if (embedded != null)
+ return true;
+
+ return !(source is Constant);
+ }
+ }
+
+ public bool IsDefaultInitializer {
+ get {
+ Constant c = source as Constant;
+ if (c == null)
+ return false;
+
+ FieldExpr fe = (FieldExpr)target;
+ return c.IsDefaultInitializer (fe.Type);
+ }
+ }
}
if (original_source == null)
return null;
- target = target.Resolve (ec);
+ using (ec.Set (EmitContext.Flags.InCompoundAssignment)) {
+ target = target.Resolve (ec);
+ }
+
if (target == null)
return null;
+ if (target is MethodGroupExpr){
+ Error_CannotAssign (((MethodGroupExpr)target).Name, target.ExprClassName);
+ return null;
+ }
//
// Only now we can decouple the original source/target
// into a tree, to guarantee that we do not have side
// effects.
//
- source = new Binary (op, target, original_source);
+ source = new Binary (op, target, original_source, true);
return base.DoResolve (ec);
}
+
+ protected override void CloneTo (CloneContext clonectx, Expression t)
+ {
+ CompoundAssign target = (CompoundAssign) t;
+
+ target.original_source = original_source.Clone (clonectx);
+ }
}
}