Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --slowpath_;
- if (skipping_) {
- pop_token();
- return true;
- }
- // FIXME: is this obsolete?
- //if (token.type == token_desc::MACRO_SPACE) {
- // if (!strings_.back().empty()) {
- // std::ostringstream error;
- // std::ostringstream location;
- // error << "Can't parse new macro parameter with a macro call scope open";
- // location<<linenum_<<' '<<target_.location_;
- // target_.error(error.str(), location.str());
- // }
- // strings_.pop_back();
- //}
- std::string symbol = strings_[token.stack_pos];
- std::string::size_type pos;
- while ((pos = symbol.find('\376')) != std::string::npos) {
- std::string::iterator b = symbol.begin(); // invalidated at each iteration
- symbol.erase(b + pos, b + symbol.find('\n', pos + 1) + 1);
- }
- std::map<std::string, std::string>::const_iterator arg;
- preproc_map::const_iterator macro;
- // If this is a known pre-processing symbol, then we insert it,
- // otherwise we assume it's a file name to load.
- if (local_defines_ &&
- (arg = local_defines_->find(symbol)) != local_defines_->end())
- {
- if (strings_.size() - token.stack_pos != 1)
- {
- std::ostringstream error;
- error << "macro argument '" << symbol
- << "' does not expect any argument";
- target_.error(error.str(), linenum_);
- }
- std::ostringstream v;
- v << arg->second << "\376line " << linenum_ << ' ' << target_.location_
- << "\n\376textdomain " << target_.textdomain_ << '\n';
- pop_token();
- put(v.str());
- }
- else if ((macro = target_.defines_->find(symbol)) != target_.defines_->end())
- {
- preproc_define const &val = macro->second;
- size_t nb_arg = strings_.size() - token.stack_pos - 1;
- if (nb_arg != val.arguments.size())
- {
- std::ostringstream error;
- error << "preprocessor symbol '" << symbol << "' expects "
- << val.arguments.size() << " arguments, but has "
- << nb_arg << " arguments";
- target_.error(error.str(), linenum_);
- }
- std::istringstream *buffer = new std::istringstream(val.value);
- std::map<std::string, std::string> *defines =
- new std::map<std::string, std::string>;
- for (size_t i = 0; i < nb_arg; ++i) {
- (*defines)[val.arguments[i]] = strings_[token.stack_pos + i + 1];
- }
- pop_token();
- 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, "",
- val.linenum, dir, val.textdomain, defines);
- } else {
- DBG_CF << "substituting (slow) macro " << symbol << '\n';
- std::ostringstream res;
- preprocessor_streambuf *buf =
- new preprocessor_streambuf(target_);
- { std::istream in(buf);
- new preprocessor_data(*buf, buffer, val.location, "",
- val.linenum, dir, val.textdomain, defines);
- res << in.rdbuf(); }
- delete buf;
- put(res.str());
- }
- } else if (target_.depth_ < 40) {
- LOG_CF << "Macro definition not found for " << symbol << " , attempting to open as file.\n";
- pop_token();
- std::string prefix;
- std::string nfname = get_wml_location(symbol, directory_);
- if (!nfname.empty())
- {
- if (!slowpath_)
- new preprocessor_file(target_, nfname);
- else {
- std::ostringstream res;
- preprocessor_streambuf *buf =
- new preprocessor_streambuf(target_);
- { std::istream in(buf);
- new preprocessor_file(*buf, nfname);
- res << in.rdbuf(); }
- delete buf;
- put(res.str());
- }
- }
- else
- {
- std::ostringstream error;
- error << "Macro/file '" << symbol << "' is missing";
- target_.error(error.str(), linenum_);
- }
- } else {
- target_.error("Too much nested preprocessing inclusions", linenum_);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment