shadowm

Untitled

Mar 22nd, 2011
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.90 KB | None | 0 0
  1.             --slowpath_;
  2.             if (skipping_) {
  3.                 pop_token();
  4.                 return true;
  5.             }
  6.             // FIXME: is this obsolete?
  7.             //if (token.type == token_desc::MACRO_SPACE) {
  8.             //  if (!strings_.back().empty()) {
  9.             //      std::ostringstream error;
  10.             //      std::ostringstream location;
  11.             //      error << "Can't parse new macro parameter with a macro call scope open";
  12.             //      location<<linenum_<<' '<<target_.location_;
  13.             //      target_.error(error.str(), location.str());
  14.             //  }
  15.             //  strings_.pop_back();
  16.             //}
  17.  
  18.             std::string symbol = strings_[token.stack_pos];
  19.             std::string::size_type pos;
  20.             while ((pos = symbol.find('\376')) != std::string::npos) {
  21.                 std::string::iterator b = symbol.begin(); // invalidated at each iteration
  22.                 symbol.erase(b + pos, b + symbol.find('\n', pos + 1) + 1);
  23.             }
  24.             std::map<std::string, std::string>::const_iterator arg;
  25.             preproc_map::const_iterator macro;
  26.             // If this is a known pre-processing symbol, then we insert it,
  27.             // otherwise we assume it's a file name to load.
  28.             if (local_defines_ &&
  29.                 (arg = local_defines_->find(symbol)) != local_defines_->end())
  30.             {
  31.                 if (strings_.size() - token.stack_pos != 1)
  32.                 {
  33.                     std::ostringstream error;
  34.                     error << "macro argument '" << symbol
  35.                           << "' does not expect any argument";
  36.                     target_.error(error.str(), linenum_);
  37.                 }
  38.                 std::ostringstream v;
  39.                 v << arg->second << "\376line " << linenum_ << ' ' << target_.location_
  40.                   << "\n\376textdomain " << target_.textdomain_ << '\n';
  41.                 pop_token();
  42.                 put(v.str());
  43.             }
  44.             else if ((macro = target_.defines_->find(symbol)) != target_.defines_->end())
  45.             {
  46.                 preproc_define const &val = macro->second;
  47.                 size_t nb_arg = strings_.size() - token.stack_pos - 1;
  48.                 if (nb_arg != val.arguments.size())
  49.                 {
  50.                     std::ostringstream error;
  51.                     error << "preprocessor symbol '" << symbol << "' expects "
  52.                           << val.arguments.size() << " arguments, but has "
  53.                           << nb_arg << " arguments";
  54.                     target_.error(error.str(), linenum_);
  55.                 }
  56.                 std::istringstream *buffer = new std::istringstream(val.value);
  57.                 std::map<std::string, std::string> *defines =
  58.                     new std::map<std::string, std::string>;
  59.                 for (size_t i = 0; i < nb_arg; ++i) {
  60.                     (*defines)[val.arguments[i]] = strings_[token.stack_pos + i + 1];
  61.                 }
  62.                 pop_token();
  63.                 std::string const &dir = directory_name(val.location.substr(0, val.location.find(' ')));
  64.                 if (!slowpath_) {
  65.                     DBG_CF << "substituting macro " << symbol << '\n';
  66.                     new preprocessor_data(target_, buffer, val.location, "",
  67.                                           val.linenum, dir, val.textdomain, defines);
  68.                 } else {
  69.                     DBG_CF << "substituting (slow) macro " << symbol << '\n';
  70.                     std::ostringstream res;
  71.                     preprocessor_streambuf *buf =
  72.                         new preprocessor_streambuf(target_);
  73.                     {   std::istream in(buf);
  74.                         new preprocessor_data(*buf, buffer, val.location, "",
  75.                                               val.linenum, dir, val.textdomain, defines);
  76.                         res << in.rdbuf(); }
  77.                     delete buf;
  78.                     put(res.str());
  79.                 }
  80.             } else if (target_.depth_ < 40) {
  81.                 LOG_CF << "Macro definition not found for " << symbol << " , attempting to open as file.\n";
  82.                 pop_token();
  83.                 std::string prefix;
  84.                 std::string nfname = get_wml_location(symbol, directory_);
  85.                 if (!nfname.empty())
  86.                 {
  87.                     if (!slowpath_)
  88.                         new preprocessor_file(target_, nfname);
  89.                     else {
  90.                         std::ostringstream res;
  91.                         preprocessor_streambuf *buf =
  92.                             new preprocessor_streambuf(target_);
  93.                         {   std::istream in(buf);
  94.                             new preprocessor_file(*buf, nfname);
  95.                             res << in.rdbuf(); }
  96.                         delete buf;
  97.                         put(res.str());
  98.                     }
  99.                 }
  100.                 else
  101.                 {
  102.                     std::ostringstream error;
  103.                     error << "Macro/file '" << symbol << "' is missing";
  104.                     target_.error(error.str(), linenum_);
  105.                 }
  106.             } else {
  107.                 target_.error("Too much nested preprocessing inclusions", linenum_);
  108.             }
  109.         }
Advertisement
Add Comment
Please, Sign In to add comment