コード例 #1
0
ファイル: CheckObjCDealloc.cpp プロジェクト: Bekenn/clang
/// Returns the property that shadowed by PropImpl if one exists and
/// nullptr otherwise.
const ObjCPropertyDecl *ObjCDeallocChecker::findShadowedPropertyDecl(
    const ObjCPropertyImplDecl *PropImpl) const {
  const ObjCPropertyDecl *PropDecl = PropImpl->getPropertyDecl();

  // Only readwrite properties can shadow.
  if (PropDecl->isReadOnly())
    return nullptr;

  auto *CatDecl = dyn_cast<ObjCCategoryDecl>(PropDecl->getDeclContext());

  // Only class extensions can contain shadowing properties.
  if (!CatDecl || !CatDecl->IsClassExtension())
    return nullptr;

  IdentifierInfo *ID = PropDecl->getIdentifier();
  DeclContext::lookup_result R = CatDecl->getClassInterface()->lookup(ID);
  for (DeclContext::lookup_iterator I = R.begin(), E = R.end(); I != E; ++I) {
    auto *ShadowedPropDecl = dyn_cast<ObjCPropertyDecl>(*I);
    if (!ShadowedPropDecl)
      continue;

    if (ShadowedPropDecl->isInstanceProperty()) {
      assert(ShadowedPropDecl->isReadOnly());
      return ShadowedPropDecl;
    }
  }

  return nullptr;
}
コード例 #2
0
DeclContextLookupResult MultiplexExternalSemaSource::
FindExternalVisibleDeclsByName(const DeclContext *DC, DeclarationName Name) {
  StoredDeclsList DeclsFound;
  for(size_t i = 0; i < Sources.size(); ++i) {
    DeclContext::lookup_result R =
      Sources[i]->FindExternalVisibleDeclsByName(DC, Name);
    for (DeclContext::lookup_iterator I = R.begin(), E = R.end(); I != E;
      ++I) {
      if (!DeclsFound.HandleRedeclaration(*I))
        DeclsFound.AddSubsequentDecl(*I);
    }
  }
  return DeclsFound.getLookupResult(); 
}
コード例 #3
0
    bool ASTImportSource::Import(DeclContext::lookup_result lookup_result,
                                 ASTContext &from_ASTContext,
                                 ASTContext &to_ASTContext,
                                 const DeclContext *childCurrentDeclContext,
                                 DeclarationName &childDeclName,
                                 DeclarationName &parentDeclName) {

      // Prepare to import the Decl(Context)  we found in the
      // child interpreter by getting the file managers from
      // each interpreter.
      FileManager &child_FM = m_child_Interp->getCI()->getFileManager();
      FileManager &parent_FM = m_parent_Interp->getCI()->getFileManager();

      // Clang's ASTImporter
      ASTImporter importer(to_ASTContext, child_FM,
                           from_ASTContext, parent_FM,
                           /*MinimalImport : ON*/ true);

      for (DeclContext::lookup_iterator I = lookup_result.begin(),
             E = lookup_result.end();
             I != E; ++I) {
        // Check if this Name we are looking for is
        // a DeclContext (for example a Namespace, function etc.).
        if (DeclContext *declContextToImport = llvm::dyn_cast<DeclContext>(*I)) {

          ImportDeclContext(declContextToImport, importer, childDeclName,
                            parentDeclName, childCurrentDeclContext);

        } else if (Decl *declToImport = llvm::dyn_cast<Decl>(*I)) {

          // else it is a Decl
          ImportDecl(declToImport, importer, childDeclName,
                     parentDeclName, childCurrentDeclContext);
        }
      }
      return true;
    }
コード例 #4
0
NamespaceDecl *Sema::ActOnRogerNamespaceHeaderPart(DeclContext *DeclContext, IdentifierInfo *II,
        SourceLocation IdentLoc,
        AttributeList *AttrList) {
    // set CurContext

    SourceLocation NamespaceLoc;
    SourceLocation InlineLoc;
    SourceLocation StartLoc = InlineLoc.isValid() ? InlineLoc : NamespaceLoc;

    assert(II);
    SourceLocation Loc = IdentLoc;
    bool IsInline = false;
    bool IsInvalid = false;
    bool IsStd = false;
    bool AddToKnown = false;
    //Scope *DeclRegionScope = NamespcScope->getParent();

    NamespaceDecl *PrevNS = 0;
    // C++ [namespace.def]p2:
    //   The identifier in an original-namespace-definition shall not
    //   have been previously defined in the declarative region in
    //   which the original-namespace-definition appears. The
    //   identifier in an original-namespace-definition is the name of
    //   the namespace. Subsequently in that declarative region, it is
    //   treated as an original-namespace-name.
    //
    // Since namespace names are unique in their scope, and we don't
    // look through using directives, just look for any ordinary names.

    const unsigned IDNS = Decl::IDNS_Ordinary | Decl::IDNS_Member |
                          Decl::IDNS_Type | Decl::IDNS_Using | Decl::IDNS_Tag |
                          Decl::IDNS_Namespace;
    NamedDecl *PrevDecl = 0;
    DeclContext::lookup_result R = DeclContext->getRedeclContext()->lookup(II);
    for (DeclContext::lookup_iterator I = R.begin(), E = R.end(); I != E;
            ++I) {
        if ((*I)->getIdentifierNamespace() & IDNS) {
            PrevDecl = *I;
            break;
        }
    }

    PrevNS = dyn_cast_or_null<NamespaceDecl>(PrevDecl);

    if (PrevNS) {
        // This is an extended namespace definition.
        if (IsInline != PrevNS->isInline()) {
//      DiagnoseNamespaceInlineMismatch(*this, NamespaceLoc, Loc, II,
//                                      &IsInline, PrevNS);
            assert(false && "need to implement this");
        }
        return PrevNS;
    } else if (PrevDecl) {
        // This is an invalid name redefinition.
        Diag(Loc, diag::err_redefinition_different_kind)
                << II;
        Diag(PrevDecl->getLocation(), diag::note_previous_definition);
        IsInvalid = true;
        // Continue on to push Namespc as current DeclContext and return it.
    } else if (II->isStr("std") &&
               DeclContext->getRedeclContext()->isTranslationUnit()) {
        // This is the first "real" definition of the namespace "std", so update
        // our cache of the "std" namespace to point at this definition.
        PrevNS = getStdNamespace();
        IsStd = true;
        AddToKnown = !IsInline;
    } else {
        // We've seen this namespace for the first time.
        AddToKnown = !IsInline;
    }

    NamespaceDecl *Namespc = NamespaceDecl::Create(Context, DeclContext, IsInline,
                             StartLoc, Loc, II, PrevNS);
    Namespc->IsRogerNamespace = true;

    if (IsInvalid)
        Namespc->setInvalidDecl();

    //ProcessDeclAttributeList(DeclRegionScope, Namespc, AttrList);

    // FIXME: Should we be merging attributes?
    if (const VisibilityAttr *Attr = Namespc->getAttr<VisibilityAttr>())
        PushNamespaceVisibilityAttr(Attr, Loc);

    if (IsStd)
        StdNamespace = Namespc;
    if (AddToKnown)
        KnownNamespaces[Namespc] = false;

    DeclContext->addDecl(Namespc);

    if (PrevNS) {
        return PrevNS;
    } else {
        return Namespc;
    }
}