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
Base class for all symbols (logical code constructs) such as modules, types, functions, variables, etc.

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
A special case for DPI imports that have "open array" typed arguments.
class DynamicArrayType
Represents a dynamically sized unpacked array.
class ErrorType
An empty type symbol that indicates an error occurred while trying to resolve the type of some expression or declaration.
class EventType
Represents a SystemVerilog event handle, which is used for synchronization between asynchronous processes.
class FixedSizeUnpackedArrayType
Represents a fixed size unpacked array (as opposed to a dynamically sized unpacked array, associative array, or queue).
class FloatingType
Represents one of the predefined floating point types, which are used for representing real numbers.
class IntegralType
A base class for integral types, which include all scalar types, predefined integer types, packed arrays, packed structures, packed unions, and enum types.
class NullType
Represents the Null type.
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 the built-in 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
Represents the '$' special token that is a standin for the unbounded end of a queue or range selection.
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
Represents the Void (or lack of a) type.

Public static variables

static uint64_t MaxBitWidth constexpr
The maximum size in bits of any fixed size type.

Public static functions

static auto getCommonBase(const Type& left, const Type& right) -> const Type*
If the two given types are both class types and have a common base class somewhere in their inheritance chain, return that common type.
static auto fromLookupResult(Compilation& compilation, const LookupResult& result, SourceRange sourceRange, const ASTContext& context) -> const Type&
Constructs a type from the results of a lookup operation.

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
Gets the declared width of the numeric type in bits.
auto getBitstreamWidth() const -> uint64_t
Gets $bits of the type. Returns zero if the type does not have a statically known size.
auto getSelectableWidth() const -> uint64_t
Gets the "selectable" width of the type.
auto isSigned() const -> bool
Indicates whether the type can represent negative numeric values.
auto isFourState() const -> bool
Indicates whether the type can represent unknown and high impedance numeric values.
auto isAggregate() const -> bool
Indicates whether this is an aggregate type, which includes all unpacked structs, unions, and arrays.
auto isSingular() const -> bool
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).
auto isIntegral() const -> bool
Indicates whether this is an integral type, which includes all scalar types, predefined integer types, packed arrays, packed structures, packed unions, and enum types.
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
Indicates whether this is a simple bit vector type, which encompasses all predefined integer types as well as scalar and vector types.
auto hasFixedRange() const -> bool
Indicates whether this type has a statically fixed size range associated with it.
auto isBooleanConvertible() const -> bool
Indicates whether this type is convertible to a boolean predicate for use in a conditional expression.
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
Indicates whether this type can be packed into a stream of bits.
auto isFixedSize() const -> bool
Check whether this type has a fixed bitstream size, as opposed to a dynamically sized type like a dynamic array or string.
auto isSimpleType() const -> bool
Indicates whether this type is considered a "simple type", which includes built-in integers, reals, and alias types.
auto isByteArray() const -> bool
Indicates whether this type is an unpacked array of bytes.
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
Indicates whether this is any form of unpacked array type: fixed size, dynamic, associative, or a queue.
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
Indicates whether this is an array of virtual interface types.
auto isAlias() const -> bool
Indicates whether this is a type alias.
auto isError() const -> bool
Indicates whether this is the error type.
auto isMatching(const Type& rhs) const -> bool
Determines whether the given type "matches" this one.
auto isEquivalent(const Type& rhs) const -> bool
Determines whether the given type is "equivalent" to this one.
auto isAssignmentCompatible(const Type& rhs) const -> bool
Determines whether the given type is "assignment compatible" to this one.
auto isCastCompatible(const Type& rhs) const -> bool
Determines whether the given type is "cast compatible" to this one.
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
Returns true if this is a class type that derives from the given base class type, and false otherwise.
auto implements(const Type& ifaceClass) const -> bool
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.
auto getIntegralFlags() const -> bitmask<IntegralFlags>
Gets a combination of flags for integral types; for non-integral types, this returns all zeros.
auto getDefaultValue() const -> ConstantValue
Gets the default value for the type.
auto getFixedRange() const -> ConstantRange
Returns the fixed range of the type, if it has one.
auto getArrayElementType() const -> const Type*
Returns the element type if this is an array type; otherwise returns nullptr.
auto getAssociativeIndexType() const -> const Type*
Returns the index type if this is an associative array and it has a non-wildcard index type specified.
auto canBeStringLike() const -> bool
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.
auto isIterable() const -> bool
Returns true if the type can be considered iterable, which includes types like arrays and strings.
auto isValidForRand(RandMode mode) const -> bool
Returns true if the type is valid for use as a random variable of the given mode.
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.
auto toString() const -> std::string
auto hash() const -> size_t

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).

uint64_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::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::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::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::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::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.

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.

std::string slang::ast::Type::toString() const

Returns a human-friendly string representation of the type.

size_t slang::ast::Type::hash() const

Returns a hash value for the type.