1 //===- unittests/Tooling/RecursiveASTVisitorTests/CallbacksBinaryOperator.cpp -===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "CallbacksCommon.h"
11 TEST(RecursiveASTVisitor
, StmtCallbacks_TraverseBinaryOperator
) {
12 class RecordingVisitor
: public RecordingVisitorBase
<RecordingVisitor
> {
14 RecordingVisitor(ShouldTraversePostOrder ShouldTraversePostOrderValue
)
15 : RecordingVisitorBase(ShouldTraversePostOrderValue
) {}
17 bool TraverseBinaryOperator(BinaryOperator
*BO
) {
18 recordCallback(__func__
, BO
, [&]() {
19 RecordingVisitorBase::TraverseBinaryOperator(BO
);
24 bool WalkUpFromStmt(Stmt
*S
) {
25 recordCallback(__func__
, S
,
26 [&]() { RecordingVisitorBase::WalkUpFromStmt(S
); });
31 StringRef Code
= R
"cpp(
39 EXPECT_TRUE(visitorCallbackLogEqual(
40 RecordingVisitor(ShouldTraversePostOrder::No
), Code
,
42 WalkUpFromStmt CompoundStmt
43 WalkUpFromStmt IntegerLiteral(1)
44 TraverseBinaryOperator BinaryOperator(+)
45 WalkUpFromStmt BinaryOperator(+)
46 WalkUpFromStmt IntegerLiteral(2)
47 WalkUpFromStmt IntegerLiteral(3)
48 WalkUpFromStmt IntegerLiteral(4)
51 EXPECT_TRUE(visitorCallbackLogEqual(
52 RecordingVisitor(ShouldTraversePostOrder::Yes
), Code
,
54 WalkUpFromStmt IntegerLiteral(1)
55 TraverseBinaryOperator BinaryOperator(+)
56 WalkUpFromStmt IntegerLiteral(2)
57 WalkUpFromStmt IntegerLiteral(3)
58 WalkUpFromStmt BinaryOperator(+)
59 WalkUpFromStmt IntegerLiteral(4)
60 WalkUpFromStmt CompoundStmt
64 TEST(RecursiveASTVisitor
,
65 StmtCallbacks_TraverseBinaryOperator_WalkUpFromBinaryOperator
) {
66 class RecordingVisitor
: public RecordingVisitorBase
<RecordingVisitor
> {
68 RecordingVisitor(ShouldTraversePostOrder ShouldTraversePostOrderValue
)
69 : RecordingVisitorBase(ShouldTraversePostOrderValue
) {}
71 bool TraverseBinaryOperator(BinaryOperator
*BO
) {
72 recordCallback(__func__
, BO
, [&]() {
73 RecordingVisitorBase::TraverseBinaryOperator(BO
);
78 bool WalkUpFromStmt(Stmt
*S
) {
79 recordCallback(__func__
, S
,
80 [&]() { RecordingVisitorBase::WalkUpFromStmt(S
); });
84 bool WalkUpFromExpr(Expr
*E
) {
85 recordCallback(__func__
, E
,
86 [&]() { RecordingVisitorBase::WalkUpFromExpr(E
); });
90 bool WalkUpFromBinaryOperator(BinaryOperator
*BO
) {
91 recordCallback(__func__
, BO
, [&]() {
92 RecordingVisitorBase::WalkUpFromBinaryOperator(BO
);
98 StringRef Code
= R
"cpp(
106 EXPECT_TRUE(visitorCallbackLogEqual(
107 RecordingVisitor(ShouldTraversePostOrder::No
), Code
,
109 WalkUpFromStmt CompoundStmt
110 WalkUpFromExpr IntegerLiteral(1)
111 WalkUpFromStmt IntegerLiteral(1)
112 TraverseBinaryOperator BinaryOperator(+)
113 WalkUpFromBinaryOperator BinaryOperator(+)
114 WalkUpFromExpr BinaryOperator(+)
115 WalkUpFromStmt BinaryOperator(+)
116 WalkUpFromExpr IntegerLiteral(2)
117 WalkUpFromStmt IntegerLiteral(2)
118 WalkUpFromExpr IntegerLiteral(3)
119 WalkUpFromStmt IntegerLiteral(3)
120 WalkUpFromExpr IntegerLiteral(4)
121 WalkUpFromStmt IntegerLiteral(4)
124 EXPECT_TRUE(visitorCallbackLogEqual(
125 RecordingVisitor(ShouldTraversePostOrder::Yes
), Code
,
127 WalkUpFromExpr IntegerLiteral(1)
128 WalkUpFromStmt IntegerLiteral(1)
129 TraverseBinaryOperator BinaryOperator(+)
130 WalkUpFromExpr IntegerLiteral(2)
131 WalkUpFromStmt IntegerLiteral(2)
132 WalkUpFromExpr IntegerLiteral(3)
133 WalkUpFromStmt IntegerLiteral(3)
134 WalkUpFromBinaryOperator BinaryOperator(+)
135 WalkUpFromExpr BinaryOperator(+)
136 WalkUpFromStmt BinaryOperator(+)
137 WalkUpFromExpr IntegerLiteral(4)
138 WalkUpFromStmt IntegerLiteral(4)
139 WalkUpFromStmt CompoundStmt
143 TEST(RecursiveASTVisitor
, StmtCallbacks_WalkUpFromBinaryOperator
) {
144 class RecordingVisitor
: public RecordingVisitorBase
<RecordingVisitor
> {
146 RecordingVisitor(ShouldTraversePostOrder ShouldTraversePostOrderValue
)
147 : RecordingVisitorBase(ShouldTraversePostOrderValue
) {}
149 bool WalkUpFromStmt(Stmt
*S
) {
150 recordCallback(__func__
, S
,
151 [&]() { RecordingVisitorBase::WalkUpFromStmt(S
); });
155 bool WalkUpFromExpr(Expr
*E
) {
156 recordCallback(__func__
, E
,
157 [&]() { RecordingVisitorBase::WalkUpFromExpr(E
); });
161 bool WalkUpFromBinaryOperator(BinaryOperator
*BO
) {
162 recordCallback(__func__
, BO
, [&]() {
163 RecordingVisitorBase::WalkUpFromBinaryOperator(BO
);
169 StringRef Code
= R
"cpp(
177 EXPECT_TRUE(visitorCallbackLogEqual(
178 RecordingVisitor(ShouldTraversePostOrder::No
), Code
,
180 WalkUpFromStmt CompoundStmt
181 WalkUpFromExpr IntegerLiteral(1)
182 WalkUpFromStmt IntegerLiteral(1)
183 WalkUpFromBinaryOperator BinaryOperator(+)
184 WalkUpFromExpr BinaryOperator(+)
185 WalkUpFromStmt BinaryOperator(+)
186 WalkUpFromExpr IntegerLiteral(2)
187 WalkUpFromStmt IntegerLiteral(2)
188 WalkUpFromExpr IntegerLiteral(3)
189 WalkUpFromStmt IntegerLiteral(3)
190 WalkUpFromExpr IntegerLiteral(4)
191 WalkUpFromStmt IntegerLiteral(4)
194 EXPECT_TRUE(visitorCallbackLogEqual(
195 RecordingVisitor(ShouldTraversePostOrder::Yes
), Code
,
197 WalkUpFromExpr IntegerLiteral(1)
198 WalkUpFromStmt IntegerLiteral(1)
199 WalkUpFromExpr IntegerLiteral(2)
200 WalkUpFromStmt IntegerLiteral(2)
201 WalkUpFromExpr IntegerLiteral(3)
202 WalkUpFromStmt IntegerLiteral(3)
203 WalkUpFromBinaryOperator BinaryOperator(+)
204 WalkUpFromExpr BinaryOperator(+)
205 WalkUpFromStmt BinaryOperator(+)
206 WalkUpFromExpr IntegerLiteral(4)
207 WalkUpFromStmt IntegerLiteral(4)
208 WalkUpFromStmt CompoundStmt