r309813 - [rename] NFC, extract symbol canonicalization logic into function
Alex Lorenz via cfe-commits
cfe-commits at lists.llvm.org
Wed Aug 2 07:15:27 PDT 2017
Author: arphaman
Date: Wed Aug 2 07:15:27 2017
New Revision: 309813
URL: http://llvm.org/viewvc/llvm-project?rev=309813&view=rev
Log:
[rename] NFC, extract symbol canonicalization logic into function
This function will be used by the clang-refactor's rename actions
Modified:
cfe/trunk/include/clang/Tooling/Refactoring/Rename/USRFindingAction.h
cfe/trunk/lib/Tooling/Refactoring/Rename/USRFindingAction.cpp
Modified: cfe/trunk/include/clang/Tooling/Refactoring/Rename/USRFindingAction.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Tooling/Refactoring/Rename/USRFindingAction.h?rev=309813&r1=309812&r2=309813&view=diff
==============================================================================
--- cfe/trunk/include/clang/Tooling/Refactoring/Rename/USRFindingAction.h (original)
+++ cfe/trunk/include/clang/Tooling/Refactoring/Rename/USRFindingAction.h Wed Aug 2 07:15:27 2017
@@ -28,6 +28,15 @@ class NamedDecl;
namespace tooling {
+/// Returns the canonical declaration that best represents a symbol that can be
+/// renamed.
+///
+/// The following canonicalization rules are currently used:
+///
+/// - A constructor is canonicalized to its class.
+/// - A destructor is canonicalized to its class.
+const NamedDecl *getCanonicalSymbolDeclaration(const NamedDecl *FoundDecl);
+
struct USRFindingAction {
USRFindingAction(ArrayRef<unsigned> SymbolOffsets,
ArrayRef<std::string> QualifiedNames, bool Force)
Modified: cfe/trunk/lib/Tooling/Refactoring/Rename/USRFindingAction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Tooling/Refactoring/Rename/USRFindingAction.cpp?rev=309813&r1=309812&r2=309813&view=diff
==============================================================================
--- cfe/trunk/lib/Tooling/Refactoring/Rename/USRFindingAction.cpp (original)
+++ cfe/trunk/lib/Tooling/Refactoring/Rename/USRFindingAction.cpp Wed Aug 2 07:15:27 2017
@@ -39,6 +39,21 @@ using namespace llvm;
namespace clang {
namespace tooling {
+const NamedDecl *getCanonicalSymbolDeclaration(const NamedDecl *FoundDecl) {
+ // If FoundDecl is a constructor or destructor, we want to instead take
+ // the Decl of the corresponding class.
+ if (const auto *CtorDecl = dyn_cast<CXXConstructorDecl>(FoundDecl))
+ FoundDecl = CtorDecl->getParent();
+ else if (const auto *DtorDecl = dyn_cast<CXXDestructorDecl>(FoundDecl))
+ FoundDecl = DtorDecl->getParent();
+ // FIXME: (Alex L): Canonicalize implicit template instantions, just like
+ // the indexer does it.
+
+ // Note: please update the declaration's doc comment every time the
+ // canonicalization rules are changed.
+ return FoundDecl;
+}
+
namespace {
// \brief NamedDeclFindingConsumer should delegate finding USRs of given Decl to
// AdditionalUSRFinder. AdditionalUSRFinder adds USRs of ctor and dtor if given
@@ -193,13 +208,7 @@ private:
return false;
}
- // If FoundDecl is a constructor or destructor, we want to instead take
- // the Decl of the corresponding class.
- if (const auto *CtorDecl = dyn_cast<CXXConstructorDecl>(FoundDecl))
- FoundDecl = CtorDecl->getParent();
- else if (const auto *DtorDecl = dyn_cast<CXXDestructorDecl>(FoundDecl))
- FoundDecl = DtorDecl->getParent();
-
+ FoundDecl = getCanonicalSymbolDeclaration(FoundDecl);
SpellingNames.push_back(FoundDecl->getNameAsString());
AdditionalUSRFinder Finder(FoundDecl, Context);
USRList.push_back(Finder.Find());
More information about the cfe-commits
mailing list