Expression

Enum Expression 

Source
pub enum Expression {
Show 17 variants IntLiteral(i32), StringLiteral(String), Variable(String), BinaryOp { op: BinaryOperator, left: Box<Expression>, right: Box<Expression>, }, FunctionCall { function: String, arguments: Vec<Expression>, }, Dereference(Box<Expression>), UnaryOp { op: UnaryOperator, operand: Box<Expression>, }, ArrayIndex { array: Box<Expression>, index: Box<Expression>, }, FieldAccess { object: Box<Expression>, field: String, }, PointerFieldAccess { pointer: Box<Expression>, field: String, }, PostIncrement { operand: Box<Expression>, }, PreIncrement { operand: Box<Expression>, }, PostDecrement { operand: Box<Expression>, }, PreDecrement { operand: Box<Expression>, }, Sizeof { type_name: String, }, Cast { target_type: Type, expr: Box<Expression>, }, CompoundLiteral { literal_type: Type, initializers: Vec<Expression>, },
}
Expand description

Represents a C expression.

Variants§

§

IntLiteral(i32)

Integer literal: 42

§

StringLiteral(String)

String literal: "hello"

§

Variable(String)

Variable reference: x

§

BinaryOp

Binary operation: a + b

Fields

§op: BinaryOperator

Operator

§left: Box<Expression>

Left operand

§right: Box<Expression>

Right operand

§

FunctionCall

Function call: malloc(4)

Fields

§function: String

Function name

§arguments: Vec<Expression>

Arguments

§

Dereference(Box<Expression>)

Pointer dereference: *ptr

§

UnaryOp

Unary operation: -x, !x

Fields

§op: UnaryOperator

Operator

§operand: Box<Expression>

Operand

§

ArrayIndex

Array indexing: arr[i]

Fields

§array: Box<Expression>

Array expression

§index: Box<Expression>

Index expression

§

FieldAccess

Struct field access: obj.field

Fields

§object: Box<Expression>

Object expression

§field: String

Field name

§

PointerFieldAccess

Pointer field access: ptr->field

Fields

§pointer: Box<Expression>

Pointer expression

§field: String

Field name

§

PostIncrement

Post-increment expression: ptr++

Fields

§operand: Box<Expression>

Operand expression

§

PreIncrement

Pre-increment expression: ++ptr

Fields

§operand: Box<Expression>

Operand expression

§

PostDecrement

Post-decrement expression: ptr--

Fields

§operand: Box<Expression>

Operand expression

§

PreDecrement

Pre-decrement expression: --ptr

Fields

§operand: Box<Expression>

Operand expression

§

Sizeof

Sizeof expression: sizeof(int) or sizeof(struct Data)

Fields

§type_name: String

Type name as a string (e.g., “int”, “struct Data”)

§

Cast

Cast expression: (int)x or (void*)ptr

C-style cast that converts an expression to a target type. Maps to Rust as operator for safe casts, or transmute for unsafe casts.

§Examples

int x = (int)3.14;           // float to int
void* ptr = (void*)buffer;   // pointer cast
long l = (long)small_int;    // widening cast

Fields

§target_type: Type

Target type to cast to

§expr: Box<Expression>

Expression being cast

§

CompoundLiteral

Compound literal: (struct Point){10, 20} or (int[]){1, 2, 3}

C99 compound literals create anonymous objects of a specified type. Useful for passing struct values to functions or creating temporary objects.

§Examples

struct Point p = (struct Point){10, 20};       // struct compound literal
int* arr = (int[]){1, 2, 3, 4, 5};             // array compound literal
draw((struct Rect){.x=0, .y=0, .w=100, .h=50}); // with designated initializers

Fields

§literal_type: Type

Type of the compound literal (struct Point, int[], etc.)

§initializers: Vec<Expression>

Initializer expressions (values for struct fields or array elements)

Implementations§

Source§

impl Expression

Source

pub fn is_string_function_call(&self) -> bool

Check if this expression is a string function call (strlen, strcmp, strcpy, strdup).

Source

pub fn string_function_name(&self) -> Option<&str>

Get the string function name if this is a string function call.

Source

pub fn has_string_literal_argument(&self) -> bool

Check if this expression has a string literal argument.

Trait Implementations§

Source§

impl Clone for Expression

Source§

fn clone(&self) -> Expression

Returns a duplicate 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 Debug for Expression

Source§

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

Formats the value using the given formatter. Read more
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 · 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> 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 = 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.