public override void Optimize() { Expression = Expression.Reduce(); foreach (var stmt in Statements) { stmt.Optimize(); } }
protected Expression Fold(Expression expr, Func<double, double> reducer) { var e = expr.Reduce(); if (e.Kind == ExpressionKind.Constant) { var v = ((Constant)e).Value; if (v.IsReal) return new Constant(reducer(v.Real), Line, Column); } return this; }
protected Expression Fold(Expression expr1, Expression expr2, Func<double, double, double> reducer) { var e1 = expr1.Reduce(); var e2 = expr2.Reduce(); if (e1.Kind == ExpressionKind.Constant && e2.Kind == ExpressionKind.Constant) { var v1 = ((Constant)e1).Value; var v2 = ((Constant)e2).Value; if (v1.IsReal && v2.IsReal) return new Constant(reducer(v1.Real, v2.Real), Line, Column); } return this; }
protected Expression Fold(Expression expr, Func <double, double> reducer) { var e = expr.Reduce(); if (e.Kind == ExpressionKind.Constant) { var v = ((Constant)e).Value; if (v.IsReal) { return(new Constant(reducer(v.Real), Line, Column)); } } return(this); }
protected Expression Fold(Expression expr1, Expression expr2, Func <double, double, double> reducer) { var e1 = expr1.Reduce(); var e2 = expr2.Reduce(); if (e1.Kind == ExpressionKind.Constant && e2.Kind == ExpressionKind.Constant) { var v1 = ((Constant)e1).Value; var v2 = ((Constant)e2).Value; if (v1.IsReal && v2.IsReal) { return(new Constant(reducer(v1.Real, v2.Real), Line, Column)); } } return(this); }
public override void Optimize() { Expression = Expression.Reduce(); Body.Optimize(); }