예제 #1
0
void Parser::onFunction(Token &out, Token &ret, Token &ref, Token &name,
                        Token &params, Token &stmt) {
  FunctionStatementPtr func = peekFunc();
  ASSERT(func);
  popFunc();
  func->setLoc(popFuncLocation().get());
  bool hasCallToGetArgs = m_hasCallToGetArgs.back();
  m_hasCallToGetArgs.pop_back();

  if (func->hasYield()) {
    string closureName = getClosureName();
    func->setName(closureName);

    Token new_params;
    prepare_generator(this, stmt, new_params, func->getYieldCount());
    StatementListStatementPtr body = stmt->getStmtList();
    func->init(this, ref.num(), new_params->params(), body, hasCallToGetArgs);

    out.reset();
    out->stmt() = func;
    create_generator(this, out, params, name, closureName, NULL, NULL);

  } else {
    StatementListStatementPtr body = stmt->getStmtList();
    func->init(this, ref.num(), params->params(), body, hasCallToGetArgs);
    out.reset();
    out->stmt() = func;
  }
}
예제 #2
0
void Parser::onFunction(Token &out, Token &ref, Token &name, Token &params,
                        Token &stmt) {
  out.reset();
  FunctionStatementPtr func = peekFunc();
  ASSERT(func);
  StatementListStatementPtr body = stmt->getStmtList();
  func->init(this, ref.num(), params->params(), body, m_hasCallToGetArgs);
  out->stmt() = func;
  popFunc();
}