46 if (
const auto *CtorDecl = dyn_cast<CXXConstructorDecl>(FoundDecl))
47 FoundDecl = CtorDecl->getParent();
48 else if (
const auto *DtorDecl = dyn_cast<CXXDestructorDecl>(FoundDecl))
49 FoundDecl = DtorDecl->getParent();
66 : FoundDecl(FoundDecl), Context(Context) {}
68 std::vector<std::string> Find() {
71 if (
const auto *MethodDecl = dyn_cast<CXXMethodDecl>(FoundDecl)) {
72 addUSRsOfOverridenFunctions(MethodDecl);
73 for (
const auto &OverriddenMethod : OverriddenMethods) {
74 if (checkIfOverriddenFunctionAscends(OverriddenMethod))
77 addUSRsOfInstantiatedMethods(MethodDecl);
78 }
else if (
const auto *
RecordDecl = dyn_cast<CXXRecordDecl>(FoundDecl)) {
81 dyn_cast<ClassTemplateDecl>(FoundDecl)) {
86 return std::vector<std::string>(USRSet.begin(), USRSet.end());
89 bool shouldVisitTemplateInstantiations()
const {
return true; }
93 OverriddenMethods.push_back(MethodDecl);
95 InstantiatedMethods.push_back(MethodDecl);
99 bool VisitClassTemplatePartialSpecializationDecl(
101 PartialSpecs.push_back(PartialSpec);
112 if (
const auto *ClassTemplateSpecDecl =
113 dyn_cast<ClassTemplateSpecializationDecl>(RecordDecl))
114 handleClassTemplateDecl(ClassTemplateSpecDecl->getSpecializedTemplate());
115 addUSRsOfCtorDtors(RecordDecl);
120 addUSRsOfCtorDtors(Specialization);
122 for (
const auto *PartialSpec : PartialSpecs) {
124 addUSRsOfCtorDtors(PartialSpec);
136 for (
const auto *CtorDecl : RecordDecl->
ctors())
143 void addUSRsOfOverridenFunctions(
const CXXMethodDecl *MethodDecl) {
147 addUSRsOfOverridenFunctions(OverriddenMethod);
150 void addUSRsOfInstantiatedMethods(
const CXXMethodDecl *MethodDecl) {
157 for (
const auto *Method : InstantiatedMethods) {
159 Method->getInstantiatedFromMemberFunction())) != USRSet.end())
164 bool checkIfOverriddenFunctionAscends(
const CXXMethodDecl *MethodDecl) {
166 if (USRSet.find(
getUSRForDecl(OverriddenMethod)) != USRSet.end())
168 return checkIfOverriddenFunctionAscends(OverriddenMethod);
173 const Decl *FoundDecl;
175 std::set<std::string> USRSet;
176 std::vector<const CXXMethodDecl *> OverriddenMethods;
177 std::vector<const CXXMethodDecl *> InstantiatedMethods;
178 std::vector<const ClassTemplatePartialSpecializationDecl *> PartialSpecs;
184 AdditionalUSRFinder Finder(ND, Context);
185 return Finder.Find();
192 std::vector<std::string> &SpellingNames,
193 std::vector<std::vector<std::string>> &USRList,
194 bool Force,
bool &ErrorOccurred)
195 : SymbolOffsets(SymbolOffsets), QualifiedNames(QualifiedNames),
196 SpellingNames(SpellingNames), USRList(USRList), Force(Force),
197 ErrorOccurred(ErrorOccurred) {}
201 unsigned SymbolOffset,
const std::string &QualifiedName) {
206 ErrorOccurred =
true;
209 "SourceLocation in file %0 at offset %1 is invalid");
217 const NamedDecl *FoundDecl = QualifiedName.empty()
221 if (FoundDecl ==
nullptr) {
222 if (QualifiedName.empty()) {
226 "clang-rename could not find symbol (offset %0)");
227 Engine.
Report(Point, CouldNotFindSymbolAt) << SymbolOffset;
228 ErrorOccurred =
true;
233 SpellingNames.push_back(std::string());
234 USRList.push_back(std::vector<std::string>());
240 Engine.
Report(CouldNotFindSymbolNamed) << QualifiedName;
241 ErrorOccurred =
true;
247 AdditionalUSRFinder Finder(FoundDecl, Context);
248 USRList.push_back(Finder.Find());
252 void HandleTranslationUnit(
ASTContext &Context)
override {
254 for (
unsigned Offset : SymbolOffsets) {
255 if (!FindSymbol(Context, SourceMgr,
Offset,
""))
258 for (
const std::string &QualifiedName : QualifiedNames) {
259 if (!FindSymbol(Context, SourceMgr, 0, QualifiedName))
266 std::vector<std::string> &SpellingNames;
267 std::vector<std::vector<std::string>> &USRList;
272 std::unique_ptr<ASTConsumer> USRFindingAction::newASTConsumer() {
273 return std::make_unique<NamedDeclFindingConsumer>(
274 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()
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.