diff --git a/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/StatementGenerator.java b/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/StatementGenerator.java index e671fde9..f69ec781 100644 --- a/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/StatementGenerator.java +++ b/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/StatementGenerator.java @@ -22,12 +22,13 @@ import java.util.*; public class StatementGenerator { private JavaClassRegistry reg; - private Map localVars = new HashMap<>(); + private Map localVars; private GenericsRegistry generics; - public StatementGenerator(JavaClassRegistry reg, GenericsRegistry generics){ + public StatementGenerator(JavaClassRegistry reg, GenericsRegistry generics, Map localVars){ this.reg = reg; this.generics = generics; + this.localVars = localVars; } public ParameterList convert(Java8Parser.FormalParameterListContext formalParameterListContext) { @@ -798,14 +799,21 @@ public class StatementGenerator { params = new ParameterList(new ArrayList<>(), expression.getStart()); } + HashMap lambdaLocals = new HashMap<>(); + lambdaLocals.putAll(localVars); + for(FormalParameter param : params.getFormalparalist()){ + lambdaLocals.put(param.getName(), param.getType()); + } + StatementGenerator lambdaGenerator = new StatementGenerator(reg, generics, lambdaLocals); + Block block; if(expression.lambdaBody().expression() != null){ List statements = new ArrayList<>(); - statements.add(new Return(convert(expression.lambdaBody().expression()), + statements.add(new Return(lambdaGenerator.convert(expression.lambdaBody().expression()), expression.lambdaBody().expression().getStart())); block = new Block(statements, expression.lambdaBody().getStart()); }else{ - block = convert(expression.lambdaBody().block()); + block = lambdaGenerator.convert(expression.lambdaBody().block()); } List funNParams = new ArrayList<>(); funNParams.add(TypePlaceholder.fresh(expression.getStart()));//ret-Type diff --git a/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/SyntaxTreeGenerator.java b/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/SyntaxTreeGenerator.java index f2fd5a86..758a1114 100644 --- a/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/SyntaxTreeGenerator.java +++ b/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/SyntaxTreeGenerator.java @@ -209,7 +209,7 @@ public class SyntaxTreeGenerator{ private Method convert(int modifiers, Java8Parser.MethodHeaderContext header, Java8Parser.MethodBodyContext body, JavaClassName parentClass, GenericsRegistry localGenerics) { - StatementGenerator stmtGen = new StatementGenerator(reg, localGenerics); + StatementGenerator stmtGen = new StatementGenerator(reg, localGenerics, new HashMap<>()); String name = header.methodDeclarator().Identifier().getText(); GenericDeclarationList gtvDeclarations = new GenericDeclarationList(new ArrayList<>(), header.getStart()); diff --git a/src/de/dhbwstuttgart/syntaxtree/FormalParameter.java b/src/de/dhbwstuttgart/syntaxtree/FormalParameter.java index 91b4d236..7fb16d83 100755 --- a/src/de/dhbwstuttgart/syntaxtree/FormalParameter.java +++ b/src/de/dhbwstuttgart/syntaxtree/FormalParameter.java @@ -17,4 +17,8 @@ public class FormalParameter extends SyntaxTreeNode public RefTypeOrTPHOrWildcardOrGeneric getType() { return type; } + + public String getName() { + return name; + } } diff --git a/src/de/dhbwstuttgart/typeinference/typeAlgo/TYPE.java b/src/de/dhbwstuttgart/typeinference/typeAlgo/TYPE.java index 3fe36ecb..88eb7f78 100644 --- a/src/de/dhbwstuttgart/typeinference/typeAlgo/TYPE.java +++ b/src/de/dhbwstuttgart/typeinference/typeAlgo/TYPE.java @@ -243,6 +243,13 @@ public class TYPE implements StatementVisitor{ public static List getMethods(String name, int numArgs, TypeInferenceBlockInformation info) { List ret = new ArrayList<>(); + if(name.equals("apply")){ + List funNParams = new ArrayList<>(); + for(int i = 0; i< numArgs + 1 ; i++){ + funNParams.add(TypePlaceholder.fresh(new NullToken())); + } + ret.add(new MethodAssumption(new FunN(funNParams), funNParams.get(0), funNParams.subList(1, funNParams.size()))); + } for(ClassOrInterface cl : info.getAvailableClasses()){ for(Method m : cl.getMethods()){ if(m.getName().equals(name) && diff --git a/test/typeinference/JavaTXCompilerTest.java b/test/typeinference/JavaTXCompilerTest.java index 975e5928..f62dd5b5 100644 --- a/test/typeinference/JavaTXCompilerTest.java +++ b/test/typeinference/JavaTXCompilerTest.java @@ -26,7 +26,8 @@ public class JavaTXCompilerTest { @Test public void test() throws IOException, ClassNotFoundException { - filesToTest.add(new File(rootDirectory+"Lambda.jav")); + filesToTest.add(new File(rootDirectory+"mathStruc.jav")); + //filesToTest.add(new File(rootDirectory+"Lambda.jav")); //filesToTest.add(new File(rootDirectory+"Lambda2.jav")); //filesToTest.add(new File(rootDirectory+"Lambda3.jav")); //filesToTest.add(new File(rootDirectory+"Vector.jav"));