clang  19.0.0git
Public Member Functions | Static Public Member Functions | List of all members
clang::interp::Context Class Referencefinal

Holds all information required to evaluate constexpr code in a module. More...

#include "/home/runner/work/llvm/llvm/repo/clang/lib/AST/Interp/Context.h"

Public Member Functions

 Context (ASTContext &Ctx)
 Initialises the constexpr VM. More...
 
 ~Context ()
 Cleans up the constexpr VM. More...
 
bool isPotentialConstantExpr (State &Parent, const FunctionDecl *FnDecl)
 Checks if a function is a potential constant expression. More...
 
bool evaluateAsRValue (State &Parent, const Expr *E, APValue &Result)
 Evaluates a toplevel expression as an rvalue. More...
 
bool evaluate (State &Parent, const Expr *E, APValue &Result)
 Like evaluateAsRvalue(), but does no implicit lvalue-to-rvalue conversion. More...
 
bool evaluateAsInitializer (State &Parent, const VarDecl *VD, APValue &Result)
 Evaluates a toplevel initializer. More...
 
ASTContextgetASTContext () const
 Returns the AST context. More...
 
const LangOptionsgetLangOpts () const
 Returns the language options. More...
 
InterpStackgetStack ()
 Returns the interpreter stack. More...
 
unsigned getCharBit () const
 Returns CHAR_BIT. More...
 
const llvm::fltSemantics & getFloatSemantics (QualType T) const
 Return the floating-point semantics for T. More...
 
uint32_t getBitWidth (QualType T) const
 Return the size of T in bits. More...
 
std::optional< PrimTypeclassify (QualType T) const
 Classifies a type. More...
 
std::optional< PrimTypeclassify (const Expr *E) const
 Classifies an expression. More...
 
const CXXMethodDeclgetOverridingFunction (const CXXRecordDecl *DynamicDecl, const CXXRecordDecl *StaticDecl, const CXXMethodDecl *InitialFunction) const
 
const FunctiongetOrCreateFunction (const FunctionDecl *FD)
 
ProgramgetProgram () const
 Returns the program. This is only needed for unittests. More...
 
unsigned collectBaseOffset (const RecordDecl *BaseDecl, const RecordDecl *DerivedDecl) const
 

Static Public Member Functions

static bool shouldBeGloballyIndexed (const ValueDecl *VD)
 Returns whether we should create a global variable for the given ValueDecl. More...
 

Detailed Description

Holds all information required to evaluate constexpr code in a module.

Definition at line 40 of file Context.h.

Constructor & Destructor Documentation

◆ Context()

Context::Context ( ASTContext Ctx)

Initialises the constexpr VM.

Definition at line 25 of file Context.cpp.

◆ ~Context()

Context::~Context ( )

Cleans up the constexpr VM.

Definition at line 27 of file Context.cpp.

Member Function Documentation

◆ classify() [1/2]

std::optional<PrimType> clang::interp::Context::classify ( const Expr E) const
inline

◆ classify() [2/2]

std::optional< PrimType > Context::classify ( QualType  T) const

◆ collectBaseOffset()

unsigned Context::collectBaseOffset ( const RecordDecl BaseDecl,
const RecordDecl DerivedDecl 
) const

◆ evaluate()

bool Context::evaluate ( State Parent,
const Expr E,
APValue Result 
)

Like evaluateAsRvalue(), but does no implicit lvalue-to-rvalue conversion.

Definition at line 67 of file Context.cpp.

References clang::interp::InterpStack::clear(), clang::interp::InterpStack::empty(), and Parent.

◆ evaluateAsInitializer()

bool Context::evaluateAsInitializer ( State Parent,
const VarDecl VD,
APValue Result 
)

◆ evaluateAsRValue()

bool Context::evaluateAsRValue ( State Parent,
const Expr E,
APValue Result 
)

Evaluates a toplevel expression as an rvalue.

Definition at line 42 of file Context.cpp.

References clang::interp::InterpStack::clear(), clang::interp::InterpStack::empty(), clang::Expr::isGLValue(), and Parent.

◆ getASTContext()

ASTContext& clang::interp::Context::getASTContext ( ) const
inline

Returns the AST context.

Definition at line 61 of file Context.h.

Referenced by clang::interp::EvaluationResult::dump(), and clang::interp::Pointer::toRValue().

◆ getBitWidth()

uint32_t clang::interp::Context::getBitWidth ( QualType  T) const
inline

Return the size of T in bits.

Definition at line 71 of file Context.h.

References clang::ASTContext::getIntWidth(), and clang::T.

◆ getCharBit()

unsigned Context::getCharBit ( ) const

Returns CHAR_BIT.

Definition at line 183 of file Context.cpp.

References clang::TargetInfo::getCharWidth(), and clang::ASTContext::getTargetInfo().

◆ getFloatSemantics()

const llvm::fltSemantics & Context::getFloatSemantics ( QualType  T) const

Return the floating-point semantics for T.

Simple wrapper around getFloatTypeSemantics() to make code a little shorter.

Definition at line 189 of file Context.cpp.

References clang::ASTContext::getFloatTypeSemantics(), and clang::T.

◆ getLangOpts()

const LangOptions & Context::getLangOpts ( ) const

Returns the language options.

Definition at line 117 of file Context.cpp.

References clang::ASTContext::getLangOpts().

◆ getOrCreateFunction()

const Function * Context::getOrCreateFunction ( const FunctionDecl FD)

Definition at line 250 of file Context.cpp.

References clang::Func.

◆ getOverridingFunction()

const CXXMethodDecl * Context::getOverridingFunction ( const CXXRecordDecl DynamicDecl,
const CXXRecordDecl StaticDecl,
const CXXMethodDecl InitialFunction 
) const

◆ getProgram()

Program& clang::interp::Context::getProgram ( ) const
inline

Returns the program. This is only needed for unittests.

Definition at line 105 of file Context.h.

◆ getStack()

InterpStack& clang::interp::Context::getStack ( )
inline

Returns the interpreter stack.

Definition at line 65 of file Context.h.

◆ isPotentialConstantExpr()

bool Context::isPotentialConstantExpr ( State Parent,
const FunctionDecl FnDecl 
)

Checks if a function is a potential constant expression.

Definition at line 29 of file Context.cpp.

References clang::interp::InterpStack::empty(), clang::Func, and Parent.

◆ shouldBeGloballyIndexed()

static bool clang::interp::Context::shouldBeGloballyIndexed ( const ValueDecl VD)
inlinestatic

Returns whether we should create a global variable for the given ValueDecl.

Definition at line 97 of file Context.h.

References V.

Referenced by clang::interp::Program::createGlobal(), clang::interp::DeclScope< Emitter >::DeclScope(), evaluateAsInitializer(), and clang::interp::ByteCodeExprGen< Emitter >::visitVarDecl().


The documentation for this class was generated from the following files: