pub struct VlaDef {
pub object: ObjectId,
pub storage: ObjectId,
pub count: Expr,
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 on the heap — the elements live in a hidden
Vec whose Drop 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 mut __cinrs_vla_a: Vec<T> = vec![<zero>; count]; // storage
let mut a: *mut T = __cinrs_vla_a.as_mut_ptr(); // objectFrom 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: ObjectIdThe object the C program declared, whose type is the array type and whose generated binding is a pointer to the first element.
storage: ObjectIdThe hidden Vec the elements live in; see Object::vla_storage.
count: ExprThe 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.
range: SourceRangeWhere the declarator was written.