diff --git a/maven-repository/de/dhbwstuttgart/JavaTXcompiler/0.1/JavaTXcompiler-0.1.jar.md5 b/maven-repository/de/dhbwstuttgart/JavaTXcompiler/0.1/JavaTXcompiler-0.1.jar.md5 new file mode 100644 index 00000000..010e8d91 --- /dev/null +++ b/maven-repository/de/dhbwstuttgart/JavaTXcompiler/0.1/JavaTXcompiler-0.1.jar.md5 @@ -0,0 +1 @@ +5da32a6f73bb3ccac5dc264606071605 \ No newline at end of file diff --git a/maven-repository/de/dhbwstuttgart/JavaTXcompiler/0.1/JavaTXcompiler-0.1.jar.sha1 b/maven-repository/de/dhbwstuttgart/JavaTXcompiler/0.1/JavaTXcompiler-0.1.jar.sha1 new file mode 100644 index 00000000..d56be4c6 --- /dev/null +++ b/maven-repository/de/dhbwstuttgart/JavaTXcompiler/0.1/JavaTXcompiler-0.1.jar.sha1 @@ -0,0 +1 @@ +bcb7e8eb537f65ec0110731a924a3d4d3bba7805 \ No newline at end of file diff --git a/maven-repository/de/dhbwstuttgart/JavaTXcompiler/0.1/JavaTXcompiler-0.1.pom b/maven-repository/de/dhbwstuttgart/JavaTXcompiler/0.1/JavaTXcompiler-0.1.pom new file mode 100644 index 00000000..ac9984f4 --- /dev/null +++ b/maven-repository/de/dhbwstuttgart/JavaTXcompiler/0.1/JavaTXcompiler-0.1.pom @@ -0,0 +1,8 @@ + + + 4.0.0 + de.dhbwstuttgart + JavaTXcompiler + 0.1 + diff --git a/maven-repository/de/dhbwstuttgart/JavaTXcompiler/0.1/JavaTXcompiler-0.1.pom.md5 b/maven-repository/de/dhbwstuttgart/JavaTXcompiler/0.1/JavaTXcompiler-0.1.pom.md5 new file mode 100644 index 00000000..f86629e3 --- /dev/null +++ b/maven-repository/de/dhbwstuttgart/JavaTXcompiler/0.1/JavaTXcompiler-0.1.pom.md5 @@ -0,0 +1 @@ +a909ae513fbc19ba7c25b0cbb9871db6 \ No newline at end of file diff --git a/maven-repository/de/dhbwstuttgart/JavaTXcompiler/0.1/JavaTXcompiler-0.1.pom.sha1 b/maven-repository/de/dhbwstuttgart/JavaTXcompiler/0.1/JavaTXcompiler-0.1.pom.sha1 new file mode 100644 index 00000000..f3611f50 --- /dev/null +++ b/maven-repository/de/dhbwstuttgart/JavaTXcompiler/0.1/JavaTXcompiler-0.1.pom.sha1 @@ -0,0 +1 @@ +4863f156f9b2754ccff7128ff372a8e1e11ee0f8 \ No newline at end of file diff --git a/maven-repository/de/dhbwstuttgart/JavaTXcompiler/maven-metadata.xml b/maven-repository/de/dhbwstuttgart/JavaTXcompiler/maven-metadata.xml new file mode 100644 index 00000000..bdf2c955 --- /dev/null +++ b/maven-repository/de/dhbwstuttgart/JavaTXcompiler/maven-metadata.xml @@ -0,0 +1,12 @@ + + + de.dhbwstuttgart + JavaTXcompiler + + 0.1 + + 0.1 + + 20180119143709 + + diff --git a/maven-repository/de/dhbwstuttgart/JavaTXcompiler/maven-metadata.xml.md5 b/maven-repository/de/dhbwstuttgart/JavaTXcompiler/maven-metadata.xml.md5 new file mode 100644 index 00000000..10c960f2 --- /dev/null +++ b/maven-repository/de/dhbwstuttgart/JavaTXcompiler/maven-metadata.xml.md5 @@ -0,0 +1 @@ +f023e768b9a1e74695541c63858fa86c \ No newline at end of file diff --git a/maven-repository/de/dhbwstuttgart/JavaTXcompiler/maven-metadata.xml.sha1 b/maven-repository/de/dhbwstuttgart/JavaTXcompiler/maven-metadata.xml.sha1 new file mode 100644 index 00000000..74223164 --- /dev/null +++ b/maven-repository/de/dhbwstuttgart/JavaTXcompiler/maven-metadata.xml.sha1 @@ -0,0 +1 @@ +705a6736ea0a93b18743edd577dcb3c5e6dd518e \ No newline at end of file diff --git a/pom.xml b/pom.xml index 9f184c4f..b435e6c5 100644 --- a/pom.xml +++ b/pom.xml @@ -53,7 +53,7 @@ target target/classes - ${artifactId}-${version} + ${project.artifactId}-${project.version} target/test-classes src/ test/ @@ -96,7 +96,8 @@ org.apache.maven.plugins - maven-compiler-plugin + maven-compiler-plugin + 2.3.2 8 8 diff --git a/src/de/dhbwstuttgart/core/JavaTXCompiler.java b/src/de/dhbwstuttgart/core/JavaTXCompiler.java index 106411f6..92c1d98b 100644 --- a/src/de/dhbwstuttgart/core/JavaTXCompiler.java +++ b/src/de/dhbwstuttgart/core/JavaTXCompiler.java @@ -7,6 +7,7 @@ import de.dhbwstuttgart.parser.scope.GenericsRegistry; import de.dhbwstuttgart.parser.SyntaxTreeGenerator.SyntaxTreeGenerator; import de.dhbwstuttgart.parser.antlr.Java8Parser.CompilationUnitContext; import de.dhbwstuttgart.parser.scope.JavaClassName; +import de.dhbwstuttgart.sat.asp.ASPUnify; import de.dhbwstuttgart.sat.asp.ASPUnifyWithoutWildcards; import de.dhbwstuttgart.sat.asp.parser.ASPParser; import de.dhbwstuttgart.sat.asp.writer.ASPFactory; @@ -141,14 +142,14 @@ public class JavaTXCompiler { final ConstraintSet cons = getConstraints(); - + System.out.println(cons); String content = ""; content = ASPFactory.generateASP(cons, allClasses); final String tempDirectory = "/tmp/"; PrintWriter writer = new PrintWriter(tempDirectory + "test.lp", "UTF-8"); writer.println(content); writer.close(); - ASPUnifyWithoutWildcards clingo = new ASPUnifyWithoutWildcards(Arrays.asList(new File(tempDirectory + "test.lp"))); + ASPUnify clingo = new ASPUnify(Arrays.asList(new File(tempDirectory + "test.lp"))); String result = clingo.runClingo(); System.out.println(result); ResultSet resultSet = ASPParser.parse(result, getInvolvedTPHS(cons)); diff --git a/src/de/dhbwstuttgart/sat/asp/ASPUnify.java b/src/de/dhbwstuttgart/sat/asp/ASPUnify.java new file mode 100644 index 00000000..2b93776b --- /dev/null +++ b/src/de/dhbwstuttgart/sat/asp/ASPUnify.java @@ -0,0 +1,55 @@ +package de.dhbwstuttgart.sat.asp; + + +import org.apache.commons.io.IOUtils; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + +public class ASPUnify { + private final List input; + private static final List programFiles = new ArrayList<>(); + static{ + programFiles.add(new File("/home/janulrich/Sync/HiwiJob/ResearchPapers/MasterarbeitStadelmeier/asp/complete/fc.lp")); + programFiles.add(new File("/home/janulrich/Sync/HiwiJob/ResearchPapers/MasterarbeitStadelmeier/asp/complete/reduceRules.lp")); + programFiles.add(new File("/home/janulrich/Sync/HiwiJob/ResearchPapers/MasterarbeitStadelmeier/asp/complete/adaptRules.lp")); + programFiles.add(new File("/home/janulrich/Sync/HiwiJob/ResearchPapers/MasterarbeitStadelmeier/asp/complete/step4.lp")); + programFiles.add(new File("/home/janulrich/Sync/HiwiJob/ResearchPapers/MasterarbeitStadelmeier/asp/complete/subst.lp")); + programFiles.add(new File("/home/janulrich/Sync/HiwiJob/ResearchPapers/MasterarbeitStadelmeier/asp/complete/unifikation.lp")); + } + + public ASPUnify(List 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 { + String pathToClingo = + "clingo"; + List commands = new ArrayList<>(); + commands.add(pathToClingo); + //commands.add("--outf=2"); //use JSON-Output + commands.add("--outf=1"); //use Text-Output + commands.add("-n 0"); //Compute all models + for(File file : input){ + commands.add(file.getPath()); + } + commands.addAll(programFiles.stream().map(f->f.getPath()).collect(Collectors.toList())); + + commands.stream().forEach(s -> System.out.print(s + " ")); + System.out.println(); + + Process clingo = new ProcessBuilder( commands.toArray(new String[0])).start(); + InputStream output = clingo.getInputStream(); + clingo.waitFor(); + String result = IOUtils.toString(output, StandardCharsets.UTF_8); + return result; + } +} diff --git a/src/de/dhbwstuttgart/sat/asp/Clingo.java b/src/de/dhbwstuttgart/sat/asp/Clingo.java index d4fdcc4b..c1536da1 100644 --- a/src/de/dhbwstuttgart/sat/asp/Clingo.java +++ b/src/de/dhbwstuttgart/sat/asp/Clingo.java @@ -27,7 +27,7 @@ public class Clingo { */ public String runClingo() throws IOException, InterruptedException { String pathToClingo = - "/home/janulrich/Sync/HiwiJob/ResearchPapers/MasterarbeitStadelmeier/asp/clingo-5.2.1-linux-x86_64/clingo"; + "clingo"; List commands = new ArrayList<>(); commands.add(pathToClingo); //commands.add("--outf=2"); //use JSON-Output diff --git a/src/de/dhbwstuttgart/sat/asp/model/ASPRule.java b/src/de/dhbwstuttgart/sat/asp/model/ASPRule.java index d4177e25..02ce6b1e 100644 --- a/src/de/dhbwstuttgart/sat/asp/model/ASPRule.java +++ b/src/de/dhbwstuttgart/sat/asp/model/ASPRule.java @@ -7,9 +7,7 @@ public enum ASPRule { ASP_PAIR_SMALLER_NAME("smaller"), ASP_PAIR_SMALLER_DOT_NAME("smallerDot"), ASP_PARAMLIST_NAME("param"), - ASP_FC_PARAMLIST_NAME("paramFC"), ASP_TYPE("type"), - ASP_FCTYPE("typeFC"), ASP_TYPE_VAR("typeVar"), ASP_ODER("oder"), ASP_CONSTRAINT("constraint"), ASP_LIST_NAME("list"), diff --git a/src/de/dhbwstuttgart/sat/asp/parser/ASPParser.java b/src/de/dhbwstuttgart/sat/asp/parser/ASPParser.java index 80ff707b..7a43a123 100644 --- a/src/de/dhbwstuttgart/sat/asp/parser/ASPParser.java +++ b/src/de/dhbwstuttgart/sat/asp/parser/ASPParser.java @@ -9,7 +9,9 @@ import de.dhbwstuttgart.sat.asp.model.ASPRule; import de.dhbwstuttgart.sat.asp.parser.antlr.*; import de.dhbwstuttgart.sat.asp.parser.model.ParsedType; import de.dhbwstuttgart.syntaxtree.type.*; +import de.dhbwstuttgart.typeinference.constraints.Pair; import de.dhbwstuttgart.typeinference.result.*; +import de.dhbwstuttgart.typeinference.unify.model.PairOperator; import org.antlr.v4.runtime.CharStreams; import org.antlr.v4.runtime.CommonTokenStream; import org.antlr.v4.runtime.tree.ParseTreeWalker; @@ -40,13 +42,6 @@ public class ASPParser extends ASPResultBaseListener { return new ASPParser(toParse, oldPlaceholders).resultSet; } - @Override - public void enterParameter(UnifyResultParser.ParameterContext ctx) { - //Linked List (pointer, Type, nextPointer) - List params = parseParameterList(ctx.parameterList()); - parameterLists.put(params.get(0), new ParameterListNode(params.get(1), params.get(2))); - } - private static class Relation { public final String right; public final String left; @@ -76,67 +71,71 @@ public class ASPParser extends ASPResultBaseListener { ).collect(Collectors.toList()); } - @Override - public void enterUnifier(UnifyResultParser.UnifierContext ctx) { - List parameterList = parseParameterList(ctx.parameterList()); - if(parameterList.size()<2)throw new DebugException("Fehler in Unifier-Regel"); - String ls = parameterList.get(0); - String rs = parameterList.get(1); - unifierRelations.add(new Relation(ls, rs)); - - } - - @Override - public void enterSmaller(UnifyResultParser.SmallerContext ctx) { - List parameterList = parseParameterList(ctx.parameterList()); - if(parameterList.size()<2)throw new DebugException("Fehler in Smaller-Regel"); - String ls = parameterList.get(0); - String rs = parameterList.get(1); - smallerRelations.add(new Relation(ls, rs)); - } - - @Override - public void enterTypeVar(UnifyResultParser.TypeVarContext ctx) { - List parameterList = parseParameterList(ctx.parameterList()); - if(parameterList.size()<1)throw new DebugException("Fehler in typeVar-Regel"); - tphs.add(parameterList.get(0)); - } - - @Override - public void enterType(UnifyResultParser.TypeContext ctx){ - List parameterList = parseParameterList(ctx.parameterList()); - if(parameterList.size()<3)throw new DebugException("Fehler in Type-Regel"); - String name = parameterList.get(0); - String typeName = parameterList.get(1); - String paramPointer = parameterList.get(2); - types.put(name, new ParsedType(typeName, paramPointer)); - } - - /* - private List parsedRule; - private List parseRule(String rule){ - UnifyResultLexer lexer = new UnifyResultLexer(CharStreams.fromString(rule)); - UnifyResultParser.AspruleContext parseTree = new UnifyResultParser(new CommonTokenStream(lexer)).asprule(); - parsedRule = new ArrayList<>(); - new ParseTreeWalker().walk(this, parseTree); - return parsedRule; - } - - @Override - public void enterAsprule(UnifyResultParser.AspruleContext ctx) { - super.enterAsprule(ctx); - for(int i = 0; i< ctx.getChildCount();i++){ - parsedRule.add(ctx.getChild(i).getText()); - } - } - */ - private void getTPHs(ASPResultParser.AnswerContext answer){ for(ASPResultParser.ResultSetRuleContext e : answer.resultSetRule()){ - if(e.NAME().getText().equals(ASPRule.ASP_TYPE_VAR)){ - tphs.add(e.parameterList().getChild(0).getText()); + if(e.NAME().getText().equals(ASPRule.ASP_TYPE_VAR.toString())){ + String pointer = e.parameterList().value(0).getText(); + tphs.add(pointer); + String tphName = ASPStringConverter.fromConstant(pointer); + Optional oTPH = originalTPHs.stream().filter((a)->a.getName().equals(tphName)).findAny(); + TypePlaceholder tph; + if(oTPH.isPresent()){ + tph = oTPH.get(); + }else{ + tph = TypePlaceholder.fresh(new NullToken()); + } + types.put(pointer, tph); } - } + } + } + private void getTypes(ASPResultParser.AnswerContext answer) { + HashMap rawTypes = new HashMap<>(); + for(ASPResultParser.ResultSetRuleContext e : answer.resultSetRule()){ + if(e.NAME().getText().equals(ASPRule.ASP_TYPE.toString())){ + String pointer = e.parameterList().value(0).getText(); + String name = e.parameterList().value(1).getText(); + Integer numParams = Integer.parseInt(e.parameterList().value(2).getText()); + String[] params = new String[numParams + 1]; + params[0] = name; + rawTypes.put(pointer, params); + } + } + for(ASPResultParser.ResultSetRuleContext e : answer.resultSetRule()){ + if(e.NAME().getText().equals(ASPRule.ASP_PARAMLIST_NAME.toString())){ + String typePointer = e.parameterList().value(0).getText(); + String paramPointer = e.parameterList().value(1).getText(); + Integer paramNum = Integer.parseInt(e.parameterList().value(2).getText()); + if(rawTypes.containsKey(typePointer)) { + String[] paramArray = rawTypes.get(typePointer); + paramArray[paramNum] = paramPointer; + } + } + } + + for(String name : rawTypes.keySet()){ + types.put(name, createType(name, rawTypes)); + } + + } + private RefType createType(String name, HashMap rawTypes){ + String[] paramArray = rawTypes.get(name); + List paramList = new ArrayList<>(); + for(int i = 1; i< paramArray.length ;i++){ + String paramPointer = paramArray[i]; + RefTypeOrTPHOrWildcardOrGeneric param; + if(rawTypes.containsKey(paramPointer)){ + param = createType(paramPointer, rawTypes); + }else if(tphs.contains(paramPointer)){ + String tphName = ASPStringConverter.fromConstant(paramPointer); + param = types.get(paramPointer); + }else{ + throw new DebugException("Fehler beim Einlesen der Clingo Ausgabe"); + } + if(param == null) + throw new NullPointerException(); + paramList.add(param); + } + return new RefType(new JavaClassName(ASPStringConverter.fromConstant(paramArray[0])), paramList, new NullToken()); } private ASPParser(String toParse, Collection oldPlaceholders){ @@ -157,73 +156,32 @@ public class ASPParser extends ASPResultBaseListener { } System.out.println(completeResult); */ - UnifyResultLexer lexer = new UnifyResultLexer(CharStreams.fromString(toParse)); - UnifyResultParser.AnswerContext parseTree = new UnifyResultParser(new CommonTokenStream(lexer)).answer(); - new ParseTreeWalker().walk(this, parseTree); + ASPResultLexer lexer = new ASPResultLexer(CharStreams.fromString(toParse)); + ASPResultParser.AnswerContext parseTree = new ASPResultParser(new CommonTokenStream(lexer)).answer(); + //new ParseTreeWalker().walk(this, parseTree); /* 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 ret = new HashSet<>(); - //Zuerst die params und typeVars: - //for(String paramPointer : types.values().stream().map(parsedType -> parsedType.params).collect(Collectors.toList())){ } + getTPHs(parseTree); + getTypes(parseTree); - //Dann die Equalsdot Statements - for(Relation eq : unifierRelations){ - RefTypeOrTPHOrWildcardOrGeneric lsType = this.getType(eq.left); - RefTypeOrTPHOrWildcardOrGeneric rsType = this.getType(eq.right); - if(lsType instanceof TypePlaceholder && rsType instanceof RefType) - ret.add(new PairTPHequalRefTypeOrWildcardType((TypePlaceholder) lsType, rsType)); - else if(lsType instanceof TypePlaceholder && rsType instanceof TypePlaceholder) - ret.add(new PairTPHEqualTPH((TypePlaceholder)lsType, (TypePlaceholder)rsType)); - else throw new NotImplementedException(); + Set ret = new HashSet<>(); + for(ASPResultParser.ResultSetRuleContext e : parseTree.resultSetRule()){ + if(e.NAME().getText().equals(ASPRule.ASP_PAIR_EQUALS_NAME.toString())){ + String tp1 = e.parameterList().value(0).getText(); + String tp2 = e.parameterList().value(1).getText(); + if(tphs.contains(tp1) && tphs.contains(tp2)){ + ret.add(new PairTPHEqualTPH((TypePlaceholder) types.get(tp1), (TypePlaceholder) types.get(tp2))); + }else if(tphs.contains(tp1)){ + if(types.containsKey(tp2)) + ret.add(new PairTPHequalRefTypeOrWildcardType((TypePlaceholder) types.get(tp1), types.get(tp2))); + else System.out.println(tp2); + } + } } this.resultSet = new ResultSet(ret); } - 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 params = new ArrayList<>(); - ParsedType t = types.get(name); - - for(String param : getParams(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 List getParams(String pointer) { - List params = new ArrayList<>(); - while(pointer != null){ - //if(pointer.equals(ASPRule.ASP_PARAMLIST_END_POINTER.toString()))return params; - if(!parameterLists.containsKey(pointer)) - throw new DebugException("Fehler in Ergebnisparsen"); - //TODO: Fehler in ASP. Die adapt Regel muss erkennen, wenn die Parameterliste auf der linken Seite kürzer ist und diese Rechtzeitig beenden - ParameterListNode param = parameterLists.get(pointer); - pointer = param.nextNode; - params.add(param.type); - } - return params; - //Optional ret = parameterLists.stream().filter(aspParameterList -> aspParameterList.name.equals(rs)).findAny(); - //return ret.get(); - } } \ No newline at end of file diff --git a/src/de/dhbwstuttgart/sat/asp/parser/antlr/ASPResult.g4 b/src/de/dhbwstuttgart/sat/asp/parser/antlr/ASPResult.g4 index 08d5f37f..96e4a2a7 100644 --- a/src/de/dhbwstuttgart/sat/asp/parser/antlr/ASPResult.g4 +++ b/src/de/dhbwstuttgart/sat/asp/parser/antlr/ASPResult.g4 @@ -8,7 +8,7 @@ parameterList : '(' value (',' value)* ')'; value : NAME | resultSetRule ; -NAME : [a-zA-Z0-9_]+; +NAME : [a-zA-Z0-9_']+; WS : [ \t\r\n\u000C]+ -> skip ; diff --git a/src/de/dhbwstuttgart/sat/asp/parser/antlr/ASPResultLexer.java b/src/de/dhbwstuttgart/sat/asp/parser/antlr/ASPResultLexer.java index d3467ebf..f118c7a9 100644 --- a/src/de/dhbwstuttgart/sat/asp/parser/antlr/ASPResultLexer.java +++ b/src/de/dhbwstuttgart/sat/asp/parser/antlr/ASPResultLexer.java @@ -98,18 +98,18 @@ public class ASPResultLexer extends Lexer { "\4\3\t\3\4\4\t\4\4\5\t\5\4\6\t\6\4\7\t\7\4\b\t\b\4\t\t\t\3\2\3\2\3\2\3"+ "\2\3\2\3\2\3\2\3\3\3\3\3\4\3\4\3\5\3\5\3\6\3\6\3\7\6\7$\n\7\r\7\16\7%"+ "\3\b\6\b)\n\b\r\b\16\b*\3\b\3\b\3\t\3\t\7\t\61\n\t\f\t\16\t\64\13\t\3"+ - "\t\3\t\2\2\n\3\3\5\4\7\5\t\6\13\7\r\b\17\t\21\n\3\2\5\6\2\62;C\\aac|\5"+ - "\2\13\f\16\17\"\"\4\2\f\f\17\17\29\2\3\3\2\2\2\2\5\3\2\2\2\2\7\3\2\2\2"+ - "\2\t\3\2\2\2\2\13\3\2\2\2\2\r\3\2\2\2\2\17\3\2\2\2\2\21\3\2\2\2\3\23\3"+ - "\2\2\2\5\32\3\2\2\2\7\34\3\2\2\2\t\36\3\2\2\2\13 \3\2\2\2\r#\3\2\2\2\17"+ - "(\3\2\2\2\21.\3\2\2\2\23\24\7C\2\2\24\25\7P\2\2\25\26\7U\2\2\26\27\7Y"+ - "\2\2\27\30\7G\2\2\30\31\7T\2\2\31\4\3\2\2\2\32\33\7\60\2\2\33\6\3\2\2"+ - "\2\34\35\7*\2\2\35\b\3\2\2\2\36\37\7.\2\2\37\n\3\2\2\2 !\7+\2\2!\f\3\2"+ - "\2\2\"$\t\2\2\2#\"\3\2\2\2$%\3\2\2\2%#\3\2\2\2%&\3\2\2\2&\16\3\2\2\2\'"+ - ")\t\3\2\2(\'\3\2\2\2)*\3\2\2\2*(\3\2\2\2*+\3\2\2\2+,\3\2\2\2,-\b\b\2\2"+ - "-\20\3\2\2\2.\62\7\'\2\2/\61\n\4\2\2\60/\3\2\2\2\61\64\3\2\2\2\62\60\3"+ - "\2\2\2\62\63\3\2\2\2\63\65\3\2\2\2\64\62\3\2\2\2\65\66\b\t\2\2\66\22\3"+ - "\2\2\2\6\2%*\62\3\b\2\2"; + "\t\3\t\2\2\n\3\3\5\4\7\5\t\6\13\7\r\b\17\t\21\n\3\2\5\7\2))\62;C\\aac"+ + "|\5\2\13\f\16\17\"\"\4\2\f\f\17\17\29\2\3\3\2\2\2\2\5\3\2\2\2\2\7\3\2"+ + "\2\2\2\t\3\2\2\2\2\13\3\2\2\2\2\r\3\2\2\2\2\17\3\2\2\2\2\21\3\2\2\2\3"+ + "\23\3\2\2\2\5\32\3\2\2\2\7\34\3\2\2\2\t\36\3\2\2\2\13 \3\2\2\2\r#\3\2"+ + "\2\2\17(\3\2\2\2\21.\3\2\2\2\23\24\7C\2\2\24\25\7P\2\2\25\26\7U\2\2\26"+ + "\27\7Y\2\2\27\30\7G\2\2\30\31\7T\2\2\31\4\3\2\2\2\32\33\7\60\2\2\33\6"+ + "\3\2\2\2\34\35\7*\2\2\35\b\3\2\2\2\36\37\7.\2\2\37\n\3\2\2\2 !\7+\2\2"+ + "!\f\3\2\2\2\"$\t\2\2\2#\"\3\2\2\2$%\3\2\2\2%#\3\2\2\2%&\3\2\2\2&\16\3"+ + "\2\2\2\')\t\3\2\2(\'\3\2\2\2)*\3\2\2\2*(\3\2\2\2*+\3\2\2\2+,\3\2\2\2,"+ + "-\b\b\2\2-\20\3\2\2\2.\62\7\'\2\2/\61\n\4\2\2\60/\3\2\2\2\61\64\3\2\2"+ + "\2\62\60\3\2\2\2\62\63\3\2\2\2\63\65\3\2\2\2\64\62\3\2\2\2\65\66\b\t\2"+ + "\2\66\22\3\2\2\2\6\2%*\62\3\b\2\2"; public static final ATN _ATN = new ATNDeserializer().deserialize(_serializedATN.toCharArray()); static { diff --git a/src/de/dhbwstuttgart/sat/asp/writer/ASPFactory.java b/src/de/dhbwstuttgart/sat/asp/writer/ASPFactory.java index 1928cefe..adf75ec0 100644 --- a/src/de/dhbwstuttgart/sat/asp/writer/ASPFactory.java +++ b/src/de/dhbwstuttgart/sat/asp/writer/ASPFactory.java @@ -62,6 +62,7 @@ public class ASPFactory implements TypeVisitor{ for(Pair p : oder.iterator().next()){ this.convertPair(p); //Einfach als und Constraints behandeln, wenn es nur einen Oder-Zweig gibt } + return; } List ret = new ArrayList<>(); Iterator> it = oder.iterator(); @@ -90,15 +91,12 @@ public class ASPFactory implements TypeVisitor{ } protected ASPWriter writer = new ASPWriter(); - boolean isFCType = false; protected void convertFC(Collection classes) throws ClassNotFoundException { Collection fc = FCGenerator.toFC(classes); - isFCType = true; for(Pair fcp : fc){ convertPair(fcp); } - isFCType = false; } protected void convertPair(Pair p){ @@ -136,7 +134,6 @@ public class ASPFactory implements TypeVisitor{ Iterator it = pointers.iterator(); Integer i = 1; String ruleName = ASPRule.ASP_PARAMLIST_NAME.toString(); - if(isFCType) ruleName = ASPRule.ASP_FC_PARAMLIST_NAME.toString(); while (it.hasNext()){ ASPStatement stmt; String type = it.next(); @@ -154,7 +151,7 @@ public class ASPFactory implements TypeVisitor{ params.add(param.acceptTV(this)); } String typeName = ASPStringConverter.toConstant(refType.getName()); - String ruleName = isFCType?ASPRule.ASP_FCTYPE.toString():ASPRule.ASP_TYPE.toString(); + String ruleName = ASPRule.ASP_TYPE.toString(); convertParameterlist(pointer, params); ASPStatement stmt = makeStatement(ruleName, pointer, typeName, Integer.toString(params.size())); writer.add(stmt); @@ -184,7 +181,7 @@ public class ASPFactory implements TypeVisitor{ //Kann eigentlich wie ein normaler RefType behandelt werden String pointer = ASPStringConverter.toConstant(NameGenerator.makeNewName()); String typeName = ASPStringConverter.toConstant(genericRefType.getParsedName()); - String ruleName = isFCType?ASPRule.ASP_FCTYPE.toString():ASPRule.ASP_TYPE.toString(); + String ruleName = ASPRule.ASP_TYPE.toString(); ASPStatement stmt = makeStatement(ruleName, pointer, typeName, ASPRule.ASP_LIST_ENDPOINTER.toString()); writer.add(stmt); return pointer; diff --git a/test/asp/UnifyWithoutWildcards.java b/test/asp/UnifyWithoutWildcards.java index a442ff9a..75cc1cce 100644 --- a/test/asp/UnifyWithoutWildcards.java +++ b/test/asp/UnifyWithoutWildcards.java @@ -116,6 +116,23 @@ public class UnifyWithoutWildcards { assert resultSet.results.size() == 1; } + @Test + public void martinTest() throws InterruptedException, IOException, ClassNotFoundException { + ConstraintSet testSet = new ConstraintSet<>(); + List list1 = + Arrays.asList(TypePlaceholder.fresh(new NullToken()),TypePlaceholder.fresh(new NullToken())); + TypePlaceholder t1 = TypePlaceholder.fresh(new NullToken()); + RefType t2 = new RefType(new JavaClassName("java.util.Map"), list1, new NullToken()); + RefType t3 = new RefType(new JavaClassName("java.util.Map"), list1, new NullToken()); + Set> oderCons = new HashSet<>(); + Constraint cons1 = new Constraint<>(); + cons1.add(new Pair(t2, t3, PairOperator.EQUALSDOT)); + oderCons.add(cons1); + testSet.addOderConstraint(oderCons); + ResultSet resultSet = run(testSet, getFC()); + assert resultSet.results.size() > 0; + } + @Test public void fc() throws ClassNotFoundException { Collection fc = new ArrayList<>(); @@ -129,7 +146,7 @@ public class UnifyWithoutWildcards { public ResultSet run(ConstraintSet toTest, Collection fc) throws IOException, InterruptedException, ClassNotFoundException { String content = ""; content = ASPFactory.generateASP(toTest, fc); - + System.out.println(content); PrintWriter writer = new PrintWriter(tempDirectory + "test.lp", "UTF-8"); writer.println(content); writer.close(); @@ -185,6 +202,7 @@ public class UnifyWithoutWildcards { Set ret = new HashSet<>(); ret.add(ASTFactory.createClass(Matrix.class)); ret.add(ASTFactory.createClass(Test1.class)); + ret.add(ASTFactory.createClass(Map.class)); //ret.add(ASTFactory.createObjectClass()); //ret.add(ASTFactory.createClass(java.util.List.class)); return ret; diff --git a/test/asp/withWildcards/InputGenerator.java b/test/asp/withWildcards/InputGenerator.java index db47b0f2..fe24cb43 100644 --- a/test/asp/withWildcards/InputGenerator.java +++ b/test/asp/withWildcards/InputGenerator.java @@ -108,9 +108,9 @@ public class InputGenerator { final ConstraintSet cons = compiler.getConstraints(); - String content = ""; content = ASPFactory.generateASP(cons, allClasses); + System.out.println(cons); System.out.println(content); } diff --git a/test/asp/withWildcards/JavaTXCompilerASPTest.java b/test/asp/withWildcards/JavaTXCompilerASPTest.java new file mode 100644 index 00000000..e2faa589 --- /dev/null +++ b/test/asp/withWildcards/JavaTXCompilerASPTest.java @@ -0,0 +1,129 @@ +package asp.withWildcards; + +import de.dhbwstuttgart.core.JavaTXCompiler; +import de.dhbwstuttgart.syntaxtree.SourceFile; +import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter; +import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter; +import de.dhbwstuttgart.syntaxtree.visual.ResultSetPrinter; +import de.dhbwstuttgart.typedeployment.TypeInsert; +import de.dhbwstuttgart.typedeployment.TypeInsertFactory; +import de.dhbwstuttgart.typeinference.result.ResultSet; +import org.junit.Test; + +import java.io.File; +import java.io.IOException; +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +public class JavaTXCompilerASPTest { + + public static final String rootDirectory = System.getProperty("user.dir")+"/test/javFiles/"; + + @Test + public void finiteClosure() throws IOException, ClassNotFoundException, InterruptedException { + execute(new File(rootDirectory+"fc.jav")); + } + @Test + public void lambda() throws IOException, ClassNotFoundException, InterruptedException { + execute(new File(rootDirectory+"Lambda.jav")); + } + @Test + public void lambda2() throws IOException, ClassNotFoundException, InterruptedException { + execute(new File(rootDirectory+"Lambda2.jav")); + } + @Test + public void lambda3() throws IOException, ClassNotFoundException, InterruptedException { + execute(new File(rootDirectory+"Lambda3.jav")); + } + @Test + public void mathStruc() throws IOException, ClassNotFoundException, InterruptedException { + execute(new File(rootDirectory+"mathStruc.jav")); + } + @Test + public void generics() throws IOException, ClassNotFoundException, InterruptedException { + execute(new File(rootDirectory+"Generics.jav")); + } + @Test + public void genericsMethodCall() throws IOException, ClassNotFoundException, InterruptedException { + TestResultSet result = execute(new File(rootDirectory+"MethodCallGenerics.jav")); + //TODO: Hier sollte der Rückgabetyp der Methode String sein + } + @Test + public void faculty() throws IOException, ClassNotFoundException, InterruptedException { + execute(new File(rootDirectory+"Faculty.jav")); + } + @Test + public void facultyTyped() throws IOException, ClassNotFoundException, InterruptedException { + execute(new File(rootDirectory+"FacultyTyped.jav")); + } + @Test + public void matrix() throws IOException, ClassNotFoundException, InterruptedException { + execute(new File(rootDirectory+"Matrix.jav")); + } + @Test + public void packageTests() throws IOException, ClassNotFoundException, InterruptedException { + execute(new File(rootDirectory+"Package.jav")); + } + @Test + public void vector() throws IOException, ClassNotFoundException, InterruptedException { + execute(new File(rootDirectory+"Vector.jav")); + } + @Test + public void lambdaRunnable() throws IOException, ClassNotFoundException, InterruptedException { + execute(new File(rootDirectory+"LambdaRunnable.jav")); + } + @Test + public void expressions() throws IOException, ClassNotFoundException, InterruptedException { + execute(new File(rootDirectory+"Expressions.jav")); + } + @Test + public void addLong() throws IOException, ClassNotFoundException, InterruptedException { + execute(new File(rootDirectory+"AddLong.jav")); + } + + private static class TestResultSet{ + + } + + public TestResultSet execute(File fileToTest) throws IOException, ClassNotFoundException, InterruptedException { + JavaTXCompiler compiler = new JavaTXCompiler(fileToTest); + + List results = compiler.aspTypeInference(); + + for(File f : compiler.sourceFiles.keySet()){ + SourceFile sf = compiler.sourceFiles.get(f); + System.out.println(ASTTypePrinter.print(sf)); + System.out.println(ASTPrinter.print(sf)); + //List results = compiler.typeInference(); PL 2017-10-03 vor die For-Schleife gezogen + assert results.size()>0; + System.out.println(ResultSetPrinter.print(results.get(0))); + Set insertedTypes = new HashSet<>(); + for(ResultSet resultSet : results){ + Set result = TypeInsertFactory.createTypeInsertPoints(sf, resultSet); + assert result.size()>0; + String content = readFile(f.getPath(), StandardCharsets.UTF_8); + for(TypeInsert tip : result){ + insertedTypes.add(tip.insert(content)); + } + } + for(String s : insertedTypes){ + System.out.println(s); + } + } + return new TestResultSet(); + } + + static String readFile(String path, Charset encoding) + throws IOException + { + byte[] encoded = Files.readAllBytes(Paths.get(path)); + return new String(encoded, encoding); + } + +} + diff --git a/test/javFiles/Vector.jav b/test/javFiles/Vector.jav index 40072fe4..b30d3d4f 100644 --- a/test/javFiles/Vector.jav +++ b/test/javFiles/Vector.jav @@ -1,4 +1,5 @@ import java.util.Vector; +import java.lang.Integer; class MyVector{