From facf07a6d56461462dc3d8fff3b87e9d6295a098 Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Tue, 13 May 2014 01:15:00 +0000 Subject: [PATCH] Refactor to avoid explicitly listing all the different flavours of redeclarable declarations, and duplicating code between them. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@208662 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Serialization/ASTReaderDecl.cpp | 99 +++++++++++++---------------- 1 file changed, 43 insertions(+), 56 deletions(-) diff --git a/lib/Serialization/ASTReaderDecl.cpp b/lib/Serialization/ASTReaderDecl.cpp index a525f2f089..d2219d4981 100644 --- a/lib/Serialization/ASTReaderDecl.cpp +++ b/lib/Serialization/ASTReaderDecl.cpp @@ -198,7 +198,14 @@ namespace clang { RawLocation(RawLocation), Record(Record), Idx(Idx), TypeIDForTypeDecl(0), HasPendingBody(false) { } + template + static void attachPreviousDeclImpl(Redeclarable *D, Decl *Previous); + static void attachPreviousDeclImpl(...); static void attachPreviousDecl(Decl *D, Decl *previous); + + template + static void attachLatestDeclImpl(Redeclarable *D, Decl *Latest); + static void attachLatestDeclImpl(...); static void attachLatestDecl(Decl *D, Decl *latest); /// \brief Determine whether this declaration has a pending body. @@ -2449,27 +2456,25 @@ ASTDeclReader::FindExistingResult ASTDeclReader::findExisting(NamedDecl *D) { return FindExistingResult(Reader, D, /*Existing=*/0); } -void ASTDeclReader::attachPreviousDecl(Decl *D, Decl *previous) { - assert(D && previous); - if (TagDecl *TD = dyn_cast(D)) { - TD->RedeclLink.setNext(cast(previous)); - } else if (FunctionDecl *FD = dyn_cast(D)) { - FD->RedeclLink.setNext(cast(previous)); - } else if (VarDecl *VD = dyn_cast(D)) { - VD->RedeclLink.setNext(cast(previous)); - } else if (TypedefNameDecl *TD = dyn_cast(D)) { - TD->RedeclLink.setNext(cast(previous)); - } else if (UsingShadowDecl *USD = dyn_cast(D)) { - USD->RedeclLink.setNext(cast(previous)); - } else if (ObjCInterfaceDecl *ID = dyn_cast(D)) { - ID->RedeclLink.setNext(cast(previous)); - } else if (ObjCProtocolDecl *PD = dyn_cast(D)) { - PD->RedeclLink.setNext(cast(previous)); - } else if (NamespaceDecl *ND = dyn_cast(D)) { - ND->RedeclLink.setNext(cast(previous)); - } else { - RedeclarableTemplateDecl *TD = cast(D); - TD->RedeclLink.setNext(cast(previous)); +template +void ASTDeclReader::attachPreviousDeclImpl(Redeclarable *D, + Decl *Previous) { + D->RedeclLink.setNext(cast(Previous)); +} +void ASTDeclReader::attachPreviousDeclImpl(...) { + llvm_unreachable("attachPreviousDecl on non-redeclarable declaration"); +} + +void ASTDeclReader::attachPreviousDecl(Decl *D, Decl *Previous) { + assert(D && Previous); + + switch (D->getKind()) { +#define ABSTRACT_DECL(TYPE) +#define DECL(TYPE, BASE) \ + case Decl::TYPE: \ + attachPreviousDeclImpl(cast(D), Previous); \ + break; +#include "clang/AST/DeclNodes.inc" } // If the declaration was visible in one module, a redeclaration of it in @@ -2478,46 +2483,28 @@ void ASTDeclReader::attachPreviousDecl(Decl *D, Decl *previous) { // FIXME: In this case, the declaration should only be visible if a module // that makes it visible has been imported. D->IdentifierNamespace |= - previous->IdentifierNamespace & + Previous->IdentifierNamespace & (Decl::IDNS_Ordinary | Decl::IDNS_Tag | Decl::IDNS_Type); } +template +void ASTDeclReader::attachLatestDeclImpl(Redeclarable *D, Decl *Latest) { + D->RedeclLink = Redeclarable::LatestDeclLink(cast(Latest)); +} +void ASTDeclReader::attachLatestDeclImpl(...) { + llvm_unreachable("attachLatestDecl on non-redeclarable declaration"); +} + void ASTDeclReader::attachLatestDecl(Decl *D, Decl *Latest) { assert(D && Latest); - if (TagDecl *TD = dyn_cast(D)) { - TD->RedeclLink - = Redeclarable::LatestDeclLink(cast(Latest)); - } else if (FunctionDecl *FD = dyn_cast(D)) { - FD->RedeclLink - = Redeclarable::LatestDeclLink(cast(Latest)); - } else if (VarDecl *VD = dyn_cast(D)) { - VD->RedeclLink - = Redeclarable::LatestDeclLink(cast(Latest)); - } else if (TypedefNameDecl *TD = dyn_cast(D)) { - TD->RedeclLink - = Redeclarable::LatestDeclLink( - cast(Latest)); - } else if (UsingShadowDecl *USD = dyn_cast(D)) { - USD->RedeclLink - = Redeclarable::LatestDeclLink( - cast(Latest)); - } else if (ObjCInterfaceDecl *ID = dyn_cast(D)) { - ID->RedeclLink - = Redeclarable::LatestDeclLink( - cast(Latest)); - } else if (ObjCProtocolDecl *PD = dyn_cast(D)) { - PD->RedeclLink - = Redeclarable::LatestDeclLink( - cast(Latest)); - } else if (NamespaceDecl *ND = dyn_cast(D)) { - ND->RedeclLink - = Redeclarable::LatestDeclLink( - cast(Latest)); - } else { - RedeclarableTemplateDecl *TD = cast(D); - TD->RedeclLink - = Redeclarable::LatestDeclLink( - cast(Latest)); + + switch (D->getKind()) { +#define ABSTRACT_DECL(TYPE) +#define DECL(TYPE, BASE) \ + case Decl::TYPE: \ + attachLatestDeclImpl(cast(D), Latest); \ + break; +#include "clang/AST/DeclNodes.inc" } } -- 2.40.0