Gyoji Compiler
Loading...
Searching...
No Matches
Public Types | Public Member Functions | List of all members
Gyoji::mir::Type Class Reference

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...
 

Public Member Functions

 Type (std::string _name, TypeType _type, bool _complete, const Gyoji::context::SourceReference &_source_ref)
 
 Type (std::string _name, const Gyoji::context::SourceReference &_source_ref, const Type &_other)
 
 ~Type ()
 Move along, nothing to see here.
 
const std::stringget_name () const
 
bool is_complete () const
 
bool is_primitive () const
 
bool is_pointer () const
 
bool is_reference () const
 
bool is_numeric () const
 
bool is_integer () const
 
bool is_unsigned () const
 
bool is_signed () const
 
bool is_float () const
 
bool is_bool () const
 
bool is_void () const
 
bool is_enum () const
 
bool is_composite () const
 
bool is_function_pointer () const
 
bool is_array () const
 
size_t get_primitive_size () const
 
TypeType get_type () const
 
const std::vector< TypeMember > & get_members () const
 
const std::map< std::string, TypeMethod > & get_methods () const
 
const TypeMembermember_get (const std::string &member_name) const
 
const Typeget_pointer_target () const
 
size_t get_array_length () const
 
const Typeget_return_type () const
 
const std::vector< Argument > & get_argument_types () const
 
void complete_composite_definition (std::vector< TypeMember > _members, std::map< std::string, TypeMethod > _methods, const Gyoji::context::SourceReference &_source_ref)
 
void complete_pointer_definition (const Type *_type, const Gyoji::context::SourceReference &_source_ref)
 
void complete_array_definition (const Type *_type, size_t _array_size, const Gyoji::context::SourceReference &_source_ref)
 
void complete_function_pointer_definition (const Type *_return_type, const std::vector< Argument > &_argument_types, const Gyoji::context::SourceReference &_source_ref)
 
void dump (FILE *out) const
 
const Gyoji::context::SourceReferenceget_declared_source_ref () const
 
const Gyoji::context::SourceReferenceget_defined_source_ref () const
 

Detailed Description

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.

Member Enumeration Documentation

◆ TypeType

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_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.

Constructor & Destructor Documentation

◆ Type() [1/2]

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() [2/2]

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::~Type ( )

Move along, nothing to see here.

Move along, nothing to see here.

Member Function Documentation

◆ complete_array_definition()

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.

◆ complete_composite_definition()

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.

◆ complete_function_pointer_definition()

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.

◆ complete_pointer_definition()

void Type::complete_pointer_definition ( const Type _type,
const Gyoji::context::SourceReference _source_ref 
)

Completes the definition of a pointer or reference.

◆ dump()

void Type::dump ( FILE *  out) const

Used for debugging purposes to dump the content of the type database.

◆ get_argument_types()

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()'.

◆ get_array_length()

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.

◆ get_declared_source_ref()

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.

◆ get_defined_source_ref()

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.

◆ get_members()

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.

◆ get_methods()

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'.

◆ get_name()

const std::string & Type::get_name ( ) const

This returns the fully-qualified name of the type.

◆ get_pointer_target()

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()'.

◆ get_primitive_size()

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'

◆ get_return_type()

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()'.

◆ get_type()

Type::TypeType Type::get_type ( ) const

This returns the type of type (see TypeType).

◆ is_array()

bool Type::is_array ( ) const

This returns true if the type is an array of data of a specific type.

◆ is_bool()

bool Type::is_bool ( ) const

This returns true if the type is a boolean type.

◆ is_complete()

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.

◆ is_composite()

bool Type::is_composite ( ) const

This returns true if the type is a composite type such as a class or structure.

◆ is_enum()

bool Type::is_enum ( ) const

This returns true if the type is an enum type.

◆ is_float()

bool Type::is_float ( ) const

This returns true if the type is a floating-point number (f32, f64).

◆ is_function_pointer()

bool Type::is_function_pointer ( ) const

This returns true if the type is a pointer to a function.

◆ is_integer()

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).

◆ is_numeric()

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).

◆ is_pointer()

bool Type::is_pointer ( ) const

This returns true if the type is a pointer to another type.

◆ is_primitive()

bool Type::is_primitive ( ) const

This returns true if the type is one of the built-in primitive types.

◆ is_reference()

bool Type::is_reference ( ) const

This returns true if the type is a reference to another type.

◆ is_signed()

bool Type::is_signed ( ) const

This returns true if the type is a signed integer (i8, i16, i32, i64).

◆ is_unsigned()

bool Type::is_unsigned ( ) const

This returns true if the type is an unsigned integer (u8,u16,u32,u64).

◆ is_void()

bool Type::is_void ( ) const

This returns true if the type is a void type.

◆ member_get()

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.


The documentation for this class was generated from the following files: