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_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.
Type::Type | ( | std::string | _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, |
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, | ||
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()'.
Type::TypeType Type::get_type | ( | ) | const |
This returns the type of type (see TypeType).
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_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.