Skip to content

Mapping nodes to semantics

Matheus Dias de Souza edited this page May 3, 2024 · 2 revisions

ActionScript 3 compilers may need to attach something to nodes. They can do so by using the TreeSemantics mapping, which works just as a hash map, but using an efficient implementation for the different node types and splitting of dictionaries for large compilation units.

use as3_parser::ns::*;

// Construct a TreeSemantics structure, where Thingy
// is any type that implements Clone.
let semantics = TreeSemantics::<Thingy>::new();

// Retrieve something of a node.
let something = semantics.get(&node);

// Assign something to a node.
semantics.set(&node, something);

// Delete the something of a node.
semantics.delete(&node);

// Check whether a node has something.
let has_something = semantics.has(&node);

Almost every node type that is used behind a Rc container may be used as a node type in TreeSemantics, such as Rc<Expression>, Rc<Directive>, and Rc<FunctionCommon>.

Clone this wiki locally