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: BinaryOperatorOperator
left: Box<Expression>Left operand
right: Box<Expression>Right operand
FunctionCall
Function call: malloc(4)
Dereference(Box<Expression>)
Pointer dereference: *ptr
UnaryOp
Unary operation: -x, !x
ArrayIndex
Array indexing: arr[i]
FieldAccess
Struct field access: obj.field
PointerFieldAccess
Pointer field access: ptr->field
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)
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 castCompoundLiteral
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 initializersFields
initializers: Vec<Expression>Initializer expressions (values for struct fields or array elements)
Implementations§
Source§impl Expression
impl Expression
Sourcepub fn is_string_function_call(&self) -> bool
pub fn is_string_function_call(&self) -> bool
Check if this expression is a string function call (strlen, strcmp, strcpy, strdup).
Sourcepub fn string_function_name(&self) -> Option<&str>
pub fn string_function_name(&self) -> Option<&str>
Get the string function name if this is a string function call.
Sourcepub fn has_string_literal_argument(&self) -> bool
pub fn has_string_literal_argument(&self) -> bool
Check if this expression has a string literal argument.
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 more