]> granicus.if.org Git - clang/commitdiff
Implement FunctionDecl::getDefinition() to be consistent with
authorYaron Keren <yaron.keren@gmail.com>
Wed, 13 Jul 2016 19:04:51 +0000 (19:04 +0000)
committerYaron Keren <yaron.keren@gmail.com>
Wed, 13 Jul 2016 19:04:51 +0000 (19:04 +0000)
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
lib/Sema/SemaDecl.cpp
lib/Sema/SemaLookup.cpp

index 97081ee6b9a2cb6f5995faab011ce1594b99cab8..db13e2597907510c4f8c6dee372e53efe371f7ae 100644 (file)
@@ -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
index 6f7a13d632237a3279360efa023992cad5a1367b..c0ccbbf62410334ef5b47890125b37ef088b9878 100644 (file)
@@ -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;
 }
 
index 9160a3f674136349a7796ab3946d731c3a4775ad..e2550824fb69be8de02087946a016e282b601473 100644 (file)
@@ -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))