Skip to main content

Expression

Enum Expression 

Source
pub enum Expression {
Show 59 variants PostIncrement(Loc, Box<Expression>), PostDecrement(Loc, Box<Expression>), New(Loc, Box<Expression>), ArraySubscript(Loc, Box<Expression>, Option<Box<Expression>>), ArraySlice(Loc, Box<Expression>, Option<Box<Expression>>, Option<Box<Expression>>), Parenthesis(Loc, Box<Expression>), MemberAccess(Loc, Box<Expression>, Identifier), FunctionCall(Loc, Box<Expression>, Vec<Expression>), FunctionCallBlock(Loc, Box<Expression>, Box<Statement>), NamedFunctionCall(Loc, Box<Expression>, Vec<NamedArgument>), Not(Loc, Box<Expression>), BitwiseNot(Loc, Box<Expression>), Delete(Loc, Box<Expression>), PreIncrement(Loc, Box<Expression>), PreDecrement(Loc, Box<Expression>), UnaryPlus(Loc, Box<Expression>), Negate(Loc, Box<Expression>), Power(Loc, Box<Expression>, Box<Expression>), Multiply(Loc, Box<Expression>, Box<Expression>), Divide(Loc, Box<Expression>, Box<Expression>), Modulo(Loc, Box<Expression>, Box<Expression>), Add(Loc, Box<Expression>, Box<Expression>), Subtract(Loc, Box<Expression>, Box<Expression>), ShiftLeft(Loc, Box<Expression>, Box<Expression>), ShiftRight(Loc, Box<Expression>, Box<Expression>), BitwiseAnd(Loc, Box<Expression>, Box<Expression>), BitwiseXor(Loc, Box<Expression>, Box<Expression>), BitwiseOr(Loc, Box<Expression>, Box<Expression>), Less(Loc, Box<Expression>, Box<Expression>), More(Loc, Box<Expression>, Box<Expression>), LessEqual(Loc, Box<Expression>, Box<Expression>), MoreEqual(Loc, Box<Expression>, Box<Expression>), Equal(Loc, Box<Expression>, Box<Expression>), NotEqual(Loc, Box<Expression>, Box<Expression>), And(Loc, Box<Expression>, Box<Expression>), Or(Loc, Box<Expression>, Box<Expression>), ConditionalOperator(Loc, Box<Expression>, Box<Expression>, Box<Expression>), Assign(Loc, Box<Expression>, Box<Expression>), AssignOr(Loc, Box<Expression>, Box<Expression>), AssignAnd(Loc, Box<Expression>, Box<Expression>), AssignXor(Loc, Box<Expression>, Box<Expression>), AssignShiftLeft(Loc, Box<Expression>, Box<Expression>), AssignShiftRight(Loc, Box<Expression>, Box<Expression>), AssignAdd(Loc, Box<Expression>, Box<Expression>), AssignSubtract(Loc, Box<Expression>, Box<Expression>), AssignMultiply(Loc, Box<Expression>, Box<Expression>), AssignDivide(Loc, Box<Expression>, Box<Expression>), AssignModulo(Loc, Box<Expression>, Box<Expression>), BoolLiteral(Loc, bool), NumberLiteral(Loc, String, String, Option<Identifier>), RationalNumberLiteral(Loc, String, String, String, Option<Identifier>), HexNumberLiteral(Loc, String, Option<Identifier>), StringLiteral(Vec<StringLiteral>), Type(Loc, Type), HexLiteral(Vec<HexLiteral>), AddressLiteral(Loc, String), Variable(Identifier), List(Loc, ParameterList), ArrayLiteral(Loc, Vec<Expression>),
}
Expand description

An expression.

Variants§

§

PostIncrement(Loc, Box<Expression>)

<1>++

§

PostDecrement(Loc, Box<Expression>)

<1>--

§

New(Loc, Box<Expression>)

new <1>

§

ArraySubscript(Loc, Box<Expression>, Option<Box<Expression>>)

<1>\[ [2] \]

§

ArraySlice(Loc, Box<Expression>, Option<Box<Expression>>, Option<Box<Expression>>)

<1>\[ [2] : [3] \]

§

Parenthesis(Loc, Box<Expression>)

(<1>)

§

MemberAccess(Loc, Box<Expression>, Identifier)

<1>.<2>

§

FunctionCall(Loc, Box<Expression>, Vec<Expression>)

<1>(<2>,*)

§

FunctionCallBlock(Loc, Box<Expression>, Box<Statement>)

<1><2> where <2> is a block.

§

NamedFunctionCall(Loc, Box<Expression>, Vec<NamedArgument>)

<1>({ <2>,* })

§

Not(Loc, Box<Expression>)

!<1>

§

BitwiseNot(Loc, Box<Expression>)

~<1>

§

Delete(Loc, Box<Expression>)

delete <1>

§

PreIncrement(Loc, Box<Expression>)

++<1>

§

PreDecrement(Loc, Box<Expression>)

--<1>

§

UnaryPlus(Loc, Box<Expression>)

+<1>

Note that this isn’t actually supported by Solidity.

§

Negate(Loc, Box<Expression>)

-<1>

§

Power(Loc, Box<Expression>, Box<Expression>)

<1> ** <2>

§

Multiply(Loc, Box<Expression>, Box<Expression>)

<1> * <2>

§

Divide(Loc, Box<Expression>, Box<Expression>)

<1> / <2>

§

Modulo(Loc, Box<Expression>, Box<Expression>)

<1> % <2>

§

Add(Loc, Box<Expression>, Box<Expression>)

<1> + <2>

§

Subtract(Loc, Box<Expression>, Box<Expression>)

<1> - <2>

§

ShiftLeft(Loc, Box<Expression>, Box<Expression>)

<1> << <2>

§

ShiftRight(Loc, Box<Expression>, Box<Expression>)

<1> >> <2>

§

BitwiseAnd(Loc, Box<Expression>, Box<Expression>)

<1> & <2>

§

BitwiseXor(Loc, Box<Expression>, Box<Expression>)

<1> ^ <2>

§

BitwiseOr(Loc, Box<Expression>, Box<Expression>)

<1> | <2>

§

Less(Loc, Box<Expression>, Box<Expression>)

<1> < <2>

§

More(Loc, Box<Expression>, Box<Expression>)

<1> > <2>

§

LessEqual(Loc, Box<Expression>, Box<Expression>)

<1> <= <2>

§

MoreEqual(Loc, Box<Expression>, Box<Expression>)

<1> >= <2>

§

Equal(Loc, Box<Expression>, Box<Expression>)

<1> == <2>

§

NotEqual(Loc, Box<Expression>, Box<Expression>)

<1> != <2>

§

And(Loc, Box<Expression>, Box<Expression>)

<1> && <2>

§

Or(Loc, Box<Expression>, Box<Expression>)

<1> || <2>

§

ConditionalOperator(Loc, Box<Expression>, Box<Expression>, Box<Expression>)

<1> ? <2> : <3>

AKA ternary operator.

§

Assign(Loc, Box<Expression>, Box<Expression>)

<1> = <2>

§

AssignOr(Loc, Box<Expression>, Box<Expression>)

<1> |= <2>

§

AssignAnd(Loc, Box<Expression>, Box<Expression>)

<1> &= <2>

§

AssignXor(Loc, Box<Expression>, Box<Expression>)

<1> ^= <2>

§

AssignShiftLeft(Loc, Box<Expression>, Box<Expression>)

<1> <<= <2>

§

AssignShiftRight(Loc, Box<Expression>, Box<Expression>)

<1> >>= <2>

§

AssignAdd(Loc, Box<Expression>, Box<Expression>)

<1> += <2>

§

AssignSubtract(Loc, Box<Expression>, Box<Expression>)

<1> -= <2>

§

AssignMultiply(Loc, Box<Expression>, Box<Expression>)

<1> *= <2>

§

AssignDivide(Loc, Box<Expression>, Box<Expression>)

<1> /= <2>

§

AssignModulo(Loc, Box<Expression>, Box<Expression>)

<1> %= <2>

§

BoolLiteral(Loc, bool)

true or false

§

NumberLiteral(Loc, String, String, Option<Identifier>)

``

§

RationalNumberLiteral(Loc, String, String, String, Option<Identifier>)

``

§

HexNumberLiteral(Loc, String, Option<Identifier>)

``

§

StringLiteral(Vec<StringLiteral>)

<1>+. See StringLiteral.

§

Type(Loc, Type)

See Type.

§

HexLiteral(Vec<HexLiteral>)

<1>+. See HexLiteral.

§

AddressLiteral(Loc, String)

0x[a-fA-F0-9]{40}

This should be correctly checksummed, but it currently isn’t being enforced in the parser.

§

Variable(Identifier)

Any valid Identifier.

§

List(Loc, ParameterList)

(<1>,*)

§

ArrayLiteral(Loc, Vec<Expression>)

\[ <1>.* \]

Implementations§

Source§

impl Expression

Source

pub const fn operator(&self) -> Option<&'static str>

Returns the operator string of this expression, if any.

Source§

impl Expression

Source

pub fn remove_parenthesis(&self) -> &Expression

Removes one layer of parentheses.

Source

pub fn strip_parentheses(&self) -> &Expression

Strips all parentheses recursively.

Source

pub fn components(&self) -> (Option<&Self>, Option<&Self>)

Returns shared references to the components of this expression.

(left_component, right_component)

§Examples
use solang_parser::pt::{Expression, Identifier, Loc};

// `a++`
let var = Expression::Variable(Identifier::new("a"));
let post_increment = Expression::PostIncrement(Loc::default(), Box::new(var.clone()));
assert_eq!(post_increment.components(), (Some(&var), None));

// `++a`
let var = Expression::Variable(Identifier::new("a"));
let pre_increment = Expression::PreIncrement(Loc::default(), Box::new(var.clone()));
assert_eq!(pre_increment.components(), (None, Some(&var)));

// `a + b`
let var_a = Expression::Variable(Identifier::new("a"));
let var_b = Expression::Variable(Identifier::new("b"));
let pre_increment = Expression::Add(Loc::default(), Box::new(var_a.clone()), Box::new(var_b.clone()));
assert_eq!(pre_increment.components(), (Some(&var_a), Some(&var_b)));
Source

pub fn components_mut(&mut self) -> (Option<&mut Self>, Option<&mut Self>)

Returns mutable references to the components of this expression.

See also Expression::components.

Source

pub const fn is_unsplittable(&self) -> bool

Returns whether this expression can be split across multiple lines.

Source

pub const fn has_space_around(&self) -> bool

Returns whether this expression has spaces around it.

Source

pub fn is_literal(&self) -> bool

Returns if the expression is a literal

Trait Implementations§

Source§

impl Clone for Expression

Source§

fn clone(&self) -> Expression

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl CodeLocation for Expression

Source§

fn loc(&self) -> Loc

Returns the code location of self.
Source§

impl Debug for Expression

Source§

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

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

impl Display for Expression

Source§

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

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

impl Eq for Expression

Source§

impl OptionalCodeLocation for Expression

Source§

fn loc_opt(&self) -> Option<Loc>

Returns the optional code location of self.
Source§

impl PartialEq for Expression

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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 Expression

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
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.