sun::semantic_analysis::TypeRegistry
class · Source (opens in a new tab)
class sun::semantic_analysis::TypeRegistryTypeRegistry - Per-compilation-unit registry for class and interface types.
This replaces the static caches in Types class to avoid cross-test pollution. One exists per compilation, as part of its AnalysisResults, next to the DeclarationTable whose declarations its types are created for.
Public Functions
- TypeRegistry
- clear
- findSpecialization
- getClass
- getEnum
- getGenericInterface
- getInterface
- getSpecializedClass
- getSpecializedInterface
- isBuiltinTypeName
- operator=
- registerBuiltins
- specialize
TypeRegistry
TypeRegistry(DeclarationTable &declarations)
public · function · Source (opens in a new tab)
sun::semantic_analysis::TypeRegistry::TypeRegistry(DeclarationTable &declarations)Initializes the collection of primitive and declared semantic types.
Every type is created for a declaration in declarations, which belongs to the same analysis results and must outlive the registry.
Related: DeclarationTable
TypeRegistry(const TypeRegistry &)=delete
public · function · Source (opens in a new tab)
sun::semantic_analysis::TypeRegistry::TypeRegistry(const TypeRegistry &)=deleteNon-copyable to prevent accidental duplication.
TypeRegistry(TypeRegistry &&)=default
public · function · Source (opens in a new tab)
sun::semantic_analysis::TypeRegistry::TypeRegistry(TypeRegistry &&)=defaultMovable.
clear
public · function · Source (opens in a new tab)
void sun::semantic_analysis::TypeRegistry::clear()Clear all caches (useful for REPL reset).
findSpecialization
public · function · Source (opens in a new tab)
DeclarationId sun::semantic_analysis::TypeRegistry::findSpecialization(const SpecializationKey &key) constReturn an existing instance without allocating a declaration.
Related: DeclarationId, SpecializationKey
getClass
getClass(DeclarationId id, const QualifiedName &name)
public · function · Source (opens in a new tab)
std::shared_ptr< sun::types::ClassType > sun::semantic_analysis::TypeRegistry::getClass(DeclarationId id, const QualifiedName &name)Bind the current source name to a source class's existing identity.
Related: sun::types::ClassType, DeclarationId, QualifiedName
getClass(DeclarationId id)
public · function · Source (opens in a new tab)
std::shared_ptr< sun::types::ClassType > sun::semantic_analysis::TypeRegistry::getClass(DeclarationId id)Get a source class before its source name has been assigned.
Related: sun::types::ClassType, DeclarationId
getEnum
getEnum(DeclarationId id)
public · function · Source (opens in a new tab)
std::shared_ptr< sun::types::EnumType > sun::semantic_analysis::TypeRegistry::getEnum(DeclarationId id)Get a source enum before its source name has been assigned.
Related: sun::types::EnumType, DeclarationId
getEnum(DeclarationId id, const QualifiedName &name)
public · function · Source (opens in a new tab)
std::shared_ptr< sun::types::EnumType > sun::semantic_analysis::TypeRegistry::getEnum(DeclarationId id, const QualifiedName &name)Bind the current source name to a source enum's existing identity.
Related: sun::types::EnumType, DeclarationId, QualifiedName
getGenericInterface
public · function · Source (opens in a new tab)
std::shared_ptr< sun::types::InterfaceType > sun::semantic_analysis::TypeRegistry::getGenericInterface(DeclarationId declaration, const QualifiedName &name, std::vector< std::string > typeParams)Intern a generic interface template by its source declaration.
Related: sun::types::InterfaceType, DeclarationId, QualifiedName
getInterface
getInterface(DeclarationId id)
public · function · Source (opens in a new tab)
std::shared_ptr< sun::types::InterfaceType > sun::semantic_analysis::TypeRegistry::getInterface(DeclarationId id)Get a source interface before its source name has been assigned.
Related: sun::types::InterfaceType, DeclarationId
getInterface(DeclarationId id, const QualifiedName &name)
public · function · Source (opens in a new tab)
std::shared_ptr< sun::types::InterfaceType > sun::semantic_analysis::TypeRegistry::getInterface(DeclarationId id, const QualifiedName &name)Bind the current source name to a source interface's identity.
Related: sun::types::InterfaceType, DeclarationId, QualifiedName
getSpecializedClass
public · function · Source (opens in a new tab)
std::shared_ptr< sun::types::ClassType > sun::semantic_analysis::TypeRegistry::getSpecializedClass(DeclarationId id, const QualifiedName &name, const QualifiedName &source, const std::vector< sun::types::TypePtr > &arguments)Configure the class attached to an interned specialization.
Related: sun::types::ClassType, DeclarationId, QualifiedName, sun::types::TypePtr
getSpecializedInterface
public · function · Source (opens in a new tab)
std::shared_ptr< sun::types::InterfaceType > sun::semantic_analysis::TypeRegistry::getSpecializedInterface(DeclarationId id, const QualifiedName &name, const QualifiedName &source, const std::vector< sun::types::TypePtr > &arguments)Configure the interface attached to an interned specialization.
Related: sun::types::InterfaceType, DeclarationId, QualifiedName, sun::types::TypePtr
isBuiltinTypeName
public · function · Source (opens in a new tab)
bool sun::semantic_analysis::TypeRegistry::isBuiltinTypeName(const std::string &name) constReports whether a class or interface name would redefine a builtin error type.
Type trait names such as _Integer need no entry: the parser already rejects a declared name that starts with _.
Related: Type
operator=
operator=(const TypeRegistry &)=delete
public · function · Source (opens in a new tab)
TypeRegistry & sun::semantic_analysis::TypeRegistry::operator=(const TypeRegistry &)=deleteDisallows assignment so ownership and object identity cannot be duplicated.
Related: TypeRegistry
operator=(TypeRegistry &&)=default
public · function · Source (opens in a new tab)
TypeRegistry & sun::semantic_analysis::TypeRegistry::operator=(TypeRegistry &&)=defaultTransfers the stored state from another instance during move assignment.
Related: TypeRegistry
registerBuiltins
public · function · Source (opens in a new tab)
void sun::semantic_analysis::TypeRegistry::registerBuiltins()Register built-in error types.
The iteration protocol (IIterator/IIterable) lives in stdlib/iterator.sun since it names Option.
specialize
public · function · Source (opens in a new tab)
DeclarationId sun::semantic_analysis::TypeRegistry::specialize(const SpecializationKey &key)Intern an instance before resolving its members or body.
Related: DeclarationId, SpecializationKey
Public Fields
arithmeticError
public · variable · Source (opens in a new tab)
std::shared_ptr<sun::types::ClassType> sun::semantic_analysis::TypeRegistry::arithmeticErrorBuiltin error thrown by invalid integer division and remainder.
Related: sun::types::ClassType
errorInterface
public · variable · Source (opens in a new tab)
std::shared_ptr<sun::types::InterfaceType> sun::semantic_analysis::TypeRegistry::errorInterfaceThe builtin error interface shared throughout this analysis session.
Related: sun::types::InterfaceType
Private Functions
nominalType
private · function · Source (opens in a new tab)
template <typename T>
std::shared_ptr< T > sun::semantic_analysis::TypeRegistry::nominalType(DeclarationId id, DeclarationKind kind)Looks up the class, interface, or enum type for a declaration identity.
Related: DeclarationId, DeclarationKind
registerArithmeticError
private · function · Source (opens in a new tab)
void sun::semantic_analysis::TypeRegistry::registerArithmeticError()Registers the builtin arithmetic error after its IError interface.
registerIError
private · function · Source (opens in a new tab)
void sun::semantic_analysis::TypeRegistry::registerIError()Registers the builtin error interface and its code and message methods.
Private Fields
declarations_
private · variable · Source (opens in a new tab)
DeclarationTable& sun::semantic_analysis::TypeRegistry::declarations_No documentation comment.
Related: DeclarationTable
nominalTypes_
private · variable · Source (opens in a new tab)
std::unordered_map<DeclarationId, std::shared_ptr<sun::types::NominalType> > sun::semantic_analysis::TypeRegistry::nominalTypes_No documentation comment.
Related: DeclarationId, sun::types::NominalType
specializations_
private · variable · Source (opens in a new tab)
std::unordered_map<SpecializationKey, DeclarationId, SpecializationKeyHash> sun::semantic_analysis::TypeRegistry::specializations_No documentation comment.
Related: SpecializationKey, DeclarationId, SpecializationKeyHash