@Override public void visitBinaryExpr(BinaryExpr binaryExpr) { if (binaryExpr.getOp().isSideEffecting()) { predicateHolds(); } super.visitBinaryExpr(binaryExpr); }
private boolean maybeLongRunning(ForStmt forStmt) { final Optional<ImmutablePair<String, Integer>> initValueAndLoopCounterName = getLoopCounterNameAndInitValue(forStmt.getInit()); if (!initValueAndLoopCounterName.isPresent()) { return false; } final String loopCounterName = initValueAndLoopCounterName.get().left; final int initValue = initValueAndLoopCounterName.get().right; final Optional<ImmutablePair<BinOp, Integer>> condTestTypeAndLimitValue = getCondTestTypeAndLimitValue(forStmt.getCondition(), loopCounterName); if (!condTestTypeAndLimitValue.isPresent()) { return false; } final BinOp condTestType = condTestTypeAndLimitValue.get().left; final int condLimitValue = condTestTypeAndLimitValue.get().right; if (condTestType.isSideEffecting()) { return false; } final Optional<Integer> incrementValue = getIncrementValue(forStmt.getIncrement(), loopCounterName); if (!incrementValue.isPresent()) { return false; } return (((condTestType == BinOp.LT || condTestType == BinOp.LE) && incrementValue.get() <= 0) || ((condTestType == BinOp.GT || condTestType == BinOp.GE) && incrementValue.get() >= 0) || ((condLimitValue - initValue) / incrementValue.get() >= limit)); }
@Override public void visitBinaryExpr(BinaryExpr binaryExpr) { super.visitBinaryExpr(binaryExpr); if (binaryExpr.getOp().isSideEffecting()) { if (binaryExpr.getLhs() instanceof VariableIdentifierExpr && ((VariableIdentifierExpr) binaryExpr.getLhs()).getName() .equals(loopCounterName)) { foundModification = true; } } }
@Override public void visitBinaryExpr(BinaryExpr binaryExpr) { boolean isSideEffecting = binaryExpr.getOp().isSideEffecting(); if (isSideEffecting) { enterLValueContext(); } visitChildFromParent(binaryExpr.getLhs(), binaryExpr); if (isSideEffecting) { exitLValueContext(); } visitChildFromParent(binaryExpr.getRhs(), binaryExpr); }
/** * Determines whether the given statement came from a live code injection. * * @param stmt A statement to be analysed * @return Whether the statement is injected live code or not */ public static boolean isSimpleLiveCodeInjection(Stmt stmt) { if (!(stmt instanceof ExprStmt)) { return false; } final Expr expr = ((ExprStmt) stmt).getExpr(); if (expr instanceof BinaryExpr) { if (!((BinaryExpr) expr).getOp().isSideEffecting()) { return false; } return isLiveInjectionVariableReference(((BinaryExpr) expr).getLhs()); } if (expr instanceof UnaryExpr) { if (!((UnaryExpr) expr).getOp().isSideEffecting()) { return false; } return isLiveInjectionVariableReference(((UnaryExpr) expr).getExpr()); } if (expr instanceof FunctionCallExpr) { return ((FunctionCallExpr) expr).getCallee().startsWith(Constants.LIVE_PREFIX); } return false; }