diff --git a/src/de/dhbwstuttgart/bytecode/BytecodeGen.java b/src/de/dhbwstuttgart/bytecode/BytecodeGen.java index 69acdefc..0dd57374 100644 --- a/src/de/dhbwstuttgart/bytecode/BytecodeGen.java +++ b/src/de/dhbwstuttgart/bytecode/BytecodeGen.java @@ -44,6 +44,9 @@ public class BytecodeGen implements ASTVisitor { private boolean isInterface; private List listOfResultSets; private ResultSet resultSet; + + private String path; + private int indexOfFirstParam = 0; private String superClass; @@ -64,16 +67,17 @@ public class BytecodeGen implements ASTVisitor { ArrayList methodNameAndParamsT = new ArrayList<>(); - public BytecodeGen(HashMap classFiles, List listOfResultSets) { + public BytecodeGen(HashMap classFiles, List listOfResultSets, String path) { this.classFiles = classFiles; this.listOfResultSets = listOfResultSets; + this.path = path; } @Override public void visit(SourceFile sourceFile) { for(ClassOrInterface cl : sourceFile.getClasses()) { System.out.println("in Class: " + cl.getClassName().toString()); - BytecodeGen classGen = new BytecodeGen(classFiles, listOfResultSets); + BytecodeGen classGen = new BytecodeGen(classFiles, listOfResultSets,path); cl.accept(classGen); classGen.writeClass(cl.getClassName().toString()); } @@ -190,7 +194,7 @@ public class BytecodeGen implements ASTVisitor { MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "", desc, sig, null); mv.visitCode(); BytecodeGenMethod gen = new BytecodeGenMethod(className,superClass,resultSet,field, mv,paramsAndLocals,cw, - genericsAndBoundsMethod,genericsAndBounds,isInterface,classFiles); + genericsAndBoundsMethod,genericsAndBounds,isInterface,classFiles, path); if(!field.getParameterList().iterator().hasNext()) { mv.visitInsn(Opcodes.RETURN); } @@ -264,7 +268,7 @@ public class BytecodeGen implements ASTVisitor { mv.visitCode(); BytecodeGenMethod gen = new BytecodeGenMethod(className,superClass,resultSet,method, mv,paramsAndLocals,cw, - genericsAndBoundsMethod,genericsAndBounds,isInterface,classFiles); + genericsAndBoundsMethod,genericsAndBounds,isInterface,classFiles, path); mv.visitMaxs(0, 0); mv.visitEnd(); diff --git a/src/de/dhbwstuttgart/bytecode/BytecodeGenMethod.java b/src/de/dhbwstuttgart/bytecode/BytecodeGenMethod.java index bead57c1..9d03979f 100644 --- a/src/de/dhbwstuttgart/bytecode/BytecodeGenMethod.java +++ b/src/de/dhbwstuttgart/bytecode/BytecodeGenMethod.java @@ -57,7 +57,7 @@ public class BytecodeGenMethod implements StatementVisitor { private HashMap genericsAndBounds; private boolean isBinaryExp = false; private String superClass; - + private String path; private IStatement statement = null; // for tests ** @@ -73,7 +73,7 @@ public class BytecodeGenMethod implements StatementVisitor { public BytecodeGenMethod(String className, String superClass,ResultSet resultSet, Method m, MethodVisitor mv, HashMap paramsAndLocals, ClassWriter cw, HashMap genericsAndBoundsMethod, - HashMap genericsAndBounds, boolean isInterface, HashMap classFiles) { + HashMap genericsAndBounds, boolean isInterface, HashMap classFiles, String path) { this.className = className; this.superClass = superClass; @@ -86,19 +86,21 @@ public class BytecodeGenMethod implements StatementVisitor { this.genericsAndBounds = genericsAndBounds; this.isInterface = isInterface; this.classFiles = classFiles; - + this.path = path; + if (!isInterface) this.m.block.accept(this); } public BytecodeGenMethod(LambdaExpression lambdaExpression, ResultSet resultSet, MethodVisitor mv, - int indexOfFirstParamLam, boolean isInterface, HashMap classFiles) { + int indexOfFirstParamLam, boolean isInterface, HashMap classFiles, String path) { this.resultSet = resultSet; this.mv = mv; this.isInterface = isInterface; this.classFiles = classFiles; + this.path = path; Iterator itr = lambdaExpression.params.iterator(); int i = indexOfFirstParamLam; @@ -534,7 +536,7 @@ public class BytecodeGenMethod implements StatementVisitor { methodName, arg3.toString(), null, null); new BytecodeGenMethod(lambdaExpression, this.resultSet, mvLambdaBody, indexOfFirstParamLam, isInterface, - classFiles); + classFiles,this.path); mvLambdaBody.visitMaxs(0, 0); mvLambdaBody.visitEnd(); @@ -575,7 +577,7 @@ public class BytecodeGenMethod implements StatementVisitor { try { System.out.println("generating " + name + ".class file..."); output = new FileOutputStream( - new File(System.getProperty("user.dir") + "/testBytecode/generatedBC/" + name + ".class")); + new File(path + name + ".class")); output.write(bytecode); output.close(); System.out.println(name + ".class file generated"); diff --git a/src/de/dhbwstuttgart/core/JavaTXCompiler.java b/src/de/dhbwstuttgart/core/JavaTXCompiler.java index bccb88aa..c4db69f2 100644 --- a/src/de/dhbwstuttgart/core/JavaTXCompiler.java +++ b/src/de/dhbwstuttgart/core/JavaTXCompiler.java @@ -246,7 +246,7 @@ public class JavaTXCompiler { HashMap classFiles = new HashMap<>(); SourceFile sf = sourceFiles.get(f); List typeinferenceResult = this.typeInference(); - BytecodeGen bytecodeGen = new BytecodeGen(classFiles,typeinferenceResult); + BytecodeGen bytecodeGen = new BytecodeGen(classFiles,typeinferenceResult,path); // BytecodeGen bytecodeGen = new BytecodeGen(classFiles,typeinferenceResult.get(0)); bytecodeGen.visit(sf); this.writeClassFile(bytecodeGen.getClassFiles(), path);