forked from JavaTX/JavaCompilerCore
Methode getSimplifyList definiert, die eine Liste von Ergebnisse des
Simplify-Alg zurueckliefert
This commit is contained in:
parent
c77a2b3354
commit
c921330b55
@ -29,6 +29,7 @@ import de.dhbwstuttgart.bytecode.utilities.MethodAndTPH;
|
|||||||
import de.dhbwstuttgart.bytecode.utilities.NormalConstructor;
|
import de.dhbwstuttgart.bytecode.utilities.NormalConstructor;
|
||||||
import de.dhbwstuttgart.bytecode.utilities.NormalMethod;
|
import de.dhbwstuttgart.bytecode.utilities.NormalMethod;
|
||||||
import de.dhbwstuttgart.bytecode.utilities.Simplify;
|
import de.dhbwstuttgart.bytecode.utilities.Simplify;
|
||||||
|
import de.dhbwstuttgart.bytecode.utilities.SimplifyResult;
|
||||||
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.AssignToLocal;
|
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.AssignToLocal;
|
||||||
import de.dhbwstuttgart.syntaxtree.*;
|
import de.dhbwstuttgart.syntaxtree.*;
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.Literal;
|
import de.dhbwstuttgart.syntaxtree.statement.Literal;
|
||||||
@ -81,6 +82,17 @@ public class BytecodeGen implements ASTVisitor {
|
|||||||
|
|
||||||
ArrayList<String> methodNameAndParamsT = new ArrayList<>();
|
ArrayList<String> methodNameAndParamsT = new ArrayList<>();
|
||||||
|
|
||||||
|
private HashMap<String, SimplifyResult> simplifyResults = new HashMap<>();
|
||||||
|
private List<HashMap<String, SimplifyResult>> simplifyResultsList = new ArrayList<>();
|
||||||
|
|
||||||
|
public List<HashMap<String, SimplifyResult>> getSimplifyResultsList() {
|
||||||
|
return simplifyResultsList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSimplifyResultsList(List<HashMap<String, SimplifyResult>> simplifyResultsList) {
|
||||||
|
this.simplifyResultsList = simplifyResultsList;
|
||||||
|
}
|
||||||
|
|
||||||
public BytecodeGen(HashMap<String,byte[]> classFiles, List<ResultSet> listOfResultSets,SourceFile sf ,String path) {
|
public BytecodeGen(HashMap<String,byte[]> classFiles, List<ResultSet> listOfResultSets,SourceFile sf ,String path) {
|
||||||
this.classFiles = classFiles;
|
this.classFiles = classFiles;
|
||||||
this.listOfResultSets = listOfResultSets;
|
this.listOfResultSets = listOfResultSets;
|
||||||
@ -94,6 +106,7 @@ public class BytecodeGen implements ASTVisitor {
|
|||||||
System.out.println("in Class: " + cl.getClassName().toString());
|
System.out.println("in Class: " + cl.getClassName().toString());
|
||||||
BytecodeGen classGen = new BytecodeGen(classFiles, listOfResultSets, sf, path);
|
BytecodeGen classGen = new BytecodeGen(classFiles, listOfResultSets, sf, path);
|
||||||
cl.accept(classGen);
|
cl.accept(classGen);
|
||||||
|
simplifyResultsList.add(classGen.getSimplifyResults());
|
||||||
classGen.writeClass(cl.getClassName().toString());
|
classGen.writeClass(cl.getClassName().toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -173,6 +186,10 @@ public class BytecodeGen implements ASTVisitor {
|
|||||||
right = null;
|
right = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SimplifyResult sRes = new SimplifyResult(consClass, tphsClass, new HashMap<>());
|
||||||
|
simplifyResults.put(className, sRes);
|
||||||
|
|
||||||
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);
|
||||||
@ -370,6 +387,8 @@ public class BytecodeGen implements ASTVisitor {
|
|||||||
// ArrayList<GenericInsertPair> pairs = simplifyPairs(method.name,tphExtractor.allPairs,tphExtractor.allCons);
|
// ArrayList<GenericInsertPair> pairs = simplifyPairs(method.name,tphExtractor.allPairs,tphExtractor.allCons);
|
||||||
Signature signature = new Signature(method, genericsAndBoundsMethod, genericsAndBounds,methodParamsAndTypes,resultSet,constraints);
|
Signature signature = new Signature(method, genericsAndBoundsMethod, genericsAndBounds,methodParamsAndTypes,resultSet,constraints);
|
||||||
sig = signature.toString();
|
sig = signature.toString();
|
||||||
|
|
||||||
|
simplifyResults.get(className).getMethodsConstraints().put(methParamTypes, constraints);
|
||||||
}
|
}
|
||||||
System.out.println(method.getName()+" ==> "+sig);
|
System.out.println(method.getName()+" ==> "+sig);
|
||||||
NormalMethod meth = new NormalMethod(method,genericsAndBounds,genericsAndBoundsMethod,hasGen);
|
NormalMethod meth = new NormalMethod(method,genericsAndBounds,genericsAndBoundsMethod,hasGen);
|
||||||
@ -386,6 +405,10 @@ public class BytecodeGen implements ASTVisitor {
|
|||||||
mv.visitEnd();
|
mv.visitEnd();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public HashMap<String, SimplifyResult> getSimplifyResults() {
|
||||||
|
return simplifyResults;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visit(ParameterList formalParameters) {
|
public void visit(ParameterList formalParameters) {
|
||||||
paramsAndLocals = new HashMap<>();
|
paramsAndLocals = new HashMap<>();
|
||||||
|
@ -456,10 +456,15 @@ public class Signature {
|
|||||||
String boundDesc = b.acceptTV(new TypeToDescriptor());
|
String boundDesc = b.acceptTV(new TypeToDescriptor());
|
||||||
// System.out.println("GetBounds: " + boundDesc);
|
// System.out.println("GetBounds: " + boundDesc);
|
||||||
// Ensure that <...> extends java.lang.Object OR ...
|
// Ensure that <...> extends java.lang.Object OR ...
|
||||||
|
if(b instanceof GenericRefType) {
|
||||||
|
sw.visitClassBound().visitTypeVariable(boundDesc);
|
||||||
|
} else {
|
||||||
sw.visitClassBound().visitClassType(boundDesc);
|
sw.visitClassBound().visitClassType(boundDesc);
|
||||||
|
sw.visitClassBound().visitEnd();
|
||||||
|
}
|
||||||
genAndBounds.put(g.getName(), boundDesc);
|
genAndBounds.put(g.getName(), boundDesc);
|
||||||
}
|
}
|
||||||
sw.visitClassBound().visitEnd();
|
// sw.visitClassBound().visitEnd();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
|
@ -0,0 +1,42 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package de.dhbwstuttgart.bytecode.utilities;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author fayez
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class SimplifyResult {
|
||||||
|
private final ArrayList<TPHConstraint> classConstraints;
|
||||||
|
private final ArrayList<TypePlaceholder> tphsClass;
|
||||||
|
private final HashMap<String, HashMap<TPHConstraint, HashSet<String>>> methodsConstraints;
|
||||||
|
|
||||||
|
public SimplifyResult(ArrayList<TPHConstraint> classConstraints, ArrayList<TypePlaceholder> tphsClass,
|
||||||
|
HashMap<String, HashMap<TPHConstraint, HashSet<String>>> methodsConstraints) {
|
||||||
|
super();
|
||||||
|
this.classConstraints = classConstraints;
|
||||||
|
this.tphsClass = tphsClass;
|
||||||
|
this.methodsConstraints = methodsConstraints;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<TPHConstraint> getClassConstraints() {
|
||||||
|
return classConstraints;
|
||||||
|
}
|
||||||
|
|
||||||
|
public HashMap<String, HashMap<TPHConstraint, HashSet<String>>> getMethodsConstraints() {
|
||||||
|
return methodsConstraints;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<TypePlaceholder> getTphsClass() {
|
||||||
|
return tphsClass;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -3,6 +3,7 @@ package de.dhbwstuttgart.core;
|
|||||||
|
|
||||||
|
|
||||||
import de.dhbwstuttgart.bytecode.BytecodeGen;
|
import de.dhbwstuttgart.bytecode.BytecodeGen;
|
||||||
|
import de.dhbwstuttgart.bytecode.utilities.SimplifyResult;
|
||||||
import de.dhbwstuttgart.environment.CompilationEnvironment;
|
import de.dhbwstuttgart.environment.CompilationEnvironment;
|
||||||
import de.dhbwstuttgart.parser.JavaTXParser;
|
import de.dhbwstuttgart.parser.JavaTXParser;
|
||||||
import de.dhbwstuttgart.parser.NullToken;
|
import de.dhbwstuttgart.parser.NullToken;
|
||||||
@ -58,6 +59,8 @@ public class JavaTXCompiler {
|
|||||||
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")+"src/test/java/logFiles" geschrieben werden soll?
|
Boolean log = true; //gibt an ob ein Log-File nach System.getProperty("user.dir")+"src/test/java/logFiles" geschrieben werden soll?
|
||||||
|
|
||||||
|
private List<List<HashMap<String, SimplifyResult>>> simplifyResultsSF = new ArrayList<>();
|
||||||
|
|
||||||
public JavaTXCompiler(File sourceFile) throws IOException, ClassNotFoundException {
|
public JavaTXCompiler(File sourceFile) throws IOException, ClassNotFoundException {
|
||||||
this(Arrays.asList(sourceFile));
|
this(Arrays.asList(sourceFile));
|
||||||
}
|
}
|
||||||
@ -649,6 +652,7 @@ public class JavaTXCompiler {
|
|||||||
BytecodeGen bytecodeGen = new BytecodeGen(classFiles,typeinferenceResult,sf,path);
|
BytecodeGen bytecodeGen = new BytecodeGen(classFiles,typeinferenceResult,sf,path);
|
||||||
// BytecodeGen bytecodeGen = new BytecodeGen(classFiles,typeinferenceResult.get(0));
|
// BytecodeGen bytecodeGen = new BytecodeGen(classFiles,typeinferenceResult.get(0));
|
||||||
bytecodeGen.visit(sf);
|
bytecodeGen.visit(sf);
|
||||||
|
this.simplifyResultsSF.add(bytecodeGen.getSimplifyResultsList());
|
||||||
this.writeClassFile(bytecodeGen.getClassFiles(), path);
|
this.writeClassFile(bytecodeGen.getClassFiles(), path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -665,4 +669,8 @@ public class JavaTXCompiler {
|
|||||||
System.out.println(name+".class file generated");
|
System.out.println(name+".class file generated");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<List<HashMap<String, SimplifyResult>>> getSimplifyResults() {
|
||||||
|
return simplifyResultsSF;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
38
src/test/java/bytecode/TypedIDTest.java
Normal file
38
src/test/java/bytecode/TypedIDTest.java
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
package bytecode;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLClassLoader;
|
||||||
|
|
||||||
|
import org.junit.BeforeClass;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||||
|
|
||||||
|
public class TypedIDTest {
|
||||||
|
|
||||||
|
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 test() throws Exception {
|
||||||
|
path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/TypedID.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("TypedID");
|
||||||
|
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
6
src/test/resources/bytecode/javFiles/TypedID.jav
Normal file
6
src/test/resources/bytecode/javFiles/TypedID.jav
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
public class TypedID<L extends K,K> {
|
||||||
|
|
||||||
|
id(L b){
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user