Skip to main content

Expr

Enum Expr 

Source
pub enum Expr {
Show 30 variants Error, Name(Symbol), Int(IntId), Float(FloatId), Char(CharId), Str(StrId), Bool(bool), Nullptr, Index { base: ExprId, index: ExprId, }, Call { callee: ExprId, args: ExprList, }, Member { base: ExprId, name: Symbol, arrow: bool, }, Unary { op: UnaryOp, operand: ExprId, }, Binary { op: BinaryOp, lhs: ExprId, rhs: ExprId, }, Assign { op: Option<BinaryOp>, lhs: ExprId, rhs: ExprId, }, Cond { cond: ExprId, then: Option<ExprId>, otherwise: ExprId, }, Comma { lhs: ExprId, rhs: ExprId, }, Cast { ty: TypeNameId, operand: ExprId, }, CompoundLiteral { ty: TypeNameId, init: InitId, }, SizeofExpr(ExprId), SizeofType(TypeNameId), AlignofExpr(ExprId), AlignofType(TypeNameId), Generic { control: ExprId, assocs: GenericList, }, StmtExpr(StmtId), LabelAddr(Symbol), Offsetof { ty: TypeNameId, path: DesignatorList, }, ChooseExpr { cond: ExprId, then: ExprId, otherwise: ExprId, }, TypesCompatible { a: TypeNameId, b: TypeNameId, }, VaArg { list: ExprId, ty: TypeNameId, }, Extension(ExprId),
}
Expand description

One expression node.

Sixteen bytes, which is what the widest variant needs and what the whole arena therefore costs per node. Anything that would not fit is an index into a side table on Ast, which is why a call holds a range and not a vector.

Variants§

§

Error

A parse that did not work out.

Poisoned, per section 6.8: semantic analysis says nothing about a node that is already the result of a diagnostic, which is the mechanism that stops one syntax error becoming forty type errors.

§

Name(Symbol)

An identifier, before anything has looked it up.

The parser already knows whether the name is a typedef name, because it had to know to parse the surrounding text at all, but it does not resolve it to a declaration. That is semantic analysis, which has the scopes and the linkage rules.

§

Int(IntId)

An integer constant, in the constant table on Ast.

§

Float(FloatId)

A floating constant.

§

Char(CharId)

A character constant.

§

Str(StrId)

A string literal, with the adjacent ones already joined onto it by phase 7.

§

Bool(bool)

true or false, which C23 made constants rather than macros.

§

Nullptr

nullptr.

§

Index

base[index], in the order it was written, which is not always the pointer first.

Fields

§base: ExprId

The left operand.

§index: ExprId

The operand in the brackets.

§

Call

callee(args).

Fields

§callee: ExprId

What is being called, which is an expression and not necessarily a name.

§args: ExprList

The arguments, in order.

§

Member

base.name or base->name.

Fields

§base: ExprId

The left operand.

§name: Symbol

The member name, which lives in its own namespace and is not looked up here.

§arrow: bool

Whether it was written with an arrow.

§

Unary

A prefix or postfix operator on one operand.

Fields

§op: UnaryOp

Which operator.

§operand: ExprId

The operand.

§

Binary

A binary operator, including the ones that do not evaluate both sides.

Fields

§op: BinaryOp

Which operator.

§lhs: ExprId

The left operand.

§rhs: ExprId

The right operand.

§

Assign

lhs = rhs, or a compound assignment with the operator kept as written.

Fields

§op: Option<BinaryOp>

The operator in a compound assignment, and None for a plain one.

§lhs: ExprId

The left operand.

§rhs: ExprId

The right operand.

§

Cond

cond ? then : otherwise, where then is absent in GNU’s cond ?: otherwise.

Fields

§cond: ExprId

The condition.

§then: Option<ExprId>

The second operand, absent when the middle was left out.

§otherwise: ExprId

The third operand.

§

Comma

lhs, rhs.

Its own node rather than a BinaryOp, because the comma operator is a sequence point with a discarded left side and shares nothing with arithmetic but its spelling.

Fields

§lhs: ExprId

The operand whose value is thrown away.

§rhs: ExprId

The operand whose value the expression has.

§

Cast

(ty)operand.

Fields

§ty: TypeNameId

The type name in the parentheses.

§operand: ExprId

What is being converted.

§

CompoundLiteral

(ty){ ... }, which is an object and not a conversion.

Fields

§ty: TypeNameId

The type name in the parentheses.

§init: InitId

The braced initializer.

§

SizeofExpr(ExprId)

sizeof operand, written without parentheses around a type.

§

SizeofType(TypeNameId)

sizeof (ty).

§

AlignofExpr(ExprId)

alignof operand, which is GNU’s __alignof__ since ISO C only has the type form.

§

AlignofType(TypeNameId)

alignof (ty).

§

Generic

_Generic(control, ...).

Fields

§control: ExprId

The controlling expression, which is never evaluated.

§assocs: GenericList

The associations, in the order they were written, including the default one.

§

StmtExpr(StmtId)

({ ... }), GNU’s statement expression, whose value is its last expression statement.

§

LabelAddr(Symbol)

&&label, GNU’s label address.

§

Offsetof

__builtin_offsetof(ty, path), where path is a member and not an expression.

Fields

§ty: TypeNameId

The type being measured.

§path: DesignatorList

The member path, which is a designator list because a.b[3].c is legal here.

§

ChooseExpr

__builtin_choose_expr(cond, then, otherwise).

The whole reason this exists is that the branch not chosen is never type checked, so it has to survive to semantic analysis as itself rather than as a conditional.

Fields

§cond: ExprId

The condition, which must be a constant expression.

§then: ExprId

The branch taken when the condition is nonzero.

§otherwise: ExprId

The other branch.

§

TypesCompatible

__builtin_types_compatible_p(a, b).

Fields

§a: TypeNameId

The first type.

§b: TypeNameId

The second type.

§

VaArg

__builtin_va_arg(list, ty).

Fields

§list: ExprId

The argument list.

§ty: TypeNameId

The type being fetched.

§

Extension(ExprId)

__extension__ operand, which turns the pedantic diagnostics off inside it.

Trait Implementations§

Source§

impl Clone for Expr

Source§

fn clone(&self) -> Expr

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 Copy for Expr

Source§

impl Debug for Expr

Source§

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

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

impl Eq for Expr

Source§

impl PartialEq for Expr

Source§

fn eq(&self, other: &Expr) -> 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 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 UnsafeUnpin for Expr

§

impl UnwindSafe for Expr

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