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.

Public static functions

static void visitPaths(const Expression& expr, EvalContext& evalContext, function_ref<void(const ValuePath&)> callback, bool skipSelectors = false)
Visits all value paths in the provided arbitrary expression, invoking the callback for each one.

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

const ValueSymbol* rootSymbol() const
Gets the value symbol at the root of the path, if there is one.
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).
bool overlaps(const ValuePath& other) const
Returns true if this path overlaps other.
std::string toString(EvalContext& evalContext) const
Returns a humany-friendly string representation of the path.
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.
void expandIndirectRefs(BumpAllocator& alloc, EvalContext& evalContext, function_ref<void(const ValuePath&)> callback) const
Expands indirect references (via explicit modport port and ref port connections) and visits the resulting paths with the provided callback.
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 Expression* rootExpr
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

static void slang::ast::ValuePath::visitPaths(const Expression& expr, EvalContext& evalContext, function_ref<void(const ValuePath&)> callback, bool skipSelectors = false)

Visits all value paths in the provided arbitrary expression, invoking the callback for each one.

If skipSelectors is true this function won't visit expressions inside selectors, such as a and b in foo[a:b]. It also won't visit the lhs of class and virtual interface handle accesses.

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.

void slang::ast::ValuePath::expandIndirectRefs(BumpAllocator& alloc, EvalContext& evalContext, function_ref<void(const ValuePath&)> callback) const

Expands indirect references (via explicit modport port and ref port connections) and visits the resulting paths with the provided callback.

If this path does not contain such references, the callback will be invoked once with *this.

Variable documentation

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 is no static prefix of the path.