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"
41 const CXXRecordDecl *Decl) {
42 std::vector<std::string> USRs;
46 const auto *RecordDecl = Decl->getDefinition();
49 for (
const auto *CtorDecl : RecordDecl->ctors())
68 const auto &
SourceMgr = Context.getSourceManager();
75 if (FoundDecl ==
nullptr) {
77 errs() <<
"clang-rename: could not find symbol at "
79 << FullLoc.getSpellingLineNumber() <<
":"
80 << FullLoc.getSpellingColumnNumber() <<
" (offset " <<
SymbolOffset
87 if (
const auto *CtorDecl = dyn_cast<CXXConstructorDecl>(FoundDecl))
88 FoundDecl = CtorDecl->getParent();
89 else if (
const auto *DtorDecl = dyn_cast<CXXDestructorDecl>(FoundDecl))
90 FoundDecl = DtorDecl->getParent();
94 if (
const auto *Record = dyn_cast<CXXRecordDecl>(FoundDecl))
98 *SpellingName = FoundDecl->getNameAsString();
103 std::vector<std::string> *
USRs;
106 std::unique_ptr<ASTConsumer>
107 USRFindingAction::newASTConsumer() {
108 std::unique_ptr<NamedDeclFindingConsumer> Consumer(
112 Consumer->USRs = &USRs;
113 Consumer->SpellingName = &SpellingName;
114 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 relevent 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
static cl::opt< unsigned > SymbolOffset("offset", cl::desc("Locates the symbol by offset as opposed to <line>:<column>."), cl::cat(ClangRenameCategory))
static std::vector< std::string > getAllConstructorUSRs(const CXXRecordDecl *Decl)
ClangTidyContext & Context