slang::DeclaredType class

Ties together various syntax nodes that declare the type of some parent symbol along with the logic necessary to resolve that type. Optionally includes an initializer expression as well, which can be necessary when resolving types that are implicitly inferred from the initializer.

Constructors, destructors, conversion operators

DeclaredType(const Symbol& parent, bitmask<DeclaredTypeFlags> flags = DeclaredTypeFlags::None) explicit

Public functions

auto getType() const -> const Type&
Resolves and returns the actual type.
void setType(const Type& newType)
void setTypeSyntax(const DataTypeSyntax& newType)
auto getTypeSyntax() const -> const DataTypeSyntax*
void setDimensionSyntax(const SyntaxList<VariableDimensionSyntax>& newDimensions)
auto getDimensionSyntax() const -> const SyntaxList<VariableDimensionSyntax>*
Gets any previously set unpacked dimensions.
auto getInitializer() const -> const Expression*
Resolves and returns the initializer expression, if present. Otherwise returns nullptr.
void setInitializer(const Expression& expr)
void setInitializerSyntax(const ExpressionSyntax& syntax, SourceLocation loc)
auto getInitializerSyntax() const -> const ExpressionSyntax*
Gets the initializer syntax previously set by setInitializerSyntax.
auto getInitializerLocation() const -> SourceLocation
Gets the initializer location previously set by setInitializerSyntax.
void setFromDeclarator(const DeclaratorSyntax& decl)
auto isEvaluating() const -> bool
auto hasResolvedInitializer() const -> bool
void setOverrideIndex(SymbolIndex index)
void addFlags(bitmask<DeclaredTypeFlags> toAdd)
void mergeImplicitPort(const ImplicitTypeSyntax& implicit, SourceLocation location, span<const VariableDimensionSyntax*const> unpackedDimensions)
void copyTypeFrom(const DeclaredType& source)
void resolveAt(const BindContext& context) const

Function documentation

slang::DeclaredType::DeclaredType(const Symbol& parent, bitmask<DeclaredTypeFlags> flags = DeclaredTypeFlags::None) explicit

Parameters
parent is the parent symbol that owns the declared type. @flags are optional additional flags that constraint type resolution.
flags

Constructs a new instance of the class.

void slang::DeclaredType::setType(const Type& newType)

Manually sets the resolved type, overriding anything that may have been resolved previously.

void slang::DeclaredType::setTypeSyntax(const DataTypeSyntax& newType)

Sets the source syntax for the type, which will later be used when resolution is requested.

const DataTypeSyntax* slang::DeclaredType::getTypeSyntax() const

Gets the type syntax that was previously set via setTypeSyntax – if any. Otherwise returns nullptr.

void slang::DeclaredType::setDimensionSyntax(const SyntaxList<VariableDimensionSyntax>& newDimensions)

Sets an additional set of dimensions that represent the unpacked portion of the type declaration.

void slang::DeclaredType::setInitializer(const Expression& expr)

Manually sets the resolved initializer expression, overriding anything that may have been resolved previously.

void slang::DeclaredType::setInitializerSyntax(const ExpressionSyntax& syntax, SourceLocation loc)

Parameters
syntax
loc is the source location to use when reporting diagnostics about the initializer.

Sets the syntax for the initializer expression, which will be later used when resolution is requested.

void slang::DeclaredType::setFromDeclarator(const DeclaratorSyntax& decl)

Sets type and initializer information from the given declarator syntax. This is just convenient shorthand for invoking setTypeSyntax and setInitializerSyntax manually.

bool slang::DeclaredType::isEvaluating() const

Returns true if this declared type is in the process of being resolved. This is used to detect cycles in the the type resolution process.

bool slang::DeclaredType::hasResolvedInitializer() const

Indicates whether this declared type has an already resolved initializer expression. If no initializer syntax has been set, or if it has but the initializer has not being resolved yet, returns false.

void slang::DeclaredType::setOverrideIndex(SymbolIndex index)

Sets a separate, later position in the parent scope for binding the declared type and initializer. This is used for merged port symbols because their declared I/O location and symbol location may differ.

void slang::DeclaredType::addFlags(bitmask<DeclaredTypeFlags> toAdd)

Adds additional type resolution flags to constraint resolution behavior. This will clear any resolved type to force resolution again with the new flags set.

void slang::DeclaredType::mergeImplicitPort(const ImplicitTypeSyntax& implicit, SourceLocation location, span<const VariableDimensionSyntax*const> unpackedDimensions)

Perform a merge of implicit port information; this facilitates the non-ascii port system permitted by Verilog, where port I/O declarations are separate from the actual symbol declaration but may still carry some type info.

void slang::DeclaredType::copyTypeFrom(const DeclaredType& source)

Copies any type information from the provided source – does not include initializer information.

void slang::DeclaredType::resolveAt(const BindContext& context) const

Forces resolution of type (and the initializer as well if applicable) using the given bind context, which could differ from the normal binding context that would otherwise be used for resolution.