Add reduction of TreeValue operators.

This commit is contained in:
Danila Fedorin 2017-08-25 18:48:05 -07:00
parent bfc1ed5819
commit 20b2e77ee1
1 changed files with 13 additions and 4 deletions

View File

@ -1,10 +1,7 @@
package org.nwapw.abacus.tree;
import org.nwapw.abacus.Abacus;
import org.nwapw.abacus.function.NumberFunction;
import org.nwapw.abacus.function.NumberOperator;
import org.nwapw.abacus.function.Operator;
import org.nwapw.abacus.function.TreeValueFunction;
import org.nwapw.abacus.function.*;
import org.nwapw.abacus.number.NumberInterface;
/**
@ -60,6 +57,18 @@ public class NumberReducer implements Reducer<NumberInterface> {
abacus.getPluginManager().treeValueFunctionFor(callNode.getCallTo());
if(function == null) return null;
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;
}