Package com.sun.tools.corba.ee.idl
Class Preprocessor
- java.lang.Object
-
- com.sun.tools.corba.ee.idl.Preprocessor
-
public class Preprocessor extends java.lang.Object
This class should be extended if new pragmas are desired. If the preprocessor encounters a pragma name which it doesn't recognize (anything other than ID, prefix, or version), it calls the method otherPragmas. This is the only method which need be overridden. The Preprocessor base class has a number of utility-like methods which can be used by the overridden otherPragmas method.
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.Stack<java.lang.Boolean>
alreadyProcessedABranch
private static java.lang.String
indent
private boolean
lastWasMacroID
private java.util.Vector<java.lang.String>
macros
private Parser
parser
private java.util.Vector<PragmaHandler>
pragmaHandlers
private java.util.Vector<SymtabEntry>
PragmaIDs
private Scanner
scanner
private java.util.Hashtable<java.lang.String,java.lang.String>
symbols
(package private) Token
token
-
Constructor Summary
Constructors Constructor Description Preprocessor()
Public zero-argument constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private Expression
andExpr(Expression e, SymtabEntry entry)
(package private) Expression
booleanConstExpr(SymtabEntry entry)
protected java.lang.Object
clone()
(package private) void
closeScope(SymtabEntry entry)
This method is called when the parser encounters a right curly brace.private void
constExpr()
(package private) java.lang.String
currentToken()
Get the current token.private void
define()
private Expression
definedExpr(SymtabEntry entry)
private void
elif()
private boolean
embedded(java.lang.String string, int index, int endIndex)
private Expression
equalityExpr(Expression e, SymtabEntry entry)
(package private) java.lang.String
expandMacro(java.lang.String macroDef, Token t)
(package private) SymtabEntry
getEntryForName(java.lang.String string)
This method, given an entry name, returns the entry with that name.private java.lang.String
getFilename(java.lang.String name)
private java.util.Vector<java.lang.String>
getParmValues()
(package private) java.lang.String
getStringToEOL()
This method returns a string of all of the characters from the input file from the current position up to, but not including, the end-of-line character(s).(package private) java.lang.String
getUntil(char c)
This method returns a string of all of the characters from the input file from the current position up to, but not including, the given character.private void
idPragma()
private void
ifClause()
private void
ifdef(boolean not)
private void
ifDefine(boolean inParens, boolean not)
private void
include()
private void
include2(IncludeEntry include)
private void
include3(IncludeEntry include)
private void
include4(IncludeEntry include, java.lang.String filename)
(package private) void
init(Parser p)
private boolean
inQuotes(java.lang.String string, int index)
private void
localPragma()
private void
localServantPragma()
private void
macro(java.util.Vector<java.lang.String> parmNames)
private void
macroParms(java.util.Vector<java.lang.String> parmNames)
private void
macroParms2(java.util.Vector<java.lang.String> parmNames)
private void
macroParmValues(java.util.Vector<java.lang.String> values)
private void
match(int type)
private void
miniMatch(int type)
(package private) java.lang.String
nextToken()
This method returns the next token String from the input file.private Expression
notExpr(SymtabEntry entry)
(package private) void
openScope(SymtabEntry entry)
This method is called when the parser encounters a left curly brace.private Expression
orExpr(Expression e, SymtabEntry entry)
private void
otherPragmas(java.lang.String pragmaType, java.lang.String currentToken)
(package private) void
parseException(java.lang.String message)
This method displays a Parser Exception complete with line number and position information with the given message string.private void
pragma()
private void
prefixPragma()
(package private) Expression
primaryExpr(SymtabEntry entry)
(package private) Token
process(Token t)
(package private) void
registerPragma(PragmaHandler handler)
private java.lang.String
removeDoublePound(java.lang.String string)
Remove any occurrences of ##.private java.lang.String
replaceAll(java.lang.String string, java.lang.String from, java.lang.String to)
(package private) SymtabEntry
scopedName()
This method assumes that the current token marks the beginning of a scoped name.private void
skipToEndif()
private void
skipToEndiforElse()
(package private) void
skipToEOL()
Skip to the end of the line.(package private) java.lang.String
skipUntil(char c)
This method skips the data in the input file until the specified character is encountered, then it returns the next token.private java.lang.String
tokenToString()
private void
undefine()
private void
versionPragma()
-
-
-
Field Detail
-
PragmaIDs
private final java.util.Vector<SymtabEntry> PragmaIDs
-
pragmaHandlers
private final java.util.Vector<PragmaHandler> pragmaHandlers
-
lastWasMacroID
private boolean lastWasMacroID
-
parser
private Parser parser
-
scanner
private Scanner scanner
-
symbols
private java.util.Hashtable<java.lang.String,java.lang.String> symbols
-
macros
private java.util.Vector<java.lang.String> macros
-
alreadyProcessedABranch
private final java.util.Stack<java.lang.Boolean> alreadyProcessedABranch
-
token
Token token
-
indent
private static java.lang.String indent
-
-
Method Detail
-
init
void init(Parser p)
-
clone
protected java.lang.Object clone()
- Overrides:
clone
in classjava.lang.Object
-
process
Token process(Token t) throws java.io.IOException, ParseException
- Throws:
java.io.IOException
ParseException
-
include
private void include() throws java.io.IOException, ParseException
- Throws:
java.io.IOException
ParseException
-
include2
private void include2(IncludeEntry include) throws java.io.IOException, ParseException
- Throws:
java.io.IOException
ParseException
-
include3
private void include3(IncludeEntry include) throws java.io.IOException, ParseException
- Throws:
java.io.IOException
ParseException
-
include4
private void include4(IncludeEntry include, java.lang.String filename) throws java.io.IOException, ParseException
- Throws:
java.io.IOException
ParseException
-
define
private void define() throws java.io.IOException, ParseException
- Throws:
java.io.IOException
ParseException
-
undefine
private void undefine() throws java.io.IOException, ParseException
- Throws:
java.io.IOException
ParseException
-
ifClause
private void ifClause() throws java.io.IOException, ParseException
- Throws:
java.io.IOException
ParseException
-
constExpr
private void constExpr() throws java.io.IOException, ParseException
- Throws:
java.io.IOException
ParseException
-
booleanConstExpr
Expression booleanConstExpr(SymtabEntry entry) throws java.io.IOException, ParseException
- Throws:
java.io.IOException
ParseException
-
orExpr
private Expression orExpr(Expression e, SymtabEntry entry) throws java.io.IOException, ParseException
- Throws:
java.io.IOException
ParseException
-
andExpr
private Expression andExpr(Expression e, SymtabEntry entry) throws java.io.IOException, ParseException
- Throws:
java.io.IOException
ParseException
-
notExpr
private Expression notExpr(SymtabEntry entry) throws java.io.IOException, ParseException
- Throws:
java.io.IOException
ParseException
-
definedExpr
private Expression definedExpr(SymtabEntry entry) throws java.io.IOException, ParseException
- Throws:
java.io.IOException
ParseException
-
equalityExpr
private Expression equalityExpr(Expression e, SymtabEntry entry) throws java.io.IOException, ParseException
- Throws:
java.io.IOException
ParseException
-
primaryExpr
Expression primaryExpr(SymtabEntry entry) throws java.io.IOException, ParseException
- Throws:
java.io.IOException
ParseException
-
ifDefine
private void ifDefine(boolean inParens, boolean not) throws java.io.IOException, ParseException
- Throws:
java.io.IOException
ParseException
-
ifdef
private void ifdef(boolean not) throws java.io.IOException, ParseException
- Throws:
java.io.IOException
ParseException
-
elif
private void elif() throws java.io.IOException, ParseException
- Throws:
java.io.IOException
ParseException
-
skipToEndiforElse
private void skipToEndiforElse() throws java.io.IOException, ParseException
- Throws:
java.io.IOException
ParseException
-
skipToEndif
private void skipToEndif() throws java.io.IOException, ParseException
- Throws:
java.io.IOException
ParseException
-
pragma
private void pragma() throws java.io.IOException, ParseException
- Throws:
java.io.IOException
ParseException
-
localPragma
private void localPragma() throws java.io.IOException, ParseException
- Throws:
java.io.IOException
ParseException
-
localServantPragma
private void localServantPragma() throws java.io.IOException, ParseException
- Throws:
java.io.IOException
ParseException
-
idPragma
private void idPragma() throws java.io.IOException, ParseException
- Throws:
java.io.IOException
ParseException
-
prefixPragma
private void prefixPragma() throws java.io.IOException, ParseException
- Throws:
java.io.IOException
ParseException
-
versionPragma
private void versionPragma() throws java.io.IOException, ParseException
- Throws:
java.io.IOException
ParseException
-
registerPragma
void registerPragma(PragmaHandler handler)
-
otherPragmas
private void otherPragmas(java.lang.String pragmaType, java.lang.String currentToken) throws java.io.IOException
- Throws:
java.io.IOException
-
currentToken
java.lang.String currentToken()
Get the current token.- Returns:
- the current token
-
getEntryForName
SymtabEntry getEntryForName(java.lang.String string)
This method, given an entry name, returns the entry with that name. It can take fully or partially qualified names and returns the appropriate entry defined within the current scope. If no entry exists, null is returned.- Parameters:
string
- entry name to look for- Returns:
- entry with that name or
null
if no entry
-
getStringToEOL
java.lang.String getStringToEOL() throws java.io.IOException
This method returns a string of all of the characters from the input file from the current position up to, but not including, the end-of-line character(s).- Returns:
- String from current position
- Throws:
java.io.IOException
-
getUntil
java.lang.String getUntil(char c) throws java.io.IOException
This method returns a string of all of the characters from the input file from the current position up to, but not including, the given character. It encapsulates parenthesis and quoted strings, meaning it does not stop if the given character is found within parentheses or quotes. For instance, given the input of `start(inside)end', getUntil ('n') will return "start(inside)e"- Parameters:
c
- token to read up to. The token itself will not be read.- Throws:
java.io.IOException
-
tokenToString
private java.lang.String tokenToString()
-
nextToken
java.lang.String nextToken() throws java.io.IOException
This method returns the next token String from the input file.- Returns:
- the next token String
- Throws:
java.io.IOException
-
scopedName
SymtabEntry scopedName() throws java.io.IOException
This method assumes that the current token marks the beginning of a scoped name. It then parses the subsequent identifier and double colon tokens, builds the scoped name, and finds the symbol table entry with that name.- Returns:
- a SymtabEntry of the name
- Throws:
java.io.IOException
-
skipToEOL
void skipToEOL() throws java.io.IOException
Skip to the end of the line.- Throws:
java.io.IOException
-
skipUntil
java.lang.String skipUntil(char c) throws java.io.IOException
This method skips the data in the input file until the specified character is encountered, then it returns the next token.- Parameters:
c
- token to indicate end of skipping- Throws:
java.io.IOException
-
parseException
void parseException(java.lang.String message)
This method displays a Parser Exception complete with line number and position information with the given message string.- Parameters:
message
- message to display as part of the Exception- See Also:
Throwable.getMessage()
-
expandMacro
java.lang.String expandMacro(java.lang.String macroDef, Token t) throws java.io.IOException, ParseException
- Throws:
java.io.IOException
ParseException
-
miniMatch
private void miniMatch(int type) throws ParseException
- Throws:
ParseException
-
getParmValues
private java.util.Vector<java.lang.String> getParmValues() throws java.io.IOException, ParseException
- Throws:
java.io.IOException
ParseException
-
macroParmValues
private void macroParmValues(java.util.Vector<java.lang.String> values) throws java.io.IOException, ParseException
- Throws:
java.io.IOException
ParseException
-
macro
private void macro(java.util.Vector<java.lang.String> parmNames) throws java.io.IOException, ParseException
- Throws:
java.io.IOException
ParseException
-
macroParms
private void macroParms(java.util.Vector<java.lang.String> parmNames) throws java.io.IOException, ParseException
- Throws:
java.io.IOException
ParseException
-
macroParms2
private void macroParms2(java.util.Vector<java.lang.String> parmNames) throws java.io.IOException, ParseException
- Throws:
java.io.IOException
ParseException
-
replaceAll
private java.lang.String replaceAll(java.lang.String string, java.lang.String from, java.lang.String to)
-
embedded
private boolean embedded(java.lang.String string, int index, int endIndex)
-
inQuotes
private boolean inQuotes(java.lang.String string, int index)
-
removeDoublePound
private java.lang.String removeDoublePound(java.lang.String string)
Remove any occurrences of ##.
-
getFilename
private java.lang.String getFilename(java.lang.String name) throws java.io.FileNotFoundException
- Throws:
java.io.FileNotFoundException
-
match
private void match(int type) throws java.io.IOException, ParseException
- Throws:
java.io.IOException
ParseException
-
openScope
void openScope(SymtabEntry entry)
This method is called when the parser encounters a left curly brace. An extender of PragmaHandler may find scope information useful. For example, the prefix pragma takes effect as soon as it is encountered and stays in effect until the current scope is closed. If a similar pragma extension is desired, then the openScope and closeScope methods are available for overriding.- Parameters:
entry
- the symbol table entry whose scope has just been opened. Be aware that, since the scope has just been entered, this entry is incomplete at this point.
-
closeScope
void closeScope(SymtabEntry entry)
This method is called when the parser encounters a right curly brace. An extender of PragmaHandler may find scope information useful. For example, the prefix pragma takes effect as soon as it is encountered and stays in effect until the current scope is closed. If a similar pragma extension is desired, then the openScope and closeScope methods are available for overriding.- Parameters:
entry
- the symbol table entry whose scope has just been closed.
-
-