Esempio n. 1
0
 @Override
 @Nullable
 public DfaConstValue getConstantValue(@NotNull DfaVariableValue value) {
   int index = getEqClassIndex(value);
   EqClass ec = index == -1 ? null : myEqClasses.get(index);
   return ec == null ? null : (DfaConstValue) unwrap(ec.findConstant(true));
 }
Esempio n. 2
0
 @Nullable
 private Double getDoubleValue(int eqClassIndex) {
   EqClass ec = myEqClasses.get(eqClassIndex);
   DfaValue dfaConst = ec == null ? null : ec.findConstant(false);
   Object constValue =
       dfaConst instanceof DfaConstValue ? ((DfaConstValue) dfaConst).getValue() : null;
   return constValue instanceof Number ? ((Number) constValue).doubleValue() : null;
 }
Esempio n. 3
0
  private boolean applyRelation(
      @NotNull final DfaValue dfaLeft, @NotNull final DfaValue dfaRight, boolean isNegated) {
    if (isUnknownState(dfaLeft) || isUnknownState(dfaRight)) {
      return true;
    }

    // DfaConstValue || DfaVariableValue
    Integer c1Index = getOrCreateEqClassIndex(dfaLeft);
    Integer c2Index = getOrCreateEqClassIndex(dfaRight);
    if (c1Index == null || c2Index == null) {
      return true;
    }

    if (!isNegated) { // Equals
      if (c1Index.equals(c2Index) || areCompatibleConstants(c1Index, c2Index)) return true;
      if (!uniteClasses(c1Index, c2Index)) return false;

      for (long encodedPair : myDistinctClasses.toArray()) {
        EqClass c1 = myEqClasses.get(low(encodedPair));
        EqClass c2 = myEqClasses.get(high(encodedPair));
        DfaConstValue const1 = (DfaConstValue) c1.findConstant(false);
        DfaConstValue const2 = (DfaConstValue) c2.findConstant(false);
        if (const1 != null
            && const2 != null
            && !preserveConstantDistinction(const1.getValue(), const2.getValue())) {
          myDistinctClasses.remove(encodedPair);
        }
      }
      myCachedDistinctClassPairs = null;
      myCachedNonTrivialEqClasses = null;
      myCachedHash = null;
    } else { // Not Equals
      if (c1Index.equals(c2Index) || areCompatibleConstants(c1Index, c2Index)) return false;
      if (isNull(dfaLeft) && isPrimitive(dfaRight) || isNull(dfaRight) && isPrimitive(dfaLeft))
        return true;
      makeClassesDistinct(c1Index, c2Index);
      myCachedDistinctClassPairs = null;
      myCachedHash = null;
    }

    return true;
  }
Esempio n. 4
0
  private boolean shouldMarkUnknown(@NotNull DfaVariableValue value) {
    int eqClassIndex = getEqClassIndex(value);
    if (eqClassIndex < 0) return false;

    EqClass eqClass = myEqClasses.get(eqClassIndex);
    if (eqClass == null) return false;
    if (eqClass.findConstant(true) != null) return true;

    for (UnorderedPair<EqClass> pair : getDistinctClassPairs()) {
      if (pair.first == eqClass && pair.second.findConstant(true) != null
          || pair.second == eqClass && pair.first.findConstant(true) != null) {
        return true;
      }
    }
    return false;
  }