Exemple #1
0
void Parser::onYield(Token &out, Token *expr) {
  if (!RuntimeOption::EnableHipHopSyntax) {
    raise_error("Yield is not enabled: %s", getMessage().c_str());
    return;
  }
  if (!haveFunc()) {
    raise_error("Yield cannot only be used inside a function: %s",
                getMessage().c_str());
    return;
  }

  FunctionStatementPtr func = peekFunc();
  if (func->hasReturn()) {
    raise_error("Cannot mix 'return' and 'yield' in the same function: %s",
                getMessage().c_str());
    return;
  }
  int index = func->addYield();

  Token stmts;
  transform_yield(this, stmts, index, expr);

  out.reset();
  out->stmt() = stmts->getStmtList();
}
Exemple #2
0
void Parser::onYield(Token &out, Token *expr) {
  if (!RuntimeOption::EnableHipHopSyntax) {
    error("Yield is not enabled: %s", getMessage().c_str());
    return;
  }
  if (!haveFunc()) {
    error("Yield cannot only be used inside a function: %s",
          getMessage().c_str());
    return;
  }

  FunctionStatementPtr func = peekFunc();
  if (func->hasReturn()) {
    error("Cannot mix 'return' and 'yield' in the same function: %s",
          getMessage().c_str());
    return;
  }
  if (haveClass()) {
    if (strcasecmp(func->name().data(), peekClass()->name().data()) == 0) {
      error("'yield' is not allowed in potential constructors: %s",
            getMessage().c_str());
      return;
    }
    if (func->name().substr(0, 2) == "__") {
      error("'yield' is not allowed in constructor, destructor, or "
            "magic methods: %s", getMessage().c_str());
      return;
    }
  }
  int index = func->addYield();

  Token stmts;
  transform_yield(this, stmts, index, expr);

  out.reset();
  out->stmt() = stmts->getStmtList();
}