sun::types::EnumType

sun::types::EnumType

class · Source (opens in a new tab)

class sun::types::EnumType : public sun::types::NominalType

Enum type for user-defined enums Enums use an integer representation, with variants as named constants Example: enum Color { Red, Green, Blue }.

Inherits

Public Functions

EnumType

EnumType(std::string name_, std::vector< EnumVariant > vars, std::string baseName="")

public · function · Source (opens in a new tab)

sun::types::EnumType::EnumType(std::string name_, std::vector< EnumVariant > vars, std::string baseName="")

Creates a semantic enum descriptor with its name and optional variants.

Related: EnumVariant

EnumType(std::string name_, std::string baseName="")

public · function · Source (opens in a new tab)

sun::types::EnumType::EnumType(std::string name_, std::string baseName="")

Creates a semantic enum descriptor with its name and optional variants.

addVariant

public · function · Source (opens in a new tab)

void sun::types::EnumType::addVariant(const std::string &variantName, int64_t value, DeclarationId declarationId={})

Register a variant once, retaining its declaration identity.

Related: DeclarationId

equals

public · function · Source (opens in a new tab)

bool sun::types::EnumType::equals(const Type &other) const override

Reports whether the other type has the same semantic identity.

Related: Type

getBaseName

public · function · Source (opens in a new tab)

const std::string & sun::types::EnumType::getBaseName() const

Base name accessor.

getDisplayName

public · function · Source (opens in a new tab)

std::string sun::types::EnumType::getDisplayName() const

Get user-friendly display name for error messages.

getGenericArgs

public · function · Source (opens in a new tab)

const std::vector< TypePtr > & sun::types::EnumType::getGenericArgs() const

Returns the generic type arguments.

Related: TypePtr

getGenericBase

public · function · Source (opens in a new tab)

const std::string & sun::types::EnumType::getGenericBase() const

Returns the original generic declaration.

getGenericQualifiedName

public · function · Source (opens in a new tab)

const sun::semantic_analysis::QualifiedName & sun::types::EnumType::getGenericQualifiedName() const

The original template name, independent of specialization and source aliases.

Related: sun::semantic_analysis::QualifiedName

getKind

public · function · Source (opens in a new tab)

Kind sun::types::EnumType::getKind() const override

Returns the type category used for semantic checks and dispatch.

Related: Kind

getName

public · function · Source (opens in a new tab)

const std::string & sun::types::EnumType::getName() const

Returns the declared name used to identify this object.

getNumVariants

public · function · Source (opens in a new tab)

size_t sun::types::EnumType::getNumVariants() const

Get the number of variants.

getQualifiedName

public · function · Source (opens in a new tab)

const sun::semantic_analysis::QualifiedName & sun::types::EnumType::getQualifiedName() const

Source spelling; declaration records carry module ownership.

Related: sun::semantic_analysis::QualifiedName

getUnderlyingType

public · function · Source (opens in a new tab)

const TypePtr & sun::types::EnumType::getUnderlyingType() const

Return the integer type used to store the enum tag.

Related: TypePtr

getVariant

public · function · Source (opens in a new tab)

const EnumVariant * sun::types::EnumType::getVariant(const std::string &variantName) const

Returns the variant stored by this object.

Related: EnumVariant

getVariants

public · function · Source (opens in a new tab)

const std::vector< EnumVariant > & sun::types::EnumType::getVariants() const

Provides the alternatives declared by this enum.

Related: EnumVariant

hasBaseName

public · function · Source (opens in a new tab)

bool sun::types::EnumType::hasBaseName() const

Reports whether the unqualified declaration name is available.

hasPayload

public · function · Source (opens in a new tab)

bool sun::types::EnumType::hasPayload() const

True if any variant carries a payload (tagged-union representation).

hasVariant

public · function · Source (opens in a new tab)

bool sun::types::EnumType::hasVariant(const std::string &variantName) const

Check if a variant exists by name.

isGenericSpecialization

public · function · Source (opens in a new tab)

bool sun::types::EnumType::isGenericSpecialization() const

Reports whether this type represents generic specialization values.

setBaseName

public · function · Source (opens in a new tab)

void sun::types::EnumType::setBaseName(std::string baseName)

Sets the unqualified declaration name without changing its enclosing scopes.

setGenericOrigin

public · function · Source (opens in a new tab)

void sun::types::EnumType::setGenericOrigin(std::string base, std::vector< TypePtr > args)

Generic specialization origin (e.g.

Option_i32 records base "Option" and args [i32]); empty for non-generic enums.

Related: TypePtr

setGenericQualifiedName

public · function · Source (opens in a new tab)

void sun::types::EnumType::setGenericQualifiedName(sun::semantic_analysis::QualifiedName name)

Record the template that produced this type.

Related: sun::semantic_analysis::QualifiedName

setQualifiedName

public · function · Source (opens in a new tab)

void sun::types::EnumType::setQualifiedName(sun::semantic_analysis::QualifiedName qn)

Records the declaration name together with its enclosing scopes.

Related: sun::semantic_analysis::QualifiedName

setUnderlyingType

public · function · Source (opens in a new tab)

void sun::types::EnumType::setUnderlyingType(TypePtr type)

Set the integer representation before generating enum storage.

Related: TypePtr

setVariantPayloadTypes

public · function · Source (opens in a new tab)

void sun::types::EnumType::setVariantPayloadTypes(const std::string &variantName, std::vector< TypePtr > payloadTypes)

Attach resolved payload types to a variant (full-analysis phase; payload annotations may reference classes not yet registered during declaration collection).

Related: TypePtr

toDisplayString

public · function · Source (opens in a new tab)

std::string sun::types::EnumType::toDisplayString() const override

Returns a source-facing type name without internal compiler prefixes.

toLLVMType

public · function · Source (opens in a new tab)

llvm::Type * sun::types::EnumType::toLLVMType(llvm::LLVMContext &ctx) const override

Payload-free enums use their integer type.

Payload enums need the module DataLayout for storage sizing: LLVMTypeResolver computes the storage struct and caches it here; afterwards toLLVMType serves the cache (e.g. for class field embedding via ClassType::getStructType).

Related: ClassType::getStructType

toString

public · function · Source (opens in a new tab)

std::string sun::types::EnumType::toString() const override

Returns a readable representation for diagnostics and debugging.

Public Fields

StaticKind

public · variable · static · Source (opens in a new tab)

Kind sun::types::EnumType::StaticKind = Kind::Enum

No documentation comment.

Related: Kind, Kind::Enum

cachedStorageType

public · variable · Source (opens in a new tab)

llvm::StructType* sun::types::EnumType::cachedStorageType = nullptr

No documentation comment.

cachedVariantStructs

public · variable · Source (opens in a new tab)

std::unordered_map<std::string, llvm::StructType*> sun::types::EnumType::cachedVariantStructs

No documentation comment.

visibility

public · variable · Source (opens in a new tab)

sun::semantic_analysis::Visibility sun::types::EnumType::visibility =
      sun::semantic_analysis::Visibility::Private

No documentation comment.

Related: sun::semantic_analysis::Visibility, sun::semantic_analysis::Visibility::Private

Public Friends

sun::semantic_analysis::TypeRegistry

public · friend · Source (opens in a new tab)

friend class sun::semantic_analysis::TypeRegistry

No documentation comment.

Related: sun::semantic_analysis::TypeRegistry

Private Fields

baseName_

private · variable · Source (opens in a new tab)

std::string sun::types::EnumType::baseName_

No documentation comment.

genericArgs_

private · variable · Source (opens in a new tab)

std::vector<TypePtr> sun::types::EnumType::genericArgs_

No documentation comment.

Related: TypePtr

genericBase_

private · variable · Source (opens in a new tab)

std::string sun::types::EnumType::genericBase_

No documentation comment.

genericQualifiedName_

private · variable · Source (opens in a new tab)

sun::semantic_analysis::QualifiedName sun::types::EnumType::genericQualifiedName_

No documentation comment.

Related: sun::semantic_analysis::QualifiedName

name_

private · variable · Source (opens in a new tab)

std::string sun::types::EnumType::name_

No documentation comment.

qualifiedName_

private · variable · Source (opens in a new tab)

sun::semantic_analysis::QualifiedName sun::types::EnumType::qualifiedName_

No documentation comment.

Related: sun::semantic_analysis::QualifiedName

underlyingType_

private · variable · Source (opens in a new tab)

TypePtr sun::types::EnumType::underlyingType_ = std::make_shared<PrimitiveType>(Kind::Int32)

No documentation comment.

Related: TypePtr, PrimitiveType, Kind::Int32

variants

private · variable · Source (opens in a new tab)

std::vector<EnumVariant> sun::types::EnumType::variants

No documentation comment.

Related: EnumVariant