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

public abstract class RunPhase extends GLSLParserBaseListener
  • Constructor Details

    • RunPhase

      public RunPhase()
  • Method Details

    • run

      protected abstract void run(GLSLParser.TranslationUnitContext ctx)
    • getEditContext

      protected EditContext 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. See createLocalRoot(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 replaced
      newContents - The string from which a new node is generated
      parseMethod - The method with which the string will be parsed
    • removeNode

      protected void removeNode(org.antlr.v4.runtime.ParserRuleContext node)
    • compilePath

      protected org.antlr.v4.runtime.tree.xpath.XPath compilePath(String xpath)
    • 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 of ParseTreePattern.findAll(org.antlr.v4.runtime.tree.ParseTree, java.lang.String).
      Parameters:
      tree - The parse tree to find and match in
      xpath - The xpath that leads to a subtree for matching
      pattern - 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. true by 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 fragment foo() could be parsed as a functionCall, a primaryExpression, an expression or other enclosing parse rules. If it's inserted into an expression, it should be parsed as an expression so 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 an expression specifically.
      Parameters:
      str - The string to be parsed
      parseMethod - The parser method with which the string is parsed
      Returns:
      The resulting parsed node