Skip to content
Snippets Groups Projects
Commit 77d78e04 authored by Jonathan Andrade's avatar Jonathan Andrade
Browse files

First intent to create ACFG

parent 58d41e99
No related branches found
No related tags found
No related merge requests found
Pipeline #241 failed
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>es.upv.mist.slicing</groupId>
<artifactId>sdg</artifactId>
<version>1.3.0</version>
</parent>
<artifactId>iacfg</artifactId>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>commons-cli</groupId>
<artifactId>commons-cli</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>es.upv.mist.slicing</groupId>
<artifactId>sdg-core</artifactId>
<version>1.3.0</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
\ No newline at end of file
package es.upv.mist.slicing;
import com.github.javaparser.StaticJavaParser;
import com.github.javaparser.ast.NodeList;
import com.github.javaparser.ast.body.CallableDeclaration;
import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration;
import com.github.javaparser.ast.body.ConstructorDeclaration;
import com.github.javaparser.ast.body.MethodDeclaration;
import com.github.javaparser.ast.visitor.VoidVisitorAdapter;
import es.upv.mist.slicing.graphs.sdg.SDG;
import es.upv.mist.slicing.utils.ASTUtils;
import es.upv.mist.slicing.utils.StaticTypeSolver;
import org.apache.commons.cli.ParseException;
import com.github.javaparser.ast.CompilationUnit;
import com.github.javaparser.utils.CodeGenerationUtils;
import es.upv.mist.slicing.graphs.augmented.ACFG;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Stream;
public class I_ACFG extends SDG {
protected static final Map<CallableDeclaration<?>, ACFG> acfgMap = ASTUtils.newIdentityHashMap();
public static void main(String[] args) throws ParseException {
String ruta = "/src/main/java/es/upv/mist/slicing/tests/";
String fichero = "Test_Entrevista.java";
I_ACFG iAcfg = new I_ACFG();
iAcfg.generarACFG(ruta, fichero);
}
public void generarACFG(String ruta, String fichero) {
NodeList<CompilationUnit> units = new NodeList<>();
File file = new File(CodeGenerationUtils.mavenModuleRoot(I_ACFG.class)+ruta+fichero);
CompilationUnit compilationUnit = null;
StaticJavaParser.getConfiguration().setAttributeComments(false);
Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).log(Level.INFO, "Configuring JavaParser");
StaticTypeSolver.addTypeSolverJRE();
try {
units.add(compilationUnit = StaticJavaParser.parse(file));
} catch (FileNotFoundException e) {
System.out.println("No se encontró el archivo");
}
buildACFGs(units);
System.out.println("TESTING: " + acfgMap.toString());
}
protected void buildACFGs(NodeList<CompilationUnit> nodeList) {
nodeList.accept(new VoidVisitorAdapter<Void>() {
@Override
public void visit(MethodDeclaration n, Void arg) {
boolean isInInterface = n.findAncestor(ClassOrInterfaceDeclaration.class)
.map(ClassOrInterfaceDeclaration::isInterface).orElse(false);
if (n.isAbstract() || isInInterface)
return; // Allow abstract methods
ACFG acfg = new ACFG();
acfg.build(n);
acfgMap.put(n, acfg);
super.visit(n, arg);
}
@Override
public void visit(ConstructorDeclaration n, Void arg) {
boolean isInInterface = n.findAncestor(ClassOrInterfaceDeclaration.class)
.map(ClassOrInterfaceDeclaration::isInterface).orElse(false);
if (n.isAbstract() || isInInterface)
return; // Allow abstract methods
ACFG acfg = new ACFG();
acfg.build(n);
acfgMap.put(n, acfg);
super.visit(n, arg);
}
}, null);
}
protected Stream<File> findJavaFile(File file) {
Stream.Builder<File> builder = Stream.builder();
builder.accept(file);
return builder.build();
}
}
\ No newline at end of file
package es.upv.mist.slicing.tests;
public class Test_Entrevista {
public static void main(String[] args)
{
int x = 1;
while (x > 1) {
if (x > 10) {
x++;
} else {
while (x > 1) {
if (x > 10) {
x++;
} else {
if (x > 10) {
x++;
} else {
x--;
}
}
}
}
}
}
}
...@@ -32,8 +32,8 @@ ...@@ -32,8 +32,8 @@
</build> </build>
<properties> <properties>
<maven.compiler.source>11</maven.compiler.source> <maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target> <maven.compiler.target>21</maven.compiler.target>
</properties> </properties>
<modules> <modules>
...@@ -41,5 +41,6 @@ ...@@ -41,5 +41,6 @@
<module>sdg-cli</module> <module>sdg-cli</module>
<module>javaparser-symbol-solver-core</module> <module>javaparser-symbol-solver-core</module>
<module>sdg-bench</module> <module>sdg-bench</module>
<module>iacfg</module>
</modules> </modules>
</project> </project>
...@@ -97,8 +97,8 @@ public class Slicer { ...@@ -97,8 +97,8 @@ public class Slicer {
private File scFile; private File scFile;
private int scLine; private int scLine;
private String scVar; private String scVar;
private final CommandLine cliOpts;
private final CommandLine cliOpts;
public Slicer(String... cliArgs) throws ParseException { public Slicer(String... cliArgs) throws ParseException {
cliOpts = new DefaultParser().parse(OPTIONS, cliArgs); cliOpts = new DefaultParser().parse(OPTIONS, cliArgs);
if (cliOpts.hasOption('h')) if (cliOpts.hasOption('h'))
...@@ -185,7 +185,7 @@ public class Slicer { ...@@ -185,7 +185,7 @@ public class Slicer {
List<Problem> problems = new LinkedList<>(); List<Problem> problems = new LinkedList<>();
boolean scFileFound = false; boolean scFileFound = false;
for (File file : (Iterable<File>) findAllJavaFiles(dirIncludeSet)::iterator) for (File file : (Iterable<File>) findAllJavaFiles(dirIncludeSet)::iterator)
scFileFouah, nd |= parse(file, units, problems); scFileFound |= parse(file, units, problems);
if (!scFileFound) if (!scFileFound)
parse(scFile, units, problems); parse(scFile, units, problems);
if (!problems.isEmpty()) { if (!problems.isEmpty()) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment