diff options
| author | bjculkin <bjculkin@mix.wvu.edu> | 2017-03-21 14:08:50 -0400 |
|---|---|---|
| committer | bjculkin <bjculkin@mix.wvu.edu> | 2017-03-21 14:08:50 -0400 |
| commit | a7e84eea087a35721a971e827149f0ca5fba4676 (patch) | |
| tree | fbb7b0e5e402fb2a4aae5614c51f1955640a09e8 /dice-lang/src/bjc/dicelang/v1/ast/optimization/ArithmeticCollapser.java | |
| parent | 94913a2fccff9e80f84ac477c2020bd7c7b1833a (diff) | |
Remove version 1 files
Remove the old, not used version 1 files from the repository. Check the
history if you care about them.
Diffstat (limited to 'dice-lang/src/bjc/dicelang/v1/ast/optimization/ArithmeticCollapser.java')
| -rw-r--r-- | dice-lang/src/bjc/dicelang/v1/ast/optimization/ArithmeticCollapser.java | 42 |
1 files changed, 0 insertions, 42 deletions
diff --git a/dice-lang/src/bjc/dicelang/v1/ast/optimization/ArithmeticCollapser.java b/dice-lang/src/bjc/dicelang/v1/ast/optimization/ArithmeticCollapser.java deleted file mode 100644 index acc1afa..0000000 --- a/dice-lang/src/bjc/dicelang/v1/ast/optimization/ArithmeticCollapser.java +++ /dev/null @@ -1,42 +0,0 @@ -package bjc.dicelang.v1.ast.optimization; - -import bjc.dicelang.v1.ast.DiceASTUtils; -import bjc.dicelang.v1.ast.nodes.DiceASTType; -import bjc.dicelang.v1.ast.nodes.IDiceASTNode; -import bjc.dicelang.v1.ast.nodes.ILiteralDiceNode; -import bjc.dicelang.v1.ast.nodes.IntegerLiteralNode; -import bjc.dicelang.v1.ast.nodes.OperatorDiceNode; -import bjc.utils.data.ITree; -import bjc.utils.data.Tree; -import bjc.utils.funcdata.IList; - -import java.util.function.BinaryOperator; - -class ArithmeticCollapser { - private BinaryOperator<Integer> reducer; - private OperatorDiceNode type; - - public ArithmeticCollapser(BinaryOperator<Integer> reducr, OperatorDiceNode typ) { - reducer = reducr; - this.type = typ; - } - - public ITree<IDiceASTNode> collapse(IList<ITree<IDiceASTNode>> children) { - boolean allConstant = children.allMatch((subtree) -> { - return subtree.transformHead((node) -> { - if(node.getType() == DiceASTType.LITERAL) - return ((ILiteralDiceNode) node).canOptimize(); - - return false; - }); - }); - - if(!allConstant) return new Tree<>(type, children); - - int initState = DiceASTUtils.literalToInteger(children.first()); - - return children.tail().reduceAux(initState, (currentNode, state) -> { - return reducer.apply(state, DiceASTUtils.literalToInteger(currentNode)); - }, (state) -> new Tree<>(new IntegerLiteralNode(state))); - } -} |
