Skip to content

Commit

Permalink
Undoing changes in VariableReplacementAnalysis
Browse files Browse the repository at this point in the history
  • Loading branch information
tsantalis committed Oct 13, 2024
1 parent ad69b00 commit 7210bb3
Showing 1 changed file with 4 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2477,7 +2477,7 @@ else if(variableDeclarations1.size() == 0 && v2.getInitializer() != null &&
containsMapping = comp1.contains(mapping.getFragment1()) && comp2.contains(mapping.getFragment2());
}
if(containsMapping && operation2.loopWithVariables(v1.getVariableName(), v2.getVariableName()) == null) {
if(bothFragmentsUseVariable(v1, mapping) || bothFragmentsDeclareVariable(v1, mapping)) {
if(bothFragmentsUseVariable(v1, mapping)) {
VariableDeclaration otherV1 = mapping.getFragment1().getVariableDeclaration(v1.getVariableName());
if(otherV1 != null) {
VariableScope otherV1Scope = otherV1.getScope();
Expand All @@ -2490,7 +2490,7 @@ else if(set.size() == 1) {
return true;
}
}
if(bothFragmentsUseVariable(v2, mapping) || bothFragmentsDeclareVariable(v2, mapping)) {
if(bothFragmentsUseVariable(v2, mapping)) {
VariableDeclaration otherV2 = mapping.getFragment2().getVariableDeclaration(v2.getVariableName());
if(otherV2 != null) {
VariableScope otherV2Scope = otherV2.getScope();
Expand All @@ -2511,21 +2511,17 @@ else if(set.size() == 1) {
return false;
}

private static boolean bothFragmentsDeclareVariable(VariableDeclaration v1, AbstractCodeMapping mapping) {
return mapping.getFragment1().getVariableDeclaration(v1.getVariableName()) != null && mapping.getFragment2().getVariableDeclaration(v1.getVariableName()) != null;
}

public static boolean bothFragmentsUseVariable(VariableDeclaration v1, AbstractCodeMapping mapping) {
boolean containedInFragment1 = false;
for(LeafExpression variable : mapping.getFragment1().getVariables()) {
if(variable.getString().equals(v1.getVariableName()) && mapping.getFragment1().getVariableDeclaration(v1.getVariableName()) == null) {
if(variable.getString().equals(v1.getVariableName())) {
containedInFragment1 = true;
break;
}
}
boolean containedInFragment2 = false;
for(LeafExpression variable : mapping.getFragment2().getVariables()) {
if(variable.getString().equals(v1.getVariableName()) && mapping.getFragment2().getVariableDeclaration(v1.getVariableName()) == null) {
if(variable.getString().equals(v1.getVariableName())) {
containedInFragment2 = true;
break;
}
Expand Down

0 comments on commit 7210bb3

Please sign in to comment.