/** * Accept method in the visitor pattern for traversing the GAPP data structure. * Calls the accept method of every instruction in this data structure. * * @param visitor The visitor used for calling * @param arg An argument, which will be used in the calls */ public void accept(GAPPVisitor visitor, Object arg) { for (GAPPBaseInstruction inst : instructions) { inst.accept(visitor, null); } }
/** * Loads the source from a file * * @param file The file */ public void loadSource(ControlFlowGraph graph) { instructionsLoc = new LinkedList<GAPPBaseInstruction>(); EmptyControlFlowVisitor visitor = new EmptyControlFlowVisitor() { @Override public void visit(AssignmentNode node) { instructionsLoc.addAll(node.getGAPP().getInstructions()); super.visit(node); } }; graph.accept(visitor); this.instructions = instructionsLoc.toArray(new GAPPBaseInstruction[0]); modelSrc.clear(); for (GAPPBaseInstruction instruction : instructionsLoc) { modelSrc.addElement(instruction.toString()); } ui.jListSrc.repaint(); }
private void evaluateInstruction() { instructions[curInstruction].accept(executer, null); }
/** * Updates all setOfVariables * @param instructions The GAPP instructions */ public static void updateSetOfVariables(LinkedList<GAPPBaseInstruction> instructions) { SetOfVariablesUpdater updater = new SetOfVariablesUpdater(); for (GAPPBaseInstruction i: instructions) i.accept(updater, null); }
/** * Returns a (deep) copy of this instance * @return The copy */ public GAPP getCopy() { GAPP copy = new GAPP(); GAPPCopier copier = new GAPPCopier(); for (GAPPBaseInstruction curInstr : instructions) { copy.instructions.add((GAPPBaseInstruction) curInstr.accept(copier, null)); } return copy; }
@Override public String toString() { PrettyPrint printer = new PrettyPrint(); accept(printer, null); return printer.getResultString(); } }
@Override public void visit(AssignmentNode node) { if (node.getGAPP() != null) { LinkedList<GAPPBaseInstruction> instructions = node.getGAPP().getInstructions(); LinkedList<GAPPBaseInstruction> delInstructions = new LinkedList<GAPPBaseInstruction>(); for (GAPPBaseInstruction instr : instructions) { Object result = instr.accept(this, null); if (result != null && ((Boolean) result).booleanValue()) { delInstructions.add(instr); } } for (GAPPBaseInstruction instr : delInstructions) { instructions.remove(instr); } } super.visit(node); } }