Statement

Enum Statement 

Source
pub enum Statement {
Show 18 variants VariableDeclaration { name: String, var_type: Type, initializer: Option<Expression>, }, Return(Option<Expression>), Assignment { target: String, value: Expression, }, If { condition: Expression, then_block: Vec<Statement>, else_block: Option<Vec<Statement>>, }, For { init: Option<Box<Statement>>, condition: Option<Expression>, increment: Option<Box<Statement>>, body: Vec<Statement>, }, While { condition: Expression, body: Vec<Statement>, }, DerefAssignment { target: Expression, value: Expression, }, ArrayIndexAssignment { array: Box<Expression>, index: Box<Expression>, value: Expression, }, FieldAssignment { object: Expression, field: String, value: Expression, }, Break, Continue, Switch { condition: Expression, cases: Vec<SwitchCase>, default_case: Option<Vec<Statement>>, }, PostIncrement { target: String, }, PreIncrement { target: String, }, PostDecrement { target: String, }, PreDecrement { target: String, }, CompoundAssignment { target: String, op: BinaryOperator, value: Expression, }, FunctionCall { function: String, arguments: Vec<Expression>, },
}
Expand description

Represents a C statement.

Variants§

§

VariableDeclaration

Variable declaration: int* ptr = malloc(4);

Fields

§name: String

Variable name

§var_type: Type

Variable type

§initializer: Option<Expression>

Optional initializer expression

§

Return(Option<Expression>)

Return statement: return expr;

§

Assignment

Assignment statement: x = 42;

Fields

§target: String

Target variable name

§value: Expression

Value expression to assign

§

If

If statement: if (cond) { ... } else { ... }

Fields

§condition: Expression

Condition expression

§then_block: Vec<Statement>

Then block

§else_block: Option<Vec<Statement>>

Optional else block

§

For

For loop: for (init; cond; inc) { ... }

Fields

§init: Option<Box<Statement>>

Optional init statement

§condition: Option<Expression>

Optional condition expression

§increment: Option<Box<Statement>>

Optional increment statement

§body: Vec<Statement>

Loop body

§

While

While loop: while (cond) { ... }

Fields

§condition: Expression

Condition expression

§body: Vec<Statement>

Loop body

§

DerefAssignment

Pointer dereference assignment: *ptr = value;

Fields

§target: Expression

Target expression to dereference

§value: Expression

Value expression to assign

§

ArrayIndexAssignment

Array index assignment: arr[i] = value;

Fields

§array: Box<Expression>

Array expression

§index: Box<Expression>

Index expression

§value: Expression

Value expression to assign

§

FieldAssignment

Field assignment: ptr->field = value; or obj.field = value;

Fields

§object: Expression

Object/pointer expression

§field: String

Field name

§value: Expression

Value expression to assign

§

Break

Break statement: break;

§

Continue

Continue statement: continue;

§

Switch

Switch statement: switch (expr) { case 1: ...; default: ...; }

Fields

§condition: Expression

Condition expression to switch on

§cases: Vec<SwitchCase>

List of case statements

§default_case: Option<Vec<Statement>>

Optional default case body

§

PostIncrement

Post-increment statement: ptr++;

Fields

§target: String

Target variable name

§

PreIncrement

Pre-increment statement: ++ptr;

Fields

§target: String

Target variable name

§

PostDecrement

Post-decrement statement: ptr--;

Fields

§target: String

Target variable name

§

PreDecrement

Pre-decrement statement: --ptr;

Fields

§target: String

Target variable name

§

CompoundAssignment

Compound assignment: ptr += offset;, x *= 2;, etc.

Fields

§target: String

Target variable name

§op: BinaryOperator

Binary operator to apply

§value: Expression

Value expression

§

FunctionCall

Function call statement: strlen(s);, strcpy(dst, src);

Fields

§function: String

Function name

§arguments: Vec<Expression>

Arguments

Implementations§

Source§

impl Statement

Source

pub fn is_string_function_call(&self) -> bool

Check if this statement is a string function call.

Source

pub fn is_function_call(&self) -> bool

Check if this statement is a function call.

Source

pub fn as_function_call(&self) -> Option<&Expression>

Convert this statement to a function call expression if it is one.

§Implementation Status

Stub implementation - always returns None. The Statement::FunctionCall variant doesn’t store the call as an Expression, so conversion would require reconstructing an Expression::FunctionCall from the statement’s fields.

Trait Implementations§

Source§

impl Clone for Statement

Source§

fn clone(&self) -> Statement

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 Statement

Source§

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

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

impl PartialEq for Statement

Source§

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

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.