Example #1
0
void Parser::onMethod(Token &out, Token &modifiers, Token &ret, Token &ref,
                      Token &name, Token &params, Token &stmt,
                      bool reloc /* = true */) {
  ClassStatementPtr cs = peekClass();
  MethodStatementPtr ms = peekFunc()->unsafe_cast<MethodStatement>();
  ASSERT(ms);
  popFunc();
  if (reloc) {
    ms->setLoc(popFuncLocation().get());
  }
  ms->resetLoc(this);
  bool hasCallToGetArgs = m_hasCallToGetArgs.back();
  m_hasCallToGetArgs.pop_back();

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

    Token new_params;
    prepare_generator(this, stmt, new_params, ms->getYieldCount());
    StatementListStatementPtr stmts = stmt->getStmtList();
    if (stmts) stmts->resetLoc(this);
    ms->init(this, ref.num(), new_params->params(), stmts, hasCallToGetArgs);

    String clsname = cs->name();
    create_generator(this, out, params, name, closureName, clsname.data(),
                     &modifiers);
  } else {
    StatementListStatementPtr stmts = stmt->getStmtList();
    if (stmts) stmts->resetLoc(this);
    ms->init(this, ref.num(), params->params(), stmts, hasCallToGetArgs);
  }
  cs->addMethod(ms);
}
Example #2
0
void Parser::onMethod(Token &out, Token &modifiers, Token &ref, Token &name,
                      Token &params, Token &stmt) {
  ClassStatementPtr cs = peekClass();
  MethodStatementPtr ms = peekFunc()->unsafe_cast<MethodStatement>();
  ASSERT(ms);
  popFunc();
  StatementListStatementPtr stmts = stmt->getStmtList();
  ms->resetLoc(this);
  if (stmts) stmts->resetLoc(this);
  ms->init(this, ref.num(), params->params(), stmts, m_hasCallToGetArgs);
  cs->addMethod(ms);
}