@Override public TernaryValue and(TernaryValue that) { return (FALSE.equals(that)) ? FALSE : UNKNOWN; }
@Override public TernaryValue xor(TernaryValue that) { return that.not(); }
case NOT: TernaryValue value = getImpureBooleanValue(n.getLastChild()); return value.not(); case AND: { TernaryValue lhs = getImpureBooleanValue(n.getFirstChild()); TernaryValue rhs = getImpureBooleanValue(n.getLastChild()); return lhs.and(rhs); return lhs.or(rhs); n.getSecondChild()); TernaryValue falseValue = getImpureBooleanValue(n.getLastChild()); if (trueValue.equals(falseValue)) { return trueValue; } else {
Double rv = NodeUtil.getNumberValue(right); if (lv != null && rv != null) { return TernaryValue.forBoolean(lv.doubleValue() == rv.doubleValue()); TernaryValue lv = NodeUtil.getPureBooleanValue(left); TernaryValue rv = NodeUtil.getPureBooleanValue(right); return lv.and(rv).or(lv.not().and(rv.not()));
@Override public boolean apply(EdgeTuple<Node, Branch> input) { Branch branch = input.edge; if (!branch.isConditional()) { return true; } Node predecessor = input.sourceNode; Node condition = NodeUtil.getConditionExpression(predecessor); // TODO(user): Handle more complicated expression like true == true, // etc.... if (condition != null) { TernaryValue val = NodeUtil.getImpureBooleanValue(condition); if (val != TernaryValue.UNKNOWN) { return val.toBoolean(true) == (branch == Branch.ON_TRUE); } } return true; } };
case Token.TEMPLATELIT: if (n.hasOneChild()) { return TernaryValue.forBoolean(!n.getFirstChild().getString().isEmpty()); return TernaryValue.forBoolean(n.getString().length() > 0); return TernaryValue.forBoolean(n.getDouble() != 0); return getPureBooleanValue(n.getLastChild()).not();
return TernaryValue.UNKNOWN; } else { return TernaryValue.forBoolean(lv.compareTo(rv) < 0); return TernaryValue.forBoolean(willNegate); } else { return TernaryValue.forBoolean(lv.doubleValue() < rv.doubleValue());
case Token.NOT: TernaryValue value = getImpureBooleanValue(n.getLastChild()); return value.not(); case Token.AND: { TernaryValue lhs = getImpureBooleanValue(n.getFirstChild()); TernaryValue rhs = getImpureBooleanValue(n.getLastChild()); return lhs.and(rhs); return lhs.or(rhs); n.getSecondChild()); TernaryValue falseValue = getImpureBooleanValue(n.getLastChild()); if (trueValue.equals(falseValue)) { return trueValue; } else {
Double rv = NodeUtil.getNumberValue(right, useTypes); if (lv != null && rv != null) { return TernaryValue.forBoolean(lv.doubleValue() == rv.doubleValue()); TernaryValue lv = NodeUtil.getPureBooleanValue(left); TernaryValue rv = NodeUtil.getPureBooleanValue(right); return lv.and(rv).or(lv.not().and(rv.not()));
@Override public boolean apply(EdgeTuple<Node, Branch> input) { Branch branch = input.edge; if (!branch.isConditional()) { return true; } Node predecessor = input.sourceNode; Node condition = NodeUtil.getConditionExpression(predecessor); // TODO(user): Handle more complicated expression like true == true, // etc.... if (condition != null) { TernaryValue val = NodeUtil.getImpureBooleanValue(condition); if (val != TernaryValue.UNKNOWN) { return val.toBoolean(true) == (branch == Branch.ON_TRUE); } } return true; } }
return TernaryValue.forBoolean( null != n.getCookedString() && !n.getCookedString().isEmpty()); return TernaryValue.forBoolean(n.getString().length() > 0); return TernaryValue.forBoolean(n.getDouble() != 0); return getPureBooleanValue(n.getLastChild()).not();
return TernaryValue.UNKNOWN; } else { return TernaryValue.forBoolean(lv.compareTo(rv) < 0); return TernaryValue.forBoolean(willNegate); } else { return TernaryValue.forBoolean(lv.doubleValue() < rv.doubleValue());
return getBooleanValueWithTypes(n.getLastChild()); case NOT: return getBooleanValueWithTypes(n.getLastChild()).not(); case AND: return TernaryValue.UNKNOWN.and(getBooleanValueWithTypes(n.getLastChild())); case OR: return TernaryValue.UNKNOWN.or(getBooleanValueWithTypes(n.getLastChild())); case HOOK: return trueValue.equals(falseValue) ? trueValue : TernaryValue.UNKNOWN; return TernaryValue.UNKNOWN.and(type.getPossibleToBooleanOutcomes().toTernaryValue());
/** * Try to fold comparison nodes, e.g == */ private Node tryFoldComparison(Node n, Node left, Node right) { TernaryValue result = evaluateComparison(n.getType(), left, right, shouldUseTypes); if (result == TernaryValue.UNKNOWN) { return n; } Node newNode = NodeUtil.booleanNode(result.toBoolean(true)); n.getParent().replaceChild(n, newNode); reportCodeChange(); return newNode; }
@Override public TernaryValue and(TernaryValue that) { return (FALSE.equals(that)) ? FALSE : UNKNOWN; }
@Override public TernaryValue xor(TernaryValue that) { return that.not(); }
/** * Try to fold comparison nodes, e.g == */ private Node tryFoldComparison(Node n, Node left, Node right) { TernaryValue result = evaluateComparison(n.getToken(), left, right); if (result == TernaryValue.UNKNOWN) { return n; } Node newNode = NodeUtil.booleanNode(result.toBoolean(true)); reportChangeToEnclosingScope(n); n.replaceWith(newNode); markFunctionsDeleted(n); return newNode; }
@Override public TernaryValue or(TernaryValue that) { return (TRUE.equals(that)) ? TRUE : UNKNOWN; }