Class SourceFile

java.lang.Object
com.jozufozu.flywheel.core.source.SourceFile

public class SourceFile extends Object
Immutable class representing a shader file.

This class parses shader files and generates what is effectively a high level AST of the source.

  • Field Details

    • functionDeclaration

      public static final Pattern functionDeclaration
    • name

      public final net.minecraft.resources.ResourceLocation name
    • parent

      public final ShaderSources parent
    • source

      public final String source
    • elided

      public final String elided
      Sections of the source that must be trimmed for compilation. Currently, it only contains the spans of imports.
    • lines

      public final SourceLines lines
    • functions

      public final com.google.common.collect.ImmutableMap<String,ShaderFunction> functions
      Function lookup by name.
    • structs

      public final com.google.common.collect.ImmutableMap<String,ShaderStruct> structs
      Struct lookup by name.
    • imports

      public final com.google.common.collect.ImmutableList<Import> imports
      Includes ordered as defined in the source.
  • Constructor Details

    • SourceFile

      public SourceFile(ShaderSources parent, net.minecraft.resources.ResourceLocation name, String source)
  • Method Details

    • getLineSpan

      public Span getLineSpan(int line)
    • getLineSpanNoWhitespace

      public Span getLineSpanNoWhitespace(int line)
    • findStruct

      public Optional<ShaderStruct> findStruct(CharSequence name)
      Search this file and recursively search all imports to find a struct definition matching the given name.
      Parameters:
      name - The name of the struct to find.
      Returns:
      null if no definition matches the name.
    • findFunction

      public Optional<ShaderFunction> findFunction(CharSequence name)
      Search this file and recursively search all imports to find a function definition matching the given name.
      Parameters:
      name - The name of the function to find.
      Returns:
      Optional#empty() if no definition matches the name.
    • importStatement

      public CharSequence importStatement()
    • generateFinalSource

      public void generateFinalSource(FileIndex env, StringBuilder source)
    • printSource

      public String printSource()
    • toString

      public String toString()
      Overrides:
      toString in class Object