From a7e84eea087a35721a971e827149f0ca5fba4676 Mon Sep 17 00:00:00 2001 From: bjculkin Date: Tue, 21 Mar 2017 14:08:50 -0400 Subject: Remove version 1 files Remove the old, not used version 1 files from the repository. Check the history if you care about them. --- .../v1/ast/optimization/OperationCondenser.java | 96 ---------------------- 1 file changed, 96 deletions(-) delete mode 100644 dice-lang/src/bjc/dicelang/v1/ast/optimization/OperationCondenser.java (limited to 'dice-lang/src/bjc/dicelang/v1/ast/optimization/OperationCondenser.java') diff --git a/dice-lang/src/bjc/dicelang/v1/ast/optimization/OperationCondenser.java b/dice-lang/src/bjc/dicelang/v1/ast/optimization/OperationCondenser.java deleted file mode 100644 index 7ce6f5d..0000000 --- a/dice-lang/src/bjc/dicelang/v1/ast/optimization/OperationCondenser.java +++ /dev/null @@ -1,96 +0,0 @@ -package bjc.dicelang.v1.ast.optimization; - -import bjc.dicelang.v1.ast.nodes.DiceASTType; -import bjc.dicelang.v1.ast.nodes.IDiceASTNode; -import bjc.dicelang.v1.ast.nodes.OperatorDiceNode; -import bjc.utils.data.IHolder; -import bjc.utils.data.ITree; -import bjc.utils.data.Identity; -import bjc.utils.data.TopDownTransformResult; -import bjc.utils.data.Tree; - -/** - * Condenses chained operations into a single level - * - * @author ben - * - */ -public class OperationCondenser { - /** - * Condense chained similiar operations into a single level - * - * @param ast - * The AST to condense - * @return The condensed AST - */ - public static ITree condense(ITree ast) { - return ast.topDownTransform(OperationCondenser::pickNode, OperationCondenser::doCondense); - } - - private static ITree doCondense(ITree ast) { - OperatorDiceNode operation = ast.transformHead((node) -> (OperatorDiceNode) node); - - IHolder canCondense = new Identity<>(true); - - ast.doForChildren((child) -> { - if(canCondense.getValue()) { - canCondense.replace(child.transformHead((node) -> { - if(node.getType() == DiceASTType.OPERATOR) { - if(operation.equals(node)) return true; - - return false; - } - - return true; - })); - } - }); - - if(!canCondense.getValue()) return ast; - - ITree condensedAST = new Tree<>(operation); - - ast.doForChildren((child) -> { - if(child.getHead().getType() == DiceASTType.OPERATOR) { - child.doForChildren((subChild) -> { - condensedAST.addChild(subChild); - }); - } else { - condensedAST.addChild(child); - } - }); - - return condensedAST; - } - - private static TopDownTransformResult pickNode(IDiceASTNode node) { - switch(node.getType()) { - case LITERAL: - return TopDownTransformResult.SKIP; - case OPERATOR: - return pickOperator((OperatorDiceNode) node); - case VARIABLE: - return TopDownTransformResult.SKIP; - default: - throw new UnsupportedOperationException("Attempted to traverse unknown node type " + node); - } - } - - private static TopDownTransformResult pickOperator(OperatorDiceNode node) { - switch(node) { - case ADD: - case MULTIPLY: - case SUBTRACT: - case DIVIDE: - case COMPOUND: - return TopDownTransformResult.PUSHDOWN; - case ARRAY: - case ASSIGN: - case GROUP: - case LET: - return TopDownTransformResult.PASSTHROUGH; - default: - throw new UnsupportedOperationException("Attempted to traverse unknown operator " + node); - } - } -} -- cgit v1.2.3