From 9a94ba2114e2bfa369c91fddf09b8a143ac4a521 Mon Sep 17 00:00:00 2001 From: Fayez Abu Alia Date: Wed, 31 Jan 2018 14:16:20 +0100 Subject: [PATCH] =?UTF-8?q?unn=C3=B6tige=20Kommentare=20wurden=20entfernt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dhbwstuttgart/bytecode/BytecodeGen.java | 26 ++---- .../bytecode/BytecodeGenMethod.java | 83 ++++++------------- .../descriptor/DescriptorToString.java | 12 ++- .../bytecode/signature/Signature.java | 6 +- test/bytecode/ATest.java | 8 ++ test/bytecode/DuMethod.jav | 2 +- test/bytecode/Example.jav | 7 ++ test/bytecode/Import.jav | 8 ++ test/bytecode/ImportTest.java | 7 ++ test/bytecode/JavaTXCompilerTest.java | 13 ++- test/bytecode/LamAssign.jav | 4 - test/bytecode/OverlaodGen.jav | 11 +++ test/bytecode/OverlaodGenTest.java | 7 ++ 13 files changed, 100 insertions(+), 94 deletions(-) create mode 100644 test/bytecode/ATest.java create mode 100644 test/bytecode/Example.jav create mode 100644 test/bytecode/Import.jav create mode 100644 test/bytecode/ImportTest.java create mode 100644 test/bytecode/OverlaodGen.jav create mode 100644 test/bytecode/OverlaodGenTest.java diff --git a/src/de/dhbwstuttgart/bytecode/BytecodeGen.java b/src/de/dhbwstuttgart/bytecode/BytecodeGen.java index f6f14b4ca..25c060243 100644 --- a/src/de/dhbwstuttgart/bytecode/BytecodeGen.java +++ b/src/de/dhbwstuttgart/bytecode/BytecodeGen.java @@ -56,7 +56,6 @@ public class BytecodeGen implements ASTVisitor { public void visit(SourceFile sourceFile) { for(ClassOrInterface cl : sourceFile.getClasses()) { BytecodeGen classGen = new BytecodeGen(classFiles, resultSet); - System.out.println("In CLASS: "+(cl.getClassName().toString())); cl.accept(classGen); classGen.writeClass(cl.getClassName().toString()); } @@ -86,8 +85,7 @@ public class BytecodeGen implements ASTVisitor { cw.visitSource(className +".jav", null); isInterface = (classOrInterface.getModifiers()&512)==512; - System.out.println("IS Interface = "+"modifiers= "+classOrInterface.getModifiers()+" ->"+(classOrInterface.getModifiers()&512) + isInterface); - + int acc = isInterface?classOrInterface.getModifiers()+Opcodes.ACC_ABSTRACT:classOrInterface.getModifiers()+Opcodes.ACC_SUPER; String sig = null; /* if class has generics then creates signature @@ -96,8 +94,6 @@ public class BytecodeGen implements ASTVisitor { */ if(classOrInterface.getGenerics().iterator().hasNext()) { Signature signature = new Signature(classOrInterface, genericsAndBounds); - - System.out.println(signature.toString()); sig = signature.toString(); } // needs implemented Interfaces? @@ -106,8 +102,6 @@ public class BytecodeGen implements ASTVisitor { // for each field in the class for(Field f : classOrInterface.getFieldDecl()) { - System.out.println("get Fields"); - System.out.println(f.getName()); f.accept(this); } @@ -136,16 +130,13 @@ public class BytecodeGen implements ASTVisitor { } String sig = null; if(hasGen) { - System.out.println("IM IN CONST HAS Gens"); Signature signature = new Signature(field, genericsAndBounds,methodParamsAndTypes); sig = signature.toString(); - System.out.println(sig); } NormalConstructor constructor = new NormalConstructor(field,genericsAndBounds,hasGen); desc = constructor.accept(new DescriptorToString(resultSet)); MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "", desc, sig, null); mv.visitCode(); - System.out.println("-----Constructor-----"); BytecodeGenMethod gen = new BytecodeGenMethod(className,resultSet,field, mv,paramsAndLocals,cw, genericsAndBoundsMethod,genericsAndBounds,isInterface,classFiles); if(!field.getParameterList().iterator().hasNext()) { @@ -166,9 +157,7 @@ public class BytecodeGen implements ASTVisitor { // Method getModifiers() ? int acc = isInterface?Opcodes.ACC_ABSTRACT:0; - System.out.println("-----Method-----"); - - boolean hasGenInParameterList = genericsAndBounds.containsKey(method.getReturnType().acceptTV(new TypeToDescriptor())); + boolean hasGenInParameterList = genericsAndBounds.containsKey(resultSet.resolveType(method.getReturnType()).resolvedType.acceptTV(new TypeToDescriptor())); if(!hasGenInParameterList) { for(String paramName : methodParamsAndTypes.keySet()) { String typeOfParam = methodParamsAndTypes.get(paramName).acceptTV(new TypeToDescriptor()); @@ -178,6 +167,10 @@ public class BytecodeGen implements ASTVisitor { } } } + + //TODO: Test if the return-type or any of the parameter is a parameterized type. (VP) + //than create the descriptor with the new syntax. + String sig = null; boolean hasGen = method.getGenerics().iterator().hasNext() || hasGenInParameterList; @@ -186,13 +179,10 @@ public class BytecodeGen implements ASTVisitor { // resultset hier zum testen Signature signature = new Signature(method, genericsAndBoundsMethod, methodParamsAndTypes,resultSet); sig = signature.toString(); - System.out.println(sig); - } NormalMethod meth = new NormalMethod(method,genericsAndBounds,genericsAndBoundsMethod,hasGen); methDesc = meth.accept(new DescriptorToString(resultSet)); - System.out.println("methDesc" + methDesc); MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC+acc, method.getName(), methDesc, sig, null); mv.visitCode(); @@ -212,7 +202,7 @@ public class BytecodeGen implements ASTVisitor { while(itr.hasNext()) { FormalParameter fp = itr.next(); paramsAndLocals.put(fp.getName(), i); - methodParamsAndTypes.put(fp.getName(), fp.getType()); + methodParamsAndTypes.put(fp.getName(), resultSet.resolveType(fp.getType()).resolvedType); fp.accept(this); i++; } @@ -255,7 +245,6 @@ public class BytecodeGen implements ASTVisitor { // ?? @Override public void visit(FieldVar fieldVar) { - System.out.println("in fieldvar"); // cw.newField(fieldVar.receiver.toString(), fieldVar.fieldVarName.toString(), fieldVar.getType().toString()); FieldVisitor fv = cw.visitField(Opcodes.ACC_PRIVATE, fieldVar.fieldVarName, "L"+fieldVar.getType()+";", null, null); fv.visitEnd(); @@ -264,7 +253,6 @@ public class BytecodeGen implements ASTVisitor { // access flages?? modifiers @Override public void visit(Field field) { - System.out.println("in field"); FieldVisitor fv = cw.visitField(Opcodes.ACC_PRIVATE, field.getName(), "L"+field.getType().toString().replace(".", "/")+";", null, null); fv.visitEnd(); } diff --git a/src/de/dhbwstuttgart/bytecode/BytecodeGenMethod.java b/src/de/dhbwstuttgart/bytecode/BytecodeGenMethod.java index 756837b0f..c19315e8a 100644 --- a/src/de/dhbwstuttgart/bytecode/BytecodeGenMethod.java +++ b/src/de/dhbwstuttgart/bytecode/BytecodeGenMethod.java @@ -32,7 +32,6 @@ import de.dhbwstuttgart.syntaxtree.Method; import de.dhbwstuttgart.syntaxtree.StatementVisitor; import de.dhbwstuttgart.syntaxtree.statement.literal.Literal; import de.dhbwstuttgart.syntaxtree.statement.literal.Null; -import de.dhbwstuttgart.syntaxtree.type.FunN; import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric; import de.dhbwstuttgart.typeinference.result.ResultSet; @@ -53,7 +52,7 @@ public class BytecodeGenMethod implements StatementVisitor{ private String fieldName; private String fieldDesc; private Expression rightSideTemp; - private String where; +// private String where; private boolean isRightSideALambda = false; private KindOfLambda kindOfLambda; private HashMap classFiles; @@ -64,7 +63,7 @@ public class BytecodeGenMethod implements StatementVisitor{ HashMap paramsAndLocals, ClassWriter cw, HashMap genericsAndBoundsMethod, HashMap genericsAndBounds, boolean isInterface, HashMap classFiles) { - this.where = "<<<<<< NORMAL METHOD >>>>>>"; +// this.where = "<<<<<< NORMAL METHOD >>>>>>"; this.className = className; this.resultSet = resultSet; @@ -79,23 +78,16 @@ public class BytecodeGenMethod implements StatementVisitor{ this.lamCounter = -1; this.varsFunInterface = new ArrayList<>(); - System.out.println("PARAMS = "+this.paramsAndLocals.size()); if(!isInterface) this.m.block.accept(this); -// System.out.println("PARAMS = "+this.paramsAndLocals.size()); -// for(int i = 0; i classFiles) { - System.out.println("\t\t++++++IN LAMBDA -------"); - this.where = "<<<<<< LAMBDA METHOD >>>>>>"; +// this.where = "<<<<<< LAMBDA METHOD >>>>>>"; this.resultSet = resultSet; this.mv = mv; this.isInterface = isInterface; @@ -114,7 +106,6 @@ public class BytecodeGenMethod implements StatementVisitor{ } private String getResolvedType(RefTypeOrTPHOrWildcardOrGeneric type) { -// return resultSet.resolveType(type).resolvedType.toString().replace(".", "/"); return resultSet.resolveType(type).resolvedType.acceptTV(new TypeToDescriptor()); } @@ -122,10 +113,8 @@ public class BytecodeGenMethod implements StatementVisitor{ @Override public void visit(Block block) { for(Statement stmt : block.getStatements()) { - System.out.println(where); - System.out.println("Stmt : " + stmt.toString()); +// System.out.println(where); stmt.accept(this); - System.out.println("--------------------------\n"); } } @@ -140,7 +129,7 @@ public class BytecodeGenMethod implements StatementVisitor{ // ?? @Override public void visit(LocalVar localVar) { - System.out.println("in Local Var: " + localVar.name); +// System.out.println("in Local Var: " + localVar.name); mv.visitVarInsn(Opcodes.ALOAD, paramsAndLocals.get(localVar.name)); } // ?? @@ -148,12 +137,12 @@ public class BytecodeGenMethod implements StatementVisitor{ public void visit(LocalVarDecl localVarDecl) { // Integer i; // paramsAndLocals.put(localVarDecl.getName(), paramsAndLocals.size()+1); - System.out.println("In localVarDecl :: "+localVarDecl.getName()); +// System.out.println("In localVarDecl :: "+localVarDecl.getName()); } @Override public void visit(Assign assign) { - System.out.println("Assign : \nright = "+assign.rightSide + "\nLeft = " + assign.lefSide); +// System.out.println("Assign : \nright = "+assign.rightSide + "\nLeft = " + assign.lefSide); // if the right side is a lambda => the left side must be a functional interface if(assign.rightSide.getClass().equals(LambdaExpression.class)) { @@ -162,7 +151,6 @@ public class BytecodeGenMethod implements StatementVisitor{ isRightSideALambda = false; } - System.out.println("\t isRight Side lambda: " + isRightSideALambda); if(assign.lefSide.getClass().equals(AssignToField.class)) { // load_0, ldc or .. then putfield this.rightSideTemp = assign.rightSide; @@ -175,16 +163,13 @@ public class BytecodeGenMethod implements StatementVisitor{ @Override public void visit(Binary binary) { - System.out.println("\t++ In Binary: "); + } @Override public void visit(LambdaExpression lambdaExpression) { - System.out.println("\n++ In Lambda: "); this.lamCounter++; - System.out.println("Lam Hs Gens: " + lambdaExpression.getGenerics().iterator().hasNext()); - System.out.println("Lam Hs Gens: " + resultSet.resolveType(lambdaExpression.getReturnType()).resolvedType.acceptTV(new TypeToSignature())); Lambda lam = new Lambda(lambdaExpression); String lamDesc = lam.accept(new DescriptorToString(resultSet)); //Call site, which, when invoked, returns an instance of the functional interface to which @@ -206,7 +191,6 @@ public class BytecodeGenMethod implements StatementVisitor{ typeErasure += "L"+Type.getInternalName(Object.class) + ";"; } - System.out.println("LamReturnType: "+lambdaExpression.getReturnType().acceptTV(new TypeToString())); typeErasure += ")L"+Type.getInternalName(Object.class) + ";"; // Type erasure Type arg1 = Type.getMethodType(typeErasure); @@ -235,8 +219,7 @@ public class BytecodeGenMethod implements StatementVisitor{ SamMethod samMethod = new SamMethod(kindOfLambda.getArgumentList(), lambdaExpression.getType()); // Desc: (this/nothing)TargetType String fiMethodDesc = samMethod.accept(new DescriptorToString(resultSet)); - mv.visitInvokeDynamicInsn("apply", fiMethodDesc, bootstrap, - arg1, arg2,arg3); + mv.visitInvokeDynamicInsn("apply", fiMethodDesc, bootstrap, arg1, arg2,arg3); MethodVisitor mvLambdaBody = cw.visitMethod(Opcodes.ACC_PRIVATE+ staticOrInstance + Opcodes.ACC_SYNTHETIC, methodName, arg3.toString(), null, null); @@ -249,32 +232,31 @@ public class BytecodeGenMethod implements StatementVisitor{ cw.visitInnerClass("java/lang/invoke/MethodHandles$Lookup", "java/lang/invoke/MethodHandles", "Lookup", Opcodes.ACC_PUBLIC + Opcodes.ACC_STATIC + Opcodes.ACC_FINAL); - generateBCForFunN(lambdaExpression); + generateBCForFunN(lambdaExpression,typeErasure); } - private void generateBCForFunN(LambdaExpression lambdaExpression) { + private void generateBCForFunN(LambdaExpression lambdaExpression, String methDesc) { ClassWriter classWriter =new ClassWriter(ClassWriter.COMPUTE_FRAMES|ClassWriter.COMPUTE_MAXS); SignatureWriter methSig = new SignatureWriter(); - String methDesc = "("; + int numberOfParams = 0; SignatureVisitor paramVisitor = methSig.visitParameterType(); Iterator itr = lambdaExpression.params.iterator(); while(itr.hasNext()) { numberOfParams++; // getBounds - methDesc += "L"+Type.getInternalName(Object.class)+";"; paramVisitor.visitTypeVariable("T"+numberOfParams); itr.next(); } methSig.visitReturnType().visitTypeVariable("R"); // ")"+lam.getReturn.getBounds - methDesc += ")L"+Type.getInternalName(Object.class)+";"; Signature sig = new Signature(lambdaExpression,numberOfParams); String name = "Fun"+numberOfParams; classWriter.visit(Opcodes.V1_8, Opcodes.ACC_INTERFACE+Opcodes.ACC_ABSTRACT, name, sig.toString(), Type.getInternalName(Object.class), null); - MethodVisitor mvApply = classWriter.visitMethod(Opcodes.ACC_PUBLIC+Opcodes.ACC_ABSTRACT, "apply", methDesc, methSig.toString(), null); + MethodVisitor mvApply = classWriter.visitMethod(Opcodes.ACC_PUBLIC+Opcodes.ACC_ABSTRACT, "apply", + methDesc, methSig.toString(), null); mvApply.visitEnd(); writeClassFile(classWriter.toByteArray(),name); } @@ -282,8 +264,8 @@ public class BytecodeGenMethod implements StatementVisitor{ public void writeClassFile(byte[] bytecode, String name) { FileOutputStream output; try { - System.out.println("generating"+name+ ".class file"); - output = new FileOutputStream(new File(System.getProperty("user.dir") + "/testBytecode/generatedBC/" +name+".class")); + System.out.println("generating "+name+ ".class file..."); + output = new FileOutputStream(new File(System.getProperty("user.dir") + "/testBytecode/generatedBC/examples/" +name+".class")); output.write(bytecode); output.close(); System.out.println(name+".class file generated"); @@ -309,7 +291,6 @@ public class BytecodeGenMethod implements StatementVisitor{ @Override public void visit(FieldVar fieldVar) { - System.out.println("in fieldVar " + fieldVar.fieldVarName + " ** receiver: "+fieldVar.receiver); fieldName = fieldVar.fieldVarName; fieldDesc = "L"+getResolvedType(fieldVar.getType())+";"; @@ -333,7 +314,7 @@ public class BytecodeGenMethod implements StatementVisitor{ @Override public void visit(IfStmt ifStmt) { - System.out.println("++ IF-Statment: "); + } @Override @@ -344,13 +325,11 @@ public class BytecodeGenMethod implements StatementVisitor{ @Override public void visit(MethodCall methodCall) { - System.out.println(" In Methodcall: (" +methodCall.name+")" ); - System.out.print("\t\tMethod-Receiver: "); - if(methodCall.receiver instanceof ExpressionReceiver){ - System.out.print(((ExpressionReceiver) methodCall.receiver).expr + "\n"); - }else{ - System.out.print(((StaticClassName) methodCall.receiver).getType().toString() + "\n"); - } +// if(methodCall.receiver instanceof ExpressionReceiver){ +// System.out.print(((ExpressionReceiver) methodCall.receiver).expr + "\n"); +// }else{ +// System.out.print(((StaticClassName) methodCall.receiver).getType().toString() + "\n"); +// } methodCall.receiver.accept(this); methodCall.arglist.accept(this); @@ -359,14 +338,13 @@ public class BytecodeGenMethod implements StatementVisitor{ genericsAndBoundsMethod,genericsAndBounds); String mDesc = method.accept(new DescriptorToString(resultSet)); - System.out.println("is Vars empty: "+varsFunInterface.isEmpty()); +// System.out.println("is Vars empty: "+varsFunInterface.isEmpty()); // is methodCall.receiver functional Interface)? if(varsFunInterface.contains(methodCall.receiver.getType())) { mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, getResolvedType(methodCall.receiver.getType()), methodCall.name, mDesc, false); }else { - System.out.println("mDesc = " + mDesc); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, getResolvedType(methodCall.receiver.getType()), methodCall.name, mDesc, isInterface); } @@ -378,8 +356,8 @@ public class BytecodeGenMethod implements StatementVisitor{ @Override public void visit(NewClass methodCall) { - System.out.println("In NewClass: "); - System.out.println("\t\tname: " + methodCall.name + " *** " + "Receiver: " + methodCall.receiver); +// System.out.println("In NewClass: "); +// System.out.println("\t\tname: " + methodCall.name + " *** " + "Receiver: " + methodCall.receiver); mv.visitTypeInsn(Opcodes.NEW, methodCall.name.replace(".", "/")); mv.visitInsn(Opcodes.DUP); @@ -402,8 +380,6 @@ public class BytecodeGenMethod implements StatementVisitor{ @Override public void visit(ExpressionReceiver receiver) { - System.out.println(" in Receiver"); - System.out.println(" expr : " + receiver.expr); receiver.expr.accept(this); } @@ -420,7 +396,6 @@ public class BytecodeGenMethod implements StatementVisitor{ @Override public void visit(StaticClassName staticClassName) { - System.out.println("In StaticClassName: "); // mv.visitMethodInsn(Opcodes.INVOKESTATIC, staticClassName.getType().toString().replace(".", "/"), // staticClassName.toString(), staticClassName.getType().toString(), false); mv.visitFieldInsn(Opcodes.GETSTATIC, getResolvedType(staticClassName.getType()), @@ -429,18 +404,17 @@ public class BytecodeGenMethod implements StatementVisitor{ @Override public void visit(Super aSuper) { - System.out.println(">> In Super: "); + } @Override public void visit(This aThis) { - System.out.println("-> IN This"); mv.visitVarInsn(Opcodes.ALOAD, 0); } @Override public void visit(UnaryPlus unaryPlus) { - System.out.println("++ In UnaryPlus: "); + } @Override @@ -468,11 +442,9 @@ public class BytecodeGenMethod implements StatementVisitor{ @Override public void visit(ArgumentList argumentList) { - System.out.println("in ArgumentList: "); for(Expression al : argumentList.getArguments()) { al.accept(this); } - System.out.println("out from Argumentlist"); } @Override @@ -491,7 +463,6 @@ public class BytecodeGenMethod implements StatementVisitor{ @Override public void visit(AssignToLocal assignLeftSide) { - System.out.println("In Assign To Local: "); if(isRightSideALambda) varsFunInterface.add(assignLeftSide.localVar.getType()); paramsAndLocals.put(assignLeftSide.localVar.name, paramsAndLocals.size()+1); diff --git a/src/de/dhbwstuttgart/bytecode/descriptor/DescriptorToString.java b/src/de/dhbwstuttgart/bytecode/descriptor/DescriptorToString.java index 2ed48867b..c7c623b6f 100644 --- a/src/de/dhbwstuttgart/bytecode/descriptor/DescriptorToString.java +++ b/src/de/dhbwstuttgart/bytecode/descriptor/DescriptorToString.java @@ -7,8 +7,10 @@ import de.dhbwstuttgart.bytecode.MethodFromMethodCall; import de.dhbwstuttgart.bytecode.NormalConstructor; import de.dhbwstuttgart.bytecode.NormalMethod; import de.dhbwstuttgart.bytecode.SamMethod; +import de.dhbwstuttgart.bytecode.signature.TypeToSignature; import de.dhbwstuttgart.syntaxtree.FormalParameter; import de.dhbwstuttgart.syntaxtree.statement.Expression; +import de.dhbwstuttgart.syntaxtree.type.RefType; import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric; import de.dhbwstuttgart.typeinference.result.ResultSet; @@ -35,6 +37,8 @@ public class DescriptorToString implements DescriptorVisitor{ Iterator itr = method.getParameterList().iterator(); while(itr.hasNext()) { FormalParameter fp = itr.next(); +// System.out.println(resultSet.resolveType(fp.getType()).resolvedType.acceptTV(new TypeToSignature())); +// System.out.println("Parmetrisierte typ ? "+ ((RefType) fp.getType()).getParaList().size()); if(method.hasGen()) { String fpDesc = fp.getType().acceptTV(new TypeToDescriptor()); if(method.getGenericsAndBoundsMethod().containsKey(fpDesc)) { @@ -44,6 +48,8 @@ public class DescriptorToString implements DescriptorVisitor{ }else { desc += "L"+resultSet.resolveType(fp.getType()).resolvedType.acceptTV(new TypeToDescriptor())+ ";"; } + }else if(((RefType) fp.getType()).getParaList().size() > 0){ + desc += "L"+resultSet.resolveType(fp.getType()).resolvedType.toString().replace(".", "%").replace("<", "%%").replace(">", "%%")+ ";"; }else { desc += "L"+resultSet.resolveType(fp.getType()).resolvedType.acceptTV(new TypeToDescriptor())+ ";"; } @@ -76,16 +82,16 @@ public class DescriptorToString implements DescriptorVisitor{ while(itr.hasNext()) { FormalParameter fp = itr.next(); if(constructor.hasGen()) { - System.out.println("Cons has Gens"); +// System.out.println("Cons has Gens"); String fpDesc = fp.getType().acceptTV(new TypeToDescriptor()); - System.out.println(fpDesc); +// System.out.println(fpDesc); if(constructor.getGenericsAndBounds().containsKey(fpDesc)){ desc += "L"+constructor.getGenericsAndBounds().get(fpDesc)+ ";"; }else { desc += "L"+resultSet.resolveType(fp.getType()).resolvedType.acceptTV(new TypeToDescriptor())+ ";"; } }else { - System.out.println("Cons has NOT Gens"); +// System.out.println("Cons has NOT Gens"); desc += "L"+resultSet.resolveType(fp.getType()).resolvedType.acceptTV(new TypeToDescriptor())+ ";"; } } diff --git a/src/de/dhbwstuttgart/bytecode/signature/Signature.java b/src/de/dhbwstuttgart/bytecode/signature/Signature.java index 1c208b851..fc9e21913 100644 --- a/src/de/dhbwstuttgart/bytecode/signature/Signature.java +++ b/src/de/dhbwstuttgart/bytecode/signature/Signature.java @@ -61,7 +61,6 @@ public class Signature { private void createSignatureForFunN(LambdaExpression lambdaExpression, int numberOfParams) { -// sw.visitReturnType().visitTypeVariable("R"); sw.visitFormalTypeParameter("R"); // getBounds vom Return-Type sw.visitClassBound().visitClassType(Type.getInternalName(Object.class)); @@ -73,7 +72,6 @@ public class Signature { sw.visitClassBound().visitClassType(Type.getInternalName(Object.class)); sw.visitClassBound().visitEnd(); } -// sw.visitClassBound().visitEnd(); // TODO: prüfe ob Return-Type = void, sw.visitSuperclass().visitClassType(Type.getInternalName(Object.class));; sw.visitEnd(); @@ -136,7 +134,7 @@ public class Signature { RefTypeOrTPHOrWildcardOrGeneric r = resultSet.resolveType(t).resolvedType; sv.visitInterface().visitClassType(r.acceptTV(new TypeToSignature())); // sv.visitClassType(r.acceptTV(new TypeToSignature())); - System.out.println(r.getClass()+" Signature TPH: "+r.acceptTV(new TypeToSignature())); +// System.out.println(r.getClass()+" Signature TPH: "+r.acceptTV(new TypeToSignature())); break; default: if(!isParameterType) @@ -172,7 +170,7 @@ public class Signature { while(bItr.hasNext()) { RefTypeOrTPHOrWildcardOrGeneric b =bItr.next(); String boundDesc = b.acceptTV(new TypeToDescriptor()); - System.out.println("GetBounds: " + boundDesc); +// System.out.println("GetBounds: " + boundDesc); // Ensure that <...> extends java.lang.Object OR ... sw.visitClassBound().visitClassType(boundDesc); genAndBounds.put(g.getParsedName(), boundDesc); diff --git a/test/bytecode/ATest.java b/test/bytecode/ATest.java new file mode 100644 index 000000000..9865825ec --- /dev/null +++ b/test/bytecode/ATest.java @@ -0,0 +1,8 @@ +package bytecode; + +public class ATest extends JavaTXCompilerTest { + public ATest() { + fileName = "A"; + } + +} diff --git a/test/bytecode/DuMethod.jav b/test/bytecode/DuMethod.jav index b56f6c55c..3898a7baf 100644 --- a/test/bytecode/DuMethod.jav +++ b/test/bytecode/DuMethod.jav @@ -1,7 +1,7 @@ public class DuMethod{ method(a){ - return a; + return a+a; } method(a){ diff --git a/test/bytecode/Example.jav b/test/bytecode/Example.jav new file mode 100644 index 000000000..451803eaa --- /dev/null +++ b/test/bytecode/Example.jav @@ -0,0 +1,7 @@ +public class Example { + + public m() { + String x = "X"; + return x; + } +} \ No newline at end of file diff --git a/test/bytecode/Import.jav b/test/bytecode/Import.jav new file mode 100644 index 000000000..c658568f8 --- /dev/null +++ b/test/bytecode/Import.jav @@ -0,0 +1,8 @@ +import java.util.Vector; + +class Import { + void methode(){ + Vector v = new Vector<>(); + v.add("X"); + } +} \ No newline at end of file diff --git a/test/bytecode/ImportTest.java b/test/bytecode/ImportTest.java new file mode 100644 index 000000000..b7244e15a --- /dev/null +++ b/test/bytecode/ImportTest.java @@ -0,0 +1,7 @@ +package bytecode; + +public class ImportTest extends JavaTXCompilerTest{ + public ImportTest() { + this.fileName = "Import"; + } +} diff --git a/test/bytecode/JavaTXCompilerTest.java b/test/bytecode/JavaTXCompilerTest.java index f017e23e6..2f8329629 100644 --- a/test/bytecode/JavaTXCompilerTest.java +++ b/test/bytecode/JavaTXCompilerTest.java @@ -34,17 +34,16 @@ public class JavaTXCompilerTest { filesToTest.add(new File(rootDirectory+fileName+".jav")); System.out.println(rootDirectory+fileName+".jav"); JavaTXCompiler compiler = new JavaTXCompiler(filesToTest); - System.out.println("test"); for(File f : filesToTest){ String content = readFile(f.getPath(), StandardCharsets.UTF_8); List typeinferenceResult = compiler.typeInference(); HashMap bytecode = this.getBytecode(compiler.sourceFiles.get(f), typeinferenceResult.get(0)); - for(ResultPair ep : typeinferenceResult.get(0).results) { - System.out.println(ep.getLeft() + " ->" + ep.getRight()); - } +// for(ResultPair ep : typeinferenceResult.get(0).results) { +// System.out.println(ep.getLeft() + " ->" + ep.getRight()); +// } - String name = ""; + String name; int pos = f.getName().lastIndexOf("."); if(pos != -1) { name = f.getName().substring(0, pos); @@ -67,8 +66,8 @@ public class JavaTXCompilerTest { for(String name : classFiles.keySet()) { byte[] bytecode = classFiles.get(name); try { - System.out.println("generating"+name+ ".class file"); - output = new FileOutputStream(new File(System.getProperty("user.dir") + "/testBytecode/generatedBC/" +name+".class")); + System.out.println("generating "+name+ ".class file ..."); + output = new FileOutputStream(new File(System.getProperty("user.dir") + "/testBytecode/generatedBC/examples/" +name+".class")); output.write(bytecode); output.close(); System.out.println(name+".class file generated"); diff --git a/test/bytecode/LamAssign.jav b/test/bytecode/LamAssign.jav index 8f42d5eae..e522bd3b0 100644 --- a/test/bytecode/LamAssign.jav +++ b/test/bytecode/LamAssign.jav @@ -7,7 +7,3 @@ class LamAssign { return lam1; } } - -//interface Fun1{ -// A apply(B b); -//} diff --git a/test/bytecode/OverlaodGen.jav b/test/bytecode/OverlaodGen.jav new file mode 100644 index 000000000..d5946496a --- /dev/null +++ b/test/bytecode/OverlaodGen.jav @@ -0,0 +1,11 @@ +import java.util.Vector; + +class OverlaodGen { + void method(Vector v) { +// Integer i = v.get(0); + } + + void method(Vector v) { +// String s = v.get(0); + } +} \ No newline at end of file diff --git a/test/bytecode/OverlaodGenTest.java b/test/bytecode/OverlaodGenTest.java new file mode 100644 index 000000000..72bde4f99 --- /dev/null +++ b/test/bytecode/OverlaodGenTest.java @@ -0,0 +1,7 @@ +package bytecode; + +public class OverlaodGenTest extends JavaTXCompilerTest { + public OverlaodGenTest() { + this.fileName = "OverlaodGen"; + } +}