From 2eb7a63480d1f5406ac7f2973084ec7bd8aa8f86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Sat, 23 Jun 2018 01:05:13 +0200 Subject: [PATCH] modified: src/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java FunN$$ eingefuegt modified: src/de/dhbwstuttgart/syntaxtree/type/FunN.java modified: src/de/dhbwstuttgart/typeinference/assumptions/FunNClass.java modified: src/de/dhbwstuttgart/typeinference/assumptions/MethodAssumption.java modified: src/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java Methodcall einige Bugs sowohl beim apply als uch bei allen anderen gefixt. modified: test/javFiles/Lambda.jav --- .../syntaxtree/factory/UnifyTypeFactory.java | 2 +- src/de/dhbwstuttgart/syntaxtree/type/FunN.java | 2 +- .../typeinference/assumptions/FunNClass.java | 16 ++++++++++------ .../assumptions/MethodAssumption.java | 8 +++++--- .../typeinference/typeAlgo/TYPEStmt.java | 12 ++++++++---- test/javFiles/Lambda.jav | 4 ++++ 6 files changed, 29 insertions(+), 15 deletions(-) diff --git a/src/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java b/src/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java index b05dd0ee..71985334 100644 --- a/src/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java +++ b/src/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java @@ -208,7 +208,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/de/dhbwstuttgart/syntaxtree/type/FunN.java b/src/de/dhbwstuttgart/syntaxtree/type/FunN.java index 84fe1ace..46de6566 100644 --- a/src/de/dhbwstuttgart/syntaxtree/type/FunN.java +++ b/src/de/dhbwstuttgart/syntaxtree/type/FunN.java @@ -24,7 +24,7 @@ public class FunN extends RefType { * @return */ public FunN(List params) { - super(new JavaClassName("Fun"+params.size()), params, new NullToken()); + super(new JavaClassName("Fun"+(params.size())), params, new NullToken()); } /** diff --git a/src/de/dhbwstuttgart/typeinference/assumptions/FunNClass.java b/src/de/dhbwstuttgart/typeinference/assumptions/FunNClass.java index 3518c16a..0c8220f1 100644 --- a/src/de/dhbwstuttgart/typeinference/assumptions/FunNClass.java +++ b/src/de/dhbwstuttgart/typeinference/assumptions/FunNClass.java @@ -8,32 +8,36 @@ import de.dhbwstuttgart.syntaxtree.GenericTypeVar; import de.dhbwstuttgart.syntaxtree.Method; import de.dhbwstuttgart.syntaxtree.factory.ASTFactory; import de.dhbwstuttgart.syntaxtree.factory.NameGenerator; +import de.dhbwstuttgart.syntaxtree.type.GenericRefType; import de.dhbwstuttgart.syntaxtree.type.RefType; import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric; +import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder; + import org.antlr.v4.runtime.Token; import java.util.ArrayList; import java.util.List; public class FunNClass extends ClassOrInterface { - public FunNClass(List funNParams) { - super(0, new JavaClassName("Fun"+(funNParams.size()-1)), new ArrayList<>(), + public FunNClass(List funNParams) { + super(0, new JavaClassName("Fun"+(funNParams.size())), new ArrayList<>(), createMethods(funNParams), new ArrayList<>(), createGenerics(funNParams), ASTFactory.createObjectType(), true, new ArrayList<>(), new NullToken()); } - private static GenericDeclarationList createGenerics(List funNParams) { + private static GenericDeclarationList createGenerics(List funNParams) { + //PL 2018-06-22: so geaendert, dass generierte Generics den Namen der funParams entsprechen. List generics = new ArrayList<>(); - for(RefTypeOrTPHOrWildcardOrGeneric param : funNParams){ - generics.add(new GenericTypeVar(NameGenerator.makeNewName(), + for(GenericRefType param : funNParams){ + generics.add(new GenericTypeVar(param.getParsedName(),//NameGenerator.makeNewName(), new ArrayList<>(), new NullToken(), new NullToken())); } return new GenericDeclarationList(generics, new NullToken()); } - private static List createMethods(List funNParams) { + private static List createMethods(List funNParams) { return null; } } diff --git a/src/de/dhbwstuttgart/typeinference/assumptions/MethodAssumption.java b/src/de/dhbwstuttgart/typeinference/assumptions/MethodAssumption.java index e17281e5..294c8507 100644 --- a/src/de/dhbwstuttgart/typeinference/assumptions/MethodAssumption.java +++ b/src/de/dhbwstuttgart/typeinference/assumptions/MethodAssumption.java @@ -16,10 +16,10 @@ import java.util.List; public class MethodAssumption extends Assumption{ private ClassOrInterface receiver; private RefTypeOrTPHOrWildcardOrGeneric retType; - List params; + List params; public MethodAssumption(ClassOrInterface receiver, RefTypeOrTPHOrWildcardOrGeneric retType, - List params, TypeScope scope){ + List params, TypeScope scope){ super(scope); this.receiver = receiver; this.retType = retType; @@ -38,7 +38,9 @@ public class MethodAssumption extends Assumption{ } public RefTypeOrTPHOrWildcardOrGeneric getReturnType(GenericsResolver resolver) { - if(retType instanceof GenericRefType)return resolver.resolve(retType); + if(retType instanceof GenericRefType) { + return resolver.resolve(retType); + } return retType; } diff --git a/src/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java b/src/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java index fcd8ecfa..44fc5e88 100644 --- a/src/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java +++ b/src/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java @@ -6,6 +6,7 @@ import de.dhbwstuttgart.parser.NullToken; import de.dhbwstuttgart.parser.SyntaxTreeGenerator.AssignToLocal; import de.dhbwstuttgart.syntaxtree.*; import de.dhbwstuttgart.syntaxtree.factory.ASTFactory; +import de.dhbwstuttgart.syntaxtree.factory.NameGenerator; import de.dhbwstuttgart.syntaxtree.statement.*; import de.dhbwstuttgart.syntaxtree.type.*; import de.dhbwstuttgart.typeinference.assumptions.FieldAssumption; @@ -451,11 +452,14 @@ public class TYPEStmt implements StatementVisitor{ List ret = new ArrayList<>(); //TODO: apply Methoden wieder anfügen. Diese könnten möglicherweise auch in den Assumptions auftauchen (überdenken) if(name.equals("apply")){ - List funNParams = new ArrayList<>(); + List funNParams = new ArrayList<>(); for(int i = 0; i< numArgs + 1 ; i++){ - funNParams.add(TypePlaceholder.fresh(new NullToken())); + //funNParams.add(TypePlaceholder.fresh(new NullToken())); + funNParams.add(new GenericRefType(NameGenerator.makeNewName(), + new NullToken())); } - ret.add(new MethodAssumption(new FunNClass(funNParams), funNParams.get(0), funNParams.subList(1, funNParams.size()), + funNParams.get(funNParams.size()-1); + ret.add(new MethodAssumption(new FunNClass(funNParams), funNParams.get(funNParams.size()-1), funNParams.subList(0, funNParams.size()-1), new TypeScope() { @Override public Iterable getGenerics() { @@ -498,7 +502,7 @@ public class TYPEStmt implements StatementVisitor{ */ List params = new ArrayList<>(); for(FormalParameter fp : parameterList.getFormalparalist()){ - params.add(info.checkGTV(fp.getType())); + params.add(fp.getType()); //info.checkGTV(fp.getType())); //PL 2018-06-22 GTV sollen in Argumenten erhalten bleiben } return params; } diff --git a/test/javFiles/Lambda.jav b/test/javFiles/Lambda.jav index 02e8b51b..7a3aee0b 100644 --- a/test/javFiles/Lambda.jav +++ b/test/javFiles/Lambda.jav @@ -1,9 +1,13 @@ import java.lang.Integer; import java.lang.Number; +import java.util.Vector; public class Lambda { m () { + var v; + v.addElement(3); + v.elementAt(1); var lam1 = (x) -> { return x; };