MatrixOP funktioniert (mit JUnit wird class file erzeugt) und dann mit TestBytecode.java getestet
This commit is contained in:
parent
90c0cd431f
commit
e07b189ba4
@ -70,6 +70,7 @@ public class BytecodeGen implements ASTVisitor {
|
||||
// stores generics and their bounds of class
|
||||
HashMap<String, String> genericsAndBounds = new HashMap<>();
|
||||
|
||||
private int constructorPos = 0;
|
||||
|
||||
private final TPHExtractor tphExtractor = new TPHExtractor();
|
||||
private final ArrayList<GenericInsertPair> commonPairs = new ArrayList<>();
|
||||
@ -293,9 +294,13 @@ public class BytecodeGen implements ASTVisitor {
|
||||
System.out.println("Constructor: " + field.getName() + " Sig: "+ sig + " Desc: " + desc);
|
||||
MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "<init>", desc, sig, null);
|
||||
mv.visitCode();
|
||||
|
||||
Block block = fieldInitializations.get().block;
|
||||
|
||||
constructorPos += 1;
|
||||
|
||||
BytecodeGenMethod gen = new BytecodeGenMethod(className,superClass,resultSet,field, mv,paramsAndLocals,cw,
|
||||
genericsAndBoundsMethod,genericsAndBounds,isInterface,classFiles, sf,path, block);
|
||||
genericsAndBoundsMethod,genericsAndBounds,isInterface,classFiles, sf,path, block, constructorPos);
|
||||
if(!field.getParameterList().iterator().hasNext() && !(field.block.statements.get(field.block.statements.size()-1) instanceof ReturnVoid)) {
|
||||
mv.visitInsn(Opcodes.RETURN);
|
||||
}
|
||||
|
@ -86,12 +86,14 @@ public class BytecodeGenMethod implements StatementVisitor {
|
||||
private KindOfLambda kindOfLambda;
|
||||
private HashMap<String, byte[]> classFiles;
|
||||
|
||||
private int constructorPos = 0;
|
||||
|
||||
private ArrayList<RefTypeOrTPHOrWildcardOrGeneric> varsFunInterface = new ArrayList<>();;
|
||||
// generate bytecode for constructor
|
||||
public BytecodeGenMethod(String className, String superClass,ResultSet resultSet, Method m, MethodVisitor mv,
|
||||
HashMap<String, Integer> paramsAndLocals, ClassWriter cw, HashMap<String, String> genericsAndBoundsMethod,
|
||||
HashMap<String, String> genericsAndBounds, boolean isInterface, HashMap<String, byte[]> classFiles,
|
||||
SourceFile sf,String path, Block block) {
|
||||
SourceFile sf,String path, Block block, int constructorPos) {
|
||||
|
||||
this.className = className;
|
||||
this.superClass = superClass;
|
||||
@ -106,6 +108,7 @@ public class BytecodeGenMethod implements StatementVisitor {
|
||||
this.classFiles = classFiles;
|
||||
this.sf = sf;
|
||||
this.path = path;
|
||||
this.constructorPos = constructorPos;
|
||||
if(block != null)
|
||||
this.blockFieldInit = block;
|
||||
this.m.block.accept(this);
|
||||
@ -634,20 +637,20 @@ public class BytecodeGenMethod implements StatementVisitor {
|
||||
// Desc: (this/nothing)TargetType
|
||||
String fiMethodDesc = samMethod.accept(new DescriptorToString(resultSet));
|
||||
mv.visitInvokeDynamicInsn("apply", fiMethodDesc, bootstrap, arg1, arg2, arg3);
|
||||
if(constructorPos<2) {
|
||||
MethodVisitor mvLambdaBody = cw.visitMethod(Opcodes.ACC_PRIVATE + staticOrInstance + Opcodes.ACC_SYNTHETIC,
|
||||
methodName, newDesc, null, null);
|
||||
|
||||
MethodVisitor mvLambdaBody = cw.visitMethod(Opcodes.ACC_PRIVATE + staticOrInstance + Opcodes.ACC_SYNTHETIC,
|
||||
methodName, newDesc, null, null);
|
||||
ArrayList<String> usedVars = kindOfLambda.getUsedVars();
|
||||
|
||||
ArrayList<String> usedVars = kindOfLambda.getUsedVars();
|
||||
|
||||
new BytecodeGenMethod(lambdaExpression, usedVars,this.resultSet, mvLambdaBody, indexOfFirstParamLam, isInterface,
|
||||
classFiles,this.path, lamCounter, sf);
|
||||
|
||||
mvLambdaBody.visitMaxs(0, 0);
|
||||
mvLambdaBody.visitEnd();
|
||||
cw.visitInnerClass("java/lang/invoke/MethodHandles$Lookup", "java/lang/invoke/MethodHandles", "Lookup",
|
||||
Opcodes.ACC_PUBLIC + Opcodes.ACC_STATIC + Opcodes.ACC_FINAL);
|
||||
new BytecodeGenMethod(lambdaExpression, usedVars,this.resultSet, mvLambdaBody, indexOfFirstParamLam, isInterface,
|
||||
classFiles,this.path, lamCounter, sf);
|
||||
|
||||
mvLambdaBody.visitMaxs(0, 0);
|
||||
mvLambdaBody.visitEnd();
|
||||
cw.visitInnerClass("java/lang/invoke/MethodHandles$Lookup", "java/lang/invoke/MethodHandles", "Lookup",
|
||||
Opcodes.ACC_PUBLIC + Opcodes.ACC_STATIC + Opcodes.ACC_FINAL);
|
||||
}
|
||||
// generateBCForFunN(lambdaExpression, typeErasure);
|
||||
}
|
||||
|
||||
|
@ -162,7 +162,7 @@ public class KindOfLambda implements StatementVisitor{
|
||||
|
||||
@Override
|
||||
public void visit(UnaryExpr unaryExpr) {
|
||||
throw new NotImplementedException();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -202,7 +202,8 @@ public class KindOfLambda implements StatementVisitor{
|
||||
|
||||
@Override
|
||||
public void visit(WhileStmt whileStmt) {
|
||||
// TODO Auto-generated method stub
|
||||
whileStmt.expr.accept(this);
|
||||
whileStmt.loopBlock.accept(this);
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user