17 #include "clang/AST/AST.h"
18 #include "clang/AST/ASTConsumer.h"
19 #include "clang/AST/ASTContext.h"
20 #include "clang/Basic/FileManager.h"
21 #include "clang/Frontend/CompilerInstance.h"
22 #include "clang/Frontend/FrontendAction.h"
23 #include "clang/Lex/Lexer.h"
24 #include "clang/Lex/Preprocessor.h"
25 #include "clang/Tooling/CommonOptionsParser.h"
26 #include "clang/Tooling/Refactoring.h"
27 #include "clang/Tooling/Tooling.h"
38 const CXXRecordDecl *Decl) {
39 std::vector<std::string> USRs;
43 const auto *RecordDecl = Decl->getDefinition();
46 for (
const auto *CtorDecl : RecordDecl->ctors())
65 const auto &
SourceMgr = Context.getSourceManager();
71 const NamedDecl *FoundDecl =
nullptr;
77 if (FoundDecl ==
nullptr) {
79 errs() <<
"clang-rename: could not find symbol at "
81 << FullLoc.getSpellingLineNumber() <<
":"
82 << FullLoc.getSpellingColumnNumber() <<
" (offset " <<
SymbolOffset
89 if (
const auto *CtorDecl = dyn_cast<CXXConstructorDecl>(FoundDecl))
90 FoundDecl = CtorDecl->getParent();
91 else if (
const auto *DtorDecl = dyn_cast<CXXDestructorDecl>(FoundDecl))
92 FoundDecl = DtorDecl->getParent();
96 if (
const auto *Record = dyn_cast<CXXRecordDecl>(FoundDecl))
100 *SpellingName = FoundDecl->getNameAsString();
106 std::vector<std::string> *
USRs;
109 std::unique_ptr<ASTConsumer>
110 USRFindingAction::newASTConsumer() {
111 std::unique_ptr<NamedDeclFindingConsumer> Consumer(
116 Consumer->USRs = &USRs;
117 Consumer->SpellingName = &SpellingName;
118 return std::move(Consumer);
const SourceLocation Point
std::string * SpellingName
const NamedDecl * getNamedDeclAt(const ASTContext &Context, const SourceLocation Point)
std::string getUSRForDecl(const Decl *Decl)
Provides an action to find all relevant USRs at a point.
Methods for determining the USR of a symbol at a location in source code.
void HandleTranslationUnit(ASTContext &Context) override
std::vector< std::string > * USRs
const NamedDecl * getNamedDeclFor(const ASTContext &Context, const std::string &Name)
static cl::opt< unsigned > SymbolOffset("offset", cl::desc("Locates the symbol by offset as opposed to <line>:<column>."), cl::cat(ClangRenameCategory))
static cl::opt< std::string > OldName("old-name", cl::desc("The fully qualified name of the symbol, if -offset is not used."), cl::cat(ClangRenameCategory))
static std::vector< std::string > getAllConstructorUSRs(const CXXRecordDecl *Decl)
ClangTidyContext & Context