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+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/doc/OldStuff/JavaDoc/package-list b/doc/OldStuff/JavaDoc/package-list
index d3f5a12f..8b137891 100755
--- a/doc/OldStuff/JavaDoc/package-list
+++ b/doc/OldStuff/JavaDoc/package-list
@@ -1 +1 @@
-
+
diff --git a/doc/OldStuff/JavaDoc/stylesheet.css b/doc/OldStuff/JavaDoc/stylesheet.css
index 7ac5ff16..b62ecb51 100755
--- a/doc/OldStuff/JavaDoc/stylesheet.css
+++ b/doc/OldStuff/JavaDoc/stylesheet.css
@@ -1,29 +1,29 @@
-/* Javadoc style sheet */
-
-/* Define colors, fonts and other style attributes here to override the defaults */
-
-/* Page background color */
-body { background-color: #FFFFFF }
-
-/* Table colors */
-.TableHeadingColor { background: #CCCCFF } /* Dark mauve */
-.TableSubHeadingColor { background: #EEEEFF } /* Light mauve */
-.TableRowColor { background: #FFFFFF } /* White */
-
-/* Font used in left-hand frame lists */
-.FrameTitleFont { font-size: 10pts; font-family: Helvetica, Arial, san-serif }
-.FrameHeadingFont { font-size: 10pts; font-family: Helvetica, Arial, san-serif }
-.FrameItemFont { font-size: 10pts; font-family: Helvetica, Arial, san-serif }
-
-/* Example of smaller, sans-serif font in frames */
-/* .FrameItemFont { font-size: 10pt; font-family: Helvetica, Arial, sans-serif } */
-
-/* Navigation bar fonts and colors */
-.NavBarCell1 { background-color:#EEEEFF;}/* Light mauve */
-.NavBarCell1Rev { background-color:#00008B;}/* Dark Blue */
-.NavBarFont1 { font-family: Arial, Helvetica, sans-serif; color:#000000;}
-.NavBarFont1Rev { font-family: Arial, Helvetica, sans-serif; color:#FFFFFF;}
-
-.NavBarCell2 { font-family: Arial, Helvetica, sans-serif; background-color:#FFFFFF;}
-.NavBarCell3 { font-family: Arial, Helvetica, sans-serif; background-color:#FFFFFF;}
-
+/* Javadoc style sheet */
+
+/* Define colors, fonts and other style attributes here to override the defaults */
+
+/* Page background color */
+body { background-color: #FFFFFF }
+
+/* Table colors */
+.TableHeadingColor { background: #CCCCFF } /* Dark mauve */
+.TableSubHeadingColor { background: #EEEEFF } /* Light mauve */
+.TableRowColor { background: #FFFFFF } /* White */
+
+/* Font used in left-hand frame lists */
+.FrameTitleFont { font-size: 10pts; font-family: Helvetica, Arial, san-serif }
+.FrameHeadingFont { font-size: 10pts; font-family: Helvetica, Arial, san-serif }
+.FrameItemFont { font-size: 10pts; font-family: Helvetica, Arial, san-serif }
+
+/* Example of smaller, sans-serif font in frames */
+/* .FrameItemFont { font-size: 10pt; font-family: Helvetica, Arial, sans-serif } */
+
+/* Navigation bar fonts and colors */
+.NavBarCell1 { background-color:#EEEEFF;}/* Light mauve */
+.NavBarCell1Rev { background-color:#00008B;}/* Dark Blue */
+.NavBarFont1 { font-family: Arial, Helvetica, sans-serif; color:#000000;}
+.NavBarFont1Rev { font-family: Arial, Helvetica, sans-serif; color:#FFFFFF;}
+
+.NavBarCell2 { font-family: Arial, Helvetica, sans-serif; background-color:#FFFFFF;}
+.NavBarCell3 { font-family: Arial, Helvetica, sans-serif; background-color:#FFFFFF;}
+
diff --git a/doc/OldStuff/Operator.ucd b/doc/OldStuff/Operator.ucd
index f6f2c698..9799f2e5 100755
--- a/doc/OldStuff/Operator.ucd
+++ b/doc/OldStuff/Operator.ucd
@@ -1,220 +1,220 @@
-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+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/doc/OldStuff/Rest/ClassDiagram.svg b/doc/OldStuff/Rest/ClassDiagram.svg
index 143b2ea2..4c300b8e 100755
--- a/doc/OldStuff/Rest/ClassDiagram.svg
+++ b/doc/OldStuff/Rest/ClassDiagram.svg
@@ -1,6746 +1,6746 @@
-
-
-
-
+
+
+
+
diff --git a/doc/OldStuff/Rest/Operator.svg b/doc/OldStuff/Rest/Operator.svg
index 5bb765ad..618a3990 100755
--- a/doc/OldStuff/Rest/Operator.svg
+++ b/doc/OldStuff/Rest/Operator.svg
@@ -1,458 +1,458 @@
-
-
-
-
+
+
+
+
diff --git a/doc/OldStuff/Rest/Rest.svg b/doc/OldStuff/Rest/Rest.svg
index b1ea2764..0b70339a 100755
--- a/doc/OldStuff/Rest/Rest.svg
+++ b/doc/OldStuff/Rest/Rest.svg
@@ -1,2013 +1,2013 @@
-
-
-
-
+
+
+
+
diff --git a/doc/OldStuff/Rest/Statement.svg b/doc/OldStuff/Rest/Statement.svg
index 1c7a9dd1..985c9e9f 100755
--- a/doc/OldStuff/Rest/Statement.svg
+++ b/doc/OldStuff/Rest/Statement.svg
@@ -1,1868 +1,1868 @@
-
-
-
-
+
+
+
+
diff --git a/doc/OldStuff/Statement.ucd b/doc/OldStuff/Statement.ucd
index 1136e26e..9e2b116f 100755
--- a/doc/OldStuff/Statement.ucd
+++ b/doc/OldStuff/Statement.ucd
@@ -1,623 +1,623 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
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+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/main/java/de/dhbwstuttgart/bytecode/simplifyRes/GenericGeneratorResultsForAllMethods.java b/src/main/java/de/dhbwstuttgart/bytecode/simplifyRes/GenericGeneratorResultsForAllMethods.java
index bd3d224d..9798ad7f 100644
--- a/src/main/java/de/dhbwstuttgart/bytecode/simplifyRes/GenericGeneratorResultsForAllMethods.java
+++ b/src/main/java/de/dhbwstuttgart/bytecode/simplifyRes/GenericGeneratorResultsForAllMethods.java
@@ -3,8 +3,11 @@
*/
package de.dhbwstuttgart.bytecode.simplifyRes;
+import java.util.Collections;
import java.util.List;
+import com.google.common.collect.Collections2;
+
/**
* @author fayez
*
@@ -12,7 +15,9 @@ import java.util.List;
public class GenericGeneratorResultsForAllMethods {
private final List methodsAndConstraints;
-
+ public GenericGeneratorResultsForAllMethods() {
+ this(Collections.emptyList());
+ }
/**
* @param methodsAndConstraints
*/
diff --git a/src/main/java/de/dhbwstuttgart/bytecode/simplifyRes/GenericGenratorResultForSourceFile.java b/src/main/java/de/dhbwstuttgart/bytecode/simplifyRes/GenericGenratorResultForSourceFile.java
index e1928893..f311899e 100644
--- a/src/main/java/de/dhbwstuttgart/bytecode/simplifyRes/GenericGenratorResultForSourceFile.java
+++ b/src/main/java/de/dhbwstuttgart/bytecode/simplifyRes/GenericGenratorResultForSourceFile.java
@@ -40,9 +40,11 @@ public class GenericGenratorResultForSourceFile {
public GenericsGeneratorResultForClass getSimplifyResultsByName(String pkgName, String name) {
if (this.pkgName.equals(pkgName)) {
- return genericGeneratorResultForAllClasses.stream().filter(sr -> sr.getClassName().equals(name)).findAny()
- .orElseThrow(() -> new NoSuchElementException(
- "Simplify results for the class " + pkgName + "." + name + " are not found"));
+ return genericGeneratorResultForAllClasses
+ .stream()
+ .filter(sr -> sr.getClassName().equals(name))
+ .findAny()
+ .orElse(new GenericsGeneratorResultForClass(name));
}
throw new NoSuchElementException("Simplify results for the class " + pkgName + "." + name + " are not found");
}
diff --git a/src/main/java/de/dhbwstuttgart/bytecode/simplifyRes/GenericsGeneratorResultForClass.java b/src/main/java/de/dhbwstuttgart/bytecode/simplifyRes/GenericsGeneratorResultForClass.java
index 5b53efcc..a02cd162 100644
--- a/src/main/java/de/dhbwstuttgart/bytecode/simplifyRes/GenericsGeneratorResultForClass.java
+++ b/src/main/java/de/dhbwstuttgart/bytecode/simplifyRes/GenericsGeneratorResultForClass.java
@@ -3,6 +3,7 @@
*/
package de.dhbwstuttgart.bytecode.simplifyRes;
+import java.util.Collections;
import java.util.List;
/**
@@ -14,6 +15,9 @@ public class GenericsGeneratorResultForClass {
private final List classConstraints;
private final GenericGeneratorResultsForAllMethods methodsAndTheirConstraints;
+ public GenericsGeneratorResultForClass(String className) {
+ this(className, Collections.emptyList(), new GenericGeneratorResultsForAllMethods());
+ }
/**
* @param className
* @param classConstraints
@@ -52,6 +56,9 @@ public class GenericsGeneratorResultForClass {
.anyMatch(i -> i.equals(id));
}
+
+
+
public List getMethodConstraintsByID(String id) {
return methodsAndTheirConstraints.getMethodsAndConstraints().stream().filter(mc -> mc.getMethodID().equals(id))
.findFirst().get().getConstraints();
diff --git a/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java b/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java
index 5650b8ef..c4d0407a 100644
--- a/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java
+++ b/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java
@@ -59,43 +59,64 @@ import org.apache.commons.io.output.NullOutputStream;
public class JavaTXCompiler {
- final CompilationEnvironment environment;
- Boolean resultmodel = true;
- public final Map sourceFiles = new HashMap<>();
- Boolean log = true; // gibt an ob ein Log-File nach
- // System.getProperty("user.dir")+"src/test/java/logFiles" geschrieben werden
- // soll?
- public volatile UnifyTaskModel usedTasks = new UnifyTaskModel();
+ public static JavaTXCompiler INSTANCE;
+ final CompilationEnvironment environment;
+ Boolean resultmodel = true;
+ public final Map sourceFiles = new HashMap<>();
+ Boolean log = true; //gibt an ob ein Log-File nach System.getProperty("user.dir")+"src/test/java/logFiles" geschrieben werden soll?
+ public volatile UnifyTaskModel usedTasks = new UnifyTaskModel();
+
+ /**
+ * Äußerste Liste der Source-Files.
+ * Danach Liste der Klassen in Source File.
+ * Danach Map Klassenname
+ */
+ private List>> simplifyResultsSF = new ArrayList<>();
+
+ public JavaTXCompiler(File sourceFile) throws IOException, ClassNotFoundException {
+ this(Arrays.asList(sourceFile));
+ INSTANCE = this;
+ }
- public JavaTXCompiler(File sourceFile) throws IOException, ClassNotFoundException {
- this(Arrays.asList(sourceFile));
- }
+ public JavaTXCompiler(File sourceFile, Boolean log) throws IOException, ClassNotFoundException {
+ this(sourceFile);
+ this.log = log;
+ INSTANCE = this;
+ }
+
+ public JavaTXCompiler(List sources) throws IOException, ClassNotFoundException {
+ environment = new CompilationEnvironment(sources);
+ for (File s : sources) {
+ sourceFiles.put(s, parse(s));
+ }
+ INSTANCE = this;
+ }
- public JavaTXCompiler(File sourceFile, Boolean log) throws IOException, ClassNotFoundException {
- this(sourceFile);
- this.log = log;
- }
+ public ConstraintSet getConstraints() throws ClassNotFoundException {
+ List allClasses = new ArrayList<>();//environment.getAllAvailableClasses();
+ for (SourceFile sf : sourceFiles.values()) {
+ allClasses.addAll(sf.getClasses());
+ }
+ List importedClasses = new ArrayList<>();
+ //Alle Importierten Klassen in allen geparsten Sourcefiles kommen ins FC
+ for (File forSourceFile : sourceFiles.keySet())
+ for (JavaClassName name : sourceFiles.get(forSourceFile).getImports()) {
+ //TODO: Hier werden imports von eigenen (.jav) Klassen nicht beachtet
+ ClassOrInterface importedClass = ASTFactory.createClass(
+ ClassLoader.getSystemClassLoader().loadClass(name.toString()));
+ importedClasses.add(importedClass);
+ }
+ allClasses.addAll(importedClasses);
- public JavaTXCompiler(List sources) throws IOException, ClassNotFoundException {
- environment = new CompilationEnvironment(sources);
- for (File s : sources) {
- sourceFiles.put(s, parse(s));
- }
- }
+ return new TYPE(sourceFiles.values(), allClasses).getConstraints();
+ }
- public ConstraintSet getConstraints() throws ClassNotFoundException {
- List allClasses = new ArrayList<>();// environment.getAllAvailableClasses();
- for (SourceFile sf : sourceFiles.values()) {
- allClasses.addAll(sf.getClasses());
- }
- List importedClasses = new ArrayList<>();
- // Alle Importierten Klassen in allen geparsten Sourcefiles kommen ins FC
- for (File forSourceFile : sourceFiles.keySet())
- for (JavaClassName name : sourceFiles.get(forSourceFile).getImports()) {
- // TODO: Hier werden imports von eigenen (.jav) Klassen nicht beachtet
- ClassOrInterface importedClass = ASTFactory
- .createClass(ClassLoader.getSystemClassLoader().loadClass(name.toString()));
- importedClasses.add(importedClass);
+ public List getAvailableClasses(SourceFile forSourceFile) throws ClassNotFoundException {
+ //PL 2018-09-18: List durch Set ersetzt, damit die Klassen nur einmal hinzugefuegt werden
+ //List allClasses = new ArrayList<>();//environment.getAllAvailableClasses();
+ Set allClasses = new HashSet<>();
+
+ /* PL 2018-09-19 geloescht werden bereits in typeInference hinzugefuegt
}
allClasses.addAll(importedClasses);
@@ -711,6 +732,20 @@ public class JavaTXCompiler {
return ret;
}
+ public void generateBytecodForFile(String path, HashMap classFiles, SourceFile sf,
+ List typeinferenceResult) throws IOException {
+ try {
+ List genericResults = getGeneratedGenericResultsForAllSourceFiles(typeinferenceResult);
+ BytecodeGen bytecodeGen = new BytecodeGen(classFiles,typeinferenceResult, genericResults, sf,path);
+ bytecodeGen.visit(sf);
+ this.writeClassFile(bytecodeGen.getClassFiles(), path);
+ } catch (ClassNotFoundException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+
public List getGeneratedGenericResultsForAllSourceFiles()
throws ClassNotFoundException {
List result = new ArrayList<>();
diff --git a/src/main/java/de/dhbwstuttgart/syntaxtree/GenericDeclarationList.java b/src/main/java/de/dhbwstuttgart/syntaxtree/GenericDeclarationList.java
index 6a264684..426b57f3 100644
--- a/src/main/java/de/dhbwstuttgart/syntaxtree/GenericDeclarationList.java
+++ b/src/main/java/de/dhbwstuttgart/syntaxtree/GenericDeclarationList.java
@@ -2,6 +2,10 @@ package de.dhbwstuttgart.syntaxtree;
import org.antlr.v4.runtime.Token;
+import com.google.common.collect.Lists;
+
+import de.dhbwstuttgart.parser.NullToken;
+
import java.util.*;
@@ -15,11 +19,21 @@ public class GenericDeclarationList extends SyntaxTreeNode implements Iterable gtvs = new ArrayList<>();
-
- public GenericDeclarationList(List values, Token endOffset) {
+
+ @SuppressWarnings("unchecked")
+ public GenericDeclarationList(Iterable extends GenericTypeVar> values, Token endOffset) {
+ super(endOffset);
+ gtvs = isListOfGenericTypeVar(values) ? (List)values : Lists.newArrayList(values);
+ this.offsetOfLastElement = endOffset;
+ }
+
+ public GenericDeclarationList(ArrayList values, Token endOffset) {
super(endOffset);
gtvs = values;
- this.offsetOfLastElement = endOffset;
+ this.offsetOfLastElement = endOffset; }
+
+ private boolean isListOfGenericTypeVar(Iterable extends GenericTypeVar> values) {
+ return values instanceof List && ((List>)values).size() > 0 && ((List>)values).get(0) instanceof GenericTypeVar;
}
@Override
diff --git a/src/main/java/de/dhbwstuttgart/syntaxtree/statement/NewArray.java b/src/main/java/de/dhbwstuttgart/syntaxtree/statement/NewArray.java
index 0f699161..14c54d8c 100644
--- a/src/main/java/de/dhbwstuttgart/syntaxtree/statement/NewArray.java
+++ b/src/main/java/de/dhbwstuttgart/syntaxtree/statement/NewArray.java
@@ -1,24 +1,24 @@
-package de.dhbwstuttgart.syntaxtree.statement;
-import java.util.List;
-
-import de.dhbwstuttgart.syntaxtree.StatementVisitor;
-import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
-import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceBlockInformation;
-import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
-import de.dhbwstuttgart.exceptions.NotImplementedException;
-
-
-public class NewArray extends Expression
-{
- public NewArray(int offset,int variableLength)
- {
- super(null,null);
- }
- private RefTypeOrTPHOrWildcardOrGeneric type;
- public List expr;
-
- @Override
- public void accept(StatementVisitor visitor) {
- visitor.visit(this);
- }
-}
+package de.dhbwstuttgart.syntaxtree.statement;
+import java.util.List;
+
+import de.dhbwstuttgart.syntaxtree.StatementVisitor;
+import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
+import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceBlockInformation;
+import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
+import de.dhbwstuttgart.exceptions.NotImplementedException;
+
+
+public class NewArray extends Expression
+{
+ public NewArray(int offset,int variableLength)
+ {
+ super(null,null);
+ }
+ private RefTypeOrTPHOrWildcardOrGeneric type;
+ public List expr;
+
+ @Override
+ public void accept(StatementVisitor visitor) {
+ visitor.visit(this);
+ }
+}
diff --git a/src/main/java/de/dhbwstuttgart/typedeployment/TypeInsertFactory.java b/src/main/java/de/dhbwstuttgart/typedeployment/TypeInsertFactory.java
index 3fee03f6..7f039bdc 100644
--- a/src/main/java/de/dhbwstuttgart/typedeployment/TypeInsertFactory.java
+++ b/src/main/java/de/dhbwstuttgart/typedeployment/TypeInsertFactory.java
@@ -1,11 +1,37 @@
package de.dhbwstuttgart.typedeployment;
+import de.dhbwstuttgart.bytecode.Exception.BytecodeGeneratorError;
+import de.dhbwstuttgart.bytecode.constraint.TPHConstraint;
+import de.dhbwstuttgart.bytecode.descriptor.TypeToDescriptor;
+import de.dhbwstuttgart.bytecode.simplifyRes.GenericGenratorResultForSourceFile;
+import de.dhbwstuttgart.bytecode.simplifyRes.GenericsGeneratorResult;
+import de.dhbwstuttgart.bytecode.simplifyRes.GenericsGeneratorResultForClass;
+import de.dhbwstuttgart.bytecode.utilities.MethodUtility;
+import de.dhbwstuttgart.bytecode.utilities.Resolver;
+import de.dhbwstuttgart.core.JavaTXCompiler;
+import de.dhbwstuttgart.parser.NullToken;
import de.dhbwstuttgart.syntaxtree.*;
+import de.dhbwstuttgart.syntaxtree.statement.NewArray;
import de.dhbwstuttgart.syntaxtree.type.*;
import de.dhbwstuttgart.typeinference.result.*;
-import org.antlr.v4.runtime.Token;
+import org.antlr.v4.parse.ANTLRParser.action_return;
+import org.antlr.v4.parse.ANTLRParser.block_return;
+import org.antlr.v4.parse.ANTLRParser.labeledAlt_return;
+import org.antlr.v4.parse.ANTLRParser.parserRule_return;
+import org.antlr.v4.runtime.Token;
+import org.objectweb.asm.Type;
+import org.stringtemplate.v4.compiler.STParser.ifstat_return;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.Serializable;
import java.util.*;
+import java.util.Map.Entry;
+import java.util.stream.Collectors;
+
+import javax.print.DocFlavor.STRING;
+import javax.security.auth.kerberos.KerberosKey;
/**
* TODO:
@@ -29,62 +55,90 @@ public class TypeInsertFactory {
public static TypeInsert createInsertPoints(RefTypeOrTPHOrWildcardOrGeneric type, Token offset, ClassOrInterface cl, Method m,
ResultSet resultSet) {
- ResolvedType resolvedType = resultSet.resolveType(type);
- TypeInsertPoint insertPoint = new TypeInsertPoint(offset,
- new TypeToInsertString(resolvedType.resolvedType).insert);
- return new TypeInsert(insertPoint, new HashSet<>(), resolvedType.getResultPair());
+
+ try {
+ ResolvedType resolvedType = resultSet.resolveType(type);
+ TypeInsertPoint insertPoint = new TypeInsertPoint(offset,
+ new TypeToInsertString(resolvedType.resolvedType).insert);
+ List simplifyResults = JavaTXCompiler.INSTANCE.getGeneratedGenericResultsForAllSourceFiles();
+ for (GenericGenratorResultForSourceFile simplifyResultsEntries : simplifyResults) {
+ GenericsGeneratorResultForClass genericResultsForClass = simplifyResultsEntries.getSimplifyResultsByName("", cl.getClassName().toString());
+ return new TypeInsert(insertPoint, createGenericInsert(genericResultsForClass, cl, m, resultSet), resolvedType.getResultPair());
+ }
+
+ return new TypeInsert(insertPoint, new HashSet<>(), resolvedType.getResultPair());
+ } catch (ClassNotFoundException e) {
+ e.printStackTrace();
+ return null;
+ }
}
- private static TypeInsertPoint createGenericInsert(Set toInsert, ClassOrInterface cl, Method m){
- //Momentan wird Methode ignoriert. Parameter werden immer als Klassenparameter angefügt:
- //Offset zum Einstzen bestimmen:
- Token offset;
- String insert = "";
- String end;
- if(cl.getGenerics().iterator().hasNext()){
- //offset = cl.getGenerics().iterator().next().getOffset();
- offset = cl.getGenerics().getOffset();
- end=",";
- }else{
- offset = cl.getGenerics().getOffset();
- insert += "<";
- end = ">";
+ private static synchronized Set createGenericInsert(GenericsGeneratorResultForClass genericResult, ClassOrInterface cl, Method m, ResultSet resultSet){
+ Set result = createGenericClassInserts(genericResult, cl);
+
+ for (Method method : cl.getMethods()) {
+ Resolver resolver = new Resolver(resultSet);
+ List methodConstraints = genericResult.getMethodConstraintsByID(MethodUtility.createID(resolver, method));
+ createMethodConstraints(method, methodConstraints);
}
-
- //Alle einzusetzenden Generics und deren Bounds bestimmen:
- HashMap> genericsAndBounds = new HashMap<>();
- for(GenericInsertPair p : toInsert){
- if(!genericsAndBounds.containsKey(p.TA1)){
- genericsAndBounds.put((TypePlaceholder) p.TA1, new HashSet<>());
- }
- if(p.TA2 != null){
- genericsAndBounds.get(p.TA1).add((TypePlaceholder) p.TA2);
- if(!genericsAndBounds.containsKey(p.TA2)){
- genericsAndBounds.put((TypePlaceholder) p.TA2, new HashSet<>());
- }
- }
- }
-
- //String zum Einsetzen (Generics mit bounds) generieren:
- Iterator it = genericsAndBounds.keySet().iterator();
- if(! it.hasNext())return new TypeInsertPoint(offset, "");
- while(it.hasNext()){
- TypePlaceholder tph = it.next();
- insert += tph.getName();
- Set bounds = genericsAndBounds.get(tph);
- if(bounds.size() > 0){
- insert += " extends ";
- Iterator boundIt = bounds.iterator();
- while(boundIt.hasNext()){
- TypePlaceholder bound = boundIt.next();
- insert += bound.getName();
- if(boundIt.hasNext())insert += " & ";
- }
- }
- if(it.hasNext())insert+=",";
- }
- return new TypeInsertPoint(offset, insert + end);
+
+ return result;
}
+
+ private static Set createMethodConstraints(Method method, List constraints) {
+ Set result = new HashSet<>();
+ Token offset = new GenericDeclarationList(method.getGenerics(), new NullToken()).getOffset();
+
+ if (constraints.size() == 0) {
+ result.add(new TypeInsertPoint(offset, ""));
+ return result;
+ }
+
+ String insert = " <";
+
+ for (GenericsGeneratorResult genericInsertConstraint : constraints) {
+ if (genericInsertConstraint.getConstraint().getRight().equals(Type.getInternalName(Object.class))) {
+ insert += genericInsertConstraint.getConstraint().getLeft();
+ } else {
+ insert += genericInsertConstraint.getConstraint().getLeft() + " extends " + genericInsertConstraint.getConstraint().getRight() + ", ";
+ }
+ }
+
+ insert = insert.substring(0, insert.length() -2);
+ insert += ">";
+
+ result.add(new TypeInsertPoint(offset, insert));
+ return result;
+ }
+
+ private static Set createGenericClassInserts(GenericsGeneratorResultForClass genericResult, ClassOrInterface cl) {
+ Set result = new HashSet<>();
+ Token offset = cl.getGenerics().getOffset();
+
+ List classConstraints = genericResult.getClassConstraints();
+
+ if (classConstraints.size() == 0) {
+ result.add(new TypeInsertPoint(offset, ""));
+ return result;
+ }
+
+ String insert = " <";
+
+ for (GenericsGeneratorResult genericInsertConstraint : classConstraints) {
+ if (genericInsertConstraint.getConstraint().getRight().equals(Type.getInternalName(Object.class))) {
+ insert += genericInsertConstraint.getConstraint().getLeft();
+ } else {
+ insert += genericInsertConstraint.getConstraint().getLeft() + " extends " + genericInsertConstraint.getConstraint().getRight() + ", ";
+ }
+ }
+
+ insert = insert.substring(0, insert.length() -2);
+ insert += ">";
+
+ result.add(new TypeInsertPoint(offset, insert));
+
+ return result;
+ }
}
class TypeToInsertString implements ResultSetVisitor{
diff --git a/src/main/java/de/dhbwstuttgart/typedeployment/TypeInsertPlacer.java b/src/main/java/de/dhbwstuttgart/typedeployment/TypeInsertPlacer.java
index 6ccf5620..9e5ba545 100644
--- a/src/main/java/de/dhbwstuttgart/typedeployment/TypeInsertPlacer.java
+++ b/src/main/java/de/dhbwstuttgart/typedeployment/TypeInsertPlacer.java
@@ -1,73 +1,73 @@
-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;
-
-import java.util.HashSet;
-import java.util.Set;
-
-public class TypeInsertPlacer extends AbstractASTWalker{
- Set inserts = new HashSet<>();
- private ResultSet withResults;
-
- public Set getTypeInserts(SourceFile forSourceFile, ResultSet withResults){
- this.withResults = withResults;
- forSourceFile.accept(this);
- return inserts;
- }
-
- @Override
- public void visit(ClassOrInterface classOrInterface) {
- TypeInsertPlacerClass cl = new TypeInsertPlacerClass(classOrInterface, withResults);
- this.inserts.addAll(cl.inserts);
- }
-}
-
-class TypeInsertPlacerClass extends AbstractASTWalker{
- protected final ResultSet results;
- protected final ClassOrInterface cl;
- public final Set inserts = new HashSet<>();
- private Method method;
-
- TypeInsertPlacerClass(ClassOrInterface forClass, ResultSet withResults){
- this.cl = forClass;
- this.method = null;
- this.results = withResults;
- forClass.accept(this);
- }
-
- @Override
- public void visit(Method method) {
- this.method = method;
- if(method.getReturnType() instanceof TypePlaceholder)
- inserts.add(TypeInsertFactory.createInsertPoints(
- method.getReturnType(), method.getReturnType().getOffset(), cl, method, results));
- super.visit(method);
- }
-
- @Override
- public void visit(Field field) {
- if(field.getType() instanceof TypePlaceholder){
- inserts.add(TypeInsertFactory.createInsertPoints(
- field.getType(), field.getType().getOffset(), cl, method, results));
- }
- super.visit(field);
- }
-
- @Override
- public void visit(FormalParameter param) {
- if(param.getType() instanceof TypePlaceholder)
- inserts.add(TypeInsertFactory.createInsertPoints(
- param.getType(), param.getType().getOffset(), cl, method, results));
- super.visit(param);
- }
-
- @Override
- public void visit(LambdaExpression lambdaExpression) {
- //Lambda-Ausdrücke brauchen keine Typeinsetzungen
- }
-}
+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;
+
+import java.util.HashSet;
+import java.util.Set;
+
+public class TypeInsertPlacer extends AbstractASTWalker{
+ Set inserts = new HashSet<>();
+ private ResultSet withResults;
+
+ public Set getTypeInserts(SourceFile forSourceFile, ResultSet withResults){
+ this.withResults = withResults;
+ forSourceFile.accept(this);
+ return inserts;
+ }
+
+ @Override
+ public void visit(ClassOrInterface classOrInterface) {
+ TypeInsertPlacerClass cl = new TypeInsertPlacerClass(classOrInterface, withResults);
+ this.inserts.addAll(cl.inserts);
+ }
+}
+
+class TypeInsertPlacerClass extends AbstractASTWalker{
+ protected final ResultSet results;
+ protected final ClassOrInterface cl;
+ public final Set inserts = new HashSet<>();
+ private Method method;
+
+ TypeInsertPlacerClass(ClassOrInterface forClass, ResultSet withResults){
+ this.cl = forClass;
+ this.method = null;
+ this.results = withResults;
+ forClass.accept(this);
+ }
+
+ @Override
+ public void visit(Method method) {
+ this.method = method;
+ if(method.getReturnType() instanceof TypePlaceholder)
+ inserts.add(TypeInsertFactory.createInsertPoints(
+ method.getReturnType(), method.getReturnType().getOffset(), cl, method, results));
+ super.visit(method);
+ }
+
+ @Override
+ public void visit(Field field) {
+ if(field.getType() instanceof TypePlaceholder){
+ inserts.add(TypeInsertFactory.createInsertPoints(
+ field.getType(), field.getType().getOffset(), cl, method, results));
+ }
+ super.visit(field);
+ }
+
+ @Override
+ public void visit(FormalParameter param) {
+ if(param.getType() instanceof TypePlaceholder)
+ inserts.add(TypeInsertFactory.createInsertPoints(
+ param.getType(), param.getType().getOffset(), cl, method, results));
+ super.visit(param);
+ }
+
+ @Override
+ public void visit(LambdaExpression lambdaExpression) {
+ //Lambda-Ausdrücke brauchen keine Typeinsetzungen
+ }
+}
diff --git a/src/main/java/de/dhbwstuttgart/typedeployment/TypeInsertPoint.java b/src/main/java/de/dhbwstuttgart/typedeployment/TypeInsertPoint.java
index 4c495d65..bde45df1 100644
--- a/src/main/java/de/dhbwstuttgart/typedeployment/TypeInsertPoint.java
+++ b/src/main/java/de/dhbwstuttgart/typedeployment/TypeInsertPoint.java
@@ -1,59 +1,59 @@
-package de.dhbwstuttgart.typedeployment;
-
-import org.antlr.v4.runtime.Token;
-
-import de.dhbwstuttgart.typeinference.unify.model.ReferenceType;
-
-import java.time.OffsetDateTime;
-import java.util.List;
-import java.util.stream.Collectors;
-
-public class TypeInsertPoint {
- public Token point;
- private String insertString;
- private int extraOffset = 0;
-
- public TypeInsertPoint(Token point, String toInsert){
- this.point = point;
- this.insertString = (toInsert.endsWith(" ")) ? toInsert : toInsert + " " ;
- }
-
- public String insert(String intoSource, List additionalOffset){
- int offset = additionalOffset.stream().filter((token ->
- //token.point.getLine() != point.getLine() && token.point.getCharPositionInLine() <= point.getCharPositionInLine()))
- token.point.getStartIndex() <= point.getStartIndex()))
- .mapToInt((typeInsertPoint -> typeInsertPoint.insertString.length())).sum();
- return new StringBuilder(intoSource).insert(point.getStartIndex()+offset+extraOffset, insertString).toString();
- }
-
- public String getInsertString() {
- return insertString;
- }
-
- public void addExtraOffset(int toAdd) {
- this.extraOffset += toAdd;
- }
-
- public int getPositionInCode() {
- return point.getStartIndex() + extraOffset;
- }
-
- /* PL 2018-06-19
- * Zwei TypeInsertPoint's sind gleich, wenn ihre point's gleich sind
- * eingefuegt damit man TypeReplaceMarker vergleichen kann
- * @see java.lang.Object#equals(java.lang.Object)
- */
- public boolean equals(Object obj) {
- if(!(obj instanceof TypeInsertPoint)) {
- return false;
- }
- else {
- return ((TypeInsertPoint)obj).point.equals(this.point) &&
- ((TypeInsertPoint)obj).insertString.equals(this.insertString);
- }
- }
-
- public String toString() {
- return point.toString() + " " + insertString.toString();
- }
-}
+package de.dhbwstuttgart.typedeployment;
+
+import org.antlr.v4.runtime.Token;
+
+import de.dhbwstuttgart.typeinference.unify.model.ReferenceType;
+
+import java.time.OffsetDateTime;
+import java.util.List;
+import java.util.stream.Collectors;
+
+public class TypeInsertPoint {
+ public Token point;
+ private String insertString;
+ private int extraOffset = 0;
+
+ public TypeInsertPoint(Token point, String toInsert){
+ this.point = point;
+ this.insertString = (toInsert.endsWith(" ")) ? toInsert : toInsert + " " ;
+ }
+
+ public String insert(String intoSource, List additionalOffset){
+ int offset = additionalOffset.stream().filter((token ->
+ //token.point.getLine() != point.getLine() && token.point.getCharPositionInLine() <= point.getCharPositionInLine()))
+ token.point.getStartIndex() <= point.getStartIndex()))
+ .mapToInt((typeInsertPoint -> typeInsertPoint.insertString.length())).sum();
+ return new StringBuilder(intoSource).insert(point.getStartIndex()+offset+extraOffset, insertString).toString();
+ }
+
+ public String getInsertString() {
+ return insertString;
+ }
+
+ public void addExtraOffset(int toAdd) {
+ this.extraOffset += toAdd;
+ }
+
+ public int getPositionInCode() {
+ return point.getStartIndex() + extraOffset;
+ }
+
+ /* PL 2018-06-19
+ * Zwei TypeInsertPoint's sind gleich, wenn ihre point's gleich sind
+ * eingefuegt damit man TypeReplaceMarker vergleichen kann
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ public boolean equals(Object obj) {
+ if(!(obj instanceof TypeInsertPoint)) {
+ return false;
+ }
+ else {
+ return ((TypeInsertPoint)obj).point.equals(this.point) &&
+ ((TypeInsertPoint)obj).insertString.equals(this.insertString);
+ }
+ }
+
+ public String toString() {
+ return point.toString() + " " + insertString.toString();
+ }
+}
diff --git a/src/main/java/de/dhbwstuttgart/typeinference/result/ResultPair.java b/src/main/java/de/dhbwstuttgart/typeinference/result/ResultPair.java
index 552bf494..490e6f95 100644
--- a/src/main/java/de/dhbwstuttgart/typeinference/result/ResultPair.java
+++ b/src/main/java/de/dhbwstuttgart/typeinference/result/ResultPair.java
@@ -1,62 +1,62 @@
-package de.dhbwstuttgart.typeinference.result;
-
-import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
-
-/**
- * Paare, welche das Unifikationsergebnis darstellen
- */
-public abstract class ResultPair {
- private final A left;
- private final B right;
-
- public abstract void accept(ResultPairVisitor visitor);
-
- public ResultPair(A left, B right){
- this.left = left;
- this.right = right;
- }
-
- public A getLeft() {
- return left;
- }
-
- public B getRight() {
- return right;
- }
-
- public String toString() {
- return "(" + left.toString() + ", " + right.toString() + ")";
- }
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((left == null) ? 0 : left.getOffset().hashCode());
- result = prime * result + ((right == null) ? 0 : right.getOffset().hashCode());
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (getClass() != obj.getClass())
- return false;
- ResultPair,?> other = (ResultPair,?>) obj;
- if (left == null) {
- if (other.left != null)
- return false;
- } else if (!left.getOffset().equals(other.left.getOffset()))
- return false;
- if (right == null) {
- if (other.right != null)
- return false;
- } else if (!right.getOffset().equals(other.right.getOffset()))
- return false;
- return true;
- }
-
-}
+package de.dhbwstuttgart.typeinference.result;
+
+import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
+
+/**
+ * Paare, welche das Unifikationsergebnis darstellen
+ */
+public abstract class ResultPair {
+ private final A left;
+ private final B right;
+
+ public abstract void accept(ResultPairVisitor visitor);
+
+ public ResultPair(A left, B right){
+ this.left = left;
+ this.right = right;
+ }
+
+ public A getLeft() {
+ return left;
+ }
+
+ public B getRight() {
+ return right;
+ }
+
+ public String toString() {
+ return "(" + left.toString() + ", " + right.toString() + ")";
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((left == null) ? 0 : left.getOffset().hashCode());
+ result = prime * result + ((right == null) ? 0 : right.getOffset().hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ ResultPair,?> other = (ResultPair,?>) obj;
+ if (left == null) {
+ if (other.left != null)
+ return false;
+ } else if (!left.getOffset().equals(other.left.getOffset()))
+ return false;
+ if (right == null) {
+ if (other.right != null)
+ return false;
+ } else if (!right.getOffset().equals(other.right.getOffset()))
+ return false;
+ return true;
+ }
+
+}
diff --git a/src/main/java/de/dhbwstuttgart/typeinference/result/ResultSet.java b/src/main/java/de/dhbwstuttgart/typeinference/result/ResultSet.java
index f508fe34..a46b9ed2 100644
--- a/src/main/java/de/dhbwstuttgart/typeinference/result/ResultSet.java
+++ b/src/main/java/de/dhbwstuttgart/typeinference/result/ResultSet.java
@@ -1,309 +1,309 @@
-package de.dhbwstuttgart.typeinference.result;
-
-import java.util.HashSet;
-import java.util.Set;
-
-import de.dhbwstuttgart.exceptions.NotImplementedException;
-import de.dhbwstuttgart.syntaxtree.type.ExtendsWildcardType;
-import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
-import de.dhbwstuttgart.syntaxtree.type.RefType;
-import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
-import de.dhbwstuttgart.syntaxtree.type.SuperWildcardType;
-import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
-
-@SuppressWarnings("rawtypes")
-public class ResultSet {
-
- public final Set results;
- public Set> genIns;
-
- public ResultSet(Set set){
- this.results = set;
- this.genIns = new HashSet<>();
+package de.dhbwstuttgart.typeinference.result;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import de.dhbwstuttgart.exceptions.NotImplementedException;
+import de.dhbwstuttgart.syntaxtree.type.ExtendsWildcardType;
+import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
+import de.dhbwstuttgart.syntaxtree.type.RefType;
+import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
+import de.dhbwstuttgart.syntaxtree.type.SuperWildcardType;
+import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
+
+@SuppressWarnings("rawtypes")
+public class ResultSet {
+
+ public final Set results;
+ public Set> genIns;
+
+ public ResultSet(Set set){
+ this.results = set;
+ this.genIns = new HashSet<>();
results.forEach(x -> { if (x instanceof PairTPHsmallerTPH) { this.genIns.add(x);}} );
- }
-
- public boolean contains(ResultPair toCheck) {
- return this.results.contains(toCheck);
- }
-
- public void remove(ResultPair toCheck) {
- results.remove(toCheck);
- }
-
- public ResolvedType resolveType(RefTypeOrTPHOrWildcardOrGeneric type) {
- if(type instanceof TypePlaceholder)
- return new Resolver(this).resolve((TypePlaceholder)type);
- if(type instanceof GenericRefType)return new ResolvedType(type, new HashSet<>());
- if(type instanceof RefType) {
- RelatedTypeWalker related = new RelatedTypeWalker(null, this);
- type.accept(related);
- return new ResolvedType(type, related.relatedTPHs);
- } else {
- throw new NotImplementedException();
- //return new ResolvedType(type,new HashSet<>());
- }
- }
-
- public String toString() {
- return results.toString();
- }
-
- @Override
- public boolean equals(Object o) {
- if (o instanceof ResultSet) {
- ResultSet other = (ResultSet)o;
- return this.results.equals(other.results);
- } else {
- return false;
- }
- }
-
- @Override
- public int hashCode() {
- return results.hashCode();
- }
-}
-
-class Resolver implements ResultSetVisitor {
- private final ResultSet result;
- private TypePlaceholder toResolve;
- private RefTypeOrTPHOrWildcardOrGeneric resolved;
- private final Set additionalTPHs = new HashSet<>();
- private ResultPair,?> currentPair;
-
- public Resolver(ResultSet resultPairs){
- this.result = resultPairs;
- }
-
- public ResolvedType resolve(TypePlaceholder tph){
- toResolve = tph;
- resolved = null;
- System.out.println(tph.toString());
- for(ResultPair,?> resultPair : result.results) {
- if(resultPair instanceof PairTPHEqualTPH && ((PairTPHEqualTPH) resultPair).getLeft().equals(toResolve)){
- currentPair = resultPair;
- return resolve(((PairTPHEqualTPH) resultPair).getRight());
- }
- }
- for(ResultPair,?> resultPair : result.results){
- currentPair = resultPair;
- resultPair.accept(this);
- }
- if(resolved==null){//TPH kommt nicht im Result vor:
- resolved = tph;
- }
-
- ResolvedType result = new ResolvedType(resolved, additionalTPHs);//resolved;
- result.setResultPair(currentPair);
- return result;
- }
-
- @Override
- public void visit(PairTPHsmallerTPH p) {
- currentPair = p;
- if(p.left.equals(toResolve)){
- additionalTPHs.add(new GenericInsertPair(p.left, p.right));
- additionalTPHs.addAll(new RelatedTypeWalker(p.right, result).relatedTPHs);
- }
- if(p.right.equals(toResolve))
- additionalTPHs.addAll(new RelatedTypeWalker(p.left, result).relatedTPHs);
- }
-
- @Override
- public void visit(PairTPHequalRefTypeOrWildcardType p) {
- currentPair = p;
- if(p.left.equals(toResolve)){
- resolved = p.right;
- RelatedTypeWalker related = new RelatedTypeWalker(null, result);
- p.right.accept(related);
- additionalTPHs.addAll(related.relatedTPHs);
- }
- }
-
- @Override
- public void visit(PairTPHEqualTPH p) {
- //Do nothing. Dieser Fall wird in der resolve-Methode abgefangen
- }
-
- @Override
- public void visit(RefType refType) {
-
- }
-
- @Override
- public void visit(GenericRefType genericRefType) {
-
- }
-
- @Override
- public void visit(SuperWildcardType superWildcardType) {
-
- }
-
- @Override
- public void visit(TypePlaceholder typePlaceholder) {
-
- }
-
- @Override
- public void visit(ExtendsWildcardType extendsWildcardType) {
-
- }
-
-
-
-}
-
-/**
- * Sucht aus dem Result Set den Sub/supertyp für einen TPH
- */
-@SuppressWarnings("rawtypes")
-class TPHResolver implements ResultSetVisitor {
-
- private final TypePlaceholder tph;
- Set resolved = new HashSet<>();
- private final ResultSet resultSet;
-
- TPHResolver(TypePlaceholder tph, ResultSet resultSet){
- this.resultSet = resultSet;
- this.tph = tph;
- for(ResultPair p : resultSet.results){
- p.accept(this);
- }
- if(resolved.size() == 0){
- resolved.add(new GenericInsertPair(tph, null));
- }
- }
-
- @Override
- public void visit(PairTPHsmallerTPH p) {
- if(p.left.equals(tph) || p.right.equals(tph)){
- resolved.add(new GenericInsertPair(p.left, p.right));
- }
- }
-
- @Override
- public void visit(PairTPHequalRefTypeOrWildcardType p) {
- TypePlaceholder otherSide = null;
- if(p.right.equals(tph)){
- otherSide = p.left;
- }
- if(otherSide != null){
- Set newResultSet = new HashSet<>(this.resultSet.results);
- newResultSet.remove(p);
- resolved.addAll(new TPHResolver(otherSide, new ResultSet(newResultSet)).resolved);
- }
- }
-
- @Override
- public void visit(PairTPHEqualTPH p) {
- //ignorieren. Wird vom Resolver behandelt
- }
-
- @Override
- public void visit(RefType refType) {
-
- }
-
- @Override
- public void visit(GenericRefType genericRefType) {
-
- }
-
- @Override
- public void visit(SuperWildcardType superWildcardType) {
-
- }
-
- @Override
- public void visit(TypePlaceholder typePlaceholder) {
-
- }
-
- @Override
- public void visit(ExtendsWildcardType extendsWildcardType) {
-
- }
-}
-
-@SuppressWarnings("rawtypes")
-class RelatedTypeWalker implements ResultSetVisitor {
-
- final Set relatedTPHs = new HashSet<>();
- private final TypePlaceholder toResolve;
- private final ResultSet resultSet;
-
- /**
- * Läuft über das resultSet und speichert alle TPHs, welche mit start in Verbindung stehen
- * @param start - kann null sein, wenn der Walker für einen RefType benutzt wird
- * @param resultSet
- */
- RelatedTypeWalker(TypePlaceholder start, ResultSet resultSet){
- this.toResolve = start;
- this.resultSet = resultSet;
- int resolved = 0;
- do{
- resolved = relatedTPHs.size();
- for(ResultPair p : resultSet.results){
- p.accept(this);
- p.accept(this);
- }
- }while(resolved - relatedTPHs.size() > 0);
- }
-
- @Override
- public void visit(PairTPHsmallerTPH p) {
- if(p.getRight().equals(toResolve)){
- relatedTPHs.addAll(new TPHResolver(p.right, resultSet).resolved);
- //relatedTPHs.addAll(new RelatedTypeWalker(p.right, resultSet).relatedTPHs);
- }
- if(p.getLeft().equals(toResolve)){
- relatedTPHs.addAll(new TPHResolver(p.left, resultSet).resolved);
- //relatedTPHs.addAll(new RelatedTypeWalker(p.left, resultSet).relatedTPHs);
- }
- }
-
- @Override
- public void visit(PairTPHequalRefTypeOrWildcardType p) {
- if(p.getLeft().equals(toResolve)){
- p.getRight().accept(this);
- }
- }
-
- @Override
- public void visit(PairTPHEqualTPH p) {
- //Kann ignoriert werden. Diese Fälle werden vom Resolver behandelt
- }
-
- /*
- Die folgenden Funktionen fügen alle TPHs an die relatedTPHs an, denen sie begegnen:
- Das wird verwendet, wenn alle relatedTPHs aus den Parametern eines RefTypes angefügt werden sollen
- */
-
- @Override
- public void visit(RefType refType) {
- for(RefTypeOrTPHOrWildcardOrGeneric param : refType.getParaList()){
- param.accept(this);
- }
- }
-
- @Override
- public void visit(SuperWildcardType superWildcardType) {
- superWildcardType.getInnerType().accept(this);
- }
-
- @Override
- public void visit(TypePlaceholder typePlaceholder) {
- relatedTPHs.addAll(new TPHResolver(typePlaceholder, resultSet).resolved);
- }
-
- @Override
- public void visit(ExtendsWildcardType extendsWildcardType) {
- extendsWildcardType.getInnerType().accept(this);
- }
-
- @Override
- public void visit(GenericRefType genericRefType) {
- }
+ }
+
+ public boolean contains(ResultPair toCheck) {
+ return this.results.contains(toCheck);
+ }
+
+ public void remove(ResultPair toCheck) {
+ results.remove(toCheck);
+ }
+
+ public ResolvedType resolveType(RefTypeOrTPHOrWildcardOrGeneric type) {
+ if(type instanceof TypePlaceholder)
+ return new Resolver(this).resolve((TypePlaceholder)type);
+ if(type instanceof GenericRefType)return new ResolvedType(type, new HashSet<>());
+ if(type instanceof RefType) {
+ RelatedTypeWalker related = new RelatedTypeWalker(null, this);
+ type.accept(related);
+ return new ResolvedType(type, related.relatedTPHs);
+ } else {
+ throw new NotImplementedException();
+ //return new ResolvedType(type,new HashSet<>());
+ }
+ }
+
+ public String toString() {
+ return results.toString();
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (o instanceof ResultSet) {
+ ResultSet other = (ResultSet)o;
+ return this.results.equals(other.results);
+ } else {
+ return false;
+ }
+ }
+
+ @Override
+ public int hashCode() {
+ return results.hashCode();
+ }
+}
+
+class Resolver implements ResultSetVisitor {
+ private final ResultSet result;
+ private TypePlaceholder toResolve;
+ private RefTypeOrTPHOrWildcardOrGeneric resolved;
+ private final Set additionalTPHs = new HashSet<>();
+ private ResultPair,?> currentPair;
+
+ public Resolver(ResultSet resultPairs){
+ this.result = resultPairs;
+ }
+
+ public ResolvedType resolve(TypePlaceholder tph){
+ toResolve = tph;
+ resolved = null;
+ System.out.println(tph.toString());
+ for(ResultPair,?> resultPair : result.results) {
+ if(resultPair instanceof PairTPHEqualTPH && ((PairTPHEqualTPH) resultPair).getLeft().equals(toResolve)){
+ currentPair = resultPair;
+ return resolve(((PairTPHEqualTPH) resultPair).getRight());
+ }
+ }
+ for(ResultPair,?> resultPair : result.results){
+ currentPair = resultPair;
+ resultPair.accept(this);
+ }
+ if(resolved==null){//TPH kommt nicht im Result vor:
+ resolved = tph;
+ }
+
+ ResolvedType result = new ResolvedType(resolved, additionalTPHs);//resolved;
+ result.setResultPair(currentPair);
+ return result;
+ }
+
+ @Override
+ public void visit(PairTPHsmallerTPH p) {
+ currentPair = p;
+ if(p.left.equals(toResolve)){
+ additionalTPHs.add(new GenericInsertPair(p.left, p.right));
+ additionalTPHs.addAll(new RelatedTypeWalker(p.right, result).relatedTPHs);
+ }
+ if(p.right.equals(toResolve))
+ additionalTPHs.addAll(new RelatedTypeWalker(p.left, result).relatedTPHs);
+ }
+
+ @Override
+ public void visit(PairTPHequalRefTypeOrWildcardType p) {
+ currentPair = p;
+ if(p.left.equals(toResolve)){
+ resolved = p.right;
+ RelatedTypeWalker related = new RelatedTypeWalker(null, result);
+ p.right.accept(related);
+ additionalTPHs.addAll(related.relatedTPHs);
+ }
+ }
+
+ @Override
+ public void visit(PairTPHEqualTPH p) {
+ //Do nothing. Dieser Fall wird in der resolve-Methode abgefangen
+ }
+
+ @Override
+ public void visit(RefType refType) {
+
+ }
+
+ @Override
+ public void visit(GenericRefType genericRefType) {
+
+ }
+
+ @Override
+ public void visit(SuperWildcardType superWildcardType) {
+
+ }
+
+ @Override
+ public void visit(TypePlaceholder typePlaceholder) {
+
+ }
+
+ @Override
+ public void visit(ExtendsWildcardType extendsWildcardType) {
+
+ }
+
+
+
+}
+
+/**
+ * Sucht aus dem Result Set den Sub/supertyp für einen TPH
+ */
+@SuppressWarnings("rawtypes")
+class TPHResolver implements ResultSetVisitor {
+
+ private final TypePlaceholder tph;
+ Set resolved = new HashSet<>();
+ private final ResultSet resultSet;
+
+ TPHResolver(TypePlaceholder tph, ResultSet resultSet){
+ this.resultSet = resultSet;
+ this.tph = tph;
+ for(ResultPair p : resultSet.results){
+ p.accept(this);
+ }
+ if(resolved.size() == 0){
+ resolved.add(new GenericInsertPair(tph, null));
+ }
+ }
+
+ @Override
+ public void visit(PairTPHsmallerTPH p) {
+ if(p.left.equals(tph) || p.right.equals(tph)){
+ resolved.add(new GenericInsertPair(p.left, p.right));
+ }
+ }
+
+ @Override
+ public void visit(PairTPHequalRefTypeOrWildcardType p) {
+ TypePlaceholder otherSide = null;
+ if(p.right.equals(tph)){
+ otherSide = p.left;
+ }
+ if(otherSide != null){
+ Set newResultSet = new HashSet<>(this.resultSet.results);
+ newResultSet.remove(p);
+ resolved.addAll(new TPHResolver(otherSide, new ResultSet(newResultSet)).resolved);
+ }
+ }
+
+ @Override
+ public void visit(PairTPHEqualTPH p) {
+ //ignorieren. Wird vom Resolver behandelt
+ }
+
+ @Override
+ public void visit(RefType refType) {
+
+ }
+
+ @Override
+ public void visit(GenericRefType genericRefType) {
+
+ }
+
+ @Override
+ public void visit(SuperWildcardType superWildcardType) {
+
+ }
+
+ @Override
+ public void visit(TypePlaceholder typePlaceholder) {
+
+ }
+
+ @Override
+ public void visit(ExtendsWildcardType extendsWildcardType) {
+
+ }
+}
+
+@SuppressWarnings("rawtypes")
+class RelatedTypeWalker implements ResultSetVisitor {
+
+ final Set relatedTPHs = new HashSet<>();
+ private final TypePlaceholder toResolve;
+ private final ResultSet resultSet;
+
+ /**
+ * Läuft über das resultSet und speichert alle TPHs, welche mit start in Verbindung stehen
+ * @param start - kann null sein, wenn der Walker für einen RefType benutzt wird
+ * @param resultSet
+ */
+ RelatedTypeWalker(TypePlaceholder start, ResultSet resultSet){
+ this.toResolve = start;
+ this.resultSet = resultSet;
+ int resolved = 0;
+ do{
+ resolved = relatedTPHs.size();
+ for(ResultPair p : resultSet.results){
+ p.accept(this);
+ p.accept(this);
+ }
+ }while(resolved - relatedTPHs.size() > 0);
+ }
+
+ @Override
+ public void visit(PairTPHsmallerTPH p) {
+ if(p.getRight().equals(toResolve)){
+ relatedTPHs.addAll(new TPHResolver(p.right, resultSet).resolved);
+ //relatedTPHs.addAll(new RelatedTypeWalker(p.right, resultSet).relatedTPHs);
+ }
+ if(p.getLeft().equals(toResolve)){
+ relatedTPHs.addAll(new TPHResolver(p.left, resultSet).resolved);
+ //relatedTPHs.addAll(new RelatedTypeWalker(p.left, resultSet).relatedTPHs);
+ }
+ }
+
+ @Override
+ public void visit(PairTPHequalRefTypeOrWildcardType p) {
+ if(p.getLeft().equals(toResolve)){
+ p.getRight().accept(this);
+ }
+ }
+
+ @Override
+ public void visit(PairTPHEqualTPH p) {
+ //Kann ignoriert werden. Diese Fälle werden vom Resolver behandelt
+ }
+
+ /*
+ Die folgenden Funktionen fügen alle TPHs an die relatedTPHs an, denen sie begegnen:
+ Das wird verwendet, wenn alle relatedTPHs aus den Parametern eines RefTypes angefügt werden sollen
+ */
+
+ @Override
+ public void visit(RefType refType) {
+ for(RefTypeOrTPHOrWildcardOrGeneric param : refType.getParaList()){
+ param.accept(this);
+ }
+ }
+
+ @Override
+ public void visit(SuperWildcardType superWildcardType) {
+ superWildcardType.getInnerType().accept(this);
+ }
+
+ @Override
+ public void visit(TypePlaceholder typePlaceholder) {
+ relatedTPHs.addAll(new TPHResolver(typePlaceholder, resultSet).resolved);
+ }
+
+ @Override
+ public void visit(ExtendsWildcardType extendsWildcardType) {
+ extendsWildcardType.getInnerType().accept(this);
+ }
+
+ @Override
+ public void visit(GenericRefType genericRefType) {
+ }
}
\ No newline at end of file
diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/GuavaSetOperations.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/GuavaSetOperations.java
index b51fb648..19e7c48f 100644
--- a/src/main/java/de/dhbwstuttgart/typeinference/unify/GuavaSetOperations.java
+++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/GuavaSetOperations.java
@@ -1,23 +1,23 @@
-package de.dhbwstuttgart.typeinference.unify;
-
-import java.util.List;
-import java.util.Set;
-
-import com.google.common.collect.Sets;
-
-import de.dhbwstuttgart.typeinference.unify.interfaces.ISetOperations;
-
-/**
- * Implements set operations using google guava.
- * @author DH10STF
- *
- */
-public class GuavaSetOperations implements ISetOperations {
-
- @Override
- public Set> cartesianProduct(List extends Set extends B>> sets) {
- // Wraps the call to google guava
- return Sets.cartesianProduct(sets);
- }
-
-}
+package de.dhbwstuttgart.typeinference.unify;
+
+import java.util.List;
+import java.util.Set;
+
+import com.google.common.collect.Sets;
+
+import de.dhbwstuttgart.typeinference.unify.interfaces.ISetOperations;
+
+/**
+ * Implements set operations using google guava.
+ * @author DH10STF
+ *
+ */
+public class GuavaSetOperations implements ISetOperations {
+
+ @Override
+ public Set> cartesianProduct(List extends Set extends B>> sets) {
+ // Wraps the call to google guava
+ return Sets.cartesianProduct(sets);
+ }
+
+}
diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/MartelliMontanariUnify.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/MartelliMontanariUnify.java
index 087b8943..2fceb245 100644
--- a/src/main/java/de/dhbwstuttgart/typeinference/unify/MartelliMontanariUnify.java
+++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/MartelliMontanariUnify.java
@@ -1,108 +1,108 @@
-package de.dhbwstuttgart.typeinference.unify;
-
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Optional;
-import java.util.Set;
-import java.util.stream.Collectors;
-
-import de.dhbwstuttgart.typeinference.unify.interfaces.IUnify;
-import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
-import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType;
-import de.dhbwstuttgart.typeinference.unify.model.TypeParams;
-import de.dhbwstuttgart.typeinference.unify.model.Unifier;
-import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
-import de.dhbwstuttgart.typeinference.unify.model.UnifyType;
-
-/**
- * Implementation of the Martelli-Montanari unification algorithm.
- * @author Florian Steurer
- */
-public class MartelliMontanariUnify implements IUnify {
-
- @Override
- public Optional unify(Set terms) {
- // Sets with less than 2 terms are trivially unified
- if(terms.size() < 2)
- return Optional.of(Unifier.identity());
-
- // For the the set of terms {t1,...,tn},
- // build a list of equations {(t1 = t2), (t2 = t3), (t3 = t4), ....}
- ArrayList termsList = new ArrayList();
- Iterator iter = terms.iterator();
- UnifyType prev = iter.next();
+package de.dhbwstuttgart.typeinference.unify;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Optional;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+import de.dhbwstuttgart.typeinference.unify.interfaces.IUnify;
+import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
+import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType;
+import de.dhbwstuttgart.typeinference.unify.model.TypeParams;
+import de.dhbwstuttgart.typeinference.unify.model.Unifier;
+import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
+import de.dhbwstuttgart.typeinference.unify.model.UnifyType;
+
+/**
+ * Implementation of the Martelli-Montanari unification algorithm.
+ * @author Florian Steurer
+ */
+public class MartelliMontanariUnify implements IUnify {
+
+ @Override
+ public Optional unify(Set terms) {
+ // Sets with less than 2 terms are trivially unified
+ if(terms.size() < 2)
+ return Optional.of(Unifier.identity());
+
+ // For the the set of terms {t1,...,tn},
+ // build a list of equations {(t1 = t2), (t2 = t3), (t3 = t4), ....}
+ ArrayList termsList = new ArrayList();
+ Iterator iter = terms.iterator();
+ UnifyType prev = iter.next();
while(iter.hasNext()) {
- UnifyType next = iter.next();
+ UnifyType next = iter.next();
termsList.add(new UnifyPair(prev, next, PairOperator.EQUALSDOT));
- prev = next;
- }
-
- // Start with the identity unifier. Substitutions will be added later.
- Unifier mgu = Unifier.identity();
-
- // Apply rules while possible
- int idx = 0;
- while(idx < termsList.size()) {
- UnifyPair pair = termsList.get(idx);
- UnifyType rhsType = pair.getRhsType();
- UnifyType lhsType = pair.getLhsType();
- TypeParams rhsTypeParams = rhsType.getTypeParams();
- TypeParams lhsTypeParams = lhsType.getTypeParams();
-
- // REDUCE - Rule
- if(!(rhsType instanceof PlaceholderType) && !(lhsType instanceof PlaceholderType)) {
- Set result = new HashSet<>();
-
- // f<...> = g<...> with f != g are not unifiable
- if(!rhsType.getName().equals(lhsType.getName()))
- return Optional.empty(); // conflict
- // f = f are not unifiable
- if(rhsTypeParams.size() != lhsTypeParams.size())
- return Optional.empty(); // conflict
- // f = g is not unifiable (cannot be f = f because erase rule would have been applied)
- //if(rhsTypeParams.size() == 0)
- //return Optional.empty();
-
- // Unpack the arguments
- for(int i = 0; i < rhsTypeParams.size(); i++)
- result.add(new UnifyPair(rhsTypeParams.get(i), lhsTypeParams.get(i), PairOperator.EQUALSDOT));
-
- termsList.remove(idx);
- termsList.addAll(result);
- continue;
- }
-
- // DELETE - Rule
- if(pair.getRhsType().equals(pair.getLhsType())) {
- termsList.remove(idx);
- continue;
- }
-
- // SWAP - Rule
- if(!(lhsType instanceof PlaceholderType) && (rhsType instanceof PlaceholderType)) {
- termsList.remove(idx);
- termsList.add(new UnifyPair(rhsType, lhsType, PairOperator.EQUALSDOT));
- continue;
- }
-
- // OCCURS-CHECK
- if(pair.getLhsType() instanceof PlaceholderType
- && pair.getRhsType().getTypeParams().occurs((PlaceholderType) pair.getLhsType()))
- return Optional.empty();
-
- // SUBST - Rule
- if(lhsType instanceof PlaceholderType) {
- mgu.add((PlaceholderType) lhsType, rhsType);
- //PL 2018-04-01 nach checken, ob es richtig ist, dass keine Substitutionen uebergeben werden muessen.
- termsList = termsList.stream().map(x -> mgu.apply(x)).collect(Collectors.toCollection(ArrayList::new));
- idx = idx+1 == termsList.size() ? 0 : idx+1;
- continue;
- }
-
- idx++;
- }
-
- return Optional.of(mgu);
- }
-}
+ prev = next;
+ }
+
+ // Start with the identity unifier. Substitutions will be added later.
+ Unifier mgu = Unifier.identity();
+
+ // Apply rules while possible
+ int idx = 0;
+ while(idx < termsList.size()) {
+ UnifyPair pair = termsList.get(idx);
+ UnifyType rhsType = pair.getRhsType();
+ UnifyType lhsType = pair.getLhsType();
+ TypeParams rhsTypeParams = rhsType.getTypeParams();
+ TypeParams lhsTypeParams = lhsType.getTypeParams();
+
+ // REDUCE - Rule
+ if(!(rhsType instanceof PlaceholderType) && !(lhsType instanceof PlaceholderType)) {
+ Set result = new HashSet<>();
+
+ // f<...> = g<...> with f != g are not unifiable
+ if(!rhsType.getName().equals(lhsType.getName()))
+ return Optional.empty(); // conflict
+ // f = f are not unifiable
+ if(rhsTypeParams.size() != lhsTypeParams.size())
+ return Optional.empty(); // conflict
+ // f = g is not unifiable (cannot be f = f because erase rule would have been applied)
+ //if(rhsTypeParams.size() == 0)
+ //return Optional.empty();
+
+ // Unpack the arguments
+ for(int i = 0; i < rhsTypeParams.size(); i++)
+ result.add(new UnifyPair(rhsTypeParams.get(i), lhsTypeParams.get(i), PairOperator.EQUALSDOT));
+
+ termsList.remove(idx);
+ termsList.addAll(result);
+ continue;
+ }
+
+ // DELETE - Rule
+ if(pair.getRhsType().equals(pair.getLhsType())) {
+ termsList.remove(idx);
+ continue;
+ }
+
+ // SWAP - Rule
+ if(!(lhsType instanceof PlaceholderType) && (rhsType instanceof PlaceholderType)) {
+ termsList.remove(idx);
+ termsList.add(new UnifyPair(rhsType, lhsType, PairOperator.EQUALSDOT));
+ continue;
+ }
+
+ // OCCURS-CHECK
+ if(pair.getLhsType() instanceof PlaceholderType
+ && pair.getRhsType().getTypeParams().occurs((PlaceholderType) pair.getLhsType()))
+ return Optional.empty();
+
+ // SUBST - Rule
+ if(lhsType instanceof PlaceholderType) {
+ mgu.add((PlaceholderType) lhsType, rhsType);
+ //PL 2018-04-01 nach checken, ob es richtig ist, dass keine Substitutionen uebergeben werden muessen.
+ termsList = termsList.stream().map(x -> mgu.apply(x)).collect(Collectors.toCollection(ArrayList::new));
+ idx = idx+1 == termsList.size() ? 0 : idx+1;
+ continue;
+ }
+
+ idx++;
+ }
+
+ return Optional.of(mgu);
+ }
+}
diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/Match.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/Match.java
index 3e995607..75469f64 100644
--- a/src/main/java/de/dhbwstuttgart/typeinference/unify/Match.java
+++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/Match.java
@@ -1,91 +1,91 @@
-package de.dhbwstuttgart.typeinference.unify;
-
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Optional;
-import java.util.Set;
-import java.util.stream.Collectors;
-
-import de.dhbwstuttgart.typeinference.unify.interfaces.IMatch;
-import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
-import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType;
-import de.dhbwstuttgart.typeinference.unify.model.TypeParams;
-import de.dhbwstuttgart.typeinference.unify.model.Unifier;
-import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
-import de.dhbwstuttgart.typeinference.unify.model.UnifyType;
-
-/**
- * Implementation of match derived from unification algorithm.
- * @author Martin Pluemicke
- */
-public class Match implements IMatch {
-
- @Override
- //A =. A ==> True
- //A =. A ==> False
- public Optional match(ArrayList termsList) {
-
- // Start with the identity unifier. Substitutions will be added later.
- Unifier mgu = Unifier.identity();
-
- // Apply rules while possible
- int idx = 0;
- while(idx < termsList.size()) {
- UnifyPair pair = termsList.get(idx);
- UnifyType rhsType = pair.getRhsType();
- UnifyType lhsType = pair.getLhsType();
- TypeParams rhsTypeParams = rhsType.getTypeParams();
- TypeParams lhsTypeParams = lhsType.getTypeParams();
-
- // REDUCE - Rule
- if(!(rhsType instanceof PlaceholderType) && !(lhsType instanceof PlaceholderType)) {
- Set result = new HashSet<>();
-
- // f<...> = g<...> with f != g are not unifiable
- if(!rhsType.getName().equals(lhsType.getName()))
- return Optional.empty(); // conflict
- // f = f are not unifiable
- if(rhsTypeParams.size() != lhsTypeParams.size())
- return Optional.empty(); // conflict
- // f = g is not unifiable (cannot be f = f because erase rule would have been applied)
- //if(rhsTypeParams.size() == 0)
- //return Optional.empty();
-
- // Unpack the arguments
- for(int i = 0; i < rhsTypeParams.size(); i++)
- result.add(new UnifyPair(lhsTypeParams.get(i), rhsTypeParams.get(i), PairOperator.EQUALSDOT));
-
- termsList.remove(idx);
- termsList.addAll(result);
- continue;
- }
-
- // DELETE - Rule
- if(pair.getRhsType().equals(pair.getLhsType())) {
- termsList.remove(idx);
- continue;
- }
-
- // SWAP - Rule
- if(!(lhsType instanceof PlaceholderType) && (rhsType instanceof PlaceholderType)) {
- return Optional.empty(); // conflict
- }
-
- // OCCURS-CHECK
- //deleted
-
- // SUBST - Rule
- if(lhsType instanceof PlaceholderType) {
- mgu.add((PlaceholderType) lhsType, rhsType);
- termsList = termsList.stream().map(mgu::applyleft).collect(Collectors.toCollection(ArrayList::new));
- idx = idx+1 == termsList.size() ? 0 : idx+1;
- continue;
- }
-
- idx++;
- }
-
- return Optional.of(mgu);
- }
-}
+package de.dhbwstuttgart.typeinference.unify;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Optional;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+import de.dhbwstuttgart.typeinference.unify.interfaces.IMatch;
+import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
+import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType;
+import de.dhbwstuttgart.typeinference.unify.model.TypeParams;
+import de.dhbwstuttgart.typeinference.unify.model.Unifier;
+import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
+import de.dhbwstuttgart.typeinference.unify.model.UnifyType;
+
+/**
+ * Implementation of match derived from unification algorithm.
+ * @author Martin Pluemicke
+ */
+public class Match implements IMatch {
+
+ @Override
+ //A =. A ==> True
+ //A =. A ==> False
+ public Optional match(ArrayList termsList) {
+
+ // Start with the identity unifier. Substitutions will be added later.
+ Unifier mgu = Unifier.identity();
+
+ // Apply rules while possible
+ int idx = 0;
+ while(idx < termsList.size()) {
+ UnifyPair pair = termsList.get(idx);
+ UnifyType rhsType = pair.getRhsType();
+ UnifyType lhsType = pair.getLhsType();
+ TypeParams rhsTypeParams = rhsType.getTypeParams();
+ TypeParams lhsTypeParams = lhsType.getTypeParams();
+
+ // REDUCE - Rule
+ if(!(rhsType instanceof PlaceholderType) && !(lhsType instanceof PlaceholderType)) {
+ Set result = new HashSet<>();
+
+ // f<...> = g<...> with f != g are not unifiable
+ if(!rhsType.getName().equals(lhsType.getName()))
+ return Optional.empty(); // conflict
+ // f = f are not unifiable
+ if(rhsTypeParams.size() != lhsTypeParams.size())
+ return Optional.empty(); // conflict
+ // f = g is not unifiable (cannot be f = f because erase rule would have been applied)
+ //if(rhsTypeParams.size() == 0)
+ //return Optional.empty();
+
+ // Unpack the arguments
+ for(int i = 0; i < rhsTypeParams.size(); i++)
+ result.add(new UnifyPair(lhsTypeParams.get(i), rhsTypeParams.get(i), PairOperator.EQUALSDOT));
+
+ termsList.remove(idx);
+ termsList.addAll(result);
+ continue;
+ }
+
+ // DELETE - Rule
+ if(pair.getRhsType().equals(pair.getLhsType())) {
+ termsList.remove(idx);
+ continue;
+ }
+
+ // SWAP - Rule
+ if(!(lhsType instanceof PlaceholderType) && (rhsType instanceof PlaceholderType)) {
+ return Optional.empty(); // conflict
+ }
+
+ // OCCURS-CHECK
+ //deleted
+
+ // SUBST - Rule
+ if(lhsType instanceof PlaceholderType) {
+ mgu.add((PlaceholderType) lhsType, rhsType);
+ termsList = termsList.stream().map(mgu::applyleft).collect(Collectors.toCollection(ArrayList::new));
+ idx = idx+1 == termsList.size() ? 0 : idx+1;
+ continue;
+ }
+
+ idx++;
+ }
+
+ return Optional.of(mgu);
+ }
+}
diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/RuleSet.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/RuleSet.java
index da8998d2..a392a2fa 100644
--- a/src/main/java/de/dhbwstuttgart/typeinference/unify/RuleSet.java
+++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/RuleSet.java
@@ -1,1022 +1,1022 @@
-package de.dhbwstuttgart.typeinference.unify;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Optional;
-import java.util.Queue;
-import java.util.Set;
-import java.util.Stack;
-import java.util.function.Function;
-import java.util.stream.Collectors;
-
-import de.dhbwstuttgart.exceptions.DebugException;
-import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
-import de.dhbwstuttgart.typeinference.unify.interfaces.IRuleSet;
-import de.dhbwstuttgart.typeinference.unify.model.ExtendsType;
-import de.dhbwstuttgart.typeinference.unify.model.FunNType;
-import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
-import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType;
-import de.dhbwstuttgart.typeinference.unify.model.ReferenceType;
-import de.dhbwstuttgart.typeinference.unify.model.SuperType;
-import de.dhbwstuttgart.typeinference.unify.model.TypeParams;
-import de.dhbwstuttgart.typeinference.unify.model.Unifier;
-import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
-import de.dhbwstuttgart.typeinference.unify.model.UnifyType;
-import de.dhbwstuttgart.typeinference.unify.model.WildcardType;
-import de.dhbwstuttgart.typeinference.unify.distributeVariance;
-
-import java.io.FileWriter;
-import java.io.IOException;
-import java.io.Writer;
-
-/**
- * Implementation of the type inference rules.
- * @author Florian Steurer
- *
- */
-public class RuleSet implements IRuleSet{
-
- Writer logFile;
-
- public RuleSet() {
- super();
- }
-
- RuleSet(Writer logFile) {
- this.logFile = logFile;
- }
-
- @Override
- public Optional reduceUp(UnifyPair pair) {
- // Check if reduce up is applicable
- if(pair.getPairOp() != PairOperator.SMALLERDOT)
- return Optional.empty();
-
- UnifyType rhsType = pair.getRhsType();
- if(!(rhsType instanceof SuperType))
- return Optional.empty();
-
- UnifyType lhsType = pair.getLhsType();
- if(!(lhsType instanceof ReferenceType) && !(lhsType instanceof PlaceholderType))
- return Optional.empty();
-
- // Rule is applicable, unpack the SuperType
- return Optional.of(new UnifyPair(lhsType, ((SuperType) rhsType).getSuperedType(), PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair()));
- }
-
- @Override
- public Optional reduceLow(UnifyPair pair) {
- // Check if rule is applicable
- if(pair.getPairOp() != PairOperator.SMALLERDOT)
- return Optional.empty();
-
- UnifyType lhsType = pair.getLhsType();
- if(!(lhsType instanceof ExtendsType))
- return Optional.empty();
-
- UnifyType rhsType = pair.getRhsType();
- if(!(rhsType instanceof ReferenceType) && !(rhsType instanceof PlaceholderType))
- return Optional.empty();
-
- // Rule is applicable, unpack the ExtendsType
- return Optional.of(new UnifyPair(((ExtendsType) lhsType).getExtendedType(), rhsType, PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair()));
- }
-
- @Override
- public Optional reduceUpLow(UnifyPair pair) {
- // Check if rule is applicable
- if(pair.getPairOp() != PairOperator.SMALLERDOT)
- return Optional.empty();
-
- UnifyType lhsType = pair.getLhsType();
- if(!(lhsType instanceof ExtendsType))
- return Optional.empty();
-
- UnifyType rhsType = pair.getRhsType();
- if(!(rhsType instanceof SuperType))
- return Optional.empty();
-
- // Rule is applicable, unpack both sides
- return Optional.of(new UnifyPair(((ExtendsType) lhsType).getExtendedType(),((SuperType) rhsType).getSuperedType(), PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair()));
- }
-
- @Override
- public Optional> reduceExt(UnifyPair pair, IFiniteClosure fc) {
- if(pair.getPairOp() != PairOperator.SMALLERDOTWC)
- return Optional.empty();
-
- UnifyType x = pair.getLhsType();
- UnifyType sTypeX;
-
- if(x instanceof ReferenceType)
- sTypeX = x;
- else if(x instanceof ExtendsType)
- sTypeX = ((ExtendsType) x).getExtendedType();
- else
- return Optional.empty();
-
- UnifyType extY = pair.getRhsType();
-
- if(!(extY instanceof ExtendsType))
- return Optional.empty();
-
- if(x.getTypeParams().empty() || extY.getTypeParams().size() != x.getTypeParams().size())
- return Optional.empty();
-
- UnifyType xFromFc = fc.getLeftHandedType(sTypeX.getName()).orElse(null);
-
- if(xFromFc == null || !xFromFc.getTypeParams().arePlaceholders())
- return Optional.empty();
-
- if(x instanceof ExtendsType)
- xFromFc = new ExtendsType(xFromFc);
-
- UnifyType extYFromFc = fc.grArg(xFromFc, new HashSet<>()).stream().filter(t -> t.getName().equals(extY.getName())).filter(t -> t.getTypeParams().arePlaceholders()).findAny().orElse(null);
-
- if(extYFromFc == null || extYFromFc.getTypeParams() != xFromFc.getTypeParams())
- return Optional.empty();
-
- TypeParams extYParams = extY.getTypeParams();
- TypeParams xParams = x.getTypeParams();
-
- int[] pi = pi(xParams, extYParams);
-
- if(pi.length == 0)
- return Optional.empty();
-
- Set result = new HashSet<>();
-
- for(int rhsIdx = 0; rhsIdx < extYParams.size(); rhsIdx++)
- result.add(new UnifyPair(xParams.get(pi[rhsIdx]), extYParams.get(rhsIdx), PairOperator.SMALLERDOTWC, pair.getSubstitution(), pair.getBasePair()));
-
- return Optional.of(result);
- }
-
- @Override
- public Optional> reduceSup(UnifyPair pair, IFiniteClosure fc) {
- if(pair.getPairOp() != PairOperator.SMALLERDOTWC)
- return Optional.empty();
-
- UnifyType x = pair.getLhsType();
- UnifyType sTypeX;
-
- if(x instanceof ReferenceType)
- sTypeX = x;
- else if(x instanceof SuperType)
- sTypeX = ((SuperType) x).getSuperedType();
- else
- return Optional.empty();
-
- UnifyType supY = pair.getRhsType();
-
- if(!(supY instanceof SuperType))
- return Optional.empty();
-
- if(x.getTypeParams().empty() || supY.getTypeParams().size() != x.getTypeParams().size())
- return Optional.empty();
-
- UnifyType xFromFc = fc.getLeftHandedType(sTypeX.getName()).orElse(null);
-
- if(xFromFc == null || !xFromFc.getTypeParams().arePlaceholders())
- return Optional.empty();
-
- if(x instanceof SuperType)
- xFromFc = new SuperType(xFromFc);
-
- UnifyType supYFromFc = fc.grArg(xFromFc, new HashSet<>()).stream().filter(t -> t.getName().equals(supY.getName())).filter(t -> t.getTypeParams().arePlaceholders()).findAny().orElse(null);
-
- if(supYFromFc == null || supYFromFc.getTypeParams() != xFromFc.getTypeParams())
- return Optional.empty();
-
- TypeParams supYParams = supY.getTypeParams();
- TypeParams xParams = x.getTypeParams();
- Set result = new HashSet<>();
-
- int[] pi = pi(xParams, supYParams);
-
- if(pi.length == 0)
- return Optional.empty();
-
- for(int rhsIdx = 0; rhsIdx < supYParams.size(); rhsIdx++)
- result.add(new UnifyPair(supYParams.get(rhsIdx), xParams.get(pi[rhsIdx]), PairOperator.SMALLERDOTWC, pair.getSubstitution(), pair.getBasePair()));
-
- return Optional.of(result);
- }
-
- @Override
- public Optional> reduceEq(UnifyPair pair) {
- if(pair.getPairOp() != PairOperator.SMALLERDOTWC)
- return Optional.empty();
-
- UnifyType lhsType = pair.getLhsType();
- if(lhsType instanceof PlaceholderType || lhsType.getTypeParams().empty())
- return Optional.empty();
-
- UnifyType rhsType = pair.getRhsType();
-
- if(!rhsType.getName().equals(lhsType.getName()))
- return Optional.empty();
-
- if(rhsType instanceof PlaceholderType || lhsType instanceof PlaceholderType || rhsType.getTypeParams().empty())
- return Optional.empty();
-
- if(rhsType.getTypeParams().size() != lhsType.getTypeParams().size())
- return Optional.empty();
-
- // Keine Permutation wie im Paper nötig
- Set result = new HashSet<>();
- TypeParams lhsTypeParams = lhsType.getTypeParams();
- TypeParams rhsTypeParams = rhsType.getTypeParams();
-
- for(int i = 0; i < lhsTypeParams.size(); i++)
- result.add(new UnifyPair(lhsTypeParams.get(i), rhsTypeParams.get(i), PairOperator.EQUALSDOT, pair.getSubstitution(), pair.getBasePair()));
-
- return Optional.of(result);
- }
-
- @Override
- public Optional> reduce1(UnifyPair pair, IFiniteClosure fc) {
- if(pair.getPairOp() != PairOperator.SMALLERDOT)
- return Optional.empty();
-
- UnifyType c = pair.getLhsType();
- if(!(c instanceof ReferenceType))
- return Optional.empty();
-
- UnifyType d = pair.getRhsType();
- if(!(d instanceof ReferenceType))
- return Optional.empty();
-
- ReferenceType lhsSType = (ReferenceType) c;
- ReferenceType rhsSType = (ReferenceType) d;
-
- //try {
- // logFile.write("PAIR Rules: " + pair + "\n");
- // logFile.flush();
- //}
- //catch (IOException e) { }
-
- if(lhsSType.getTypeParams().empty() || lhsSType.getTypeParams().size() != rhsSType.getTypeParams().size())
- return Optional.empty();
-
- UnifyType cFromFc = fc.getLeftHandedType(c.getName()).orElse(null);
- //2018-02-23: liefert Vector>: Das kann nicht sein.
-
- //NOCHMAL UEBERPRUEFEN
- //PL 18-02-09 Eingfuegt Anfang
- //C und D koennen auch gleich sein.
- if (c.getName().equals(d.getName())) {
- Set result = new HashSet<>();
- TypeParams rhsTypeParams = d.getTypeParams();
- TypeParams lhsTypeParams = c.getTypeParams();
- for(int rhsIdx = 0; rhsIdx < c.getTypeParams().size(); rhsIdx++)
- result.add(new UnifyPair(lhsTypeParams.get(rhsIdx), rhsTypeParams.get(rhsIdx), PairOperator.SMALLERDOTWC, pair.getSubstitution(), pair.getBasePair()));
-
- return Optional.of(result);
- }
- //PL 18-02-09 Eingfuegt ENDE
-
- //try {
- // logFile.write("cFromFc: " + cFromFc);
- // logFile.flush();
- //}
- //catch (IOException e) { }
-
- if(cFromFc == null || !cFromFc.getTypeParams().arePlaceholders())
- return Optional.empty();
-
- UnifyType dFromFc = fc.getAncestors(cFromFc).stream().filter(x -> x.getName().equals(d.getName())).findAny().orElse(null);
-
- //try {
- // logFile.write("cFromFc: " + cFromFc);
- // logFile.flush();
- //}
- //catch (IOException e) { }
-
- if(dFromFc == null || !dFromFc.getTypeParams().arePlaceholders() || dFromFc.getTypeParams().size() != cFromFc.getTypeParams().size())
- return Optional.empty();
- //System.out.println("cFromFc: " + cFromFc);
- //System.out.println("dFromFc: " + dFromFc);
- int[] pi = pi(cFromFc.getTypeParams(), dFromFc.getTypeParams());
-
- if(pi.length == 0)
- return Optional.empty();
-
- TypeParams rhsTypeParams = d.getTypeParams();
- TypeParams lhsTypeParams = c.getTypeParams();
- Set result = new HashSet<>();
-
- for(int rhsIdx = 0; rhsIdx < rhsTypeParams.size(); rhsIdx++)
- result.add(new UnifyPair(lhsTypeParams.get(pi[rhsIdx]), rhsTypeParams.get(rhsIdx), PairOperator.SMALLERDOTWC, pair.getSubstitution(), pair.getBasePair()));
-
- return Optional.of(result);
- }
-
- @Override
- public Optional> reduce2(UnifyPair pair) {
- if(pair.getPairOp() != PairOperator.EQUALSDOT)
- return Optional.empty();
-
- UnifyType lhsType = pair.getLhsType();
- ReferenceType lhsSType;
- UnifyType rhsType = pair.getRhsType();
- ReferenceType rhsSType;
-
- if ((lhsType instanceof ReferenceType) && (rhsType instanceof ReferenceType)) {
- lhsSType = (ReferenceType) lhsType;
- rhsSType = (ReferenceType) rhsType;
- }
- else if (((lhsType instanceof ExtendsType) && (rhsType instanceof ExtendsType))
- || ((lhsType instanceof SuperType) && (rhsType instanceof SuperType))) {
- UnifyType lhsSTypeRaw = ((WildcardType) lhsType).getWildcardedType();
- UnifyType rhsSTypeRaw = ((WildcardType) rhsType).getWildcardedType();
- if ((lhsSTypeRaw instanceof ReferenceType) && (rhsSTypeRaw instanceof ReferenceType)) {
- lhsSType = (ReferenceType) lhsSTypeRaw;
- rhsSType = (ReferenceType) rhsSTypeRaw;
- }
- else
- return Optional.empty();
- }
- else
- return Optional.empty();
-
- if(lhsSType.getTypeParams().empty())
- return Optional.empty();
-
- /* PL 2018-01-22 in obere Teil integriert
- UnifyType rhsType = pair.getRhsType();
- ReferenceType rhsSType;
-
- if(rhsType instanceof ReferenceType)
- rhsSType = (ReferenceType) rhsType;
- else if(rhsType instanceof WildcardType) {
- UnifyType rhsSTypeRaw = ((WildcardType) rhsType).getWildcardedType();
- if(rhsSTypeRaw instanceof ReferenceType)
- rhsSType = (ReferenceType) rhsSTypeRaw;
- else
- return Optional.empty();
- }
- else
- return Optional.empty();
- */
-
- if(!rhsSType.getName().equals(lhsSType.getName()))
- return Optional.empty();
-
- 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();
-
- Set result = new HashSet<>();
-
- TypeParams rhsTypeParams = rhsSType.getTypeParams();
- TypeParams lhsTypeParams = lhsSType.getTypeParams();
- for(int i = 0; i < rhsTypeParams.size(); i++)
- result.add(new UnifyPair(lhsTypeParams.get(i), rhsTypeParams.get(i), PairOperator.EQUALSDOT, pair.getSubstitution(), pair.getBasePair()));
-
- return Optional.of(result);
- }
-
- @Override
- public boolean erase1(UnifyPair pair, IFiniteClosure fc) {
- if((pair.getPairOp() != PairOperator.SMALLERDOT) && (pair.getPairOp() != PairOperator.SMALLERNEQDOT))
- return false;
-
- if (pair.getPairOp() == PairOperator.SMALLERNEQDOT) {
- UnifyType lhs = pair.getLhsType();
- UnifyType rhs = pair.getRhsType();
- if (lhs instanceof WildcardType) {
- lhs = ((WildcardType)lhs).getWildcardedType();
- }
- if (rhs instanceof WildcardType) {
- rhs = ((WildcardType)rhs).getWildcardedType();
- }
-
- if (lhs.equals(rhs)){
- return false;
- }
- }
-
- UnifyType lhsType = pair.getLhsType();
- if(!(lhsType instanceof ReferenceType) && !(lhsType instanceof PlaceholderType))
- return false;
-
- UnifyType rhsType = pair.getRhsType();
- if(!(rhsType instanceof ReferenceType) && !(rhsType instanceof PlaceholderType))
- return false;
-
- return fc.greater(lhsType, new HashSet<>()).contains(rhsType);
- }
-
- @Override
- public boolean erase2(UnifyPair pair, IFiniteClosure fc) {
- if(pair.getPairOp() != PairOperator.SMALLERDOTWC)
- return false;
-
- UnifyType lhsType = pair.getLhsType();
- UnifyType rhsType = pair.getRhsType();
-
- return fc.grArg(lhsType, new HashSet<>()).contains(rhsType);
- }
-
- @Override
- public boolean erase3(UnifyPair pair) {
- if(pair.getPairOp() != PairOperator.EQUALSDOT)
- return false;
-
- return pair.getLhsType().equals(pair.getRhsType());
- }
-
- @Override
- public Optional swap(UnifyPair pair) {
- if(pair.getPairOp() != PairOperator.EQUALSDOT)
- return Optional.empty();
-
- if(pair.getLhsType() instanceof PlaceholderType)
- return Optional.empty();
-
- if(!(pair.getRhsType() instanceof PlaceholderType))
- return Optional.empty();
-
- return Optional.of(new UnifyPair(pair.getRhsType(), pair.getLhsType(), PairOperator.EQUALSDOT, pair.getSubstitution(), pair.getBasePair()));
- }
-
- @Override
- public Optional adapt(UnifyPair pair, IFiniteClosure fc) {
- if(pair.getPairOp() != PairOperator.SMALLERDOT)
- return Optional.empty();
-
- UnifyType typeD = pair.getLhsType();
- if(!(typeD instanceof ReferenceType))
- return Optional.empty();
-
- UnifyType typeDs = pair.getRhsType();
- if(!(typeDs instanceof ReferenceType))
- return Optional.empty();
-
- /*if(typeD.getTypeParams().size() == 0 || typeDs.getTypeParams().size() == 0)
- return Optional.empty();*/
-
- if(typeD.getName().equals(typeDs.getName()))
- return Optional.empty();
-
-
- Optional opt = fc.getLeftHandedType(typeD.getName());
- if(!opt.isPresent())
- return Optional.empty();
-
- // The generic Version of Type D (D)
- UnifyType typeDgen = opt.get();
-
- // Actually greater+ because the types are ensured to have different names
- Set greater = fc.getAncestors(typeDgen);
- opt = greater.stream().filter(x -> x.getName().equals(typeDs.getName())).findAny();
-
- if(!opt.isPresent())
- return Optional.empty();
-
- UnifyType newLhs = opt.get();
-
- TypeParams typeDParams = typeD.getTypeParams();
- TypeParams typeDgenParams = typeDgen.getTypeParams();
-
- //System.out.println("Pair: " +pair);
- //System.out.println("typeD: " +typeD);
- //System.out.println("typeDParams: " +typeDParams);
- //System.out.println("typeDgen: " +typeD);
- //System.out.println("typeDgenParams: " +typeDgenParams);
- Unifier unif = Unifier.identity();
- for(int i = 0; i < typeDParams.size(); i++) {
- //System.out.println("ADAPT" +typeDgenParams);
- if (typeDgenParams.get(i) instanceof PlaceholderType)
- unif.add((PlaceholderType) typeDgenParams.get(i), typeDParams.get(i));
- else System.out.println("ERROR");
- }
- return Optional.of(new UnifyPair(unif.apply(newLhs), typeDs, PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair()));
- }
-
- @Override
- public Optional adaptExt(UnifyPair pair, IFiniteClosure fc) {
- if(pair.getPairOp() != PairOperator.SMALLERDOTWC)
- return Optional.empty();
-
- UnifyType typeD = pair.getLhsType();
- if(!(typeD instanceof ReferenceType) && !(typeD instanceof ExtendsType))
- return Optional.empty();
-
- UnifyType typeExtDs = pair.getRhsType();
- if(!(typeExtDs instanceof ExtendsType))
- return Optional.empty();
-
- if(typeD.getTypeParams().size() == 0 || typeExtDs.getTypeParams().size() == 0)
- return Optional.empty();
-
- UnifyType typeDgen;
- if(typeD instanceof ReferenceType)
- typeDgen = fc.getLeftHandedType(typeD.getName()).orElse(null);
- else {
- Optional opt = fc.getLeftHandedType(((ExtendsType) typeD).getExtendedType().getName());
- typeDgen = opt.isPresent() ? new ExtendsType(opt.get()) : null;
- }
-
- if(typeDgen == null)
- return Optional.empty();
-
- Set grArg = fc.grArg(typeDgen, new HashSet<>());
-
- Optional opt = grArg.stream().filter(x -> x.getName().equals(typeExtDs.getName())).findAny();
-
- if(!opt.isPresent())
- return Optional.empty();
-
- UnifyType newLhs = ((ExtendsType) opt.get()).getExtendedType();
-
- TypeParams typeDParams = typeD.getTypeParams();
- TypeParams typeDgenParams = typeDgen.getTypeParams();
-
- Unifier unif = new Unifier((PlaceholderType) typeDgenParams.get(0), typeDParams.get(0));
- for(int i = 1; i < typeDParams.size(); i++)
- unif.add((PlaceholderType) typeDgenParams.get(i), typeDParams.get(i));
-
- return Optional.of(new UnifyPair(unif.apply(newLhs), typeExtDs, PairOperator.SMALLERDOTWC, pair.getSubstitution(), pair.getBasePair()));
- }
-
- @Override
- public Optional adaptSup(UnifyPair pair, IFiniteClosure fc) {
- if(pair.getPairOp() != PairOperator.SMALLERDOTWC)
- return Optional.empty();
-
- UnifyType typeDs = pair.getLhsType();
- if(!(typeDs instanceof ReferenceType) && !(typeDs instanceof SuperType))
- return Optional.empty();
-
- UnifyType typeSupD = pair.getRhsType();
- if(!(typeSupD instanceof SuperType))
- return Optional.empty();
-
- if(typeDs.getTypeParams().size() == 0 || typeSupD.getTypeParams().size() == 0)
- return Optional.empty();
-
-
- Optional opt = fc.getLeftHandedType(((SuperType) typeSupD).getSuperedType().getName());
-
- if(!opt.isPresent())
- return Optional.empty();
-
- UnifyType typeDgen = opt.get();
- UnifyType typeSupDgen = new SuperType(typeDgen);
-
- // Use of smArg instead of grArg because
- // a in grArg(b) => b in smArg(a)
- Set smArg = fc.smArg(typeSupDgen, new HashSet<>());
- opt = smArg.stream().filter(x -> x.getName().equals(typeDs.getName())).findAny();
-
- if(!opt.isPresent())
- return Optional.empty();
-
- // New RHS
- UnifyType newRhs = null;
- if(typeDs instanceof ReferenceType)
- newRhs = new ExtendsType(typeDs);
- else
- newRhs = new ExtendsType(((SuperType) typeDs).getSuperedType());
-
- // New LHS
- UnifyType newLhs = opt.get();
- TypeParams typeDParams = typeSupD.getTypeParams();
- TypeParams typeSupDsgenParams = typeSupDgen.getTypeParams();
-
- Unifier unif = new Unifier((PlaceholderType) typeSupDsgenParams.get(0), typeDParams.get(0));
- for(int i = 1; i < typeDParams.size(); i++)
- unif.add((PlaceholderType) typeSupDsgenParams.get(i), typeDParams.get(i));
-
- return Optional.of(new UnifyPair(unif.apply(newLhs), newRhs, PairOperator.SMALLERDOTWC, pair.getSubstitution(), pair.getBasePair()));
- }
-
- /**
- * Finds the permutation pi of the type arguments of two types based on the finite closure
- * @param cArgs The type which arguments are permuted
- * @param dArgs The other type
- * @return An array containing the values of pi for every type argument of C or an empty array if the search failed.
- */
- private int[] pi(TypeParams cArgs, TypeParams dArgs) {
- if(!(cArgs.size()==dArgs.size()))throw new DebugException("Fehler in Unifizierung");
-
- int[] permutation = new int[dArgs.size()];
-
- boolean succ = true;
- for (int dArgIdx = 0; dArgIdx < dArgs.size() && succ; dArgIdx++) {
- UnifyType dArg = dArgs.get(dArgIdx);
- succ = false;
- for (int pi = 0; pi < cArgs.size(); pi++)
- if (cArgs.get(pi).getName().equals(dArg.getName())) {
- permutation[dArgIdx] = pi;
- succ = true;
- break;
- }
- }
-
- return succ ? permutation : new int[0];
- }
-
- public Optional> subst(Set pairs) {
- return subst(pairs, new ArrayList<>());
- }
-
- @Override
- public Optional> subst(Set pairs, List>> oderConstraints) {
- HashMap typeMap = new HashMap<>();
-
- Stack occuringTypes = new Stack<>();
-
- for(UnifyPair pair : pairs) {
- occuringTypes.push(pair.getLhsType());
- occuringTypes.push(pair.getRhsType());
- }
-
- while(!occuringTypes.isEmpty()) {
- UnifyType t1 = occuringTypes.pop();
- if(!typeMap.containsKey(t1))
- typeMap.put(t1, 0);
- typeMap.put(t1, typeMap.get(t1)+1);
-
- if(t1 instanceof ExtendsType)
- occuringTypes.push(((ExtendsType) t1).getExtendedType());
- if(t1 instanceof SuperType)
- occuringTypes.push(((SuperType) t1).getSuperedType());
- else
- t1.getTypeParams().forEach(x -> occuringTypes.push(x));
- }
-
- Queue result1 = new LinkedList(pairs);
- ArrayList result = new ArrayList();
- boolean applied = false;
-
- while(!result1.isEmpty()) {
- UnifyPair pair = result1.poll();
- PlaceholderType lhsType = null;
- UnifyType rhsType;
-
- if(pair.getPairOp() == PairOperator.EQUALSDOT
- && pair.getLhsType() instanceof PlaceholderType)
- lhsType = (PlaceholderType) pair.getLhsType();
- rhsType = pair.getRhsType(); //PL eingefuegt 2017-09-29 statt !((rhsType = pair.getRhsType()) instanceof PlaceholderType)
- if(lhsType != null
- //&& !((rhsType = pair.getRhsType()) instanceof PlaceholderType) //PL geloescht am 2017-09-29 Begründung: auch Typvariablen muessen ersetzt werden.
- && typeMap.get(lhsType) > 1 // The type occurs in more pairs in the set than just the recent pair.
- && !rhsType.getTypeParams().occurs(lhsType)
- && !((rhsType instanceof WildcardType) && ((WildcardType)rhsType).getWildcardedType().equals(lhsType))) //PL eigefuegt 2018-02-18
- {
- Unifier uni = new Unifier(lhsType, rhsType);
- result = result.stream().map(x -> uni.apply(pair,x)).collect(Collectors.toCollection(ArrayList::new));
- result1 = result1.stream().map(x -> uni.apply(pair,x)).collect(Collectors.toCollection(LinkedList::new));
-
- Function super Set,? extends HashSet> applyUni = b -> b.stream().map(
- x -> uni.apply(pair,x)).collect(Collectors.toCollection(HashSet::new));
- List>> oderConstraintsRet = new ArrayList<>();
- for(Set> oc : oderConstraints) {
- //Set> ocRet = new HashSet<>();
- //for(Set cs : oc) {
- Set> csRet = oc.stream().map(applyUni).collect(Collectors.toCollection(HashSet::new));
- oderConstraintsRet.add(csRet);
- //}
- }
- oderConstraints.replaceAll(oc -> oc.stream().map(applyUni).collect(Collectors.toCollection(HashSet::new)));
- /*
- oderConstraints = oderConstraints.stream().map(
- a -> a.stream().map(applyUni
- //b -> b.stream().map(
- // x -> uni.apply(pair,x)).collect(Collectors.toCollection(HashSet::new) )
- ).collect(Collectors.toCollection(HashSet::new))
- ).collect(Collectors.toList(ArrayList::new));
- }
- */
- applied = true;
- }
- result.add(pair);
- }
-
- return applied ? Optional.of(new HashSet<>(result)) : Optional.empty();
- }
-
- @Override
- public Optional reduceWildcardLow(UnifyPair pair) {
- if(pair.getPairOp() != PairOperator.SMALLERDOTWC)
- return Optional.empty();
-
- UnifyType lhsType = pair.getLhsType();
- UnifyType rhsType = pair.getRhsType();
- if(!(lhsType instanceof ExtendsType) || !(rhsType instanceof ExtendsType))
- return Optional.empty();
-
- return Optional.of(new UnifyPair(((ExtendsType) lhsType).getExtendedType(), ((ExtendsType) rhsType).getExtendedType(), PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair()));
- }
-
- @Override
- public Optional reduceWildcardLowRight(UnifyPair pair) {
- if(pair.getPairOp() != PairOperator.SMALLERDOTWC)
- return Optional.empty();
-
- UnifyType lhsType = pair.getLhsType();
- UnifyType rhsType = pair.getRhsType();
- if(!(lhsType instanceof ReferenceType) || !(rhsType instanceof ExtendsType))
- return Optional.empty();
-
- return Optional.of(new UnifyPair(lhsType, ((ExtendsType) rhsType).getExtendedType(), PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair()));
- }
-
- @Override
- public Optional reduceWildcardUp(UnifyPair pair) {
- if(pair.getPairOp() != PairOperator.SMALLERDOTWC)
- return Optional.empty();
-
- UnifyType lhsType = pair.getLhsType();
- UnifyType rhsType = pair.getRhsType();
- if(!(lhsType instanceof SuperType) || !(rhsType instanceof SuperType))
- return Optional.empty();
-
- return Optional.of(new UnifyPair(((SuperType) rhsType).getSuperedType(), ((SuperType) lhsType).getSuperedType(), PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair()));
- }
-
- @Override
- public Optional reduceWildcardUpRight(UnifyPair pair) {
- if(pair.getPairOp() != PairOperator.SMALLERDOTWC)
- return Optional.empty();
-
- UnifyType lhsType = pair.getLhsType();
- UnifyType rhsType = pair.getRhsType();
- if(!(lhsType instanceof ReferenceType) || !(rhsType instanceof SuperType))
- return Optional.empty();
-
- return Optional.of(new UnifyPair(((SuperType) rhsType).getSuperedType(), lhsType, PairOperator.SMALLERDOTWC, pair.getSubstitution(), pair.getBasePair()));
- }
-
- /* PL 2018-03-06 auskommentiert sind mutmaßlich falsch
- * vgl. JAVA_BSP/Wildcard6.java
- @Override
- public Optional reduceWildcardLowUp(UnifyPair pair) {
- if(pair.getPairOp() != PairOperator.SMALLERDOTWC)
- return Optional.empty();
-
- UnifyType lhsType = pair.getLhsType();
- UnifyType rhsType = pair.getRhsType();
- if(!(lhsType instanceof ExtendsType) || !(rhsType instanceof SuperType))
- return Optional.empty();
-
- return Optional.of(new UnifyPair(((ExtendsType) lhsType).getExtendedType(), ((SuperType) rhsType).getSuperedType(), PairOperator.EQUALSDOT));
- }
-
- @Override
- public Optional reduceWildcardUpLow(UnifyPair pair) {
- if(pair.getPairOp() != PairOperator.SMALLERDOTWC)
- return Optional.empty();
-
- UnifyType lhsType = pair.getLhsType();
- UnifyType rhsType = pair.getRhsType();
- if(!(lhsType instanceof SuperType) || !(rhsType instanceof ExtendsType))
- return Optional.empty();
-
- return Optional.of(new UnifyPair(((SuperType) lhsType).getSuperedType(), ((ExtendsType) rhsType).getExtendedType(), PairOperator.EQUALSDOT));
- }
-
-
- @Override
- public Optional reduceWildcardLeft(UnifyPair pair) {
- if(pair.getPairOp() != PairOperator.SMALLERDOTWC)
- return Optional.empty();
-
- UnifyType rhsType = pair.getRhsType();
- if(!(rhsType instanceof ReferenceType))
- return Optional.empty();
-
- UnifyType lhsType = pair.getLhsType();
-
- if(lhsType instanceof WildcardType)
- return Optional.of(new UnifyPair(((WildcardType) lhsType).getWildcardedType(), rhsType, PairOperator.EQUALSDOT));
-
- return Optional.empty();
- }
- */
- @Override
- public Optional> reduceFunN(UnifyPair pair) {
- if((pair.getPairOp() != PairOperator.SMALLERDOT)
- && (pair.getPairOp() != PairOperator.EQUALSDOT)) //PL 2017-10-03 hinzugefuegt
- //da Regel auch fuer EQUALSDOT anwendbar
- //TODO: fuer allen anderen Relationen noch pruefen
- return Optional.empty();
-
- UnifyType lhsType = pair.getLhsType();
- UnifyType rhsType = pair.getRhsType();
-
- if(!(lhsType instanceof FunNType) || !(rhsType instanceof FunNType))
- return Optional.empty();
-
- FunNType funNLhsType = (FunNType) lhsType;
- FunNType funNRhsType = (FunNType) rhsType;
-
- if(funNLhsType.getN() != funNRhsType.getN())
- return Optional.empty();
-
- Set result = new HashSet();
- if (pair.getPairOp() == PairOperator.SMALLERDOT) {
- result.add(new UnifyPair(funNLhsType.getTypeParams().get(funNLhsType.getTypeParams().size()-1), funNRhsType.getTypeParams().get(funNRhsType.getTypeParams().size()-1), PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair()));
- for(int i = 0; i < funNLhsType.getTypeParams().size()-1; i++) {
- result.add(new UnifyPair(funNRhsType.getTypeParams().get(i), funNLhsType.getTypeParams().get(i), PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair()));
- }
- }
- else {// pair.getPairOp() == PairOperator.EQUALDOT
- result.add(new UnifyPair(funNLhsType.getTypeParams().get(funNLhsType.getTypeParams().size()-1), funNRhsType.getTypeParams().get(funNRhsType.getTypeParams().size()-1), PairOperator.EQUALSDOT, pair.getSubstitution(), pair.getBasePair()));
- for(int i = 0; i < funNLhsType.getTypeParams().size()-1; i++) {
- result.add(new UnifyPair(funNRhsType.getTypeParams().get(i), funNLhsType.getTypeParams().get(i), PairOperator.EQUALSDOT, pair.getSubstitution(), pair.getBasePair()));
- }
- }
- result.stream().forEach(x -> { UnifyType l = x.getLhsType();
- if (l instanceof PlaceholderType) { ((PlaceholderType)l).disableWildcardtable(); }
- UnifyType r = x.getRhsType();
- if (r instanceof PlaceholderType) { ((PlaceholderType)r).disableWildcardtable(); }
- } );
- try {
- logFile.write("FUNgreater: " + pair + "\n");
- logFile.write("FUNred: " + result + "\n");
- logFile.flush();
- }
- catch (IOException e) {
- System.out.println("logFile-Error");
- }
- return Optional.of(result);
- }
-
-
- @Override
- public Optional> greaterFunN(UnifyPair pair) {
- if(pair.getPairOp() != PairOperator.SMALLERDOT)
- return Optional.empty();
-
- UnifyType lhsType = pair.getLhsType();
- UnifyType rhsType = pair.getRhsType();
-
- if(!(lhsType instanceof FunNType) || !(rhsType instanceof PlaceholderType))
- return Optional.empty();
-
- FunNType funNLhsType = (FunNType) lhsType;
-
- Set result = new HashSet();
-
- Integer variance = ((PlaceholderType)rhsType).getVariance();
- Integer inversVariance = distributeVariance.inverseVariance(variance);
-
- UnifyType[] freshPlaceholders = new UnifyType[funNLhsType.getTypeParams().size()];
- for(int i = 0; i < freshPlaceholders.length-1; i++) {
- freshPlaceholders[i] = PlaceholderType.freshPlaceholder();
- ((PlaceholderType)freshPlaceholders[i]).setVariance(inversVariance);
- }
- freshPlaceholders[freshPlaceholders.length-1] = PlaceholderType.freshPlaceholder();
- ((PlaceholderType)freshPlaceholders[freshPlaceholders.length-1]).setVariance(variance);
- result.add(new UnifyPair(funNLhsType.getTypeParams().get(funNLhsType.getTypeParams().size()-1), freshPlaceholders[funNLhsType.getTypeParams().size()-1], PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair()));
-
- for(int i = 0; i < funNLhsType.getTypeParams().size()-1; i++) {
- result.add(new UnifyPair(freshPlaceholders[i], funNLhsType.getTypeParams().get(i), PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair()));
- }
-
- result.add(new UnifyPair(rhsType, funNLhsType.setTypeParams(new TypeParams(freshPlaceholders)), PairOperator.EQUALSDOT, pair.getSubstitution(), pair.getBasePair()));
-
- result.stream().forEach(x -> { UnifyType l = x.getLhsType();
- if (l instanceof PlaceholderType) { ((PlaceholderType)l).disableWildcardtable(); }
- UnifyType r = x.getRhsType();
- if (r instanceof PlaceholderType) { ((PlaceholderType)r).disableWildcardtable(); }
- } );
- try {
- logFile.write("FUNgreater: " + pair + "\n");
- logFile.write("FUNgreater: " + result + "\n");
- logFile.flush();
- }
- catch (IOException e) {
- System.out.println("lofFile-Error");
- }
- return Optional.of(result);
- }
-
- @Override
- public Optional> smallerFunN(UnifyPair pair) {
- if(pair.getPairOp() != PairOperator.SMALLERDOT)
- return Optional.empty();
-
- UnifyType lhsType = pair.getLhsType();
- UnifyType rhsType = pair.getRhsType();
-
- if(!(lhsType instanceof PlaceholderType) || !(rhsType instanceof FunNType))
- return Optional.empty();
-
- FunNType funNRhsType = (FunNType) rhsType;
-
- Set result = new HashSet();
-
- Integer variance = ((PlaceholderType)lhsType).getVariance();
- Integer inversVariance = distributeVariance.inverseVariance(variance);
-
- UnifyType[] freshPlaceholders = new UnifyType[funNRhsType.getTypeParams().size()];
- for(int i = 0; i < freshPlaceholders.length-1; i++) {
- freshPlaceholders[i] = PlaceholderType.freshPlaceholder();
- ((PlaceholderType)freshPlaceholders[i]).setVariance(inversVariance);
- }
- freshPlaceholders[freshPlaceholders.length-1] = PlaceholderType.freshPlaceholder();
- ((PlaceholderType)freshPlaceholders[freshPlaceholders.length-1]).setVariance(variance);
-
- result.add(new UnifyPair(freshPlaceholders[funNRhsType.getTypeParams().size()-1], funNRhsType.getTypeParams().get(funNRhsType.getTypeParams().size()-1), PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair()));
-
- for(int i = 0; i < funNRhsType.getTypeParams().size()-1; i++) {
- result.add(new UnifyPair(funNRhsType.getTypeParams().get(i), freshPlaceholders[i], PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair()));
- }
-
- result.add(new UnifyPair(lhsType, funNRhsType.setTypeParams(new TypeParams(freshPlaceholders)), PairOperator.EQUALSDOT, pair.getSubstitution(), pair.getBasePair()));
-
- result.stream().forEach(x -> { UnifyType l = x.getLhsType();
- if (l instanceof PlaceholderType) { ((PlaceholderType)l).disableWildcardtable(); }
- UnifyType r = x.getRhsType();
- if (r instanceof PlaceholderType) { ((PlaceholderType)r).disableWildcardtable(); }
- } );
- try {
- logFile.write("FUNgreater: " + pair + "\n");
- logFile.write("FUNsmaller: " + result + "\n");
- logFile.flush();
- }
- catch (IOException e) {
- System.out.println("lofFile-Error");
- }
- return Optional.of(result);
- }
-
- @Override
- public Optional reduceTph(UnifyPair pair) {
- if(pair.getPairOp() != PairOperator.SMALLERDOTWC)
- return Optional.empty();
-
- UnifyType lhsType = pair.getLhsType();
- UnifyType rhsType = pair.getRhsType();
- if(!(lhsType instanceof PlaceholderType) || !(rhsType instanceof ReferenceType))
- return Optional.empty();
-
- return Optional.of(new UnifyPair(lhsType, rhsType, PairOperator.EQUALSDOT, pair.getSubstitution(), pair.getBasePair()));
- }
-
- @Override
- public Optional> reduceTphExt(UnifyPair pair) {
- if(pair.getPairOp() != PairOperator.SMALLERDOTWC)
- return Optional.empty();
-
- UnifyType lhsType = pair.getLhsType();
- UnifyType rhsType = pair.getRhsType();
- if(!(lhsType instanceof ExtendsType) || !(rhsType instanceof PlaceholderType))
- return Optional.empty();
-
- UnifyType extendedType = ((ExtendsType)lhsType).getExtendedType();
-
- if (extendedType.equals(rhsType)) return Optional.empty(); //PL 2019-02-18 eingefügt ? extends a <.? a
-
- boolean isGen = extendedType instanceof PlaceholderType && !((PlaceholderType) extendedType).isGenerated();
-
- Set result = new HashSet<>();
- if(isGen)
- result.add(new UnifyPair(rhsType, lhsType, PairOperator.EQUALSDOT, pair.getSubstitution(), pair.getBasePair()));
- else {
- UnifyType freshTph = PlaceholderType.freshPlaceholder();
- result.add(new UnifyPair(rhsType, new ExtendsType(freshTph), PairOperator.EQUALSDOT, pair.getSubstitution(), pair.getBasePair()));
- result.add(new UnifyPair(extendedType, freshTph, PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair()));
- }
-
- return Optional.of(result);
- }
-
- @Override
- public Optional> reduceTphSup(UnifyPair pair) {
- if(pair.getPairOp() != PairOperator.SMALLERDOTWC)
- return Optional.empty();
-
- UnifyType lhsType = pair.getLhsType();
- UnifyType rhsType = pair.getRhsType();
- if(!(lhsType instanceof SuperType) || !(rhsType instanceof PlaceholderType))
- return Optional.empty();
-
- UnifyType superedType = ((SuperType)lhsType).getSuperedType();
-
- if (superedType.equals(rhsType)) return Optional.empty(); //PL 2019-02-18 eingefügt ? super a <.? a
-
- boolean isGen = superedType instanceof PlaceholderType && !((PlaceholderType) superedType).isGenerated();
-
- Set result = new HashSet<>();
- if(isGen)
- result.add(new UnifyPair(rhsType, lhsType, PairOperator.EQUALSDOT, pair.getSubstitution(), pair.getBasePair()));
- else {
- UnifyType freshTph = PlaceholderType.freshPlaceholder();
- result.add(new UnifyPair(rhsType, new SuperType(freshTph), PairOperator.EQUALSDOT, pair.getSubstitution(), pair.getBasePair()));
- Set fBounded = pair.getfBounded();
- fBounded.add(lhsType);
- result.add(new UnifyPair(freshTph, superedType, PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair(), fBounded));
- }
-
- return Optional.of(result);
- }
-}
+package de.dhbwstuttgart.typeinference.unify;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Optional;
+import java.util.Queue;
+import java.util.Set;
+import java.util.Stack;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+
+import de.dhbwstuttgart.exceptions.DebugException;
+import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
+import de.dhbwstuttgart.typeinference.unify.interfaces.IRuleSet;
+import de.dhbwstuttgart.typeinference.unify.model.ExtendsType;
+import de.dhbwstuttgart.typeinference.unify.model.FunNType;
+import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
+import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType;
+import de.dhbwstuttgart.typeinference.unify.model.ReferenceType;
+import de.dhbwstuttgart.typeinference.unify.model.SuperType;
+import de.dhbwstuttgart.typeinference.unify.model.TypeParams;
+import de.dhbwstuttgart.typeinference.unify.model.Unifier;
+import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
+import de.dhbwstuttgart.typeinference.unify.model.UnifyType;
+import de.dhbwstuttgart.typeinference.unify.model.WildcardType;
+import de.dhbwstuttgart.typeinference.unify.distributeVariance;
+
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.Writer;
+
+/**
+ * Implementation of the type inference rules.
+ * @author Florian Steurer
+ *
+ */
+public class RuleSet implements IRuleSet{
+
+ Writer logFile;
+
+ public RuleSet() {
+ super();
+ }
+
+ RuleSet(Writer logFile) {
+ this.logFile = logFile;
+ }
+
+ @Override
+ public Optional reduceUp(UnifyPair pair) {
+ // Check if reduce up is applicable
+ if(pair.getPairOp() != PairOperator.SMALLERDOT)
+ return Optional.empty();
+
+ UnifyType rhsType = pair.getRhsType();
+ if(!(rhsType instanceof SuperType))
+ return Optional.empty();
+
+ UnifyType lhsType = pair.getLhsType();
+ if(!(lhsType instanceof ReferenceType) && !(lhsType instanceof PlaceholderType))
+ return Optional.empty();
+
+ // Rule is applicable, unpack the SuperType
+ return Optional.of(new UnifyPair(lhsType, ((SuperType) rhsType).getSuperedType(), PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair()));
+ }
+
+ @Override
+ public Optional reduceLow(UnifyPair pair) {
+ // Check if rule is applicable
+ if(pair.getPairOp() != PairOperator.SMALLERDOT)
+ return Optional.empty();
+
+ UnifyType lhsType = pair.getLhsType();
+ if(!(lhsType instanceof ExtendsType))
+ return Optional.empty();
+
+ UnifyType rhsType = pair.getRhsType();
+ if(!(rhsType instanceof ReferenceType) && !(rhsType instanceof PlaceholderType))
+ return Optional.empty();
+
+ // Rule is applicable, unpack the ExtendsType
+ return Optional.of(new UnifyPair(((ExtendsType) lhsType).getExtendedType(), rhsType, PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair()));
+ }
+
+ @Override
+ public Optional reduceUpLow(UnifyPair pair) {
+ // Check if rule is applicable
+ if(pair.getPairOp() != PairOperator.SMALLERDOT)
+ return Optional.empty();
+
+ UnifyType lhsType = pair.getLhsType();
+ if(!(lhsType instanceof ExtendsType))
+ return Optional.empty();
+
+ UnifyType rhsType = pair.getRhsType();
+ if(!(rhsType instanceof SuperType))
+ return Optional.empty();
+
+ // Rule is applicable, unpack both sides
+ return Optional.of(new UnifyPair(((ExtendsType) lhsType).getExtendedType(),((SuperType) rhsType).getSuperedType(), PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair()));
+ }
+
+ @Override
+ public Optional> reduceExt(UnifyPair pair, IFiniteClosure fc) {
+ if(pair.getPairOp() != PairOperator.SMALLERDOTWC)
+ return Optional.empty();
+
+ UnifyType x = pair.getLhsType();
+ UnifyType sTypeX;
+
+ if(x instanceof ReferenceType)
+ sTypeX = x;
+ else if(x instanceof ExtendsType)
+ sTypeX = ((ExtendsType) x).getExtendedType();
+ else
+ return Optional.empty();
+
+ UnifyType extY = pair.getRhsType();
+
+ if(!(extY instanceof ExtendsType))
+ return Optional.empty();
+
+ if(x.getTypeParams().empty() || extY.getTypeParams().size() != x.getTypeParams().size())
+ return Optional.empty();
+
+ UnifyType xFromFc = fc.getLeftHandedType(sTypeX.getName()).orElse(null);
+
+ if(xFromFc == null || !xFromFc.getTypeParams().arePlaceholders())
+ return Optional.empty();
+
+ if(x instanceof ExtendsType)
+ xFromFc = new ExtendsType(xFromFc);
+
+ UnifyType extYFromFc = fc.grArg(xFromFc, new HashSet<>()).stream().filter(t -> t.getName().equals(extY.getName())).filter(t -> t.getTypeParams().arePlaceholders()).findAny().orElse(null);
+
+ if(extYFromFc == null || extYFromFc.getTypeParams() != xFromFc.getTypeParams())
+ return Optional.empty();
+
+ TypeParams extYParams = extY.getTypeParams();
+ TypeParams xParams = x.getTypeParams();
+
+ int[] pi = pi(xParams, extYParams);
+
+ if(pi.length == 0)
+ return Optional.empty();
+
+ Set result = new HashSet<>();
+
+ for(int rhsIdx = 0; rhsIdx < extYParams.size(); rhsIdx++)
+ result.add(new UnifyPair(xParams.get(pi[rhsIdx]), extYParams.get(rhsIdx), PairOperator.SMALLERDOTWC, pair.getSubstitution(), pair.getBasePair()));
+
+ return Optional.of(result);
+ }
+
+ @Override
+ public Optional> reduceSup(UnifyPair pair, IFiniteClosure fc) {
+ if(pair.getPairOp() != PairOperator.SMALLERDOTWC)
+ return Optional.empty();
+
+ UnifyType x = pair.getLhsType();
+ UnifyType sTypeX;
+
+ if(x instanceof ReferenceType)
+ sTypeX = x;
+ else if(x instanceof SuperType)
+ sTypeX = ((SuperType) x).getSuperedType();
+ else
+ return Optional.empty();
+
+ UnifyType supY = pair.getRhsType();
+
+ if(!(supY instanceof SuperType))
+ return Optional.empty();
+
+ if(x.getTypeParams().empty() || supY.getTypeParams().size() != x.getTypeParams().size())
+ return Optional.empty();
+
+ UnifyType xFromFc = fc.getLeftHandedType(sTypeX.getName()).orElse(null);
+
+ if(xFromFc == null || !xFromFc.getTypeParams().arePlaceholders())
+ return Optional.empty();
+
+ if(x instanceof SuperType)
+ xFromFc = new SuperType(xFromFc);
+
+ UnifyType supYFromFc = fc.grArg(xFromFc, new HashSet<>()).stream().filter(t -> t.getName().equals(supY.getName())).filter(t -> t.getTypeParams().arePlaceholders()).findAny().orElse(null);
+
+ if(supYFromFc == null || supYFromFc.getTypeParams() != xFromFc.getTypeParams())
+ return Optional.empty();
+
+ TypeParams supYParams = supY.getTypeParams();
+ TypeParams xParams = x.getTypeParams();
+ Set result = new HashSet<>();
+
+ int[] pi = pi(xParams, supYParams);
+
+ if(pi.length == 0)
+ return Optional.empty();
+
+ for(int rhsIdx = 0; rhsIdx < supYParams.size(); rhsIdx++)
+ result.add(new UnifyPair(supYParams.get(rhsIdx), xParams.get(pi[rhsIdx]), PairOperator.SMALLERDOTWC, pair.getSubstitution(), pair.getBasePair()));
+
+ return Optional.of(result);
+ }
+
+ @Override
+ public Optional> reduceEq(UnifyPair pair) {
+ if(pair.getPairOp() != PairOperator.SMALLERDOTWC)
+ return Optional.empty();
+
+ UnifyType lhsType = pair.getLhsType();
+ if(lhsType instanceof PlaceholderType || lhsType.getTypeParams().empty())
+ return Optional.empty();
+
+ UnifyType rhsType = pair.getRhsType();
+
+ if(!rhsType.getName().equals(lhsType.getName()))
+ return Optional.empty();
+
+ if(rhsType instanceof PlaceholderType || lhsType instanceof PlaceholderType || rhsType.getTypeParams().empty())
+ return Optional.empty();
+
+ if(rhsType.getTypeParams().size() != lhsType.getTypeParams().size())
+ return Optional.empty();
+
+ // Keine Permutation wie im Paper nötig
+ Set result = new HashSet<>();
+ TypeParams lhsTypeParams = lhsType.getTypeParams();
+ TypeParams rhsTypeParams = rhsType.getTypeParams();
+
+ for(int i = 0; i < lhsTypeParams.size(); i++)
+ result.add(new UnifyPair(lhsTypeParams.get(i), rhsTypeParams.get(i), PairOperator.EQUALSDOT, pair.getSubstitution(), pair.getBasePair()));
+
+ return Optional.of(result);
+ }
+
+ @Override
+ public Optional> reduce1(UnifyPair pair, IFiniteClosure fc) {
+ if(pair.getPairOp() != PairOperator.SMALLERDOT)
+ return Optional.empty();
+
+ UnifyType c = pair.getLhsType();
+ if(!(c instanceof ReferenceType))
+ return Optional.empty();
+
+ UnifyType d = pair.getRhsType();
+ if(!(d instanceof ReferenceType))
+ return Optional.empty();
+
+ ReferenceType lhsSType = (ReferenceType) c;
+ ReferenceType rhsSType = (ReferenceType) d;
+
+ //try {
+ // logFile.write("PAIR Rules: " + pair + "\n");
+ // logFile.flush();
+ //}
+ //catch (IOException e) { }
+
+ if(lhsSType.getTypeParams().empty() || lhsSType.getTypeParams().size() != rhsSType.getTypeParams().size())
+ return Optional.empty();
+
+ UnifyType cFromFc = fc.getLeftHandedType(c.getName()).orElse(null);
+ //2018-02-23: liefert Vector>: Das kann nicht sein.
+
+ //NOCHMAL UEBERPRUEFEN
+ //PL 18-02-09 Eingfuegt Anfang
+ //C und D koennen auch gleich sein.
+ if (c.getName().equals(d.getName())) {
+ Set result = new HashSet<>();
+ TypeParams rhsTypeParams = d.getTypeParams();
+ TypeParams lhsTypeParams = c.getTypeParams();
+ for(int rhsIdx = 0; rhsIdx < c.getTypeParams().size(); rhsIdx++)
+ result.add(new UnifyPair(lhsTypeParams.get(rhsIdx), rhsTypeParams.get(rhsIdx), PairOperator.SMALLERDOTWC, pair.getSubstitution(), pair.getBasePair()));
+
+ return Optional.of(result);
+ }
+ //PL 18-02-09 Eingfuegt ENDE
+
+ //try {
+ // logFile.write("cFromFc: " + cFromFc);
+ // logFile.flush();
+ //}
+ //catch (IOException e) { }
+
+ if(cFromFc == null || !cFromFc.getTypeParams().arePlaceholders())
+ return Optional.empty();
+
+ UnifyType dFromFc = fc.getAncestors(cFromFc).stream().filter(x -> x.getName().equals(d.getName())).findAny().orElse(null);
+
+ //try {
+ // logFile.write("cFromFc: " + cFromFc);
+ // logFile.flush();
+ //}
+ //catch (IOException e) { }
+
+ if(dFromFc == null || !dFromFc.getTypeParams().arePlaceholders() || dFromFc.getTypeParams().size() != cFromFc.getTypeParams().size())
+ return Optional.empty();
+ //System.out.println("cFromFc: " + cFromFc);
+ //System.out.println("dFromFc: " + dFromFc);
+ int[] pi = pi(cFromFc.getTypeParams(), dFromFc.getTypeParams());
+
+ if(pi.length == 0)
+ return Optional.empty();
+
+ TypeParams rhsTypeParams = d.getTypeParams();
+ TypeParams lhsTypeParams = c.getTypeParams();
+ Set result = new HashSet<>();
+
+ for(int rhsIdx = 0; rhsIdx < rhsTypeParams.size(); rhsIdx++)
+ result.add(new UnifyPair(lhsTypeParams.get(pi[rhsIdx]), rhsTypeParams.get(rhsIdx), PairOperator.SMALLERDOTWC, pair.getSubstitution(), pair.getBasePair()));
+
+ return Optional.of(result);
+ }
+
+ @Override
+ public Optional> reduce2(UnifyPair pair) {
+ if(pair.getPairOp() != PairOperator.EQUALSDOT)
+ return Optional.empty();
+
+ UnifyType lhsType = pair.getLhsType();
+ ReferenceType lhsSType;
+ UnifyType rhsType = pair.getRhsType();
+ ReferenceType rhsSType;
+
+ if ((lhsType instanceof ReferenceType) && (rhsType instanceof ReferenceType)) {
+ lhsSType = (ReferenceType) lhsType;
+ rhsSType = (ReferenceType) rhsType;
+ }
+ else if (((lhsType instanceof ExtendsType) && (rhsType instanceof ExtendsType))
+ || ((lhsType instanceof SuperType) && (rhsType instanceof SuperType))) {
+ UnifyType lhsSTypeRaw = ((WildcardType) lhsType).getWildcardedType();
+ UnifyType rhsSTypeRaw = ((WildcardType) rhsType).getWildcardedType();
+ if ((lhsSTypeRaw instanceof ReferenceType) && (rhsSTypeRaw instanceof ReferenceType)) {
+ lhsSType = (ReferenceType) lhsSTypeRaw;
+ rhsSType = (ReferenceType) rhsSTypeRaw;
+ }
+ else
+ return Optional.empty();
+ }
+ else
+ return Optional.empty();
+
+ if(lhsSType.getTypeParams().empty())
+ return Optional.empty();
+
+ /* PL 2018-01-22 in obere Teil integriert
+ UnifyType rhsType = pair.getRhsType();
+ ReferenceType rhsSType;
+
+ if(rhsType instanceof ReferenceType)
+ rhsSType = (ReferenceType) rhsType;
+ else if(rhsType instanceof WildcardType) {
+ UnifyType rhsSTypeRaw = ((WildcardType) rhsType).getWildcardedType();
+ if(rhsSTypeRaw instanceof ReferenceType)
+ rhsSType = (ReferenceType) rhsSTypeRaw;
+ else
+ return Optional.empty();
+ }
+ else
+ return Optional.empty();
+ */
+
+ if(!rhsSType.getName().equals(lhsSType.getName()))
+ return Optional.empty();
+
+ 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();
+
+ Set result = new HashSet<>();
+
+ TypeParams rhsTypeParams = rhsSType.getTypeParams();
+ TypeParams lhsTypeParams = lhsSType.getTypeParams();
+ for(int i = 0; i < rhsTypeParams.size(); i++)
+ result.add(new UnifyPair(lhsTypeParams.get(i), rhsTypeParams.get(i), PairOperator.EQUALSDOT, pair.getSubstitution(), pair.getBasePair()));
+
+ return Optional.of(result);
+ }
+
+ @Override
+ public boolean erase1(UnifyPair pair, IFiniteClosure fc) {
+ if((pair.getPairOp() != PairOperator.SMALLERDOT) && (pair.getPairOp() != PairOperator.SMALLERNEQDOT))
+ return false;
+
+ if (pair.getPairOp() == PairOperator.SMALLERNEQDOT) {
+ UnifyType lhs = pair.getLhsType();
+ UnifyType rhs = pair.getRhsType();
+ if (lhs instanceof WildcardType) {
+ lhs = ((WildcardType)lhs).getWildcardedType();
+ }
+ if (rhs instanceof WildcardType) {
+ rhs = ((WildcardType)rhs).getWildcardedType();
+ }
+
+ if (lhs.equals(rhs)){
+ return false;
+ }
+ }
+
+ UnifyType lhsType = pair.getLhsType();
+ if(!(lhsType instanceof ReferenceType) && !(lhsType instanceof PlaceholderType))
+ return false;
+
+ UnifyType rhsType = pair.getRhsType();
+ if(!(rhsType instanceof ReferenceType) && !(rhsType instanceof PlaceholderType))
+ return false;
+
+ return fc.greater(lhsType, new HashSet<>()).contains(rhsType);
+ }
+
+ @Override
+ public boolean erase2(UnifyPair pair, IFiniteClosure fc) {
+ if(pair.getPairOp() != PairOperator.SMALLERDOTWC)
+ return false;
+
+ UnifyType lhsType = pair.getLhsType();
+ UnifyType rhsType = pair.getRhsType();
+
+ return fc.grArg(lhsType, new HashSet<>()).contains(rhsType);
+ }
+
+ @Override
+ public boolean erase3(UnifyPair pair) {
+ if(pair.getPairOp() != PairOperator.EQUALSDOT)
+ return false;
+
+ return pair.getLhsType().equals(pair.getRhsType());
+ }
+
+ @Override
+ public Optional swap(UnifyPair pair) {
+ if(pair.getPairOp() != PairOperator.EQUALSDOT)
+ return Optional.empty();
+
+ if(pair.getLhsType() instanceof PlaceholderType)
+ return Optional.empty();
+
+ if(!(pair.getRhsType() instanceof PlaceholderType))
+ return Optional.empty();
+
+ return Optional.of(new UnifyPair(pair.getRhsType(), pair.getLhsType(), PairOperator.EQUALSDOT, pair.getSubstitution(), pair.getBasePair()));
+ }
+
+ @Override
+ public Optional adapt(UnifyPair pair, IFiniteClosure fc) {
+ if(pair.getPairOp() != PairOperator.SMALLERDOT)
+ return Optional.empty();
+
+ UnifyType typeD = pair.getLhsType();
+ if(!(typeD instanceof ReferenceType))
+ return Optional.empty();
+
+ UnifyType typeDs = pair.getRhsType();
+ if(!(typeDs instanceof ReferenceType))
+ return Optional.empty();
+
+ /*if(typeD.getTypeParams().size() == 0 || typeDs.getTypeParams().size() == 0)
+ return Optional.empty();*/
+
+ if(typeD.getName().equals(typeDs.getName()))
+ return Optional.empty();
+
+
+ Optional opt = fc.getLeftHandedType(typeD.getName());
+ if(!opt.isPresent())
+ return Optional.empty();
+
+ // The generic Version of Type D (D)
+ UnifyType typeDgen = opt.get();
+
+ // Actually greater+ because the types are ensured to have different names
+ Set greater = fc.getAncestors(typeDgen);
+ opt = greater.stream().filter(x -> x.getName().equals(typeDs.getName())).findAny();
+
+ if(!opt.isPresent())
+ return Optional.empty();
+
+ UnifyType newLhs = opt.get();
+
+ TypeParams typeDParams = typeD.getTypeParams();
+ TypeParams typeDgenParams = typeDgen.getTypeParams();
+
+ //System.out.println("Pair: " +pair);
+ //System.out.println("typeD: " +typeD);
+ //System.out.println("typeDParams: " +typeDParams);
+ //System.out.println("typeDgen: " +typeD);
+ //System.out.println("typeDgenParams: " +typeDgenParams);
+ Unifier unif = Unifier.identity();
+ for(int i = 0; i < typeDParams.size(); i++) {
+ //System.out.println("ADAPT" +typeDgenParams);
+ if (typeDgenParams.get(i) instanceof PlaceholderType)
+ unif.add((PlaceholderType) typeDgenParams.get(i), typeDParams.get(i));
+ else System.out.println("ERROR");
+ }
+ return Optional.of(new UnifyPair(unif.apply(newLhs), typeDs, PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair()));
+ }
+
+ @Override
+ public Optional adaptExt(UnifyPair pair, IFiniteClosure fc) {
+ if(pair.getPairOp() != PairOperator.SMALLERDOTWC)
+ return Optional.empty();
+
+ UnifyType typeD = pair.getLhsType();
+ if(!(typeD instanceof ReferenceType) && !(typeD instanceof ExtendsType))
+ return Optional.empty();
+
+ UnifyType typeExtDs = pair.getRhsType();
+ if(!(typeExtDs instanceof ExtendsType))
+ return Optional.empty();
+
+ if(typeD.getTypeParams().size() == 0 || typeExtDs.getTypeParams().size() == 0)
+ return Optional.empty();
+
+ UnifyType typeDgen;
+ if(typeD instanceof ReferenceType)
+ typeDgen = fc.getLeftHandedType(typeD.getName()).orElse(null);
+ else {
+ Optional opt = fc.getLeftHandedType(((ExtendsType) typeD).getExtendedType().getName());
+ typeDgen = opt.isPresent() ? new ExtendsType(opt.get()) : null;
+ }
+
+ if(typeDgen == null)
+ return Optional.empty();
+
+ Set grArg = fc.grArg(typeDgen, new HashSet<>());
+
+ Optional opt = grArg.stream().filter(x -> x.getName().equals(typeExtDs.getName())).findAny();
+
+ if(!opt.isPresent())
+ return Optional.empty();
+
+ UnifyType newLhs = ((ExtendsType) opt.get()).getExtendedType();
+
+ TypeParams typeDParams = typeD.getTypeParams();
+ TypeParams typeDgenParams = typeDgen.getTypeParams();
+
+ Unifier unif = new Unifier((PlaceholderType) typeDgenParams.get(0), typeDParams.get(0));
+ for(int i = 1; i < typeDParams.size(); i++)
+ unif.add((PlaceholderType) typeDgenParams.get(i), typeDParams.get(i));
+
+ return Optional.of(new UnifyPair(unif.apply(newLhs), typeExtDs, PairOperator.SMALLERDOTWC, pair.getSubstitution(), pair.getBasePair()));
+ }
+
+ @Override
+ public Optional adaptSup(UnifyPair pair, IFiniteClosure fc) {
+ if(pair.getPairOp() != PairOperator.SMALLERDOTWC)
+ return Optional.empty();
+
+ UnifyType typeDs = pair.getLhsType();
+ if(!(typeDs instanceof ReferenceType) && !(typeDs instanceof SuperType))
+ return Optional.empty();
+
+ UnifyType typeSupD = pair.getRhsType();
+ if(!(typeSupD instanceof SuperType))
+ return Optional.empty();
+
+ if(typeDs.getTypeParams().size() == 0 || typeSupD.getTypeParams().size() == 0)
+ return Optional.empty();
+
+
+ Optional opt = fc.getLeftHandedType(((SuperType) typeSupD).getSuperedType().getName());
+
+ if(!opt.isPresent())
+ return Optional.empty();
+
+ UnifyType typeDgen = opt.get();
+ UnifyType typeSupDgen = new SuperType(typeDgen);
+
+ // Use of smArg instead of grArg because
+ // a in grArg(b) => b in smArg(a)
+ Set smArg = fc.smArg(typeSupDgen, new HashSet<>());
+ opt = smArg.stream().filter(x -> x.getName().equals(typeDs.getName())).findAny();
+
+ if(!opt.isPresent())
+ return Optional.empty();
+
+ // New RHS
+ UnifyType newRhs = null;
+ if(typeDs instanceof ReferenceType)
+ newRhs = new ExtendsType(typeDs);
+ else
+ newRhs = new ExtendsType(((SuperType) typeDs).getSuperedType());
+
+ // New LHS
+ UnifyType newLhs = opt.get();
+ TypeParams typeDParams = typeSupD.getTypeParams();
+ TypeParams typeSupDsgenParams = typeSupDgen.getTypeParams();
+
+ Unifier unif = new Unifier((PlaceholderType) typeSupDsgenParams.get(0), typeDParams.get(0));
+ for(int i = 1; i < typeDParams.size(); i++)
+ unif.add((PlaceholderType) typeSupDsgenParams.get(i), typeDParams.get(i));
+
+ return Optional.of(new UnifyPair(unif.apply(newLhs), newRhs, PairOperator.SMALLERDOTWC, pair.getSubstitution(), pair.getBasePair()));
+ }
+
+ /**
+ * Finds the permutation pi of the type arguments of two types based on the finite closure
+ * @param cArgs The type which arguments are permuted
+ * @param dArgs The other type
+ * @return An array containing the values of pi for every type argument of C or an empty array if the search failed.
+ */
+ private int[] pi(TypeParams cArgs, TypeParams dArgs) {
+ if(!(cArgs.size()==dArgs.size()))throw new DebugException("Fehler in Unifizierung");
+
+ int[] permutation = new int[dArgs.size()];
+
+ boolean succ = true;
+ for (int dArgIdx = 0; dArgIdx < dArgs.size() && succ; dArgIdx++) {
+ UnifyType dArg = dArgs.get(dArgIdx);
+ succ = false;
+ for (int pi = 0; pi < cArgs.size(); pi++)
+ if (cArgs.get(pi).getName().equals(dArg.getName())) {
+ permutation[dArgIdx] = pi;
+ succ = true;
+ break;
+ }
+ }
+
+ return succ ? permutation : new int[0];
+ }
+
+ public Optional> subst(Set pairs) {
+ return subst(pairs, new ArrayList<>());
+ }
+
+ @Override
+ public Optional> subst(Set pairs, List>> oderConstraints) {
+ HashMap typeMap = new HashMap<>();
+
+ Stack occuringTypes = new Stack<>();
+
+ for(UnifyPair pair : pairs) {
+ occuringTypes.push(pair.getLhsType());
+ occuringTypes.push(pair.getRhsType());
+ }
+
+ while(!occuringTypes.isEmpty()) {
+ UnifyType t1 = occuringTypes.pop();
+ if(!typeMap.containsKey(t1))
+ typeMap.put(t1, 0);
+ typeMap.put(t1, typeMap.get(t1)+1);
+
+ if(t1 instanceof ExtendsType)
+ occuringTypes.push(((ExtendsType) t1).getExtendedType());
+ if(t1 instanceof SuperType)
+ occuringTypes.push(((SuperType) t1).getSuperedType());
+ else
+ t1.getTypeParams().forEach(x -> occuringTypes.push(x));
+ }
+
+ Queue result1 = new LinkedList(pairs);
+ ArrayList result = new ArrayList();
+ boolean applied = false;
+
+ while(!result1.isEmpty()) {
+ UnifyPair pair = result1.poll();
+ PlaceholderType lhsType = null;
+ UnifyType rhsType;
+
+ if(pair.getPairOp() == PairOperator.EQUALSDOT
+ && pair.getLhsType() instanceof PlaceholderType)
+ lhsType = (PlaceholderType) pair.getLhsType();
+ rhsType = pair.getRhsType(); //PL eingefuegt 2017-09-29 statt !((rhsType = pair.getRhsType()) instanceof PlaceholderType)
+ if(lhsType != null
+ //&& !((rhsType = pair.getRhsType()) instanceof PlaceholderType) //PL geloescht am 2017-09-29 Begründung: auch Typvariablen muessen ersetzt werden.
+ && typeMap.get(lhsType) > 1 // The type occurs in more pairs in the set than just the recent pair.
+ && !rhsType.getTypeParams().occurs(lhsType)
+ && !((rhsType instanceof WildcardType) && ((WildcardType)rhsType).getWildcardedType().equals(lhsType))) //PL eigefuegt 2018-02-18
+ {
+ Unifier uni = new Unifier(lhsType, rhsType);
+ result = result.stream().map(x -> uni.apply(pair,x)).collect(Collectors.toCollection(ArrayList::new));
+ result1 = result1.stream().map(x -> uni.apply(pair,x)).collect(Collectors.toCollection(LinkedList::new));
+
+ Function super Set,? extends HashSet> applyUni = b -> b.stream().map(
+ x -> uni.apply(pair,x)).collect(Collectors.toCollection(HashSet::new));
+ List>> oderConstraintsRet = new ArrayList<>();
+ for(Set> oc : oderConstraints) {
+ //Set> ocRet = new HashSet<>();
+ //for(Set cs : oc) {
+ Set> csRet = oc.stream().map(applyUni).collect(Collectors.toCollection(HashSet::new));
+ oderConstraintsRet.add(csRet);
+ //}
+ }
+ oderConstraints.replaceAll(oc -> oc.stream().map(applyUni).collect(Collectors.toCollection(HashSet::new)));
+ /*
+ oderConstraints = oderConstraints.stream().map(
+ a -> a.stream().map(applyUni
+ //b -> b.stream().map(
+ // x -> uni.apply(pair,x)).collect(Collectors.toCollection(HashSet::new) )
+ ).collect(Collectors.toCollection(HashSet::new))
+ ).collect(Collectors.toList(ArrayList::new));
+ }
+ */
+ applied = true;
+ }
+ result.add(pair);
+ }
+
+ return applied ? Optional.of(new HashSet<>(result)) : Optional.empty();
+ }
+
+ @Override
+ public Optional reduceWildcardLow(UnifyPair pair) {
+ if(pair.getPairOp() != PairOperator.SMALLERDOTWC)
+ return Optional.empty();
+
+ UnifyType lhsType = pair.getLhsType();
+ UnifyType rhsType = pair.getRhsType();
+ if(!(lhsType instanceof ExtendsType) || !(rhsType instanceof ExtendsType))
+ return Optional.empty();
+
+ return Optional.of(new UnifyPair(((ExtendsType) lhsType).getExtendedType(), ((ExtendsType) rhsType).getExtendedType(), PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair()));
+ }
+
+ @Override
+ public Optional reduceWildcardLowRight(UnifyPair pair) {
+ if(pair.getPairOp() != PairOperator.SMALLERDOTWC)
+ return Optional.empty();
+
+ UnifyType lhsType = pair.getLhsType();
+ UnifyType rhsType = pair.getRhsType();
+ if(!(lhsType instanceof ReferenceType) || !(rhsType instanceof ExtendsType))
+ return Optional.empty();
+
+ return Optional.of(new UnifyPair(lhsType, ((ExtendsType) rhsType).getExtendedType(), PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair()));
+ }
+
+ @Override
+ public Optional reduceWildcardUp(UnifyPair pair) {
+ if(pair.getPairOp() != PairOperator.SMALLERDOTWC)
+ return Optional.empty();
+
+ UnifyType lhsType = pair.getLhsType();
+ UnifyType rhsType = pair.getRhsType();
+ if(!(lhsType instanceof SuperType) || !(rhsType instanceof SuperType))
+ return Optional.empty();
+
+ return Optional.of(new UnifyPair(((SuperType) rhsType).getSuperedType(), ((SuperType) lhsType).getSuperedType(), PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair()));
+ }
+
+ @Override
+ public Optional reduceWildcardUpRight(UnifyPair pair) {
+ if(pair.getPairOp() != PairOperator.SMALLERDOTWC)
+ return Optional.empty();
+
+ UnifyType lhsType = pair.getLhsType();
+ UnifyType rhsType = pair.getRhsType();
+ if(!(lhsType instanceof ReferenceType) || !(rhsType instanceof SuperType))
+ return Optional.empty();
+
+ return Optional.of(new UnifyPair(((SuperType) rhsType).getSuperedType(), lhsType, PairOperator.SMALLERDOTWC, pair.getSubstitution(), pair.getBasePair()));
+ }
+
+ /* PL 2018-03-06 auskommentiert sind mutmaßlich falsch
+ * vgl. JAVA_BSP/Wildcard6.java
+ @Override
+ public Optional reduceWildcardLowUp(UnifyPair pair) {
+ if(pair.getPairOp() != PairOperator.SMALLERDOTWC)
+ return Optional.empty();
+
+ UnifyType lhsType = pair.getLhsType();
+ UnifyType rhsType = pair.getRhsType();
+ if(!(lhsType instanceof ExtendsType) || !(rhsType instanceof SuperType))
+ return Optional.empty();
+
+ return Optional.of(new UnifyPair(((ExtendsType) lhsType).getExtendedType(), ((SuperType) rhsType).getSuperedType(), PairOperator.EQUALSDOT));
+ }
+
+ @Override
+ public Optional reduceWildcardUpLow(UnifyPair pair) {
+ if(pair.getPairOp() != PairOperator.SMALLERDOTWC)
+ return Optional.empty();
+
+ UnifyType lhsType = pair.getLhsType();
+ UnifyType rhsType = pair.getRhsType();
+ if(!(lhsType instanceof SuperType) || !(rhsType instanceof ExtendsType))
+ return Optional.empty();
+
+ return Optional.of(new UnifyPair(((SuperType) lhsType).getSuperedType(), ((ExtendsType) rhsType).getExtendedType(), PairOperator.EQUALSDOT));
+ }
+
+
+ @Override
+ public Optional reduceWildcardLeft(UnifyPair pair) {
+ if(pair.getPairOp() != PairOperator.SMALLERDOTWC)
+ return Optional.empty();
+
+ UnifyType rhsType = pair.getRhsType();
+ if(!(rhsType instanceof ReferenceType))
+ return Optional.empty();
+
+ UnifyType lhsType = pair.getLhsType();
+
+ if(lhsType instanceof WildcardType)
+ return Optional.of(new UnifyPair(((WildcardType) lhsType).getWildcardedType(), rhsType, PairOperator.EQUALSDOT));
+
+ return Optional.empty();
+ }
+ */
+ @Override
+ public Optional> reduceFunN(UnifyPair pair) {
+ if((pair.getPairOp() != PairOperator.SMALLERDOT)
+ && (pair.getPairOp() != PairOperator.EQUALSDOT)) //PL 2017-10-03 hinzugefuegt
+ //da Regel auch fuer EQUALSDOT anwendbar
+ //TODO: fuer allen anderen Relationen noch pruefen
+ return Optional.empty();
+
+ UnifyType lhsType = pair.getLhsType();
+ UnifyType rhsType = pair.getRhsType();
+
+ if(!(lhsType instanceof FunNType) || !(rhsType instanceof FunNType))
+ return Optional.empty();
+
+ FunNType funNLhsType = (FunNType) lhsType;
+ FunNType funNRhsType = (FunNType) rhsType;
+
+ if(funNLhsType.getN() != funNRhsType.getN())
+ return Optional.empty();
+
+ Set result = new HashSet();
+ if (pair.getPairOp() == PairOperator.SMALLERDOT) {
+ result.add(new UnifyPair(funNLhsType.getTypeParams().get(funNLhsType.getTypeParams().size()-1), funNRhsType.getTypeParams().get(funNRhsType.getTypeParams().size()-1), PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair()));
+ for(int i = 0; i < funNLhsType.getTypeParams().size()-1; i++) {
+ result.add(new UnifyPair(funNRhsType.getTypeParams().get(i), funNLhsType.getTypeParams().get(i), PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair()));
+ }
+ }
+ else {// pair.getPairOp() == PairOperator.EQUALDOT
+ result.add(new UnifyPair(funNLhsType.getTypeParams().get(funNLhsType.getTypeParams().size()-1), funNRhsType.getTypeParams().get(funNRhsType.getTypeParams().size()-1), PairOperator.EQUALSDOT, pair.getSubstitution(), pair.getBasePair()));
+ for(int i = 0; i < funNLhsType.getTypeParams().size()-1; i++) {
+ result.add(new UnifyPair(funNRhsType.getTypeParams().get(i), funNLhsType.getTypeParams().get(i), PairOperator.EQUALSDOT, pair.getSubstitution(), pair.getBasePair()));
+ }
+ }
+ result.stream().forEach(x -> { UnifyType l = x.getLhsType();
+ if (l instanceof PlaceholderType) { ((PlaceholderType)l).disableWildcardtable(); }
+ UnifyType r = x.getRhsType();
+ if (r instanceof PlaceholderType) { ((PlaceholderType)r).disableWildcardtable(); }
+ } );
+ try {
+ logFile.write("FUNgreater: " + pair + "\n");
+ logFile.write("FUNred: " + result + "\n");
+ logFile.flush();
+ }
+ catch (IOException e) {
+ System.out.println("logFile-Error");
+ }
+ return Optional.of(result);
+ }
+
+
+ @Override
+ public Optional> greaterFunN(UnifyPair pair) {
+ if(pair.getPairOp() != PairOperator.SMALLERDOT)
+ return Optional.empty();
+
+ UnifyType lhsType = pair.getLhsType();
+ UnifyType rhsType = pair.getRhsType();
+
+ if(!(lhsType instanceof FunNType) || !(rhsType instanceof PlaceholderType))
+ return Optional.empty();
+
+ FunNType funNLhsType = (FunNType) lhsType;
+
+ Set result = new HashSet();
+
+ Integer variance = ((PlaceholderType)rhsType).getVariance();
+ Integer inversVariance = distributeVariance.inverseVariance(variance);
+
+ UnifyType[] freshPlaceholders = new UnifyType[funNLhsType.getTypeParams().size()];
+ for(int i = 0; i < freshPlaceholders.length-1; i++) {
+ freshPlaceholders[i] = PlaceholderType.freshPlaceholder();
+ ((PlaceholderType)freshPlaceholders[i]).setVariance(inversVariance);
+ }
+ freshPlaceholders[freshPlaceholders.length-1] = PlaceholderType.freshPlaceholder();
+ ((PlaceholderType)freshPlaceholders[freshPlaceholders.length-1]).setVariance(variance);
+ result.add(new UnifyPair(funNLhsType.getTypeParams().get(funNLhsType.getTypeParams().size()-1), freshPlaceholders[funNLhsType.getTypeParams().size()-1], PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair()));
+
+ for(int i = 0; i < funNLhsType.getTypeParams().size()-1; i++) {
+ result.add(new UnifyPair(freshPlaceholders[i], funNLhsType.getTypeParams().get(i), PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair()));
+ }
+
+ result.add(new UnifyPair(rhsType, funNLhsType.setTypeParams(new TypeParams(freshPlaceholders)), PairOperator.EQUALSDOT, pair.getSubstitution(), pair.getBasePair()));
+
+ result.stream().forEach(x -> { UnifyType l = x.getLhsType();
+ if (l instanceof PlaceholderType) { ((PlaceholderType)l).disableWildcardtable(); }
+ UnifyType r = x.getRhsType();
+ if (r instanceof PlaceholderType) { ((PlaceholderType)r).disableWildcardtable(); }
+ } );
+ try {
+ logFile.write("FUNgreater: " + pair + "\n");
+ logFile.write("FUNgreater: " + result + "\n");
+ logFile.flush();
+ }
+ catch (IOException e) {
+ System.out.println("lofFile-Error");
+ }
+ return Optional.of(result);
+ }
+
+ @Override
+ public Optional> smallerFunN(UnifyPair pair) {
+ if(pair.getPairOp() != PairOperator.SMALLERDOT)
+ return Optional.empty();
+
+ UnifyType lhsType = pair.getLhsType();
+ UnifyType rhsType = pair.getRhsType();
+
+ if(!(lhsType instanceof PlaceholderType) || !(rhsType instanceof FunNType))
+ return Optional.empty();
+
+ FunNType funNRhsType = (FunNType) rhsType;
+
+ Set result = new HashSet();
+
+ Integer variance = ((PlaceholderType)lhsType).getVariance();
+ Integer inversVariance = distributeVariance.inverseVariance(variance);
+
+ UnifyType[] freshPlaceholders = new UnifyType[funNRhsType.getTypeParams().size()];
+ for(int i = 0; i < freshPlaceholders.length-1; i++) {
+ freshPlaceholders[i] = PlaceholderType.freshPlaceholder();
+ ((PlaceholderType)freshPlaceholders[i]).setVariance(inversVariance);
+ }
+ freshPlaceholders[freshPlaceholders.length-1] = PlaceholderType.freshPlaceholder();
+ ((PlaceholderType)freshPlaceholders[freshPlaceholders.length-1]).setVariance(variance);
+
+ result.add(new UnifyPair(freshPlaceholders[funNRhsType.getTypeParams().size()-1], funNRhsType.getTypeParams().get(funNRhsType.getTypeParams().size()-1), PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair()));
+
+ for(int i = 0; i < funNRhsType.getTypeParams().size()-1; i++) {
+ result.add(new UnifyPair(funNRhsType.getTypeParams().get(i), freshPlaceholders[i], PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair()));
+ }
+
+ result.add(new UnifyPair(lhsType, funNRhsType.setTypeParams(new TypeParams(freshPlaceholders)), PairOperator.EQUALSDOT, pair.getSubstitution(), pair.getBasePair()));
+
+ result.stream().forEach(x -> { UnifyType l = x.getLhsType();
+ if (l instanceof PlaceholderType) { ((PlaceholderType)l).disableWildcardtable(); }
+ UnifyType r = x.getRhsType();
+ if (r instanceof PlaceholderType) { ((PlaceholderType)r).disableWildcardtable(); }
+ } );
+ try {
+ logFile.write("FUNgreater: " + pair + "\n");
+ logFile.write("FUNsmaller: " + result + "\n");
+ logFile.flush();
+ }
+ catch (IOException e) {
+ System.out.println("lofFile-Error");
+ }
+ return Optional.of(result);
+ }
+
+ @Override
+ public Optional reduceTph(UnifyPair pair) {
+ if(pair.getPairOp() != PairOperator.SMALLERDOTWC)
+ return Optional.empty();
+
+ UnifyType lhsType = pair.getLhsType();
+ UnifyType rhsType = pair.getRhsType();
+ if(!(lhsType instanceof PlaceholderType) || !(rhsType instanceof ReferenceType))
+ return Optional.empty();
+
+ return Optional.of(new UnifyPair(lhsType, rhsType, PairOperator.EQUALSDOT, pair.getSubstitution(), pair.getBasePair()));
+ }
+
+ @Override
+ public Optional> reduceTphExt(UnifyPair pair) {
+ if(pair.getPairOp() != PairOperator.SMALLERDOTWC)
+ return Optional.empty();
+
+ UnifyType lhsType = pair.getLhsType();
+ UnifyType rhsType = pair.getRhsType();
+ if(!(lhsType instanceof ExtendsType) || !(rhsType instanceof PlaceholderType))
+ return Optional.empty();
+
+ UnifyType extendedType = ((ExtendsType)lhsType).getExtendedType();
+
+ if (extendedType.equals(rhsType)) return Optional.empty(); //PL 2019-02-18 eingefügt ? extends a <.? a
+
+ boolean isGen = extendedType instanceof PlaceholderType && !((PlaceholderType) extendedType).isGenerated();
+
+ Set result = new HashSet<>();
+ if(isGen)
+ result.add(new UnifyPair(rhsType, lhsType, PairOperator.EQUALSDOT, pair.getSubstitution(), pair.getBasePair()));
+ else {
+ UnifyType freshTph = PlaceholderType.freshPlaceholder();
+ result.add(new UnifyPair(rhsType, new ExtendsType(freshTph), PairOperator.EQUALSDOT, pair.getSubstitution(), pair.getBasePair()));
+ result.add(new UnifyPair(extendedType, freshTph, PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair()));
+ }
+
+ return Optional.of(result);
+ }
+
+ @Override
+ public Optional> reduceTphSup(UnifyPair pair) {
+ if(pair.getPairOp() != PairOperator.SMALLERDOTWC)
+ return Optional.empty();
+
+ UnifyType lhsType = pair.getLhsType();
+ UnifyType rhsType = pair.getRhsType();
+ if(!(lhsType instanceof SuperType) || !(rhsType instanceof PlaceholderType))
+ return Optional.empty();
+
+ UnifyType superedType = ((SuperType)lhsType).getSuperedType();
+
+ if (superedType.equals(rhsType)) return Optional.empty(); //PL 2019-02-18 eingefügt ? super a <.? a
+
+ boolean isGen = superedType instanceof PlaceholderType && !((PlaceholderType) superedType).isGenerated();
+
+ Set result = new HashSet<>();
+ if(isGen)
+ result.add(new UnifyPair(rhsType, lhsType, PairOperator.EQUALSDOT, pair.getSubstitution(), pair.getBasePair()));
+ else {
+ UnifyType freshTph = PlaceholderType.freshPlaceholder();
+ result.add(new UnifyPair(rhsType, new SuperType(freshTph), PairOperator.EQUALSDOT, pair.getSubstitution(), pair.getBasePair()));
+ Set fBounded = pair.getfBounded();
+ fBounded.add(lhsType);
+ result.add(new UnifyPair(freshTph, superedType, PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair(), fBounded));
+ }
+
+ return Optional.of(result);
+ }
+}
diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify.java
index 62404b30..6b045547 100644
--- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify.java
+++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify.java
@@ -1,121 +1,121 @@
-package de.dhbwstuttgart.typeinference.unify;
-
-import java.io.FileWriter;
-import java.io.IOException;
-import java.io.Writer;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Set;
-import java.util.concurrent.ForkJoinPool;
-
-import de.dhbwstuttgart.core.JavaTXCompiler;
-import de.dhbwstuttgart.typeinference.constraints.Constraint;
-import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
-import de.dhbwstuttgart.typeinference.constraints.Pair;
-import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
-import de.dhbwstuttgart.typeinference.unify.model.FiniteClosure;
-import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
-
-public class TypeUnify {
-
- /**
- * unify parallel ohne result modell
- * @param undConstrains
- * @param oderConstraints
- * @param fc
- * @param logFile
- * @param log
- * @param cons
- * @return
- */
- public Set> unify(Set undConstrains, List>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModel ret, UnifyTaskModel usedTasks) {
- TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, true, logFile, log, 0, ret, usedTasks);
- ForkJoinPool pool = new ForkJoinPool();
- pool.invoke(unifyTask);
- Set> res = unifyTask.join();
- try {
- logFile.write("\nnoShortendElements: " + unifyTask.noShortendElements + "\n");
- logFile.flush();
- }
- catch (IOException e) {
- System.err.println("no log-File");
- }
- return res;
- }
-
- /**
- * unify asynchron mit Rückgabe UnifyResultModel ohne dass alle results gesammelt sind
- * @param undConstrains
- * @param oderConstraints
- * @param fc
- * @param logFile
- * @param log
- * @param cons
- * @param ret
- * @return
- */
- public UnifyResultModel unifyAsync(Set undConstrains, List>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModel ret, UnifyTaskModel usedTasks) {
- TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, true, logFile, log, 0, ret, usedTasks);
- ForkJoinPool pool = new ForkJoinPool();
- pool.invoke(unifyTask);
- return ret;
- }
-
- /**
- * unify parallel mit Rückgabe UnifyResultModel nachdem alle results gesammelt sind
- * @param undConstrains
- * @param oderConstraints
- * @param fc
- * @param logFile
- * @param log
- * @param cons
- * @param ret
- * @return
- */
- public UnifyResultModel unifyParallel(Set undConstrains, List>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModel ret, UnifyTaskModel usedTasks) {
- TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, true, logFile, log, 0, ret, usedTasks);
- ForkJoinPool pool = new ForkJoinPool();
- pool.invoke(unifyTask);
- Set> res = unifyTask.join();
- try {
- logFile.write("\nnoShortendElements: " + unifyTask.noShortendElements +"\n");
- logFile.flush();
- }
- catch (IOException e) {
- System.err.println("no log-File");
- }
- return ret;
- }
-
- /*
- public Set> unifySequential(Set eq, IFiniteClosure fc, FileWriter logFile, Boolean log) {
- TypeUnifyTask unifyTask = new TypeUnifyTask(eq, fc, false, logFile, log);
- Set> res = unifyTask.compute();
- return res;
- }
- */
-
- /**
- * unify sequentiell mit oderconstraints
- * @param undConstrains
- * @param oderConstraints
- * @param fc
- * @param logFile
- * @param log
- * @param cons
- * @return
- */
- public Set> unifyOderConstraints(Set undConstrains, List>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModel ret, UnifyTaskModel usedTasks) {
- TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, false, logFile, log, 0, ret, usedTasks);
- Set> res = unifyTask.compute();
- try {
- logFile.write("\nnoShortendElements: " + unifyTask.noShortendElements +"\n");
- logFile.flush();
- }
- catch (IOException e) {
- System.err.println("no log-File");
- }
- return res;
- }
-
-}
+package de.dhbwstuttgart.typeinference.unify;
+
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.Writer;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+import java.util.concurrent.ForkJoinPool;
+
+import de.dhbwstuttgart.core.JavaTXCompiler;
+import de.dhbwstuttgart.typeinference.constraints.Constraint;
+import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
+import de.dhbwstuttgart.typeinference.constraints.Pair;
+import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
+import de.dhbwstuttgart.typeinference.unify.model.FiniteClosure;
+import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
+
+public class TypeUnify {
+
+ /**
+ * unify parallel ohne result modell
+ * @param undConstrains
+ * @param oderConstraints
+ * @param fc
+ * @param logFile
+ * @param log
+ * @param cons
+ * @return
+ */
+ public Set