slang::ast::LValue class

A representation of an lvalue used for constant evaluation.

An lvalue is anything that can appear on the left hand side of an assignment expression. It represents some storage location in memory that can be read from and written to.

Public types

struct Concat
A concatenation of lvalues is also an lvalue and can be assigned to.

Constructors, destructors, conversion operators

LValue() defaulted
Default constructor – results in an empty / invalid lvalue.
LValue(nullptr_t)
Implicit conversion from nullptr – results in an empty / invalid lvalue.
LValue(ConstantValue& base) explicit
Constructs a new lvalue that points to the given ConstantValue as a storage location.
LValue(std::vector<LValue>&& elems, Concat::Kind kind)
Constructs a new lvalue that is a concatenation of the given elements.
operator bool() const explicit

Public functions

auto bad() const -> bool
auto resolve() -> ConstantValue*
Resolve the lvalue to a single target storage location.
auto load() const -> ConstantValue
Loads the lvalue, resolving all path elements and performing any necessary concatenations.
void store(const ConstantValue& value)
Stores the given value into the storage pointed to by the lvalue.
void addBitSlice(ConstantRange range)
Extends the lvalue by adding a bit slice.
void addIndex(int32_t index, ConstantValue&& defaultValue)
Extends the lvalue by adding an element index.
void addIndexOutOfBounds(ConstantValue&& defaultValue)
Extends the lvalue with a deliberate out-of-bounds value.
void addArraySlice(ConstantRange range, ConstantValue&& defaultValue)
Extends the lvalue by adding an array slice.
void addArrayLookup(ConstantValue&& index, ConstantValue&& defaultValue)
Extends the lvalue by adding a lookup of an associative array.

Function documentation

slang::ast::LValue::LValue(ConstantValue& base) explicit

Constructs a new lvalue that points to the given ConstantValue as a storage location.

slang::ast::LValue::operator bool() const explicit

Returns true if the lvalue is invalid

bool slang::ast::LValue::bad() const

Returns true if the lvalue is invalid

ConstantValue* slang::ast::LValue::resolve()

Resolve the lvalue to a single target storage location.

If the lvalue is invalid, or the path does not resolve to a single target (such as if it is a concatenation) returns nullptr.

void slang::ast::LValue::addIndexOutOfBounds(ConstantValue&& defaultValue)

Extends the lvalue with a deliberate out-of-bounds value.

This ensures that reads will return the default and writes will be ignored.