Package com.jogamp.gluegen.jcpp
Class Preprocessor
- java.lang.Object
-
- com.jogamp.gluegen.jcpp.Preprocessor
-
- All Implemented Interfaces:
Closeable
,AutoCloseable
public class Preprocessor extends Object implements Closeable
-
-
Constructor Summary
Constructors Constructor Description Preprocessor()
Preprocessor(Source initial)
Preprocessor(File file)
Equivalent to 'new Preprocessor(newFileLexerSource
(file))'
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addFeature(Feature f)
Adds a feature to the feature-set of this Preprocessor.void
addFeatures(Feature... f)
Adds features to the feature-set of this Preprocessor.void
addFeatures(Collection<Feature> f)
Adds features to the feature-set of this Preprocessor.void
addInput(Source source)
Adds input for the Preprocessor.void
addInput(File file)
Adds input for the Preprocessor.void
addMacro(Macro m)
Adds a Macro to this Preprocessor.void
addMacro(String name)
Defines the given name as a macro, with the value1
.void
addMacro(String name, String value)
Defines the given name as a macro.void
addWarning(Warning w)
Adds a warning to the warning-set of this Preprocessor.void
addWarnings(Collection<Warning> w)
Adds warnings to the warning-set of this Preprocessor.void
close()
protected void
error(int line, int column, String msg)
Handles an error.protected void
error(Token tok, String msg)
Handles an error.boolean
getFeature(Feature f)
Returns true if the given feature is in the feature-set of this Preprocessor.Set<Feature>
getFeatures()
Returns the feature-set for this Preprocessor.VirtualFileSystem
getFileSystem()
Returns the VirtualFileSystem used by this Preprocessor.List<String>
getFrameworksPath()
Returns the Objective-C frameworks path used by this Preprocessor.List<? extends VirtualFile>
getIncludes()
Returns the list ofVirtualFiles
which have been included by this Preprocessor.PreprocessorListener
getListener()
Returns the PreprocessorListener which handles events for this Preprocessor.Macro
getMacro(String name)
Returns the named macro.Map<String,Macro>
getMacros()
Returns the Map of Macros parsed during the run of this Preprocessor.List<Macro>
getMacros(boolean expand)
Returns a list ofMacro
s.List<String>
getQuoteIncludePath()
Returns the user include-path of this Preprocessor.Source
getSource()
Returns the top Source on the input stack.List<String>
getSystemIncludePath()
Returns the system include-path of this Preprocessor.boolean
getWarning(Warning w)
Returns true if the given warning is in the warning-set of this Preprocessor.Set<Warning>
getWarnings()
Returns the warning-set for this Preprocessor.protected boolean
include(VirtualFile file)
Attempts to include the given file.protected boolean
include(Iterable<String> path, String name)
Attempts to include a file from an include path, by name.protected void
pop_source()
protected Token
pop_source(boolean linemarker)
Pops a Source from the input stack.protected void
pragma(Token name, List<Token> value)
protected void
pragma_once(Token name)
protected void
push_source(Source source, boolean autopop)
Pushes a Source onto the input stack.void
setFileSystem(VirtualFileSystem filesystem)
Sets the VirtualFileSystem used by this Preprocessor.void
setFrameworksPath(List<String> path)
Sets the Objective-C frameworks path used by this Preprocessor.void
setListener(PreprocessorListener listener)
Sets the PreprocessorListener which handles events for this Preprocessor.void
setQuoteIncludePath(List<String> path)
Sets the user include path used by this Preprocessor.void
setSystemIncludePath(List<String> path)
Sets the system include path used by this Preprocessor.Token
token()
Returns the next preprocessor token.String
toString()
protected void
warning(int line, int column, String msg)
Handles a warning.protected void
warning(Token tok, String msg)
Handles a warning.
-
-
-
Constructor Detail
-
Preprocessor
public Preprocessor()
-
Preprocessor
public Preprocessor(@Nonnull Source initial)
-
Preprocessor
public Preprocessor(@Nonnull File file) throws IOException
Equivalent to 'new Preprocessor(newFileLexerSource
(file))'- Throws:
IOException
-
-
Method Detail
-
setFileSystem
public void setFileSystem(@Nonnull VirtualFileSystem filesystem)
Sets the VirtualFileSystem used by this Preprocessor.
-
getFileSystem
@Nonnull public VirtualFileSystem getFileSystem()
Returns the VirtualFileSystem used by this Preprocessor.
-
setListener
public void setListener(@Nonnull PreprocessorListener listener)
Sets the PreprocessorListener which handles events for this Preprocessor. The listener is notified of warnings, errors and source changes, amongst other things.
-
getListener
@Nonnull public PreprocessorListener getListener()
Returns the PreprocessorListener which handles events for this Preprocessor.
-
getFeatures
@Nonnull public Set<Feature> getFeatures()
Returns the feature-set for this Preprocessor. This set may be freely modified by user code.
-
addFeature
public void addFeature(@Nonnull Feature f)
Adds a feature to the feature-set of this Preprocessor.
-
addFeatures
public void addFeatures(@Nonnull Collection<Feature> f)
Adds features to the feature-set of this Preprocessor.
-
addFeatures
public void addFeatures(Feature... f)
Adds features to the feature-set of this Preprocessor.
-
getFeature
public boolean getFeature(@Nonnull Feature f)
Returns true if the given feature is in the feature-set of this Preprocessor.
-
getWarnings
@Nonnull public Set<Warning> getWarnings()
Returns the warning-set for this Preprocessor. This set may be freely modified by user code.
-
addWarning
public void addWarning(@Nonnull Warning w)
Adds a warning to the warning-set of this Preprocessor.
-
addWarnings
public void addWarnings(@Nonnull Collection<Warning> w)
Adds warnings to the warning-set of this Preprocessor.
-
getWarning
public boolean getWarning(@Nonnull Warning w)
Returns true if the given warning is in the warning-set of this Preprocessor.
-
addInput
public void addInput(@Nonnull Source source)
Adds input for the Preprocessor. Inputs are processed in the order in which they are added.
-
addInput
public void addInput(@Nonnull File file) throws IOException
Adds input for the Preprocessor.- Throws:
IOException
- See Also:
addInput(Source)
-
error
protected void error(int line, int column, @Nonnull 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(@Nonnull Token tok, @Nonnull 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:
error(int, int, String)
-
warning
protected void warning(int line, int column, @Nonnull 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(@Nonnull Token tok, @Nonnull 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:
warning(int, int, String)
-
addMacro
public void addMacro(@Nonnull Macro m) throws LexerException, IOException
Adds a Macro to this Preprocessor. The givenMacro
object encapsulates both the name and the expansion.- Throws:
LexerException
- if the definition fails or is otherwise illegal.IOException
-
addMacro
public void addMacro(@Nonnull String name, @Nonnull 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(@Nonnull String name) throws LexerException
Defines the given name as a macro, with the value1
. This is a convnience method, and is equivalent toaddMacro(name, "1")
.- Throws:
LexerException
- if the definition fails or is otherwise illegal.
-
setQuoteIncludePath
public void setQuoteIncludePath(@Nonnull List<String> path)
Sets the user include path used by this Preprocessor.
-
getQuoteIncludePath
@Nonnull public List<String> getQuoteIncludePath()
Returns the user include-path of this Preprocessor. This list may be freely modified by user code.
-
setSystemIncludePath
public void setSystemIncludePath(@Nonnull List<String> path)
Sets the system include path used by this Preprocessor.
-
getSystemIncludePath
@Nonnull public List<String> getSystemIncludePath()
Returns the system include-path of this Preprocessor. This list may be freely modified by user code.
-
setFrameworksPath
public void setFrameworksPath(@Nonnull List<String> path)
Sets the Objective-C frameworks path used by this Preprocessor.
-
getFrameworksPath
@Nonnull public List<String> getFrameworksPath()
Returns the Objective-C frameworks path used by this Preprocessor. This list may be freely modified by user code.
-
getMacros
@Nonnull public Map<String,Macro> getMacros()
Returns the Map of Macros parsed during the run of this Preprocessor.- Returns:
- The
Map
of macros currently defined.
-
getMacros
public List<Macro> getMacros(boolean expand) throws IOException, LexerException
- Parameters:
expand
- iftrue
and if macro is notfunction-like
, i.e. a constant, the returned macro will be expanded.- Throws:
IOException
LexerException
-
getMacro
@CheckForNull public Macro getMacro(@Nonnull 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.
-
getIncludes
@Nonnull public List<? extends VirtualFile> getIncludes()
Returns the list ofVirtualFiles
which have been included by this Preprocessor. This does not include anySource
provided to the constructor oraddInput(java.io.File)
oraddInput(Source)
.
-
getSource
public Source getSource()
Returns the top Source on the input stack.- Returns:
- the top Source on the input stack.
- See Also:
Source
,push_source(Source,boolean)
,pop_source()
-
push_source
protected void push_source(@Nonnull 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:
getSource()
,pop_source()
-
pop_source
@CheckForNull protected Token pop_source(boolean linemarker) throws IOException
Pops a Source from the input stack.- Parameters:
linemarker
- TODO: currently ignored, might be a bug?- Throws:
IOException
- if an I/O error occurs.- See Also:
getSource()
,push_source(Source,boolean)
-
pop_source
protected void pop_source() throws IOException
- Throws:
IOException
-
include
protected boolean include(@Nonnull VirtualFile file) throws IOException
Attempts to include the given file. User code may override this method to implement a virtual file system.- Parameters:
file
- The VirtualFile to attempt to include.- Returns:
- true if the file was successfully included, false otherwise.
- Throws:
IOException
- if an I/O error occurs.
-
include
protected boolean include(@Nonnull Iterable<String> path, @Nonnull String name) throws IOException
Attempts to include a file from an include path, by name.- Parameters:
path
- The list of virtual directories to search for the given name.name
- The name of the file to attempt to include.- Returns:
- true if the file was successfully included, false otherwise.
- Throws:
IOException
- if an I/O error occurs.
-
pragma_once
protected void pragma_once(@Nonnull Token name) throws IOException, LexerException
- Throws:
IOException
LexerException
-
pragma
protected void pragma(@Nonnull Token name, @Nonnull List<Token> value) throws IOException, LexerException
- Throws:
IOException
LexerException
-
token
@Nonnull public 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.InternalException
- if an unexpected error condition arises.- See Also:
Token
-
close
public void close() throws IOException
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
-
-