forked from JavaTX/JavaCompilerCore
Beginn der Implementierung von Bytecode für Lambda Expression
This commit is contained in:
parent
8d1b2c6b82
commit
2d8adb5c69
@ -1,12 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry excluding=".classpath|.cvsignore|.externalToolBuilders/|.project|.settings/|Papers/|bin/|doc/|examples/|lib/|notizen/|src/|test/|tools/" including="log4j.xml" kind="src" path=""/>
|
||||
<classpathentry kind="src" path="BCEL"/>
|
||||
<classpathentry excluding=".classpath|.cvsignore|.externalToolBuilders/|.project|.settings/|Papers/|bin/|doc/|examples/|lib/|notizen/|src/|test/|tools/|BCEL/" including="log4j.xml" kind="src" path=""/>
|
||||
<classpathentry kind="src" path="test"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
|
||||
<classpathentry kind="lib" path="lib/junit-4.0.jar" sourcepath="/home/janulrich/.m2/repository/junit/junit/4.0/junit-4.0-sources.jar"/>
|
||||
<classpathentry kind="lib" path="lib/cloning.jar"/>
|
||||
<classpathentry kind="lib" path="lib/guava-10.0.1.jar"/>
|
||||
<classpathentry kind="lib" path="lib/bcel-6.0-SNAPSHOT.jar"/>
|
||||
<classpathentry kind="lib" path="lib/bcel-6.0-SNAPSHOT.jar" sourcepath="/home/janulrich/Downloads/bcel-5.2-src.zip"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
|
@ -1227,10 +1227,10 @@ public class Class extends GTVDeclarationContext implements AClassOrInterface, I
|
||||
//Alle Methoden auf Konstruktoren durchsuchen und diese umwandeln:
|
||||
Menge<Field> tempFields = new Menge<Field>();
|
||||
for(Field f : this.getFields()){
|
||||
if(f instanceof Method && !(f instanceof Constructor)){
|
||||
if(f instanceof Method && !(f instanceof Constructor)){ //Der Check, ob f ein Konstruktor ist eigentlich obsolet, da der Parser keinen Konstruktor generiert
|
||||
Method method = (Method)f;
|
||||
if(method.get_Method_Name().equals(this.getName().toString()) ){
|
||||
tempFields.add(new Constructor(method));
|
||||
tempFields.add(new Constructor(method, this));
|
||||
}else{
|
||||
tempFields.add(f);
|
||||
}
|
||||
|
@ -38,11 +38,12 @@ public class Constructor extends Method {
|
||||
* Parser kann nicht zwischen einem Konstruktor und einer Methode unterscheiden.
|
||||
* Diese Klasse beherbegt den als Methode geparsten Konstruktor und wandelt sein verhalten zu dem eines Konstruktors ab.
|
||||
*/
|
||||
public Constructor(Method methode){
|
||||
public Constructor(Method methode, Class parent){
|
||||
super(methode.get_Method_Name(), methode.getType(), methode.getParameterList(),methode.get_Block(), methode.getGenericDeclarationList(), methode.getOffset());
|
||||
//Sicherstellen, dass das erste Statement in der Methode ein SuperCall ist:
|
||||
if(this.get_Block().get_Statement().size() <1 || ! (this.get_Block().get_Statement().firstElement() instanceof SuperCall)){
|
||||
this.get_Block().statements.add(0, new SuperCall(this.get_Block()));
|
||||
this.parserPostProcessing(parent);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
@ -121,6 +122,8 @@ public class Constructor extends Method {
|
||||
return this.getType().getName();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -1779,7 +1779,7 @@ public class SourceFile
|
||||
@Override
|
||||
public void parserPostProcessing(SyntaxTreeNode parent) {
|
||||
if(parent!=null)throw new DebugException("Eine SourceFile hat kein Elternelement im Syntaxbaum");
|
||||
super.parserPostProcessing(parent);
|
||||
super.parserPostProcessing(this);
|
||||
//for(SyntaxTreeNode node : this.getChildren())node.parserPostProcessing(this);
|
||||
}
|
||||
|
||||
|
@ -30,12 +30,14 @@ public abstract class SyntaxTreeNode implements IItemWithOffset{
|
||||
*
|
||||
*/
|
||||
public void parserPostProcessing(SyntaxTreeNode parent) {
|
||||
if(parent == null)throw new NullPointerException();
|
||||
this.parent = parent;
|
||||
for(SyntaxTreeNode node : this.getChildren())
|
||||
if(node!=null)node.parserPostProcessing(this);
|
||||
}
|
||||
|
||||
public SyntaxTreeNode getParent() {
|
||||
//if(this.parent == null)throw new NullPointerException();
|
||||
return this.parent;
|
||||
}
|
||||
|
||||
@ -123,10 +125,10 @@ public abstract class SyntaxTreeNode implements IItemWithOffset{
|
||||
}
|
||||
|
||||
public GTVDeclarationContext getGTVDeclarationContext(){
|
||||
if(this.getParent()==null)return null;
|
||||
if(this.getParent()==null)
|
||||
throw new NullPointerException();//throw new DebugException("getGTVDeclarationContext auf unzulässiger Klasse aufgerufen");
|
||||
return this.getParent().getGTVDeclarationContext();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package de.dhbwstuttgart.syntaxtree.misc;
|
||||
|
||||
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.ArgumentList;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.MethodCall;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Receiver;
|
||||
@ -16,10 +17,10 @@ import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException;
|
||||
public class ConstructorCall extends MethodCall
|
||||
{
|
||||
public ConstructorCall(Receiver receiver, String methodName, ArgumentList argumentList, int offset){
|
||||
super(offset, 0);
|
||||
this.set_Receiver(receiver);
|
||||
this.set_Name(methodName);
|
||||
this.set_ArgumentList(argumentList);
|
||||
super(receiver, methodName, argumentList,offset);
|
||||
//this.set_Receiver(receiver);
|
||||
//this.set_Name(methodName);
|
||||
//this.set_ArgumentList(argumentList);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -38,4 +39,10 @@ public class ConstructorCall extends MethodCall
|
||||
ret.add(constraintsFromMethodAssumption(cAss, assumptions));
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void parserPostProcessing(SyntaxTreeNode parent) {
|
||||
super.parserPostProcessing(parent);
|
||||
}
|
||||
|
||||
}
|
@ -2,6 +2,7 @@ package de.dhbwstuttgart.syntaxtree.statement;
|
||||
|
||||
import java.util.Hashtable;
|
||||
|
||||
import org.apache.bcel.classfile.BootstrapMethod;
|
||||
import org.apache.bcel.classfile.ConstantPool;
|
||||
import org.apache.bcel.generic.BIPUSH;
|
||||
import org.apache.bcel.generic.ClassGen;
|
||||
@ -217,20 +218,25 @@ public class LambdaExpression extends Expr{
|
||||
public InstructionList genByteCode(ClassGen cg) {
|
||||
ConstantPoolGen cp = cg.getConstantPool();
|
||||
InstructionList il = new InstructionList();
|
||||
|
||||
/*
|
||||
* 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
|
||||
* Invokedynamic 186 (0xBA)
|
||||
* - Auf dem Operanten Stack liegen die Argumente
|
||||
*
|
||||
* InvokeDynamik_Info Structure auf den der Indexzeiger zeigen muss: https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.4.10
|
||||
*
|
||||
* Ablauf:
|
||||
* 1. Methode erstellen, mit dem Inhalt der Lambda-Expression //Dabei wird das This-Stat
|
||||
* 2. Invokedynamic-Call erzeugen
|
||||
*
|
||||
*/
|
||||
new BootstrapMethod();
|
||||
|
||||
//---Variante 1 mit opcode----
|
||||
short opcode = 186;//opcode - was genau ist das?
|
||||
il.append(new INVOKEDYNAMIC(opcode, 0));//Invokedynamic lässt sich bei mir weder automatisch noch manuell importieren
|
||||
short opcode = 186;
|
||||
int index = 0; //indexbyte 1 und 2 müssen ein Zeiger auf ein call site specifier im Konstantenpool sein (InvokeDynamic_Info).
|
||||
il.append(new INVOKEDYNAMIC(opcode, index));
|
||||
|
||||
//---Variante 2 mit Konstantenpool-Referenz---
|
||||
//int cpSize = cp.getSize()-1;//Vermutlich ist die benötigte Referenz das aktuellste Element?
|
||||
//il.append(new INVOKEDYNAMIC((short) cpSize, 0));
|
||||
return il;
|
||||
}
|
||||
|
||||
|
@ -299,11 +299,13 @@ public class MethodCall extends Expr
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
@Override
|
||||
public void parserPostProcessing(SyntaxTreeNode parent) {
|
||||
super.parserPostProcessing(parent);
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
@Override
|
||||
public InstructionList genByteCode(ClassGen _cg) {
|
||||
// TODO Auto-generated method stub
|
||||
|
@ -65,7 +65,10 @@ public class SuperCall extends ThisCall
|
||||
((Constructor)p).get_Block().statements.firstElement().equals(this)){
|
||||
//Constraints generieren:
|
||||
|
||||
if(this.arglist == null)this.arglist = new ArgumentList();
|
||||
|
||||
MethodCall constructorCall = new ConstructorCall(new Receiver(new This(this)), className, arglist, this.getOffset());
|
||||
constructorCall.parserPostProcessing(this);
|
||||
ret.add(constructorCall.TYPEStmt(assumptions));
|
||||
return ret;
|
||||
}else{
|
||||
|
@ -5,6 +5,11 @@ package de.dhbwstuttgart.syntaxtree.statement;
|
||||
import java.util.Hashtable;
|
||||
|
||||
import org.apache.bcel.generic.ClassGen;
|
||||
import org.apache.bcel.generic.InstructionFactory;
|
||||
import org.apache.bcel.generic.InstructionHandle;
|
||||
import org.apache.bcel.generic.InstructionList;
|
||||
import org.apache.bcel.generic.MethodGen;
|
||||
import org.apache.bcel.generic.ObjectType;
|
||||
|
||||
import de.dhbwstuttgart.typeinference.Menge;
|
||||
import de.dhbwstuttgart.logger.Logger;
|
||||
@ -143,9 +148,11 @@ public class This extends Expr
|
||||
}
|
||||
|
||||
@Override
|
||||
public void genByteCode(ClassGen _cg) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
public InstructionList genByteCode(ClassGen _cg) {
|
||||
InstructionList il = new InstructionList();
|
||||
InstructionHandle ih_0 = il.append(InstructionFactory.createLoad(org.apache.bcel.generic.Type.OBJECT, 0));
|
||||
InstructionHandle ih_1 = il.append(InstructionFactory.createReturn(org.apache.bcel.generic.Type.OBJECT));
|
||||
return il;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,4 +1,3 @@
|
||||
class Matrix2{
|
||||
<EN, T2, EM extends EN, R extends EM, DF extends T2> Fun1<Fun1<EN, Fun2<R, Matrix2, T2>>, DF> op = (m)->(f)->{return f.apply(this,m);};
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package plugindevelopment.TypeInsertTests;
|
||||
package plugindevelopment.TypeInsertTests.LargeSourceCodeTests;
|
||||
|
||||
import de.dhbwstuttgart.typeinference.Menge;
|
||||
import plugindevelopment.TypeInsertTests.MultipleTypesInsertTester;
|
||||
|
||||
import org.junit.Test;
|
||||
|
Loading…
Reference in New Issue
Block a user