Skip to main content

number_unit

Function number_unit 

Source
pub fn number_unit(unit: &mut SourceUnit)
Expand description

Assigns every expression in unit an id unique within it.

Ids are handed out in pre-order and in source order, starting at ExprId(0): an expression is numbered before its children, and a child before anything to its right. So the ids of one unit are exactly 0..n for n expressions, with no gaps and no repeats, which is what lets a later pass index a Vec of n entries by them.

The numbering starts from zero for each unit, so ids from two files are not comparable. See ExprId.

Running this twice over the same unit assigns the same ids again, so it is idempotent rather than merely repeatable.