Top Description Fields Constructors Methods
com.jogamp.gluegen.jcpp

public Class Preprocessor

extends Object
implements Closeable
Class Inheritance
All Implemented Interfaces
java.io.Closeable, java.lang.AutoCloseable
Imports
java.io.Closeable, .File, .IOException, java.util.ArrayList, .Arrays, .Collection, .Collections, .EnumSet, .HashMap, .HashSet, .List, .Map, .Set, .Stack, .TreeMap, javax.annotation.CheckForNull, .Nonnull, com.jogamp.gluegen.Logging, .Logging.LoggerIf, com.jogamp.gluegen.jcpp.PreprocessorListener.SourceChangeEvent

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. (See CppReader, which does this.)

Field Summary

Modifier and TypeField and Description
private static final Macro
private static final Macro
private static final Macro
private int
private Token
private final Set<Feature>
private VirtualFileSystem
private List<String>
private final List<VirtualFile>
private final List<Source>
private static final Source
private PreprocessorListener
private final Logging.LoggerIf
private final Map<String, Macro>
private final Set<String>
private List<String>
private Source
private Token
private final Stack<State>
private List<String>
private final Set<Warning>

Constructor Summary

AccessConstructor and Description
public
public
Preprocessor(final Source initial)

public
Preprocessor(final File file)

Equivalent to 'new Preprocessor(new FileLexerSource(file))'

Method Summary

Modifier and TypeMethod and Description
private Token
public void
addFeature(final Feature f)

Adds a feature to the feature-set of this Preprocessor.

public void
addFeatures(final Collection<Feature> f)

Adds features to the feature-set of this Preprocessor.

public void
addFeatures(final Feature... f)

Adds features to the feature-set of this Preprocessor.

public void
addInput(final Source source)

Adds input for the Preprocessor.

public void
addInput(final File file)

Adds input for the Preprocessor.

public void
addMacro(final Macro m)

Adds a Macro to this Preprocessor.

public void
addMacro(final String name, final String value)

Defines the given name as a macro.

public void
addMacro(final String name)

Defines the given name as a macro, with the value 1.

public void
addWarning(final Warning w)

Adds a warning to the warning-set of this Preprocessor.

public void
addWarnings(final Collection<Warning> w)

Adds warnings to the warning-set of this Preprocessor.

public void
close()

Implements java.io.Closeable.close.

Closes this stream and releases any system resources associated with it.
private Token
protected void
error(final int line, final int column, final String msg)

Handles an error.

protected void
error(final Token tok, final String msg)

Handles an error.

private void
error(final Token pptok, final boolean is_error)

pack-priv List<Token>
expand(final List<Token> arg)

Expands an argument.

private Token
private Token
private long
expr(final int priority)

private int
expr_priority(final Token op)

private Token
private void
expr_untoken(final Token tok)

public boolean
getFeature(final Feature f)

Returns true if the given feature is in the feature-set of this Preprocessor.

public Set<Feature>
getFeatures()

Returns the feature-set for this Preprocessor.

public VirtualFileSystem
getFileSystem()

Returns the VirtualFileSystem used by this Preprocessor.

public List<String>
getFrameworksPath()

Returns the Objective-C frameworks path used by this Preprocessor.

public List<? extends VirtualFile>
getIncludes()

Returns the list of VirtualFiles which have been included by this Preprocessor.

public PreprocessorListener
getListener()

Returns the PreprocessorListener which handles events for this Preprocessor.

public Macro
getMacro(final String name)

Returns the named macro.

public Map<String, Macro>
getMacros()

Returns the Map of Macros parsed during the run of this Preprocessor.

public List<Macro>
getMacros(final boolean
if true and if macro is not function-like, i.e. a constant, the returned macro will be expanded.
expand
)

Returns a list of Macros.

public List<String>
getQuoteIncludePath()

Returns the user include-path of this Preprocessor.

public Source
getSource()

Returns the top Source on the input stack.

public List<String>
getSystemIncludePath()

Returns the system include-path of this Preprocessor.

public boolean
getWarning(final Warning w)

Returns true if the given warning is in the warning-set of this Preprocessor.

public Set<Warning>
getWarnings()

Returns the warning-set for this Preprocessor.

protected boolean
include(final VirtualFile file)

Attempts to include the given file.

protected boolean
include(final Iterable<String> path, final String name)

Includes a file from an include path, by name.

private void
include(final String parent, final int line, final String name, final boolean quoted, final boolean next)

Handles an include directive.

private Token
include(final boolean next)

private boolean
private boolean
isWhite(final Token tok)

private Token
line_token(final int line, final String name, final String extra)

private boolean
macro(final Macro m, final Token orig)

private Token
protected Token
pop_source(final boolean linemarker)

Pops a Source from the input stack.

protected void
private void
protected void
pragma(final Token name, final List<Token> value)

private Token
protected void
pragma_once(final Token name)

protected void
push_source(final Source source, final boolean autopop)

Pushes a Source onto the input stack.

private void
public void
setFileSystem(final VirtualFileSystem filesystem)

Sets the VirtualFileSystem used by this Preprocessor.

public void
setFrameworksPath(final List<String> path)

Sets the Objective-C frameworks path used by this Preprocessor.

public void
setListener(final PreprocessorListener listener)

Sets the PreprocessorListener which handles events for this Preprocessor.

public void
setQuoteIncludePath(final List<String> path)

Sets the user include path used by this Preprocessor.

public void
setSystemIncludePath(final List<String> path)

Sets the system include path used by this Preprocessor.

private Token
source_skipline(final boolean white)

Returns an NL or an EOF token.

private Token
private Token
private void
source_untoken(final Token tok)

public Token
token()

Returns the next preprocessor token.

private Token
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
private Token
toWhitespace(final Token tok)

private Token
protected void
warning(final int line, final int column, final String msg)

Handles a warning.

protected void
warning(final Token tok, final String msg)

Handles a warning.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

__COUNTER__back to summary
private static final Macro __COUNTER__
__FILE__back to summary
private static final Macro __FILE__
__LINE__back to summary
private static final Macro __LINE__
counterback to summary
private int counter
expr_tokenback to summary
private Token expr_token
Annotations
@CheckForNull
featuresback to summary
private final Set<Feature> features
filesystemback to summary
private VirtualFileSystem filesystem
frameworkspathback to summary
private List<String> frameworkspath
includesback to summary
private final List<VirtualFile> includes
inputsback to summary
private final List<Source> inputs
INTERNALback to summary
private static final Source INTERNAL
listenerback to summary
private PreprocessorListener listener
LOGback to summary
private final Logging.LoggerIf LOG
macrosback to summary
private final Map<String, Macro> macros
onceseenpathsback to summary
private final Set<String> onceseenpaths
quoteincludepathback to summary
private List<String> quoteincludepath
sourceback to summary
private Source source
source_tokenback to summary
private Token source_token
statesback to summary
private final Stack<State> states
sysincludepathback to summary
private List<String> sysincludepath
warningsback to summary
private final Set<Warning> warnings

Constructor Detail

Preprocessorback to summary
public Preprocessor()
Preprocessorback to summary
public Preprocessor(final Source initial)
Preprocessorback to summary
public Preprocessor(final File file) throws IOException

Equivalent to 'new Preprocessor(new FileLexerSource(file))'

Method Detail

_tokenback to summary
private Token _token() throws IOException, LexerException
Annotations
@Nonnull
addFeatureback to summary
public void addFeature(final Feature f)

Adds a feature to the feature-set of this Preprocessor.

addFeaturesback to summary
public void addFeatures(final Collection<Feature> f)

Adds features to the feature-set of this Preprocessor.

addFeaturesback to summary
public void addFeatures(final Feature... f)

Adds features to the feature-set of this Preprocessor.

addInputback to summary
public void addInput(final Source source)

Adds input for the Preprocessor. Inputs are processed in the order in which they are added.

addInputback to summary
public void addInput(final File file) throws IOException

Adds input for the Preprocessor.

See Also
addInput(Source)
addMacroback to summary
public void addMacro(final Macro m) throws LexerException, IOException

Adds a Macro to this Preprocessor. The given Macro object encapsulates both the name and the expansion.

addMacroback to summary
public void addMacro(final String name, final 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.

addMacroback to summary
public void addMacro(final 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").

addWarningback to summary
public void addWarning(final Warning w)

Adds a warning to the warning-set of this Preprocessor.

addWarningsback to summary
public void addWarnings(final Collection<Warning> w)

Adds warnings to the warning-set of this Preprocessor.

closeback to summary
public void close() throws IOException

Implements java.io.Closeable.close.

Doc from java.io.Closeable.close.

Closes this stream and releases any system resources associated with it. If the stream is already closed then invoking this method has no effect.

As noted in AutoCloseable#close(), cases where the close may fail require careful attention. It is strongly advised to relinquish the underlying resources and to internally mark the Closeable as closed, prior to throwing the IOException.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs
defineback to summary
private Token define() throws IOException, LexerException
errorback to summary
protected void error(final int line, final int column, final String msg) throws LexerException

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

errorback to summary
protected void error(final Token tok, final String msg) throws LexerException

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

See Also
error(int, int, String)
errorback to summary
private void error(final Token pptok, final boolean is_error) throws IOException, LexerException
expandback to summary
pack-priv List<Token> expand(final List<Token> arg) throws IOException, LexerException

Expands an argument.

Annotations
@Nonnull
expanded_tokenback to summary
private Token expanded_token() throws IOException, LexerException
Annotations
@Nonnull
expanded_token_nonwhiteback to summary
private Token expanded_token_nonwhite() throws IOException, LexerException
Annotations
@Nonnull
exprback to summary
private long expr(final int priority) throws IOException, LexerException
expr_priorityback to summary
private int expr_priority(final Token op)
expr_tokenback to summary
private Token expr_token() throws IOException, LexerException
Annotations
@Nonnull
expr_untokenback to summary
private void expr_untoken(final Token tok) throws LexerException
getFeatureback to summary
public boolean getFeature(final Feature f)

Returns true if the given feature is in the feature-set of this Preprocessor.

getFeaturesback to summary
public Set<Feature> getFeatures()

Returns the feature-set for this Preprocessor. This set may be freely modified by user code.

Annotations
@Nonnull
getFileSystemback to summary
public VirtualFileSystem getFileSystem()

Returns the VirtualFileSystem used by this Preprocessor.

Annotations
@Nonnull
getFrameworksPathback to summary
public List<String> getFrameworksPath()

Returns the Objective-C frameworks path used by this Preprocessor. This list may be freely modified by user code.

Annotations
@Nonnull
getIncludesback to summary
public List<? extends VirtualFile> getIncludes()

Returns the list of VirtualFiles which have been included by this Preprocessor. This does not include any Source provided to the constructor or addInput(java.io.File) or addInput(Source).

Annotations
@Nonnull
getListenerback to summary
public PreprocessorListener getListener()

Returns the PreprocessorListener which handles events for this Preprocessor.

Annotations
@Nonnull
getMacroback to summary
public Macro getMacro(final String name)

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

Annotations
@CheckForNull
getMacrosback to summary
public Map<String, Macro> getMacros()

Returns the Map of Macros parsed during the run of this Preprocessor.

Annotations
@Nonnull
getMacrosback to summary
public List<Macro> getMacros(final boolean expand) throws IOException, LexerException

Returns a list of Macros.

Implementation returns a new list of copy-ctor Macros.

Parameters
expand:boolean

if true and if macro is not function-like, i.e. a constant, the returned macro will be expanded.

getQuoteIncludePathback to summary
public List<String> getQuoteIncludePath()

Returns the user include-path of this Preprocessor. This list may be freely modified by user code.

Annotations
@Nonnull
getSourceback to summary
public Source getSource()

Returns the top Source on the input stack.

See Also
Source, push_source(Source, boolean), pop_source()
getSystemIncludePathback to summary
public List<String> getSystemIncludePath()

Returns the system include-path of this Preprocessor. This list may be freely modified by user code.

Annotations
@Nonnull
getWarningback to summary
public boolean getWarning(final Warning w)

Returns true if the given warning is in the warning-set of this Preprocessor.

getWarningsback to summary
public Set<Warning> getWarnings()

Returns the warning-set for this Preprocessor. This set may be freely modified by user code.

Annotations
@Nonnull
includeback to summary
protected boolean include(final VirtualFile file) throws IOException, LexerException

Attempts to include the given file. User code may override this method to implement a virtual file system.

includeback to summary
protected boolean include(final Iterable<String> path, final String name) throws IOException, LexerException

Includes a file from an include path, by name.

includeback to summary
private void include(final String parent, final int line, final String name, final boolean quoted, final boolean next) throws IOException, LexerException

Handles an include directive.

includeback to summary
private Token include(final boolean next) throws IOException, LexerException
Annotations
@Nonnull
isActiveback to summary
private boolean isActive()
isWhiteback to summary
private boolean isWhite(final Token tok)
line_tokenback to summary
private Token line_token(final int line, final String name, final String extra)
Annotations
@Nonnull
macroback to summary
private boolean macro(final Macro m, final Token orig) throws IOException, LexerException
next_sourceback to summary
private Token next_source()
Annotations
@Nonnull
pop_sourceback to summary
protected Token pop_source(final boolean linemarker) throws IOException

Pops a Source from the input stack.

Annotations
@CheckForNull
See Also
getSource(), push_source(Source, boolean)
pop_sourceback to summary
protected void pop_source() throws IOException
pop_stateback to summary
private void pop_state() throws LexerException
pragmaback to summary
protected void pragma(final Token name, final List<Token> value) throws IOException, LexerException
pragmaback to summary
private Token pragma() throws IOException, LexerException
Annotations
@Nonnull
pragma_onceback to summary
protected void pragma_once(final Token name) throws IOException, LexerException
push_sourceback to summary
protected void push_source(final Source source, final boolean autopop)

Pushes a Source onto the input stack.

See Also
getSource(), pop_source()
push_stateback to summary
private void push_state()
setFileSystemback to summary
public void setFileSystem(final VirtualFileSystem filesystem)

Sets the VirtualFileSystem used by this Preprocessor.

setFrameworksPathback to summary
public void setFrameworksPath(final List<String> path)

Sets the Objective-C frameworks path used by this Preprocessor.

setListenerback to summary
public void setListener(final PreprocessorListener listener)

Sets the PreprocessorListener which handles events for this Preprocessor. The listener is notified of warnings, errors and source changes, amongst other things.

setQuoteIncludePathback to summary
public void setQuoteIncludePath(final List<String> path)

Sets the user include path used by this Preprocessor.

setSystemIncludePathback to summary
public void setSystemIncludePath(final List<String> path)

Sets the system include path used by this Preprocessor.

source_skiplineback to summary
private Token source_skipline(final boolean white) throws IOException, LexerException

Returns an NL or an EOF token. The metadata on the token will be correct, which is better than generating a new one. This method can, as of recent patches, return a P_LINE token.

source_tokenback to summary
private Token source_token() throws IOException, LexerException
Annotations
@Nonnull
source_token_nonwhiteback to summary
private Token source_token_nonwhite() throws IOException, LexerException
source_untokenback to summary
private void source_untoken(final Token tok)
tokenback to summary
public Token token() throws IOException, LexerException

Returns the next preprocessor token.

Annotations
@Nonnull
Exceptions
LexerException:
if a preprocessing error occurs.
InternalException:
if an unexpected error condition arises.
See Also
Token
token_nonwhiteback to summary
private Token token_nonwhite() throws IOException, LexerException
Annotations
@Nonnull
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object

Annotations
@Override
toWhitespaceback to summary
private Token toWhitespace(final Token tok)
Annotations
@Nonnull
undefback to summary
private Token undef() throws IOException, LexerException
Annotations
@Nonnull
warningback to summary
protected void warning(final int line, final int column, final String msg) throws LexerException

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

warningback to summary
protected void warning(final Token tok, final String msg) throws LexerException

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

See Also
warning(int, int, String)