1 //===- unittests/Tooling/RecursiveASTVisitorTests/CallbacksUnaryOperator.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_TraverseUnaryOperator
) {
12 class RecordingVisitor
: public RecordingVisitorBase
<RecordingVisitor
> {
14 RecordingVisitor(ShouldTraversePostOrder ShouldTraversePostOrderValue
)
15 : RecordingVisitorBase(ShouldTraversePostOrderValue
) {}
17 bool TraverseUnaryOperator(UnaryOperator
*UO
) {
18 recordCallback(__func__
, UO
, [&]() {
19 RecordingVisitorBase::TraverseUnaryOperator(UO
);
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 TraverseUnaryOperator UnaryOperator(-)
45 WalkUpFromStmt UnaryOperator(-)
46 WalkUpFromStmt IntegerLiteral(2)
47 WalkUpFromStmt IntegerLiteral(3)
50 EXPECT_TRUE(visitorCallbackLogEqual(
51 RecordingVisitor(ShouldTraversePostOrder::Yes
), Code
,
53 WalkUpFromStmt IntegerLiteral(1)
54 TraverseUnaryOperator UnaryOperator(-)
55 WalkUpFromStmt IntegerLiteral(2)
56 WalkUpFromStmt UnaryOperator(-)
57 WalkUpFromStmt IntegerLiteral(3)
58 WalkUpFromStmt CompoundStmt
62 TEST(RecursiveASTVisitor
,
63 StmtCallbacks_TraverseUnaryOperator_WalkUpFromUnaryOperator
) {
64 class RecordingVisitor
: public RecordingVisitorBase
<RecordingVisitor
> {
66 RecordingVisitor(ShouldTraversePostOrder ShouldTraversePostOrderValue
)
67 : RecordingVisitorBase(ShouldTraversePostOrderValue
) {}
69 bool TraverseUnaryOperator(UnaryOperator
*UO
) {
70 recordCallback(__func__
, UO
, [&]() {
71 RecordingVisitorBase::TraverseUnaryOperator(UO
);
76 bool WalkUpFromStmt(Stmt
*S
) {
77 recordCallback(__func__
, S
,
78 [&]() { RecordingVisitorBase::WalkUpFromStmt(S
); });
82 bool WalkUpFromExpr(Expr
*E
) {
83 recordCallback(__func__
, E
,
84 [&]() { RecordingVisitorBase::WalkUpFromExpr(E
); });
88 bool WalkUpFromUnaryOperator(UnaryOperator
*UO
) {
89 recordCallback(__func__
, UO
, [&]() {
90 RecordingVisitorBase::WalkUpFromUnaryOperator(UO
);
96 StringRef Code
= R
"cpp(
104 EXPECT_TRUE(visitorCallbackLogEqual(
105 RecordingVisitor(ShouldTraversePostOrder::No
), Code
,
107 WalkUpFromStmt CompoundStmt
108 WalkUpFromExpr IntegerLiteral(1)
109 WalkUpFromStmt IntegerLiteral(1)
110 TraverseUnaryOperator UnaryOperator(-)
111 WalkUpFromUnaryOperator UnaryOperator(-)
112 WalkUpFromExpr UnaryOperator(-)
113 WalkUpFromStmt UnaryOperator(-)
114 WalkUpFromExpr IntegerLiteral(2)
115 WalkUpFromStmt IntegerLiteral(2)
116 WalkUpFromExpr IntegerLiteral(3)
117 WalkUpFromStmt IntegerLiteral(3)
120 EXPECT_TRUE(visitorCallbackLogEqual(
121 RecordingVisitor(ShouldTraversePostOrder::Yes
), Code
,
123 WalkUpFromExpr IntegerLiteral(1)
124 WalkUpFromStmt IntegerLiteral(1)
125 TraverseUnaryOperator UnaryOperator(-)
126 WalkUpFromExpr IntegerLiteral(2)
127 WalkUpFromStmt IntegerLiteral(2)
128 WalkUpFromUnaryOperator UnaryOperator(-)
129 WalkUpFromExpr UnaryOperator(-)
130 WalkUpFromStmt UnaryOperator(-)
131 WalkUpFromExpr IntegerLiteral(3)
132 WalkUpFromStmt IntegerLiteral(3)
133 WalkUpFromStmt CompoundStmt
137 TEST(RecursiveASTVisitor
, StmtCallbacks_WalkUpFromUnaryOperator
) {
138 class RecordingVisitor
: public RecordingVisitorBase
<RecordingVisitor
> {
140 RecordingVisitor(ShouldTraversePostOrder ShouldTraversePostOrderValue
)
141 : RecordingVisitorBase(ShouldTraversePostOrderValue
) {}
143 bool WalkUpFromStmt(Stmt
*S
) {
144 recordCallback(__func__
, S
,
145 [&]() { RecordingVisitorBase::WalkUpFromStmt(S
); });
149 bool WalkUpFromExpr(Expr
*E
) {
150 recordCallback(__func__
, E
,
151 [&]() { RecordingVisitorBase::WalkUpFromExpr(E
); });
155 bool WalkUpFromUnaryOperator(UnaryOperator
*UO
) {
156 recordCallback(__func__
, UO
, [&]() {
157 RecordingVisitorBase::WalkUpFromUnaryOperator(UO
);
163 StringRef Code
= R
"cpp(
171 EXPECT_TRUE(visitorCallbackLogEqual(
172 RecordingVisitor(ShouldTraversePostOrder::No
), Code
,
174 WalkUpFromStmt CompoundStmt
175 WalkUpFromExpr IntegerLiteral(1)
176 WalkUpFromStmt IntegerLiteral(1)
177 WalkUpFromUnaryOperator UnaryOperator(-)
178 WalkUpFromExpr UnaryOperator(-)
179 WalkUpFromStmt UnaryOperator(-)
180 WalkUpFromExpr IntegerLiteral(2)
181 WalkUpFromStmt IntegerLiteral(2)
182 WalkUpFromExpr IntegerLiteral(3)
183 WalkUpFromStmt IntegerLiteral(3)
186 EXPECT_TRUE(visitorCallbackLogEqual(
187 RecordingVisitor(ShouldTraversePostOrder::Yes
), Code
,
189 WalkUpFromExpr IntegerLiteral(1)
190 WalkUpFromStmt IntegerLiteral(1)
191 WalkUpFromExpr IntegerLiteral(2)
192 WalkUpFromStmt IntegerLiteral(2)
193 WalkUpFromUnaryOperator UnaryOperator(-)
194 WalkUpFromExpr UnaryOperator(-)
195 WalkUpFromStmt UnaryOperator(-)
196 WalkUpFromExpr IntegerLiteral(3)
197 WalkUpFromStmt IntegerLiteral(3)
198 WalkUpFromStmt CompoundStmt