From 0bc8a21dba8731f186ee78607a5876c220f620e3 Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Sat, 14 Jan 2012 15:55:47 +0000 Subject: Introduce Decl::getPreviousDecl() and Decl::getMostRecentDecl(), virtual functions that provide previous/most recent redeclaration information for any declaration. Use this to eliminate the redundant, less efficient getPreviousDecl() functions. llvm-svn: 148184 --- clang/lib/Serialization/ASTReaderDecl.cpp | 44 ++----------------------------- 1 file changed, 2 insertions(+), 42 deletions(-) (limited to 'clang/lib/Serialization/ASTReaderDecl.cpp') diff --git a/clang/lib/Serialization/ASTReaderDecl.cpp b/clang/lib/Serialization/ASTReaderDecl.cpp index 21a0fb06a9c..94c3ef0a58d 100644 --- a/clang/lib/Serialization/ASTReaderDecl.cpp +++ b/clang/lib/Serialization/ASTReaderDecl.cpp @@ -2211,46 +2211,6 @@ namespace { }; } -/// \brief Retrieve the previous declaration to D. -static Decl *getPreviousDecl(Decl *D) { - if (TagDecl *TD = dyn_cast(D)) - return TD->getPreviousDeclaration(); - if (FunctionDecl *FD = dyn_cast(D)) - return FD->getPreviousDeclaration(); - if (VarDecl *VD = dyn_cast(D)) - return VD->getPreviousDeclaration(); - if (TypedefNameDecl *TD = dyn_cast(D)) - return TD->getPreviousDeclaration(); - if (ObjCInterfaceDecl *ID = dyn_cast(D)) - return ID->getPreviousDeclaration(); - if (ObjCProtocolDecl *PD = dyn_cast(D)) - return PD->getPreviousDeclaration(); - if (NamespaceDecl *ND = dyn_cast(D)) - return ND->getPreviousDeclaration(); - - return cast(D)->getPreviousDeclaration(); -} - -/// \brief Retrieve the most recent declaration of D. -static Decl *getMostRecentDecl(Decl *D) { - if (TagDecl *TD = dyn_cast(D)) - return TD->getMostRecentDeclaration(); - if (FunctionDecl *FD = dyn_cast(D)) - return FD->getMostRecentDeclaration(); - if (VarDecl *VD = dyn_cast(D)) - return VD->getMostRecentDeclaration(); - if (TypedefNameDecl *TD = dyn_cast(D)) - return TD->getMostRecentDeclaration(); - if (ObjCInterfaceDecl *ID = dyn_cast(D)) - return ID->getMostRecentDeclaration(); - if (ObjCProtocolDecl *PD = dyn_cast(D)) - return PD->getMostRecentDeclaration(); - if (NamespaceDecl *ND = dyn_cast(D)) - return ND->getMostRecentDeclaration(); - - return cast(D)->getMostRecentDeclaration(); -} - void ASTReader::loadPendingDeclChain(serialization::GlobalDeclID ID) { Decl *D = GetDecl(ID); Decl *CanonDecl = D->getCanonicalDecl(); @@ -2276,11 +2236,11 @@ void ASTReader::loadPendingDeclChain(serialization::GlobalDeclID ID) { return; // Capture all of the parsed declarations and put them at the end. - Decl *MostRecent = getMostRecentDecl(CanonDecl); + Decl *MostRecent = CanonDecl->getMostRecentDecl(); Decl *FirstParsed = MostRecent; if (CanonDecl != MostRecent && !MostRecent->isFromASTFile()) { Decl *Current = MostRecent; - while (Decl *Prev = getPreviousDecl(Current)) { + while (Decl *Prev = Current->getPreviousDecl()) { if (Prev == CanonDecl) break; -- cgit v1.2.3