/// <summary> /// Visits a <see cref="ConstantExpression" />. /// </summary> /// <param name="constantExpression">The constant expression.</param> /// <param name="rewritingParameters">The rewriting parameters.</param> /// <param name="currentResult">The current result.</param> public void Constant( ConstantExpression constantExpression, RewritingParameters rewritingParameters, Reference <Expression> currentResult) { currentResult.Value = rewritingParameters.FlatRepresentationConsumer.GetResultingExpression(constantExpression); }
/// <summary> /// Visits a <see cref="VariableExpression" />. /// </summary> /// <param name="variableExpression">The variable expression.</param> /// <param name="rewritingParameters">The rewriting parameters.</param> /// <param name="currentResult">The current result.</param> public void Variable( VariableExpression variableExpression, RewritingParameters rewritingParameters, Reference <Expression> currentResult) { currentResult.Value = rewritingParameters.FlatRepresentationConsumer.GetResultingExpression(variableExpression); }
/// <summary> /// Units the specified unit expression. /// </summary> /// <param name="unitExpression">The unit expression.</param> /// <param name="rewritingParameters">The rewriting parameters.</param> /// <param name="currentResult">The current result.</param> public void Unit( UnitExpression unitExpression, RewritingParameters rewritingParameters, Reference <Expression> currentResult) { currentResult.Value = rewritingParameters.FlatRepresentationConsumer.GetResultingExpression(unitExpression, rewritingParameters.ReduceByBaseUnit); }
/// <summary> /// Visits a <see cref="MagnitudeExpression" />. /// </summary> /// <param name="magnitudeExpression">The magnitude expression.</param> /// <param name="rewritingParameters">The rewriting parameters.</param> /// <param name="currentResult">The current result.</param> public void Magnitude( MagnitudeExpression magnitudeExpression, RewritingParameters rewritingParameters, Reference <Expression> currentResult) { magnitudeExpression.Lhs.Visit(this, rewritingParameters, currentResult); }
/// <summary> /// Visits a <see cref="ParenthesisExpression" />. /// </summary> /// <param name="parenthesisExpression">The parentheses expression.</param> /// <param name="rewritingParameters">The rewriting parameters.</param> /// <param name="currentResult">The current result.</param> public void Parenthesis( ParenthesisExpression parenthesisExpression, RewritingParameters rewritingParameters, Reference <Expression> currentResult) { parenthesisExpression.Expression.Visit(this, rewritingParameters, currentResult); if (ReferenceEquals(parenthesisExpression.Expression, currentResult.Value)) { currentResult.Value = parenthesisExpression; } else { currentResult.Value = new ParenthesisExpression(currentResult.Value); } }
/// <summary> /// Visits a <see cref="DivisionExpression" />. /// </summary> /// <param name="divisionExpression">The division expression.</param> /// <param name="rewritingParameters">The rewriting parameters.</param> /// <param name="currentResult">The current result.</param> public void Divide( DivisionExpression divisionExpression, RewritingParameters rewritingParameters, Reference <Expression> currentResult) { divisionExpression.Lhs.Visit(this, rewritingParameters, currentResult); var lhs = currentResult.Value; divisionExpression.Rhs.Visit(this, rewritingParameters, currentResult); var rhs = currentResult.Value; currentResult.Value = this.SelectCurrentExpression( divisionExpression, lhs, rhs, (newLhs, newRhs) => new DivisionExpression(newLhs, newRhs)); }
/// <summary> /// Visits a <see cref="MultiplicationExpression" />. /// </summary> /// <param name="multiplicationExpression">The multiplication expression.</param> /// <param name="rewritingParameters">The rewriting parameters.</param> /// <param name="currentResult">The current result.</param> public void Multiply( MultiplicationExpression multiplicationExpression, RewritingParameters rewritingParameters, Reference <Expression> currentResult) { multiplicationExpression.Lhs.Visit(this, rewritingParameters, currentResult); var lhs = currentResult.Value; multiplicationExpression.Rhs.Visit(this, rewritingParameters, currentResult); var rhs = currentResult.Value; currentResult.Value = this.SelectCurrentExpression( multiplicationExpression, lhs, rhs, (newLhs, newRhs) => new MultiplicationExpression(newLhs, newRhs)); }
/// <summary> /// Visits the specified expression. /// </summary> /// <param name="expression">The expression.</param> /// <param name="rewritingParameters">The rewriting parameters.</param> /// <param name="currentResult">The current result.</param> /// <returns> /// The rewritten <see cref="Expression" />. /// </returns> public Expression Visit( Expression expression, RewritingParameters rewritingParameters = null, Reference <Expression> currentResult = null) { rewritingParameters = rewritingParameters ?? new RewritingParameters(false, new FlatRepresentationConsumer(new Dictionary <string, IFlatIdentifierRepresentation>())); currentResult = currentResult ?? new Reference <Expression>(expression); expression.Visit(this, rewritingParameters, currentResult); var result = currentResult.Value; if (result == null) { return(ConstantExpression.One); } return(result); }
/// <summary> /// Visits the unknown. /// </summary> /// <param name="expresstion">The expresstion.</param> /// <param name="rewritingParameters">The rewriting parameters.</param> /// <param name="currentResult">The current result.</param> public void VisitUnknown(Expression expresstion, RewritingParameters rewritingParameters = null, Reference <Expression> currentResult = null) { throw VisitException.Create(expresstion, rewritingParameters, currentResult); }