slang::ast::ValuePath class

Represents a path to some subset of a value symbol, such as via field accesses or array element selects.

Some portions of the path may be statically known, if they have constant select value or are for known struct fields. Others are only dynamically known, such as non-constant selects, dynamic array accesses, class handle member access, virtual interface access, etc.

Leading elements of the path that are statically known form a "static prefix". The longest such prefix is the "longest static prefix" which the LRM uses as a way to specify legal and illegal conditions for assignments.

Public types

class iterator
An iterator for components of the path.

Constructors, destructors, conversion operators

ValuePath()
Constructs an empty path.
ValuePath(const Expression& expr, EvalContext& evalContext)
Constructs a new value path from a path expression.

Public functions

ValuePath shrinkToLSP() const
Returns a new path that represents the current path with all dynamic components removed, such that the resulting path is just the longest static prefix.
ValuePath clone(BumpAllocator& alloc, EvalContext& evalContext) const
Clones the path into a new one that represents the same path but with all constant select expressions baked into constants in the expression tree.
ValuePath retarget(BumpAllocator& alloc, EvalContext& evalContext, const ValueSymbol& target) const
Retargets the value path to a new root.
bool empty() const
Returns true if the path is empty, meaning it has no root or path components.
bool isFullyStatic() const
Returns true if the path is fully static (i.e. has no dynamic components).
std::string toString(EvalContext& evalContext) const
Returns a humany-friendly string representation of the path.
size_t hash() const
Hashes the path.
bool operator==(const ValuePath& other) const
Equality operator.
iterator begin() const
Gets an iterator to the "start" of the path, which is the outermost expression.
iterator end() const
Gets an iterator to the end of the path, which is one past the root of the path.

Public variables

const ValueSymbol* rootSymbol
The root of the path.
const Type* rootType
The type of the root of the path.
const Expression* fullExpr
The full expression representing the path.
const Expression* lsp
The portion of the path that is the longest static prefix, if any.
std::pair<uint64_t, uint64_t> lspBounds
If the path has a longest static prefix, the bit range selected by that prefix.

Function documentation

ValuePath slang::ast::ValuePath::retarget(BumpAllocator& alloc, EvalContext& evalContext, const ValueSymbol& target) const

Retargets the value path to a new root.

The new target must have the same type as the existing root type. The path cannot be empty.

Variable documentation

const ValueSymbol* slang::ast::ValuePath::rootSymbol

The root of the path.

Note that it is possible for rootSymbol to be nullptr but fullExpr to be non-null, in cases like selects of a concat: {a, b}[0] and selects of a function call result: foo().bar. Note that such a path is not considered a static prefix.

const Type* slang::ast::ValuePath::rootType

The type of the root of the path.

This will be non-null if fullExpr is non-null, even if rootSymbol is otherwise null due to a path selecting from a concat.

const Expression* slang::ast::ValuePath::fullExpr

The full expression representing the path.

This can be nullptr if, for example, shrinkToLSP() is called on a path that does not have a static prefix.

const Expression* slang::ast::ValuePath::lsp

The portion of the path that is the longest static prefix, if any.

This can be nullptr if there are no static prefixes of the path.