Class ExecutionPlanner<T extends JobParameters>

java.lang.Object
io.github.douira.glsl_transformer.cst.transform.ExecutionPlanner<T>
All Implemented Interfaces:
ParameterHolder<T>
Direct Known Subclasses:
CSTTransformer

public abstract class ExecutionPlanner<T extends JobParameters> extends Object implements ParameterHolder<T>
The execution planner finds a valid way of satisfying the root transformation's dependencies. All other transformations and phases are added as dependencies to the root transformation.
  • Constructor Details

    • ExecutionPlanner

      public ExecutionPlanner()
      Creates a new execution planner with no root transformation. One will be created on demand.
    • ExecutionPlanner

      public ExecutionPlanner(Transformation<T> rootTransformation)
      Creates a new execution planner with a given root transformation.
      Parameters:
      rootTransformation - The root transformation to use
  • Method Details

    • getParser

      public abstract io.github.douira.glsl_transformer.GLSLParser getParser()
      Returns this execution planner's parser. How the parser is stored is up to the implementing class.
      Returns:
      The parser
    • getLexer

      public abstract io.github.douira.glsl_transformer.GLSLLexer getLexer()
      Returns the execution planner's lexer.
      Returns:
      The lexer
    • getJobParameters

      public T getJobParameters()
      Returns the execution planner's current job parameters. This may be null if the caller decides not to pass job parameters. However, a convention to always pass valid job parameters could be established if they are required for transformation phases to function.
      Specified by:
      getJobParameters in interface ParameterHolder<T extends JobParameters>
      Returns:
      The job parameters
    • setJobParameters

      public void setJobParameters(T jobParameters)
      Specified by:
      setJobParameters in interface ParameterHolder<T extends JobParameters>
    • withJobParameters

      public void withJobParameters(T parameters, Runnable run)
      Runs a function while this transformation manager has the given job parameters set.
      Parameters:
      parameters - The job parameters
      run - The function to run while the transformation manager has job parameters
    • getRootNode

      public io.github.douira.glsl_transformer.GLSLParser.TranslationUnitContext getRootNode()
      Returns the current root node being processed. Access to this method is restricted to classes in this package on purpose. Classes extending TransformationPhase should not have access to this but rather use it through the provided injection method.
      Returns:
      The current root node being processed
    • addConcurrent

      public void addConcurrent(LifecycleUser<T> rootDependency)
      Registers a single lifecycle user with this execution planner. This can be a transformation or a transformation phase. Multiple transformations can be added by calling this function multiple times or by adding a single enclosing transformation that includes multiple sub-transformations as concurrent dependencies.
      Parameters:
      rootDependency - The node to add as a dependency of the root node
    • getRootTransformation

      public Transformation<T> getRootTransformation()
      Returns the root transformation that contains all other phases and transformations. This is exposed so that simple structures may be added without requiring nested transformations.
      Returns:
      The root transformation instance
    • setRootTransformation

      public void setRootTransformation(Transformation<T> rootTransformation)
      Sets the root transformation. All dependencies should be accessible through this root transformation. Conditional dependencies can be used in the root transformation if a custom transformation is set with this method. Note that this doesn't reset the execution plan cache and can cause old execution plans unrelated to the new root transformation to be used when fixed job parameters match. This method is only intended to be used in cases where the root transformation is set once.
      Parameters:
      rootTransformation - The root transformation
    • planExecutionFor

      public void planExecutionFor(T parameters)
      Triggers execution planning for a given set of fixed job parameters. This can be useful for pre-computing execution plans instead of having them be computed on the fly and cached.
      Parameters:
      parameters - The fixed job parameters to compute the execution plan for
    • transformTree

      protected void transformTree(io.github.douira.glsl_transformer.GLSLParser.TranslationUnitContext ctx, BufferedTokenStream tokenStream)
      Transforms the given parse tree with the registered transformations.
      Parameters:
      ctx - The root node of the parse tree to be transformed
      tokenStream - The token stream of the parse tree