1
0
mirror of https://github.com/DanilaFe/abacus synced 2024-12-22 07:20:09 -08:00

Add reduction of TreeValue operators.

This commit is contained in:
Danila Fedorin 2017-08-25 18:48:05 -07:00
parent bfc1ed5819
commit 20b2e77ee1

View File

@ -1,10 +1,7 @@
package org.nwapw.abacus.tree; package org.nwapw.abacus.tree;
import org.nwapw.abacus.Abacus; import org.nwapw.abacus.Abacus;
import org.nwapw.abacus.function.NumberFunction; import org.nwapw.abacus.function.*;
import org.nwapw.abacus.function.NumberOperator;
import org.nwapw.abacus.function.Operator;
import org.nwapw.abacus.function.TreeValueFunction;
import org.nwapw.abacus.number.NumberInterface; import org.nwapw.abacus.number.NumberInterface;
/** /**
@ -60,6 +57,18 @@ public class NumberReducer implements Reducer<NumberInterface> {
abacus.getPluginManager().treeValueFunctionFor(callNode.getCallTo()); abacus.getPluginManager().treeValueFunctionFor(callNode.getCallTo());
if(function == null) return null; if(function == null) return null;
return function.applyWithReducer(this, realChildren); return function.applyWithReducer(this, realChildren);
} else if (node instanceof TreeValueBinaryNode) {
BinaryNode binaryNode = (BinaryNode) node;
TreeValueOperator operator = abacus.getPluginManager()
.treeValueOperatorFor(binaryNode.getOperation());
if(operator == null) return null;
return operator.applyWithReducer(this, binaryNode.getLeft(), binaryNode.getRight());
} else if(node instanceof TreeValueUnaryNode) {
UnaryNode unaryNode = (UnaryNode) node;
TreeValueOperator operator = abacus.getPluginManager()
.treeValueOperatorFor(unaryNode.getOperation());
if(operator == null) return null;
return operator.applyWithReducer(this, unaryNode.getApplyTo());
} }
return null; return null;
} }