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
A run phase simply executes one method when it is executed in a level by the
phase collector. Even though it extends
Phase, no listener methods on
it are executed.-
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, org.antlr.v4.runtime.RuleContext parent, 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) Gets the sibling nodes of a given node.protected voidinit()This method is called right after this phase is collected by the phase collector.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) Removes the given node from its parent's child list.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) Gets the sibling nodes of a given node. It looks up the parent and then returns the parent's children.- Parameters:
node- The node to get the siblings for- Returns:
- The siblings of the given node.
nullif the node has no parent.
-
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(String, RuleContext, Function)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) Removes the given node from its parent's child list.- Parameters:
node- The node to remove- Implementation Note:
- The empty space is filled in with an empty terminal node in order to not mess up the walker's iteration.
-
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(ParseTree, 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()This method is called right after this phase is collected by the phase collector. It can be used to compile xpaths and pattern matchers. -
createLocalRoot
public org.antlr.v4.runtime.ParserRuleContext createLocalRoot(String str, org.antlr.v4.runtime.RuleContext parent, 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. All nodes inserted into the parse tree must have properly configured parent references or looking up a node's local root won't work. Other things in ANTLR may also break if non-root nodes are missing their parent references.- Parameters:
str- The string to be parsedparent- The parent to be set on the node. All nodes will eventually end up in the a main tree so some parent will be available. Getting the siblings of the new node will not work if no parent is set.parseMethod- The parser method with which the string is parsed- Returns:
- The resulting parsed node
-