package fr.lifl.stc.stan.implicitFlow.execution; import java.util.HashMap; import org.apache.bcel.generic.Select; import org.apache.bcel.generic.BranchInstruction; import org.apache.bcel.generic.ExceptionThrower; import org.apache.bcel.generic.Instruction; import org.apache.bcel.generic.InstructionHandle; import fr.lifl.stc.stan.analyser.MethodAnalyzer; import fr.lifl.stc.stan.implicitFlow.ImplicitDependences; import fr.lifl.stc.stan.implicitFlow.data.BooleanExpression; import fr.lifl.stc.stan.implicitFlow.data.BooleanVariable; import fr.lifl.stc.stan.implicitFlow.execution.InstructionTypeIF; /** * * @author dorina * */ public class InterpreterIF { MethodAnalyzer analyzer; MethodInfoIF meth; BooleanVariable[] conditions; ImplicitDependences deps; /** * * @param analyzer */ public InterpreterIF(MethodAnalyzer analyzer) { this.analyzer = analyzer; meth = analyzer.getMethodInfoIF(); conditions = meth.getConditions(); deps = analyzer.getImplicitDeps(); } /** * * @param line * @return */ public BooleanVariable getCondition(int line){ for(int i = 0; i < conditions.length; i++) if(conditions[i].getLine() == line) return conditions[i]; System.err.println("line "+line+" is not a conditional bytecode!"); return null; } /** * * @param line * @param switch_ind * @return */ public BooleanVariable getCondition(int line, int switch_ind){ for(int i = 0; i < conditions.length; i++) if(conditions[i].getLine() == line && conditions[i].getSwitchInd() == switch_ind) return conditions[i]; System.err.println("line "+line+" is not a conditional bytecode!"); return null; } /** * * @return */ public InstructionHandle getStart() { return meth.firstInstruction(); } /** * * @param ih * @return */ public HashMap getNextInstructions(InstructionHandle ih) { HashMap list; BranchInstruction branch; InstructionTypeIF type; Instruction inst = ih.getInstruction(); list = new HashMap(); type = InstructionTypeIF.getType(inst); if (type == InstructionTypeIF.CONDITIONAL_INSTRUCTION) { branch = (BranchInstruction) (inst); list.put(branch.getTarget(), new BooleanExpression(getCondition(ih.getPosition()))); list.put(ih.getNext(), new BooleanExpression( getCondition(ih.getPosition()).getNegation())); } else if (type == InstructionTypeIF.TABLESWITCH_INSTRUCTION) { InstructionHandle targets[]; targets = ((Select) (inst)).getTargets(); BooleanExpression default_expression = new BooleanExpression(); BooleanVariable tmp; for (int i = 0; i