예제 #1
0
void ExpStatement::onParse(AnalysisResultConstPtr ar, FileScopePtr scope) {
  if (Option::OutputHHBC && !ar->isParseOnDemand()) return;
  if (!m_exp->is(Expression::KindOfAssignmentExpression)) return;

  AssignmentExpressionPtr assign =
    dynamic_pointer_cast<AssignmentExpression>(m_exp);
  if (!assign->getVariable()->is(Expression::KindOfArrayElementExpression)) {
    return;
  }
  if (!assign->getValue()->is(Expression::KindOfScalarExpression) ||
      !dynamic_pointer_cast<ScalarExpression>
      (assign->getValue())->isLiteralString()) {
    return;
  }

  string file = assign->getValue()->getLiteralString();
  if (file.empty()) return;

  string s = assign->getText();
  string path = Option::GetAutoloadRoot(s);
  if (path.empty()) return;

  if (path[path.length() - 1] != '/' && file[0] != '/') {
    file = path + '/' + file;
  } else {
    file = path + file;
  }

  if (Option::OutputHHBC) {
    ar->parseOnDemand(file);
    return;
  }

  ScalarExpressionPtr exp
    (new ScalarExpression(getScope(), assign->getValue()->getLocation(),
                          T_STRING, file, true));
  IncludeExpressionPtr include
    (new IncludeExpression(getScope(), assign->getLocation(),
                           exp, T_INCLUDE_ONCE));
  include->setDocumentRoot(); // autoload always starts from document root
  include->onParse(ar, scope);
  m_exp = include;
}
예제 #2
0
void Parser::onUnaryOpExp(Token *out, Token *operand, int op, bool front) {
  switch (op) {
  case T_INCLUDE:
  case T_INCLUDE_ONCE:
  case T_REQUIRE:
  case T_REQUIRE_ONCE:
    {
      IncludeExpressionPtr exp = NEW_EXP(IncludeExpression, operand->exp, op);
      out->exp = exp;
      exp->onParse(m_ar);
    }
    break;
  default:
    {
      UnaryOpExpressionPtr exp = NEW_EXP(UnaryOpExpression, operand->exp, op,
                                         front);
      out->exp = exp;
      exp->onParse(m_ar);
    }
    break;
  }
}