slang::ast::Type class

Base class for all data types in SystemVerilog.

Note that this can actually be an alias for some other type (such as with typedefs or type parameters). Each type knows its "canonical" type, which in the case of most types points to itself and for type aliases points to the fully unwrapped target type. Most methods on this class that query traits drill down to the canonical type.

Base classes

class Symbol

Derived classes

class AssociativeArrayType
Represents an unpacked array that provides associative lookup.
class CHandleType
Represents storage for pointers passed using the DPI (a "C" compatible handle).
class ClassType
Represents a class definition type.
class CovergroupType
Represents a covergroup definition type.
class DPIOpenArrayType
class DynamicArrayType
Represents a dynamically sized unpacked array.
class ErrorType
class EventType
class FixedSizeUnpackedArrayType
class FloatingType
class IntegralType
class NullType
class PropertyType
Represents the type of property instances and arguments.
class QueueType
Represents an unpacked array that provides queue semantics.
class SequenceType
Represents the type of sequence instances and arguments.
class StringType
Represents an ASCII string type.
class TypeAliasType
Represents a type alias, which is introduced via a typedef or type parameter.
class TypeRefType
Represents the result of a type reference expression, i.e. the type() operator.
class UnboundedType
class UnpackedStructType
Represents an unpacked structure of members.
class UnpackedUnionType
Represents an unpacked union of members.
class UntypedType
Represents an 'untyped' type, which is used for e.g. arguments of sequences.
class VirtualInterfaceType
Represents a virtual interface type.
class VoidType

Public static functions

static auto getCommonBase(const Type& left, const Type& right) -> const Type*
static auto fromLookupResult(Compilation& compilation, const LookupResult& result, SourceRange sourceRange, const ASTContext& context) -> const Type&

Public functions

auto getCanonicalType() const -> const Type&
Gets the canonical type for this type, which involves unwrapping any type aliases.
auto getBitWidth() const -> bitwidth_t
auto bitstreamWidth() const -> size_t
Gets $bits of the type. Returns zero if the type does not have a statically known size.
auto getSelectableWidth() const -> uint32_t
auto isSigned() const -> bool
auto isFourState() const -> bool
auto isAggregate() const -> bool
auto isSingular() const -> bool
auto isIntegral() const -> bool
auto isScalar() const -> bool
Indicates whether this is a scalar integral type (bit, logic, or reg).
auto isPredefinedInteger() const -> bool
Indicates whether this is a predefined integer type.
auto isSimpleBitVector() const -> bool
auto hasFixedRange() const -> bool
auto isBooleanConvertible() const -> bool
auto isArray() const -> bool
Indicates whether this is a packed or unpacked array.
auto isStruct() const -> bool
Indicates whether this is a packed or unpacked struct.
auto isBitstreamType(bool destination = false) const -> bool
auto isFixedSize() const -> bool
auto isSimpleType() const -> bool
auto isByteArray() const -> bool
auto isNumeric() const -> bool
Indicates whether this is a numeric type, which includes all integral and floating types.
auto isPackedArray() const -> bool
Indicates whether this is a packed array type.
auto isUnpackedArray() const -> bool
auto isDynamicallySizedArray() const -> bool
Indicates whether this is a dynamic array, associative array, or a queue.
auto isTaggedUnion() const -> bool
Indicates whether this is a tagged union, packed or unpacked.
auto isUnpackedStruct() const -> bool
Indicates whether this is an unpacked structure type.
auto isPackedUnion() const -> bool
Indicates whether this is a packed union type.
auto isUnpackedUnion() const -> bool
Indicates whether this is an unpacked union type.
auto isAssociativeArray() const -> bool
Indicates whether this is an associative array type.
auto isQueue() const -> bool
Indicates whether this is a queue type.
auto isEnum() const -> bool
Indicates whether this is an enum type.
auto isClass() const -> bool
Indicates whether this is a class type.
auto isCovergroup() const -> bool
Indicates whether this is a covergroup type.
auto isFloating() const -> bool
Indicates whether this is a floating point type.
auto isVoid() const -> bool
Indicates whether this is the Void type.
auto isNull() const -> bool
Indicates whether this is the null type.
auto isCHandle() const -> bool
Indicates whether this is a C-handle type.
auto isString() const -> bool
Indicates whether this is a string type.
auto isEvent() const -> bool
Indicates whether this is an event type.
auto isUnbounded() const -> bool
Indicates whether this is the unbounded type.
auto isTypeRefType() const -> bool
Indicates whether this is the type reference type.
auto isUntypedType() const -> bool
Indicates whether this is the untyped type.
auto isSequenceType() const -> bool
Indicates whether this is the sequence type.
auto isPropertyType() const -> bool
Indicates whether this is the property type.
auto isVirtualInterface() const -> bool
Indicates whether this is a virtual interface type.
auto isVirtualInterfaceOrArray() const -> bool
auto isAlias() const -> bool
auto isError() const -> bool
Indicates whether this is the error type.
auto isMatching(const Type& rhs) const -> bool
auto isEquivalent(const Type& rhs) const -> bool
auto isAssignmentCompatible(const Type& rhs) const -> bool
auto isCastCompatible(const Type& rhs) const -> bool
auto isBitstreamCastable(const Type& rhs) const -> bool
Determines whether the given type can be bit-stream cast to this one.
auto isDerivedFrom(const Type& base) const -> bool
auto implements(const Type& ifaceClass) const -> bool
auto getIntegralFlags() const -> bitmask<IntegralFlags>
auto getDefaultValue() const -> ConstantValue
auto getFixedRange() const -> ConstantRange
auto getArrayElementType() const -> const Type*
Returns the element type if this is an array type; otherwise returns nullptr.
auto getAssociativeIndexType() const -> const Type*
auto canBeStringLike() const -> bool
auto isIterable() const -> bool
auto isValidForRand(RandMode mode) const -> bool
auto isValidForDPIReturn() const -> bool
Returns true if the type is valid for use as a DPI return value.
auto isValidForDPIArg() const -> bool
Returns true if the type is valid for use as a DPI argument.
auto isValidForSequence() const -> bool
Returns true if the type is valid for use in sequence expressions.
auto isValidForPort(const Type** foundInvalid) const -> bool
Returns true if the type is valid for use in a port.
auto isValidForUnion(bool isTagged, const Type** foundInvalid) const -> bool
Returns true if the type is valid for use in a union.
auto coerceValue(const ConstantValue& value) const -> ConstantValue
Coerces the given constant into one that is appropriate for this type.

Function documentation

static const Type* slang::ast::Type::getCommonBase(const Type& left, const Type& right)

If the two given types are both class types and have a common base class somewhere in their inheritance chain, return that common type. Otherwise, returns nullptr.

static const Type& slang::ast::Type::fromLookupResult(Compilation& compilation, const LookupResult& result, SourceRange sourceRange, const ASTContext& context)

Constructs a type from the results of a lookup operation. Note that this will not issue any diagnostics from the result object; the caller must do that themselves if they wish.

bitwidth_t slang::ast::Type::getBitWidth() const

Gets the declared width of the numeric type in bits. Returns zero if the type is not numeric (i.e. integral or floating).

uint32_t slang::ast::Type::getSelectableWidth() const

Gets the "selectable" width of the type. This is the size of the object when determining whether assignments to the static portions overlap with each other. Dynamically sized types are given the size of 1 for selection purposes.

bool slang::ast::Type::isSigned() const

Indicates whether the type can represent negative numeric values. For non-numeric types, this always returns false.

bool slang::ast::Type::isFourState() const

Indicates whether the type can represent unknown and high impedance numeric values. For aggregate types, this drills down into submembers to determine whether they are all two state or if some are four state. For all other types, this always returns false.

bool slang::ast::Type::isAggregate() const

Indicates whether this is an aggregate type, which includes all unpacked structs, unions, and arrays.

bool slang::ast::Type::isSingular() const

Indicates whether this is a singular type, which is the opposite of an aggregate type (that is, all types except unpacked structs, unions, and arrays).

bool slang::ast::Type::isIntegral() const

Indicates whether this is an integral type, which includes all scalar types, predefined integer types, packed arrays, packed structures, packed unions, and enum types.

bool slang::ast::Type::isSimpleBitVector() const

Indicates whether this is a simple bit vector type, which encompasses all predefined integer types as well as scalar and vector types.

bool slang::ast::Type::hasFixedRange() const

Indicates whether this type has a statically fixed size range associated with it. This is true for packed arrays and fixed size unpacked arrays, as well as all integral types (their range is their bitwidth).

bool slang::ast::Type::isBooleanConvertible() const

Indicates whether this type is convertible to a boolean predicate for use in a conditional expression.

bool slang::ast::Type::isBitstreamType(bool destination = false) const

Indicates whether this type can be packed into a stream of bits. If destination is true, this is being checked in the context of the destination side of a bitstream cast, which disallows associative arrays.

bool slang::ast::Type::isFixedSize() const

Check whether this type has a fixed bitstream size, as opposed to a dynamically sized type like a dynamic array or string.

bool slang::ast::Type::isSimpleType() const

Indicates whether this type is considered a "simple type", which includes built-in integers, reals, and alias types.

bool slang::ast::Type::isByteArray() const

Indicates whether this type is an unpacked array of bytes. Various string-related methods in the language check for this to interpret such arguments as strings.

bool slang::ast::Type::isUnpackedArray() const

Indicates whether this is any form of unpacked array type: fixed size, dynamic, associative, or a queue.

bool slang::ast::Type::isVirtualInterfaceOrArray() const

Indicates whether this is an array of virtual interface types. A plain virtual interface type will also return true.

bool slang::ast::Type::isAlias() const

Indicates whether this is a type alias. Note that unlike other methods, this one does not unwrap to the canonical type.

bool slang::ast::Type::isMatching(const Type& rhs) const

Determines whether the given type "matches" this one. For most intents and purposes, matching types are completely identical.

bool slang::ast::Type::isEquivalent(const Type& rhs) const

Determines whether the given type is "equivalent" to this one. This typically means that the two types can be implicitly converted between one another.

bool slang::ast::Type::isAssignmentCompatible(const Type& rhs) const

Determines whether the given type is "assignment compatible" to this one. This includes all equivalent types, plus types for which additional implicit conversion rules have been defined. Note that the reverse operation is not necessarily true.

bool slang::ast::Type::isCastCompatible(const Type& rhs) const

Determines whether the given type is "cast compatible" to this one. This means that the type is either implicitly or explicitly convertible to this one. Note that the reverse operation is not necessarily true.

bool slang::ast::Type::isDerivedFrom(const Type& base) const

Returns true if this is a class type that derives from the given base class type, and false otherwise.

bool slang::ast::Type::implements(const Type& ifaceClass) const

Returns true if this is a class type that implements the given interface class type, or if this is an interface class type that extends the given interface class type. Otherwise, returns false.

bitmask<IntegralFlags> slang::ast::Type::getIntegralFlags() const

Gets a combination of flags for integral types; for non-integral types, this returns all zeros.

ConstantValue slang::ast::Type::getDefaultValue() const

Gets the default value for the type. An uninitialized variable of this type will have the given default value.

ConstantRange slang::ast::Type::getFixedRange() const

Returns the fixed range of the type, if it has one. This can be determined via the hasFixedRange() method. If it does not, this returns an empty range.

const Type* slang::ast::Type::getAssociativeIndexType() const

Returns the index type if this is an associative array and it has a non-wildcard index type specified. Otherwise, returns nullptr.

bool slang::ast::Type::canBeStringLike() const

Returns true if the type can represent a string-like value; this includes the string type itself as well as byte arrays and all integral types.

bool slang::ast::Type::isIterable() const

Returns true if the type can be considered iterable, which includes types like arrays and strings.

bool slang::ast::Type::isValidForRand(RandMode mode) const

Returns true if the type is valid for use as a random variable of the given mode.