summaryrefslogtreecommitdiff
path: root/dice-lang/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'dice-lang/src/main')
-rw-r--r--dice-lang/src/main/java/bjc/dicelang/ast/DiceASTInliner.java13
1 files changed, 12 insertions, 1 deletions
diff --git a/dice-lang/src/main/java/bjc/dicelang/ast/DiceASTInliner.java b/dice-lang/src/main/java/bjc/dicelang/ast/DiceASTInliner.java
index 7f5f2d7..305c9af 100644
--- a/dice-lang/src/main/java/bjc/dicelang/ast/DiceASTInliner.java
+++ b/dice-lang/src/main/java/bjc/dicelang/ast/DiceASTInliner.java
@@ -36,33 +36,41 @@ public class DiceASTInliner {
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);
}
} else {
+ // 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);
}
- return new Tree<>(node);
+ // return new Tree<>(node);
}
/**
@@ -99,14 +107,17 @@ public class DiceASTInliner {
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);
});