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
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
FieldsModifier and TypeFieldDescriptionprotected intLimits 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 -
Method Summary
Modifier and TypeMethodDescriptionactivation(Supplier<Boolean> activation) Override to make type more specificvoidaddWalkIntoRule(Class<? extends ExtendedContext> walkIntoRule) Adds a class to the set of allowed rules for the walk.booleancanStop()Returns if the parse tree listener is ever interested in maybe returning true fromPartialParseTreeListener.isFinished(depth)orPartialParseTreeListener.isDeepEnough(ExtendedContext, depth).protected abstract booleancanWalk()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 booleancheckBeforeWalk(io.github.douira.glsl_transformer.GLSLParser.TranslationUnitContext ctx) Method called by the execution planner before the walk happens.protected intReturns the maximum walk depth.protected Set<Class<? extends ExtendedContext>>Returns the walk into rules.booleanisDeepEnough(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 voidrunAfterWalk(io.github.douira.glsl_transformer.GLSLParser.TranslationUnitContext ctx) Method called by the execution planner after the walk happens.voidsetMaximumWalkDepth(int maximumWalkDepth) Sets the maximum walk depth.voidsetWalkIntoRules(Set<Class<? extends ExtendedContext>> walkIntoRules) Sets the class of rules that this phase should walk into.voidSets the maximum walk depth to -1 which means it's not limited.protected voidMarks this phase as being done walking the tree in the current execution.Methods inherited from class io.github.douira.glsl_transformer.cst.transform.TransformationPhaseBase
compilePath, compilePattern, createLocalRoot, findAndMatch, getPlanner, getSiblings, injectDefine, injectExternalDeclaration, injectExternalDeclarations, injectNode, injectNodes, injectNodes, isActive, isInitialized, removeNode, replaceNode, replaceNode, setInitialized, setPlannerMethods 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, visitTerminalMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.github.douira.glsl_transformer.cst.transform.lifecycle.LifecycleUser
getJobParameters, getLexer, getParser, getRootNode, init, initOnce, resetStateMethods inherited from interface org.antlr.v4.runtime.tree.ParseTreeListener
enterEveryRule, exitEveryRule, visitErrorNode, visitTerminalMethods inherited from interface io.github.douira.glsl_transformer.cst.traversal.PartialParseTreeListener
isFinished
-
Field Details
-
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 maximumWalkDepthLimits 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 methodscheckBeforeWalk(TranslationUnitContext)andrunAfterWalk(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:
trueif 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
Description copied from interface:ActivatableLifecycleUserOverride to make type more specific- Specified by:
activationin interfaceActivatable- Specified by:
activationin interfaceActivatableLifecycleUser<T extends JobParameters>- Overrides:
activationin classTransformationPhaseBase<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
Description copied from interface:PartialParseTreeListenerReturns if this parse tree listener wants to continue to walk the tree but not go any deeper into the current (given) rule.- Specified by:
isDeepEnoughin interfacePartialParseTreeListener- Parameters:
node- The current node in which to maybe not visit the childrendepth- The depth of the node in the tree. The root node has depth 0.- Returns:
trueif the parse tree walker
-
canStop
public boolean canStop()Description copied from interface:PartialParseTreeListenerReturns if the parse tree listener is ever interested in maybe returning true fromPartialParseTreeListener.isFinished(depth)orPartialParseTreeListener.isDeepEnough(ExtendedContext, depth). If this method return false, the other two methods will never be called for better performance.- Specified by:
canStopin interfacePartialParseTreeListener- Returns:
trueif the parse tree listener is ever interested in prematurely stopping the walk
-
setWalkIntoRules
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
Returns the walk into rules.- Returns:
- The walk into rules
-
addWalkIntoRule
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.
-