clang 20.0.0git
IgnoreExpr.h
Go to the documentation of this file.
1//===--- IgnoreExpr.h - Ignore intermediate Expressions -----------------===//
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//===----------------------------------------------------------------------===//
8//
9// This file defines common functions to ignore intermediate expression nodes
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_CLANG_AST_IGNOREEXPR_H
14#define LLVM_CLANG_AST_IGNOREEXPR_H
15
16#include "clang/AST/Expr.h"
17#include "clang/AST/ExprCXX.h"
18
19namespace clang {
20namespace detail {
21/// Given an expression E and functions Fn_1,...,Fn_n : Expr * -> Expr *,
22/// Return Fn_n(...(Fn_1(E)))
23inline Expr *IgnoreExprNodesImpl(Expr *E) { return E; }
24template <typename FnTy, typename... FnTys>
25Expr *IgnoreExprNodesImpl(Expr *E, FnTy &&Fn, FnTys &&... Fns) {
26 return IgnoreExprNodesImpl(std::forward<FnTy>(Fn)(E),
27 std::forward<FnTys>(Fns)...);
28}
29} // namespace detail
30
31/// Given an expression E and functions Fn_1,...,Fn_n : Expr * -> Expr *,
32/// Recursively apply each of the functions to E until reaching a fixed point.
33/// Note that a null E is valid; in this case nothing is done.
34template <typename... FnTys> Expr *IgnoreExprNodes(Expr *E, FnTys &&... Fns) {
35 Expr *LastE = nullptr;
36 while (E != LastE) {
37 LastE = E;
38 E = detail::IgnoreExprNodesImpl(E, std::forward<FnTys>(Fns)...);
39 }
40 return E;
41}
42
43template <typename... FnTys>
44const Expr *IgnoreExprNodes(const Expr *E, FnTys &&...Fns) {
45 return IgnoreExprNodes(const_cast<Expr *>(E), std::forward<FnTys>(Fns)...);
46}
47
49 if (auto *ICE = dyn_cast<ImplicitCastExpr>(