1*0741a2c9SStefan Pintilie //===- unittests/Tooling/RecursiveASTVisitorTests/CallbacksCompoundAssignOperator.cpp -===//
2*0741a2c9SStefan Pintilie //
3*0741a2c9SStefan Pintilie // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*0741a2c9SStefan Pintilie // See https://llvm.org/LICENSE.txt for license information.
5*0741a2c9SStefan Pintilie // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*0741a2c9SStefan Pintilie //
7*0741a2c9SStefan Pintilie //===----------------------------------------------------------------------===//
8*0741a2c9SStefan Pintilie 
9*0741a2c9SStefan Pintilie #include "CallbacksCommon.h"
10*0741a2c9SStefan Pintilie 
TEST(RecursiveASTVisitor,StmtCallbacks_TraverseCompoundAssignOperator)11*0741a2c9SStefan Pintilie TEST(RecursiveASTVisitor, StmtCallbacks_TraverseCompoundAssignOperator) {
12*0741a2c9SStefan Pintilie   class RecordingVisitor : public RecordingVisitorBase<RecordingVisitor> {
13*0741a2c9SStefan Pintilie   public:
14*0741a2c9SStefan Pintilie     RecordingVisitor(ShouldTraversePostOrder ShouldTraversePostOrderValue)
15*0741a2c9SStefan Pintilie         : RecordingVisitorBase(ShouldTraversePostOrderValue) {}
16*0741a2c9SStefan Pintilie 
17*0741a2c9SStefan Pintilie     bool TraverseCompoundAssignOperator(CompoundAssignOperator *CAO) {
18*0741a2c9SStefan Pintilie       recordCallback(__func__, CAO, [&]() {
19*0741a2c9SStefan Pintilie         RecordingVisitorBase::TraverseCompoundAssignOperator(CAO);
20*0741a2c9SStefan Pintilie       });
21*0741a2c9SStefan Pintilie       return true;
22*0741a2c9SStefan Pintilie     }
23*0741a2c9SStefan Pintilie 
24*0741a2c9SStefan Pintilie     bool WalkUpFromStmt(Stmt *S) {
25*0741a2c9SStefan Pintilie       recordCallback(__func__, S,
26*0741a2c9SStefan Pintilie                      [&]() { RecordingVisitorBase::WalkUpFromStmt(S); });
27*0741a2c9SStefan Pintilie       return true;
28*0741a2c9SStefan Pintilie     }
29*0741a2c9SStefan Pintilie   };
30*0741a2c9SStefan Pintilie 
31*0741a2c9SStefan Pintilie   StringRef Code = R"cpp(
32*0741a2c9SStefan Pintilie void test(int a) {
33*0741a2c9SStefan Pintilie   1;
34*0741a2c9SStefan Pintilie   a += 2;
35*0741a2c9SStefan Pintilie   3;
36*0741a2c9SStefan Pintilie }
37*0741a2c9SStefan Pintilie )cpp";
38*0741a2c9SStefan Pintilie 
39*0741a2c9SStefan Pintilie   EXPECT_TRUE(visitorCallbackLogEqual(
40*0741a2c9SStefan Pintilie       RecordingVisitor(ShouldTraversePostOrder::No), Code,
41*0741a2c9SStefan Pintilie       R"txt(
42*0741a2c9SStefan Pintilie WalkUpFromStmt CompoundStmt
43*0741a2c9SStefan Pintilie WalkUpFromStmt IntegerLiteral(1)
44*0741a2c9SStefan Pintilie TraverseCompoundAssignOperator CompoundAssignOperator(+=)
45*0741a2c9SStefan Pintilie   WalkUpFromStmt CompoundAssignOperator(+=)
46*0741a2c9SStefan Pintilie   WalkUpFromStmt DeclRefExpr(a)
47*0741a2c9SStefan Pintilie   WalkUpFromStmt IntegerLiteral(2)
48*0741a2c9SStefan Pintilie WalkUpFromStmt IntegerLiteral(3)
49*0741a2c9SStefan Pintilie )txt"));
50*0741a2c9SStefan Pintilie 
51*0741a2c9SStefan Pintilie   EXPECT_TRUE(visitorCallbackLogEqual(
52*0741a2c9SStefan Pintilie       RecordingVisitor(ShouldTraversePostOrder::Yes), Code,
53*0741a2c9SStefan Pintilie       R"txt(
54*0741a2c9SStefan Pintilie WalkUpFromStmt IntegerLiteral(1)
55*0741a2c9SStefan Pintilie TraverseCompoundAssignOperator CompoundAssignOperator(+=)
56*0741a2c9SStefan Pintilie   WalkUpFromStmt DeclRefExpr(a)
57*0741a2c9SStefan Pintilie   WalkUpFromStmt IntegerLiteral(2)
58*0741a2c9SStefan Pintilie   WalkUpFromStmt CompoundAssignOperator(+=)
59*0741a2c9SStefan Pintilie WalkUpFromStmt IntegerLiteral(3)
60*0741a2c9SStefan Pintilie WalkUpFromStmt CompoundStmt
61*0741a2c9SStefan Pintilie )txt"));
62*0741a2c9SStefan Pintilie }
63*0741a2c9SStefan Pintilie 
TEST(RecursiveASTVisitor,StmtCallbacks_TraverseCompoundAssignOperator_WalkUpFromCompoundAssignOperator)64*0741a2c9SStefan Pintilie TEST(
65*0741a2c9SStefan Pintilie     RecursiveASTVisitor,
66*0741a2c9SStefan Pintilie     StmtCallbacks_TraverseCompoundAssignOperator_WalkUpFromCompoundAssignOperator) {
67*0741a2c9SStefan Pintilie   class RecordingVisitor : public RecordingVisitorBase<RecordingVisitor> {
68*0741a2c9SStefan Pintilie   public:
69*0741a2c9SStefan Pintilie     RecordingVisitor(ShouldTraversePostOrder ShouldTraversePostOrderValue)
70*0741a2c9SStefan Pintilie         : RecordingVisitorBase(ShouldTraversePostOrderValue) {}
71*0741a2c9SStefan Pintilie 
72*0741a2c9SStefan Pintilie     bool TraverseCompoundAssignOperator(CompoundAssignOperator *CAO) {
73*0741a2c9SStefan Pintilie       recordCallback(__func__, CAO, [&]() {
74*0741a2c9SStefan Pintilie         RecordingVisitorBase::TraverseCompoundAssignOperator(CAO);
75*0741a2c9SStefan Pintilie       });
76*0741a2c9SStefan Pintilie       return true;
77*0741a2c9SStefan Pintilie     }
78*0741a2c9SStefan Pintilie 
79*0741a2c9SStefan Pintilie     bool WalkUpFromStmt(Stmt *S) {
80*0741a2c9SStefan Pintilie       recordCallback(__func__, S,
81*0741a2c9SStefan Pintilie                      [&]() { RecordingVisitorBase::WalkUpFromStmt(S); });
82*0741a2c9SStefan Pintilie       return true;
83*0741a2c9SStefan Pintilie     }
84*0741a2c9SStefan Pintilie 
85*0741a2c9SStefan Pintilie     bool WalkUpFromExpr(Expr *E) {
86*0741a2c9SStefan Pintilie       recordCallback(__func__, E,
87*0741a2c9SStefan Pintilie                      [&]() { RecordingVisitorBase::WalkUpFromExpr(E); });
88*0741a2c9SStefan Pintilie       return true;
89*0741a2c9SStefan Pintilie     }
90*0741a2c9SStefan Pintilie 
91*0741a2c9SStefan Pintilie     bool WalkUpFromCompoundAssignOperator(CompoundAssignOperator *CAO) {
92*0741a2c9SStefan Pintilie       recordCallback(__func__, CAO, [&]() {
93*0741a2c9SStefan Pintilie         RecordingVisitorBase::WalkUpFromCompoundAssignOperator(CAO);
94*0741a2c9SStefan Pintilie       });
95*0741a2c9SStefan Pintilie       return true;
96*0741a2c9SStefan Pintilie     }
97*0741a2c9SStefan Pintilie   };
98*0741a2c9SStefan Pintilie 
99*0741a2c9SStefan Pintilie   StringRef Code = R"cpp(
100*0741a2c9SStefan Pintilie void test(int a) {
101*0741a2c9SStefan Pintilie   1;
102*0741a2c9SStefan Pintilie   a += 2;
103*0741a2c9SStefan Pintilie   3;
104*0741a2c9SStefan Pintilie }
105*0741a2c9SStefan Pintilie )cpp";
106*0741a2c9SStefan Pintilie 
107*0741a2c9SStefan Pintilie   EXPECT_TRUE(visitorCallbackLogEqual(
108*0741a2c9SStefan Pintilie       RecordingVisitor(ShouldTraversePostOrder::No), Code,
109*0741a2c9SStefan Pintilie       R"txt(
110*0741a2c9SStefan Pintilie WalkUpFromStmt CompoundStmt
111*0741a2c9SStefan Pintilie WalkUpFromExpr IntegerLiteral(1)
112*0741a2c9SStefan Pintilie   WalkUpFromStmt IntegerLiteral(1)
113*0741a2c9SStefan Pintilie TraverseCompoundAssignOperator CompoundAssignOperator(+=)
114*0741a2c9SStefan Pintilie   WalkUpFromCompoundAssignOperator CompoundAssignOperator(+=)
115*0741a2c9SStefan Pintilie     WalkUpFromExpr CompoundAssignOperator(+=)
116*0741a2c9SStefan Pintilie       WalkUpFromStmt CompoundAssignOperator(+=)
117*0741a2c9SStefan Pintilie   WalkUpFromExpr DeclRefExpr(a)
118*0741a2c9SStefan Pintilie     WalkUpFromStmt DeclRefExpr(a)
119*0741a2c9SStefan Pintilie   WalkUpFromExpr IntegerLiteral(2)
120*0741a2c9SStefan Pintilie     WalkUpFromStmt IntegerLiteral(2)
121*0741a2c9SStefan Pintilie WalkUpFromExpr IntegerLiteral(3)
122*0741a2c9SStefan Pintilie   WalkUpFromStmt IntegerLiteral(3)
123*0741a2c9SStefan Pintilie )txt"));
124*0741a2c9SStefan Pintilie 
125*0741a2c9SStefan Pintilie   EXPECT_TRUE(visitorCallbackLogEqual(
126*0741a2c9SStefan Pintilie       RecordingVisitor(ShouldTraversePostOrder::Yes), Code,
127*0741a2c9SStefan Pintilie       R"txt(
128*0741a2c9SStefan Pintilie WalkUpFromExpr IntegerLiteral(1)
129*0741a2c9SStefan Pintilie   WalkUpFromStmt IntegerLiteral(1)
130*0741a2c9SStefan Pintilie TraverseCompoundAssignOperator CompoundAssignOperator(+=)
131*0741a2c9SStefan Pintilie   WalkUpFromExpr DeclRefExpr(a)
132*0741a2c9SStefan Pintilie     WalkUpFromStmt DeclRefExpr(a)
133*0741a2c9SStefan Pintilie   WalkUpFromExpr IntegerLiteral(2)
134*0741a2c9SStefan Pintilie     WalkUpFromStmt IntegerLiteral(2)
135*0741a2c9SStefan Pintilie   WalkUpFromCompoundAssignOperator CompoundAssignOperator(+=)
136*0741a2c9SStefan Pintilie     WalkUpFromExpr CompoundAssignOperator(+=)
137*0741a2c9SStefan Pintilie       WalkUpFromStmt CompoundAssignOperator(+=)
138*0741a2c9SStefan Pintilie WalkUpFromExpr IntegerLiteral(3)
139*0741a2c9SStefan Pintilie   WalkUpFromStmt IntegerLiteral(3)
140*0741a2c9SStefan Pintilie WalkUpFromStmt CompoundStmt
141*0741a2c9SStefan Pintilie )txt"));
142*0741a2c9SStefan Pintilie }
143*0741a2c9SStefan Pintilie 
TEST(RecursiveASTVisitor,StmtCallbacks_WalkUpFromCompoundAssignOperator)144*0741a2c9SStefan Pintilie TEST(RecursiveASTVisitor, StmtCallbacks_WalkUpFromCompoundAssignOperator) {
145*0741a2c9SStefan Pintilie   class RecordingVisitor : public RecordingVisitorBase<RecordingVisitor> {
146*0741a2c9SStefan Pintilie   public:
147*0741a2c9SStefan Pintilie     RecordingVisitor(ShouldTraversePostOrder ShouldTraversePostOrderValue)
148*0741a2c9SStefan Pintilie         : RecordingVisitorBase(ShouldTraversePostOrderValue) {}
149*0741a2c9SStefan Pintilie 
150*0741a2c9SStefan Pintilie     bool WalkUpFromStmt(Stmt *S) {
151*0741a2c9SStefan Pintilie       recordCallback(__func__, S,
152*0741a2c9SStefan Pintilie                      [&]() { RecordingVisitorBase::WalkUpFromStmt(S); });
153*0741a2c9SStefan Pintilie       return true;
154*0741a2c9SStefan Pintilie     }
155*0741a2c9SStefan Pintilie 
156*0741a2c9SStefan Pintilie     bool WalkUpFromExpr(Expr *E) {
157*0741a2c9SStefan Pintilie       recordCallback(__func__, E,
158*0741a2c9SStefan Pintilie                      [&]() { RecordingVisitorBase::WalkUpFromExpr(E); });
159*0741a2c9SStefan Pintilie       return true;
160*0741a2c9SStefan Pintilie     }
161*0741a2c9SStefan Pintilie 
162*0741a2c9SStefan Pintilie     bool WalkUpFromCompoundAssignOperator(CompoundAssignOperator *CAO) {
163*0741a2c9SStefan Pintilie       recordCallback(__func__, CAO, [&]() {
164*0741a2c9SStefan Pintilie         RecordingVisitorBase::WalkUpFromCompoundAssignOperator(CAO);
165*0741a2c9SStefan Pintilie       });
166*0741a2c9SStefan Pintilie       return true;
167*0741a2c9SStefan Pintilie     }
168*0741a2c9SStefan Pintilie   };
169*0741a2c9SStefan Pintilie 
170*0741a2c9SStefan Pintilie   StringRef Code = R"cpp(
171*0741a2c9SStefan Pintilie void test(int a) {
172*0741a2c9SStefan Pintilie   1;
173*0741a2c9SStefan Pintilie   a += 2;
174*0741a2c9SStefan Pintilie   3;
175*0741a2c9SStefan Pintilie }
176*0741a2c9SStefan Pintilie )cpp";
177*0741a2c9SStefan Pintilie 
178*0741a2c9SStefan Pintilie   EXPECT_TRUE(visitorCallbackLogEqual(
179*0741a2c9SStefan Pintilie       RecordingVisitor(ShouldTraversePostOrder::No), Code,
180*0741a2c9SStefan Pintilie       R"txt(
181*0741a2c9SStefan Pintilie WalkUpFromStmt CompoundStmt
182*0741a2c9SStefan Pintilie WalkUpFromExpr IntegerLiteral(1)
183*0741a2c9SStefan Pintilie   WalkUpFromStmt IntegerLiteral(1)
184*0741a2c9SStefan Pintilie WalkUpFromCompoundAssignOperator CompoundAssignOperator(+=)
185*0741a2c9SStefan Pintilie   WalkUpFromExpr CompoundAssignOperator(+=)
186*0741a2c9SStefan Pintilie     WalkUpFromStmt CompoundAssignOperator(+=)
187*0741a2c9SStefan Pintilie WalkUpFromExpr DeclRefExpr(a)
188*0741a2c9SStefan Pintilie   WalkUpFromStmt DeclRefExpr(a)
189*0741a2c9SStefan Pintilie WalkUpFromExpr IntegerLiteral(2)
190*0741a2c9SStefan Pintilie   WalkUpFromStmt IntegerLiteral(2)
191*0741a2c9SStefan Pintilie WalkUpFromExpr IntegerLiteral(3)
192*0741a2c9SStefan Pintilie   WalkUpFromStmt IntegerLiteral(3)
193*0741a2c9SStefan Pintilie )txt"));
194*0741a2c9SStefan Pintilie 
195*0741a2c9SStefan Pintilie   EXPECT_TRUE(visitorCallbackLogEqual(
196*0741a2c9SStefan Pintilie       RecordingVisitor(ShouldTraversePostOrder::Yes), Code,
197*0741a2c9SStefan Pintilie       R"txt(
198*0741a2c9SStefan Pintilie WalkUpFromExpr IntegerLiteral(1)
199*0741a2c9SStefan Pintilie   WalkUpFromStmt IntegerLiteral(1)
200*0741a2c9SStefan Pintilie WalkUpFromExpr DeclRefExpr(a)
201*0741a2c9SStefan Pintilie   WalkUpFromStmt DeclRefExpr(a)
202*0741a2c9SStefan Pintilie WalkUpFromExpr IntegerLiteral(2)
203*0741a2c9SStefan Pintilie   WalkUpFromStmt IntegerLiteral(2)
204*0741a2c9SStefan Pintilie WalkUpFromCompoundAssignOperator CompoundAssignOperator(+=)
205*0741a2c9SStefan Pintilie   WalkUpFromExpr CompoundAssignOperator(+=)
206*0741a2c9SStefan Pintilie     WalkUpFromStmt CompoundAssignOperator(+=)
207*0741a2c9SStefan Pintilie WalkUpFromExpr IntegerLiteral(3)
208*0741a2c9SStefan Pintilie   WalkUpFromStmt IntegerLiteral(3)
209*0741a2c9SStefan Pintilie WalkUpFromStmt CompoundStmt
210*0741a2c9SStefan Pintilie )txt"));
211*0741a2c9SStefan Pintilie }
212