clang 22.0.0git
State.h
Go to the documentation of this file.
1//===--- State.h - State chain for the VM and AST Walker --------*- 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// Defines the base class of the interpreter and evaluator state.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_CLANG_AST_INTERP_STATE_H
14#define LLVM_CLANG_AST_INTERP_STATE_H
15
17#include "clang/AST/Expr.h"
18
19namespace clang {
20class OptionalDiagnostic;
21
22/// Kinds of access we can perform on an object, for diagnostics. Note that
23/// we consider a member function call to be a kind of access, even though
24/// it is not formally an access of the object, because it has (largely) the
25/// same set of semantic restrictions.
39};
40
41/// The order of this enum is important for diagnostics.
51};
52
53namespace interp {
54class Frame;
55class SourceInfo;
56
57/// Interface for the VM to interact with the AST walker's context.
58class State {
59public:
60 virtual ~State();
61
62 virtual bool checkingForUndefinedBehavior() const = 0;
63 virtual bool checkingPotentialConstantExpression() const = 0;
64 virtual bool noteUndefinedBehavior() = 0;
65 virtual bool keepEvaluatingAfterFailure() const = 0;
66 virtual bool keepEvaluatingAfterSideEffect() const = 0;
67 virtual Frame *getCurrentFrame() = 0;
68 virtual const Frame *getBottomFrame() const = 0;
69 virtual bool hasActiveDiagnostic() = 0;
70 virtual void setActiveDiagnostic(bool Flag) = 0;
71 virtual void setFoldFailureDiagnostic(bool Flag) = 0;
72 virtual Expr::EvalStatus &getEvalStatus() const = 0;
73 virtual ASTContext &getASTContext() const = 0;
74 virtual bool hasPriorDiagnostic() = 0;
75 virtual unsigned getCallStackDepth() = 0;
76 virtual bool noteSideEffect() = 0;
77
78public:
79 State() = default;
80 /// Diagnose that the evaluation could not be folded (FF => FoldFailure)
83 diag::kind DiagId = diag::note_invalid_subexpr_in_const_expr,
84 unsigned ExtraNotes = 0);
85
87 FFDiag(const Expr *E,
88 diag::kind DiagId = diag::note_invalid_subexpr_in_const_expr,
89 unsigned ExtraNotes = 0);
90
92 FFDiag(const SourceInfo &SI,
93 diag::kind DiagId = diag::note_invalid_subexpr_in_const_expr,
94 unsigned ExtraNotes = 0);
95
96 /// Diagnose that the evaluation does not produce a C++11 core constant
97 /// expression.
98 ///
99 /// FIXME: Stop evaluating if we're in EM_ConstantExpression or
100 /// EM_PotentialConstantExpression mode and we produce one of these.
103 diag::kind DiagId = diag::note_invalid_subexpr_in_const_expr,
104 unsigned ExtraNotes = 0);
105
107 CCEDiag(const Expr *E,
108 diag::kind DiagId = diag::note_invalid_subexpr_in_const_expr,
109 unsigned ExtraNotes = 0);
110
112 CCEDiag(const SourceInfo &SI,
113 diag::kind DiagId = diag::note_invalid_subexpr_in_const_expr,
114 unsigned ExtraNotes = 0);
115
116 /// Add a note to a prior diagnostic.
118
119 /// Add a stack of notes to a prior diagnostic.
121
122 /// Directly reports a diagnostic message.
124
125 const LangOptions &getLangOpts() const;
126
127 /// Whether or not we're in a context where the front end requires a
128 /// constant value.
129 bool InConstantContext = false;
130
131private:
132 void addCallStack(unsigned Limit);
133
135
137 unsigned ExtraNotes, bool IsCCEDiag);
138};
139
140} // namespace interp
141} // namespace clang
142
143#endif
Expr * E
SourceLocation Loc
Definition: SemaObjC.cpp:754
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:188
A little helper class used to produce diagnostics.
Definition: Diagnostic.h:1233
This represents one expression.
Definition: Expr.h:112
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:434
A partial diagnostic which we might know in advance that we are not going to emit.
Encodes a location in the source.
Base class for stack frames, shared between VM and walker.
Definition: Frame.h:25
Describes the statement/declaration an opcode was generated from.
Definition: Source.h:73
Interface for the VM to interact with the AST walker's context.
Definition: State.h:58
virtual bool hasActiveDiagnostic()=0
virtual void setActiveDiagnostic(bool Flag)=0
virtual bool checkingPotentialConstantExpression() const =0
DiagnosticBuilder report(SourceLocation Loc, diag::kind DiagId)
Directly reports a diagnostic message.
Definition: State.cpp:74
virtual Frame * getCurrentFrame()=0
virtual bool noteUndefinedBehavior()=0
OptionalDiagnostic FFDiag(SourceLocation Loc, diag::kind DiagId=diag::note_invalid_subexpr_in_const_expr, unsigned ExtraNotes=0)
Diagnose that the evaluation could not be folded (FF => FoldFailure)
Definition: State.cpp:21
virtual Expr::EvalStatus & getEvalStatus() const =0
virtual unsigned getCallStackDepth()=0
virtual bool checkingForUndefinedBehavior() const =0
virtual bool keepEvaluatingAfterFailure() const =0
void addNotes(ArrayRef< PartialDiagnosticAt > Diags)
Add a stack of notes to a prior diagnostic.
Definition: State.cpp:69
virtual const Frame * getBottomFrame() const =0
const LangOptions & getLangOpts() const
Definition: State.cpp:115
OptionalDiagnostic CCEDiag(SourceLocation Loc, diag::kind DiagId=diag::note_invalid_subexpr_in_const_expr, unsigned ExtraNotes=0)
Diagnose that the evaluation does not produce a C++11 core constant expression.
Definition: State.cpp:42
virtual void setFoldFailureDiagnostic(bool Flag)=0
virtual bool noteSideEffect()=0
virtual bool hasPriorDiagnostic()=0
virtual bool keepEvaluatingAfterSideEffect() const =0
bool InConstantContext
Whether or not we're in a context where the front end requires a constant value.
Definition: State.h:129
virtual ASTContext & getASTContext() const =0
virtual ~State()
Definition: State.cpp:19
The JSON file list parser is used to communicate input to InstallAPI.
CheckSubobjectKind
The order of this enum is important for diagnostics.
Definition: State.h:42
@ CSK_ArrayToPointer
Definition: State.h:46
@ CSK_Derived
Definition: State.h:44
@ CSK_Base
Definition: State.h:43
@ CSK_Real
Definition: State.h:48
@ CSK_ArrayIndex
Definition: State.h:47
@ CSK_Imag
Definition: State.h:49
@ CSK_VectorElement
Definition: State.h:50
@ CSK_Field
Definition: State.h:45
AccessKinds
Kinds of access we can perform on an object, for diagnostics.
Definition: State.h:26
@ AK_TypeId
Definition: State.h:34
@ AK_Construct
Definition: State.h:35
@ AK_Increment
Definition: State.h:30
@ AK_DynamicCast
Definition: State.h:33
@ AK_Read
Definition: State.h:27
@ AK_Assign
Definition: State.h:29
@ AK_IsWithinLifetime
Definition: State.h:37
@ AK_MemberCall
Definition: State.h:32
@ AK_ReadObjectRepresentation
Definition: State.h:28
@ AK_Dereference
Definition: State.h:38
@ AK_Destroy
Definition: State.h:36
@ AK_Decrement
Definition: State.h:31
EvalStatus is a struct with detailed info about an evaluation in progress.
Definition: Expr.h:609