MAsterarbeit

This commit is contained in:
JanUlrich 2018-06-28 16:04:12 +02:00
parent ba63da2860
commit 79fb15f269
21 changed files with 336 additions and 152 deletions

View File

@ -0,0 +1 @@
5da32a6f73bb3ccac5dc264606071605

View File

@ -0,0 +1 @@
bcb7e8eb537f65ec0110731a924a3d4d3bba7805

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>de.dhbwstuttgart</groupId>
<artifactId>JavaTXcompiler</artifactId>
<version>0.1</version>
</project>

View File

@ -0,0 +1 @@
a909ae513fbc19ba7c25b0cbb9871db6

View File

@ -0,0 +1 @@
4863f156f9b2754ccff7128ff372a8e1e11ee0f8

View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<metadata>
<groupId>de.dhbwstuttgart</groupId>
<artifactId>JavaTXcompiler</artifactId>
<versioning>
<release>0.1</release>
<versions>
<version>0.1</version>
</versions>
<lastUpdated>20180119143709</lastUpdated>
</versioning>
</metadata>

View File

@ -0,0 +1 @@
f023e768b9a1e74695541c63858fa86c

View File

@ -0,0 +1 @@
705a6736ea0a93b18743edd577dcb3c5e6dd518e

View File

@ -53,7 +53,7 @@
<build> <build>
<directory>target</directory> <directory>target</directory>
<outputDirectory>target/classes</outputDirectory> <outputDirectory>target/classes</outputDirectory>
<finalName>${artifactId}-${version}</finalName> <finalName>${project.artifactId}-${project.version}</finalName>
<testOutputDirectory>target/test-classes</testOutputDirectory> <testOutputDirectory>target/test-classes</testOutputDirectory>
<sourceDirectory>src/</sourceDirectory> <sourceDirectory>src/</sourceDirectory>
<testSourceDirectory>test/</testSourceDirectory> <testSourceDirectory>test/</testSourceDirectory>
@ -96,7 +96,8 @@
</plugin> </plugin>
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId> <artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration> <configuration>
<source>8</source> <source>8</source>
<target>8</target> <target>8</target>

View File

@ -7,6 +7,7 @@ import de.dhbwstuttgart.parser.scope.GenericsRegistry;
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.SyntaxTreeGenerator; import de.dhbwstuttgart.parser.SyntaxTreeGenerator.SyntaxTreeGenerator;
import de.dhbwstuttgart.parser.antlr.Java8Parser.CompilationUnitContext; import de.dhbwstuttgart.parser.antlr.Java8Parser.CompilationUnitContext;
import de.dhbwstuttgart.parser.scope.JavaClassName; import de.dhbwstuttgart.parser.scope.JavaClassName;
import de.dhbwstuttgart.sat.asp.ASPUnify;
import de.dhbwstuttgart.sat.asp.ASPUnifyWithoutWildcards; import de.dhbwstuttgart.sat.asp.ASPUnifyWithoutWildcards;
import de.dhbwstuttgart.sat.asp.parser.ASPParser; import de.dhbwstuttgart.sat.asp.parser.ASPParser;
import de.dhbwstuttgart.sat.asp.writer.ASPFactory; import de.dhbwstuttgart.sat.asp.writer.ASPFactory;
@ -141,14 +142,14 @@ public class JavaTXCompiler {
final ConstraintSet<Pair> cons = getConstraints(); final ConstraintSet<Pair> cons = getConstraints();
System.out.println(cons);
String content = ""; String content = "";
content = ASPFactory.generateASP(cons, allClasses); content = ASPFactory.generateASP(cons, allClasses);
final String tempDirectory = "/tmp/"; final String tempDirectory = "/tmp/";
PrintWriter writer = new PrintWriter(tempDirectory + "test.lp", "UTF-8"); PrintWriter writer = new PrintWriter(tempDirectory + "test.lp", "UTF-8");
writer.println(content); writer.println(content);
writer.close(); 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(); String result = clingo.runClingo();
System.out.println(result); System.out.println(result);
ResultSet resultSet = ASPParser.parse(result, getInvolvedTPHS(cons)); ResultSet resultSet = ASPParser.parse(result, getInvolvedTPHS(cons));

View File

@ -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<File> input;
private static final List<File> 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<File> 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<String> 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;
}
}

View File

@ -27,7 +27,7 @@ public class Clingo {
*/ */
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"; "clingo";
List<String> commands = new ArrayList<>(); List<String> commands = new ArrayList<>();
commands.add(pathToClingo); commands.add(pathToClingo);
//commands.add("--outf=2"); //use JSON-Output //commands.add("--outf=2"); //use JSON-Output

View File

@ -7,9 +7,7 @@ public enum ASPRule {
ASP_PAIR_SMALLER_NAME("smaller"), ASP_PAIR_SMALLER_NAME("smaller"),
ASP_PAIR_SMALLER_DOT_NAME("smallerDot"), ASP_PAIR_SMALLER_DOT_NAME("smallerDot"),
ASP_PARAMLIST_NAME("param"), ASP_PARAMLIST_NAME("param"),
ASP_FC_PARAMLIST_NAME("paramFC"),
ASP_TYPE("type"), ASP_TYPE("type"),
ASP_FCTYPE("typeFC"),
ASP_TYPE_VAR("typeVar"), ASP_ODER("oder"), ASP_TYPE_VAR("typeVar"), ASP_ODER("oder"),
ASP_CONSTRAINT("constraint"), ASP_CONSTRAINT("constraint"),
ASP_LIST_NAME("list"), ASP_LIST_NAME("list"),

View File

@ -9,7 +9,9 @@ import de.dhbwstuttgart.sat.asp.model.ASPRule;
import de.dhbwstuttgart.sat.asp.parser.antlr.*; import de.dhbwstuttgart.sat.asp.parser.antlr.*;
import de.dhbwstuttgart.sat.asp.parser.model.ParsedType; import de.dhbwstuttgart.sat.asp.parser.model.ParsedType;
import de.dhbwstuttgart.syntaxtree.type.*; import de.dhbwstuttgart.syntaxtree.type.*;
import de.dhbwstuttgart.typeinference.constraints.Pair;
import de.dhbwstuttgart.typeinference.result.*; import de.dhbwstuttgart.typeinference.result.*;
import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
import org.antlr.v4.runtime.CharStreams; import org.antlr.v4.runtime.CharStreams;
import org.antlr.v4.runtime.CommonTokenStream; import org.antlr.v4.runtime.CommonTokenStream;
import org.antlr.v4.runtime.tree.ParseTreeWalker; import org.antlr.v4.runtime.tree.ParseTreeWalker;
@ -40,13 +42,6 @@ public class ASPParser extends ASPResultBaseListener {
return new ASPParser(toParse, oldPlaceholders).resultSet; return new ASPParser(toParse, oldPlaceholders).resultSet;
} }
@Override
public void enterParameter(UnifyResultParser.ParameterContext ctx) {
//Linked List (pointer, Type, nextPointer)
List<String> params = parseParameterList(ctx.parameterList());
parameterLists.put(params.get(0), new ParameterListNode(params.get(1), params.get(2)));
}
private static class Relation { private static class Relation {
public final String right; public final String right;
public final String left; public final String left;
@ -76,68 +71,72 @@ public class ASPParser extends ASPResultBaseListener {
).collect(Collectors.toList()); ).collect(Collectors.toList());
} }
@Override
public void enterUnifier(UnifyResultParser.UnifierContext ctx) {
List<String> 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<String> 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<String> 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<String> 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<String> parsedRule;
private List<String> 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){ private void getTPHs(ASPResultParser.AnswerContext answer){
for(ASPResultParser.ResultSetRuleContext e : answer.resultSetRule()){ for(ASPResultParser.ResultSetRuleContext e : answer.resultSetRule()){
if(e.NAME().getText().equals(ASPRule.ASP_TYPE_VAR)){ if(e.NAME().getText().equals(ASPRule.ASP_TYPE_VAR.toString())){
tphs.add(e.parameterList().getChild(0).getText()); String pointer = e.parameterList().value(0).getText();
tphs.add(pointer);
String tphName = ASPStringConverter.fromConstant(pointer);
Optional<TypePlaceholder> 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<String, String[]> 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<String, String[]> rawTypes){
String[] paramArray = rawTypes.get(name);
List<RefTypeOrTPHOrWildcardOrGeneric> 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<TypePlaceholder> oldPlaceholders){ private ASPParser(String toParse, Collection<TypePlaceholder> oldPlaceholders){
//System.out.println(toParse); //System.out.println(toParse);
@ -157,73 +156,32 @@ public class ASPParser extends ASPResultBaseListener {
} }
System.out.println(completeResult); System.out.println(completeResult);
*/ */
UnifyResultLexer lexer = new UnifyResultLexer(CharStreams.fromString(toParse)); ASPResultLexer lexer = new ASPResultLexer(CharStreams.fromString(toParse));
UnifyResultParser.AnswerContext parseTree = new UnifyResultParser(new CommonTokenStream(lexer)).answer(); ASPResultParser.AnswerContext parseTree = new ASPResultParser(new CommonTokenStream(lexer)).answer();
new ParseTreeWalker().walk(this, parseTree); //new ParseTreeWalker().walk(this, parseTree);
/* /*
Diese Funktion läuft im folgenden mehrmals über das Result aus dem ASP Programm. 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 Dabei werden Schritt für Schritt die Felder dieser Klasse befüllt die am Schluss das ResultSet ergeben
*/ */
Set<ResultPair> ret = new HashSet<>(); getTPHs(parseTree);
//Zuerst die params und typeVars: getTypes(parseTree);
//for(String paramPointer : types.values().stream().map(parsedType -> parsedType.params).collect(Collectors.toList())){ }
//Dann die Equalsdot Statements Set<ResultPair> ret = new HashSet<>();
for(Relation eq : unifierRelations){ for(ASPResultParser.ResultSetRuleContext e : parseTree.resultSetRule()){
RefTypeOrTPHOrWildcardOrGeneric lsType = this.getType(eq.left); if(e.NAME().getText().equals(ASPRule.ASP_PAIR_EQUALS_NAME.toString())){
RefTypeOrTPHOrWildcardOrGeneric rsType = this.getType(eq.right); String tp1 = e.parameterList().value(0).getText();
if(lsType instanceof TypePlaceholder && rsType instanceof RefType) String tp2 = e.parameterList().value(1).getText();
ret.add(new PairTPHequalRefTypeOrWildcardType((TypePlaceholder) lsType, rsType)); if(tphs.contains(tp1) && tphs.contains(tp2)){
else if(lsType instanceof TypePlaceholder && rsType instanceof TypePlaceholder) ret.add(new PairTPHEqualTPH((TypePlaceholder) types.get(tp1), (TypePlaceholder) types.get(tp2)));
ret.add(new PairTPHEqualTPH((TypePlaceholder)lsType, (TypePlaceholder)rsType)); }else if(tphs.contains(tp1)){
else throw new NotImplementedException(); 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); 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<RefTypeOrTPHOrWildcardOrGeneric> 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<String> getParams(String pointer) {
List<String> 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<ASPParameterList> ret = parameterLists.stream().filter(aspParameterList -> aspParameterList.name.equals(rs)).findAny();
//return ret.get();
}
} }

View File

@ -8,7 +8,7 @@ parameterList : '(' value (',' value)* ')';
value : NAME value : NAME
| resultSetRule ; | resultSetRule ;
NAME : [a-zA-Z0-9_]+; NAME : [a-zA-Z0-9_']+;
WS : [ \t\r\n\u000C]+ -> skip WS : [ \t\r\n\u000C]+ -> skip
; ;

View File

@ -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"+ "\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%"+ "\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"+ "\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"+ "\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"+
"\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"+ "|\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\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\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"+
"\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"+ "\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"+
"(\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\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"+
"\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"+ "\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"+
"\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"+ "\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"+
"\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\'"+ "!\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"+
")\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"+ "\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,"+
"-\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"+ "-\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\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\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\2\2\6\2%*\62\3\b\2\2"; "\2\66\22\3\2\2\2\6\2%*\62\3\b\2\2";
public static final ATN _ATN = public static final ATN _ATN =
new ATNDeserializer().deserialize(_serializedATN.toCharArray()); new ATNDeserializer().deserialize(_serializedATN.toCharArray());
static { static {

View File

@ -62,6 +62,7 @@ public class ASPFactory implements TypeVisitor<String>{
for(Pair p : oder.iterator().next()){ for(Pair p : oder.iterator().next()){
this.convertPair(p); //Einfach als und Constraints behandeln, wenn es nur einen Oder-Zweig gibt this.convertPair(p); //Einfach als und Constraints behandeln, wenn es nur einen Oder-Zweig gibt
} }
return;
} }
List<ASPStatement> ret = new ArrayList<>(); List<ASPStatement> ret = new ArrayList<>();
Iterator<Constraint<Pair>> it = oder.iterator(); Iterator<Constraint<Pair>> it = oder.iterator();
@ -90,15 +91,12 @@ public class ASPFactory implements TypeVisitor<String>{
} }
protected ASPWriter writer = new ASPWriter(); protected ASPWriter writer = new ASPWriter();
boolean isFCType = false;
protected void convertFC(Collection<ClassOrInterface> classes) throws ClassNotFoundException { protected void convertFC(Collection<ClassOrInterface> classes) throws ClassNotFoundException {
Collection<Pair> fc = FCGenerator.toFC(classes); Collection<Pair> fc = FCGenerator.toFC(classes);
isFCType = true;
for(Pair fcp : fc){ for(Pair fcp : fc){
convertPair(fcp); convertPair(fcp);
} }
isFCType = false;
} }
protected void convertPair(Pair p){ protected void convertPair(Pair p){
@ -136,7 +134,6 @@ public class ASPFactory implements TypeVisitor<String>{
Iterator<String> it = pointers.iterator(); Iterator<String> it = pointers.iterator();
Integer i = 1; Integer i = 1;
String ruleName = ASPRule.ASP_PARAMLIST_NAME.toString(); String ruleName = ASPRule.ASP_PARAMLIST_NAME.toString();
if(isFCType) ruleName = ASPRule.ASP_FC_PARAMLIST_NAME.toString();
while (it.hasNext()){ while (it.hasNext()){
ASPStatement stmt; ASPStatement stmt;
String type = it.next(); String type = it.next();
@ -154,7 +151,7 @@ public class ASPFactory implements TypeVisitor<String>{
params.add(param.acceptTV(this)); params.add(param.acceptTV(this));
} }
String typeName = ASPStringConverter.toConstant(refType.getName()); 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); convertParameterlist(pointer, params);
ASPStatement stmt = makeStatement(ruleName, pointer, typeName, Integer.toString(params.size())); ASPStatement stmt = makeStatement(ruleName, pointer, typeName, Integer.toString(params.size()));
writer.add(stmt); writer.add(stmt);
@ -184,7 +181,7 @@ public class ASPFactory implements TypeVisitor<String>{
//Kann eigentlich wie ein normaler RefType behandelt werden //Kann eigentlich wie ein normaler RefType behandelt werden
String pointer = ASPStringConverter.toConstant(NameGenerator.makeNewName()); String pointer = ASPStringConverter.toConstant(NameGenerator.makeNewName());
String typeName = ASPStringConverter.toConstant(genericRefType.getParsedName()); 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()); ASPStatement stmt = makeStatement(ruleName, pointer, typeName, ASPRule.ASP_LIST_ENDPOINTER.toString());
writer.add(stmt); writer.add(stmt);
return pointer; return pointer;

View File

@ -116,6 +116,23 @@ public class UnifyWithoutWildcards {
assert resultSet.results.size() == 1; assert resultSet.results.size() == 1;
} }
@Test
public void martinTest() throws InterruptedException, IOException, ClassNotFoundException {
ConstraintSet<Pair> testSet = new ConstraintSet<>();
List<RefTypeOrTPHOrWildcardOrGeneric> 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<Constraint<Pair>> oderCons = new HashSet<>();
Constraint<Pair> 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 @Test
public void fc() throws ClassNotFoundException { public void fc() throws ClassNotFoundException {
Collection<ClassOrInterface> fc = new ArrayList<>(); Collection<ClassOrInterface> fc = new ArrayList<>();
@ -129,7 +146,7 @@ public class UnifyWithoutWildcards {
public ResultSet run(ConstraintSet<Pair> toTest, Collection<ClassOrInterface> fc) throws IOException, InterruptedException, ClassNotFoundException { public ResultSet run(ConstraintSet<Pair> toTest, Collection<ClassOrInterface> fc) throws IOException, InterruptedException, ClassNotFoundException {
String content = ""; String content = "";
content = ASPFactory.generateASP(toTest, fc); content = ASPFactory.generateASP(toTest, fc);
System.out.println(content);
PrintWriter writer = new PrintWriter(tempDirectory + "test.lp", "UTF-8"); PrintWriter writer = new PrintWriter(tempDirectory + "test.lp", "UTF-8");
writer.println(content); writer.println(content);
writer.close(); writer.close();
@ -185,6 +202,7 @@ public class UnifyWithoutWildcards {
Set<ClassOrInterface> ret = new HashSet<>(); Set<ClassOrInterface> ret = new HashSet<>();
ret.add(ASTFactory.createClass(Matrix.class)); ret.add(ASTFactory.createClass(Matrix.class));
ret.add(ASTFactory.createClass(Test1.class)); ret.add(ASTFactory.createClass(Test1.class));
ret.add(ASTFactory.createClass(Map.class));
//ret.add(ASTFactory.createObjectClass()); //ret.add(ASTFactory.createObjectClass());
//ret.add(ASTFactory.createClass(java.util.List.class)); //ret.add(ASTFactory.createClass(java.util.List.class));
return ret; return ret;

View File

@ -108,9 +108,9 @@ public class InputGenerator {
final ConstraintSet<Pair> cons = compiler.getConstraints(); final ConstraintSet<Pair> cons = compiler.getConstraints();
String content = ""; String content = "";
content = ASPFactory.generateASP(cons, allClasses); content = ASPFactory.generateASP(cons, allClasses);
System.out.println(cons);
System.out.println(content); System.out.println(content);
} }

View File

@ -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<ResultSet> 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<ResultSet> 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<String> insertedTypes = new HashSet<>();
for(ResultSet resultSet : results){
Set<TypeInsert> result = TypeInsertFactory.createTypeInsertPoints(sf, resultSet);
assert result.size()>0;
String content = readFile(f.getPath(), StandardCharsets.UTF_8);
for(TypeInsert tip : result){
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);
}
}

View File

@ -1,4 +1,5 @@
import java.util.Vector; import java.util.Vector;
import java.lang.Integer;
class MyVector{ class MyVector{