Skip to content

Commit

Permalink
Adding some missing definitions. Added javadoc. Reorganized.
Browse files Browse the repository at this point in the history
  • Loading branch information
pmop committed May 11, 2019
1 parent 2760838 commit 375cd6c
Show file tree
Hide file tree
Showing 2 changed files with 152 additions and 35 deletions.
118 changes: 118 additions & 0 deletions src/main/java/mujava/op/basic/AOIS.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
69 changes: 34 additions & 35 deletions src/main/java/mujava/op/basic/AOIU.java
Original file line number Diff line number Diff line change
Expand Up @@ -212,38 +212,49 @@ 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());
}
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;
Expand All @@ -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;
}
Expand All @@ -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) {
Expand All @@ -305,7 +304,7 @@ private boolean isDuplicated(Variable variable) {
}
}
}
boolean d_aoiu_aoiu57;
return d_aoiu_aoiu57;
}

/*"term = v1 += v2
Expand Down

0 comments on commit 375cd6c

Please sign in to comment.