Compare commits
33 Commits
classloade
...
addPackage
Author | SHA1 | Date | |
---|---|---|---|
e634f2ca67 | |||
c964fa7ce2 | |||
941a3bed66 | |||
653901ef32 | |||
2e03b5b10c | |||
670e3ed99f | |||
c8ece0a010 | |||
c27e1fa4e1 | |||
b3b25b7869 | |||
9240b0d163 | |||
a0a813f87c | |||
60b182b9b1 | |||
8e2d4e1c70 | |||
907ab2fcec | |||
eb27003515 | |||
71c801c19c | |||
ba750187ba | |||
ccf5df1f1e | |||
3de735ebe3 | |||
fd3d4e97a1 | |||
6deeb4105f | |||
9d4980d9a1 | |||
b83e2c10e3 | |||
4f10e789d4 | |||
8b9f0d6376 | |||
3f919be1bf | |||
97bdfe1d3a | |||
7c7dbf3769 | |||
577faa88af | |||
8bdb7e7b13 | |||
eca187da79 | |||
850af6a6ae | |||
ed1bb44089 |
.gitignorepom.xml
src
main
java
de
dhbwstuttgart
test
3
.gitignore
vendored
3
.gitignore
vendored
@ -26,3 +26,6 @@ manually/
|
||||
|
||||
logFiles/**
|
||||
!logFiles/.gitkeep
|
||||
|
||||
src/main/java/de/dhbwstuttgart/parser/antlr/
|
||||
src/main/java/de/dhbwstuttgart/sat/asp/parser/antlr/
|
||||
|
4
pom.xml
4
pom.xml
@ -75,7 +75,7 @@ http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
</goals>
|
||||
<configuration>
|
||||
<sourceDirectory>src/main/antlr4/java8</sourceDirectory>
|
||||
<outputDirectory>${project.basedir}/target/generated-sources/antlr4/de/dhbwstuttgart/parser/antlr</outputDirectory>
|
||||
<outputDirectory>${project.basedir}/src/main/java/de/dhbwstuttgart/parser/antlr</outputDirectory>
|
||||
<arguments>
|
||||
<argument>-package</argument>
|
||||
<argument>de.dhbwstuttgart.parser.antlr</argument>
|
||||
@ -89,7 +89,7 @@ http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
</goals>
|
||||
<configuration>
|
||||
<sourceDirectory>src/main/antlr4/sat</sourceDirectory>
|
||||
<outputDirectory>${project.basedir}/target/generated-sources/antlr4/de/dhbwstuttgart/sat/asp/parser/antlr</outputDirectory>
|
||||
<outputDirectory>${project.basedir}/src/main/java/de/dhbwstuttgart/sat/asp/parser/antlr</outputDirectory>
|
||||
<arguments>
|
||||
<argument>-package</argument>
|
||||
<argument>de.dhbwstuttgart.sat.asp.parser.antlr</argument>
|
||||
|
@ -135,50 +135,68 @@ public class JavaTXCompiler {
|
||||
//sf enthaelt neues Source-File, neue Klassen-Objekte und neue
|
||||
//ArrayListen-Objekte fuer Fields, Construktoren und Methoden
|
||||
//Alle anderen Objekte werden nur kopiert.
|
||||
sf.KlassenVektor.forEach(cl -> {
|
||||
ClassOrInterface superclass = null;
|
||||
if (cl.getSuperClass().getName().equals(new JavaClassName("java.lang.Object"))) {
|
||||
superclass = objectClass;
|
||||
}
|
||||
else {
|
||||
Optional<ClassOrInterface> optSuperclass =
|
||||
importedClasses.stream().filter(x -> x.getClassName().equals(
|
||||
SourceFile sf_new = sf;
|
||||
sf.KlassenVektor.forEach(cl -> addMethods(sf_new, cl, importedClasses, objectClass));
|
||||
allClasses.addAll(sf.getClasses());
|
||||
}
|
||||
allClasses.addAll(importedClasses);
|
||||
return new TYPE(sourceFiles.values(), allClasses).getConstraints();
|
||||
}
|
||||
|
||||
void addMethods(SourceFile sf, ClassOrInterface cl, List<ClassOrInterface> importedClasses, ClassOrInterface objectClass) {
|
||||
if (!cl.areMethodsAdded()) {
|
||||
ClassOrInterface superclass = null;
|
||||
if (cl.getSuperClass().getName().equals(new JavaClassName("java.lang.Object"))) {
|
||||
superclass = objectClass;
|
||||
}
|
||||
else {
|
||||
Optional<ClassOrInterface> optSuperclass =
|
||||
importedClasses.stream().filter(x -> x.getClassName().equals(
|
||||
cl.getSuperClass().getName())).findFirst();
|
||||
if (optSuperclass.isPresent()) {
|
||||
superclass = optSuperclass.get();
|
||||
}
|
||||
else {
|
||||
optSuperclass =
|
||||
sf.KlassenVektor.stream().filter(x -> x.getClassName().equals(
|
||||
cl.getSuperClass().getName())).findFirst();
|
||||
if (optSuperclass.isPresent()) {
|
||||
superclass = optSuperclass.get();
|
||||
addMethods(sf, superclass, importedClasses, objectClass);
|
||||
}
|
||||
else {
|
||||
else {
|
||||
//throw new ClassNotFoundException("");
|
||||
}
|
||||
}
|
||||
Iterator<RefTypeOrTPHOrWildcardOrGeneric> paraIt= cl.getSuperClass().getParaList().iterator();
|
||||
Iterator<GenericTypeVar> tvarVarIt = superclass.getGenerics().iterator();
|
||||
}
|
||||
Iterator<RefTypeOrTPHOrWildcardOrGeneric> paraIt= cl.getSuperClass().getParaList().iterator();
|
||||
Iterator<GenericTypeVar> tvarVarIt = superclass.getGenerics().iterator();
|
||||
|
||||
HashMap<String, RefTypeOrTPHOrWildcardOrGeneric> gtvs = new HashMap<>();
|
||||
while (paraIt.hasNext()) {
|
||||
gtvs.put(tvarVarIt.next().getName(), paraIt.next());
|
||||
}
|
||||
Iterator<Method> methodIt = superclass.getMethods().iterator();
|
||||
while(methodIt.hasNext()) {
|
||||
Method m = methodIt.next();
|
||||
ParameterList newParaList = new ParameterList(
|
||||
HashMap<String, RefTypeOrTPHOrWildcardOrGeneric> gtvs = new HashMap<>();
|
||||
while (paraIt.hasNext()) {
|
||||
gtvs.put(tvarVarIt.next().getName(), paraIt.next());
|
||||
}
|
||||
Iterator<Method> methodIt = superclass.getMethods().iterator();
|
||||
//TODO: PL 2020-05-06: Hier müssen ueberschriebene Methoden noch rausgefiltert werden
|
||||
while(methodIt.hasNext()) {
|
||||
Method m = methodIt.next();
|
||||
ParameterList newParaList = new ParameterList(
|
||||
m.getParameterList()
|
||||
.getFormalparalist()
|
||||
.stream()
|
||||
.map(fp -> new FormalParameter(fp.getName(), fp.getType().acceptTV(new TypeExchanger(gtvs)), fp.getOffset()))
|
||||
.collect(Collectors.toCollection(ArrayList::new)), m.getParameterList().getOffset());
|
||||
cl.getMethods().add(new Method(m.modifier, m.name, m.getReturnType().acceptTV(new TypeExchanger(gtvs)), newParaList, m.block,
|
||||
cl.getMethods().add(new Method(m.modifier, m.name, m.getReturnType().acceptTV(new TypeExchanger(gtvs)), newParaList, m.block,
|
||||
//new GenericDeclarationList(newGenericsList, ((GenericDeclarationList)m.getGenerics()).getOffset()),
|
||||
(GenericDeclarationList)m.getGenerics(),
|
||||
m.getOffset()));
|
||||
}
|
||||
(GenericDeclarationList)m.getGenerics(),
|
||||
m.getOffset(), true));
|
||||
}
|
||||
|
||||
});
|
||||
allClasses.addAll(sf.getClasses());
|
||||
}
|
||||
allClasses.addAll(importedClasses);
|
||||
return new TYPE(sourceFiles.values(), allClasses).getConstraints();
|
||||
}
|
||||
cl.setMethodsAdded();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public List<ClassOrInterface> getAvailableClasses(SourceFile forSourceFile) throws ClassNotFoundException {
|
||||
//PL 2018-09-18: List durch Set ersetzt, damit die Klassen nur einmal hinzugefuegt werden
|
||||
@ -517,13 +535,13 @@ public class JavaTXCompiler {
|
||||
// Set<Set<UnifyPair>> result = unify.unifySequential(xConsSet, finiteClosure,
|
||||
// logFile, log);
|
||||
// Set<Set<UnifyPair>> result = unify.unify(xConsSet, finiteClosure);
|
||||
List<Set<Set<UnifyPair>>> oderConstraints = unifyCons.getOderConstraints().stream().map(x -> {
|
||||
List<Set<Constraint<UnifyPair>>> oderConstraints = unifyCons.getOderConstraints()/*.stream().map(x -> {
|
||||
Set<Set<UnifyPair>> ret = new HashSet<>();
|
||||
for (Constraint<UnifyPair> y : x) {
|
||||
ret.add(new HashSet<>(y));
|
||||
}
|
||||
return ret;
|
||||
}).collect(Collectors.toCollection(ArrayList::new));
|
||||
}).collect(Collectors.toCollection(ArrayList::new))*/;
|
||||
unify.unifyAsync(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, urm,
|
||||
usedTasks);
|
||||
} catch (IOException e) {
|
||||
@ -545,11 +563,11 @@ public class JavaTXCompiler {
|
||||
final ConstraintSet<Pair> cons = getConstraints();
|
||||
Set<Set<UnifyPair>> results = new HashSet<>();
|
||||
try {
|
||||
Writer logFile = //new OutputStreamWriter(new NullOutputStream());
|
||||
Writer logFile = new OutputStreamWriter(new NullOutputStream());
|
||||
// new FileWriter(new
|
||||
// File(System.getProperty("user.dir")+"/src/test/resources/logFiles/"+"log_"+sourceFiles.keySet().iterator().next().getName()));
|
||||
new FileWriter(new File(System.getProperty("user.dir") + "/logFiles/" + "log_"
|
||||
+ sourceFiles.keySet().iterator().next().getName()));
|
||||
//new FileWriter(new File(System.getProperty("user.dir") + "/logFiles/" + "log_"
|
||||
// + sourceFiles.keySet().iterator().next().getName()));
|
||||
IFiniteClosure finiteClosure = UnifyTypeFactory.generateFC(allClasses, logFile, classLoader);
|
||||
System.out.println(finiteClosure);
|
||||
ConstraintSet<UnifyPair> unifyCons = UnifyTypeFactory.convert(cons);
|
||||
@ -705,13 +723,13 @@ public class JavaTXCompiler {
|
||||
// Set<Set<UnifyPair>> result = unify.unifySequential(xConsSet, finiteClosure,
|
||||
// logFile, log);
|
||||
// Set<Set<UnifyPair>> result = unify.unify(xConsSet, finiteClosure);
|
||||
List<Set<Set<UnifyPair>>> oderConstraints = unifyCons.getOderConstraints().stream().map(x -> {
|
||||
Set<Set<UnifyPair>> ret = new HashSet<>();
|
||||
List<Set<Constraint<UnifyPair>>> oderConstraints = unifyCons.getOderConstraints()//.stream().map(x -> {
|
||||
/*Set<Set<UnifyPair>> ret = new HashSet<>();
|
||||
for (Constraint<UnifyPair> y : x) {
|
||||
ret.add(new HashSet<>(y));
|
||||
}
|
||||
return ret;
|
||||
}).collect(Collectors.toCollection(ArrayList::new));
|
||||
}).collect(Collectors.toCollection(ArrayList::new))*/;
|
||||
if (resultmodel) {
|
||||
/* UnifyResultModel Anfang */
|
||||
UnifyResultModel urm = new UnifyResultModel(cons, finiteClosure);
|
||||
@ -958,7 +976,7 @@ public class JavaTXCompiler {
|
||||
|
||||
@Override
|
||||
public RefTypeOrTPHOrWildcardOrGeneric visit(TypePlaceholder typePlaceholder) {
|
||||
throw new DebugException("Dieser Fall darf nicht auftreten");
|
||||
return typePlaceholder; //TypePlaceholder der vererbert wird kann bei der Vererbung nicht instanziert werden.
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -23,6 +23,7 @@ import java.util.Optional;
|
||||
* Stellt jede Art von Klasse dar. Auch abstrakte Klassen und Interfaces
|
||||
*/
|
||||
public class ClassOrInterface extends SyntaxTreeNode implements TypeScope{
|
||||
private Boolean methodAdded = false; //wird benoetigt bei in JavaTXCompiler.getConstraints()
|
||||
protected int modifiers;
|
||||
protected JavaClassName name;
|
||||
private List<Field> fields = new ArrayList<>();
|
||||
@ -68,6 +69,16 @@ public class ClassOrInterface extends SyntaxTreeNode implements TypeScope{
|
||||
this.constructors = new ArrayList<>(cl.constructors);
|
||||
}
|
||||
|
||||
//Gets if it is added
|
||||
public Boolean areMethodsAdded() {
|
||||
return methodAdded;
|
||||
}
|
||||
|
||||
//Sets that it is added
|
||||
public void setMethodsAdded() {
|
||||
methodAdded = true;
|
||||
}
|
||||
|
||||
// Gets class name
|
||||
public JavaClassName getClassName(){
|
||||
return this.name;
|
||||
|
@ -31,6 +31,7 @@ public class Method extends SyntaxTreeNode implements IItemWithOffset, TypeScope
|
||||
private ExceptionList exceptionlist;
|
||||
private GenericDeclarationList generics;
|
||||
private final RefTypeOrTPHOrWildcardOrGeneric returnType;
|
||||
public final Boolean isInherited;
|
||||
|
||||
public Method(int modifier, String name, RefTypeOrTPHOrWildcardOrGeneric returnType, ParameterList parameterList, Block block,
|
||||
GenericDeclarationList gtvDeclarations, Token offset) {
|
||||
@ -41,6 +42,19 @@ public class Method extends SyntaxTreeNode implements IItemWithOffset, TypeScope
|
||||
this.parameterlist = parameterList;
|
||||
this.block = block;
|
||||
this.generics = gtvDeclarations;
|
||||
this.isInherited = false;
|
||||
}
|
||||
|
||||
public Method(int modifier, String name, RefTypeOrTPHOrWildcardOrGeneric returnType, ParameterList parameterList, Block block,
|
||||
GenericDeclarationList gtvDeclarations, Token offset, Boolean isInherited) {
|
||||
super(offset);
|
||||
this.name = name;
|
||||
this.modifier = modifier;
|
||||
this.returnType = returnType;
|
||||
this.parameterlist = parameterList;
|
||||
this.block = block;
|
||||
this.generics = gtvDeclarations;
|
||||
this.isInherited = isInherited;
|
||||
}
|
||||
|
||||
public ParameterList getParameterList() {
|
||||
|
@ -3,8 +3,11 @@ package de.dhbwstuttgart.syntaxtree.factory;
|
||||
import java.lang.reflect.*;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||
import de.dhbwstuttgart.parser.NullToken;
|
||||
@ -35,8 +38,15 @@ public class ASTFactory {
|
||||
for(java.lang.reflect.Constructor constructor : jreClass.getConstructors()){
|
||||
konstruktoren.add(createConstructor(constructor, jreClass));
|
||||
}
|
||||
for(java.lang.reflect.Method method : jreClass.getMethods()){
|
||||
methoden.add(createMethod(method, jreClass));
|
||||
Set<java.lang.reflect.Method> allMethods = new HashSet<>(Arrays.asList(jreClass.getMethods()));
|
||||
Set<java.lang.reflect.Method> allDeclaredMethods = new HashSet<>(Arrays.asList(jreClass.getDeclaredMethods()));
|
||||
Set<java.lang.reflect.Method> allInheritedMethods = new HashSet<>(allMethods);
|
||||
allInheritedMethods.removeAll(allDeclaredMethods);
|
||||
for(java.lang.reflect.Method method : allDeclaredMethods){
|
||||
methoden.add(createMethod(method, jreClass, false));
|
||||
}
|
||||
for(java.lang.reflect.Method method : allInheritedMethods){
|
||||
methoden.add(createMethod(method, jreClass, true));
|
||||
}
|
||||
List<Field> felder = new ArrayList<>();
|
||||
for(java.lang.reflect.Field field : jreClass.getDeclaredFields()){
|
||||
@ -102,7 +112,7 @@ public class ASTFactory {
|
||||
return new de.dhbwstuttgart.syntaxtree.Constructor(modifier, name,returnType, parameterList, block, gtvDeclarations, offset /*, new ArrayList<>() geloescht PL 2018-11-24 */);
|
||||
}
|
||||
|
||||
public static Method createMethod(java.lang.reflect.Method jreMethod, java.lang.Class inClass){
|
||||
public static Method createMethod(java.lang.reflect.Method jreMethod, java.lang.Class inClass, Boolean isInherited){
|
||||
String name = jreMethod.getName();
|
||||
RefTypeOrTPHOrWildcardOrGeneric returnType;
|
||||
Type jreRetType;
|
||||
@ -126,7 +136,7 @@ public class ASTFactory {
|
||||
GenericDeclarationList gtvDeclarations = createGenerics(jreMethod.getTypeParameters(), inClass, jreMethod.getName());
|
||||
Token offset = new NullToken();
|
||||
|
||||
return new Method(jreMethod.getModifiers(), name,returnType, parameterList, block, gtvDeclarations, offset);
|
||||
return new Method(jreMethod.getModifiers(), name,returnType, parameterList, block, gtvDeclarations, offset, isInherited);
|
||||
}
|
||||
|
||||
public static GenericDeclarationList createGenerics(TypeVariable[] typeParameters, Class context, String methodName){
|
||||
|
@ -153,8 +153,12 @@ public class UnifyTypeFactory {
|
||||
return constraints.map(UnifyTypeFactory::convert);
|
||||
}
|
||||
|
||||
//NEVER USED
|
||||
public static Constraint<UnifyPair> convert(Constraint<Pair> constraint){
|
||||
return constraint.stream().map(UnifyTypeFactory::convert).collect(Collectors.toCollection(Constraint::new));
|
||||
Constraint<UnifyPair> unifyPairConstraint = constraint.stream()
|
||||
.map(UnifyTypeFactory::convert)
|
||||
.collect(Collectors.toCollection( () -> new Constraint<UnifyPair> (constraint.isInherited(), convert(constraint.getExtendConstraint()))));
|
||||
return unifyPairConstraint;
|
||||
}
|
||||
|
||||
public static UnifyPair convert(Pair p) {
|
||||
|
@ -7,6 +7,7 @@ import de.dhbwstuttgart.syntaxtree.type.*;
|
||||
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.Iterator;
|
||||
import java.util.Optional;
|
||||
|
||||
public class OutputGenerator implements ASTVisitor{
|
||||
private static final String TAB = " ";
|
||||
@ -123,6 +124,11 @@ public class OutputGenerator implements ASTVisitor{
|
||||
f.accept(this);
|
||||
out.append("\n");
|
||||
}
|
||||
Optional<Constructor> fI;
|
||||
if ((fI = classOrInterface.getfieldInitializations()).isPresent()) {
|
||||
out.append("Initializations:");
|
||||
fI.get().accept(this);
|
||||
}
|
||||
for(Method m : classOrInterface.getMethods()){
|
||||
out.append(tabs);
|
||||
m.accept(this);
|
||||
|
@ -17,13 +17,15 @@ public class MethodAssumption extends Assumption{
|
||||
private ClassOrInterface receiver;
|
||||
private RefTypeOrTPHOrWildcardOrGeneric retType;
|
||||
List<? extends RefTypeOrTPHOrWildcardOrGeneric> params;
|
||||
private final Boolean isInherited;
|
||||
|
||||
public MethodAssumption(ClassOrInterface receiver, RefTypeOrTPHOrWildcardOrGeneric retType,
|
||||
List<? extends RefTypeOrTPHOrWildcardOrGeneric> params, TypeScope scope){
|
||||
List<? extends RefTypeOrTPHOrWildcardOrGeneric> params, TypeScope scope, Boolean isInherited){
|
||||
super(scope);
|
||||
this.receiver = receiver;
|
||||
this.retType = retType;
|
||||
this.params = params;
|
||||
this.isInherited = isInherited;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -70,4 +72,8 @@ public class MethodAssumption extends Assumption{
|
||||
|
||||
return receiverType;
|
||||
}
|
||||
|
||||
public Boolean isInherited() {
|
||||
return isInherited;
|
||||
}
|
||||
}
|
||||
|
@ -7,4 +7,47 @@ import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class Constraint<A> extends HashSet<A> {
|
||||
private static final long serialVersionUID = 1L;
|
||||
private Boolean isInherited = false;//wird nur für die Method-Constraints benoetigt
|
||||
private Constraint<A> extendConstraint = null;
|
||||
|
||||
public Constraint() {
|
||||
super();
|
||||
}
|
||||
|
||||
public Constraint(Boolean isInherited) {
|
||||
this.isInherited = isInherited;
|
||||
}
|
||||
|
||||
public Constraint(Boolean isInherited, Constraint<A> extendConstraint) {
|
||||
this.isInherited = isInherited;
|
||||
this.extendConstraint = extendConstraint;
|
||||
}
|
||||
|
||||
public void setIsInherited(Boolean isInherited) {
|
||||
this.isInherited = isInherited;
|
||||
}
|
||||
|
||||
public Boolean isInherited() {
|
||||
return isInherited;
|
||||
}
|
||||
|
||||
public Constraint<A> getExtendConstraint() {
|
||||
return extendConstraint;
|
||||
}
|
||||
|
||||
public void setExtendConstraint(Constraint<A> c) {
|
||||
extendConstraint = c;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return super.toString() + " isInherited = " + isInherited
|
||||
//" + extendsContraint: " + (extendConstraint != null ? extendConstraint.toStringBase() : "null" )
|
||||
+ "\n" ;
|
||||
}
|
||||
|
||||
public String toStringBase() {
|
||||
return super.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -45,16 +45,49 @@ public class ConstraintSet<A> {
|
||||
return new GuavaSetOperations().cartesianProduct(allConstraints);
|
||||
}
|
||||
|
||||
public <B> ConstraintSet<B> map(Function<? super A,? extends B> o) {
|
||||
public <B> ConstraintSet<B> map(Function<? super A, ? extends B> o) {
|
||||
Hashtable<Constraint<A>,Constraint<B>> CSA2CSB = new Hashtable<>();
|
||||
ConstraintSet<B> ret = new ConstraintSet<>();
|
||||
ret.undConstraints = undConstraints.stream().map(o).collect(Collectors.toCollection(Constraint<B>::new));
|
||||
List<Set<Constraint<B>>> newOder = new ArrayList<>();
|
||||
/*
|
||||
for(Set<Constraint<A>> oderConstraint : oderConstraints){
|
||||
oderConstraint.forEach(as -> {
|
||||
Constraint<B> newConst = as.stream()
|
||||
.map(o)
|
||||
.collect(Collectors.toCollection(
|
||||
() -> new Constraint<B> (as.isInherited())));
|
||||
CSA2CSB.put(as, newConst);} );
|
||||
}
|
||||
*/
|
||||
|
||||
for(Set<Constraint<A>> oderConstraint : oderConstraints){
|
||||
newOder.add(
|
||||
oderConstraint.parallelStream().map((Constraint<A> as) ->
|
||||
as.stream().map(o).collect(Collectors.toCollection(Constraint<B>::new))).collect(Collectors.toSet())
|
||||
oderConstraint.parallelStream().map((Constraint<A> as) -> {
|
||||
|
||||
Constraint<B> newConst = as.stream()
|
||||
.map(o)
|
||||
.collect(Collectors.toCollection((as.getExtendConstraint() != null)
|
||||
? () -> new Constraint<B> (as.isInherited(),
|
||||
as.getExtendConstraint().stream().map(o).collect(Collectors.toCollection(Constraint::new)))
|
||||
: () -> new Constraint<B> (as.isInherited())
|
||||
));
|
||||
|
||||
//CSA2CSB.put(as, newConst);
|
||||
|
||||
return newConst;
|
||||
|
||||
/*
|
||||
Constraint<B> bs = CSA2CSB.get(as);
|
||||
if (as.getExtendConstraint() != null) {
|
||||
bs.setExtendConstraint(CSA2CSB.get(as.getExtendConstraint()));
|
||||
}
|
||||
return bs;
|
||||
*/
|
||||
}).collect(Collectors.toSet())
|
||||
);
|
||||
}
|
||||
|
||||
ret.oderConstraints = newOder;
|
||||
return ret;
|
||||
}
|
||||
|
@ -16,8 +16,10 @@ import de.dhbwstuttgart.typeinference.assumptions.FunNClass;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.MethodAssumption;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceBlockInformation;
|
||||
import de.dhbwstuttgart.typeinference.constraints.*;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.ExtendsType;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
@ -168,7 +170,19 @@ public class TYPEStmt implements StatementVisitor{
|
||||
Set<Constraint<Pair>> methodConstraints = new HashSet<>();
|
||||
for(MethodAssumption m : this.getMethods(methodCall.name, methodCall.arglist, info)){
|
||||
GenericsResolver resolver = getResolverInstance();
|
||||
methodConstraints.add(generateConstraint(methodCall, m, info, resolver));
|
||||
Constraint<Pair> oneMethodConstraint = generateConstraint(methodCall, m, info, resolver);
|
||||
methodConstraints.add(oneMethodConstraint);
|
||||
|
||||
Constraint<Pair> extendsOneMethodConstraint = oneMethodConstraint.stream()
|
||||
.map(x -> (x.TA1 instanceof TypePlaceholder &&
|
||||
x.GetOperator() == PairOperator.EQUALSDOT &&
|
||||
!(x.TA2 instanceof TypePlaceholder))
|
||||
? new Pair(x.TA1, new ExtendsWildcardType(x.TA2, x.TA2.getOffset()), PairOperator.EQUALSDOT)
|
||||
: x)
|
||||
.collect(Collectors.toCollection(() -> new Constraint<Pair>(oneMethodConstraint.isInherited())));
|
||||
oneMethodConstraint.setExtendConstraint(extendsOneMethodConstraint);
|
||||
extendsOneMethodConstraint.setExtendConstraint(oneMethodConstraint);
|
||||
methodConstraints.add(extendsOneMethodConstraint);
|
||||
}
|
||||
if(methodConstraints.size()<1){
|
||||
throw new TypeinferenceException("Methode "+methodCall.name+" ist nicht vorhanden!",methodCall.getOffset());
|
||||
@ -560,7 +574,7 @@ public class TYPEStmt implements StatementVisitor{
|
||||
|
||||
protected Constraint<Pair> generateConstraint(MethodCall forMethod, MethodAssumption assumption,
|
||||
TypeInferenceBlockInformation info, GenericsResolver resolver){
|
||||
Constraint<Pair> methodConstraint = new Constraint<>();
|
||||
Constraint<Pair> methodConstraint = new Constraint<>(assumption.isInherited());
|
||||
ClassOrInterface receiverCl = assumption.getReceiver();
|
||||
/*
|
||||
List<RefTypeOrTPHOrWildcardOrGeneric> params = new ArrayList<>();
|
||||
@ -626,7 +640,7 @@ public class TYPEStmt implements StatementVisitor{
|
||||
public RefTypeOrTPHOrWildcardOrGeneric getReturnType() {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}));
|
||||
}, false));
|
||||
}
|
||||
for(ClassOrInterface cl : info.getAvailableClasses()){
|
||||
for(Method m : cl.getMethods()){
|
||||
@ -635,7 +649,7 @@ public class TYPEStmt implements StatementVisitor{
|
||||
RefTypeOrTPHOrWildcardOrGeneric retType = m.getReturnType();//info.checkGTV(m.getReturnType());
|
||||
|
||||
ret.add(new MethodAssumption(cl, retType, convertParams(m.getParameterList(),info),
|
||||
createTypeScope(cl, m)));
|
||||
createTypeScope(cl, m), m.isInherited));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -670,7 +684,7 @@ public class TYPEStmt implements StatementVisitor{
|
||||
for(Method m : cl.getConstructors()){
|
||||
if(m.getParameterList().getFormalparalist().size() == argList.getArguments().size()){
|
||||
ret.add(new MethodAssumption(cl, ofType, convertParams(m.getParameterList(),
|
||||
info), createTypeScope(cl, m)));
|
||||
info), createTypeScope(cl, m), m.isInherited));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -26,11 +26,15 @@ 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.constraints.Constraint;
|
||||
import de.dhbwstuttgart.typeinference.unify.distributeVariance;
|
||||
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.Writer;
|
||||
import java.io.OutputStreamWriter;
|
||||
|
||||
import org.apache.commons.io.output.NullOutputStream;
|
||||
|
||||
/**
|
||||
* Implementation of the type inference rules.
|
||||
@ -43,6 +47,7 @@ public class RuleSet implements IRuleSet{
|
||||
|
||||
public RuleSet() {
|
||||
super();
|
||||
logFile = new OutputStreamWriter(new NullOutputStream());
|
||||
}
|
||||
|
||||
RuleSet(Writer logFile) {
|
||||
@ -627,7 +632,7 @@ public class RuleSet implements IRuleSet{
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Set<UnifyPair>> subst(Set<UnifyPair> pairs, List<Set<Set<UnifyPair>>> oderConstraints) {
|
||||
public Optional<Set<UnifyPair>> subst(Set<UnifyPair> pairs, List<Set<Constraint<UnifyPair>>> oderConstraints) {
|
||||
HashMap<UnifyType, Integer> typeMap = new HashMap<>();
|
||||
|
||||
Stack<UnifyType> occuringTypes = new Stack<>();
|
||||
@ -674,16 +679,13 @@ public class RuleSet implements IRuleSet{
|
||||
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<UnifyPair>,? extends HashSet<UnifyPair>> applyUni = b -> b.stream().map(
|
||||
x -> uni.apply(pair,x)).collect(Collectors.toCollection(HashSet::new));
|
||||
List<Set<Set<UnifyPair>>> oderConstraintsRet = new ArrayList<>();
|
||||
for(Set<Set<UnifyPair>> oc : oderConstraints) {
|
||||
//Set<Set<UnifyPair>> ocRet = new HashSet<>();
|
||||
//for(Set<UnifyPair> cs : oc) {
|
||||
Set<Set<UnifyPair>> csRet = oc.stream().map(applyUni).collect(Collectors.toCollection(HashSet::new));
|
||||
oderConstraintsRet.add(csRet);
|
||||
//}
|
||||
}
|
||||
Function<? super Constraint<UnifyPair>,? extends Constraint<UnifyPair>> applyUni = b -> b.stream().map(
|
||||
x -> uni.apply(pair,x)).collect(Collectors.toCollection((b.getExtendConstraint() != null)
|
||||
? () -> new Constraint<UnifyPair>(
|
||||
b.isInherited(),
|
||||
b.getExtendConstraint().stream().map(x -> uni.apply(pair,x)).collect(Collectors.toCollection(Constraint::new)))
|
||||
: () -> new Constraint<UnifyPair>(b.isInherited())
|
||||
));
|
||||
oderConstraints.replaceAll(oc -> oc.stream().map(applyUni).collect(Collectors.toCollection(HashSet::new)));
|
||||
/*
|
||||
oderConstraints = oderConstraints.stream().map(
|
||||
|
@ -28,7 +28,7 @@ public class TypeUnify {
|
||||
* @param cons
|
||||
* @return
|
||||
*/
|
||||
public Set<Set<UnifyPair>> unify(Set<UnifyPair> undConstrains, List<Set<Set<UnifyPair>>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModel ret, UnifyTaskModel usedTasks) {
|
||||
public Set<Set<UnifyPair>> unify(Set<UnifyPair> undConstrains, List<Set<Constraint<UnifyPair>>> 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);
|
||||
@ -54,7 +54,7 @@ public class TypeUnify {
|
||||
* @param ret
|
||||
* @return
|
||||
*/
|
||||
public UnifyResultModel unifyAsync(Set<UnifyPair> undConstrains, List<Set<Set<UnifyPair>>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModel ret, UnifyTaskModel usedTasks) {
|
||||
public UnifyResultModel unifyAsync(Set<UnifyPair> undConstrains, List<Set<Constraint<UnifyPair>>> 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);
|
||||
@ -72,7 +72,7 @@ public class TypeUnify {
|
||||
* @param ret
|
||||
* @return
|
||||
*/
|
||||
public UnifyResultModel unifyParallel(Set<UnifyPair> undConstrains, List<Set<Set<UnifyPair>>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModel ret, UnifyTaskModel usedTasks) {
|
||||
public UnifyResultModel unifyParallel(Set<UnifyPair> undConstrains, List<Set<Constraint<UnifyPair>>> 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);
|
||||
@ -105,7 +105,7 @@ public class TypeUnify {
|
||||
* @param cons
|
||||
* @return
|
||||
*/
|
||||
public Set<Set<UnifyPair>> unifyOderConstraints(Set<UnifyPair> undConstrains, List<Set<Set<UnifyPair>>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModel ret, UnifyTaskModel usedTasks) {
|
||||
public Set<Set<UnifyPair>> unifyOderConstraints(Set<UnifyPair> undConstrains, List<Set<Constraint<UnifyPair>>> 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<Set<UnifyPair>> res = unifyTask.compute();
|
||||
try {
|
||||
|
@ -18,7 +18,7 @@ public class TypeUnify2Task extends TypeUnifyTask {
|
||||
|
||||
Set<Set<UnifyPair>> setToFlatten;
|
||||
|
||||
public TypeUnify2Task(Set<Set<UnifyPair>> setToFlatten, Set<UnifyPair> eq, List<Set<Set<UnifyPair>>> oderConstraints, Set<UnifyPair> nextSetElement, IFiniteClosure fc, boolean parallel, Writer logFile, Boolean log, int rekTiefe, UnifyResultModel urm, UnifyTaskModel usedTasks) {
|
||||
public TypeUnify2Task(Set<Set<UnifyPair>> setToFlatten, Set<UnifyPair> eq, List<Set<Constraint<UnifyPair>>> oderConstraints, Set<UnifyPair> nextSetElement, IFiniteClosure fc, boolean parallel, Writer logFile, Boolean log, int rekTiefe, UnifyResultModel urm, UnifyTaskModel usedTasks) {
|
||||
super(eq, oderConstraints, fc, parallel, logFile, log, rekTiefe, urm, usedTasks);
|
||||
this.setToFlatten = setToFlatten;
|
||||
this.nextSetElement = nextSetElement;
|
||||
|
@ -34,6 +34,7 @@ import de.dhbwstuttgart.typeinference.unify.interfaces.ISetOperations;
|
||||
import de.dhbwstuttgart.typeinference.unify.interfaces.IUnify;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.ExtendsType;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.FunNType;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.OrderingExtend;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.ReferenceType;
|
||||
@ -101,11 +102,11 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
|
||||
protected Set<UnifyPair> eq; //und-constraints
|
||||
|
||||
protected List<Set<Set<UnifyPair>>> oderConstraintsField;
|
||||
protected List<Set<Constraint<UnifyPair>>> oderConstraintsField;
|
||||
|
||||
protected IFiniteClosure fc;
|
||||
|
||||
protected Ordering<Set<UnifyPair>> oup;
|
||||
protected OrderingExtend<Set<UnifyPair>> oup;
|
||||
|
||||
protected boolean parallel;
|
||||
|
||||
@ -146,7 +147,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
*/
|
||||
|
||||
|
||||
public TypeUnifyTask(Set<UnifyPair> eq, List<Set<Set<UnifyPair>>> oderConstraints, IFiniteClosure fc, boolean parallel, Writer logFile, Boolean log, int rekTiefe, UnifyResultModel urm, UnifyTaskModel usedTasks) {
|
||||
public TypeUnifyTask(Set<UnifyPair> eq, List<Set<Constraint<UnifyPair>>> oderConstraints, IFiniteClosure fc, boolean parallel, Writer logFile, Boolean log, int rekTiefe, UnifyResultModel urm, UnifyTaskModel usedTasks) {
|
||||
synchronized (this) {
|
||||
this.eq = eq;
|
||||
//this.oderConstraints = oderConstraints.stream().map(x -> x.stream().map(y -> new HashSet<>(y)).collect(Collectors.toSet(HashSet::new))).collect(Collectors.toList(ArrayList::new));
|
||||
@ -173,9 +174,9 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
thNo = totalnoOfThread;
|
||||
writeLog("thNo2 " + thNo);
|
||||
try {
|
||||
this.logFile = //new OutputStreamWriter(new NullOutputStream());
|
||||
this.logFile = new OutputStreamWriter(new NullOutputStream());
|
||||
//new FileWriter(new File(System.getProperty("user.dir")+"/src/test/resources/logFiles/"+"Thread_"+thNo));
|
||||
new FileWriter(new File(System.getProperty("user.dir")+"/logFiles/"+"Thread_"+thNo));
|
||||
//new FileWriter(new File(System.getProperty("user.dir")+"/logFiles/"+"Thread_"+thNo));
|
||||
logFile.write("");
|
||||
}
|
||||
catch (IOException e) {
|
||||
@ -247,7 +248,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
oderConstraintsField.stream()
|
||||
.filter(x -> x.size()==1)
|
||||
.map(y -> y.stream().findFirst().get()).forEach(x -> neweq.addAll(x));
|
||||
ArrayList<Set<Set<UnifyPair>>> remainingOderconstraints = oderConstraintsField.stream()
|
||||
ArrayList<Set<Constraint<UnifyPair>>> remainingOderconstraints = oderConstraintsField.stream()
|
||||
.filter(x -> x.size()>1)
|
||||
.collect(Collectors.toCollection(ArrayList::new));
|
||||
Set<Set<UnifyPair>> res = unify(neweq, remainingOderconstraints, fc, parallel, rekTiefeField, true);
|
||||
@ -292,7 +293,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
* @param fc The finite closure
|
||||
* @return The set of all principal type unifiers
|
||||
*/
|
||||
protected Set<Set<UnifyPair>> unify(final Set<UnifyPair> eq, List<Set<Set<UnifyPair>>> oderConstraints, IFiniteClosure fc, boolean parallel, int rekTiefe, Boolean finalresult) {
|
||||
protected Set<Set<UnifyPair>> unify(final Set<UnifyPair> eq, List<Set<Constraint<UnifyPair>>> oderConstraints, IFiniteClosure fc, boolean parallel, int rekTiefe, Boolean finalresult) {
|
||||
//Set<UnifyPair> aas = eq.stream().filter(x -> x.getLhsType().getName().equals("AA") //&& x.getPairOp().equals(PairOperator.SMALLERDOT)
|
||||
// ).collect(Collectors.toCollection(HashSet::new));
|
||||
//writeLog(nOfUnify.toString() + " AA: " + aas.toString());
|
||||
@ -357,7 +358,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
|
||||
// There are up to 10 toplevel set. 8 of 10 are the result of the
|
||||
// cartesian product of the sets created by pattern matching.
|
||||
List<Set<Set<UnifyPair>>> topLevelSets = new ArrayList<>();
|
||||
List<Set<? extends Set<UnifyPair>>> topLevelSets = new ArrayList<>();
|
||||
|
||||
//System.out.println(eq2s);
|
||||
|
||||
@ -385,8 +386,8 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
Set<UnifyPair> undefinedPairs = new HashSet<>();
|
||||
if (printtag) System.out.println("eq2s " + eq2s);
|
||||
//writeLog("BufferSet: " + bufferSet.toString()+"\n");
|
||||
List<Set<Set<UnifyPair>>> oderConstraintsOutput = new ArrayList<>();//new ArrayList<>(oderConstraints);
|
||||
Set<Set<Set<Set<UnifyPair>>>> secondLevelSets = calculatePairSets(eq2s, oderConstraints, fc, undefinedPairs, oderConstraintsOutput);
|
||||
List<Set<Constraint<UnifyPair>>> oderConstraintsOutput = new ArrayList<>();//new ArrayList<>(oderConstraints);
|
||||
Set<Set<Set<? extends Set<UnifyPair>>>> secondLevelSets = calculatePairSets(eq2s, oderConstraints, fc, undefinedPairs, oderConstraintsOutput);
|
||||
//PL 2017-09-20: Im calculatePairSets wird möglicherweise O .< java.lang.Integer
|
||||
//nicht ausgewertet Faculty Beispiel im 1. Schritt
|
||||
//PL 2017-10-03 geloest, muesste noch mit FCs mit kleineren
|
||||
@ -434,8 +435,8 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
*/
|
||||
|
||||
//Alternative KEIN KARTESISCHES PRODUKT der secondlevel Ebene bilden
|
||||
for(Set<Set<Set<UnifyPair>>> secondLevelSet : secondLevelSets) {
|
||||
for (Set<Set<UnifyPair>> secondlevelelem : secondLevelSet) {
|
||||
for(Set<Set<? extends Set<UnifyPair>>> secondLevelSet : secondLevelSets) {
|
||||
for (Set<? extends Set<UnifyPair>> secondlevelelem : secondLevelSet) {
|
||||
topLevelSets.add(secondlevelelem);
|
||||
}
|
||||
}
|
||||
@ -450,7 +451,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
}
|
||||
|
||||
|
||||
Set<Set<UnifyPair>> unify2(Set<Set<UnifyPair>> setToFlatten, Set<UnifyPair> eq, List<Set<Set<UnifyPair>>> oderConstraints, IFiniteClosure fc, boolean parallel, int rekTiefe, Boolean finalresult) {
|
||||
Set<Set<UnifyPair>> unify2(Set<Set<UnifyPair>> setToFlatten, Set<UnifyPair> eq, List<Set<Constraint<UnifyPair>>> oderConstraints, IFiniteClosure fc, boolean parallel, int rekTiefe, Boolean finalresult) {
|
||||
//Aufruf von computeCartesianRecursive ENDE
|
||||
|
||||
//keine Ahnung woher das kommt
|
||||
@ -482,7 +483,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
//writeLog("vor Subst: " + eqPrime);
|
||||
writeLog("vor Subst: " + oderConstraints);
|
||||
String ocString = oderConstraints.toString();
|
||||
List<Set<Set<UnifyPair>>> newOderConstraints = new ArrayList<>(oderConstraints);
|
||||
List<Set<Constraint<UnifyPair>>> newOderConstraints = new ArrayList<>(oderConstraints);
|
||||
Optional<Set<UnifyPair>> eqPrimePrime = rules.subst(eqPrime, newOderConstraints);
|
||||
Set<Set<UnifyPair>> unifyres1 = null;
|
||||
Set<Set<UnifyPair>> unifyres2 = null;
|
||||
@ -572,23 +573,24 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
|
||||
|
||||
|
||||
Set<Set<UnifyPair>> computeCartesianRecursive(Set<Set<UnifyPair>> fstElems, ArrayList<Set<Set<UnifyPair>>> topLevelSets, Set<UnifyPair> eq, List<Set<Set<UnifyPair>>> oderConstraints, IFiniteClosure fc, boolean parallel, int rekTiefe, Boolean finalresult) {
|
||||
Set<Set<UnifyPair>> computeCartesianRecursive(Set<Set<UnifyPair>> fstElems, ArrayList<Set<? extends Set<UnifyPair>>> topLevelSets, Set<UnifyPair> eq, List<Set<Constraint<UnifyPair>>> oderConstraints, IFiniteClosure fc, boolean parallel, int rekTiefe, Boolean finalresult) {
|
||||
//ArrayList<Set<Set<UnifyPair>>> remainingSets = new ArrayList<>(topLevelSets);
|
||||
|
||||
fstElems.addAll(topLevelSets.stream()
|
||||
.filter(x -> x.size()==1)
|
||||
.map(y -> y.stream().findFirst().get())
|
||||
.collect(Collectors.toCollection(HashSet::new)));
|
||||
ArrayList<Set<Set<UnifyPair>>> remainingSets = topLevelSets.stream()
|
||||
ArrayList<Set<? extends Set<UnifyPair>>> remainingSets = topLevelSets.stream()
|
||||
.filter(x -> x.size()>1)
|
||||
.collect(Collectors.toCollection(ArrayList::new));
|
||||
if (remainingSets.isEmpty()) {//Alle Elemente sind 1-elementig
|
||||
Set<Set<UnifyPair>> result = unify2(fstElems, eq, oderConstraints, fc, parallel, rekTiefe, finalresult);
|
||||
return result;
|
||||
}
|
||||
Set<Set<UnifyPair>> nextSet = remainingSets.remove(0);
|
||||
writeLog("nextSet: " + nextSet.toString());
|
||||
Set<? extends Set<UnifyPair>> nextSet = remainingSets.remove(0);
|
||||
//writeLog("nextSet: " + nextSet.toString());
|
||||
List<Set<UnifyPair>> nextSetasList =new ArrayList<>(nextSet);
|
||||
/*
|
||||
try {
|
||||
//List<Set<UnifyPair>>
|
||||
//nextSetasList = oup.sortedCopy(nextSet);//new ArrayList<>(nextSet);
|
||||
@ -596,11 +598,13 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
catch (java.lang.IllegalArgumentException e) {
|
||||
System.out.print("");
|
||||
}
|
||||
*/
|
||||
Set<Set<UnifyPair>> result = new HashSet<>();
|
||||
int variance = 0;
|
||||
|
||||
ArrayList<UnifyPair> zeroNextElem = new ArrayList<>(nextSetasList.get(0));
|
||||
UnifyPair fstBasePair = zeroNextElem.remove(0).getBasePair();
|
||||
Boolean oderConstraint = false;
|
||||
|
||||
if (fstBasePair != null) {
|
||||
Boolean sameBase = true;
|
||||
@ -620,50 +624,47 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
}
|
||||
}
|
||||
else {
|
||||
variance = 2;
|
||||
//variance = 2;
|
||||
oderConstraint = true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
//variance = 2;
|
||||
oderConstraint = true;
|
||||
}
|
||||
|
||||
if (oderConstraint) {//Varianz-Bestimmung Oder-Constraints
|
||||
if (printtag) System.out.println("nextSetasList " + nextSetasList);
|
||||
Optional<Integer> optVariance =
|
||||
nextSetasList.iterator()
|
||||
.next()
|
||||
.stream()
|
||||
.filter(x -> x.getGroundBasePair().getLhsType() instanceof PlaceholderType &&
|
||||
! (x.getRhsType() instanceof PlaceholderType) &&
|
||||
x.getPairOp() == PairOperator.EQUALSDOT)
|
||||
.map(x ->
|
||||
((PlaceholderType)x.getGroundBasePair().getLhsType()).getVariance())
|
||||
.findAny();
|
||||
//Fuer Operatorenaufrufe wird variance auf 2 gesetzt.
|
||||
//da kein Receiver existiert also keon x.getGroundBasePair().getLhsType() instanceof PlaceholderType
|
||||
//Es werden alle Elemente des Kartesischen Produkts abgearbeitet
|
||||
variance = optVariance.isPresent() ? optVariance.get() : 2;
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
variance = 2;
|
||||
}
|
||||
//if (variance == 1 && nextSetasList.size() > 1) {
|
||||
// List<Set<UnifyPair>> al = new ArrayList<>(nextSetasList.size());
|
||||
// for (int ii = 0; ii < nextSetasList.size();ii++) {
|
||||
// al.add(0,nextSetasList.get(ii));
|
||||
// }
|
||||
// nextSetasList = al;
|
||||
//}
|
||||
//Set<UnifyPair> a = nextSetasListIt.next();
|
||||
/*if (nextSetasList.size()>1) {zu loeschen
|
||||
if (nextSetasList.iterator().next().iterator().next().getLhsType().getName().equals("D"))
|
||||
System.out.print("");
|
||||
if (variance == 1) {
|
||||
a_next = oup.max(nextSetasList.iterator());
|
||||
}
|
||||
else if (variance == -1) {
|
||||
a_next = oup.min(nextSetasList.iterator());
|
||||
}
|
||||
else if (variance == 0) {
|
||||
a_next = nextSetasList.iterator().next();
|
||||
}
|
||||
}
|
||||
else {
|
||||
a_next = nextSetasList.iterator().next();
|
||||
}
|
||||
*/
|
||||
if (!nextSetasList.iterator().hasNext())
|
||||
System.out.print("");
|
||||
if (nextSetasList.iterator().next().stream().filter(x -> x.getLhsType().getName().equals("D")).findFirst().isPresent() && nextSetasList.size()>1)
|
||||
System.out.print("");
|
||||
writeLog("nextSetasList: " + nextSetasList.toString());
|
||||
//writeLog("nextSetasList: " + nextSetasList.toString());
|
||||
Set<UnifyPair> nextSetElem = nextSetasList.get(0);
|
||||
writeLog("BasePair1: " + nextSetElem + " " + nextSetElem.iterator().next().getBasePair());
|
||||
//writeLog("BasePair1: " + nextSetElem + " " + nextSetElem.iterator().next().getBasePair());
|
||||
|
||||
/* sameEqSet-Bestimmung: Wenn a = ty \in nextSet dann enthaelt sameEqSet alle Paare a < ty1 oder ty2 < a aus fstElems */
|
||||
Set<UnifyPair> sameEqSet = new HashSet<>();
|
||||
if (variance != 2) {
|
||||
Optional<UnifyPair> optOrigPair = nextSetElem.stream().filter(x -> (
|
||||
Optional<UnifyPair> optOrigPair = null;
|
||||
//if (variance != 2) {
|
||||
if (!oderConstraint) {
|
||||
optOrigPair = nextSetElem.stream().filter(x -> (
|
||||
//x.getBasePair() != null && ist gegeben wenn variance != 2
|
||||
//x.getBasePair().getPairOp().equals(PairOperator.SMALLERDOT) &&
|
||||
(x.getPairOp().equals(PairOperator.EQUALSDOT)
|
||||
@ -696,12 +697,23 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
Set<UnifyPair> a = null;
|
||||
while (nextSetasList.size() > 0) { //(nextSetasList.size() != 0) {
|
||||
Set<UnifyPair> a_last = a;
|
||||
|
||||
//Liste der Faelle für die parallele Verarbeitung
|
||||
List<Set<UnifyPair>> nextSetasListRest = new ArrayList<>();
|
||||
//List<Set<UnifyPair>> nextSetasListRestMin = new ArrayList<>();
|
||||
//List<Set<UnifyPair>> nextSetasListRestOder = new ArrayList<>();
|
||||
|
||||
//Liste der Faelle, bei dem Receiver jeweils "? extends" enthaelt bzw. nicht enthaelt
|
||||
//In der Regel ein Element
|
||||
List<Set<UnifyPair>> nextSetasListOderConstraints = new ArrayList<>();
|
||||
|
||||
writeLog("nextSet: " + nextSet.toString());
|
||||
writeLog("nextSetasList: " + nextSetasList.toString());
|
||||
if (variance == 1) {
|
||||
a = oup.max(nextSetasList.iterator());
|
||||
nextSetasList.remove(a);
|
||||
if (oderConstraint) {
|
||||
nextSetasListOderConstraints.add(((Constraint<UnifyPair>)a).getExtendConstraint());
|
||||
}
|
||||
writeLog("nextSetasListOderConstraints 1: " + nextSetasListOderConstraints);
|
||||
nextSetasListRest = new ArrayList<>(nextSetasList);
|
||||
Iterator<Set<UnifyPair>> nextSetasListItRest = new ArrayList<Set<UnifyPair>>(nextSetasListRest).iterator();
|
||||
while (nextSetasListItRest.hasNext()) {
|
||||
@ -711,27 +723,17 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
nextSetasListRest.remove(a_next);
|
||||
}
|
||||
}
|
||||
//Alle maximale Elemente in nextSetasListRest bestimmen
|
||||
List<Set<UnifyPair>> nextSetasListRestTest;
|
||||
do {
|
||||
nextSetasListRestTest = new ArrayList<Set<UnifyPair>>(nextSetasListRest);
|
||||
if (!nextSetasListRest.isEmpty()) {
|
||||
Set<UnifyPair> max = oup.max(nextSetasListRest.iterator());
|
||||
Iterator<Set<UnifyPair>> nextSetasListItRest2 = new ArrayList<Set<UnifyPair>>(nextSetasListRest).iterator();
|
||||
while (nextSetasListItRest2.hasNext()) {
|
||||
Set<UnifyPair> a_nextRest = nextSetasListItRest2.next();
|
||||
if (//a.equals(a_next) ||
|
||||
(oup.compare(max, a_nextRest) == 1)) {
|
||||
nextSetasListRest.remove(a_nextRest);
|
||||
}
|
||||
|
||||
}}
|
||||
} while(!nextSetasListRestTest.equals(nextSetasListRest));
|
||||
|
||||
//Alle maximale Elemente in nextSetasListRest bestimmen
|
||||
nextSetasListRest = oup.maxElements(nextSetasListRest);
|
||||
}
|
||||
else if (variance == -1) {
|
||||
a = oup.min(nextSetasList.iterator());
|
||||
writeLog("Min: a in " + variance + " "+ a);
|
||||
if (oderConstraint) {
|
||||
nextSetasListOderConstraints.add(((Constraint<UnifyPair>)a).getExtendConstraint());
|
||||
}
|
||||
writeLog("nextSetasListOderConstraints -1: " + nextSetasListOderConstraints);
|
||||
nextSetasList.remove(a);
|
||||
nextSetasListRest = new ArrayList<>(nextSetasList);
|
||||
Iterator<Set<UnifyPair>> nextSetasListItRest = new ArrayList<Set<UnifyPair>>(nextSetasListRest).iterator();
|
||||
@ -743,50 +745,38 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
}
|
||||
}
|
||||
//Alle minimalen Elemente in nextSetasListRest bestimmen
|
||||
|
||||
List<Set<UnifyPair>> nextSetasListRestTest;
|
||||
do {
|
||||
nextSetasListRestTest = new ArrayList<Set<UnifyPair>>(nextSetasListRest);
|
||||
if (!nextSetasListRest.isEmpty()) {
|
||||
Set<UnifyPair> min = oup.min(nextSetasListRest.iterator());
|
||||
Iterator<Set<UnifyPair>> nextSetasListItRest2 = new ArrayList<Set<UnifyPair>>(nextSetasListRest).iterator();
|
||||
while (nextSetasListItRest2.hasNext()) {
|
||||
Set<UnifyPair> a_nextRest = nextSetasListItRest2.next();
|
||||
if (//a.equals(a_next) ||
|
||||
(oup.compare(min, a_nextRest) == -1)) {
|
||||
nextSetasListRest.remove(a_nextRest);
|
||||
}
|
||||
|
||||
}}
|
||||
} while(!nextSetasListRestTest.equals(nextSetasListRest));
|
||||
nextSetasListRest = oup.minElements(nextSetasListRest);
|
||||
}
|
||||
else if (variance == 2) {
|
||||
a = nextSetasList.remove(0);
|
||||
nextSetasListRest = new ArrayList<>(nextSetasList);
|
||||
}
|
||||
else if (variance == 0) {
|
||||
a = nextSetasList.remove(0);
|
||||
//wenn a <. theta dann ist ein maximales Element sehr wahrscheinlich
|
||||
//wenn theta <. a dann ist ein minimales Element sehr wahrscheinlich
|
||||
if (!oderConstraint && optOrigPair != null && optOrigPair.isPresent()) {
|
||||
if (optOrigPair.get().getBasePair().getLhsType() instanceof PlaceholderType) {
|
||||
a = oup.max(nextSetasList.iterator());
|
||||
}
|
||||
else {
|
||||
a = oup.min(nextSetasList.iterator());
|
||||
}
|
||||
nextSetasList.remove(a);
|
||||
}
|
||||
else {
|
||||
if (oderConstraint) {
|
||||
a = oup.max(nextSetasList.iterator());
|
||||
nextSetasList.remove(a);
|
||||
nextSetasListOderConstraints.add(((Constraint<UnifyPair>)a).getExtendConstraint());
|
||||
}
|
||||
else {
|
||||
a = nextSetasList.remove(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
//writeLog("nextSet: " + nextSetasList.toString()+ "\n");
|
||||
//nextSetasList.remove(a);
|
||||
/* zu loeschen
|
||||
if (nextSetasList.size() > 0) {
|
||||
if (nextSetasList.size()>1) {
|
||||
if (variance == 1) {
|
||||
a_next = oup.max(nextSetasList.iterator());
|
||||
}
|
||||
else if (variance == -1) {
|
||||
a_next = oup.min(nextSetasList.iterator());
|
||||
}
|
||||
else {
|
||||
a_next = nextSetasList.iterator().next();
|
||||
}
|
||||
}
|
||||
else {
|
||||
a_next = nextSetasList.iterator().next();
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
//PL 2018-03-01
|
||||
//TODO: 1. Maximum und Minimum unterscheiden
|
||||
//TODO: 2. compare noch für alle Elmemente die nicht X =. ty sind erweitern
|
||||
@ -803,7 +793,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
Set<Set<UnifyPair>> aParDef = new HashSet<>();
|
||||
|
||||
/* PL 2019-03-11 Anfang eingefuegt Vergleich mit anderen Paaren ggf. loeschen */
|
||||
if (variance != 2 && !sameEqSet.isEmpty()) {
|
||||
if (!oderConstraint && !sameEqSet.isEmpty()) {
|
||||
Optional<UnifyPair> optAPair = a.stream().filter(x -> (
|
||||
//x.getBasePair() != null && ist gegeben wenn variance != 2
|
||||
//x.getBasePair().getPairOp().equals(PairOperator.SMALLERDOT) &&
|
||||
@ -836,7 +826,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
Set<TypeUnify2Task> forks = new HashSet<>();
|
||||
Set<UnifyPair> newEqOrig = new HashSet<>(eq);
|
||||
Set<Set<UnifyPair>> newElemsOrig = new HashSet<>(elems);
|
||||
List<Set<Set<UnifyPair>>> newOderConstraintsOrig = new ArrayList<>(oderConstraints);
|
||||
List<Set<Constraint<UnifyPair>>> newOderConstraintsOrig = new ArrayList<>(oderConstraints);
|
||||
newElemsOrig.add(a);
|
||||
|
||||
/* FORK ANFANG */
|
||||
@ -861,10 +851,11 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
}
|
||||
|
||||
/* PL 2019-03-13 Anfang eingefuegt Vergleich mit anderen Paaren ggf. loeschen */
|
||||
Optional<UnifyPair> optAPair = nSaL.stream().filter(x -> (
|
||||
//x.getBasePair() != null && ist gegeben wenn variance != 2
|
||||
//x.getBasePair().getPairOp().equals(PairOperator.SMALLERDOT) &&
|
||||
(x.getPairOp().equals(PairOperator.EQUALSDOT)
|
||||
if (!oderConstraint) {//weiss nicht ob das wirklich stimmt
|
||||
Optional<UnifyPair> optAPair = nSaL.stream().filter(x -> (
|
||||
//x.getBasePair() != null && ist gegeben wenn variance != 2
|
||||
//x.getBasePair().getPairOp().equals(PairOperator.SMALLERDOT) &&
|
||||
(x.getPairOp().equals(PairOperator.EQUALSDOT)
|
||||
/*
|
||||
(x.getBasePair().getLhsType() instanceof PlaceholderType
|
||||
&& x.getLhsType().equals(x.getBasePair().getLhsType()))
|
||||
@ -876,21 +867,24 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
x.getLhsType().equals(x.getBasePair().getRhsType())
|
||||
).findFirst();
|
||||
|
||||
if (optAPair.isPresent()) {//basepair ist entweder a <. Ty oder ty <. a
|
||||
UnifyPair aPair = optAPair.get();
|
||||
//writeLog("optOrigPair: " + optOrigPair + " " + "aPair: " + aPair+ " " + "aPair.basePair(): " + aPair.getBasePair());
|
||||
writeLog("variance: " + new Integer(variance).toString() + "sameEqSet:" + sameEqSet);
|
||||
if (!sameEqSet.isEmpty() && !checkA(aPair, sameEqSet, elems, result)) {
|
||||
nSaL = null;
|
||||
noShortendElements++;
|
||||
continue;
|
||||
if (optAPair.isPresent()) {//basepair ist entweder a <. Ty oder ty <. a
|
||||
UnifyPair aPair = optAPair.get();
|
||||
//writeLog("optOrigPair: " + optOrigPair + " " + "aPair: " + aPair+ " " + "aPair.basePair(): " + aPair.getBasePair());
|
||||
writeLog("variance: " + new Integer(variance).toString() + "sameEqSet:" + sameEqSet);
|
||||
if (!sameEqSet.isEmpty() && !checkA(aPair, sameEqSet, elems, result)) {
|
||||
nSaL = null;
|
||||
noShortendElements++;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
/* PL 2019-03-13 Ende eingefuegt Vergleich mit anderen Paaren ggf. loeschen */
|
||||
|
||||
else {
|
||||
nextSetasListOderConstraints.add(((Constraint<UnifyPair>)nSaL).getExtendConstraint());
|
||||
}
|
||||
Set<UnifyPair> newEq = new HashSet<>(eq);
|
||||
Set<Set<UnifyPair>> newElems = new HashSet<>(elems);
|
||||
List<Set<Set<UnifyPair>>> newOderConstraints = new ArrayList<>(oderConstraints);
|
||||
List<Set<Constraint<UnifyPair>>> newOderConstraints = new ArrayList<>(oderConstraints);
|
||||
newElems.add(nSaL);
|
||||
TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, newOderConstraints, nSaL, fc, parallel, logFile, log, rekTiefe, urm, usedTasks);
|
||||
forks.add(fork);
|
||||
@ -942,7 +936,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
Set<TypeUnify2Task> forks = new HashSet<>();
|
||||
Set<UnifyPair> newEqOrig = new HashSet<>(eq);
|
||||
Set<Set<UnifyPair>> newElemsOrig = new HashSet<>(elems);
|
||||
List<Set<Set<UnifyPair>>> newOderConstraintsOrig = new ArrayList<>(oderConstraints);
|
||||
List<Set<Constraint<UnifyPair>>> newOderConstraintsOrig = new ArrayList<>(oderConstraints);
|
||||
newElemsOrig.add(a);
|
||||
|
||||
/* FORK ANFANG */
|
||||
@ -966,8 +960,9 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
writeLog("-1 RM" + nSaL.toString());
|
||||
}
|
||||
|
||||
if (!oderConstraint) {//weiss nicht ob das wirklich stimmt
|
||||
/* PL 2019-03-13 Anfang eingefuegt Vergleich mit anderen Paaren ggf. loeschen */
|
||||
Optional<UnifyPair> optAPair = nSaL.stream().filter(x -> (
|
||||
Optional<UnifyPair> optAPair = nSaL.stream().filter(x -> (
|
||||
//x.getBasePair() != null && ist gegeben wenn variance != 2
|
||||
//x.getBasePair().getPairOp().equals(PairOperator.SMALLERDOT) &&
|
||||
(x.getPairOp().equals(PairOperator.EQUALSDOT)
|
||||
@ -982,21 +977,24 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
x.getLhsType().equals(x.getBasePair().getRhsType())
|
||||
).findFirst();
|
||||
|
||||
if (optAPair.isPresent()) {//basepair ist entweder a <. Ty oder ty <. a
|
||||
UnifyPair aPair = optAPair.get();
|
||||
//writeLog("optOrigPair: " + optOrigPair + " " + "aPair: " + aPair+ " " + "aPair.basePair(): " + aPair.getBasePair());
|
||||
writeLog("variance: " + new Integer(variance).toString() + "sameEqSet:" + sameEqSet);
|
||||
if (!sameEqSet.isEmpty() && !checkA(aPair, sameEqSet, elems, result)) {
|
||||
nSaL = null;
|
||||
noShortendElements++;
|
||||
continue;
|
||||
if (optAPair.isPresent()) {//basepair ist entweder a <. Ty oder ty <. a
|
||||
UnifyPair aPair = optAPair.get();
|
||||
//writeLog("optOrigPair: " + optOrigPair + " " + "aPair: " + aPair+ " " + "aPair.basePair(): " + aPair.getBasePair());
|
||||
writeLog("variance: " + new Integer(variance).toString() + "sameEqSet:" + sameEqSet);
|
||||
if (!sameEqSet.isEmpty() && !checkA(aPair, sameEqSet, elems, result)) {
|
||||
nSaL = null;
|
||||
noShortendElements++;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
/* PL 2019-03-13 Ende eingefuegt Vergleich mit anderen Paaren ggf. loeschen */
|
||||
|
||||
else {
|
||||
nextSetasListOderConstraints.add(((Constraint<UnifyPair>)nSaL).getExtendConstraint());
|
||||
}
|
||||
Set<UnifyPair> newEq = new HashSet<>(eq);
|
||||
Set<Set<UnifyPair>> newElems = new HashSet<>(elems);
|
||||
List<Set<Set<UnifyPair>>> newOderConstraints = new ArrayList<>(oderConstraints);
|
||||
List<Set<Constraint<UnifyPair>>> newOderConstraints = new ArrayList<>(oderConstraints);
|
||||
newElems.add(nSaL);
|
||||
TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, newOderConstraints, nSaL, fc, parallel, logFile, log, rekTiefe, urm, usedTasks);
|
||||
forks.add(fork);
|
||||
@ -1049,7 +1047,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
Set<TypeUnify2Task> forks = new HashSet<>();
|
||||
Set<UnifyPair> newEqOrig = new HashSet<>(eq);
|
||||
Set<Set<UnifyPair>> newElemsOrig = new HashSet<>(elems);
|
||||
List<Set<Set<UnifyPair>>> newOderConstraintsOrig = new ArrayList<>(oderConstraints);
|
||||
List<Set<Constraint<UnifyPair>>> newOderConstraintsOrig = new ArrayList<>(oderConstraints);
|
||||
newElemsOrig.add(a);
|
||||
|
||||
/* FORK ANFANG */
|
||||
@ -1072,7 +1070,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
nextSetasList.remove(nSaL); //PL einkommentiert 20-02-03
|
||||
Set<UnifyPair> newEq = new HashSet<>(eq);
|
||||
Set<Set<UnifyPair>> newElems = new HashSet<>(elems);
|
||||
List<Set<Set<UnifyPair>>> newOderConstraints = new ArrayList<>(oderConstraints);
|
||||
List<Set<Constraint<UnifyPair>>> newOderConstraints = new ArrayList<>(oderConstraints);
|
||||
newElems.add(nSaL);
|
||||
TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, newOderConstraints, nSaL, fc, parallel, logFile, log, rekTiefe, urm, usedTasks);
|
||||
forks.add(fork);
|
||||
@ -1117,7 +1115,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
//parallel = false; //Wenn MaxNoOfThreads erreicht ist, sequentiell weiterarbeiten
|
||||
elems.add(a); //PL 2019-01-16 muss das wirklich hin steht schon in Zeile 859 ja braucht man siehe Zeile 859
|
||||
res = unify2(elems, eq, oderConstraints, fc, parallel, rekTiefe, finalresult);
|
||||
}}}
|
||||
}}}
|
||||
if (!isUndefinedPairSetSet(res) && isUndefinedPairSetSet(result)) {
|
||||
//wenn korrektes Ergebnis gefunden alle Fehlerfaelle loeschen
|
||||
result = res;
|
||||
@ -1248,129 +1246,132 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
System.out.print("");
|
||||
Iterator<Set<UnifyPair>> nextSetasListIt = new ArrayList<Set<UnifyPair>>(nextSetasList).iterator();
|
||||
if (variance == 1) {
|
||||
/* vorgezogen vor das if
|
||||
if (parallel) {
|
||||
for (Set<Set<UnifyPair>> par_res : add_res) {
|
||||
if (!isUndefinedPairSetSet(par_res) && isUndefinedPairSetSet(result)) {
|
||||
//wenn korrektes Ergebnis gefunden alle Fehlerfaelle loeschen
|
||||
result = par_res;
|
||||
if (par_res.iterator().next() instanceof WildcardType) {
|
||||
System.out.println("");
|
||||
}
|
||||
}
|
||||
else {
|
||||
if ((isUndefinedPairSetSet(par_res) && isUndefinedPairSetSet(result))
|
||||
|| (!isUndefinedPairSetSet(par_res) && !isUndefinedPairSetSet(result))
|
||||
|| result.isEmpty()) {
|
||||
//alle Fehlerfaelle und alle korrekten Ergebnis jeweils adden
|
||||
writeLog("RES var1 ADD:" + result.toString() + " " + par_res.toString());
|
||||
result.addAll(par_res);
|
||||
}
|
||||
}
|
||||
}
|
||||
//break;
|
||||
*/
|
||||
|
||||
/* nextSetasList = nextSetasListRest; */
|
||||
/* wird bereits vor den unify2-Aufruf durchgefuehrt und nextSetasListRest zugeordnet
|
||||
*/
|
||||
|
||||
System.out.println("");
|
||||
writeLog("a: " + rekTiefe + " variance: " + variance + a.toString());
|
||||
writeLog("aParDef: " + aParDef.toString());
|
||||
aParDef.add(a);
|
||||
Iterator<Set<UnifyPair>> aParDefIt = aParDef.iterator();
|
||||
while(aParDefIt.hasNext()) {
|
||||
Set<UnifyPair> a_new = aParDefIt.next();
|
||||
while (nextSetasListIt.hasNext()) {
|
||||
Set<UnifyPair> a_next = nextSetasListIt.next();
|
||||
if (a_new.equals(a_next) ||
|
||||
(oup.compare(a_new, a_next) == 1)) {
|
||||
writeLog("Removed: " + a_next.toString());
|
||||
nextSetasList.remove(a_next);
|
||||
}
|
||||
else {
|
||||
writeLog("Not Removed: " + a_next.toString());
|
||||
System.out.println("");
|
||||
if (oderConstraint) {
|
||||
nextSetasList.removeAll(nextSetasListOderConstraints);
|
||||
nextSetasListOderConstraints = new ArrayList<>();
|
||||
writeLog("Removed: " + nextSetasListOderConstraints);
|
||||
while(aParDefIt.hasNext()) {
|
||||
Set<UnifyPair> a_new = aParDefIt.next();
|
||||
List<Set<UnifyPair>> smallerSetasList = oup.smallerThan(a_new, nextSetasList);
|
||||
List<Set<UnifyPair>> notInherited = smallerSetasList.stream()
|
||||
.filter(x -> !((Constraint<UnifyPair>)x).isInherited())
|
||||
.collect(Collectors.toCollection(ArrayList::new));
|
||||
List<Set<UnifyPair>> notErased = new ArrayList<>();
|
||||
notInherited.stream().forEach(x -> { notErased.addAll(oup.smallerEqThan(x, smallerSetasList)); });
|
||||
List<Set<UnifyPair>> erased = new ArrayList<>(smallerSetasList);
|
||||
erased.removeAll(notErased);
|
||||
nextSetasList.removeAll(erased);
|
||||
|
||||
writeLog("Removed: " + erased);
|
||||
|
||||
writeLog("Not Removed: " + nextSetasList);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
while(aParDefIt.hasNext()) {
|
||||
//nextSetasListIt = nextSetasList.iterator(); Sollte eingefuegt werden PL 2020-04-28
|
||||
Set<UnifyPair> a_new = aParDefIt.next();
|
||||
List<Set<UnifyPair>> erased = oup.smallerEqThan(a_new, nextSetasList);
|
||||
nextSetasList.removeAll(erased);
|
||||
|
||||
writeLog("Removed: " + erased);
|
||||
|
||||
writeLog("Not Removed: " + nextSetasList);
|
||||
}
|
||||
}
|
||||
}
|
||||
else { if (variance == -1) {
|
||||
/* vorgezogen vor das if
|
||||
if (parallel) {
|
||||
for (Set<Set<UnifyPair>> par_res : add_res) {
|
||||
if (!isUndefinedPairSetSet(par_res) && isUndefinedPairSetSet(result)) {
|
||||
//wenn korrektes Ergebnis gefunden alle Fehlerfaelle loeschen
|
||||
result = par_res;
|
||||
if (par_res.iterator().next() instanceof WildcardType) {
|
||||
System.out.println("");
|
||||
}
|
||||
}
|
||||
else {
|
||||
if ((isUndefinedPairSetSet(par_res) && isUndefinedPairSetSet(result))
|
||||
|| (!isUndefinedPairSetSet(par_res) && !isUndefinedPairSetSet(result))
|
||||
|| result.isEmpty()) {
|
||||
//alle Fehlerfaelle und alle korrekten Ergebnis jeweils adden
|
||||
writeLog("RES var-1 ADD:" + result.toString() + " " + par_res.toString());
|
||||
result.addAll(par_res);
|
||||
}
|
||||
}
|
||||
}
|
||||
//break;
|
||||
}
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
System.out.println("");
|
||||
writeLog("a: " + rekTiefe + " variance: " + variance + a.toString());
|
||||
writeLog("aParDef: " + aParDef.toString());
|
||||
aParDef.add(a);
|
||||
Iterator<Set<UnifyPair>> aParDefIt = aParDef.iterator();
|
||||
while(aParDefIt.hasNext()) {
|
||||
Set<UnifyPair> a_new = aParDefIt.next();
|
||||
while (nextSetasListIt.hasNext()) {
|
||||
Set<UnifyPair> a_next = nextSetasListIt.next();
|
||||
if (a_new.equals(a_next) ||
|
||||
(oup.compare(a_new, a_next) == -1)) {
|
||||
writeLog("Removed: " + a_next.toString());
|
||||
nextSetasList.remove(a_next); //PL geaendert 2019-01-09
|
||||
if (oderConstraint) {
|
||||
nextSetasList.removeAll(nextSetasListOderConstraints);
|
||||
writeLog("Removed: " + nextSetasListOderConstraints);
|
||||
nextSetasListOderConstraints = new ArrayList<>();
|
||||
while(aParDefIt.hasNext()) {
|
||||
Set<UnifyPair> a_new = aParDefIt.next();
|
||||
List<Set<UnifyPair>> greaterSetasList = oup.greaterThan(a_new, nextSetasList);
|
||||
|
||||
//a_new muss hingefuegt werden, wenn es nicht vererbt ist, dann wird es spaeter wieder geloescht
|
||||
if (!((Constraint<UnifyPair>)a_new).isInherited()) {
|
||||
greaterSetasList.add(a_new);
|
||||
}
|
||||
List<Set<UnifyPair>> notInherited = greaterSetasList.stream()
|
||||
.filter(x -> !((Constraint<UnifyPair>)x).isInherited())
|
||||
.collect(Collectors.toCollection(ArrayList::new));
|
||||
List<Set<UnifyPair>> notErased = new ArrayList<>();
|
||||
|
||||
//Wenn x nicht vererbt ist, beginnt beim naechstgroesseren Element die naechste Ueberladung
|
||||
notInherited.stream().forEach(x -> { notErased.addAll(oup.greaterEqThan(x, greaterSetasList)); });
|
||||
|
||||
//das kleineste Element ist das Element von dem a_new geerbt hat
|
||||
//muss deshalb geloescht werden
|
||||
Iterator<Set<UnifyPair>> notErasedIt = notErased.iterator();
|
||||
if (notErasedIt.hasNext()) {
|
||||
Set<UnifyPair> min = oup.min(notErasedIt);
|
||||
notErased.remove(min);
|
||||
notErased.remove(((Constraint<UnifyPair>)min).getExtendConstraint());
|
||||
}
|
||||
|
||||
List<Set<UnifyPair>> erased = new ArrayList<>(greaterSetasList);
|
||||
erased.removeAll(notErased);
|
||||
nextSetasList.removeAll(erased);
|
||||
|
||||
writeLog("Removed: " + erased);
|
||||
|
||||
writeLog("Not Removed: " + nextSetasList);
|
||||
|
||||
}
|
||||
else {
|
||||
System.out.println("");
|
||||
writeLog("Not Removed: " + a_next.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
while(aParDefIt.hasNext()) {
|
||||
//nextSetasListIt = nextSetasList.iterator(); Sollte eingefuegt werden PL 2020-04-28
|
||||
Set<UnifyPair> a_new = aParDefIt.next();
|
||||
List<Set<UnifyPair>> erased = oup.greaterEqThan(a_new, nextSetasList);
|
||||
|
||||
nextSetasList.removeAll(erased);
|
||||
|
||||
writeLog("Removed: " + erased);
|
||||
|
||||
writeLog("Not Removed: " + nextSetasList);
|
||||
}
|
||||
}
|
||||
}
|
||||
else { if (variance == 0) {
|
||||
writeLog("a: " + rekTiefe + " variance: " + variance + a.toString());
|
||||
break; }
|
||||
else { if (variance == 2) {
|
||||
/* vorgezogen vor das if
|
||||
if (parallel) {
|
||||
for (Set<Set<UnifyPair>> par_res : add_res) {
|
||||
if (!isUndefinedPairSetSet(par_res) && isUndefinedPairSetSet(result)) {
|
||||
//wenn korrektes Ergebnis gefunden alle Fehlerfaelle loeschen
|
||||
result = par_res;
|
||||
if (par_res.iterator().next() instanceof WildcardType) {
|
||||
System.out.println("");
|
||||
}
|
||||
}
|
||||
else {
|
||||
if ((isUndefinedPairSetSet(par_res) && isUndefinedPairSetSet(result))
|
||||
|| (!isUndefinedPairSetSet(par_res) && !isUndefinedPairSetSet(result))
|
||||
|| result.isEmpty()) {
|
||||
//alle Fehlerfaelle und alle korrekten Ergebnis jeweils adden
|
||||
writeLog("RES var2 ADD:" + result.toString() + " " + par_res.toString());
|
||||
result.addAll(par_res);
|
||||
}
|
||||
}
|
||||
}
|
||||
//break;
|
||||
if (!oderConstraint) {
|
||||
break;
|
||||
}
|
||||
*/
|
||||
else {
|
||||
nextSetasList.removeAll(nextSetasListOderConstraints);
|
||||
nextSetasListOderConstraints = new ArrayList<>();
|
||||
writeLog("Removed: " + nextSetasListOderConstraints);
|
||||
List<Set<UnifyPair>> smallerSetasList = oup.smallerThan(a, nextSetasList);
|
||||
List<Set<UnifyPair>> notInherited = smallerSetasList.stream()
|
||||
.filter(x -> !((Constraint<UnifyPair>)x).isInherited())
|
||||
.collect(Collectors.toCollection(ArrayList::new));
|
||||
List<Set<UnifyPair>> notErased = new ArrayList<>();
|
||||
notInherited.stream().forEach(x -> { notErased.addAll(oup.smallerEqThan(x, smallerSetasList)); });
|
||||
List<Set<UnifyPair>> erased = new ArrayList<>(smallerSetasList);
|
||||
erased.removeAll(notErased);
|
||||
nextSetasList.removeAll(erased);
|
||||
|
||||
writeLog("Removed: " + erased);
|
||||
|
||||
writeLog("Not Removed: " + nextSetasList);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
else { if (variance == 2) {
|
||||
}}}
|
||||
writeLog("a: " + rekTiefe + " variance: " + variance + a.toString());
|
||||
}
|
||||
@ -1389,7 +1390,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
res.stream()
|
||||
.map(b ->
|
||||
b.stream()
|
||||
.map(x -> x.getAllBases())
|
||||
.map(x -> x.getThisAndAllBases()) //getAllBases durch getThisAndAllBases ersetzt, weil auch im UnifyPair selbst schon ein Fehler liegen kann.
|
||||
.reduce((y,z) -> { y.addAll(z); return y;}).get())
|
||||
.reduce((y,z) -> { y.addAll(z); return y;}).get()
|
||||
);
|
||||
@ -1410,6 +1411,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
if (res.size() > 1) {
|
||||
System.out.println();
|
||||
}
|
||||
writeLog("nextSetasList vor filter-Aufruf: " + nextSetasList);
|
||||
nextSetasList = nextSetasList.stream().filter(x -> {
|
||||
//Boolean ret = false;
|
||||
//for (PlaceholderType var : vars) {
|
||||
@ -1418,6 +1420,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
return (!x.containsAll(durchschnitt));
|
||||
})//.filter(y -> couldBecorrect(reducedUndefResSubstGroundedBasePair, y)) //fuer testzwecke auskommentiert um nofstred zu bestimmen PL 2018-10-10
|
||||
.collect(Collectors.toCollection(ArrayList::new));
|
||||
writeLog("nextSetasList nach filter-Aufruf: " + nextSetasList);
|
||||
nofstred = nextSetasList.size();
|
||||
//NOCH NICHT korrekt PL 2018-10-12
|
||||
//nextSetasList = nextSetasList.stream().filter(y -> couldBecorrect(reducedUndefResSubstGroundedBasePair, y))
|
||||
@ -1764,10 +1767,10 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
* from the pairs that matched the case. Each generated set contains singleton sets or sets with few elements
|
||||
* (as in case 1 where sigma is added to the innermost set).
|
||||
*/
|
||||
protected Set<Set<Set<Set<UnifyPair>>>> calculatePairSets(Set<UnifyPair> eq2s, List<Set<Set<UnifyPair>>> oderConstraintsInput, IFiniteClosure fc, Set<UnifyPair> undefined, List<Set<Set<UnifyPair>>> oderConstraintsOutput) {
|
||||
protected Set<Set<Set<? extends Set<UnifyPair>>>> calculatePairSets(Set<UnifyPair> eq2s, List<Set<Constraint<UnifyPair>>> oderConstraintsInput, IFiniteClosure fc, Set<UnifyPair> undefined, List<Set<Constraint<UnifyPair>>> oderConstraintsOutput) {
|
||||
writeLog("eq2s: " + eq2s.toString());
|
||||
oderConstraintsOutput.addAll(oderConstraintsInput);
|
||||
List<Set<Set<Set<UnifyPair>>>> result = new ArrayList<>(9);
|
||||
List<Set<Set<? extends Set<UnifyPair>>>> result = new ArrayList<>(9);
|
||||
|
||||
// Init all 8 cases + 9. Case: oderConstraints
|
||||
for(int i = 0; i < 9; i++)
|
||||
@ -1777,29 +1780,52 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
Iterator<UnifyPair> eq2sprimeit = eq2sprime.iterator();
|
||||
ArrayList<UnifyPair> eq2sAsListFst = new ArrayList<>();
|
||||
ArrayList<UnifyPair> eq2sAsListSnd = new ArrayList<>();
|
||||
ArrayList<UnifyPair> eq2sAsListThird = new ArrayList<>();
|
||||
ArrayList<UnifyPair> eq2sAsListFourth = new ArrayList<>();
|
||||
ArrayList<UnifyPair> eq2sAsListBack = new ArrayList<>();
|
||||
ArrayList<UnifyPair> eq2sAsList = new ArrayList<>();
|
||||
Boolean first = true;
|
||||
while(eq2sprimeit.hasNext()) {// alle mit Variance != 0 nach vorne schieben
|
||||
UnifyPair up = eq2sprimeit.next();
|
||||
if ((up.getLhsType() instanceof PlaceholderType && ((PlaceholderType)up.getLhsType()).getVariance() != 0 && !((PlaceholderType)up.getLhsType()).isInnerType())
|
||||
|| (up.getRhsType() instanceof PlaceholderType && ((PlaceholderType)up.getRhsType()).getVariance() != 0) && !((PlaceholderType)up.getRhsType()).isInnerType()) {
|
||||
eq2sAsListFst.add(up);
|
||||
if ((up.getLhsType() instanceof PlaceholderType &&
|
||||
((PlaceholderType)up.getLhsType()).getVariance() == 1 &&
|
||||
!((PlaceholderType)up.getLhsType()).isInnerType()) ||
|
||||
(up.getRhsType() instanceof PlaceholderType &&
|
||||
((PlaceholderType)up.getRhsType()).getVariance() == -1) &&
|
||||
!((PlaceholderType)up.getRhsType()).isInnerType())
|
||||
{
|
||||
eq2sAsListFst.add(up);
|
||||
eq2s.remove(up);
|
||||
}
|
||||
else if ((up.getLhsType() instanceof PlaceholderType && ((PlaceholderType)up.getLhsType()).getVariance() != 0 && ((PlaceholderType)up.getLhsType()).isInnerType())
|
||||
|| (up.getRhsType() instanceof PlaceholderType && ((PlaceholderType)up.getRhsType()).getVariance() != 0) && ((PlaceholderType)up.getRhsType()).isInnerType()) {
|
||||
else if ((up.getLhsType() instanceof PlaceholderType && ((PlaceholderType)up.getLhsType()).getVariance() == 1 && ((PlaceholderType)up.getLhsType()).isInnerType())
|
||||
|| (up.getRhsType() instanceof PlaceholderType && ((PlaceholderType)up.getRhsType()).getVariance() == -1) && ((PlaceholderType)up.getRhsType()).isInnerType()) {
|
||||
eq2sAsListSnd.add(up);
|
||||
eq2s.remove(up);
|
||||
}
|
||||
}
|
||||
else if ((up.getLhsType() instanceof PlaceholderType &&
|
||||
((PlaceholderType)up.getLhsType()).getVariance() == -1 &&
|
||||
!((PlaceholderType)up.getLhsType()).isInnerType()) ||
|
||||
(up.getRhsType() instanceof PlaceholderType &&
|
||||
((PlaceholderType)up.getRhsType()).getVariance() == -1) &&
|
||||
!((PlaceholderType)up.getRhsType()).isInnerType())
|
||||
{
|
||||
eq2sAsListThird.add(up);
|
||||
eq2s.remove(up);
|
||||
}
|
||||
else if ((up.getLhsType() instanceof PlaceholderType && ((PlaceholderType)up.getLhsType()).getVariance() == -1 && ((PlaceholderType)up.getLhsType()).isInnerType())
|
||||
|| (up.getRhsType() instanceof PlaceholderType && ((PlaceholderType)up.getRhsType()).getVariance() == 1) && ((PlaceholderType)up.getRhsType()).isInnerType()) {
|
||||
eq2sAsListFourth.add(up);
|
||||
eq2s.remove(up);
|
||||
}
|
||||
else if ((up.getLhsType() instanceof PlaceholderType && ((PlaceholderType)up.getLhsType()).isInnerType())
|
||||
|| (up.getRhsType() instanceof PlaceholderType && ((PlaceholderType)up.getRhsType()).isInnerType())) {
|
||||
eq2sAsListBack.add(up);
|
||||
eq2s.remove(up);
|
||||
}
|
||||
}
|
||||
if (eq2sAsListFst.isEmpty()) {
|
||||
List<Set<Set<UnifyPair>>> oderConstraintsVariance = oderConstraintsOutput.stream() //Alle Elemente rauswerfen, die Variance 0 haben oder keine TPH in LHS oder RHS sind
|
||||
//if (eq2sAsListFst.isEmpty())
|
||||
{
|
||||
List<Set<Constraint<UnifyPair>>> oderConstraintsVariance = oderConstraintsOutput.stream() //Alle Elemente rauswerfen, die Variance 0 haben oder keine TPH in LHS oder RHS sind
|
||||
.filter(x -> x.stream()
|
||||
.filter(y ->
|
||||
y.stream().filter(z -> ((z.getLhsType() instanceof PlaceholderType)
|
||||
@ -1809,10 +1835,20 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
).findFirst().isPresent()
|
||||
).findFirst().isPresent()).collect(Collectors.toList());
|
||||
if (!oderConstraintsVariance.isEmpty()) {
|
||||
Set<Set<UnifyPair>> ret = oderConstraintsVariance.get(0);
|
||||
Set<Constraint<UnifyPair>> ret = oderConstraintsVariance.get(0);
|
||||
oderConstraintsOutput.remove(ret);
|
||||
//Set<UnifyPair> retFlat = new HashSet<>();
|
||||
//ret.stream().forEach(x -> retFlat.addAll(x));
|
||||
|
||||
//Alle wildcard Faelle rausfiltern bei not wildcardable
|
||||
ret = ret.stream().filter(x -> { Optional<UnifyPair> optElem;
|
||||
return !((optElem=x.stream().filter(y -> (y.getLhsType()) instanceof PlaceholderType
|
||||
&& !((PlaceholderType)y.getLhsType()).isWildcardable()
|
||||
&& y.getPairOp() == PairOperator.EQUALSDOT
|
||||
&& !(y.getRhsType() instanceof PlaceholderType))
|
||||
.findAny()).isPresent()
|
||||
&& optElem.get().getRhsType() instanceof ExtendsType);})
|
||||
.collect(Collectors.toSet());
|
||||
ret.stream().forEach(x -> x.stream().forEach(y -> { Set<UnifyPair> x_new = new HashSet<>(x); //PL 2020-03-18: y selbst darf nicht in die Substitutionen
|
||||
x_new.remove(y);
|
||||
y.addSubstitutions(x_new);
|
||||
@ -1829,16 +1865,28 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
|
||||
eq2sAsList.addAll(eq2sAsListFst);
|
||||
eq2sAsList.addAll(eq2sAsListSnd);
|
||||
eq2sAsList.addAll(eq2sAsListThird);
|
||||
eq2sAsList.addAll(eq2sAsListFourth);
|
||||
eq2sAsList.addAll(eq2s);
|
||||
eq2sAsList.addAll(eq2sAsListBack);
|
||||
|
||||
if (eq2sAsList.isEmpty() && first) {//Alle eq2s sind empty und alle oderConstraints mit Variance != 0 sind bearbeitet
|
||||
if (!oderConstraintsOutput.isEmpty()) {
|
||||
Set<Set<UnifyPair>> ret = oderConstraintsOutput.remove(0);
|
||||
Set<Constraint<UnifyPair>> ret = oderConstraintsOutput.remove(0);
|
||||
//if (ret.iterator().next().iterator().next().getLhsType().getName().equals("M"))
|
||||
// System.out.println("M");
|
||||
//Set<UnifyPair> retFlat = new HashSet<>();
|
||||
//ret.stream().forEach(x -> retFlat.addAll(x));
|
||||
//ret.stream().forEach(x -> retFlat.addAll(x));
|
||||
|
||||
//Alle wildcard Faelle rausfiltern bei not wildcardable
|
||||
ret = ret.stream().filter(x -> { Optional<UnifyPair> optElem;
|
||||
return !((optElem=x.stream().filter(y -> (y.getLhsType()) instanceof PlaceholderType
|
||||
&& !((PlaceholderType)y.getLhsType()).isWildcardable()
|
||||
&& y.getPairOp() == PairOperator.EQUALSDOT
|
||||
&& !(y.getRhsType() instanceof PlaceholderType))
|
||||
.findAny()).isPresent()
|
||||
&& optElem.get().getRhsType() instanceof ExtendsType);})
|
||||
.collect(Collectors.toSet());
|
||||
ret.stream().forEach(x -> x.stream().forEach(y -> { Set<UnifyPair> x_new = new HashSet<>(x); //PL 2020-03-18: y selbst darf nicht in die Substitutionen
|
||||
x_new.remove(y);
|
||||
y.addSubstitutions(x_new);
|
||||
|
@ -4,6 +4,7 @@ import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
import de.dhbwstuttgart.typeinference.constraints.Constraint;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
|
||||
|
||||
/**
|
||||
@ -91,7 +92,7 @@ public interface IRuleSet {
|
||||
* @param pairs The set of pairs where the subst rule should apply.
|
||||
* @return An optional of the modified set, if there were any substitutions. An empty optional if there were no substitutions.
|
||||
*/
|
||||
public Optional<Set<UnifyPair>> subst(Set<UnifyPair> pairs, List<Set<Set<UnifyPair>>> oderConstraints);
|
||||
public Optional<Set<UnifyPair>> subst(Set<UnifyPair> pairs, List<Set<Constraint<UnifyPair>>> oderConstraints);
|
||||
|
||||
/**
|
||||
* Applies the subst-Rule to a set of pairs (usually Eq').
|
||||
|
@ -75,6 +75,17 @@ implements IFiniteClosure {
|
||||
|
||||
// Build the transitive closure of the inheritance tree
|
||||
for(UnifyPair pair : pairs) {
|
||||
|
||||
/*
|
||||
try {
|
||||
logFile.write("Pair: " + pair + "\n");
|
||||
logFile.flush();
|
||||
}
|
||||
catch (IOException e) {
|
||||
System.err.println("no LogFile");
|
||||
}
|
||||
*/
|
||||
|
||||
if(pair.getPairOp() != PairOperator.SMALLER)
|
||||
continue;
|
||||
|
||||
@ -93,13 +104,17 @@ implements IFiniteClosure {
|
||||
|
||||
Node<UnifyType> childNode = inheritanceGraph.get(pair.getLhsType());
|
||||
Node<UnifyType> parentNode = inheritanceGraph.get(pair.getRhsType());
|
||||
|
||||
|
||||
// Add edge
|
||||
parentNode.addDescendant(childNode);
|
||||
|
||||
// Add edges to build the transitive closure
|
||||
parentNode.getPredecessors().stream().forEach(x -> x.addDescendant(childNode));
|
||||
childNode.getDescendants().stream().forEach(x -> x.addPredecessor(parentNode));
|
||||
|
||||
//PL eingefuegt 2020-05-07 File UnitTest InheritTest.java
|
||||
this.inheritanceGraph.forEach((x,y) -> { if (y.getDescendants().contains(parentNode)) { y.addDescendant(childNode); y.addAllDescendant(childNode.getDescendants());};
|
||||
if (y.getPredecessors().contains(childNode)) { y.addPredecessor(parentNode); y.addAllPredecessor(parentNode.getPredecessors());};} );
|
||||
}
|
||||
|
||||
// Build the alternative representation with strings as keys
|
||||
@ -655,6 +670,7 @@ implements IFiniteClosure {
|
||||
*/
|
||||
|
||||
public int compare (UnifyType left, UnifyType right, PairOperator pairop) {
|
||||
//try {logFile.write("left: "+ left + " right: " + right + " pairop: " + pairop);} catch (IOException ie) {}
|
||||
if (left.getName().equals("Matrix") || right.getName().equals("Matrix"))
|
||||
System.out.println("");
|
||||
/*
|
||||
@ -746,7 +762,10 @@ implements IFiniteClosure {
|
||||
//Gleichungen der Form a <./=. Theta oder Theta <./=. a oder a <./=. b sind ok.
|
||||
long greaterLen = greaterRes.stream().filter(delFun).count();
|
||||
if (greaterLen == 0) return 1;
|
||||
else return 0;
|
||||
else {
|
||||
//try {logFile.write("0 left: "+ left + " right: " + right + " pairop: " + pairop);} catch (IOException ie) {}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -45,6 +45,15 @@ class Node<T> {
|
||||
descendant.addPredecessor(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds some directed edges from this node to the descendant (this -> descendant)
|
||||
*/
|
||||
public void addAllDescendant(Set<Node<T>> allDescendants) {
|
||||
for(Node<T> descendant: allDescendants) {
|
||||
addDescendant(descendant);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a directed edge from the predecessor to this node (predecessor -> this)
|
||||
*/
|
||||
@ -56,6 +65,15 @@ class Node<T> {
|
||||
predecessor.addDescendant(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds some directed edges from the predecessor to this node (predecessor -> this)
|
||||
*/
|
||||
public void addAllPredecessor(Set<Node<T>> allPredecessors) {
|
||||
for(Node<T> predecessor: allPredecessors) {
|
||||
addPredecessor(predecessor);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The content of this node.
|
||||
*/
|
||||
|
@ -0,0 +1,89 @@
|
||||
package de.dhbwstuttgart.typeinference.unify.model;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public abstract class OrderingExtend<T> extends com.google.common.collect.Ordering<T> {
|
||||
|
||||
public List<T> maxElements(Iterable<T> iterable) {
|
||||
ArrayList<T> ret = new ArrayList<>();
|
||||
while (iterable.iterator().hasNext()) {
|
||||
Set<T> believe = new HashSet<>();
|
||||
|
||||
T max = max(iterable);
|
||||
ret.add(max);
|
||||
|
||||
Iterator<T> it = iterable.iterator();
|
||||
while (it.hasNext()) {
|
||||
T elem = it.next();
|
||||
if (!(compare(max, elem) == 1) && !max.equals(elem)) {
|
||||
believe.add(elem);
|
||||
}
|
||||
}
|
||||
iterable = believe;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public List<T> minElements(Iterable<T> iterable) {
|
||||
ArrayList<T> ret = new ArrayList<>();
|
||||
while (iterable.iterator().hasNext()) {
|
||||
Set<T> believe = new HashSet<>();
|
||||
|
||||
T min = min(iterable);
|
||||
ret.add(min);
|
||||
|
||||
Iterator<T> it = iterable.iterator();
|
||||
while (it.hasNext()) {
|
||||
T elem = it.next();
|
||||
if (!(compare(min, elem) == -1) && !min.equals(elem)) {
|
||||
believe.add(elem);
|
||||
}
|
||||
}
|
||||
iterable = believe;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
public List<T> smallerEqThan(T elem, Iterable<T> iterable) {
|
||||
List<T> ret = smallerThan(elem, iterable);
|
||||
ret.add(elem);
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
public List<T> smallerThan(T elem, Iterable<T> iterable) {
|
||||
ArrayList<T> ret = new ArrayList<>();
|
||||
Iterator<T> it = iterable.iterator();
|
||||
while (it.hasNext()) {
|
||||
T itElem = it.next();
|
||||
if (!itElem.equals(elem) && compare(elem, itElem) == 1) {
|
||||
ret.add(itElem);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public List<T> greaterEqThan(T elem, Iterable<T> iterable) {
|
||||
List<T> ret = greaterThan(elem, iterable);
|
||||
ret.add(elem);
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
public List<T> greaterThan(T elem, Iterable<T> iterable) {
|
||||
ArrayList<T> ret = new ArrayList<>();
|
||||
Iterator<T> it = iterable.iterator();
|
||||
while (it.hasNext()) {
|
||||
T itElem = it.next();
|
||||
if (!itElem.equals(elem) && (compare(elem, itElem) == -1)) {
|
||||
ret.add(itElem);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
}
|
@ -4,22 +4,25 @@ import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.function.BinaryOperator;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import com.google.common.collect.Ordering;
|
||||
|
||||
import de.dhbwstuttgart.typeinference.unify.Match;
|
||||
import de.dhbwstuttgart.typeinference.unify.TypeUnifyTask;
|
||||
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
|
||||
|
||||
|
||||
|
||||
public class OrderingUnifyPair extends Ordering<Set<UnifyPair>> {
|
||||
public class OrderingUnifyPair extends OrderingExtend<Set<UnifyPair>> {
|
||||
|
||||
protected IFiniteClosure fc;
|
||||
|
||||
@ -42,7 +45,7 @@ public class OrderingUnifyPair extends Ordering<Set<UnifyPair>> {
|
||||
}}
|
||||
catch (ClassCastException e) {
|
||||
try {
|
||||
((FiniteClosure)fc).logFile.write("ClassCastException: " + left.toString() +"\n\n");
|
||||
((FiniteClosure)fc).logFile.write("ClassCastException: " + left.toString() + " " + left.getGroundBasePair() + "\n\n");
|
||||
((FiniteClosure)fc).logFile.flush();
|
||||
}
|
||||
catch (IOException ie) {
|
||||
@ -165,16 +168,7 @@ public class OrderingUnifyPair extends Ordering<Set<UnifyPair>> {
|
||||
left.add(p4);
|
||||
*/
|
||||
|
||||
if ((left.size() == 1) && right.size() == 1) {
|
||||
if (left.iterator().next().getLhsType().getName().equals("AFS")) {
|
||||
System.out.println("");
|
||||
}
|
||||
if (((right.iterator().next().getRhsType() instanceof SuperType) && (((SuperType)right.iterator().next().getRhsType()).getSuperedType().getName().equals("java.lang.Object")))
|
||||
||((left.iterator().next().getRhsType() instanceof SuperType) && (((SuperType)left.iterator().next().getRhsType()).getSuperedType().getName().equals("java.lang.Object"))))
|
||||
{
|
||||
System.out.println("");
|
||||
}
|
||||
}
|
||||
|
||||
Set<UnifyPair> lefteq = left.stream()
|
||||
.filter(x -> (x.getLhsType() instanceof PlaceholderType && x.getPairOp() == PairOperator.EQUALSDOT))
|
||||
.collect(Collectors.toCollection(HashSet::new));
|
||||
@ -202,6 +196,135 @@ public class OrderingUnifyPair extends Ordering<Set<UnifyPair>> {
|
||||
//if (lefteq.iterator().next().getLhsType().getName().equals("AJO")) {
|
||||
// System.out.print("");
|
||||
//}
|
||||
|
||||
//ODER-CONSTRAINT
|
||||
Set<UnifyPair> leftBase = left.stream().map(x -> x.getGroundBasePair()).collect(Collectors.toCollection(HashSet::new));
|
||||
Set<UnifyPair> rightBase = right.stream().map(x -> x.getGroundBasePair()).collect(Collectors.toCollection(HashSet::new));
|
||||
|
||||
Set<UnifyPair> lefteqOder = left.stream()
|
||||
.filter(x -> { UnifyPair y = x.getGroundBasePair();
|
||||
/*try {
|
||||
((FiniteClosure)fc).logFile.write("leftBase: " + leftBase.toString() +"\n");
|
||||
((FiniteClosure)fc).logFile.write("rightBase: " + rightBase.toString() +"\n\n");
|
||||
((FiniteClosure)fc).logFile.write("left: " + left.toString() +"\n");
|
||||
((FiniteClosure)fc).logFile.write("right: " + right.toString() +"\n\n");
|
||||
((FiniteClosure)fc).logFile.write("y: " + y.toString() +"\n");
|
||||
((FiniteClosure)fc).logFile.write("y.getLhsType() : " + y.getLhsType() .toString() +"\n\n");
|
||||
((FiniteClosure)fc).logFile.write("y.getRhsType(): " + y.getRhsType().toString() +"\n");
|
||||
((FiniteClosure)fc).logFile.write("x.getPairOp(): " + x.getPairOp().toString() +"\n\n");
|
||||
}
|
||||
catch (IOException ie) {
|
||||
} */
|
||||
return (y.getLhsType() instanceof PlaceholderType &&
|
||||
!(y.getRhsType() instanceof PlaceholderType) &&
|
||||
x.getPairOp() == PairOperator.EQUALSDOT);})
|
||||
.collect(Collectors.toCollection(HashSet::new));
|
||||
Set<UnifyPair> righteqOder = right.stream()
|
||||
.filter(x -> { UnifyPair y = x.getGroundBasePair();
|
||||
return (y.getLhsType() instanceof PlaceholderType &&
|
||||
!(y.getRhsType() instanceof PlaceholderType) &&
|
||||
x.getPairOp() == PairOperator.EQUALSDOT);})
|
||||
.collect(Collectors.toCollection(HashSet::new));
|
||||
Set<UnifyPair> lefteqRet = left.stream()
|
||||
.filter(x -> { UnifyPair y = x.getGroundBasePair();
|
||||
return (y.getRhsType() instanceof PlaceholderType &&
|
||||
x.getPairOp() == PairOperator.EQUALSDOT);})
|
||||
.collect(Collectors.toCollection(HashSet::new));
|
||||
Set<UnifyPair> righteqRet = right.stream()
|
||||
.filter(x -> { UnifyPair y = x.getGroundBasePair();
|
||||
return (y.getRhsType() instanceof PlaceholderType &&
|
||||
x.getPairOp() == PairOperator.EQUALSDOT);})
|
||||
.collect(Collectors.toCollection(HashSet::new));
|
||||
Set<UnifyPair> leftleOder = left.stream()
|
||||
.filter(x -> (x.getPairOp() == PairOperator.SMALLERDOT))
|
||||
.collect(Collectors.toCollection(HashSet::new));
|
||||
Set<UnifyPair> rightleOder = right.stream()
|
||||
.filter(x -> (x.getPairOp() == PairOperator.SMALLERDOT))
|
||||
.collect(Collectors.toCollection(HashSet::new));
|
||||
|
||||
/*
|
||||
synchronized(this) {
|
||||
try {
|
||||
((FiniteClosure)fc).logFile.write("leftBase: " + leftBase.toString() +"\n");
|
||||
((FiniteClosure)fc).logFile.write("rightBase: " + rightBase.toString() +"\n\n");
|
||||
((FiniteClosure)fc).logFile.write("left: " + left.toString() +"\n");
|
||||
((FiniteClosure)fc).logFile.write("right: " + right.toString() +"\n\n");
|
||||
((FiniteClosure)fc).logFile.write("lefteqOder: " + lefteqOder.toString() +"\n");
|
||||
((FiniteClosure)fc).logFile.write("righteqOder: " + righteqOder.toString() +"\n\n");
|
||||
((FiniteClosure)fc).logFile.write("lefteqRet: " + lefteqRet.toString() +"\n");
|
||||
((FiniteClosure)fc).logFile.write("righteqRet: " + righteqRet.toString() +"\n\n");
|
||||
((FiniteClosure)fc).logFile.write("leftleOder: " + leftleOder.toString() +"\n");
|
||||
((FiniteClosure)fc).logFile.write("rightleOder: " + rightleOder.toString() +"\n\n");
|
||||
((FiniteClosure)fc).logFile.flush();
|
||||
}
|
||||
catch (IOException ie) {
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
Integer compareEq;
|
||||
if (lefteqOder.size() == 1 && righteqOder.size() == 1 && lefteqRet.size() == 1 && righteqRet.size() == 1) {
|
||||
Match m = new Match();
|
||||
if ((compareEq = compareEq(lefteqOder.iterator().next().getGroundBasePair(), righteqOder.iterator().next().getGroundBasePair())) == -1) {
|
||||
ArrayList<UnifyPair> matchList =
|
||||
rightleOder.stream().map(x -> {
|
||||
UnifyPair leftElem = leftleOder.stream()
|
||||
.filter(y -> y.getGroundBasePair().getLhsType().equals(x.getGroundBasePair().getLhsType()))
|
||||
.findAny().get();
|
||||
return new UnifyPair(x.getRhsType(), leftElem.getRhsType(), PairOperator.EQUALSDOT);})
|
||||
.collect(Collectors.toCollection(ArrayList::new));
|
||||
if (m.match(matchList).isPresent()) {
|
||||
//try { ((FiniteClosure)fc).logFile.write("result1: -1 \n\n"); } catch (IOException ie) {}
|
||||
return -1;
|
||||
}
|
||||
else {
|
||||
//try { ((FiniteClosure)fc).logFile.write("result1: 0 \n\n"); } catch (IOException ie) {}
|
||||
return 0;
|
||||
}
|
||||
} else if (compareEq == 1) {
|
||||
ArrayList<UnifyPair> matchList =
|
||||
leftleOder.stream().map(x -> {
|
||||
UnifyPair rightElem = rightleOder.stream()
|
||||
.filter(y ->
|
||||
y.getGroundBasePair().getLhsType().equals(x.getGroundBasePair().getLhsType()))
|
||||
.findAny().get();
|
||||
return new UnifyPair(x.getRhsType(), rightElem.getRhsType(), PairOperator.EQUALSDOT);})
|
||||
.collect(Collectors.toCollection(ArrayList::new));
|
||||
if (m.match(matchList).isPresent()) {
|
||||
//try { ((FiniteClosure)fc).logFile.write("result2: 1 \n\n"); } catch (IOException ie) {}
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
//try { ((FiniteClosure)fc).logFile.write("result2: 0 \n\n"); } catch (IOException ie) {}
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
/*
|
||||
synchronized(this) {
|
||||
try {
|
||||
((FiniteClosure)fc).logFile.write("leftBase: " + leftBase.toString() +"\n");
|
||||
((FiniteClosure)fc).logFile.write("rightBase: " + rightBase.toString() +"\n\n");
|
||||
((FiniteClosure)fc).logFile.write("left: " + left.toString() +"\n");
|
||||
((FiniteClosure)fc).logFile.write("right: " + right.toString() +"\n\n");
|
||||
((FiniteClosure)fc).logFile.write("lefteqOder: " + lefteqOder.toString() +"\n");
|
||||
((FiniteClosure)fc).logFile.write("righteqOder: " + righteqOder.toString() +"\n\n");
|
||||
((FiniteClosure)fc).logFile.write("lefteqRet: " + lefteqRet.toString() +"\n");
|
||||
((FiniteClosure)fc).logFile.write("righteqRet: " + righteqRet.toString() +"\n\n");
|
||||
((FiniteClosure)fc).logFile.write("leftleOder: " + leftleOder.toString() +"\n");
|
||||
((FiniteClosure)fc).logFile.write("rightleOder: " + rightleOder.toString() +"\n\n");
|
||||
((FiniteClosure)fc).logFile.write("result3: 0 \n\n");
|
||||
((FiniteClosure)fc).logFile.flush();
|
||||
}
|
||||
catch (IOException ie) {
|
||||
}
|
||||
}
|
||||
*/
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (lefteq.size() == 1 && lefteq.iterator().next().getRhsType() instanceof ExtendsType && leftle.size() == 1 && righteq.size() == 0 && rightle.size() == 1) {
|
||||
return 1;
|
||||
}
|
||||
|
@ -138,6 +138,11 @@ public class UnifyPair {
|
||||
return ret;
|
||||
}
|
||||
|
||||
public Set<UnifyPair> getThisAndAllBases () {
|
||||
Set<UnifyPair> ret = getAllBases();
|
||||
ret.add(this);
|
||||
return ret;
|
||||
}
|
||||
public Set<UnifyPair> getAllBases () {
|
||||
Set<UnifyPair> ret = new HashSet<>();
|
||||
if (basePair != null) {
|
||||
@ -217,12 +222,14 @@ public class UnifyPair {
|
||||
public String toString() {
|
||||
String ret = "";
|
||||
if (lhs instanceof PlaceholderType) {
|
||||
ret = new Integer(((PlaceholderType)lhs).getVariance()).toString() + " " + ((PlaceholderType)lhs).isInnerType()
|
||||
+ " " + ((PlaceholderType)lhs).isWildcardable();
|
||||
ret = new Integer(((PlaceholderType)lhs).getVariance()).toString() + " "
|
||||
+ "WC: " + ((PlaceholderType)lhs).isWildcardable()
|
||||
+ ", IT: " + ((PlaceholderType)lhs).isInnerType();
|
||||
}
|
||||
if (rhs instanceof PlaceholderType) {
|
||||
ret = ret + ", " + new Integer(((PlaceholderType)rhs).getVariance()).toString() + " " + ((PlaceholderType)rhs).isInnerType()
|
||||
+ " " + ((PlaceholderType)rhs).isWildcardable();
|
||||
ret = ret + ", " + new Integer(((PlaceholderType)rhs).getVariance()).toString() + " "
|
||||
+ "WC: " + ((PlaceholderType)rhs).isWildcardable()
|
||||
+ ", IT: " + ((PlaceholderType)rhs).isInnerType();
|
||||
}
|
||||
return "(" + lhs + " " + pairOp + " " + rhs + ", " + ret + ")"; //+ ", [" + getfBounded().toString()+ "])";
|
||||
}
|
||||
|
64
src/test/java/AllgemeinTest.java
Normal file
64
src/test/java/AllgemeinTest.java
Normal file
@ -0,0 +1,64 @@
|
||||
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Field;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||
|
||||
public class AllgemeinTest {
|
||||
|
||||
private static String path;
|
||||
private static File fileToTest;
|
||||
private static JavaTXCompiler compiler;
|
||||
private static ClassLoader loader;
|
||||
private static Class<?> classToTest;
|
||||
private static String pathToClassFile;
|
||||
private static Object instanceOfClass;
|
||||
|
||||
|
||||
@Test
|
||||
public void test() throws Exception {
|
||||
//String className = "GenTest";
|
||||
//String className = "Overloading_Generics";
|
||||
//String className = "Generics";
|
||||
//String className = "OverloadingMain";
|
||||
//String className = "OverrideMain";
|
||||
//String className = "OverrideMainRet";
|
||||
//String className = "FCTest1";
|
||||
//String className = "FCTest2";
|
||||
//String className = "Pair";
|
||||
//String className = "FCTest3";
|
||||
//String className = "Var";
|
||||
//String className = "Put";
|
||||
String className = "Twice";
|
||||
//PL 2019-10-24: genutzt fuer unterschiedliche Tests
|
||||
path = System.getProperty("user.dir")+"/src/test/resources/AllgemeinTest/" + className + ".jav";
|
||||
//path = System.getProperty("user.dir")+"/src/test/resources/AllgemeinTest/Overloading_Generics.jav";
|
||||
//path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/mathStrucInteger.jav";
|
||||
//compiler = new JavaTXCompiler(Lists.newArrayList(new File(System.getProperty("user.dir")+"/src/test/resources/AllgemeinTest/Overloading_Generics.jav")));
|
||||
///*
|
||||
compiler = new JavaTXCompiler(
|
||||
Lists.newArrayList(new File(path)),
|
||||
Lists.newArrayList(new File(System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/")));
|
||||
//*/
|
||||
compiler.generateBytecode(System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/");
|
||||
pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/";
|
||||
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||
classToTest = loader.loadClass(className);
|
||||
//classToTest = loader.loadClass("Overloading_Generics");
|
||||
//instanceOfClass = classToTest.getDeclaredConstructor().newInstance("A");
|
||||
//classToTest = loader.loadClass("Overloading_Generics1");
|
||||
//instanceOfClass = classToTest.getDeclaredConstructor(Object.class).newInstance("B");
|
||||
}
|
||||
|
||||
}
|
193
src/test/java/bytecode/InheritTest.java
Normal file
193
src/test/java/bytecode/InheritTest.java
Normal file
@ -0,0 +1,193 @@
|
||||
package bytecode;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Field;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Stack;
|
||||
import java.util.Vector;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile;
|
||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||
|
||||
public class InheritTest {
|
||||
private static String path;
|
||||
private static File fileToTest;
|
||||
private static JavaTXCompiler compiler;
|
||||
private static ClassLoader loader;
|
||||
private static Class<?> classToTest;
|
||||
private static Class<?> classToTestAA, classToTestBB, classToTestCC, classToTestDD;
|
||||
private static String pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/";;
|
||||
//private static String pathToClassFile1 = System.getProperty("user.dir") + "/src/test/resources/testBytecode/generatedBC/";
|
||||
private static Object instanceOfClass;
|
||||
private static Object instanceOfClassAA, instanceOfClassBB, instanceOfClassCC, instanceOfClassDD;
|
||||
private static HashMap<ArrayList<String>, Method> hm = new HashMap<>();
|
||||
private static List<ResultSet> typeinferenceResult;
|
||||
private static List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles;
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpBeforeClass() throws Exception {
|
||||
path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/AA.jav";
|
||||
fileToTest = new File(path);
|
||||
compiler = new JavaTXCompiler(fileToTest);
|
||||
List<ResultSet> typeinferenceResult = compiler.typeInference();
|
||||
List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(typeinferenceResult);
|
||||
compiler.generateBytecode(new File(pathToClassFile),typeinferenceResult,simplifyResultsForAllSourceFiles);
|
||||
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||
classToTestAA = loader.loadClass("AA");
|
||||
instanceOfClassAA = classToTestAA.getDeclaredConstructor().newInstance();
|
||||
|
||||
|
||||
|
||||
path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/BB.jav";
|
||||
fileToTest = new File(path);
|
||||
compiler = new JavaTXCompiler(fileToTest);
|
||||
typeinferenceResult = compiler.typeInference();
|
||||
simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(typeinferenceResult);
|
||||
compiler.generateBytecode(new File(pathToClassFile),typeinferenceResult,simplifyResultsForAllSourceFiles);
|
||||
classToTestBB = loader.loadClass("BB");
|
||||
instanceOfClassBB = classToTestBB.getDeclaredConstructor().newInstance();
|
||||
|
||||
path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/CC.jav";
|
||||
fileToTest = new File(path);
|
||||
compiler = new JavaTXCompiler(fileToTest);
|
||||
typeinferenceResult = compiler.typeInference();
|
||||
simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(typeinferenceResult);
|
||||
compiler.generateBytecode(new File(pathToClassFile),typeinferenceResult,simplifyResultsForAllSourceFiles);
|
||||
classToTestCC = loader.loadClass("CC");
|
||||
instanceOfClassCC = classToTestCC.getDeclaredConstructor().newInstance();
|
||||
|
||||
path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/DD.jav";
|
||||
fileToTest = new File(path);
|
||||
compiler = new JavaTXCompiler(fileToTest);
|
||||
typeinferenceResult = compiler.typeInference();
|
||||
simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(typeinferenceResult);
|
||||
compiler.generateBytecode(new File(pathToClassFile),typeinferenceResult,simplifyResultsForAllSourceFiles);
|
||||
classToTestDD = loader.loadClass("DD");
|
||||
instanceOfClassDD = classToTestDD.getDeclaredConstructor().newInstance();
|
||||
|
||||
|
||||
path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/Inherit.jav";
|
||||
fileToTest = new File(path);
|
||||
compiler = new JavaTXCompiler(fileToTest);
|
||||
typeinferenceResult = compiler.typeInference();
|
||||
simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(typeinferenceResult);
|
||||
compiler.generateBytecode(new File(pathToClassFile),typeinferenceResult,simplifyResultsForAllSourceFiles);
|
||||
classToTest = loader.loadClass("Inherit");
|
||||
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInheritClassName() {
|
||||
assertEquals("Inherit", classToTest.getName());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testAAName() {
|
||||
assertEquals("AA", classToTestAA.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBBName() {
|
||||
assertEquals("BB", classToTestBB.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCCName() {
|
||||
assertEquals("CC", classToTestCC.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDDName() {
|
||||
assertEquals("DD", classToTestDD.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testmainAA() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException, MalformedURLException, ClassNotFoundException, NoSuchFieldException {
|
||||
Method m = classToTestAA.getDeclaredMethod("m", Integer.class);
|
||||
assertEquals(m.invoke(instanceOfClassAA, 5), "AA");
|
||||
Method main = classToTest.getDeclaredMethod("main", classToTestAA, Integer.class);
|
||||
assertEquals(main.invoke(instanceOfClass, instanceOfClassAA, 5), "AA");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testmainBB() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException, MalformedURLException, ClassNotFoundException, NoSuchFieldException {
|
||||
Method m = classToTestAA.getDeclaredMethod("m", Integer.class);
|
||||
assertEquals(m.invoke(instanceOfClassBB, 5), "AA");
|
||||
Method main = classToTest.getDeclaredMethod("main", classToTestAA, Integer.class);
|
||||
assertEquals(main.invoke(instanceOfClass, instanceOfClassBB, 5), "AA");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testmainCC() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException, MalformedURLException, ClassNotFoundException, NoSuchFieldException {
|
||||
Method m = classToTestCC.getDeclaredMethod("m", Integer.class);
|
||||
assertEquals(m.invoke(instanceOfClassCC, 5), "CC");
|
||||
Method main = classToTest.getDeclaredMethod("main", classToTestCC, Integer.class);
|
||||
assertEquals(main.invoke(instanceOfClass, instanceOfClassCC, 5), "CC");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testmainDD() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException, MalformedURLException, ClassNotFoundException, NoSuchFieldException {
|
||||
Method m = classToTestCC.getDeclaredMethod("m", Integer.class);
|
||||
assertEquals(m.invoke(instanceOfClassDD, 5), "CC");
|
||||
Method main = classToTest.getDeclaredMethod("main", classToTestCC, Integer.class);
|
||||
assertEquals(main.invoke(instanceOfClass, instanceOfClassDD, 5), "CC");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testmainVectorAA() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException, MalformedURLException, ClassNotFoundException, NoSuchFieldException {
|
||||
Method m = classToTestAA.getDeclaredMethod("m", Integer.class);
|
||||
assertEquals(m.invoke(instanceOfClassAA, 5), "AA");
|
||||
Vector v = new Vector<>();
|
||||
v.add(instanceOfClassAA);
|
||||
Method main = classToTest.getDeclaredMethod("main", Vector.class, Integer.class);
|
||||
assertEquals(main.invoke(instanceOfClass, v, 5), "AA");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testmainVectorBB() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException, MalformedURLException, ClassNotFoundException, NoSuchFieldException {
|
||||
Method m = classToTestAA.getDeclaredMethod("m", Integer.class);
|
||||
assertEquals(m.invoke(instanceOfClassBB, 5), "AA");
|
||||
Vector v = new Vector<>();
|
||||
v.add(instanceOfClassBB);
|
||||
Method main = classToTest.getDeclaredMethod("main", Vector.class, Integer.class);
|
||||
assertEquals(main.invoke(instanceOfClass, v, 5), "AA");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testmainVectorCC() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException, MalformedURLException, ClassNotFoundException, NoSuchFieldException {
|
||||
Method m = classToTestCC.getDeclaredMethod("m", Integer.class);
|
||||
assertEquals(m.invoke(instanceOfClassCC, 5), "CC");
|
||||
Vector v = new Vector<>();
|
||||
v.add(instanceOfClassCC);
|
||||
Method main = classToTest.getDeclaredMethod("main", Vector.class, Integer.class);
|
||||
assertEquals(main.invoke(instanceOfClass, v, 5), "CC");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testmainVectorDD() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException, MalformedURLException, ClassNotFoundException, NoSuchFieldException {
|
||||
Method m = classToTestCC.getDeclaredMethod("m", Integer.class);
|
||||
assertEquals(m.invoke(instanceOfClassDD, 5), "CC");
|
||||
Vector v = new Vector<>();
|
||||
v.add(instanceOfClassDD);
|
||||
Method main = classToTest.getDeclaredMethod("main", Vector.class, Integer.class);
|
||||
assertEquals(main.invoke(instanceOfClass, v, 5), "CC");
|
||||
}
|
||||
}
|
211
src/test/java/bytecode/InheritTest2.java
Normal file
211
src/test/java/bytecode/InheritTest2.java
Normal file
@ -0,0 +1,211 @@
|
||||
package bytecode;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Field;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Stack;
|
||||
import java.util.Vector;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile;
|
||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||
|
||||
public class InheritTest2 {
|
||||
private static String path;
|
||||
private static File fileToTest;
|
||||
private static JavaTXCompiler compiler;
|
||||
private static ClassLoader loader;
|
||||
private static Class<?> classToTest;
|
||||
private static Class<?> classToTestAA, classToTestBB, classToTestCC, classToTestDD;
|
||||
private static String pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/";;
|
||||
//private static String pathToClassFile1 = System.getProperty("user.dir") + "/src/test/resources/testBytecode/generatedBC/";
|
||||
private static Object instanceOfClass;
|
||||
private static Object instanceOfClassAA, instanceOfClassBB, instanceOfClassCC, instanceOfClassDD;
|
||||
private static HashMap<ArrayList<String>, Method> hm = new HashMap<>();
|
||||
private static List<ResultSet> typeinferenceResult;
|
||||
private static List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles;
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpBeforeClass() throws Exception {
|
||||
path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/AA.jav";
|
||||
fileToTest = new File(path);
|
||||
compiler = new JavaTXCompiler(fileToTest);
|
||||
List<ResultSet> typeinferenceResult = compiler.typeInference();
|
||||
List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(typeinferenceResult);
|
||||
compiler.generateBytecode(new File(pathToClassFile),typeinferenceResult,simplifyResultsForAllSourceFiles);
|
||||
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||
classToTestAA = loader.loadClass("AA");
|
||||
instanceOfClassAA = classToTestAA.getDeclaredConstructor().newInstance();
|
||||
|
||||
|
||||
|
||||
path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/BB.jav";
|
||||
fileToTest = new File(path);
|
||||
compiler = new JavaTXCompiler(fileToTest);
|
||||
typeinferenceResult = compiler.typeInference();
|
||||
simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(typeinferenceResult);
|
||||
compiler.generateBytecode(new File(pathToClassFile),typeinferenceResult,simplifyResultsForAllSourceFiles);
|
||||
classToTestBB = loader.loadClass("BB");
|
||||
instanceOfClassBB = classToTestBB.getDeclaredConstructor().newInstance();
|
||||
|
||||
path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/CC.jav";
|
||||
fileToTest = new File(path);
|
||||
compiler = new JavaTXCompiler(fileToTest);
|
||||
typeinferenceResult = compiler.typeInference();
|
||||
simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(typeinferenceResult);
|
||||
compiler.generateBytecode(new File(pathToClassFile),typeinferenceResult,simplifyResultsForAllSourceFiles);
|
||||
classToTestCC = loader.loadClass("CC");
|
||||
instanceOfClassCC = classToTestCC.getDeclaredConstructor().newInstance();
|
||||
|
||||
path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/DD.jav";
|
||||
fileToTest = new File(path);
|
||||
compiler = new JavaTXCompiler(fileToTest);
|
||||
typeinferenceResult = compiler.typeInference();
|
||||
simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(typeinferenceResult);
|
||||
compiler.generateBytecode(new File(pathToClassFile),typeinferenceResult,simplifyResultsForAllSourceFiles);
|
||||
classToTestDD = loader.loadClass("DD");
|
||||
instanceOfClassDD = classToTestDD.getDeclaredConstructor().newInstance();
|
||||
|
||||
|
||||
path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/Inherit2.jav";
|
||||
fileToTest = new File(path);
|
||||
compiler = new JavaTXCompiler(fileToTest);
|
||||
typeinferenceResult = compiler.typeInference();
|
||||
simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(typeinferenceResult);
|
||||
compiler.generateBytecode(new File(pathToClassFile),typeinferenceResult,simplifyResultsForAllSourceFiles);
|
||||
classToTest = loader.loadClass("Inherit2");
|
||||
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInheritClassName() {
|
||||
assertEquals("Inherit2", classToTest.getName());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testAAName() {
|
||||
assertEquals("AA", classToTestAA.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBBName() {
|
||||
assertEquals("BB", classToTestBB.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCCName() {
|
||||
assertEquals("CC", classToTestCC.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDDName() {
|
||||
assertEquals("DD", classToTestDD.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testmainAA() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException, MalformedURLException, ClassNotFoundException, NoSuchFieldException {
|
||||
Method m2 = classToTestAA.getDeclaredMethod("m2", classToTestAA);
|
||||
assertEquals(m2.invoke(instanceOfClassAA, instanceOfClassAA), "AA");
|
||||
Method main = classToTest.getDeclaredMethod("main", classToTestAA);
|
||||
assertEquals(main.invoke(instanceOfClass, instanceOfClassAA), "AA");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testmainBB() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException, MalformedURLException, ClassNotFoundException, NoSuchFieldException {
|
||||
Method m2 = classToTestAA.getDeclaredMethod("m2", classToTestAA);
|
||||
assertEquals(m2.invoke(instanceOfClassAA, instanceOfClassAA), "AA");
|
||||
Method main = classToTest.getDeclaredMethod("main", classToTestAA);
|
||||
assertEquals(main.invoke(instanceOfClass, instanceOfClassBB), "AA");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testmainCC() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException, MalformedURLException, ClassNotFoundException, NoSuchFieldException {
|
||||
Method m2 = classToTestCC.getDeclaredMethod("m2", classToTestCC);
|
||||
assertEquals(m2.invoke(instanceOfClassCC, instanceOfClassCC), "CC");
|
||||
Method main = classToTest.getDeclaredMethod("main", classToTestCC);
|
||||
assertEquals(main.invoke(instanceOfClass, instanceOfClassCC), "CC");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testmainDD() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException, MalformedURLException, ClassNotFoundException, NoSuchFieldException {
|
||||
Method m2 = classToTestCC.getDeclaredMethod("m2", classToTestCC);
|
||||
assertEquals(m2.invoke(instanceOfClassCC, instanceOfClassCC), "CC");
|
||||
Method main = classToTest.getDeclaredMethod("main", classToTestCC);
|
||||
assertEquals(main.invoke(instanceOfClass, instanceOfClassDD), "CC");
|
||||
}
|
||||
|
||||
|
||||
//PL 2020-05-12: Die folgenden Test funktionieren erst, wenn Generics im Bytecode implementiert sind
|
||||
@Test
|
||||
public void testmainVectorAA() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException, MalformedURLException, ClassNotFoundException, NoSuchFieldException {
|
||||
Method m2 = classToTestAA.getDeclaredMethod("m2", classToTestAA);
|
||||
assertEquals(m2.invoke(instanceOfClassAA, instanceOfClassAA), "AA");
|
||||
Vector v = new Vector<>();
|
||||
v.add(instanceOfClassAA);
|
||||
Method main = classToTest.getDeclaredMethod("main", Vector.class);
|
||||
try {
|
||||
assertEquals(main.invoke(instanceOfClass, v), "AA");
|
||||
}
|
||||
catch (java.lang.reflect.InvocationTargetException e) {
|
||||
testmainVectorCC();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testmainVectorBB() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException, MalformedURLException, ClassNotFoundException, NoSuchFieldException {
|
||||
Method m2 = classToTestAA.getDeclaredMethod("m2", classToTestAA);
|
||||
assertEquals(m2.invoke(instanceOfClassAA, instanceOfClassAA), "AA");
|
||||
Vector v = new Vector<>();
|
||||
v.add(instanceOfClassBB);
|
||||
Method main = classToTest.getDeclaredMethod("main", Vector.class);
|
||||
try {
|
||||
assertEquals(main.invoke(instanceOfClass, v), "AA");
|
||||
}
|
||||
catch (java.lang.reflect.InvocationTargetException e) {
|
||||
testmainVectorCC();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testmainVectorCC() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException, MalformedURLException, ClassNotFoundException, NoSuchFieldException {
|
||||
Method m2 = classToTestCC.getDeclaredMethod("m2", classToTestCC);
|
||||
assertEquals(m2.invoke(instanceOfClassCC, instanceOfClassCC), "CC");
|
||||
Vector v = new Vector<>();
|
||||
v.add(instanceOfClassCC);
|
||||
Method main = classToTest.getDeclaredMethod("main", Vector.class);
|
||||
String erg;
|
||||
assertEquals(erg= (String) main.invoke(instanceOfClass, v),
|
||||
erg.equals("CC")? "CC": "AA");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testmainVectorDD() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException, MalformedURLException, ClassNotFoundException, NoSuchFieldException {
|
||||
Method m2 = classToTestCC.getDeclaredMethod("m2", classToTestCC);
|
||||
assertEquals(m2.invoke(instanceOfClassCC, instanceOfClassCC), "CC");
|
||||
Vector v = new Vector<>();
|
||||
v.add(instanceOfClassDD);
|
||||
Method main = classToTest.getDeclaredMethod("main", Vector.class);
|
||||
String erg;
|
||||
assertEquals(erg= (String) main.invoke(instanceOfClass, v),
|
||||
erg.equals("CC")? "CC": "AA");
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -28,7 +28,7 @@ public class MatrixTest {
|
||||
|
||||
@Test
|
||||
public void test() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, ClassNotFoundException, IOException, InstantiationException {
|
||||
path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/Matrix.jav";
|
||||
path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/MatrixAL.jav";
|
||||
fileToTest = new File(path);
|
||||
compiler = new JavaTXCompiler(fileToTest);
|
||||
pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/";
|
||||
|
86
src/test/java/bytecode/PutTest.java
Normal file
86
src/test/java/bytecode/PutTest.java
Normal file
@ -0,0 +1,86 @@
|
||||
package bytecode;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.util.List;
|
||||
import java.util.Stack;
|
||||
import java.util.Vector;
|
||||
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile;
|
||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||
|
||||
public class PutTest {
|
||||
private static String path;
|
||||
private static File fileToTest;
|
||||
private static JavaTXCompiler compiler;
|
||||
private static ClassLoader loader;
|
||||
private static Class<?> classToTest;
|
||||
private static Class<?> classToTest1;
|
||||
private static String pathToClassFile;
|
||||
private static Object instanceOfClass;
|
||||
private static Object instanceOfClass1;
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpBeforeClass() throws Exception {
|
||||
path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/Put.jav";
|
||||
fileToTest = new File(path);
|
||||
compiler = new JavaTXCompiler(fileToTest);
|
||||
pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/";
|
||||
List<ResultSet> typeinferenceResult = compiler.typeInference();
|
||||
List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(typeinferenceResult);
|
||||
compiler.generateBytecode(new File(pathToClassFile),typeinferenceResult,simplifyResultsForAllSourceFiles);
|
||||
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||
classToTest = loader.loadClass("Put");
|
||||
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPutClassName() {
|
||||
assertEquals("Put", classToTest.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPutElementVector() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
||||
Method m = classToTest.getDeclaredMethod("putElement", Object.class, Vector.class);
|
||||
Vector<Integer> v_invoke = new Vector<>();
|
||||
m.invoke(instanceOfClass, 5, v_invoke);
|
||||
Vector<Integer> v = new Vector<>();
|
||||
v.add(5);
|
||||
assertEquals(v, v_invoke);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPutElementStack() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
||||
Method m = classToTest.getDeclaredMethod("putElement", Object.class, Stack.class);
|
||||
Stack<Integer> s_invoke = new Stack<>();
|
||||
m.invoke(instanceOfClass, 5, s_invoke);
|
||||
assertEquals(new Integer(5), s_invoke.pop());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMainVector() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
||||
Method m = classToTest.getDeclaredMethod("main", Object.class, Vector.class);
|
||||
Vector<Integer> v_invoke = new Vector<>();
|
||||
m.invoke(instanceOfClass, 6, v_invoke);
|
||||
Vector<Integer> v = new Vector<>();
|
||||
v.add(6);
|
||||
assertEquals(v, v_invoke);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMainStack() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
||||
Method m = classToTest.getDeclaredMethod("main", Object.class, Stack.class);
|
||||
Stack<Integer> s_invoke = new Stack<>();
|
||||
m.invoke(instanceOfClass, 6, s_invoke);
|
||||
assertEquals(new Integer(6), s_invoke.pop());
|
||||
}
|
||||
}
|
40
src/test/java/bytecode/mathStrucMatrixOPTest.java.txt
Normal file
40
src/test/java/bytecode/mathStrucMatrixOPTest.java.txt
Normal file
@ -0,0 +1,40 @@
|
||||
package bytecode;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Field;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||
|
||||
public class mathStrucMatrixOPTest {
|
||||
|
||||
private static String path;
|
||||
private static File fileToTest;
|
||||
private static JavaTXCompiler compiler;
|
||||
private static ClassLoader loader;
|
||||
private static Class<?> classToTest;
|
||||
private static String pathToClassFile;
|
||||
private static Object instanceOfClass;
|
||||
|
||||
|
||||
@Test
|
||||
public void test() throws Exception {
|
||||
//PL 2019-10-24: laeuft nicht durch deshalb ersetzt
|
||||
path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/mathStrucMatrixOp.jav";
|
||||
//path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/mathStrucInteger.jav";
|
||||
fileToTest = new File(path);
|
||||
compiler = new JavaTXCompiler(fileToTest);
|
||||
compiler.generateBytecode(System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/");
|
||||
pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/";
|
||||
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||
classToTest = loader.loadClass("mathStrucMatrixOP");
|
||||
instanceOfClass = classToTest.getDeclaredConstructor(Object.class).newInstance("A");
|
||||
}
|
||||
|
||||
}
|
38
src/test/java/bytecode/mathStrucVectorAddTest.java.txt
Normal file
38
src/test/java/bytecode/mathStrucVectorAddTest.java.txt
Normal file
@ -0,0 +1,38 @@
|
||||
package bytecode;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Field;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||
|
||||
public class mathStrucVectorAddTest {
|
||||
|
||||
private static String path;
|
||||
private static File fileToTest;
|
||||
private static JavaTXCompiler compiler;
|
||||
private static ClassLoader loader;
|
||||
private static Class<?> classToTest;
|
||||
private static String pathToClassFile;
|
||||
private static Object instanceOfClass;
|
||||
|
||||
|
||||
@Test
|
||||
public void test() throws Exception {
|
||||
path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/mathStrucVector.jav";
|
||||
fileToTest = new File(path);
|
||||
compiler = new JavaTXCompiler(fileToTest);
|
||||
compiler.generateBytecode(System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/");
|
||||
pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/";
|
||||
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||
classToTest = loader.loadClass("mathStrucVector");
|
||||
//instanceOfClass = classToTest.getDeclaredConstructor(Integer.class).newInstance("A");
|
||||
}
|
||||
|
||||
}
|
51
src/test/java/packages/mathStrucMatrixOPTest.java.txt
Normal file
51
src/test/java/packages/mathStrucMatrixOPTest.java.txt
Normal file
@ -0,0 +1,51 @@
|
||||
package packages;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
|
||||
public class mathStrucMatrixOPTest extends TestCase {
|
||||
|
||||
public static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/javFiles/packageTest/de/test/";
|
||||
|
||||
|
||||
public mathStrucMatrixOPTest() throws ClassNotFoundException, IOException {
|
||||
/*
|
||||
Generate ToImport class in rootDirectory and in output-Directory
|
||||
*/
|
||||
/* PL 2020-01-07 kann z.Zt. nicht erzeugt werden (siehe Bug 170, http://bugzilla.ba-horb.de/show_bug.cgi?id=170)
|
||||
JavaTXCompiler compiler = new JavaTXCompiler(new File(rootDirectory+"mathStruc.jav"));
|
||||
compiler.typeInference();
|
||||
compiler.generateBytecode(rootDirectory + "output/");
|
||||
File f = new File(rootDirectory + "output/de/test/mathStruc.class");
|
||||
assertTrue(f.exists());
|
||||
*/
|
||||
JavaTXCompiler compiler = new JavaTXCompiler(new File(rootDirectory+"MatrixOP.jav"));
|
||||
compiler.typeInference();
|
||||
compiler.generateBytecode(rootDirectory + "output/");
|
||||
File f = new File(rootDirectory + "output/de/test/MatrixOP.class");
|
||||
assertTrue(f.exists());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetPackageNameInBytecodeAndOutputFolder() throws IOException, ClassNotFoundException {
|
||||
JavaTXCompiler compiler = new JavaTXCompiler(
|
||||
Lists.newArrayList(new File(rootDirectory+"mathStrucMatrixOP.jav")),
|
||||
Lists.newArrayList(new File(rootDirectory+"output/")));
|
||||
compiler.typeInference();
|
||||
File f = new File(rootDirectory + "output/de/test/mathStrucMatrixOP.class");
|
||||
if(f.exists() && !f.isDirectory()) {
|
||||
f.delete();
|
||||
}
|
||||
compiler.generateBytecode(rootDirectory + "output/");
|
||||
f = new File(rootDirectory + "output/de/test/mathStrucMatrixOP.class");
|
||||
assertTrue(f.exists());
|
||||
}
|
||||
}
|
12
src/test/resources/AllgemeinTest/FCTest1.jav
Normal file
12
src/test/resources/AllgemeinTest/FCTest1.jav
Normal file
@ -0,0 +1,12 @@
|
||||
import java.util.Vector;
|
||||
import java.util.List;
|
||||
import java.lang.Integer;
|
||||
|
||||
class FCTest1 extends Vector<Vector<Integer>> {
|
||||
fc1() {
|
||||
var y;
|
||||
var z;
|
||||
y.add(z);
|
||||
return y;
|
||||
}
|
||||
}
|
11
src/test/resources/AllgemeinTest/FCTest2.jav
Normal file
11
src/test/resources/AllgemeinTest/FCTest2.jav
Normal file
@ -0,0 +1,11 @@
|
||||
import java.util.Vector;
|
||||
import java.util.List;
|
||||
import java.lang.Integer;
|
||||
|
||||
class FCTest2 extends Vector<Vector<Integer>> {
|
||||
fc2(y) {
|
||||
var z;
|
||||
y.add(z);
|
||||
return y;
|
||||
}
|
||||
}
|
19
src/test/resources/AllgemeinTest/FCTest3.jav
Normal file
19
src/test/resources/AllgemeinTest/FCTest3.jav
Normal file
@ -0,0 +1,19 @@
|
||||
import java.util.Vector;
|
||||
import java.lang.Integer;
|
||||
|
||||
class FCTest3 extends Pair<Vector<Integer>, Vector<Integer>> {
|
||||
|
||||
|
||||
fc2(x) {
|
||||
x.snd().addElement(2);
|
||||
}
|
||||
|
||||
|
||||
|
||||
fc2a() {
|
||||
var y;
|
||||
y.snd().addElement(2);
|
||||
return y;
|
||||
}
|
||||
|
||||
}
|
10
src/test/resources/AllgemeinTest/GenTest.jav
Normal file
10
src/test/resources/AllgemeinTest/GenTest.jav
Normal file
@ -0,0 +1,10 @@
|
||||
import java.lang.Integer;
|
||||
import java.util.Vector;
|
||||
|
||||
public class GenTest {
|
||||
|
||||
main(x) {
|
||||
var v = new Vector();
|
||||
return 1 + v.elementAt(0);
|
||||
}
|
||||
}
|
9
src/test/resources/AllgemeinTest/Generics.jav
Normal file
9
src/test/resources/AllgemeinTest/Generics.jav
Normal file
@ -0,0 +1,9 @@
|
||||
class Generics {
|
||||
a;
|
||||
id(b) { return b; }
|
||||
setA(x) {
|
||||
a = x;
|
||||
return a;
|
||||
}
|
||||
m(x,y) { x = id(y); }
|
||||
}
|
9
src/test/resources/AllgemeinTest/OverloadingMain.jav
Normal file
9
src/test/resources/AllgemeinTest/OverloadingMain.jav
Normal file
@ -0,0 +1,9 @@
|
||||
import java.util.Stack;
|
||||
import java.util.Vector;
|
||||
|
||||
class OverloadingMain {
|
||||
|
||||
mmMain(x) { var y; return new O1().mm(y); }
|
||||
|
||||
}
|
||||
|
20
src/test/resources/AllgemeinTest/Overloading_Generics.jav
Normal file
20
src/test/resources/AllgemeinTest/Overloading_Generics.jav
Normal file
@ -0,0 +1,20 @@
|
||||
import java.lang.Integer;
|
||||
|
||||
|
||||
public class Overloading_Generics {
|
||||
|
||||
id1 (x) { return x; }
|
||||
|
||||
//Integer id (Integer x) { return x; }
|
||||
}
|
||||
|
||||
|
||||
class Overloading_Generics1 {
|
||||
main(x) {
|
||||
var olg = new Overloading_Generics();
|
||||
return olg.id1(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
25
src/test/resources/AllgemeinTest/OverrideMain.jav
Normal file
25
src/test/resources/AllgemeinTest/OverrideMain.jav
Normal file
@ -0,0 +1,25 @@
|
||||
import java.util.Vector;
|
||||
import java.util.Stack;
|
||||
|
||||
class OverrideMain {
|
||||
ovrMain(x) {
|
||||
var overide;
|
||||
overide.ovr(x);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
[
|
||||
[(TPH L = java.util.Stack<TPH FTM>), (TPH N = java.lang.String), (TPH M = ? extends Override2), (TPH FTN, TPH FTM), (TPH K = void)],
|
||||
[(TPH FTO, TPH FTP), (TPH M = ? extends Override2), (TPH N = java.lang.String), (TPH L = java.util.Stack<TPH FTP>), (TPH K = void)],
|
||||
[(TPH M = ? extends Override2), (TPH N = java.lang.String), (TPH K = void), (TPH FTR, TPH FTQ), (TPH L = java.util.Vector<TPH FTQ>)],
|
||||
[(TPH FTT, TPH FTS), (TPH M = ? extends Override2), (TPH L = java.util.Vector<TPH FTS>), (TPH K = void), (TPH N = java.lang.String)],
|
||||
[(TPH L = java.util.Vector<TPH FTV>), (TPH M = ? extends Override2), (TPH N = java.lang.String), (TPH FTU, TPH FTV), (TPH K = void)],
|
||||
[(TPH FTX, TPH FTW), (TPH M = ? extends Override2), (TPH L = java.util.Vector<TPH FTW>), (TPH K = void), (TPH N = java.lang.String)],
|
||||
[(TPH M = ? extends Override2), (TPH L = java.util.Stack<TPH FTZ>), (TPH K = void), (TPH FTY, TPH FTZ), (TPH N = java.lang.String)],
|
||||
[(TPH FUB, TPH FUA), (TPH K = void), (TPH M = ? extends Override2), (TPH N = java.lang.String), (TPH L = java.util.Vector<TPH FUA>)],
|
||||
[(TPH N = java.lang.String), (TPH L = java.util.Vector<TPH FUC>), (TPH FUD, TPH FUC), (TPH M = ? extends Override2), (TPH K = void)],
|
||||
[(TPH N = java.lang.String), (TPH FUF, TPH FUE), (TPH M = ? extends Override2), (TPH K = void), (TPH L = java.util.Vector<TPH FUE>)]]
|
||||
|
||||
[[(TPH M = ? extends Override2), (TPH MNX, TPH MNY), (TPH N = java.lang.String), (TPH K = void), (TPH L = java.util.Stack<TPH MNY>)], [(TPH L = java.util.Stack<TPH MOC>), (TPH N = java.lang.String), (TPH M = ? extends Override2), (TPH K = void), (TPH MOB, TPH MOC)], [(TPH M = ? extends Override2), (TPH N = java.lang.String), (TPH MNZ, TPH MOA), (TPH L = java.util.Vector<TPH MOA>), (TPH K = void)], [(TPH L = java.util.Vector<TPH MOE>), (TPH K = void), (TPH M = ? extends Override2), (TPH MOD, TPH MOE), (TPH N = java.lang.String)], [(TPH M = ? extends Override2), (TPH K = void), (TPH N = java.lang.String), (TPH MOF, TPH MOG), (TPH L = java.util.Stack<TPH MOG>)], [(TPH L = java.util.Vector<TPH MOI>), (TPH K = void), (TPH MOH, TPH MOI), (TPH M = ? extends Override2), (TPH N = java.lang.String)], [(TPH L = java.util.Vector<TPH MOK>), (TPH MOJ, TPH MOK), (TPH K = void), (TPH M = ? extends Override2), (TPH N = java.lang.String)], [(TPH MOL, TPH MOM), (TPH L = java.util.Stack<TPH MOM>), (TPH M = ? extends Override2), (TPH K = void), (TPH N = java.lang.String)], [(TPH L = java.util.Vector<TPH MOO>), (TPH MON, TPH MOO), (TPH N = java.lang.String), (TPH K = void), (TPH M = ? extends Override2)], [(TPH L = java.util.Stack<TPH MOP>), (TPH N = java.lang.String), (TPH M = ? extends Override2), (TPH MOQ, TPH MOP), (TPH K = void)]]
|
||||
*/
|
11
src/test/resources/AllgemeinTest/OverrideMainRet.jav
Normal file
11
src/test/resources/AllgemeinTest/OverrideMainRet.jav
Normal file
@ -0,0 +1,11 @@
|
||||
import java.util.Vector;
|
||||
import java.util.Stack;
|
||||
|
||||
class OverrideMainRet {
|
||||
ovrMain() {
|
||||
var overide;
|
||||
var x;
|
||||
overide.ovr(x);
|
||||
return x;
|
||||
}
|
||||
}
|
12
src/test/resources/AllgemeinTest/Pair.java
Normal file
12
src/test/resources/AllgemeinTest/Pair.java
Normal file
@ -0,0 +1,12 @@
|
||||
class Pair<T, U> {
|
||||
T x;
|
||||
U y;
|
||||
|
||||
public T fst () {
|
||||
return x;
|
||||
}
|
||||
|
||||
public U snd () {
|
||||
return y;
|
||||
}
|
||||
}
|
8
src/test/resources/bytecode/javFiles/AA.jav
Normal file
8
src/test/resources/bytecode/javFiles/AA.jav
Normal file
@ -0,0 +1,8 @@
|
||||
import java.lang.Integer;
|
||||
import java.lang.String;
|
||||
|
||||
public class AA {
|
||||
m(Integer i) { return "AA"; }
|
||||
|
||||
m2(AA x) { return "AA"; }
|
||||
}
|
3
src/test/resources/bytecode/javFiles/BB.jav
Normal file
3
src/test/resources/bytecode/javFiles/BB.jav
Normal file
@ -0,0 +1,3 @@
|
||||
import java.lang.Integer;
|
||||
|
||||
public class BB extends AA { }
|
11
src/test/resources/bytecode/javFiles/CC.jav
Normal file
11
src/test/resources/bytecode/javFiles/CC.jav
Normal file
@ -0,0 +1,11 @@
|
||||
import java.lang.Integer;
|
||||
import java.lang.String;
|
||||
|
||||
|
||||
public class CC extends BB {
|
||||
m(Integer i) {
|
||||
return "CC";
|
||||
}
|
||||
|
||||
m2(CC x) { return "CC"; }
|
||||
}
|
4
src/test/resources/bytecode/javFiles/DD.jav
Normal file
4
src/test/resources/bytecode/javFiles/DD.jav
Normal file
@ -0,0 +1,4 @@
|
||||
import java.lang.Integer;
|
||||
|
||||
public class DD extends CC { }
|
||||
|
18
src/test/resources/bytecode/javFiles/Inherit.jav
Normal file
18
src/test/resources/bytecode/javFiles/Inherit.jav
Normal file
@ -0,0 +1,18 @@
|
||||
import java.util.Vector;
|
||||
|
||||
import java.lang.Integer;
|
||||
import java.lang.String;
|
||||
|
||||
|
||||
public class Inherit {
|
||||
|
||||
main(d, i) {
|
||||
return d.m(i);
|
||||
}
|
||||
|
||||
main(v, i) {
|
||||
var aa = v.elementAt(0);
|
||||
return aa.m(i);
|
||||
}
|
||||
|
||||
}
|
17
src/test/resources/bytecode/javFiles/Inherit2.jav
Normal file
17
src/test/resources/bytecode/javFiles/Inherit2.jav
Normal file
@ -0,0 +1,17 @@
|
||||
import java.util.Vector;
|
||||
|
||||
import java.lang.Integer;
|
||||
import java.lang.String;
|
||||
|
||||
|
||||
public class Inherit2 {
|
||||
|
||||
main(d) {
|
||||
return d.m2(d);
|
||||
}
|
||||
|
||||
main(v) {
|
||||
var aa = v.elementAt(0);
|
||||
return aa.m2(aa);
|
||||
}
|
||||
}
|
19
src/test/resources/bytecode/javFiles/Put.jav
Normal file
19
src/test/resources/bytecode/javFiles/Put.jav
Normal file
@ -0,0 +1,19 @@
|
||||
import java.util.Vector;
|
||||
import java.util.Stack;
|
||||
|
||||
public class Put {
|
||||
|
||||
putElement(ele, v) {
|
||||
v.addElement(ele);
|
||||
}
|
||||
|
||||
putElement(ele, s) {
|
||||
s.push(ele);
|
||||
}
|
||||
|
||||
|
||||
main(ele, x) {
|
||||
putElement(ele, x);
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user