|
Gyoji Compiler
|
This represents a type as declared in a translation unit. More...
#include <types.hpp>
Public Types | |
| enum | TypeType { TYPE_PRIMITIVE_u8 , TYPE_PRIMITIVE_u16 , TYPE_PRIMITIVE_u32 , TYPE_PRIMITIVE_u64 , TYPE_PRIMITIVE_i8 , TYPE_PRIMITIVE_i16 , TYPE_PRIMITIVE_i32 , TYPE_PRIMITIVE_i64 , TYPE_PRIMITIVE_f32 , TYPE_PRIMITIVE_f64 , TYPE_PRIMITIVE_bool , TYPE_PRIMITIVE_void , TYPE_COMPOSITE , TYPE_ANONYMOUS_STRUCTURE , TYPE_POINTER , TYPE_FUNCTION_POINTER , TYPE_REFERENCE , TYPE_ENUM , TYPE_ARRAY } |
| Type of type. More... | |
This represents a type as declared in a translation unit.
A type consists of several aspects:
The type as resolved should define all of the fields associated in a heirarchal fashion all the way down to the primitive types used to store the data in memory or registers. From this type information, it should be possible to identify the specific operations that can be performed to manipulate any of the data as primitive machine operations.
Type of type.
@description Yes, you read that right. Even types have types. In this case, the type of the type is like a 'category' of type. In many cases, the type is a single entity, but in cases like pointers and classes, the type is composite in some way and may reference other types. Types also have various attributes which make them unique in structure. This enumeration gives the variations that types may have and gives a way to distinguish how the code-generator or analysis phases should reason about the various types.
For example, the borrow-checker may need to reason that a reference to a member variable and a reference to the class containing that member variable are related in an interesting way so that it can reason about the validity of a borrow. This is only possible if the borrow checker can know the attributes of types and how they relate.
| Enumerator | |
|---|---|
| TYPE_PRIMITIVE_u8 | Primitive 8-bit unsigned integer. This represents a single byte unsigned integer capable of storing values from 0 to 255 inclusive. |
| TYPE_PRIMITIVE_u16 | Primitive 16-bit unsigned integer. This represents a two-byte unsigned integer capable of storing values from 0 to 65535 inclusive. |
| TYPE_PRIMITIVE_u32 | Primitive 32-bit unsigned integer. This represents a four-byte unsigned integer capable of storing values from 0 to 2^32-1 inclusive. |
| TYPE_PRIMITIVE_u64 | Primitive 64-bit unsigned integer. This represents a four-byte unsigned integer capable of storing values from 0 to 2^64-1 inclusive. |
| TYPE_PRIMITIVE_i8 | Primitive 8-bit signed integer. This represents a single byte unsigned integer capable of storing values from -128 to 127 inclusive represented in two's complement notation. |
| TYPE_PRIMITIVE_i16 | Primitive 16-bit signed integer. This represents a single byte unsigned integer capable of storing values from -2^15 to 2^15-1 inclusive represented in two's complement notation. |
| TYPE_PRIMITIVE_i32 | Primitive 32-bit signed integer. This represents a single byte unsigned integer capable of storing values from -2^31 to 2^31-1 inclusive represented in two's complement notation. |
| TYPE_PRIMITIVE_i64 | Primitive 64-bit signed integer. This represents a single byte unsigned integer capable of storing values from -2^63 to 2^63-1 inclusive represented in two's complement notation. |
| TYPE_PRIMITIVE_f32 | Primitive 32 bit floating-point number. This is a single precision IEEE floating-point number. |
| TYPE_PRIMITIVE_f64 | Primitive 64 bit floating-point number. This is a double precision IEEE floating-point number. |
| TYPE_PRIMITIVE_bool | Primitive boolean value holding 'true' or 'false'. This may be represented as different physical sizes based on the compiler platform and may be anywhere between 1 bit (packed inside other storage) or as large as the 'natural' type of the platform like a 32-bit value for fast register access. The storage details are left to the specific platform, but the 'sizeof' operation is guaranteed to return the actual storage size used. |
| TYPE_PRIMITIVE_void | Primitive 'void' type. This value represents the absence of a value. It is provided so that, for example, functions can be declared not to return a value. Depending on the specifics of the platform, a value may actually be present and returned, however, the languge will ignore that value if present and will behave as if no data was returned or exchanged. Variables, members, and arguments may not be declared as void, but it may only be used for return-values to indicate their absence. |
| TYPE_COMPOSITE | This is a composite type consisting of one or more other name/type pairs. This may not be a leaf-node because ultimately all types must be resolvable down to primitive types. |
| TYPE_ANONYMOUS_STRUCTURE | This is a pseudo-type that is a 'composite' type used to initialize actual types. This is an anonymous structure containing some number of fields. It's not actually storable and exists only in the MIR. It should not be lowered to the physical machine as it's only used during the code-generation stage as a container for pointers to the actual values. |
| TYPE_POINTER | This is a pointer to another type or to a primitive and is stored internally in a u64 primitive value containing the address of the data to be accessed. |
| TYPE_FUNCTION_POINTER | This is a pointer to a function. |
| TYPE_REFERENCE | This is similar to a pointer and is also stored internally as an address in a u64, but carries additional semantics used by the borrow checker. |
| TYPE_ENUM | This is an enum constant type that resolves to a u32 primitive but may contain names specifying the values they map to. |
| TYPE_ARRAY | This is an array of primitive elements. |
| Type::Type | ( | std::string | _name, |
| std::string | _simple_name, | ||
| TypeType | _type, | ||
| bool | _complete, | ||
| const Gyoji::context::SourceReference & | _source_ref | ||
| ) |
This defines a primitive type of the given type as a primitive type. When declaring variables such as classes, the entirety of the type may not be known right away. In this case, the type is considered 'incomplete'. Examples of this are class forward-declarations. The type of the class is known at the point of forward-declaration, but the members inside it are not yet known and the type is not complete until a 'full' declaration is provided.
Primitive types are always defined as complete.
| Type::Type | ( | std::string | _name, |
| std::string | _simple_name, | ||
| const Gyoji::context::SourceReference & | _source_ref, | ||
| const Type & | _other | ||
| ) |
This defines a type that is a copy of another type. This is used, for example, in a 'typedef' when a type is just different name for an already existing type.
| Type::~Type | ( | ) |
Move along, nothing to see here.
Move along, nothing to see here.
| void Type::complete_array_definition | ( | const Type * | _type, |
| size_t | _array_size, | ||
| const Gyoji::context::SourceReference & | _source_ref | ||
| ) |
Completes the definition of an array type.
| void Type::complete_composite_definition | ( | std::vector< TypeMember > | _members, |
| std::map< std::string, TypeMethod > | _methods, | ||
| const Gyoji::context::SourceReference & | _source_ref | ||
| ) |
Completes the definition of a composite type.
| void Type::complete_function_pointer_definition | ( | const Type * | _return_type, |
| const std::vector< Argument > & | _argument_types, | ||
| bool | _is_unsafe, | ||
| const Gyoji::context::SourceReference & | _source_ref | ||
| ) |
Completes the definition of a function pointer by passing the return-value type and the types of each of the arguments.
| void Type::complete_pointer_definition | ( | const Type * | _type, |
| const Gyoji::context::SourceReference & | _source_ref | ||
| ) |
Completes the definition of a pointer or reference.
| void Type::dump | ( | FILE * | out | ) | const |
Used for debugging purposes to dump the content of the type database.
| const std::vector< Argument > & Type::get_argument_types | ( | ) | const |
This returns the list of arguments to the function for function pointer types. This is ONLY valid for types that are 'is_function_pointer()'.
| size_t Type::get_array_length | ( | ) | const |
This returns the number of elements the array can store. For non-array types, this is always '1'. This makes sense in a way because you can interpret a u32 as an array of exactly one u32.
| const SourceReference & Type::get_declared_source_ref | ( | ) | const |
If a type is forward-declared without a complete type, this returns the reference to the source location where the forward declaration happened. If it was not forward declared, this will be the same source reference as where it is defined.
| const SourceReference & Type::get_defined_source_ref | ( | ) | const |
This is the location where the type's definition was completed. For forward-declared types, this will be the location where the type was 'completed'. For other types, this will be the same as the place where the type was declared.
| const std::vector< TypeMember > & Type::get_members | ( | ) | const |
This returns an immutable reference to the array of members of a class. This is ONLY valid for types that are 'is_composite()'.
Note that the ORDER of the elements in the vector here are important because they represent indices used when the MIR accesses the members of the container.
| const std::map< std::string, TypeMethod > & Type::get_methods | ( | ) | const |
Returns a map of the methods available in this class. This is ONLY valid for types that are 'is_composite'.
| const std::string & Type::get_name | ( | ) | const |
This returns the fully-qualified name of the type.
| const Type * Type::get_pointer_target | ( | ) | const |
This returns a pointer to the type pointed to by this type. It is ONLY valid for types that are 'is_pointer()' or 'is_reference()'.
| size_t Type::get_primitive_size | ( | ) | const |
This returns the size in bytes of the primitive. This is ONLY valid for primitive number types and it is a bug to call this for any type that returns 'false' for 'is_numeric'
| const Type * Type::get_return_type | ( | ) | const |
This returns a pointer to the type returned by the function for function pointer types. This is ONLY valid for types that are 'is_function_pointer()'.
| const std::string & Type::get_simple_name | ( | ) | const |
This returns the 'simple' name (i.e. not fully qualified). This is mainly used to construct the constructor and destructor names by appending the "Simple" name to the fully-qualified name as a method name.
| Type::TypeType Type::get_type | ( | ) | const |
This returns the type of type (see TypeType).
| bool Type::is_anonymous | ( | ) | const |
This returns true if this is the anonymous structure pseudo-type.
| bool Type::is_array | ( | ) | const |
This returns true if the type is an array of data of a specific type.
| bool Type::is_bool | ( | ) | const |
This returns true if the type is a boolean type.
| bool Type::is_complete | ( | ) | const |
This returns true if the type has not yet been completely specified. In particular, types may be incomplete when they are initially declared in a forward-declaration, but may receive a final definition only later when the type resolution occurs.
| bool Type::is_composite | ( | ) | const |
This returns true if the type is a composite type such as a class or structure.
| bool Type::is_enum | ( | ) | const |
This returns true if the type is an enum type.
| bool Type::is_float | ( | ) | const |
This returns true if the type is a floating-point number (f32, f64).
| bool Type::is_function_pointer | ( | ) | const |
This returns true if the type is a pointer to a function.
| bool Type::is_integer | ( | ) | const |
This returns true if the type is a signed integer (i8, i16, i32, i64), or an unsigned integer (u8,u16,u32,u64).
| bool Type::is_numeric | ( | ) | const |
This returns true if the type is a signed integer (i8, i16, i32, i64), an unsigned integer (u8,u16,u32,u64), or a floating-point number (f32, f64).
| bool Type::is_pointer | ( | ) | const |
This returns true if the type is a pointer to another type.
| bool Type::is_primitive | ( | ) | const |
This returns true if the type is one of the built-in primitive types.
| bool Type::is_reference | ( | ) | const |
This returns true if the type is a reference to another type.
| bool Type::is_signed | ( | ) | const |
This returns true if the type is a signed integer (i8, i16, i32, i64).
| bool Type::is_unsafe | ( | ) | const |
Returns true if this is an unsafe function pointer. This is ONLY valid for types that are 'is_function_pointer()'.
| bool Type::is_unsigned | ( | ) | const |
This returns true if the type is an unsigned integer (u8,u16,u32,u64).
| bool Type::is_void | ( | ) | const |
This returns true if the type is a void type.
| const TypeMember * Type::member_get | ( | const std::string & | member_name | ) | const |
This returns a pointer to the member indicated by the given name. This is ONLY valid for types that are 'is_composite()'. If the member with the given name does not exist, nullptr is returned.