SPPCompiler.SemanticAnalysis.Asts.Mixins.AbstractTypeAst module¶
- class SPPCompiler.SemanticAnalysis.Asts.Mixins.AbstractTypeAst.AbstractTypeAst¶
Bases:
AbstractTypeTemporaryAst
The AbstractTypeAst contains a number of methods required to be implemented by all the different TypeAst classes. This allows for any of the Unary/Postfix/Single types to be used for any TypeAst value, with a common interface for all utility methods.
- is_never_type()¶
- Return type:
bool
- property fq_type_parts: list[Asts.IdentifierAst | Asts.TypeIdentifierAst]¶
The fully qualified type parts of the type. This extracts the IdentifierAst nodes and TypeIdentifierAst nodes that are part of the type. The fq_type_parts of “std::vector::Vec[T]::Element” would be [“std”, “vector”, “Vec”, “Element”].
- property namespace_parts: list[Asts.IdentifierAst]¶
The namespace parts of the type. This extracts the IdentifierAst nodes preceding the TypeIdentifier for this type. The namespace parts of “std::vector::Vec[T]::Element” would be [“std”, “vector”].
- property type_parts: list[Asts.TypeIdentifierAst]¶
The type parts of the type. This extracts the TypeIdentifierAst nodes that are part of the type. The type parts of “std::vector::Vec[T]::Element” would be [“Vec”, “Element”].
- property without_convention: Asts.TypeAst | None¶
Get the type without any convention. This is used to get the type without any convention, for example, “&T” would become “T”.
- property convention: Asts.ConventionAst | None¶
Get the convention of the type. This is gets th outer “borrow” convention ast if there is one present. For example, “&T” would return the “&” convention ast, while “T” would return “None”.
- property without_generics: Asts.TypeAst | None¶
Get the type without any generic arguments. This is used to get the type without any generic arguments, for example, “Vec[T]” would become “Vec”. This is used in the type inference process to get the base type of a generic type.
- substituted_generics(generic_arguments)¶
Substitute the generic arguments in a type. This allows “Vec[T]” to become “Vec[Str]” when it is known that “T” is a “Str”. This is used in the type inference process. This creates a new type ast with the generics substituted, and returns the new type ast.
- match_generic(that, generic_name)¶
Perform a deep search to match a generic fro the type (almost an inverse of the substitute generics; search rather than substitute). For example, when comparing “Vec[T]” with “Vec[Str]”, looking for “T”, “Str” would be returned. Types of varying generic depths are supported, which is key for advanced inference.
- contains_generic(generic_type)¶
Check recursively in this type, and its generic arguments, if the generic target type exists as a generic argument to a generic parameter. This is used to check that superimposition generics are constrained, and therefore inferrable, inside the “sup” block.
- final with_generics(generics_argument_group)¶
Directly set the generics argument group for this type. This doesn’t use substitution, but rather “glues” the generics argument group to the type. This is used when the generics are already known to be valid.
- final with_convention(convention)¶
Create a new instance of a type (that contains this original type), which acts as a unary type wrapper, with the given convention. This is used to attach conventions to types, for example, “&T”.
- Parameters:
convention – The convention to attach to the type.
- Returns:
The new type ast with the attached convention.
- class SPPCompiler.SemanticAnalysis.Asts.Mixins.AbstractTypeAst.AbstractTypeTemporaryAst¶
Bases:
object
The AbstractTypeTemporaryAst is a temporary type ast that is used or instant-conversion purposes. The ast that it is inherited by will only be created for conversion purposes, ie shorthand type syntax.
- convert()¶
This method allows conversion of temporarily created TypeAsts, to reduce the amount of analysing for different type asts. For example, “(Bool, Bool)” is converted into “Tup[Bool, Bool]” before it is ever analysed. All type shorthands implement and use this method.