[PATCH] D68322: [clang-rename] Better renaming the typedef decl.
Haojian Wu via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Oct 2 01:12:22 PDT 2019
hokein created this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
when renaming a typedef decl, we used to rename the underlying decl of the
typedef, we should rename the typedef itself.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D68322
Files:
clang/include/clang/Tooling/Refactoring/RecursiveSymbolVisitor.h
clang/test/clang-rename/Typedef.cpp
Index: clang/test/clang-rename/Typedef.cpp
===================================================================
--- /dev/null
+++ clang/test/clang-rename/Typedef.cpp
@@ -0,0 +1,8 @@
+namespace std {
+class basic_string {};
+typedef basic_string string;
+} // namespace std
+
+std::string foo(); // // CHECK: std::new_string foo();
+
+// RUN: clang-rename -offset=93 -new-name=new_string %s -- | sed 's,//.*,,' | FileCheck %s
Index: clang/include/clang/Tooling/Refactoring/RecursiveSymbolVisitor.h
===================================================================
--- clang/include/clang/Tooling/Refactoring/RecursiveSymbolVisitor.h
+++ clang/include/clang/Tooling/Refactoring/RecursiveSymbolVisitor.h
@@ -98,7 +98,17 @@
TypeBeginLoc, TypeEndLoc))
return false;
}
- return visit(Loc.getType()->getAsCXXRecordDecl(), TypeBeginLoc, TypeEndLoc);
+ if (const Type *TP = Loc.getTypePtr()) {
+ if (TP->getTypeClass() == clang::Type::Record)
+ return visit(TP->getAsCXXRecordDecl(), TypeBeginLoc, TypeEndLoc);
+ }
+ return true;
+ }
+
+ bool VisitTypedefTypeLoc(TypedefTypeLoc TL) {
+ const SourceLocation TypeEndLoc =
+ Lexer::getLocForEndOfToken(TL.getBeginLoc(), 0, SM, LangOpts);
+ return visit(TL.getTypedefNameDecl(), TL.getBeginLoc(), TypeEndLoc);
}
bool TraverseNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D68322.222765.patch
Type: text/x-patch
Size: 1397 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20191002/e0028642/attachment.bin>
More information about the cfe-commits
mailing list