Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

CPPPreprocessor Class Reference

#include <cppPreprocessor.h>

Inheritance diagram for CPPPreprocessor:

CPPExpressionParser CPPParser CPPTypeParser List of all members.

Public Types

typedef map< string, CPPManifest * > Manifests
typedef set< CPPFileParsedFiles
typedef set< string > Includes

Public Member Functions

 CPPPreprocessor ()
void set_verbose (int verbose)
 Sets the verbosity level of the parser.

int get_verbose () const
 Returns the verbosity level of the parser.

void copy_filepos (const CPPPreprocessor &other)
CPPFile get_file () const
int get_line_number () const
int get_col_number () const
CPPToken get_next_token ()
void warning (const string &message, int line=0, int col=0, CPPFile file=CPPFile())
void error (const string &message, int line=0, int col=0, CPPFile file=CPPFile())
CPPCommentBlockget_comment_before (int line, CPPFile file)
 Returns the CPPCommentBlock immediately preceding the indicated line, if any.

int get_warning_count () const
int get_error_count () const

Public Attributes

Manifests _manifests
DSearchPath _include_path
DSearchPath _system_include_path
CPPComments _comments
ParsedFiles _parsed_files
Includes _quote_includes
Includes _angle_includes
bool _resolve_identifiers
int _verbose

Protected Member Functions

bool init_cpp (const CPPFile &file)
bool init_const_expr (const string &expr)
bool init_type (const string &type)
bool push_file (const CPPFile &file)
bool push_string (const string &input, bool lock_position)
string expand_manifests (const string &input_expr)
 Given a string, expand all manifests within the string and return the new string.

CPPExpressionparse_expr (const string &expr, CPPScope *current_scope, CPPScope *global_scope)
 Given a string, expand all manifests within the string and evaluate it as an expression.


Private Types

typedef list< InputFileFiles
enum  State { S_normal, S_eof, S_nested, S_end_nested }

Private Member Functions

CPPToken internal_get_next_token ()
int skip_whitespace (int c)
int skip_comment (int c)
int skip_c_comment (int c)
int skip_cpp_comment (int c)
int process_directive (int c)
int get_preprocessor_command (int c, string &command)
int get_preprocessor_args (int c, string &args)
void handle_define_directive (const string &args, int first_line, int first_col, const CPPFile &first_file)
void handle_undef_directive (const string &args, int first_line, int first_col, const CPPFile &first_file)
void handle_ifdef_directive (const string &args, int first_line, int first_col, const CPPFile &first_file)
void handle_ifndef_directive (const string &args, int first_line, int first_col, const CPPFile &first_file)
void handle_if_directive (const string &args, int first_line, int first_col, const CPPFile &first_file)
void handle_include_directive (const string &args, int first_line, int first_col, const CPPFile &first_file)
void handle_error_directive (const string &args, int first_line, int first_col, const CPPFile &first_file)
void skip_false_if_block (bool consider_elifs)
 We come here when we fail an #if or an #ifdef test, or when we reach the #else clause to something we didn't fail.

CPPToken get_quoted_char (int c)
CPPToken get_quoted_string (int c)
CPPToken get_identifier (int c)
CPPToken expand_manifest (const CPPManifest *manifest)
void extract_manifest_args (const string &name, int num_args, vector_string &args)
void expand_defined_function (string &expr, size_t q, size_t &p)
void expand_manifest_inline (string &expr, size_t q, size_t &p, const CPPManifest *manifest)
void extract_manifest_args_inline (const string &name, int num_args, vector_string &args, const string &expr, size_t &p)
CPPToken get_number (int c, int c2=0)
string scan_quoted (int c)
bool should_ignore_manifest (const CPPManifest *manifest) const
 Returns true if the manifest is one that is being ignored right now (presumably because we are presently expanding it).

bool should_ignore_preprocessor () const
 Returns true if we should ignore any preprocessor directives (e.g.

int get ()
void unget (int c)
CPPTemplateParameterListnested_parse_template_instantiation (CPPTemplateScope *scope)
 Recursively invokes yacc to parse the stuff within angle brackets that's the template instantiation part of an identifier.

void skip_to_end_nested ()
 This is an error-recovery function, called after returning from a nested parse.

void skip_to_angle_bracket ()
 This is an error-recovery function, called after returning from a nested parse.


Static Private Member Functions

int check_keyword (const string &name)

Private Attributes

Files _files
State _state
int _paren_nesting
bool _angle_bracket_found
bool _start_of_line
int _unget
int _last_c
bool _last_cpp_comment
bool _save_comments
vector< CPPToken_saved_tokens
int _warning_count
int _error_count

Member Typedef Documentation

typedef list<InputFile> CPPPreprocessor::Files [private]
 

Definition at line 196 of file cppPreprocessor.h.

typedef set<string> CPPPreprocessor::Includes
 

Definition at line 91 of file cppPreprocessor.h.

typedef map<string, CPPManifest *> CPPPreprocessor::Manifests
 

Definition at line 80 of file cppPreprocessor.h.

typedef set<CPPFile> CPPPreprocessor::ParsedFiles
 

Definition at line 88 of file cppPreprocessor.h.


Member Enumeration Documentation

enum CPPPreprocessor::State [private]
 

Enumeration values:
S_normal 
S_eof 
S_nested 
S_end_nested 

Definition at line 199 of file cppPreprocessor.h.


Constructor & Destructor Documentation

CPPPreprocessor::CPPPreprocessor  ) 
 

Definition at line 197 of file cppPreprocessor.cxx.


Member Function Documentation

int CPPPreprocessor::check_keyword const string &  name  )  [static, private]
 

Definition at line 2001 of file cppPreprocessor.cxx.

void CPPPreprocessor::copy_filepos const CPPPreprocessor &  other  ) 
 

Definition at line 255 of file cppPreprocessor.cxx.

References _files.

void CPPPreprocessor::error const string &  message,
int  line = 0,
int  col = 0,
CPPFile  file = CPPFile()
 

Definition at line 510 of file cppPreprocessor.cxx.

References _error_count.

Referenced by CPPIdentifier::get_scope(), and CPPIdentifier::is_tbd().

void CPPPreprocessor::expand_defined_function string &  expr,
size_t  q,
size_t p
[private]
 

Definition at line 1783 of file cppPreprocessor.cxx.

Referenced by push_string().

CPPToken CPPPreprocessor::expand_manifest const CPPManifest manifest  )  [private]
 

Definition at line 1680 of file cppPreprocessor.cxx.

Referenced by skip_false_if_block().

void CPPPreprocessor::expand_manifest_inline string &  expr,
size_t  q,
size_t p,
const CPPManifest manifest
[private]
 

Definition at line 1812 of file cppPreprocessor.cxx.

Referenced by push_string().

string CPPPreprocessor::expand_manifests const string &  input_expr  )  [protected]
 

Given a string, expand all manifests within the string and return the new string.

Definition at line 731 of file cppPreprocessor.cxx.

References CPPExpressionParser::_expr, _verbose, current_scope, global_scope, NULL, and CPPExpressionParser::parse_expr().

Referenced by handle_undef_directive().

void CPPPreprocessor::extract_manifest_args const string &  name,
int  num_args,
vector_string &  args
[private]
 

Definition at line 1713 of file cppPreprocessor.cxx.

References size_t, and warning().

void CPPPreprocessor::extract_manifest_args_inline const string &  name,
int  num_args,
vector_string &  args,
const string &  expr,
size_t p
[private]
 

Definition at line 1833 of file cppPreprocessor.cxx.

int CPPPreprocessor::get  )  [private]
 

Definition at line 2203 of file cppPreprocessor.cxx.

References _files, _saved_tokens, get_next_token(), indent(), S_end_nested, and S_eof.

Referenced by get_quoted_string(), handle_error_directive(), handle_include_directive(), internal_get_next_token(), and process_directive().

int CPPPreprocessor::get_col_number  )  const
 

Definition at line 300 of file cppPreprocessor.cxx.

References _saved_tokens.

Referenced by handle_error_directive(), handle_include_directive(), init_const_expr(), and set_verbose().

CPPCommentBlock * CPPPreprocessor::get_comment_before int  line,
CPPFile  file
 

Returns the CPPCommentBlock immediately preceding the indicated line, if any.

If there is no such comment, returns NULL.

Definition at line 571 of file cppPreprocessor.cxx.

References _saved_tokens, _state, push_string(), and S_normal.

Referenced by CPPScope::set_current_vis().

int CPPPreprocessor::get_error_count  )  const
 

Definition at line 554 of file cppPreprocessor.cxx.

References _last_c, _saved_tokens, _state, push_file(), and S_normal.

Referenced by CPPParser::is_fully_specified(), CPPExpressionParser::~CPPExpressionParser(), and CPPTypeParser::~CPPTypeParser().

CPPFile CPPPreprocessor::get_file  )  const
 

Definition at line 270 of file cppPreprocessor.cxx.

References _files.

Referenced by handle_error_directive(), handle_include_directive(), init_const_expr(), and set_verbose().

CPPToken CPPPreprocessor::get_identifier int  c  )  [private]
 

Definition at line 1628 of file cppPreprocessor.cxx.

int CPPPreprocessor::get_line_number  )  const
 

Definition at line 285 of file cppPreprocessor.cxx.

References _files.

Referenced by handle_error_directive(), handle_include_directive(), init_const_expr(), and set_verbose().

CPPToken CPPPreprocessor::get_next_token  ) 
 

Definition at line 315 of file cppPreprocessor.cxx.

Referenced by get().

CPPToken CPPPreprocessor::get_number int  c,
int  c2 = 0
[private]
 

Definition at line 1890 of file cppPreprocessor.cxx.

References cpp_longlong_keyword.

int CPPPreprocessor::get_preprocessor_args int  c,
string &  args
[private]
 

Definition at line 1261 of file cppPreprocessor.cxx.

Referenced by handle_include_directive().

int CPPPreprocessor::get_preprocessor_command int  c,
string &  command
[private]
 

Definition at line 1233 of file cppPreprocessor.cxx.

References _manifests, and warning().

Referenced by handle_include_directive().

CPPToken CPPPreprocessor::get_quoted_char int  c  )  [private]
 

Definition at line 1589 of file cppPreprocessor.cxx.

CPPToken CPPPreprocessor::get_quoted_string int  c  )  [private]
 

Definition at line 1612 of file cppPreprocessor.cxx.

References get().

int CPPPreprocessor::get_verbose  )  const
 

Returns the verbosity level of the parser.

Definition at line 243 of file cppPreprocessor.cxx.

References _files.

int CPPPreprocessor::get_warning_count  )  const
 

Definition at line 542 of file cppPreprocessor.cxx.

References NULL.

void CPPPreprocessor::handle_define_directive const string &  args,
int  first_line,
int  first_col,
const CPPFile first_file
[private]
 

Definition at line 1298 of file cppPreprocessor.cxx.

void CPPPreprocessor::handle_error_directive const string &  args,
int  first_line,
int  first_col,
const CPPFile first_file
[private]
 

Definition at line 1513 of file cppPreprocessor.cxx.

References _manifests, get(), get_col_number(), get_file(), and get_line_number().

void CPPPreprocessor::handle_if_directive const string &  args,
int  first_line,
int  first_col,
const CPPFile first_file
[private]
 

Definition at line 1384 of file cppPreprocessor.cxx.

References CPPFile::S_system.

Referenced by handle_include_directive().

void CPPPreprocessor::handle_ifdef_directive const string &  args,
int  first_line,
int  first_col,
const CPPFile first_file
[private]
 

Definition at line 1345 of file cppPreprocessor.cxx.

References _files, and _quote_includes.

void CPPPreprocessor::handle_ifndef_directive const string &  args,
int  first_line,
int  first_col,
const CPPFile first_file
[private]
 

Definition at line 1364 of file cppPreprocessor.cxx.

void CPPPreprocessor::handle_include_directive const string &  args,
int  first_line,
int  first_col,
const CPPFile first_file
[private]
 

Definition at line 1420 of file cppPreprocessor.cxx.

References _save_comments, _start_of_line, get(), get_col_number(), get_file(), get_line_number(), get_preprocessor_args(), get_preprocessor_command(), handle_if_directive(), and skip_comment().

void CPPPreprocessor::handle_undef_directive const string &  args,
int  first_line,
int  first_col,
const CPPFile first_file
[private]
 

Definition at line 1324 of file cppPreprocessor.cxx.

References expand_manifests().

bool CPPPreprocessor::init_const_expr const string &  expr  )  [protected]
 

Definition at line 624 of file cppPreprocessor.cxx.

References _files, get_col_number(), get_file(), get_line_number(), and indent().

Referenced by CPPExpressionParser::~CPPExpressionParser().

bool CPPPreprocessor::init_cpp const CPPFile file  )  [protected]
 

Definition at line 608 of file cppPreprocessor.cxx.

References _last_c, _parsed_files, and _start_of_line.

Referenced by CPPParser::is_fully_specified().

bool CPPPreprocessor::init_type const string &  type  )  [protected]
 

Definition at line 639 of file cppPreprocessor.cxx.

References _files.

Referenced by CPPTypeParser::~CPPTypeParser().

CPPToken CPPPreprocessor::internal_get_next_token  )  [private]
 

Definition at line 823 of file cppPreprocessor.cxx.

References get().

CPPTemplateParameterList * CPPPreprocessor::nested_parse_template_instantiation CPPTemplateScope scope  )  [private]
 

Recursively invokes yacc to parse the stuff within angle brackets that's the template instantiation part of an identifier.

This involves setting and restoring some state flags so we can return EOF when we reach the closing bracket.

Definition at line 2271 of file cppPreprocessor.cxx.

CPPExpression * CPPPreprocessor::parse_expr const string &  expr,
CPPScope current_scope,
CPPScope global_scope
[protected]
 

Given a string, expand all manifests within the string and evaluate it as an expression.

Returns NULL if the string is not a valid expression.

This is an internal support function for CPPPreprocessor; however, there is a public variant of this function defined for CPPParser.

Definition at line 802 of file cppPreprocessor.cxx.

Referenced by CPPParser::parse_file().

int CPPPreprocessor::process_directive int  c  )  [private]
 

Definition at line 1177 of file cppPreprocessor.cxx.

References get(), and skip_comment().

bool CPPPreprocessor::push_file const CPPFile file  )  [protected]
 

Definition at line 654 of file cppPreprocessor.cxx.

References _files.

Referenced by get_error_count().

bool CPPPreprocessor::push_string const string &  input,
bool  lock_position
[protected]
 

Definition at line 685 of file cppPreprocessor.cxx.

References _manifests, expand_defined_function(), expand_manifest_inline(), and size_t.

Referenced by get_comment_before().

string CPPPreprocessor::scan_quoted int  c  )  [private]
 

Definition at line 2070 of file cppPreprocessor.cxx.

References _files.

void CPPPreprocessor::set_verbose int  verbose  ) 
 

Sets the verbosity level of the parser.

At 0, no warnings will be reported; at 1 or higher, expect to get spammed.

Definition at line 230 of file cppPreprocessor.cxx.

References _files, get_col_number(), get_file(), and get_line_number().

bool CPPPreprocessor::should_ignore_manifest const CPPManifest manifest  )  const [private]
 

Returns true if the manifest is one that is being ignored right now (presumably because we are presently expanding it).

Definition at line 2160 of file cppPreprocessor.cxx.

References CPPType::new_type(), NULL, skip_to_end_nested(), CPPSimpleType::T_unknown, and warning().

bool CPPPreprocessor::should_ignore_preprocessor  )  const [private]
 

Returns true if we should ignore any preprocessor directives (e.g.

we're presently expanding a manifest).

Definition at line 2184 of file cppPreprocessor.cxx.

References _angle_bracket_found, and _files.

int CPPPreprocessor::skip_c_comment int  c  )  [private]
 

Definition at line 1060 of file cppPreprocessor.cxx.

References _comments.

int CPPPreprocessor::skip_comment int  c  )  [private]
 

Definition at line 1032 of file cppPreprocessor.cxx.

Referenced by handle_include_directive(), and process_directive().

int CPPPreprocessor::skip_cpp_comment int  c  )  [private]
 

Definition at line 1123 of file cppPreprocessor.cxx.

void CPPPreprocessor::skip_false_if_block bool  consider_elifs  )  [private]
 

We come here when we fail an #if or an #ifdef test, or when we reach the #else clause to something we didn't fail.

This function skips all text up until the matching #endif.

Definition at line 1533 of file cppPreprocessor.cxx.

References _manifests, and expand_manifest().

void CPPPreprocessor::skip_to_angle_bracket  )  [private]
 

This is an error-recovery function, called after returning from a nested parse.

If we haven't yet consumed the closing angle bracket on the template instantiation, keep consuming tokens until we do.

Definition at line 2398 of file cppPreprocessor.cxx.

void CPPPreprocessor::skip_to_end_nested  )  [private]
 

This is an error-recovery function, called after returning from a nested parse.

If the state is not S_end_nested, there was an error in parsing the nested tokens, and not all of the nested tokens may have been consumed. This function will consume the rest of the nested tokens.

Definition at line 2362 of file cppPreprocessor.cxx.

Referenced by should_ignore_manifest().

int CPPPreprocessor::skip_whitespace int  c  )  [private]
 

Definition at line 1004 of file cppPreprocessor.cxx.

void CPPPreprocessor::unget int  c  )  [private]
 

Definition at line 2248 of file cppPreprocessor.cxx.

References _saved_tokens.

void CPPPreprocessor::warning const string &  message,
int  line = 0,
int  col = 0,
CPPFile  file = CPPFile()
 

Definition at line 484 of file cppPreprocessor.cxx.

Referenced by extract_manifest_args(), get_preprocessor_command(), CPPDeclaration::get_template_scope(), CPPScope::is_fully_specified(), CPPStructType::is_incomplete(), and should_ignore_manifest().


Member Data Documentation

bool CPPPreprocessor::_angle_bracket_found [private]
 

Definition at line 204 of file cppPreprocessor.h.

Referenced by should_ignore_preprocessor().

Includes CPPPreprocessor::_angle_includes
 

Definition at line 93 of file cppPreprocessor.h.

CPPComments CPPPreprocessor::_comments
 

Definition at line 86 of file cppPreprocessor.h.

Referenced by skip_c_comment().

int CPPPreprocessor::_error_count [private]
 

Definition at line 216 of file cppPreprocessor.h.

Referenced by error().

Files CPPPreprocessor::_files [private]
 

Definition at line 197 of file cppPreprocessor.h.

Referenced by copy_filepos(), get(), get_file(), get_line_number(), get_verbose(), handle_ifdef_directive(), init_const_expr(), init_type(), push_file(), scan_quoted(), set_verbose(), and should_ignore_preprocessor().

DSearchPath CPPPreprocessor::_include_path
 

Definition at line 83 of file cppPreprocessor.h.

int CPPPreprocessor::_last_c [private]
 

Definition at line 209 of file cppPreprocessor.h.

Referenced by get_error_count(), and init_cpp().

bool CPPPreprocessor::_last_cpp_comment [private]
 

Definition at line 210 of file cppPreprocessor.h.

Manifests CPPPreprocessor::_manifests
 

Definition at line 81 of file cppPreprocessor.h.

Referenced by get_preprocessor_command(), handle_error_directive(), push_string(), and skip_false_if_block().

int CPPPreprocessor::_paren_nesting [private]
 

Definition at line 203 of file cppPreprocessor.h.

ParsedFiles CPPPreprocessor::_parsed_files
 

Definition at line 89 of file cppPreprocessor.h.

Referenced by init_cpp().

Includes CPPPreprocessor::_quote_includes
 

Definition at line 92 of file cppPreprocessor.h.

Referenced by handle_ifdef_directive().

bool CPPPreprocessor::_resolve_identifiers
 

Definition at line 100 of file cppPreprocessor.h.

bool CPPPreprocessor::_save_comments [private]
 

Definition at line 211 of file cppPreprocessor.h.

Referenced by handle_include_directive().

vector<CPPToken> CPPPreprocessor::_saved_tokens [private]
 

Definition at line 213 of file cppPreprocessor.h.

Referenced by get(), get_col_number(), get_comment_before(), get_error_count(), and unget().

bool CPPPreprocessor::_start_of_line [private]
 

Definition at line 206 of file cppPreprocessor.h.

Referenced by handle_include_directive(), and init_cpp().

State CPPPreprocessor::_state [private]
 

Definition at line 202 of file cppPreprocessor.h.

Referenced by get_comment_before(), and get_error_count().

DSearchPath CPPPreprocessor::_system_include_path
 

Definition at line 84 of file cppPreprocessor.h.

int CPPPreprocessor::_unget [private]
 

Definition at line 207 of file cppPreprocessor.h.

int CPPPreprocessor::_verbose
 

Definition at line 106 of file cppPreprocessor.h.

Referenced by expand_manifests().

int CPPPreprocessor::_warning_count [private]
 

Definition at line 215 of file cppPreprocessor.h.


The documentation for this class was generated from the following files:
Generated on Thu May 1 22:13:24 2003 for DTool by doxygen1.3