cure-java-ast 0.1.10

Java AST (arena + NodeId + builder) with cure Lang implementation
Documentation

cure-java-ast

crates.io Documentation License: MIT

Java AST for the cure pipeline: a u32-indexed arena with copy-increment ids, interned name symbols, and the reference implementation of the engine's [Lang] trait.

Design

  • Arena, not boxes. Every node is a Node { data: NodeData, children } slot in one Vec; a node handle is a JavaId(u32) — Copy, comparable, sortable. Tree rewrites become cheap arena edits instead of pointer surgery.
  • Child list inline storage. Children ≤ 3 are stored inline in the node (no heap allocation); larger lists spill to the heap. Java grammar is fan-out-heavy with tiny arity, so the common case is allocation-free.
  • Interned name symbols. Names live in a unit-level symbol table (Sym(u32)); nodes reference symbols, not Strings — 87 % of identifier occurrences in real corpora are repeats.
  • Derived analysis caches. The AST carries invalidation-tracked caches: per-node aggregate effects, variable types from scope resolution, and a region-event index (use/write/shadow events over name keys) that the engine binary-searches for kill analysis. Caches rebuild lazily and only for invalidated subtrees.
  • Signatures vs. bodies. Class/member signatures are kept in plain structs (CompilationUnit, TypeDecl, Member, …) for fidelity; executable bodies live in the arena.

Navigating

use cure_java_ast::{JavaAst, JavaId, NodeData};

/// Collect every reference to the variable `name` under `root`.
fn find_refs(ast: &JavaAst, root: JavaId, name: &str, out: &mut Vec<JavaId>) {
    if let NodeData::VarRef { name: sym } = ast.node(root).data {
        if ast.sn(sym) == name {
            out.push(root);
        }
    }
    for &child in ast.children(root) {
        find_refs(ast, child, name, out);
    }
}

Construction normally happens via cure-java-parser; printing via cure-java-print; the rewrite rules over this AST live in cure-java-simplify — see the pipeline example in the repository README.

License: MIT. Zero runtime dependencies.