Skip to main content

ExprKind

Enum ExprKind 

Source
pub enum ExprKind {
Show 32 variants Ident(Ident), Int(IntLit), Float(FloatLit), Char(CharLit), Str(StrLit), Unary { op: UnaryOp, operand: Box<Expr>, }, Binary { op: BinaryOp, lhs: Box<Expr>, rhs: Box<Expr>, }, Assign { op: Option<BinaryOp>, lhs: Box<Expr>, rhs: Box<Expr>, }, Conditional { cond: Box<Expr>, then_expr: Option<Box<Expr>>, else_expr: Box<Expr>, }, Comma { lhs: Box<Expr>, rhs: Box<Expr>, }, Call { callee: Box<Expr>, args: Vec<Expr>, }, Member { base: Box<Expr>, arrow: bool, field: Ident, }, Index { base: Box<Expr>, index: Box<Expr>, }, PostIncDec { op: IncDec, operand: Box<Expr>, }, PreIncDec { op: IncDec, operand: Box<Expr>, }, Cast { ty: Box<TypeName>, expr: Box<Expr>, }, LabelAddr(Ident), SizeofExpr(Box<Expr>), SizeofType(Box<TypeName>), AlignofExpr(Box<Expr>), AlignofType(Box<TypeName>), Generic { controlling: Box<Expr>, assocs: Vec<GenericAssoc>, }, Bool(bool), Nullptr, VaArg { ap: Box<Expr>, ty: Box<TypeName>, }, OffsetOf { ty: Box<TypeName>, member: Ident, path: Vec<Designator>, }, CompoundLiteral { ty: Box<TypeName>, init: Vec<InitItem>, }, StmtExpr(Box<Block>), TypesCompatible { lhs: Box<TypeName>, rhs: Box<TypeName>, }, ChooseExpr { cond: Box<Expr>, then_expr: Box<Expr>, else_expr: Box<Expr>, }, ComplexPart { real: bool, operand: Box<Expr>, }, Error,
}
Expand description

The shape of an Expr.

Variants§

§

Ident(Ident)

An identifier reference.

§

Int(IntLit)

An integer constant.

§

Float(FloatLit)

A floating constant.

§

Char(CharLit)

A character constant.

§

Str(StrLit)

A string literal, after adjacent-literal concatenation.

§

Unary

A unary operator application.

Fields

§op: UnaryOp

The operator.

§operand: Box<Expr>

The operand.

§

Binary

A binary operator application.

Fields

§op: BinaryOp

The operator.

§lhs: Box<Expr>

Left operand.

§rhs: Box<Expr>

Right operand.

§

Assign

An assignment; op is None for = and Some(op) for op=.

Fields

§op: Option<BinaryOp>

The compound operator, if any.

§lhs: Box<Expr>

The assigned-to operand.

§rhs: Box<Expr>

The assigned value.

§

Conditional

cond ? then_expr : else_expr, and GNU’s cond ?: else_expr.

Fields

§cond: Box<Expr>

The condition.

§then_expr: Option<Box<Expr>>

The value when the condition holds; None for a ?: b, where it is the condition’s own value and the condition is evaluated once.

§else_expr: Box<Expr>

The value otherwise.

§

Comma

lhs, rhs

Fields

§lhs: Box<Expr>

Evaluated and discarded.

§rhs: Box<Expr>

The result.

§

Call

callee(args…)

Fields

§callee: Box<Expr>

The called expression.

§args: Vec<Expr>

The arguments.

§

Member

base.field or base->field

Fields

§base: Box<Expr>

The object or pointer.

§arrow: bool

Whether -> was used.

§field: Ident

The member name.

§

Index

base[index]

Fields

§base: Box<Expr>

The array or pointer.

§index: Box<Expr>

The subscript.

§

PostIncDec

x++ / x--

Fields

§op: IncDec

Which operator.

§operand: Box<Expr>

The operand.

§

PreIncDec

++x / --x

Fields

§op: IncDec

Which operator.

§operand: Box<Expr>

The operand.

§

Cast

(T)expr

Fields

§ty: Box<TypeName>

The target type.

§expr: Box<Expr>

The operand.

§

LabelAddr(Ident)

GNU’s &&label: the address of a label of the enclosing function, of type void *, which goto * jumps to.

§

SizeofExpr(Box<Expr>)

sizeof expr

§

SizeofType(Box<TypeName>)

sizeof(T)

§

AlignofExpr(Box<Expr>)

_Alignof expr — a GNU extension C never standardised.

§

AlignofType(Box<TypeName>)

_Alignof(T) / alignof(T) — C11.

§

Generic

_Generic(controlling, T: value, …) — C11.

Fields

§controlling: Box<Expr>

The controlling expression, which is never evaluated.

§assocs: Vec<GenericAssoc>

The associations, in the order written.

§

Bool(bool)

true / false — C23.

§

Nullptr

nullptr — C23.

§

VaArg

va_arg(ap, T).

It looks like a call but takes a type name, so — like sizeof — the parser has to know about it.

Fields

§ap: Box<Expr>

The argument list read from.

§ty: Box<TypeName>

The type of the argument being read.

§

OffsetOf

__builtin_offsetof(T, member), which <stddef.h>’s offsetof is.

Another one that takes a type name where an expression would go.

Fields

§ty: Box<TypeName>

The struct or union type.

§member: Ident

The first step of the member designator, which C requires to be a member name.

§path: Vec<Designator>

The steps after it — offsetof(struct S, a.b) and offsetof(struct S, a[2].b) are both member designators (C99 7.17p3). A Designator::Range never appears here.

§

CompoundLiteral

(T){ … } — a C99 compound literal.

Fields

§ty: Box<TypeName>

The literal’s type.

§init: Vec<InitItem>

The initialiser elements.

§

StmtExpr(Box<Block>)

({ … }) — GNU’s statement expression, whose value is the value of the last expression statement in the block.

§

TypesCompatible

__builtin_types_compatible_p(T1, T2), an integer constant.

Fields

§lhs: Box<TypeName>

The first type.

§rhs: Box<TypeName>

The second type.

§

ChooseExpr

__builtin_choose_expr(c, a, b).

Only the operand the constant condition picks is type checked, which is the whole point of the builtin.

Fields

§cond: Box<Expr>

The controlling constant expression.

§then_expr: Box<Expr>

Chosen when it is non-zero.

§else_expr: Box<Expr>

Chosen otherwise.

§

ComplexPart

__real__ e / __imag__ e, which need complex arithmetic.

Fields

§real: bool

Whether this is __real__.

§operand: Box<Expr>

The operand.

§

Error

Produced by error recovery.

Trait Implementations§

Source§

impl Clone for ExprKind

Source§

fn clone(&self) -> Self

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 Debug for ExprKind

Source§

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

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

impl PartialEq for ExprKind

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for ExprKind

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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.