forked from JavaTX/JavaCompilerCore
Merge branch 'bytecode2' into plugin
# Conflicts: # pom.xml # src/main/java/de/dhbwstuttgart/bytecode/BytecodeGenMethod.java # src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java # src/main/java/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java # src/main/java/de/dhbwstuttgart/typeinference/unify/RuleSet.java # src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify.java # src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java # src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java # src/main/java/de/dhbwstuttgart/typeinference/unify/UnifyResultEvent.java # src/main/java/de/dhbwstuttgart/typeinference/unify/UnifyResultModel.java # src/main/java/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java
This commit is contained in:
commit
6c83206f3a
257
pom.xml
257
pom.xml
@ -1,88 +1,175 @@
|
|||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
|
||||||
http://maven.apache.org/maven-v4_0_0.xsd">
|
http://maven.apache.org/maven-v4_0_0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>de.dhbwstuttgart</groupId>
|
<groupId>de.dhbwstuttgart</groupId>
|
||||||
<artifactId>JavaTXcompiler</artifactId>
|
<artifactId>JavaTXcompiler</artifactId>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
<version>0.1</version>
|
|
||||||
<name>JavaTXcompiler</name>
|
|
||||||
<url>http://maven.apache.org</url>
|
|
||||||
<dependencies>
|
|
||||||
<dependency>
|
|
||||||
<groupId>junit</groupId>
|
|
||||||
<artifactId>junit</artifactId>
|
|
||||||
<version>4.0</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.antlr</groupId>
|
|
||||||
<artifactId>antlr4</artifactId>
|
|
||||||
<version>4.7</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>commons-io</groupId>
|
|
||||||
<artifactId>commons-io</artifactId>
|
|
||||||
<version>2.6</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.google.guava</groupId>
|
|
||||||
<artifactId>guava</artifactId>
|
|
||||||
<version>22.0</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.reflections</groupId>
|
|
||||||
<artifactId>reflections</artifactId>
|
|
||||||
<version>0.9.11</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.ow2.asm</groupId>
|
|
||||||
<artifactId>asm-all</artifactId>
|
|
||||||
<version>[4.0.0,)</version>
|
|
||||||
</dependency>
|
|
||||||
<!--
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.bitbucket.mstrobel</groupId>
|
|
||||||
<artifactId>procyon-reflection</artifactId>
|
|
||||||
<version>[0.5.32,)</version>
|
|
||||||
</dependency> -->
|
|
||||||
</dependencies>
|
|
||||||
|
|
||||||
<build>
|
<version>0.1</version>
|
||||||
<directory>target</directory>
|
<name>JavaTXcompiler</name>
|
||||||
<outputDirectory>target/classes</outputDirectory>
|
<url>http://maven.apache.org</url>
|
||||||
<finalName>${artifactId}-${version}</finalName>
|
<dependencies>
|
||||||
<testOutputDirectory>target/test-classes</testOutputDirectory>
|
<dependency>
|
||||||
<sourceDirectory>src/</sourceDirectory>
|
<groupId>junit</groupId>
|
||||||
<testSourceDirectory>test/</testSourceDirectory>
|
<artifactId>junit</artifactId>
|
||||||
<plugins>
|
<version>4.0</version>
|
||||||
<plugin>
|
<scope>test</scope>
|
||||||
<groupId>org.antlr</groupId>
|
</dependency>
|
||||||
<artifactId>antlr4-maven-plugin</artifactId>
|
<dependency>
|
||||||
<version>4.7</version>
|
<groupId>org.antlr</groupId>
|
||||||
<executions>
|
<artifactId>antlr4</artifactId>
|
||||||
<execution>
|
<version>4.7</version>
|
||||||
<id>antlr</id>
|
</dependency>
|
||||||
<goals>
|
<dependency>
|
||||||
<goal>antlr4</goal>
|
<groupId>commons-io</groupId>
|
||||||
</goals>
|
<artifactId>commons-io</artifactId>
|
||||||
<configuration>
|
<version>2.6</version>
|
||||||
<sourceDirectory>src/de/dhbwstuttgart/parser/antlr/</sourceDirectory>
|
</dependency>
|
||||||
<outputDirectory>src/de/dhbwstuttgart/parser/antlr/</outputDirectory>
|
<dependency>
|
||||||
<arguments>
|
<groupId>com.google.guava</groupId>
|
||||||
<argument>-package</argument>
|
<artifactId>guava</artifactId>
|
||||||
<argument>de.dhbwstuttgart.parser.antlr</argument>
|
<version>22.0</version>
|
||||||
</arguments>
|
</dependency>
|
||||||
</configuration>
|
<dependency>
|
||||||
</execution>
|
<groupId>org.reflections</groupId>
|
||||||
</executions>
|
<artifactId>reflections</artifactId>
|
||||||
</plugin>
|
<version>0.9.11</version>
|
||||||
</plugins>
|
</dependency>
|
||||||
</build>
|
<!-- https://mvnrepository.com/artifact/org.ow2.asm/asm -->
|
||||||
<properties>
|
<dependency>
|
||||||
<maven.compiler.source>1.8</maven.compiler.source>
|
<groupId>org.ow2.asm</groupId>
|
||||||
<maven.compiler.target>1.8</maven.compiler.target>
|
<artifactId>asm</artifactId>
|
||||||
</properties>
|
<version>7.0</version>
|
||||||
|
</dependency>
|
||||||
|
<!-- <dependency> <groupId>org.ow2.asm</groupId> <artifactId>asm-all</artifactId>
|
||||||
|
<version>[4.0.0,)</version> </dependency> -->
|
||||||
|
<!-- <dependency> <groupId>org.bitbucket.mstrobel</groupId> <artifactId>procyon-reflection</artifactId>
|
||||||
|
<version>[0.5.32,)</version> </dependency> -->
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<directory>target</directory>
|
||||||
|
<outputDirectory>target/classes</outputDirectory>
|
||||||
|
<finalName>${project.artifactId}-${project.version}</finalName>
|
||||||
|
<testOutputDirectory>target/test-classes</testOutputDirectory>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
|
<version>3.0.0-M3</version>
|
||||||
|
<configuration>
|
||||||
|
<skipTests>true</skipTests>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.antlr</groupId>
|
||||||
|
<artifactId>antlr4-maven-plugin</artifactId>
|
||||||
|
<version>4.7</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>antlr</id>
|
||||||
|
<goals>
|
||||||
|
<goal>antlr4</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<sourceDirectory>src/main/antlr4/java8</sourceDirectory>
|
||||||
|
<outputDirectory>${project.basedir}/target/generated-sources/antlr4/de/dhbwstuttgart/parser/antlr</outputDirectory>
|
||||||
|
<arguments>
|
||||||
|
<argument>-package</argument>
|
||||||
|
<argument>de.dhbwstuttgart.parser.antlr</argument>
|
||||||
|
</arguments>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
<execution>
|
||||||
|
<id>aspParser</id>
|
||||||
|
<goals>
|
||||||
|
<goal>antlr4</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<sourceDirectory>src/main/antlr4/sat</sourceDirectory>
|
||||||
|
<outputDirectory>${project.basedir}/target/generated-sources/antlr4/de/dhbwstuttgart/sat/asp/parser/antlr</outputDirectory>
|
||||||
|
<arguments>
|
||||||
|
<argument>-package</argument>
|
||||||
|
<argument>de.dhbwstuttgart.sat.asp.parser.antlr</argument>
|
||||||
|
</arguments>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-assembly-plugin</artifactId>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>single</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
<configuration>
|
||||||
|
<descriptorRefs>
|
||||||
|
<descriptorRef>jar-with-dependencies</descriptorRef>
|
||||||
|
</descriptorRefs>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.reficio</groupId>
|
||||||
|
<artifactId>p2-maven-plugin</artifactId>
|
||||||
|
<version>1.1.2-SNAPSHOT</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>default-cli</id>
|
||||||
|
<configuration>
|
||||||
|
<artifacts>
|
||||||
|
<!-- specify your depencies here -->
|
||||||
|
<!-- groupId:artifactId:version -->
|
||||||
|
<artifact>
|
||||||
|
<id>de.dhbwstuttgart:JavaTXcompiler:0.1</id>
|
||||||
|
</artifact>
|
||||||
|
<artifact>
|
||||||
|
<id>org.reflections:reflections:0.9.11</id>
|
||||||
|
</artifact>
|
||||||
|
<artifact>
|
||||||
|
<id>com.google.guava:guava:22.0</id>
|
||||||
|
</artifact>
|
||||||
|
<artifact>
|
||||||
|
<id>javax.annotation:javax.annotation-api:1.3.1</id>
|
||||||
|
</artifact>
|
||||||
|
<artifact>
|
||||||
|
<id>org.glassfish:javax.annotation:3.1.1</id>
|
||||||
|
</artifact>
|
||||||
|
</artifacts>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
<pluginRepositories>
|
||||||
|
<pluginRepository>
|
||||||
|
<id>reficio</id>
|
||||||
|
<url>http://repo.reficio.org/maven/</url>
|
||||||
|
</pluginRepository>
|
||||||
|
</pluginRepositories>
|
||||||
|
<repositories>
|
||||||
|
<repository>
|
||||||
|
<id>maven-repository</id>
|
||||||
|
<url>file:///${project.basedir}/target</url>
|
||||||
|
</repository>
|
||||||
|
</repositories>
|
||||||
|
<properties>
|
||||||
|
<maven.compiler.source>1.8</maven.compiler.source>
|
||||||
|
<maven.compiler.target>1.8</maven.compiler.target>
|
||||||
|
<tycho.version>0.23.0</tycho.version>
|
||||||
|
</properties>
|
||||||
|
<distributionManagement>
|
||||||
|
<repository>
|
||||||
|
<id>maven-repository</id>
|
||||||
|
<name>MyCo Internal Repository</name>
|
||||||
|
<url>file:///${project.basedir}/maven-repository/</url>
|
||||||
|
</repository>
|
||||||
|
</distributionManagement>
|
||||||
</project>
|
</project>
|
||||||
|
@ -147,23 +147,7 @@ public class BytecodeGen implements ASTVisitor {
|
|||||||
if(!tphExtractor.allTPHS.get(t))
|
if(!tphExtractor.allTPHS.get(t))
|
||||||
tphsClass.add(t);
|
tphsClass.add(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
ArrayList<TPHConstraint> consClass = new ArrayList<>();
|
|
||||||
for(TPHConstraint cons : tphExtractor.allCons) {
|
|
||||||
TypePlaceholder right = null;
|
|
||||||
for(TypePlaceholder tph : tphsClass) {
|
|
||||||
if(cons.getLeft().equals(tph.getName())) {
|
|
||||||
|
|
||||||
consClass.add(cons);
|
|
||||||
right = getTPH(cons.getRight());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(right != null) {
|
|
||||||
tphsClass.add(right);
|
|
||||||
removeFromMethod(right.getName());
|
|
||||||
right = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
String sig = null;
|
String sig = null;
|
||||||
/* if class has generics then creates signature
|
/* if class has generics then creates signature
|
||||||
* Signature looks like:
|
* Signature looks like:
|
||||||
@ -172,6 +156,23 @@ public class BytecodeGen implements ASTVisitor {
|
|||||||
if(classOrInterface.getGenerics().iterator().hasNext() || !commonPairs.isEmpty() ||
|
if(classOrInterface.getGenerics().iterator().hasNext() || !commonPairs.isEmpty() ||
|
||||||
classOrInterface.getSuperClass().acceptTV(new TypeToSignature()).contains("<")
|
classOrInterface.getSuperClass().acceptTV(new TypeToSignature()).contains("<")
|
||||||
|| !tphsClass.isEmpty()) {
|
|| !tphsClass.isEmpty()) {
|
||||||
|
HashMap<TPHConstraint, HashSet<String>> constraints = Simplify.simplifyConstraintsClass(tphExtractor,tphsClass);
|
||||||
|
ArrayList<TPHConstraint> consClass = new ArrayList<>();
|
||||||
|
for(TPHConstraint cons : constraints.keySet()) {
|
||||||
|
TypePlaceholder right = null;
|
||||||
|
for(TypePlaceholder tph : tphsClass) {
|
||||||
|
if(cons.getLeft().equals(tph.getName())) {
|
||||||
|
|
||||||
|
consClass.add(cons);
|
||||||
|
right = getTPH(cons.getRight());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(right != null) {
|
||||||
|
tphsClass.add(right);
|
||||||
|
removeFromMethod(right.getName());
|
||||||
|
right = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
Signature signature = new Signature(classOrInterface, genericsAndBounds,commonPairs,tphsClass, consClass);
|
Signature signature = new Signature(classOrInterface, genericsAndBounds,commonPairs,tphsClass, consClass);
|
||||||
sig = signature.toString();
|
sig = signature.toString();
|
||||||
System.out.println("Signature: => " + sig);
|
System.out.println("Signature: => " + sig);
|
||||||
|
@ -140,7 +140,8 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public BytecodeGenMethod(LambdaExpression lambdaExpression, ArrayList<String> usedVars, ResultSet resultSet, MethodVisitor mv,
|
public BytecodeGenMethod(LambdaExpression lambdaExpression, ArrayList<String> usedVars, ResultSet resultSet, MethodVisitor mv,
|
||||||
int indexOfFirstParamLam, boolean isInterface, HashMap<String, byte[]> classFiles, String path, int lamCounter, SourceFile sf) {
|
int indexOfFirstParamLam, boolean isInterface, HashMap<String, byte[]> classFiles, String path, int lamCounter, SourceFile sf,HashMap<String, String> genericsAndBoundsMethod,
|
||||||
|
HashMap<String, String> genericsAndBounds) {
|
||||||
|
|
||||||
this.resultSet = resultSet;
|
this.resultSet = resultSet;
|
||||||
this.mv = mv;
|
this.mv = mv;
|
||||||
@ -149,6 +150,9 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
this.path = path;
|
this.path = path;
|
||||||
this.lamCounter = lamCounter;
|
this.lamCounter = lamCounter;
|
||||||
this.sf = sf;
|
this.sf = sf;
|
||||||
|
this.genericsAndBoundsMethod = genericsAndBoundsMethod;
|
||||||
|
this.genericsAndBounds = genericsAndBounds;
|
||||||
|
|
||||||
Iterator<FormalParameter> itr = lambdaExpression.params.iterator();
|
Iterator<FormalParameter> itr = lambdaExpression.params.iterator();
|
||||||
int i = indexOfFirstParamLam;
|
int i = indexOfFirstParamLam;
|
||||||
|
|
||||||
@ -644,7 +648,8 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
ArrayList<String> usedVars = kindOfLambda.getUsedVars();
|
ArrayList<String> usedVars = kindOfLambda.getUsedVars();
|
||||||
|
|
||||||
new BytecodeGenMethod(lambdaExpression, usedVars,this.resultSet, mvLambdaBody, indexOfFirstParamLam, isInterface,
|
new BytecodeGenMethod(lambdaExpression, usedVars,this.resultSet, mvLambdaBody, indexOfFirstParamLam, isInterface,
|
||||||
classFiles,this.path, lamCounter, sf);
|
classFiles,this.path, lamCounter, sf, genericsAndBoundsMethod,
|
||||||
|
genericsAndBounds);
|
||||||
|
|
||||||
mvLambdaBody.visitMaxs(0, 0);
|
mvLambdaBody.visitMaxs(0, 0);
|
||||||
mvLambdaBody.visitEnd();
|
mvLambdaBody.visitEnd();
|
||||||
@ -744,6 +749,13 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
statement = new IfStatement(ifStmt.expr, ifStmt.then_block, ifStmt.else_block);
|
statement = new IfStatement(ifStmt.expr, ifStmt.then_block, ifStmt.else_block);
|
||||||
isBinaryExp = statement.isExprBinary();
|
isBinaryExp = statement.isExprBinary();
|
||||||
ifStmt.expr.accept(this);
|
ifStmt.expr.accept(this);
|
||||||
|
if(!(ifStmt.expr instanceof BinaryExpr)) {
|
||||||
|
doUnboxing(getResolvedType(ifStmt.expr.getType()));
|
||||||
|
Label branchLabel = new Label();
|
||||||
|
Label endLabel = new Label();
|
||||||
|
mv.visitJumpInsn(Opcodes.IFEQ, branchLabel);
|
||||||
|
statement.genBCForRelOp(mv, branchLabel, endLabel, this);
|
||||||
|
}
|
||||||
statement = null;
|
statement = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -758,84 +770,90 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
System.out.println("In MethodCall = " + methodCall.name);
|
System.out.println("In MethodCall = " + methodCall.name);
|
||||||
String receiverName = getResolvedType(methodCall.receiver.getType());
|
String receiverName = getResolvedType(methodCall.receiver.getType());
|
||||||
System.out.println("Methods of " + receiverName + " ");
|
System.out.println("Methods of " + receiverName + " ");
|
||||||
ClassLoader cLoader = ClassLoader.getSystemClassLoader();
|
|
||||||
// This will be used if the class is not standard class (not in API)
|
|
||||||
ClassLoader cLoader2;
|
|
||||||
java.lang.reflect.Method methodRefl = null;
|
java.lang.reflect.Method methodRefl = null;
|
||||||
String clazz = receiverName.replace("/", ".");
|
String clazz = receiverName.replace("/", ".");
|
||||||
String methCallType = resultSet.resolveType(methodCall.getType()).resolvedType.acceptTV(new TypeToDescriptor());
|
// if(!receiverName.equals(className)) {
|
||||||
String[] typesOfParams = getTypes(methodCall.arglist.getArguments());
|
ClassLoader cLoader = ClassLoader.getSystemClassLoader();
|
||||||
try {
|
// This will be used if the class is not standard class (not in API)
|
||||||
if(receiverName.contains("<")) {
|
ClassLoader cLoader2;
|
||||||
clazz = clazz.substring(0, receiverName.indexOf("<"));
|
|
||||||
}
|
|
||||||
|
|
||||||
java.lang.reflect.Method[] methods = cLoader.loadClass(clazz).getMethods();
|
String methCallType = resultSet.resolveType(methodCall.getType()).resolvedType.acceptTV(new TypeToDescriptor());
|
||||||
System.out.println("Methods of " + receiverName + " ");
|
String[] typesOfParams = getTypes(methodCall.arglist.getArguments());
|
||||||
methodRefl = getMethod(methodCall.name,methodCall.arglist.getArguments().size(),methods);
|
try {
|
||||||
|
if(receiverName.contains("<")) {
|
||||||
} catch (Exception e) {
|
clazz = clazz.substring(0, receiverName.indexOf("<"));
|
||||||
// try {
|
}
|
||||||
// cLoader2 = new URLClassLoader(new URL[] {new URL("file://"+path)});
|
|
||||||
// java.lang.reflect.Method[] methods = cLoader2.loadClass(clazz).getMethods();
|
java.lang.reflect.Method[] methods = cLoader.loadClass(clazz).getMethods();
|
||||||
// System.out.println("Methods of " + receiverName + " ");
|
System.out.println("Methods of " + receiverName + " ");
|
||||||
// for(int i = 0; i<methods.length; i++) {
|
methodRefl = getMethod(methodCall.name,methodCall.arglist.getArguments().size(),methods);
|
||||||
// System.out.println(methods[i]);
|
|
||||||
// }
|
} catch (Exception e) {
|
||||||
// methodRefl = getMethod(methodCall.name,methodCall.arglist.getArguments().size(),methCallType, typesOfParams,methods);
|
// try {
|
||||||
// }catch (Exception e2) {
|
// cLoader2 = new URLClassLoader(new URL[] {new URL("file://"+path)});
|
||||||
String superClass = "";
|
// java.lang.reflect.Method[] methods = cLoader2.loadClass(clazz).getMethods();
|
||||||
// TODO: Test SubMatrix.jav
|
// System.out.println("Methods of " + receiverName + " ");
|
||||||
while(true) {
|
// for(int i = 0; i<methods.length; i++) {
|
||||||
for(ClassOrInterface cl : sf.getClasses()) {
|
// System.out.println(methods[i]);
|
||||||
if(receiverName.equals(cl.getClassName().toString())) {
|
// }
|
||||||
superClass = cl.getSuperClass().getName().toString();
|
// methodRefl = getMethod(methodCall.name,methodCall.arglist.getArguments().size(),methCallType, typesOfParams,methods);
|
||||||
break;
|
// }catch (Exception e2) {
|
||||||
}
|
String superClass = "";
|
||||||
}
|
// TODO: Test SubMatrix.jav
|
||||||
System.out.println(superClass);
|
while(true) {
|
||||||
|
for(ClassOrInterface cl : sf.getClasses()) {
|
||||||
if(superClass.equals(""))
|
if(receiverName.equals(cl.getClassName().toString())) {
|
||||||
break;
|
superClass = cl.getSuperClass().getName().toString();
|
||||||
|
|
||||||
try {
|
|
||||||
String superClazz = superClass.replace("/", ".");
|
|
||||||
if(superClass.contains("<")) {
|
|
||||||
superClazz = superClazz.substring(0, superClass.indexOf("<"));
|
|
||||||
}
|
|
||||||
java.lang.reflect.Method[] methods = cLoader.loadClass(superClazz).getMethods();
|
|
||||||
System.out.println("Methods of " + superClass + " ");
|
|
||||||
|
|
||||||
for(java.lang.reflect.Method m : methods) {
|
|
||||||
if(methodCall.name.equals(m.getName())) {
|
|
||||||
methodRefl = m;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
System.out.println(superClass);
|
||||||
|
|
||||||
break;
|
if(superClass.equals(""))
|
||||||
} catch (Exception e3) {
|
break;
|
||||||
receiverName = superClass;
|
|
||||||
continue;
|
try {
|
||||||
|
String superClazz = superClass.replace("/", ".");
|
||||||
|
if(superClass.contains("<")) {
|
||||||
|
superClazz = superClazz.substring(0, superClass.indexOf("<"));
|
||||||
|
}
|
||||||
|
java.lang.reflect.Method[] methods = cLoader.loadClass(superClazz).getMethods();
|
||||||
|
System.out.println("Methods of " + superClass + " ");
|
||||||
|
|
||||||
|
for(java.lang.reflect.Method m : methods) {
|
||||||
|
if(methodCall.name.equals(m.getName())) {
|
||||||
|
methodRefl = m;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
} catch (Exception e3) {
|
||||||
|
receiverName = superClass;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
// }
|
||||||
// }
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if(methodRefl == null) {
|
|
||||||
try {
|
|
||||||
cLoader2 = new URLClassLoader(new URL[] {new URL("file://"+path)});
|
|
||||||
java.lang.reflect.Method[] methods = cLoader2.loadClass(clazz).getMethods();
|
|
||||||
System.out.println("Methods of " + receiverName + " ");
|
|
||||||
for(int i = 0; i<methods.length; i++) {
|
|
||||||
System.out.println(methods[i]);
|
|
||||||
}
|
|
||||||
methodRefl = getMethod(methodCall.name,methodCall.arglist.getArguments().size(),methCallType, typesOfParams,methods);
|
|
||||||
}catch (Exception e2) {
|
|
||||||
//do nothing
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
if(methodRefl == null) {
|
||||||
|
try {
|
||||||
|
cLoader2 = new URLClassLoader(new URL[] {new URL("file://"+path)});
|
||||||
|
java.lang.reflect.Method[] methods = cLoader2.loadClass(clazz).getMethods();
|
||||||
|
System.out.println("Methods of " + receiverName + " ");
|
||||||
|
for(int i = 0; i<methods.length; i++) {
|
||||||
|
System.out.println(methods[i]);
|
||||||
|
}
|
||||||
|
methodRefl = getMethod(methodCall.name,methodCall.arglist.getArguments().size(),methCallType, typesOfParams,methods);
|
||||||
|
}
|
||||||
|
catch (Exception e2) {
|
||||||
|
System.out.println("");
|
||||||
|
//do nothing
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// }
|
||||||
|
|
||||||
methodCall.receiver.accept(this);
|
methodCall.receiver.accept(this);
|
||||||
|
|
||||||
System.out.println("Methodcall type : " + resultSet.resolveType(methodCall.getType()).resolvedType.acceptTV(new TypeToDescriptor()));
|
System.out.println("Methodcall type : " + resultSet.resolveType(methodCall.getType()).resolvedType.acceptTV(new TypeToDescriptor()));
|
||||||
@ -848,6 +866,7 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
mDesc = method.accept(new DescriptorToString(resultSet));
|
mDesc = method.accept(new DescriptorToString(resultSet));
|
||||||
methodCall.arglist.accept(this);
|
methodCall.arglist.accept(this);
|
||||||
} else {
|
} else {
|
||||||
|
System.out.println(methodCall.name + " -> Refl != null");
|
||||||
receiverRefl = methodRefl.getAnnotatedReceiverType().getType().toString();
|
receiverRefl = methodRefl.getAnnotatedReceiverType().getType().toString();
|
||||||
for(Parameter p:methodRefl.getParameters()) {
|
for(Parameter p:methodRefl.getParameters()) {
|
||||||
System.out.println(p.getName() + " und is Primitive = " + p.getType().isPrimitive());
|
System.out.println(p.getName() + " und is Primitive = " + p.getType().isPrimitive());
|
||||||
@ -863,7 +882,7 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.println("Methodcall Desc : " + mDesc);
|
System.out.println("Methodcall ("+ methodCall.name +") Desc : " + mDesc);
|
||||||
|
|
||||||
|
|
||||||
// methodCall.arglist.accept(this);
|
// methodCall.arglist.accept(this);
|
||||||
@ -1195,6 +1214,7 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
case "java/lang/Boolean":
|
case "java/lang/Boolean":
|
||||||
|
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Boolean", "booleanValue", "()Z", false);
|
||||||
break;
|
break;
|
||||||
case "java/lang/Byte":
|
case "java/lang/Byte":
|
||||||
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Byte", "byteValue", "()B", false);
|
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Byte", "byteValue", "()B", false);
|
||||||
|
@ -5,13 +5,19 @@ package de.dhbwstuttgart.bytecode;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.Iterator;
|
||||||
|
|
||||||
import de.dhbwstuttgart.bytecode.constraint.ExtendsConstraint;
|
import de.dhbwstuttgart.bytecode.constraint.ExtendsConstraint;
|
||||||
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint;
|
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint;
|
||||||
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation;
|
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation;
|
||||||
import de.dhbwstuttgart.bytecode.utilities.MethodAndTPH;
|
import de.dhbwstuttgart.bytecode.utilities.MethodAndTPH;
|
||||||
import de.dhbwstuttgart.syntaxtree.AbstractASTWalker;
|
import de.dhbwstuttgart.syntaxtree.AbstractASTWalker;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.Constructor;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.FormalParameter;
|
||||||
import de.dhbwstuttgart.syntaxtree.Method;
|
import de.dhbwstuttgart.syntaxtree.Method;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.ParameterList;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.statement.LocalVar;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.statement.LocalVarDecl;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||||
import de.dhbwstuttgart.typeinference.result.GenericInsertPair;
|
import de.dhbwstuttgart.typeinference.result.GenericInsertPair;
|
||||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||||
@ -20,36 +26,42 @@ import de.dhbwstuttgart.typeinference.result.ResultSet;
|
|||||||
* @author Fayez Abu Alia
|
* @author Fayez Abu Alia
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class TPHExtractor extends AbstractASTWalker{
|
public class TPHExtractor extends AbstractASTWalker {
|
||||||
// Alle TPHs der Felder werden iKopf der Klasse definiert
|
// Alle TPHs der Felder werden iKopf der Klasse definiert
|
||||||
// alle TPHs der Klasse: (TPH, is in Method?)
|
// alle TPHs der Klasse: (TPH, is in Method?)
|
||||||
final HashMap<TypePlaceholder,Boolean> allTPHS = new HashMap<>();
|
final HashMap<TypePlaceholder, Boolean> allTPHS = new HashMap<>();
|
||||||
MethodAndTPH methodAndTph;
|
MethodAndTPH methodAndTph;
|
||||||
|
|
||||||
Boolean inMethod = false;
|
Boolean inMethod = false;
|
||||||
|
boolean inLocalOrParam = false;
|
||||||
|
|
||||||
public final ArrayList<MethodAndTPH> ListOfMethodsAndTph = new ArrayList<>();
|
public final ArrayList<MethodAndTPH> ListOfMethodsAndTph = new ArrayList<>();
|
||||||
final ArrayList<GenericInsertPair> allPairs = new ArrayList<>();
|
final ArrayList<GenericInsertPair> allPairs = new ArrayList<>();
|
||||||
public final ArrayList<TPHConstraint> allCons = new ArrayList<>();
|
public final ArrayList<TPHConstraint> allCons = new ArrayList<>();
|
||||||
private ResultSet resultSet;
|
private ResultSet resultSet;
|
||||||
|
|
||||||
public TPHExtractor() {
|
public TPHExtractor() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setResultSet(ResultSet resultSet) {
|
public void setResultSet(ResultSet resultSet) {
|
||||||
this.resultSet = resultSet;
|
this.resultSet = resultSet;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visit(TypePlaceholder tph) {
|
public void visit(TypePlaceholder tph) {
|
||||||
if(resultSet.resolveType(tph).resolvedType instanceof TypePlaceholder) {
|
if (resultSet.resolveType(tph).resolvedType instanceof TypePlaceholder) {
|
||||||
TypePlaceholder resolvedTPH = (TypePlaceholder) resultSet.resolveType(tph).resolvedType;
|
TypePlaceholder resolvedTPH = (TypePlaceholder) resultSet.resolveType(tph).resolvedType;
|
||||||
if(inMethod)
|
if (inMethod) {
|
||||||
methodAndTph.getTphs().add(resolvedTPH.getName());
|
methodAndTph.getTphs().add(resolvedTPH.getName());
|
||||||
|
if (inLocalOrParam)
|
||||||
allTPHS.put(resolvedTPH,inMethod);
|
methodAndTph.getLocalTphs().add(resolvedTPH.getName());
|
||||||
resultSet.resolveType(tph).additionalGenerics.forEach(ag ->{
|
}
|
||||||
if(ag.contains(resolvedTPH)&&ag.TA1.equals(resolvedTPH)&&!contains(allPairs,ag)) {
|
|
||||||
if(inMethod)
|
allTPHS.put(resolvedTPH, inMethod);
|
||||||
|
resultSet.resolveType(tph).additionalGenerics.forEach(ag -> {
|
||||||
|
if (ag.contains(resolvedTPH) && ag.TA1.equals(resolvedTPH) && !contains(allPairs, ag)) {
|
||||||
|
if (inMethod)
|
||||||
methodAndTph.getPairs().add(ag);
|
methodAndTph.getPairs().add(ag);
|
||||||
allPairs.add(ag);
|
allPairs.add(ag);
|
||||||
TPHConstraint con = new ExtendsConstraint(ag.TA1.getName(), ag.TA2.getName(), Relation.EXTENDS);
|
TPHConstraint con = new ExtendsConstraint(ag.TA1.getName(), ag.TA2.getName(), Relation.EXTENDS);
|
||||||
@ -58,14 +70,16 @@ public class TPHExtractor extends AbstractASTWalker{
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean contains(ArrayList<GenericInsertPair> pairs, GenericInsertPair genPair) {
|
private boolean contains(ArrayList<GenericInsertPair> pairs, GenericInsertPair genPair) {
|
||||||
for(int i=0; i<pairs.size();++i) {
|
for (int i = 0; i < pairs.size(); ++i) {
|
||||||
GenericInsertPair p = pairs.get(i);
|
GenericInsertPair p = pairs.get(i);
|
||||||
if(p.TA1.equals(genPair.TA1) && p.TA2.equals(genPair.TA2))
|
if (p.TA1.equals(genPair.TA1) && p.TA2.equals(genPair.TA2))
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visit(Method method) {
|
public void visit(Method method) {
|
||||||
inMethod = true;
|
inMethod = true;
|
||||||
@ -74,5 +88,33 @@ public class TPHExtractor extends AbstractASTWalker{
|
|||||||
inMethod = false;
|
inMethod = false;
|
||||||
ListOfMethodsAndTph.add(methodAndTph);
|
ListOfMethodsAndTph.add(methodAndTph);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visit(Constructor cons) {
|
||||||
|
inMethod = false;
|
||||||
|
super.visit(cons);
|
||||||
|
inMethod = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visit(LocalVarDecl localVarDecl) {
|
||||||
|
inLocalOrParam = true;
|
||||||
|
super.visit(localVarDecl);
|
||||||
|
inLocalOrParam = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visit(LocalVar localVar) {
|
||||||
|
inLocalOrParam = true;
|
||||||
|
super.visit(localVar);
|
||||||
|
inLocalOrParam = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visit(ParameterList formalParameters) {
|
||||||
|
inLocalOrParam = true;
|
||||||
|
super.visit(formalParameters);
|
||||||
|
inLocalOrParam = false;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -391,7 +391,7 @@ public class Signature {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for(TPHConstraint cons : consClass) {
|
for(TPHConstraint cons : consClass) {
|
||||||
if(!types.contains(cons.getRight())) {
|
if(!types.contains(cons.getRight()) && !genericsAndBounds.keySet().contains(cons.getRight()+"$")) {
|
||||||
String t = cons.getRight()+"$";
|
String t = cons.getRight()+"$";
|
||||||
String bound = Type.getInternalName(Object.class);
|
String bound = Type.getInternalName(Object.class);
|
||||||
sw.visitFormalTypeParameter(t);
|
sw.visitFormalTypeParameter(t);
|
||||||
|
@ -0,0 +1,51 @@
|
|||||||
|
package de.dhbwstuttgart.bytecode.utilities;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint;
|
||||||
|
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation;
|
||||||
|
|
||||||
|
public class ConstraintsFinder {
|
||||||
|
private List<TPHConstraint> allConstaints;
|
||||||
|
|
||||||
|
public ConstraintsFinder(List<TPHConstraint> allConstaints) {
|
||||||
|
super();
|
||||||
|
this.allConstaints = allConstaints;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<List<TPHConstraint>> findConstraints() {
|
||||||
|
List<List<TPHConstraint>> result = new ArrayList<>();
|
||||||
|
|
||||||
|
List<TPHConstraint> visitedCons = new ArrayList<>();
|
||||||
|
for(TPHConstraint c : allConstaints) {
|
||||||
|
if(c.getRel() == Relation.EXTENDS) {
|
||||||
|
// get constraints with the same left side
|
||||||
|
List<TPHConstraint> cons = getConstraints(c,visitedCons);
|
||||||
|
if(cons.size()>1)
|
||||||
|
result.add(cons);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<TPHConstraint> getConstraints(TPHConstraint c, List<TPHConstraint> visitedCons) {
|
||||||
|
List<TPHConstraint> res = new ArrayList<>();
|
||||||
|
for(TPHConstraint cons : allConstaints) {
|
||||||
|
if(!isVisited(cons,visitedCons) && cons.getLeft().equals(c.getLeft())) {
|
||||||
|
res.add(cons);
|
||||||
|
visitedCons.add(cons);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isVisited(TPHConstraint cons, List<TPHConstraint> visitedCons) {
|
||||||
|
for(TPHConstraint c : visitedCons) {
|
||||||
|
if(c.getLeft().equals(cons.getLeft()) && c.getRight().equals(cons.getRight()))
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
@ -10,6 +10,8 @@ public class MethodAndTPH {
|
|||||||
private String name;
|
private String name;
|
||||||
private final ArrayList<String> tphs = new ArrayList<>();
|
private final ArrayList<String> tphs = new ArrayList<>();
|
||||||
private final ArrayList<GenericInsertPair> pairs = new ArrayList<>();
|
private final ArrayList<GenericInsertPair> pairs = new ArrayList<>();
|
||||||
|
// tphs of local variables and parameters
|
||||||
|
private final ArrayList<String> localTphs = new ArrayList<>();
|
||||||
|
|
||||||
public MethodAndTPH(String name) {
|
public MethodAndTPH(String name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
@ -26,4 +28,9 @@ public class MethodAndTPH {
|
|||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ArrayList<String> getLocalTphs() {
|
||||||
|
return localTphs;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,49 @@
|
|||||||
|
package de.dhbwstuttgart.bytecode.utilities;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.factory.NameGenerator;
|
||||||
|
|
||||||
|
public class NameReplacer {
|
||||||
|
private List<TPHConstraint> constraints;
|
||||||
|
private List<TPHConstraint> allConstraints;
|
||||||
|
private List<String> tphs;
|
||||||
|
private List<String> localTphs;
|
||||||
|
|
||||||
|
public NameReplacer(List<TPHConstraint> constraints, List<TPHConstraint> allConstraints,List<String> tphs, ArrayList<String> localTphs) {
|
||||||
|
super();
|
||||||
|
this.constraints = constraints;
|
||||||
|
this.allConstraints = allConstraints;
|
||||||
|
this.tphs = tphs;
|
||||||
|
this.localTphs = localTphs;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String, List<String>> replaceNames() {
|
||||||
|
String newName = NameGenerator.makeNewName();
|
||||||
|
ArrayList<String> names = new ArrayList<>();
|
||||||
|
for(TPHConstraint cons : constraints) {
|
||||||
|
names.add(cons.getRight());
|
||||||
|
cons.setRight(newName);
|
||||||
|
}
|
||||||
|
|
||||||
|
for(TPHConstraint cons : allConstraints) {
|
||||||
|
if(names.contains(cons.getLeft()))
|
||||||
|
cons.setLeft(newName);
|
||||||
|
if(names.contains(cons.getRight()))
|
||||||
|
cons.setRight(newName);
|
||||||
|
}
|
||||||
|
|
||||||
|
tphs.removeAll(names);
|
||||||
|
tphs.add(newName);
|
||||||
|
localTphs.removeAll(names);
|
||||||
|
localTphs.add(newName);
|
||||||
|
|
||||||
|
HashMap<String, List<String>> res = new HashMap<>();
|
||||||
|
res.put(newName, names);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
}
|
File diff suppressed because it is too large
Load Diff
@ -1,3 +1,4 @@
|
|||||||
|
//PL 2018-12-19: typeInferenceOld nach typeInference uebertragen
|
||||||
package de.dhbwstuttgart.core;
|
package de.dhbwstuttgart.core;
|
||||||
|
|
||||||
|
|
||||||
@ -15,6 +16,7 @@ import de.dhbwstuttgart.syntaxtree.ParameterList;
|
|||||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||||
import de.dhbwstuttgart.syntaxtree.factory.ASTFactory;
|
import de.dhbwstuttgart.syntaxtree.factory.ASTFactory;
|
||||||
import de.dhbwstuttgart.syntaxtree.factory.UnifyTypeFactory;
|
import de.dhbwstuttgart.syntaxtree.factory.UnifyTypeFactory;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||||
import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter;
|
import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter;
|
||||||
import de.dhbwstuttgart.typeinference.constraints.Constraint;
|
import de.dhbwstuttgart.typeinference.constraints.Constraint;
|
||||||
@ -25,26 +27,37 @@ import de.dhbwstuttgart.typeinference.typeAlgo.TYPE;
|
|||||||
import de.dhbwstuttgart.typeinference.unify.RuleSet;
|
import de.dhbwstuttgart.typeinference.unify.RuleSet;
|
||||||
import de.dhbwstuttgart.typeinference.unify.TypeUnify;
|
import de.dhbwstuttgart.typeinference.unify.TypeUnify;
|
||||||
import de.dhbwstuttgart.typeinference.unify.distributeVariance;
|
import de.dhbwstuttgart.typeinference.unify.distributeVariance;
|
||||||
|
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
|
||||||
import de.dhbwstuttgart.typeinference.unify.model.FiniteClosure;
|
import de.dhbwstuttgart.typeinference.unify.model.FiniteClosure;
|
||||||
import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
|
import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
|
||||||
import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType;
|
import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType;
|
||||||
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
|
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
|
||||||
|
import de.dhbwstuttgart.typeinference.unify.model.UnifyType;
|
||||||
import de.dhbwstuttgart.typeinference.unify.TypeUnifyTask;
|
import de.dhbwstuttgart.typeinference.unify.TypeUnifyTask;
|
||||||
|
import de.dhbwstuttgart.typeinference.unify.UnifyResultListener;
|
||||||
|
import de.dhbwstuttgart.typeinference.unify.UnifyResultListenerImpl;
|
||||||
|
import de.dhbwstuttgart.typeinference.unify.UnifyResultModel;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.FileWriter;
|
import java.io.FileWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.OutputStreamWriter;
|
||||||
|
import java.io.Writer;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
import org.antlr.v4.parse.ANTLRParser.throwsSpec_return;
|
||||||
|
import org.apache.commons.io.output.NullOutputStream;
|
||||||
|
|
||||||
public class JavaTXCompiler {
|
public class JavaTXCompiler {
|
||||||
|
|
||||||
final CompilationEnvironment environment;
|
final CompilationEnvironment environment;
|
||||||
|
Boolean resultmodel = true;
|
||||||
public final Map<File, SourceFile> sourceFiles = new HashMap<>();
|
public final Map<File, SourceFile> sourceFiles = new HashMap<>();
|
||||||
Boolean log = true; //gibt an ob ein Log-File nach System.getProperty("user.dir")+"/test/logFiles/log" geschrieben werden soll?
|
Boolean log = true; //gibt an ob ein Log-File nach System.getProperty("user.dir")+"src/test/java/logFiles" geschrieben werden soll?
|
||||||
|
|
||||||
public JavaTXCompiler(File sourceFile) throws IOException, ClassNotFoundException {
|
public JavaTXCompiler(File sourceFile) throws IOException, ClassNotFoundException {
|
||||||
this(Arrays.asList(sourceFile));
|
this(Arrays.asList(sourceFile));
|
||||||
@ -103,7 +116,8 @@ public class JavaTXCompiler {
|
|||||||
return new ArrayList<>(allClasses);
|
return new ArrayList<>(allClasses);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<ResultSet> typeInference() throws ClassNotFoundException {
|
/*
|
||||||
|
public List<ResultSet> typeInferenceOld() throws ClassNotFoundException {
|
||||||
List<ClassOrInterface> allClasses = new ArrayList<>();//environment.getAllAvailableClasses();
|
List<ClassOrInterface> allClasses = new ArrayList<>();//environment.getAllAvailableClasses();
|
||||||
//Alle Importierten Klassen in allen geparsten Sourcefiles kommen ins FC
|
//Alle Importierten Klassen in allen geparsten Sourcefiles kommen ins FC
|
||||||
for(SourceFile sf : this.sourceFiles.values()) {
|
for(SourceFile sf : this.sourceFiles.values()) {
|
||||||
@ -187,10 +201,7 @@ public class JavaTXCompiler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return x;//HIER DIE JEWEILS RECHT BZW. LINKE SEITE AUF GLEICHE VARIANZ SETZEN WIE DIE JEWEILS ANDERE SEITE
|
return x;//HIER DIE JEWEILS RECHT BZW. LINKE SEITE AUF GLEICHE VARIANZ SETZEN WIE DIE JEWEILS ANDERE SEITE
|
||||||
})
|
}).map( y -> {
|
||||||
/* PL 2018-11-07 wird in varianceInheritance erledigt
|
|
||||||
.map( y -> {
|
|
||||||
|
|
||||||
if ((y.getLhsType() instanceof PlaceholderType) && (y.getRhsType() instanceof PlaceholderType)) {
|
if ((y.getLhsType() instanceof PlaceholderType) && (y.getRhsType() instanceof PlaceholderType)) {
|
||||||
if (((PlaceholderType)y.getLhsType()).getVariance() != 0 && ((PlaceholderType)y.getRhsType()).getVariance() == 0) {
|
if (((PlaceholderType)y.getLhsType()).getVariance() != 0 && ((PlaceholderType)y.getRhsType()).getVariance() == 0) {
|
||||||
((PlaceholderType)y.getRhsType()).setVariance(((PlaceholderType)y.getLhsType()).getVariance());
|
((PlaceholderType)y.getRhsType()).setVariance(((PlaceholderType)y.getLhsType()).getVariance());
|
||||||
@ -200,20 +211,16 @@ public class JavaTXCompiler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return y; } )
|
return y; } )
|
||||||
*/
|
|
||||||
.collect(Collectors.toCollection(HashSet::new));
|
.collect(Collectors.toCollection(HashSet::new));
|
||||||
varianceInheritance(xConsSet);
|
varianceInheritance(xConsSet);
|
||||||
|
Set<Set<UnifyPair>> result = unify.unifySequential(xConsSet, finiteClosure, logFile, log);
|
||||||
|
//Set<Set<UnifyPair>> result = unify.unify(xConsSet, finiteClosure);
|
||||||
|
System.out.println("RESULT: " + result);
|
||||||
Set<Set<UnifyPair>> result = unify.unifySequential(xConsSet, finiteClosure, logFile, log);
|
logFile.write("RES: " + result.toString()+"\n");
|
||||||
//Set<Set<UnifyPair>> result = unify.unify(xConsSet, finiteClosure);
|
logFile.flush();
|
||||||
System.out.println("RESULT: " + result);
|
results.addAll(result);
|
||||||
logFile.write("RES: " + result.toString()+"\n");
|
|
||||||
logFile.flush();
|
|
||||||
results.addAll(result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
results = results.stream().map(x -> {
|
results = results.stream().map(x -> {
|
||||||
Optional<Set<UnifyPair>> res = new RuleSet().subst(x.stream().map(y -> {
|
Optional<Set<UnifyPair>> res = new RuleSet().subst(x.stream().map(y -> {
|
||||||
if (y.getPairOp() == PairOperator.SMALLERDOTWC) y.setPairOp(PairOperator.EQUALSDOT);
|
if (y.getPairOp() == PairOperator.SMALLERDOTWC) y.setPairOp(PairOperator.EQUALSDOT);
|
||||||
@ -236,12 +243,14 @@ public class JavaTXCompiler {
|
|||||||
return results.stream().map((unifyPairs ->
|
return results.stream().map((unifyPairs ->
|
||||||
new ResultSet(UnifyTypeFactory.convert(unifyPairs, generateTPHMap(cons))))).collect(Collectors.toList());
|
new ResultSet(UnifyTypeFactory.convert(unifyPairs, generateTPHMap(cons))))).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
/**
|
/**
|
||||||
* Vererbt alle Variancen
|
* Vererbt alle Variancen bei Paaren (a <. theta) oder (Theta <. a)
|
||||||
|
* wenn a eine Variance !=0 hat auf alle Typvariablen in Theta.
|
||||||
* @param eq The set of constraints
|
* @param eq The set of constraints
|
||||||
*/
|
*/
|
||||||
private void varianceInheritance(Set<UnifyPair> eq) {
|
/*
|
||||||
|
private void varianceInheritance(Set<UnifyPair> eq) {
|
||||||
Set<PlaceholderType> usedTPH = new HashSet<>();
|
Set<PlaceholderType> usedTPH = new HashSet<>();
|
||||||
Set<PlaceholderType> phSet = eq.stream().map(x -> {
|
Set<PlaceholderType> phSet = eq.stream().map(x -> {
|
||||||
Set<PlaceholderType> pair = new HashSet<>();
|
Set<PlaceholderType> pair = new HashSet<>();
|
||||||
@ -267,20 +276,365 @@ public class JavaTXCompiler {
|
|||||||
phSetVariance.removeIf(x -> (x.getVariance() == 0 || usedTPH.contains(x)));
|
phSetVariance.removeIf(x -> (x.getVariance() == 0 || usedTPH.contains(x)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
public UnifyResultModel typeInferenceAsync(UnifyResultListener resultListener) throws ClassNotFoundException {
|
||||||
|
List<ClassOrInterface> allClasses = new ArrayList<>();//environment.getAllAvailableClasses();
|
||||||
|
//Alle Importierten Klassen in allen geparsten Sourcefiles kommen ins FC
|
||||||
|
for(SourceFile sf : this.sourceFiles.values()) {
|
||||||
|
allClasses.addAll(getAvailableClasses(sf));
|
||||||
|
allClasses.addAll(sf.getClasses());
|
||||||
|
}
|
||||||
|
|
||||||
private Map<String, TypePlaceholder> generateTPHMap(ConstraintSet<Pair> constraints) {
|
final ConstraintSet<Pair> cons = getConstraints();
|
||||||
HashMap<String, TypePlaceholder> ret = new HashMap<>();
|
Set<Set<UnifyPair>> results = new HashSet<>();
|
||||||
constraints.map((Pair p) -> {
|
UnifyResultModel urm = new UnifyResultModel();
|
||||||
if (p.TA1 instanceof TypePlaceholder) {
|
urm.addUnifyResultListener(resultListener);
|
||||||
ret.put(((TypePlaceholder) p.TA1).getName(), (TypePlaceholder) p.TA1);
|
try {
|
||||||
}
|
Writer logFile = new OutputStreamWriter(new NullOutputStream());
|
||||||
if (p.TA2 instanceof TypePlaceholder) {
|
//new FileWriter(new File("log_"+sourceFiles.keySet().iterator().next().getName()));
|
||||||
ret.put(((TypePlaceholder) p.TA2).getName(), (TypePlaceholder) p.TA2);
|
|
||||||
}
|
IFiniteClosure finiteClosure = UnifyTypeFactory.generateFC(allClasses,logFile);
|
||||||
return null;
|
System.out.println(finiteClosure);
|
||||||
});
|
ConstraintSet<UnifyPair> unifyCons = UnifyTypeFactory.convert(cons);
|
||||||
return ret;
|
|
||||||
|
Function<UnifyPair, UnifyPair> distributeInnerVars =
|
||||||
|
x -> {
|
||||||
|
UnifyType lhs, rhs;
|
||||||
|
if (((lhs = x.getLhsType()) instanceof PlaceholderType)
|
||||||
|
&& ((rhs = x.getRhsType()) instanceof PlaceholderType)
|
||||||
|
&& (((PlaceholderType)lhs).isInnerType()
|
||||||
|
|| ((PlaceholderType)rhs).isInnerType()))
|
||||||
|
{
|
||||||
|
((PlaceholderType)lhs).setInnerType(true);
|
||||||
|
((PlaceholderType)rhs).setInnerType(true);
|
||||||
|
}
|
||||||
|
return x;
|
||||||
|
|
||||||
|
};
|
||||||
|
logFile.write(unifyCons.toString());
|
||||||
|
unifyCons = unifyCons.map(distributeInnerVars);
|
||||||
|
logFile.write(unifyCons.toString());
|
||||||
|
TypeUnify unify = new TypeUnify();
|
||||||
|
//Set<Set<UnifyPair>> results = new HashSet<>(); Nach vorne gezogen
|
||||||
|
logFile.write("FC:\\" + finiteClosure.toString()+"\n");
|
||||||
|
for(SourceFile sf : this.sourceFiles.values()) {
|
||||||
|
logFile.write(ASTTypePrinter.print(sf));
|
||||||
|
}
|
||||||
|
logFile.flush();
|
||||||
|
|
||||||
|
Set<String> methodParaTypeVarNames = allClasses.stream().map(x -> x.getMethods().stream().map(y -> y.getParameterList().getFormalparalist()
|
||||||
|
.stream().filter(z -> z.getType() instanceof TypePlaceholder)
|
||||||
|
.map(z -> ((TypePlaceholder)z.getType()).getName()).collect(Collectors.toCollection(HashSet::new)))
|
||||||
|
.reduce(new HashSet<String>(), (a,b) -> { a.addAll(b); return a;}, (a,b) -> { a.addAll(b); return a;} ) )
|
||||||
|
.reduce(new HashSet<String>(), (a,b) -> { a.addAll(b); return a;} );
|
||||||
|
|
||||||
|
Set<String> constructorParaTypeVarNames = allClasses.stream().map(x -> x.getConstructors().stream().map(y -> y.getParameterList().getFormalparalist()
|
||||||
|
.stream().filter(z -> z.getType() instanceof TypePlaceholder)
|
||||||
|
.map(z -> ((TypePlaceholder)z.getType()).getName()).collect(Collectors.toCollection(HashSet::new)))
|
||||||
|
.reduce(new HashSet<String>(), (a,b) -> { a.addAll(b); return a;}, (a,b) -> { a.addAll(b); return a;} ) )
|
||||||
|
.reduce(new HashSet<String>(), (a,b) -> { a.addAll(b); return a;} );
|
||||||
|
|
||||||
|
Set<String> paraTypeVarNames = methodParaTypeVarNames;
|
||||||
|
paraTypeVarNames.addAll(constructorParaTypeVarNames);
|
||||||
|
|
||||||
|
|
||||||
|
Set<String> returnTypeVarNames = allClasses.stream().map(x -> x.getMethods().stream().filter(y -> y.getReturnType() instanceof TypePlaceholder)
|
||||||
|
.map(z -> ((TypePlaceholder)z.getReturnType()).getName()).collect(Collectors.toCollection(HashSet::new))).reduce((a,b) -> { a.addAll(b); return a;} ).get();
|
||||||
|
|
||||||
|
Set<String> fieldTypeVarNames = allClasses.stream().map(x -> x.getFieldDecl().stream().filter(y -> y.getReturnType() instanceof TypePlaceholder)
|
||||||
|
.map(z -> ((TypePlaceholder)z.getReturnType()).getName()).collect(Collectors.toCollection(HashSet::new))).reduce((a,b) -> { a.addAll(b); return a;} ).get();
|
||||||
|
|
||||||
|
returnTypeVarNames.addAll(fieldTypeVarNames);
|
||||||
|
|
||||||
|
unifyCons = unifyCons.map(x -> {
|
||||||
|
//Hier muss ueberlegt werden, ob
|
||||||
|
//1. alle Argument- und Retuntyp-Variablen in allen UnifyPairs
|
||||||
|
// mit disableWildcardtable() werden.
|
||||||
|
//2. alle Typvariablen mit Argument- oder Retuntyp-Variablen
|
||||||
|
//in Beziehung auch auf disableWildcardtable() gesetzt werden muessen
|
||||||
|
//PL 2018-04-23
|
||||||
|
if ((x.getLhsType() instanceof PlaceholderType)) {
|
||||||
|
if (paraTypeVarNames.contains(x.getLhsType().getName())) {
|
||||||
|
((PlaceholderType)x.getLhsType()).setVariance((byte)1);
|
||||||
|
((PlaceholderType)x.getLhsType()).disableWildcardtable();
|
||||||
|
}
|
||||||
|
if (returnTypeVarNames.contains(x.getLhsType().getName())) {
|
||||||
|
((PlaceholderType)x.getLhsType()).setVariance((byte)-1);
|
||||||
|
((PlaceholderType)x.getLhsType()).disableWildcardtable();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ((x.getRhsType() instanceof PlaceholderType)) {
|
||||||
|
if (paraTypeVarNames.contains(x.getRhsType().getName())) {
|
||||||
|
((PlaceholderType)x.getRhsType()).setVariance((byte)1);
|
||||||
|
((PlaceholderType)x.getRhsType()).disableWildcardtable();
|
||||||
|
}
|
||||||
|
if (returnTypeVarNames.contains(x.getRhsType().getName())) {
|
||||||
|
((PlaceholderType)x.getRhsType()).setVariance((byte)-1);
|
||||||
|
((PlaceholderType)x.getRhsType()).disableWildcardtable();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return x;//HIER DIE JEWEILS RECHT BZW. LINKE SEITE AUF GLEICHE VARIANZ SETZEN WIE DIE JEWEILS ANDERE SEITE
|
||||||
|
});
|
||||||
|
Set<PlaceholderType> varianceTPHold;
|
||||||
|
Set<PlaceholderType> varianceTPH = new HashSet<>();
|
||||||
|
varianceTPH = varianceInheritanceConstraintSet(unifyCons);
|
||||||
|
|
||||||
|
/* PL 2018-11-07 wird in varianceInheritanceConstraintSet erledigt
|
||||||
|
do { //PL 2018-11-05 Huellenbildung Variance auf alle TPHs der Terme auf der jeweiligen
|
||||||
|
//anderen Seite übertragen
|
||||||
|
varianceTPHold = new HashSet<>(varianceTPH);
|
||||||
|
varianceTPH = varianceInheritanceConstraintSet(unifyCons);
|
||||||
|
unifyCons.map( y -> {
|
||||||
|
if ((y.getLhsType() instanceof PlaceholderType) && (y.getRhsType() instanceof PlaceholderType)) {
|
||||||
|
if (((PlaceholderType)y.getLhsType()).getVariance() != 0 && ((PlaceholderType)y.getRhsType()).getVariance() == 0) {
|
||||||
|
((PlaceholderType)y.getRhsType()).setVariance(((PlaceholderType)y.getLhsType()).getVariance());
|
||||||
|
}
|
||||||
|
if (((PlaceholderType)y.getLhsType()).getVariance() == 0 && ((PlaceholderType)y.getRhsType()).getVariance() != 0) {
|
||||||
|
((PlaceholderType)y.getLhsType()).setVariance(((PlaceholderType)y.getRhsType()).getVariance());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return y; } ); }
|
||||||
|
while (!varianceTPHold.equals(varianceTPH));
|
||||||
|
*/
|
||||||
|
|
||||||
|
//Set<Set<UnifyPair>> result = unify.unifySequential(xConsSet, finiteClosure, logFile, log);
|
||||||
|
//Set<Set<UnifyPair>> result = unify.unify(xConsSet, finiteClosure);
|
||||||
|
List<Set<Set<UnifyPair>>> oderConstraints = unifyCons.getOderConstraints().stream().map(x -> {
|
||||||
|
Set<Set<UnifyPair>> ret = new HashSet<>();
|
||||||
|
for (Constraint<UnifyPair> y : x) {
|
||||||
|
ret.add(new HashSet<>(y));
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}).collect(Collectors.toCollection(ArrayList::new));
|
||||||
|
unify.unifyAsync(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, cons, urm);
|
||||||
|
}
|
||||||
|
catch (IOException e) {
|
||||||
|
System.err.println("kein LogFile");
|
||||||
|
}
|
||||||
|
return urm;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public List<ResultSet> typeInference() throws ClassNotFoundException {
|
||||||
|
List<ClassOrInterface> allClasses = new ArrayList<>();//environment.getAllAvailableClasses();
|
||||||
|
//Alle Importierten Klassen in allen geparsten Sourcefiles kommen ins FC
|
||||||
|
for(SourceFile sf : this.sourceFiles.values()) {
|
||||||
|
allClasses.addAll(getAvailableClasses(sf));
|
||||||
|
allClasses.addAll(sf.getClasses());
|
||||||
|
}
|
||||||
|
|
||||||
|
final ConstraintSet<Pair> cons = getConstraints();
|
||||||
|
Set<Set<UnifyPair>> results = new HashSet<>();
|
||||||
|
try {
|
||||||
|
Writer logFile = new OutputStreamWriter(new NullOutputStream());
|
||||||
|
//new FileWriter(new File("log_"+sourceFiles.keySet().iterator().next().getName()));
|
||||||
|
|
||||||
|
IFiniteClosure finiteClosure = UnifyTypeFactory.generateFC(allClasses,logFile);
|
||||||
|
System.out.println(finiteClosure);
|
||||||
|
ConstraintSet<UnifyPair> unifyCons = UnifyTypeFactory.convert(cons);
|
||||||
|
|
||||||
|
Function<UnifyPair, UnifyPair> distributeInnerVars =
|
||||||
|
x -> {
|
||||||
|
UnifyType lhs, rhs;
|
||||||
|
if (((lhs = x.getLhsType()) instanceof PlaceholderType)
|
||||||
|
&& ((rhs = x.getRhsType()) instanceof PlaceholderType)
|
||||||
|
&& (((PlaceholderType)lhs).isInnerType()
|
||||||
|
|| ((PlaceholderType)rhs).isInnerType()))
|
||||||
|
{
|
||||||
|
((PlaceholderType)lhs).setInnerType(true);
|
||||||
|
((PlaceholderType)rhs).setInnerType(true);
|
||||||
|
}
|
||||||
|
return x;
|
||||||
|
|
||||||
|
};
|
||||||
|
logFile.write(unifyCons.toString());
|
||||||
|
unifyCons = unifyCons.map(distributeInnerVars);
|
||||||
|
logFile.write(unifyCons.toString());
|
||||||
|
TypeUnify unify = new TypeUnify();
|
||||||
|
//Set<Set<UnifyPair>> results = new HashSet<>(); Nach vorne gezogen
|
||||||
|
logFile.write("FC:\\" + finiteClosure.toString()+"\n");
|
||||||
|
for(SourceFile sf : this.sourceFiles.values()) {
|
||||||
|
logFile.write(ASTTypePrinter.print(sf));
|
||||||
|
}
|
||||||
|
logFile.flush();
|
||||||
|
|
||||||
|
Set<String> methodParaTypeVarNames = allClasses.stream().map(x -> x.getMethods().stream().map(y -> y.getParameterList().getFormalparalist()
|
||||||
|
.stream().filter(z -> z.getType() instanceof TypePlaceholder)
|
||||||
|
.map(z -> ((TypePlaceholder)z.getType()).getName()).collect(Collectors.toCollection(HashSet::new)))
|
||||||
|
.reduce(new HashSet<String>(), (a,b) -> { a.addAll(b); return a;}, (a,b) -> { a.addAll(b); return a;} ) )
|
||||||
|
.reduce(new HashSet<String>(), (a,b) -> { a.addAll(b); return a;} );
|
||||||
|
|
||||||
|
Set<String> constructorParaTypeVarNames = allClasses.stream().map(x -> x.getConstructors().stream().map(y -> y.getParameterList().getFormalparalist()
|
||||||
|
.stream().filter(z -> z.getType() instanceof TypePlaceholder)
|
||||||
|
.map(z -> ((TypePlaceholder)z.getType()).getName()).collect(Collectors.toCollection(HashSet::new)))
|
||||||
|
.reduce(new HashSet<String>(), (a,b) -> { a.addAll(b); return a;}, (a,b) -> { a.addAll(b); return a;} ) )
|
||||||
|
.reduce(new HashSet<String>(), (a,b) -> { a.addAll(b); return a;} );
|
||||||
|
|
||||||
|
Set<String> paraTypeVarNames = methodParaTypeVarNames;
|
||||||
|
paraTypeVarNames.addAll(constructorParaTypeVarNames);
|
||||||
|
|
||||||
|
|
||||||
|
Set<String> returnTypeVarNames = allClasses.stream().map(x -> x.getMethods().stream().filter(y -> y.getReturnType() instanceof TypePlaceholder)
|
||||||
|
.map(z -> ((TypePlaceholder)z.getReturnType()).getName()).collect(Collectors.toCollection(HashSet::new))).reduce((a,b) -> { a.addAll(b); return a;} ).get();
|
||||||
|
|
||||||
|
Set<String> fieldTypeVarNames = allClasses.stream().map(x -> x.getFieldDecl().stream().filter(y -> y.getReturnType() instanceof TypePlaceholder)
|
||||||
|
.map(z -> ((TypePlaceholder)z.getReturnType()).getName()).collect(Collectors.toCollection(HashSet::new))).reduce((a,b) -> { a.addAll(b); return a;} ).get();
|
||||||
|
|
||||||
|
returnTypeVarNames.addAll(fieldTypeVarNames);
|
||||||
|
|
||||||
|
unifyCons = unifyCons.map(x -> {
|
||||||
|
//Hier muss ueberlegt werden, ob
|
||||||
|
//1. alle Argument- und Retuntyp-Variablen in allen UnifyPairs
|
||||||
|
// mit disableWildcardtable() werden.
|
||||||
|
//2. alle Typvariablen mit Argument- oder Retuntyp-Variablen
|
||||||
|
//in Beziehung auch auf disableWildcardtable() gesetzt werden muessen
|
||||||
|
//PL 2018-04-23
|
||||||
|
if ((x.getLhsType() instanceof PlaceholderType)) {
|
||||||
|
if (paraTypeVarNames.contains(x.getLhsType().getName())) {
|
||||||
|
((PlaceholderType)x.getLhsType()).setVariance((byte)1);
|
||||||
|
((PlaceholderType)x.getLhsType()).disableWildcardtable();
|
||||||
|
}
|
||||||
|
if (returnTypeVarNames.contains(x.getLhsType().getName())) {
|
||||||
|
((PlaceholderType)x.getLhsType()).setVariance((byte)-1);
|
||||||
|
((PlaceholderType)x.getLhsType()).disableWildcardtable();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ((x.getRhsType() instanceof PlaceholderType)) {
|
||||||
|
if (paraTypeVarNames.contains(x.getRhsType().getName())) {
|
||||||
|
((PlaceholderType)x.getRhsType()).setVariance((byte)1);
|
||||||
|
((PlaceholderType)x.getRhsType()).disableWildcardtable();
|
||||||
|
}
|
||||||
|
if (returnTypeVarNames.contains(x.getRhsType().getName())) {
|
||||||
|
((PlaceholderType)x.getRhsType()).setVariance((byte)-1);
|
||||||
|
((PlaceholderType)x.getRhsType()).disableWildcardtable();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return x;//HIER DIE JEWEILS RECHT BZW. LINKE SEITE AUF GLEICHE VARIANZ SETZEN WIE DIE JEWEILS ANDERE SEITE
|
||||||
|
});
|
||||||
|
Set<PlaceholderType> varianceTPHold;
|
||||||
|
Set<PlaceholderType> varianceTPH = new HashSet<>();
|
||||||
|
varianceTPH = varianceInheritanceConstraintSet(unifyCons);
|
||||||
|
|
||||||
|
/* PL 2018-11-07 wird in varianceInheritanceConstraintSet erledigt
|
||||||
|
do { //PL 2018-11-05 Huellenbildung Variance auf alle TPHs der Terme auf der jeweiligen
|
||||||
|
//anderen Seite übertragen
|
||||||
|
varianceTPHold = new HashSet<>(varianceTPH);
|
||||||
|
varianceTPH = varianceInheritanceConstraintSet(unifyCons);
|
||||||
|
unifyCons.map( y -> {
|
||||||
|
if ((y.getLhsType() instanceof PlaceholderType) && (y.getRhsType() instanceof PlaceholderType)) {
|
||||||
|
if (((PlaceholderType)y.getLhsType()).getVariance() != 0 && ((PlaceholderType)y.getRhsType()).getVariance() == 0) {
|
||||||
|
((PlaceholderType)y.getRhsType()).setVariance(((PlaceholderType)y.getLhsType()).getVariance());
|
||||||
|
}
|
||||||
|
if (((PlaceholderType)y.getLhsType()).getVariance() == 0 && ((PlaceholderType)y.getRhsType()).getVariance() != 0) {
|
||||||
|
((PlaceholderType)y.getLhsType()).setVariance(((PlaceholderType)y.getRhsType()).getVariance());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return y; } ); }
|
||||||
|
while (!varianceTPHold.equals(varianceTPH));
|
||||||
|
*/
|
||||||
|
|
||||||
|
//Set<Set<UnifyPair>> result = unify.unifySequential(xConsSet, finiteClosure, logFile, log);
|
||||||
|
//Set<Set<UnifyPair>> result = unify.unify(xConsSet, finiteClosure);
|
||||||
|
List<Set<Set<UnifyPair>>> oderConstraints = unifyCons.getOderConstraints().stream().map(x -> {
|
||||||
|
Set<Set<UnifyPair>> ret = new HashSet<>();
|
||||||
|
for (Constraint<UnifyPair> y : x) {
|
||||||
|
ret.add(new HashSet<>(y));
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}).collect(Collectors.toCollection(ArrayList::new));
|
||||||
|
if (resultmodel) {
|
||||||
|
/* UnifyResultModel Anfang */
|
||||||
|
UnifyResultModel urm = new UnifyResultModel();
|
||||||
|
UnifyResultListenerImpl li = new UnifyResultListenerImpl();
|
||||||
|
urm.addUnifyResultListener(li);
|
||||||
|
unify.unifyParallel(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, cons, urm);
|
||||||
|
System.out.println("RESULT Final: " + li.getResults());
|
||||||
|
logFile.write("RES_FINAL: " + li.getResults().toString()+"\n");
|
||||||
|
logFile.flush();
|
||||||
|
return li.getResults();
|
||||||
|
}
|
||||||
|
/* UnifyResultModel End */
|
||||||
|
else {
|
||||||
|
Set<Set<UnifyPair>> result = unify.unify(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, cons);
|
||||||
|
//Set<Set<UnifyPair>> result = unify.unifyOderConstraints(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, cons);
|
||||||
|
System.out.println("RESULT: " + result);
|
||||||
|
logFile.write("RES: " + result.toString()+"\n");
|
||||||
|
logFile.flush();
|
||||||
|
results.addAll(result);
|
||||||
|
|
||||||
|
|
||||||
|
results = results.stream().map(x -> {
|
||||||
|
Optional<Set<UnifyPair>> res = new RuleSet().subst(x.stream().map(y -> {
|
||||||
|
if (y.getPairOp() == PairOperator.SMALLERDOTWC) y.setPairOp(PairOperator.EQUALSDOT);
|
||||||
|
return y; //alle Paare a <.? b erden durch a =. b ersetzt
|
||||||
|
}).collect(Collectors.toCollection(HashSet::new)));
|
||||||
|
if (res.isPresent()) {//wenn subst ein Erg liefert wurde was veraendert
|
||||||
|
return new TypeUnifyTask().applyTypeUnificationRules(res.get(), finiteClosure);
|
||||||
|
}
|
||||||
|
else return x; //wenn nichts veraendert wurde wird x zurueckgegeben
|
||||||
|
}).collect(Collectors.toCollection(HashSet::new));
|
||||||
|
System.out.println("RESULT Final: " + results);
|
||||||
|
logFile.write("RES_FINAL: " + results.toString()+"\n");
|
||||||
|
logFile.flush();
|
||||||
|
logFile.write("PLACEHOLDERS: " + PlaceholderType.EXISTING_PLACEHOLDERS);
|
||||||
|
logFile.flush();
|
||||||
|
}}
|
||||||
|
catch (IOException e) {
|
||||||
|
System.err.println("kein LogFile");
|
||||||
|
}
|
||||||
|
return results.stream().map((unifyPairs ->
|
||||||
|
new ResultSet(UnifyTypeFactory.convert(unifyPairs, Pair.generateTPHMap(cons))))).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Vererbt alle Variancen bei Paaren (a <. theta) oder (Theta <. a)
|
||||||
|
* wenn a eine Variance !=0 hat auf alle Typvariablen in Theta.
|
||||||
|
* @param eq The set of constraints
|
||||||
|
*/
|
||||||
|
private Set<PlaceholderType> varianceInheritanceConstraintSet(ConstraintSet<UnifyPair> cons) {
|
||||||
|
Set<UnifyPair> eq = cons.getAll();
|
||||||
|
Set<PlaceholderType> usedTPH = new HashSet<>();
|
||||||
|
Set<PlaceholderType> phSet = eq.stream().map(x -> {
|
||||||
|
Set<PlaceholderType> pair = new HashSet<>();
|
||||||
|
if (x.getLhsType() instanceof PlaceholderType) pair.add((PlaceholderType)x.getLhsType());
|
||||||
|
if (x.getRhsType() instanceof PlaceholderType) pair.add((PlaceholderType)x.getRhsType());
|
||||||
|
return pair;
|
||||||
|
}).reduce(new HashSet<>(), (a,b) -> { a.addAll(b); return a;} , (c,d) -> { c.addAll(d); return c;});
|
||||||
|
|
||||||
|
ArrayList<PlaceholderType> phSetVariance = new ArrayList<>(phSet);
|
||||||
|
phSetVariance.removeIf(x -> (x.getVariance() == 0));
|
||||||
|
while(!phSetVariance.isEmpty()) {
|
||||||
|
PlaceholderType a = phSetVariance.remove(0);
|
||||||
|
usedTPH.add(a);
|
||||||
|
//HashMap<PlaceholderType,Integer> ht = new HashMap<>();
|
||||||
|
//ht.put(a, a.getVariance());
|
||||||
|
//ConstraintSet<UnifyPair> eq1 = cons;
|
||||||
|
//eq1.removeIf(x -> !(x.getLhsType() instanceof PlaceholderType && ((PlaceholderType)x.getLhsType()).equals(a)));
|
||||||
|
//durch if-Abfrage im foreach geloest
|
||||||
|
cons.forEach(x -> {
|
||||||
|
if (x.getLhsType() instanceof PlaceholderType && ((PlaceholderType)x.getLhsType()).equals(a)) {
|
||||||
|
x.getRhsType().accept(new distributeVariance(), a.getVariance());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
//` eq1 = new HashSet<>(eq);
|
||||||
|
//eq1.removeIf(x -> !(x.getRhsType() instanceof PlaceholderType && ((PlaceholderType)x.getRhsType()).equals(a)));
|
||||||
|
//durch if-Abfrage im foreach geloest
|
||||||
|
cons.forEach(x -> {
|
||||||
|
if (x.getRhsType() instanceof PlaceholderType && ((PlaceholderType)x.getRhsType()).equals(a)) {
|
||||||
|
x.getLhsType().accept(new distributeVariance(), a.getVariance());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
phSetVariance = new ArrayList<>(phSet); //macht vermutlich keinen Sinn PL 2018-10-18, doch, es koennen neue TPHs mit Variancen dazugekommen sein PL 2018-11-07
|
||||||
|
phSetVariance.removeIf(x -> (x.getVariance() == 0 || usedTPH.contains(x)));
|
||||||
|
}
|
||||||
|
return usedTPH;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private SourceFile parse(File sourceFile) throws IOException, java.lang.ClassNotFoundException {
|
private SourceFile parse(File sourceFile) throws IOException, java.lang.ClassNotFoundException {
|
||||||
CompilationUnitContext tree = JavaTXParser.parse(sourceFile);
|
CompilationUnitContext tree = JavaTXParser.parse(sourceFile);
|
||||||
|
@ -80,6 +80,9 @@ public abstract class AbstractASTWalker implements ASTVisitor{
|
|||||||
for(Field f : classOrInterface.getFieldDecl()){
|
for(Field f : classOrInterface.getFieldDecl()){
|
||||||
f.accept(this);
|
f.accept(this);
|
||||||
}
|
}
|
||||||
|
for(Constructor c : classOrInterface.getConstructors()){
|
||||||
|
c.accept(this);
|
||||||
|
}
|
||||||
for(Method m : classOrInterface.getMethods()){
|
for(Method m : classOrInterface.getMethods()){
|
||||||
m.accept(this);
|
m.accept(this);
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package de.dhbwstuttgart.syntaxtree.factory;
|
package de.dhbwstuttgart.syntaxtree.factory;
|
||||||
|
|
||||||
|
import java.io.FileWriter;
|
||||||
|
import java.io.Writer;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
@ -29,7 +31,7 @@ public class UnifyTypeFactory {
|
|||||||
|
|
||||||
private static ArrayList<PlaceholderType> PLACEHOLDERS = new ArrayList<>();
|
private static ArrayList<PlaceholderType> PLACEHOLDERS = new ArrayList<>();
|
||||||
|
|
||||||
public static FiniteClosure generateFC(List<ClassOrInterface> fromClasses) throws ClassNotFoundException {
|
public static FiniteClosure generateFC(List<ClassOrInterface> fromClasses, Writer logFile) throws ClassNotFoundException {
|
||||||
/*
|
/*
|
||||||
Die transitive Hülle muss funktionieren.
|
Die transitive Hülle muss funktionieren.
|
||||||
Man darf schreiben List<A> extends AL<A>
|
Man darf schreiben List<A> extends AL<A>
|
||||||
@ -40,7 +42,7 @@ public class UnifyTypeFactory {
|
|||||||
Generell dürfen sie immer die gleichen Namen haben.
|
Generell dürfen sie immer die gleichen Namen haben.
|
||||||
TODO: die transitive Hülle bilden
|
TODO: die transitive Hülle bilden
|
||||||
*/
|
*/
|
||||||
return new FiniteClosure(FCGenerator.toUnifyFC(fromClasses));
|
return new FiniteClosure(FCGenerator.toUnifyFC(fromClasses), logFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static UnifyPair generateSmallerPair(UnifyType tl, UnifyType tr){
|
public static UnifyPair generateSmallerPair(UnifyType tl, UnifyType tr){
|
||||||
@ -63,26 +65,26 @@ public class UnifyTypeFactory {
|
|||||||
* Convert from
|
* Convert from
|
||||||
* ASTType -> UnifyType
|
* ASTType -> UnifyType
|
||||||
*/
|
*/
|
||||||
public static UnifyType convert(RefTypeOrTPHOrWildcardOrGeneric t){
|
public static UnifyType convert(RefTypeOrTPHOrWildcardOrGeneric t, Boolean innerType){
|
||||||
if(t instanceof GenericRefType){
|
if(t instanceof GenericRefType){
|
||||||
return UnifyTypeFactory.convert((GenericRefType)t);
|
return UnifyTypeFactory.convert((GenericRefType)t, innerType);
|
||||||
}else
|
}else
|
||||||
if(t instanceof FunN){
|
if(t instanceof FunN){
|
||||||
return UnifyTypeFactory.convert((FunN)t);
|
return UnifyTypeFactory.convert((FunN)t, innerType);
|
||||||
}else if(t instanceof TypePlaceholder){
|
}else if(t instanceof TypePlaceholder){
|
||||||
return UnifyTypeFactory.convert((TypePlaceholder)t);
|
return UnifyTypeFactory.convert((TypePlaceholder)t, innerType);
|
||||||
}else if(t instanceof ExtendsWildcardType){
|
}else if(t instanceof ExtendsWildcardType){
|
||||||
return UnifyTypeFactory.convert((ExtendsWildcardType)t);
|
return UnifyTypeFactory.convert((ExtendsWildcardType)t, innerType);
|
||||||
}else if(t instanceof SuperWildcardType){
|
}else if(t instanceof SuperWildcardType){
|
||||||
return UnifyTypeFactory.convert((SuperWildcardType)t);
|
return UnifyTypeFactory.convert((SuperWildcardType)t, innerType);
|
||||||
}else if(t instanceof RefType){
|
}else if(t instanceof RefType){
|
||||||
return UnifyTypeFactory.convert((RefType)t);
|
return UnifyTypeFactory.convert((RefType)t, innerType);
|
||||||
}
|
}
|
||||||
//Es wurde versucht ein Typ umzuwandeln, welcher noch nicht von der Factory abgedeckt ist
|
//Es wurde versucht ein Typ umzuwandeln, welcher noch nicht von der Factory abgedeckt ist
|
||||||
throw new NotImplementedException("Der Typ "+t+" kann nicht umgewandelt werden");
|
throw new NotImplementedException("Der Typ "+t+" kann nicht umgewandelt werden");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static UnifyType convert(RefType t){
|
public static UnifyType convert(RefType t, Boolean innerType){
|
||||||
//Check if it is a FunN Type:
|
//Check if it is a FunN Type:
|
||||||
Pattern p = Pattern.compile("Fun(\\d+)");
|
Pattern p = Pattern.compile("Fun(\\d+)");
|
||||||
Matcher m = p.matcher(t.getName().toString());
|
Matcher m = p.matcher(t.getName().toString());
|
||||||
@ -90,14 +92,14 @@ public class UnifyTypeFactory {
|
|||||||
if(b){
|
if(b){
|
||||||
Integer N = Integer.valueOf(m.group(1));
|
Integer N = Integer.valueOf(m.group(1));
|
||||||
if((N + 1) == t.getParaList().size()){
|
if((N + 1) == t.getParaList().size()){
|
||||||
return convert(new FunN(t.getParaList()));
|
return convert(new FunN(t.getParaList()), false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
UnifyType ret;
|
UnifyType ret;
|
||||||
if(t.getParaList() != null && t.getParaList().size() > 0){
|
if(t.getParaList() != null && t.getParaList().size() > 0){
|
||||||
List<UnifyType> params = new ArrayList<>();
|
List<UnifyType> params = new ArrayList<>();
|
||||||
for(RefTypeOrTPHOrWildcardOrGeneric pT : t.getParaList()){
|
for(RefTypeOrTPHOrWildcardOrGeneric pT : t.getParaList()){
|
||||||
params.add(UnifyTypeFactory.convert(pT));
|
params.add(UnifyTypeFactory.convert(pT, true));
|
||||||
}
|
}
|
||||||
ret = new ReferenceType(t.getName().toString(),new TypeParams(params));
|
ret = new ReferenceType(t.getName().toString(),new TypeParams(params));
|
||||||
}else{
|
}else{
|
||||||
@ -106,39 +108,45 @@ public class UnifyTypeFactory {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static UnifyType convert(FunN t){
|
public static UnifyType convert(FunN t, Boolean innerType){
|
||||||
UnifyType ret;
|
UnifyType ret;
|
||||||
List<UnifyType> params = new ArrayList<>();
|
List<UnifyType> params = new ArrayList<>();
|
||||||
if(t.getParaList() != null && t.getParaList().size() > 0){
|
if(t.getParaList() != null && t.getParaList().size() > 0){
|
||||||
for(RefTypeOrTPHOrWildcardOrGeneric pT : t.getParaList()){
|
for(RefTypeOrTPHOrWildcardOrGeneric pT : t.getParaList()){
|
||||||
params.add(UnifyTypeFactory.convert(pT));
|
params.add(UnifyTypeFactory.convert(pT, false));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ret = FunNType.getFunNType(new TypeParams(params));
|
ret = FunNType.getFunNType(new TypeParams(params));
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static UnifyType convert(TypePlaceholder tph){
|
public static UnifyType convert(TypePlaceholder tph, Boolean innerType){
|
||||||
|
if (tph.getName().equals("AFR")) {
|
||||||
|
System.out.println("XXX"+innerType);
|
||||||
|
}
|
||||||
PlaceholderType ntph = new PlaceholderType(tph.getName());
|
PlaceholderType ntph = new PlaceholderType(tph.getName());
|
||||||
int in = PLACEHOLDERS.indexOf(ntph);
|
int in = PLACEHOLDERS.indexOf(ntph);
|
||||||
if (in == -1) {
|
if (in == -1) {
|
||||||
PLACEHOLDERS.add(ntph);
|
PLACEHOLDERS.add(ntph);
|
||||||
|
ntph.setInnerType(innerType);
|
||||||
return ntph;
|
return ntph;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return PLACEHOLDERS.get(in);
|
PlaceholderType oldpht = PLACEHOLDERS.get(in);
|
||||||
|
oldpht.setInnerType(oldpht.isInnerType() || innerType);
|
||||||
|
return oldpht;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static UnifyType convert(GenericRefType t){
|
public static UnifyType convert(GenericRefType t, Boolean innerType){
|
||||||
return new ReferenceType(t.getParsedName());
|
return new ReferenceType(t.getParsedName());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static UnifyType convert(WildcardType t){
|
public static UnifyType convert(WildcardType t, Boolean innerType){
|
||||||
if(t.isExtends())
|
if(t.isExtends())
|
||||||
return new ExtendsType(UnifyTypeFactory.convert(t.getInnerType()));
|
return new ExtendsType(UnifyTypeFactory.convert(t.getInnerType(), false));
|
||||||
else if(t.isSuper())
|
else if(t.isSuper())
|
||||||
return new SuperType(UnifyTypeFactory.convert(t.getInnerType()));
|
return new SuperType(UnifyTypeFactory.convert(t.getInnerType(), false));
|
||||||
else throw new NotImplementedException();
|
else throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -152,22 +160,42 @@ public class UnifyTypeFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static UnifyPair convert(Pair p) {
|
public static UnifyPair convert(Pair p) {
|
||||||
|
UnifyPair ret = null;
|
||||||
if(p.GetOperator().equals(PairOperator.SMALLERDOT)) {
|
if(p.GetOperator().equals(PairOperator.SMALLERDOT)) {
|
||||||
UnifyPair ret = generateSmallerDotPair(UnifyTypeFactory.convert(p.TA1)
|
ret = generateSmallerDotPair(UnifyTypeFactory.convert(p.TA1, false)
|
||||||
, UnifyTypeFactory.convert(p.TA2));
|
, UnifyTypeFactory.convert(p.TA2, false));
|
||||||
return ret;
|
//return ret;
|
||||||
}else if(p.GetOperator().equals(PairOperator.SMALLERNEQDOT)) {
|
}else if(p.GetOperator().equals(PairOperator.SMALLERNEQDOT)) {
|
||||||
UnifyPair ret = generateSmallNotEqualDotPair(UnifyTypeFactory.convert(p.TA1)
|
ret = generateSmallNotEqualDotPair(UnifyTypeFactory.convert(p.TA1, false)
|
||||||
, UnifyTypeFactory.convert(p.TA2));
|
, UnifyTypeFactory.convert(p.TA2, false));
|
||||||
return ret;
|
//return ret;
|
||||||
}else if(p.GetOperator().equals(PairOperator.EQUALSDOT)) {
|
}else if(p.GetOperator().equals(PairOperator.EQUALSDOT)) {
|
||||||
UnifyPair ret = generateEqualDotPair(UnifyTypeFactory.convert(p.TA1)
|
ret = generateEqualDotPair(UnifyTypeFactory.convert(p.TA1, false)
|
||||||
, UnifyTypeFactory.convert(p.TA2));
|
, UnifyTypeFactory.convert(p.TA2, false));
|
||||||
return ret;
|
//return ret;
|
||||||
}else if(p.GetOperator().equals(PairOperator.SMALLER)){
|
}else if(p.GetOperator().equals(PairOperator.SMALLER)){
|
||||||
return generateSmallerPair(UnifyTypeFactory.convert(p.TA1),
|
ret = generateSmallerPair(UnifyTypeFactory.convert(p.TA1, false),
|
||||||
UnifyTypeFactory.convert(p.TA2));
|
UnifyTypeFactory.convert(p.TA2, false));
|
||||||
}else throw new NotImplementedException();
|
}else throw new NotImplementedException();
|
||||||
|
UnifyType lhs, rhs;
|
||||||
|
if (((lhs = ret.getLhsType()) instanceof PlaceholderType)
|
||||||
|
&& ((PlaceholderType)lhs).isWildcardable()
|
||||||
|
&& (rhs = ret.getLhsType()) instanceof PlaceholderType) {
|
||||||
|
if (lhs.getName().equals("AQ")) {
|
||||||
|
System.out.println("");
|
||||||
|
}
|
||||||
|
((PlaceholderType)rhs).enableWildcardtable();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (((rhs = ret.getLhsType()) instanceof PlaceholderType)
|
||||||
|
&& ((PlaceholderType)rhs).isWildcardable()
|
||||||
|
&& (lhs = ret.getLhsType()) instanceof PlaceholderType) {
|
||||||
|
if (rhs.getName().equals("AQ")) {
|
||||||
|
System.out.println("");
|
||||||
|
}
|
||||||
|
((PlaceholderType)lhs).enableWildcardtable();
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package de.dhbwstuttgart.typeinference.constraints;
|
package de.dhbwstuttgart.typeinference.constraints;
|
||||||
|
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||||
import de.dhbwstuttgart.typeinference.unify.GuavaSetOperations;
|
import de.dhbwstuttgart.typeinference.unify.GuavaSetOperations;
|
||||||
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
|
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
|
||||||
|
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
package de.dhbwstuttgart.typeinference.constraints;
|
package de.dhbwstuttgart.typeinference.constraints;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||||
import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
|
import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
|
||||||
|
|
||||||
|
|
||||||
@ -110,5 +113,20 @@ public class Pair implements Serializable
|
|||||||
public boolean OperatorSmallerDot() {
|
public boolean OperatorSmallerDot() {
|
||||||
return eOperator == PairOperator.SMALLERDOT;
|
return eOperator == PairOperator.SMALLERDOT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static public Map<String, TypePlaceholder> generateTPHMap(ConstraintSet<Pair> constraints) {
|
||||||
|
HashMap<String, TypePlaceholder> ret = new HashMap<>();
|
||||||
|
constraints.map((Pair p) -> {
|
||||||
|
if (p.TA1 instanceof TypePlaceholder) {
|
||||||
|
ret.put(((TypePlaceholder) p.TA1).getName(), (TypePlaceholder) p.TA1);
|
||||||
|
}
|
||||||
|
if (p.TA2 instanceof TypePlaceholder) {
|
||||||
|
ret.put(((TypePlaceholder) p.TA2).getName(), (TypePlaceholder) p.TA2);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// ino.end
|
// ino.end
|
||||||
|
@ -28,6 +28,7 @@ import de.dhbwstuttgart.typeinference.unify.distributeVariance;
|
|||||||
|
|
||||||
import java.io.FileWriter;
|
import java.io.FileWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.Writer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implementation of the type inference rules.
|
* Implementation of the type inference rules.
|
||||||
@ -36,13 +37,13 @@ import java.io.IOException;
|
|||||||
*/
|
*/
|
||||||
public class RuleSet implements IRuleSet{
|
public class RuleSet implements IRuleSet{
|
||||||
|
|
||||||
FileWriter logFile;
|
Writer logFile;
|
||||||
|
|
||||||
public RuleSet() {
|
public RuleSet() {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
RuleSet(FileWriter logFile) {
|
RuleSet(Writer logFile) {
|
||||||
this.logFile = logFile;
|
this.logFile = logFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -319,13 +320,21 @@ public class RuleSet implements IRuleSet{
|
|||||||
|
|
||||||
UnifyType lhsType = pair.getLhsType();
|
UnifyType lhsType = pair.getLhsType();
|
||||||
ReferenceType lhsSType;
|
ReferenceType lhsSType;
|
||||||
|
UnifyType rhsType = pair.getRhsType();
|
||||||
|
ReferenceType rhsSType;
|
||||||
|
|
||||||
if(lhsType instanceof ReferenceType)
|
if ((lhsType instanceof ReferenceType) && (rhsType instanceof ReferenceType)) {
|
||||||
lhsSType = (ReferenceType) lhsType;
|
lhsSType = (ReferenceType) lhsType;
|
||||||
else if(lhsType instanceof WildcardType) {
|
rhsSType = (ReferenceType) rhsType;
|
||||||
|
}
|
||||||
|
else if (((lhsType instanceof ExtendsType) && (rhsType instanceof ExtendsType))
|
||||||
|
|| ((lhsType instanceof SuperType) && (rhsType instanceof SuperType))) {
|
||||||
UnifyType lhsSTypeRaw = ((WildcardType) lhsType).getWildcardedType();
|
UnifyType lhsSTypeRaw = ((WildcardType) lhsType).getWildcardedType();
|
||||||
if(lhsSTypeRaw instanceof ReferenceType)
|
UnifyType rhsSTypeRaw = ((WildcardType) rhsType).getWildcardedType();
|
||||||
|
if ((lhsSTypeRaw instanceof ReferenceType) && (rhsSTypeRaw instanceof ReferenceType)) {
|
||||||
lhsSType = (ReferenceType) lhsSTypeRaw;
|
lhsSType = (ReferenceType) lhsSTypeRaw;
|
||||||
|
rhsSType = (ReferenceType) rhsSTypeRaw;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
@ -334,7 +343,8 @@ public class RuleSet implements IRuleSet{
|
|||||||
|
|
||||||
if(lhsSType.getTypeParams().empty())
|
if(lhsSType.getTypeParams().empty())
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
|
|
||||||
|
/* PL 2018-01-22 in obere Teil integriert
|
||||||
UnifyType rhsType = pair.getRhsType();
|
UnifyType rhsType = pair.getRhsType();
|
||||||
ReferenceType rhsSType;
|
ReferenceType rhsSType;
|
||||||
|
|
||||||
@ -349,6 +359,7 @@ public class RuleSet implements IRuleSet{
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
|
*/
|
||||||
|
|
||||||
if(!rhsSType.getName().equals(lhsSType.getName()))
|
if(!rhsSType.getName().equals(lhsSType.getName()))
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
|
@ -1,25 +1,54 @@
|
|||||||
package de.dhbwstuttgart.typeinference.unify;
|
package de.dhbwstuttgart.typeinference.unify;
|
||||||
|
|
||||||
import java.io.FileWriter;
|
import java.io.FileWriter;
|
||||||
|
import java.io.Writer;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.ForkJoinPool;
|
import java.util.concurrent.ForkJoinPool;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.typeinference.constraints.Constraint;
|
||||||
|
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||||
|
import de.dhbwstuttgart.typeinference.constraints.Pair;
|
||||||
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
|
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
|
||||||
|
import de.dhbwstuttgart.typeinference.unify.model.FiniteClosure;
|
||||||
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
|
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
|
||||||
|
|
||||||
public class TypeUnify {
|
public class TypeUnify {
|
||||||
public Set<Set<UnifyPair>> unify(Set<UnifyPair> eq, IFiniteClosure fc, FileWriter logFile, Boolean log) {
|
public Set<Set<UnifyPair>> unify(Set<UnifyPair> undConstrains, List<Set<Set<UnifyPair>>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, ConstraintSet<Pair> cons) {
|
||||||
TypeUnifyTask unifyTask = new TypeUnifyTask(eq, fc, true, logFile, log);
|
TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, true, logFile, log, 0, new UnifyResultModel(), cons);
|
||||||
ForkJoinPool pool = new ForkJoinPool();
|
ForkJoinPool pool = new ForkJoinPool();
|
||||||
pool.invoke(unifyTask);
|
pool.invoke(unifyTask);
|
||||||
Set<Set<UnifyPair>> res = unifyTask.join();
|
Set<Set<UnifyPair>> res = unifyTask.join();
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public UnifyResultModel unifyAsync(Set<UnifyPair> undConstrains, List<Set<Set<UnifyPair>>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, ConstraintSet<Pair> cons, UnifyResultModel ret) {
|
||||||
|
TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, true, logFile, log, 0, ret, cons);
|
||||||
|
ForkJoinPool pool = new ForkJoinPool();
|
||||||
|
pool.invoke(unifyTask);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
public UnifyResultModel unifyParallel(Set<UnifyPair> undConstrains, List<Set<Set<UnifyPair>>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, ConstraintSet<Pair> cons, UnifyResultModel ret) {
|
||||||
|
TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, true, logFile, log, 0, ret, cons);
|
||||||
|
ForkJoinPool pool = new ForkJoinPool();
|
||||||
|
pool.invoke(unifyTask);
|
||||||
|
Set<Set<UnifyPair>> res = unifyTask.join();
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
public Set<Set<UnifyPair>> unifySequential(Set<UnifyPair> eq, IFiniteClosure fc, FileWriter logFile, Boolean log) {
|
public Set<Set<UnifyPair>> unifySequential(Set<UnifyPair> eq, IFiniteClosure fc, FileWriter logFile, Boolean log) {
|
||||||
TypeUnifyTask unifyTask = new TypeUnifyTask(eq, fc, false, logFile, log);
|
TypeUnifyTask unifyTask = new TypeUnifyTask(eq, fc, false, logFile, log);
|
||||||
Set<Set<UnifyPair>> res = unifyTask.compute();
|
Set<Set<UnifyPair>> res = unifyTask.compute();
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
public Set<Set<UnifyPair>> unifyOderConstraints(Set<UnifyPair> undConstrains, List<Set<Set<UnifyPair>>> oderConstraints, IFiniteClosure fc, FileWriter logFile, Boolean log, ConstraintSet<Pair> cons) {
|
||||||
|
TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, false, logFile, log, 0, new UnifyResultModel(), cons);
|
||||||
|
Set<Set<UnifyPair>> res = unifyTask.compute();
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,38 @@
|
|||||||
|
package de.dhbwstuttgart.typeinference.unify;
|
||||||
|
|
||||||
|
import java.io.FileWriter;
|
||||||
|
import java.io.Writer;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.typeinference.constraints.Constraint;
|
||||||
|
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||||
|
import de.dhbwstuttgart.typeinference.constraints.Pair;
|
||||||
|
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
|
||||||
|
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
|
||||||
|
|
||||||
|
public class TypeUnify2Task extends TypeUnifyTask {
|
||||||
|
|
||||||
|
Set<Set<UnifyPair>> setToFlatten;
|
||||||
|
|
||||||
|
public TypeUnify2Task(Set<Set<UnifyPair>> setToFlatten, Set<UnifyPair> eq, List<Set<Set<UnifyPair>>> oderConstraints, IFiniteClosure fc, boolean parallel, Writer logFile, Boolean log, int rekTiefe, UnifyResultModel urm, ConstraintSet<Pair> cons) {
|
||||||
|
super(eq, oderConstraints, fc, parallel, logFile, log, rekTiefe, urm, cons);
|
||||||
|
this.setToFlatten = setToFlatten;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Set<Set<UnifyPair>> compute() {
|
||||||
|
if (one) {
|
||||||
|
System.out.println("two");
|
||||||
|
}
|
||||||
|
one = true;
|
||||||
|
Set<Set<UnifyPair>> res = unify2(setToFlatten, eq, oderConstraintsField, fc, parallel, rekTiefeField);
|
||||||
|
/*if (isUndefinedPairSetSet(res)) {
|
||||||
|
return new HashSet<>(); }
|
||||||
|
else
|
||||||
|
*/
|
||||||
|
noOfThread--;
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
}
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,18 @@
|
|||||||
|
package de.dhbwstuttgart.typeinference.unify;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||||
|
|
||||||
|
public class UnifyResultEvent {
|
||||||
|
|
||||||
|
private List<ResultSet> newTypeResult;
|
||||||
|
|
||||||
|
public UnifyResultEvent(List<ResultSet> newTypeResult) {
|
||||||
|
this.newTypeResult = newTypeResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ResultSet> getNewTypeResult() {
|
||||||
|
return newTypeResult;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,21 @@
|
|||||||
|
package de.dhbwstuttgart.typeinference.unify;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||||
|
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
|
||||||
|
|
||||||
|
public class UnifyResultListenerImpl implements UnifyResultListener {
|
||||||
|
|
||||||
|
List<ResultSet> results = new ArrayList<>();
|
||||||
|
|
||||||
|
public synchronized void onNewTypeResultFound(UnifyResultEvent evt) {
|
||||||
|
results.addAll(evt.getNewTypeResult());
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ResultSet> getResults() {
|
||||||
|
return results;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,28 @@
|
|||||||
|
package de.dhbwstuttgart.typeinference.unify;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||||
|
|
||||||
|
public class UnifyResultModel {
|
||||||
|
|
||||||
|
private List<UnifyResultListener> listeners = new ArrayList<>();
|
||||||
|
|
||||||
|
public void addUnifyResultListener(UnifyResultListener listenerToAdd) {
|
||||||
|
listeners.add(listenerToAdd);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeUnifyResultListener(UnifyResultListener listenerToRemove) {
|
||||||
|
listeners.remove(listenerToRemove);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void notify(List<ResultSet> newResult) {
|
||||||
|
UnifyResultEvent evt = new UnifyResultEvent(newResult);
|
||||||
|
|
||||||
|
for (UnifyResultListener listener : listeners) {
|
||||||
|
listener.onNewTypeResultFound(evt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,8 @@
|
|||||||
package de.dhbwstuttgart.typeinference.unify.model;
|
package de.dhbwstuttgart.typeinference.unify.model;
|
||||||
|
|
||||||
|
import java.io.FileWriter;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.Writer;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -30,6 +33,11 @@ import de.dhbwstuttgart.typeinference.unify.interfaces.IUnify;
|
|||||||
public class FiniteClosure //extends Ordering<UnifyType> //entfernt PL 2018-12-11
|
public class FiniteClosure //extends Ordering<UnifyType> //entfernt PL 2018-12-11
|
||||||
implements IFiniteClosure {
|
implements IFiniteClosure {
|
||||||
|
|
||||||
|
Writer logFile;
|
||||||
|
static Boolean log = false;
|
||||||
|
public void setLogTrue() {
|
||||||
|
log = true;
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* A map that maps every type to the node in the inheritance graph that contains that type.
|
* A map that maps every type to the node in the inheritance graph that contains that type.
|
||||||
*/
|
*/
|
||||||
@ -46,10 +54,21 @@ implements IFiniteClosure {
|
|||||||
*/
|
*/
|
||||||
private Set<UnifyPair> pairs;
|
private Set<UnifyPair> pairs;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hastable fuer die greater-Werte, damit sie nicht doppelt berechnet werden muessen
|
||||||
|
*/
|
||||||
|
Hashtable<hashKeyType, Set<UnifyType>> greaterHash = new Hashtable<>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hastable fuer die smaller-Werte, damit sie nicht doppelt berechnet werden muessen
|
||||||
|
*/
|
||||||
|
Hashtable<hashKeyType, Set<UnifyType>> smallerHash = new Hashtable<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new instance using the inheritance tree defined in the pairs.
|
* Creates a new instance using the inheritance tree defined in the pairs.
|
||||||
*/
|
*/
|
||||||
public FiniteClosure(Set<UnifyPair> pairs) {
|
public FiniteClosure(Set<UnifyPair> pairs, Writer logFile) {
|
||||||
|
this.logFile = logFile;
|
||||||
this.pairs = new HashSet<>(pairs);
|
this.pairs = new HashSet<>(pairs);
|
||||||
inheritanceGraph = new HashMap<UnifyType, Node<UnifyType>>();
|
inheritanceGraph = new HashMap<UnifyType, Node<UnifyType>>();
|
||||||
|
|
||||||
@ -91,6 +110,18 @@ implements IFiniteClosure {
|
|||||||
strInheritanceGraph.get(key.getName()).add(inheritanceGraph.get(key));
|
strInheritanceGraph.get(key.getName()).add(inheritanceGraph.get(key));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void testSmaller() {
|
||||||
|
UnifyType tq1, tq2, tq3;
|
||||||
|
tq1 = new ExtendsType(PlaceholderType.freshPlaceholder());
|
||||||
|
List<UnifyType> l1 = new ArrayList<>();
|
||||||
|
List<UnifyType> l2 = new ArrayList<>();
|
||||||
|
l1.add(tq1);
|
||||||
|
tq2 = new ReferenceType("java.util.Vector", new TypeParams(l1));
|
||||||
|
l2.add(tq2);
|
||||||
|
tq3 = new ReferenceType("java.util.Vector", new TypeParams(l2));
|
||||||
|
Set<UnifyType> smaller = smaller(tq3, new HashSet<>());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns all types of the finite closure that are subtypes of the argument.
|
* Returns all types of the finite closure that are subtypes of the argument.
|
||||||
@ -98,12 +129,29 @@ implements IFiniteClosure {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Set<UnifyType> smaller(UnifyType type, Set<UnifyType> fBounded) {
|
public Set<UnifyType> smaller(UnifyType type, Set<UnifyType> fBounded) {
|
||||||
|
|
||||||
|
Set<UnifyType> ret;
|
||||||
|
if ((ret = smallerHash.get(new hashKeyType(type))) != null) {
|
||||||
|
//System.out.println(greaterHash);
|
||||||
|
return new HashSet<>(ret);
|
||||||
|
}
|
||||||
|
|
||||||
if(type instanceof FunNType)
|
if(type instanceof FunNType)
|
||||||
return computeSmallerFunN((FunNType) type, fBounded);
|
return computeSmallerFunN((FunNType) type, fBounded);
|
||||||
|
|
||||||
Set<Pair<UnifyType,Set<UnifyType>>> ts = new HashSet<>();
|
Set<Pair<UnifyType,Set<UnifyType>>> ts = new HashSet<>();
|
||||||
ts.add(new Pair<>(type, fBounded));
|
ts.add(new Pair<>(type, fBounded));
|
||||||
return computeSmaller(ts);
|
Set<UnifyType> result = computeSmaller(ts);
|
||||||
|
smallerHash.put(new hashKeyType(type), result);
|
||||||
|
/*
|
||||||
|
try {
|
||||||
|
logFile.write("\ntype: " + type + "\nret: " + ret + "\nresult: " + result);//"smallerHash: " + greaterHash.toString());
|
||||||
|
logFile.flush();
|
||||||
|
}
|
||||||
|
catch (IOException e) {
|
||||||
|
System.err.println("no LogFile");
|
||||||
|
}*/
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -197,6 +245,13 @@ implements IFiniteClosure {
|
|||||||
//Eingefuegt PL 2018-05-24 F-Bounded Problematik
|
//Eingefuegt PL 2018-05-24 F-Bounded Problematik
|
||||||
public Set<UnifyType> greater(UnifyType type, Set<UnifyType> fBounded) {
|
public Set<UnifyType> greater(UnifyType type, Set<UnifyType> fBounded) {
|
||||||
|
|
||||||
|
Set<UnifyType> ret;
|
||||||
|
if ((ret = greaterHash.get(new hashKeyType(type))) != null) {
|
||||||
|
//System.out.println(greaterHash);
|
||||||
|
return new HashSet<>(ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if(type instanceof FunNType) {
|
if(type instanceof FunNType) {
|
||||||
return computeGreaterFunN((FunNType) type, fBounded);
|
return computeGreaterFunN((FunNType) type, fBounded);
|
||||||
}
|
}
|
||||||
@ -214,6 +269,17 @@ implements IFiniteClosure {
|
|||||||
|
|
||||||
// if T <* T' then sigma(T) <* sigma(T')
|
// if T <* T' then sigma(T) <* sigma(T')
|
||||||
Set<Node<UnifyType>> candidates = strInheritanceGraph.get(type.getName());
|
Set<Node<UnifyType>> candidates = strInheritanceGraph.get(type.getName());
|
||||||
|
|
||||||
|
/*
|
||||||
|
try {
|
||||||
|
if (log) logFile.write(candidates.toString());
|
||||||
|
//log = false;
|
||||||
|
}
|
||||||
|
catch (IOException e) {
|
||||||
|
System.err.println("no LogFile");
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
for(Node<UnifyType> candidate : candidates) {
|
for(Node<UnifyType> candidate : candidates) {
|
||||||
UnifyType theta1 = candidate.getContent();
|
UnifyType theta1 = candidate.getContent();
|
||||||
|
|
||||||
@ -222,9 +288,9 @@ implements IFiniteClosure {
|
|||||||
termList.add(new UnifyPair(theta1,type, PairOperator.EQUALSDOT));
|
termList.add(new UnifyPair(theta1,type, PairOperator.EQUALSDOT));
|
||||||
Optional<Unifier> optSigma = match.match(termList);
|
Optional<Unifier> optSigma = match.match(termList);
|
||||||
//PL 18-04-05 Unifier durch Matcher ersetzt ENDE
|
//PL 18-04-05 Unifier durch Matcher ersetzt ENDE
|
||||||
if(!optSigma.isPresent())
|
if(!optSigma.isPresent()) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
Unifier sigma = optSigma.get();
|
Unifier sigma = optSigma.get();
|
||||||
sigma.swapPlaceholderSubstitutionsReverse(theta1.getTypeParams());
|
sigma.swapPlaceholderSubstitutionsReverse(theta1.getTypeParams());
|
||||||
|
|
||||||
@ -237,7 +303,15 @@ implements IFiniteClosure {
|
|||||||
PairResultFBounded.add(new Pair<>(theta2.apply(sigma), fBoundedNew));
|
PairResultFBounded.add(new Pair<>(theta2.apply(sigma), fBoundedNew));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
|
try {
|
||||||
|
if (log) logFile.write(PairResultFBounded.toString());
|
||||||
|
log = false;
|
||||||
|
}
|
||||||
|
catch (IOException e) {
|
||||||
|
System.err.println("no LogFile");
|
||||||
|
}
|
||||||
|
*/
|
||||||
for(Pair<UnifyType,Set<UnifyType>> pt : PairResultFBounded) {
|
for(Pair<UnifyType,Set<UnifyType>> pt : PairResultFBounded) {
|
||||||
UnifyType t = pt.getKey();
|
UnifyType t = pt.getKey();
|
||||||
Set<UnifyType> lfBounded = pt.getValue().get();
|
Set<UnifyType> lfBounded = pt.getValue().get();
|
||||||
@ -273,6 +347,16 @@ implements IFiniteClosure {
|
|||||||
//System.out.println("");
|
//System.out.println("");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
greaterHash.put(new hashKeyType(type), result);
|
||||||
|
/*
|
||||||
|
try {
|
||||||
|
logFile.write("\ntype: " + type + "\nret: " + ret + "\nresult: " + result);//"greaterHash: " + greaterHash.toString());
|
||||||
|
logFile.flush();
|
||||||
|
}
|
||||||
|
catch (IOException e) {
|
||||||
|
System.err.println("no LogFile");
|
||||||
|
}*/
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -487,7 +571,7 @@ implements IFiniteClosure {
|
|||||||
result.add(type);
|
result.add(type);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<UnifyType> getAllTypesByName(String typeName) {
|
public Set<UnifyType> getAllTypesByName(String typeName) {
|
||||||
if(!strInheritanceGraph.containsKey(typeName))
|
if(!strInheritanceGraph.containsKey(typeName))
|
||||||
@ -570,8 +654,7 @@ implements IFiniteClosure {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
public int compare (UnifyType left, UnifyType right, PairOperator pairop) {
|
public int compare (UnifyType left, UnifyType right, PairOperator pairop) {
|
||||||
if ((left instanceof ExtendsType && right instanceof ReferenceType)
|
if (left.getName().equals("Matrix") || right.getName().equals("Matrix"))
|
||||||
|| (right instanceof ExtendsType && left instanceof ReferenceType))
|
|
||||||
System.out.println("");
|
System.out.println("");
|
||||||
/*
|
/*
|
||||||
List<UnifyType> al = new ArrayList<>();
|
List<UnifyType> al = new ArrayList<>();
|
||||||
@ -607,14 +690,28 @@ implements IFiniteClosure {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ((right instanceof PlaceholderType) && (left instanceof WildcardType)) {
|
if (right instanceof PlaceholderType) {//&& (left instanceof WildcardType)) {PL geloescht 2019-01-15 analog zu oben
|
||||||
return 0;
|
if ((left instanceof WildcardType) //PL eingefuegt 2019-01-15 analog zu oben
|
||||||
|
&& ((ex = ((WildcardType)left).wildcardedType) instanceof PlaceholderType)
|
||||||
|
&& ((PlaceholderType)right).getName().equals(((PlaceholderType)ex).getName())) {// ? extends a <. a oder ? super a <. a
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
UnifyPair up = new UnifyPair(left, right, pairop);
|
UnifyPair up = new UnifyPair(left, right, pairop);
|
||||||
TypeUnifyTask unifyTask = new TypeUnifyTask();
|
TypeUnifyTask unifyTask = new TypeUnifyTask();
|
||||||
HashSet<UnifyPair> hs = new HashSet<>();
|
HashSet<UnifyPair> hs = new HashSet<>();
|
||||||
hs.add(up);
|
hs.add(up);
|
||||||
Set<UnifyPair> smallerRes = unifyTask.applyTypeUnificationRules(hs, this);
|
Set<UnifyPair> smallerRes = unifyTask.applyTypeUnificationRules(hs, this);
|
||||||
|
if (left.getName().equals("Matrix") || right.getName().equals("Matrix"))
|
||||||
|
{try {
|
||||||
|
logFile.write("\nsmallerRes: " + smallerRes);//"smallerHash: " + greaterHash.toString());
|
||||||
|
logFile.flush();
|
||||||
|
}
|
||||||
|
catch (IOException e) {
|
||||||
|
System.err.println("no LogFile");}}
|
||||||
//Gleichungen der Form a <./=. Theta oder Theta <./=. a oder a <./=. b sind ok.
|
//Gleichungen der Form a <./=. Theta oder Theta <./=. a oder a <./=. b sind ok.
|
||||||
long smallerLen = smallerRes.stream().filter(x -> !(x.getLhsType() instanceof PlaceholderType || x.getRhsType() instanceof PlaceholderType)).count();
|
long smallerLen = smallerRes.stream().filter(x -> !(x.getLhsType() instanceof PlaceholderType || x.getRhsType() instanceof PlaceholderType)).count();
|
||||||
if (smallerLen == 0) return -1;
|
if (smallerLen == 0) return -1;
|
||||||
@ -624,6 +721,13 @@ implements IFiniteClosure {
|
|||||||
hs = new HashSet<>();
|
hs = new HashSet<>();
|
||||||
hs.add(up);
|
hs.add(up);
|
||||||
Set<UnifyPair> greaterRes = unifyTask.applyTypeUnificationRules(hs, this);
|
Set<UnifyPair> greaterRes = unifyTask.applyTypeUnificationRules(hs, this);
|
||||||
|
if (left.getName().equals("Matrix") || right.getName().equals("Matrix"))
|
||||||
|
{try {
|
||||||
|
logFile.write("\ngreaterRes: " + greaterRes);//"smallerHash: " + greaterHash.toString());
|
||||||
|
logFile.flush();
|
||||||
|
}
|
||||||
|
catch (IOException e) {
|
||||||
|
System.err.println("no LogFile");}}
|
||||||
//Gleichungen der Form a <./=. Theta oder Theta <./=. a oder a <./=. b sind ok.
|
//Gleichungen der Form a <./=. Theta oder Theta <./=. a oder a <./=. b sind ok.
|
||||||
long greaterLen = greaterRes.stream().filter(x -> !(x.getLhsType() instanceof PlaceholderType || x.getRhsType() instanceof PlaceholderType)).count();
|
long greaterLen = greaterRes.stream().filter(x -> !(x.getLhsType() instanceof PlaceholderType || x.getRhsType() instanceof PlaceholderType)).count();
|
||||||
if (greaterLen == 0) return 1;
|
if (greaterLen == 0) return 1;
|
||||||
|
@ -183,7 +183,7 @@ public class OrderingUnifyPair extends Ordering<Set<UnifyPair>> {
|
|||||||
if (leftlewc.iterator().next().getLhsType() instanceof PlaceholderType) {
|
if (leftlewc.iterator().next().getLhsType() instanceof PlaceholderType) {
|
||||||
hm = rsleuni.stream().reduce(new HashMap<UnifyType,UnifyPair>(), (x, y)-> { x.put(y.getLhsType(),y); return x; }, combiner);
|
hm = rsleuni.stream().reduce(new HashMap<UnifyType,UnifyPair>(), (x, y)-> { x.put(y.getLhsType(),y); return x; }, combiner);
|
||||||
Stream<UnifyPair> lslewcstr = lsleuni.stream().filter(x -> !(hm.get(x.getLhsType()) == null));
|
Stream<UnifyPair> lslewcstr = lsleuni.stream().filter(x -> !(hm.get(x.getLhsType()) == null));
|
||||||
si = lslewcstr.map(x -> fc.compare(x.getRhsType(), hm.get(x.getLhsType()).getRhsType(), PairOperator.SMALLERDOTWC)).reduce((x,y)-> { if (x == y) return x; else return 0; } );
|
si = lslewcstr.map(x -> fc.compare(x.getRhsType(), hm.get(x.getLhsType()).getRhsType(), PairOperator.SMALLERDOTWC)).reduce((x,y)-> { if (x == y) return x; else return 0; } );
|
||||||
}
|
}
|
||||||
//4. Fall
|
//4. Fall
|
||||||
else {
|
else {
|
||||||
|
@ -32,11 +32,11 @@ public class FieldTphConsMethTest {
|
|||||||
pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/";
|
pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/";
|
||||||
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||||
classToTest = loader.loadClass("FieldTphConsMeth");
|
classToTest = loader.loadClass("FieldTphConsMeth");
|
||||||
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test() throws Exception {
|
public void test() throws Exception {
|
||||||
|
instanceOfClass = classToTest.getConstructor(Object.class).newInstance("C");
|
||||||
Field a = classToTest.getDeclaredField("a");
|
Field a = classToTest.getDeclaredField("a");
|
||||||
a.setAccessible(true);
|
a.setAccessible(true);
|
||||||
|
|
||||||
@ -44,6 +44,7 @@ public class FieldTphConsMethTest {
|
|||||||
Object result = m.invoke(instanceOfClass, 42);
|
Object result = m.invoke(instanceOfClass, 42);
|
||||||
|
|
||||||
assertEquals(42,result);
|
assertEquals(42,result);
|
||||||
|
assertEquals("C", a.get(instanceOfClass));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
66
src/test/java/bytecode/FieldTphMMethTest.java
Normal file
66
src/test/java/bytecode/FieldTphMMethTest.java
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
package bytecode;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLClassLoader;
|
||||||
|
|
||||||
|
import org.junit.BeforeClass;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||||
|
|
||||||
|
public class FieldTphMMethTest {
|
||||||
|
|
||||||
|
private static String path;
|
||||||
|
private static File fileToTest;
|
||||||
|
private static JavaTXCompiler compiler;
|
||||||
|
private static ClassLoader loader;
|
||||||
|
private static Class<?> classToTest;
|
||||||
|
private static String pathToClassFile;
|
||||||
|
private static Object instanceOfClass;
|
||||||
|
private static Object instanceOfClass2;
|
||||||
|
|
||||||
|
@BeforeClass
|
||||||
|
public static void setUpBeforeClass() throws Exception {
|
||||||
|
path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/FieldTphMMeth.jav";
|
||||||
|
fileToTest = new File(path);
|
||||||
|
compiler = new JavaTXCompiler(fileToTest);
|
||||||
|
compiler.generateBytecode(System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/");
|
||||||
|
pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/";
|
||||||
|
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||||
|
classToTest = loader.loadClass("FieldTphMMeth");
|
||||||
|
instanceOfClass = classToTest.getConstructor(Object.class,Object.class,Boolean.class).newInstance("C",42,true);
|
||||||
|
instanceOfClass2 = classToTest.getConstructor(Object.class,Object.class,Boolean.class).newInstance("C",42,false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testM() throws Exception {
|
||||||
|
|
||||||
|
Method m = classToTest.getDeclaredMethod("m", Object.class,Object.class,Boolean.class);
|
||||||
|
Object result = m.invoke(instanceOfClass, "C",42,false);
|
||||||
|
|
||||||
|
assertEquals(42,result);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testWithTrue() throws Exception {
|
||||||
|
Field a = classToTest.getDeclaredField("a");
|
||||||
|
a.setAccessible(true);
|
||||||
|
|
||||||
|
assertEquals("C", a.get(instanceOfClass));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testWithFalse() throws Exception {
|
||||||
|
Field a = classToTest.getDeclaredField("a");
|
||||||
|
a.setAccessible(true);
|
||||||
|
|
||||||
|
assertEquals(42, a.get(instanceOfClass2));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -3,7 +3,7 @@ package bytecode;
|
|||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Method;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLClassLoader;
|
import java.net.URLClassLoader;
|
||||||
|
|
||||||
@ -12,8 +12,8 @@ import org.junit.Test;
|
|||||||
|
|
||||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||||
|
|
||||||
public class FieldTph {
|
public class InfTest {
|
||||||
|
|
||||||
private static String path;
|
private static String path;
|
||||||
private static File fileToTest;
|
private static File fileToTest;
|
||||||
private static JavaTXCompiler compiler;
|
private static JavaTXCompiler compiler;
|
||||||
@ -22,22 +22,16 @@ public class FieldTph {
|
|||||||
private static String pathToClassFile;
|
private static String pathToClassFile;
|
||||||
private static Object instanceOfClass;
|
private static Object instanceOfClass;
|
||||||
|
|
||||||
@BeforeClass
|
@Test
|
||||||
public static void setUpBeforeClass() throws Exception {
|
public void generateBC() throws Exception {
|
||||||
path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/FieldTph.jav";
|
path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/Inf.jav";
|
||||||
fileToTest = new File(path);
|
fileToTest = new File(path);
|
||||||
compiler = new JavaTXCompiler(fileToTest);
|
compiler = new JavaTXCompiler(fileToTest);
|
||||||
compiler.generateBytecode(System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/");
|
|
||||||
pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/";
|
pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/";
|
||||||
|
compiler.generateBytecode(pathToClassFile);
|
||||||
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||||
classToTest = loader.loadClass("FieldTph");
|
classToTest = loader.loadClass("Inf");
|
||||||
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void test() {
|
|
||||||
Field[] fields = classToTest.getFields();
|
|
||||||
assertEquals(1, fields.length);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
37
src/test/java/bytecode/KompTphTest.java
Normal file
37
src/test/java/bytecode/KompTphTest.java
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
package bytecode;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLClassLoader;
|
||||||
|
|
||||||
|
import org.junit.BeforeClass;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||||
|
|
||||||
|
public class KompTphTest {
|
||||||
|
|
||||||
|
private static String path;
|
||||||
|
private static File fileToTest;
|
||||||
|
private static JavaTXCompiler compiler;
|
||||||
|
private static ClassLoader loader;
|
||||||
|
private static Class<?> classToTest;
|
||||||
|
private static String pathToClassFile;
|
||||||
|
private static Object instanceOfClass;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void generateBC() throws Exception {
|
||||||
|
path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/KompTph.jav";
|
||||||
|
fileToTest = new File(path);
|
||||||
|
compiler = new JavaTXCompiler(fileToTest);
|
||||||
|
pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/";
|
||||||
|
compiler.generateBytecode(pathToClassFile);
|
||||||
|
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||||
|
classToTest = loader.loadClass("KompTph");
|
||||||
|
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -4,6 +4,7 @@ import static org.junit.Assert.*;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
@ -27,7 +28,7 @@ public class MatrixOpTest {
|
|||||||
private static Object instanceOfClass_m3;
|
private static Object instanceOfClass_m3;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, ClassNotFoundException, IOException, InstantiationException {
|
public void test() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, ClassNotFoundException, IOException, InstantiationException, NoSuchFieldException {
|
||||||
path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/MatrixOP.jav";
|
path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/MatrixOP.jav";
|
||||||
fileToTest = new File(path);
|
fileToTest = new File(path);
|
||||||
compiler = new JavaTXCompiler(fileToTest);
|
compiler = new JavaTXCompiler(fileToTest);
|
||||||
@ -35,7 +36,7 @@ public class MatrixOpTest {
|
|||||||
compiler.generateBytecode(pathToClassFile);
|
compiler.generateBytecode(pathToClassFile);
|
||||||
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||||
classToTest = loader.loadClass("MatrixOP");
|
classToTest = loader.loadClass("MatrixOP");
|
||||||
/*
|
|
||||||
Vector<Vector<Integer>> vv = new Vector<Vector<Integer>>();
|
Vector<Vector<Integer>> vv = new Vector<Vector<Integer>>();
|
||||||
Vector<Integer> v1 = new Vector<Integer> ();
|
Vector<Integer> v1 = new Vector<Integer> ();
|
||||||
v1.addElement(2);
|
v1.addElement(2);
|
||||||
@ -48,6 +49,7 @@ public class MatrixOpTest {
|
|||||||
//m1.addElement(v2);
|
//m1.addElement(v2);
|
||||||
vv.addElement(v1);
|
vv.addElement(v1);
|
||||||
vv.addElement(v2);
|
vv.addElement(v2);
|
||||||
|
|
||||||
instanceOfClass_m1 = classToTest.getDeclaredConstructor(Vector.class).newInstance(vv); //Matrix m1 = new Matrix(vv);
|
instanceOfClass_m1 = classToTest.getDeclaredConstructor(Vector.class).newInstance(vv); //Matrix m1 = new Matrix(vv);
|
||||||
|
|
||||||
Vector<Vector<Integer>> vv1 = new Vector<Vector<Integer>>();
|
Vector<Vector<Integer>> vv1 = new Vector<Vector<Integer>>();
|
||||||
@ -62,13 +64,23 @@ public class MatrixOpTest {
|
|||||||
//m2.addElement(v4);
|
//m2.addElement(v4);
|
||||||
vv1.addElement(v3);
|
vv1.addElement(v3);
|
||||||
vv1.addElement(v4);
|
vv1.addElement(v4);
|
||||||
|
|
||||||
instanceOfClass_m2 = classToTest.getDeclaredConstructor(Vector.class).newInstance(vv1);//Matrix m2 = new Matrix(vv1);
|
instanceOfClass_m2 = classToTest.getDeclaredConstructor(Vector.class).newInstance(vv1);//Matrix m2 = new Matrix(vv1);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//Matrix m3 = m1.mul(vv1);
|
//Matrix m3 = m1.mul(vv1);
|
||||||
Method mul = classToTest.getDeclaredMethod("mul", Vector.class);
|
// Method mul = classToTest.getDeclaredMethod("mul", Vector.class);
|
||||||
Object result = mul.invoke(instanceOfClass_m1, instanceOfClass_m2);
|
// Object result = mul.invoke(instanceOfClass_m1, instanceOfClass_m2);
|
||||||
|
Field mul = classToTest.getField("mul");
|
||||||
|
mul.setAccessible(true);
|
||||||
|
|
||||||
|
Class<?> lambda = mul.get(instanceOfClass_m1).getClass();
|
||||||
|
Method apply = lambda.getMethod("apply", Object.class,Object.class);
|
||||||
|
// Damit man auf die Methode zugreifen kann
|
||||||
|
apply.setAccessible(true);
|
||||||
|
|
||||||
|
Object result = apply.invoke(mul.get(instanceOfClass_m1),instanceOfClass_m1, instanceOfClass_m2);
|
||||||
System.out.println(instanceOfClass_m1.toString() + " * " + instanceOfClass_m2.toString() + " = " + result.toString());
|
System.out.println(instanceOfClass_m1.toString() + " * " + instanceOfClass_m2.toString() + " = " + result.toString());
|
||||||
|
|
||||||
Vector<Vector<Integer>> res = new Vector<Vector<Integer>>();
|
Vector<Vector<Integer>> res = new Vector<Vector<Integer>>();
|
||||||
@ -85,7 +97,7 @@ public class MatrixOpTest {
|
|||||||
res.addElement(v6);
|
res.addElement(v6);
|
||||||
instanceOfClass_m3 = classToTest.getDeclaredConstructor(Vector.class).newInstance(res);
|
instanceOfClass_m3 = classToTest.getDeclaredConstructor(Vector.class).newInstance(res);
|
||||||
assertEquals(result, instanceOfClass_m3);
|
assertEquals(result, instanceOfClass_m3);
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
64
src/test/java/bytecode/simplifyalgo/FinderTest.java
Normal file
64
src/test/java/bytecode/simplifyalgo/FinderTest.java
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
package bytecode.simplifyalgo;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.junit.BeforeClass;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.objectweb.asm.Type;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.bytecode.TPHExtractor;
|
||||||
|
import de.dhbwstuttgart.bytecode.constraint.ExtendsConstraint;
|
||||||
|
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint;
|
||||||
|
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation;
|
||||||
|
import de.dhbwstuttgart.bytecode.utilities.ConstraintsFinder;
|
||||||
|
import de.dhbwstuttgart.bytecode.utilities.MethodAndTPH;
|
||||||
|
import de.dhbwstuttgart.bytecode.utilities.Simplify;
|
||||||
|
import de.dhbwstuttgart.typedeployment.TypeInsertPlacer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Fayez Abu Alia
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class FinderTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testM1() {
|
||||||
|
List<TPHConstraint> allCons = new ArrayList<>();
|
||||||
|
// L < M
|
||||||
|
TPHConstraint c1 = new ExtendsConstraint("L", "M", Relation.EXTENDS);
|
||||||
|
// L < N
|
||||||
|
TPHConstraint c2 = new ExtendsConstraint("L", "N", Relation.EXTENDS);
|
||||||
|
// M < O
|
||||||
|
TPHConstraint c3 = new ExtendsConstraint("M", "O", Relation.EXTENDS);
|
||||||
|
// M < P
|
||||||
|
TPHConstraint c4 = new ExtendsConstraint("M", "P", Relation.EXTENDS);
|
||||||
|
|
||||||
|
allCons.add(c1);
|
||||||
|
allCons.add(c2);
|
||||||
|
allCons.add(c3);
|
||||||
|
allCons.add(c4);
|
||||||
|
List<List<TPHConstraint>> res = new ArrayList<>();
|
||||||
|
List<TPHConstraint> l1 = new ArrayList<>();
|
||||||
|
List<TPHConstraint> l2 = new ArrayList<>();
|
||||||
|
|
||||||
|
l1.add(c1);
|
||||||
|
l1.add(c2);
|
||||||
|
|
||||||
|
l2.add(c3);
|
||||||
|
l2.add(c4);
|
||||||
|
|
||||||
|
res.add(l1);
|
||||||
|
res.add(l2);
|
||||||
|
|
||||||
|
ConstraintsFinder finder = new ConstraintsFinder(allCons);
|
||||||
|
|
||||||
|
assertEquals(finder.findConstraints(), res);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
27
src/test/resources/bytecode/javFiles/FieldTphMMeth.jav
Normal file
27
src/test/resources/bytecode/javFiles/FieldTphMMeth.jav
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
import java.lang.Boolean;
|
||||||
|
|
||||||
|
public class FieldTphMMeth {
|
||||||
|
a;
|
||||||
|
|
||||||
|
public FieldTphMMeth(c,d,e) {
|
||||||
|
a = m(c,d,e);
|
||||||
|
}
|
||||||
|
|
||||||
|
m(b,d,e) {
|
||||||
|
if(e) {
|
||||||
|
return m3(b);
|
||||||
|
} else{
|
||||||
|
return m3(d);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
m2(b) {
|
||||||
|
a = m3(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
m3(b){
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
19
src/test/resources/bytecode/javFiles/Inf.jav
Normal file
19
src/test/resources/bytecode/javFiles/Inf.jav
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
public class Inf {
|
||||||
|
m(x,y,a){
|
||||||
|
var z;
|
||||||
|
var v;
|
||||||
|
var w;
|
||||||
|
var b;
|
||||||
|
y=x;
|
||||||
|
z=x;
|
||||||
|
v=y;
|
||||||
|
w=y;
|
||||||
|
y=a;
|
||||||
|
b=a;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// v w
|
||||||
|
// \ /
|
||||||
|
// z y b
|
||||||
|
// \ / \ /
|
||||||
|
// x a
|
13
src/test/resources/bytecode/javFiles/KompTph.jav
Normal file
13
src/test/resources/bytecode/javFiles/KompTph.jav
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
public class KompTph {
|
||||||
|
public m(a, b, c) {
|
||||||
|
var d = a;
|
||||||
|
var e = a;
|
||||||
|
a = b;
|
||||||
|
c = b;
|
||||||
|
m2(a,c);
|
||||||
|
}
|
||||||
|
|
||||||
|
public m2(a,b){
|
||||||
|
m(a,a,b);
|
||||||
|
}
|
||||||
|
}
|
@ -18,7 +18,7 @@ public class MatrixOP extends Vector<Vector<Integer>> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mul = (m1, m2) -> {
|
public mul = (m1, m2) -> {
|
||||||
var ret = new MatrixOP();
|
var ret = new MatrixOP();
|
||||||
var i = 0;
|
var i = 0;
|
||||||
while(i < size()) {
|
while(i < size()) {
|
||||||
|
Loading…
Reference in New Issue
Block a user