sun::types::ClassType
class · Source (opens in a new tab)
class sun::types::ClassType : public sun::types::NominalTypeClass 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
- sun::types::NominalType (public)
Public Functions
- ClassType
- addField
- addImplementedInterface
- addMethod
- bindInterfaceMethod
- convertibleToInterface
- equals
- getBaseGenericName
- getBaseName
- getConstructor
- getDisplayName
- getField
- getFields
- getGenericQualifiedName
- getImplementedInterfaces
- getInterfaceMethod
- getKind
- getLifetimeParams
- getMethod
- getMethodForArgs
- getMethods
- getQualifiedName
- getStructType
- getTypeArguments
- getTypeParameters
- hasBaseName
- hasField
- hasQualifiedName
- implementsInterface
- isArrayCompatible
- isGenericDefinition
- isInterfaceConvertible
- isPacked
- isSpecialized
- markStaticOnlyInterface
- setBaseName
- setGenericQualifiedName
- setLifetimeParams
- setMethodReturnType
- setPacked
- setQualifiedName
- toDisplayString
- toLLVMType
- toString
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) constReport 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 overrideReports 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() constReturns 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() constBase name accessors (user-written name for error messages).
getConstructor
public · function · Source (opens in a new tab)
const ClassMethod * sun::types::ClassType::getConstructor() constGet the constructor method (named "init").
Related: ClassMethod
getDisplayName
public · function · Source (opens in a new tab)
std::string sun::types::ClassType::getDisplayName() constGet 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) constRetrieve 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) constReturns 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() constProvides 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() constQualified 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() constProvides the interfaces implemented by this class.
Related: DeclarationId
getInterfaceMethod
public · function · Source (opens in a new tab)
DeclarationId sun::types::ClassType::getInterfaceMethod(DeclarationId requirement) constRetrieve the concrete method selected during conformance checking.
Related: DeclarationId
getKind
public · function · Source (opens in a new tab)
Kind sun::types::ClassType::getKind() const overrideReturns 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() constProvides 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) constRetrieve 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) constReturns 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) constThe 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() constProvides 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() constQualified 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) constGet the actual struct type for the class.
getTypeArguments
public · function · Source (opens in a new tab)
const std::vector< TypePtr > & sun::types::ClassType::getTypeArguments() constProvides 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() constProvides the generic parameters declared by this type or function.
hasBaseName
public · function · Source (opens in a new tab)
bool sun::types::ClassType::hasBaseName() constReports 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) constReports whether this object has field.
hasQualifiedName
public · function · Source (opens in a new tab)
bool sun::types::ClassType::hasQualifiedName() constReports 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) constCheck 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() constReports 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() constPacked 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() constReports 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 overrideReturns 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 overrideClasses are value types represented as LLVM structs.
toString
public · function · Source (opens in a new tab)
std::string sun::types::ClassType::toString() const overrideReturns 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::ClassNo documentation comment.
Related: Kind, Kind::Class
deinitializer
public · variable · Source (opens in a new tab)
DeclarationId sun::types::ClassType::deinitializerThe 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::PrivateNo 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::TypeRegistryNo documentation comment.
Related: sun::semantic_analysis::TypeRegistry
Private Fields
- baseGenericName
- baseName_
- cachedLLVMType
- fields
- genericQualifiedName_
- implementedInterfaces
- interfaceImplementations_
- isPacked_
- lifetimeParams_
- methods
- name_
- qualifiedName_
- staticOnlyInterfaces
- typeArguments
- typeParameters
baseGenericName
private · variable · Source (opens in a new tab)
std::string sun::types::ClassType::baseGenericNameNo 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 = nullptrNo documentation comment.
fields
private · variable · Source (opens in a new tab)
std::vector<ClassField> sun::types::ClassType::fieldsNo 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::implementedInterfacesNo 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_ = falseNo 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::methodsNo 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::staticOnlyInterfacesNo documentation comment.
Related: DeclarationId
typeArguments
private · variable · Source (opens in a new tab)
std::vector<TypePtr> sun::types::ClassType::typeArgumentsNo documentation comment.
Related: TypePtr
typeParameters
private · variable · Source (opens in a new tab)
std::vector<std::string> sun::types::ClassType::typeParametersNo documentation comment.