public void visitIfElse(IfStatement ifElse) {
   ifElse.getBooleanExpression().visit(this);
   pushState();
   ifElse.getIfBlock().visit(this);
   popState();
   pushState();
   ifElse.getElseBlock().visit(this);
   popState();
 }
  public void visitIfElse(IfStatement ifElse) {
    ifElse.getBooleanExpression().visit(this);
    ifElse.getIfBlock().visit(this);

    Statement elseBlock = ifElse.getElseBlock();
    if (elseBlock instanceof EmptyStatement) {
      // dispatching to EmptyStatement will not call back visitor,
      // must call our visitEmptyStatement explicitly
      visitEmptyStatement((EmptyStatement) elseBlock);
    } else {
      elseBlock.visit(this);
    }
  }
Пример #3
0
  @Override
  public void visitIfElse(final IfStatement ifElse) {
    visitStatement(ifElse);
    ifElse.getBooleanExpression().visit(this);
    Map<Variable, VariableState> ifState = pushState();
    ifElse.getIfBlock().visit(this);
    popState();
    Statement elseBlock = ifElse.getElseBlock();
    Map<Variable, VariableState> elseState = pushState();
    if (elseBlock instanceof EmptyStatement) {
      // dispatching to EmptyStatement will not call back visitor,
      // must call our visitEmptyStatement explicitly
      visitEmptyStatement((EmptyStatement) elseBlock);
    } else {
      elseBlock.visit(this);
    }
    popState();

    // merge if/else branches
    Map<Variable, VariableState> curState = getState();
    Set<Variable> allVars = new HashSet<Variable>();
    allVars.addAll(curState.keySet());
    allVars.addAll(ifState.keySet());
    allVars.addAll(elseState.keySet());
    for (Variable var : allVars) {
      VariableState beforeValue = curState.get(var);
      VariableState ifValue = ifState.get(var);
      VariableState elseValue = elseState.get(var);
      // merge if and else values
      VariableState mergedIfElse;
      mergedIfElse =
          ifValue != null && elseValue != null && ifValue.isFinal && elseValue.isFinal
              ? VariableState.is_final
              : VariableState.is_var;
      if (beforeValue == null) {
        curState.put(var, mergedIfElse);
      } else {
        if (beforeValue == VariableState.is_uninitialized) {
          curState.put(var, mergedIfElse);
        } else if (ifValue != null || elseValue != null) {
          curState.put(var, VariableState.is_var);
        }
      }
    }
  }