From 4e226ee7fb59b908b5840f5b767916b6b7656add Mon Sep 17 00:00:00 2001 From: Yaron Keren Date: Wed, 13 Jul 2016 19:04:51 +0000 Subject: [PATCH] Implement FunctionDecl::getDefinition() to be consistent with VarDecl, TagDecl, EnumDecl, RecordDecl, CXXRecordDecl. Use getDefinition in two locations to make the code more readable. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@275303 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/AST/Decl.h | 11 +++++++++++ lib/Sema/SemaDecl.cpp | 7 ++----- lib/Sema/SemaLookup.cpp | 4 ++-- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/include/clang/AST/Decl.h b/include/clang/AST/Decl.h index 97081ee6b9..db13e25979 100644 --- a/include/clang/AST/Decl.h +++ b/include/clang/AST/Decl.h @@ -1780,6 +1780,17 @@ public: return isDefined(Definition); } + /// \brief Get the definition for this declaration. + FunctionDecl *getDefinition() { + const FunctionDecl *Definition; + if (isDefined(Definition)) + return const_cast(Definition); + return nullptr; + } + const FunctionDecl *getDefinition() const { + return const_cast(this)->getDefinition(); + } + /// getBody - Retrieve the body (definition) of the function. The /// function body might be in any of the (re-)declarations of this /// function. The variant that accepts a FunctionDecl pointer will diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 6f7a13d632..c0ccbbf624 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -2327,11 +2327,8 @@ static const Decl *getDefinition(const Decl *D) { return Def; return VD->getActingDefinition(); } - if (const FunctionDecl *FD = dyn_cast(D)) { - const FunctionDecl* Def; - if (FD->isDefined(Def)) - return Def; - } + if (const FunctionDecl *FD = dyn_cast(D)) + return FD->getDefinition(); return nullptr; } diff --git a/lib/Sema/SemaLookup.cpp b/lib/Sema/SemaLookup.cpp index 9160a3f674..e2550824fb 100644 --- a/lib/Sema/SemaLookup.cpp +++ b/lib/Sema/SemaLookup.cpp @@ -4936,8 +4936,8 @@ void Sema::diagnoseTypo(const TypoCorrection &Correction, static NamedDecl *getDefinitionToImport(NamedDecl *D) { if (VarDecl *VD = dyn_cast(D)) return VD->getDefinition(); - if (const FunctionDecl *FD = dyn_cast(D)) - return FD->isDefined(FD) ? const_cast(FD) : nullptr; + if (FunctionDecl *FD = dyn_cast(D)) + return FD->getDefinition(); if (TagDecl *TD = dyn_cast(D)) return TD->getDefinition(); if (ObjCInterfaceDecl *ID = dyn_cast(D)) -- 2.40.0