Skip to main content

Node

Enum Node 

Source
pub enum Node {
    Function {
        name: String,
        kind: String,
        line: u32,
        body: Vec<Node>,
    },
    Branch {
        test: Vec<Node>,
        then: Vec<Node>,
        alternate: Option<Box<Node>>,
    },
    Conditional {
        test: Vec<Node>,
        then: Vec<Node>,
        alternate: Vec<Node>,
    },
    Loop {
        body: Vec<Node>,
    },
    Switch {
        cases: Vec<SwitchCase>,
    },
    Catch {
        body: Vec<Node>,
    },
    Jump {
        labeled: bool,
    },
    Logical {
        op: LogicalOp,
        operands: Vec<Node>,
    },
    Call {
        callee: Option<String>,
    },
    Group(Vec<Node>),
}
Expand description

A node of the normalized complexity IR.

Fields that hold sub-expressions or sub-statements are Vec<Node> so the adapter can drop irrelevant detail and the engine can recurse uniformly.

Variants§

§

Function

A function-like unit (function, method, arrow, accessor, …). The engine scores each one independently — nesting resets to 0 at this boundary — and reports it as a child of the enclosing unit. kind/name are opaque, adapter-chosen labels (the engine never interprets them).

Fields

§name: String
§kind: String
§line: u32

1-based line where the unit starts.

§body: Vec<Node>
§

Branch

An if (with optional else / else if). then is scored with a nesting bonus; alternate (a nested Branch for else if, or any other node for a plain else) is scored flat — one cognitive point, no bonus.

Fields

§test: Vec<Node>
§then: Vec<Node>
§alternate: Option<Box<Node>>
§

Conditional

A ternary ?:. Scored like a branch: +1 plus nesting bonus.

Fields

§test: Vec<Node>
§then: Vec<Node>
§alternate: Vec<Node>
§

Loop

Any loop (for / for-in / for-of / while / do-while), normalized to one shape. +1 plus nesting bonus, and a cyclomatic point.

Fields

§body: Vec<Node>
§

Switch

A switch. +1 plus nesting bonus (but the switch itself is not a McCabe decision point — each non-default case is, scored via SwitchCase).

Fields

§

Catch

A catch clause. +1 plus nesting bonus, and a cyclomatic point.

Fields

§body: Vec<Node>
§

Jump

A break / continue. Only a labelled jump adds one cognitive point.

Fields

§labeled: bool
§

Logical

A run of like logical operators. One cognitive point per node; the adapter folds a && b && c into a single node with three operands.

Fields

§operands: Vec<Node>
§

Call

A function call. If callee names the nearest enclosing function, the engine counts it as recursion (one cognitive point).

Fields

§callee: Option<String>
§

Group(Vec<Node>)

A transparent container for any construct that holds children but carries no score of its own (statements, expressions, blocks). The engine simply recurses into it.

Trait Implementations§

Source§

impl Clone for Node

Source§

fn clone(&self) -> Node

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 Debug for Node

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Node

§

impl RefUnwindSafe for Node

§

impl Send for Node

§

impl Sync for Node

§

impl Unpin for Node

§

impl UnsafeUnpin for Node

§

impl UnwindSafe for Node

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.