Skip to content

Commit

Permalink
preproc: Use the same format as #error for reporting #warning lines
Browse files Browse the repository at this point in the history
Adds a preprocessor_streambuf::warning() method, equivalent to
preprocessor_streambuf::error() but logging to the warning logger and
returning to the caller instead of throwing an exception.
  • Loading branch information
irydacea committed Jan 12, 2015
1 parent 7aaa982 commit c394060
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
2 changes: 2 additions & 0 deletions changelog
Expand Up @@ -48,6 +48,8 @@ Version 1.12.0+dev:
honored by Windows builds using Boost.filesystem (bug #22967).
* Fixed dotfiles being included when {including} directories in WML, on
builds using the new filesystem code (regression introduced in 1.11.19).
* Preprocessor #warning messages now conform better to the new WML
parser/preprocessor diagnostics format introduced in version 1.11.10.
* Miscellaneous and bug fixes:
* Fixed non-ASCII characters in the user's path prevent
BfW to launch on windows (bug #22983)
Expand Down
18 changes: 15 additions & 3 deletions src/serialization/preprocessor.cpp
Expand Up @@ -240,6 +240,7 @@ class preprocessor_streambuf: public streambuf
public:
preprocessor_streambuf(preproc_map *);
void error(const std::string &, int);
void warning(const std::string &, int);
};

preprocessor_streambuf::preprocessor_streambuf(preproc_map *def) :
Expand Down Expand Up @@ -357,6 +358,17 @@ void preprocessor_streambuf::error(const std::string& error_type, int l)
throw preproc_config::error(error);
}

void preprocessor_streambuf::warning(const std::string& warning_type, int l)
{
std::string position, warning;
std::ostringstream pos;
pos << l << ' ' << location_;
position = lineno_string(pos.str());
warning = warning_type + '\n';
warning += "at " + position;
WRN_CF << warning << '\n';
}


/**
* Sets up a new preprocessor for stream buffer \a t.
Expand Down Expand Up @@ -987,9 +999,9 @@ bool preprocessor_data::get_chunk()
} else if (command == "warning") {
if (!skipping_) {
skip_spaces();
std::string message = read_rest_of_line();
WRN_CF << "#warning: \"" << message << "\" at "
<< linenum_ << ' ' << get_location(target_.location_) << '\n';
std::ostringstream warning;
warning << "#warning: \"" << read_rest_of_line() << '"';
target_.warning(warning.str(), linenum_);
} else
DBG_CF << "Skipped a warning\n";
} else
Expand Down

0 comments on commit c394060

Please sign in to comment.