@Override public void applyReductionImpl() { BlockStmt replacement = new BlockStmt(new ArrayList<>(), true); boolean reachedOriginalCode = false; for (Stmt stmt : switchStmt.getBody().getStmts()) { if (!reachedOriginalCode) { if (!(stmt instanceof ExprCaseLabel && isZeroLabel((ExprCaseLabel) stmt))) { continue; } reachedOriginalCode = true; } if (stmt instanceof BreakStmt) { break; } if (stmt instanceof CaseLabel) { continue; } replacement.addStmt(stmt); } parent.replaceChild(switchStmt, replacement); }
private FunctionDefinition fuzzFunction() { fuzzingContext.enterScope(); List<ParameterDecl> params = new ArrayList<>(); for (int i = 0; i < generator.nextInt(MAX_FUNCTION_PARAMS); i++) { final String name = "p" + i; final Type type = fuzzType(); // TODO: consider adding array parameters final ParameterDecl parameterDecl = new ParameterDecl(name, type, null); fuzzingContext.addParameter(parameterDecl); params.add(parameterDecl); } FunctionPrototype prototype = new FunctionPrototype(createName("f"), fuzzType(), params); fuzzingContext.enterFunction(prototype); final BlockStmt body = fuzzBlockStmt(false); if (!containsReturnStmt(body)) { body.addStmt(fuzzReturnStmt()); } FunctionDefinition functionDefinition = new FunctionDefinition( prototype, body); fuzzingContext.leaveFunction(); fuzzingContext.leaveScope(); return functionDefinition; }
private void addSpecialDeclarations() { if (fd.getPrototype().getReturnType().getWithoutQualifiers() != VoidType.VOID) { fd.getBody().insertStmt(0, new DeclarationStmt( new VariablesDeclaration(fd.getPrototype().getReturnType().getWithoutQualifiers(), new VariableDeclInfo(makeReturnValueName(), null, null)))); fd.getBody().addStmt(new ReturnStmt(makeReturnValue())); } fd.getBody().insertStmt(0, new DeclarationStmt( new VariablesDeclaration(BasicType.BOOL, new VariableDeclInfo(makeHasReturnedName(), null, new ScalarInitializer(BoolConstantExpr.FALSE))))); }