slang::ast::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
Constructs a new instance of the class.

Public functions

auto getType() const -> const Type&
Resolves and returns the actual type.
void setType(const Type& newType)
Manually sets the resolved type, overriding anything that may have been resolved previously.
void setTypeSyntax(const syntax::DataTypeSyntax& newType)
Sets the source syntax for the type, which will later be used when resolution is requested.
void setLink(const DeclaredType& target)
Sets this declared type to link to the given type, taking on whatever type and initializer that target has.
auto getTypeSyntax() const -> const syntax::DataTypeSyntax*
Gets the type syntax that was previously set via setTypeSyntax – if any.
void setDimensionSyntax(const syntax::SyntaxList<syntax::VariableDimensionSyntax>& newDimensions)
Sets an additional set of dimensions that represent the unpacked portion of the type declaration.
auto getDimensionSyntax() const -> const syntax::SyntaxList<syntax::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)
Manually sets the resolved initializer expression, overriding anything that may have been resolved previously.
void setInitializerSyntax(const syntax::ExpressionSyntax& syntax, SourceLocation loc)
Sets the syntax for the initializer expression, which will be later used when resolution is requested.
auto getInitializerSyntax() const -> const syntax::ExpressionSyntax*
Gets the initializer syntax previously set by setInitializerSyntax.
auto getInitializerLocation() const -> SourceLocation
Gets the initializer location previously set by setInitializerSyntax.
void setFromDeclarator(const syntax::DeclaratorSyntax& decl)
Sets type and initializer information from the given declarator syntax.
auto isEvaluating() const -> bool
Returns true if this declared type is in the process of being resolved.
void setOverrideIndex(SymbolIndex index)
Sets a separate, later position in the parent scope for creating the declared type and initializer.
void addFlags(bitmask<DeclaredTypeFlags> toAdd)
Adds additional type resolution flags to constrain resolution behavior.
auto getFlags() const -> bitmask<DeclaredTypeFlags>
Gets the flags associated with this declared type.
void mergeImplicitPort(const syntax::ImplicitTypeSyntax& implicit, SourceLocation location, std::span<const syntax::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 resolveAt(const ASTContext& context) const
Resolves the initializer using the given AST context, which could differ from the AST context that is used for type resolution.
void forceResolveAt(const ASTContext& context) const
Forces resolution of both the type and the initializer using the given AST context instead of using the normal logic built into DeclaredType to determine the context.

Function documentation

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

Constructs a new instance of the class.

Parameters
parent The parent symbol that owns the declared type.
flags Optional additional flags that constrain type resolution.

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

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

Otherwise returns nullptr.

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

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

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

void slang::ast::DeclaredType::setFromDeclarator(const syntax::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::ast::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.

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

Sets a separate, later position in the parent scope for creating 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::ast::DeclaredType::addFlags(bitmask<DeclaredTypeFlags> toAdd)

Adds additional type resolution flags to constrain resolution behavior.

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