/** * Return a MeasuredNode of the given condition node, without minimizing * the result. * <p> * Since a MinimizedCondition necessarily must contain two trees, * this method sets the negative side to a invalid node * with an unreasonably high length so that it will * never be chosen by {@link #getMinimized}. * * @param n the conditional expression tree * @return a MinimizedCondition object representing that tree. */ static MinimizedCondition unoptimized(Node n) { checkNotNull(n.getParent()); MeasuredNode pos = new MeasuredNode(n, null, 0, false); MeasuredNode neg = new MeasuredNode(null, null, Integer.MAX_VALUE, true); return new MinimizedCondition(pos, neg); }
/** * Return a MeasuredNode of the given condition node, without minimizing * the result. * <p> * Since a MinimizedCondition necessarily must contain two trees, this * method sets the negative side to a {@link Token#SCRIPT} node (never valid * inside an expression) with an unreasonably high length so that it will * never be chosen by {@link #getMinimized}. * * @param n the conditional expression tree to minimize. * This must be connected to the AST, and will be swapped * with a placeholder node during minimization. * @return a MinimizedCondition object representing that tree. */ static MinimizedCondition unoptimized(Node n) { Preconditions.checkNotNull(n.getParent()); Node placeholder = swapWithPlaceholderNode(n); MeasuredNode pos = new MeasuredNode(n, 0, false); MeasuredNode neg = new MeasuredNode(IR.script(), Integer.MAX_VALUE, true); return new MinimizedCondition(pos, neg).setPlaceholder(placeholder); }
MeasuredNode pos = new MeasuredNode(n, 0, false); MeasuredNode neg = pos.cloneTree().negate(); return new MinimizedCondition(pos, neg);
private MeasuredNode change() { return (isChanged()) ? this : new MeasuredNode(node, children, length, true); }
private MeasuredNode cloneTree() { return new MeasuredNode(node.cloneTree(), length, changed); }
private MeasuredNode updateToken(Token token) { return new MeasuredNode( new Node(token).srcref(node), normalizeChildren(node, children), length, true); }
private static MeasuredNode addNode(Node parent, MeasuredNode... children) { int cost = 0; boolean changed = false; for (MeasuredNode child : children) { parent.addChildrenToBack(child.node); cost += child.length; changed = changed || child.changed; } cost += estimateCostOneLevel(parent); return new MeasuredNode(parent, cost, changed); }
/** * Return a MeasuredNode for a non-particapting AST Node. This is * used for leaf expression nodes. */ private static MeasuredNode forNode(Node n) { return new MeasuredNode(n, null, 0, false); }
/** * The returned MeasuredNode is only marked as changed if the children * are marked as changed. */ private static MeasuredNode addNode(Node parent, MeasuredNode ...children) { int cost = 0; boolean changed = false; for (MeasuredNode child : children) { cost += child.length; changed = changed || child.changed; } cost += estimateCostOneLevel(parent, children); return new MeasuredNode(parent, children, cost, changed); }