]> granicus.if.org Git - clang/commitdiff
Introduce a new predicate Decl::isFromASTFile() to determine whether a
authorDouglas Gregor <dgregor@apple.com>
Fri, 9 Sep 2011 23:01:35 +0000 (23:01 +0000)
committerDouglas Gregor <dgregor@apple.com>
Fri, 9 Sep 2011 23:01:35 +0000 (23:01 +0000)
declaration was deserialized from an AST file. Use this instead of
Decl::getPCHLevel() wherever possible. This is a simple step toward
killing off Decl::getPCHLevel().

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@139427 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/DeclBase.h
include/clang/Sema/Lookup.h
lib/CodeGen/CGObjCMac.cpp
lib/Serialization/ASTWriter.cpp
lib/Serialization/ASTWriterDecl.cpp

index 14d811fa674fc9d74e8e741d8e6d98d54a36983f..4cfe32c4480306eeadc9ccf2e8d6c0d94805ed4f 100644 (file)
@@ -511,6 +511,10 @@ public:
   /// loaded from a PCH file the AST file depends on, and so on.
   unsigned getPCHLevel() const { return PCHLevel; }
 
+  /// \brief Determine whether this declaration came from an AST file (such as
+  /// a precompiled header or module) rather than having been parsed.
+  bool isFromASTFile() const { return PCHLevel > 0; }
+  
   /// \brief The maximum PCH level that any declaration may have.
   static const unsigned MaxPCHLevel = 3;
 
index 1fa9066cf2b13bdcd10c315b31513b8260775f2d..ce762b87f2820dc0a005b6807cf0164352a191b7 100644 (file)
@@ -274,7 +274,7 @@ public:
     // So long as this declaration is not module-private or was parsed as
     // part of this translation unit (i.e., in the module), we're allowed to
     // find it.
-    if (!D->isModulePrivate() || D->getPCHLevel() == 0)
+    if (!D->isModulePrivate() || !D->isFromASTFile())
       return true;
 
     // FIXME: We should be allowed to refer to a module-private name from 
index 8223560bc043cd7e2e173172e400b78c81fb0539..f0ff9eb4326dfb247f953909494fa9a1773d92e4 100644 (file)
@@ -3549,7 +3549,7 @@ llvm::Function *CGObjCCommonMac::GetMethodDefinition(const ObjCMethodDecl *MD) {
   if (I != MethodDefinitions.end())
     return I->second;
 
-  if (MD->hasBody() && MD->getPCHLevel() > 0) {
+  if (MD->hasBody() && MD->isFromASTFile()) {
     // MD isn't emitted yet because it comes from PCH.
     CGM.EmitTopLevelDecl(const_cast<ObjCMethodDecl*>(MD));
     assert(MethodDefinitions[MD] && "EmitTopLevelDecl didn't emit the method!");
index a995a70f24cf242ce6aac6a0171c35023a0503c8..92692f0cd3d9e7c81c7fa8c0ead7e45621086e26 100644 (file)
@@ -2208,12 +2208,12 @@ void ASTWriter::WriteSelectors(Sema &SemaRef) {
         bool changed = false;
         for (ObjCMethodList *M = &Data.Instance; !changed && M && M->Method;
              M = M->Next) {
-          if (M->Method->getPCHLevel() == 0)
+          if (!M->Method->isFromASTFile())
             changed = true;
         }
         for (ObjCMethodList *M = &Data.Factory; !changed && M && M->Method;
              M = M->Next) {
-          if (M->Method->getPCHLevel() == 0)
+          if (!M->Method->isFromASTFile())
             changed = true;
         }
         if (!changed)
@@ -2941,7 +2941,7 @@ void ASTWriter::WriteASTCore(Sema &SemaRef, MemorizeStatCalls *StatCalls,
          TD = SemaRef.LocallyScopedExternalDecls.begin(),
          TDEnd = SemaRef.LocallyScopedExternalDecls.end();
        TD != TDEnd; ++TD) {
-    if (TD->second->getPCHLevel() == 0)
+    if (!TD->second->isFromASTFile())
       AddDeclRef(TD->second, LocallyScopedExternalDecls);
   }
   
@@ -3055,7 +3055,7 @@ void ASTWriter::WriteASTCore(Sema &SemaRef, MemorizeStatCalls *StatCalls,
   for (DeclContext::decl_iterator I = TU->noload_decls_begin(),
                                   E = TU->noload_decls_end();
        I != E; ++I) {
-    if ((*I)->getPCHLevel() == 0)
+    if (!(*I)->isFromASTFile())
       NewGlobalDecls.push_back(std::make_pair((*I)->getKind(), GetDeclRef(*I)));
     else if ((*I)->isChangedSinceDeserialization())
       (void)GetDeclRef(*I); // Make sure it's written, but don't record it.
@@ -3992,7 +3992,7 @@ void ASTWriter::CompletedTagDefinition(const TagDecl *D) {
   assert(D->isDefinition());
   if (const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(D)) {
     // We are interested when a PCH decl is modified.
-    if (RD->getPCHLevel() > 0) {
+    if (RD->isFromASTFile()) {
       // A forward reference was mutated into a definition. Rewrite it.
       // FIXME: This happens during template instantiation, should we
       // have created a new definition decl instead ?
@@ -4006,7 +4006,7 @@ void ASTWriter::CompletedTagDefinition(const TagDecl *D) {
         continue;
 
       // We are interested when a PCH decl is modified.
-      if (Redecl->getPCHLevel() > 0) {
+      if (Redecl->isFromASTFile()) {
         UpdateRecord &Record = DeclUpdates[Redecl];
         Record.push_back(UPD_CXX_SET_DEFINITIONDATA);
         assert(Redecl->DefinitionData);
@@ -4021,7 +4021,7 @@ void ASTWriter::AddedVisibleDecl(const DeclContext *DC, const Decl *D) {
   if (isa<TranslationUnitDecl>(DC) || isa<NamespaceDecl>(DC))
     return;
 
-  if (!(D->getPCHLevel() == 0 && cast<Decl>(DC)->getPCHLevel() > 0))
+  if (!(!D->isFromASTFile() && cast<Decl>(DC)->isFromASTFile()))
     return; // Not a source decl added to a DeclContext from PCH.
 
   AddUpdatedDeclContext(DC);
@@ -4029,7 +4029,7 @@ void ASTWriter::AddedVisibleDecl(const DeclContext *DC, const Decl *D) {
 
 void ASTWriter::AddedCXXImplicitMember(const CXXRecordDecl *RD, const Decl *D) {
   assert(D->isImplicit());
-  if (!(D->getPCHLevel() == 0 && RD->getPCHLevel() > 0))
+  if (!(!D->isFromASTFile() && RD->isFromASTFile()))
     return; // Not a source member added to a class from PCH.
   if (!isa<CXXMethodDecl>(D))
     return; // We are interested in lazily declared implicit methods.
@@ -4045,7 +4045,7 @@ void ASTWriter::AddedCXXTemplateSpecialization(const ClassTemplateDecl *TD,
                                      const ClassTemplateSpecializationDecl *D) {
   // The specializations set is kept in the canonical template.
   TD = TD->getCanonicalDecl();
-  if (!(D->getPCHLevel() == 0 && TD->getPCHLevel() > 0))
+  if (!(!D->isFromASTFile() && TD->isFromASTFile()))
     return; // Not a source specialization added to a template from PCH.
 
   UpdateRecord &Record = DeclUpdates[TD];
@@ -4057,7 +4057,7 @@ void ASTWriter::AddedCXXTemplateSpecialization(const FunctionTemplateDecl *TD,
                                                const FunctionDecl *D) {
   // The specializations set is kept in the canonical template.
   TD = TD->getCanonicalDecl();
-  if (!(D->getPCHLevel() == 0 && TD->getPCHLevel() > 0))
+  if (!(!D->isFromASTFile() && TD->isFromASTFile()))
     return; // Not a source specialization added to a template from PCH.
 
   UpdateRecord &Record = DeclUpdates[TD];
@@ -4066,7 +4066,7 @@ void ASTWriter::AddedCXXTemplateSpecialization(const FunctionTemplateDecl *TD,
 }
 
 void ASTWriter::CompletedImplicitDefinition(const FunctionDecl *D) {
-  if (D->getPCHLevel() == 0)
+  if (!D->isFromASTFile())
     return; // Declaration not imported from PCH.
 
   // Implicit decl from a PCH was defined.
@@ -4075,7 +4075,7 @@ void ASTWriter::CompletedImplicitDefinition(const FunctionDecl *D) {
 }
 
 void ASTWriter::StaticDataMemberInstantiated(const VarDecl *D) {
-  if (D->getPCHLevel() == 0)
+  if (!D->isFromASTFile())
     return;
 
   // Since the actual instantiation is delayed, this really means that we need
@@ -4088,10 +4088,10 @@ void ASTWriter::StaticDataMemberInstantiated(const VarDecl *D) {
 
 void ASTWriter::AddedObjCCategoryToInterface(const ObjCCategoryDecl *CatD,
                                              const ObjCInterfaceDecl *IFD) {
-  if (IFD->getPCHLevel() == 0)
+  if (!IFD->isFromASTFile())
     return; // Declaration not imported from PCH.
   if (CatD->getNextClassCategory() &&
-      CatD->getNextClassCategory()->getPCHLevel() == 0)
+      !CatD->getNextClassCategory()->isFromASTFile())
     return; // We already recorded that the tail of a category chain should be
             // attached to an interface.
 
index d94f783aa96f7e2e17b22b0c5157ed344b4cc6db..1192c308724c3640b6eb3b233a21f7743f711722 100644 (file)
@@ -155,7 +155,7 @@ void ASTDeclWriter::VisitDecl(Decl *D) {
   Record.push_back(D->isUsed(false));
   Record.push_back(D->isReferenced());
   Record.push_back(D->getAccess());
-  Record.push_back(D->getPCHLevel());
+  Record.push_back(D->PCHLevel);
   Record.push_back(D->ModulePrivate);
 }
 
@@ -181,7 +181,7 @@ void ASTDeclWriter::VisitTypedefDecl(TypedefDecl *D) {
   if (!D->hasAttrs() &&
       !D->isImplicit() &&
       !D->isUsed(false) &&
-      D->getPCHLevel() == 0 &&
+      !D->isFromASTFile() &&
       D->RedeclLink.getNext() == D &&
       !D->isInvalidDecl() &&
       !D->isReferenced() &&
@@ -230,7 +230,7 @@ void ASTDeclWriter::VisitEnumDecl(EnumDecl *D) {
   if (!D->hasAttrs() &&
       !D->isImplicit() &&
       !D->isUsed(false) &&
-      D->getPCHLevel() == 0 &&
+      !D->isFromASTFile() &&
       !D->hasExtInfo() &&
       D->RedeclLink.getNext() == D &&
       !D->isInvalidDecl() &&
@@ -254,7 +254,7 @@ void ASTDeclWriter::VisitRecordDecl(RecordDecl *D) {
   if (!D->hasAttrs() &&
       !D->isImplicit() &&
       !D->isUsed(false) &&
-      D->getPCHLevel() == 0 &&
+      !D->isFromASTFile() &&
       !D->hasExtInfo() &&
       D->RedeclLink.getNext() == D &&
       !D->isInvalidDecl() &&
@@ -476,7 +476,7 @@ void ASTDeclWriter::VisitObjCIvarDecl(ObjCIvarDecl *D) {
       !D->isUsed(false) &&
       !D->isInvalidDecl() &&
       !D->isReferenced() &&
-      D->getPCHLevel() == 0 &&
+      !D->isFromASTFile() &&
       !D->isModulePrivate() &&
       !D->getBitWidth() &&
       !D->hasExtInfo() &&
@@ -615,7 +615,7 @@ void ASTDeclWriter::VisitFieldDecl(FieldDecl *D) {
       !D->isUsed(false) &&
       !D->isInvalidDecl() &&
       !D->isReferenced() &&
-      D->getPCHLevel() == 0 &&
+      !D->isFromASTFile() &&
       !D->isModulePrivate() &&
       !D->getBitWidth() &&
       !D->hasInClassInitializer() &&
@@ -670,7 +670,7 @@ void ASTDeclWriter::VisitVarDecl(VarDecl *D) {
       !D->isReferenced() &&
       D->getAccess() == AS_none &&
       !D->isModulePrivate() &&
-      D->getPCHLevel() == 0 &&
+      !D->isFromASTFile() &&
       D->getDeclName().getNameKind() == DeclarationName::Identifier &&
       !D->hasExtInfo() &&
       D->RedeclLink.getNext() == D &&
@@ -712,7 +712,7 @@ void ASTDeclWriter::VisitParmVarDecl(ParmVarDecl *D) {
       !D->isUsed(false) &&
       D->getAccess() == AS_none &&
       !D->isModulePrivate() &&
-      D->getPCHLevel() == 0 &&
+      !D->isFromASTFile() &&
       D->getStorageClass() == 0 &&
       !D->hasCXXDirectInitializer() && // Can params have this ever?
       D->getFunctionScopeDepth() == 0 &&
@@ -799,7 +799,7 @@ void ASTDeclWriter::VisitNamespaceDecl(NamespaceDecl *D) {
   Code = serialization::DECL_NAMESPACE;
 
   if (Writer.hasChain() && !D->isOriginalNamespace() &&
-      D->getOriginalNamespace()->getPCHLevel() > 0) {
+      D->getOriginalNamespace()->isFromASTFile()) {
     NamespaceDecl *NS = D->getOriginalNamespace();
     Writer.AddUpdatedDeclContext(NS);
 
@@ -825,7 +825,7 @@ void ASTDeclWriter::VisitNamespaceDecl(NamespaceDecl *D) {
     // anonymous namespace.
     Decl *Parent = cast<Decl>(
         D->getParent()->getRedeclContext()->getPrimaryContext());
-    if (Parent->getPCHLevel() > 0 || isa<TranslationUnitDecl>(Parent)) {
+    if (Parent->isFromASTFile() || isa<TranslationUnitDecl>(Parent)) {
       ASTWriter::UpdateRecord &Record = Writer.DeclUpdates[Parent];
       Record.push_back(UPD_CXX_ADDED_ANONYMOUS_NAMESPACE);
       Writer.AddDeclRef(D, Record);