Esempio n. 1
0
 @Override
 public DfaInstructionState[] visitPush(
     PushInstruction instruction, DataFlowRunner runner, DfaMemoryState memState) {
   if (myContext == instruction.getPlace()) {
     final Map<DfaVariableValue, DfaVariableState> map =
         ((ValuableDataFlowRunner.MyDfaMemoryState) memState).getVariableStates();
     for (Map.Entry<DfaVariableValue, DfaVariableState> entry : map.entrySet()) {
       ValuableDataFlowRunner.ValuableDfaVariableState state =
           (ValuableDataFlowRunner.ValuableDfaVariableState) entry.getValue();
       DfaVariableValue variableValue = entry.getKey();
       final PsiExpression psiExpression = state.myExpression;
       if (psiExpression != null && variableValue.getQualifier() == null) {
         myValues.put(variableValue.getPsiVariable(), psiExpression);
       }
     }
     DfaValue value = instruction.getValue();
     if (value instanceof DfaVariableValue
         && ((DfaVariableValue) value).getQualifier() == null) {
       if (memState.isNotNull((DfaVariableValue) value)) {
         myNotNulls.add(((DfaVariableValue) value).getPsiVariable());
       }
       if (memState.isNull(value)) {
         myNulls.add(((DfaVariableValue) value).getPsiVariable());
       }
     }
   }
   return super.visitPush(instruction, runner, memState);
 }
  @Nullable
  private DfaInstructionState[] handleRelationBinop(
      BinopInstruction instruction,
      DataFlowRunner runner,
      DfaMemoryState memState,
      DfaValue dfaRight,
      DfaValue dfaLeft) {
    DfaValueFactory factory = runner.getFactory();
    final Instruction next = runner.getInstruction(instruction.getIndex() + 1);
    DfaRelationValue dfaRelation =
        factory
            .getRelationFactory()
            .createRelation(dfaLeft, dfaRight, instruction.getOperationSign(), false);
    if (dfaRelation == null) {
      return null;
    }

    myCanBeNullInInstanceof.add(instruction);

    ArrayList<DfaInstructionState> states = new ArrayList<DfaInstructionState>();

    final DfaMemoryState trueCopy = memState.createCopy();
    if (trueCopy.applyCondition(dfaRelation)) {
      trueCopy.push(factory.getConstFactory().getTrue());
      instruction.setTrueReachable();
      states.add(new DfaInstructionState(next, trueCopy));
    }

    //noinspection UnnecessaryLocalVariable
    DfaMemoryState falseCopy = memState;
    if (falseCopy.applyCondition(dfaRelation.createNegated())) {
      falseCopy.push(factory.getConstFactory().getFalse());
      instruction.setFalseReachable();
      states.add(new DfaInstructionState(next, falseCopy));
      if (instruction instanceof InstanceofInstruction && !falseCopy.isNull(dfaLeft)) {
        myUsefulInstanceofs.add((InstanceofInstruction) instruction);
      }
    }

    return states.toArray(new DfaInstructionState[states.size()]);
  }