1 //===- unittests/Tooling/RecursiveASTVisitorTests/CallbacksCompoundAssignOperator.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_TraverseCompoundAssignOperator
) {
12 class RecordingVisitor
: public RecordingVisitorBase
<RecordingVisitor
> {
14 RecordingVisitor(ShouldTraversePostOrder ShouldTraversePostOrderValue
)
15 : RecordingVisitorBase(ShouldTraversePostOrderValue
) {}
17 bool TraverseCompoundAssignOperator(CompoundAssignOperator
*CAO
) {
18 recordCallback(__func__
, CAO
, [&]() {
19 RecordingVisitorBase::TraverseCompoundAssignOperator(CAO
);
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 TraverseCompoundAssignOperator CompoundAssignOperator(+=)
45 WalkUpFromStmt CompoundAssignOperator(+=)
46 WalkUpFromStmt DeclRefExpr(a)
47 WalkUpFromStmt IntegerLiteral(2)
48 WalkUpFromStmt IntegerLiteral(3)
51 EXPECT_TRUE(visitorCallbackLogEqual(
52 RecordingVisitor(ShouldTraversePostOrder::Yes
), Code
,
54 WalkUpFromStmt IntegerLiteral(1)
55 TraverseCompoundAssignOperator CompoundAssignOperator(+=)
56 WalkUpFromStmt DeclRefExpr(a)
57 WalkUpFromStmt IntegerLiteral(2)
58 WalkUpFromStmt CompoundAssignOperator(+=)
59 WalkUpFromStmt IntegerLiteral(3)
60 WalkUpFromStmt CompoundStmt
66 StmtCallbacks_TraverseCompoundAssignOperator_WalkUpFromCompoundAssignOperator
) {
67 class RecordingVisitor
: public RecordingVisitorBase
<RecordingVisitor
> {
69 RecordingVisitor(ShouldTraversePostOrder ShouldTraversePostOrderValue
)
70 : RecordingVisitorBase(ShouldTraversePostOrderValue
) {}
72 bool TraverseCompoundAssignOperator(CompoundAssignOperator
*CAO
) {
73 recordCallback(__func__
, CAO
, [&]() {
74 RecordingVisitorBase::TraverseCompoundAssignOperator(CAO
);
79 bool WalkUpFromStmt(Stmt
*S
) {
80 recordCallback(__func__
, S
,
81 [&]() { RecordingVisitorBase::WalkUpFromStmt(S
); });
85 bool WalkUpFromExpr(Expr
*E
) {
86 recordCallback(__func__
, E
,
87 [&]() { RecordingVisitorBase::WalkUpFromExpr(E
); });
91 bool WalkUpFromCompoundAssignOperator(CompoundAssignOperator
*CAO
) {
92 recordCallback(__func__
, CAO
, [&]() {
93 RecordingVisitorBase::WalkUpFromCompoundAssignOperator(CAO
);
99 StringRef Code
= R
"cpp(
107 EXPECT_TRUE(visitorCallbackLogEqual(
108 RecordingVisitor(ShouldTraversePostOrder::No
), Code
,
110 WalkUpFromStmt CompoundStmt
111 WalkUpFromExpr IntegerLiteral(1)
112 WalkUpFromStmt IntegerLiteral(1)
113 TraverseCompoundAssignOperator CompoundAssignOperator(+=)
114 WalkUpFromCompoundAssignOperator CompoundAssignOperator(+=)
115 WalkUpFromExpr CompoundAssignOperator(+=)
116 WalkUpFromStmt CompoundAssignOperator(+=)
117 WalkUpFromExpr DeclRefExpr(a)
118 WalkUpFromStmt DeclRefExpr(a)
119 WalkUpFromExpr IntegerLiteral(2)
120 WalkUpFromStmt IntegerLiteral(2)
121 WalkUpFromExpr IntegerLiteral(3)
122 WalkUpFromStmt IntegerLiteral(3)
125 EXPECT_TRUE(visitorCallbackLogEqual(
126 RecordingVisitor(ShouldTraversePostOrder::Yes
), Code
,
128 WalkUpFromExpr IntegerLiteral(1)
129 WalkUpFromStmt IntegerLiteral(1)
130 TraverseCompoundAssignOperator CompoundAssignOperator(+=)
131 WalkUpFromExpr DeclRefExpr(a)
132 WalkUpFromStmt DeclRefExpr(a)
133 WalkUpFromExpr IntegerLiteral(2)
134 WalkUpFromStmt IntegerLiteral(2)
135 WalkUpFromCompoundAssignOperator CompoundAssignOperator(+=)
136 WalkUpFromExpr CompoundAssignOperator(+=)
137 WalkUpFromStmt CompoundAssignOperator(+=)
138 WalkUpFromExpr IntegerLiteral(3)
139 WalkUpFromStmt IntegerLiteral(3)
140 WalkUpFromStmt CompoundStmt
144 TEST(RecursiveASTVisitor
, StmtCallbacks_WalkUpFromCompoundAssignOperator
) {
145 class RecordingVisitor
: public RecordingVisitorBase
<RecordingVisitor
> {
147 RecordingVisitor(ShouldTraversePostOrder ShouldTraversePostOrderValue
)
148 : RecordingVisitorBase(ShouldTraversePostOrderValue
) {}
150 bool WalkUpFromStmt(Stmt
*S
) {
151 recordCallback(__func__
, S
,
152 [&]() { RecordingVisitorBase::WalkUpFromStmt(S
); });
156 bool WalkUpFromExpr(Expr
*E
) {
157 recordCallback(__func__
, E
,
158 [&]() { RecordingVisitorBase::WalkUpFromExpr(E
); });
162 bool WalkUpFromCompoundAssignOperator(CompoundAssignOperator
*CAO
) {
163 recordCallback(__func__
, CAO
, [&]() {
164 RecordingVisitorBase::WalkUpFromCompoundAssignOperator(CAO
);
170 StringRef Code
= R
"cpp(
178 EXPECT_TRUE(visitorCallbackLogEqual(
179 RecordingVisitor(ShouldTraversePostOrder::No
), Code
,
181 WalkUpFromStmt CompoundStmt
182 WalkUpFromExpr IntegerLiteral(1)
183 WalkUpFromStmt IntegerLiteral(1)
184 WalkUpFromCompoundAssignOperator CompoundAssignOperator(+=)
185 WalkUpFromExpr CompoundAssignOperator(+=)
186 WalkUpFromStmt CompoundAssignOperator(+=)
187 WalkUpFromExpr DeclRefExpr(a)
188 WalkUpFromStmt DeclRefExpr(a)
189 WalkUpFromExpr IntegerLiteral(2)
190 WalkUpFromStmt IntegerLiteral(2)
191 WalkUpFromExpr IntegerLiteral(3)
192 WalkUpFromStmt IntegerLiteral(3)
195 EXPECT_TRUE(visitorCallbackLogEqual(
196 RecordingVisitor(ShouldTraversePostOrder::Yes
), Code
,
198 WalkUpFromExpr IntegerLiteral(1)
199 WalkUpFromStmt IntegerLiteral(1)
200 WalkUpFromExpr DeclRefExpr(a)
201 WalkUpFromStmt DeclRefExpr(a)
202 WalkUpFromExpr IntegerLiteral(2)
203 WalkUpFromStmt IntegerLiteral(2)
204 WalkUpFromCompoundAssignOperator CompoundAssignOperator(+=)
205 WalkUpFromExpr CompoundAssignOperator(+=)
206 WalkUpFromStmt CompoundAssignOperator(+=)
207 WalkUpFromExpr IntegerLiteral(3)
208 WalkUpFromStmt IntegerLiteral(3)
209 WalkUpFromStmt CompoundStmt