pub struct IrNode {
pub shape: Shape,
pub name: Option<Lexeme>,
pub token_start: usize,
pub token_end: usize,
pub range: ByteRange,
pub children: Vec<Self>,
}Expand description
One node of the Syntax IR tree.
A node covers a contiguous token range (token_start..token_end indices
into SyntaxIrFile::tokens) and a contiguous byte range of the source.
Children are in source order and lie within their parent’s ranges. Nodes
destroy their descendants iteratively so dropping a recovered file does not
consume stack space proportional to its depth.
Fields§
§shape: ShapeThe node’s shape.
name: Option<Lexeme>The declared name, when the frontend can recover one (functions, methods, records, macro definitions).
token_start: usizeIndex of the node’s first token in the file’s token stream.
token_end: usizeIndex one past the node’s last token.
range: ByteRangeSource bytes the node covers.
children: Vec<Self>Child nodes in source order.
Implementations§
Source§impl IrNode
impl IrNode
Sourcepub const fn token_len(&self) -> usize
pub const fn token_len(&self) -> usize
Number of tokens the node covers; 0 for a malformed range.
Sourcepub fn walk(&self, visit: &mut impl FnMut(&Self))
pub fn walk(&self, visit: &mut impl FnMut(&Self))
Depth-first pre-order traversal over this node and its descendants.
The traversal is iterative so callers can safely inspect externally constructed IR too, even when it did not come from a bounded frontend.
Sourcepub fn statement_summaries(&self, tokens: &[Token]) -> Vec<StatementSummary>
pub fn statement_summaries(&self, tokens: &[Token]) -> Vec<StatementSummary>
The sequence of statement children, summarised.
This is the per-block statement sequence view of the IR: direct
children whose shapes are statements, in source order, each reduced
to its StatementSummary. Non-statement children (nested items,
blocks acting as expressions) are skipped, matching how statement
windows are cut.
Shape::Native children are included: a native node that is a
direct child of the node being summarised sits in statement position
by construction (C goto, a preprocessor conditional inside a
function body), and dropping it would silently shorten the sequence.
Trait Implementations§
impl Eq for IrNode
impl StructuralPartialEq for IrNode
Auto Trait Implementations§
impl Freeze for IrNode
impl RefUnwindSafe for IrNode
impl Send for IrNode
impl Sync for IrNode
impl Unpin for IrNode
impl UnsafeUnpin for IrNode
impl UnwindSafe for IrNode
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.