/** * Computes the intersection of this set and {@code that}. */ public BooleanLiteralSet intersection(BooleanLiteralSet that) { return fromOrdinal(this.ordinal() & that.ordinal()); }
private static BooleanLiteralSet joinBooleanOutcomes( boolean isAnd, BooleanLiteralSet left, BooleanLiteralSet right) { // A truthy value on the lhs of an {@code &&} can never make it to the // result. Same for a falsy value on the lhs of an {@code ||}. // Hence the intersection. return right.union(left.intersection(BooleanLiteralSet.get(!isAnd))); }
@Override public BooleanLiteralSet getPossibleToBooleanOutcomes() { BooleanLiteralSet literals = BooleanLiteralSet.EMPTY; for (int i = 0; i < alternatesRetainingStructuralSubtypes.size(); i++) { JSType element = alternatesRetainingStructuralSubtypes.get(i); literals = literals.union(element.getPossibleToBooleanOutcomes()); if (literals == BooleanLiteralSet.BOTH) { break; } } return literals; }
/** * Returns whether {@code this} contains the given literal value. */ public boolean contains(boolean literalValue) { switch (this.ordinal()) { case 0: return false; case 1: return literalValue; case 2: return !literalValue; case 3: return true; default: throw new IndexOutOfBoundsException("Ordinal: " + this.ordinal()); } }
/** * Computes the restricted type of this type knowing that the * {@code ToBoolean} predicate has a specific value. For more information * about the {@code ToBoolean} predicate, see * {@link #getPossibleToBooleanOutcomes}. * * @param outcome the value of the {@code ToBoolean} predicate * * @return the restricted type, or the Any Type if the underlying type could * not have yielded this ToBoolean value * * TODO(user): Move this method to the SemanticRAI and use the visit * method of types to get the restricted type. */ public JSType getRestrictedTypeGivenToBooleanOutcome(boolean outcome) { if (outcome && this == getNativeType(JSTypeNative.UNKNOWN_TYPE)) { return getNativeType(JSTypeNative.CHECKED_UNKNOWN_TYPE); } BooleanLiteralSet literals = getPossibleToBooleanOutcomes(); if (literals.contains(outcome)) { return this; } else { return getNativeType(JSTypeNative.NO_TYPE); } }
if (leftType != null && rightType != null) { leftType = leftType.getRestrictedTypeGivenToBooleanOutcome(!nIsAnd); if (leftOutcome.toBooleanOutcomes == BooleanLiteralSet.get(!nIsAnd)) {
return TernaryValue.UNKNOWN.and(type.getPossibleToBooleanOutcomes().toTernaryValue());
@Override public BooleanLiteralSet getPossibleToBooleanOutcomes() { BooleanLiteralSet literals = BooleanLiteralSet.EMPTY; for (JSType element : alternatesWithoutStucturalTyping) { literals = literals.union(element.getPossibleToBooleanOutcomes()); if (literals == BooleanLiteralSet.BOTH) { break; } } return literals; }
/** * Returns whether {@code this} contains the given literal value. */ public boolean contains(boolean literalValue) { switch (this.ordinal()) { case 0: return false; case 1: return literalValue; case 2: return !literalValue; case 3: return true; default: throw new IndexOutOfBoundsException("Ordinal: " + this.ordinal()); } }
/** * Computes the restricted type of this type knowing that the * {@code ToBoolean} predicate has a specific value. For more information * about the {@code ToBoolean} predicate, see * {@link #getPossibleToBooleanOutcomes}. * * @param outcome the value of the {@code ToBoolean} predicate * * @return the restricted type, or the Any Type if the underlying type could * not have yielded this ToBoolean value * * TODO(user): Move this method to the SemanticRAI and use the visit * method of types to get the restricted type. */ public JSType getRestrictedTypeGivenToBooleanOutcome(boolean outcome) { if (outcome && areIdentical(this, getNativeType(JSTypeNative.UNKNOWN_TYPE))) { return getNativeType(JSTypeNative.CHECKED_UNKNOWN_TYPE); } BooleanLiteralSet literals = getPossibleToBooleanOutcomes(); if (literals.contains(outcome)) { return this; } else { return getNativeType(JSTypeNative.NO_TYPE); } }
if (leftType != null && rightType != null) { leftType = leftType.getRestrictedTypeGivenToBooleanOutcome(!nIsAnd); if (leftOutcome.toBooleanOutcomes == BooleanLiteralSet.get(!nIsAnd)) {
private static BooleanLiteralSet joinBooleanOutcomes( boolean isAnd, BooleanLiteralSet left, BooleanLiteralSet right) { // A truthy value on the lhs of an {@code &&} can never make it to the // result. Same for a falsy value on the lhs of an {@code ||}. // Hence the intersection. return right.union(left.intersection(BooleanLiteralSet.get(!isAnd))); }
/** * Computes the union of this set and {@code that}. */ public BooleanLiteralSet union(BooleanLiteralSet that) { return fromOrdinal(this.ordinal() | that.ordinal()); }
/** * Computes the intersection of this set and {@code that}. */ public BooleanLiteralSet intersection(BooleanLiteralSet that) { return fromOrdinal(this.ordinal() & that.ordinal()); }
/** * Computes the union of this set and {@code that}. */ public BooleanLiteralSet union(BooleanLiteralSet that) { return fromOrdinal(this.ordinal() | that.ordinal()); }