diff --git a/common/src/main/java/foundry/veil/impl/client/render/dynamicbuffer/DynamicBufferProcessor.java b/common/src/main/java/foundry/veil/impl/client/render/dynamicbuffer/DynamicBufferProcessor.java index 998712c2..a439560e 100644 --- a/common/src/main/java/foundry/veil/impl/client/render/dynamicbuffer/DynamicBufferProcessor.java +++ b/common/src/main/java/foundry/veil/impl/client/render/dynamicbuffer/DynamicBufferProcessor.java @@ -171,8 +171,8 @@ public String modify(Context ctx, String source) throws IOException { // Inject Normal passthrough into vertex and fragment shaders if (type == DynamicBufferType.NORMAL && !markers.containsKey("veil:" + DynamicBufferType.NORMAL.getName())) { - // Inject a normal output into the particle fragment shader - if (fragmentShader && "particle".equals(ctx.shaderInstance())) { + // Inject a normal output into the particle, lead, and text fragment shaders + if (fragmentShader && ("particle".equals(ctx.shaderInstance()) || "rendertype_leash".equals(ctx.shaderInstance()) || "rendertype_text".equals(ctx.shaderInstance()))) { tree.add(GlslInjectionPoint.BEFORE_MAIN, GlslParser.parseExpression(output)); mainFunctionBody.add(new GlslAssignmentNode(new GlslVariableNode(type.getSourceName()), GlslParser.parseExpression("vec4(0.0, 0.0, 1.0, 1.0)"), GlslAssignmentNode.Operand.EQUAL)); modified = true; diff --git a/common/src/main/java/foundry/veil/impl/client/render/shader/modifier/SimpleShaderModification.java b/common/src/main/java/foundry/veil/impl/client/render/shader/modifier/SimpleShaderModification.java index 41628af8..bab904be 100644 --- a/common/src/main/java/foundry/veil/impl/client/render/shader/modifier/SimpleShaderModification.java +++ b/common/src/main/java/foundry/veil/impl/client/render/shader/modifier/SimpleShaderModification.java @@ -84,7 +84,7 @@ public void inject(GlslTree tree, VeilJobParameters parameters) throws GlslSynta return new IOException("Unknown function with " + paramCount + " parameters: " + name); }); - GlslNode insert = new GlslCompoundNode(GlslParser.parseExpressionList(this.fillPlaceholders(function.code()))); + GlslNode insert = GlslNode.compound(GlslParser.parseExpressionList(this.fillPlaceholders(function.code()))); if (function.head()) { body.add(0, insert); } else { diff --git a/common/src/main/java/foundry/veil/impl/glsl/GlslLexer.java b/common/src/main/java/foundry/veil/impl/glsl/GlslLexer.java index 25a73e55..c2b4b010 100644 --- a/common/src/main/java/foundry/veil/impl/glsl/GlslLexer.java +++ b/common/src/main/java/foundry/veil/impl/glsl/GlslLexer.java @@ -247,9 +247,9 @@ public enum TokenType { // TYPE_NAME ?? FLOATING_CONSTANT("(?:(?:\\d+\\.\\d+|\\d+\\.|\\.\\d+)(?:[eE][+-]?\\d+)?(?:f|F|lf|LF)?)|(?:\\d+)(?:\\.|[eE][+-]?\\d+)(?:f|F|lf|LF)?"), - UINTEGER_HEXADECIMAL_CONSTANT("0[xX][0-9a-fA-F]*[uU]?"), - UINTEGER_OCTAL_CONSTANT("0[0-7]*[uU]?"), - UINTEGER_DECIMAL_CONSTANT("[1-9][\\d]*[uU]?"), + UINTEGER_HEXADECIMAL_CONSTANT("0[xX][0-9a-fA-F]*[uU]"), + UINTEGER_OCTAL_CONSTANT("0[0-7]*[uU]"), + UINTEGER_DECIMAL_CONSTANT("[1-9][\\d]*[uU]"), INTEGER_HEXADECIMAL_CONSTANT("0[xX][0-9a-fA-F]*"), INTEGER_OCTAL_CONSTANT("0[0-7]*"), INTEGER_DECIMAL_CONSTANT("[1-9][\\d]*"), diff --git a/common/src/main/java/foundry/veil/impl/glsl/GlslParser.java b/common/src/main/java/foundry/veil/impl/glsl/GlslParser.java index 06626a1d..203a50ed 100644 --- a/common/src/main/java/foundry/veil/impl/glsl/GlslParser.java +++ b/common/src/main/java/foundry/veil/impl/glsl/GlslParser.java @@ -62,10 +62,12 @@ public static GlslTree parse(String input) throws GlslSyntaxException { } cursor = reader.getCursor(); - GlslNode declaration = parseDeclaration(reader); - if (declaration != null) { - reader.markNode(cursor, declaration); - body.add(declaration); + List declarations = parseDeclaration(reader); + if (declarations != null) { + for (GlslNode declaration : declarations) { + reader.markNode(cursor, declaration); + body.add(declaration); + } continue; } @@ -85,7 +87,7 @@ public static GlslNode parseExpression(String input) throws GlslSyntaxException public static GlslNode parseExpression(GlslLexer.Token[] tokens) throws GlslSyntaxException { GlslTokenReader reader = new GlslTokenReader(tokens); - GlslNode expression = parseStatement(reader); + List expression = parseStatement(reader); if (expression == null) { reader.throwError(); } @@ -98,7 +100,7 @@ public static GlslNode parseExpression(GlslLexer.Token[] tokens) throws GlslSynt if (reader.canRead()) { throw reader.error("Too many tokens provided"); } - return expression; + return GlslNode.compound(expression); } public static List parseExpressionList(String input) throws GlslSyntaxException { @@ -131,7 +133,7 @@ public static List parseExpressionList(GlslLexer.Token[] tokens) throw return new GlslIntConstantNode(GlslIntFormat.DECIMAL, true, Integer.parseUnsignedInt(reader.peek(-1).value(), 10)); } if (reader.tryConsume(GlslLexer.TokenType.INTEGER_HEXADECIMAL_CONSTANT)) { - return new GlslIntConstantNode(GlslIntFormat.HEXADECIMAL, true, Integer.parseUnsignedInt(reader.peek(-1).value(), 16)); + return new GlslIntConstantNode(GlslIntFormat.HEXADECIMAL, true, Integer.parseUnsignedInt(reader.peek(-1).value().substring(2), 16)); } if (reader.tryConsume(GlslLexer.TokenType.INTEGER_OCTAL_CONSTANT)) { return new GlslIntConstantNode(GlslIntFormat.OCTAL, true, Integer.parseUnsignedInt(reader.peek(-1).value(), 8)); @@ -144,7 +146,7 @@ public static List parseExpressionList(GlslLexer.Token[] tokens) throw return new GlslIntConstantNode(GlslIntFormat.DECIMAL, false, Integer.parseUnsignedInt(value, 10)); } if (reader.tryConsume(GlslLexer.TokenType.UINTEGER_HEXADECIMAL_CONSTANT)) { - String value = reader.peek(-1).value(); + String value = reader.peek(-1).value().substring(2); if (value.endsWith("u")) { value = value.substring(0, value.length() - 1); } @@ -242,6 +244,15 @@ public static List parseExpressionList(GlslLexer.Token[] tokens) throw if (integerExpression != null && reader.tryConsume(GlslLexer.TokenType.RIGHT_BRACKET)) { primaryExpression = new GlslArrayNode(primaryExpression, integerExpression); expressionCursor = reader.getCursor(); + + // primary_expression LEFT_BRACKET integer_expression RIGHT_BRACKET LEFT_BRACKET integer_expression RIGHT_BRACKET + if (reader.tryConsume(GlslLexer.TokenType.LEFT_BRACKET)) { + GlslNode integerExpression2 = parseIntegerExpression(reader); + if (integerExpression2 != null && reader.tryConsume(GlslLexer.TokenType.RIGHT_BRACKET)) { + primaryExpression = new GlslArrayNode(primaryExpression, integerExpression); + expressionCursor = reader.getCursor(); + } + } } } reader.setCursor(expressionCursor); @@ -731,7 +742,7 @@ public static List parseExpressionList(GlslLexer.Token[] tokens) throw return GlslNode.compound(expressions); } - private static @Nullable GlslNode parseDeclaration(GlslTokenReader reader) { + private static @Nullable List parseDeclaration(GlslTokenReader reader) { // function_prototype SEMICOLON // init_declarator_list SEMICOLON // PRECISION precision_qualifier type_specifier SEMICOLON @@ -748,13 +759,13 @@ public static List parseExpressionList(GlslLexer.Token[] tokens) throw GlslFunctionHeader functionPrototype = parseFunctionPrototype(reader); if (functionPrototype != null) { if (reader.tryConsume(GlslLexer.TokenType.SEMICOLON)) { - return new GlslFunctionNode(functionPrototype, null); + return Collections.singletonList(new GlslFunctionNode(functionPrototype, null)); } reader.setCursor(cursor); } // init_declarator_list SEMICOLON - GlslNode initDeclaratorList = parseInitDeclaratorList(reader); + List initDeclaratorList = parseInitDeclaratorList(reader); if (initDeclaratorList != null) { if (reader.tryConsume(GlslLexer.TokenType.SEMICOLON)) { return initDeclaratorList; @@ -768,7 +779,7 @@ public static List parseExpressionList(GlslLexer.Token[] tokens) throw if (precisionQualifier != null) { GlslTypeSpecifier typeSpecifier = parseTypeSpecifier(reader); if (typeSpecifier != null && reader.tryConsume(GlslLexer.TokenType.SEMICOLON)) { - return new GlslPrecisionNode(precisionQualifier, typeSpecifier); + return Collections.singletonList(new GlslPrecisionNode(precisionQualifier, typeSpecifier)); } } reader.setCursor(cursor); @@ -779,7 +790,6 @@ public static List parseExpressionList(GlslLexer.Token[] tokens) throw return null; } - // FIXME cursor = reader.getCursor(); if (reader.tryConsume(GlslLexer.TokenType.IDENTIFIER, GlslLexer.TokenType.LEFT_BRACE)) { String identifier = reader.peek(-2).value(); @@ -791,7 +801,7 @@ public static List parseExpressionList(GlslLexer.Token[] tokens) throw // type_qualifier IDENTIFIER LEFT_BRACE struct_declaration_list RIGHT_BRACE SEMICOLON if (reader.tryConsume(GlslLexer.TokenType.SEMICOLON)) { - return new GlslStructNode(structSpecifier); + return Collections.singletonList(new GlslStructNode(structSpecifier)); } if (reader.tryConsume(GlslLexer.TokenType.IDENTIFIER)) { @@ -799,13 +809,13 @@ public static List parseExpressionList(GlslLexer.Token[] tokens) throw // type_qualifier IDENTIFIER LEFT_BRACE struct_declaration_list RIGHT_BRACE IDENTIFIER SEMICOLON if (reader.tryConsume(GlslLexer.TokenType.SEMICOLON)) { - return new GlslNewNode(structSpecifier, label, null); + return Collections.singletonList(new GlslNewNode(structSpecifier, label, null)); } // type_qualifier IDENTIFIER LEFT_BRACE struct_declaration_list RIGHT_BRACE IDENTIFIER array_specifier SEMICOLON GlslSpecifiedType arraySpecifier = parseArraySpecifier(reader, structSpecifier); if (arraySpecifier != null && reader.tryConsume(GlslLexer.TokenType.SEMICOLON)) { - return new GlslNewNode(arraySpecifier, label, null); + return Collections.singletonList(new GlslNewNode(arraySpecifier, label, null)); } } } @@ -816,16 +826,28 @@ public static List parseExpressionList(GlslLexer.Token[] tokens) throw // type_qualifier SEMICOLON if (reader.tryConsume(GlslLexer.TokenType.SEMICOLON)) { - return new GlslDeclaration(typeQualifier, Collections.emptyList()); + return Collections.singletonList(new GlslDeclaration(typeQualifier, Collections.emptyList())); } + GlslTypeSpecifier typeSpecifier = null; + // type_qualifier IDENTIFIER SEMICOLON // type_qualifier IDENTIFIER identifier_list SEMICOLON List identifiers = parseIdentifierList(reader); if (identifiers == null) { - reader.markError("Expected ';'"); - reader.setCursor(cursor); - return null; + typeSpecifier = parseTypeSpecifier(reader); + if (typeSpecifier == null) { + reader.markError("Expected ';'"); + reader.setCursor(cursor); + return null; + } + + identifiers = parseIdentifierList(reader); + if (identifiers == null) { + reader.markError("Expected ';'"); + reader.setCursor(cursor); + return null; + } } if (!reader.tryConsume(GlslLexer.TokenType.SEMICOLON)) { @@ -834,7 +856,12 @@ public static List parseExpressionList(GlslLexer.Token[] tokens) throw return null; } - return new GlslDeclaration(typeQualifier, identifiers); + // Small hack to detect uniform float a, b, c; + if (typeSpecifier != null) { + GlslSpecifiedType type = new GlslSpecifiedType(typeSpecifier, typeQualifier); + return identifiers.stream().map(name -> (GlslNode) new GlslNewNode(type, name, null)).toList(); + } + return Collections.singletonList(new GlslDeclaration(typeQualifier, identifiers)); } private static @Nullable List parseIdentifierList(GlslTokenReader reader) { @@ -995,27 +1022,65 @@ private static List parseParameterList(GlslTokenReader return null; } - private static @Nullable GlslNode parseInitDeclaratorList(GlslTokenReader reader) { + private static @Nullable List parseInitDeclaratorList(GlslTokenReader reader) { // single_declaration // init_declarator_list COMMA IDENTIFIER // init_declarator_list COMMA IDENTIFIER array_specifier // init_declarator_list COMMA IDENTIFIER array_specifier EQUAL initializer // init_declarator_list COMMA IDENTIFIER EQUAL initializer + int cursor = reader.getCursor(); List initDeclaratorList = new ArrayList<>(); while (reader.canRead()) { GlslNode singleDeclaration = parseSingleDeclaration(reader); if (singleDeclaration == null) { + reader.setCursor(cursor); break; } initDeclaratorList.add(singleDeclaration); - } + cursor = reader.getCursor(); - if (initDeclaratorList.isEmpty()) { - return null; + if (reader.tryConsume(GlslLexer.TokenType.COMMA)) { + if (!reader.tryConsume(GlslLexer.TokenType.IDENTIFIER)) { + reader.setCursor(cursor); + break; + } + + int cursor2 = reader.getCursor(); + String name = reader.peek(-1).value(); + GlslSpecifiedType type = Objects.requireNonNull(singleDeclaration.getType()); + GlslSpecifiedType arraySpecifier = parseArraySpecifier(reader, type); + if (arraySpecifier != null) { + if (!reader.tryConsume(GlslLexer.TokenType.EQUAL)) { + // IDENTIFIER array_specifier + initDeclaratorList.add(new GlslNewNode(arraySpecifier, name, null)); + cursor = reader.getCursor(); + continue; + } + + GlslNode initializer = parseInitializer(reader); + if (initializer != null) { + // IDENTIFIER array_specifier EQUAL initializer + initDeclaratorList.add(new GlslNewNode(arraySpecifier, name, initializer)); + cursor = reader.getCursor(); + continue; + } + } + reader.setCursor(cursor2); + + if (reader.tryConsume(GlslLexer.TokenType.EQUAL)) { + GlslNode initializer = parseInitializer(reader); + if (initializer != null) { + // IDENTIFIER EQUAL initializer + initDeclaratorList.add(new GlslNewNode(type, name, initializer)); + cursor = reader.getCursor(); + } + } + } } - return GlslNode.compound(initDeclaratorList); + + return !initDeclaratorList.isEmpty() ? initDeclaratorList : null; } private static @Nullable GlslNode parseSingleDeclaration(GlslTokenReader reader) { @@ -1490,13 +1555,13 @@ private static List parseInitializerList(GlslTokenReader reader) { int cursor = reader.getCursor(); List initializers = new ArrayList<>(); while (reader.canRead()) { - GlslNode statement = parseStatement(reader); - if (statement == null) { + List statements = parseStatement(reader); + if (statements == null) { reader.setCursor(cursor); break; } - initializers.add(statement); + initializers.addAll(statements); cursor = reader.getCursor(); if (!reader.tryConsume(GlslLexer.TokenType.COMMA)) { @@ -1507,7 +1572,7 @@ private static List parseInitializerList(GlslTokenReader reader) { return initializers; } - private static @Nullable GlslNode parseStatement(GlslTokenReader reader) { + private static @Nullable List parseStatement(GlslTokenReader reader) { // compound_statement // simple_statement @@ -1517,22 +1582,24 @@ private static List parseInitializerList(GlslTokenReader reader) { GlslNode compoundStatement = parseCompoundStatement(reader); if (compoundStatement != null) { reader.markNode(cursor, compoundStatement); - return compoundStatement; + return Collections.singletonList(compoundStatement); } reader.setCursor(cursor); // simple_statement - GlslNode simpleStatement = parseSimpleStatement(reader); - if (simpleStatement != null) { - reader.markNode(cursor, simpleStatement); - return simpleStatement; + List simpleStatements = parseSimpleStatement(reader); + if (simpleStatements != null) { + for (GlslNode simpleStatement : simpleStatements) { + reader.markNode(cursor, simpleStatement); + } + return simpleStatements; } reader.setCursor(cursor); return null; } - private static @Nullable GlslNode parseSimpleStatement(GlslTokenReader reader) { + private static @Nullable List parseSimpleStatement(GlslTokenReader reader) { // declaration_statement // expression_statement // selection_statement @@ -1545,47 +1612,47 @@ private static List parseInitializerList(GlslTokenReader reader) { GlslNode statement; // declaration_statement -> declaration - statement = parseDeclaration(reader); - if (statement != null) { - return statement; + List declaration = parseDeclaration(reader); + if (declaration != null) { + return declaration; } reader.setCursor(cursor); // expression_statement statement = parseExpressionStatement(reader); if (statement != null) { - return statement; + return Collections.singletonList(statement); } reader.setCursor(cursor); // selection_statement statement = parseSelectionStatement(reader); if (statement != null) { - return statement; + return Collections.singletonList(statement); } reader.setCursor(cursor); statement = parseSwitchStatement(reader); if (statement != null) { - return statement; + return Collections.singletonList(statement); } reader.setCursor(cursor); statement = parseCaseLabel(reader); if (statement != null) { - return statement; + return Collections.singletonList(statement); } reader.setCursor(cursor); statement = parseIterationStatement(reader); if (statement != null) { - return statement; + return Collections.singletonList(statement); } reader.setCursor(cursor); statement = parseJumpStatement(reader); if (statement != null) { - return statement; + return Collections.singletonList(statement); } reader.setCursor(cursor); @@ -1625,7 +1692,8 @@ private static List parseInitializerList(GlslTokenReader reader) { } // simple_statement - return parseSimpleStatement(reader); + List statements = parseSimpleStatement(reader); + return statements!=null?GlslNode.compound(statements):null; } private static @Nullable GlslNode parseCompoundStatementNoNewScope(GlslTokenReader reader) { @@ -1650,12 +1718,12 @@ private static List parseInitializerList(GlslTokenReader reader) { private static List parseStatementList(GlslTokenReader reader) { List statements = new ArrayList<>(); while (reader.canRead()) { - GlslNode statement = parseStatement(reader); + List statement = parseStatement(reader); if (statement == null) { break; } - statements.add(statement); + statements.addAll(statement); } return statements; @@ -1679,11 +1747,11 @@ private static List parseStatementList(GlslTokenReader reader) { // IF LEFT_PAREN condition RIGHT_PAREN statement ELSE statement // IF LEFT_PAREN condition RIGHT_PAREN statement + int cursor = reader.getCursor(); if (!reader.tryConsume(GlslLexer.TokenType.IF)) { return null; } - int cursor = reader.getCursor(); if (!reader.tryConsume(GlslLexer.TokenType.LEFT_PAREN)) { reader.markError("Expected '('"); reader.setCursor(cursor); @@ -1703,8 +1771,8 @@ private static List parseStatementList(GlslTokenReader reader) { } // selection_rest_statement - GlslNode statement = parseStatement(reader); - if (statement == null) { + List statements = parseStatement(reader); + if (statements == null) { reader.setCursor(cursor); return null; } @@ -1713,9 +1781,9 @@ private static List parseStatementList(GlslTokenReader reader) { // statement ELSE statement if (reader.tryConsume(GlslLexer.TokenType.ELSE)) { - GlslNode otherStatement = parseStatement(reader); - if (otherStatement != null) { - return new GlslSelectionNode(expression, statement, otherStatement); + List otherStatements = parseStatement(reader); + if (otherStatements != null) { + return new GlslSelectionNode(expression, GlslNode.compound(statements), GlslNode.compound(otherStatements)); } reader.setCursor(cursor); @@ -1723,7 +1791,7 @@ private static List parseStatementList(GlslTokenReader reader) { } reader.setCursor(cursor); - return new GlslSelectionNode(expression, statement, GlslEmptyNode.INSTANCE); + return new GlslSelectionNode(expression, GlslNode.compound(statements), GlslEmptyNode.INSTANCE); } private static @Nullable GlslNode parseCondition(GlslTokenReader reader) { @@ -1799,11 +1867,11 @@ private static List parseStatementList(GlslTokenReader reader) { // DO statement WHILE LEFT_PAREN condition RIGHT_PAREN SEMICOLON if (reader.tryConsume(GlslLexer.TokenType.DO)) { - GlslNode body = parseStatement(reader); + List body = parseStatement(reader); if (body != null && reader.tryConsume(GlslLexer.TokenType.WHILE, GlslLexer.TokenType.LEFT_PAREN)) { GlslNode condition = parseCondition(reader); if (condition != null && reader.tryConsume(GlslLexer.TokenType.RIGHT_PAREN, GlslLexer.TokenType.SEMICOLON)) { - return new WhileLoopNode(condition, body, WhileLoopNode.Type.DO); + return new WhileLoopNode(condition, GlslNode.compound(body), WhileLoopNode.Type.DO); } } } @@ -1837,7 +1905,8 @@ private static List parseStatementList(GlslTokenReader reader) { } // declaration_statement - return parseDeclaration(reader); + List declaration = parseDeclaration(reader); + return declaration != null ? GlslNode.compound(declaration) : null; } private static GlslNode parseConditionopt(GlslTokenReader reader) { diff --git a/common/src/main/java/foundry/veil/impl/glsl/grammar/GlslFunctionHeader.java b/common/src/main/java/foundry/veil/impl/glsl/grammar/GlslFunctionHeader.java index 6eeef966..f886428e 100644 --- a/common/src/main/java/foundry/veil/impl/glsl/grammar/GlslFunctionHeader.java +++ b/common/src/main/java/foundry/veil/impl/glsl/grammar/GlslFunctionHeader.java @@ -50,13 +50,14 @@ public String toString() { } public String getSourceString() { - return this.returnType.getSourceString() + ' ' + this.name + '(' + + return this.returnType.getSourceString() + this.returnType.getPostSourceString() + ' ' + this.name + '(' + this.parameters.stream().map(parameter -> { String name = parameter.getName(); + GlslSpecifiedType type = parameter.getType(); if (name != null) { - return parameter.getType().getSourceString() + " " + name; + return type.getSourceString() + " " + name + type.getPostSourceString(); } - return parameter.getType().getSourceString(); + return type.getSourceString(); }).collect(Collectors.joining(", ")) + ')'; } } diff --git a/common/src/main/java/foundry/veil/impl/glsl/node/branch/GlslCaseLabelNode.java b/common/src/main/java/foundry/veil/impl/glsl/node/branch/GlslCaseLabelNode.java index 47fd1852..5c9d95a9 100644 --- a/common/src/main/java/foundry/veil/impl/glsl/node/branch/GlslCaseLabelNode.java +++ b/common/src/main/java/foundry/veil/impl/glsl/node/branch/GlslCaseLabelNode.java @@ -32,7 +32,7 @@ public String toString() { @Override public String getSourceString() { - return "case: " + this.condition.getSourceString(); + return this.condition == null ? "default" : "case " + this.condition.getSourceString(); } @Override diff --git a/common/src/main/java/foundry/veil/impl/glsl/node/branch/GlslSwitchNode.java b/common/src/main/java/foundry/veil/impl/glsl/node/branch/GlslSwitchNode.java index b68981a6..72b15ca3 100644 --- a/common/src/main/java/foundry/veil/impl/glsl/node/branch/GlslSwitchNode.java +++ b/common/src/main/java/foundry/veil/impl/glsl/node/branch/GlslSwitchNode.java @@ -82,7 +82,9 @@ public String getSourceString() { StringBuilder builder = new StringBuilder("switch("); builder.append(this.condition.getSourceString()).append(") {"); for (GlslNode branch : this.branches) { - builder.append('\t').append(branch.getSourceString()).append('\n'); + builder.append('\t').append(branch.getSourceString()); + builder.append(branch instanceof GlslCaseLabelNode ? ':' : ';'); + builder.append('\n'); } builder.append('}'); return builder.toString(); diff --git a/common/src/main/java/foundry/veil/impl/glsl/node/expression/GlslAndNode.java b/common/src/main/java/foundry/veil/impl/glsl/node/expression/GlslAndNode.java index 90fe7597..d01f0c57 100644 --- a/common/src/main/java/foundry/veil/impl/glsl/node/expression/GlslAndNode.java +++ b/common/src/main/java/foundry/veil/impl/glsl/node/expression/GlslAndNode.java @@ -37,7 +37,7 @@ public GlslAndNode setExpressions(GlslNode... expressions) { @Override public String getSourceString() { - return this.expressions.stream().map(GlslNode::getSourceString).collect(Collectors.joining(" & ")); + return '(' + this.expressions.stream().map(GlslNode::getSourceString).collect(Collectors.joining(" & ")) + ')'; } @Override diff --git a/common/src/main/java/foundry/veil/impl/glsl/node/expression/GlslConditionalNode.java b/common/src/main/java/foundry/veil/impl/glsl/node/expression/GlslConditionalNode.java index ea24fe0a..2f391e07 100644 --- a/common/src/main/java/foundry/veil/impl/glsl/node/expression/GlslConditionalNode.java +++ b/common/src/main/java/foundry/veil/impl/glsl/node/expression/GlslConditionalNode.java @@ -49,7 +49,7 @@ public GlslConditionalNode setSecond(GlslNode second) { @Override public String getSourceString() { - return this.condition.getSourceString() + " ? " + this.first.getSourceString() + " : " + this.second.getSourceString(); + return '(' + this.condition.getSourceString() + " ? " + this.first.getSourceString() + " : " + this.second.getSourceString() + ')'; } @Override diff --git a/common/src/main/java/foundry/veil/impl/glsl/node/expression/GlslExclusiveOrNode.java b/common/src/main/java/foundry/veil/impl/glsl/node/expression/GlslExclusiveOrNode.java index c1e2c525..743fa266 100644 --- a/common/src/main/java/foundry/veil/impl/glsl/node/expression/GlslExclusiveOrNode.java +++ b/common/src/main/java/foundry/veil/impl/glsl/node/expression/GlslExclusiveOrNode.java @@ -25,7 +25,7 @@ public List getExpressions() { @Override public String getSourceString() { - return this.expressions.stream().map(GlslNode::getSourceString).collect(Collectors.joining(" ^ ")); + return '(' + this.expressions.stream().map(GlslNode::getSourceString).collect(Collectors.joining(" ^ ")) + ')'; } @Override diff --git a/common/src/main/java/foundry/veil/impl/glsl/node/expression/GlslInclusiveOrNode.java b/common/src/main/java/foundry/veil/impl/glsl/node/expression/GlslInclusiveOrNode.java index 6c82f73d..ed46d35e 100644 --- a/common/src/main/java/foundry/veil/impl/glsl/node/expression/GlslInclusiveOrNode.java +++ b/common/src/main/java/foundry/veil/impl/glsl/node/expression/GlslInclusiveOrNode.java @@ -25,7 +25,7 @@ public List getExpressions() { @Override public String getSourceString() { - return this.expressions.stream().map(GlslNode::getSourceString).collect(Collectors.joining(" | ")); + return '(' + this.expressions.stream().map(GlslNode::getSourceString).collect(Collectors.joining(" | ")) + ')'; } @Override diff --git a/common/src/main/java/foundry/veil/impl/glsl/node/expression/GlslLogicalAndNode.java b/common/src/main/java/foundry/veil/impl/glsl/node/expression/GlslLogicalAndNode.java index 7dde1785..2e2789db 100644 --- a/common/src/main/java/foundry/veil/impl/glsl/node/expression/GlslLogicalAndNode.java +++ b/common/src/main/java/foundry/veil/impl/glsl/node/expression/GlslLogicalAndNode.java @@ -25,7 +25,7 @@ public List getExpressions() { @Override public String getSourceString() { - return this.expressions.stream().map(GlslNode::getSourceString).collect(Collectors.joining(" && ")); + return '(' + this.expressions.stream().map(GlslNode::getSourceString).collect(Collectors.joining(" && ")) + ')'; } @Override diff --git a/common/src/main/java/foundry/veil/impl/glsl/node/expression/GlslLogicalOrNode.java b/common/src/main/java/foundry/veil/impl/glsl/node/expression/GlslLogicalOrNode.java index e8c475a9..183226aa 100644 --- a/common/src/main/java/foundry/veil/impl/glsl/node/expression/GlslLogicalOrNode.java +++ b/common/src/main/java/foundry/veil/impl/glsl/node/expression/GlslLogicalOrNode.java @@ -25,7 +25,7 @@ public List getExpressions() { @Override public String getSourceString() { - return this.expressions.stream().map(GlslNode::getSourceString).collect(Collectors.joining(" || ")); + return '(' + this.expressions.stream().map(GlslNode::getSourceString).collect(Collectors.joining(" || ")) + ')'; } @Override diff --git a/common/src/main/java/foundry/veil/impl/glsl/node/expression/GlslLogicalXorNode.java b/common/src/main/java/foundry/veil/impl/glsl/node/expression/GlslLogicalXorNode.java index 1b4dea7e..cee1d6d8 100644 --- a/common/src/main/java/foundry/veil/impl/glsl/node/expression/GlslLogicalXorNode.java +++ b/common/src/main/java/foundry/veil/impl/glsl/node/expression/GlslLogicalXorNode.java @@ -25,7 +25,7 @@ public List getExpressions() { @Override public String getSourceString() { - return this.expressions.stream().map(GlslNode::getSourceString).collect(Collectors.joining(" ^^ ")); + return '(' + this.expressions.stream().map(GlslNode::getSourceString).collect(Collectors.joining(" ^^ ")) + ')'; } @Override diff --git a/common/src/main/java/foundry/veil/impl/glsl/node/primary/GlslIntConstantNode.java b/common/src/main/java/foundry/veil/impl/glsl/node/primary/GlslIntConstantNode.java index 5373af11..f60bb317 100644 --- a/common/src/main/java/foundry/veil/impl/glsl/node/primary/GlslIntConstantNode.java +++ b/common/src/main/java/foundry/veil/impl/glsl/node/primary/GlslIntConstantNode.java @@ -27,9 +27,9 @@ public boolean isNumber() { @Override public String getSourceString() { return switch (this.format) { - case HEXADECIMAL -> "0x" + Integer.toHexString(this.value); - case OCTAL -> Integer.toOctalString(this.value); - case DECIMAL -> Integer.toString(this.value); + case HEXADECIMAL -> "0x" + Integer.toHexString(this.value) + (this.signed ? "" : "u"); + case OCTAL -> Integer.toOctalString(this.value) + (this.signed ? "" : "u"); + case DECIMAL -> this.value + (this.signed ? "" : "u"); }; } diff --git a/common/src/main/java/foundry/veil/impl/glsl/node/variable/GlslNewNode.java b/common/src/main/java/foundry/veil/impl/glsl/node/variable/GlslNewNode.java index 7246ea47..400c2541 100644 --- a/common/src/main/java/foundry/veil/impl/glsl/node/variable/GlslNewNode.java +++ b/common/src/main/java/foundry/veil/impl/glsl/node/variable/GlslNewNode.java @@ -26,7 +26,7 @@ public GlslSpecifiedType getType() { @Override public Stream stream() { - return Stream.concat(Stream.of(this), this.initializer.stream()); + return this.initializer != null ? Stream.concat(Stream.of(this), this.initializer.stream()) : Stream.of(this); } public @Nullable String getName() { diff --git a/common/src/main/resources/veil.mixins.json b/common/src/main/resources/veil.mixins.json index ff8d4baf..11294918 100644 --- a/common/src/main/resources/veil.mixins.json +++ b/common/src/main/resources/veil.mixins.json @@ -2,7 +2,7 @@ "required": true, "minVersion": "0.8", "package": "foundry.veil.mixin", - "compatibilityLevel": "JAVA_17", + "compatibilityLevel": "JAVA_21", "refmap": "${mod_id}.refmap.json", "mixins": [ "debug.SimpleReloadInstanceMixin", diff --git a/common/src/test/java/GlslTest.java b/common/src/test/java/GlslTest.java index 81d02d9d..258f4d41 100644 --- a/common/src/test/java/GlslTest.java +++ b/common/src/test/java/GlslTest.java @@ -316,4 +316,34 @@ void main() { tree.visit(writer); System.out.println(writer); } + + @Test + void testWeird() throws GlslSyntaxException { + GlslTree tree = GlslParser.parse(""" + void main() { + int m0=x%2,m=m0+1; + } + """); + + GlslStringWriter writer = new GlslStringWriter(); + tree.visit(writer); + System.out.println(writer); + } + + @Test + void testMatrix() throws GlslSyntaxException { + GlslTree tree = GlslParser.parse(""" + void main() { + if (ProjMat[2][3] != 0.) { + shadeColor = vec4(0.); + vertexColor = vec4(-1.); + lightMapColor = vec4(1.); + } + } + """); + + GlslStringWriter writer = new GlslStringWriter(); + tree.visit(writer); + System.out.println(writer); + } } diff --git a/fabric/src/main/resources/veil.fabric.mixins.json b/fabric/src/main/resources/veil.fabric.mixins.json index 3add684b..840a9ccf 100644 --- a/fabric/src/main/resources/veil.fabric.mixins.json +++ b/fabric/src/main/resources/veil.fabric.mixins.json @@ -2,7 +2,7 @@ "required": true, "minVersion": "0.8", "package": "foundry.veil.fabric.mixin", - "compatibilityLevel": "JAVA_17", + "compatibilityLevel": "JAVA_21", "refmap": "${mod_id}.refmap.json", "plugin": "foundry.veil.fabric.VeilMixinPlugin", "mixins": [ diff --git a/neoforge/src/main/resources/veil.neoforge.mixins.json b/neoforge/src/main/resources/veil.neoforge.mixins.json index 3f08917d..ac632063 100644 --- a/neoforge/src/main/resources/veil.neoforge.mixins.json +++ b/neoforge/src/main/resources/veil.neoforge.mixins.json @@ -2,7 +2,7 @@ "required": true, "minVersion": "0.8", "package": "foundry.veil.forge.mixin", - "compatibilityLevel": "JAVA_17", + "compatibilityLevel": "JAVA_21", "refmap": "${mod_id}.refmap.json", "plugin": "foundry.veil.forge.VeilMixinPlugin", "mixins": [