[PATCH] D14212: Make hasLHS and hasRHS matchers available for ArraySubscriptExpr
Alexander Kornienko via cfe-commits
cfe-commits at lists.llvm.org
Fri Oct 30 13:59:51 PDT 2015
alexfh created this revision.
alexfh added a reviewer: klimek.
alexfh added a subscriber: cfe-commits.
Herald added a subscriber: klimek.
The hasBase and hasIndex don't tell anything about the position of the
base and the index in the code, so we need hasLHS and hasRHS in some cases.
http://reviews.llvm.org/D14212
Files:
include/clang/ASTMatchers/ASTMatchers.h
unittests/ASTMatchers/ASTMatchersTest.cpp
Index: unittests/ASTMatchers/ASTMatchersTest.cpp
===================================================================
--- unittests/ASTMatchers/ASTMatchersTest.cpp
+++ unittests/ASTMatchers/ASTMatchersTest.cpp
@@ -2357,6 +2357,11 @@
EXPECT_TRUE(matches("void x() { true || false; }", OperatorTrueFalse));
EXPECT_TRUE(matches("void x() { true && false; }", OperatorTrueFalse));
EXPECT_TRUE(notMatches("void x() { false || true; }", OperatorTrueFalse));
+
+ StatementMatcher OperatorIntPointer = arraySubscriptExpr(
+ hasLHS(hasType(isInteger())), hasRHS(hasType(pointsTo(qualType()))));
+ EXPECT_TRUE(matches("void x() { 1[\"abc\"]; }", OperatorIntPointer));
+ EXPECT_TRUE(notMatches("void x() { \"abc\"[1]; }", OperatorIntPointer));
}
TEST(MatchBinaryOperator, HasEitherOperand) {
Index: include/clang/ASTMatchers/ASTMatchers.h
===================================================================
--- include/clang/ASTMatchers/ASTMatchers.h
+++ include/clang/ASTMatchers/ASTMatchers.h
@@ -3127,9 +3127,11 @@
/// \code
/// a || b
/// \endcode
-AST_MATCHER_P(BinaryOperator, hasLHS,
- internal::Matcher<Expr>, InnerMatcher) {
- Expr *LeftHandSide = Node.getLHS();
+AST_POLYMORPHIC_MATCHER_P(hasLHS,
+ AST_POLYMORPHIC_SUPPORTED_TYPES(BinaryOperator,
+ ArraySubscriptExpr),
+ internal::Matcher<Expr>, InnerMatcher) {
+ const Expr *LeftHandSide = Node.getLHS();
return (LeftHandSide != nullptr &&
InnerMatcher.matches(*LeftHandSide, Finder, Builder));
}
@@ -3140,9 +3142,11 @@
/// \code
/// a || b
/// \endcode
-AST_MATCHER_P(BinaryOperator, hasRHS,
- internal::Matcher<Expr>, InnerMatcher) {
- Expr *RightHandSide = Node.getRHS();
+AST_POLYMORPHIC_MATCHER_P(hasRHS,
+ AST_POLYMORPHIC_SUPPORTED_TYPES(BinaryOperator,
+ ArraySubscriptExpr),
+ internal::Matcher<Expr>, InnerMatcher) {
+ const Expr *RightHandSide = Node.getRHS();
return (RightHandSide != nullptr &&
InnerMatcher.matches(*RightHandSide, Finder, Builder));
}
@@ -3246,7 +3250,7 @@
/// \endcode
AST_MATCHER_P(ConditionalOperator, hasTrueExpression,
internal::Matcher<Expr>, InnerMatcher) {
- Expr *Expression = Node.getTrueExpr();
+ const Expr *Expression = Node.getTrueExpr();
return (Expression != nullptr &&
InnerMatcher.matches(*Expression, Finder, Builder));
}
@@ -3259,7 +3263,7 @@
/// \endcode
AST_MATCHER_P(ConditionalOperator, hasFalseExpression,
internal::Matcher<Expr>, InnerMatcher) {
- Expr *Expression = Node.getFalseExpr();
+ const Expr *Expression = Node.getFalseExpr();
return (Expression != nullptr &&
InnerMatcher.matches(*Expression, Finder, Builder));
}
@@ -4253,7 +4257,7 @@
AST_MATCHER_P_OVERLOAD(NestedNameSpecifier, hasPrefix,
internal::Matcher<NestedNameSpecifier>, InnerMatcher,
0) {
- NestedNameSpecifier *NextNode = Node.getPrefix();
+ const NestedNameSpecifier *NextNode = Node.getPrefix();
if (!NextNode)
return false;
return InnerMatcher.matches(*NextNode, Finder, Builder);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D14212.38831.patch
Type: text/x-patch
Size: 3297 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20151030/33a54e74/attachment.bin>
More information about the cfe-commits
mailing list