The Battle for Wesnoth  1.15.2+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:
Inheritance graph

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 614 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 1055 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(), error(), preprocessor_streambuf::error(), FOR_REMOVAL, buffered_istream::get(), preprocessor_streambuf::get_current_file(), get_filename(), get_location(), filesystem::get_wml_location(), i, in, in_, preproc_define::is_deprecated(), mp_ui_alerts::items, left_curly_str, game_config::images::level, lineno_string(), preproc_define::linenum, preprocessor_data::token_desc::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, OUTPUT_SEPARATOR, 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::stack_pos, preprocessor_data::token_desc::START, version_info::str(), preprocessor_data::token_desc::STRING, strings_, preproc_define::textdomain, preprocessor_streambuf::textdomain_, tokens_, preprocessor_data::token_desc::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 711 of file preprocessor.cpp.

References operator!=(), operator==(), 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 964 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 986 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 947 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 931 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 918 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!= ( preprocessor_data::token_desc::TOKEN_TYPE  rhs,
char  lhs 
)
friend

Definition at line 732 of file preprocessor.cpp.

◆ operator!= [2/2]

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

Definition at line 737 of file preprocessor.cpp.

◆ operator== [1/2]

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

Definition at line 722 of file preprocessor.cpp.

◆ operator== [2/2]

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

Definition at line 727 of file preprocessor.cpp.

Member Data Documentation

◆ directory_

std::string preprocessor_data::directory_
private

Definition at line 657 of file preprocessor.cpp.

Referenced by get_chunk().

◆ in_

buffered_istream preprocessor_data::in_
private

Input stream.

Definition at line 655 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 652 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 684 of file preprocessor.cpp.

◆ linenum_

int preprocessor_data::linenum_
private

Definition at line 681 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 663 of file preprocessor.cpp.

Referenced by get_chunk(), and preprocessor_scope_helper::preprocessor_scope_helper().

◆ 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 680 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 673 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 660 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 666 of file preprocessor.cpp.

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


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