Skip to content

Commit

Permalink
no need to use auto hinted matcher if no hint is needed
Browse files Browse the repository at this point in the history
  • Loading branch information
douira committed Dec 26, 2022
1 parent b921b1e commit e0e456d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,15 @@ public class CommonTransformer {
"gl_TextureMatrix[0]", Matcher.expressionPattern);
public static final AutoHintedMatcher<Expression> glTextureMatrix1 = new AutoHintedMatcher<>(
"gl_TextureMatrix[1]", Matcher.expressionPattern);
public static final AutoHintedMatcher<ExternalDeclaration> sampler = new AutoHintedMatcher<>(
public static final Matcher<ExternalDeclaration> sampler = new Matcher<>(
"uniform Type name;", Matcher.externalDeclarationPattern) {
{
markClassedPredicateWildcard("type",
pattern.getRoot().identifierIndex.getUnique("Type").getAncestor(TypeSpecifier.class),
BuiltinFixedTypeSpecifier.class,
specifier -> specifier.type.kind == TypeKind.SAMPLER);
markClassWildcard("name*", pattern.getRoot().identifierIndex.getUnique("name").getAncestor(DeclarationMember.class));
markClassWildcard("name*",
pattern.getRoot().identifierIndex.getUnique("name").getAncestor(DeclarationMember.class));
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,15 +211,19 @@ public static void transformEach(ASTParser t, TranslationUnit tree, Root root, P
}
}

private static class DeclarationMatcher extends AutoHintedMatcher<ExternalDeclaration> {
private static class DeclarationMatcher extends Matcher<ExternalDeclaration> {
private final StorageType storageType;

public DeclarationMatcher(StorageType storageType) {
super("out float name;", Matcher.externalDeclarationPattern);
this.storageType = storageType;
}

{
markClassWildcard("qualifier", pattern.getRoot().nodeIndex.getUnique(TypeQualifier.class));
markClassWildcard("type", pattern.getRoot().nodeIndex.getUnique(BuiltinNumericTypeSpecifier.class));
markClassWildcard("name*", pattern.getRoot().identifierIndex.getUnique("name").getAncestor(DeclarationMember.class));
markClassWildcard("name*",
pattern.getRoot().identifierIndex.getUnique("name").getAncestor(DeclarationMember.class));
}

@Override
Expand All @@ -242,9 +246,9 @@ public boolean matchesExtract(ExternalDeclaration tree) {
}

private static final ShaderType[] pipeline = { ShaderType.VERTEX, ShaderType.GEOMETRY, ShaderType.FRAGMENT };
private static final AutoHintedMatcher<ExternalDeclaration> outDeclarationMatcher = new DeclarationMatcher(
private static final Matcher<ExternalDeclaration> outDeclarationMatcher = new DeclarationMatcher(
StorageType.OUT);
private static final AutoHintedMatcher<ExternalDeclaration> inDeclarationMatcher = new DeclarationMatcher(
private static final Matcher<ExternalDeclaration> inDeclarationMatcher = new DeclarationMatcher(
StorageType.IN);

private static final String tagPrefix = "iris_template_";
Expand All @@ -259,7 +263,8 @@ public boolean matchesExtract(ExternalDeclaration tree) {
.withStatement("__oldDecl = vec3(__internalDecl, vec4(0));");

static {
declarationTemplate.markLocalReplacement(declarationTemplate.getSourceRoot().nodeIndex.getUnique(TypeQualifier.class));
declarationTemplate
.markLocalReplacement(declarationTemplate.getSourceRoot().nodeIndex.getUnique(TypeQualifier.class));
declarationTemplate.markLocalReplacement("__type", TypeSpecifier.class);
declarationTemplate.markIdentifierReplacement("__name");
initTemplate.markIdentifierReplacement("__decl");
Expand Down

0 comments on commit e0e456d

Please sign in to comment.