Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix motivating pr #96

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
<url>https://maven.pkg.github.com/spgroup/soot/</url>
</repository>
<repository>
<id>rbonifacio</id>
<id>svfa-scala</id>
<name>Temporary repository for the SVFA library</name>
<url>https://maven.pkg.github.com/rbonifacio/svfa-scala/</url>
<url>https://maven.pkg.github.com/spgroup/svfa-scala/</url>
</repository>
</repositories>

Expand All @@ -41,7 +41,7 @@
<dependency>
<groupId>br.unb.cic</groupId>
<artifactId>svfa-scala_2.12</artifactId>
<version>0.5.9</version>
<version>0.5.10</version>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public void configure() {
protected Map<String, List<Integer>> sourceDefinitions() {
Map<String, List<Integer>> res = new HashMap<>();
List<Integer> lines = new ArrayList<>();
lines.add(11);
lines.add(15);
res.put("br.unb.cic.analysis.samples.DFPBaseSample", lines);
return res;
}
Expand All @@ -35,7 +35,7 @@ protected Map<String, List<Integer>> sourceDefinitions() {
protected Map<String, List<Integer>> sinkDefinitions() {
Map<String, List<Integer>> res = new HashMap<>();
List<Integer> lines = new ArrayList<>();
lines.add(13);
lines.add(17);
res.put("br.unb.cic.analysis.samples.DFPBaseSample", lines);

return res;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package br.unb.cic.analysis.dfp;

import br.unb.cic.analysis.AbstractMergeConflictDefinition;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class DFPAnalysisMotivantingTest {

private DFPAnalysisSemanticConflicts analysis;
AbstractMergeConflictDefinition definition;
@Before
public void configure() {
definition = new AbstractMergeConflictDefinition(true) {
@Override
protected Map<String, List<Integer>> sourceDefinitions() {
Map<String, List<Integer>> res = new HashMap<>();
List<Integer> lines = new ArrayList<>();
lines.add(9);
res.put("br.unb.cic.analysis.samples.DFPMotivating", lines);
return res;
}

@Override
protected Map<String, List<Integer>> sinkDefinitions() {
Map<String, List<Integer>> res = new HashMap<>();
List<Integer> lines = new ArrayList<>();
lines.add(11);
res.put("br.unb.cic.analysis.samples.DFPMotivating", lines);

return res;
}
};

String cp = "target/test-classes";
analysis = new DFPInterProcedural(cp, definition);
}

@Test
public void testDFPAnalysisExpectingOneMoreConflict() {
analysis.configureSoot();

analysis.buildDFP();
System.out.println(analysis.svg().reportConflicts().size());
analysis.reportDFConflicts();
System.out.println(analysis.svgToDotModel());
System.out.println(analysis.findSourceSinkPaths());
System.out.println(analysis.svg().findConflictingPaths());
Assert.assertTrue(analysis.svg().reportConflicts().size() == 1);
}
}
20 changes: 12 additions & 8 deletions src/test/java/br/unb/cic/analysis/samples/DFPBaseSample.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,19 @@
public class DFPBaseSample {
private String text;

public DFPBaseSample(String text){
this.text = text;
}

public void cleanText(){
DFPBaseSample inst = new DFPBaseSample();
DFPBaseSample inst = new DFPBaseSample("the the dog");
inst.normalizeWhiteSpace(); //Left
inst.removeComments();
inst.removeDuplicateWords(); //Right

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Acho que aqui precisaria de uma linha a mais com this.text = inst.text, ou então usar o this em todas, já que está manipulando um objeto novo

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mais que isso, @nathaliafab , faz sentido criar o objeto aí? na versão que você encaminhou não tinha isso, até onde lembro. @galilasmb não copiasse o código de @nathaliafab ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Com o this não funciona, temos que saber qual objeto está manipulando, por isso usamos o objeto instanciado em vez do this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

como assim o this não funciona, @galilasmb ? deveria sim ser possível analisar esse método com this. se não é possível, há algo a ser ajustado na implementação da análise.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Posso testar mais, mas na última vez ele não conseguia achar o points-to.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pauloborba @galilasmb usando spark realmente o this não funciona. Precisa de um new. Usando o cha, funcionou aqui para mim.

Em um exemplo em que temos this.chamadaDeMetodo() esse método não é acessado pela análise que usa spark. Pelo menos em OA, funciona assim atualmente.

}

private void normalizeWhiteSpace(){
text.replace(" ", "");
text = text.replace(" ", " ");
}

private void removeComments(){
Expand All @@ -34,13 +38,13 @@ private void removeComments(){
}

private void removeDuplicateWords(){
String[] words = text.split(" ");
StringBuilder result = new StringBuilder(words[0]);
for (int i = 1; i < words.length; i++) {
if (!words[i].equals(words[i - 1])) {
result.append(" ");
String[] words = text.split(" ", -1);
StringBuilder result = new StringBuilder();
for (int i = 0; i < words.length; i++) {
if (i == 0 || !words[i].equals(words[i - 1]))
result.append(words[i]);
}
if (i < words.length - 1)
result.append(" ");
}

text = result.toString();
Expand Down
26 changes: 26 additions & 0 deletions src/test/java/br/unb/cic/analysis/samples/DFPMotivating.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package br.unb.cic.analysis.samples;

public class DFPMotivating {
public String text;
public int fixes, comments;

public void generateReport(){
DFPMotivating inst = new DFPMotivating();
inst.countDupWhitespace(); //RIGHT
inst.countComments();
inst.countDupWords(); // LEFT
}

private void countDupWords() {
fixes = fixes + 2;
}

private void countComments() {
comments = comments +1;
}

private void countDupWhitespace() {
fixes = fixes + 1;
}

}