FE 0.14.0
A C++23 toolkit for writing compiler/interpreter frontends.
Loading...
Searching...
No Matches

CRTP base that gives Self one VLA per element type in Self::VLA_Types directly behind it in memory - the C flexible array member, generalized to several arrays of different type. More...

#include <fe/vla.h>

Public Types

using VLA_Self = Self
 The type this base was instantiated with - Self itself, unless a class deriving from it inherited it.
template<size_t I, class S = Self>
using VLA_Type = std::tuple_element_t<I, typename S::VLA_Types>
 Element type of the I th VLA.

Public Member Functions

template<size_t I>
auto vla () const noexcept
 The I th VLA as a View<VLA_Type<I>>.

Static Public Member Functions

static constexpr size_t num_vlas () noexcept
static constexpr size_t vla_align () noexcept
template<class C>
static constexpr size_t vla_bytes (const C &counts) noexcept
 Bytes an Self with these element counts occupies, sizeof(Self) included.

Friends

class Arena

Detailed Description

template<class Self>
class fe::VLA< Self >

CRTP base that gives Self one VLA per element type in Self::VLA_Types directly behind it in memory - the C flexible array member, generalized to several arrays of different type.

Self must be created through Arena::mk or Arena::ref, which allocate the arrays along with Self and fill them from the last Self::VLA_Types arguments, in that order. This base is empty - the element counts live at the front of the VLA block - so that Self::VLA_Types may name types only declared inside Self.

class Interval : public Node, public fe::VLA<Interval> {
public:
using VLA_Types = std::tuple<const Expr*, const Expr*>;
Interval(Loc loc, Tag from, Tag to); // no parameter for either array
auto from_args() const { return vla<0>(); } // fe::View<const Expr*>
auto to_args() const { return vla<1>(); }
};
arena.ref<Interval>(loc, from, to, from_args, to_args);
CRTP base that gives Self one VLA per element type in Self::VLA_Types directly behind it in memory - ...
Definition vla.h:38
auto vla() const noexcept
The I th VLA as a View<VLA_Type<I>>.
Definition vla.h:60
Location within a Src: the half-open byte range [Loc::begin, Loc::end).
Definition loc.h:42
Warning
Only the most derived class may carry them. A class deriving from Self would inherit this base and place its arrays at Self's offset - on top of its own members - so Arena::mk and Arena::ref reject it.

Definition at line 38 of file vla.h.

Member Typedef Documentation

◆ VLA_Self

template<class Self>
using fe::VLA< Self >::VLA_Self = Self

The type this base was instantiated with - Self itself, unless a class deriving from it inherited it.

Definition at line 41 of file vla.h.

◆ VLA_Type

template<class Self>
template<size_t I, class S = Self>
using fe::VLA< Self >::VLA_Type = std::tuple_element_t<I, typename S::VLA_Types>

Element type of the I th VLA.

S defers the lookup: Self is still incomplete while this base is instantiated.

Definition at line 46 of file vla.h.

Member Function Documentation

◆ num_vlas()

template<class Self>
constexpr size_t fe::VLA< Self >::num_vlas ( )
inlinestaticconstexprnoexcept

Definition at line 48 of file vla.h.

Referenced by vla_bytes().

◆ vla()

template<class Self>
template<size_t I>
auto fe::VLA< Self >::vla ( ) const
inlinenodiscardnoexcept

The I th VLA as a View<VLA_Type<I>>.

Definition at line 60 of file vla.h.

◆ vla_align()

template<class Self>
constexpr size_t fe::VLA< Self >::vla_align ( )
inlinestaticconstexprnoexcept

Definition at line 50 of file vla.h.

References vla_align().

Referenced by vla_align().

◆ vla_bytes()

template<class Self>
template<class C>
constexpr size_t fe::VLA< Self >::vla_bytes ( const C & counts)
inlinestaticnodiscardconstexprnoexcept

Bytes an Self with these element counts occupies, sizeof(Self) included.

Definition at line 54 of file vla.h.

References num_vlas().

◆ Arena

template<class Self>
friend class Arena
friend

Definition at line 116 of file vla.h.

References Arena.

Referenced by Arena.


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