当前位置: 首页>>代码示例>>C++>>正文


C++ Argument::pstate方法代码示例

本文整理汇总了C++中Argument::pstate方法的典型用法代码示例。如果您正苦于以下问题:C++ Argument::pstate方法的具体用法?C++ Argument::pstate怎么用?C++ Argument::pstate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Argument的用法示例。


在下文中一共展示了Argument::pstate方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: bind

  void bind(std::string type, std::string name, Parameters* ps, Arguments* as, Context* ctx, Env* env, Eval* eval)
  {
    std::string callee(type + " " + name);

    Listize listize(ctx->mem);
    std::map<std::string, Parameter*> param_map;

    for (size_t i = 0, L = as->length(); i < L; ++i) {
      if (auto str = dynamic_cast<String_Quoted*>((*as)[i]->value())) {
        // force optional quotes (only if needed)
        if (str->quote_mark()) {
          str->quote_mark('*');
          str->is_delayed(true);
        }
      }
    }

    // Set up a map to ensure named arguments refer to actual parameters. Also
    // eval each default value left-to-right, wrt env, populating env as we go.
    for (size_t i = 0, L = ps->length(); i < L; ++i) {
      Parameter*  p = (*ps)[i];
      param_map[p->name()] = p;
      // if (p->default_value()) {
      //   env->local_frame()[p->name()] = p->default_value()->perform(eval->with(env));
      // }
    }

    // plug in all args; if we have leftover params, deal with it later
    size_t ip = 0, LP = ps->length();
    size_t ia = 0, LA = as->length();
    while (ia < LA) {
      Argument* a = (*as)[ia];
      if (ip >= LP) {
        // skip empty rest arguments
        if (a->is_rest_argument()) {
          if (List* l = dynamic_cast<List*>(a->value())) {
            if (l->length() == 0) {
              ++ ia; continue;
            }
          }
        }
        std::stringstream msg;
        msg << "wrong number of arguments (" << LA << " for " << LP << ")";
        msg << " for `" << name << "'";
        return error(msg.str(), as->pstate());
      }
      Parameter* p = (*ps)[ip];

      // If the current parameter is the rest parameter, process and break the loop
      if (p->is_rest_parameter()) {
        // The next argument by coincidence provides a rest argument
        if (a->is_rest_argument()) {

          // We should always get a list for rest arguments
          if (List* rest = dynamic_cast<List*>(a->value())) {
              // create a new list object for wrapped items
              List* arglist = SASS_MEMORY_NEW(ctx->mem, List,
                                              p->pstate(),
                                              0,
                                              rest->separator(),
                                              true);
              // wrap each item from list as an argument
              for (Expression* item : rest->elements()) {
                if (Argument* arg = dynamic_cast<Argument*>(item)) {
                  (*arglist) << SASS_MEMORY_NEW(ctx->mem, Argument, *arg);
                } else {
                  (*arglist) << SASS_MEMORY_NEW(ctx->mem, Argument,
                                                item->pstate(),
                                                item,
                                                "",
                                                false,
                                                false);
                }
              }
              // assign new arglist to environment
              env->local_frame()[p->name()] = arglist;
            }
          // invalid state
          else {
            throw std::runtime_error("invalid state");
          }
        } else if (a->is_keyword_argument()) {

          // expand keyword arguments into their parameters
          List* arglist = SASS_MEMORY_NEW(ctx->mem, List, p->pstate(), 0, SASS_COMMA, true);
          env->local_frame()[p->name()] = arglist;
          Map* argmap = static_cast<Map*>(a->value());
          for (auto key : argmap->keys()) {
            std::string name = unquote(static_cast<String_Constant*>(key)->value());
            (*arglist) << SASS_MEMORY_NEW(ctx->mem, Argument,
                                          key->pstate(),
                                          argmap->at(key),
                                          "$" + name,
                                          false,
                                          false);
          }

        } else {

          // create a new list object for wrapped items
//.........这里部分代码省略.........
开发者ID:lowsar,项目名称:libsass,代码行数:101,代码来源:bind.cpp

示例2: bind

  void bind(string callee, Parameters* ps, Arguments* as, Context& ctx, Env* env, Eval* eval)
  {
    map<string, Parameter*> param_map;

    // Set up a map to ensure named arguments refer to actual parameters. Also
    // eval each default value left-to-right, wrt env, populating env as we go.
    for (size_t i = 0, L = ps->length(); i < L; ++i) {
      Parameter*  p = (*ps)[i];
      param_map[p->name()] = p;
      // if (p->default_value()) {
      //   env->local_frame()[p->name()] = p->default_value()->perform(eval->with(env));
      // }
    }

    // plug in all args; if we have leftover params, deal with it later
    size_t ip = 0, LP = ps->length();
    size_t ia = 0, LA = as->length();
    while (ia < LA) {
      Argument* a = (*as)[ia];
      if (ip >= LP) {
        // skip empty rest arguments
        if (a->is_rest_argument()) {
          if (List* l = dynamic_cast<List*>(a->value())) {
            if (l->length() == 0) {
              ++ ia; continue;
            }
          }
        }
        stringstream msg;
        msg << callee << " only takes " << LP << " arguments; "
            << "given " << LA;
        error(msg.str(), as->pstate());
      }
      Parameter* p = (*ps)[ip];

      // If the current parameter is the rest parameter, process and break the loop
      if (p->is_rest_parameter()) {
        // The next argument by coincidence provides a rest argument
        if (a->is_rest_argument()) {
          // We should always get a list for rest arguments
          if (List* rest = dynamic_cast<List*>(a->value())) {
            // arg contains a list
            List* args = rest;
            // make sure it's an arglist
            if (rest->is_arglist()) {
              // can pass it through as it was
              env->local_frame()[p->name()] = args;
            }
            // create a new list and wrap each item as an argument
            // otherwise we will not be able to fetch it again
            else {
              // create a new list object for wrapped items
              List* arglist = new (ctx.mem) List(p->pstate(),
                                                 0,
                                                 rest->separator(),
                                                 true);
              // wrap each item from list as an argument
              for (Expression* item : rest->elements()) {
                (*arglist) << new (ctx.mem) Argument(item->pstate(),
                                                     item,
                                                     "",
                                                     false,
                                                     false);
              }
              // assign new arglist to environment
              env->local_frame()[p->name()] = arglist;
            }
          }
          // invalid state
          else {
            throw runtime_error("invalid state");
          }
        } else if (a->is_keyword_argument()) {

          // expand keyword arguments into their parameters
          List* arglist = new (ctx.mem) List(p->pstate(), 0, List::COMMA, true);
          env->local_frame()[p->name()] = arglist;
          Map* argmap = static_cast<Map*>(a->value());
          for (auto key : argmap->keys()) {
            string name = unquote(static_cast<String_Constant*>(key)->value());
            (*arglist) << new (ctx.mem) Argument(key->pstate(),
                                                 argmap->at(key),
                                                 name,
                                                 false,
                                                 false);
          }

        } else {

          // create a new list object for wrapped items
          List* arglist = new (ctx.mem) List(p->pstate(),
                                             0,
                                             List::COMMA,
                                             true);
          // consume the next args
          while (ia < LA) {
            // get and post inc
            a = (*as)[ia++];
            // wrap current argument into new object
            (*arglist) << new (ctx.mem) Argument(a->pstate(),
//.........这里部分代码省略.........
开发者ID:326029212,项目名称:vue-gulp-webpack,代码行数:101,代码来源:bind.cpp


注:本文中的Argument::pstate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。