From 3c732346d907ae5b59e7aece1975fa29ff40baeb Mon Sep 17 00:00:00 2001 From: JanUlrich Date: Sat, 6 Jan 2018 09:38:53 +0100 Subject: [PATCH 01/12] ASPParameterlist erzeugt auch paramNum --- pom.xml | 5 +++++ src/de/dhbwstuttgart/sat/asp/model/ASPParameterList.java | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/pom.xml b/pom.xml index 6b0f2fba5..9cce2d998 100644 --- a/pom.xml +++ b/pom.xml @@ -22,6 +22,11 @@ antlr4 4.7 + + commons-io + commons-io + 2.6 + com.google.guava guava diff --git a/src/de/dhbwstuttgart/sat/asp/model/ASPParameterList.java b/src/de/dhbwstuttgart/sat/asp/model/ASPParameterList.java index f0c067444..46eed10aa 100644 --- a/src/de/dhbwstuttgart/sat/asp/model/ASPParameterList.java +++ b/src/de/dhbwstuttgart/sat/asp/model/ASPParameterList.java @@ -11,11 +11,13 @@ import java.util.Set; public class ASPParameterList { private final static String ASP_PARAMLIST_NAME = "param"; + private final static String ASP_PARAMLISTNUMERATION_NAME = "paramNum"; private final static String ASP_PARAMLIST_END_POINTER = "null"; public final String name; private final List types; public ASPParameterList(List types, ASPWriter writer){ + int paramNum = 0; this.types = types; if(types.size() == 0){ name = ASP_PARAMLIST_END_POINTER; @@ -30,6 +32,8 @@ public class ASPParameterList { if(! it.hasNext())nextPointer = ASP_PARAMLIST_END_POINTER; param += nextPointer; writer.add(new ASPStatement(ASP_PARAMLIST_NAME + "(" + param + ")")); + writer.add(new ASPStatement(ASP_PARAMLISTNUMERATION_NAME + "(" + name + "," +t + "," + paramNum + ")")); + paramNum++; //paramDefinitions.add(new ASPStatement(ASP_PARAMLIST_NAME + "(" + param + ")")); } } From 19a1ef40244e76c117a7f0ad3bab406bb7f54733 Mon Sep 17 00:00:00 2001 From: JanUlrich Date: Wed, 10 Jan 2018 10:53:07 +0100 Subject: [PATCH 02/12] =?UTF-8?q?Erste=20lauff=C3=A4hige=20aber=20unvollst?= =?UTF-8?q?=C3=A4ndige=20Version=20des=20UnifyWithoutWildcards?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/de/dhbwstuttgart/sat/asp/Clingo.java | 46 +++++++++++++++++++ .../dhbwstuttgart/sat/asp/model/ASPRule.java | 24 ++++++++++ .../dhbwstuttgart/sat/asp/model/ASPType.java | 4 -- .../sat/asp/parser/ASPParser.java | 17 +++++++ .../asp/parser/model/ParsedASPStatement.java | 7 +++ .../sat/asp/{ => writer}/ASPGenerator.java | 8 +--- .../sat/asp/{ => writer}/ASPWriter.java | 6 +-- .../{ => writer}/model/ASPGenericType.java | 7 +-- .../sat/asp/{ => writer}/model/ASPPair.java | 2 +- .../asp/{ => writer}/model/ASPPairEquals.java | 7 +-- .../{ => writer}/model/ASPPairSmaller.java | 11 +++-- .../{ => writer}/model/ASPPairSmallerDot.java | 7 +-- .../{ => writer}/model/ASPParameterList.java | 20 ++++---- .../asp/{ => writer}/model/ASPRefType.java | 7 +-- .../asp/{ => writer}/model/ASPStatement.java | 2 +- .../sat/asp/writer/model/ASPType.java | 4 ++ .../asp/{ => writer}/model/ASPTypeVar.java | 2 +- test/asp/ClingoTest.java | 46 +++++++++++++++++++ test/asp/typeinference/ASPTest.java | 2 +- test/asp/unifywithoutwildcards/ASPTests.java | 10 ++++ test/typeinference/JavaTXCompilerTest.java | 15 ------ 21 files changed, 193 insertions(+), 61 deletions(-) create mode 100644 src/de/dhbwstuttgart/sat/asp/Clingo.java create mode 100644 src/de/dhbwstuttgart/sat/asp/model/ASPRule.java delete mode 100644 src/de/dhbwstuttgart/sat/asp/model/ASPType.java create mode 100644 src/de/dhbwstuttgart/sat/asp/parser/ASPParser.java create mode 100644 src/de/dhbwstuttgart/sat/asp/parser/model/ParsedASPStatement.java rename src/de/dhbwstuttgart/sat/asp/{ => writer}/ASPGenerator.java (94%) rename src/de/dhbwstuttgart/sat/asp/{ => writer}/ASPWriter.java (67%) rename src/de/dhbwstuttgart/sat/asp/{ => writer}/model/ASPGenericType.java (53%) rename src/de/dhbwstuttgart/sat/asp/{ => writer}/model/ASPPair.java (90%) rename src/de/dhbwstuttgart/sat/asp/{ => writer}/model/ASPPairEquals.java (55%) rename src/de/dhbwstuttgart/sat/asp/{ => writer}/model/ASPPairSmaller.java (51%) rename src/de/dhbwstuttgart/sat/asp/{ => writer}/model/ASPPairSmallerDot.java (55%) rename src/de/dhbwstuttgart/sat/asp/{ => writer}/model/ASPParameterList.java (59%) rename src/de/dhbwstuttgart/sat/asp/{ => writer}/model/ASPRefType.java (68%) rename src/de/dhbwstuttgart/sat/asp/{ => writer}/model/ASPStatement.java (91%) create mode 100644 src/de/dhbwstuttgart/sat/asp/writer/model/ASPType.java rename src/de/dhbwstuttgart/sat/asp/{ => writer}/model/ASPTypeVar.java (83%) create mode 100644 test/asp/ClingoTest.java create mode 100644 test/asp/unifywithoutwildcards/ASPTests.java diff --git a/src/de/dhbwstuttgart/sat/asp/Clingo.java b/src/de/dhbwstuttgart/sat/asp/Clingo.java new file mode 100644 index 000000000..85f6dc569 --- /dev/null +++ b/src/de/dhbwstuttgart/sat/asp/Clingo.java @@ -0,0 +1,46 @@ +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.io.OutputStream; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + +public class Clingo { + private final List input; + private static final List programFiles = new ArrayList<>(); + 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/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/reduce2.lp")); + programFiles.add(new File("/home/janulrich/Sync/HiwiJob/ResearchPapers/MasterarbeitStadelmeier/asp/unifyWithoutWildcards/unify.lp")); + } + + public Clingo(List inputFiles){ + this.input = inputFiles; + } + + public String runClingo() throws IOException, InterruptedException { + String pathToClingo = + "/home/janulrich/Sync/HiwiJob/ResearchPapers/MasterarbeitStadelmeier/asp/clingo-5.2.1-linux-x86_64/clingo"; + List commands = new ArrayList<>(); + commands.add(pathToClingo); + commands.add("--outf=2"); //use JSON-Output + for(File file : input){ + commands.add(file.getPath()); + } + commands.addAll(programFiles.stream().map(f->f.getPath()).collect(Collectors.toList())); + 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/model/ASPRule.java b/src/de/dhbwstuttgart/sat/asp/model/ASPRule.java new file mode 100644 index 000000000..412375474 --- /dev/null +++ b/src/de/dhbwstuttgart/sat/asp/model/ASPRule.java @@ -0,0 +1,24 @@ +package de.dhbwstuttgart.sat.asp.model; + +public enum ASPRule { + ASP_GENERIC_TYPE_NAME("genericType"), + ASP_PAIR_EQUALS_NAME("equals"), + ASP_PAIR_SMALLER_NAME("smaller"), + ASP_PAIR_SMALLER_DOT_NAME("smallerDot"), + ASP_PARAMLIST_NAME("param"), + ASP_PARAMLISTNUMERATION_NAME("paramNum"), + ASP_PARAMLIST_END_POINTER("null"), + ASP_TYPE("type") + ; + + private final String text; + + private ASPRule(final String text) { + this.text = text; + } + + @Override + public String toString() { + return text; + } +} diff --git a/src/de/dhbwstuttgart/sat/asp/model/ASPType.java b/src/de/dhbwstuttgart/sat/asp/model/ASPType.java deleted file mode 100644 index e703596cf..000000000 --- a/src/de/dhbwstuttgart/sat/asp/model/ASPType.java +++ /dev/null @@ -1,4 +0,0 @@ -package de.dhbwstuttgart.sat.asp.model; - -public interface ASPType { -} diff --git a/src/de/dhbwstuttgart/sat/asp/parser/ASPParser.java b/src/de/dhbwstuttgart/sat/asp/parser/ASPParser.java new file mode 100644 index 000000000..c7be7dbc7 --- /dev/null +++ b/src/de/dhbwstuttgart/sat/asp/parser/ASPParser.java @@ -0,0 +1,17 @@ +package de.dhbwstuttgart.sat.asp.parser; + +import de.dhbwstuttgart.typeinference.result.ResultPair; +import de.dhbwstuttgart.typeinference.result.ResultSet; + +import java.util.HashSet; +import java.util.Set; + +public class ASPParser { + ResultSet parse(String result){ + Set ret = new HashSet<>(); + for(String pair : result.split(",")){ + + } + return new ResultSet(ret); + } +} \ No newline at end of file diff --git a/src/de/dhbwstuttgart/sat/asp/parser/model/ParsedASPStatement.java b/src/de/dhbwstuttgart/sat/asp/parser/model/ParsedASPStatement.java new file mode 100644 index 000000000..614bddb01 --- /dev/null +++ b/src/de/dhbwstuttgart/sat/asp/parser/model/ParsedASPStatement.java @@ -0,0 +1,7 @@ +package de.dhbwstuttgart.sat.asp.parser.model; + +public class ParsedASPStatement { + public ParsedASPStatement(String statement){ + + } +} diff --git a/src/de/dhbwstuttgart/sat/asp/ASPGenerator.java b/src/de/dhbwstuttgart/sat/asp/writer/ASPGenerator.java similarity index 94% rename from src/de/dhbwstuttgart/sat/asp/ASPGenerator.java rename to src/de/dhbwstuttgart/sat/asp/writer/ASPGenerator.java index 1b942ad0f..002e3c7f6 100644 --- a/src/de/dhbwstuttgart/sat/asp/ASPGenerator.java +++ b/src/de/dhbwstuttgart/sat/asp/writer/ASPGenerator.java @@ -1,9 +1,8 @@ -package de.dhbwstuttgart.sat.asp; +package de.dhbwstuttgart.sat.asp.writer; -import de.dhbwstuttgart.exceptions.DebugException; import de.dhbwstuttgart.exceptions.NotImplementedException; import de.dhbwstuttgart.parser.scope.JavaClassName; -import de.dhbwstuttgart.sat.asp.model.*; +import de.dhbwstuttgart.sat.asp.writer.model.*; import de.dhbwstuttgart.syntaxtree.ClassOrInterface; import de.dhbwstuttgart.syntaxtree.GenericTypeVar; import de.dhbwstuttgart.syntaxtree.factory.UnifyTypeFactory; @@ -11,13 +10,10 @@ import de.dhbwstuttgart.syntaxtree.type.*; import de.dhbwstuttgart.typeinference.constraints.Constraint; import de.dhbwstuttgart.typeinference.constraints.ConstraintSet; import de.dhbwstuttgart.typeinference.constraints.Pair; -import de.dhbwstuttgart.typeinference.unify.model.UnifyType; -import java.sql.Ref; import java.util.ArrayList; import java.util.Collection; import java.util.List; -import java.util.Optional; public class ASPGenerator { ASPWriter writer = new ASPWriter(); diff --git a/src/de/dhbwstuttgart/sat/asp/ASPWriter.java b/src/de/dhbwstuttgart/sat/asp/writer/ASPWriter.java similarity index 67% rename from src/de/dhbwstuttgart/sat/asp/ASPWriter.java rename to src/de/dhbwstuttgart/sat/asp/writer/ASPWriter.java index 4d33cbbf7..450950d99 100644 --- a/src/de/dhbwstuttgart/sat/asp/ASPWriter.java +++ b/src/de/dhbwstuttgart/sat/asp/writer/ASPWriter.java @@ -1,8 +1,6 @@ -package de.dhbwstuttgart.sat.asp; +package de.dhbwstuttgart.sat.asp.writer; -import de.dhbwstuttgart.sat.asp.model.ASPRefType; -import de.dhbwstuttgart.sat.asp.model.ASPStatement; -import de.dhbwstuttgart.sat.asp.model.ASPType; +import de.dhbwstuttgart.sat.asp.writer.model.ASPStatement; import java.util.HashSet; diff --git a/src/de/dhbwstuttgart/sat/asp/model/ASPGenericType.java b/src/de/dhbwstuttgart/sat/asp/writer/model/ASPGenericType.java similarity index 53% rename from src/de/dhbwstuttgart/sat/asp/model/ASPGenericType.java rename to src/de/dhbwstuttgart/sat/asp/writer/model/ASPGenericType.java index 26e6ea02a..57619edf6 100644 --- a/src/de/dhbwstuttgart/sat/asp/model/ASPGenericType.java +++ b/src/de/dhbwstuttgart/sat/asp/writer/model/ASPGenericType.java @@ -1,7 +1,8 @@ -package de.dhbwstuttgart.sat.asp.model; +package de.dhbwstuttgart.sat.asp.writer.model; + +import de.dhbwstuttgart.sat.asp.model.ASPRule; public class ASPGenericType implements ASPType{ - public static final String ASP_GENERIC_TYPE_NAME = "genericType"; private final String name; public ASPGenericType(String name){ @@ -9,6 +10,6 @@ public class ASPGenericType implements ASPType{ } public String toString(){ - return ASP_GENERIC_TYPE_NAME + "(" + name + ")"; + return ASPRule.ASP_GENERIC_TYPE_NAME + "(" + name + ")"; } } diff --git a/src/de/dhbwstuttgart/sat/asp/model/ASPPair.java b/src/de/dhbwstuttgart/sat/asp/writer/model/ASPPair.java similarity index 90% rename from src/de/dhbwstuttgart/sat/asp/model/ASPPair.java rename to src/de/dhbwstuttgart/sat/asp/writer/model/ASPPair.java index bbd3ff3fd..662f995c7 100644 --- a/src/de/dhbwstuttgart/sat/asp/model/ASPPair.java +++ b/src/de/dhbwstuttgart/sat/asp/writer/model/ASPPair.java @@ -1,4 +1,4 @@ -package de.dhbwstuttgart.sat.asp.model; +package de.dhbwstuttgart.sat.asp.writer.model; public abstract class ASPPair { public final ASPType leftSide; diff --git a/src/de/dhbwstuttgart/sat/asp/model/ASPPairEquals.java b/src/de/dhbwstuttgart/sat/asp/writer/model/ASPPairEquals.java similarity index 55% rename from src/de/dhbwstuttgart/sat/asp/model/ASPPairEquals.java rename to src/de/dhbwstuttgart/sat/asp/writer/model/ASPPairEquals.java index b67920bdb..8806f2ce2 100644 --- a/src/de/dhbwstuttgart/sat/asp/model/ASPPairEquals.java +++ b/src/de/dhbwstuttgart/sat/asp/writer/model/ASPPairEquals.java @@ -1,13 +1,14 @@ -package de.dhbwstuttgart.sat.asp.model; +package de.dhbwstuttgart.sat.asp.writer.model; + +import de.dhbwstuttgart.sat.asp.model.ASPRule; public class ASPPairEquals extends ASPPair{ - private final static String ASP_PAIR_EQUALS_NAME = "equals"; public ASPPairEquals(ASPType ls, ASPType rs){ super(ls, rs); } @Override protected String getRuleName() { - return ASP_PAIR_EQUALS_NAME; + return ASPRule.ASP_PAIR_EQUALS_NAME.toString(); } } diff --git a/src/de/dhbwstuttgart/sat/asp/model/ASPPairSmaller.java b/src/de/dhbwstuttgart/sat/asp/writer/model/ASPPairSmaller.java similarity index 51% rename from src/de/dhbwstuttgart/sat/asp/model/ASPPairSmaller.java rename to src/de/dhbwstuttgart/sat/asp/writer/model/ASPPairSmaller.java index 882054ccf..f57170f62 100644 --- a/src/de/dhbwstuttgart/sat/asp/model/ASPPairSmaller.java +++ b/src/de/dhbwstuttgart/sat/asp/writer/model/ASPPairSmaller.java @@ -1,13 +1,16 @@ -package de.dhbwstuttgart.sat.asp.model; +package de.dhbwstuttgart.sat.asp.writer.model; + +import de.dhbwstuttgart.sat.asp.model.ASPRule; + +import java.util.Map; public class ASPPairSmaller extends ASPPair{ - private final static String ASP_PAIR_SMALLER_NAME = "smaller"; public ASPPairSmaller(ASPType ls, ASPType rs){ super(ls, rs); } @Override protected String getRuleName() { - return ASP_PAIR_SMALLER_NAME; + return ASPRule.ASP_PAIR_SMALLER_NAME.toString(); } -} +} \ No newline at end of file diff --git a/src/de/dhbwstuttgart/sat/asp/model/ASPPairSmallerDot.java b/src/de/dhbwstuttgart/sat/asp/writer/model/ASPPairSmallerDot.java similarity index 55% rename from src/de/dhbwstuttgart/sat/asp/model/ASPPairSmallerDot.java rename to src/de/dhbwstuttgart/sat/asp/writer/model/ASPPairSmallerDot.java index 0e6598c1a..e8482bfc8 100644 --- a/src/de/dhbwstuttgart/sat/asp/model/ASPPairSmallerDot.java +++ b/src/de/dhbwstuttgart/sat/asp/writer/model/ASPPairSmallerDot.java @@ -1,13 +1,14 @@ -package de.dhbwstuttgart.sat.asp.model; +package de.dhbwstuttgart.sat.asp.writer.model; + +import de.dhbwstuttgart.sat.asp.model.ASPRule; public class ASPPairSmallerDot extends ASPPair{ - private final static String ASP_PAIR_SMALLER_NAME = "smallerDot"; public ASPPairSmallerDot(ASPType ls, ASPType rs){ super(ls, rs); } @Override protected String getRuleName() { - return ASP_PAIR_SMALLER_NAME; + return ASPRule.ASP_PAIR_SMALLER_DOT_NAME.toString(); } } diff --git a/src/de/dhbwstuttgart/sat/asp/model/ASPParameterList.java b/src/de/dhbwstuttgart/sat/asp/writer/model/ASPParameterList.java similarity index 59% rename from src/de/dhbwstuttgart/sat/asp/model/ASPParameterList.java rename to src/de/dhbwstuttgart/sat/asp/writer/model/ASPParameterList.java index 46eed10aa..3c176e49d 100644 --- a/src/de/dhbwstuttgart/sat/asp/model/ASPParameterList.java +++ b/src/de/dhbwstuttgart/sat/asp/writer/model/ASPParameterList.java @@ -1,18 +1,14 @@ -package de.dhbwstuttgart.sat.asp.model; +package de.dhbwstuttgart.sat.asp.writer.model; -import de.dhbwstuttgart.sat.asp.ASPGenerator; -import de.dhbwstuttgart.sat.asp.ASPWriter; +import de.dhbwstuttgart.sat.asp.model.ASPRule; +import de.dhbwstuttgart.sat.asp.writer.ASPGenerator; +import de.dhbwstuttgart.sat.asp.writer.ASPWriter; import de.dhbwstuttgart.syntaxtree.factory.NameGenerator; -import java.util.HashSet; import java.util.Iterator; import java.util.List; -import java.util.Set; public class ASPParameterList { - private final static String ASP_PARAMLIST_NAME = "param"; - private final static String ASP_PARAMLISTNUMERATION_NAME = "paramNum"; - private final static String ASP_PARAMLIST_END_POINTER = "null"; public final String name; private final List types; @@ -20,7 +16,7 @@ public class ASPParameterList { int paramNum = 0; this.types = types; if(types.size() == 0){ - name = ASP_PARAMLIST_END_POINTER; + name = ASPRule.ASP_PARAMLIST_END_POINTER.toString(); }else{ name = newName(); String nextPointer = name; @@ -29,10 +25,10 @@ public class ASPParameterList { ASPType t = it.next(); String param = nextPointer + "," + t.toString() + ","; nextPointer = newName(); - if(! it.hasNext())nextPointer = ASP_PARAMLIST_END_POINTER; + if(! it.hasNext())nextPointer = ASPRule.ASP_PARAMLIST_END_POINTER.toString(); param += nextPointer; - writer.add(new ASPStatement(ASP_PARAMLIST_NAME + "(" + param + ")")); - writer.add(new ASPStatement(ASP_PARAMLISTNUMERATION_NAME + "(" + name + "," +t + "," + paramNum + ")")); + writer.add(new ASPStatement(ASPRule.ASP_PARAMLIST_NAME + "(" + param + ")")); + writer.add(new ASPStatement(ASPRule.ASP_PARAMLISTNUMERATION_NAME + "(" + name + "," +t + "," + paramNum + ")")); paramNum++; //paramDefinitions.add(new ASPStatement(ASP_PARAMLIST_NAME + "(" + param + ")")); } diff --git a/src/de/dhbwstuttgart/sat/asp/model/ASPRefType.java b/src/de/dhbwstuttgart/sat/asp/writer/model/ASPRefType.java similarity index 68% rename from src/de/dhbwstuttgart/sat/asp/model/ASPRefType.java rename to src/de/dhbwstuttgart/sat/asp/writer/model/ASPRefType.java index ba3188769..6491ff33c 100644 --- a/src/de/dhbwstuttgart/sat/asp/model/ASPRefType.java +++ b/src/de/dhbwstuttgart/sat/asp/writer/model/ASPRefType.java @@ -1,7 +1,8 @@ -package de.dhbwstuttgart.sat.asp.model; +package de.dhbwstuttgart.sat.asp.writer.model; + +import de.dhbwstuttgart.sat.asp.model.ASPRule; public class ASPRefType implements ASPType { - public static final String ASP_TYPE = "type"; private final ASPParameterList params; private final String name; @@ -15,6 +16,6 @@ public class ASPRefType implements ASPType { } public String toString(){ - return ASP_TYPE + "(" + name +"," + params.name + ")"; + return ASPRule.ASP_TYPE + "(" + name +"," + params.name + ")"; } } diff --git a/src/de/dhbwstuttgart/sat/asp/model/ASPStatement.java b/src/de/dhbwstuttgart/sat/asp/writer/model/ASPStatement.java similarity index 91% rename from src/de/dhbwstuttgart/sat/asp/model/ASPStatement.java rename to src/de/dhbwstuttgart/sat/asp/writer/model/ASPStatement.java index 8e4a1d35f..76bb63e8d 100644 --- a/src/de/dhbwstuttgart/sat/asp/model/ASPStatement.java +++ b/src/de/dhbwstuttgart/sat/asp/writer/model/ASPStatement.java @@ -1,4 +1,4 @@ -package de.dhbwstuttgart.sat.asp.model; +package de.dhbwstuttgart.sat.asp.writer.model; public class ASPStatement { private final String stmt; diff --git a/src/de/dhbwstuttgart/sat/asp/writer/model/ASPType.java b/src/de/dhbwstuttgart/sat/asp/writer/model/ASPType.java new file mode 100644 index 000000000..da6942181 --- /dev/null +++ b/src/de/dhbwstuttgart/sat/asp/writer/model/ASPType.java @@ -0,0 +1,4 @@ +package de.dhbwstuttgart.sat.asp.writer.model; + +public interface ASPType { +} diff --git a/src/de/dhbwstuttgart/sat/asp/model/ASPTypeVar.java b/src/de/dhbwstuttgart/sat/asp/writer/model/ASPTypeVar.java similarity index 83% rename from src/de/dhbwstuttgart/sat/asp/model/ASPTypeVar.java rename to src/de/dhbwstuttgart/sat/asp/writer/model/ASPTypeVar.java index e2f87636b..4b07d30b4 100644 --- a/src/de/dhbwstuttgart/sat/asp/model/ASPTypeVar.java +++ b/src/de/dhbwstuttgart/sat/asp/writer/model/ASPTypeVar.java @@ -1,4 +1,4 @@ -package de.dhbwstuttgart.sat.asp.model; +package de.dhbwstuttgart.sat.asp.writer.model; public class ASPTypeVar implements ASPType{ private final String name; diff --git a/test/asp/ClingoTest.java b/test/asp/ClingoTest.java new file mode 100644 index 000000000..dbfa70d8d --- /dev/null +++ b/test/asp/ClingoTest.java @@ -0,0 +1,46 @@ +package asp; + +import de.dhbwstuttgart.parser.NullToken; +import de.dhbwstuttgart.sat.asp.writer.ASPGenerator; +import de.dhbwstuttgart.sat.asp.Clingo; +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 org.junit.Test; + +import java.io.*; +import java.util.*; + +public class ClingoTest { + public static final String rootDirectory = "~/Sync/HiwiJob/ResearchPapers/MasterarbeitStadelmeier/asp/unifyWithoutWildcards"; + public static final String tempDirectory = "/tmp/"; + + @Test + public void test() throws IOException, InterruptedException { + String content = ""; + content = new ASPGenerator(this.getPairs(), this.getFC()).getASP(); + + PrintWriter writer = new PrintWriter(tempDirectory + "test.lp", "UTF-8"); + writer.println(content); + writer.close(); + + Clingo clingo = new Clingo(Arrays.asList(new File(tempDirectory + "test.lp"))); + System.out.println(clingo.runClingo()); + } + + public Collection getFC() { + Set ret = new HashSet<>(); + ret.add(ASTFactory.createObjectClass()); + ret.add(ASTFactory.createClass(java.util.List.class)); + return ret; + } + + public ConstraintSet getPairs() { + ConstraintSet ret = new ConstraintSet<>(); + ret.addUndConstraint(new Pair(TypePlaceholder.fresh(new NullToken()), ASTFactory.createObjectType(), PairOperator.SMALLERDOT)); + return ret; + } +} diff --git a/test/asp/typeinference/ASPTest.java b/test/asp/typeinference/ASPTest.java index 5074e4f30..b41d94054 100644 --- a/test/asp/typeinference/ASPTest.java +++ b/test/asp/typeinference/ASPTest.java @@ -1,7 +1,7 @@ package asp.typeinference; import de.dhbwstuttgart.core.JavaTXCompiler; -import de.dhbwstuttgart.sat.asp.ASPGenerator; +import de.dhbwstuttgart.sat.asp.writer.ASPGenerator; import de.dhbwstuttgart.syntaxtree.ClassOrInterface; import de.dhbwstuttgart.syntaxtree.SourceFile; import de.dhbwstuttgart.typeinference.constraints.ConstraintSet; diff --git a/test/asp/unifywithoutwildcards/ASPTests.java b/test/asp/unifywithoutwildcards/ASPTests.java new file mode 100644 index 000000000..80e7bb785 --- /dev/null +++ b/test/asp/unifywithoutwildcards/ASPTests.java @@ -0,0 +1,10 @@ +package asp.unifywithoutwildcards; + +import org.junit.Test; + +public class ASPTests { + @Test + public void test(){ + + } +} diff --git a/test/typeinference/JavaTXCompilerTest.java b/test/typeinference/JavaTXCompilerTest.java index fbbed9af9..f46229541 100644 --- a/test/typeinference/JavaTXCompilerTest.java +++ b/test/typeinference/JavaTXCompilerTest.java @@ -1,29 +1,15 @@ package typeinference; import de.dhbwstuttgart.core.JavaTXCompiler; -import de.dhbwstuttgart.parser.scope.JavaClassName; -import de.dhbwstuttgart.sat.asp.ASPGenerator; -import de.dhbwstuttgart.syntaxtree.ClassOrInterface; import de.dhbwstuttgart.syntaxtree.SourceFile; -import de.dhbwstuttgart.syntaxtree.factory.ASTFactory; -import de.dhbwstuttgart.syntaxtree.factory.UnifyTypeFactory; import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter; import de.dhbwstuttgart.typedeployment.TypeInsert; import de.dhbwstuttgart.typedeployment.TypeInsertFactory; -import de.dhbwstuttgart.typeinference.constraints.Constraint; -import de.dhbwstuttgart.typeinference.constraints.ConstraintSet; -import de.dhbwstuttgart.typeinference.constraints.Pair; import de.dhbwstuttgart.typeinference.result.ResultSet; -import de.dhbwstuttgart.typeinference.typeAlgo.TYPE; -import de.dhbwstuttgart.typeinference.unify.TypeUnify; -import de.dhbwstuttgart.typeinference.unify.model.FiniteClosure; -import de.dhbwstuttgart.typeinference.unify.model.UnifyPair; import org.junit.Test; import java.io.File; import java.io.IOException; -import java.net.URL; -import java.net.URLClassLoader; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.nio.file.Files; @@ -32,7 +18,6 @@ import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Set; -import java.util.stream.Collectors; public class JavaTXCompilerTest { From 1f5071d4e4d2ac7deaa81fd77e8dd0387db1bb6a Mon Sep 17 00:00:00 2001 From: JanUlrich Date: Fri, 19 Jan 2018 15:24:49 +0100 Subject: [PATCH 03/12] =?UTF-8?q?Methode=20soll=20kein=20Feld=20mehr=20sei?= =?UTF-8?q?n.=20Nicht=20lauff=C3=A4hig!?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/de/dhbwstuttgart/syntaxtree/Field.java | 2 +- src/de/dhbwstuttgart/syntaxtree/Method.java | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/de/dhbwstuttgart/syntaxtree/Field.java b/src/de/dhbwstuttgart/syntaxtree/Field.java index 421f0ff33..4ee1675ee 100644 --- a/src/de/dhbwstuttgart/syntaxtree/Field.java +++ b/src/de/dhbwstuttgart/syntaxtree/Field.java @@ -5,7 +5,7 @@ import org.antlr.v4.runtime.Token; import java.util.ArrayList; -public class Field extends SyntaxTreeNode implements TypeScope{ +public class Field extends SyntaxTreeNode { private String name; private RefTypeOrTPHOrWildcardOrGeneric type; diff --git a/src/de/dhbwstuttgart/syntaxtree/Method.java b/src/de/dhbwstuttgart/syntaxtree/Method.java index 3686fb4ee..fd4ad1808 100644 --- a/src/de/dhbwstuttgart/syntaxtree/Method.java +++ b/src/de/dhbwstuttgart/syntaxtree/Method.java @@ -22,7 +22,7 @@ import de.dhbwstuttgart.syntaxtree.statement.Block; * @author janulrich * */ -public class Method extends Field implements IItemWithOffset +public class Method implements IItemWithOffset, TypeScope { public final Block block; private ParameterList parameterlist = new ParameterList(new ArrayList<>(), new NullToken()); @@ -54,4 +54,9 @@ public class Method extends Field implements IItemWithOffset public void accept(ASTVisitor visitor) { visitor.visit(this); } + + @Override + public Token getOffset() { + return null; + } } From 8d12821c681fde205636d83f75b57c013eaa7f29 Mon Sep 17 00:00:00 2001 From: JanUlrich Date: Sun, 21 Jan 2018 11:38:55 +0100 Subject: [PATCH 04/12] Methode erbt nicht mehr von Feld --- .../dhbwstuttgart/bytecode/NormalMethod.java | 2 +- .../SyntaxTreeGenerator.java | 7 +++---- .../syntaxtree/AbstractASTWalker.java | 2 +- .../dhbwstuttgart/syntaxtree/Constructor.java | 4 ++-- src/de/dhbwstuttgart/syntaxtree/Field.java | 6 ++++-- src/de/dhbwstuttgart/syntaxtree/Method.java | 18 ++++++++++++++---- .../syntaxtree/factory/ASTFactory.java | 5 ++--- .../syntaxtree/visual/OutputGenerator.java | 2 +- .../typeinference/typeAlgo/TYPEStmt.java | 2 +- 9 files changed, 29 insertions(+), 19 deletions(-) diff --git a/src/de/dhbwstuttgart/bytecode/NormalMethod.java b/src/de/dhbwstuttgart/bytecode/NormalMethod.java index 3f6bf2b43..16e84cc53 100644 --- a/src/de/dhbwstuttgart/bytecode/NormalMethod.java +++ b/src/de/dhbwstuttgart/bytecode/NormalMethod.java @@ -42,7 +42,7 @@ public class NormalMethod { } public RefTypeOrTPHOrWildcardOrGeneric getReturnType() { - return method.getType(); + return method.getReturnType(); } public boolean hasGen() { diff --git a/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/SyntaxTreeGenerator.java b/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/SyntaxTreeGenerator.java index c5b135e61..3d9d7aca4 100644 --- a/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/SyntaxTreeGenerator.java +++ b/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/SyntaxTreeGenerator.java @@ -139,9 +139,9 @@ public class SyntaxTreeGenerator{ block = stmtGen.convert(body.block()); } if(parentClass.equals(new JavaClassName(name))){ - return new Constructor(modifiers, name, retType, modifiers, parameterList, block, gtvDeclarations, header.getStart(), fieldInitializations); + return new Constructor(modifiers, name, retType, parameterList, block, gtvDeclarations, header.getStart(), fieldInitializations); }else{ - return new Method(modifiers, name, retType, modifiers, parameterList,block, gtvDeclarations, header.getStart()); + return new Method(modifiers, name, retType, parameterList,block, gtvDeclarations, header.getStart()); } } @@ -221,10 +221,9 @@ public class SyntaxTreeGenerator{ */ private Constructor generateStandardConstructor(String className, JavaClassName parentClass, RefType superClass, GenericDeclarationList classGenerics, Token offset){ RefType classType = ClassOrInterface.generateTypeOfClass(reg.getName(className), classGenerics, offset); - int modifiers = 0; ParameterList params = new ParameterList(new ArrayList<>(), offset); Block block = new Block(new ArrayList<>(), offset); - return new Constructor(Modifier.PUBLIC, className, classType, modifiers, params, block, classGenerics, offset, fieldInitializations); + return new Constructor(Modifier.PUBLIC, className, classType, params, block, classGenerics, offset, fieldInitializations); } private RefType convert(Java8Parser.SuperclassContext superclass) { diff --git a/src/de/dhbwstuttgart/syntaxtree/AbstractASTWalker.java b/src/de/dhbwstuttgart/syntaxtree/AbstractASTWalker.java index d771bd934..8a66629bf 100644 --- a/src/de/dhbwstuttgart/syntaxtree/AbstractASTWalker.java +++ b/src/de/dhbwstuttgart/syntaxtree/AbstractASTWalker.java @@ -61,7 +61,7 @@ public abstract class AbstractASTWalker implements ASTVisitor{ } private void visitMethod(Method method){ - method.getType().accept(this); + method.getReturnType().accept(this); method.getParameterList().accept(this); if(method.block != null) method.block.accept(this); diff --git a/src/de/dhbwstuttgart/syntaxtree/Constructor.java b/src/de/dhbwstuttgart/syntaxtree/Constructor.java index bb48be400..a99692bb8 100644 --- a/src/de/dhbwstuttgart/syntaxtree/Constructor.java +++ b/src/de/dhbwstuttgart/syntaxtree/Constructor.java @@ -14,9 +14,9 @@ public class Constructor extends Method { //TODO: Constructor braucht ein super-Statement - public Constructor(int modifier, String name, RefTypeOrTPHOrWildcardOrGeneric returnType, int modifiers, ParameterList parameterList, Block codeInsideConstructor, + public Constructor(int modifier, String name, RefTypeOrTPHOrWildcardOrGeneric returnType, ParameterList parameterList, Block codeInsideConstructor, GenericDeclarationList gtvDeclarations, Token offset, List fieldInitializations) { - super(modifier, name, returnType, modifiers, parameterList, prepareBlock(codeInsideConstructor,fieldInitializations), gtvDeclarations, offset); + super(modifier, name, returnType, parameterList, prepareBlock(codeInsideConstructor,fieldInitializations), gtvDeclarations, offset); } diff --git a/src/de/dhbwstuttgart/syntaxtree/Field.java b/src/de/dhbwstuttgart/syntaxtree/Field.java index 4ee1675ee..8a4230e3c 100644 --- a/src/de/dhbwstuttgart/syntaxtree/Field.java +++ b/src/de/dhbwstuttgart/syntaxtree/Field.java @@ -5,8 +5,9 @@ import org.antlr.v4.runtime.Token; import java.util.ArrayList; -public class Field extends SyntaxTreeNode { - +public class Field extends SyntaxTreeNode implements TypeScope{ + + public final int modifier; private String name; private RefTypeOrTPHOrWildcardOrGeneric type; @@ -14,6 +15,7 @@ public class Field extends SyntaxTreeNode { super(offset); this.name = name; this.type = type; + this.modifier = modifier; } public String getName(){ diff --git a/src/de/dhbwstuttgart/syntaxtree/Method.java b/src/de/dhbwstuttgart/syntaxtree/Method.java index fd4ad1808..99cd3f91c 100644 --- a/src/de/dhbwstuttgart/syntaxtree/Method.java +++ b/src/de/dhbwstuttgart/syntaxtree/Method.java @@ -22,16 +22,22 @@ import de.dhbwstuttgart.syntaxtree.statement.Block; * @author janulrich * */ -public class Method implements IItemWithOffset, TypeScope +public class Method extends SyntaxTreeNode implements IItemWithOffset, TypeScope { public final Block block; + public final int modifier; + public final String name; private ParameterList parameterlist = new ParameterList(new ArrayList<>(), new NullToken()); private ExceptionList exceptionlist; private GenericDeclarationList generics; + private final RefTypeOrTPHOrWildcardOrGeneric returnType; - public Method(int modifier, String name, RefTypeOrTPHOrWildcardOrGeneric returnType, int modifiers, ParameterList parameterList, Block block, + public Method(int modifier, String name, RefTypeOrTPHOrWildcardOrGeneric returnType, ParameterList parameterList, Block block, GenericDeclarationList gtvDeclarations, Token offset) { - super(name, returnType, modifiers, offset); + super(offset); + this.name = name; + this.modifier = modifier; + this.returnType = returnType; this.parameterlist = parameterList; this.block = block; this.generics = gtvDeclarations; @@ -47,7 +53,7 @@ public class Method implements IItemWithOffset, TypeScope @Override public RefTypeOrTPHOrWildcardOrGeneric getReturnType() { - return this.getType(); + return this.returnType; } @Override @@ -59,4 +65,8 @@ public class Method implements IItemWithOffset, TypeScope public Token getOffset() { return null; } + + public String getName() { + return name; + } } diff --git a/src/de/dhbwstuttgart/syntaxtree/factory/ASTFactory.java b/src/de/dhbwstuttgart/syntaxtree/factory/ASTFactory.java index 046b97b88..59e543855 100644 --- a/src/de/dhbwstuttgart/syntaxtree/factory/ASTFactory.java +++ b/src/de/dhbwstuttgart/syntaxtree/factory/ASTFactory.java @@ -88,7 +88,7 @@ public class ASTFactory { return null; } - return new de.dhbwstuttgart.syntaxtree.Constructor(constructor.getModifiers(), name,returnType, modifier, parameterList, block, gtvDeclarations, offset, new ArrayList<>()); + return new de.dhbwstuttgart.syntaxtree.Constructor(modifier, name,returnType, parameterList, block, gtvDeclarations, offset, new ArrayList<>()); } //private static RefType createType(Class classType) { @@ -109,9 +109,8 @@ public class ASTFactory { Block block = new Block(new ArrayList(), new NullToken()); GenericDeclarationList gtvDeclarations = createGenerics(jreMethod.getTypeParameters(), inClass, jreMethod.getName()); Token offset = new NullToken(); - int modifier = jreMethod.getModifiers(); - return new Method(jreMethod.getModifiers(), name,returnType, modifier, parameterList, block, gtvDeclarations, offset); + return new Method(jreMethod.getModifiers(), name,returnType, parameterList, block, gtvDeclarations, offset); } public static GenericDeclarationList createGenerics(TypeVariable[] typeParameters, Class context, String methodName){ diff --git a/src/de/dhbwstuttgart/syntaxtree/visual/OutputGenerator.java b/src/de/dhbwstuttgart/syntaxtree/visual/OutputGenerator.java index e760e458c..d56c39d8c 100644 --- a/src/de/dhbwstuttgart/syntaxtree/visual/OutputGenerator.java +++ b/src/de/dhbwstuttgart/syntaxtree/visual/OutputGenerator.java @@ -81,7 +81,7 @@ public class OutputGenerator implements ASTVisitor{ @Override public void visit(Method method) { - method.getType().accept(this); + method.getReturnType().accept(this); out.append(" " + method.getName()); method.getParameterList().accept(this); if(method.block != null) diff --git a/src/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java b/src/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java index 2152fc65c..3448e8e3d 100644 --- a/src/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java +++ b/src/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java @@ -345,7 +345,7 @@ public class TYPEStmt implements StatementVisitor{ for(Method m : cl.getMethods()){ if(m.getName().equals(name) && m.getParameterList().getFormalparalist().size() == numArgs){ - RefTypeOrTPHOrWildcardOrGeneric retType = info.checkGTV(m.getType()); + RefTypeOrTPHOrWildcardOrGeneric retType = info.checkGTV(m.getReturnType()); ret.add(new MethodAssumption(cl, retType, convertParams(m.getParameterList(),info), createTypeScope(cl, m))); From 0610ea8e63c02f2cfda8004e6b5bd95f54527175 Mon Sep 17 00:00:00 2001 From: JanUlrich Date: Mon, 29 Jan 2018 17:32:25 +0100 Subject: [PATCH 05/12] FC Generator --- src/de/dhbwstuttgart/core/JavaTXCompiler.java | 1 + .../SyntaxTreeGenerator/FCGenerator.java | 148 ++++++++++++++++++ .../syntaxtree/factory/UnifyTypeFactory.java | 53 +------ 3 files changed, 151 insertions(+), 51 deletions(-) create mode 100644 src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/FCGenerator.java diff --git a/src/de/dhbwstuttgart/core/JavaTXCompiler.java b/src/de/dhbwstuttgart/core/JavaTXCompiler.java index 2abd8b9d2..86666a49f 100644 --- a/src/de/dhbwstuttgart/core/JavaTXCompiler.java +++ b/src/de/dhbwstuttgart/core/JavaTXCompiler.java @@ -89,6 +89,7 @@ public class JavaTXCompiler { final ConstraintSet cons = getConstraints(); FiniteClosure finiteClosure = UnifyTypeFactory.generateFC(allClasses); + System.out.println(finiteClosure); ConstraintSet unifyCons = UnifyTypeFactory.convert(cons); TypeUnify unify = new TypeUnify(); diff --git a/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/FCGenerator.java b/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/FCGenerator.java new file mode 100644 index 000000000..cbca13ce6 --- /dev/null +++ b/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/FCGenerator.java @@ -0,0 +1,148 @@ +package de.dhbwstuttgart.parser.SyntaxTreeGenerator; + +import de.dhbwstuttgart.exceptions.DebugException; +import de.dhbwstuttgart.exceptions.NotImplementedException; +import de.dhbwstuttgart.syntaxtree.ClassOrInterface; +import de.dhbwstuttgart.syntaxtree.GenericTypeVar; +import de.dhbwstuttgart.syntaxtree.factory.ASTFactory; +import de.dhbwstuttgart.syntaxtree.factory.UnifyTypeFactory; +import de.dhbwstuttgart.syntaxtree.type.*; +import de.dhbwstuttgart.typeinference.constraints.Pair; +import de.dhbwstuttgart.typeinference.unify.model.*; + +import java.util.*; + +public class FCGenerator { + /** + * Baut die FiniteClosure aus availableClasses. + * Klassen welche nicht in availableClasses vorkommen werden im Java Classpath nachgeschlagen. + * + * @param availableClasses - Alle geparsten Klassen + */ + public static Set toFC(Collection availableClasses) throws ClassNotFoundException { + HashSet pairs = new HashSet<>(); + for(ClassOrInterface cly : availableClasses){ + pairs.addAll(getSuperTypes(cly, availableClasses)); + } + System.out.println(pairs); + return pairs; + } + + /** + * Bildet eine Kette vom übergebenen Typ bis hin zum höchsten bekannten Typ + * Als Generics werden TPHs benutzt, welche der Unifikationsalgorithmus korrekt interpretieren muss. + * Die verwendeten TPHs werden in der Kette nach oben gereicht, so erhält der selbe GTV immer den selben TPH + * @param forType + * @return + */ + private static List getSuperTypes(ClassOrInterface forType, Collection availableClasses) throws ClassNotFoundException { + return getSuperTypes(forType, availableClasses, new HashMap<>()); + } + + //TODO: implements Interface auch als superklassen beachten + private static List getSuperTypes(ClassOrInterface forType, Collection availableClasses, HashMap gtvs) throws ClassNotFoundException { + List params = new ArrayList<>(); + //Die GTVs, die in forType hinzukommen: + HashMap newGTVs = new HashMap<>(); + //Generics mit gleichem Namen müssen den selben TPH bekommen + for(GenericTypeVar gtv : forType.getGenerics()){ + if(!gtvs.containsKey(gtv.getParsedName())){ + gtvs.put(gtv.getParsedName(), PlaceholderType.freshPlaceholder()); + newGTVs.put(gtv.getParsedName(), PlaceholderType.freshPlaceholder()); + } + params.add(gtvs.get(gtv.getParsedName())); + } + + Optional hasSuperclass = availableClasses.stream().filter(cl -> forType.getSuperClass().getName().equals(cl.getClassName())).findAny(); + ClassOrInterface superClass; + if(!hasSuperclass.isPresent()) //Wenn es die Klasse in den available Klasses nicht gibt wird sie im Classpath gesucht. Ansonsten Exception + { + superClass = ASTFactory.createClass(ClassLoader.getSystemClassLoader().loadClass(forType.getSuperClass().getName().toString())); + }else{ + superClass = hasSuperclass.get(); + } + /* + Die Parameter der superklasse müssen jetzt nach den Angaben in der Subklasse + modifiziert werden + Beispie: Matrix extends Vector> + Den ersten Parameter mit Vector austauschen und dort alle Generics zu den Typplaceholdern in gtvs austauschen + */ + //Hier vermerken, welche Typen im der Superklasse ausgetauscht werden müssen + Iterator itGenParams = superClass.getGenerics().iterator(); + Iterator itSetParams = forType.getSuperClass().getParaList().iterator(); + while(itGenParams.hasNext()){ + RefTypeOrTPHOrWildcardOrGeneric setType = itSetParams.next(); + //In diesem Typ die GTVs durch TPHs und Einsetzungen austauschen: + UnifyType setSetType = setType.acceptTV(new TypeExchanger(gtvs)); + newGTVs.put(itGenParams.next().getParsedName(), setSetType); + } + + UnifyType superType = forType.getSuperClass().acceptTV(new TypeExchanger(newGTVs)); + + TypeParams paramList = new TypeParams(params); + UnifyType t1 = new ReferenceType(forType.getClassName().toString(), paramList); + UnifyType t2 = superType; + + UnifyPair ret = UnifyTypeFactory.generateSmallerPair(t1, t2); + + List superTypes; + //Rekursiver Aufruf. Abbruchbedingung ist Object als Superklasse: + if(superClass.getClassName().equals(ASTFactory.createObjectClass().getClassName())){ + superTypes = Arrays.asList(UnifyTypeFactory.generateSmallerPair(UnifyTypeFactory.convert(ASTFactory.createObjectType()), UnifyTypeFactory.convert(ASTFactory.createObjectType()))); + }else{ + superTypes = getSuperTypes(superClass, availableClasses, newGTVs); + } + + List retList = new ArrayList<>(); + retList.add(ret); + retList.addAll(superTypes); + + return retList; + } + + /** + * Tauscht die GTVs in einem Typ gegen die entsprechenden Typen in der übergebenen Map aus. + */ + private static class TypeExchanger implements TypeVisitor{ + + private final HashMap gtvs; + + TypeExchanger(HashMap gtvs){ + this.gtvs = gtvs; + } + + @Override + public UnifyType visit(RefType refType) { + List params = new ArrayList<>(); + for(RefTypeOrTPHOrWildcardOrGeneric param : refType.getParaList()){ + params.add(param.acceptTV(this)); + } + TypeParams paramList = new TypeParams(params); + UnifyType ret = new ReferenceType(refType.getName().toString(), paramList); + return ret; + } + + @Override + public UnifyType visit(SuperWildcardType superWildcardType) { + throw new DebugException("Dieser Fall darf nicht auftreten"); + } + + @Override + public UnifyType visit(TypePlaceholder typePlaceholder) { + throw new DebugException("Dieser Fall darf nicht auftreten"); + } + + @Override + public UnifyType visit(ExtendsWildcardType extendsWildcardType) { + throw new DebugException("Dieser Fall darf nicht auftreten"); + } + + @Override + public UnifyType visit(GenericRefType genericRefType) { + if(! gtvs.containsKey(genericRefType.getParsedName())) + throw new DebugException("Dieser Fall darf nicht auftreten"); + return gtvs.get(genericRefType.getParsedName()); + } + + } +} diff --git a/src/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java b/src/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java index 6e48c7974..aef8068cb 100644 --- a/src/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java +++ b/src/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java @@ -6,6 +6,7 @@ import java.util.stream.Collectors; import de.dhbwstuttgart.exceptions.DebugException; import de.dhbwstuttgart.exceptions.NotImplementedException; import de.dhbwstuttgart.parser.NullToken; +import de.dhbwstuttgart.parser.SyntaxTreeGenerator.FCGenerator; import de.dhbwstuttgart.parser.scope.JavaClassName; import de.dhbwstuttgart.syntaxtree.ClassOrInterface; import de.dhbwstuttgart.syntaxtree.GenericTypeVar; @@ -35,57 +36,7 @@ public class UnifyTypeFactory { Generell dürfen sie immer die gleichen Namen haben. TODO: die transitive Hülle bilden */ - HashSet pairs = new HashSet<>(); - for(ClassOrInterface cly : fromClasses){ - pairs.addAll(getSuperTypes(cly, fromClasses)); - } - return new FiniteClosure(pairs); - } - - /** - * Bildet eine Kette vom übergebenen Typ bis hin zum höchsten bekannten Typ - * Als Generics werden TPHs benutzt, welche der Unifikationsalgorithmus korrekt interpretieren muss. - * Die verwendeten TPHs werden in der Kette nach oben gereicht, so erhält der selbe GTV immer den selben TPH - * @param forType - * @return - */ - private static List getSuperTypes(ClassOrInterface forType, List availableClasses) throws ClassNotFoundException { - return getSuperTypes(forType, availableClasses, new HashMap<>()); - } - - private static List getSuperTypes(ClassOrInterface forType, List availableClasses, HashMap gtvs) throws ClassNotFoundException { - List params = new ArrayList<>(); - //Generics mit gleichem Namen müssen den selben TPH bekommen - for(GenericTypeVar gtv : forType.getGenerics()){ - if(!gtvs.containsKey(gtv.getParsedName())) - gtvs.put(gtv.getParsedName(), PlaceholderType.freshPlaceholder()); - params.add(gtvs.get(gtv.getParsedName())); - } - Optional hasSuperclass = availableClasses.stream().filter(cl -> forType.getSuperClass().getName().equals(cl.getClassName())).findAny(); - ClassOrInterface superClass; - if(!hasSuperclass.isPresent()) //TODO: Wenn es die Object-Klasse ist, dann ist es in Ordnung, ansonsten Fehler ausgeben: - { - superClass = ASTFactory.createClass(ClassLoader.getSystemClassLoader().loadClass(forType.getSuperClass().getName().toString())); - }else{ - superClass = hasSuperclass.get(); - } - List superTypes; - if(superClass.getClassName().equals(ASTFactory.createObjectClass().getClassName())){ - superTypes = Arrays.asList(generateSmallerPair(convert(ASTFactory.createObjectType()), convert(ASTFactory.createObjectType()))); - }else{ - superTypes = getSuperTypes(superClass, availableClasses, gtvs); - } - - TypeParams paramList = new TypeParams(params); - UnifyType t1 = new ReferenceType(forType.getClassName().toString(), paramList); - UnifyType t2 = superTypes.get(0).getLhsType(); - - UnifyPair ret = generateSmallerPair(t1, t2); - List retList = new ArrayList<>(); - retList.add(ret); - retList.addAll(superTypes); - - return retList; + return new FiniteClosure(FCGenerator.toFC(fromClasses)); } public static UnifyPair generateSmallerPair(UnifyType tl, UnifyType tr){ From ede55d228e23eeaf7fd054357e1b7b51ada0f6f8 Mon Sep 17 00:00:00 2001 From: JanUlrich Date: Mon, 29 Jan 2018 17:35:49 +0100 Subject: [PATCH 06/12] Fehler in ASTFactory beheben. GenericRefType statt RefType in den Parameterlisten --- src/de/dhbwstuttgart/syntaxtree/factory/ASTFactory.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/de/dhbwstuttgart/syntaxtree/factory/ASTFactory.java b/src/de/dhbwstuttgart/syntaxtree/factory/ASTFactory.java index 59e543855..6acb4214d 100644 --- a/src/de/dhbwstuttgart/syntaxtree/factory/ASTFactory.java +++ b/src/de/dhbwstuttgart/syntaxtree/factory/ASTFactory.java @@ -48,7 +48,7 @@ public class ASTFactory { if(superjreClass != null){ List params = new ArrayList<>(); for(TypeVariable tv : superjreClass.getTypeParameters()){ - params.add(new RefType(new GenericTypeName(new GenericContext( name, null),tv.getName()), new NullToken())); + params.add(new GenericRefType(new GenericTypeName(new GenericContext( name, null),tv.getName()), new NullToken())); } superClass = new RefType(new JavaClassName(superjreClass.getName()), params, new NullToken()); }else{//Jede Klasse und jedes Interface erbt von Object: (auch Object selbst!) From c7dea4c86bfa9c22567dd9452537bca5518c2b30 Mon Sep 17 00:00:00 2001 From: JanUlrich Date: Mon, 29 Jan 2018 18:26:14 +0100 Subject: [PATCH 07/12] Matrix Test --- .../syntaxtree/factory/UnifyTypeFactory.java | 1 - .../typeinference/unify/model/UnifyType.java | 10 ++++++++++ test/typeinference/MatrixTest.java | 9 +++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 test/typeinference/MatrixTest.java diff --git a/src/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java b/src/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java index aef8068cb..a962c2bc5 100644 --- a/src/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java +++ b/src/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java @@ -26,7 +26,6 @@ public class UnifyTypeFactory { public static FiniteClosure generateFC(List fromClasses) throws ClassNotFoundException { /* - TODO: Generics werden zu TPHs Die transitive Hülle muss funktionieren. Man darf schreiben List extends AL und Vector extends List diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/UnifyType.java b/src/de/dhbwstuttgart/typeinference/unify/model/UnifyType.java index 567181984..1080f03b6 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/UnifyType.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/UnifyType.java @@ -96,4 +96,14 @@ public abstract class UnifyType { ret.addAll(typeParams.getInvolvedPlaceholderTypes()); return ret; } + + @Override + public int hashCode() { + return this.toString().hashCode(); + } + + @Override + public boolean equals(Object obj) { + return this.toString().equals(obj.toString()); + } } \ No newline at end of file diff --git a/test/typeinference/MatrixTest.java b/test/typeinference/MatrixTest.java new file mode 100644 index 000000000..8cc587c9b --- /dev/null +++ b/test/typeinference/MatrixTest.java @@ -0,0 +1,9 @@ +package typeinference; + +import java.io.File; + +public class MatrixTest extends JavaTXCompilerTest{ + public MatrixTest() { + this.fileToTest = new File(rootDirectory+"Matrix.jav"); + } +} \ No newline at end of file From 5d94820fed8e2681e1d1848febad2bd57d38d0ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Mon, 29 Jan 2018 21:30:45 +0100 Subject: [PATCH 08/12] modified: src/de/dhbwstuttgart/typeinference/unify/RuleSet.java modified: src/de/dhbwstuttgart/typeinference/unify/model/Node.java Genauere Fehlermeldung --- src/de/dhbwstuttgart/typeinference/unify/RuleSet.java | 2 +- src/de/dhbwstuttgart/typeinference/unify/model/Node.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/de/dhbwstuttgart/typeinference/unify/RuleSet.java b/src/de/dhbwstuttgart/typeinference/unify/RuleSet.java index 39ea0effc..8c41660b5 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/RuleSet.java +++ b/src/de/dhbwstuttgart/typeinference/unify/RuleSet.java @@ -305,7 +305,7 @@ public class RuleSet implements IRuleSet{ if(!rhsSType.getName().equals(lhsSType.getName())) return Optional.empty(); - if(!(lhsSType.getTypeParams().size()==rhsSType.getTypeParams().size()))throw new DebugException("Fehler in Unifizierung"); + if(!(lhsSType.getTypeParams().size()==rhsSType.getTypeParams().size()))throw new DebugException("Fehler in Unifizierung"+ " " + lhsSType.toString() + " " + rhsSType.toString()); //if(rhsSType.getTypeParams().size() != lhsSType.getTypeParams().size()) // return Optional.empty(); diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/Node.java b/src/de/dhbwstuttgart/typeinference/unify/model/Node.java index d24b68253..c6aa9b3e1 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/Node.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/Node.java @@ -94,6 +94,6 @@ class Node { @Override public String toString() { - return "Node(" + content.toString() + ")"; + return "Node(" + content.toString() + ")\n"; } } From 39793b461e934819280ef55d8e35deea1c82e3ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Mon, 29 Jan 2018 22:35:48 +0100 Subject: [PATCH 09/12] modified: test/javFiles/Matrix.jav Falsche Typen in methode korrigiert. --- test/javFiles/Matrix.jav | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/javFiles/Matrix.jav b/test/javFiles/Matrix.jav index e6aa84cd4..14b58cdee 100644 --- a/test/javFiles/Matrix.jav +++ b/test/javFiles/Matrix.jav @@ -2,8 +2,8 @@ import java.util.Vector; class Matrix extends Vector> { - methode(Matrix m) { - Vector> i; + methode(Vector> m) { + Matrix i; methode(i); } } From 027538a0829f02d4d20103075ac735a702314f6a Mon Sep 17 00:00:00 2001 From: JanUlrich Date: Tue, 30 Jan 2018 01:08:21 +0100 Subject: [PATCH 10/12] =?UTF-8?q?Unary=20Expression=20und=20while=20statem?= =?UTF-8?q?ent=20anf=C3=BCgen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../syntaxtree/statement/NegativeExpr.html | 2 +- .../syntaxtree/statement/NotExpr.html | 2 +- .../syntaxtree/statement/PositivExpr.html | 2 +- .../syntaxtree/statement/PostDecExpr.html | 2 +- .../syntaxtree/statement/PostIncExpr.html | 2 +- .../syntaxtree/statement/PreDecExpr.html | 2 +- .../syntaxtree/statement/PreIncExpr.html | 2 +- .../statement/class-use/NegativeExpr.html | 6 +- .../statement/class-use/NotExpr.html | 6 +- .../statement/class-use/PositivExpr.html | 6 +- .../statement/class-use/PostDecExpr.html | 6 +- .../statement/class-use/PostIncExpr.html | 6 +- .../statement/class-use/PreDecExpr.html | 6 +- .../statement/class-use/PreIncExpr.html | 6 +- .../dhbwstuttgart/bytecode/BytecodeGen.java | 12 ++-- .../bytecode/BytecodeGenMethod.java | 11 +-- .../dhbwstuttgart/bytecode/KindOfLambda.java | 12 ++-- .../StatementGenerator.java | 27 ++++--- .../SyntaxTreeGenerator/SyntacticSugar.java | 30 +++++--- .../SyntaxTreeGenerator/TypeGenerator.java | 7 +- .../syntaxtree/AbstractASTWalker.java | 11 +-- .../syntaxtree/StatementVisitor.java | 4 +- .../syntaxtree/factory/ASTFactory.java | 2 +- .../syntaxtree/statement/IfStmt.java | 6 +- .../statement/JavaInternalExpression.java | 12 ++++ .../syntaxtree/statement/NegativeExpr.java | 18 ----- .../syntaxtree/statement/NotExpr.java | 14 ---- .../syntaxtree/statement/PositivExpr.java | 15 ---- .../syntaxtree/statement/PostDecExpr.java | 17 ----- .../syntaxtree/statement/PostIncExpr.java | 15 ---- .../syntaxtree/statement/PreDecExpr.java | 17 ----- .../syntaxtree/statement/PreIncExpr.java | 12 ---- .../syntaxtree/statement/UnaryExpr.java | 29 +++++++- .../syntaxtree/statement/UnaryMinus.java | 12 ---- .../syntaxtree/statement/UnaryNot.java | 7 -- .../syntaxtree/statement/UnaryPlus.java | 20 ------ .../syntaxtree/visual/OutputGenerator.java | 10 +-- .../visual/TypeOutputGenerator.java | 5 -- .../typedeployment/TypeInsertPlacer.java | 2 + .../typeinference/typeAlgo/TYPEStmt.java | 28 ++++++-- test/javFiles/Matrix.jav | 70 ++++++------------- 41 files changed, 187 insertions(+), 294 deletions(-) create mode 100644 src/de/dhbwstuttgart/syntaxtree/statement/JavaInternalExpression.java delete mode 100644 src/de/dhbwstuttgart/syntaxtree/statement/NegativeExpr.java delete mode 100644 src/de/dhbwstuttgart/syntaxtree/statement/NotExpr.java delete mode 100644 src/de/dhbwstuttgart/syntaxtree/statement/PositivExpr.java delete mode 100644 src/de/dhbwstuttgart/syntaxtree/statement/PostDecExpr.java delete mode 100644 src/de/dhbwstuttgart/syntaxtree/statement/PostIncExpr.java delete mode 100644 src/de/dhbwstuttgart/syntaxtree/statement/PreDecExpr.java delete mode 100644 src/de/dhbwstuttgart/syntaxtree/statement/PreIncExpr.java delete mode 100644 src/de/dhbwstuttgart/syntaxtree/statement/UnaryMinus.java delete mode 100644 src/de/dhbwstuttgart/syntaxtree/statement/UnaryNot.java delete mode 100644 src/de/dhbwstuttgart/syntaxtree/statement/UnaryPlus.java diff --git a/doc/LambdaJavadoc/de/dhbwstuttgart/syntaxtree/statement/NegativeExpr.html b/doc/LambdaJavadoc/de/dhbwstuttgart/syntaxtree/statement/NegativeExpr.html index 274fb17d4..7ddcc7466 100644 --- a/doc/LambdaJavadoc/de/dhbwstuttgart/syntaxtree/statement/NegativeExpr.html +++ b/doc/LambdaJavadoc/de/dhbwstuttgart/syntaxtree/statement/NegativeExpr.html @@ -115,7 +115,7 @@ var activeTableTab = "activeTableTab";
    • -
    • de.dhbwstuttgart.syntaxtree.statement.NegativeExpr
    • +
    • de.dhbwstuttgart.syntaxtree.statement.javaInternal.NegativeExpr
  • diff --git a/doc/LambdaJavadoc/de/dhbwstuttgart/syntaxtree/statement/NotExpr.html b/doc/LambdaJavadoc/de/dhbwstuttgart/syntaxtree/statement/NotExpr.html index d59ab82bc..1eb88e1d6 100644 --- a/doc/LambdaJavadoc/de/dhbwstuttgart/syntaxtree/statement/NotExpr.html +++ b/doc/LambdaJavadoc/de/dhbwstuttgart/syntaxtree/statement/NotExpr.html @@ -115,7 +115,7 @@ var activeTableTab = "activeTableTab";
  • de.dhbwstuttgart.syntaxtree.statement.UnaryExpr
    • -
    • de.dhbwstuttgart.syntaxtree.statement.NotExpr
    • +
    • de.dhbwstuttgart.syntaxtree.statement.javaInternal.NotExpr
  • diff --git a/doc/LambdaJavadoc/de/dhbwstuttgart/syntaxtree/statement/PositivExpr.html b/doc/LambdaJavadoc/de/dhbwstuttgart/syntaxtree/statement/PositivExpr.html index 6dfdb37bc..e02874de6 100644 --- a/doc/LambdaJavadoc/de/dhbwstuttgart/syntaxtree/statement/PositivExpr.html +++ b/doc/LambdaJavadoc/de/dhbwstuttgart/syntaxtree/statement/PositivExpr.html @@ -115,7 +115,7 @@ var activeTableTab = "activeTableTab";
  • de.dhbwstuttgart.syntaxtree.statement.UnaryExpr
    • -
    • de.dhbwstuttgart.syntaxtree.statement.PositivExpr
    • +
    • de.dhbwstuttgart.syntaxtree.statement.javaInternal.PositivExpr
  • diff --git a/doc/LambdaJavadoc/de/dhbwstuttgart/syntaxtree/statement/PostDecExpr.html b/doc/LambdaJavadoc/de/dhbwstuttgart/syntaxtree/statement/PostDecExpr.html index 86c5a8fa3..9c293c667 100644 --- a/doc/LambdaJavadoc/de/dhbwstuttgart/syntaxtree/statement/PostDecExpr.html +++ b/doc/LambdaJavadoc/de/dhbwstuttgart/syntaxtree/statement/PostDecExpr.html @@ -115,7 +115,7 @@ var activeTableTab = "activeTableTab";
  • de.dhbwstuttgart.syntaxtree.statement.UnaryExpr
    • -
    • de.dhbwstuttgart.syntaxtree.statement.PostDecExpr
    • +
    • de.dhbwstuttgart.syntaxtree.statement.javaInternal.PostDecExpr
  • diff --git a/doc/LambdaJavadoc/de/dhbwstuttgart/syntaxtree/statement/PostIncExpr.html b/doc/LambdaJavadoc/de/dhbwstuttgart/syntaxtree/statement/PostIncExpr.html index 94b06b129..4d52f3996 100644 --- a/doc/LambdaJavadoc/de/dhbwstuttgart/syntaxtree/statement/PostIncExpr.html +++ b/doc/LambdaJavadoc/de/dhbwstuttgart/syntaxtree/statement/PostIncExpr.html @@ -115,7 +115,7 @@ var activeTableTab = "activeTableTab";
  • de.dhbwstuttgart.syntaxtree.statement.UnaryExpr
    • -
    • de.dhbwstuttgart.syntaxtree.statement.PostIncExpr
    • +
    • de.dhbwstuttgart.syntaxtree.statement.javaInternal.PostIncExpr
  • diff --git a/doc/LambdaJavadoc/de/dhbwstuttgart/syntaxtree/statement/PreDecExpr.html b/doc/LambdaJavadoc/de/dhbwstuttgart/syntaxtree/statement/PreDecExpr.html index 47989bf28..3027535ed 100644 --- a/doc/LambdaJavadoc/de/dhbwstuttgart/syntaxtree/statement/PreDecExpr.html +++ b/doc/LambdaJavadoc/de/dhbwstuttgart/syntaxtree/statement/PreDecExpr.html @@ -115,7 +115,7 @@ var activeTableTab = "activeTableTab";
  • de.dhbwstuttgart.syntaxtree.statement.UnaryExpr
    • -
    • de.dhbwstuttgart.syntaxtree.statement.PreDecExpr
    • +
    • de.dhbwstuttgart.syntaxtree.statement.javaInternal.PreDecExpr
  • diff --git a/doc/LambdaJavadoc/de/dhbwstuttgart/syntaxtree/statement/PreIncExpr.html b/doc/LambdaJavadoc/de/dhbwstuttgart/syntaxtree/statement/PreIncExpr.html index 437a143fd..e2caa4bd8 100644 --- a/doc/LambdaJavadoc/de/dhbwstuttgart/syntaxtree/statement/PreIncExpr.html +++ b/doc/LambdaJavadoc/de/dhbwstuttgart/syntaxtree/statement/PreIncExpr.html @@ -115,7 +115,7 @@ var activeTableTab = "activeTableTab";
  • de.dhbwstuttgart.syntaxtree.statement.UnaryExpr
    • -
    • de.dhbwstuttgart.syntaxtree.statement.PreIncExpr
    • +
    • de.dhbwstuttgart.syntaxtree.statement.javaInternal.PreIncExpr
  • diff --git a/doc/LambdaJavadoc/de/dhbwstuttgart/syntaxtree/statement/class-use/NegativeExpr.html b/doc/LambdaJavadoc/de/dhbwstuttgart/syntaxtree/statement/class-use/NegativeExpr.html index beb55c1f2..6e30f09e8 100644 --- a/doc/LambdaJavadoc/de/dhbwstuttgart/syntaxtree/statement/class-use/NegativeExpr.html +++ b/doc/LambdaJavadoc/de/dhbwstuttgart/syntaxtree/statement/class-use/NegativeExpr.html @@ -3,7 +3,7 @@ -Uses of Class de.dhbwstuttgart.syntaxtree.statement.NegativeExpr +Uses of Class de.dhbwstuttgart.syntaxtree.statement.javaInternal.NegativeExpr @@ -70,9 +70,9 @@
    -

    Uses of Class
    de.dhbwstuttgart.syntaxtree.statement.NegativeExpr

    +

    Uses of Class
    de.dhbwstuttgart.syntaxtree.statement.NegativeExpr

    -
    No usage of de.dhbwstuttgart.syntaxtree.statement.NegativeExpr
    +
    No usage of de.dhbwstuttgart.syntaxtree.statement.javaInternal.NegativeExpr
    -

    Uses of Class
    de.dhbwstuttgart.syntaxtree.statement.NotExpr

    +

    Uses of Class
    de.dhbwstuttgart.syntaxtree.statement.NotExpr

    -
    No usage of de.dhbwstuttgart.syntaxtree.statement.NotExpr
    +
    No usage of de.dhbwstuttgart.syntaxtree.statement.javaInternal.NotExpr
    -

    Uses of Class
    de.dhbwstuttgart.syntaxtree.statement.PositivExpr

    +

    Uses of Class
    de.dhbwstuttgart.syntaxtree.statement.PositivExpr

    -
    No usage of de.dhbwstuttgart.syntaxtree.statement.PositivExpr
    +
    No usage of de.dhbwstuttgart.syntaxtree.statement.javaInternal.PositivExpr
    -

    Uses of Class
    de.dhbwstuttgart.syntaxtree.statement.PostDecExpr

    +

    Uses of Class
    de.dhbwstuttgart.syntaxtree.statement.PostDecExpr

    -
    No usage of de.dhbwstuttgart.syntaxtree.statement.PostDecExpr
    +
    No usage of de.dhbwstuttgart.syntaxtree.statement.javaInternal.PostDecExpr
    -

    Uses of Class
    de.dhbwstuttgart.syntaxtree.statement.PostIncExpr

    +

    Uses of Class
    de.dhbwstuttgart.syntaxtree.statement.PostIncExpr

    -
    No usage of de.dhbwstuttgart.syntaxtree.statement.PostIncExpr
    +
    No usage of de.dhbwstuttgart.syntaxtree.statement.javaInternal.PostIncExpr
    -

    Uses of Class
    de.dhbwstuttgart.syntaxtree.statement.PreDecExpr

    +

    Uses of Class
    de.dhbwstuttgart.syntaxtree.statement.PreDecExpr

    -
    No usage of de.dhbwstuttgart.syntaxtree.statement.PreDecExpr
    +
    No usage of de.dhbwstuttgart.syntaxtree.statement.javaInternal.PreDecExpr
    -

    Uses of Class
    de.dhbwstuttgart.syntaxtree.statement.PreIncExpr

    +

    Uses of Class
    de.dhbwstuttgart.syntaxtree.statement.PreIncExpr

    -
    No usage of de.dhbwstuttgart.syntaxtree.statement.PreIncExpr
    +
    No usage of de.dhbwstuttgart.syntaxtree.statement.javaInternal.PreIncExpr
    diff --git a/src/de/dhbwstuttgart/bytecode/BytecodeGen.java b/src/de/dhbwstuttgart/bytecode/BytecodeGen.java index f1994c204..6fff6729c 100644 --- a/src/de/dhbwstuttgart/bytecode/BytecodeGen.java +++ b/src/de/dhbwstuttgart/bytecode/BytecodeGen.java @@ -4,6 +4,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; +import de.dhbwstuttgart.exceptions.NotImplementedException; import de.dhbwstuttgart.syntaxtree.statement.*; import org.objectweb.asm.ClassWriter; import org.objectweb.asm.FieldVisitor; @@ -382,12 +383,6 @@ public class BytecodeGen implements ASTVisitor { } - @Override - public void visit(UnaryPlus unaryPlus) { - // TODO Auto-generated method stub - - } - @Override public void visit(WhileStmt whileStmt) { // TODO Auto-generated method stub @@ -453,4 +448,9 @@ public class BytecodeGen implements ASTVisitor { } + @Override + public void visit(UnaryExpr unaryExpr) { + throw new NotImplementedException(); + } + } diff --git a/src/de/dhbwstuttgart/bytecode/BytecodeGenMethod.java b/src/de/dhbwstuttgart/bytecode/BytecodeGenMethod.java index 5368cf936..0d0f8ceaa 100644 --- a/src/de/dhbwstuttgart/bytecode/BytecodeGenMethod.java +++ b/src/de/dhbwstuttgart/bytecode/BytecodeGenMethod.java @@ -8,6 +8,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; +import de.dhbwstuttgart.exceptions.NotImplementedException; import de.dhbwstuttgart.syntaxtree.statement.*; import org.objectweb.asm.ClassWriter; import org.objectweb.asm.Handle; @@ -336,6 +337,11 @@ public class BytecodeGenMethod implements StatementVisitor{ receiver.expr.accept(this); } + @Override + public void visit(UnaryExpr unaryExpr) { + throw new NotImplementedException(); + } + @Override public void visit(Return aReturn) { aReturn.retexpr.accept(this); @@ -367,11 +373,6 @@ public class BytecodeGenMethod implements StatementVisitor{ mv.visitVarInsn(Opcodes.ALOAD, 0); } - @Override - public void visit(UnaryPlus unaryPlus) { - System.out.println("++ In UnaryPlus: "); - } - @Override public void visit(WhileStmt whileStmt) { // TODO Auto-generated method stub diff --git a/src/de/dhbwstuttgart/bytecode/KindOfLambda.java b/src/de/dhbwstuttgart/bytecode/KindOfLambda.java index 36a28ce6f..5264888ca 100644 --- a/src/de/dhbwstuttgart/bytecode/KindOfLambda.java +++ b/src/de/dhbwstuttgart/bytecode/KindOfLambda.java @@ -1,5 +1,6 @@ package de.dhbwstuttgart.bytecode; +import de.dhbwstuttgart.exceptions.NotImplementedException; import de.dhbwstuttgart.syntaxtree.statement.*; import java.util.ArrayList; @@ -126,6 +127,11 @@ public class KindOfLambda implements StatementVisitor{ receiver.expr.accept(this); } + @Override + public void visit(UnaryExpr unaryExpr) { + throw new NotImplementedException(); + } + @Override public void visit(Return aReturn) { aReturn.retexpr.accept(this); @@ -155,12 +161,6 @@ public class KindOfLambda implements StatementVisitor{ this.argumentList.add(aThis.getType()); } - @Override - public void visit(UnaryPlus unaryPlus) { - // TODO Auto-generated method stub - - } - @Override public void visit(WhileStmt whileStmt) { // TODO Auto-generated method stub diff --git a/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/StatementGenerator.java b/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/StatementGenerator.java index f4ada6b2e..a1d17e8ad 100644 --- a/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/StatementGenerator.java +++ b/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/StatementGenerator.java @@ -16,6 +16,7 @@ import de.dhbwstuttgart.syntaxtree.type.Void; import org.antlr.v4.runtime.Token; import org.antlr.v4.runtime.tree.TerminalNode; +import java.lang.reflect.Type; import java.util.*; public class StatementGenerator { @@ -289,8 +290,8 @@ public class StatementGenerator { } private Statement convert(Java8Parser.PostIncrementExpressionContext stmt) { - //TODO - throw new NotImplementedException(); + return new UnaryExpr(UnaryExpr.Operation.POSTINCREMENT, convert(stmt.postfixExpression()), + TypePlaceholder.fresh(stmt.getStart()), stmt.getStart()); } private Statement convert(Java8Parser.PostDecrementExpressionContext stmt) { @@ -316,8 +317,10 @@ public class StatementGenerator { } private Statement convert(Java8Parser.IfThenElseStatementContext stmt){ - //TODO - throw new NotImplementedException(); + Expression expr = convert(stmt.expression()); + Statement thenBlock = convert(stmt.statementNoShortIf()); + Statement elseBlock = convert(stmt.statement()); + return new IfStmt(TypePlaceholder.fresh(stmt.getStart()), expr, thenBlock, elseBlock, stmt.getStart()); } private Statement convert(Java8Parser.IfThenElseStatementNoShortIfContext stmt){ @@ -591,7 +594,7 @@ public class StatementGenerator { if(expression.relationalExpression() == null){ return convert(expression.shiftExpression()); }else{ - throw new NotImplementedException(); + return convert(expression.relationalExpression()); } } @@ -604,7 +607,9 @@ public class StatementGenerator { } private Expression convert(Java8Parser.AdditiveExpressionContext expression) { - if(expression.additiveExpression() == null){ + if(expression.additiveExpression() != null){ + return convert(expression.additiveExpression()); + }else if(expression.multiplicativeExpression() != null){ return convert(expression.multiplicativeExpression()); }else{ throw new NotImplementedException(); @@ -627,9 +632,11 @@ public class StatementGenerator { }else if(expression.unaryExpressionNotPlusMinus() != null){ return convert(expression.unaryExpressionNotPlusMinus()); }else if(expression.getText().startsWith("+")){ - return new UnaryPlus(convert(expression.unaryExpression())); + return new UnaryExpr(UnaryExpr.Operation.PLUS, convert(expression.unaryExpression()), + TypePlaceholder.fresh(expression.getStart()), expression.getStart()); }else if(expression.getText().startsWith("-")){ - return new UnaryMinus(convert(expression.unaryExpression())); + return new UnaryExpr(UnaryExpr.Operation.MINUS, convert(expression.unaryExpression()), + TypePlaceholder.fresh(expression.getStart()), expression.getStart()); }else{ //Diese Exceptions sollte nie geworfen werden. //Der Code wurde nur noch nicht getestet. Sollte zur Sicherheit drin bleiben. @@ -672,10 +679,10 @@ public class StatementGenerator { } for(Java8Parser.PostIncrementExpression_lf_postfixExpressionContext inc : expression.postIncrementExpression_lf_postfixExpression()){ - expr = new PostIncExpr(expr); + expr = new UnaryExpr(UnaryExpr.Operation.POSTINCREMENT, expr, TypePlaceholder.fresh(inc.getStart()), inc.getStart()); } for(Java8Parser.PostDecrementExpression_lf_postfixExpressionContext dec : expression.postDecrementExpression_lf_postfixExpression()){ - expr = new PostDecExpr(expr); + expr = new UnaryExpr(UnaryExpr.Operation.POSTDECREMENT, expr, TypePlaceholder.fresh(dec.getStart()), dec.getStart()); } return expr; diff --git a/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/SyntacticSugar.java b/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/SyntacticSugar.java index d758f52bb..d79260048 100644 --- a/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/SyntacticSugar.java +++ b/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/SyntacticSugar.java @@ -1,6 +1,9 @@ package de.dhbwstuttgart.parser.SyntaxTreeGenerator; +import de.dhbwstuttgart.exceptions.NotImplementedException; import de.dhbwstuttgart.parser.NullToken; +import de.dhbwstuttgart.syntaxtree.AbstractASTWalker; +import de.dhbwstuttgart.syntaxtree.Constructor; import de.dhbwstuttgart.syntaxtree.statement.*; import java.util.List; @@ -10,22 +13,27 @@ public class SyntacticSugar { public static List addTrailingReturn(List statements){ if(statements.size()!=0) { Statement lastStmt = statements.get(statements.size() - 1); - if (lastStmt instanceof Return) return statements; - if (lastStmt instanceof WhileStmt) { - //TODO - //if (hasReturn(((WhileStmt) lastStmt).loopBlock)) return statements; - } else if (lastStmt instanceof IfStmt) { - if (hasReturn(((IfStmt) lastStmt).then_block) - && hasReturn(((IfStmt) lastStmt).else_block)) return statements; - } else if (lastStmt instanceof ForStmt) { - if (hasReturn(((ForStmt) lastStmt).body_Loop_block)) return statements; - } else { - } + ReturnFinder hasReturn = new ReturnFinder(); + lastStmt.accept(hasReturn); + if(hasReturn.hasReturn)return statements; } statements.add(new ReturnVoid(new NullToken())); return statements; } + private static class ReturnFinder extends AbstractASTWalker{ + public boolean hasReturn = false; + @Override + public void visit(Return aReturn) { + hasReturn = true; + } + + @Override + public void visit(ReturnVoid aReturn) { + hasReturn = true; + } + } + private static boolean hasReturn(Block block){ for(Statement s : block.getStatements()) if(s instanceof Return)return true; diff --git a/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/TypeGenerator.java b/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/TypeGenerator.java index d54b682a1..1dd259d0d 100644 --- a/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/TypeGenerator.java +++ b/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/TypeGenerator.java @@ -40,7 +40,12 @@ public class TypeGenerator { public static RefTypeOrTPHOrWildcardOrGeneric convert(Java8Parser.UnannTypeContext unannTypeContext, JavaClassRegistry reg, GenericsRegistry genericsRegistry) { if(unannTypeContext.unannPrimitiveType()!=null){ - throw new NotImplementedException(); + if(unannTypeContext.unannPrimitiveType().getText().equals("boolean")){ + return new RefType(ASTFactory.createClass(Boolean.class).getClassName(), unannTypeContext.getStart()); + }else{ + Java8Parser.NumericTypeContext numericType = unannTypeContext.unannPrimitiveType().numericType(); + throw new NotImplementedException(); + } }else if(unannTypeContext.unannReferenceType().unannArrayType()!=null){ //System.out.println(unannTypeContext.getText()); diff --git a/src/de/dhbwstuttgart/syntaxtree/AbstractASTWalker.java b/src/de/dhbwstuttgart/syntaxtree/AbstractASTWalker.java index 8a66629bf..054c3915e 100644 --- a/src/de/dhbwstuttgart/syntaxtree/AbstractASTWalker.java +++ b/src/de/dhbwstuttgart/syntaxtree/AbstractASTWalker.java @@ -7,6 +7,7 @@ import de.dhbwstuttgart.syntaxtree.statement.literal.Literal; import de.dhbwstuttgart.syntaxtree.statement.literal.Null; import de.dhbwstuttgart.syntaxtree.type.*; +import javax.management.Notification; import java.lang.reflect.Modifier; import java.util.Iterator; @@ -202,6 +203,11 @@ public abstract class AbstractASTWalker implements ASTVisitor{ receiver.expr.accept(this); } + @Override + public void visit(UnaryExpr unaryExpr) { + unaryExpr.expr.accept(this); + } + @Override public void visit(Return aReturn) { aReturn.retexpr.accept(this); @@ -227,11 +233,6 @@ public abstract class AbstractASTWalker implements ASTVisitor{ } - @Override - public void visit(UnaryPlus unaryPlus) { - - } - @Override public void visit(WhileStmt whileStmt) { diff --git a/src/de/dhbwstuttgart/syntaxtree/StatementVisitor.java b/src/de/dhbwstuttgart/syntaxtree/StatementVisitor.java index 195db2301..1c4e149c1 100644 --- a/src/de/dhbwstuttgart/syntaxtree/StatementVisitor.java +++ b/src/de/dhbwstuttgart/syntaxtree/StatementVisitor.java @@ -50,8 +50,6 @@ public interface StatementVisitor { void visit(This aThis); - void visit(UnaryPlus unaryPlus); - void visit(WhileStmt whileStmt); void visit(DoStmt whileStmt); @@ -67,4 +65,6 @@ public interface StatementVisitor { void visit(SuperCall superCall); void visit(ExpressionReceiver expressionReceiver); + + void visit(UnaryExpr unaryExpr); } diff --git a/src/de/dhbwstuttgart/syntaxtree/factory/ASTFactory.java b/src/de/dhbwstuttgart/syntaxtree/factory/ASTFactory.java index 6acb4214d..b06835695 100644 --- a/src/de/dhbwstuttgart/syntaxtree/factory/ASTFactory.java +++ b/src/de/dhbwstuttgart/syntaxtree/factory/ASTFactory.java @@ -133,7 +133,7 @@ public class ASTFactory { } */ - public static RefTypeOrTPHOrWildcardOrGeneric createType(java.lang.reflect.Type type, JavaClassName parentClass, String parentMethod){ + private static RefTypeOrTPHOrWildcardOrGeneric createType(java.lang.reflect.Type type, JavaClassName parentClass, String parentMethod){ if(type.getTypeName().equals("void")){ return new Void(new NullToken()); }else if(type.getTypeName().equals("int")){ diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/IfStmt.java b/src/de/dhbwstuttgart/syntaxtree/statement/IfStmt.java index 5d6a46589..4af1e7700 100644 --- a/src/de/dhbwstuttgart/syntaxtree/statement/IfStmt.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/IfStmt.java @@ -11,11 +11,11 @@ import org.antlr.v4.runtime.Token; public class IfStmt extends Statement { public final Expression expr; - public final Block then_block; - public final Block else_block; + public final Statement then_block; + public final Statement else_block; public IfStmt(RefTypeOrTPHOrWildcardOrGeneric type, - Expression expr, Block thenBlock, Block elseBlock, Token offset) + Expression expr, Statement thenBlock, Statement elseBlock, Token offset) { super(type,offset); this.expr = expr; diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/JavaInternalExpression.java b/src/de/dhbwstuttgart/syntaxtree/statement/JavaInternalExpression.java new file mode 100644 index 000000000..366c06020 --- /dev/null +++ b/src/de/dhbwstuttgart/syntaxtree/statement/JavaInternalExpression.java @@ -0,0 +1,12 @@ +package de.dhbwstuttgart.syntaxtree.statement; + +import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric; +import org.antlr.v4.runtime.Token; + +import java.nio.charset.StandardCharsets; + +public abstract class JavaInternalExpression extends Statement{ + public JavaInternalExpression(RefTypeOrTPHOrWildcardOrGeneric retType, Token offset){ + super(retType, offset); + } +} diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/NegativeExpr.java b/src/de/dhbwstuttgart/syntaxtree/statement/NegativeExpr.java deleted file mode 100644 index 67e71e95e..000000000 --- a/src/de/dhbwstuttgart/syntaxtree/statement/NegativeExpr.java +++ /dev/null @@ -1,18 +0,0 @@ -package de.dhbwstuttgart.syntaxtree.statement; -import java.util.Hashtable; -import java.util.Iterator; - -import org.antlr.v4.runtime.Token; - - - -public class NegativeExpr extends UnaryExpr -{ - public NegativeExpr(Token offset) - { - super(offset); - } - private UnaryMinus neg; - public Expression expr; - -} diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/NotExpr.java b/src/de/dhbwstuttgart/syntaxtree/statement/NotExpr.java deleted file mode 100644 index 0fcfd3338..000000000 --- a/src/de/dhbwstuttgart/syntaxtree/statement/NotExpr.java +++ /dev/null @@ -1,14 +0,0 @@ -package de.dhbwstuttgart.syntaxtree.statement; - - -import org.antlr.v4.runtime.Token; - -public class NotExpr extends UnaryExpr -{ - public NotExpr(Token offset) - { - super(offset); - } - private UnaryNot not; - public Expression expr; -} diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/PositivExpr.java b/src/de/dhbwstuttgart/syntaxtree/statement/PositivExpr.java deleted file mode 100644 index bec6ffbe3..000000000 --- a/src/de/dhbwstuttgart/syntaxtree/statement/PositivExpr.java +++ /dev/null @@ -1,15 +0,0 @@ -package de.dhbwstuttgart.syntaxtree.statement; - - -import org.antlr.v4.runtime.Token; - -public class PositivExpr extends UnaryExpr -{ - public PositivExpr(Token offset) - { - super(offset); - } - protected UnaryPlus plus; - public Expression expr; - -} diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/PostDecExpr.java b/src/de/dhbwstuttgart/syntaxtree/statement/PostDecExpr.java deleted file mode 100644 index 18b56f96f..000000000 --- a/src/de/dhbwstuttgart/syntaxtree/statement/PostDecExpr.java +++ /dev/null @@ -1,17 +0,0 @@ -package de.dhbwstuttgart.syntaxtree.statement; -import java.util.Hashtable; -import java.util.Iterator; - -import de.dhbwstuttgart.parser.antlr.Java8Parser; - - - - -public class PostDecExpr extends PostIncExpr -{ - - public PostDecExpr(Expression expr) { - super(expr); - } - -} diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/PostIncExpr.java b/src/de/dhbwstuttgart/syntaxtree/statement/PostIncExpr.java deleted file mode 100644 index 1292192b3..000000000 --- a/src/de/dhbwstuttgart/syntaxtree/statement/PostIncExpr.java +++ /dev/null @@ -1,15 +0,0 @@ -package de.dhbwstuttgart.syntaxtree.statement; - -import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceBlockInformation; -import de.dhbwstuttgart.typeinference.constraints.ConstraintSet; -import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceInformation; -import de.dhbwstuttgart.exceptions.NotImplementedException; - - -public class PostIncExpr extends UnaryExpr -{ - public PostIncExpr(Expression expr) { - super(null); - } - -} diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/PreDecExpr.java b/src/de/dhbwstuttgart/syntaxtree/statement/PreDecExpr.java deleted file mode 100644 index de0fb0b19..000000000 --- a/src/de/dhbwstuttgart/syntaxtree/statement/PreDecExpr.java +++ /dev/null @@ -1,17 +0,0 @@ -package de.dhbwstuttgart.syntaxtree.statement; -import java.util.Hashtable; -import java.util.Iterator; - -import org.antlr.v4.runtime.Token; - - - - - -public class PreDecExpr extends UnaryExpr -{ - public PreDecExpr(Token offset) - { - super(offset); - } -} diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/PreIncExpr.java b/src/de/dhbwstuttgart/syntaxtree/statement/PreIncExpr.java deleted file mode 100644 index 736dc3116..000000000 --- a/src/de/dhbwstuttgart/syntaxtree/statement/PreIncExpr.java +++ /dev/null @@ -1,12 +0,0 @@ -package de.dhbwstuttgart.syntaxtree.statement; - - -import org.antlr.v4.runtime.Token; - -public class PreIncExpr extends UnaryExpr -{ - public PreIncExpr(Token offset) - { - super(offset); - } -} diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/UnaryExpr.java b/src/de/dhbwstuttgart/syntaxtree/statement/UnaryExpr.java index 2157560c4..ca06146a8 100644 --- a/src/de/dhbwstuttgart/syntaxtree/statement/UnaryExpr.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/UnaryExpr.java @@ -1,14 +1,37 @@ package de.dhbwstuttgart.syntaxtree.statement; +import de.dhbwstuttgart.syntaxtree.StatementVisitor; +import de.dhbwstuttgart.syntaxtree.statement.Expression; +import de.dhbwstuttgart.syntaxtree.statement.JavaInternalExpression; +import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric; import org.antlr.v4.runtime.Token; -public abstract class UnaryExpr extends MethodCall +public class UnaryExpr extends JavaInternalExpression { + public enum Operation{ + NOT, + MINUS, + PREINCREMENT, + PREDECREMENT, + POSTINCREMENT, + PLUS, POSTDECREMENT + } + + + public final Operation operation; public Expression expr; - public UnaryExpr(Token offset) + public UnaryExpr(Operation operation, Expression argument, RefTypeOrTPHOrWildcardOrGeneric retType, Token offset) { - super(null,null,null,null,null); + super(retType, offset); + this.expr = argument; + this.operation = operation; } + @Override + public void accept(StatementVisitor visitor) { + visitor.visit(this); + } + + } diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/UnaryMinus.java b/src/de/dhbwstuttgart/syntaxtree/statement/UnaryMinus.java deleted file mode 100644 index 6c1002258..000000000 --- a/src/de/dhbwstuttgart/syntaxtree/statement/UnaryMinus.java +++ /dev/null @@ -1,12 +0,0 @@ -package de.dhbwstuttgart.syntaxtree.statement; - - -import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode; - -public class UnaryMinus extends UnaryPlus -{ - - public UnaryMinus(Expression expression) { - super(expression); - } -} diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/UnaryNot.java b/src/de/dhbwstuttgart/syntaxtree/statement/UnaryNot.java deleted file mode 100644 index 2dce91bd7..000000000 --- a/src/de/dhbwstuttgart/syntaxtree/statement/UnaryNot.java +++ /dev/null @@ -1,7 +0,0 @@ -package de.dhbwstuttgart.syntaxtree.statement; - - -public class UnaryNot -{ - -} diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/UnaryPlus.java b/src/de/dhbwstuttgart/syntaxtree/statement/UnaryPlus.java deleted file mode 100644 index b374166f0..000000000 --- a/src/de/dhbwstuttgart/syntaxtree/statement/UnaryPlus.java +++ /dev/null @@ -1,20 +0,0 @@ -package de.dhbwstuttgart.syntaxtree.statement; - -import de.dhbwstuttgart.syntaxtree.StatementVisitor; -import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceBlockInformation; -import de.dhbwstuttgart.typeinference.constraints.ConstraintSet; -import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceInformation; -import de.dhbwstuttgart.exceptions.NotImplementedException; - -public class UnaryPlus extends Expression -{ - public UnaryPlus(Expression expression){ - super(expression.getType(),expression.getOffset()); - - } - - @Override - public void accept(StatementVisitor visitor) { - visitor.visit(this); - } -} diff --git a/src/de/dhbwstuttgart/syntaxtree/visual/OutputGenerator.java b/src/de/dhbwstuttgart/syntaxtree/visual/OutputGenerator.java index d56c39d8c..191d58a02 100644 --- a/src/de/dhbwstuttgart/syntaxtree/visual/OutputGenerator.java +++ b/src/de/dhbwstuttgart/syntaxtree/visual/OutputGenerator.java @@ -296,11 +296,6 @@ public class OutputGenerator implements ASTVisitor{ out.append("this"); } - @Override - public void visit(UnaryPlus unaryPlus) { - - } - @Override public void visit(WhileStmt whileStmt) { out.append("while("); @@ -349,4 +344,9 @@ public class OutputGenerator implements ASTVisitor{ public void visit(ExpressionReceiver receiver) { receiver.expr.accept(this); } + + @Override + public void visit(UnaryExpr unaryExpr) { + throw new NotImplementedException(); + } } \ No newline at end of file diff --git a/src/de/dhbwstuttgart/syntaxtree/visual/TypeOutputGenerator.java b/src/de/dhbwstuttgart/syntaxtree/visual/TypeOutputGenerator.java index dcefafa44..6f90051a3 100644 --- a/src/de/dhbwstuttgart/syntaxtree/visual/TypeOutputGenerator.java +++ b/src/de/dhbwstuttgart/syntaxtree/visual/TypeOutputGenerator.java @@ -214,11 +214,6 @@ public class TypeOutputGenerator extends OutputGenerator { aThis.getType().accept(this); } - @Override - public void visit(UnaryPlus unaryPlus) { - super.visit(unaryPlus); - } - @Override public void visit(WhileStmt whileStmt) { super.visit(whileStmt); diff --git a/src/de/dhbwstuttgart/typedeployment/TypeInsertPlacer.java b/src/de/dhbwstuttgart/typedeployment/TypeInsertPlacer.java index 8dea5748d..ad591ebe5 100644 --- a/src/de/dhbwstuttgart/typedeployment/TypeInsertPlacer.java +++ b/src/de/dhbwstuttgart/typedeployment/TypeInsertPlacer.java @@ -1,6 +1,8 @@ package de.dhbwstuttgart.typedeployment; +import de.dhbwstuttgart.exceptions.NotImplementedException; import de.dhbwstuttgart.syntaxtree.*; +import de.dhbwstuttgart.syntaxtree.statement.JavaInternalExpression; import de.dhbwstuttgart.syntaxtree.statement.LambdaExpression; import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder; import de.dhbwstuttgart.typeinference.result.ResultSet; diff --git a/src/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java b/src/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java index 3448e8e3d..ed5837adb 100644 --- a/src/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java +++ b/src/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java @@ -2,12 +2,14 @@ package de.dhbwstuttgart.typeinference.typeAlgo; //import com.sun.org.apache.xpath.internal.Arg; +import com.sun.org.apache.xpath.internal.operations.Bool; import de.dhbwstuttgart.exceptions.NotImplementedException; import de.dhbwstuttgart.exceptions.TypeinferenceException; import de.dhbwstuttgart.parser.NullToken; import de.dhbwstuttgart.parser.SyntaxTreeGenerator.AssignToLocal; import de.dhbwstuttgart.parser.antlr.Java8Parser; import de.dhbwstuttgart.syntaxtree.*; +import de.dhbwstuttgart.syntaxtree.factory.ASTFactory; import de.dhbwstuttgart.syntaxtree.statement.*; import de.dhbwstuttgart.syntaxtree.statement.literal.Literal; import de.dhbwstuttgart.syntaxtree.statement.literal.Null; @@ -193,6 +195,23 @@ public class TYPEStmt implements StatementVisitor{ receiver.expr.accept(this); } + @Override + public void visit(UnaryExpr unaryExpr) { + if(unaryExpr.operation == UnaryExpr.Operation.POSTDECREMENT || + unaryExpr.operation == UnaryExpr.Operation.POSTINCREMENT || + unaryExpr.operation == UnaryExpr.Operation.PREDECREMENT || + unaryExpr.operation == UnaryExpr.Operation.PREINCREMENT){ + //@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 + RefType number = new RefType(ASTFactory.createClass(Number.class).getClassName(), unaryExpr.getOffset()); + constraintsSet.addUndConstraint(new Pair(unaryExpr.expr.getType(), number, PairOperator.EQUALSDOT)); + //The type of the postfix increment expression is the type of the variable + constraintsSet.addUndConstraint(new Pair(unaryExpr.expr.getType(), unaryExpr.getType(), PairOperator.EQUALSDOT)); + }else{ + throw new NotImplementedException(); + } + } + @Override public void visit(Return returnExpr) { returnExpr.retexpr.accept(this); @@ -241,14 +260,11 @@ public class TYPEStmt implements StatementVisitor{ }; } - @Override - public void visit(UnaryPlus unaryPlus) { - throw new NotImplementedException(); - } - @Override public void visit(WhileStmt whileStmt) { - throw new NotImplementedException(); + RefType booleanType = new RefType(ASTFactory.createClass(java.lang.Boolean.class).getClassName(), new NullToken()); + constraintsSet.addUndConstraint(new Pair(whileStmt.expr.getType(), booleanType, PairOperator.EQUALSDOT)); + whileStmt.loopBlock.accept(this); } @Override diff --git a/test/javFiles/Matrix.jav b/test/javFiles/Matrix.jav index e6aa84cd4..66abd5e03 100644 --- a/test/javFiles/Matrix.jav +++ b/test/javFiles/Matrix.jav @@ -1,54 +1,24 @@ import java.util.Vector; class Matrix extends Vector> { - - methode(Matrix m) { - Vector> i; - methode(i); - } - } - -/* -import java.util.Vector; - -class Matrix extends Vector> { - - Matrix mul_rec(Matrix m) { - auto v1 = new Vector(); - auto v2 = new Vector(); - auto i = 0; - while(i < m.size()) { - auto v; - v = m.elementAt(i); - v2.addElement(v.remove(v.size()-1)); - i++; - } - Matrix ret; - if (m.elementAt(0).size() > 0) { - ret = this.mul_rec(m); - } - else { - ret = new Matrix(); - i = 0; - while (i < this.size()) { - ret.addElement(new Vector()); - i++; - } - } - i = 0; - while (i < this.size()) { - int erg = 0; - auto j; - j = 0; - while (j < v2.size()) { - erg = erg + this.elementAt(i).elementAt(j).intValue() - * v2.elementAt(j).intValue(); - j++; - } - ret.elementAt(i).addElement(erg); - i++; - } - return ret; - } + mul(m) { + var ret = new Matrix(); + var i = 0; + while(i (); + var j = 0; + while(j < v1.size()) { + var erg = 0; + var k = 0; + while(k < v1.size()) { + erg = erg + v1.elementAt(k) + * m.elementAt(k).elementAt(j); + k++; } + v2.addElement(new Integer(erg)); + j++; } + ret.addElement(v2); + i++; } + return ret; + } } -*/ \ No newline at end of file From 3ce4937bc1961b097ffb1e9ef6102649168dbe7e Mon Sep 17 00:00:00 2001 From: JanUlrich Date: Tue, 30 Jan 2018 02:23:58 +0100 Subject: [PATCH 11/12] =?UTF-8?q?Fehler=20im=20Trailing=20Return=20anh?= =?UTF-8?q?=C3=A4ngen=20beheben?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SyntaxTreeGenerator/FCGenerator.java | 2 ++ .../StatementGenerator.java | 8 ++++---- .../SyntaxTreeGenerator.java | 2 +- .../syntaxtree/AbstractASTWalker.java | 9 +++++---- .../syntaxtree/visual/OutputGenerator.java | 20 ++++++++++++++++++- test/javFiles/Matrix.jav | 2 +- test/typeinference/JavaTXCompilerTest.java | 2 ++ 7 files changed, 34 insertions(+), 11 deletions(-) diff --git a/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/FCGenerator.java b/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/FCGenerator.java index cbca13ce6..7863c8ed6 100644 --- a/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/FCGenerator.java +++ b/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/FCGenerator.java @@ -141,6 +141,8 @@ public class FCGenerator { public UnifyType visit(GenericRefType genericRefType) { if(! gtvs.containsKey(genericRefType.getParsedName())) throw new DebugException("Dieser Fall darf nicht auftreten"); + //TODO: Diesen Dirty-Hack beseitigen. Fehler tritt bei java.lang.invoke.LambdaFormEditor$Transform$Kind auf. + //return UnifyTypeFactory.convert(ASTFactory.createObjectType()); return gtvs.get(genericRefType.getParsedName()); } diff --git a/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/StatementGenerator.java b/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/StatementGenerator.java index a1d17e8ad..069f49dc2 100644 --- a/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/StatementGenerator.java +++ b/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/StatementGenerator.java @@ -96,7 +96,7 @@ public class StatementGenerator { private Statement convert(Java8Parser.StatementWithoutTrailingSubstatementContext stmt) { if(stmt.block() != null){ - return convert(stmt.block()); + return convert(stmt.block(), false); }else if(stmt.emptyStatement() != null){ return new EmptyStmt(stmt.getStart()); }else if(stmt.expressionStatement() != null){ @@ -122,14 +122,14 @@ public class StatementGenerator { }else throw new NotImplementedException(); } - public Block convert(Java8Parser.BlockContext block) { + public Block convert(Java8Parser.BlockContext block, boolean addTrailingReturn) { List statements = new ArrayList<>(); if(block.blockStatements() != null) for(Java8Parser.BlockStatementContext statementContext : block.blockStatements().blockStatement()){ List stmt = convert(statementContext); statements.addAll(stmt); } - statements = SyntacticSugar.addTrailingReturn(statements); + if(addTrailingReturn)statements = SyntacticSugar.addTrailingReturn(statements); return new Block(statements, block.getStart()); } @@ -857,7 +857,7 @@ public class StatementGenerator { expression.lambdaBody().expression().getStart())); block = new Block(statements, expression.lambdaBody().getStart()); }else{ - block = lambdaGenerator.convert(expression.lambdaBody().block()); + block = lambdaGenerator.convert(expression.lambdaBody().block(), true); } List funNParams = new ArrayList<>(); funNParams.add(TypePlaceholder.fresh(expression.getStart()));//ret-Type diff --git a/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/SyntaxTreeGenerator.java b/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/SyntaxTreeGenerator.java index 3d9d7aca4..b681d9c3a 100644 --- a/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/SyntaxTreeGenerator.java +++ b/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/SyntaxTreeGenerator.java @@ -136,7 +136,7 @@ public class SyntaxTreeGenerator{ //TODO: Error! Abstrakte Methode ohne abstrakt Keyword } }else{ - block = stmtGen.convert(body.block()); + block = stmtGen.convert(body.block(),true); } if(parentClass.equals(new JavaClassName(name))){ return new Constructor(modifiers, name, retType, parameterList, block, gtvDeclarations, header.getStart(), fieldInitializations); diff --git a/src/de/dhbwstuttgart/syntaxtree/AbstractASTWalker.java b/src/de/dhbwstuttgart/syntaxtree/AbstractASTWalker.java index 054c3915e..dfb8438c7 100644 --- a/src/de/dhbwstuttgart/syntaxtree/AbstractASTWalker.java +++ b/src/de/dhbwstuttgart/syntaxtree/AbstractASTWalker.java @@ -158,12 +158,13 @@ public abstract class AbstractASTWalker implements ASTVisitor{ @Override public void visit(ForStmt forStmt) { - + forStmt.body_Loop_block.accept(this); } @Override public void visit(IfStmt ifStmt) { - + ifStmt.then_block.accept(this); + ifStmt.else_block.accept(this); } @Override @@ -235,12 +236,12 @@ public abstract class AbstractASTWalker implements ASTVisitor{ @Override public void visit(WhileStmt whileStmt) { - + whileStmt.loopBlock.accept(this); } @Override public void visit(DoStmt whileStmt) { - + whileStmt.loopBlock.accept(this); } @Override diff --git a/src/de/dhbwstuttgart/syntaxtree/visual/OutputGenerator.java b/src/de/dhbwstuttgart/syntaxtree/visual/OutputGenerator.java index 191d58a02..879a4ba29 100644 --- a/src/de/dhbwstuttgart/syntaxtree/visual/OutputGenerator.java +++ b/src/de/dhbwstuttgart/syntaxtree/visual/OutputGenerator.java @@ -347,6 +347,24 @@ public class OutputGenerator implements ASTVisitor{ @Override public void visit(UnaryExpr unaryExpr) { - throw new NotImplementedException(); + if(unaryExpr.operation == UnaryExpr.Operation.MINUS){ + out.append("-"); + } + if(unaryExpr.operation == UnaryExpr.Operation.PLUS){ + out.append("+"); + } + if(unaryExpr.operation == UnaryExpr.Operation.PREDECREMENT){ + out.append("--"); + } + if(unaryExpr.operation == UnaryExpr.Operation.PREINCREMENT){ + out.append("++"); + } + unaryExpr.expr.accept(this); + if(unaryExpr.operation == UnaryExpr.Operation.POSTDECREMENT){ + out.append("--"); + } + if(unaryExpr.operation == UnaryExpr.Operation.POSTINCREMENT){ + out.append("++"); + } } } \ No newline at end of file diff --git a/test/javFiles/Matrix.jav b/test/javFiles/Matrix.jav index 66abd5e03..476027b32 100644 --- a/test/javFiles/Matrix.jav +++ b/test/javFiles/Matrix.jav @@ -4,7 +4,7 @@ class Matrix extends Vector> { mul(m) { var ret = new Matrix(); var i = 0; - while(i (); var j = 0; diff --git a/test/typeinference/JavaTXCompilerTest.java b/test/typeinference/JavaTXCompilerTest.java index f46229541..03452018e 100644 --- a/test/typeinference/JavaTXCompilerTest.java +++ b/test/typeinference/JavaTXCompilerTest.java @@ -2,6 +2,7 @@ package typeinference; 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.typedeployment.TypeInsert; import de.dhbwstuttgart.typedeployment.TypeInsertFactory; @@ -51,6 +52,7 @@ public class JavaTXCompilerTest { 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; Set insertedTypes = new HashSet<>(); From 8e4791cca6beff87e588959c73df93cf98cf41a6 Mon Sep 17 00:00:00 2001 From: JanUlrich Date: Wed, 31 Jan 2018 13:34:54 +0100 Subject: [PATCH 12/12] Anpassungen im Matrix Test --- test/javFiles/Matrix.jav | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/javFiles/Matrix.jav b/test/javFiles/Matrix.jav index 476027b32..e11835359 100644 --- a/test/javFiles/Matrix.jav +++ b/test/javFiles/Matrix.jav @@ -1,4 +1,6 @@ import java.util.Vector; +import java.lang.Integer; +import java.lang.Boolean; class Matrix extends Vector> { mul(m) {
  • de.dhbwstuttgart.syntaxtree.statement.UnaryExpr