Struct Variable

Source
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 uses Expression

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 section
  • matrix[i][j] → 2 sections
  • tensor[i][j][k] → 3 sections

Implementations§

Source§

impl Variable

Source

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());
Source

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());
Source

pub fn name(&self) -> &str

Get the variable name

Source

pub fn is_scalar(&self) -> bool

Check if this is a scalar (no array sections)

Source

pub fn is_array(&self) -> bool

Check if this is an array (has sections)

Source

pub fn dimensions(&self) -> usize

Get the number of dimensions

Returns 0 for scalars, 1+ for arrays.

Trait Implementations§

Source§

impl Clone for Variable

Source§

fn clone(&self) -> Variable

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Variable

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Display for Variable

Source§

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<&str> for Variable

Source§

fn from(name: &str) -> Self

Converts to this type from the input type.
Source§

impl From<Identifier> for Variable

Source§

fn from(id: Identifier) -> Self

Converts to this type from the input type.
Source§

impl From<String> for Variable

Source§

fn from(name: String) -> Self

Converts to this type from the input type.
Source§

impl From<Variable> for ClauseItem

Source§

fn from(var: Variable) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for Variable

Source§

fn eq(&self, other: &Variable) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for Variable

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.