Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / unittests / Tooling / RecursiveASTVisitorTests / CallbacksUnaryOperator.cpp
blob26c755599be800c5fd840768c17704b92d48d8fc
1 //===- unittests/Tooling/RecursiveASTVisitorTests/CallbacksUnaryOperator.cpp -===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
9 #include "CallbacksCommon.h"
11 TEST(RecursiveASTVisitor, StmtCallbacks_TraverseUnaryOperator) {
12 class RecordingVisitor : public RecordingVisitorBase<RecordingVisitor> {
13 public:
14 RecordingVisitor(ShouldTraversePostOrder ShouldTraversePostOrderValue)
15 : RecordingVisitorBase(ShouldTraversePostOrderValue) {}
17 bool TraverseUnaryOperator(UnaryOperator *UO) {
18 recordCallback(__func__, UO, [&]() {
19 RecordingVisitorBase::TraverseUnaryOperator(UO);
20 });
21 return true;
24 bool WalkUpFromStmt(Stmt *S) {
25 recordCallback(__func__, S,
26 [&]() { RecordingVisitorBase::WalkUpFromStmt(S); });
27 return true;
31 StringRef Code = R"cpp(
32 void test() {
34 -2;
37 )cpp";
39 EXPECT_TRUE(visitorCallbackLogEqual(
40 RecordingVisitor(ShouldTraversePostOrder::No), Code,
41 R"txt(
42 WalkUpFromStmt CompoundStmt
43 WalkUpFromStmt IntegerLiteral(1)
44 TraverseUnaryOperator UnaryOperator(-)
45 WalkUpFromStmt UnaryOperator(-)
46 WalkUpFromStmt IntegerLiteral(2)
47 WalkUpFromStmt IntegerLiteral(3)
48 )txt"));
50 EXPECT_TRUE(visitorCallbackLogEqual(
51 RecordingVisitor(ShouldTraversePostOrder::Yes), Code,
52 R"txt(
53 WalkUpFromStmt IntegerLiteral(1)
54 TraverseUnaryOperator UnaryOperator(-)
55 WalkUpFromStmt IntegerLiteral(2)
56 WalkUpFromStmt UnaryOperator(-)
57 WalkUpFromStmt IntegerLiteral(3)
58 WalkUpFromStmt CompoundStmt
59 )txt"));
62 TEST(RecursiveASTVisitor,
63 StmtCallbacks_TraverseUnaryOperator_WalkUpFromUnaryOperator) {
64 class RecordingVisitor : public RecordingVisitorBase<RecordingVisitor> {
65 public:
66 RecordingVisitor(ShouldTraversePostOrder ShouldTraversePostOrderValue)
67 : RecordingVisitorBase(ShouldTraversePostOrderValue) {}
69 bool TraverseUnaryOperator(UnaryOperator *UO) {
70 recordCallback(__func__, UO, [&]() {
71 RecordingVisitorBase::TraverseUnaryOperator(UO);
72 });
73 return true;
76 bool WalkUpFromStmt(Stmt *S) {
77 recordCallback(__func__, S,
78 [&]() { RecordingVisitorBase::WalkUpFromStmt(S); });
79 return true;
82 bool WalkUpFromExpr(Expr *E) {
83 recordCallback(__func__, E,
84 [&]() { RecordingVisitorBase::WalkUpFromExpr(E); });
85 return true;
88 bool WalkUpFromUnaryOperator(UnaryOperator *UO) {
89 recordCallback(__func__, UO, [&]() {
90 RecordingVisitorBase::WalkUpFromUnaryOperator(UO);
91 });
92 return true;
96 StringRef Code = R"cpp(
97 void test() {
99 -2;
102 )cpp";
104 EXPECT_TRUE(visitorCallbackLogEqual(
105 RecordingVisitor(ShouldTraversePostOrder::No), Code,
106 R"txt(
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)
118 )txt"));
120 EXPECT_TRUE(visitorCallbackLogEqual(
121 RecordingVisitor(ShouldTraversePostOrder::Yes), Code,
122 R"txt(
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
134 )txt"));
137 TEST(RecursiveASTVisitor, StmtCallbacks_WalkUpFromUnaryOperator) {
138 class RecordingVisitor : public RecordingVisitorBase<RecordingVisitor> {
139 public:
140 RecordingVisitor(ShouldTraversePostOrder ShouldTraversePostOrderValue)
141 : RecordingVisitorBase(ShouldTraversePostOrderValue) {}
143 bool WalkUpFromStmt(Stmt *S) {
144 recordCallback(__func__, S,
145 [&]() { RecordingVisitorBase::WalkUpFromStmt(S); });
146 return true;
149 bool WalkUpFromExpr(Expr *E) {
150 recordCallback(__func__, E,
151 [&]() { RecordingVisitorBase::WalkUpFromExpr(E); });
152 return true;
155 bool WalkUpFromUnaryOperator(UnaryOperator *UO) {
156 recordCallback(__func__, UO, [&]() {
157 RecordingVisitorBase::WalkUpFromUnaryOperator(UO);
159 return true;
163 StringRef Code = R"cpp(
164 void test() {
169 )cpp";
171 EXPECT_TRUE(visitorCallbackLogEqual(
172 RecordingVisitor(ShouldTraversePostOrder::No), Code,
173 R"txt(
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)
184 )txt"));
186 EXPECT_TRUE(visitorCallbackLogEqual(
187 RecordingVisitor(ShouldTraversePostOrder::Yes), Code,
188 R"txt(
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
199 )txt"));