rendered paste bodyIndex: C:/Wesnoth/wesnoth/src/serialization/preprocessor.cpp
===================================================================
--- C:/Wesnoth/wesnoth/src/serialization/preprocessor.cpp (revision 23206)
+++ C:/Wesnoth/wesnoth/src/serialization/preprocessor.cpp (working copy)
@@ -54,7 +54,8 @@
int old_linenum_;
protected:
preprocessor_streambuf &target_;
- preprocessor(preprocessor_streambuf &);
+ std::vector< std::string > &called_macros_;
+ preprocessor(preprocessor_streambuf &, std::vector<std::string> &);
public:
virtual bool get_chunk() = 0;
virtual ~preprocessor();
@@ -202,12 +203,13 @@
* and when it is deleted, it will manage the stream
* to cause the previous scope to resume.
*/
-preprocessor::preprocessor(preprocessor_streambuf &t) :
+preprocessor::preprocessor(preprocessor_streambuf &t, std::vector<std::string> &callstack) :
old_preprocessor_(t.current_),
old_textdomain_(t.textdomain_),
old_location_(t.location_),
old_linenum_(t.linenum_),
- target_(t)
+ target_(t),
+ called_macros_(callstack)
{
++target_.depth_;
target_.current_ = this;
@@ -254,7 +256,7 @@
std::vector< std::string > files_;
std::vector< std::string >::const_iterator pos_, end_;
public:
- preprocessor_file(preprocessor_streambuf &, std::string const &);
+ preprocessor_file(preprocessor_streambuf &, std::vector<std::string> &, std::string const &);
virtual bool get_chunk();
};
@@ -284,16 +286,18 @@
void put(char);
void put(std::string const &);
public:
- preprocessor_data(preprocessor_streambuf &, std::istream *,
+ preprocessor_data(preprocessor_streambuf &,
+ std::vector< std::string > &,
+ std::istream *,
std::string const &history,
std::string const &name, int line,
std::string const &dir, std::string const &domain);
virtual bool get_chunk();
};
-preprocessor_file::preprocessor_file(preprocessor_streambuf &t,
+preprocessor_file::preprocessor_file(preprocessor_streambuf &t, std::vector< std::string > &callstack,
std::string const &name) :
- preprocessor(t),
+ preprocessor(t,callstack),
files_(),
pos_(),
end_()
@@ -301,7 +305,7 @@
if (is_directory(name))
get_files_in_dir(name, &files_, NULL, ENTIRE_FILE_PATH, SKIP_MEDIA_DIR, DO_REORDER);
else
- new preprocessor_data(t, istream_file(name), "", name, 1, directory_name(name), t.textdomain_);
+ new preprocessor_data(t, called_macros_, istream_file(name), "", name, 1, directory_name(name), t.textdomain_);
pos_ = files_.begin();
end_ = files_.end();
}
@@ -319,16 +323,16 @@
unsigned sz = name.size();
if (sz < 5 || !std::equal(name.begin() + sz - 4, name.end(), ".cfg"))
continue;
- new preprocessor_file(target_, name);
+ new preprocessor_file(target_, called_macros_, name);
return true;
}
return false;
}
-preprocessor_data::preprocessor_data(preprocessor_streambuf &t, std::istream *i,
+preprocessor_data::preprocessor_data(preprocessor_streambuf &t, std::vector< std::string > &callstack, std::istream *i,
std::string const &history, std::string const &name, int linenum,
std::string const &directory, std::string const &domain) :
- preprocessor(t),
+ preprocessor(t, callstack),
in_(i),
directory_(directory),
strings_(),
@@ -687,6 +691,12 @@
preproc_map::const_iterator macro = target_.defines_->find(symbol),
unknown_macro = target_.defines_->end();
if (macro != unknown_macro) {
+
+ ERR_CF<<called_macros_.size();
+ for(std::vector<std::string>::iterator iter=called_macros_.begin(); iter!=called_macros_.end(); ++iter)
+ {
+ }
+
preproc_define const &val = macro->second;
size_t nb_arg = strings_.size() - token.stack_pos - 1;
if (nb_arg != val.arguments.size()) {
@@ -769,10 +779,11 @@
}
pop_token();
+ called_macros_.push_back(symbol);
std::string const &dir = directory_name(val.location.substr(0, val.location.find(' ')));
if (!slowpath_) {
DBG_CF << "substituting macro " << symbol << '\n';
- new preprocessor_data(target_, buffer, val.location, "",
+ new preprocessor_data(target_, called_macros_, buffer, val.location, "",
val.linenum, dir, val.textdomain);
} else {
DBG_CF << "substituting (slow) macro " << symbol << '\n';
@@ -780,12 +791,13 @@
preprocessor_streambuf *buf =
new preprocessor_streambuf(target_);
{ std::istream in(buf);
- new preprocessor_data(*buf, buffer, val.location, "",
+ new preprocessor_data(*buf, called_macros_, buffer, val.location, "",
val.linenum, dir, val.textdomain);
res << in.rdbuf(); }
delete buf;
strings_.back() += res.str();
}
+ called_macros_.pop_back();
} else if (target_.depth_ < 40) {
pop_token();
std::string prefix;
@@ -827,13 +839,13 @@
&& newfilename.find("/../") == std::string::npos)
{
if (!slowpath_)
- new preprocessor_file(target_, nfname);
+ new preprocessor_file(target_, called_macros_, nfname);
else {
std::ostringstream res;
preprocessor_streambuf *buf =
new preprocessor_streambuf(target_);
{ std::istream in(buf);
- new preprocessor_file(*buf, nfname);
+ new preprocessor_file(*buf, called_macros_, nfname);
res << in.rdbuf(); }
delete buf;
strings_.back() += res.str();
@@ -893,7 +905,8 @@
defines = owned_defines;
}
preprocessor_streambuf *buf = new preprocessor_streambuf(defines, error_log);
- new preprocessor_file(*buf, fname);
+ std::vector<std::string> call_stack;
+ new preprocessor_file(*buf, call_stack, fname);
if(error_log!=NULL&&error_log->empty()==false)
throw preproc_config::error("Error preprocessing files.");
return new preprocessor_deleter(buf, owned_defines);