@Override public Expr generateExpr(IRandom generator, Expr... args) { assert args.length == getNumArguments(); return new ParenExpr(new UnaryExpr(args[0], op)); }
@Override public UnaryExpr clone() { return new UnaryExpr(expr.clone(), op); }
private List<Stmt> regionStackToStmts(List<List<Stmt>> regionStack) { if (regionStack.size() == 1) { return regionStack.get(0); } final List<Stmt> result = new ArrayList<>(); result.addAll(regionStack.get(0)); // Check that the remainder actually contains some statements if (regionStack.subList(1, regionStack.size()).stream().anyMatch(item -> !item.isEmpty())) { result.add(new IfStmt( new UnaryExpr(makeHasReturned(), UnOp.LNOT), new BlockStmt(regionStackToStmts( regionStack.subList(1, regionStack.size())), true), null)); } return result; }
private void handleLoop(LoopStmt loopStmt) { if (containsReturn(loopStmt)) { loopStmt.setCondition( new BinaryExpr( new ParenExpr(new UnaryExpr(makeHasReturned(), UnOp.LNOT)), loopStmt.getCondition(), BinOp.LAND)); } }
private void findFoldZeroSubSomethingOpportunities(IAstNode parent, Expr child, Expr lhs, Expr rhs) { if (isZeroFloat(lhs)) { addReplaceWithExpr(parent, child, new ParenExpr(new UnaryExpr(rhs, UnOp.MINUS))); } final Type childType = typer.lookupType(child); final Type rhsType = typer.lookupType(rhs); if (childType != null && rhsType != null && childType.getWithoutQualifiers().equals(rhsType.getWithoutQualifiers())) { if (isZeroFloatVecOrSquareMat(lhs)) { addReplaceWithExpr(parent, child, new ParenExpr(new UnaryExpr(rhs, UnOp.MINUS))); } } }
@Override public Expr visitUnary_expression(Unary_expressionContext ctx) { if (ctx.postfix_expression() != null) { return visitPostfix_expression(ctx.postfix_expression()); } if (ctx.INC_OP() != null) { return new UnaryExpr(visitUnary_expression(ctx.unary_expression()), UnOp.PRE_INC); } if (ctx.DEC_OP() != null) { return new UnaryExpr(visitUnary_expression(ctx.unary_expression()), UnOp.PRE_DEC); } assert ctx.unary_operator() != null; return new UnaryExpr(visitUnary_expression(ctx.unary_expression()), processUnaryOperator(ctx.unary_operator())); }
new BlockStmt(Arrays.asList(BreakStmt.INSTANCE), true), null), new ExprStmt(new UnaryExpr( new VariableIdentifierExpr(limiterName), UnOp.POST_INC)));
@Override public Expr visitPostfix_expression(Postfix_expressionContext ctx) { if (ctx.primary_expression() != null) { return visitPrimary_expression(ctx.primary_expression()); } if (ctx.LBRACKET() != null) { return new ArrayIndexExpr(visitPostfix_expression(ctx.postfix_expression()), visitExpression(ctx.integer_expression().expression())); } if (ctx.method_call_generic() != null) { // TODO: check grammar throw new RuntimeException("Not yet supported: " + getOriginalSourceText(ctx)); } if (ctx.IDENTIFIER() != null) { return new MemberLookupExpr(visitPostfix_expression(ctx.postfix_expression()), ctx.IDENTIFIER().getText()); } if (ctx.INC_OP() != null) { return new UnaryExpr(visitPostfix_expression(ctx.postfix_expression()), UnOp.POST_INC); } if (ctx.DEC_OP() != null) { return new UnaryExpr(visitPostfix_expression(ctx.postfix_expression()), UnOp.POST_DEC); } assert ctx.function_call_generic() != null; Expr result = visitFunction_call_generic(ctx.function_call_generic()); assert result != null; return result; }
private Stmt makeSingleIterationForStmt(Stmt stmt, OpaqueExpressionGenerator opaqueExpressionGenerator, Fuzzer fuzzer, IRandom generator, ShadingLanguageVersion shadingLanguageVersion) { boolean up = generator.nextBoolean(); String loopVariableName = "_injected_loop_counter_" + loopVariableCounter; loopVariableCounter++; boolean loopBoundsMustBeConst = shadingLanguageVersion.restrictedForLoops(); Expr start = up ? opaqueExpressionGenerator .makeOpaqueZero(BasicType.INT, loopBoundsMustBeConst, 0, fuzzer) : opaqueExpressionGenerator .makeOpaqueOne(BasicType.INT, loopBoundsMustBeConst, 0, fuzzer); DeclarationStmt init = new DeclarationStmt(new VariablesDeclaration(BasicType.INT, new VariableDeclInfo(loopVariableName, null, new ScalarInitializer(start)))); Expr end = up ? opaqueExpressionGenerator .makeOpaqueOne(BasicType.INT, loopBoundsMustBeConst, 0, fuzzer) : opaqueExpressionGenerator .makeOpaqueZero(BasicType.INT, loopBoundsMustBeConst, 0, fuzzer); BinOp testOp = generator.nextBoolean() ? (up ? BinOp.LT : BinOp.GT) : BinOp.NE; Expr test = new BinaryExpr(new VariableIdentifierExpr(loopVariableName), end, testOp); UnOp incOp = up ? UnOp.POST_INC : UnOp.POST_DEC; Expr inc = new UnaryExpr(new VariableIdentifierExpr(loopVariableName), incOp); return new ForStmt(init, makeWrappedLoopCondition(test), inc, stmt); }