pub struct ArraySection {
pub lower_bound: Option<Expression>,
pub length: Option<Expression>,
pub stride: Option<Expression>,
}
Expand description
Array section specification: [lower:length:stride]
OpenMP allows specifying portions of arrays using array sections:
arr[0:N]
- elements 0 through N-1arr[i:10:2]
- 10 elements starting at i, every 2nd elementarr[:]
- all elements
§Learning: Optional Fields
All three parts (lower, length, stride) are optional! This is
modeled with Option<Expression>
:
Some(expr)
- part is presentNone
- part is omitted
§Syntax Examples
OpenMP Syntax | lower | length | stride |
---|---|---|---|
arr[0:N] | Some(0) | Some(N) | None |
arr[:] | None | None | None |
arr[i:10:2] | Some(i) | Some(10) | Some(2) |
arr[i] | Some(i) | None | None |
§Example
use roup::ir::{ArraySection, Expression, ParserConfig};
let config = ParserConfig::default();
// arr[0:N]
let section = ArraySection {
lower_bound: Some(Expression::new("0", &config)),
length: Some(Expression::new("N", &config)),
stride: None,
};
Fields§
§lower_bound: Option<Expression>
Lower bound (starting index)
If None
, starts at beginning (equivalent to 0)
length: Option<Expression>
Length (number of elements)
If None
, goes to end of dimension
stride: Option<Expression>
Stride (spacing between elements)
If None
, defaults to 1 (consecutive elements)
Implementations§
Source§impl ArraySection
impl ArraySection
Sourcepub fn new(
lower_bound: Option<Expression>,
length: Option<Expression>,
stride: Option<Expression>,
) -> Self
pub fn new( lower_bound: Option<Expression>, length: Option<Expression>, stride: Option<Expression>, ) -> Self
Create a new array section with all fields
Sourcepub fn single_index(index: Expression) -> Self
pub fn single_index(index: Expression) -> Self
Create an array section for a single index: arr[i]
§Example
use roup::ir::{ArraySection, Expression, ParserConfig};
let config = ParserConfig::default();
let section = ArraySection::single_index(Expression::new("i", &config));
// Represents arr[i]
Sourcepub const fn all() -> Self
pub const fn all() -> Self
Create an array section for all elements: arr[:]
§Example
use roup::ir::ArraySection;
let section = ArraySection::all();
// Represents arr[:]
Sourcepub fn is_single_index(&self) -> bool
pub fn is_single_index(&self) -> bool
Check if this represents a single index access
Trait Implementations§
Source§impl Clone for ArraySection
impl Clone for ArraySection
Source§fn clone(&self) -> ArraySection
fn clone(&self) -> ArraySection
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl Debug for ArraySection
impl Debug for ArraySection
Source§impl Display for ArraySection
impl Display for ArraySection
Source§fn fmt(&self, f: &mut Formatter<'_>) -> Result
fn fmt(&self, f: &mut Formatter<'_>) -> Result
Format as OpenMP array section syntax
§Example
use roup::ir::{ArraySection, Expression, ParserConfig};
let config = ParserConfig::default();
let section = ArraySection::new(
Some(Expression::new("0", &config)),
Some(Expression::new("N", &config)),
None,
);
assert_eq!(format!("{}", section), "0:N");
Source§impl PartialEq for ArraySection
impl PartialEq for ArraySection
impl StructuralPartialEq for ArraySection
Auto Trait Implementations§
impl Freeze for ArraySection
impl RefUnwindSafe for ArraySection
impl Send for ArraySection
impl Sync for ArraySection
impl Unpin for ArraySection
impl UnwindSafe for ArraySection
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more