Top Description Inners Fields Constructors Methods
com.jogamp.gluegen.pcpp

public Class PCPP

extends Object
implements GenericCPP
Class Inheritance
All Implemented Interfaces
com.jogamp.gluegen.GenericCPP
Imports
java.io.BufferedReader, .File, .FileReader, .IOException, .InputStreamReader, .OutputStream, .PrintWriter, .Reader, .StreamTokenizer, java.util.ArrayList, .Collections, .HashMap, .HashSet, .List, .Map, .Set, java.util.logging.Level, com.jogamp.gluegen.ASTLocusTag, .ConstantDefinition, .GenericCPP, .GlueGenException, .Logging, .Logging.LoggerIf

A minimal pseudo-C-preprocessor designed in particular to preserve #define statements defining constants so they can be observed by a glue code generator.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
pack-priv static class

Field Summary

Modifier and TypeField and Description
private static int
private final Map<String, String>
defineMap

Map containing the results of #define statements.

private final boolean
private final List<Boolean>
private final boolean
private final List<String>
includePaths

List containing the #include paths as Strings

private final Logging.LoggerIf
private final Map<String, PCPP.Macro>
private final Set<String>
private OutputStream
private PCPP.ParseState
private PrintWriter

Constructor Summary

AccessConstructor and Description
public
PCPP(final List<String> includePaths, final boolean debug, final boolean copyOutput2Stderr)

Method Summary

Modifier and TypeMethod and Description
public void
addDefine(final String name, final String value)

Implements com.jogamp.gluegen.GenericCPP.addDefine.

private void
addDefine(final String name, final boolean nameIsMacro, List<String> values)

private String
private void
debugPrint(final boolean onlyPrintIfEnabled, final String msg)

private boolean
private String
public String
private void
public List<ConstantDefinition>
getConstantDefinitions()

Implements com.jogamp.gluegen.GenericCPP.getConstantDefinitions.

Returns a list of ConstantDefinition, i.e. non-function-like and non-empty macros w/ constant-value, as derived during parsing.
private void
private void
handleElse()

Handles #else directives

private void
private void
private void
handleIf(final boolean
if true, we're processing #if; if false, we're processing #elif.
isIf
)

private void
handleIfdef(final boolean
if true, we're processing #ifdef; if false, we're processing #ifndef.
isIfdef
)

private boolean

Returns:

the value of the sub-expression or (if greedy==true) series of sub-expressions.
handleIfRecursive
(final boolean
if true, continue evaluating sub-expressions until EOL is reached. If false, return as soon as the first sub-expression is processed.
greedy
)

This method is called recursively to process nested sub-expressions such as:

   #if !defined(OPENSTEP) && !(defined(NeXT) || !defined(NeXT_PDO))
private void
private void
private void
private void
private void
private int
public static void
main(final String[] args)

private void
nextRequiredToken(final int requiredToken)

Reads the next token and throws an IOException if it is not the specified token character.

private int
nextToken()

Equivalent to nextToken(false)

private int
nextToken(final boolean returnEOLs)

private String
private String
public OutputStream
private void
private void
private void
private void
private void
private void
pushEnableBit(final boolean enabled)

private String
resolveDefine(final String word, final boolean returnNullIfNotFound)

public void
run(final Reader reader, final String filename)

Implements com.jogamp.gluegen.GenericCPP.run.

public void
private boolean
private static void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

debugPrintIndentLevelback to summary
private static int debugPrintIndentLevel
defineMapback to summary
private final Map<String, String> defineMap

Map containing the results of #define statements. We must evaluate certain very simple definitions (to properly handle OpenGL's gl.h) but preserve the text of definitions evaluating to constants. Macros and multi-line defines (which typically contain either macro definitions or expressions) are currently not handled.

enableCopyOutput2Stderrback to summary
private final boolean enableCopyOutput2Stderr
enabledBitsback to summary
private final List<Boolean> enabledBits
enableDebugPrintback to summary
private final boolean enableDebugPrint
includePathsback to summary
private final List<String> includePaths

List containing the #include paths as Strings

LOGback to summary
private final Logging.LoggerIf LOG
macroMapback to summary
private final Map<String, PCPP.Macro> macroMap
nonConstantDefinesback to summary
private final Set<String> nonConstantDefines
outback to summary
private OutputStream out
stateback to summary
private PCPP.ParseState state
writerback to summary
private PrintWriter writer

Constructor Detail

PCPPback to summary
public PCPP(final List<String> includePaths, final boolean debug, final boolean copyOutput2Stderr)

Method Detail

addDefineback to summary
public void addDefine(final String name, final String value)

Implements com.jogamp.gluegen.GenericCPP.addDefine.

Annotations
@Override
addDefineback to summary
private void addDefine(final String name, final boolean nameIsMacro, List<String> values)
curTokenAsStringback to summary
private String curTokenAsString()
debugPrintback to summary
private void debugPrint(final boolean onlyPrintIfEnabled, final String msg)
enabledback to summary
private boolean enabled()
filenameback to summary
private String filename()
findFileback to summary
public String findFile(final String filename)

Implements com.jogamp.gluegen.GenericCPP.findFile.

Annotations
@Override
flushback to summary
private void flush()
getConstantDefinitionsback to summary
public List<ConstantDefinition> getConstantDefinitions() throws GlueGenException

Implements com.jogamp.gluegen.GenericCPP.getConstantDefinitions.

Doc from com.jogamp.gluegen.GenericCPP.getConstantDefinitions.

Returns a list of ConstantDefinition, i.e. non-function-like and non-empty macros w/ constant-value, as derived during parsing.

May return an empty list, in case this preprocessor does not store ConstantDefinitions.

Annotations
@Override
handleDefineback to summary
private void handleDefine() throws IOException
handleElseback to summary
private void handleElse() throws IOException

Handles #else directives

handleEndifback to summary
private void handleEndif()
handleErrorback to summary
private void handleError() throws IOException, GlueGenException
handleIfback to summary
private void handleIf(final boolean isIf) throws IOException
Parameters
isIf:boolean

if true, we're processing #if; if false, we're processing #elif.

handleIfdefback to summary
private void handleIfdef(final boolean isIfdef) throws IOException
Parameters
isIfdef:boolean

if true, we're processing #ifdef; if false, we're processing #ifndef.

handleIfRecursiveback to summary
private boolean handleIfRecursive(final boolean greedy) throws IOException

This method is called recursively to process nested sub-expressions such as:

   #if !defined(OPENSTEP) && !(defined(NeXT) || !defined(NeXT_PDO))
Parameters
greedy:boolean

if true, continue evaluating sub-expressions until EOL is reached. If false, return as soon as the first sub-expression is processed.

Returns:boolean

the value of the sub-expression or (if greedy==true) series of sub-expressions.

handleIncludeback to summary
private void handleInclude() throws IOException
handleUndefineback to summary
private void handleUndefine() throws IOException
handleWarningback to summary
private void handleWarning() throws IOException
initTokenizerback to summary
private void initTokenizer(final StreamTokenizer tok)
lineDirectiveback to summary
private void lineDirective()
lineNumberback to summary
private int lineNumber()
mainback to summary
public static void main(final String[] args) throws IOException
nextRequiredTokenback to summary
private void nextRequiredToken(final int requiredToken) throws IOException

Reads the next token and throws an IOException if it is not the specified token character.

nextTokenback to summary
private int nextToken() throws IOException

Equivalent to nextToken(false)

nextTokenback to summary
private int nextToken(final boolean returnEOLs) throws IOException
nextWordback to summary
private String nextWord() throws IOException
nextWordOrStringback to summary
private String nextWordOrString() throws IOException
outback to summary
public OutputStream out()

Implements com.jogamp.gluegen.GenericCPP.out.

Annotations
@Override
parseback to summary
private void parse() throws IOException
popEnableBitback to summary
private void popEnableBit()
preprocessorDirectiveback to summary
private void preprocessorDirective() throws IOException
printlnback to summary
private void println()
printTokenback to summary
private void printToken()
pushEnableBitback to summary
private void pushEnableBit(final boolean enabled)
resolveDefineback to summary
private String resolveDefine(final String word, final boolean returnNullIfNotFound)
runback to summary
public void run(final Reader reader, final String filename) throws GlueGenException

Implements com.jogamp.gluegen.GenericCPP.run.

Annotations
@Override
setOutback to summary
public void setOut(final OutputStream out)

Implements com.jogamp.gluegen.GenericCPP.setOut.

Annotations
@Override
startOfLineback to summary
private boolean startOfLine()
usageback to summary
private static void usage()
com.jogamp.gluegen.pcpp back to summary

private Class PCPP.Macro

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final List<String>
private final List<String>

Constructor Summary

AccessConstructor and Description
pack-priv
Macro(final List<String> params, final List<String> values)

Method Summary

Modifier and TypeMethod and Description
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

paramsback to summary
private final List<String> params
valuesback to summary
private final List<String> values

Constructor Detail

Macroback to summary
pack-priv Macro(final List<String> params, final List<String> values)

Method Detail

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
com.jogamp.gluegen.pcpp back to summary

pack-priv Class PCPP.ParseState

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final String
private boolean
private boolean
private final StreamTokenizer

Constructor Summary

AccessConstructor and Description
pack-priv
ParseState(final StreamTokenizer tok, final String filename)

Method Summary

Modifier and TypeMethod and Description
pack-priv int
pack-priv String
pack-priv String
pack-priv int
pack-priv int
pack-priv void
pack-priv void
setStartOfFile(final boolean val)

pack-priv void
setStartOfLine(final boolean val)

pack-priv boolean
pack-priv boolean
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

filenameback to summary
private final String filename
startOfFileback to summary
private boolean startOfFile
startOfLineback to summary
private boolean startOfLine
tokback to summary
private final StreamTokenizer tok

Constructor Detail

ParseStateback to summary
pack-priv ParseState(final StreamTokenizer tok, final String filename)

Method Detail

curTokenback to summary
pack-priv int curToken()
curWordback to summary
pack-priv String curWord()
filenameback to summary
pack-priv String filename()
lineNumberback to summary
pack-priv int lineNumber()
nextTokenback to summary
pack-priv int nextToken() throws IOException
pushBackTokenback to summary
pack-priv void pushBackToken() throws IOException
setStartOfFileback to summary
pack-priv void setStartOfFile(final boolean val)
setStartOfLineback to summary
pack-priv void setStartOfLine(final boolean val)
startOfFileback to summary
pack-priv boolean startOfFile()
startOfLineback to summary
pack-priv boolean startOfLine()