preproc: Add warning on macro redefinitions without #undef

This is intended to help guard authors against unintentional name
clashes.
This commit is contained in:
Ignacio R. Morelle 2015-08-18 03:20:45 -03:00
parent 5fd31c88a5
commit 987bb787ce
2 changed files with 17 additions and 0 deletions

View file

@ -36,6 +36,8 @@ Version 1.13.1+dev:
* Added support for has_flag= in terrain graphics [variant].
* Added category= to [label] - allows grouping labels so that players can
show/hide them
* The WML preprocessor now writes warnings to stderr for macros redefined
without #undef, to help detect unintentional name clashes.
* Editor:
* Added Category field and color sliders to the Edit Label panel.
* Miscellaneous and bug fixes:

View file

@ -886,6 +886,21 @@ bool preprocessor_data::get_chunk()
target_.error("Unterminated preprocessor definition", linenum_);
}
if (!skipping_) {
preproc_map::const_iterator old_i = target_.defines_->find(symbol);
if (old_i != target_.defines_->end()) {
std::ostringstream new_pos, old_pos;
const preproc_define& old_d = old_i->second;
new_pos << linenum << ' ' << target_.location_;
old_pos << old_d.linenum << ' ' << old_d.location;
WRN_PREPROC << "Redefining macro " << symbol
<< " without explicit #undef at "
<< lineno_string(new_pos.str()) << '\n'
<< "previously defined at "
<< lineno_string(old_pos.str()) << '\n';
}
buffer.erase(buffer.end() - 7, buffer.end());
(*target_.defines_)[symbol] = preproc_define(buffer, items, target_.textdomain_,
linenum + 1, target_.location_);