pub enum ExpressionKind {
IntLiteral(i64),
Identifier(String),
BinaryOp {
left: Box<ExpressionAst>,
op: BinaryOperator,
right: Box<ExpressionAst>,
},
UnaryOp {
op: UnaryOperator,
operand: Box<ExpressionAst>,
},
Call {
function: String,
args: Vec<ExpressionAst>,
},
ArrayAccess {
array: Box<ExpressionAst>,
indices: Vec<ExpressionAst>,
},
Conditional {
condition: Box<ExpressionAst>,
then_expr: Box<ExpressionAst>,
else_expr: Box<ExpressionAst>,
},
Parenthesized(Box<ExpressionAst>),
Complex(String),
}
Expand description
Common expression patterns in OpenMP directives
§Learning: Large Enums with Data
This enum demonstrates Rust’s powerful enum system. Each variant can carry different data:
IntLiteral(i64)
- carries an integerIdentifier(String)
- carries an owned stringBinaryOp { ... }
- carries multiple fields
This is much more powerful than C enums, which can only be simple tags.
Variants§
IntLiteral(i64)
Integer literal: 42
, 0x10
, 0b1010
Identifier(String)
Identifier: N
, num_threads
, my_var
BinaryOp
Binary operation: a + b
, N * 2
, i < 10
UnaryOp
Unary operation: -x
, !flag
, *ptr
Call
Function call: foo(a, b)
, omp_get_num_threads()
ArrayAccess
Array subscript: arr[i]
, matrix[i][j]
Conditional
Ternary conditional: cond ? a : b
Parenthesized(Box<ExpressionAst>)
Parenthesized: (expr)
Complex(String)
Too complex to parse, kept as string
This is our escape hatch for expressions that are valid but not yet supported by the parser.
Trait Implementations§
Source§impl Clone for ExpressionKind
impl Clone for ExpressionKind
Source§fn clone(&self) -> ExpressionKind
fn clone(&self) -> ExpressionKind
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 ExpressionKind
impl Debug for ExpressionKind
Source§impl PartialEq for ExpressionKind
impl PartialEq for ExpressionKind
impl StructuralPartialEq for ExpressionKind
Auto Trait Implementations§
impl Freeze for ExpressionKind
impl RefUnwindSafe for ExpressionKind
impl Send for ExpressionKind
impl Sync for ExpressionKind
impl Unpin for ExpressionKind
impl UnwindSafe for ExpressionKind
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