clang 22.0.0git
EnterExpressionEvaluationContext.h
Go to the documentation of this file.
1//===--- EnterExpressionEvaluationContext.h ---------------------*- C++ -*-===//
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#ifndef LLVM_CLANG_SEMA_ENTEREXPRESSIONEVALUATIONCONTEXT_H
10#define LLVM_CLANG_SEMA_ENTEREXPRESSIONEVALUATIONCONTEXT_H
11
12#include "clang/Sema/Sema.h"
13
14namespace clang {
15
16class Decl;
17
18/// RAII object that enters a new expression evaluation context.
20 Sema &Actions;
21 bool Entered = true;
22
23public:
25 Sema &Actions, Sema::ExpressionEvaluationContext NewContext,
26 Decl *LambdaContextDecl = nullptr,
29 bool ShouldEnter = true)
30 : Actions(Actions), Entered(ShouldEnter) {
31 if (Entered)
32 Actions.PushExpressionEvaluationContext(NewContext, LambdaContextDecl,
33 ExprContext);
34 }
36 Sema &Actions, Sema::ExpressionEvaluationContext NewContext,
40 : Actions(Actions) {
41 Actions.PushExpressionEvaluationContext(
42 NewContext, Sema::ReuseLambdaContextDecl, ExprContext);
43 }
44
47 bool ShouldEnter = true)
48 : Actions(Actions), Entered(false) {
49 // In C++11 onwards, narrowing checks are performed on the contents of
50 // braced-init-lists, even when they occur within unevaluated operands.
51 // Therefore we still need to instantiate constexpr functions used in such
52 // a context.
53 if (ShouldEnter && Actions.isUnevaluatedContext() &&
54 Actions.getLangOpts().CPlusPlus11) {
55 Actions.PushExpressionEvaluationContext(
56 Sema::ExpressionEvaluationContext::UnevaluatedList);
57 Entered = true;
58 }
59 }
60
62 if (Entered)
63 Actions.PopExpressionEvaluationContext();
64 }
65};
66
67/// RAII object that enters a new function expression evaluation context.
69 Sema &Actions;
70
71public:
73 Sema &Actions, Sema::ExpressionEvaluationContext NewContext,
74 FunctionDecl *FD = nullptr)
75 : Actions(Actions) {
76 Actions.PushExpressionEvaluationContextForFunction(NewContext, FD);
77 }
79 Actions.PopExpressionEvaluationContext();
80 }
81};
82
83} // namespace clang
84
85#endif
Decl - This represents one declaration (or definition), e.g.
Definition DeclBase.h:86
EnterExpressionEvaluationContextForFunction(Sema &Actions, Sema::ExpressionEvaluationContext NewContext, FunctionDecl *FD=nullptr)
EnterExpressionEvaluationContext(Sema &Actions, InitListTag, bool ShouldEnter=true)
EnterExpressionEvaluationContext(Sema &Actions, Sema::ExpressionEvaluationContext NewContext, Sema::ReuseLambdaContextDecl_t, Sema::ExpressionEvaluationContextRecord::ExpressionKind ExprContext=Sema::ExpressionEvaluationContextRecord::EK_Other)
EnterExpressionEvaluationContext(Sema &Actions, Sema::ExpressionEvaluationContext NewContext, Decl *LambdaContextDecl=nullptr, Sema::ExpressionEvaluationContextRecord::ExpressionKind ExprContext=Sema::ExpressionEvaluationContextRecord::EK_Other, bool ShouldEnter=true)
Represents a function declaration or definition.
Definition Decl.h:1999
Sema - This implements semantic analysis and AST building for C.
Definition Sema.h:854
ReuseLambdaContextDecl_t
Definition Sema.h:6977
@ ReuseLambdaContextDecl
Definition Sema.h:6977
ExpressionEvaluationContext
Describes how the expressions currently being parsed are evaluated at run-time, if at all.
Definition Sema.h:6668
The JSON file list parser is used to communicate input to InstallAPI.
#define false
Definition stdbool.h:26
ExpressionKind
Describes whether we are in an expression constext which we have to handle differently.
Definition Sema.h:6787