slang::Expression class

The base class for all expressions in SystemVerilog.

Derived classes

class AssignmentExpression
Represents an assignment expression.
class AssignmentPatternExpressionBase
Base class for assignment pattern expressions.
class BinaryExpression
Represents a binary operator expression.
class CallExpression
Represents a subroutine call.
class ConcatenationExpression
Represents a concatenation expression.
class ConditionalExpression
Represents a conditional operator expression.
class ConversionExpression
Represents a type conversion expression (implicit or explicit).
class CopyClassExpression
Represents a new expression that copies a class instance.
class DataTypeExpression
class ElementSelectExpression
Represents a single element selection expression.
class EmptyArgumentExpression
class HierarchicalReferenceExpression
class InsideExpression
Represents a set membership operator expression.
class IntegerLiteral
Represents an integer literal.
class InvalidExpression
class MemberAccessExpression
Represents an access of a structure variable's members.
class MinTypMaxExpression
Represents a min:typ:max expression.
class NamedValueExpression
Represents an expression that references a named value.
class NewArrayExpression
Represents a new[] expression that creates a dynamic array.
class NewClassExpression
Represents a new expression that creates a class instance.
class NullLiteral
Represents a null literal.
class OpenRangeExpression
class RangeSelectExpression
Represents a range selection expression.
class RealLiteral
Represents a real number literal.
class ReplicationExpression
Represents a replication expression.
class StreamingConcatenationExpression
Represents a streaming concatenation.
class StringLiteral
Represents a string literal.
class TimeLiteral
Represents a time literal.
class UnaryExpression
Represents a unary operator expression.
class UnbasedUnsizedIntegerLiteral
Represents an unbased unsized integer literal, which fills all bits in an expression.

Public static functions

static auto bind(const ExpressionSyntax& syntax, const BindContext& context, bitmask<BindFlags> extraFlags = BindFlags::None) -> const Expression&
Binds an expression tree from the given syntax nodes.
static auto bindLValue(const ExpressionSyntax& lhs, const Type& rhs, SourceLocation location, const BindContext& context, bool isInout) -> const Expression&
Binds the left hand side of an assignment-like expression from the given syntax nodes.
static auto bindRValue(const Type& lhs, const ExpressionSyntax& rhs, SourceLocation location, const BindContext& context) -> const Expression&
Binds the right hand side of an assignment-like expression from the given syntax nodes.
static auto bindArgument(const Type& argType, ArgumentDirection direction, const ExpressionSyntax& syntax, const BindContext& context) -> const Expression&
Binds an argument or port connection with the given direction and syntax nodes.
static auto bindImplicitParam(const DataTypeSyntax& implicitType, const ExpressionSyntax& rhs, SourceLocation location, const BindContext& context) -> const Expression&
static auto convertAssignment(const BindContext& context, const Type& type, Expression& expr, SourceLocation location, optional<SourceRange> lhsRange = std::nullopt) -> Expression&
static auto bindMembershipExpressions(const BindContext& context, TokenKind keyword, bool wildcard, bool unwrapUnpacked, const ExpressionSyntax& valueExpr, span<const ExpressionSyntax*const> expressions, SmallVector<const Expression*>& results) -> bool
static void findPotentiallyImplicitNets(const ExpressionSyntax& expr, const BindContext& context, SmallVector<Token>& results)

Public functions

auto bad() const -> bool
Indicates whether the expression is invalid.
auto isImplicitString() const -> bool
auto isUnsizedInteger() const -> bool
auto eval(EvalContext& context) const -> ConstantValue
auto evalLValue(EvalContext& context) const -> LValue
auto verifyConstant(EvalContext& context) const -> bool
auto verifyAssignable(const BindContext& context, bool isNonBlocking = false, SourceLocation location = {}) const -> bool
auto isImplicitlyAssignableTo(const Type& type) const -> bool

Public variables

ExpressionKind kind
The kind of expression; indicates the type of derived class.
not_null<const Type*> type
The type of the expression.
const ConstantValue* constant
const ExpressionSyntax* syntax
SourceRange sourceRange
The source range of this expression, if it originated from source code.

Function documentation

static const Expression& slang::Expression::bindImplicitParam(const DataTypeSyntax& implicitType, const ExpressionSyntax& rhs, SourceLocation location, const BindContext& context)

Binds an initializer expression for an implicitly typed parameter. There are special inference rules for parameters.

static Expression& slang::Expression::convertAssignment(const BindContext& context, const Type& type, Expression& expr, SourceLocation location, optional<SourceRange> lhsRange = std::nullopt)

Converts the given expression to the specified type, as if the right hand side had been assigned (without a cast) to a left hand side of the specified type.

static bool slang::Expression::bindMembershipExpressions(const BindContext& context, TokenKind keyword, bool wildcard, bool unwrapUnpacked, const ExpressionSyntax& valueExpr, span<const ExpressionSyntax*const> expressions, SmallVector<const Expression*>& results)

Parameters
context
keyword parameter is used to customize diagnostics produced.
wildcard is set to true, expression types will be restricted to be only integral types.
unwrapUnpacked is set to true, unpacked arrays will be unwrapped to their element types to find the type to check against. Otherwise, all aggregates are illegal.
valueExpr is the value being checked for membership, and
expressions denotes the set to check within. All of the expressions influence each other for purposes of finding a common comparison type.
results
Returns true if all expressions are legal, otherwise false and appropriate diagnostics are issued.

Specialized method for binding all of the expressions in a set membership check. This is used for case statements and the 'inside' operator.

The The If If

static void slang::Expression::findPotentiallyImplicitNets(const ExpressionSyntax& expr, const BindContext& context, SmallVector<Token>& results)

This method finds all unqualified name references in the given expression and attempts to look them up in the given context. If they can't be found, their name tokens are returned in the given results vector.

bool slang::Expression::isImplicitString() const

Indicates whether the expression is of type string, or if it is implicitly convertible to a string.

bool slang::Expression::isUnsizedInteger() const

Indicates whether the expression is represented by an unsized integer value. For example, the integer literal "4" or the unbased unsized literal "'1";

ConstantValue slang::Expression::eval(EvalContext& context) const

Evaluates the expression under the given evaluation context. Any errors that occur will be stored in the evaluation context instead of issued to the compilation.

LValue slang::Expression::evalLValue(EvalContext& context) const

Evaluates an expression as an lvalue. Note that this will throw an exception if the expression does not represent an lvalue.

bool slang::Expression::verifyConstant(EvalContext& context) const

Verifies that this expression is valid as a constant expression. If it's not, appropriate diagnostics will be issued.

bool slang::Expression::verifyAssignable(const BindContext& context, bool isNonBlocking = false, SourceLocation location = {}) const

Verifies that this expression is a valid lvalue and that each element of that lvalue can be assigned to. If it's not, appropriate diagnostics will be issued.

bool slang::Expression::isImplicitlyAssignableTo(const Type& type) const

Returns true if this expression can be implicitly assigned to value of the given type.

Variable documentation

const ConstantValue* slang::Expression::constant

A pointer to a constant value if the expression has been evaluated. The value may be empty to indicate that the expression is known to not be constant. If the pointer is null, the expression hasn't been evaluated yet.

const ExpressionSyntax* slang::Expression::syntax

The syntax used to create the expression, if any. An expression tree can be created manually in which case it may not have a syntax representation.