Fehler in Lambda-Generierung fixen

This commit is contained in:
JanUlrich 2016-09-16 14:26:18 +02:00
parent aa6a6beb93
commit a5c34896ba
2 changed files with 15 additions and 4 deletions

View File

@ -1,6 +1,7 @@
package de.dhbwstuttgart.syntaxtree.statement;
import java.util.ArrayList;
import java.util.List;
import org.apache.bcel.Const;
import org.apache.bcel.Constants;
@ -214,6 +215,16 @@ public class LambdaExpression extends Expr{
return ret;
}
/*
private List<LocalOrFieldVarOrClassname> crawlVariables(SyntaxTreeNode inStatements){
List<LocalOrFieldVarOrClassname> ret = new ArrayList<>();
for(SyntaxTreeNode child : inStatements.getChildren()){
ret.addAll(crawlVariables(child));
}
return ret;
}
*/
@Override
public InstructionList genByteCode(ClassGenerator cg, TypeinferenceResultSet rs) {
DHBWConstantPoolGen cp = cg.getConstantPool();
@ -296,7 +307,7 @@ public class LambdaExpression extends Expr{
String interfaceMethodName = "apply"; //Das ist ein Hack, funktioniert momentan, da nur FunN Interfaces für LambdaAusdrücke funktionieren
//String invokeDynamicType = org.apache.bcel.generic.Type.getMethodSignature(lambdaType.getBytecodeType(cg, rs), additionalParameters);
String invokeDynamicType = org.apache.bcel.generic.Type.getMethodSignature(new org.apache.bcel.generic.ObjectType("Fun0"), additionalParameters);
String invokeDynamicType = org.apache.bcel.generic.Type.getMethodSignature(new org.apache.bcel.generic.ObjectType(lambdaType.get_Name()), additionalParameters);
il.append(cg.getInstructionFactory().createInvokeDynamic(interfaceMethodName,invokeDynamicType, bMethod));
return il;

View File

@ -1,9 +1,9 @@
class LambdaExpr {
void method() {
method() {
lambda;
lambda = () -> 1;
lambda = (Integer a) -> a;
return lambda;
}
}