forked from JavaTX/JavaCompilerCore
Rekursiver Aufruf von Atrributen funktioniert
This commit is contained in:
parent
ea65a87336
commit
d27e0af57c
@ -69,8 +69,11 @@ public class ArgumentVisitor implements StatementVisitor {
|
||||
public void visit(BinaryExpr binary) {
|
||||
binary.accept(bytecodeGenMethod);
|
||||
|
||||
if(argListMethCall.get(0))
|
||||
if(argListMethCall.get(0)) {
|
||||
bytecodeGenMethod.doUnboxing(bytecodeGenMethod.getResolvedType(binary.getType()));
|
||||
} else {
|
||||
bytecodeGenMethod.doBoxing(bytecodeGenMethod.getResolvedType(binary.getType()));
|
||||
}
|
||||
argListMethCall.remove(0);
|
||||
}
|
||||
|
||||
|
@ -374,7 +374,10 @@ public class BytecodeGen implements ASTVisitor {
|
||||
@Override
|
||||
public void visit(Field field) {
|
||||
System.out.println("In Field ---");
|
||||
cw.visitField(field.modifier, field.getName(),resultSet.resolveType(field.getType()).resolvedType.acceptTV(new TypeToSignature()), null, null);
|
||||
cw.visitField(field.modifier, field.getName(),
|
||||
"L"+resultSet.resolveType(field.getType()).resolvedType.acceptTV(new TypeToDescriptor())+";",
|
||||
resultSet.resolveType(field.getType()).resolvedType.acceptTV(new TypeToSignature()),
|
||||
null);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -110,14 +110,14 @@ public class BytecodeGenMethod implements StatementVisitor {
|
||||
}
|
||||
|
||||
public BytecodeGenMethod(LambdaExpression lambdaExpression, ResultSet resultSet, MethodVisitor mv,
|
||||
int indexOfFirstParamLam, boolean isInterface, HashMap<String, byte[]> classFiles, String path) {
|
||||
int indexOfFirstParamLam, boolean isInterface, HashMap<String, byte[]> classFiles, String path, int lamCounter) {
|
||||
|
||||
this.resultSet = resultSet;
|
||||
this.mv = mv;
|
||||
this.isInterface = isInterface;
|
||||
this.classFiles = classFiles;
|
||||
this.path = path;
|
||||
|
||||
this.lamCounter = lamCounter;
|
||||
Iterator<FormalParameter> itr = lambdaExpression.params.iterator();
|
||||
int i = indexOfFirstParamLam;
|
||||
while (itr.hasNext()) {
|
||||
@ -567,7 +567,7 @@ public class BytecodeGenMethod implements StatementVisitor {
|
||||
methodName, arg3.toString(), null, null);
|
||||
|
||||
new BytecodeGenMethod(lambdaExpression, this.resultSet, mvLambdaBody, indexOfFirstParamLam, isInterface,
|
||||
classFiles,this.path);
|
||||
classFiles,this.path, lamCounter);
|
||||
|
||||
mvLambdaBody.visitMaxs(0, 0);
|
||||
mvLambdaBody.visitEnd();
|
||||
@ -674,7 +674,7 @@ public class BytecodeGenMethod implements StatementVisitor {
|
||||
System.out.println("Methods of " + receiverName + " ");
|
||||
ClassLoader cLoader = ClassLoader.getSystemClassLoader();
|
||||
// This will be used if the class is not standard class (not in API)
|
||||
// ClassLoader cLoader2;
|
||||
ClassLoader cLoader2;
|
||||
java.lang.reflect.Method methodRefl = null;
|
||||
String clazz = receiverName.replace("/", ".");
|
||||
|
||||
@ -688,15 +688,15 @@ public class BytecodeGenMethod implements StatementVisitor {
|
||||
methodRefl = getMethod(methodCall.name,methodCall.arglist.getArguments().size(),methods);
|
||||
|
||||
} catch (Exception e) {
|
||||
// try {
|
||||
// cLoader2 = new URLClassLoader(new URL[] {new URL("file://"+path)});
|
||||
// java.lang.reflect.Method[] methods = cLoader2.loadClass(clazz).getMethods();
|
||||
// System.out.println("Methods of " + receiverName + " ");
|
||||
// for(int i = 0; i<methods.length; i++) {
|
||||
// System.out.println(methods[i]);
|
||||
// }
|
||||
// methodRefl = getMethod(methodCall.name,methods);
|
||||
// }catch (Exception e2) {
|
||||
try {
|
||||
cLoader2 = new URLClassLoader(new URL[] {new URL("file://"+path)});
|
||||
java.lang.reflect.Method[] methods = cLoader2.loadClass(clazz).getMethods();
|
||||
System.out.println("Methods of " + receiverName + " ");
|
||||
for(int i = 0; i<methods.length; i++) {
|
||||
System.out.println(methods[i]);
|
||||
}
|
||||
methodRefl = getMethod(methodCall.name,methodCall.arglist.getArguments().size(),methods);
|
||||
}catch (Exception e2) {
|
||||
String superClass = "";
|
||||
// TODO: Test SubMatrix.jav
|
||||
while(true) {
|
||||
@ -731,7 +731,7 @@ public class BytecodeGenMethod implements StatementVisitor {
|
||||
receiverName = superClass;
|
||||
continue;
|
||||
}
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -1124,7 +1124,7 @@ public class BytecodeGenMethod implements StatementVisitor {
|
||||
}
|
||||
|
||||
// Boxing: prim -> RefType
|
||||
private void doBoxing(String type) {
|
||||
public void doBoxing(String type) {
|
||||
switch (type) {
|
||||
case "java/lang/String":
|
||||
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/StringBuilder", "toString", "()Ljava/lang/String;",
|
||||
|
@ -46,8 +46,8 @@ public class KindOfLambda implements StatementVisitor{
|
||||
|
||||
@Override
|
||||
public void visit(BinaryExpr binary) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
binary.lexpr.accept(this);
|
||||
binary.rexpr.accept(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -82,8 +82,9 @@ public class KindOfLambda implements StatementVisitor{
|
||||
|
||||
@Override
|
||||
public void visit(IfStmt ifStmt) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
ifStmt.expr.accept(this);
|
||||
ifStmt.then_block.accept(this);
|
||||
ifStmt.else_block.accept(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -156,8 +157,10 @@ public class KindOfLambda implements StatementVisitor{
|
||||
|
||||
@Override
|
||||
public void visit(This aThis) {
|
||||
this.isInstanceCapturingLambda = true;
|
||||
this.argumentList.add(aThis.getType());
|
||||
if(!isInstanceCapturingLambda) {
|
||||
this.isInstanceCapturingLambda = true;
|
||||
this.argumentList.add(aThis.getType());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -3,6 +3,7 @@ package bytecode;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URL;
|
||||
@ -32,17 +33,19 @@ public class FacultyTest {
|
||||
classToTest = loader.loadClass("Faculty");
|
||||
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||
|
||||
Method m = classToTest.getDeclaredMethod("m", Integer.class);
|
||||
// Method m = classToTest.getDeclaredMethod("m", Integer.class);
|
||||
Field fact = classToTest.getDeclaredField("fact");
|
||||
// Class<?> lambda = m.invoke(instanceOfClass).getClass();
|
||||
// Method apply = lambda.getMethod("apply", Object.class);
|
||||
Class<?> lambda = fact.getType();
|
||||
Method apply = lambda.getMethod("apply", Object.class);
|
||||
//
|
||||
// // Damit man auf die Methode zugreifen kann
|
||||
// apply.setAccessible(true);
|
||||
apply.setAccessible(true);
|
||||
|
||||
Integer i = 3;
|
||||
|
||||
// Integer result = (Integer) apply.invoke(m.invoke(instanceOfClass), i);
|
||||
Integer result = (Integer) m.invoke(instanceOfClass,i);
|
||||
Integer result = (Integer) apply.invoke(instanceOfClass, i);
|
||||
// Integer result = (Integer) m.invoke(instanceOfClass,i);
|
||||
|
||||
assertEquals(6, result);
|
||||
}
|
||||
|
@ -1,33 +1,46 @@
|
||||
import java.lang.Integer;
|
||||
|
||||
public class Faculty {
|
||||
|
||||
m (x) {
|
||||
|
||||
// var fact = (x) -> {
|
||||
// if (x == 1) {
|
||||
// return x;
|
||||
// }
|
||||
// else {
|
||||
// return x * (fact.apply(x-1));
|
||||
// }
|
||||
// };
|
||||
// return fact;
|
||||
// var x = 13;
|
||||
// if(x>22) {
|
||||
// return 0;
|
||||
// }else if(x <1){
|
||||
// return x;
|
||||
// }else {
|
||||
// return 1;
|
||||
// }
|
||||
|
||||
if (x < 0) {
|
||||
return 0;
|
||||
}else if(x<2) {
|
||||
return x;
|
||||
} else {
|
||||
return x * m(x-1);
|
||||
}
|
||||
}
|
||||
public fact;
|
||||
Faculty() {
|
||||
fact = (x) -> {
|
||||
if(x<0) {
|
||||
return 0;
|
||||
}else if (x < 1) {
|
||||
return x;
|
||||
}
|
||||
else {
|
||||
return x * (fact.apply(x-1));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// m (x) {
|
||||
//
|
||||
//// var fact = (x) -> {
|
||||
//// if (x == 1) {
|
||||
//// return x;
|
||||
//// }
|
||||
//// else {
|
||||
//// return x * (fact.apply(x-1));
|
||||
//// }
|
||||
//// };
|
||||
//// return fact;
|
||||
//// var x = 13;
|
||||
//// if(x>22) {
|
||||
//// return 0;
|
||||
//// }else if(x <1){
|
||||
//// return x;
|
||||
//// }else {
|
||||
//// return 1;
|
||||
//// }
|
||||
//
|
||||
// if (x < 0) {
|
||||
// return 0;
|
||||
// }else if(x<2) {
|
||||
// return x;
|
||||
// } else {
|
||||
// return x * m(x-1);
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user