From 88ec8823fd41af604404159d8b88bab6d6202575 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Wed, 27 Feb 2019 16:04:55 +0100 Subject: [PATCH] =?UTF-8?q?=09modified:=20=20=20../../../main/java/de/dhbw?= =?UTF-8?q?stuttgart/parser/SyntaxTreeGenerator/TypeGenerator.java=20=09mo?= =?UTF-8?q?dified:=20=20=20../../../main/java/de/dhbwstuttgart/syntaxtree/?= =?UTF-8?q?factory/UnifyTypeFactory.java=20=09deleted:=20=20=20=20../../..?= =?UTF-8?q?/main/java/de/dhbwstuttgart/syntaxtree/type/FunN.java=20=09modi?= =?UTF-8?q?fied:=20=20=20../../../main/java/de/dhbwstuttgart/typeinference?= =?UTF-8?q?/assumptions/FunNClass.java=20=09modified:=20=20=20../../../mai?= =?UTF-8?q?n/java/de/dhbwstuttgart/typeinference/assumptions/MethodAssumpt?= =?UTF-8?q?ion.java=20=09modified:=20=20=20../../../main/java/de/dhbwstutt?= =?UTF-8?q?gart/typeinference/typeAlgo/TYPEStmt.java=20=09modified:=20=20?= =?UTF-8?q?=20../../../main/java/de/dhbwstuttgart/typeinference/unify/mode?= =?UTF-8?q?l/FunNType.java=20Es=20wird=20jetzt=20FunN-Type=20FunN$$=20gepa?= =?UTF-8?q?rst=20Der=20Typ=20FunN=20wurde=20entfernt=20Der=20Name=20des=20?= =?UTF-8?q?Typs=20FunNType=20wurde=20um=20$$=20am=20Ende=20erg=C3=A4nzt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SyntaxTreeGenerator/TypeGenerator.java | 11 ++++- .../syntaxtree/factory/UnifyTypeFactory.java | 15 +++---- .../dhbwstuttgart/syntaxtree/type/FunN.java | 41 ------------------- .../typeinference/assumptions/FunNClass.java | 2 +- .../assumptions/MethodAssumption.java | 4 +- .../typeinference/typeAlgo/TYPEStmt.java | 4 +- .../typeinference/unify/model/FunNType.java | 2 +- .../resources/bytecode/javFiles/MatrixOP.jav | 6 +-- .../resources/bytecode/javFiles/Sorting.jav | 6 +-- src/test/resources/javFiles/Faculty.jav | 9 ++-- src/test/resources/javFiles/mathStruc.jav | 17 +++----- 11 files changed, 39 insertions(+), 78 deletions(-) delete mode 100644 src/main/java/de/dhbwstuttgart/syntaxtree/type/FunN.java diff --git a/src/main/java/de/dhbwstuttgart/parser/SyntaxTreeGenerator/TypeGenerator.java b/src/main/java/de/dhbwstuttgart/parser/SyntaxTreeGenerator/TypeGenerator.java index ad07ca0fb..ce85bf6d4 100644 --- a/src/main/java/de/dhbwstuttgart/parser/SyntaxTreeGenerator/TypeGenerator.java +++ b/src/main/java/de/dhbwstuttgart/parser/SyntaxTreeGenerator/TypeGenerator.java @@ -18,6 +18,8 @@ import org.antlr.v4.runtime.Token; import java.util.ArrayList; import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; public class TypeGenerator { @@ -139,12 +141,17 @@ public class TypeGenerator { public static RefTypeOrTPHOrWildcardOrGeneric convertTypeName( String name, Java8Parser.TypeArgumentsContext typeArguments, Token offset, JavaClassRegistry reg, GenericsRegistry generics){ - if(!reg.contains(name)){ //Dann könnte es ein Generische Type sein + if(!reg.contains(name)){ //Dann könnte es ein generischer Type oder ein FunN$$-Type sein if(generics.contains(name)){ return new GenericRefType(name, offset); }else{ + Pattern p = Pattern.compile("Fun(\\d+)[$][$]"); + Matcher m = p.matcher(name); + if (m.matches()) {//es ist FunN$$-Type + return new RefType(new JavaClassName(name), convert(typeArguments, reg, generics), offset); + } else { throw new TypeinferenceException("Der Typ "+ name + " ist nicht vorhanden",offset); - } + }} } if(typeArguments == null){ List params = new ArrayList<>(); diff --git a/src/main/java/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java b/src/main/java/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java index a764db6ee..7166d0c4c 100644 --- a/src/main/java/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java +++ b/src/main/java/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java @@ -68,9 +68,6 @@ public class UnifyTypeFactory { public static UnifyType convert(RefTypeOrTPHOrWildcardOrGeneric t, Boolean innerType){ if(t instanceof GenericRefType){ return UnifyTypeFactory.convert((GenericRefType)t, innerType); - }else - if(t instanceof FunN){ - return UnifyTypeFactory.convert((FunN)t, innerType); }else if(t instanceof TypePlaceholder){ return UnifyTypeFactory.convert((TypePlaceholder)t, innerType); }else if(t instanceof ExtendsWildcardType){ @@ -86,13 +83,13 @@ public class UnifyTypeFactory { public static UnifyType convert(RefType t, Boolean innerType){ //Check if it is a FunN Type: - Pattern p = Pattern.compile("Fun(\\d+)"); + Pattern p = Pattern.compile("Fun(\\d+)[$][$]"); Matcher m = p.matcher(t.getName().toString()); boolean b = m.matches(); if(b){ Integer N = Integer.valueOf(m.group(1)); if((N + 1) == t.getParaList().size()){ - return convert(new FunN(t.getParaList()), false); + return convertFunN(t.getParaList(), false); } } UnifyType ret; @@ -108,11 +105,11 @@ public class UnifyTypeFactory { return ret; } - public static UnifyType convert(FunN t, Boolean innerType){ + public static UnifyType convertFunN(List paraList, Boolean innerType){ UnifyType ret; List params = new ArrayList<>(); - if(t.getParaList() != null && t.getParaList().size() > 0){ - for(RefTypeOrTPHOrWildcardOrGeneric pT : t.getParaList()){ + if(paraList != null && paraList.size() > 0){ + for(RefTypeOrTPHOrWildcardOrGeneric pT : paraList){ params.add(UnifyTypeFactory.convert(pT, false)); } } @@ -236,7 +233,7 @@ public class UnifyTypeFactory { } public static RefTypeOrTPHOrWildcardOrGeneric convert(FunNType t, Map tphs) { - RefType ret = new RefType(new JavaClassName(t.getName()+"$$"), convert(t.getTypeParams(), tphs), new NullToken()); + RefType ret = new RefType(new JavaClassName(t.getName()), convert(t.getTypeParams(), tphs), new NullToken()); return ret; } diff --git a/src/main/java/de/dhbwstuttgart/syntaxtree/type/FunN.java b/src/main/java/de/dhbwstuttgart/syntaxtree/type/FunN.java deleted file mode 100644 index dc521b87d..000000000 --- a/src/main/java/de/dhbwstuttgart/syntaxtree/type/FunN.java +++ /dev/null @@ -1,41 +0,0 @@ -package de.dhbwstuttgart.syntaxtree.type; - - -import de.dhbwstuttgart.parser.NullToken; -import de.dhbwstuttgart.parser.scope.JavaClassName; - -import java.util.List; - -/** - * @see Spezifikation "Complete Typeinference in Java 8" von Martin Plümicke - * "interface FunN { R apply(T1 arg1, T2 arg2, ... , TN argN); }" - * @author A10023 - Andreas Stadelmeier - * - * Bemerkung: - * FunN ist ein RefType. Der RefType ist nicht mit einem FunNInterface verbunden. - * - */ -public class FunN extends RefType { - /** - * @author Andreas Stadelmeier, a10023 - * Benötigt für den Typinferenzalgorithmus für Java 8 - * Generiert einen RefType auf eine FunN - Klasse. - * @param params - * @return - */ - public FunN(List params) { - super(new JavaClassName("Fun"+(params.size()-1)), params, new NullToken()); - } - - /** - * Spezieller Konstruktor um eine FunN ohne Returntype zu generieren - - protected FunN(List list){ - super("",0); - if(list==null)throw new NullPointerException(); - setT(list); - this.name = new JavaClassName("Fun"+list.size());//getName(); - } - */ - -} diff --git a/src/main/java/de/dhbwstuttgart/typeinference/assumptions/FunNClass.java b/src/main/java/de/dhbwstuttgart/typeinference/assumptions/FunNClass.java index 6067851ee..d41baa06e 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/assumptions/FunNClass.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/assumptions/FunNClass.java @@ -21,7 +21,7 @@ import java.util.Optional; public class FunNClass extends ClassOrInterface { public FunNClass(List funNParams) { - super(0, new JavaClassName("Fun"+(funNParams.size())), new ArrayList<>(), Optional.empty() /* eingefuegt PL 2018-11-24 */, + super(0, new JavaClassName("Fun"+(funNParams.size()-1)), new ArrayList<>(), Optional.empty() /* eingefuegt PL 2018-11-24 */, createMethods(funNParams), new ArrayList<>(), createGenerics(funNParams), ASTFactory.createObjectType(), true, new ArrayList<>(), new NullToken()); diff --git a/src/main/java/de/dhbwstuttgart/typeinference/assumptions/MethodAssumption.java b/src/main/java/de/dhbwstuttgart/typeinference/assumptions/MethodAssumption.java index 3862d0eb3..c1a6d4498 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/assumptions/MethodAssumption.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/assumptions/MethodAssumption.java @@ -1,10 +1,10 @@ package de.dhbwstuttgart.typeinference.assumptions; import de.dhbwstuttgart.parser.NullToken; +import de.dhbwstuttgart.parser.scope.JavaClassName; import de.dhbwstuttgart.syntaxtree.ClassOrInterface; import de.dhbwstuttgart.syntaxtree.GenericTypeVar; import de.dhbwstuttgart.syntaxtree.TypeScope; -import de.dhbwstuttgart.syntaxtree.type.FunN; import de.dhbwstuttgart.syntaxtree.type.GenericRefType; import de.dhbwstuttgart.syntaxtree.type.RefType; import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric; @@ -63,7 +63,7 @@ public class MethodAssumption extends Assumption{ } RefTypeOrTPHOrWildcardOrGeneric receiverType; if(receiver instanceof FunNClass){ - receiverType = new FunN(params); + receiverType = new RefType(new JavaClassName(receiver.getClassName().toString()+"$$"), params, new NullToken()); // new FunN(params); }else{ receiverType = new RefType(receiver.getClassName(), params, new NullToken()); } diff --git a/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java b/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java index 4fd14fbc8..f1332cd46 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java @@ -65,7 +65,9 @@ public class TYPEStmt implements StatementVisitor{ //lambdaParams.add(0,tphRetType); constraintsSet.addUndConstraint( new Pair(lambdaExpression.getType(), - new FunN(lambdaParams),PairOperator.EQUALSDOT)); + new RefType(new JavaClassName("Fun"+(lambdaParams.size()-1)+"$$"), lambdaParams, new NullToken()), + //new FunN(lambdaParams), + PairOperator.EQUALSDOT)); constraintsSet.addUndConstraint( new Pair(lambdaExpression.getReturnType(), tphRetType,PairOperator.EQUALSDOT)); diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/model/FunNType.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/model/FunNType.java index 3e9f2ae66..37cf6a0a4 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/model/FunNType.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/model/FunNType.java @@ -22,7 +22,7 @@ public class FunNType extends UnifyType { * Creates a FunN-Type with the specified TypeParameters. */ protected FunNType(TypeParams p) { - super("Fun"+(p.size()-1), p); + super("Fun"+(p.size()-1)+"$$", p); } /** diff --git a/src/test/resources/bytecode/javFiles/MatrixOP.jav b/src/test/resources/bytecode/javFiles/MatrixOP.jav index 828a270bd..c439c3cad 100644 --- a/src/test/resources/bytecode/javFiles/MatrixOP.jav +++ b/src/test/resources/bytecode/javFiles/MatrixOP.jav @@ -3,7 +3,7 @@ import java.lang.Integer; //import java.lang.Byte; import java.lang.Boolean; -public class MatrixOP extends Vector> { +public class MatrixOP extends Vector> { MatrixOP () { } @@ -18,10 +18,10 @@ public class MatrixOP extends Vector> { } } - mul = (m1, m2) -> { + Fun2$$>, java.util.Vector>, MatrixOP> mul = (m1, m2) -> { var ret = new MatrixOP(); var i = 0; - while(i < size()) { + while(i < m1.size()) { var v1 = m1.elementAt(i); var v2 = new Vector(); var j = 0; diff --git a/src/test/resources/bytecode/javFiles/Sorting.jav b/src/test/resources/bytecode/javFiles/Sorting.jav index 341a1a6b2..486bfd71c 100644 --- a/src/test/resources/bytecode/javFiles/Sorting.jav +++ b/src/test/resources/bytecode/javFiles/Sorting.jav @@ -14,10 +14,10 @@ sort(in){ return merge(sort(firstHalf), sort(secondHalf)); } */ -/* + - void sort(ArrayList a){ + void sort(a){ a = merge(a,a); } -*/ + } diff --git a/src/test/resources/javFiles/Faculty.jav b/src/test/resources/javFiles/Faculty.jav index 71f405154..ed201ff9a 100644 --- a/src/test/resources/javFiles/Faculty.jav +++ b/src/test/resources/javFiles/Faculty.jav @@ -1,13 +1,14 @@ import java.lang.Integer; class Faculty { - - Integer mul(Integer x, Integer y) { + //fact; + + Integer mul(Integer x, Integer y) { return x; } - + m () { - var fact = (Integer x) -> { + var fact = (Integer x) -> { return mul(x, fact.apply(x)); }; return fact; diff --git a/src/test/resources/javFiles/mathStruc.jav b/src/test/resources/javFiles/mathStruc.jav index 93f901ce5..c8518e5d3 100644 --- a/src/test/resources/javFiles/mathStruc.jav +++ b/src/test/resources/javFiles/mathStruc.jav @@ -1,13 +1,8 @@ +class MathStruc { -class mathStruc { + A model; + + innerOp = o -> ms -> new MathStruc(o.apply(this.model, ms.model)); -mathStruc(A a) { } - -A model(){ A a; return a; } - -methode(){ -var innerOp = o -> ms -> - new mathStruc(o.apply(this.model(),ms.model())); - return innerOp; - } -} \ No newline at end of file + MathStruc(A m) { model=m; } + } \ No newline at end of file