public static void emitShader(TranslationUnit shader, Optional<String> license, PrintStream stream, int indentationWidth, Supplier<String> newlineSupplier, boolean emitGraphicsFuzzDefines) { new PrettyPrinterVisitor(stream, indentationWidth, newlineSupplier, emitGraphicsFuzzDefines, license).visit(shader); }
@Override public void visitBlockStmt(BlockStmt stmt) { out.append(indent() + "{" + newLine()); increaseIndent(); for (Stmt s : stmt.getStmts()) { visit(s); } decreaseIndent(); out.append(indent() + "}" + newLine()); }
@Override public void visitArrayType(ArrayType arrayType) { // Do not generate array info, as this has to come after the associated variable name visit(arrayType.getBaseType()); }
public static void assertEqualAsts(TranslationUnit first, TranslationUnit second) throws IOException, ParseTimeoutException { assertEqualAsts(PrettyPrinterVisitor.prettyPrintAsString(first), PrettyPrinterVisitor.prettyPrintAsString(second)); }
@Override protected <T extends IAstNode> void visitChildFromParent(Consumer<T> visitorMethod, T child, IAstNode parent) { super.visitChildFromParent(visitorMethod, child, parent); if (parent instanceof TranslationUnit && child instanceof VariablesDeclaration) { out.append(";" + newLine() + newLine()); } }
private static void writeShader( TranslationUnit tu, Optional<String> license, File outputFile, boolean emitGraphicsFuzzDefines ) throws FileNotFoundException { try (PrintStream stream = ps(outputFile)) { PrettyPrinterVisitor.emitShader( tu, license, stream, PrettyPrinterVisitor.DEFAULT_INDENTATION_WIDTH, PrettyPrinterVisitor.DEFAULT_NEWLINE_SUPPLIER, emitGraphicsFuzzDefines ); } }
@Override public void visitDoStmt(DoStmt doStmt) { out.append(indent() + "do" + newLine()); increaseIndent(); visit(doStmt.getBody()); decreaseIndent(); out.append(indent() + "while("); visit(doStmt.getCondition()); out.append(");" + newLine()); }
public static boolean isEqualAsts(String first, TranslationUnit second) throws IOException, ParseTimeoutException { return isEqualAsts(first, PrettyPrinterVisitor.prettyPrintAsString(second)); }
@Override public void visitWhileStmt(WhileStmt whileStmt) { out.append(indent() + "while("); visit(whileStmt.getCondition()); out.append(")" + newLine()); increaseIndent(); visit(whileStmt.getBody()); decreaseIndent(); }
@Override public void visitParenExpr(ParenExpr parenExpr) { out.append("("); visit(parenExpr.getExpr()); out.append(")"); }
public static void assertEqualAsts(String string, TranslationUnit tu) throws IOException, ParseTimeoutException { assertEqualAsts(string, PrettyPrinterVisitor.prettyPrintAsString(tu)); }
@Override public void visitMemberLookupExpr(MemberLookupExpr memberLookupExpr) { visit(memberLookupExpr.getStructure()); out.append("." + memberLookupExpr.getMember()); }
public static boolean isEqualAsts(String first, String second) throws IOException, ParseTimeoutException { return PrettyPrinterVisitor.prettyPrintAsString(ParseHelper.parse(first)) .equals( PrettyPrinterVisitor.prettyPrintAsString(ParseHelper.parse(second))); }
@Override public void visitQualifiedType(QualifiedType qualifiedType) { for (TypeQualifier q : qualifiedType.getQualifiers()) { out.append(q + " "); } visit(qualifiedType.getTargetType()); }