GenCode: Versuch LambdaExpression umzusetzen, scheitert aber bislang an

nicht importierbaren Klassen aus BCEL
This commit is contained in:
Fütterling, Franziska (WWI2012D) 2015-07-08 15:00:47 +02:00
parent 59b574f040
commit 3111d51005
4 changed files with 71 additions and 5 deletions

View File

@ -2,7 +2,11 @@ package de.dhbwstuttgart.syntaxtree.statement;
import java.util.Hashtable;
import org.apache.bcel.generic.BIPUSH;
import org.apache.bcel.generic.ClassGen;
import org.apache.bcel.generic.InstructionFactory;
import org.apache.bcel.generic.InstructionList;
import org.apache.bcel.generic.INVOKEDYNAMIC;
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.myexception.CTypeReconstructionException;
@ -208,9 +212,18 @@ public class LambdaExpression extends Expr{
}
@Override
public void genByteCode(ClassGen _cg) {
// TODO Auto-generated method stub
public InstructionList genByteCode(ClassGen cg) {
//InstructionFactory _factory = new InstructionFactory(cg, cg.getConstantPool());
InstructionList il = new InstructionList();
short opcode = 186;//opcode - was genau ist das?
/*
* Bytecode:
* 0: invokedynamic #2, 0 //#2 führt zu einem InvokeDynamic im KP - wildes Referenzieren
* 5: astore_1 //Speichert wahrscheinlich den String meiner TestEXPR
* 6: return
*/
il.append(new INVOKEDYNAMIC(opcode, 0));//Invokedynamic lässt sich bei mir weder automatisch noch manuell importieren
return il;
}
}

View File

@ -0,0 +1,7 @@
class LambdaExpr {
void method() {
Runnable r1 = () -> System.out.println("Hello world two!");
}
}

View File

@ -0,0 +1,45 @@
package bytecode;
import static org.junit.Assert.*;
import java.io.File;
import java.io.IOException;
import junit.framework.TestCase;
import org.junit.Test;
import plugindevelopment.TypeInsertTester;
import de.dhbwstuttgart.core.MyCompiler;
import de.dhbwstuttgart.core.MyCompilerAPI;
import de.dhbwstuttgart.logger.LoggerConfiguration;
import de.dhbwstuttgart.logger.Section;
import de.dhbwstuttgart.parser.JavaParser.yyException;
import de.dhbwstuttgart.typeinference.ByteCodeResult;
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertSet;
public class LambdaExpr {
public final static String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/";
public final static String testFile = "LambdaExpr.jav";
public final static String outputFile = "LambdaExpr.class";
@Test
public void test() {
LoggerConfiguration logConfig = new LoggerConfiguration().setOutput(Section.PARSER, System.out);
MyCompilerAPI compiler = MyCompiler.getAPI(logConfig);
try {
compiler.parse(new File(rootDirectory + testFile));
compiler.typeReconstruction();
ByteCodeResult bytecode = compiler.generateBytecode();
System.out.println(bytecode);
bytecode.getByteCode().getJavaClass().dump(new File(rootDirectory + outputFile));
} catch (IOException | yyException e) {
e.printStackTrace();
TestCase.fail();
}
}
}

View File

@ -1,8 +1,9 @@
class NewArray{
void method() {
zahl;
zahl = new Integer[2];
a;
a = new Integer[2];
a = {1,2};
}