diff options
| author | bculkin2442 <bjculkin@mix.wvu.edu> | 2016-03-22 12:28:35 -0400 |
|---|---|---|
| committer | bculkin2442 <bjculkin@mix.wvu.edu> | 2016-03-22 12:28:35 -0400 |
| commit | 01cb9f504c860bc1c037a44f3a76bf342a293d46 (patch) | |
| tree | 02d1d34de0828159bbda93e881c93a6b45720f32 /BJC-Utils2/src/main/java/bjc/utils/dice/ast/DiceASTFreezer.java | |
| parent | 4685955a62c430007c5c8ed2b915ffc618d30aca (diff) | |
General formatting cleanup and documentation update
Diffstat (limited to 'BJC-Utils2/src/main/java/bjc/utils/dice/ast/DiceASTFreezer.java')
| -rw-r--r-- | BJC-Utils2/src/main/java/bjc/utils/dice/ast/DiceASTFreezer.java | 65 |
1 files changed, 55 insertions, 10 deletions
diff --git a/BJC-Utils2/src/main/java/bjc/utils/dice/ast/DiceASTFreezer.java b/BJC-Utils2/src/main/java/bjc/utils/dice/ast/DiceASTFreezer.java index 04cc99b..efe37c0 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/dice/ast/DiceASTFreezer.java +++ b/BJC-Utils2/src/main/java/bjc/utils/dice/ast/DiceASTFreezer.java @@ -4,7 +4,52 @@ import java.util.Map; import bjc.utils.parserutils.AST; +/** + * Freeze references in a dice AST, replacing variable references with what + * the variables refer to + * + * @author ben + * + */ public class DiceASTFreezer { + /** + * Expand a reference + * + * @param vnode + * The node containing the reference to expand + * @param env + * The enviroment to expand against + * @return The expanded reference + */ + private static AST<IDiceASTNode> expandNode(VariableDiceNode vnode, + Map<String, AST<IDiceASTNode>> env) { + return env.get(vnode.getVariable()); + } + + /** + * Expand a reference + * + * @param vnode + * The node containing the reference to expand + * @param env + * The enviroment to expand against + * @return The expanded reference + */ + private static AST<IDiceASTNode> expandNode2(VariableDiceNode vnode, + Map<String, DiceASTExpression> env) { + return env.get(vnode.getVariable()).getAst(); + } + + /** + * Freeze the references in an AST + * + * @param tree + * The tree to freeze references in + * @param env + * The enviroment to get reference values from + * @return The tree with references frozen + */ + @SuppressWarnings("unused") public static AST<IDiceASTNode> freezeAST(AST<IDiceASTNode> tree, Map<String, AST<IDiceASTNode>> env) { return tree.collapse((nod) -> { @@ -20,6 +65,16 @@ public class DiceASTFreezer { } , (r) -> r); } + /** + * Freeze the references in an expression backed by an AST + * + * @param tree + * The tree-backed expression to freeze references in + * @param env + * The enviroment to get reference values from + * @return The tree with references frozen + */ + @SuppressWarnings("unused") public static AST<IDiceASTNode> freezeAST(DiceASTExpression tree, Map<String, DiceASTExpression> env) { return tree.getAst().collapse((nod) -> { @@ -34,14 +89,4 @@ public class DiceASTFreezer { return new AST<IDiceASTNode>(op, left, right); } , (r) -> r); } - - private static AST<IDiceASTNode> expandNode(VariableDiceNode vnode, - Map<String, AST<IDiceASTNode>> env) { - return env.get(vnode.getVariable()); - } - - private static AST<IDiceASTNode> expandNode2(VariableDiceNode vnode, - Map<String, DiceASTExpression> env) { - return env.get(vnode.getVariable()).getAst(); - } } |
