org.anarres.cpp
Class Preprocessor

java.lang.Object
  extended by org.anarres.cpp.Preprocessor

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


Field Summary
static int FL_LINEMARKER
           
 
Constructor Summary
Preprocessor(File file)
          Equivalent to 'new Preprocessor(new FileLexerSource(file))'
Preprocessor(Source initial)
           
Preprocessor(Source initial, int flags)
           
 
Method Summary
 void addMacro(Macro m)
           
 void addMacro(String name)
          Defines the given name as a macro.
 void addMacro(String name, String value)
          Defines the given name as a macro.
protected  void error(Token tok, String msg)
          Handles an error.
protected  Map<String,Macro> getMacros()
          Returns the Map of Macros parsed during the run of this Preprocessor.
protected  Source getSource()
          Returns the top Source on the input stack.
protected  void include(File parent, int line, String name, boolean quoted)
          Handles a include directive.
protected  void pop_source()
          Pops a Source from the input stack.
protected  void push_source(Source source, boolean autopop)
          Pushes a Source onto the input stack.
 void setFlags(int flags)
           
 void setIncludePath(List<String> path)
          Sets the include path used by this Preprocessor.
 void setListener(PreprocessorListener listener)
           
 Token token()
          Returns the next preprocessor token.
 String toString()
           
protected  void warning(Token tok, String msg)
          Handles a warning.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

FL_LINEMARKER

public static final int FL_LINEMARKER
See Also:
Constant Field Values
Constructor Detail

Preprocessor

public Preprocessor(Source initial,
                    int flags)

Preprocessor

public Preprocessor(Source initial)

Preprocessor

public Preprocessor(File file)
             throws IOException
Equivalent to 'new Preprocessor(new FileLexerSource(file))'

Throws:
IOException
Method Detail

setListener

public void setListener(PreprocessorListener listener)

setFlags

public void setFlags(int flags)

error

protected void error(Token tok,
                     String msg)
              throws LexerException
Handles an error. If a PreprocessorListener is installed, it receives the error. Otherwise, it is ignored.

Throws:
LexerException

warning

protected void warning(Token tok,
                       String msg)
                throws LexerException
Handles a warning. If a PreprocessorListener is installed, it receives the warning. Otherwise, it is ignored.

Throws:
LexerException

addMacro

public void addMacro(Macro m)
              throws LexerException
Throws:
LexerException

addMacro

public void addMacro(String name,
                     String value)
              throws LexerException
Defines the given name as a macro. This is a convnience method.

Throws:
LexerException

addMacro

public void addMacro(String name)
              throws LexerException
Defines the given name as a macro. This is a convnience method.

Throws:
LexerException

setIncludePath

public void setIncludePath(List<String> path)
Sets the include path used by this Preprocessor.


getMacros

protected Map<String,Macro> getMacros()
Returns the Map of Macros parsed during the run of this Preprocessor.


getSource

protected Source getSource()
Returns the top Source on the input stack.

See Also:
Source, push_source(Source,boolean), pop_source()

push_source

protected void push_source(Source source,
                           boolean autopop)
Pushes a Source onto the input stack.

See Also:
getSource(), pop_source()

pop_source

protected void pop_source()
Pops a Source from the input stack.

See Also:
getSource(), push_source(Source,boolean)

include

protected void include(File parent,
                       int line,
                       String name,
                       boolean quoted)
                throws IOException,
                       LexerException
Handles a include directive. The user may override this to provide alternate semantics for the include directive, for example, creating a Source based on a virtual file system.

Throws:
IOException
LexerException

token

public Token token()
            throws IOException,
                   LexerException
Returns the next preprocessor token.

Throws:
LexerException - if a preprocessing error occurs.
InternalException - if an unexpected error condition arises.
IOException
See Also:
Token

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2007 Shevek, Anarres. All Rights Reserved.