@Test public void testLiteralUniformDefines() throws Exception { final String shaderWithBindings = "" + "layout(set = 0, binding = 0) uniform buf0 { int _GLF_uniform_int_values[2]; };" + "layout(set = 0, binding = 1) uniform buf1 { uint _GLF_uniform_uint_values[1]; };" + "layout(set = 0, binding = 2) uniform buf2 { float _GLF_uniform_float_values[3]; };" + "void main() { " + "int a = _GLF_uniform_int_values[0];" + "int b = _GLF_uniform_int_values[1];" + "uint c = _GLF_uniform_uint_values[0];" + "float d = _GLF_uniform_float_values[0];" + "float e = _GLF_uniform_float_values[1];" + "float f = _GLF_uniform_float_values[2];" + "}"; final String shaderPrettyPrinted = "" + "#define _int_0 _GLF_uniform_int_values[0]\n" + "#define _int_2 _GLF_uniform_int_values[1]\n" + "#define _uint_72 _GLF_uniform_uint_values[0]\n" + "#define _float_0_0 _GLF_uniform_float_values[0]\n" + "#define _float_22_4 _GLF_uniform_float_values[1]\n" + "#define _float_11_3 _GLF_uniform_float_values[2]\n" + "\n" + " + "layout(set = 0, binding = 0) uniform buf0 {\n" + " int _GLF_uniform_int_values[2];\n" + "};\n" + " + "layout(set = 0, binding = 1) uniform buf1 {\n" + " uint _GLF_uniform_uint_values[1];\n" + "};\n" + " + "layout(set = 0, binding = 2) uniform buf2 {\n" + " float _GLF_uniform_float_values[3];\n" + "};\n" + "void main()\n" + "{\n" + " int a = _int_0;\n" + " int b = _int_2;\n" + " uint c = _uint_72;\n" + " float d = _float_0_0;\n" + " float e = _float_22_4;\n" + " float f = _float_11_3;\n" + "}\n"; UniformValueSupplier uniformValues = name -> { if (name.equals("_GLF_uniform_int_values")) { return Optional.of(Arrays.asList("0", "2")); } else if (name.equals("_GLF_uniform_float_values")) { return Optional.of(Arrays.asList("0.0", "22.4", "11.3")); } else if (name.equals("_GLF_uniform_uint_values")) { return Optional.of(Arrays.asList("72")); } return Optional.empty(); }; assertEquals(shaderPrettyPrinted, PrettyPrinterVisitor.prettyPrintAsString(ParseHelper.parse(shaderWithBindings), uniformValues)); }
public static String prettyPrintAsString(IAstNode node) { ByteArrayOutputStream bytes = new ByteArrayOutputStream(); new PrettyPrinterVisitor(new PrintStream(bytes)).visit(node); return new String(bytes.toByteArray(), StandardCharsets.UTF_8); }
PrettyPrinterVisitor extends StandardVisitor { public static String prettyPrintAsString(IAstNode node) { ByteArrayOutputStream bytes = new ByteArrayOutputStream(); new PrettyPrinterVisitor(new PrintStream(bytes)).visit(node); return new String(bytes.toByteArray(), StandardCharsets.UTF_8); } }
PrettyPrinterVisitor extends StandardVisitor { public static String prettyPrintAsString(IAstNode node) { ByteArrayOutputStream bytes = new ByteArrayOutputStream(); new PrettyPrinterVisitor(new PrintStream(bytes)).visit(node); return new String(bytes.toByteArray(), StandardCharsets.UTF_8); } PrettyPrinterVisitor(PrintStream out);  PrettyPrinterVisitor(PrintStream out,
                              int indentationWidth,
                              Supplier<String> newLineSupplier,
                              boolean emitGraphicsFuzzDefines,
                              Optional<String> license,
                              Optional<UniformValueSupplier> uniformValues); }
PrettyPrinterVisitor extends StandardVisitor { public static String prettyPrintAsString(IAstNode node) { ByteArrayOutputStream bytes = new ByteArrayOutputStream(); new PrettyPrinterVisitor(new PrintStream(bytes)).visit(node); return new String(bytes.toByteArray(), StandardCharsets.UTF_8); } PrettyPrinterVisitor(PrintStream out);  PrettyPrinterVisitor(PrintStream out,
                              int indentationWidth,
                              Supplier<String> newLineSupplier,
                              boolean emitGraphicsFuzzDefines,
                              Optional<String> license,
                              Optional<UniformValueSupplier> uniformValues); static String prettyPrintAsString(IAstNode node); static String prettyPrintAsString(IAstNode node, UniformValueSupplier uniformValues); static void emitShader(TranslationUnit shader,
                                Optional<String> license,
                                PrintStream stream,
                                int indentationWidth,
                                Supplier<String> newlineSupplier); static void emitShader(TranslationUnit shader,
                                Optional<String> license,
                                PrintStream stream,
                                int indentationWidth,
                                Supplier<String> newlineSupplier,
                                Optional<UniformValueSupplier> uniformValueSupplier); @Override void visitPrecisionDeclaration(PrecisionDeclaration precisionDeclaration); @Override void visitDeclarationStmt(DeclarationStmt declarationStmt); @Override void visitVariablesDeclaration(VariablesDeclaration variablesDeclaration); @Override void visitFunctionDefinition(FunctionDefinition functionDefinition); @Override void visitFunctionPrototype(FunctionPrototype functionPrototype); @Override void visitParameterDecl(ParameterDecl parameterDecl); @Override void visitBlockStmt(BlockStmt stmt); @Override void visitIfStmt(IfStmt ifStmt); @Override void visitBinaryExpr(BinaryExpr binaryExpr); @Override void visitParenExpr(ParenExpr parenExpr); @Override void visitVariableIdentifierExpr(VariableIdentifierExpr variableIdentifierExpr); @Override void visitUnaryExpr(UnaryExpr unaryExpr); @Override void visitMemberLookupExpr(MemberLookupExpr memberLookupExpr); @Override void visitIntConstantExpr(IntConstantExpr intConstantExpr); @Override void visitUIntConstantExpr(UIntConstantExpr intConstantExpr); @Override void visitFloatConstantExpr(FloatConstantExpr floatConstantExpr); @Override void visitBoolConstantExpr(BoolConstantExpr boolConstantExpr); @Override void visitBreakStmt(BreakStmt breakStmt); @Override void visitContinueStmt(ContinueStmt continueStmt); @Override void visitDiscardStmt(DiscardStmt discardStmt); @Override void visitReturnStmt(ReturnStmt returnStmt); @Override void visitExprStmt(ExprStmt exprStmt); @Override void visitFunctionCallExpr(FunctionCallExpr functionCallExpr); @Override void visitTypeConstructorExpr(TypeConstructorExpr typeConstructorExpr); @Override void visitQualifiedType(QualifiedType qualifiedType); @Override void visitBasicType(BasicType basicType); @Override void visitSamplerType(SamplerType samplerType); @Override void visitImageType(ImageType imageType); @Override void visitVoidType(VoidType voidType); @Override void visitAtomicIntType(AtomicIntType atomicIntType); @Override void visitNullStmt(NullStmt nullStmt); @Override void visitWhileStmt(WhileStmt whileStmt); @Override void visitForStmt(ForStmt forStmt); @Override void visitDoStmt(DoStmt doStmt); @Override void visitTernaryExpr(TernaryExpr ternaryExpr); @Override void visitArrayIndexExpr(ArrayIndexExpr arrayIndexExpr); @Override void visitStructNameType(StructNameType structNameType); @Override void visitArrayType(ArrayType arrayType); @Override void visitArrayConstructorExpr(ArrayConstructorExpr arrayConstructorExpr); @Override void visitStructDefinitionType(StructDefinitionType structDefinitionType); @Override void visitSwitchStmt(SwitchStmt switchStmt); @Override void visitDefaultCaseLabel(DefaultCaseLabel defaultCaseLabel); @Override void visitExprCaseLabel(ExprCaseLabel exprCaseLabel); @Override void visitInterfaceBlock(InterfaceBlock interfaceBlock); @Override void visitDefaultLayout(DefaultLayout defaultLayout); @Override void visitTranslationUnit(TranslationUnit translationUnit); @Override void visitPragmaStatement(PragmaStatement pragmaStatement); @Override void visitExtensionStatement(ExtensionStatement extensionStatement); @Override String toString(); static String defaultIndent(int level); static void emitGraphicsFuzzDefines(PrintStream out,
                                             ShadingLanguageVersion shadingLanguageVersion); }
PrettyPrinterVisitor extends StandardVisitor { public static String prettyPrintAsString(IAstNode node) { ByteArrayOutputStream bytes = new ByteArrayOutputStream(); new PrettyPrinterVisitor(new PrintStream(bytes)).visit(node); return new String(bytes.toByteArray(), StandardCharsets.UTF_8); } PrettyPrinterVisitor(PrintStream out);  PrettyPrinterVisitor(PrintStream out,
                              int indentationWidth,
                              Supplier<String> newLineSupplier,
                              boolean emitGraphicsFuzzDefines,
                              Optional<String> license,
                              Optional<UniformValueSupplier> uniformValues); static String prettyPrintAsString(IAstNode node); static String prettyPrintAsString(IAstNode node, UniformValueSupplier uniformValues); static void emitShader(TranslationUnit shader,
                                Optional<String> license,
                                PrintStream stream,
                                int indentationWidth,
                                Supplier<String> newlineSupplier); static void emitShader(TranslationUnit shader,
                                Optional<String> license,
                                PrintStream stream,
                                int indentationWidth,
                                Supplier<String> newlineSupplier,
                                Optional<UniformValueSupplier> uniformValueSupplier); @Override void visitPrecisionDeclaration(PrecisionDeclaration precisionDeclaration); @Override void visitDeclarationStmt(DeclarationStmt declarationStmt); @Override void visitVariablesDeclaration(VariablesDeclaration variablesDeclaration); @Override void visitFunctionDefinition(FunctionDefinition functionDefinition); @Override void visitFunctionPrototype(FunctionPrototype functionPrototype); @Override void visitParameterDecl(ParameterDecl parameterDecl); @Override void visitBlockStmt(BlockStmt stmt); @Override void visitIfStmt(IfStmt ifStmt); @Override void visitBinaryExpr(BinaryExpr binaryExpr); @Override void visitParenExpr(ParenExpr parenExpr); @Override void visitVariableIdentifierExpr(VariableIdentifierExpr variableIdentifierExpr); @Override void visitUnaryExpr(UnaryExpr unaryExpr); @Override void visitMemberLookupExpr(MemberLookupExpr memberLookupExpr); @Override void visitIntConstantExpr(IntConstantExpr intConstantExpr); @Override void visitUIntConstantExpr(UIntConstantExpr intConstantExpr); @Override void visitFloatConstantExpr(FloatConstantExpr floatConstantExpr); @Override void visitBoolConstantExpr(BoolConstantExpr boolConstantExpr); @Override void visitBreakStmt(BreakStmt breakStmt); @Override void visitContinueStmt(ContinueStmt continueStmt); @Override void visitDiscardStmt(DiscardStmt discardStmt); @Override void visitReturnStmt(ReturnStmt returnStmt); @Override void visitExprStmt(ExprStmt exprStmt); @Override void visitFunctionCallExpr(FunctionCallExpr functionCallExpr); @Override void visitTypeConstructorExpr(TypeConstructorExpr typeConstructorExpr); @Override void visitQualifiedType(QualifiedType qualifiedType); @Override void visitBasicType(BasicType basicType); @Override void visitSamplerType(SamplerType samplerType); @Override void visitImageType(ImageType imageType); @Override void visitVoidType(VoidType voidType); @Override void visitAtomicIntType(AtomicIntType atomicIntType); @Override void visitNullStmt(NullStmt nullStmt); @Override void visitWhileStmt(WhileStmt whileStmt); @Override void visitForStmt(ForStmt forStmt); @Override void visitDoStmt(DoStmt doStmt); @Override void visitTernaryExpr(TernaryExpr ternaryExpr); @Override void visitArrayIndexExpr(ArrayIndexExpr arrayIndexExpr); @Override void visitStructNameType(StructNameType structNameType); @Override void visitArrayType(ArrayType arrayType); @Override void visitArrayConstructorExpr(ArrayConstructorExpr arrayConstructorExpr); @Override void visitStructDefinitionType(StructDefinitionType structDefinitionType); @Override void visitSwitchStmt(SwitchStmt switchStmt); @Override void visitDefaultCaseLabel(DefaultCaseLabel defaultCaseLabel); @Override void visitExprCaseLabel(ExprCaseLabel exprCaseLabel); @Override void visitInterfaceBlock(InterfaceBlock interfaceBlock); @Override void visitDefaultLayout(DefaultLayout defaultLayout); @Override void visitTranslationUnit(TranslationUnit translationUnit); @Override void visitPragmaStatement(PragmaStatement pragmaStatement); @Override void visitExtensionStatement(ExtensionStatement extensionStatement); @Override String toString(); static String defaultIndent(int level); static void emitGraphicsFuzzDefines(PrintStream out,
                                             ShadingLanguageVersion shadingLanguageVersion); static final int DEFAULT_INDENTATION_WIDTH; static final Supplier<String> DEFAULT_NEWLINE_SUPPLIER; }