preproc: Use the same format as #error for reporting #warning lines

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.
This commit is contained in:
Ignacio R. Morelle 2015-01-12 20:43:59 -03:00
parent 7aaa9829a6
commit c394060a7d
2 changed files with 17 additions and 3 deletions

View file

@ -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)

View file

@ -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) :
@ -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.
@ -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