Skip to content

Commit

Permalink
fix type finder
Browse files Browse the repository at this point in the history
  • Loading branch information
ferriarnus committed Oct 21, 2024
1 parent fa9ddb5 commit 65e919b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
16 changes: 15 additions & 1 deletion src/main/java/org/taumc/glsl/TypeFinder.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import java.util.concurrent.atomic.AtomicInteger;

public class TypeFinder extends GLSLParserBaseListener {
public class TypeFinder extends GLSLCancelableBaseListener {

private final String name;
private final AtomicInteger type;
Expand All @@ -27,6 +27,20 @@ public void enterSingle_declaration(GLSLParser.Single_declarationContext ctx) {
if (ctx.fully_specified_type().type_specifier().type_specifier_nonarray().getChild(0) instanceof TerminalNode node) {
if (node.getSymbol() instanceof CommonToken t) {
type.set(t.getType());
keepWalking = false;
}
}
}
} else if (ctx.getParent() instanceof GLSLParser.Init_declarator_listContext listContext) {
for (var entry : listContext.typeless_declaration()) {
if (entry.IDENTIFIER().getSymbol() instanceof CommonToken cToken) {
if (cToken.getText().equals(name)) {
if (ctx.fully_specified_type().type_specifier().type_specifier_nonarray().getChild(0) instanceof TerminalNode node) {
if (node.getSymbol() instanceof CommonToken t) {
type.set(t.getType());
keepWalking = false;
}
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/taumc/glsl/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public static void removeVariable(GLSLParser.Translation_unitContext root, Strin

public static int findType(GLSLParser.Translation_unitContext root, String code) {
AtomicInteger type = new AtomicInteger();
ParseTreeWalker.DEFAULT.walk(new TypeFinder(code, type), root);
FastTreeWalker.walk(new TypeFinder(code, type), root);
return type.get();
}

Expand Down

0 comments on commit 65e919b

Please sign in to comment.