class
#include <slang/ast/Expression.h>
Expression The base class for all expressions in SystemVerilog.
Derived classes
- class ArbitrarySymbolExpression
- class AssertionInstanceExpression
- 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 ClockingEventExpression
- 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 DistExpression
- class ElementSelectExpression
- Represents a single element selection expression.
- class EmptyArgumentExpression
- class InsideExpression
- Represents a set membership operator expression.
- class IntegerLiteral
- Represents an integer literal.
- class InvalidExpression
- class LValueReferenceExpression
- class MemberAccessExpression
- Represents an access of a structure variable's members.
- class MinTypMaxExpression
- Represents a min:typ:max expression.
- class NewArrayExpression
- Represents a new[] expression that creates a dynamic array.
- class NewClassExpression
- Represents a
new
expression that creates a class instance. - class NewCovergroupExpression
- Represents a
new
expression that creates a covergroup 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 TaggedUnionExpression
- Represents a tagged union member setter expression.
- class TimeLiteral
- Represents a time literal.
- class TypeReferenceExpression
- class UnaryExpression
- Represents a unary operator expression.
- class UnbasedUnsizedIntegerLiteral
- Represents an unbased unsized integer literal, which fills all bits in an expression.
- class UnboundedLiteral
- Represents the unboudned queue or range literal.
- class ValueExpressionBase
- Common base class for both NamedValueExpression and HierarchicalValueExpression.
Public static functions
-
static auto bind(const ExpressionSyntax& syntax,
const ASTContext& context,
bitmask<ASTFlags> extraFlags = ASTFlags::
None) -> const Expression& - Binds an expression tree from the given syntax nodes.
- static auto bindLValue(const ExpressionSyntax& lhs, const Type& rhs, SourceLocation location, const ASTContext& context, bool isInout) -> const Expression&
- Binds the left hand side of an assignment-like expression from the given syntax nodes.
- static auto bindLValue(const ExpressionSyntax& syntax, const ASTContext& context) -> const Expression&
-
static auto bindRValue(const Type& lhs,
const ExpressionSyntax& rhs,
SourceLocation location,
const ASTContext& context,
bitmask<ASTFlags> extraFlags = ASTFlags::
None) -> const Expression& - Binds the right hand side of an assignment-like expression from the given syntax nodes.
- static auto bindRefArg(const Type& lhs, bool isConstRef, const ExpressionSyntax& rhs, SourceLocation location, const ASTContext& context) -> const Expression&
- Binds a connection to a ref argument from the given syntax nodes.
- static auto bindArgument(const Type& argType, ArgumentDirection direction, const ExpressionSyntax& syntax, const ASTContext& context, bool isConstRef = false) -> const Expression&
- Binds an argument or port connection with the given direction and syntax nodes.
-
static auto bindImplicitParam(const syntax::
DataTypeSyntax& implicitType, const ExpressionSyntax& rhs, SourceLocation location, const ASTContext& exprContext, const ASTContext& typeContext, bitmask<ASTFlags> extraFlags = ASTFlags:: None) -> std::tuple<const Expression*, const Type*> -
static auto bindSelector(Expression& value,
const syntax::
ElementSelectSyntax& syntax, const ASTContext& context) -> const Expression& - Bind a selector expression given an already existing value to select from.
- static auto tryBindInterfaceRef(const ASTContext& context, const ExpressionSyntax& syntax, bool isInterfacePort) -> Expression*
- static auto bindMembershipExpressions(const ASTContext& context, parsing::TokenKind keyword, bool requireIntegral, bool unwrapUnpacked, bool allowTypeReferences, bool allowOpenRange, const ExpressionSyntax& valueExpr, std::span<const ExpressionSyntax*const> expressions, SmallVectorBase<const Expression*>& results) -> bool
-
static void findPotentiallyImplicitNets(const syntax::
SyntaxNode& expr, const ASTContext& context, SmallVectorBase<const syntax:: IdentifierNameSyntax*>& results) - static auto convertAssignment(const ASTContext& context, const Type& type, Expression& expr, SourceLocation location, Expression** lhsExpr = nullptr, bitmask<AssignFlags>* assignFlags = nullptr) -> Expression&
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 evalSelector(EvalContext& context) const -> std::optional<ConstantRange>
- auto requireLValue(const ASTContext& context, SourceLocation location = {}, bitmask<AssignFlags> flags = {}, const Expression* longestStaticPrefix = nullptr) const -> bool
- void getLongestStaticPrefixes(SmallVector<std::pair<const ValueSymbol*, const Expression*>>& results, EvalContext& evalContext, const Expression* longestStaticPrefix = nullptr) const
- auto canConnectToRefArg(bool isConstRef, bool allowConstClassHandle = false) const -> bool
- auto isImplicitlyAssignableTo(Compilation& compilation, const Type& type) const -> bool
-
auto getEffectiveWidth() const -> std::optional<bitwidth_
t> - auto getSymbolReference(bool allowPacked = true) const -> const Symbol*
- auto hasHierarchicalReference() const -> bool
- Returns true if any subexpression of this expression is a hierarchical reference.
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:: ast:: Expression:: bindLValue(const ExpressionSyntax& syntax,
const ASTContext& context)
Binds an lvalue that is not a typical assignment-like context. For example, the output argument of certain system tasks that accept almost any type.
static std::tuple<const Expression*, const Type*> slang:: ast:: Expression:: bindImplicitParam(const syntax:: DataTypeSyntax& implicitType,
const ExpressionSyntax& rhs,
SourceLocation location,
const ASTContext& exprContext,
const ASTContext& typeContext,
bitmask<ASTFlags> extraFlags = ASTFlags:: None)
Binds an initializer expression for an implicitly typed parameter. There are special inference rules for parameters.
static Expression* slang:: ast:: Expression:: tryBindInterfaceRef(const ASTContext& context,
const ExpressionSyntax& syntax,
bool isInterfacePort)
Tries to bind an interface reference into an expression for an interface port or a virtual interface assignment. Returns nullptr if unable to do so.
static bool slang:: ast:: Expression:: bindMembershipExpressions(const ASTContext& context,
parsing::TokenKind keyword,
bool requireIntegral,
bool unwrapUnpacked,
bool allowTypeReferences,
bool allowOpenRange,
const ExpressionSyntax& valueExpr,
std::span<const ExpressionSyntax*const> expressions,
SmallVectorBase<const Expression*>& results)
Parameters | |
---|---|
context | The context used for creating expressions. |
keyword | The kind of membership being created, which is used to customize any diagnostics produced. |
requireIntegral | If set to true, expression types will be restricted to be only integral types. |
unwrapUnpacked | If set to true, unpacked arrays will be unwrapped to their element types to find the type to check against. Otherwise, all aggregates are illegal. |
allowTypeReferences | If set to true the created expressions are allowed to be type reference expressions. Otherwise an error will be issued. |
allowOpenRange | If set to true, open range expressions will be allowed. Otherwise an error will be issued for them. |
valueExpr | The value being checked for membership. |
expressions | Denotes the set to check within. All of the expressions influence each other for purposes of finding a common comparison type. |
results | A vector that will be filled with the created membership expressions. |
Returns | true if all expressions are legal, otherwise false and appropriate diagnostics are issued. |
Specialized method for creating all of the expressions in a set membership check. This is used for case statements and the 'inside' operator.
static void slang:: ast:: Expression:: findPotentiallyImplicitNets(const syntax:: SyntaxNode& expr,
const ASTContext& context,
SmallVectorBase<const syntax:: IdentifierNameSyntax*>& 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.
static Expression& slang:: ast:: Expression:: convertAssignment(const ASTContext& context,
const Type& type,
Expression& expr,
SourceLocation location,
Expression** lhsExpr = nullptr,
bitmask<AssignFlags>* assignFlags = nullptr)
Converts an expression to be of the given type, following the rules for implicit conversions, array port slicing, etc.
bool slang:: ast:: Expression:: isImplicitString() const
Indicates whether the expression is of type string, or if it is implicitly convertible to a string.
bool slang:: ast:: 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:: ast:: 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:: ast:: Expression:: evalLValue(EvalContext& context) const
Evaluates the expression as an lvalue. Note that this will throw an exception if the expression does not represent an lvalue.
std::optional<ConstantRange> slang:: ast:: Expression:: evalSelector(EvalContext& context) const
Evaluates the expression as a selector and returns the selection range that results. If the evaluates fails or the expression does not represent a selection std::nullopt will be returned.
bool slang:: ast:: Expression:: requireLValue(const ASTContext& context,
SourceLocation location = {},
bitmask<AssignFlags> flags = {},
const Expression* longestStaticPrefix = nullptr) 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. Information about the source expression driving the lvalue will be registered with the various symbols involved.
void slang:: ast:: Expression:: getLongestStaticPrefixes(SmallVector<std::pair<const ValueSymbol*, const Expression*>>& results,
EvalContext& evalContext,
const Expression* longestStaticPrefix = nullptr) const
If this expression is a valid lvalue, returns the part(s) of it that constitutes the "longest static prefix" for purposes of determining duplicate assignments / drivers to a portion of a value, for each such lvalue (usually one unless there is an lvalue concatenation). If there are no lvalues the vector will not have any entries added to it.
bool slang:: ast:: Expression:: canConnectToRefArg(bool isConstRef,
bool allowConstClassHandle = false) const
Checks whether this kind of expression can be connected to a ref argument for a subroutine or module port.
bool slang:: ast:: Expression:: isImplicitlyAssignableTo(Compilation& compilation,
const Type& type) const
Returns true if this expression can be implicitly assigned to value of the given type.
std::optional<bitwidth_ t> slang:: ast:: Expression:: getEffectiveWidth() const
Traverses the expression tree and computes what its width would be (in bits) if the types of all known constants were declared with only the bits necessary to represent them. If any encountered expressions have errors, returns nullopt.
const Symbol* slang:: ast:: Expression:: getSymbolReference(bool allowPacked = true) const
If this expression is a reference to a symbol, returns a pointer to that symbol. Otherwise, returns null. If the expression is a member access of a struct or class, returns the member being accessed. If it's a select of an array, returns the root array variable. The allowPacked argument determines whether selects of a packed type are considered a symbol reference or whether to consider only unpacked structs and arrays.
Variable documentation
const ConstantValue* slang:: ast:: 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:: ast:: 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.