1*a87dc23aSBalazs Benics //===- CallbacksCompoundAssignOperator.cpp --------------------------------===//
20741a2c9SStefan Pintilie //
30741a2c9SStefan Pintilie // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40741a2c9SStefan Pintilie // See https://llvm.org/LICENSE.txt for license information.
50741a2c9SStefan Pintilie // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60741a2c9SStefan Pintilie //
70741a2c9SStefan Pintilie //===----------------------------------------------------------------------===//
80741a2c9SStefan Pintilie 
90741a2c9SStefan Pintilie #include "CallbacksCommon.h"
100741a2c9SStefan Pintilie 
TEST(RecursiveASTVisitor,StmtCallbacks_TraverseCompoundAssignOperator)110741a2c9SStefan Pintilie TEST(RecursiveASTVisitor, StmtCallbacks_TraverseCompoundAssignOperator) {
120741a2c9SStefan Pintilie   class RecordingVisitor : public RecordingVisitorBase<RecordingVisitor> {
130741a2c9SStefan Pintilie   public:
140741a2c9SStefan Pintilie     RecordingVisitor(ShouldTraversePostOrder ShouldTraversePostOrderValue)
150741a2c9SStefan Pintilie         : RecordingVisitorBase(ShouldTraversePostOrderValue) {}
160741a2c9SStefan Pintilie 
170741a2c9SStefan Pintilie     bool TraverseCompoundAssignOperator(CompoundAssignOperator *CAO) {
180741a2c9SStefan Pintilie       recordCallback(__func__, CAO, [&]() {
190741a2c9SStefan Pintilie         RecordingVisitorBase::TraverseCompoundAssignOperator(CAO);
200741a2c9SStefan Pintilie       });
210741a2c9SStefan Pintilie       return true;
220741a2c9SStefan Pintilie     }
230741a2c9SStefan Pintilie 
240741a2c9SStefan Pintilie     bool WalkUpFromStmt(Stmt *S) {
250741a2c9SStefan Pintilie       recordCallback(__func__, S,
260741a2c9SStefan Pintilie                      [&]() { RecordingVisitorBase::WalkUpFromStmt(S); });
270741a2c9SStefan Pintilie       return true;
280741a2c9SStefan Pintilie     }
290741a2c9SStefan Pintilie   };
300741a2c9SStefan Pintilie 
310741a2c9SStefan Pintilie   StringRef Code = R"cpp(
320741a2c9SStefan Pintilie void test(int a) {
330741a2c9SStefan Pintilie   1;
340741a2c9SStefan Pintilie   a += 2;
350741a2c9SStefan Pintilie   3;
360741a2c9SStefan Pintilie }
370741a2c9SStefan Pintilie )cpp";
380741a2c9SStefan Pintilie 
390741a2c9SStefan Pintilie   EXPECT_TRUE(visitorCallbackLogEqual(
400741a2c9SStefan Pintilie       RecordingVisitor(ShouldTraversePostOrder::No), Code,
410741a2c9SStefan Pintilie       R"txt(
420741a2c9SStefan Pintilie WalkUpFromStmt CompoundStmt
430741a2c9SStefan Pintilie WalkUpFromStmt IntegerLiteral(1)
440741a2c9SStefan Pintilie TraverseCompoundAssignOperator CompoundAssignOperator(+=)
450741a2c9SStefan Pintilie   WalkUpFromStmt CompoundAssignOperator(+=)
460741a2c9SStefan Pintilie   WalkUpFromStmt DeclRefExpr(a)
470741a2c9SStefan Pintilie   WalkUpFromStmt IntegerLiteral(2)
480741a2c9SStefan Pintilie WalkUpFromStmt IntegerLiteral(3)
490741a2c9SStefan Pintilie )txt"));
500741a2c9SStefan Pintilie 
510741a2c9SStefan Pintilie   EXPECT_TRUE(visitorCallbackLogEqual(
520741a2c9SStefan Pintilie       RecordingVisitor(ShouldTraversePostOrder::Yes), Code,
530741a2c9SStefan Pintilie       R"txt(
540741a2c9SStefan Pintilie WalkUpFromStmt IntegerLiteral(1)
550741a2c9SStefan Pintilie TraverseCompoundAssignOperator CompoundAssignOperator(+=)
560741a2c9SStefan Pintilie   WalkUpFromStmt DeclRefExpr(a)
570741a2c9SStefan Pintilie   WalkUpFromStmt IntegerLiteral(2)
580741a2c9SStefan Pintilie   WalkUpFromStmt CompoundAssignOperator(+=)
590741a2c9SStefan Pintilie WalkUpFromStmt IntegerLiteral(3)
600741a2c9SStefan Pintilie WalkUpFromStmt CompoundStmt
610741a2c9SStefan Pintilie )txt"));
620741a2c9SStefan Pintilie }
630741a2c9SStefan Pintilie 
TEST(RecursiveASTVisitor,StmtCallbacks_TraverseCompoundAssignOperator_WalkUpFromCompoundAssignOperator)640741a2c9SStefan Pintilie TEST(
650741a2c9SStefan Pintilie     RecursiveASTVisitor,
660741a2c9SStefan Pintilie     StmtCallbacks_TraverseCompoundAssignOperator_WalkUpFromCompoundAssignOperator) {
670741a2c9SStefan Pintilie   class RecordingVisitor : public RecordingVisitorBase<RecordingVisitor> {
680741a2c9SStefan Pintilie   public:
690741a2c9SStefan Pintilie     RecordingVisitor(ShouldTraversePostOrder ShouldTraversePostOrderValue)
700741a2c9SStefan Pintilie         : RecordingVisitorBase(ShouldTraversePostOrderValue) {}
710741a2c9SStefan Pintilie 
720741a2c9SStefan Pintilie     bool TraverseCompoundAssignOperator(CompoundAssignOperator *CAO) {
730741a2c9SStefan Pintilie       recordCallback(__func__, CAO, [&]() {
740741a2c9SStefan Pintilie         RecordingVisitorBase::TraverseCompoundAssignOperator(CAO);
750741a2c9SStefan Pintilie       });
760741a2c9SStefan Pintilie       return true;
770741a2c9SStefan Pintilie     }
780741a2c9SStefan Pintilie 
790741a2c9SStefan Pintilie     bool WalkUpFromStmt(Stmt *S) {
800741a2c9SStefan Pintilie       recordCallback(__func__, S,
810741a2c9SStefan Pintilie                      [&]() { RecordingVisitorBase::WalkUpFromStmt(S); });
820741a2c9SStefan Pintilie       return true;
830741a2c9SStefan Pintilie     }
840741a2c9SStefan Pintilie 
850741a2c9SStefan Pintilie     bool WalkUpFromExpr(Expr *E) {
860741a2c9SStefan Pintilie       recordCallback(__func__, E,
870741a2c9SStefan Pintilie                      [&]() { RecordingVisitorBase::WalkUpFromExpr(E); });
880741a2c9SStefan Pintilie       return true;
890741a2c9SStefan Pintilie     }
900741a2c9SStefan Pintilie 
910741a2c9SStefan Pintilie     bool WalkUpFromCompoundAssignOperator(CompoundAssignOperator *CAO) {
920741a2c9SStefan Pintilie       recordCallback(__func__, CAO, [&]() {
930741a2c9SStefan Pintilie         RecordingVisitorBase::WalkUpFromCompoundAssignOperator(CAO);
940741a2c9SStefan Pintilie       });
950741a2c9SStefan Pintilie       return true;
960741a2c9SStefan Pintilie     }
970741a2c9SStefan Pintilie   };
980741a2c9SStefan Pintilie 
990741a2c9SStefan Pintilie   StringRef Code = R"cpp(
1000741a2c9SStefan Pintilie void test(int a) {
1010741a2c9SStefan Pintilie   1;
1020741a2c9SStefan Pintilie   a += 2;
1030741a2c9SStefan Pintilie   3;
1040741a2c9SStefan Pintilie }
1050741a2c9SStefan Pintilie )cpp";
1060741a2c9SStefan Pintilie 
1070741a2c9SStefan Pintilie   EXPECT_TRUE(visitorCallbackLogEqual(
1080741a2c9SStefan Pintilie       RecordingVisitor(ShouldTraversePostOrder::No), Code,
1090741a2c9SStefan Pintilie       R"txt(
1100741a2c9SStefan Pintilie WalkUpFromStmt CompoundStmt
1110741a2c9SStefan Pintilie WalkUpFromExpr IntegerLiteral(1)
1120741a2c9SStefan Pintilie   WalkUpFromStmt IntegerLiteral(1)
1130741a2c9SStefan Pintilie TraverseCompoundAssignOperator CompoundAssignOperator(+=)
1140741a2c9SStefan Pintilie   WalkUpFromCompoundAssignOperator CompoundAssignOperator(+=)
1150741a2c9SStefan Pintilie     WalkUpFromExpr CompoundAssignOperator(+=)
1160741a2c9SStefan Pintilie       WalkUpFromStmt CompoundAssignOperator(+=)
1170741a2c9SStefan Pintilie   WalkUpFromExpr DeclRefExpr(a)
1180741a2c9SStefan Pintilie     WalkUpFromStmt DeclRefExpr(a)
1190741a2c9SStefan Pintilie   WalkUpFromExpr IntegerLiteral(2)
1200741a2c9SStefan Pintilie     WalkUpFromStmt IntegerLiteral(2)
1210741a2c9SStefan Pintilie WalkUpFromExpr IntegerLiteral(3)
1220741a2c9SStefan Pintilie   WalkUpFromStmt IntegerLiteral(3)
1230741a2c9SStefan Pintilie )txt"));
1240741a2c9SStefan Pintilie 
1250741a2c9SStefan Pintilie   EXPECT_TRUE(visitorCallbackLogEqual(
1260741a2c9SStefan Pintilie       RecordingVisitor(ShouldTraversePostOrder::Yes), Code,
1270741a2c9SStefan Pintilie       R"txt(
1280741a2c9SStefan Pintilie WalkUpFromExpr IntegerLiteral(1)
1290741a2c9SStefan Pintilie   WalkUpFromStmt IntegerLiteral(1)
1300741a2c9SStefan Pintilie TraverseCompoundAssignOperator CompoundAssignOperator(+=)
1310741a2c9SStefan Pintilie   WalkUpFromExpr DeclRefExpr(a)
1320741a2c9SStefan Pintilie     WalkUpFromStmt DeclRefExpr(a)
1330741a2c9SStefan Pintilie   WalkUpFromExpr IntegerLiteral(2)
1340741a2c9SStefan Pintilie     WalkUpFromStmt IntegerLiteral(2)
1350741a2c9SStefan Pintilie   WalkUpFromCompoundAssignOperator CompoundAssignOperator(+=)
1360741a2c9SStefan Pintilie     WalkUpFromExpr CompoundAssignOperator(+=)
1370741a2c9SStefan Pintilie       WalkUpFromStmt CompoundAssignOperator(+=)
1380741a2c9SStefan Pintilie WalkUpFromExpr IntegerLiteral(3)
1390741a2c9SStefan Pintilie   WalkUpFromStmt IntegerLiteral(3)
1400741a2c9SStefan Pintilie WalkUpFromStmt CompoundStmt
1410741a2c9SStefan Pintilie )txt"));
1420741a2c9SStefan Pintilie }
1430741a2c9SStefan Pintilie 
TEST(RecursiveASTVisitor,StmtCallbacks_WalkUpFromCompoundAssignOperator)1440741a2c9SStefan Pintilie TEST(RecursiveASTVisitor, StmtCallbacks_WalkUpFromCompoundAssignOperator) {
1450741a2c9SStefan Pintilie   class RecordingVisitor : public RecordingVisitorBase<RecordingVisitor> {
1460741a2c9SStefan Pintilie   public:
1470741a2c9SStefan Pintilie     RecordingVisitor(ShouldTraversePostOrder ShouldTraversePostOrderValue)
1480741a2c9SStefan Pintilie         : RecordingVisitorBase(ShouldTraversePostOrderValue) {}
1490741a2c9SStefan Pintilie 
1500741a2c9SStefan Pintilie     bool WalkUpFromStmt(Stmt *S) {
1510741a2c9SStefan Pintilie       recordCallback(__func__, S,
1520741a2c9SStefan Pintilie                      [&]() { RecordingVisitorBase::WalkUpFromStmt(S); });
1530741a2c9SStefan Pintilie       return true;
1540741a2c9SStefan Pintilie     }
1550741a2c9SStefan Pintilie 
1560741a2c9SStefan Pintilie     bool WalkUpFromExpr(Expr *E) {
1570741a2c9SStefan Pintilie       recordCallback(__func__, E,
1580741a2c9SStefan Pintilie                      [&]() { RecordingVisitorBase::WalkUpFromExpr(E); });
1590741a2c9SStefan Pintilie       return true;
1600741a2c9SStefan Pintilie     }
1610741a2c9SStefan Pintilie 
1620741a2c9SStefan Pintilie     bool WalkUpFromCompoundAssignOperator(CompoundAssignOperator *CAO) {
1630741a2c9SStefan Pintilie       recordCallback(__func__, CAO, [&]() {
1640741a2c9SStefan Pintilie         RecordingVisitorBase::WalkUpFromCompoundAssignOperator(CAO);
1650741a2c9SStefan Pintilie       });
1660741a2c9SStefan Pintilie       return true;
1670741a2c9SStefan Pintilie     }
1680741a2c9SStefan Pintilie   };
1690741a2c9SStefan Pintilie 
1700741a2c9SStefan Pintilie   StringRef Code = R"cpp(
1710741a2c9SStefan Pintilie void test(int a) {
1720741a2c9SStefan Pintilie   1;
1730741a2c9SStefan Pintilie   a += 2;
1740741a2c9SStefan Pintilie   3;
1750741a2c9SStefan Pintilie }
1760741a2c9SStefan Pintilie )cpp";
1770741a2c9SStefan Pintilie 
1780741a2c9SStefan Pintilie   EXPECT_TRUE(visitorCallbackLogEqual(
1790741a2c9SStefan Pintilie       RecordingVisitor(ShouldTraversePostOrder::No), Code,
1800741a2c9SStefan Pintilie       R"txt(
1810741a2c9SStefan Pintilie WalkUpFromStmt CompoundStmt
1820741a2c9SStefan Pintilie WalkUpFromExpr IntegerLiteral(1)
1830741a2c9SStefan Pintilie   WalkUpFromStmt IntegerLiteral(1)
1840741a2c9SStefan Pintilie WalkUpFromCompoundAssignOperator CompoundAssignOperator(+=)
1850741a2c9SStefan Pintilie   WalkUpFromExpr CompoundAssignOperator(+=)
1860741a2c9SStefan Pintilie     WalkUpFromStmt CompoundAssignOperator(+=)
1870741a2c9SStefan Pintilie WalkUpFromExpr DeclRefExpr(a)
1880741a2c9SStefan Pintilie   WalkUpFromStmt DeclRefExpr(a)
1890741a2c9SStefan Pintilie WalkUpFromExpr IntegerLiteral(2)
1900741a2c9SStefan Pintilie   WalkUpFromStmt IntegerLiteral(2)
1910741a2c9SStefan Pintilie WalkUpFromExpr IntegerLiteral(3)
1920741a2c9SStefan Pintilie   WalkUpFromStmt IntegerLiteral(3)
1930741a2c9SStefan Pintilie )txt"));
1940741a2c9SStefan Pintilie 
1950741a2c9SStefan Pintilie   EXPECT_TRUE(visitorCallbackLogEqual(
1960741a2c9SStefan Pintilie       RecordingVisitor(ShouldTraversePostOrder::Yes), Code,
1970741a2c9SStefan Pintilie       R"txt(
1980741a2c9SStefan Pintilie WalkUpFromExpr IntegerLiteral(1)
1990741a2c9SStefan Pintilie   WalkUpFromStmt IntegerLiteral(1)
2000741a2c9SStefan Pintilie WalkUpFromExpr DeclRefExpr(a)
2010741a2c9SStefan Pintilie   WalkUpFromStmt DeclRefExpr(a)
2020741a2c9SStefan Pintilie WalkUpFromExpr IntegerLiteral(2)
2030741a2c9SStefan Pintilie   WalkUpFromStmt IntegerLiteral(2)
2040741a2c9SStefan Pintilie WalkUpFromCompoundAssignOperator CompoundAssignOperator(+=)
2050741a2c9SStefan Pintilie   WalkUpFromExpr CompoundAssignOperator(+=)
2060741a2c9SStefan Pintilie     WalkUpFromStmt CompoundAssignOperator(+=)
2070741a2c9SStefan Pintilie WalkUpFromExpr IntegerLiteral(3)
2080741a2c9SStefan Pintilie   WalkUpFromStmt IntegerLiteral(3)
2090741a2c9SStefan Pintilie WalkUpFromStmt CompoundStmt
2100741a2c9SStefan Pintilie )txt"));
2110741a2c9SStefan Pintilie }
212