45 if (
const auto *CtorDecl = dyn_cast<CXXConstructorDecl>(FoundDecl))
46 FoundDecl = CtorDecl->getParent();
47 else if (
const auto *DtorDecl = dyn_cast<CXXDestructorDecl>(FoundDecl))
48 FoundDecl = DtorDecl->getParent();
65 : FoundDecl(FoundDecl), Context(Context) {}
67 std::vector<std::string> Find() {
70 if (
const auto *MethodDecl = dyn_cast<CXXMethodDecl>(FoundDecl)) {
71 addUSRsOfOverridenFunctions(MethodDecl);
72 for (
const auto &OverriddenMethod : OverriddenMethods) {
73 if (checkIfOverriddenFunctionAscends(OverriddenMethod))
76 addUSRsOfInstantiatedMethods(MethodDecl);
77 }
else if (
const auto *
RecordDecl = dyn_cast<CXXRecordDecl>(FoundDecl)) {
80 dyn_cast<ClassTemplateDecl>(FoundDecl)) {
85 return std::vector<std::string>(USRSet.begin(), USRSet.end());
88 bool shouldVisitTemplateInstantiations()
const {
return true; }
92 OverriddenMethods.push_back(MethodDecl);
94 InstantiatedMethods.push_back(MethodDecl);
98 bool VisitClassTemplatePartialSpecializationDecl(
100 PartialSpecs.push_back(PartialSpec);
107 if (
const auto *ClassTemplateSpecDecl =
108 dyn_cast<ClassTemplateSpecializationDecl>(RecordDecl))
109 handleClassTemplateDecl(ClassTemplateSpecDecl->getSpecializedTemplate());
110 addUSRsOfCtorDtors(RecordDecl);
115 addUSRsOfCtorDtors(Specialization);
117 for (
const auto *PartialSpec : PartialSpecs) {
119 addUSRsOfCtorDtors(PartialSpec);
131 for (
const auto *CtorDecl : RecordDecl->
ctors())
138 void addUSRsOfOverridenFunctions(
const CXXMethodDecl *MethodDecl) {
142 addUSRsOfOverridenFunctions(OverriddenMethod);
145 void addUSRsOfInstantiatedMethods(
const CXXMethodDecl *MethodDecl) {
152 for (
const auto *Method : InstantiatedMethods) {
154 Method->getInstantiatedFromMemberFunction())) != USRSet.end())
159 bool checkIfOverriddenFunctionAscends(
const CXXMethodDecl *MethodDecl) {
161 if (USRSet.find(
getUSRForDecl(OverriddenMethod)) != USRSet.end())
163 return checkIfOverriddenFunctionAscends(OverriddenMethod);
168 const Decl *FoundDecl;
170 std::set<std::string> USRSet;
171 std::vector<const CXXMethodDecl *> OverriddenMethods;
172 std::vector<const CXXMethodDecl *> InstantiatedMethods;
173 std::vector<const ClassTemplatePartialSpecializationDecl *> PartialSpecs;
179 AdditionalUSRFinder Finder(ND, Context);
180 return Finder.Find();
187 std::vector<std::string> &SpellingNames,
188 std::vector<std::vector<std::string>> &USRList,
189 bool Force,
bool &ErrorOccurred)
190 : SymbolOffsets(SymbolOffsets), QualifiedNames(QualifiedNames),
191 SpellingNames(SpellingNames), USRList(USRList), Force(Force),
192 ErrorOccurred(ErrorOccurred) {}
196 unsigned SymbolOffset,
const std::string &QualifiedName) {
201 ErrorOccurred =
true;
204 "SourceLocation in file %0 at offset %1 is invalid");
212 const NamedDecl *FoundDecl = QualifiedName.empty()
216 if (FoundDecl ==
nullptr) {
217 if (QualifiedName.empty()) {
221 "clang-rename could not find symbol (offset %0)");
222 Engine.
Report(Point, CouldNotFindSymbolAt) << SymbolOffset;
223 ErrorOccurred =
true;
228 SpellingNames.push_back(std::string());
229 USRList.push_back(std::vector<std::string>());
235 Engine.
Report(CouldNotFindSymbolNamed) << QualifiedName;
236 ErrorOccurred =
true;
242 AdditionalUSRFinder Finder(FoundDecl, Context);
243 USRList.push_back(Finder.Find());
247 void HandleTranslationUnit(
ASTContext &Context)
override {
249 for (
unsigned Offset : SymbolOffsets) {
250 if (!FindSymbol(Context, SourceMgr,
Offset,
""))
253 for (
const std::string &QualifiedName : QualifiedNames) {
254 if (!FindSymbol(Context, SourceMgr, 0, QualifiedName))
261 std::vector<std::string> &SpellingNames;
262 std::vector<std::vector<std::string>> &USRList;
267 std::unique_ptr<ASTConsumer> USRFindingAction::newASTConsumer() {
268 return llvm::make_unique<NamedDeclFindingConsumer>(
269 SymbolOffsets, QualifiedNames, SpellingNames, USRList, Force,
SourceLocation getLocForStartOfFile(FileID FID) const
Return the source location corresponding to the first byte of the specified file. ...
Defines the clang::ASTContext interface.
SourceLocation getLocWithOffset(int Offset) const
Return a source location with the specified offset from this SourceLocation.
ASTConsumer - This is an abstract interface that should be implemented by clients that read ASTs...
Defines the clang::FileManager interface and associated types.
DominatorTree GraphTraits specialization so the DominatorTree can be iterable by generic graph iterat...
spec_range specializations() const
Decl - This represents one declaration (or definition), e.g.
DiagnosticsEngine & getDiagnostics() const
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
Represents a struct/union/class.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Concrete class used by the front-end to report problems and issues.
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.
FunctionDecl * getInstantiatedFromMemberFunction() const
If this function is an instantiation of a member function of a class template specialization, retrieves the function from which it was instantiated.
A class that does preorder or postorder depth-first traversal on the entire Clang AST and visits each...
CXXDestructorDecl * getDestructor() const
Returns the destructor decl for this class.
CXXRecordDecl * getTemplatedDecl() const
Get the underlying class declarations of the template.
unsigned getFileIDSize(FileID FID) const
The size of the SLocEntry that FID represents.
const FileEntry * getFileEntryForID(FileID FID) const
Returns the FileEntry record for the provided FileID.
Defines the clang::Preprocessor interface.
ClassTemplateDecl * getSpecializedTemplate() const
Retrieve the template that this specialization specializes.
overridden_method_range overridden_methods() const
CXXRecordDecl * getDefinition() const
Encodes a location in the source.
StringRef getName() const
std::string getNameAsString() const
Get a human-readable name for the declaration, even if it is one of the special kinds of names (C++ c...
Represents a static or instance method of a struct/union/class.
unsigned getCustomDiagID(Level L, const char(&FormatString)[N])
Return an ID for a diagnostic with the specified format string and level.
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
Dataflow Directional Tag Classes.
The base class of all kinds of template declarations (e.g., class, function, etc.).
FileID getMainFileID() const
Returns the FileID of the main source file.
SourceManager & getSourceManager()
TranslationUnitDecl * getTranslationUnitDecl() const
Represents a C++ struct/union/class.
Declaration of a class template.
A SourceLocation and its associated SourceManager.
Defines the clang::FrontendAction interface and various convenience abstract classes (clang::ASTFront...
This represents a decl that may have a name.
This class handles loading and caching of source files into memory.