The Battle for Wesnoth  1.19.5+dev
Classes | Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
preprocessor_data Class Reference

Specialized preprocessor for handling any kind of input stream. More...

Inheritance diagram for preprocessor_data:

Classes

struct  token_desc
 Description of a preprocessing chunk. More...
 

Public Member Functions

 preprocessor_data (preprocessor_streambuf &, filesystem::scoped_istream, const std::string &history, const std::string &name, int line, const std::string &dir, const std::string &domain, std::unique_ptr< std::map< std::string, std::string >> defines, bool is_define=false)
 
virtual bool get_chunk () override
 Preprocesses and sends some text to the parent_ buffer. More...
 
virtual preprocessor::MODE parse_mode () override
 Returns the appropriate parsing mode for this preprocessor. More...
 
- Public Member Functions inherited from preprocessor
virtual ~preprocessor ()
 
virtual void init ()
 Allows specifying any actions that need to be called after the constructor completes. More...
 

Private Member Functions

std::string read_word ()
 
std::string read_line ()
 
std::string read_rest_of_line ()
 
void skip_spaces ()
 
void skip_eol ()
 
void push_token (token_desc::token_type)
 
void pop_token ()
 
void put (char)
 
void put (const std::string &)
 
void conditional_skip (bool skip)
 

Private Attributes

filesystem::scoped_istream in_scope_
 Manages the lifetime of the std::istream pointer we own. More...
 
buffered_istream in_
 Input stream. More...
 
std::string directory_
 
std::vector< std::string > strings_
 Buffer for delayed input processing. More...
 
std::unique_ptr< std::map< std::string, std::string > > local_defines_
 Mapping of macro arguments to their content. More...
 
std::vector< token_desctokens_
 Stack of nested preprocessing chunks. More...
 
int slowpath_
 Set to true whenever input tokens cannot be directly sent to the target buffer. More...
 
int skipping_
 Non-zero when the preprocessor has to skip some input text. More...
 
int linenum_
 
bool is_define_
 True iff we are currently parsing a macros content, otherwise false. More...
 

Friends

bool operator== (preprocessor_data::token_desc::token_type, char)
 
bool operator== (char, preprocessor_data::token_desc::token_type)
 
bool operator!= (preprocessor_data::token_desc::token_type, char)
 
bool operator!= (char, preprocessor_data::token_desc::token_type)
 

Additional Inherited Members

- Public Types inherited from preprocessor
enum  MODE { NO_PARSING , PARSES_FILE , PARSES_MACRO }
 
- Protected Member Functions inherited from preprocessor
 preprocessor (preprocessor_streambuf &t)
 Sets up a new preprocessor for stream buffer t. More...
 
- Protected Attributes inherited from preprocessor
preprocessor_streambufparent_
 

Detailed Description

Specialized preprocessor for handling any kind of input stream.

This is the core of the preprocessor.

Definition at line 645 of file preprocessor.cpp.

Constructor & Destructor Documentation

◆ preprocessor_data()

preprocessor_data::preprocessor_data ( preprocessor_streambuf t,
filesystem::scoped_istream  i,
const std::string &  history,
const std::string &  name,
int  line,
const std::string &  dir,
const std::string &  domain,
std::unique_ptr< std::map< std::string, std::string >>  defines,
bool  is_define = false 
)

Member Function Documentation

◆ conditional_skip()

void preprocessor_data::conditional_skip ( bool  skip)
private

◆ get_chunk()

bool preprocessor_data::get_chunk ( )
overridevirtual

Preprocesses and sends some text to the parent_ buffer.

Returns
false when the input has no data left.

Implements preprocessor.

Definition at line 1086 of file preprocessor.cpp.

References preprocessor_streambuf::add_preprocessor(), preproc_define::arguments, b, c, conditional_skip(), current_dir_str, current_file_str, d, DBG_PREPROC, preprocessor_streambuf::defines_, deprecated_message(), preproc_define::deprecation_level, preproc_define::deprecation_message, preproc_define::deprecation_version, preprocessor_streambuf::depth(), directory_, filesystem::directory_name(), do_version_check(), e, buffered_istream::eof(), lg::err(), preprocessor_streambuf::error(), filename, FOR_REMOVAL, buffered_istream::get(), preprocessor_streambuf::get_current_file(), get_filename(), get_location(), filesystem::get_wml_location(), i, in, in_, INLINED_PREPROCESS_DIRECTIVE_CHAR, preproc_define::is_deprecated(), left_curly_str, game_config::images::level, lineno_string(), preproc_define::linenum, linenum_, local_defines_, preproc_define::location, preprocessor_streambuf::location_, LOG_PREPROC, preprocessor_data::token_desc::macro_chunk, preprocessor_data::token_desc::macro_parens, preprocessor_data::token_desc::macro_space, OP_INVALID, preproc_define::optional_arguments, preprocessor::parent_, parse_version_op(), buffered_istream::peek(), pop_token(), utils::portable_isspace(), PREEMPTIVE, preprocessor::preprocessor_streambuf, preprocessor_data::token_desc::process_else, preprocessor_data::token_desc::process_if, push_token(), put(), preprocessor_streambuf::quoted_, utils::quoted_split(), read_line(), read_rest_of_line(), read_word(), right_curly_str, s, preprocessor_data::token_desc::skip_else, skip_eol(), preprocessor_data::token_desc::skip_if, skip_spaces(), skipping_, slowpath_, utils::split(), preprocessor_data::token_desc::start, version_info::str(), preprocessor_data::token_desc::string, strings_, preproc_define::textdomain, preprocessor_streambuf::textdomain_, tokens_, token::type, preproc_define::value, preprocessor_data::token_desc::verbatim, preprocessor_streambuf::warning(), game_config::wesnoth_version, and WRN_PREPROC.

◆ parse_mode()

virtual preprocessor::MODE preprocessor_data::parse_mode ( )
inlineoverridevirtual

Returns the appropriate parsing mode for this preprocessor.

Reimplemented from preprocessor.

Definition at line 742 of file preprocessor.cpp.

References is_define_, preprocessor::PARSES_FILE, and preprocessor::PARSES_MACRO.

◆ pop_token()

void preprocessor_data::pop_token ( )
private

◆ push_token()

void preprocessor_data::push_token ( token_desc::token_type  t)
private

◆ put() [1/2]

void preprocessor_data::put ( char  c)
private

◆ put() [2/2]

void preprocessor_data::put ( const std::string &  s)
private

◆ read_line()

std::string preprocessor_data::read_line ( )
private

Definition at line 995 of file preprocessor.cpp.

References c, buffered_istream::eof(), buffered_istream::get(), in_, and linenum_.

Referenced by get_chunk().

◆ read_rest_of_line()

std::string preprocessor_data::read_rest_of_line ( )
private

Definition at line 1017 of file preprocessor.cpp.

References c, buffered_istream::eof(), buffered_istream::get(), in_, and buffered_istream::peek().

Referenced by get_chunk().

◆ read_word()

std::string preprocessor_data::read_word ( )
private

Definition at line 978 of file preprocessor.cpp.

References c, buffered_istream::get(), in_, buffered_istream::peek(), and utils::portable_isspace().

Referenced by get_chunk().

◆ skip_eol()

void preprocessor_data::skip_eol ( )
private

Definition at line 962 of file preprocessor.cpp.

References c, buffered_istream::eof(), buffered_istream::get(), in_, and linenum_.

Referenced by get_chunk().

◆ skip_spaces()

void preprocessor_data::skip_spaces ( )
private

Definition at line 949 of file preprocessor.cpp.

References c, buffered_istream::eof(), buffered_istream::get(), in_, and buffered_istream::peek().

Referenced by get_chunk().

Friends And Related Function Documentation

◆ operator!= [1/2]

bool operator!= ( char  lhs,
preprocessor_data::token_desc::token_type  rhs 
)
friend

Definition at line 768 of file preprocessor.cpp.

◆ operator!= [2/2]

bool operator!= ( preprocessor_data::token_desc::token_type  rhs,
char  lhs 
)
friend

Definition at line 763 of file preprocessor.cpp.

◆ operator== [1/2]

bool operator== ( char  lhs,
preprocessor_data::token_desc::token_type  rhs 
)
friend

Definition at line 758 of file preprocessor.cpp.

◆ operator== [2/2]

bool operator== ( preprocessor_data::token_desc::token_type  ,
char   
)
friend

Definition at line 753 of file preprocessor.cpp.

Member Data Documentation

◆ directory_

std::string preprocessor_data::directory_
private

Definition at line 688 of file preprocessor.cpp.

Referenced by get_chunk().

◆ in_

buffered_istream preprocessor_data::in_
private

Input stream.

Definition at line 686 of file preprocessor.cpp.

Referenced by get_chunk(), read_line(), read_rest_of_line(), read_word(), skip_eol(), and skip_spaces().

◆ in_scope_

filesystem::scoped_istream preprocessor_data::in_scope_
private

Manages the lifetime of the std::istream pointer we own.

Since in_ uses the stream as well this object must be created before in_ and destroyed after in_ is destroyed.

Definition at line 683 of file preprocessor.cpp.

◆ is_define_

bool preprocessor_data::is_define_
private

True iff we are currently parsing a macros content, otherwise false.

Definition at line 715 of file preprocessor.cpp.

Referenced by parse_mode().

◆ linenum_

int preprocessor_data::linenum_
private

Definition at line 712 of file preprocessor.cpp.

Referenced by get_chunk(), push_token(), put(), read_line(), and skip_eol().

◆ local_defines_

std::unique_ptr<std::map<std::string, std::string> > preprocessor_data::local_defines_
private

Mapping of macro arguments to their content.

Definition at line 694 of file preprocessor.cpp.

Referenced by get_chunk().

◆ skipping_

int preprocessor_data::skipping_
private

Non-zero when the preprocessor has to skip some input text.

Increased whenever entering a conditional branch that is not useful, e.g. a ifdef that evaluates to false.

Definition at line 711 of file preprocessor.cpp.

Referenced by conditional_skip(), get_chunk(), push_token(), and put().

◆ slowpath_

int preprocessor_data::slowpath_
private

Set to true whenever input tokens cannot be directly sent to the target buffer.

For instance, this happens with macro arguments. In that case, the output is redirected toward strings_ until it can be processed.

Definition at line 704 of file preprocessor.cpp.

Referenced by get_chunk(), push_token(), and put().

◆ strings_

std::vector<std::string> preprocessor_data::strings_
private

Buffer for delayed input processing.

Definition at line 691 of file preprocessor.cpp.

Referenced by get_chunk(), pop_token(), push_token(), and put().

◆ tokens_

std::vector<token_desc> preprocessor_data::tokens_
private

Stack of nested preprocessing chunks.

Definition at line 697 of file preprocessor.cpp.

Referenced by get_chunk(), pop_token(), and push_token().


The documentation for this class was generated from the following file: