pub enum Expr {
Num(i128),
Label(String),
Add(Box<Expr>, Box<Expr>),
Sub(Box<Expr>, Box<Expr>),
}Expand description
An expression node for label arithmetic.
Variants§
Num(i128)
A numeric literal.
Label(String)
A label reference.
Add(Box<Expr>, Box<Expr>)
Addition: left + right.
Sub(Box<Expr>, Box<Expr>)
Subtraction: left - right.
Implementations§
Source§impl Expr
impl Expr
Sourcepub fn eval(&self) -> Option<i128>
pub fn eval(&self) -> Option<i128>
Try to evaluate to a constant integer.
Returns None if the expression still contains unresolved label references.
Sourcepub fn label_addend(&self) -> Option<(&str, i64)>
pub fn label_addend(&self) -> Option<(&str, i64)>
Decompose into a single label reference plus a numeric addend.
Returns Some((label_name, addend)) when the expression is of the form
label, label + const, or label - const (after constant folding).
Returns None if the expression has zero or multiple label references,
or a negated label (e.g. 5 - label).
Trait Implementations§
impl Eq for Expr
impl StructuralPartialEq for Expr
Auto Trait Implementations§
impl Freeze for Expr
impl RefUnwindSafe for Expr
impl Send for Expr
impl Sync for Expr
impl Unpin for Expr
impl UnwindSafe for Expr
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