@Override public Expression replace(Expression expression) { if (expression == toReplace) return replacement; else return super.replace(expression); }
@Override public void visit(Variable node) { if (replaceMap.containsKey(node.getName())) result = replaceMap.get(node.getName()).copy(); super.visit(node); }
@Override protected void visitUnaryOperation(UnaryOperation node) { if (node == toReplace) { result = replacement; return; } if (node.getOperand() == toReplace) { node.setOperand(replacement); } super.visitUnaryOperation(node); }
@Override protected void visitBinaryOperation(BinaryOperation node) { if (node == toReplace) { result = replacement; return; } if (node.getLeft() == toReplace) { node.setLeft(replacement); } if (node.getRight() == toReplace) { node.setRight(replacement); } super.visitBinaryOperation(node); }
@Override public void visit(Variable node) { if (definer.isBaseVector(node.getName())) result = new BaseVector(node.getName().substring(1)); super.visit(node); }
@Override public void visit(Exponentiation node) { if (node.getRight() instanceof FloatConstant) { double constant = ((FloatConstant) node.getRight()).getValue(); int integer = (int) Math.round(constant); if (integer>0 && integer<=3) if (Math.abs(constant-integer) < 10E-7) { //Unfold //TODO chs set a new temporary variable, if left is of big height switch (integer) { case 1: result = node.getLeft(); return; case 2: result = new Multiplication(node.getLeft(), node.getLeft()); return; case 3: result = new Multiplication(new Multiplication(node.getLeft(),node.getLeft()), node.getLeft()); return; } } } super.visit(node); }
@Override public void visit(ExpressionStatement node) { node.setExpression(visitor.replace(node.getExpression())); super.visit(node); }
public void visit(AssignmentNode node) { ReplaceVisitor replaceVisitor = new ReplaceVisitor() { @Override public void visit(Variable node) { if (mapExpressions.containsKey(node)) result = mapExpressions.get(node); } @Override public void visit(MultivectorComponent node) { if (mapExpressions.containsKey(node)) result = mapExpressions.get(node); } }; node.setValue(replaceVisitor.replace(node.getValue())); mapExpressions.put(node.getVariable(), node.getValue()); }