Enum solang_parser::pt::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 copy 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 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 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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Eq for Expression

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> 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,

§

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§

default 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>,

§

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>,

§

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.