slang::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 DynamicArrayType
Represents a dynamically sized unpacked array.
class ErrorType
class EventType
class FixedSizeUnpackedArrayType
class FloatingType
class IntegralType
class NullType
class QueueType
Represents an unpacked array that provides queue semantics.
class StringType
Represents an ASCII string type.
class TypeAliasType
Represents a type alias, which is introduced via a typedef or type parameter.
class UnpackedStructType
Represents an unpacked structure of members.
class UnpackedUnionType
Represents an unpacked union of members.
class VoidType

Public static functions

static auto getCommonBase(const Type& left, const Type& right) -> const Type*
static auto fromLookupResult(Compilation& compilation, const LookupResult& result, const NameSyntax& syntax, LookupLocation location, const Scope& parent) -> 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 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 isUnpackedStruct() const -> bool
Indicates whether this is an unpacked structure 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 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 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

Function documentation

static const Type* slang::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::Type::fromLookupResult(Compilation& compilation, const LookupResult& result, const NameSyntax& syntax, LookupLocation location, const Scope& parent)

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::Type::getBitWidth() const

Gets the total width of the type in bits. Returns zero if the type does not have a statically known size.

bool slang::Type::isSigned() const

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

bool slang::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::Type::isAggregate() const

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

bool slang::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::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::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::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::Type::isBooleanConvertible() const

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

bool slang::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::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::Type::isSimpleType() const

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

bool slang::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::Type::isUnpackedArray() const

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

bool slang::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::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::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::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::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::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::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::Type::getIntegralFlags() const

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

ConstantValue slang::Type::getDefaultValue() const

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

ConstantRange slang::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::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::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.