pub struct Variable {
pub array_sections: Vec<ArraySection>,
/* private fields */
}
Expand description
A variable reference, possibly with array sections
Variables in OpenMP clauses can be:
- Simple:
x
,my_var
- Array elements:
arr[i]
- Array sections:
arr[0:N]
- Multidimensional:
matrix[i][0:N]
§Learning: Composition
Notice how Variable
is built from other IR types:
- Uses
&'a str
for the name (borrowed from source) - Uses
Vec<ArraySection>
for subscripts ArraySection
usesExpression
This shows how complex structures are built from simple parts.
§Example
use roup::ir::{Variable, ArraySection, Expression, ParserConfig};
let config = ParserConfig::default();
// Simple variable: x
let simple = Variable::new("x");
assert_eq!(simple.name(), "x");
assert!(simple.is_scalar());
// Array section: arr[0:N]
let array = Variable::with_sections(
"arr",
vec![ArraySection::new(
Some(Expression::new("0", &config)),
Some(Expression::new("N", &config)),
None,
)]
);
assert!(!array.is_scalar());
Fields§
§array_sections: Vec<ArraySection>
Array sections (empty for scalar variables)
Each element represents one dimension:
arr[i]
→ 1 sectionmatrix[i][j]
→ 2 sectionstensor[i][j][k]
→ 3 sections
Implementations§
Source§impl Variable
impl Variable
Sourcepub fn new(name: impl Into<String>) -> Self
pub fn new(name: impl Into<String>) -> Self
Create a new variable without array sections (scalar)
§Example
use roup::ir::Variable;
let var = Variable::new("x");
assert_eq!(var.name(), "x");
assert!(var.is_scalar());
Sourcepub fn with_sections(
name: impl Into<String>,
sections: Vec<ArraySection>,
) -> Self
pub fn with_sections( name: impl Into<String>, sections: Vec<ArraySection>, ) -> Self
Create a variable with array sections
§Example
use roup::ir::{Variable, ArraySection};
let var = Variable::with_sections(
"arr",
vec![ArraySection::all()]
);
assert_eq!(var.name(), "arr");
assert!(!var.is_scalar());
Sourcepub fn dimensions(&self) -> usize
pub fn dimensions(&self) -> usize
Get the number of dimensions
Returns 0 for scalars, 1+ for arrays.
Trait Implementations§
Source§impl Display for Variable
impl Display for Variable
Source§fn fmt(&self, f: &mut Formatter<'_>) -> Result
fn fmt(&self, f: &mut Formatter<'_>) -> Result
Format as OpenMP variable syntax
§Example
use roup::ir::{Variable, ArraySection, Expression, ParserConfig};
let config = ParserConfig::default();
// Scalar
let scalar = Variable::new("x");
assert_eq!(format!("{}", scalar), "x");
// Array section
let array = Variable::with_sections(
"arr",
vec![ArraySection::new(
Some(Expression::new("0", &config)),
Some(Expression::new("N", &config)),
None,
)]
);
assert_eq!(format!("{}", array), "arr[0:N]");
Source§impl From<Identifier> for Variable
impl From<Identifier> for Variable
Source§fn from(id: Identifier) -> Self
fn from(id: Identifier) -> Self
Converts to this type from the input type.
Source§impl From<Variable> for ClauseItem
impl From<Variable> for ClauseItem
impl StructuralPartialEq for Variable
Auto Trait Implementations§
impl Freeze for Variable
impl RefUnwindSafe for Variable
impl Send for Variable
impl Sync for Variable
impl Unpin for Variable
impl UnwindSafe for Variable
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