Skip to main content

CNode

Enum CNode 

Source
pub enum CNode {
Show 31 variants TranslationUnit(Vec<CNode>), FuncDef { return_type: CType, name: String, params: Vec<(CType, String)>, body: Vec<CNode>, }, VarDecl { var_type: CType, name: String, init: Option<Box<CNode>>, }, Assign { lhs: Box<CNode>, rhs: Box<CNode>, }, BinOp { left: Box<CNode>, op: CBinaryOp, right: Box<CNode>, }, UnaryOp { op: CUnaryOp, operand: Box<CNode>, }, IntLit(i64), FloatLit(f64), CharLit(char), StrLit(String), Ident(String), If { cond: Box<CNode>, then_body: Vec<CNode>, else_body: Vec<CNode>, }, While { cond: Box<CNode>, body: Vec<CNode>, }, For { init: Option<Box<CNode>>, cond: Option<Box<CNode>>, incr: Option<Box<CNode>>, body: Vec<CNode>, }, Return(Option<Box<CNode>>), Break, Continue, Call { func: String, args: Vec<CNode>, }, ArrayAccess { array: Box<CNode>, index: Box<CNode>, }, Compare { left: Box<CNode>, op: CCompareOp, right: Box<CNode>, }, ExprStmt(Box<CNode>), Block(Vec<CNode>), Ternary { cond: Box<CNode>, then_expr: Box<CNode>, else_expr: Box<CNode>, }, Sizeof(CType), Cast { target_type: CType, expr: Box<CNode>, }, Deref(Box<CNode>), AddrOf(Box<CNode>), StructAccess { expr: Box<CNode>, field: String, }, PtrAccess { expr: Box<CNode>, field: String, }, Increment { operand: Box<CNode>, pre: bool, }, Decrement { operand: Box<CNode>, pre: bool, },
}
Expand description

C AST node types for generation

Variants§

§

TranslationUnit(Vec<CNode>)

Translation unit (root node)

§

FuncDef

Function definition

Fields

§return_type: CType

Return type

§name: String

Function name

§params: Vec<(CType, String)>

Parameters

§body: Vec<CNode>

Function body

§

VarDecl

Variable declaration

Fields

§var_type: CType

Variable type

§name: String

Variable name

§init: Option<Box<CNode>>

Optional initializer

§

Assign

Assignment: lhs = rhs

Fields

§lhs: Box<CNode>

Left-hand side

§rhs: Box<CNode>

Right-hand side

§

BinOp

Binary operation

Fields

§left: Box<CNode>

Left operand

§op: CBinaryOp

Operator

§right: Box<CNode>

Right operand

§

UnaryOp

Unary operation

Fields

§op: CUnaryOp

Operator

§operand: Box<CNode>

Operand

§

IntLit(i64)

Integer literal

§

FloatLit(f64)

Float literal

§

CharLit(char)

Character literal

§

StrLit(String)

String literal

§

Ident(String)

Variable reference

§

If

If statement

Fields

§cond: Box<CNode>

Condition

§then_body: Vec<CNode>

Then body

§else_body: Vec<CNode>

Else body

§

While

While loop

Fields

§cond: Box<CNode>

Condition

§body: Vec<CNode>

Loop body

§

For

For loop

Fields

§init: Option<Box<CNode>>

Initialization

§cond: Option<Box<CNode>>

Condition

§incr: Option<Box<CNode>>

Increment

§body: Vec<CNode>

Loop body

§

Return(Option<Box<CNode>>)

Return statement

§

Break

Break statement

§

Continue

Continue statement

§

Call

Function call

Fields

§func: String

Function name

§args: Vec<CNode>

Arguments

§

ArrayAccess

Array access

Fields

§array: Box<CNode>

Array expression

§index: Box<CNode>

Index expression

§

Compare

Comparison operation

Fields

§left: Box<CNode>

Left operand

§op: CCompareOp

Operator

§right: Box<CNode>

Right operand

§

ExprStmt(Box<CNode>)

Expression statement

§

Block(Vec<CNode>)

Compound statement (block)

§

Ternary

Ternary operator: cond ? then : else

Fields

§cond: Box<CNode>

Condition

§then_expr: Box<CNode>

Then expression

§else_expr: Box<CNode>

Else expression

§

Sizeof(CType)

Sizeof expression

§

Cast

Cast expression

Fields

§target_type: CType

Target type

§expr: Box<CNode>

Expression

§

Deref(Box<CNode>)

Pointer dereference

§

AddrOf(Box<CNode>)

Address-of

§

StructAccess

Struct access: expr.field

Fields

§expr: Box<CNode>

Expression

§field: String

Field name

§

PtrAccess

Pointer struct access: expr->field

Fields

§expr: Box<CNode>

Expression

§field: String

Field name

§

Increment

Increment: ++x or x++

Fields

§operand: Box<CNode>

Operand

§pre: bool

Pre-increment (++x) or post-increment (x++)

§

Decrement

Decrement: --x or x--

Fields

§operand: Box<CNode>

Operand

§pre: bool

Pre-decrement (–x) or post-decrement (x–)

Implementations§

Source§

impl CNode

Source

pub fn to_code(&self, indent: usize) -> String

Convert AST node to C code string

Source

pub fn depth(&self) -> usize

Calculate AST depth

Trait Implementations§

Source§

impl Clone for CNode

Source§

fn clone(&self) -> CNode

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 CNode

Source§

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

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

impl PartialEq for CNode

Source§

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

Auto Trait Implementations§

§

impl Freeze for CNode

§

impl RefUnwindSafe for CNode

§

impl Send for CNode

§

impl Sync for CNode

§

impl Unpin for CNode

§

impl UnsafeUnpin for CNode

§

impl UnwindSafe for CNode

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V