Types

class gccjit::type

gccjit::type represents a type within the library. It is a subclass of gccjit::object.

Types can be created in several ways:

  • fundamental types can be accessed using gccjit::context::get_type():

    gccjit::type int_type = ctxt.get_type (GCC_JIT_TYPE_INT);
    

    or using the gccjit::context::get_int_type template:

    gccjit::type t = ctxt.get_int_type <unsigned short> ();
    

    See gcc_jit_context_get_type() for the available types.

  • derived types can be accessed by using functions such as gccjit::type::get_pointer() and gccjit::type::get_const():

    gccjit::type const_int_star = int_type.get_const ().get_pointer ();
    gccjit::type int_const_star = int_type.get_pointer ().get_const ();
    
  • by creating structures (see below).

Standard types

gccjit::type gccjit::context::get_type(enum gcc_jit_types)

Access a specific type. This is a thin wrapper around gcc_jit_context_get_type(); the parameter has the same meaning.

gccjit::type gccjit::context::get_int_type(size_t num_bytes, int is_signed)

Access the integer type of the given size.

gccjit::type gccjit::context::get_int_type<T>()

Access the given integer type. For example, you could map the unsigned short type into a gccjit::type via:

gccjit::type t = ctxt.get_int_type <unsigned short> ();

Pointers, const, and volatile

gccjit::type gccjit::type::get_pointer()

Given type “T”, get type “T*”.

gccjit::type gccjit::type::get_const()

Given type “T”, get type “const T”.

gccjit::type gccjit::type::get_volatile()

Given type “T”, get type “volatile T”.

gccjit::type gccjit::context::new_array_type(gccjit::type element_type, int num_elements, gccjit::location loc)

Given type “T”, get type “T[N]” (for a constant N). Param “loc” is optional.

Structures and unions

class gccjit::struct_

A compound type analagous to a C struct.

gccjit::struct_ is a subclass of gccjit::type (and thus of gccjit::object in turn).

class gccjit::field

A field within a gccjit::struct_.

gccjit::field is a subclass of gccjit::object.

You can model C struct types by creating gccjit::struct_ and gccjit::field instances, in either order:

  • by creating the fields, then the structure. For example, to model:

    struct coord {double x; double y; };
    

    you could call:

    gccjit::field field_x = ctxt.new_field (double_type, "x");
    gccjit::field field_y = ctxt.new_field (double_type, "y");
    std::vector fields;
    fields.push_back (field_x);
    fields.push_back (field_y);
    gccjit::struct_ coord = ctxt.new_struct_type ("coord", fields);
    
  • by creating the structure, then populating it with fields, typically to allow modelling self-referential structs such as:

    struct node { int m_hash; struct node *m_next; };
    

    like this:

    gccjit::struct_ node = ctxt.new_opaque_struct_type ("node");
    gccjit::type node_ptr = node.get_pointer ();
    gccjit::field field_hash = ctxt.new_field (int_type, "m_hash");
    gccjit::field field_next = ctxt.new_field (node_ptr, "m_next");
    std::vector fields;
    fields.push_back (field_hash);
    fields.push_back (field_next);
    node.set_fields (fields);
    
gccjit::field gccjit::context::new_field(gccjit::type type, const char* name, gccjit::location loc)

Construct a new field, with the given type and name.

gccjit::struct_ gccjit::context::new_struct_type(const std::string& name, std::vector<field>& fields, gccjit::location loc)
Construct a new struct type, with the given name and fields.
gccjit::struct_ gccjit::context::new_opaque_struct(const std::string& name, gccjit::location loc)

Construct a new struct type, with the given name, but without specifying the fields. The fields can be omitted (in which case the size of the struct is not known), or later specified using gcc_jit_struct_set_fields().

Table Of Contents

Previous topic

Objects

Next topic

Expressions