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
impl Expression
source§impl Expression
impl Expression
sourcepub fn remove_parenthesis(&self) -> &Expression
pub fn remove_parenthesis(&self) -> &Expression
Removes one layer of parentheses.
sourcepub fn strip_parentheses(&self) -> &Expression
pub fn strip_parentheses(&self) -> &Expression
Strips all parentheses recursively.
sourcepub fn components(&self) -> (Option<&Self>, Option<&Self>)
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)));
sourcepub fn components_mut(&mut self) -> (Option<&mut Self>, Option<&mut Self>)
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
.
sourcepub const fn is_unsplittable(&self) -> bool
pub const fn is_unsplittable(&self) -> bool
Returns whether this expression can be split across multiple lines.
sourcepub const fn has_space_around(&self) -> bool
pub const fn has_space_around(&self) -> bool
Returns whether this expression has spaces around it.
sourcepub fn is_literal(&self) -> bool
pub fn is_literal(&self) -> bool
Returns if the expression is a literal
Trait Implementations§
source§impl Clone for Expression
impl Clone for Expression
source§fn clone(&self) -> Expression
fn clone(&self) -> Expression
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl CodeLocation for Expression
impl CodeLocation for Expression
source§impl Debug for Expression
impl Debug for Expression
source§impl Display for Expression
impl Display for Expression
source§impl OptionalCodeLocation for Expression
impl OptionalCodeLocation for Expression
source§impl PartialEq for Expression
impl PartialEq for Expression
source§fn eq(&self, other: &Expression) -> bool
fn eq(&self, other: &Expression) -> bool
self
and other
values to be equal, and is used
by ==
.impl Eq for Expression
impl StructuralPartialEq for Expression
Auto Trait Implementations§
impl Freeze for Expression
impl RefUnwindSafe for Expression
impl Send for Expression
impl Sync for Expression
impl Unpin for Expression
impl UnwindSafe for Expression
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
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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