Class ExecutionPlanner<T extends JobParameters>

java.lang.Object
io.github.douira.glsl_transformer.transform.ExecutionPlanner<T>
Direct Known Subclasses:
TransformationManager

public abstract class ExecutionPlanner<T extends JobParameters> extends Object
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
    • withJobParameters

      public <R> R withJobParameters(T parameters, Supplier<R> run)
      Runs a function while this transformation manager has the given job parameters set. It returns the value that the function returns. This can be used together with non-standard ways of using a transformation manager like using TransformationManager.parse(IntStream, ExtendedContext, Function) directly.
      Type Parameters:
      R - The return type of the function
      Parameters:
      parameters - The job parameters to set
      run - The function to run while the transformation manager has job parameters
      Returns:
      The value returned by the supplier function
    • 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
      See Also:
      withJobParameters(JobParameters, Supplier)
    • 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