1 //===- unittests/AST/ASTExprTest.cpp --- AST Expr tests -------------------===//
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 // This file contains tests for AST Expr related methods.
11 //===----------------------------------------------------------------------===//
14 #include "clang/AST/ASTContext.h"
15 #include "clang/AST/Expr.h"
16 #include "clang/AST/IgnoreExpr.h"
17 #include "clang/ASTMatchers/ASTMatchFinder.h"
18 #include "clang/Tooling/Tooling.h"
19 #include "gtest/gtest.h"
21 using namespace clang
;
23 TEST(ASTExpr
, IgnoreExprCallbackForwarded
) {
24 constexpr char Code
[] = "";
25 auto AST
= tooling::buildASTFromCodeWithArgs(Code
, /*Args=*/{"-std=c++20"});
26 ASTContext
&Ctx
= AST
->getASTContext();
28 auto createIntLiteral
= [&](uint32_t Value
) -> IntegerLiteral
* {
29 const int numBits
= 32;
30 return IntegerLiteral::Create(Ctx
, llvm::APInt(numBits
, Value
),
31 Ctx
.UnsignedIntTy
, {});
35 Expr
*operator()(Expr
*E
) & { return nullptr; }
36 Expr
*operator()(Expr
*E
) && {
37 if (auto *PE
= dyn_cast
<ParenExpr
>(E
)) {
38 return PE
->getSubExpr();
45 auto *IntExpr
= createIntLiteral(10);
47 new (Ctx
) ParenExpr(SourceLocation
{}, SourceLocation
{}, IntExpr
);
48 EXPECT_EQ(IntExpr
, IgnoreExprNodes(PE
, IgnoreParens
{}));
53 auto *IntExpr
= createIntLiteral(10);
55 new (Ctx
) ParenExpr(SourceLocation
{}, SourceLocation
{}, IntExpr
);
56 EXPECT_EQ(nullptr, IgnoreExprNodes(PE
, CB
));