sun::types::ClassType

sun::types::ClassType

class · Source (opens in a new tab)

class sun::types::ClassType : public sun::types::NominalType

Class type for user-defined classes Classes are represented as LLVM structs with methods as separate functions Generic classes have type parameters (e.g., class List<T>) Specialized classes have type arguments (e.g., List<i32>).

Inherits

Public Functions

ClassType

ClassType(std::string className)

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

sun::types::ClassType::ClassType(std::string className)

Creates a semantic class descriptor under its declared name.

ClassType(std::string className, std::vector< std::string > typeParams)

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

sun::types::ClassType::ClassType(std::string className, std::vector< std::string > typeParams)

Constructor for generic class definition.

ClassType(std::string name_, std::string baseName, std::vector< TypePtr > typeArgs)

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

sun::types::ClassType::ClassType(std::string name_, std::string baseName, std::vector< TypePtr > typeArgs)

Constructor for specialized generic class.

Related: TypePtr

addField

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

ClassField & sun::types::ClassType::addField(const std::string &fieldName, TypePtr fieldType, DeclarationId id={})

Returns the new record so callers can set its access info.

Related: ClassField, TypePtr, DeclarationId

addImplementedInterface

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

void sun::types::ClassType::addImplementedInterface(const InterfaceType &interface)

Record a resolved interface implemented by this class.

Related: InterfaceType

addMethod

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

ClassMethod & sun::types::ClassType::addMethod(const std::string &methodName, TypePtr returnType, std::vector< TypePtr > paramTypes, bool isConstructor=false, std::vector< std::string > typeParams={}, bool canThrow=false)

Registers a method signature on this type for lookup and dispatch.

Related: ClassMethod, TypePtr

bindInterfaceMethod

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

void sun::types::ClassType::bindInterfaceMethod(DeclarationId requirement, DeclarationId implementation)

Record the concrete method selected for an interface declaration.

Related: DeclarationId

convertibleToInterface

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

bool sun::types::ClassType::convertibleToInterface(const InterfaceType &interface) const

Report whether a resolved interface can be used as a fat pointer.

Related: InterfaceType

equals

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

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

Reports whether the other type has the same semantic identity.

Related: Type

getBaseGenericName

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

const std::string & sun::types::ClassType::getBaseGenericName() const

Returns the original generic name used to identify this specialization.

getBaseName

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

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

Base name accessors (user-written name for error messages).

getConstructor

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

const ClassMethod * sun::types::ClassType::getConstructor() const

Get the constructor method (named "init").

Related: ClassMethod

getDisplayName

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

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

Get user-friendly display name for error messages For specialized classes: "Vec<i32>" or "std.Vec<i32>" For non-specialized classes, preserve the source spelling.

getField

getField(DeclarationId id) const

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

const ClassField * sun::types::ClassType::getField(DeclarationId id) const

Retrieve a selected field independently of its spelling and layout.

Related: ClassField, DeclarationId

getField(const std::string &fieldName) const

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

const ClassField * sun::types::ClassType::getField(const std::string &fieldName) const

Returns the field stored by this object.

Related: ClassField

getFields

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

const std::vector< ClassField > & sun::types::ClassType::getFields() const

Provides the field declarations belonging to this type.

Related: ClassField

getGenericQualifiedName

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

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

Qualified name of the generic this specialization was instantiated from (scope path + plain base name), for scope-tree lookups.

Related: sun::semantic_analysis::QualifiedName

getImplementedInterfaces

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

const std::vector< DeclarationId > & sun::types::ClassType::getImplementedInterfaces() const

Provides the interfaces implemented by this class.

Related: DeclarationId

getInterfaceMethod

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

DeclarationId sun::types::ClassType::getInterfaceMethod(DeclarationId requirement) const

Retrieve the concrete method selected during conformance checking.

Related: DeclarationId

getKind

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

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

Returns the type category used for semantic checks and dispatch.

Related: Kind

getLifetimeParams

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

const std::vector< std::string > & sun::types::ClassType::getLifetimeParams() const

Provides the lifetime parameters associated with this declaration.

getMethod

getMethod(DeclarationId declaration) const

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

const ClassMethod * sun::types::ClassType::getMethod(DeclarationId declaration) const

Retrieve a selected method without repeating overload resolution.

Related: ClassMethod, DeclarationId

getMethod(const std::string &methodName) const

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

const ClassMethod * sun::types::ClassType::getMethod(const std::string &methodName) const

Returns the method stored by this object.

Related: ClassMethod

getMethodForArgs

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

const ClassMethod * sun::types::ClassType::getMethodForArgs(const std::string &methodName, const std::vector< TypePtr > &argTypes) const

The method named methodName whose parameters accept argTypes, under the same rules a call site applies (types/argument_compatibility.h).

An overload matching every argument exactly is preferred over one that needs conversions; among the latter the first declared wins. Null when no overload accepts the arguments.

Related: ClassMethod, TypePtr, types/argument_compatibility.h

getMethods

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

const std::vector< ClassMethod > & sun::types::ClassType::getMethods() const

Provides the method declarations belonging to this type.

Related: ClassMethod

getQualifiedName

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

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

Qualified name accessors.

Related: sun::semantic_analysis::QualifiedName

getStructType

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

llvm::StructType * sun::types::ClassType::getStructType(llvm::LLVMContext &ctx) const

Get the actual struct type for the class.

getTypeArguments

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

const std::vector< TypePtr > & sun::types::ClassType::getTypeArguments() const

Provides the concrete types supplied for generic specialization.

Related: TypePtr

getTypeParameters

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

const std::vector< std::string > & sun::types::ClassType::getTypeParameters() const

Provides the generic parameters declared by this type or function.

hasBaseName

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

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

Reports whether the unqualified declaration name is available.

hasField

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

bool sun::types::ClassType::hasField(const std::string &fieldName) const

Reports whether this object has field.

hasQualifiedName

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

bool sun::types::ClassType::hasQualifiedName() const

Reports whether a name including the enclosing scopes has been assigned.

implementsInterface

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

bool sun::types::ClassType::implementsInterface(const InterfaceType &interface) const

Check conformance using the interface's session and declaration ID.

Related: InterfaceType

isArrayCompatible

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

static bool sun::types::ClassType::isArrayCompatible(const TypePtr &from, const TypePtr &to)

Returns true if an array argument of type from is compatible with an array parameter of type to (same element type, with an unsized parameter accepting any sized array).

Mirrors the array coercion allowed elsewhere so that e.g. array<i32, 3, 2> can be passed where array<i32> is expected.

Related: TypePtr

isGenericDefinition

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

bool sun::types::ClassType::isGenericDefinition() const

Reports whether this is a generic declaration rather than a concrete instance.

isInterfaceConvertible

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

bool sun::types::ClassType::isInterfaceConvertible(const TypePtr &from, const TypePtr &to)

True if an argument of type from reaches an interface-typed parameter to by conversion to a borrowed fat pointer.

Mirrors the interface rules of isAssignableTo (type_analysis/type_checking.cpp) so that overload selection accepts what a single known signature accepts. Implemented with complete interface and lifetime information.

Related: TypePtr, type_analysis/type_checking.cpp

isPacked

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

bool sun::types::ClassType::isPacked() const

Packed classes have no inter-field padding and struct alignment 1.

Must be set before the first getStructType() call, which memoizes.

Related: getStructType()

isSpecialized

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

bool sun::types::ClassType::isSpecialized() const

Reports whether this type was instantiated with concrete type arguments.

markStaticOnlyInterface

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

void sun::types::ClassType::markStaticOnlyInterface(const InterfaceType &interface)

Mark an implementation whose return ABI prevents dynamic dispatch.

Related: InterfaceType

setBaseName

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

void sun::types::ClassType::setBaseName(std::string bn)

Sets the unqualified declaration name without changing its enclosing scopes.

setGenericQualifiedName

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

void sun::types::ClassType::setGenericQualifiedName(sun::semantic_analysis::QualifiedName qn)

Updates the generic qualified name stored by this object.

Related: sun::semantic_analysis::QualifiedName

setLifetimeParams

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

void sun::types::ClassType::setLifetimeParams(std::vector< std::string > names)

Stores the lifetime parameters associated with this declaration.

setMethodReturnType

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

void sun::types::ClassType::setMethodReturnType(const std::string &name, TypePtr type)

Updates a builtin method contract when the standard String type is known.

Related: TypePtr

setPacked

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

void sun::types::ClassType::setPacked(bool v)

Controls whether the class uses a packed memory layout.

setQualifiedName

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

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

Records the declaration name together with its enclosing scopes.

Related: sun::semantic_analysis::QualifiedName

toDisplayString

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

std::string sun::types::ClassType::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::ClassType::toLLVMType(llvm::LLVMContext &ctx) const override

Classes are value types represented as LLVM structs.

toString

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

std::string sun::types::ClassType::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::ClassType::StaticKind = Kind::Class

No documentation comment.

Related: Kind, Kind::Class

deinitializer

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

DeclarationId sun::types::ClassType::deinitializer

The selected cleanup method, if this class defines one.

Related: DeclarationId

visibility

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

sun::semantic_analysis::Visibility sun::types::ClassType::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

baseGenericName

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

std::string sun::types::ClassType::baseGenericName

No documentation comment.

baseName_

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

std::string sun::types::ClassType::baseName_

No documentation comment.

cachedLLVMType

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

llvm::StructType* sun::types::ClassType::cachedLLVMType = nullptr

No documentation comment.

fields

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

std::vector<ClassField> sun::types::ClassType::fields

No documentation comment.

Related: ClassField

genericQualifiedName_

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

sun::semantic_analysis::QualifiedName sun::types::ClassType::genericQualifiedName_

No documentation comment.

Related: sun::semantic_analysis::QualifiedName

implementedInterfaces

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

std::vector<DeclarationId> sun::types::ClassType::implementedInterfaces

No documentation comment.

Related: DeclarationId

interfaceImplementations_

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

std::unordered_map<DeclarationId, DeclarationId> sun::types::ClassType::interfaceImplementations_

No documentation comment.

Related: DeclarationId

isPacked_

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

bool sun::types::ClassType::isPacked_ = false

No documentation comment.

lifetimeParams_

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

std::vector<std::string> sun::types::ClassType::lifetimeParams_

No documentation comment.

methods

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

std::vector<ClassMethod> sun::types::ClassType::methods

No documentation comment.

Related: ClassMethod

name_

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

std::string sun::types::ClassType::name_

No documentation comment.

qualifiedName_

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

sun::semantic_analysis::QualifiedName sun::types::ClassType::qualifiedName_

No documentation comment.

Related: sun::semantic_analysis::QualifiedName

staticOnlyInterfaces

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

std::vector<DeclarationId> sun::types::ClassType::staticOnlyInterfaces

No documentation comment.

Related: DeclarationId

typeArguments

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

std::vector<TypePtr> sun::types::ClassType::typeArguments

No documentation comment.

Related: TypePtr

typeParameters

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

std::vector<std::string> sun::types::ClassType::typeParameters

No documentation comment.