[llvm-branch-commits] [clang-tools-extra] 7af6a13 - [NFC] Switch up some dyn_cast calls
Nathan James via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Sat Jan 2 12:01:46 PST 2021
Author: Nathan James
Date: 2021-01-02T19:56:27Z
New Revision: 7af6a134508cd1c7f75c6e3441ce436f220f30a4
URL: https://github.com/llvm/llvm-project/commit/7af6a134508cd1c7f75c6e3441ce436f220f30a4
DIFF: https://github.com/llvm/llvm-project/commit/7af6a134508cd1c7f75c6e3441ce436f220f30a4.diff
LOG: [NFC] Switch up some dyn_cast calls
Added:
Modified:
clang-tools-extra/clangd/AST.cpp
clang-tools-extra/clangd/DumpAST.cpp
clang-tools-extra/clangd/FindTarget.cpp
clang-tools-extra/clangd/refactor/Rename.cpp
clang-tools-extra/clangd/refactor/tweaks/ExpandAutoType.cpp
clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp
clang-tools-extra/clangd/refactor/tweaks/RemoveUsingNamespace.cpp
clang-tools-extra/clangd/refactor/tweaks/SwapIfBranches.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/clangd/AST.cpp b/clang-tools-extra/clangd/AST.cpp
index c5f87af86319..39ab48843b28 100644
--- a/clang-tools-extra/clangd/AST.cpp
+++ b/clang-tools-extra/clangd/AST.cpp
@@ -367,7 +367,7 @@ class DeducedTypeVisitor : public RecursiveASTVisitor<DeducedTypeVisitor> {
// Loc of auto in return type (c++14).
auto CurLoc = D->getReturnTypeSourceRange().getBegin();
// Loc of "auto" in operator auto()
- if (CurLoc.isInvalid() && dyn_cast<CXXConversionDecl>(D))
+ if (CurLoc.isInvalid() && isa<CXXConversionDecl>(D))
CurLoc = D->getTypeSourceInfo()->getTypeLoc().getBeginLoc();
// Loc of "auto" in function with trailing return type (c++11).
if (CurLoc.isInvalid())
diff --git a/clang-tools-extra/clangd/DumpAST.cpp b/clang-tools-extra/clangd/DumpAST.cpp
index 12698b42ef3e..588bcfcf2424 100644
--- a/clang-tools-extra/clangd/DumpAST.cpp
+++ b/clang-tools-extra/clangd/DumpAST.cpp
@@ -242,9 +242,8 @@ class DumpVisitor : public RecursiveASTVisitor<DumpVisitor> {
return "const";
return "";
}
- if (isa<IntegerLiteral>(S) || isa<FloatingLiteral>(S) ||
- isa<FixedPointLiteral>(S) || isa<CharacterLiteral>(S) ||
- isa<ImaginaryLiteral>(S) || isa<CXXBoolLiteralExpr>(S))
+ if (isa<IntegerLiteral, FloatingLiteral, FixedPointLiteral,
+ CharacterLiteral, ImaginaryLiteral, CXXBoolLiteralExpr>(S))
return toString([&](raw_ostream &OS) {
S->printPretty(OS, nullptr, Ctx.getPrintingPolicy());
});
diff --git a/clang-tools-extra/clangd/FindTarget.cpp b/clang-tools-extra/clangd/FindTarget.cpp
index 3afd65522680..9a502a84e36f 100644
--- a/clang-tools-extra/clangd/FindTarget.cpp
+++ b/clang-tools-extra/clangd/FindTarget.cpp
@@ -843,7 +843,7 @@ llvm::SmallVector<ReferenceLoc> refInStmt(const Stmt *S) {
void VisitMemberExpr(const MemberExpr *E) {
// Skip destructor calls to avoid duplication: TypeLoc within will be
// visited separately.
- if (llvm::dyn_cast<CXXDestructorDecl>(E->getFoundDecl().getDecl()))
+ if (llvm::isa<CXXDestructorDecl>(E->getFoundDecl().getDecl()))
return;
Refs.push_back(ReferenceLoc{E->getQualifierLoc(),
E->getMemberNameInfo().getLoc(),
diff --git a/clang-tools-extra/clangd/refactor/Rename.cpp b/clang-tools-extra/clangd/refactor/Rename.cpp
index 8ed5811c88b2..d3c7da96a441 100644
--- a/clang-tools-extra/clangd/refactor/Rename.cpp
+++ b/clang-tools-extra/clangd/refactor/Rename.cpp
@@ -119,7 +119,7 @@ const NamedDecl *canonicalRenameDecl(const NamedDecl *D) {
// declaration.
while (Method->isVirtual() && Method->size_overridden_methods())
Method = *Method->overridden_methods().begin();
- return dyn_cast<NamedDecl>(Method->getCanonicalDecl());
+ return Method->getCanonicalDecl();
}
if (const auto *Function = dyn_cast<FunctionDecl>(D))
if (const FunctionTemplateDecl *Template = Function->getPrimaryTemplate())
diff --git a/clang-tools-extra/clangd/refactor/tweaks/ExpandAutoType.cpp b/clang-tools-extra/clangd/refactor/tweaks/ExpandAutoType.cpp
index c214695c5f07..cb87cc764bc3 100644
--- a/clang-tools-extra/clangd/refactor/tweaks/ExpandAutoType.cpp
+++ b/clang-tools-extra/clangd/refactor/tweaks/ExpandAutoType.cpp
@@ -111,7 +111,7 @@ Expected<Tweak::Effect> ExpandAutoType::apply(const Selection& Inputs) {
// if it's a lambda expression, return an error message
if (isa<RecordType>(*DeducedType) &&
- dyn_cast<RecordType>(*DeducedType)->getDecl()->isLambda()) {
+ cast<RecordType>(*DeducedType)->getDecl()->isLambda()) {
return error("Could not expand type of lambda expression");
}
diff --git a/clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp b/clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp
index bcf9bbe00f7c..c603861c3d69 100644
--- a/clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp
+++ b/clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp
@@ -79,7 +79,7 @@ computeReferencedDecls(const clang::Expr *Expr) {
}
};
FindDeclRefsVisitor Visitor;
- Visitor.TraverseStmt(const_cast<Stmt *>(dyn_cast<Stmt>(Expr)));
+ Visitor.TraverseStmt(const_cast<Stmt *>(cast<Stmt>(Expr)));
return Visitor.ReferencedDecls;
}
diff --git a/clang-tools-extra/clangd/refactor/tweaks/RemoveUsingNamespace.cpp b/clang-tools-extra/clangd/refactor/tweaks/RemoveUsingNamespace.cpp
index 25fab244e30c..344445d8605d 100644
--- a/clang-tools-extra/clangd/refactor/tweaks/RemoveUsingNamespace.cpp
+++ b/clang-tools-extra/clangd/refactor/tweaks/RemoveUsingNamespace.cpp
@@ -112,7 +112,7 @@ bool RemoveUsingNamespace::prepare(const Selection &Inputs) {
TargetDirective = CA->ASTNode.get<UsingDirectiveDecl>();
if (!TargetDirective)
return false;
- if (!dyn_cast<Decl>(TargetDirective->getDeclContext()))
+ if (!isa<Decl>(TargetDirective->getDeclContext()))
return false;
// FIXME: Unavailable for namespaces containing using-namespace decl.
// It is non-trivial to deal with cases where identifiers come from the inner
diff --git a/clang-tools-extra/clangd/refactor/tweaks/SwapIfBranches.cpp b/clang-tools-extra/clangd/refactor/tweaks/SwapIfBranches.cpp
index 976f68215581..f412a2670259 100644
--- a/clang-tools-extra/clangd/refactor/tweaks/SwapIfBranches.cpp
+++ b/clang-tools-extra/clangd/refactor/tweaks/SwapIfBranches.cpp
@@ -54,14 +54,14 @@ bool SwapIfBranches::prepare(const Selection &Inputs) {
for (const SelectionTree::Node *N = Inputs.ASTSelection.commonAncestor();
N && !If; N = N->Parent) {
// Stop once we hit a block, e.g. a lambda in the if condition.
- if (dyn_cast_or_null<CompoundStmt>(N->ASTNode.get<Stmt>()))
+ if (llvm::isa_and_nonnull<CompoundStmt>(N->ASTNode.get<Stmt>()))
return false;
If = dyn_cast_or_null<IfStmt>(N->ASTNode.get<Stmt>());
}
// avoid dealing with single-statement brances, they require careful handling
// to avoid changing semantics of the code (i.e. dangling else).
- return If && dyn_cast_or_null<CompoundStmt>(If->getThen()) &&
- dyn_cast_or_null<CompoundStmt>(If->getElse());
+ return If && isa_and_nonnull<CompoundStmt>(If->getThen()) &&
+ isa_and_nonnull<CompoundStmt>(If->getElse());
}
Expected<Tweak::Effect> SwapIfBranches::apply(const Selection &Inputs) {
More information about the llvm-branch-commits
mailing list