示例#1
0
void InterfaceStatement::onParse(AnalysisResultConstRawPtr ar,
                                 FileScopePtr scope) {
  std::vector<std::string> bases;
  if (m_base) m_base->getStrings(bases);

  for (auto &b : bases) {
    ar->parseOnDemandByClass(b);
  }

  auto stmt = dynamic_pointer_cast<Statement>(shared_from_this());

  std::vector<UserAttributePtr> attrs;
  if (m_attrList) {
    for (int i = 0; i < m_attrList->getCount(); ++i) {
      auto a = dynamic_pointer_cast<UserAttribute>((*m_attrList)[i]);
      attrs.push_back(a);
    }
  }

  auto classScope =
    std::make_shared<ClassScope>(
      scope, ClassScope::KindOf::Interface, m_originalName, "", bases,
      m_docComment, stmt, attrs);

  setBlockScope(classScope);
  scope->addClass(ar, classScope);

  if (m_stmt) {
    for (int i = 0; i < m_stmt->getCount(); i++) {
      auto ph = dynamic_pointer_cast<IParseHandler>((*m_stmt)[i]);
      ph->onParseRecur(ar, scope, classScope);
    }
    checkArgumentsToPromote(scope, ExpressionListPtr(), T_INTERFACE);
  }
}
示例#2
0
void UseTraitStatement::onParseRecur(AnalysisResultConstRawPtr ar,
                                     FileScopeRawPtr fs,
                                     ClassScopePtr scope) {
  if (scope->isInterface()) {
    parseTimeFatal(fs,
                   "Interfaces cannot use traits");
  }
  std::vector<std::string> usedTraits;
  getUsedTraitNames(usedTraits);
  for (auto &t : usedTraits) {
    ar->parseOnDemandByClass(toLower(t));
  }
  scope->addUsedTraits(usedTraits);
}