slang::EvalContext class


A container for all context required to evaluate a statement or expression. Mostly this involves tracking the callstack and maintaining storage for local variables.

Public types

struct Frame
Represents a single frame in the call stack.

Public functions

auto createLocal(const ValueSymbol* symbol, ConstantValue value = nullptr) -> ConstantValue*
Creates storage for a local variable in the current frame.
auto findLocal(const ValueSymbol* symbol) -> ConstantValue*
auto pushFrame(const SubroutineSymbol& subroutine, SourceLocation callLocation, LookupLocation lookupLocation) -> bool
Push a new frame onto the call stack.
void popFrame()
Pop the active frame from the call stack.
void pushLValue(LValue& lval)
void popLValue()
Pops the top of the lvalue stack (requires that the stack be non-empty).
auto getTopLValue() const -> LValue*
Gets the top of the lvalue stack, or nullptr if the stack is empty.
auto step(SourceLocation loc) -> bool
auto inFunction() const -> bool
auto isScriptEval() const -> bool
auto isVerifying() const -> bool
auto cacheResults() const -> bool
auto topFrame() const -> const Frame&
Gets the top of the call stack.
auto getDisableTarget() const -> const Symbol*
auto getDisableRange() const -> SourceRange
void setDisableTarget(const Symbol* symbol, SourceRange range)
auto dumpStack() const -> std::string
Dumps the contents of the call stack to a string for debugging.
auto getDiagnostics() const -> const Diagnostics&
Gets the set of diagnostics that have been produced during constant evaluation.
auto addDiag(DiagCode code, SourceLocation location) -> Diagnostic&
Records a diagnostic under the current evaluation context.
void reportDiags(const BindContext& context)
Issues all recorded diagnostics to the given binding context.
void reportStack(Diagnostic& diag) const
Reports the current function call stack as notes to the given diagnostic.

Function documentation

ConstantValue* slang::EvalContext::findLocal(const ValueSymbol* symbol)

Gets the current value for the given local variable symbol. Returns nullptr if the symbol cannot be found.

void slang::EvalContext::pushLValue(LValue& lval)

Pushes an lvalue onto the stack for later reference during evaluation. NOTE: the lvalue storage must remain alive for as long as it remains on the eval context's lvalue stack.

bool slang::EvalContext::step(SourceLocation loc)

Records the fact that we are executing another statement. This is used to count the number of statements executed so far to detect if we've been evaluating a single constant function for too long.

bool slang::EvalContext::inFunction() const

Returns true if the context is currently within a function call, and false if this is a top-level expression.

bool slang::EvalContext::isScriptEval() const

Indicates whether this evaluation context is for a script session (not used during normal compilation flow).

bool slang::EvalContext::isVerifying() const

Indicates whether this context is for verifying const-ness without actually evaluating anything.

bool slang::EvalContext::cacheResults() const

Indicates whether the results of evaluating expressions using this context can be cached in each expression's constant pointer.

const Symbol* slang::EvalContext::getDisableTarget() const

If a disable statement has been evaluated, this returns a pointer to the block that should be disabled (presumed to be higher up in the stack). Otherwise returns nullptr.

SourceRange slang::EvalContext::getDisableRange() const

If a disable statement has been evaluated, this returns the source range denoting where that statement occurred. Otherwise returns an empty range.

void slang::EvalContext::setDisableTarget(const Symbol* symbol, SourceRange range)

Sets the target block that should be disabled, based on evaluating a disable statement. This can be set to nullptr to clear out the target once it has been found the disable is completed.