[clang] 537cc6d - Rename CXXUnresolvedConstructExpr::arg_size for consistency
Stephen Kelly via cfe-commits
cfe-commits at lists.llvm.org
Mon Nov 2 12:22:21 PST 2020
Author: Stephen Kelly
Date: 2020-11-02T20:21:48Z
New Revision: 537cc6dd2b36a7219a9bbaa6bc6f32c99a1baae1
URL: https://github.com/llvm/llvm-project/commit/537cc6dd2b36a7219a9bbaa6bc6f32c99a1baae1
DIFF: https://github.com/llvm/llvm-project/commit/537cc6dd2b36a7219a9bbaa6bc6f32c99a1baae1.diff
LOG: Rename CXXUnresolvedConstructExpr::arg_size for consistency
Make it possible to use argumentCountIs and hasArgument with
CXXUnresolvedConstructExpr.
Differential Revision: https://reviews.llvm.org/D90553
Added:
Modified:
clang/include/clang/AST/ExprCXX.h
clang/include/clang/ASTMatchers/ASTMatchers.h
clang/lib/AST/ASTImporter.cpp
clang/lib/AST/ItaniumMangle.cpp
clang/lib/Sema/TreeTransform.h
clang/lib/Serialization/ASTReaderStmt.cpp
clang/lib/Serialization/ASTWriterStmt.cpp
clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/AST/ExprCXX.h b/clang/include/clang/AST/ExprCXX.h
index 2144279f132b..d4e0eb83bcc3 100644
--- a/clang/include/clang/AST/ExprCXX.h
+++ b/clang/include/clang/AST/ExprCXX.h
@@ -3470,43 +3470,43 @@ class CXXUnresolvedConstructExpr final
bool isListInitialization() const { return LParenLoc.isInvalid(); }
/// Retrieve the number of arguments.
- unsigned arg_size() const { return CXXUnresolvedConstructExprBits.NumArgs; }
+ unsigned getNumArgs() const { return CXXUnresolvedConstructExprBits.NumArgs; }
using arg_iterator = Expr **;
using arg_range = llvm::iterator_range<arg_iterator>;
arg_iterator arg_begin() { return getTrailingObjects<Expr *>(); }
- arg_iterator arg_end() { return arg_begin() + arg_size(); }
+ arg_iterator arg_end() { return arg_begin() + getNumArgs(); }
arg_range arguments() { return arg_range(arg_begin(), arg_end()); }
using const_arg_iterator = const Expr* const *;
using const_arg_range = llvm::iterator_range<const_arg_iterator>;
const_arg_iterator arg_begin() const { return getTrailingObjects<Expr *>(); }
- const_arg_iterator arg_end() const { return arg_begin() + arg_size(); }
+ const_arg_iterator arg_end() const { return arg_begin() + getNumArgs(); }
const_arg_range arguments() const {
return const_arg_range(arg_begin(), arg_end());
}
Expr *getArg(unsigned I) {
- assert(I < arg_size() && "Argument index out-of-range");
+ assert(I < getNumArgs() && "Argument index out-of-range");
return arg_begin()[I];
}
const Expr *getArg(unsigned I) const {
- assert(I < arg_size() && "Argument index out-of-range");
+ assert(I < getNumArgs() && "Argument index out-of-range");
return arg_begin()[I];
}
void setArg(unsigned I, Expr *E) {
- assert(I < arg_size() && "Argument index out-of-range");
+ assert(I < getNumArgs() && "Argument index out-of-range");
arg_begin()[I] = E;
}
SourceLocation getBeginLoc() const LLVM_READONLY;
SourceLocation getEndLoc() const LLVM_READONLY {
- if (!RParenLoc.isValid() && arg_size() > 0)
- return getArg(arg_size() - 1)->getEndLoc();
+ if (!RParenLoc.isValid() && getNumArgs() > 0)
+ return getArg(getNumArgs() - 1)->getEndLoc();
return RParenLoc;
}
@@ -3517,13 +3517,13 @@ class CXXUnresolvedConstructExpr final
// Iterators
child_range children() {
auto **begin = reinterpret_cast<Stmt **>(arg_begin());
- return child_range(begin, begin + arg_size());
+ return child_range(begin, begin + getNumArgs());
}
const_child_range children() const {
auto **begin = reinterpret_cast<Stmt **>(
const_cast<CXXUnresolvedConstructExpr *>(this)->arg_begin());
- return const_child_range(begin, begin + arg_size());
+ return const_child_range(begin, begin + getNumArgs());
}
};
diff --git a/clang/include/clang/ASTMatchers/ASTMatchers.h b/clang/include/clang/ASTMatchers/ASTMatchers.h
index 11886dcafa61..c535e538fe8b 100644
--- a/clang/include/clang/ASTMatchers/ASTMatchers.h
+++ b/clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -3965,9 +3965,9 @@ AST_MATCHER(VarDecl, isExceptionVariable) {
/// f(0, 0);
/// \endcode
AST_POLYMORPHIC_MATCHER_P(argumentCountIs,
- AST_POLYMORPHIC_SUPPORTED_TYPES(CallExpr,
- CXXConstructExpr,
- ObjCMessageExpr),
+ AST_POLYMORPHIC_SUPPORTED_TYPES(
+ CallExpr, CXXConstructExpr,
+ CXXUnresolvedConstructExpr, ObjCMessageExpr),
unsigned, N) {
return Node.getNumArgs() == N;
}
@@ -3981,9 +3981,9 @@ AST_POLYMORPHIC_MATCHER_P(argumentCountIs,
/// void x(int) { int y; x(y); }
/// \endcode
AST_POLYMORPHIC_MATCHER_P2(hasArgument,
- AST_POLYMORPHIC_SUPPORTED_TYPES(CallExpr,
- CXXConstructExpr,
- ObjCMessageExpr),
+ AST_POLYMORPHIC_SUPPORTED_TYPES(
+ CallExpr, CXXConstructExpr,
+ CXXUnresolvedConstructExpr, ObjCMessageExpr),
unsigned, N, internal::Matcher<Expr>, InnerMatcher) {
return (N < Node.getNumArgs() &&
InnerMatcher.matches(
diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp
index d0fcc791d659..de1f13edf3ca 100644
--- a/clang/lib/AST/ASTImporter.cpp
+++ b/clang/lib/AST/ASTImporter.cpp
@@ -7539,7 +7539,7 @@ ExpectedStmt ASTNodeImporter::VisitCXXUnresolvedConstructExpr(
if (Err)
return std::move(Err);
- SmallVector<Expr *, 8> ToArgs(E->arg_size());
+ SmallVector<Expr *, 8> ToArgs(E->getNumArgs());
if (Error Err =
ImportArrayChecked(E->arg_begin(), E->arg_end(), ToArgs.begin()))
return std::move(Err);
diff --git a/clang/lib/AST/ItaniumMangle.cpp b/clang/lib/AST/ItaniumMangle.cpp
index d38a88f95a05..be3f60480361 100644
--- a/clang/lib/AST/ItaniumMangle.cpp
+++ b/clang/lib/AST/ItaniumMangle.cpp
@@ -4175,7 +4175,7 @@ void CXXNameMangler::mangleExpression(const Expr *E, unsigned Arity) {
case Expr::CXXUnresolvedConstructExprClass: {
const CXXUnresolvedConstructExpr *CE = cast<CXXUnresolvedConstructExpr>(E);
- unsigned N = CE->arg_size();
+ unsigned N = CE->getNumArgs();
if (CE->isListInitialization()) {
assert(N == 1 && "unexpected form for list initialization");
diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index 481fe98132c8..27f0ca91aede 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -12745,12 +12745,12 @@ TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
bool ArgumentChanged = false;
SmallVector<Expr*, 8> Args;
- Args.reserve(E->arg_size());
+ Args.reserve(E->getNumArgs());
{
EnterExpressionEvaluationContext Context(
getSema(), EnterExpressionEvaluationContext::InitList,
E->isListInitialization());
- if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
+ if (getDerived().TransformExprs(E->arg_begin(), E->getNumArgs(), true, Args,
&ArgumentChanged))
return ExprError();
}
diff --git a/clang/lib/Serialization/ASTReaderStmt.cpp b/clang/lib/Serialization/ASTReaderStmt.cpp
index cf335302f7f0..8b9d4a127691 100644
--- a/clang/lib/Serialization/ASTReaderStmt.cpp
+++ b/clang/lib/Serialization/ASTReaderStmt.cpp
@@ -1990,10 +1990,10 @@ ASTStmtReader::VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E) {
void
ASTStmtReader::VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr *E) {
VisitExpr(E);
- assert(Record.peekInt() == E->arg_size() &&
+ assert(Record.peekInt() == E->getNumArgs() &&
"Read wrong record during creation ?");
Record.skipInts(1);
- for (unsigned I = 0, N = E->arg_size(); I != N; ++I)
+ for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I)
E->setArg(I, Record.readSubExpr());
E->TSI = readTypeSourceInfo();
E->setLParenLoc(readSourceLocation());
diff --git a/clang/lib/Serialization/ASTWriterStmt.cpp b/clang/lib/Serialization/ASTWriterStmt.cpp
index 522cd3247f34..d4f669ea0183 100644
--- a/clang/lib/Serialization/ASTWriterStmt.cpp
+++ b/clang/lib/Serialization/ASTWriterStmt.cpp
@@ -1900,7 +1900,7 @@ ASTStmtWriter::VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E) {
void
ASTStmtWriter::VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr *E) {
VisitExpr(E);
- Record.push_back(E->arg_size());
+ Record.push_back(E->getNumArgs());
for (CXXUnresolvedConstructExpr::arg_iterator
ArgI = E->arg_begin(), ArgE = E->arg_end(); ArgI != ArgE; ++ArgI)
Record.AddStmt(*ArgI);
diff --git a/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp b/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
index 4bd50191e163..7e53b71a50e4 100644
--- a/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
+++ b/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
@@ -1613,6 +1613,26 @@ TEST_P(ASTMatchersTest, ArgumentCountIs_CXXConstructExpr) {
Constructor1Arg));
}
+TEST(ASTMatchersTest, ArgumentCountIs_CXXUnresolvedConstructExpr) {
+ const auto *Code =
+ "template <typename T> struct S{}; template <typename T> void "
+ "x() { auto s = S<T>(); }";
+
+ EXPECT_TRUE(matches(Code, cxxUnresolvedConstructExpr(argumentCountIs(0))));
+ EXPECT_TRUE(notMatches(Code, cxxUnresolvedConstructExpr(argumentCountIs(1))));
+}
+
+TEST(ASTMatchersTest, HasArgument_CXXUnresolvedConstructExpr) {
+ const auto *Code =
+ "template <typename T> struct S{ S(int){} }; template <typename "
+ "T> void x() { int y; auto s = S<T>(y); }";
+ EXPECT_TRUE(matches(Code, cxxUnresolvedConstructExpr(hasArgument(
+ 0, declRefExpr(to(varDecl(hasName("y"))))))));
+ EXPECT_TRUE(
+ notMatches(Code, cxxUnresolvedConstructExpr(hasArgument(
+ 0, declRefExpr(to(varDecl(hasName("x"))))))));
+}
+
TEST_P(ASTMatchersTest, IsListInitialization) {
if (!GetParam().isCXX11OrLater()) {
return;
More information about the cfe-commits
mailing list