forked from JavaTX/JavaCompilerCore
generateBCForFun() um Parameter path erweitert.
This commit is contained in:
parent
303cfa5409
commit
11649b39d3
@ -44,6 +44,9 @@ public class BytecodeGen implements ASTVisitor {
|
|||||||
private boolean isInterface;
|
private boolean isInterface;
|
||||||
private List<ResultSet> listOfResultSets;
|
private List<ResultSet> listOfResultSets;
|
||||||
private ResultSet resultSet;
|
private ResultSet resultSet;
|
||||||
|
|
||||||
|
private String path;
|
||||||
|
|
||||||
private int indexOfFirstParam = 0;
|
private int indexOfFirstParam = 0;
|
||||||
|
|
||||||
private String superClass;
|
private String superClass;
|
||||||
@ -64,16 +67,17 @@ public class BytecodeGen implements ASTVisitor {
|
|||||||
|
|
||||||
ArrayList<String> methodNameAndParamsT = new ArrayList<>();
|
ArrayList<String> methodNameAndParamsT = new ArrayList<>();
|
||||||
|
|
||||||
public BytecodeGen(HashMap<String,byte[]> classFiles, List<ResultSet> listOfResultSets) {
|
public BytecodeGen(HashMap<String,byte[]> classFiles, List<ResultSet> listOfResultSets, String path) {
|
||||||
this.classFiles = classFiles;
|
this.classFiles = classFiles;
|
||||||
this.listOfResultSets = listOfResultSets;
|
this.listOfResultSets = listOfResultSets;
|
||||||
|
this.path = path;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visit(SourceFile sourceFile) {
|
public void visit(SourceFile sourceFile) {
|
||||||
for(ClassOrInterface cl : sourceFile.getClasses()) {
|
for(ClassOrInterface cl : sourceFile.getClasses()) {
|
||||||
System.out.println("in Class: " + cl.getClassName().toString());
|
System.out.println("in Class: " + cl.getClassName().toString());
|
||||||
BytecodeGen classGen = new BytecodeGen(classFiles, listOfResultSets);
|
BytecodeGen classGen = new BytecodeGen(classFiles, listOfResultSets,path);
|
||||||
cl.accept(classGen);
|
cl.accept(classGen);
|
||||||
classGen.writeClass(cl.getClassName().toString());
|
classGen.writeClass(cl.getClassName().toString());
|
||||||
}
|
}
|
||||||
@ -190,7 +194,7 @@ public class BytecodeGen implements ASTVisitor {
|
|||||||
MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "<init>", desc, sig, null);
|
MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "<init>", desc, sig, null);
|
||||||
mv.visitCode();
|
mv.visitCode();
|
||||||
BytecodeGenMethod gen = new BytecodeGenMethod(className,superClass,resultSet,field, mv,paramsAndLocals,cw,
|
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()) {
|
if(!field.getParameterList().iterator().hasNext()) {
|
||||||
mv.visitInsn(Opcodes.RETURN);
|
mv.visitInsn(Opcodes.RETURN);
|
||||||
}
|
}
|
||||||
@ -264,7 +268,7 @@ public class BytecodeGen implements ASTVisitor {
|
|||||||
|
|
||||||
mv.visitCode();
|
mv.visitCode();
|
||||||
BytecodeGenMethod gen = new BytecodeGenMethod(className,superClass,resultSet,method, mv,paramsAndLocals,cw,
|
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.visitMaxs(0, 0);
|
||||||
mv.visitEnd();
|
mv.visitEnd();
|
||||||
|
@ -57,7 +57,7 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
private HashMap<String, String> genericsAndBounds;
|
private HashMap<String, String> genericsAndBounds;
|
||||||
private boolean isBinaryExp = false;
|
private boolean isBinaryExp = false;
|
||||||
private String superClass;
|
private String superClass;
|
||||||
|
private String path;
|
||||||
private IStatement statement = null;
|
private IStatement statement = null;
|
||||||
|
|
||||||
// for tests **
|
// for tests **
|
||||||
@ -73,7 +73,7 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
|
|
||||||
public BytecodeGenMethod(String className, String superClass,ResultSet resultSet, Method m, MethodVisitor mv,
|
public BytecodeGenMethod(String className, String superClass,ResultSet resultSet, Method m, MethodVisitor mv,
|
||||||
HashMap<String, Integer> paramsAndLocals, ClassWriter cw, HashMap<String, String> genericsAndBoundsMethod,
|
HashMap<String, Integer> paramsAndLocals, ClassWriter cw, HashMap<String, String> genericsAndBoundsMethod,
|
||||||
HashMap<String, String> genericsAndBounds, boolean isInterface, HashMap<String, byte[]> classFiles) {
|
HashMap<String, String> genericsAndBounds, boolean isInterface, HashMap<String, byte[]> classFiles, String path) {
|
||||||
|
|
||||||
this.className = className;
|
this.className = className;
|
||||||
this.superClass = superClass;
|
this.superClass = superClass;
|
||||||
@ -86,19 +86,21 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
this.genericsAndBounds = genericsAndBounds;
|
this.genericsAndBounds = genericsAndBounds;
|
||||||
this.isInterface = isInterface;
|
this.isInterface = isInterface;
|
||||||
this.classFiles = classFiles;
|
this.classFiles = classFiles;
|
||||||
|
this.path = path;
|
||||||
|
|
||||||
if (!isInterface)
|
if (!isInterface)
|
||||||
this.m.block.accept(this);
|
this.m.block.accept(this);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public BytecodeGenMethod(LambdaExpression lambdaExpression, ResultSet resultSet, MethodVisitor mv,
|
public BytecodeGenMethod(LambdaExpression lambdaExpression, ResultSet resultSet, MethodVisitor mv,
|
||||||
int indexOfFirstParamLam, boolean isInterface, HashMap<String, byte[]> classFiles) {
|
int indexOfFirstParamLam, boolean isInterface, HashMap<String, byte[]> classFiles, String path) {
|
||||||
|
|
||||||
this.resultSet = resultSet;
|
this.resultSet = resultSet;
|
||||||
this.mv = mv;
|
this.mv = mv;
|
||||||
this.isInterface = isInterface;
|
this.isInterface = isInterface;
|
||||||
this.classFiles = classFiles;
|
this.classFiles = classFiles;
|
||||||
|
this.path = path;
|
||||||
|
|
||||||
Iterator<FormalParameter> itr = lambdaExpression.params.iterator();
|
Iterator<FormalParameter> itr = lambdaExpression.params.iterator();
|
||||||
int i = indexOfFirstParamLam;
|
int i = indexOfFirstParamLam;
|
||||||
@ -534,7 +536,7 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
methodName, arg3.toString(), null, null);
|
methodName, arg3.toString(), null, null);
|
||||||
|
|
||||||
new BytecodeGenMethod(lambdaExpression, this.resultSet, mvLambdaBody, indexOfFirstParamLam, isInterface,
|
new BytecodeGenMethod(lambdaExpression, this.resultSet, mvLambdaBody, indexOfFirstParamLam, isInterface,
|
||||||
classFiles);
|
classFiles,this.path);
|
||||||
|
|
||||||
mvLambdaBody.visitMaxs(0, 0);
|
mvLambdaBody.visitMaxs(0, 0);
|
||||||
mvLambdaBody.visitEnd();
|
mvLambdaBody.visitEnd();
|
||||||
@ -575,7 +577,7 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
try {
|
try {
|
||||||
System.out.println("generating " + name + ".class file...");
|
System.out.println("generating " + name + ".class file...");
|
||||||
output = new FileOutputStream(
|
output = new FileOutputStream(
|
||||||
new File(System.getProperty("user.dir") + "/testBytecode/generatedBC/" + name + ".class"));
|
new File(path + name + ".class"));
|
||||||
output.write(bytecode);
|
output.write(bytecode);
|
||||||
output.close();
|
output.close();
|
||||||
System.out.println(name + ".class file generated");
|
System.out.println(name + ".class file generated");
|
||||||
|
@ -246,7 +246,7 @@ public class JavaTXCompiler {
|
|||||||
HashMap<String,byte[]> classFiles = new HashMap<>();
|
HashMap<String,byte[]> classFiles = new HashMap<>();
|
||||||
SourceFile sf = sourceFiles.get(f);
|
SourceFile sf = sourceFiles.get(f);
|
||||||
List<ResultSet> typeinferenceResult = this.typeInference();
|
List<ResultSet> 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 bytecodeGen = new BytecodeGen(classFiles,typeinferenceResult.get(0));
|
||||||
bytecodeGen.visit(sf);
|
bytecodeGen.visit(sf);
|
||||||
this.writeClassFile(bytecodeGen.getClassFiles(), path);
|
this.writeClassFile(bytecodeGen.getClassFiles(), path);
|
||||||
|
Loading…
Reference in New Issue
Block a user