Skip to main content

VlaDef

Struct VlaDef 

Source
pub struct VlaDef {
    pub object: ObjectId,
    pub storage: ObjectId,
    pub count: Expr,
    pub align: Option<u64>,
    pub range: SourceRange,
}
Expand description

A variably modified object’s definition: T a[n];, T a[n][m];.

C99 6.7.5.2 gives the object automatic storage duration, a size fixed when the declaration is reached, and the lifetime of the block it is written in; each bound is evaluated exactly once, where the declaration stands, and lives in a hidden size_t object the type points at. This crate emulates the storage with a per-function bump arena on the heap — the elements are bumped off it, and a hidden frame guard whose Drop moves the arena back down is that lifetime — so the one definition becomes a Stmt::Let per bound followed by two more bindings:

let __cinrs_vla_len_a: size_t = <n>;                     // one per bound
let __cinrs_vla_frame_a = __cinrs_vla.frame();          // frame
let mut a: *mut T = __cinrs_vla.alloc::<T>(count);       // object

From there the object is a pointer to the first element: decay is the identity, a[i] is pointer indexing scaled by the run-time size of a row, and sizeof a is the product of the bounds times the element size — see Types::vm_step_ty for what “element” means once more than one dimension is variable.

Fields§

§object: ObjectId

The object the C program declared, whose type is the array type and whose generated binding is a pointer to the first element.

§storage: ObjectId

The hidden frame that gives the elements back; see Object::vla_storage.

§count: Expr

The number of elements to allocate: the product of every dimension, read out of the hidden bound objects, in units of the storage’s element type.

§align: Option<u64>

The alignment _Alignas(N) or __attribute__((aligned(N))) asked for, when it is stricter than the element type’s: the arena then pads its position to the first address that is a multiple of it.

§range: SourceRange

Where the declarator was written.

Trait Implementations§

Source§

impl Clone for VlaDef

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for VlaDef

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.