public override AstVisitAction VisitAssignmentStatement(AssignmentStatementAst assignmentStatementAst)
{
// first check if it's a assignable expression, fail otherwise. later on we also need support for
// arrays of variables
ExpressionAst expressionAst = assignmentStatementAst.Left;
if (!SettableExpression.SupportedExpressions.Contains(expressionAst.GetType()))
{
var msg = String.Format("The expression type '{0}' is currently not supported for assignments",
expressionAst.GetType().ToString());
throw new NotImplementedException(msg);
}
var assignableExpression = SettableExpression.Create(expressionAst, this);
var rightValue = EvaluateAst(assignmentStatementAst.Right);
object newValue = rightValue;
bool isSimpleAssignment = assignmentStatementAst.Operator == TokenKind.Equals;
// safe the effort to get the value of the left side if it's replaced anyway
dynamic currentValue = isSimpleAssignment ? null : assignableExpression.GetValue();
// compute the new value
if (isSimpleAssignment)
{
newValue = rightValue;
}
else if (assignmentStatementAst.Operator == TokenKind.PlusEquals)
{
newValue = ArithmeticOperations.Add(currentValue, rightValue);
}
else if (assignmentStatementAst.Operator == TokenKind.MinusEquals)
{
newValue = ArithmeticOperations.Subtract(currentValue, rightValue);
}
else if (assignmentStatementAst.Operator == TokenKind.MultiplyEquals)
{
newValue = ArithmeticOperations.Multiply(currentValue, rightValue);
}
else if (assignmentStatementAst.Operator == TokenKind.DivideEquals)
{
newValue = ArithmeticOperations.Divide(currentValue, rightValue);
}
else if (assignmentStatementAst.Operator == TokenKind.RemainderEquals)
{
newValue = ArithmeticOperations.Remainder(currentValue, rightValue);
}
else
{
throw new NotImplementedException("Unsupported operator: " + assignmentStatementAst.Operator.ToString());
}
if (this._writeSideEffectsToPipeline)
{
this._pipelineCommandRuntime.WriteObject(newValue);
}
// set the new value
assignableExpression.SetValue(newValue);
return AstVisitAction.SkipChildren;
}