Merge branch 'bigRefactoring' of ssh://gohorb.ba-horb.de/bahome/projekt/git/JavaCompilerCore into bytecode2

This commit is contained in:
Fayez Abu Alia 2018-02-28 14:58:58 +01:00
commit 6b57aacef0
43 changed files with 653 additions and 243 deletions

View File

@ -102,8 +102,8 @@ public class JavaTXCompiler {
System.out.println(xConsSet); System.out.println(xConsSet);
Set<Set<UnifyPair>> result = unify.unify(xConsSet, finiteClosure); Set<Set<UnifyPair>> result = unify.unify(xConsSet, finiteClosure);
System.out.println("RESULT: " + result); System.out.println("RESULT: " + result.size());
results.addAll(result); //results.addAll(result);
} }
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());

View File

@ -2,6 +2,7 @@ package de.dhbwstuttgart.parser.SyntaxTreeGenerator;
import de.dhbwstuttgart.exceptions.DebugException; import de.dhbwstuttgart.exceptions.DebugException;
import de.dhbwstuttgart.exceptions.NotImplementedException; import de.dhbwstuttgart.exceptions.NotImplementedException;
import de.dhbwstuttgart.parser.NullToken;
import de.dhbwstuttgart.syntaxtree.ClassOrInterface; import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
import de.dhbwstuttgart.syntaxtree.GenericTypeVar; import de.dhbwstuttgart.syntaxtree.GenericTypeVar;
import de.dhbwstuttgart.syntaxtree.factory.ASTFactory; import de.dhbwstuttgart.syntaxtree.factory.ASTFactory;
@ -11,6 +12,7 @@ import de.dhbwstuttgart.typeinference.constraints.Pair;
import de.dhbwstuttgart.typeinference.unify.model.*; import de.dhbwstuttgart.typeinference.unify.model.*;
import java.util.*; import java.util.*;
import java.util.stream.Collectors;
public class FCGenerator { public class FCGenerator {
/** /**
@ -19,12 +21,15 @@ public class FCGenerator {
* *
* @param availableClasses - Alle geparsten Klassen * @param availableClasses - Alle geparsten Klassen
*/ */
public static Set<UnifyPair> toFC(Collection<ClassOrInterface> availableClasses) throws ClassNotFoundException { public static Set<UnifyPair> toUnifyFC(Collection<ClassOrInterface> availableClasses) throws ClassNotFoundException {
HashSet<UnifyPair> pairs = new HashSet<>(); return toFC(availableClasses).stream().map(t -> UnifyTypeFactory.convert(t)).collect(Collectors.toSet());
}
public static Set<Pair> toFC(Collection<ClassOrInterface> availableClasses) throws ClassNotFoundException {
HashSet<Pair> pairs = new HashSet<>();
for(ClassOrInterface cly : availableClasses){ for(ClassOrInterface cly : availableClasses){
pairs.addAll(getSuperTypes(cly, availableClasses)); pairs.addAll(getSuperTypes(cly, availableClasses));
} }
System.out.println(pairs);
return pairs; return pairs;
} }
@ -35,20 +40,20 @@ public class FCGenerator {
* @param forType * @param forType
* @return * @return
*/ */
private static List<UnifyPair> getSuperTypes(ClassOrInterface forType, Collection<ClassOrInterface> availableClasses) throws ClassNotFoundException { private static List<Pair> getSuperTypes(ClassOrInterface forType, Collection<ClassOrInterface> availableClasses) throws ClassNotFoundException {
return getSuperTypes(forType, availableClasses, new HashMap<>()); return getSuperTypes(forType, availableClasses, new HashMap<>());
} }
//TODO: implements Interface auch als superklassen beachten //TODO: implements Interface auch als superklassen beachten
private static List<UnifyPair> getSuperTypes(ClassOrInterface forType, Collection<ClassOrInterface> availableClasses, HashMap<String, UnifyType> gtvs) throws ClassNotFoundException { private static List<Pair> getSuperTypes(ClassOrInterface forType, Collection<ClassOrInterface> availableClasses, HashMap<String, RefTypeOrTPHOrWildcardOrGeneric> gtvs) throws ClassNotFoundException {
List<UnifyType> params = new ArrayList<>(); List<RefTypeOrTPHOrWildcardOrGeneric> params = new ArrayList<>();
//Die GTVs, die in forType hinzukommen: //Die GTVs, die in forType hinzukommen:
HashMap<String, UnifyType> newGTVs = new HashMap<>(); HashMap<String, RefTypeOrTPHOrWildcardOrGeneric> newGTVs = new HashMap<>();
//Generics mit gleichem Namen müssen den selben TPH bekommen //Generics mit gleichem Namen müssen den selben TPH bekommen
for(GenericTypeVar gtv : forType.getGenerics()){ for(GenericTypeVar gtv : forType.getGenerics()){
if(!gtvs.containsKey(gtv.getParsedName())){ if(!gtvs.containsKey(gtv.getParsedName())){
gtvs.put(gtv.getParsedName(), PlaceholderType.freshPlaceholder()); gtvs.put(gtv.getParsedName(), TypePlaceholder.fresh(new NullToken()));
newGTVs.put(gtv.getParsedName(), PlaceholderType.freshPlaceholder()); newGTVs.put(gtv.getParsedName(), TypePlaceholder.fresh(new NullToken()));
} }
params.add(gtvs.get(gtv.getParsedName())); params.add(gtvs.get(gtv.getParsedName()));
} }
@ -73,27 +78,26 @@ public class FCGenerator {
while(itGenParams.hasNext()){ while(itGenParams.hasNext()){
RefTypeOrTPHOrWildcardOrGeneric setType = itSetParams.next(); RefTypeOrTPHOrWildcardOrGeneric setType = itSetParams.next();
//In diesem Typ die GTVs durch TPHs und Einsetzungen austauschen: //In diesem Typ die GTVs durch TPHs und Einsetzungen austauschen:
UnifyType setSetType = setType.acceptTV(new TypeExchanger(gtvs)); RefTypeOrTPHOrWildcardOrGeneric setSetType = setType.acceptTV(new TypeExchanger(gtvs));
newGTVs.put(itGenParams.next().getParsedName(), setSetType); newGTVs.put(itGenParams.next().getParsedName(), setSetType);
} }
UnifyType superType = forType.getSuperClass().acceptTV(new TypeExchanger(newGTVs)); RefTypeOrTPHOrWildcardOrGeneric superType = forType.getSuperClass().acceptTV(new TypeExchanger(newGTVs));
TypeParams paramList = new TypeParams(params); RefTypeOrTPHOrWildcardOrGeneric t1 = new RefType(forType.getClassName(), params, new NullToken());
UnifyType t1 = new ReferenceType(forType.getClassName().toString(), paramList); RefTypeOrTPHOrWildcardOrGeneric t2 = superType;
UnifyType t2 = superType;
UnifyPair ret = UnifyTypeFactory.generateSmallerPair(t1, t2); Pair ret = new Pair(t1, t2, PairOperator.SMALLER);
List<UnifyPair> superTypes; List<Pair> superTypes;
//Rekursiver Aufruf. Abbruchbedingung ist Object als Superklasse: //Rekursiver Aufruf. Abbruchbedingung ist Object als Superklasse:
if(superClass.getClassName().equals(ASTFactory.createObjectClass().getClassName())){ if(superClass.getClassName().equals(ASTFactory.createObjectClass().getClassName())){
superTypes = Arrays.asList(UnifyTypeFactory.generateSmallerPair(UnifyTypeFactory.convert(ASTFactory.createObjectType()), UnifyTypeFactory.convert(ASTFactory.createObjectType()))); superTypes = Arrays.asList(new Pair(ASTFactory.createObjectType(), ASTFactory.createObjectType(), PairOperator.SMALLER));
}else{ }else{
superTypes = getSuperTypes(superClass, availableClasses, newGTVs); superTypes = getSuperTypes(superClass, availableClasses, newGTVs);
} }
List<UnifyPair> retList = new ArrayList<>(); List<Pair> retList = new ArrayList<>();
retList.add(ret); retList.add(ret);
retList.addAll(superTypes); retList.addAll(superTypes);
@ -103,42 +107,41 @@ public class FCGenerator {
/** /**
* Tauscht die GTVs in einem Typ gegen die entsprechenden Typen in der übergebenen Map aus. * Tauscht die GTVs in einem Typ gegen die entsprechenden Typen in der übergebenen Map aus.
*/ */
private static class TypeExchanger implements TypeVisitor<UnifyType>{ private static class TypeExchanger implements TypeVisitor<RefTypeOrTPHOrWildcardOrGeneric>{
private final HashMap<String, UnifyType> gtvs; private final HashMap<String, RefTypeOrTPHOrWildcardOrGeneric> gtvs;
TypeExchanger(HashMap<String, UnifyType> gtvs){ TypeExchanger(HashMap<String, RefTypeOrTPHOrWildcardOrGeneric> gtvs){
this.gtvs = gtvs; this.gtvs = gtvs;
} }
@Override @Override
public UnifyType visit(RefType refType) { public RefTypeOrTPHOrWildcardOrGeneric visit(RefType refType) {
List<UnifyType> params = new ArrayList<>(); List<RefTypeOrTPHOrWildcardOrGeneric> params = new ArrayList<>();
for(RefTypeOrTPHOrWildcardOrGeneric param : refType.getParaList()){ for(RefTypeOrTPHOrWildcardOrGeneric param : refType.getParaList()){
params.add(param.acceptTV(this)); params.add(param.acceptTV(this));
} }
TypeParams paramList = new TypeParams(params); RefTypeOrTPHOrWildcardOrGeneric ret = new RefType(refType.getName(), params, new NullToken());
UnifyType ret = new ReferenceType(refType.getName().toString(), paramList);
return ret; return ret;
} }
@Override @Override
public UnifyType visit(SuperWildcardType superWildcardType) { public RefTypeOrTPHOrWildcardOrGeneric visit(SuperWildcardType superWildcardType) {
throw new DebugException("Dieser Fall darf nicht auftreten"); throw new DebugException("Dieser Fall darf nicht auftreten");
} }
@Override @Override
public UnifyType visit(TypePlaceholder typePlaceholder) { public RefTypeOrTPHOrWildcardOrGeneric visit(TypePlaceholder typePlaceholder) {
throw new DebugException("Dieser Fall darf nicht auftreten"); throw new DebugException("Dieser Fall darf nicht auftreten");
} }
@Override @Override
public UnifyType visit(ExtendsWildcardType extendsWildcardType) { public RefTypeOrTPHOrWildcardOrGeneric visit(ExtendsWildcardType extendsWildcardType) {
throw new DebugException("Dieser Fall darf nicht auftreten"); throw new DebugException("Dieser Fall darf nicht auftreten");
} }
@Override @Override
public UnifyType visit(GenericRefType genericRefType) { public RefTypeOrTPHOrWildcardOrGeneric visit(GenericRefType genericRefType) {
if(! gtvs.containsKey(genericRefType.getParsedName())) if(! gtvs.containsKey(genericRefType.getParsedName()))
throw new DebugException("Dieser Fall darf nicht auftreten"); throw new DebugException("Dieser Fall darf nicht auftreten");
//TODO: Diesen Dirty-Hack beseitigen. Fehler tritt bei java.lang.invoke.LambdaFormEditor$Transform$Kind auf. //TODO: Diesen Dirty-Hack beseitigen. Fehler tritt bei java.lang.invoke.LambdaFormEditor$Transform$Kind auf.

View File

@ -0,0 +1,17 @@
package de.dhbwstuttgart.sat.asp;
import de.dhbwstuttgart.parser.scope.JavaClassName;
public class ASPStringConverter {
public static String toConstant(JavaClassName name){
return toConstant(name.toString().replace(".", "_"));
}
public static String toConstant(String name){
return "c" + name.toString().replace(".", "_");
}
public static String fromConstant(String s){
return s.replace("_", ".").substring(1);
}
}

View File

@ -17,16 +17,20 @@ public class Clingo {
private static final List<File> programFiles = new ArrayList<>(); private static final List<File> programFiles = new ArrayList<>();
static{ static{
programFiles.add(new File("/home/janulrich/Sync/HiwiJob/ResearchPapers/MasterarbeitStadelmeier/asp/unifyWithoutWildcards/basis.lp")); programFiles.add(new File("/home/janulrich/Sync/HiwiJob/ResearchPapers/MasterarbeitStadelmeier/asp/unifyWithoutWildcards/basis.lp"));
programFiles.add(new File("/home/janulrich/Sync/HiwiJob/ResearchPapers/MasterarbeitStadelmeier/asp/unifyWithoutWildcards/finiteclosure.lp"));
programFiles.add(new File("/home/janulrich/Sync/HiwiJob/ResearchPapers/MasterarbeitStadelmeier/asp/unifyWithoutWildcards/subst.lp")); programFiles.add(new File("/home/janulrich/Sync/HiwiJob/ResearchPapers/MasterarbeitStadelmeier/asp/unifyWithoutWildcards/subst.lp"));
programFiles.add(new File("/home/janulrich/Sync/HiwiJob/ResearchPapers/MasterarbeitStadelmeier/asp/unifyWithoutWildcards/reduce1.lp")); programFiles.add(new File("/home/janulrich/Sync/HiwiJob/ResearchPapers/MasterarbeitStadelmeier/asp/unifyWithoutWildcards/reduce.lp"));
programFiles.add(new File("/home/janulrich/Sync/HiwiJob/ResearchPapers/MasterarbeitStadelmeier/asp/unifyWithoutWildcards/reduce2.lp"));
programFiles.add(new File("/home/janulrich/Sync/HiwiJob/ResearchPapers/MasterarbeitStadelmeier/asp/unifyWithoutWildcards/unify.lp")); programFiles.add(new File("/home/janulrich/Sync/HiwiJob/ResearchPapers/MasterarbeitStadelmeier/asp/unifyWithoutWildcards/unify.lp"));
programFiles.add(new File("/home/janulrich/Sync/HiwiJob/ResearchPapers/MasterarbeitStadelmeier/asp/unifyWithoutWildcards/adapt.lp"));
} }
public Clingo(List<File> inputFiles){ public Clingo(List<File> inputFiles){
this.input = inputFiles; this.input = inputFiles;
} }
/*
TODO: Clingo per Java Wrapper https://stackoverflow.com/questions/3356200/using-java-to-wrap-over-c
*/
public String runClingo() throws IOException, InterruptedException { public String runClingo() throws IOException, InterruptedException {
String pathToClingo = String pathToClingo =
"/home/janulrich/Sync/HiwiJob/ResearchPapers/MasterarbeitStadelmeier/asp/clingo-5.2.1-linux-x86_64/clingo"; "/home/janulrich/Sync/HiwiJob/ResearchPapers/MasterarbeitStadelmeier/asp/clingo-5.2.1-linux-x86_64/clingo";

View File

@ -9,8 +9,8 @@ public enum ASPRule {
ASP_PARAMLISTNUMERATION_NAME("paramNum"), ASP_PARAMLISTNUMERATION_NAME("paramNum"),
ASP_PARAMLIST_END_POINTER("null"), ASP_PARAMLIST_END_POINTER("null"),
ASP_TYPE("type"), ASP_TYPE("type"),
ASP_FCTYPE("type") ASP_FCTYPE("typeFC"),
; ASP_TYPE_VAR("typeVar");
private final String text; private final String text;

View File

@ -1,17 +1,187 @@
package de.dhbwstuttgart.sat.asp.parser; package de.dhbwstuttgart.sat.asp.parser;
import de.dhbwstuttgart.typeinference.result.ResultPair; import de.dhbwstuttgart.exceptions.DebugException;
import de.dhbwstuttgart.typeinference.result.ResultSet; import de.dhbwstuttgart.parser.NullToken;
import de.dhbwstuttgart.parser.scope.JavaClassName;
import de.dhbwstuttgart.sat.asp.ASPStringConverter;
import de.dhbwstuttgart.sat.asp.model.ASPRule;
import de.dhbwstuttgart.sat.asp.parser.model.ParsedType;
import de.dhbwstuttgart.sat.asp.writer.ASPGenerator;
import de.dhbwstuttgart.sat.asp.writer.model.ASPParameterList;
import de.dhbwstuttgart.sat.asp.writer.model.ASPRefType;
import de.dhbwstuttgart.sat.asp.writer.model.ASPType;
import de.dhbwstuttgart.syntaxtree.type.*;
import de.dhbwstuttgart.typeinference.result.*;
import java.util.HashSet; import javax.json.Json;
import java.util.Set; import javax.json.JsonArray;
import javax.json.JsonObject;
import java.io.StringReader;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* Ablauf:
* - Erst werden alle benötigten Statements eingelesen. Die Pointer bleiben als Strings erhalten
* - Anschließend müssen diese wieder zu einem Unify Ergebnis zurückgewandelt werden
* - Hier nicht die Typen aus dem unify.model packages verwenden.
* TODO: Überlegen welche Informationen noch nach der Unifizierung gebraucht werden
* -> Eigentlich nur die korrekten Namen der Typen und TPHs
*/
public class ASPParser { public class ASPParser {
ResultSet parse(String result){ private final Collection<TypePlaceholder> originalTPHs;
Set<ResultPair> ret = new HashSet<>(); private ResultSet resultSet;
for(String pair : result.split(",")){ private Map<String, ParsedType> types = new HashMap<>();
private Set<String> tphs = new HashSet<>();
private Map<String, ParameterListNode> parameterLists = new HashMap<>();
/**
* Parst clingo output welcher als JSON (option --outf=2) ausgibt
* @param toParse
* @return
*/
public static ResultSet parse(String toParse, Collection<TypePlaceholder> oldPlaceholders){
return new ASPParser(toParse, oldPlaceholders).resultSet;
}
private ASPParser(String toParse, Collection<TypePlaceholder> oldPlaceholders){
this.originalTPHs = oldPlaceholders;
JsonObject jsonResult = Json.createReader(new StringReader(toParse)).readObject();
JsonArray results = jsonResult.getJsonArray("Call").getJsonObject(0).
getJsonArray("Witnesses").getJsonObject(0).
getJsonArray("Value");
/*
Diese Funktion läuft im folgenden mehrmals über das Result aus dem ASP Programm.
Dabei werden Schritt für Schritt die Felder dieser Klasse befüllt die am Schluss das ResultSet ergeben
*/
Set<ResultPair> ret = new HashSet<>();
//Zuerst die params und typeVars:
for(int i = 0; i<results.size();i++){
String aspStatement = results.getString(i);
parseParameter(aspStatement);
parseTypeVar(aspStatement);
} }
return new ResultSet(ret); //Dann die Typen, das ist wichtig, da die Typen auf die Parameter referenzieren:
for(int i = 0; i<results.size();i++){
String aspStatement = results.getString(i);
parseType(aspStatement);
}
//Dann die Equalsdot Statements
for(int i = 0; i<results.size();i++){
String aspStatement = results.getString(i);
ResultPair p = parseEqualsDot(aspStatement);
if(p != null)ret.add(p);
p = parseSmallerDot(aspStatement);
if(p != null)ret.add(p);
}
this.resultSet = new ResultSet(ret);
}
private ResultPair parseSmallerDot(String statement) {
//TODO
return null;
}
private ResultPair parseEqualsDot(String statement){
Pattern p = Pattern.compile(ASPRule.ASP_PAIR_EQUALS_NAME+"\\(([^,]+),([^,]+)\\)");
Matcher m = p.matcher(statement);
boolean b = m.matches();
if(b){
if(m.groupCount()<2)throw new DebugException("Fehler in Regex");
String ls = m.group(1);
String rs = m.group(2);
RefTypeOrTPHOrWildcardOrGeneric lsType = this.getType(ls);
RefTypeOrTPHOrWildcardOrGeneric rsType = this.getType(rs);
if(lsType instanceof TypePlaceholder && rsType instanceof RefType)
return new PairTPHequalRefTypeOrWildcardType((TypePlaceholder) lsType, rsType);
}
return null;
}
private RefTypeOrTPHOrWildcardOrGeneric getType(String name) {
if(tphs.contains(name)){
name = ASPStringConverter.fromConstant(name);
for(TypePlaceholder tph : originalTPHs){
if(tph.getName().equals(name))return tph;
}
return TypePlaceholder.fresh(new NullToken());
}else
if(types.containsKey(name)){
List<RefTypeOrTPHOrWildcardOrGeneric> params = new ArrayList<>();
ParsedType t = types.get(name);
for(String param : t.params){
params.add(this.getType(param));
}
return new RefType(new JavaClassName(ASPStringConverter.fromConstant(t.name)), params, new NullToken());
}else throw new DebugException("Der Typ " + name + " konnte nicht bestimmt werden");
}
private static class ParameterListNode{
final String type;
final String nextNode;
public ParameterListNode(String type, String next) {
this.type = type;
this.nextNode = next;
}
}
private void parseParameter(String statement){
Pattern p = Pattern.compile(ASPRule.ASP_PARAMLIST_NAME+"\\(([^,]+),([^,]+),([^,]+)\\)");
Matcher m = p.matcher(statement);
boolean b = m.matches();
if(b){
if(m.groupCount()<3)throw new DebugException("Fehler in Regex");
String pointer = m.group(1);
String type = m.group(2);
String next = m.group(2);
if(next.equals(ASPRule.ASP_PARAMLIST_END_POINTER.toString()))next = null;
if(this.parameterLists.containsKey(pointer)){
throw new DebugException("Fehler in Ergebnisparsen");
}
this.parameterLists.put(pointer,new ParameterListNode(type, next));
}
}
private void parseTypeVar(String statement){
Pattern p = Pattern.compile(ASPRule.ASP_TYPE_VAR+"\\(([^,]+)\\)");
Matcher m = p.matcher(statement);
boolean b = m.matches();
if(b){
if(m.groupCount()<1)throw new DebugException("Fehler in Regex");
String name = m.group(1);
this.tphs.add(name);
}
}
private void parseType(String statement){
Pattern p = Pattern.compile(ASPRule.ASP_TYPE+"\\(([^,]+),([^,]+)\\)");
Matcher m = p.matcher(statement);
boolean b = m.matches();
if(b){
if(m.groupCount()<2)throw new DebugException("Fehler in Regex");
String ls = m.group(1);
String rs = m.group(2);
List<String> params = this.getParams(rs);
this.types.put(ls,new ParsedType(ls, params));
}
}
private List<String> getParams(String pointer) {
List<String> params = new ArrayList<>();
if(pointer.equals(ASPRule.ASP_PARAMLIST_END_POINTER.toString()))return params;
while(pointer != null){
if(!parameterLists.containsKey(pointer))
throw new DebugException("Fehler in Ergebnisparsen");
ParameterListNode param = parameterLists.get(pointer);
pointer = param.nextNode;
params.add(param.type);
}
return params;
//Optional<ASPParameterList> ret = parameterLists.stream().filter(aspParameterList -> aspParameterList.name.equals(rs)).findAny();
//return ret.get();
} }
} }

View File

@ -1,7 +0,0 @@
package de.dhbwstuttgart.sat.asp.parser.model;
public class ParsedASPStatement {
public ParsedASPStatement(String statement){
}
}

View File

@ -0,0 +1,12 @@
package de.dhbwstuttgart.sat.asp.parser.model;
import java.util.List;
public class ParsedType {
public final String name;
public final List<String> params;
public ParsedType(String name, List<String> params){
this.name = name;
this.params = params;
}
}

View File

@ -1,7 +1,9 @@
package de.dhbwstuttgart.sat.asp.writer; package de.dhbwstuttgart.sat.asp.writer;
import de.dhbwstuttgart.exceptions.NotImplementedException; import de.dhbwstuttgart.exceptions.NotImplementedException;
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.FCGenerator;
import de.dhbwstuttgart.parser.scope.JavaClassName; import de.dhbwstuttgart.parser.scope.JavaClassName;
import de.dhbwstuttgart.sat.asp.ASPStringConverter;
import de.dhbwstuttgart.sat.asp.writer.model.*; import de.dhbwstuttgart.sat.asp.writer.model.*;
import de.dhbwstuttgart.syntaxtree.ClassOrInterface; import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
import de.dhbwstuttgart.syntaxtree.GenericTypeVar; import de.dhbwstuttgart.syntaxtree.GenericTypeVar;
@ -19,25 +21,24 @@ public class ASPGenerator {
ASPWriter writer = new ASPWriter(); ASPWriter writer = new ASPWriter();
private final String asp; private final String asp;
public ASPGenerator(ConstraintSet<Pair> constraints, Collection<ClassOrInterface> fcClasses){ public ASPGenerator(ConstraintSet<Pair> constraints, Collection<ClassOrInterface> fcClasses) throws ClassNotFoundException {
List<Constraint<Pair>> constraints1 = constraints.cartesianProduct().iterator().next(); List<Constraint<Pair>> constraints1 = constraints.cartesianProduct().iterator().next();
List<Pair> constraintPairs = new ArrayList<>(); List<Pair> constraintPairs = new ArrayList<>();
for(Constraint<Pair> constraint : constraints1){ for(Constraint<Pair> constraint : constraints1){
System.out.println(UnifyTypeFactory.convert(constraint));
constraintPairs.addAll(constraint); constraintPairs.addAll(constraint);
} }
asp = toASP(constraintPairs, fcClasses); asp = toASP(constraintPairs, FCGenerator.toFC(fcClasses));
} }
public String getASP(){ public String getASP(){
return asp; return asp;
} }
private String toASP(List<Pair> constraintSet, Collection<ClassOrInterface> fcClasses){ private String toASP(List<Pair> constraintSet, Collection<Pair> fc){
TypeConverter converter = new TypeConverter(); TypeConverter converter = new TypeConverter();
for(ClassOrInterface cl : fcClasses){ for(Pair fcp : fc){
ASPRefType superClass = (ASPRefType) cl.getSuperClass().acceptTV(converter); //Wenn dieser Cast fehlschlägt stimmt etwas nicht. Alle Paare in der FC müssen smaller Operatoren haen
ASPPairSmaller fcEntry = new ASPPairSmaller(new ASPFCType(convert(cl)), new ASPFCType(superClass), writer); ASPPairSmaller fcEntry = (ASPPairSmaller) convert(fcp);
writer.add(new ASPStatement(fcEntry.toASP())); writer.add(new ASPStatement(fcEntry.toASP()));
} }
for(Pair cons : constraintSet){ for(Pair cons : constraintSet){
@ -55,24 +56,19 @@ public class ASPGenerator {
return new ASPPairEquals(ls, rs,writer); return new ASPPairEquals(ls, rs,writer);
}else if(pair.OperatorSmallerDot()){ }else if(pair.OperatorSmallerDot()){
return new ASPPairSmallerDot(ls, rs, writer); return new ASPPairSmallerDot(ls, rs, writer);
}else if(pair.OperatorSmaller()){
//Diese Cast müssen auch immer funktionieren, da in smaller Constraints nur RefTypes vorkommen
return new ASPPairSmaller(new ASPFCType((ASPRefType) ls), new ASPFCType((ASPRefType) rs), writer);
}else throw new NotImplementedException(); }else throw new NotImplementedException();
} }
private ASPRefType convert(ClassOrInterface cl){ private ASPRefType convert(ClassOrInterface cl){
List<ASPType> paramList = new ArrayList<>(); List<ASPType> paramList = new ArrayList<>();
for(GenericTypeVar gtv : cl.getGenerics()){ for(GenericTypeVar gtv : cl.getGenerics()){
paramList.add(new ASPGenericType(toConstant(gtv.getName()))); paramList.add(new ASPGenericType(ASPStringConverter.toConstant(gtv.getName())));
} }
ASPParameterList params = new ASPParameterList(paramList, writer); ASPParameterList params = new ASPParameterList(paramList, writer);
return new ASPRefType(toConstant(cl.getClassName()), params); return new ASPRefType(ASPStringConverter.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>{ private class TypeConverter implements TypeVisitor<ASPType>{
@ -84,7 +80,7 @@ public class ASPGenerator {
paramList.add(gtv.acceptTV(this)); paramList.add(gtv.acceptTV(this));
} }
ASPParameterList params = new ASPParameterList(paramList, writer); ASPParameterList params = new ASPParameterList(paramList, writer);
return new ASPRefType(toConstant(type.getName()), params); return new ASPRefType(ASPStringConverter.toConstant(type.getName()), params);
} }
@Override @Override
@ -94,7 +90,7 @@ public class ASPGenerator {
@Override @Override
public ASPType visit(TypePlaceholder typePlaceholder) { public ASPType visit(TypePlaceholder typePlaceholder) {
return new ASPTypeVar(toConstant(typePlaceholder.getName())); return new ASPTypeVar(ASPStringConverter.toConstant(typePlaceholder.getName()));
} }
@Override @Override
@ -104,7 +100,7 @@ public class ASPGenerator {
@Override @Override
public ASPType visit(GenericRefType genericRefType) { public ASPType visit(GenericRefType genericRefType) {
return new ASPRefType(toConstant(genericRefType.getName()), return new ASPRefType(ASPStringConverter.toConstant(genericRefType.getName()),
new ASPParameterList(new ArrayList<>(), writer)); new ASPParameterList(new ArrayList<>(), writer));
} }
} }

View File

@ -1,5 +1,6 @@
package de.dhbwstuttgart.sat.asp.writer.model; package de.dhbwstuttgart.sat.asp.writer.model;
import de.dhbwstuttgart.sat.asp.ASPStringConverter;
import de.dhbwstuttgart.sat.asp.model.ASPRule; import de.dhbwstuttgart.sat.asp.model.ASPRule;
import de.dhbwstuttgart.sat.asp.writer.ASPGenerator; import de.dhbwstuttgart.sat.asp.writer.ASPGenerator;
import de.dhbwstuttgart.sat.asp.writer.ASPWriter; import de.dhbwstuttgart.sat.asp.writer.ASPWriter;
@ -30,13 +31,12 @@ public class ASPParameterList {
writer.add(new ASPStatement(ASPRule.ASP_PARAMLIST_NAME + "(" + param + ")")); writer.add(new ASPStatement(ASPRule.ASP_PARAMLIST_NAME + "(" + param + ")"));
writer.add(new ASPStatement(ASPRule.ASP_PARAMLISTNUMERATION_NAME + "(" + name + "," +t + "," + paramNum + ")")); writer.add(new ASPStatement(ASPRule.ASP_PARAMLISTNUMERATION_NAME + "(" + name + "," +t + "," + paramNum + ")"));
paramNum++; paramNum++;
//paramDefinitions.add(new ASPStatement(ASP_PARAMLIST_NAME + "(" + param + ")"));
} }
} }
} }
private String newName() { private String newName() {
return ASPGenerator.toConstant(NameGenerator.makeNewName()); return ASPStringConverter.toConstant(NameGenerator.makeNewName());
} }
public String toString(){ public String toString(){

View File

@ -1,5 +1,7 @@
package de.dhbwstuttgart.sat.asp.writer.model; package de.dhbwstuttgart.sat.asp.writer.model;
import de.dhbwstuttgart.sat.asp.model.ASPRule;
public class ASPTypeVar implements ASPType{ public class ASPTypeVar implements ASPType{
private final String name; private final String name;
@ -9,7 +11,7 @@ public class ASPTypeVar implements ASPType{
@Override @Override
public String toString() { public String toString() {
return "typeVar("+ name +")"; return ASPRule.ASP_TYPE_VAR+"("+ name +")";
} }
@Override @Override

View File

@ -3,13 +3,11 @@ package de.dhbwstuttgart.syntaxtree.factory;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import de.dhbwstuttgart.exceptions.DebugException;
import de.dhbwstuttgart.exceptions.NotImplementedException; import de.dhbwstuttgart.exceptions.NotImplementedException;
import de.dhbwstuttgart.parser.NullToken; import de.dhbwstuttgart.parser.NullToken;
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.FCGenerator; import de.dhbwstuttgart.parser.SyntaxTreeGenerator.FCGenerator;
import de.dhbwstuttgart.parser.scope.JavaClassName; import de.dhbwstuttgart.parser.scope.JavaClassName;
import de.dhbwstuttgart.syntaxtree.ClassOrInterface; import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
import de.dhbwstuttgart.syntaxtree.GenericTypeVar;
import de.dhbwstuttgart.syntaxtree.type.*; import de.dhbwstuttgart.syntaxtree.type.*;
import de.dhbwstuttgart.syntaxtree.type.Void; import de.dhbwstuttgart.syntaxtree.type.Void;
import de.dhbwstuttgart.syntaxtree.type.WildcardType; import de.dhbwstuttgart.syntaxtree.type.WildcardType;
@ -35,7 +33,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.toFC(fromClasses)); return new FiniteClosure(FCGenerator.toUnifyFC(fromClasses));
} }
public static UnifyPair generateSmallerPair(UnifyType tl, UnifyType tr){ public static UnifyPair generateSmallerPair(UnifyType tl, UnifyType tr){
@ -129,10 +127,13 @@ public class UnifyTypeFactory {
UnifyPair ret = generateSmallerDotPair(UnifyTypeFactory.convert(p.TA1) UnifyPair ret = generateSmallerDotPair(UnifyTypeFactory.convert(p.TA1)
, UnifyTypeFactory.convert(p.TA2)); , UnifyTypeFactory.convert(p.TA2));
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) UnifyPair ret = generateEqualDotPair(UnifyTypeFactory.convert(p.TA1)
, UnifyTypeFactory.convert(p.TA2)); , UnifyTypeFactory.convert(p.TA2));
return ret; return ret;
}else if(p.GetOperator().equals(PairOperator.SMALLER)){
return generateSmallerPair(UnifyTypeFactory.convert(p.TA1),
UnifyTypeFactory.convert(p.TA2));
}else throw new NotImplementedException(); }else throw new NotImplementedException();
} }

View File

@ -13,16 +13,17 @@ public class BinaryExpr extends Expression
} }
public enum Operator{ public enum Operator{
ADD, ADD, // +
SUB, SUB, // -
MUL, MUL, // *
AND, MOD, // Modulo Operator %
OR, AND, // &&
DIV, OR, // ||
LESSTHAN, DIV, // /
BIGGERTHAN, LESSTHAN, // <
LESSEQUAL, BIGGERTHAN, // >
BIGGEREQUAL LESSEQUAL, // <=
BIGGEREQUAL // >=
} }
public final Operator operation; public final Operator operation;

View File

@ -9,7 +9,7 @@ public class PairTPHEqualTPH extends ResultPair<TypePlaceholder, TypePlaceholder
} }
@Override @Override
public void accept(ResultSetVisitor visitor) { public void accept(ResultPairVisitor visitor) {
visitor.visit(this); visitor.visit(this);
} }
} }

View File

@ -18,7 +18,7 @@ public class PairTPHequalRefTypeOrWildcardType extends ResultPair{
} }
@Override @Override
public void accept(ResultSetVisitor visitor) { public void accept(ResultPairVisitor visitor) {
visitor.visit(this); visitor.visit(this);
} }
} }

View File

@ -17,7 +17,7 @@ public class PairTPHsmallerTPH extends ResultPair{
} }
@Override @Override
public void accept(ResultSetVisitor visitor) { public void accept(ResultPairVisitor visitor) {
visitor.visit(this); visitor.visit(this);
} }
} }

View File

@ -9,7 +9,7 @@ public abstract class ResultPair<A extends RefTypeOrTPHOrWildcardOrGeneric,B ext
private final A left; private final A left;
private final B right; private final B right;
public abstract void accept(ResultSetVisitor visitor); public abstract void accept(ResultPairVisitor visitor);
public ResultPair(A left, B right){ public ResultPair(A left, B right){
this.left = left; this.left = left;

View File

@ -0,0 +1,7 @@
package de.dhbwstuttgart.typeinference.result;
public interface ResultPairVisitor {
void visit(PairTPHsmallerTPH p);
void visit(PairTPHequalRefTypeOrWildcardType p);
void visit(PairTPHEqualTPH p);
}

View File

@ -2,10 +2,7 @@ package de.dhbwstuttgart.typeinference.result;
import de.dhbwstuttgart.syntaxtree.type.*; import de.dhbwstuttgart.syntaxtree.type.*;
public interface ResultSetVisitor { public interface ResultSetVisitor extends ResultPairVisitor{
void visit(PairTPHsmallerTPH p);
void visit(PairTPHequalRefTypeOrWildcardType p);
void visit(PairTPHEqualTPH p);
void visit(RefType refType); void visit(RefType refType);

View File

@ -81,11 +81,6 @@ public class TYPEStmt implements StatementVisitor{
assign.rightSide.getType(), assign.lefSide.getType(), PairOperator.SMALLERDOT)); assign.rightSide.getType(), assign.lefSide.getType(), PairOperator.SMALLERDOT));
} }
@Override
public void visit(BinaryExpr binary) {
//TODO
}
@Override @Override
public void visit(Block block) { public void visit(Block block) {
for(Statement stmt : block.getStatements()){ for(Statement stmt : block.getStatements()){
@ -190,6 +185,8 @@ public class TYPEStmt implements StatementVisitor{
receiver.expr.accept(this); receiver.expr.accept(this);
} }
private final RefType number = new RefType(ASTFactory.createClass(Number.class).getClassName(), new NullToken());
private final RefType string = new RefType(ASTFactory.createClass(String.class).getClassName(), new NullToken());
@Override @Override
public void visit(UnaryExpr unaryExpr) { public void visit(UnaryExpr unaryExpr) {
if(unaryExpr.operation == UnaryExpr.Operation.POSTDECREMENT || if(unaryExpr.operation == UnaryExpr.Operation.POSTDECREMENT ||
@ -198,8 +195,7 @@ public class TYPEStmt implements StatementVisitor{
unaryExpr.operation == UnaryExpr.Operation.PREINCREMENT){ unaryExpr.operation == UnaryExpr.Operation.PREINCREMENT){
//@see: https://docs.oracle.com/javase/specs/jls/se7/html/jls-15.html#jls-15.14.2 //@see: https://docs.oracle.com/javase/specs/jls/se7/html/jls-15.html#jls-15.14.2
//Expression muss zu Numeric Convertierbar sein. also von Numeric erben //Expression muss zu Numeric Convertierbar sein. also von Numeric erben
RefType number = new RefType(ASTFactory.createClass(Number.class).getClassName(), unaryExpr.getOffset()); constraintsSet.addUndConstraint(new Pair(unaryExpr.expr.getType(), number, PairOperator.SMALLERDOT));
constraintsSet.addUndConstraint(new Pair(unaryExpr.expr.getType(), number, PairOperator.EQUALSDOT));
//The type of the postfix increment expression is the type of the variable //The type of the postfix increment expression is the type of the variable
constraintsSet.addUndConstraint(new Pair(unaryExpr.expr.getType(), unaryExpr.getType(), PairOperator.EQUALSDOT)); constraintsSet.addUndConstraint(new Pair(unaryExpr.expr.getType(), unaryExpr.getType(), PairOperator.EQUALSDOT));
}else{ }else{
@ -207,9 +203,40 @@ public class TYPEStmt implements StatementVisitor{
} }
} }
@Override
public void visit(BinaryExpr binary) {
if(binary.operation.equals(BinaryExpr.Operator.DIV) ||
binary.operation.equals(BinaryExpr.Operator.MUL)||
binary.operation.equals(BinaryExpr.Operator.MOD)||
binary.operation.equals(BinaryExpr.Operator.ADD)){
Set<Constraint> numericAdditionOrStringConcatenation = new HashSet<>();
Constraint<Pair> numeric = new Constraint<>();
//Zuerst der Fall für Numerische AusdrücPairOpnumericeratorke, das sind Mul, Mod und Div immer:
//see: https://docs.oracle.com/javase/specs/jls/se7/html/jls-15.html#jls-15.17
//Expression muss zu Numeric Convertierbar sein. also von Numeric erben
numeric.add(new Pair(binary.lexpr.getType(), number, PairOperator.SMALLERDOT));
numeric.add(new Pair(binary.rexpr.getType(), number, PairOperator.SMALLERDOT));
//The type of a multiplicative expression is the promoted type of its operands.
numeric.add(new Pair(binary.rexpr.getType(), binary.getType(), PairOperator.SMALLERDOT));
numeric.add(new Pair(binary.lexpr.getType(), binary.getType(), PairOperator.SMALLERDOT));
numericAdditionOrStringConcatenation.add(numeric);
if(binary.operation.equals(BinaryExpr.Operator.ADD)) {
//Dann kann der Ausdruck auch das aneinanderfügen zweier Strings sein: ("a" + "b") oder (1 + 2)
Constraint<Pair> stringConcat = new Constraint<>();
stringConcat.add(new Pair(binary.lexpr.getType(), string, PairOperator.EQUALSDOT));
stringConcat.add(new Pair(binary.rexpr.getType(), string, PairOperator.EQUALSDOT));
stringConcat.add(new Pair(binary.getType(), string, PairOperator.EQUALSDOT));
numericAdditionOrStringConcatenation.add(stringConcat);
}
constraintsSet.addOderConstraint(numericAdditionOrStringConcatenation);
}else {
throw new NotImplementedException();
}
}
@Override @Override
public void visit(Literal literal) { public void visit(Literal literal) {
//Nothing to do here. Literale kriegen beim parsen den korrekten Typ. //Nothing to do here. Literale erzeugen keine Constraints
} }
@Override @Override

View File

@ -0,0 +1,89 @@
package de.dhbwstuttgart.typeinference.unify;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import de.dhbwstuttgart.typeinference.unify.interfaces.IMatch;
import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType;
import de.dhbwstuttgart.typeinference.unify.model.TypeParams;
import de.dhbwstuttgart.typeinference.unify.model.Unifier;
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
import de.dhbwstuttgart.typeinference.unify.model.UnifyType;
/**
* Implementation of match derived from unification algorithm.
* @author Martin Pluemicke
*/
public class Match implements IMatch {
@Override
public Optional<Unifier> match(ArrayList<UnifyPair> termsList) {
// Start with the identity unifier. Substitutions will be added later.
Unifier mgu = Unifier.identity();
// Apply rules while possible
int idx = 0;
while(idx < termsList.size()) {
UnifyPair pair = termsList.get(idx);
UnifyType rhsType = pair.getRhsType();
UnifyType lhsType = pair.getLhsType();
TypeParams rhsTypeParams = rhsType.getTypeParams();
TypeParams lhsTypeParams = lhsType.getTypeParams();
// REDUCE - Rule
if(!(rhsType instanceof PlaceholderType) && !(lhsType instanceof PlaceholderType)) {
Set<UnifyPair> result = new HashSet<>();
// f<...> = g<...> with f != g are not unifiable
if(!rhsType.getName().equals(lhsType.getName()))
return Optional.empty(); // conflict
// f<t1,...,tn> = f<s1,...,sm> are not unifiable
if(rhsTypeParams.size() != lhsTypeParams.size())
return Optional.empty(); // conflict
// f = g is not unifiable (cannot be f = f because erase rule would have been applied)
//if(rhsTypeParams.size() == 0)
//return Optional.empty();
// Unpack the arguments
for(int i = 0; i < rhsTypeParams.size(); i++)
result.add(new UnifyPair(lhsTypeParams.get(i), rhsTypeParams.get(i), PairOperator.EQUALSDOT));
termsList.remove(idx);
termsList.addAll(result);
continue;
}
// DELETE - Rule
if(pair.getRhsType().equals(pair.getLhsType())) {
termsList.remove(idx);
continue;
}
// SWAP - Rule
if(!(lhsType instanceof PlaceholderType) && (rhsType instanceof PlaceholderType)) {
return Optional.empty(); // conflict
}
// OCCURS-CHECK
//deleted
// SUBST - Rule
if(lhsType instanceof PlaceholderType) {
mgu.add((PlaceholderType) lhsType, rhsType);
termsList = termsList.stream().map(mgu::applyleft).collect(Collectors.toCollection(ArrayList::new));
idx = idx+1 == termsList.size() ? 0 : idx+1;
continue;
}
idx++;
}
return Optional.of(mgu);
}
}

View File

@ -34,6 +34,7 @@ import de.dhbwstuttgart.typeinference.unify.model.UnifyType;
public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> { public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private static int i = 0;
/** /**
* The implementation of setOps that will be used during the unification * The implementation of setOps that will be used during the unification
@ -77,6 +78,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
/* /*
* Step 1: Repeated application of reduce, adapt, erase, swap * Step 1: Repeated application of reduce, adapt, erase, swap
*/ */
//System.out.println("Unifikation: " + eq);
Set<UnifyPair> eq0 = applyTypeUnificationRules(eq, fc); Set<UnifyPair> eq0 = applyTypeUnificationRules(eq, fc);
/* /*
@ -97,6 +99,8 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
// cartesian product of the sets created by pattern matching. // cartesian product of the sets created by pattern matching.
List<Set<Set<UnifyPair>>> topLevelSets = new ArrayList<>(); List<Set<Set<UnifyPair>>> topLevelSets = new ArrayList<>();
System.out.println(eq2s);
if(eq1s.size() != 0) { // Do not add empty sets or the cartesian product will always be empty. if(eq1s.size() != 0) { // Do not add empty sets or the cartesian product will always be empty.
Set<Set<UnifyPair>> wrap = new HashSet<>(); Set<Set<UnifyPair>> wrap = new HashSet<>();
wrap.add(eq1s); wrap.add(eq1s);
@ -134,12 +138,16 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
// Sub cartesian products of the second level (pattern matched) sets // Sub cartesian products of the second level (pattern matched) sets
// "the big (x)" // "the big (x)"
for(Set<Set<Set<UnifyPair>>> secondLevelSet : secondLevelSets) { for(Set<Set<Set<UnifyPair>>> secondLevelSet : secondLevelSets) {
//System.out.println("secondLevelSet "+secondLevelSet.size());
List<Set<Set<UnifyPair>>> secondLevelSetList = new ArrayList<>(secondLevelSet); List<Set<Set<UnifyPair>>> secondLevelSetList = new ArrayList<>(secondLevelSet);
Set<List<Set<UnifyPair>>> cartResult = setOps.cartesianProduct(secondLevelSetList); Set<List<Set<UnifyPair>>> cartResult = setOps.cartesianProduct(secondLevelSetList);
//System.out.println("CardResult: "+cartResult.size());
// Flatten and add to top level sets // Flatten and add to top level sets
Set<Set<UnifyPair>> flat = new HashSet<>(); Set<Set<UnifyPair>> flat = new HashSet<>();
int j = 0;
for(List<Set<UnifyPair>> s : cartResult) { for(List<Set<UnifyPair>> s : cartResult) {
j++;
//System.out.println("s from CardResult: "+cartResult.size() + " " + j);
Set<UnifyPair> flat1 = new HashSet<>(); Set<UnifyPair> flat1 = new HashSet<>();
for(Set<UnifyPair> s1 : s) for(Set<UnifyPair> s1 : s)
flat1.addAll(s1); flat1.addAll(s1);
@ -164,6 +172,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
/* /*
* Step 5: Substitution * Step 5: Substitution
*/ */
System.out.println("vor Subst: " + eqPrime);
Optional<Set<UnifyPair>> eqPrimePrime = rules.subst(eqPrime); Optional<Set<UnifyPair>> eqPrimePrime = rules.subst(eqPrime);
/* /*
@ -176,11 +185,13 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
//(!eqPrimePrime.isPresent()) erfolgt ist, ist das Ergebnis erzielt. //(!eqPrimePrime.isPresent()) erfolgt ist, ist das Ergebnis erzielt.
eqPrimePrimeSet.add(eqPrime); eqPrimePrimeSet.add(eqPrime);
else if(eqPrimePrime.isPresent()) { else if(eqPrimePrime.isPresent()) {
System.out.println("nextStep: " + eqPrimePrime.get());
TypeUnifyTask fork = new TypeUnifyTask(eqPrimePrime.get(), fc, true); TypeUnifyTask fork = new TypeUnifyTask(eqPrimePrime.get(), fc, true);
forks.add(fork); forks.add(fork);
fork.fork(); fork.fork();
} }
else { else {
System.out.println("nextStep: " + eqPrime);
TypeUnifyTask fork = new TypeUnifyTask(eqPrime, fc, true); TypeUnifyTask fork = new TypeUnifyTask(eqPrime, fc, true);
forks.add(fork); forks.add(fork);
fork.fork(); fork.fork();
@ -381,9 +392,12 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
UnifyType rhsType = pair.getRhsType(); UnifyType rhsType = pair.getRhsType();
// Case 1: (a <. Theta') // Case 1: (a <. Theta')
if(pairOp == PairOperator.SMALLERDOT && lhsType instanceof PlaceholderType) if(pairOp == PairOperator.SMALLERDOT && lhsType instanceof PlaceholderType) {
result.get(0).add(unifyCase1((PlaceholderType) pair.getLhsType(), pair.getRhsType(), fc)); System.out.println(pair);
Set<Set<UnifyPair>> x1 = unifyCase1((PlaceholderType) pair.getLhsType(), pair.getRhsType(), fc);
System.out.println(x1);
result.get(0).add(x1);
}
// Case 2: (a <.? ? ext Theta') // Case 2: (a <.? ? ext Theta')
else if(pairOp == PairOperator.SMALLERDOTWC && lhsType instanceof PlaceholderType && rhsType instanceof ExtendsType) else if(pairOp == PairOperator.SMALLERDOTWC && lhsType instanceof PlaceholderType && rhsType instanceof ExtendsType)
result.get(1).add(unifyCase2((PlaceholderType) pair.getLhsType(), (ExtendsType) pair.getRhsType(), fc)); result.get(1).add(unifyCase2((PlaceholderType) pair.getLhsType(), (ExtendsType) pair.getRhsType(), fc));
@ -442,13 +456,24 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
break; break;
} }
Set<UnifyType> cs = fc.getAllTypesByName(thetaPrime.getName()); Set<UnifyType> cs = fc.getAllTypesByName(thetaPrime.getName());//cs= [java.util.Vector<NP>, java.util.Vector<java.util.Vector<java.lang.Integer>>, ????java.util.Vector<gen_hv>???]
cs.add(thetaPrime);
//PL 18-02-06 entfernt, kommt durch unify wieder rein
//cs.add(thetaPrime);
//PL 18-02-06 entfernt
for(UnifyType c : cs) { for(UnifyType c : cs) {
Set<UnifyType> thetaQs = fc.getChildren(c).stream().collect(Collectors.toCollection(HashSet::new)); //PL 18-02-05 getChildren durch smaller ersetzt in getChildren werden die Varianlen nicht ersetzt.
thetaQs.add(thetaPrime); //PL 2017-10-03: War auskommentiert habe ich wieder einkommentiert, Set<UnifyType> thetaQs = fc.smaller(c).stream().collect(Collectors.toCollection(HashSet::new));
//da children offensichtlich ein echtes kleiner und kein kleinergleich ist //Set<UnifyType> thetaQs = fc.getChildren(c).stream().collect(Collectors.toCollection(HashSet::new));
//thetaQs.add(thetaPrime); //PL 18-02-05 wieder geloescht
//PL 2017-10-03: War auskommentiert habe ich wieder einkommentiert,
//da children offensichtlich ein echtes kleiner und kein kleinergleich ist
//PL 18-02-06: eingefuegt, thetaQs der Form V<V<...>> <. V'<V<...>> werden entfernt
thetaQs = thetaQs.stream().filter(ut -> ut.getTypeParams().arePlaceholders()).collect(Collectors.toCollection(HashSet::new));
//PL 18-02-06: eingefuegt
Set<UnifyType> thetaQPrimes = new HashSet<>(); Set<UnifyType> thetaQPrimes = new HashSet<>();
TypeParams cParams = c.getTypeParams(); TypeParams cParams = c.getTypeParams();
if(cParams.size() == 0) if(cParams.size() == 0)
@ -464,6 +489,11 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
} }
for(UnifyType tqp : thetaQPrimes) { for(UnifyType tqp : thetaQPrimes) {
//System.out.println(tqp.toString());
//i++;
//System.out.println(i);
//if (i == 62)
// System.out.println(tqp.toString());
Optional<Unifier> opt = stdUnify.unify(tqp, thetaPrime); Optional<Unifier> opt = stdUnify.unify(tqp, thetaPrime);
if (!opt.isPresent()) if (!opt.isPresent())
continue; continue;
@ -474,10 +504,11 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
for (Entry<PlaceholderType, UnifyType> sigma : unifier) for (Entry<PlaceholderType, UnifyType> sigma : unifier)
substitutionSet.add(new UnifyPair(sigma.getKey(), sigma.getValue(), PairOperator.EQUALSDOT)); substitutionSet.add(new UnifyPair(sigma.getKey(), sigma.getValue(), PairOperator.EQUALSDOT));
List<UnifyType> freshTphs = new ArrayList<>(); //List<UnifyType> freshTphs = new ArrayList<>(); PL 18-02-06 in die For-Schleife verschoben
for (UnifyType tq : thetaQs) { for (UnifyType tq : thetaQs) {
Set<UnifyType> smaller = fc.smaller(unifier.apply(tq)); Set<UnifyType> smaller = fc.smaller(unifier.apply(tq));
for(UnifyType theta : smaller) { for(UnifyType theta : smaller) {
List<UnifyType> freshTphs = new ArrayList<>();
Set<UnifyPair> resultPrime = new HashSet<>(); Set<UnifyPair> resultPrime = new HashSet<>();
for(int i = 0; !allGen && i < theta.getTypeParams().size(); i++) { for(int i = 0; !allGen && i < theta.getTypeParams().size(); i++) {

View File

@ -0,0 +1,35 @@
package de.dhbwstuttgart.typeinference.unify.interfaces;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import de.dhbwstuttgart.typeinference.unify.model.UnifyType;
import de.dhbwstuttgart.typeinference.unify.model.Unifier;
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
/**
* Match
* @author Martin Pluemicke
*/
public interface IMatch {
/**
* Finds the most general unifier sigma of the set {t1,...,tn} so that
* sigma(t1) = sigma(t2) = ... = sigma(tn).
* @param terms The set of terms to be unified
* @return An optional of the most general unifier if it exists or an empty optional if there is no unifier.
*/
public Optional<Unifier> match(ArrayList<UnifyPair> termsList);
/**
* Finds the most general unifier sigma of the set {t1,...,tn} so that
* sigma(t1) = sigma(t2) = ... = sigma(tn).
* @param terms The set of terms to be unified
* @return An optional of the most general unifier if it exists or an empty optional if there is no unifier.
*/
}

View File

@ -8,7 +8,11 @@ import java.util.Optional;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
//PL 18-02-05 Unifier durch Matcher ersetzt
//mus greater noch erstezt werden
import de.dhbwstuttgart.typeinference.unify.MartelliMontanariUnify; import de.dhbwstuttgart.typeinference.unify.MartelliMontanariUnify;
import de.dhbwstuttgart.typeinference.unify.Match;
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure; import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
import de.dhbwstuttgart.typeinference.unify.interfaces.IUnify; import de.dhbwstuttgart.typeinference.unify.interfaces.IUnify;
@ -46,6 +50,13 @@ public class FiniteClosure implements IFiniteClosure {
if(pair.getPairOp() != PairOperator.SMALLER) if(pair.getPairOp() != PairOperator.SMALLER)
continue; continue;
//VERSUCH PL 18-02-06
//koennte ggf. die FC reduzieren
//TO DO: Ueberpruefen, ob das sinnvll und korrekt ist
//if (!pair.getLhsType().getTypeParams().arePlaceholders()
// && !pair.getRhsType().getTypeParams().arePlaceholders())
// continue;
;
// Add nodes if not already in the graph // Add nodes if not already in the graph
if(!inheritanceGraph.containsKey(pair.getLhsType())) if(!inheritanceGraph.containsKey(pair.getLhsType()))
inheritanceGraph.put(pair.getLhsType(), new Node<UnifyType>(pair.getLhsType())); inheritanceGraph.put(pair.getLhsType(), new Node<UnifyType>(pair.getLhsType()));
@ -93,7 +104,9 @@ public class FiniteClosure implements IFiniteClosure {
private Set<UnifyType> computeSmaller(Set<UnifyType> types) { private Set<UnifyType> computeSmaller(Set<UnifyType> types) {
HashSet<UnifyType> result = new HashSet<>(); HashSet<UnifyType> result = new HashSet<>();
IUnify unify = new MartelliMontanariUnify(); //PL 18-02-05 Unifier durch Matcher ersetzt
//IUnify unify = new MartelliMontanariUnify();
Match match = new Match();
for(UnifyType t : types) { for(UnifyType t : types) {
@ -112,10 +125,16 @@ public class FiniteClosure implements IFiniteClosure {
continue; continue;
// if T <* T' then sigma(T) <* sigma(T') // if T <* T' then sigma(T) <* sigma(T')
Set<Node<UnifyType>> candidates = strInheritanceGraph.get(t.getName()); Set<Node<UnifyType>> candidates = strInheritanceGraph.get(t.getName()); //cadidates= [???Node(java.util.Vector<java.util.Vector<java.lang.Integer>>)???
// , Node(java.util.Vector<gen_hv>)
//]
for(Node<UnifyType> candidate : candidates) { for(Node<UnifyType> candidate : candidates) {
UnifyType theta2 = candidate.getContent(); UnifyType theta2 = candidate.getContent();
Optional<Unifier> optSigma = unify.unify(theta2, t); //PL 18-02-05 Unifier durch Matcher ersetzt ANFANG
ArrayList<UnifyPair> termList= new ArrayList<UnifyPair>();
termList.add(new UnifyPair(theta2,t, PairOperator.EQUALSDOT));
Optional<Unifier> optSigma = match.match(termList);
//PL 18-02-05 Unifier durch Matcher ersetzt ENDE
if(!optSigma.isPresent()) if(!optSigma.isPresent())
continue; continue;

View File

@ -94,6 +94,7 @@ class Node<T> {
@Override @Override
public String toString() { public String toString() {
return "Node(" + content.toString() + ")\n"; return "Elem: Node(" + content.toString() + ")\nPrec: " + getContentOfPredecessors().toString()
+ "\nDesc: " + getContentOfDescendants().toString() + "\n\n";
} }
} }

View File

@ -102,9 +102,9 @@ public final class TypeParams implements Iterable<UnifyType>{
if(p.equals(t)) if(p.equals(t))
return true; return true;
} }
else else {
if(p.getTypeParams().occurs(t)) if(p.getTypeParams().occurs(t))
return true; return true; }
return false; return false;
} }

View File

@ -66,6 +66,14 @@ public class Unifier implements Function<UnifyType, UnifyType>, Iterable<Entry<P
return new UnifyPair(this.apply(p.getLhsType()), this.apply(p.getRhsType()), p.getPairOp()); return new UnifyPair(this.apply(p.getLhsType()), this.apply(p.getRhsType()), p.getPairOp());
} }
/**
* Applies the unifier to the left terms of the pair.
* @return A new pair where the left and right-hand side are applied
*/
public UnifyPair applyleft(UnifyPair p) {
return new UnifyPair(this.apply(p.getLhsType()), p.getRhsType(), p.getPairOp());
}
/** /**
* True if the typevariable t will be substituted if the unifier is applied. * True if the typevariable t will be substituted if the unifier is applied.
* false otherwise. * false otherwise.

View File

@ -1,25 +1,30 @@
package asp; package asp;
import de.dhbwstuttgart.parser.NullToken; import de.dhbwstuttgart.parser.NullToken;
import de.dhbwstuttgart.sat.asp.parser.ASPParser;
import de.dhbwstuttgart.sat.asp.writer.ASPGenerator; import de.dhbwstuttgart.sat.asp.writer.ASPGenerator;
import de.dhbwstuttgart.sat.asp.Clingo; import de.dhbwstuttgart.sat.asp.Clingo;
import de.dhbwstuttgart.syntaxtree.ClassOrInterface; import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
import de.dhbwstuttgart.syntaxtree.factory.ASTFactory; import de.dhbwstuttgart.syntaxtree.factory.ASTFactory;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder; import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet; import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
import de.dhbwstuttgart.typeinference.constraints.Pair; import de.dhbwstuttgart.typeinference.constraints.Pair;
import de.dhbwstuttgart.typeinference.result.ResultSet;
import de.dhbwstuttgart.typeinference.unify.model.PairOperator; import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
import org.junit.Test; import org.junit.Test;
import javax.json.Json;
import javax.json.JsonObject;
import java.io.*; import java.io.*;
import java.util.*; import java.util.*;
public class ClingoTest { public class ClingoTest {
public static final String rootDirectory = "~/Sync/HiwiJob/ResearchPapers/MasterarbeitStadelmeier/asp/unifyWithoutWildcards"; public static final String rootDirectory = "~/Sync/HiwiJob/ResearchPapers/MasterarbeitStadelmeier/asp/unifyWithoutWildcards";
public static final String tempDirectory = "/tmp/"; public static final String tempDirectory = "/tmp/";
private final TypePlaceholder testType = TypePlaceholder.fresh(new NullToken());
@Test @Test
public void test() throws IOException, InterruptedException { public void test() throws IOException, InterruptedException, ClassNotFoundException {
String content = ""; String content = "";
content = new ASPGenerator(this.getPairs(), this.getFC()).getASP(); content = new ASPGenerator(this.getPairs(), this.getFC()).getASP();
@ -28,19 +33,21 @@ public class ClingoTest {
writer.close(); writer.close();
Clingo clingo = new Clingo(Arrays.asList(new File(tempDirectory + "test.lp"))); Clingo clingo = new Clingo(Arrays.asList(new File(tempDirectory + "test.lp")));
System.out.println(clingo.runClingo()); String result = clingo.runClingo();
System.out.println(result);
ResultSet resultSet = ASPParser.parse(result, Arrays.asList(testType));
RefTypeOrTPHOrWildcardOrGeneric resolvedType = resultSet.resolveType(testType).resolvedType;
assert resolvedType.toString().equals(ASTFactory.createObjectType().toString());
} }
public Collection<ClassOrInterface> getFC() { public Collection<ClassOrInterface> getFC() {
Set<ClassOrInterface> ret = new HashSet<>(); Set<ClassOrInterface> ret = new HashSet<>();
ret.add(ASTFactory.createObjectClass());
ret.add(ASTFactory.createClass(java.util.List.class));
return ret; return ret;
} }
public ConstraintSet<Pair> getPairs() { public ConstraintSet<Pair> getPairs() {
ConstraintSet<Pair> ret = new ConstraintSet<>(); ConstraintSet<Pair> ret = new ConstraintSet<>();
ret.addUndConstraint(new Pair(TypePlaceholder.fresh(new NullToken()), ASTFactory.createObjectType(), PairOperator.SMALLERDOT)); ret.addUndConstraint(new Pair(testType, ASTFactory.createObjectType(), PairOperator.EQUALSDOT));
return ret; return ret;
} }
} }

View File

@ -0,0 +1,29 @@
package asp;
import de.dhbwstuttgart.parser.NullToken;
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
import de.dhbwstuttgart.syntaxtree.factory.ASTFactory;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
import de.dhbwstuttgart.typeinference.constraints.Pair;
import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
public class UnifyWithoutWildcards {
public Collection<ClassOrInterface> getFC() {
Set<ClassOrInterface> ret = new HashSet<>();
ret.add(ASTFactory.createObjectClass());
ret.add(ASTFactory.createClass(java.util.List.class));
return ret;
}
public ConstraintSet<Pair> getPairs() {
ConstraintSet<Pair> ret = new ConstraintSet<>();
ret.addUndConstraint(new Pair(TypePlaceholder.fresh(new NullToken()), ASTFactory.createObjectType(), PairOperator.SMALLERDOT));
return ret;
}
}

View File

@ -14,7 +14,9 @@ import java.nio.charset.Charset;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set;
public class ASPTest { public class ASPTest {
@ -44,9 +46,9 @@ public class ASPTest {
//filesToTest.add(new File(rootDirectory+"Matrix.jav")); //filesToTest.add(new File(rootDirectory+"Matrix.jav"));
//filesToTest.add(new File(rootDirectory+"Import.jav")); //filesToTest.add(new File(rootDirectory+"Import.jav"));
JavaTXCompiler compiler = new JavaTXCompiler(fileToTest); JavaTXCompiler compiler = new JavaTXCompiler(fileToTest);
List<ClassOrInterface> allClasses = new ArrayList<>(); Set<ClassOrInterface> allClasses = new HashSet<>();
for(SourceFile sf : compiler.sourceFiles.values()) { for(SourceFile sf : compiler.sourceFiles.values()) {
//allClasses.addAll(compiler.getAvailableClasses(sf)); allClasses.addAll(compiler.getAvailableClasses(sf));
} }
for(SourceFile sf : compiler.sourceFiles.values()) { for(SourceFile sf : compiler.sourceFiles.values()) {
allClasses.addAll(sf.getClasses()); allClasses.addAll(sf.getClasses());

View File

@ -0,0 +1,8 @@
class Expressions{
void test(){
var x = 2;
x = x + 2;
}
}

View File

@ -6,21 +6,21 @@ class Matrix extends Vector<Vector<Integer>> {
mul(m) { mul(m) {
var ret = new Matrix(); var ret = new Matrix();
var i = 0; var i = 0;
while(i < size()) { //while(i < size()) {
var v1 = this.elementAt(i); var v1 = this.elementAt(i);
var v2 = new Vector<Integer>(); //var v2 = new Vector<Integer>();
var j = 0; //var j = 0;
while(j < v1.size()) { //while(j < v1.size()) {
var erg = 0; //var erg = 0;
var k = 0; //var k = 0;
while(k < v1.size()) { //while(k < v1.size()) {
erg = erg + v1.elementAt(k) //erg = erg + v1.elementAt(k)
* m.elementAt(k).elementAt(j); // * m.elementAt(k).elementAt(j);
k++; } //k++; }
v2.addElement(new Integer(erg)); //v2.addElement(new Integer(erg));
j++; } //j++; }
ret.addElement(v2); //ret.addElement(v2);
i++; } //i++; }
return ret; return ret;
} }
} }

View File

@ -1,9 +0,0 @@
package typeinference;
import java.io.File;
public class FacultyTest extends JavaTXCompilerTest{
public FacultyTest() {
this.fileToTest = new File(rootDirectory+"Faculty.jav");
}
}

View File

@ -1,9 +0,0 @@
package typeinference;
import java.io.File;
public class FiniteClosureTest extends JavaTXCompilerTest{
public FiniteClosureTest() {
// this.fileToTest = new File(rootDirectory+"fc.jav");
}
}

View File

@ -1,10 +0,0 @@
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");
}
}

View File

@ -23,19 +23,57 @@ import java.util.Set;
public class JavaTXCompilerTest { public class JavaTXCompilerTest {
public static final String rootDirectory = System.getProperty("user.dir")+"/test/javFiles/"; public static final String rootDirectory = System.getProperty("user.dir")+"/test/javFiles/";
private static final List<File> filesToTest = new ArrayList<>();
protected File fileToTest = null;
public JavaTXCompilerTest(){ @Test
public void finiteClosure() throws IOException, ClassNotFoundException {
execute(new File(rootDirectory+"fc.jav"));
} }
@Test @Test
public void test() throws IOException, ClassNotFoundException { public void lambda() throws IOException, ClassNotFoundException {
if(fileToTest != null)filesToTest.add(fileToTest); execute(new File(rootDirectory+"Lambda.jav"));
else return; }
//filesToTest.add(new File(rootDirectory+"Faculty.jav")); @Test
//filesToTest.add(new File(rootDirectory+"mathStruc.jav")); public void lambda2() throws IOException, ClassNotFoundException {
//filesToTest.add(new File(rootDirectory+"test.jav")); execute(new File(rootDirectory+"Lambda2.jav"));
filesToTest.add(new File(rootDirectory+"EmptyMethod.jav")); }
@Test
public void lambda3() throws IOException, ClassNotFoundException {
execute(new File(rootDirectory+"Lambda3.jav"));
}
@Test
public void mathStruc() throws IOException, ClassNotFoundException {
execute(new File(rootDirectory+"mathStruc.jav"));
}
@Test
public void generics() throws IOException, ClassNotFoundException {
execute(new File(rootDirectory+"Generics.jav"));
}
@Test
public void faculty() throws IOException, ClassNotFoundException {
execute(new File(rootDirectory+"Faculty.jav"));
}
@Test
public void matrix() throws IOException, ClassNotFoundException {
execute(new File(rootDirectory+"Matrix.jav"));
}
@Test
public void vector() throws IOException, ClassNotFoundException {
execute(new File(rootDirectory+"Vector.jav"));
}
@Test
public void lambdaRunnable() throws IOException, ClassNotFoundException {
execute(new File(rootDirectory+"LambdaRunnable.jav"));
}
@Test
public void expressions() throws IOException, ClassNotFoundException {
execute(new File(rootDirectory+"Expressions.jav"));
}
private static class TestResultSet{
}
public TestResultSet execute(File fileToTest) throws IOException, ClassNotFoundException {
//filesToTest.add(new File(rootDirectory+"fc.jav")); //filesToTest.add(new File(rootDirectory+"fc.jav"));
//filesToTest.add(new File(rootDirectory+"Lambda.jav")); //filesToTest.add(new File(rootDirectory+"Lambda.jav"));
//filesToTest.add(new File(rootDirectory+"Lambda2.jav")); //filesToTest.add(new File(rootDirectory+"Lambda2.jav"));
@ -45,6 +83,9 @@ public class JavaTXCompilerTest {
//filesToTest.add(new File(rootDirectory+"MethodsEasy.jav")); //filesToTest.add(new File(rootDirectory+"MethodsEasy.jav"));
//filesToTest.add(new File(rootDirectory+"Matrix.jav")); //filesToTest.add(new File(rootDirectory+"Matrix.jav"));
//filesToTest.add(new File(rootDirectory+"Import.jav")); //filesToTest.add(new File(rootDirectory+"Import.jav"));
// //filesToTest.add(new File(rootDirectory+"Faculty.jav"));
// //filesToTest.add(new File(rootDirectory+"mathStruc.jav"));
// //filesToTest.add(new File(rootDirectory+"test.jav"));
JavaTXCompiler compiler = new JavaTXCompiler(fileToTest); JavaTXCompiler compiler = new JavaTXCompiler(fileToTest);
List<ResultSet> results = compiler.typeInference(); List<ResultSet> results = compiler.typeInference();
@ -68,6 +109,7 @@ public class JavaTXCompilerTest {
System.out.println(s); System.out.println(s);
} }
} }
return new TestResultSet();
} }
static String readFile(String path, Charset encoding) static String readFile(String path, Charset encoding)

View File

@ -1,9 +0,0 @@
package typeinference;
import java.io.File;
public class Lambda2Test extends JavaTXCompilerTest{
public Lambda2Test() {
this.fileToTest = new File(rootDirectory+"Lambda2.jav");
}
}

View File

@ -1,9 +0,0 @@
package typeinference;
import java.io.File;
public class Lambda3Test extends JavaTXCompilerTest{
public Lambda3Test() {
this.fileToTest = new File(rootDirectory+"Lambda3.jav");
}
}

View File

@ -1,9 +0,0 @@
package typeinference;
import java.io.File;
public class LambdaTest extends JavaTXCompilerTest{
public LambdaTest() {
this.fileToTest = new File(rootDirectory+"Lambda.jav");
}
}

View File

@ -1,9 +0,0 @@
package typeinference;
import java.io.File;
public class MatrixTest extends JavaTXCompilerTest{
public MatrixTest() {
this.fileToTest = new File(rootDirectory+"Matrix.jav");
}
}

View File

@ -1,9 +0,0 @@
package typeinference;
import java.io.File;
public class RunnableTest extends JavaTXCompilerTest{
public RunnableTest() {
this.fileToTest = new File(rootDirectory+"LambdaRunnable.jav");
}
}

View File

@ -1,9 +0,0 @@
package typeinference;
import java.io.File;
public class VectorTest extends JavaTXCompilerTest{
public VectorTest() {
this.fileToTest = new File(rootDirectory+"Vector.jav");
}
}

View File

@ -1,9 +0,0 @@
package typeinference;
import java.io.File;
public class mathStrucTest extends JavaTXCompilerTest{
public mathStrucTest() {
this.fileToTest = new File(rootDirectory+"mathStruc.jav");
}
}