44 if (
const auto *CtorDecl = dyn_cast<CXXConstructorDecl>(FoundDecl))
45 FoundDecl = CtorDecl->getParent();
46 else if (
const auto *DtorDecl = dyn_cast<CXXDestructorDecl>(FoundDecl))
47 FoundDecl = DtorDecl->getParent();
64 : FoundDecl(FoundDecl), Context(Context) {}
66 std::vector<std::string> Find() {
69 if (
const auto *MethodDecl = dyn_cast<CXXMethodDecl>(FoundDecl)) {
70 addUSRsOfOverridenFunctions(MethodDecl);
71 for (
const auto &OverriddenMethod : OverriddenMethods) {
72 if (checkIfOverriddenFunctionAscends(OverriddenMethod))
75 addUSRsOfInstantiatedMethods(MethodDecl);
76 }
else if (
const auto *
RecordDecl = dyn_cast<CXXRecordDecl>(FoundDecl)) {
79 dyn_cast<ClassTemplateDecl>(FoundDecl)) {
84 return std::vector<std::string>(USRSet.begin(), USRSet.end());
87 bool shouldVisitTemplateInstantiations()
const {
return true; }
91 OverriddenMethods.push_back(MethodDecl);
93 InstantiatedMethods.push_back(MethodDecl);
97 bool VisitClassTemplatePartialSpecializationDecl(
99 PartialSpecs.push_back(PartialSpec);
106 if (
const auto *ClassTemplateSpecDecl =
107 dyn_cast<ClassTemplateSpecializationDecl>(RecordDecl))
108 handleClassTemplateDecl(ClassTemplateSpecDecl->getSpecializedTemplate());
109 addUSRsOfCtorDtors(RecordDecl);
114 addUSRsOfCtorDtors(Specialization);
116 for (
const auto *PartialSpec : PartialSpecs) {
118 addUSRsOfCtorDtors(PartialSpec);
130 for (
const auto *CtorDecl : RecordDecl->
ctors())
137 void addUSRsOfOverridenFunctions(
const CXXMethodDecl *MethodDecl) {
141 addUSRsOfOverridenFunctions(OverriddenMethod);
144 void addUSRsOfInstantiatedMethods(
const CXXMethodDecl *MethodDecl) {
151 for (
const auto *Method : InstantiatedMethods) {
153 Method->getInstantiatedFromMemberFunction())) != USRSet.end())
158 bool checkIfOverriddenFunctionAscends(
const CXXMethodDecl *MethodDecl) {
160 if (USRSet.find(
getUSRForDecl(OverriddenMethod)) != USRSet.end())
162 return checkIfOverriddenFunctionAscends(OverriddenMethod);
167 const Decl *FoundDecl;
169 std::set<std::string> USRSet;
170 std::vector<const CXXMethodDecl *> OverriddenMethods;
171 std::vector<const CXXMethodDecl *> InstantiatedMethods;
172 std::vector<const ClassTemplatePartialSpecializationDecl *> PartialSpecs;
178 AdditionalUSRFinder Finder(ND, Context);
179 return Finder.Find();
186 std::vector<std::string> &SpellingNames,
187 std::vector<std::vector<std::string>> &USRList,
188 bool Force,
bool &ErrorOccurred)
189 : SymbolOffsets(SymbolOffsets), QualifiedNames(QualifiedNames),
190 SpellingNames(SpellingNames), USRList(USRList), Force(Force),
191 ErrorOccurred(ErrorOccurred) {}
195 unsigned SymbolOffset,
const std::string &QualifiedName) {
200 ErrorOccurred =
true;
203 "SourceLocation in file %0 at offset %1 is invalid");
211 const NamedDecl *FoundDecl = QualifiedName.empty()
215 if (FoundDecl ==
nullptr) {
216 if (QualifiedName.empty()) {
220 "clang-rename could not find symbol (offset %0)");
221 Engine.
Report(Point, CouldNotFindSymbolAt) << SymbolOffset;
222 ErrorOccurred =
true;
227 SpellingNames.push_back(std::string());
228 USRList.push_back(std::vector<std::string>());
234 Engine.
Report(CouldNotFindSymbolNamed) << QualifiedName;
235 ErrorOccurred =
true;
241 AdditionalUSRFinder Finder(FoundDecl, Context);
242 USRList.push_back(Finder.Find());
246 void HandleTranslationUnit(
ASTContext &Context)
override {
248 for (
unsigned Offset : SymbolOffsets) {
249 if (!FindSymbol(Context, SourceMgr,
Offset,
""))
252 for (
const std::string &QualifiedName : QualifiedNames) {
253 if (!FindSymbol(Context, SourceMgr, 0, QualifiedName))
260 std::vector<std::string> &SpellingNames;
261 std::vector<std::vector<std::string>> &USRList;
266 std::unique_ptr<ASTConsumer> USRFindingAction::newASTConsumer() {
267 return llvm::make_unique<NamedDeclFindingConsumer>(
268 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.
Specialize PointerLikeTypeTraits to allow LazyGenerationalUpdatePtr to be placed into a PointerUnion...
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.