slang::ast::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

void reset()
Resets the evaluation context back to an initial constructed state.
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*
void deleteLocal(const ValueSymbol* symbol)
auto pushFrame(const SubroutineSymbol& subroutine, SourceLocation callLocation, LookupLocation lookupLocation) -> bool
Push a new frame onto the call stack.
void pushEmptyFrame()
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 cacheResults() const -> bool
auto disableCaching() -> auto
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)
void setQueueTarget(const ConstantValue* cv)
auto getQueueTarget() const -> const ConstantValue*
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 ASTContext& context)
Issues all recorded diagnostics to the given AST context.
void reportStack(Diagnostic& diag) const
Reports the current function call stack as notes to the given diagnostic.

Function documentation

ConstantValue* slang::ast::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::ast::EvalContext::deleteLocal(const ValueSymbol* symbol)

Removes a previously created local. Pointers to the local's storage will be invalidated.

void slang::ast::EvalContext::pushEmptyFrame()

Pushes an empty frame onto the call stack. Intended for use with on-the-fly evaluation in a scripting context.

void slang::ast::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::ast::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::ast::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::ast::EvalContext::cacheResults() const

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

auto slang::ast::EvalContext::disableCaching()

If result caching is enabled, this method disables it and returns an object that when destructed will restore the previous caching mode. Otherwise does nothing.

const Symbol* slang::ast::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::ast::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::ast::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.

void slang::ast::EvalContext::setQueueTarget(const ConstantValue* cv)

Sets the target queue value for use with unbounded '$' expressions. If set to nullptr, the target is cleared.

const ConstantValue* slang::ast::EvalContext::getQueueTarget() const

Gets the target queue value for use with unbounded '$' expressions. Returns nullptr if there is no queue target active.