mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2025-02-14 14:56:47 +00:00
clang-rename: adjust NamedDeclFindingASTVisitor for RecordDecls
Ensure that Context is always properly initialised in the constructor. It is used for querying the LangOpts in VisitTypeLoc. Prevent a null pointer dereference in setResult by ensuring that a RecordDecl is being handled. Patch by Alexander Shaposhnikov! llvm-svn: 276948
This commit is contained in:
parent
2e46f720fa
commit
c67dd95697
@ -42,8 +42,9 @@ public:
|
|||||||
// \brief Finds the NamedDecl for a name in the source.
|
// \brief Finds the NamedDecl for a name in the source.
|
||||||
// \param Name the fully qualified name.
|
// \param Name the fully qualified name.
|
||||||
explicit NamedDeclFindingASTVisitor(const SourceManager &SourceMgr,
|
explicit NamedDeclFindingASTVisitor(const SourceManager &SourceMgr,
|
||||||
const std::string &Name)
|
const std::string &Name,
|
||||||
: Result(nullptr), SourceMgr(SourceMgr), Name(Name) {}
|
const ASTContext *Context)
|
||||||
|
: Result(nullptr), SourceMgr(SourceMgr), Name(Name), Context(Context) {}
|
||||||
|
|
||||||
// Declaration visitors:
|
// Declaration visitors:
|
||||||
|
|
||||||
@ -76,8 +77,9 @@ public:
|
|||||||
const auto TypeBeginLoc = Loc.getBeginLoc();
|
const auto TypeBeginLoc = Loc.getBeginLoc();
|
||||||
const auto TypeEndLoc = Lexer::getLocForEndOfToken(
|
const auto TypeEndLoc = Lexer::getLocForEndOfToken(
|
||||||
TypeBeginLoc, 0, SourceMgr, Context->getLangOpts());
|
TypeBeginLoc, 0, SourceMgr, Context->getLangOpts());
|
||||||
return setResult(Loc.getType()->getAsCXXRecordDecl(), TypeBeginLoc,
|
if (auto *RD = Loc.getType()->getAsCXXRecordDecl())
|
||||||
TypeEndLoc);
|
return setResult(RD, TypeBeginLoc, TypeEndLoc);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Other:
|
// Other:
|
||||||
@ -170,7 +172,7 @@ const NamedDecl *getNamedDeclAt(const ASTContext &Context,
|
|||||||
const NamedDecl *getNamedDeclFor(const ASTContext &Context,
|
const NamedDecl *getNamedDeclFor(const ASTContext &Context,
|
||||||
const std::string &Name) {
|
const std::string &Name) {
|
||||||
const auto &SourceMgr = Context.getSourceManager();
|
const auto &SourceMgr = Context.getSourceManager();
|
||||||
NamedDeclFindingASTVisitor Visitor(SourceMgr, Name);
|
NamedDeclFindingASTVisitor Visitor(SourceMgr, Name, &Context);
|
||||||
Visitor.TraverseDecl(Context.getTranslationUnitDecl());
|
Visitor.TraverseDecl(Context.getTranslationUnitDecl());
|
||||||
|
|
||||||
return Visitor.getNamedDecl();
|
return Visitor.getNamedDecl();
|
||||||
|
@ -0,0 +1,13 @@
|
|||||||
|
// RUN: clang-rename -old-name=Foo -new-name=Bar %s -- | FileCheck %s
|
||||||
|
|
||||||
|
void foo() {
|
||||||
|
}
|
||||||
|
|
||||||
|
class Foo { // CHECK: class Bar
|
||||||
|
};
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
Foo *Pointer = 0; // CHECK: Bar *Pointer = 0;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user