@Override public void visit(AssignmentNode node) { node.getValue().accept(expressionVisitor); if (resultValue != null) { //Direct MathFunctionCalls won't need an extra temporary variable, //because they will be assigned to the AssignmentNode variable! //For this optimization the variable must be removed from the toInsertVars list toInsertVars.remove((Variable) resultValue); resultValue = null; } for (Variable var : toInsertVars) { AssignmentNode newNode = new AssignmentNode(node.getGraph(), var, toInsert.get(var)); node.insertBefore(newNode); } toInsertVars.clear(); toInsert.clear(); super.visit(node); } }
public String getReplacementID (Expression e){ OperationToken optok = ReplaceAbleOpsSet.get(e.toString().hashCode()); if (!optok.isUsedToReplace()) { optok.getAssignment().insertBefore(new AssignmentNode(optok.getAssignment().getGraph(), new Variable(optok.getIdentifier()), optok.getExpression())); optok.setUsedToReplace(true); } return ReplaceAbleOpsSet.get(e.toString().hashCode()).getIdentifier(); }
@Override//dfg public void visit(Exponentiation node) { if (isSquare(node) && (node.getLeft() instanceof Variable)) { String varname = null; if(node.getLeft() instanceof MultivectorComponent){ varname = ((MultivectorComponent)node.getLeft()).getName() + ((MultivectorComponent)node.getLeft()).getBladeIndex(); } else varname= ((Variable)node.getLeft()).getName(); if (!myHashmap.containsKey(varname)){ myHashmap.put(varname, ( varname + "_quad")); AddedExponentiationBang = new AssignmentNode(cfg, new Variable(varname+"_quad"), new Multiplication(node.getLeft(), node.getLeft())); //new AssignmentNode(cfg,new Variable(varname+"_quad"),node.copy()); currentAssignment.insertBefore(AddedExponentiationBang); } nx = new Variable(myHashmap.get(varname)); } else // left is novariable or node is no square { node.getLeft().accept(this); Expression lhs =nx; node.getRight().accept(this); Expression rhs =nx; nx = new Exponentiation(lhs, rhs); } }