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 final
Represents an unpacked array that provides associative lookup.
class CHandleType final
Represents storage for pointers passed using the DPI (a "C" compatible handle).
class ClassType final
Represents a class definition type.
class CovergroupType final
Represents a covergroup definition type.
class DPIOpenArrayType final
A special case for DPI imports that have "open array" typed arguments.
class DynamicArrayType final
Represents a dynamically sized unpacked array.
class ErrorType final
An empty type symbol that indicates an error occurred while trying to resolve the type of some expression or declaration.
class EventType final
Represents a SystemVerilog event handle, which is used for synchronization between asynchronous processes.
class FixedSizeUnpackedArrayType final
Represents a fixed size unpacked array (as opposed to a dynamically sized unpacked array, associative array, or queue).
class FloatingType final
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 final
Represents the Null type.
class PropertyType final
Represents the type of property instances and arguments.
class QueueType final
Represents an unpacked array that provides queue semantics.
class SequenceType final
Represents the type of sequence instances and arguments.
class StringType final
Represents the built-in ASCII string type.
class TypeAliasType final
Represents a type alias, which is introduced via a typedef or type parameter.
class TypeRefType final
Represents the result of a type reference expression, i.e. the type() operator.
class UnboundedType final
Represents the '$' special token that is a standin for the unbounded end of a queue or range selection.
class UnpackedStructType final
Represents an unpacked structure of members.
class UnpackedUnionType final
Represents an unpacked union of members.
class UntypedType final
Represents an 'untyped' type, which is used for e.g. arguments of sequences.
class VirtualInterfaceType final
Represents a virtual interface type.
class VoidType final
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 const 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.
static const Type& fromLookupResult(Compilation& compilation, const LookupResult& result, SourceRange sourceRange, const ASTContext& context)
Constructs a type from the results of a lookup operation.

Public functions

const Type& getCanonicalType() const
Gets the canonical type for this type, which involves unwrapping any type aliases.
bitwidth_t getBitWidth() const
Gets the declared width of the numeric type in bits.
uint64_t getBitstreamWidth() const
Gets $bits of the type. Returns zero if the type does not have a statically known size.
uint64_t getSelectableWidth() const
Gets the "selectable" width of the type.
bool isSigned() const
Indicates whether the type can represent negative numeric values.
bool isFourState() const
Indicates whether the type can represent unknown and high impedance numeric values.
bool isAggregate() const
Indicates whether this is an aggregate type, which includes all unpacked structs, unions, and arrays.
bool 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 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 isScalar() const
Indicates whether this is a scalar integral type (bit, logic, or reg).
bool isPredefinedInteger() const
Indicates whether this is a predefined integer type.
bool 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 hasFixedRange() const
Indicates whether this type has a statically fixed size range associated with it.
bool isBooleanConvertible() const
Indicates whether this type is convertible to a boolean predicate for use in a conditional expression.
bool isArray() const
Indicates whether this is a packed or unpacked array.
bool isStruct() const
Indicates whether this is a packed or unpacked struct.
bool isBitstreamType(bool destination = false) const
Indicates whether this type can be packed into a stream of bits.
bool 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 isSimpleType() const
Indicates whether this type is considered a "simple type", which includes built-in integers, reals, and alias types.
bool isByteArray() const
Indicates whether this type is an unpacked array of bytes.
bool isNumeric() const
Indicates whether this is a numeric type, which includes all integral and floating types.
bool isPackedArray() const
Indicates whether this is a packed array type.
bool isUnpackedArray() const
Indicates whether this is any form of unpacked array type: fixed size, dynamic, associative, or a queue.
bool isDynamicallySizedArray() const
Indicates whether this is a dynamic array, associative array, or a queue.
bool isUnion() const
Indicates whether this is a packed or unpacked union.
bool isTaggedUnion() const
Indicates whether this is a tagged union, packed or unpacked.
bool isUnpackedStruct() const
Indicates whether this is an unpacked structure type.
bool isPackedUnion() const
Indicates whether this is a packed union type.
bool isUnpackedUnion() const
Indicates whether this is an unpacked union type.
bool isAssociativeArray() const
Indicates whether this is an associative array type.
bool isQueue() const
Indicates whether this is a queue type.
bool isEnum() const
Indicates whether this is an enum type.
bool isClass() const
Indicates whether this is a class type.
bool isCovergroup() const
Indicates whether this is a covergroup type.
bool isFloating() const
Indicates whether this is a floating point type.
bool isVoid() const
Indicates whether this is the Void type.
bool isNull() const
Indicates whether this is the null type.
bool isCHandle() const
Indicates whether this is a C-handle type.
bool isString() const
Indicates whether this is a string type.
bool isEvent() const
Indicates whether this is an event type.
bool isUnbounded() const
Indicates whether this is the unbounded type.
bool isTypeRefType() const
Indicates whether this is the type reference type.
bool isUntypedType() const
Indicates whether this is the untyped type.
bool isSequenceType() const
Indicates whether this is the sequence type.
bool isPropertyType() const
Indicates whether this is the property type.
bool isVirtualInterface() const
Indicates whether this is a virtual interface type.
bool isVirtualInterfaceOrArray() const
Indicates whether this is an array of virtual interface types.
bool isHandleType() const
Indicates whether this is a type that acts like a handle, which includes classes, events, chandles, virtual interfaces, and the null type.
bool isAlias() const
Indicates whether this is a type alias.
bool isError() const
Indicates whether this is the error type.
bool isMatching(const Type& rhs) const
Determines whether the given type "matches" this one.
bool isEquivalent(const Type& rhs) const
Determines whether the given type is "equivalent" to this one.
bool isAssignmentCompatible(const Type& rhs) const
Determines whether the given type is "assignment compatible" to this one.
bool isCastCompatible(const Type& rhs) const
Determines whether the given type is "cast compatible" to this one.
bool isBitstreamCastable(const Type& rhs) const
Determines whether the given type can be bit-stream cast to this one.
bool 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 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.
bitmask<IntegralFlags> getIntegralFlags() const
Gets a combination of flags for integral types; for non-integral types, this returns all zeros.
ConstantValue getDefaultValue() const
Gets the default value for the type.
ConstantRange getFixedRange() const
Returns the fixed range of the type, if it has one.
const Type* getArrayElementType() const
Returns the element type if this is an array type; otherwise returns nullptr.
const Type* getAssociativeIndexType() const
Returns the index type if this is an associative array and it has a non-wildcard index type specified.
bool 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 isIterable() const
Returns true if the type can be considered iterable, which includes types like arrays and strings.
bool isValidForRand(RandMode mode, LanguageVersion languageVersion) const
Returns true if the type is valid for use as a random variable of the given mode.
bool isValidForDPIReturn() const
Returns true if the type is valid for use as a DPI return value.
bool isValidForDPIArg() const
Returns true if the type is valid for use as a DPI argument.
bool isValidForSequence() const
Returns true if the type is valid for use in sequence expressions.
bool isValidForPort(const Type** foundInvalid) const
Returns true if the type is valid for use in a port.
bool isValidForUnion(bool isTagged, const Type** foundInvalid) const
Returns true if the type is valid for use in a union.
ConstantValue coerceValue(const ConstantValue& value) const
Coerces the given constant into one that is appropriate for this type.
const Type& makeSigned(Compilation& compilation) const
If this is an integral type, returns the same type converted to a signed integral type (properly descending through sub arrays).
const Type& makeUnsigned(Compilation& compilation) const
If this is an integral type, returns the same type converted to an unsigned integral type (properly descending through sub arrays).
std::string toString() const
size_t hash() const

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.

const Type& slang::ast::Type::makeSigned(Compilation& compilation) const

If this is an integral type, returns the same type converted to a signed integral type (properly descending through sub arrays).

Otherwise returns *this.

const Type& slang::ast::Type::makeUnsigned(Compilation& compilation) const

If this is an integral type, returns the same type converted to an unsigned integral type (properly descending through sub arrays).

Otherwise returns *this.

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.