From 375cd6cb4c23d7e6f9eca204baa936f63f34e87a Mon Sep 17 00:00:00 2001 From: Pedro Matheus Date: Fri, 10 May 2019 22:31:57 -0300 Subject: [PATCH] Adding some missing definitions. Added javadoc. Reorganized. --- src/main/java/mujava/op/basic/AOIS.java | 118 ++++++++++++++++++++++++ src/main/java/mujava/op/basic/AOIU.java | 69 +++++++------- 2 files changed, 152 insertions(+), 35 deletions(-) diff --git a/src/main/java/mujava/op/basic/AOIS.java b/src/main/java/mujava/op/basic/AOIS.java index d3f7a0f..8f89982 100644 --- a/src/main/java/mujava/op/basic/AOIS.java +++ b/src/main/java/mujava/op/basic/AOIS.java @@ -324,6 +324,124 @@ private void astContext() { } + /** + * Avoid generate equivalent mutants given following criteria: + * ERule 11 + * "term = while (exp) { int v1; ... v2 = v1; } + * transformations = { + * AOIS(v1) = v1 op + * } + * constraints = { + * v1 has a local scope (inside the loop body), + * the use of v1 is the last one in the RHS of the loop, + * op ∈ {++, --} + * }" + * + * @author Pedro Pinheiro + */ + private boolean isEquivalent(Expression exp) { + boolean erule_11 = false; + ParseTreeObject pto = (ParseTreeObject) exp; + for (; pto != null && !(exp instanceof WhileStatement || exp instanceof MethodDeclaration); pto = pto.getParent()) { + } + if (pto instanceof WhileStatement) { + + } + return erule_11; + } + + /** + * Avoid generate equivalent mutants given following criteria: + * ERule 19 + * "term = v1 := v2; ... v2 := exp; + * transformations = { + * AOIS(v2) = v2 op + * } + * constraints = { + * There is no use of v2 between the use and the re-definition, + * op ∈ {++, --} + * }" + * + * @author Pedro Pinheiro + */ + private boolean isEquivalent(Variable variable) { + boolean e_aois19 = false; + ParseTreeObject pto = variable; + //Check if parent of variable is an assignment expression or an variable declaration + for (; pto != null && !(pto instanceof VariableDeclaration || + pto instanceof AssignmentExpression || pto instanceof MethodDeclaration); pto = pto.getParent()) { + } + + if (pto instanceof VariableDeclaration) { +// if (((VariableDeclaration) pto ).getVariableDeclarator().getInitializer()) + } else if (pto instanceof AssignmentExpression) { + // if it is an assignment expression, v2 has to be at the right side of it + if (((AssignmentExpression) pto).getRight().equals(variable)) { + ParseTreeObject mdecl = pto; + // go up until method declaration to get it's body + for (; mdecl != null && !(mdecl instanceof MethodDeclaration); mdecl = mdecl.getParent()) { + } + if (mdecl != null) { + // get the statement list + StatementList stList = ((MethodDeclaration) mdecl).getBody(); + boolean v2ReuseFound = false, //Flag to control whether there was no use + // of v2 between first use and redefinition + v2RedefinitionFound = false, //Flag to control whether v2 redefinition was found + v2FirstUseFound = false; //Flag to control whether v2 first use was found + // iterate over method statements + + for (int i = 0; (i < stList.size()) && !v2ReuseFound; i++) { + // get the statement from the statement list + Statement statement = stList.get(i); + // check whether the statement references v2 + if (statement.toFlattenString().contains(variable.toString())) { + if (statement instanceof ExpressionStatement) { + Expression expression = ((ExpressionStatement) statement).getExpression(); + // if v2 is in an assignment expression + if (expression instanceof AssignmentExpression) { + AssignmentExpression assignmentExpression = + (AssignmentExpression) ((ExpressionStatement) statement).getExpression(); + + // check whether v2 stands at the left, if yes and we haven't been found v2 redefinition + // mark v2 redefinition. + if (assignmentExpression.getLeft().equals(variable) && (!v2RedefinitionFound) && v2FirstUseFound) { + v2RedefinitionFound = true; + // if we've found v2 redefinition already, then this statement is v2 reuse. + } else if (assignmentExpression.getLeft().equals(variable) && v2RedefinitionFound) { + v2ReuseFound = true; + // if v2 is at right and we've been trough first use, this is v2 reuse + } else if (assignmentExpression.getRight().toFlattenString().contains(variable.toString()) + && v2FirstUseFound) { + v2ReuseFound = true; + // if v2 is at right and we haven't been trough first use, this is v2 first use + } else if (assignmentExpression.getRight().toFlattenString().contains(variable.toString()) + && !v2FirstUseFound) { + v2FirstUseFound = true; + } + // This is it for assignment expressions. + + //If its any other kind of statement + } else if (expression.toFlattenString().contains(variable.toString())) { + if (v2FirstUseFound) + v2ReuseFound = true; + else + v2FirstUseFound = true; + } + //This is it for ExpressionStatement Statements. + + + } else if (v2RedefinitionFound) { + + } + } + } + } + } + + } + return e_aois19; + } + /** * Avoid generate equivalent mutants * diff --git a/src/main/java/mujava/op/basic/AOIU.java b/src/main/java/mujava/op/basic/AOIU.java index eac0146..0509545 100644 --- a/src/main/java/mujava/op/basic/AOIU.java +++ b/src/main/java/mujava/op/basic/AOIU.java @@ -212,18 +212,24 @@ public void outputToFile(Variable original_var) { } } + /** + * Avoid equivalent mutants given following criteria: + * ERule AOIU12 + * "term = while (exp) { int v1; ... v2 = v1; } + * transformations = { + * AOIS(v1) = v1 op + * } + * constraints = { + * v1 has a local scope (inside the loop body), + * the use of v1 is the last one in the RHS of the loop, + * op ∈ {++, --} + * }" + * @param exp + * @return true when matches criteria. False otherwise. + * @author Pedro Pinheiro + */ boolean isEquivalent(AssignmentExpression exp) { boolean aoiu12 = false; - /* - AOIU 12 - "term = v1 %= v2; - transformations = { - AOIU(v2) = -v2 - } - constraints = { - - }" - */ if (exp.getOperator() == AssignmentExpression.MOD) { aoiu12 = LogReduction.AVOID; System.out.println("[TOUCHDOWN] ERULE AOIU12 >>>>> " + exp.toFlattenString()); @@ -231,19 +237,24 @@ boolean isEquivalent(AssignmentExpression exp) { return aoiu12; } + /** + * Avoid equivalent mutants given following criteria: + * ERule AOIU15 + *"term = while (exp) { int v1; ... v2 = v1; } + * transformations = { + * AOIS(v1) = v1 op + * } + * constraints = { + * v1 has a local scope (inside the loop body), + * the use of v1 is the last one in the RHS of the loop, + * op ∈ {++, --} + * }" + * @param exp + * @return true when matches criteria. False otherwise. + * @author Pedro Pinheiro + */ boolean isEquivalent(BinaryExpression exp) { boolean aoiu15 = false; - boolean aoiu12 = false; - /* - AOIU 15 - "term = if(exp op 0){...} - transformations = { - AOIU(exp) = -exp - } - constraints = { - op ∈ {==, !=} - }" - */ ExpressionAnalyzer aexp = new ExpressionAnalyzer(exp, this.getEnvironment()); if (aexp.containsZeroLiteral() && aexp.isInsideIf()) { aoiu15 = LogReduction.AVOID; @@ -256,19 +267,6 @@ boolean isEquivalent(BinaryExpression exp) { aoiu15 = false; break; } - } - /* - AOIU 12 - "term = v1 %= v2; - transformations = { - AOIU(v2) = -v2 - } - constraints = { - - }" - */ - if (aexp.getRootOperator().equals(ExpressionAnalyzer.BinaryOperator.MOD)) { - } return aoiu15; } @@ -288,6 +286,7 @@ boolean isEquivalent(BinaryExpression exp) { * @author Pedro Pinheiro */ private boolean isDuplicated(Variable variable) { + boolean d_aoiu_aoiu57 = false; ParseTreeObject pto = variable; for(int limit = 3;pto != null && (limit >= 0 ) && !(pto instanceof ReturnStatement); limit--, pto=pto.getParent()); if (pto instanceof ReturnStatement) { @@ -305,7 +304,7 @@ private boolean isDuplicated(Variable variable) { } } } - boolean d_aoiu_aoiu57; + return d_aoiu_aoiu57; } /*"term = v1 += v2