void IncludeExpression::onParse(AnalysisResultConstPtr ar, FileScopePtr scope) {
  /* m_documentRoot is a bitfield */
  bool dr = m_documentRoot;
  m_include = CheckInclude(shared_from_this(), m_exp, dr);
  m_documentRoot = dr;
  if (!m_include.empty()) ar->parseOnDemand(m_include);
}
Beispiel #2
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;
}