java.lang.Object
io.github.ocelot.glslprocessor.lib.anarres.cpp.Preprocessor

@Internal public class Preprocessor extends Object
A C Preprocessor. The Preprocessor outputs a token stream which does not need re-lexing for C or C++. Alternatively, the output text may be reconstructed by concatenating the text values of the returned Tokens.
  • Constructor Details

    • Preprocessor

      public Preprocessor()
  • Method Details

    • addFeature

      public void addFeature(@NotNull @NotNull Feature f)
      Adds a feature to the feature-set of this Preprocessor.
    • getFeature

      public boolean getFeature(@NotNull @NotNull Feature f)
      Returns true if the given feature is in the feature-set of this Preprocessor.
    • getWarnings

      @NotNull public @NotNull Set<Warning> getWarnings()
      Returns the warning-set for this Preprocessor.

      This set may be freely modified by user code.

    • getWarning

      public boolean getWarning(@NotNull @NotNull Warning w)
      Returns true if the given warning is in the warning-set of this Preprocessor.
    • addInput

      public void addInput(@NotNull @NotNull Source source)
      Adds input for the Preprocessor.

      Inputs are processed in the order in which they are added.

    • error

      protected void error(int line, int column, @NotNull @NotNull String msg) throws LexerException
      Handles an error.

      If a PreprocessorListener is installed, it receives the error. Otherwise, an exception is thrown.

      Throws:
      LexerException
    • error

      protected void error(@NotNull @NotNull Token tok, @NotNull @NotNull String msg) throws LexerException
      Handles an error.

      If a PreprocessorListener is installed, it receives the error. Otherwise, an exception is thrown.

      Throws:
      LexerException
      See Also:
    • warning

      protected void warning(int line, int column, @NotNull @NotNull String msg) throws LexerException
      Handles a warning.

      If a PreprocessorListener is installed, it receives the warning. Otherwise, an exception is thrown.

      Throws:
      LexerException
    • warning

      protected void warning(@NotNull @NotNull Token tok, @NotNull @NotNull String msg) throws LexerException
      Handles a warning.

      If a PreprocessorListener is installed, it receives the warning. Otherwise, an exception is thrown.

      Throws:
      LexerException
      See Also:
    • addMacro

      public void addMacro(@NotNull @NotNull Macro m) throws LexerException
      Adds a Macro to this Preprocessor.

      The given Macro object encapsulates both the name and the expansion.

      Throws:
      LexerException - if the definition fails or is otherwise illegal.
    • addMacro

      public void addMacro(@NotNull @NotNull String name, @NotNull @NotNull String value) throws LexerException
      Defines the given name as a macro.

      The String value is lexed into a token stream, which is used as the macro expansion.

      Throws:
      LexerException - if the definition fails or is otherwise illegal.
    • addMacro

      public void addMacro(@NotNull @NotNull String name) throws LexerException
      Defines the given name as a macro, with the value 1.

      This is a convnience method, and is equivalent to addMacro(name, "1").

      Throws:
      LexerException - if the definition fails or is otherwise illegal.
    • getMacros

      @NotNull public @NotNull Map<String,Macro> getMacros()
      Returns the Map of Macros parsed during the run of this Preprocessor.
      Returns:
      The Map of macros currently defined.
    • getMacro

      @Nullable public @Nullable Macro getMacro(@NotNull @NotNull String name)
      Returns the named macro.

      While you can modify the returned object, unexpected things might happen if you do.

      Returns:
      the Macro object, or null if not found.
    • getSource

      protected Source getSource()
      Returns the top Source on the input stack.
      Returns:
      the top Source on the input stack.
      See Also:
    • push_source

      protected void push_source(@NotNull @NotNull Source source, boolean autopop)
      Pushes a Source onto the input stack.
      Parameters:
      source - the new Source to push onto the top of the input stack.
      autopop - if true, the Source is automatically removed from the input stack at EOF.
      See Also:
    • pop_source

      @Nullable protected @Nullable Token pop_source()
      Pops a Source from the input stack.
      See Also:
    • pragma

      protected void pragma(@NotNull @NotNull Token name) throws LexerException
      Throws:
      LexerException
    • token

      @NotNull public @NotNull Token token() throws IOException, LexerException
      Returns the next preprocessor token.
      Returns:
      The next fully preprocessed token.
      Throws:
      IOException - if an I/O error occurs.
      LexerException - if a preprocessing error occurs.
      AssertionError - if an unexpected error condition arises.
      See Also:
    • toString

      public String toString()
      Overrides:
      toString in class Object