diff options
| author | Yaron Keren <yaron.keren@gmail.com> | 2016-07-13 19:04:51 +0000 |
|---|---|---|
| committer | Yaron Keren <yaron.keren@gmail.com> | 2016-07-13 19:04:51 +0000 |
| commit | 18c3d0674e4ac0f821a4cf6f9257e7523fd0773b (patch) | |
| tree | 1c3943a10b3cb091b277895048ea4989ed5c834d | |
| parent | eff2aa70fc4cbe49afd17745be24c0f882e673e2 (diff) | |
| download | bcm5719-llvm-18c3d0674e4ac0f821a4cf6f9257e7523fd0773b.tar.gz bcm5719-llvm-18c3d0674e4ac0f821a4cf6f9257e7523fd0773b.zip | |
Implement FunctionDecl::getDefinition() to be consistent with
VarDecl, TagDecl, EnumDecl, RecordDecl, CXXRecordDecl.
Use getDefinition in two locations to make the code more readable.
llvm-svn: 275303
| -rw-r--r-- | clang/include/clang/AST/Decl.h | 11 | ||||
| -rw-r--r-- | clang/lib/Sema/SemaDecl.cpp | 7 | ||||
| -rw-r--r-- | clang/lib/Sema/SemaLookup.cpp | 4 |
3 files changed, 15 insertions, 7 deletions
diff --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h index 97081ee6b9a..db13e259790 100644 --- a/clang/include/clang/AST/Decl.h +++ b/clang/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<FunctionDecl *>(Definition); + return nullptr; + } + const FunctionDecl *getDefinition() const { + return const_cast<FunctionDecl *>(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/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 6f7a13d6322..c0ccbbf6241 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/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<FunctionDecl>(D)) { - const FunctionDecl* Def; - if (FD->isDefined(Def)) - return Def; - } + if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) + return FD->getDefinition(); return nullptr; } diff --git a/clang/lib/Sema/SemaLookup.cpp b/clang/lib/Sema/SemaLookup.cpp index 9160a3f6741..e2550824fb6 100644 --- a/clang/lib/Sema/SemaLookup.cpp +++ b/clang/lib/Sema/SemaLookup.cpp @@ -4936,8 +4936,8 @@ void Sema::diagnoseTypo(const TypoCorrection &Correction, static NamedDecl *getDefinitionToImport(NamedDecl *D) { if (VarDecl *VD = dyn_cast<VarDecl>(D)) return VD->getDefinition(); - if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) - return FD->isDefined(FD) ? const_cast<FunctionDecl*>(FD) : nullptr; + if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) + return FD->getDefinition(); if (TagDecl *TD = dyn_cast<TagDecl>(D)) return TD->getDefinition(); if (ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(D)) |

