summaryrefslogtreecommitdiff
path: root/dice-lang/src/bjc/dicelang/ast/DiceASTInliner.java
diff options
context:
space:
mode:
authorbjculkin <bjculkin@WIT-136XG42.wvu-ad.wvu.edu>2017-02-27 10:08:50 -0500
committerbjculkin <bjculkin@WIT-136XG42.wvu-ad.wvu.edu>2017-02-27 10:08:50 -0500
commit79ee129fc0d36ad10bceb942262f2842419c030c (patch)
treed1298fdb8b81726f4b9012d7a29c3029a55a3aa7 /dice-lang/src/bjc/dicelang/ast/DiceASTInliner.java
parentc50a0744269ce22604c0604cc69e6d5e5ce8a3fc (diff)
Pacakge reorganization
Diffstat (limited to 'dice-lang/src/bjc/dicelang/ast/DiceASTInliner.java')
-rw-r--r--dice-lang/src/bjc/dicelang/ast/DiceASTInliner.java127
1 files changed, 0 insertions, 127 deletions
diff --git a/dice-lang/src/bjc/dicelang/ast/DiceASTInliner.java b/dice-lang/src/bjc/dicelang/ast/DiceASTInliner.java
deleted file mode 100644
index e9bc4ac..0000000
--- a/dice-lang/src/bjc/dicelang/ast/DiceASTInliner.java
+++ /dev/null
@@ -1,127 +0,0 @@
-package bjc.dicelang.ast;
-
-import bjc.utils.data.ITree;
-import bjc.utils.funcdata.FunctionalList;
-import bjc.utils.funcdata.IList;
-import bjc.utils.funcdata.IMap;
-import bjc.utils.data.Tree;
-
-import bjc.dicelang.ast.nodes.DiceASTType;
-import bjc.dicelang.ast.nodes.IDiceASTNode;
-import bjc.dicelang.ast.nodes.VariableDiceNode;
-
-/**
- * Inline variables in a dice AST
- *
- * @author ben
- *
- */
-public class DiceASTInliner {
- /**
- * Inline all the variables in the AST
- *
- * @param ast
- * The AST to inline variables into
- * @param enviroment
- * The enviroment to inline from
- * @return The inlined AST
- */
- public static ITree<IDiceASTNode> inlineAll(ITree<IDiceASTNode> ast,
- IMap<String, ITree<IDiceASTNode>> enviroment) {
- // Tell the compiler that the null is for the entire varargs
- // parameter, not a single one with a null value
- return selectiveInline(ast, enviroment, (String[]) null);
- }
-
- private static ITree<IDiceASTNode> inlineNode(IDiceASTNode node,
- IMap<String, ITree<IDiceASTNode>> enviroment,
- boolean specificInline, IList<String> variableNames) {
- // Only variables get inlined
- if (node.getType() != DiceASTType.VARIABLE) {
- return new Tree<>(node);
- }
-
- // Get the name of what we're inlining
- String variableName = ((VariableDiceNode) node).getVariable();
-
- // If we're inlining only certain variables, do so
- if (specificInline) {
- // Only inline the variable if we're supposed to
- if (variableNames.contains(variableName)) {
- // You can't inline non-existent variables
- if (!enviroment.containsKey(variableName)) {
- throw new UnsupportedOperationException(
- "Attempted to inline non-existant variable "
- + variableName);
- }
-
- // Return the tree for the variable
- return enviroment.get(variableName);
- }
-
- // We're not inlining this particular variable
- return new Tree<>(node);
- }
-
- // You can't inline non-existent variables
- if (!enviroment.containsKey(variableName)) {
- throw new UnsupportedOperationException(
- "Attempted to inline non-existant variable "
- + variableName);
- }
-
- // Return the tree for the variable
- return enviroment.get(variableName);
- }
-
- /**
- * Inline the specified variables in the AST
- *
- * @param ast
- * The AST to inline variables into
- * @param enviroment
- * The enviroment to inline from
- * @param variables
- * The variables to inline
- * @return The inlined AST
- */
- public static ITree<IDiceASTNode> selectiveInline(
- ITree<IDiceASTNode> ast,
- IMap<String, ITree<IDiceASTNode>> enviroment,
- IList<String> variables) {
- // Inline the specified variables
- return selectiveInline(ast, enviroment,
- variables.toArray(new String[0]));
- }
-
- /**
- * Inline the specified variables in the AST
- *
- * @param ast
- * The AST to inline variables into
- * @param enviroment
- * The enviroment to inline from
- * @param variables
- * The variables to inline
- * @return The inlined AST
- */
- public static ITree<IDiceASTNode> selectiveInline(
- ITree<IDiceASTNode> ast,
- IMap<String, ITree<IDiceASTNode>> enviroment,
- String... variables) {
- // If we're selectively inlining, do so
- if (variables != null && variables.length > 0) {
- IList<String> variableNames = new FunctionalList<>(variables);
-
- // Selectively inline each tree node
- return ast.flatMapTree((node) -> {
- return inlineNode(node, enviroment, true, variableNames);
- });
- }
-
- // Inline everything in each node
- return ast.flatMapTree((node) -> {
- return inlineNode(node, enviroment, false, null);
- });
- }
-}