r275303 - Implement FunctionDecl::getDefinition() to be consistent with

Yaron Keren via cfe-commits cfe-commits at lists.llvm.org
Wed Jul 13 12:04:51 PDT 2016


Author: yrnkrn
Date: Wed Jul 13 14:04:51 2016
New Revision: 275303

URL: http://llvm.org/viewvc/llvm-project?rev=275303&view=rev
Log:
Implement FunctionDecl::getDefinition() to be consistent with
VarDecl, TagDecl, EnumDecl, RecordDecl, CXXRecordDecl.

Use getDefinition in two locations to make the code more readable.


Modified:
    cfe/trunk/include/clang/AST/Decl.h
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/lib/Sema/SemaLookup.cpp

Modified: cfe/trunk/include/clang/AST/Decl.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=275303&r1=275302&r2=275303&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/trunk/include/clang/AST/Decl.h Wed Jul 13 14:04:51 2016
@@ -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

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=275303&r1=275302&r2=275303&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Wed Jul 13 14:04:51 2016
@@ -2327,11 +2327,8 @@ static const Decl *getDefinition(const 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;
 }
 

Modified: cfe/trunk/lib/Sema/SemaLookup.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaLookup.cpp?rev=275303&r1=275302&r2=275303&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaLookup.cpp (original)
+++ cfe/trunk/lib/Sema/SemaLookup.cpp Wed Jul 13 14:04:51 2016
@@ -4936,8 +4936,8 @@ void Sema::diagnoseTypo(const TypoCorrec
 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))




More information about the cfe-commits mailing list