Class TransformationPhase<T extends JobParameters>

java.lang.Object
io.github.douira.glsl_transformer.GLSLParserBaseListener
io.github.douira.glsl_transformer.cst.transform.TransformationPhaseBase<T>
io.github.douira.glsl_transformer.cst.transform.TransformationPhase<T>
All Implemented Interfaces:
Activatable, ActivatableLifecycleUser<T>, LifecycleUser<T>, PartialParseTreeListener, io.github.douira.glsl_transformer.GLSLParserListener, ParseTreeListener
Direct Known Subclasses:
RunPhase, WalkPhase

public abstract class TransformationPhase<T extends JobParameters> extends TransformationPhaseBase<T> implements PartialParseTreeListener
The transformations phase is the smallest unit of the transformation process. Its subclasses contain the specific code to make changes to the parse tree.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected int
    Limits how deep into the parse tree this transformation phase will walk before it signals deep enough.
    protected Set<Class<? extends ExtendedContext>>
    If not null, the transformation phase will only walk into a rule context's children if it's an instance of these given classes.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    Override to make type more specific
    void
    addWalkIntoRule(Class<? extends ExtendedContext> walkIntoRule)
    Adds a class to the set of allowed rules for the walk.
    boolean
    Returns if the parse tree listener is ever interested in maybe returning true from PartialParseTreeListener.isFinished(depth) or PartialParseTreeListener.isDeepEnough(ExtendedContext, depth).
    protected abstract boolean
    Called during planning in order to determine if this phase does any walking at all or if it just runs some code, like a RunPhase.
    protected boolean
    checkBeforeWalk(io.github.douira.glsl_transformer.GLSLParser.TranslationUnitContext ctx)
    Method called by the execution planner before the walk happens.
    protected int
    Returns the maximum walk depth.
    protected Set<Class<? extends ExtendedContext>>
    Returns the walk into rules.
    boolean
    isDeepEnough(ExtendedContext node, int depth)
    Returns if this parse tree listener wants to continue to walk the tree but not go any deeper into the current (given) rule.
    protected void
    runAfterWalk(io.github.douira.glsl_transformer.GLSLParser.TranslationUnitContext ctx)
    Method called by the execution planner after the walk happens.
    void
    setMaximumWalkDepth(int maximumWalkDepth)
    Sets the maximum walk depth.
    void
    setWalkIntoRules(Set<Class<? extends ExtendedContext>> walkIntoRules)
    Sets the class of rules that this phase should walk into.
    void
    Sets the maximum walk depth to -1 which means it's not limited.
    protected void
    Marks this phase as being done walking the tree in the current execution.

    Methods inherited from class io.github.douira.glsl_transformer.GLSLParserBaseListener

    enterAdditiveExpression, enterArrayAccessExpression, enterArraySpecifier, enterArraySpecifierSegment, enterAssignmentExpression, enterAttribute, enterBitwiseAndExpression, enterBitwiseExclusiveOrExpression, enterBitwiseInclusiveOrExpression, enterBreakStatement, enterBuiltinTypeSpecifierFixed, enterBuiltinTypeSpecifierParseable, enterCompoundStatement, enterConditionalExpression, enterContinueStatement, enterDeclarationMember, enterDeclarationStatement, enterDefaultCaseLabel, enterDemoteStatement, enterDiscardStatement, enterDoWhileStatement, enterEmptyDeclaration, enterEmptyStatement, enterEqualityExpression, enterEveryRule, enterExpressionStatement, enterExtensionStatement, enterExternalDeclaration, enterForStatement, enterFullySpecifiedType, enterFunctionCallExpression, enterFunctionDeclaration, enterFunctionDefinition, enterFunctionParameterList, enterFunctionPrototype, enterGroupingExpression, enterInitializer, enterInterfaceBlockDeclaration, enterInterpolationQualifier, enterInvariantQualifier, enterIterationCondition, enterLayoutDefaults, enterLayoutQualifier, enterLengthAccessExpression, enterLiteralExpression, enterLogicalAndExpression, enterLogicalExclusiveOrExpression, enterLogicalInclusiveOrExpression, enterMemberAccessExpression, enterMultiplicativeExpression, enterNamedLayoutQualifier, enterParameterDeclaration, enterPostfixExpression, enterPragmaStatement, enterPreciseQualifier, enterPrecisionDeclaration, enterPrecisionQualifier, enterPrefixExpression, enterReferenceExpression, enterRelationalExpression, enterReturnStatement, enterSelectionStatement, enterSequenceExpression, enterSharedLayoutQualifier, enterShiftExpression, enterSingleAttribute, enterStatement, enterStorageQualifier, enterStructBody, enterStructDeclarator, enterStructMember, enterStructSpecifier, enterSwitchStatement, enterTranslationUnit, enterTypeAndInitDeclaration, enterTypeQualifier, enterTypeSpecifier, enterValuedCaseLabel, enterVariableDeclaration, enterVersionStatement, enterWhileStatement, exitAdditiveExpression, exitArrayAccessExpression, exitArraySpecifier, exitArraySpecifierSegment, exitAssignmentExpression, exitAttribute, exitBitwiseAndExpression, exitBitwiseExclusiveOrExpression, exitBitwiseInclusiveOrExpression, exitBreakStatement, exitBuiltinTypeSpecifierFixed, exitBuiltinTypeSpecifierParseable, exitCompoundStatement, exitConditionalExpression, exitContinueStatement, exitDeclarationMember, exitDeclarationStatement, exitDefaultCaseLabel, exitDemoteStatement, exitDiscardStatement, exitDoWhileStatement, exitEmptyDeclaration, exitEmptyStatement, exitEqualityExpression, exitEveryRule, exitExpressionStatement, exitExtensionStatement, exitExternalDeclaration, exitForStatement, exitFullySpecifiedType, exitFunctionCallExpression, exitFunctionDeclaration, exitFunctionDefinition, exitFunctionParameterList, exitFunctionPrototype, exitGroupingExpression, exitInitializer, exitInterfaceBlockDeclaration, exitInterpolationQualifier, exitInvariantQualifier, exitIterationCondition, exitLayoutDefaults, exitLayoutQualifier, exitLengthAccessExpression, exitLiteralExpression, exitLogicalAndExpression, exitLogicalExclusiveOrExpression, exitLogicalInclusiveOrExpression, exitMemberAccessExpression, exitMultiplicativeExpression, exitNamedLayoutQualifier, exitParameterDeclaration, exitPostfixExpression, exitPragmaStatement, exitPreciseQualifier, exitPrecisionDeclaration, exitPrecisionQualifier, exitPrefixExpression, exitReferenceExpression, exitRelationalExpression, exitReturnStatement, exitSelectionStatement, exitSequenceExpression, exitSharedLayoutQualifier, exitShiftExpression, exitSingleAttribute, exitStatement, exitStorageQualifier, exitStructBody, exitStructDeclarator, exitStructMember, exitStructSpecifier, exitSwitchStatement, exitTranslationUnit, exitTypeAndInitDeclaration, exitTypeQualifier, exitTypeSpecifier, exitValuedCaseLabel, exitVariableDeclaration, exitVersionStatement, exitWhileStatement, visitErrorNode, visitTerminal

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface io.github.douira.glsl_transformer.cst.transform.lifecycle.LifecycleUser

    getJobParameters, getLexer, getParser, getRootNode, init, initOnce, resetState

    Methods inherited from interface org.antlr.v4.runtime.tree.ParseTreeListener

    enterEveryRule, exitEveryRule, visitErrorNode, visitTerminal

    Methods inherited from interface io.github.douira.glsl_transformer.cst.traversal.PartialParseTreeListener

    isFinished
  • Field Details

    • walkIntoRules

      protected Set<Class<? extends ExtendedContext>> walkIntoRules
      If not null, the transformation phase will only walk into a rule context's children if it's an instance of these given classes.
    • maximumWalkDepth

      protected int maximumWalkDepth
      Limits how deep into the parse tree this transformation phase will walk before it signals deep enough.
  • Constructor Details

    • TransformationPhase

      public TransformationPhase()
  • Method Details

    • canWalk

      protected abstract boolean canWalk()
      Called during planning in order to determine if this phase does any walking at all or if it just runs some code, like a RunPhase. This doesn't exclude or include this phase from walking but rather helps the execution planner combine walk phases into execution levels. Enabling and disabling a phase should be done with the methods checkBeforeWalk(TranslationUnitContext) and runAfterWalk(TranslationUnitContext).
      Returns:
      If this phase needs to be walked on the tree
      Implementation Note:
      This method should run quickly and will only be called once (or never) during execution planning.
    • checkBeforeWalk

      protected boolean checkBeforeWalk(io.github.douira.glsl_transformer.GLSLParser.TranslationUnitContext ctx)
      Method called by the execution planner before the walk happens. The returned boolean determines if the phase is added to the list of phases that are walked on the tree. Returns false by default and implementing classes should overwrite this.
      Parameters:
      ctx - The root node
      Returns:
      true if the phase should be walked on the tree
    • runAfterWalk

      protected void runAfterWalk(io.github.douira.glsl_transformer.GLSLParser.TranslationUnitContext ctx)
      Method called by the execution planner after the walk happens. Does nothing by default.
      Parameters:
      ctx - The root node
    • activation

      public TransformationPhase<T> activation(Supplier<Boolean> activation)
      Description copied from interface: ActivatableLifecycleUser
      Override to make type more specific
      Specified by:
      activation in interface Activatable
      Specified by:
      activation in interface ActivatableLifecycleUser<T extends JobParameters>
      Overrides:
      activation in class TransformationPhaseBase<T extends JobParameters>
      Parameters:
      activation - The activation supplier
      Returns:
      This object
    • walkFinished

      protected void walkFinished()
      Marks this phase as being done walking the tree in the current execution. This removes it from the proxy parse tree listener which in turn can make the dynamic parse tree walker not further walk the parse tree if there are no more listeners that are interested in continuing.
      API Usage Note:
      Calling this method multiple times in the same execution has no effect but is efficient
    • isDeepEnough

      public boolean isDeepEnough(ExtendedContext node, int depth)
      Description copied from interface: PartialParseTreeListener
      Returns if this parse tree listener wants to continue to walk the tree but not go any deeper into the current (given) rule.
      Specified by:
      isDeepEnough in interface PartialParseTreeListener
      Parameters:
      node - The current node in which to maybe not visit the children
      depth - The depth of the node in the tree. The root node has depth 0.
      Returns:
      true if the parse tree walker
    • canStop

      public boolean canStop()
      Description copied from interface: PartialParseTreeListener
      Returns if the parse tree listener is ever interested in maybe returning true from PartialParseTreeListener.isFinished(depth) or PartialParseTreeListener.isDeepEnough(ExtendedContext, depth). If this method return false, the other two methods will never be called for better performance.
      Specified by:
      canStop in interface PartialParseTreeListener
      Returns:
      true if the parse tree listener is ever interested in prematurely stopping the walk
    • setWalkIntoRules

      public void setWalkIntoRules(Set<Class<? extends ExtendedContext>> walkIntoRules)
      Sets the class of rules that this phase should walk into. It will signal "deep enough" to the parse tree walker for all other nodes.
      Parameters:
      walkIntoRules - The class of rules that this phase should walk into
    • getWalkIntoRules

      protected Set<Class<? extends ExtendedContext>> getWalkIntoRules()
      Returns the walk into rules.
      Returns:
      The walk into rules
    • addWalkIntoRule

      public void addWalkIntoRule(Class<? extends ExtendedContext> walkIntoRule)
      Adds a class to the set of allowed rules for the walk.
      Parameters:
      walkIntoRule - The class of a rule to allow deeper walking into
    • getMaximumWalkDepth

      protected int getMaximumWalkDepth()
      Returns the maximum walk depth.
      Returns:
      The maximum walk depth
    • setMaximumWalkDepth

      public void setMaximumWalkDepth(int maximumWalkDepth)
      Sets the maximum walk depth.
      Parameters:
      maximumWalkDepth - The maximum walk depth
    • unlimitedWalkDepth

      public void unlimitedWalkDepth()
      Sets the maximum walk depth to -1 which means it's not limited.