Class RunPhase
java.lang.Object
io.github.douira.glsl_transformer.GLSLParserBaseListener
io.github.douira.glsl_transformer.transform.RunPhase
- All Implemented Interfaces:
GLSLParserListener,org.antlr.v4.runtime.tree.ParseTreeListener
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected org.antlr.v4.runtime.tree.xpath.XPathcompilePath(String xpath) protected org.antlr.v4.runtime.tree.pattern.ParseTreePatterncompilePattern(String pattern, int rootRule) org.antlr.v4.runtime.ParserRuleContextcreateLocalRoot(String str, Function<GLSLParser, org.antlr.v4.runtime.ParserRuleContext> parseMethod) Parses the given string using the given parser method.List<org.antlr.v4.runtime.tree.pattern.ParseTreeMatch>findAndMatch(org.antlr.v4.runtime.tree.ParseTree tree, org.antlr.v4.runtime.tree.xpath.XPath xpath, org.antlr.v4.runtime.tree.pattern.ParseTreePattern pattern) This method uses a statically constructed xpath so it doesn't need to be repeatedly constructed.protected EditContextprotected org.antlr.v4.runtime.Parserprotected static List<org.antlr.v4.runtime.tree.ParseTree>getSiblings(org.antlr.v4.runtime.ParserRuleContext node) protected voidinit()protected booleanisActive()Overwrite this method to add a check of if this phase should be run at all.protected voidremoveNode(org.antlr.v4.runtime.ParserRuleContext node) protected voidreplaceNode(org.antlr.v4.runtime.ParserRuleContext node, String newContents, Function<GLSLParser, org.antlr.v4.runtime.ParserRuleContext> parseMethod) Replaces the given node in its parent with a new node generated by parsing the given string with the given method of the parser.protected abstract voidMethods inherited from class io.github.douira.glsl_transformer.GLSLParserBaseListener
enterAdditiveExpression, enterAndExpression, enterArraySpecifier, enterAssignmentExpression, enterAssignmentOperator, enterAttribute, enterBuiltinTypeSpecifierFixed, enterBuiltinTypeSpecifierParseable, enterCallParameterList, enterCaseLabel, enterCompoundStatement, enterCondition, enterConditionalExpression, enterConstantExpression, enterDeclaration, enterDeclarationMember, enterDeclarationMemberList, enterDeclarationStatement, enterDemoteStatement, enterDoWhileStatement, enterEmptyStatement, enterEqualityExpression, enterEveryRule, enterExclusiveOrExpression, enterExpression, enterExpressionStatement, enterExtensionState, enterExtensionStatement, enterExternalDeclaration, enterForStatement, enterFullySpecifiedType, enterFunctionCall, enterFunctionDefinition, enterFunctionHeader, enterFunctionIdentifier, enterFunctionParameterList, enterFunctionPrototype, enterInclusiveOrExpression, enterInitDeclaratorList, enterInitializer, enterInterpolationQualifier, enterInvariantQualifier, enterJumpStatement, enterLayoutDefaults, enterLayoutModes, enterLayoutQualifier, enterLayoutQualifierId, enterLogicalAndExpression, enterLogicalOrExpression, enterLogicalXorExpression, enterMethodCall, enterMultiplicativeExpression, enterParameterDeclaration, enterParameterDeclarator, enterPostfixExpression, enterPragmaStatement, enterPreciseQualifier, enterPrecisionQualifier, enterPrimaryExpression, enterRelationalExpression, enterSelectionStatement, enterShiftExpression, enterSimpleStatement, enterSingleAttribute, enterStatement, enterStorageQualifier, enterStructDeclaration, enterStructDeclarationList, enterStructDeclarator, enterStructDeclaratorList, enterStructSpecifier, enterSwitchStatement, enterTranslationUnit, enterTypeNameList, enterTypeQualifier, enterTypeSpecifier, enterTypeSpecifierNonarray, enterUnaryExpression, enterUnaryOperator, enterVariableIdentifier, enterVersionStatement, enterWhileStatement, exitAdditiveExpression, exitAndExpression, exitArraySpecifier, exitAssignmentExpression, exitAssignmentOperator, exitAttribute, exitBuiltinTypeSpecifierFixed, exitBuiltinTypeSpecifierParseable, exitCallParameterList, exitCaseLabel, exitCompoundStatement, exitCondition, exitConditionalExpression, exitConstantExpression, exitDeclaration, exitDeclarationMember, exitDeclarationMemberList, exitDeclarationStatement, exitDemoteStatement, exitDoWhileStatement, exitEmptyStatement, exitEqualityExpression, exitEveryRule, exitExclusiveOrExpression, exitExpression, exitExpressionStatement, exitExtensionState, exitExtensionStatement, exitExternalDeclaration, exitForStatement, exitFullySpecifiedType, exitFunctionCall, exitFunctionDefinition, exitFunctionHeader, exitFunctionIdentifier, exitFunctionParameterList, exitFunctionPrototype, exitInclusiveOrExpression, exitInitDeclaratorList, exitInitializer, exitInterpolationQualifier, exitInvariantQualifier, exitJumpStatement, exitLayoutDefaults, exitLayoutModes, exitLayoutQualifier, exitLayoutQualifierId, exitLogicalAndExpression, exitLogicalOrExpression, exitLogicalXorExpression, exitMethodCall, exitMultiplicativeExpression, exitParameterDeclaration, exitParameterDeclarator, exitPostfixExpression, exitPragmaStatement, exitPreciseQualifier, exitPrecisionQualifier, exitPrimaryExpression, exitRelationalExpression, exitSelectionStatement, exitShiftExpression, exitSimpleStatement, exitSingleAttribute, exitStatement, exitStorageQualifier, exitStructDeclaration, exitStructDeclarationList, exitStructDeclarator, exitStructDeclaratorList, exitStructSpecifier, exitSwitchStatement, exitTranslationUnit, exitTypeNameList, exitTypeQualifier, exitTypeSpecifier, exitTypeSpecifierNonarray, exitUnaryExpression, exitUnaryOperator, exitVariableIdentifier, exitVersionStatement, exitWhileStatement, visitErrorNode, visitTerminal
-
Constructor Details
-
RunPhase
public RunPhase()
-
-
Method Details
-
run
-
getEditContext
-
getParser
protected org.antlr.v4.runtime.Parser getParser() -
getSiblings
protected static List<org.antlr.v4.runtime.tree.ParseTree> getSiblings(org.antlr.v4.runtime.ParserRuleContext node) -
replaceNode
protected void replaceNode(org.antlr.v4.runtime.ParserRuleContext node, String newContents, Function<GLSLParser, org.antlr.v4.runtime.ParserRuleContext> parseMethod) Replaces the given node in its parent with a new node generated by parsing the given string with the given method of the parser. SeecreateLocalRoot(java.lang.String, java.util.function.Function<io.github.douira.glsl_transformer.GLSLParser, org.antlr.v4.runtime.ParserRuleContext>)for details of creating parsed nodes.- Parameters:
node- The node to be replacednewContents- The string from which a new node is generatedparseMethod- The method with which the string will be parsed
-
removeNode
protected void removeNode(org.antlr.v4.runtime.ParserRuleContext node) -
compilePath
-
compilePattern
protected org.antlr.v4.runtime.tree.pattern.ParseTreePattern compilePattern(String pattern, int rootRule) -
findAndMatch
public List<org.antlr.v4.runtime.tree.pattern.ParseTreeMatch> findAndMatch(org.antlr.v4.runtime.tree.ParseTree tree, org.antlr.v4.runtime.tree.xpath.XPath xpath, org.antlr.v4.runtime.tree.pattern.ParseTreePattern pattern) This method uses a statically constructed xpath so it doesn't need to be repeatedly constructed. The subtrees yielded by the xpath need to start with the rule that the pattern was constructed with or nothing will match. Adapted from ANTLR's implementation ofParseTreePattern.findAll(org.antlr.v4.runtime.tree.ParseTree, java.lang.String).- Parameters:
tree- The parse tree to find and match inxpath- The xpath that leads to a subtree for matchingpattern- The pattern that tests the subtrees for matches- Returns:
- A list of all matches resulting from the subtrees
-
isActive
protected boolean isActive()Overwrite this method to add a check of if this phase should be run at all. Especially for WalkPhase this is important since it reduces the number of listeners that need to be processed.- Returns:
- If the phase should run.
trueby default.
-
init
protected void init() -
createLocalRoot
public org.antlr.v4.runtime.ParserRuleContext createLocalRoot(String str, Function<GLSLParser, org.antlr.v4.runtime.ParserRuleContext> parseMethod) Parses the given string using the given parser method. Since the parser doesn't know which part of the parse tree any string would be part of, we need to tell it. In many cases multiple methods would produce a correct result. However, this can lead to a truncated parse tree when the resulting node is inserted into a bigger parse tree. The parsing method should be chosen such that when the resulting node is inserted into a parse tree, the tree has the same structure as if it had been parsed as one piece. For example, the code fragmentfoo()could be parsed as afunctionCall, aprimaryExpression, anexpressionor other enclosing parse rules. If it's inserted into an expression, it should be parsed as anexpressionso that this rule isn't missing from the parse tree. Using the wrong parse method often doesn't matter but it can cause tree matchers to not find the node if they are, for example, looking for anexpressionspecifically.- Parameters:
str- The string to be parsedparseMethod- The parser method with which the string is parsed- Returns:
- The resulting parsed node
-