Merge branch 'bigRefactoring' into bytecode2
This commit is contained in:
commit
dccdc5da2b
@ -29,7 +29,7 @@ import java.util.stream.Collectors;
|
||||
|
||||
public class JavaTXCompiler {
|
||||
|
||||
final CompilationEnvironment environment;
|
||||
final CompilationEnvironment environment;
|
||||
public final Map<File, SourceFile> sourceFiles = new HashMap<>();
|
||||
|
||||
public JavaTXCompiler(File sourceFile) throws IOException, ClassNotFoundException {
|
||||
@ -38,56 +38,83 @@ public class JavaTXCompiler {
|
||||
|
||||
public JavaTXCompiler(List<File> sources) throws IOException, ClassNotFoundException {
|
||||
environment = new CompilationEnvironment(sources);
|
||||
for(File s : sources){
|
||||
sourceFiles.put(s,parse(s));
|
||||
for (File s : sources) {
|
||||
sourceFiles.put(s, parse(s));
|
||||
}
|
||||
}
|
||||
|
||||
public List<ResultSet> typeInference() throws ClassNotFoundException {
|
||||
public ConstraintSet<Pair> getConstraints() throws ClassNotFoundException {
|
||||
List<ClassOrInterface> allClasses = new ArrayList<>();//environment.getAllAvailableClasses();
|
||||
for(SourceFile sf : sourceFiles.values()){
|
||||
for (SourceFile sf : sourceFiles.values()) {
|
||||
allClasses.addAll(sf.getClasses());
|
||||
}
|
||||
List<ClassOrInterface> importedClasses = new ArrayList<>();
|
||||
//Alle Importierten Klassen in allen geparsten Sourcefiles kommen ins FC
|
||||
for(File forSourceFile : sourceFiles.keySet())
|
||||
for(JavaClassName name : sourceFiles.get(forSourceFile).getImports()){
|
||||
//TODO: Hier werden imports von eigenen (.jav) Klassen nicht beachtet
|
||||
for (File forSourceFile : sourceFiles.keySet())
|
||||
for (JavaClassName name : sourceFiles.get(forSourceFile).getImports()) {
|
||||
//TODO: Hier werden imports von eigenen (.jav) Klassen nicht beachtet
|
||||
ClassOrInterface importedClass = ASTFactory.createClass(
|
||||
ClassLoader.getSystemClassLoader().loadClass(name.toString()));
|
||||
importedClasses.add(importedClass);
|
||||
}
|
||||
allClasses.addAll(importedClasses);
|
||||
FiniteClosure finiteClosure = UnifyTypeFactory.generateFC(allClasses);
|
||||
|
||||
final ConstraintSet<Pair> cons = new TYPE(sourceFiles.values(), allClasses).getConstraints();
|
||||
return new TYPE(sourceFiles.values(), allClasses).getConstraints();
|
||||
}
|
||||
|
||||
public List<ClassOrInterface> getAvailableClasses(SourceFile forSourceFile) throws ClassNotFoundException {
|
||||
List<ClassOrInterface> allClasses = new ArrayList<>();//environment.getAllAvailableClasses();
|
||||
for (SourceFile sf : sourceFiles.values()) {
|
||||
allClasses.addAll(sf.getClasses());
|
||||
}
|
||||
List<ClassOrInterface> importedClasses = new ArrayList<>();
|
||||
for (JavaClassName name : forSourceFile.getImports()) {
|
||||
//TODO: Hier werden imports von eigenen (.jav) Klassen nicht beachtet
|
||||
ClassOrInterface importedClass = ASTFactory.createClass(
|
||||
ClassLoader.getSystemClassLoader().loadClass(name.toString()));
|
||||
importedClasses.add(importedClass);
|
||||
allClasses.addAll(importedClasses);
|
||||
}
|
||||
return allClasses;
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
final ConstraintSet<Pair> cons = getConstraints();
|
||||
|
||||
FiniteClosure finiteClosure = UnifyTypeFactory.generateFC(allClasses);
|
||||
ConstraintSet<UnifyPair> unifyCons = UnifyTypeFactory.convert(cons);
|
||||
|
||||
TypeUnify unify = new TypeUnify();
|
||||
Set<Set<UnifyPair>> results = new HashSet<>();
|
||||
for(List<Constraint<UnifyPair>> xCons : unifyCons.cartesianProduct()){
|
||||
for (List<Constraint<UnifyPair>> xCons : unifyCons.cartesianProduct()) {
|
||||
Set<UnifyPair> xConsSet = new HashSet<>();
|
||||
for(Constraint<UnifyPair> constraint : xCons){
|
||||
for (Constraint<UnifyPair> constraint : xCons) {
|
||||
xConsSet.addAll(constraint);
|
||||
}
|
||||
|
||||
System.out.println(xConsSet);
|
||||
Set<Set<UnifyPair>> result = unify.unify(xConsSet, finiteClosure);
|
||||
//System.out.println("RESULT: " + result);
|
||||
System.out.println("RESULT: " + result);
|
||||
results.addAll(result);
|
||||
}
|
||||
return results.stream().map((unifyPairs ->
|
||||
new ResultSet(UnifyTypeFactory.convert(unifyPairs, generateTPHMap(cons))))).collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
||||
private Map<String, TypePlaceholder> generateTPHMap(ConstraintSet<Pair> constraints){
|
||||
private 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);
|
||||
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);
|
||||
if (p.TA2 instanceof TypePlaceholder) {
|
||||
ret.put(((TypePlaceholder) p.TA2).getName(), (TypePlaceholder) p.TA2);
|
||||
}
|
||||
return null;
|
||||
});
|
||||
@ -97,8 +124,8 @@ public class JavaTXCompiler {
|
||||
private SourceFile parse(File sourceFile) throws IOException, java.lang.ClassNotFoundException {
|
||||
CompilationUnitContext tree = JavaTXParser.parse(sourceFile);
|
||||
SyntaxTreeGenerator generator = new SyntaxTreeGenerator(environment.getRegistry(sourceFile), new GenericsRegistry(null));
|
||||
SourceFile ret = generator.convert(tree, environment.packageCrawler);
|
||||
SourceFile ret = generator.convert(tree, environment.packageCrawler);
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -43,7 +43,7 @@ public class TypeGenerator {
|
||||
throw new NotImplementedException();
|
||||
}else
|
||||
if(unannTypeContext.unannReferenceType().unannArrayType()!=null){
|
||||
System.out.println(unannTypeContext.getText());
|
||||
//System.out.println(unannTypeContext.getText());
|
||||
throw new NotImplementedException();
|
||||
}else
|
||||
if(unannTypeContext.unannReferenceType().unannTypeVariable()!=null){
|
||||
|
@ -1,24 +1,115 @@
|
||||
package de.dhbwstuttgart.sat.asp;
|
||||
|
||||
import de.dhbwstuttgart.exceptions.DebugException;
|
||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
||||
import de.dhbwstuttgart.sat.asp.model.*;
|
||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||
import de.dhbwstuttgart.syntaxtree.GenericTypeVar;
|
||||
import de.dhbwstuttgart.syntaxtree.factory.UnifyTypeFactory;
|
||||
import de.dhbwstuttgart.syntaxtree.type.*;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Constraint;
|
||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Pair;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.UnifyType;
|
||||
|
||||
import java.sql.Ref;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public class ASPGenerator {
|
||||
public static String toASP(ConstraintSet constraintSet, Collection<ClassOrInterface> fcClasses){
|
||||
String ret = "";
|
||||
for(ClassOrInterface cl : fcClasses){
|
||||
String className = toConstant(cl.getClassName());
|
||||
String superClassName = toConstant(cl.getSuperClass().getName());
|
||||
ASPWriter writer = new ASPWriter();
|
||||
private final String asp;
|
||||
|
||||
public ASPGenerator(ConstraintSet<Pair> constraints, Collection<ClassOrInterface> fcClasses){
|
||||
List<Constraint<Pair>> constraints1 = constraints.cartesianProduct().iterator().next();
|
||||
List<Pair> constraintPairs = new ArrayList<>();
|
||||
for(Constraint<Pair> constraint : constraints1){
|
||||
System.out.println(UnifyTypeFactory.convert(constraint));
|
||||
constraintPairs.addAll(constraint);
|
||||
}
|
||||
return ret;
|
||||
asp = toASP(constraintPairs, fcClasses);
|
||||
}
|
||||
|
||||
public String getASP(){
|
||||
return asp;
|
||||
}
|
||||
|
||||
private String toASP(List<Pair> constraintSet, Collection<ClassOrInterface> fcClasses){
|
||||
TypeConverter converter = new TypeConverter();
|
||||
for(ClassOrInterface cl : fcClasses){
|
||||
ASPType superClass = cl.getSuperClass().acceptTV(converter);
|
||||
ASPPairSmaller fcEntry = new ASPPairSmaller(convert(cl), superClass);
|
||||
writer.add(new ASPStatement(fcEntry.toASP()));
|
||||
}
|
||||
for(Pair cons : constraintSet){
|
||||
writer.add(new ASPStatement(convert(cons).toASP()));
|
||||
}
|
||||
|
||||
return writer.getASPFile();
|
||||
}
|
||||
|
||||
private ASPPair convert(Pair pair){
|
||||
TypeConverter converter = new TypeConverter();
|
||||
ASPType ls = pair.TA1.acceptTV(converter);
|
||||
ASPType rs = pair.TA2.acceptTV(converter);
|
||||
if(pair.OperatorEqual()){
|
||||
return new ASPPairEquals(ls, rs);
|
||||
}else if(pair.OperatorSmallerDot()){
|
||||
return new ASPPairSmallerDot(ls, rs);
|
||||
}else throw new NotImplementedException();
|
||||
}
|
||||
|
||||
private ASPType convert(ClassOrInterface cl){
|
||||
List<ASPType> paramList = new ArrayList<>();
|
||||
for(GenericTypeVar gtv : cl.getGenerics()){
|
||||
paramList.add(new ASPGenericType(toConstant(gtv.getName())));
|
||||
}
|
||||
ASPParameterList params = new ASPParameterList(paramList, writer);
|
||||
return new ASPRefType(toConstant(cl.getClassName()), params);
|
||||
}
|
||||
|
||||
public static String toConstant(JavaClassName name){
|
||||
return toConstant(name.toString().replace(".", "_"));
|
||||
}
|
||||
|
||||
public static String toConstant(String name){
|
||||
return "c" + name.toString().replace(".", "_");
|
||||
}
|
||||
|
||||
private class TypeConverter implements TypeVisitor<ASPType>{
|
||||
|
||||
@Override
|
||||
public ASPType visit(RefType type) {
|
||||
List<ASPType> paramList = new ArrayList<>();
|
||||
for(RefTypeOrTPHOrWildcardOrGeneric gtv : type.getParaList()){
|
||||
paramList.add(gtv.acceptTV(this));
|
||||
}
|
||||
ASPParameterList params = new ASPParameterList(paramList, writer);
|
||||
return new ASPRefType(toConstant(type.getName()), params);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ASPType visit(SuperWildcardType superWildcardType) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ASPType visit(TypePlaceholder typePlaceholder) {
|
||||
return new ASPTypeVar(toConstant(typePlaceholder.getName()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ASPType visit(ExtendsWildcardType extendsWildcardType) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ASPType visit(GenericRefType genericRefType) {
|
||||
return new ASPRefType(toConstant(genericRefType.getName()),
|
||||
new ASPParameterList(new ArrayList<>(), writer));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
24
src/de/dhbwstuttgart/sat/asp/ASPWriter.java
Normal file
24
src/de/dhbwstuttgart/sat/asp/ASPWriter.java
Normal file
@ -0,0 +1,24 @@
|
||||
package de.dhbwstuttgart.sat.asp;
|
||||
|
||||
import de.dhbwstuttgart.sat.asp.model.ASPRefType;
|
||||
import de.dhbwstuttgart.sat.asp.model.ASPStatement;
|
||||
import de.dhbwstuttgart.sat.asp.model.ASPType;
|
||||
|
||||
import java.util.HashSet;
|
||||
|
||||
public class ASPWriter {
|
||||
|
||||
private HashSet<ASPStatement> content = new HashSet<>();
|
||||
|
||||
public void add(ASPStatement stmt){
|
||||
content.add(stmt);
|
||||
}
|
||||
|
||||
public String getASPFile(){
|
||||
String ret = "";
|
||||
for(ASPStatement statement : content){
|
||||
ret += statement.getASP() + ".\n";
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
}
|
14
src/de/dhbwstuttgart/sat/asp/model/ASPGenericType.java
Normal file
14
src/de/dhbwstuttgart/sat/asp/model/ASPGenericType.java
Normal file
@ -0,0 +1,14 @@
|
||||
package de.dhbwstuttgart.sat.asp.model;
|
||||
|
||||
public class ASPGenericType implements ASPType{
|
||||
public static final String ASP_GENERIC_TYPE_NAME = "genericType";
|
||||
private final String name;
|
||||
|
||||
public ASPGenericType(String name){
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String toString(){
|
||||
return ASP_GENERIC_TYPE_NAME + "(" + name + ")";
|
||||
}
|
||||
}
|
21
src/de/dhbwstuttgart/sat/asp/model/ASPPair.java
Normal file
21
src/de/dhbwstuttgart/sat/asp/model/ASPPair.java
Normal file
@ -0,0 +1,21 @@
|
||||
package de.dhbwstuttgart.sat.asp.model;
|
||||
|
||||
public abstract class ASPPair {
|
||||
public final ASPType leftSide;
|
||||
public final ASPType rightSide;
|
||||
|
||||
public ASPPair(ASPType ls, ASPType rs){
|
||||
this.leftSide = ls;
|
||||
this.rightSide = rs;
|
||||
}
|
||||
|
||||
public String toASP(){
|
||||
return this.getRuleName() + "(" + leftSide + ","+ rightSide + ")";
|
||||
}
|
||||
|
||||
public String toString(){
|
||||
return toASP();
|
||||
}
|
||||
|
||||
protected abstract String getRuleName();
|
||||
}
|
13
src/de/dhbwstuttgart/sat/asp/model/ASPPairEquals.java
Normal file
13
src/de/dhbwstuttgart/sat/asp/model/ASPPairEquals.java
Normal file
@ -0,0 +1,13 @@
|
||||
package de.dhbwstuttgart.sat.asp.model;
|
||||
|
||||
public class ASPPairEquals extends ASPPair{
|
||||
private final static String ASP_PAIR_EQUALS_NAME = "equals";
|
||||
public ASPPairEquals(ASPType ls, ASPType rs){
|
||||
super(ls, rs);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getRuleName() {
|
||||
return ASP_PAIR_EQUALS_NAME;
|
||||
}
|
||||
}
|
13
src/de/dhbwstuttgart/sat/asp/model/ASPPairSmaller.java
Normal file
13
src/de/dhbwstuttgart/sat/asp/model/ASPPairSmaller.java
Normal file
@ -0,0 +1,13 @@
|
||||
package de.dhbwstuttgart.sat.asp.model;
|
||||
|
||||
public class ASPPairSmaller extends ASPPair{
|
||||
private final static String ASP_PAIR_SMALLER_NAME = "smaller";
|
||||
public ASPPairSmaller(ASPType ls, ASPType rs){
|
||||
super(ls, rs);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getRuleName() {
|
||||
return ASP_PAIR_SMALLER_NAME;
|
||||
}
|
||||
}
|
13
src/de/dhbwstuttgart/sat/asp/model/ASPPairSmallerDot.java
Normal file
13
src/de/dhbwstuttgart/sat/asp/model/ASPPairSmallerDot.java
Normal file
@ -0,0 +1,13 @@
|
||||
package de.dhbwstuttgart.sat.asp.model;
|
||||
|
||||
public class ASPPairSmallerDot extends ASPPair{
|
||||
private final static String ASP_PAIR_SMALLER_NAME = "smallerDot";
|
||||
public ASPPairSmallerDot(ASPType ls, ASPType rs){
|
||||
super(ls, rs);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getRuleName() {
|
||||
return ASP_PAIR_SMALLER_NAME;
|
||||
}
|
||||
}
|
45
src/de/dhbwstuttgart/sat/asp/model/ASPParameterList.java
Normal file
45
src/de/dhbwstuttgart/sat/asp/model/ASPParameterList.java
Normal file
@ -0,0 +1,45 @@
|
||||
package de.dhbwstuttgart.sat.asp.model;
|
||||
|
||||
import de.dhbwstuttgart.sat.asp.ASPGenerator;
|
||||
import de.dhbwstuttgart.sat.asp.ASPWriter;
|
||||
import de.dhbwstuttgart.syntaxtree.factory.NameGenerator;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class ASPParameterList {
|
||||
private final static String ASP_PARAMLIST_NAME = "param";
|
||||
private final static String ASP_PARAMLIST_END_POINTER = "null";
|
||||
public final String name;
|
||||
private final List<ASPType> types;
|
||||
|
||||
public ASPParameterList(List<ASPType> types, ASPWriter writer){
|
||||
this.types = types;
|
||||
if(types.size() == 0){
|
||||
name = ASP_PARAMLIST_END_POINTER;
|
||||
}else{
|
||||
name = newName();
|
||||
String nextPointer = name;
|
||||
Iterator<ASPType> it = types.iterator();
|
||||
while(it.hasNext()){
|
||||
ASPType t = it.next();
|
||||
String param = nextPointer + "," + t.toString() + ",";
|
||||
nextPointer = newName();
|
||||
if(! it.hasNext())nextPointer = ASP_PARAMLIST_END_POINTER;
|
||||
param += nextPointer;
|
||||
writer.add(new ASPStatement(ASP_PARAMLIST_NAME + "(" + param + ")"));
|
||||
//paramDefinitions.add(new ASPStatement(ASP_PARAMLIST_NAME + "(" + param + ")"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String newName() {
|
||||
return ASPGenerator.toConstant(NameGenerator.makeNewName());
|
||||
}
|
||||
|
||||
public String toString(){
|
||||
return name;
|
||||
}
|
||||
}
|
20
src/de/dhbwstuttgart/sat/asp/model/ASPRefType.java
Normal file
20
src/de/dhbwstuttgart/sat/asp/model/ASPRefType.java
Normal file
@ -0,0 +1,20 @@
|
||||
package de.dhbwstuttgart.sat.asp.model;
|
||||
|
||||
public class ASPRefType implements ASPType {
|
||||
public static final String ASP_TYPE = "type";
|
||||
private final ASPParameterList params;
|
||||
private final String name;
|
||||
|
||||
public ASPRefType(String name, ASPParameterList params){
|
||||
this.name = name;
|
||||
this.params = params;
|
||||
}
|
||||
|
||||
public ASPParameterList getParams() {
|
||||
return params;
|
||||
}
|
||||
|
||||
public String toString(){
|
||||
return ASP_TYPE + "(" + name +"," + params.name + ")";
|
||||
}
|
||||
}
|
27
src/de/dhbwstuttgart/sat/asp/model/ASPStatement.java
Normal file
27
src/de/dhbwstuttgart/sat/asp/model/ASPStatement.java
Normal file
@ -0,0 +1,27 @@
|
||||
package de.dhbwstuttgart.sat.asp.model;
|
||||
|
||||
public class ASPStatement {
|
||||
private final String stmt;
|
||||
public ASPStatement(String stmt) {
|
||||
this.stmt = stmt;
|
||||
}
|
||||
|
||||
public String toString(){
|
||||
return stmt;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return stmt.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if(obj instanceof ASPStatement)return stmt.equals(((ASPStatement) obj).stmt);
|
||||
return false;
|
||||
}
|
||||
|
||||
public String getASP() {
|
||||
return stmt;
|
||||
}
|
||||
}
|
@ -1,9 +1,4 @@
|
||||
package de.dhbwstuttgart.sat.asp.model;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ASPType {
|
||||
public ASPType(String name, List<ASPType> params){
|
||||
|
||||
}
|
||||
public interface ASPType {
|
||||
}
|
||||
|
14
src/de/dhbwstuttgart/sat/asp/model/ASPTypeVar.java
Normal file
14
src/de/dhbwstuttgart/sat/asp/model/ASPTypeVar.java
Normal file
@ -0,0 +1,14 @@
|
||||
package de.dhbwstuttgart.sat.asp.model;
|
||||
|
||||
public class ASPTypeVar implements ASPType{
|
||||
private final String name;
|
||||
|
||||
public ASPTypeVar(String name){
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "typeVar("+ name +")";
|
||||
}
|
||||
}
|
@ -12,6 +12,7 @@ import de.dhbwstuttgart.syntaxtree.GenericTypeVar;
|
||||
import de.dhbwstuttgart.syntaxtree.type.*;
|
||||
import de.dhbwstuttgart.syntaxtree.type.Void;
|
||||
import de.dhbwstuttgart.syntaxtree.type.WildcardType;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Constraint;
|
||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Pair;
|
||||
import de.dhbwstuttgart.typeinference.result.PairTPHEqualTPH;
|
||||
@ -169,6 +170,10 @@ public class UnifyTypeFactory {
|
||||
return constraints.map(UnifyTypeFactory::convert);
|
||||
}
|
||||
|
||||
public static Constraint<UnifyPair> convert(Constraint<Pair> constraint){
|
||||
return constraint.stream().map(UnifyTypeFactory::convert).collect(Collectors.toCollection(Constraint::new));
|
||||
}
|
||||
|
||||
public static UnifyPair convert(Pair p) {
|
||||
if(p.GetOperator().equals(PairOperator.SMALLERDOT)) {
|
||||
UnifyPair ret = generateSmallerDotPair(UnifyTypeFactory.convert(p.TA1)
|
||||
|
@ -104,5 +104,8 @@ public class Pair implements Serializable
|
||||
return eOperator;
|
||||
}
|
||||
|
||||
public boolean OperatorSmallerDot() {
|
||||
return eOperator == PairOperator.SMALLERDOT;
|
||||
}
|
||||
}
|
||||
// ino.end
|
||||
|
@ -1,6 +1,7 @@
|
||||
package de.dhbwstuttgart.typeinference.result;
|
||||
|
||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||
import de.dhbwstuttgart.syntaxtree.GenericTypeVar;
|
||||
import de.dhbwstuttgart.syntaxtree.type.*;
|
||||
|
||||
import java.util.HashSet;
|
||||
@ -15,6 +16,7 @@ public class ResultSet {
|
||||
public ResolvedType resolveType(RefTypeOrTPHOrWildcardOrGeneric type) {
|
||||
if(type instanceof TypePlaceholder)
|
||||
return new Resolver(this).resolve((TypePlaceholder)type);
|
||||
if(type instanceof GenericRefType)new ResolvedType(type, new HashSet<>());
|
||||
if(type instanceof RefType){
|
||||
RelatedTypeWalker related = new RelatedTypeWalker(null, this);
|
||||
type.accept(related);
|
||||
|
@ -153,8 +153,8 @@ public final class TypeParams implements Iterable<UnifyType>{
|
||||
return false;
|
||||
|
||||
for(int i = 0; i < this.size(); i++){
|
||||
if(this.get(i) == null)
|
||||
System.out.print("s");
|
||||
//if(this.get(i) == null)
|
||||
//System.out.print("s");
|
||||
}
|
||||
for(int i = 0; i < this.size(); i++)
|
||||
if(!(this.get(i).equals(other.get(i))))
|
||||
|
68
test/asp/typeinference/ASPTest.java
Normal file
68
test/asp/typeinference/ASPTest.java
Normal file
@ -0,0 +1,68 @@
|
||||
package asp.typeinference;
|
||||
|
||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||
import de.dhbwstuttgart.sat.asp.ASPGenerator;
|
||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Pair;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ASPTest {
|
||||
|
||||
public static final String rootDirectory = System.getProperty("user.dir")+"/test/javFiles/";
|
||||
private static final List<File> filesToTest = new ArrayList<>();
|
||||
protected File fileToTest = null;
|
||||
|
||||
public ASPTest(){
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void test() throws IOException, ClassNotFoundException {
|
||||
if(fileToTest != null)filesToTest.add(fileToTest);
|
||||
else return;
|
||||
//filesToTest.add(new File(rootDirectory+"Faculty.jav"));
|
||||
//filesToTest.add(new File(rootDirectory+"mathStruc.jav"));
|
||||
//filesToTest.add(new File(rootDirectory+"test.jav"));
|
||||
filesToTest.add(new File(rootDirectory+"EmptyMethod.jav"));
|
||||
//filesToTest.add(new File(rootDirectory+"fc.jav"));
|
||||
//filesToTest.add(new File(rootDirectory+"Lambda.jav"));
|
||||
//filesToTest.add(new File(rootDirectory+"Lambda2.jav"));
|
||||
//filesToTest.add(new File(rootDirectory+"Lambda3.jav"));
|
||||
//filesToTest.add(new File(rootDirectory+"Vector.jav"));
|
||||
//filesToTest.add(new File(rootDirectory+"Generics.jav"));
|
||||
//filesToTest.add(new File(rootDirectory+"MethodsEasy.jav"));
|
||||
//filesToTest.add(new File(rootDirectory+"Matrix.jav"));
|
||||
//filesToTest.add(new File(rootDirectory+"Import.jav"));
|
||||
JavaTXCompiler compiler = new JavaTXCompiler(fileToTest);
|
||||
List<ClassOrInterface> allClasses = new ArrayList<>();
|
||||
for(SourceFile sf : compiler.sourceFiles.values()) {
|
||||
//allClasses.addAll(compiler.getAvailableClasses(sf));
|
||||
}
|
||||
for(SourceFile sf : compiler.sourceFiles.values()) {
|
||||
allClasses.addAll(sf.getClasses());
|
||||
}
|
||||
|
||||
final ConstraintSet<Pair> cons = compiler.getConstraints();
|
||||
ASPGenerator generator = new ASPGenerator(cons, allClasses);
|
||||
System.out.println(generator.getASP());
|
||||
}
|
||||
|
||||
static String readFile(String path, Charset encoding)
|
||||
throws IOException
|
||||
{
|
||||
byte[] encoded = Files.readAllBytes(Paths.get(path));
|
||||
return new String(encoded, encoding);
|
||||
}
|
||||
|
||||
}
|
||||
|
9
test/asp/typeinference/GenericsTest.java
Normal file
9
test/asp/typeinference/GenericsTest.java
Normal file
@ -0,0 +1,9 @@
|
||||
package asp.typeinference;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class GenericsTest extends ASPTest {
|
||||
public GenericsTest() {
|
||||
this.fileToTest = new File(rootDirectory+"Generics.jav");
|
||||
}
|
||||
}
|
9
test/asp/typeinference/VectorTest.java
Normal file
9
test/asp/typeinference/VectorTest.java
Normal file
@ -0,0 +1,9 @@
|
||||
package asp.typeinference;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class VectorTest extends ASPTest {
|
||||
public VectorTest() {
|
||||
this.fileToTest = new File(rootDirectory+"Vector.jav");
|
||||
}
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
|
||||
class Generics<B> {
|
||||
<A extends B> A mt1(A a, B b){
|
||||
//<A extends B> A mt1(A a, B b){
|
||||
B mt1(B a, B b){
|
||||
return mt1(a, a);
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package typeinference;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
//TODO: Hier gibt es einen Fehler. Das erstellte ConstraintSet stimmt nicht
|
||||
public class GenericsTest extends JavaTXCompilerTest{
|
||||
public GenericsTest() {
|
||||
this.fileToTest = new File(rootDirectory+"Generics.jav");
|
||||
|
@ -1,11 +1,23 @@
|
||||
package typeinference;
|
||||
|
||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
||||
import de.dhbwstuttgart.sat.asp.ASPGenerator;
|
||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||
import de.dhbwstuttgart.syntaxtree.factory.ASTFactory;
|
||||
import de.dhbwstuttgart.syntaxtree.factory.UnifyTypeFactory;
|
||||
import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter;
|
||||
import de.dhbwstuttgart.typedeployment.TypeInsert;
|
||||
import de.dhbwstuttgart.typedeployment.TypeInsertFactory;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Constraint;
|
||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Pair;
|
||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||
import de.dhbwstuttgart.typeinference.typeAlgo.TYPE;
|
||||
import de.dhbwstuttgart.typeinference.unify.TypeUnify;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.FiniteClosure;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
@ -17,8 +29,10 @@ import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class JavaTXCompilerTest {
|
||||
|
||||
@ -28,11 +42,10 @@ public class JavaTXCompilerTest {
|
||||
|
||||
public JavaTXCompilerTest(){
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() throws IOException, java.lang.ClassNotFoundException {
|
||||
public void test() throws IOException, ClassNotFoundException {
|
||||
if(fileToTest != null)filesToTest.add(fileToTest);
|
||||
else return;
|
||||
else return;
|
||||
//filesToTest.add(new File(rootDirectory+"Faculty.jav"));
|
||||
//filesToTest.add(new File(rootDirectory+"mathStruc.jav"));
|
||||
//filesToTest.add(new File(rootDirectory+"test.jav"));
|
||||
@ -47,6 +60,7 @@ public class JavaTXCompilerTest {
|
||||
//filesToTest.add(new File(rootDirectory+"Matrix.jav"));
|
||||
//filesToTest.add(new File(rootDirectory+"Import.jav"));
|
||||
JavaTXCompiler compiler = new JavaTXCompiler(fileToTest);
|
||||
|
||||
List<ResultSet> results = compiler.typeInference();
|
||||
|
||||
for(File f : compiler.sourceFiles.keySet()){
|
||||
@ -54,14 +68,18 @@ public class JavaTXCompilerTest {
|
||||
System.out.println(ASTTypePrinter.print(sf));
|
||||
//List<ResultSet> results = compiler.typeInference(); PL 2017-10-03 vor die For-Schleife gezogen
|
||||
assert results.size()>0;
|
||||
Set<String> insertedTypes = new HashSet<>();
|
||||
for(ResultSet resultSet : results){
|
||||
Set<TypeInsert> result = TypeInsertFactory.createTypeInsertPoints(sf, resultSet);
|
||||
assert result.size()>0;
|
||||
String content = readFile(f.getPath(), StandardCharsets.UTF_8);
|
||||
for(TypeInsert tip : result){
|
||||
System.out.println(tip.insert(content));
|
||||
insertedTypes.add(tip.insert(content));
|
||||
}
|
||||
}
|
||||
for(String s : insertedTypes){
|
||||
System.out.println(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user