Compare commits
12 Commits
71dfe5d9e1
...
aspGen
| Author | SHA1 | Date | |
|---|---|---|---|
| 9c2c6a3ea9 | |||
| a7ad4fa984 | |||
| fcda301b1e | |||
|
|
2aa3997f17 | ||
|
|
7e37497740 | ||
|
|
3d2b935c60 | ||
|
|
db01b0c8dd | ||
| 662756ac18 | |||
| b0bf41968e | |||
|
|
2221b559ca | ||
|
|
021b7ec9fe | ||
|
|
154d4823e4 |
9
README.md
Normal file
9
README.md
Normal file
@@ -0,0 +1,9 @@
|
||||
Prototype
|
||||
|
||||
run with:
|
||||
|
||||
mvn test -Dtest="TestComplete#matrixTest"
|
||||
|
||||
mvn test -Dtest="typeinference.JavaTXCompilerTest#importTest"
|
||||
|
||||
then the output is in: /tmp/output
|
||||
5
pom.xml
5
pom.xml
@@ -53,9 +53,8 @@ http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.11.0</version>
|
||||
<configuration>
|
||||
<compilerArgs>--enable-preview</compilerArgs>
|
||||
<source>21</source>
|
||||
<target>21</target>
|
||||
<source>22</source>
|
||||
<target>22</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
|
||||
10
resources/AllgemeinTest/Box.jav
Normal file
10
resources/AllgemeinTest/Box.jav
Normal file
@@ -0,0 +1,10 @@
|
||||
class Box<A> {
|
||||
|
||||
A a;
|
||||
|
||||
Box(A a) {
|
||||
this.a = a;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
13
resources/bytecode/javFiles/Bug325.jav
Normal file
13
resources/bytecode/javFiles/Bug325.jav
Normal file
@@ -0,0 +1,13 @@
|
||||
import java.lang.Integer;
|
||||
import java.util.function.Function;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class Bug325 {
|
||||
public main() {
|
||||
List<Integer> list = new ArrayList<>(List.of(1,2,3,4,5));
|
||||
var func = x -> x*2;
|
||||
return list.stream().map(func).toList();
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
import java.util.List;
|
||||
import java.util.AbstractList;
|
||||
import java.util.Vector;
|
||||
import java.lang.Integer;
|
||||
|
||||
@@ -66,7 +66,7 @@ public class JavaTXCompiler {
|
||||
Boolean resultmodel = true;
|
||||
public final Map<File, SourceFile> sourceFiles = new HashMap<>();
|
||||
|
||||
Boolean log = false; //gibt an ob ein Log-File nach System.getProperty("user.dir")+""/logFiles/"" geschrieben werden soll?
|
||||
Boolean log = true; //gibt an ob ein Log-File nach System.getProperty("user.dir")+""/logFiles/"" geschrieben werden soll?
|
||||
public volatile UnifyTaskModel usedTasks = new UnifyTaskModel();
|
||||
public final DirectoryClassLoader classLoader;
|
||||
|
||||
@@ -207,7 +207,7 @@ public class JavaTXCompiler {
|
||||
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(), true));
|
||||
(GenericDeclarationList) m.getGenerics(), m.getOffset(), true, false));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -33,6 +33,7 @@ public class Method extends SyntaxTreeNode implements IItemWithOffset, TypeScope
|
||||
private GenericDeclarationList generics;
|
||||
private final RefTypeOrTPHOrWildcardOrGeneric returnType;
|
||||
public final Boolean isInherited;
|
||||
public final Boolean isImplemented;
|
||||
|
||||
/*
|
||||
* its Constraints
|
||||
@@ -50,10 +51,11 @@ public class Method extends SyntaxTreeNode implements IItemWithOffset, TypeScope
|
||||
this.block = block;
|
||||
this.generics = gtvDeclarations;
|
||||
this.isInherited = false;
|
||||
this.isImplemented = false;
|
||||
}
|
||||
|
||||
public Method(int modifier, String name, RefTypeOrTPHOrWildcardOrGeneric returnType, ParameterList parameterList, Block block,
|
||||
GenericDeclarationList gtvDeclarations, Token offset, Boolean isInherited) {
|
||||
GenericDeclarationList gtvDeclarations, Token offset, Boolean isInherited, Boolean isOverridden) {
|
||||
super(offset);
|
||||
this.name = name;
|
||||
this.modifier = modifier;
|
||||
@@ -62,6 +64,7 @@ public class Method extends SyntaxTreeNode implements IItemWithOffset, TypeScope
|
||||
this.block = block;
|
||||
this.generics = gtvDeclarations;
|
||||
this.isInherited = isInherited;
|
||||
this.isImplemented = isOverridden;
|
||||
}
|
||||
|
||||
public ParameterList getParameterList() {
|
||||
@@ -107,4 +110,10 @@ public class Method extends SyntaxTreeNode implements IItemWithOffset, TypeScope
|
||||
public int hashCode() {
|
||||
return Objects.hash(name, parameterlist, returnType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -105,11 +105,46 @@ public class ASTFactory {
|
||||
allInheritedMethods.removeAll(allDeclaredMethods);
|
||||
for (java.lang.reflect.Method method : allDeclaredMethods) {
|
||||
var signature = methodSignatures.get(new Pair<>(method.getName(), org.objectweb.asm.Type.getMethodDescriptor(method)));
|
||||
methoden.add(createMethod(method, signature, jreClass, false));
|
||||
}
|
||||
if (jreClass.getSuperclass()==null) {
|
||||
methoden.add(createMethod(method, signature, jreClass, false, false));
|
||||
}
|
||||
else {
|
||||
Boolean isImplemented = false;
|
||||
isImplemented = Arrays.stream(jreClass.getInterfaces()).
|
||||
reduce(false,
|
||||
(x,y) -> {
|
||||
try {
|
||||
y.getDeclaredMethod(method.getName(), method.getParameterTypes());
|
||||
return true;
|
||||
}
|
||||
catch (java.lang.NoSuchMethodException e) {
|
||||
return false;
|
||||
}},
|
||||
(x,y) -> (x || y)
|
||||
);
|
||||
|
||||
if (isImplemented) {
|
||||
methoden.add(createMethod(method, signature, jreClass, false, true));
|
||||
}
|
||||
else {
|
||||
if (Modifier.isAbstract(jreClass.getSuperclass().getModifiers())) {
|
||||
try {
|
||||
jreClass.getSuperclass().getDeclaredMethod(method.getName(), method.getParameterTypes());
|
||||
methoden.add(createMethod(method, signature, jreClass, false, true));
|
||||
}
|
||||
catch (java.lang.NoSuchMethodException e) {
|
||||
methoden.add(createMethod(method, signature, jreClass, false, false));
|
||||
}
|
||||
}
|
||||
else {
|
||||
methoden.add(createMethod(method, signature, jreClass, false, false));
|
||||
}
|
||||
|
||||
}
|
||||
}}
|
||||
for (java.lang.reflect.Method method : allInheritedMethods) {
|
||||
var signature = methodSignatures.get(new Pair<>(method.getName(), org.objectweb.asm.Type.getMethodDescriptor(method)));
|
||||
methoden.add(createMethod(method, signature, jreClass, true));
|
||||
methoden.add(createMethod(method, signature, jreClass, true, false));
|
||||
}
|
||||
List<Field> felder = new ArrayList<>();
|
||||
for (java.lang.reflect.Field field : jreClass.getDeclaredFields()) {
|
||||
@@ -192,7 +227,7 @@ public class ASTFactory {
|
||||
return Optional.of(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, String signature, java.lang.Class inClass, Boolean isInherited) {
|
||||
public static Method createMethod(java.lang.reflect.Method jreMethod, String signature, java.lang.Class inClass, Boolean isInherited, Boolean isImplemented) {
|
||||
String name = jreMethod.getName();
|
||||
RefTypeOrTPHOrWildcardOrGeneric returnType;
|
||||
Type jreRetType;
|
||||
@@ -218,7 +253,7 @@ public class ASTFactory {
|
||||
GenericDeclarationList gtvDeclarations = createGenerics(jreMethod.getTypeParameters(), inClass, jreMethod.getName(), signature);
|
||||
Token offset = new NullToken();
|
||||
|
||||
return new Method(jreMethod.getModifiers(), name, returnType, parameterList, block, gtvDeclarations, offset, isInherited);
|
||||
return new Method(jreMethod.getModifiers(), name, returnType, parameterList, block, gtvDeclarations, offset, isInherited, isImplemented);
|
||||
}
|
||||
|
||||
public static GenericDeclarationList createGenerics(TypeVariable[] typeParameters, Class context, String methodName, String signature) {
|
||||
|
||||
@@ -20,14 +20,16 @@ public class MethodAssumption extends Assumption{
|
||||
private RefTypeOrTPHOrWildcardOrGeneric retType;
|
||||
List<? extends RefTypeOrTPHOrWildcardOrGeneric> params;
|
||||
private final Boolean isInherited;
|
||||
private final Boolean isOverridden;
|
||||
|
||||
public MethodAssumption(ClassOrInterface receiver, RefTypeOrTPHOrWildcardOrGeneric retType,
|
||||
List<? extends RefTypeOrTPHOrWildcardOrGeneric> params, TypeScope scope, Boolean isInherited){
|
||||
List<? extends RefTypeOrTPHOrWildcardOrGeneric> params, TypeScope scope, Boolean isInherited, Boolean isOverridden){
|
||||
super(scope);
|
||||
this.receiver = receiver;
|
||||
this.retType = retType;
|
||||
this.params = params;
|
||||
this.isInherited = isInherited;
|
||||
this.isOverridden = isOverridden;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -74,4 +76,8 @@ public class MethodAssumption extends Assumption{
|
||||
public Boolean isInherited() {
|
||||
return isInherited;
|
||||
}
|
||||
|
||||
public Boolean isOverridden() {
|
||||
return isOverridden;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,8 @@ 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 Boolean isInherited = false;//wird beides nur für die Method-Constraints benoetigt
|
||||
private Boolean isImplemented = false;
|
||||
|
||||
/*
|
||||
* wird verwendet um bei der Codegenerierung die richtige Methoden - Signatur
|
||||
@@ -22,12 +23,14 @@ public class Constraint<A> extends HashSet<A> {
|
||||
super();
|
||||
}
|
||||
|
||||
public Constraint(Boolean isInherited) {
|
||||
public Constraint(Boolean isInherited, Boolean isImplemented) {
|
||||
this.isInherited = isInherited;
|
||||
this.isImplemented = isImplemented;
|
||||
}
|
||||
|
||||
public Constraint(Boolean isInherited, Constraint<A> extendConstraint, Set<A> methodSignatureConstraint) {
|
||||
public Constraint(Boolean isInherited, Boolean isImplemented, Constraint<A> extendConstraint, Set<A> methodSignatureConstraint) {
|
||||
this.isInherited = isInherited;
|
||||
this.isImplemented = isImplemented;
|
||||
this.extendConstraint = extendConstraint;
|
||||
this.methodSignatureConstraint = methodSignatureConstraint;
|
||||
}
|
||||
@@ -40,6 +43,10 @@ public class Constraint<A> extends HashSet<A> {
|
||||
return isInherited;
|
||||
}
|
||||
|
||||
public Boolean isImplemented() {
|
||||
return isImplemented;
|
||||
}
|
||||
|
||||
public Constraint<A> getExtendConstraint() {
|
||||
return extendConstraint;
|
||||
}
|
||||
@@ -57,7 +64,7 @@ public class Constraint<A> extends HashSet<A> {
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return super.toString() + "\nisInherited = " + isInherited
|
||||
return super.toString() + "\nisInherited = " + isInherited + " isOveridden = " + isImplemented
|
||||
+ methodSignatureConstraint
|
||||
//" + extendsContraint: " + (extendConstraint != null ? extendConstraint.toStringBase() : "null" )
|
||||
+ "\n" ;
|
||||
@@ -66,5 +73,5 @@ public class Constraint<A> extends HashSet<A> {
|
||||
public String toStringBase() {
|
||||
return super.toString();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -71,12 +71,13 @@ public class ConstraintSet<A> {
|
||||
|
||||
for(Set<Constraint<A>> oderConstraint : oderConstraints){
|
||||
newOder.add(
|
||||
oderConstraint.parallelStream().map((Constraint<A> as) -> {
|
||||
oderConstraint.stream().map((Constraint<A> as) -> {
|
||||
|
||||
Constraint<B> newConst = as.stream()
|
||||
.map(o)
|
||||
.collect(Collectors.toCollection((
|
||||
() -> new Constraint<B> (as.isInherited(),
|
||||
as.isImplemented(),
|
||||
(as.getExtendConstraint() != null)
|
||||
? as.getExtendConstraint().stream().map(o).collect(Collectors.toCollection(Constraint::new))
|
||||
: null,
|
||||
@@ -126,4 +127,5 @@ public class ConstraintSet<A> {
|
||||
public Set<A> getUndConstraints() {
|
||||
return undConstraints;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -136,8 +136,12 @@ public class Pair implements Serializable
|
||||
public boolean OperatorSmallerDot() {
|
||||
return eOperator == PairOperator.SMALLERDOT;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public boolean OperatorSmallerNEQDot() {
|
||||
return eOperator == PairOperator.SMALLERNEQDOT;
|
||||
}
|
||||
|
||||
|
||||
static public Map<String, TypePlaceholder> generateTPHMap(ConstraintSet<Pair> constraints) {
|
||||
HashMap<String, TypePlaceholder> ret = new HashMap<>();
|
||||
constraints.map((Pair p) -> {
|
||||
|
||||
@@ -5,13 +5,17 @@ import de.dhbwstuttgart.parser.scope.JavaClassName;
|
||||
import de.dhbwstuttgart.syntaxtree.*;
|
||||
import de.dhbwstuttgart.syntaxtree.factory.ASTFactory;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Statement;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.syntaxtree.type.*;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceBlockInformation;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceInformation;
|
||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Pair;
|
||||
import de.dhbwstuttgart.util.BiRelation;
|
||||
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class TYPE {
|
||||
|
||||
@@ -24,16 +28,80 @@ public class TYPE {
|
||||
}
|
||||
|
||||
public ConstraintSet getConstraints() {
|
||||
ConstraintSet ret = new ConstraintSet();
|
||||
ConstraintSet<Pair> ret = new ConstraintSet();
|
||||
for (ClassOrInterface cl : sf.KlassenVektor) {
|
||||
var allClasses = new HashSet<ClassOrInterface>();
|
||||
allClasses.addAll(allAvailableClasses);
|
||||
allClasses.addAll(sf.availableClasses);
|
||||
ret.addAll(getConstraintsClass(cl, new TypeInferenceInformation(allClasses)));
|
||||
}
|
||||
writeASP(ret);
|
||||
//System.exit(0);
|
||||
return ret;
|
||||
}
|
||||
|
||||
private String toASP(RefTypeOrTPHOrWildcardOrGeneric type){
|
||||
if(type instanceof TypePlaceholder){
|
||||
return "_"+((TypePlaceholder) type).getName();
|
||||
}else if(type instanceof RefType){
|
||||
if(((RefType) type).getParaList().size() > 0){
|
||||
return ((RefType) type).getName() + "<" +
|
||||
((RefType) type).getParaList().stream().map(this::toASP).collect(Collectors.joining(", ")) +
|
||||
">";
|
||||
}else{
|
||||
return ((RefType) type).getName().toString();
|
||||
}
|
||||
}else if(type instanceof ExtendsWildcardType){
|
||||
return toASP(((ExtendsWildcardType) type).getInnerType());
|
||||
} else if(type instanceof SuperWildcardType) {
|
||||
return toASP(((SuperWildcardType) type).getInnerType());
|
||||
} else if(type instanceof GenericRefType){
|
||||
return "G"+((GenericRefType) type).getParsedName();
|
||||
}
|
||||
throw new RuntimeException("Unsupported Type: "+ type);
|
||||
}
|
||||
private String genASP(Set<Pair> cs){
|
||||
String ret = "";
|
||||
for(Pair p : cs) {
|
||||
if (p.OperatorEqual()) {
|
||||
ret +=(toASP(p.TA1) + "=." + toASP(p.TA2) + "\n");
|
||||
} else if (p.OperatorSmallerDot()) {
|
||||
ret +=(toASP(p.TA1) + "<." + toASP(p.TA2) + "\n");
|
||||
} else if (p.OperatorSmallerNEQDot()) {
|
||||
ret += (toASP(p.TA1) + "<." + toASP(p.TA2) + "\n");
|
||||
}else if(p.OperatorSmaller()){
|
||||
ret += toASP(p.TA1) +"<"+toASP(p.TA2)+ "\n";
|
||||
} else {
|
||||
throw new RuntimeException("Operator unsupported: " + p.GetOperator());
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
private void writeASP(ConstraintSet<Pair> cs){
|
||||
try(var f = new FileWriter("/tmp/output")){
|
||||
f.append(genASP(cs.getUndConstraints()));
|
||||
List<List<Set<Pair>>> orCons = cs.getOderConstraints().stream().map(css -> {
|
||||
return css.stream().map(cp -> {
|
||||
return cp.stream().collect(Collectors.toSet());
|
||||
}).collect(Collectors.toList());
|
||||
}).toList();
|
||||
|
||||
for(var orCon : orCons){
|
||||
f.append("{\n");
|
||||
var it = orCon.iterator();
|
||||
while(it.hasNext()) {
|
||||
var orC = it.next();
|
||||
f.append("{\n");
|
||||
f.append(genASP(orC));
|
||||
f.append("}\n");
|
||||
if(it.hasNext())f.append("|");
|
||||
}
|
||||
f.append("}\n");
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
private ConstraintSet getConstraintsClass(ClassOrInterface cl, TypeInferenceInformation info) {
|
||||
ConstraintSet ret = new ConstraintSet();
|
||||
ConstraintSet methConstrains;
|
||||
|
||||
@@ -591,7 +591,7 @@ public class TYPEStmt implements StatementVisitor {
|
||||
for (var ctor : clazz.getConstructors()) {
|
||||
var params = convertParams(ctor.getParameterList(), info);
|
||||
if (params.size() != superCall.arglist.getArguments().size()) continue;
|
||||
var assumption = new MethodAssumption(null, new Void(new NullToken()), params, createTypeScope(clazz, ctor), ctor.isInherited);
|
||||
var assumption = new MethodAssumption(null, new Void(new NullToken()), params, createTypeScope(clazz, ctor), ctor.isInherited, false);
|
||||
|
||||
GenericsResolver resolver = getResolverInstance();
|
||||
Set<Constraint<Pair>> oneMethodConstraints = generateConstraint(superCall, assumption, info, resolver);
|
||||
@@ -607,7 +607,7 @@ public class TYPEStmt implements StatementVisitor {
|
||||
for (var ctor : info.getCurrentClass().getConstructors()) {
|
||||
var params = convertParams(ctor.getParameterList(), info);
|
||||
if (params.size() != thisCall.arglist.getArguments().size()) continue;
|
||||
var assumption = new MethodAssumption(null, new Void(new NullToken()), params, createTypeScope(info.getCurrentClass(), ctor), ctor.isInherited);
|
||||
var assumption = new MethodAssumption(null, new Void(new NullToken()), params, createTypeScope(info.getCurrentClass(), ctor), ctor.isInherited, false);
|
||||
|
||||
GenericsResolver resolver = getResolverInstance();
|
||||
Set<Constraint<Pair>> oneMethodConstraints = generateConstraint(thisCall, assumption, info, resolver);
|
||||
@@ -640,8 +640,8 @@ public class TYPEStmt implements StatementVisitor {
|
||||
|
||||
protected Set<Constraint<Pair>> generateConstraint(MethodCall forMethod, MethodAssumption assumption, TypeInferenceBlockInformation info, GenericsResolver resolver) {
|
||||
Constraint<Pair> methodConstraint, extendsMethodConstraint;
|
||||
methodConstraint = new Constraint<>(assumption.isInherited());
|
||||
extendsMethodConstraint = new Constraint<>(assumption.isInherited());// PL 2023-01-24: Ersetzt die Dopplung in visit(MethodCall)
|
||||
methodConstraint = new Constraint<>(assumption.isInherited(), assumption.isOverridden());
|
||||
extendsMethodConstraint = new Constraint<>(assumption.isInherited(), assumption.isOverridden());// PL 2023-01-24: Ersetzt die Dopplung in visit(MethodCall)
|
||||
|
||||
ClassOrInterface receiverCl = assumption.getReceiver();
|
||||
/*
|
||||
@@ -746,14 +746,14 @@ public class TYPEStmt implements StatementVisitor {
|
||||
public RefTypeOrTPHOrWildcardOrGeneric getReturnType() {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}, false));
|
||||
}, false, false));
|
||||
}
|
||||
for (ClassOrInterface cl : info.getAvailableClasses()) {
|
||||
for (Method m : cl.getMethods()) {
|
||||
if (m.getName().equals(name) && m.getParameterList().getFormalparalist().size() == numArgs) {
|
||||
RefTypeOrTPHOrWildcardOrGeneric retType = m.getReturnType();// info.checkGTV(m.getReturnType());
|
||||
|
||||
ret.add(new MethodAssumption(cl, retType, convertParams(m.getParameterList(), info), createTypeScope(cl, m), m.isInherited));
|
||||
ret.add(new MethodAssumption(cl, retType, convertParams(m.getParameterList(), info), createTypeScope(cl, m), m.isInherited, m.isImplemented));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -785,7 +785,7 @@ public class TYPEStmt implements StatementVisitor {
|
||||
for (Method m : cl.getConstructors()) {
|
||||
if (m.getParameterList().getFormalparalist().size() == argList.getArguments().size()) {
|
||||
var params = convertParams(m.getParameterList(), info);
|
||||
ret.add(new MethodAssumption(cl, cl.generateTypeOfThisClass(), params, createTypeScope(cl, m), m.isInherited));
|
||||
ret.add(new MethodAssumption(cl, cl.generateTypeOfThisClass(), params, createTypeScope(cl, m), m.isInherited, m.isImplemented));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -702,9 +702,10 @@ public class RuleSet implements IRuleSet{
|
||||
x -> uni.apply(pair,x)).collect(Collectors.toCollection((b.getExtendConstraint() != null)
|
||||
? () -> new Constraint<UnifyPair>(
|
||||
b.isInherited(),
|
||||
b.isImplemented(),
|
||||
b.getExtendConstraint().stream().map(x -> uni.apply(pair,x)).collect(Collectors.toCollection(Constraint::new)),
|
||||
b.getmethodSignatureConstraint().stream().map(x -> uni.apply(pair,x)).collect(Collectors.toCollection(HashSet::new)))
|
||||
: () -> new Constraint<UnifyPair>(b.isInherited())
|
||||
: () -> new Constraint<UnifyPair>(b.isInherited(), b.isImplemented())
|
||||
));
|
||||
oderConstraints.replaceAll(oc -> oc.stream().map(applyUni).collect(Collectors.toCollection(HashSet::new)));
|
||||
/*
|
||||
|
||||
@@ -816,6 +816,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
writeLog("nextSetasList: " + nextSetasList.toString());
|
||||
if (variance == 1) {
|
||||
a = oup.max(nextSetasList.iterator());
|
||||
writeLog("Max: a in " + variance + " "+ a);
|
||||
nextSetasList.remove(a);
|
||||
if (oderConstraint) {
|
||||
nextSetasListOderConstraints.add(((Constraint<UnifyPair>)a).getExtendConstraint());
|
||||
@@ -1353,12 +1354,15 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
while(aParDefIt.hasNext()) {
|
||||
Set<UnifyPair> a_new = aParDefIt.next();
|
||||
List<Set<UnifyPair>> smallerSetasList = oup.smallerThan(a_new, nextSetasList);
|
||||
writeLog("smallerSetasList: " + smallerSetasList);
|
||||
List<Set<UnifyPair>> notInherited = smallerSetasList.stream()
|
||||
.filter(x -> !((Constraint<UnifyPair>)x).isInherited())
|
||||
.filter(x -> !((Constraint<UnifyPair>)x).isInherited() && !((Constraint<UnifyPair>)x).isImplemented())
|
||||
.collect(Collectors.toCollection(ArrayList::new));
|
||||
writeLog("notInherited: " + notInherited+"\n");
|
||||
List<Set<UnifyPair>> notErased = new ArrayList<>();
|
||||
notInherited.stream().forEach(x -> { notErased.addAll(oup.smallerEqThan(x, smallerSetasList)); });
|
||||
List<Set<UnifyPair>> erased = new ArrayList<>(smallerSetasList);
|
||||
writeLog("notErased: " + notErased+"\n");
|
||||
erased.removeAll(notErased);
|
||||
nextSetasList.removeAll(erased);
|
||||
|
||||
|
||||
@@ -699,7 +699,7 @@ implements IFiniteClosure {
|
||||
*/
|
||||
|
||||
public int compare (UnifyType left, UnifyType right, PairOperator pairop) {
|
||||
//try {logFile.write("left: "+ left + " right: " + right + " pairop: " + pairop);} catch (IOException ie) {}
|
||||
try {logFile.write("left: "+ left + " right: " + right + " pairop: " + pairop +"\n");} catch (IOException ie) {}
|
||||
if (left.getName().equals("Matrix") || right.getName().equals("Matrix"))
|
||||
System.out.println("");
|
||||
/*
|
||||
@@ -756,15 +756,15 @@ implements IFiniteClosure {
|
||||
HashSet<UnifyPair> hs = new HashSet<>();
|
||||
hs.add(up);
|
||||
Set<UnifyPair> smallerRes = unifyTask.applyTypeUnificationRules(hs, this);
|
||||
/*
|
||||
//if (left.getName().equals("Matrix") || right.getName().equals("Matrix"))
|
||||
|
||||
//if (left.getName().equals("Vector") || right.getName().equals("AbstractList"))
|
||||
{try {
|
||||
logFile.write("\nsmallerRes: " + smallerRes);//"smallerHash: " + greaterHash.toString());
|
||||
logFile.flush();
|
||||
}
|
||||
catch (IOException e) {
|
||||
System.err.println("no LogFile");}}
|
||||
*/
|
||||
|
||||
//Gleichungen der Form a <./=. Theta oder Theta <./=. a oder a <./=. b sind ok.
|
||||
Predicate<UnifyPair> delFun = x -> !((x.getLhsType() instanceof PlaceholderType ||
|
||||
x.getRhsType() instanceof PlaceholderType)
|
||||
@@ -772,6 +772,12 @@ implements IFiniteClosure {
|
||||
((WildcardType)x.getLhsType()).getWildcardedType().equals(x.getRhsType()))
|
||||
);
|
||||
long smallerLen = smallerRes.stream().filter(delFun).count();
|
||||
try {
|
||||
logFile.write("\nsmallerLen: " + smallerLen +"\n");
|
||||
logFile.flush();
|
||||
}
|
||||
catch (IOException e) {
|
||||
System.err.println("no LogFile");}
|
||||
if (smallerLen == 0) return -1;
|
||||
else {
|
||||
up = new UnifyPair(right, left, pairop);
|
||||
@@ -779,15 +785,15 @@ implements IFiniteClosure {
|
||||
hs = new HashSet<>();
|
||||
hs.add(up);
|
||||
Set<UnifyPair> greaterRes = unifyTask.applyTypeUnificationRules(hs, this);
|
||||
/*
|
||||
//if (left.getName().equals("Matrix") || right.getName().equals("Matrix"))
|
||||
|
||||
//if (left.getName().equals("Vector") || right.getName().equals("AbstractList"))
|
||||
{try {
|
||||
logFile.write("\ngreaterRes: " + greaterRes);//"smallerHash: " + greaterHash.toString());
|
||||
logFile.flush();
|
||||
}
|
||||
catch (IOException e) {
|
||||
System.err.println("no LogFile");}}
|
||||
*/
|
||||
|
||||
//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;
|
||||
|
||||
@@ -3,7 +3,9 @@ import de.dhbwstuttgart.environment.ByteArrayClassLoader;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.FileWriter;
|
||||
import java.lang.reflect.*;
|
||||
import java.util.AbstractList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Vector;
|
||||
@@ -236,6 +238,9 @@ public class TestComplete {
|
||||
@Test
|
||||
//@Ignore("This is too complex")
|
||||
public void matrixTest() throws Exception {
|
||||
try(var f = new FileWriter("/tmp/output")){
|
||||
f.append("hallo");
|
||||
}
|
||||
var classFiles = generateClassFiles(new ByteArrayClassLoader(), "Matrix.jav");
|
||||
var matrix = classFiles.get("Matrix");
|
||||
|
||||
@@ -263,7 +268,7 @@ public class TestComplete {
|
||||
|
||||
var instanceOfClass_m2 = matrix.getDeclaredConstructor(Vector.class).newInstance(vv1);
|
||||
|
||||
var mul = matrix.getDeclaredMethod("mul", Vector.class);
|
||||
var mul = matrix.getDeclaredMethod("mul", List.class);
|
||||
var result = mul.invoke(instanceOfClass_m1, instanceOfClass_m2);
|
||||
System.out.println(instanceOfClass_m1.toString() + " * " + instanceOfClass_m2.toString() + " = " + result.toString());
|
||||
|
||||
@@ -1084,6 +1089,13 @@ public class TestComplete {
|
||||
var res = clazz.getDeclaredMethod("convert", List.class).invoke(instance, list);
|
||||
assertEquals(res, List.of(6, 7, 8));
|
||||
}
|
||||
@Test
|
||||
public void testBug325() throws Exception {
|
||||
var classFiles = generateClassFiles(new ByteArrayClassLoader(), "Bug325.jav");
|
||||
var clazz = classFiles.get("Bug325");
|
||||
var instance = clazz.getDeclaredConstructor().newInstance();
|
||||
clazz.getDeclaredMethod("main").invoke(instance);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBug326() throws Exception {
|
||||
|
||||
@@ -34,7 +34,7 @@ public class JavaTXCompilerTest {
|
||||
|
||||
@Test
|
||||
public void importTest() throws IOException, ClassNotFoundException {
|
||||
execute(new File(rootDirectory + "Import.jav"));
|
||||
execute(new File(rootDirectory + "OrConsTest.jav"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
20
src/test/resources/javFiles/OrConsTest.jav
Normal file
20
src/test/resources/javFiles/OrConsTest.jav
Normal file
@@ -0,0 +1,20 @@
|
||||
|
||||
import java.lang.Integer;
|
||||
import java.lang.String;
|
||||
|
||||
|
||||
class C1{
|
||||
m(){return this;}
|
||||
}
|
||||
|
||||
class C2{
|
||||
m(){return this;}
|
||||
}
|
||||
|
||||
public class OrConsTest {
|
||||
|
||||
ol(var1) {
|
||||
return var1.m().m().m().m().m().m().m().m().m().m().m().m();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user