From 8bda352bc92d888200eefcbc5776a4afc663dcc1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Enrico=20Schr=C3=B6dter?= Date: Mon, 25 Apr 2016 14:58:52 +0200 Subject: [PATCH 1/7] - Method refactored --- src/de/dhbwstuttgart/syntaxtree/Method.java | 68 ++++++++++----------- 1 file changed, 32 insertions(+), 36 deletions(-) diff --git a/src/de/dhbwstuttgart/syntaxtree/Method.java b/src/de/dhbwstuttgart/syntaxtree/Method.java index 9a59788a..3dcaf42a 100755 --- a/src/de/dhbwstuttgart/syntaxtree/Method.java +++ b/src/de/dhbwstuttgart/syntaxtree/Method.java @@ -613,45 +613,41 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable DHBWInstructionFactory _factory = cg.getInstructionFactory(); for(TypeinferenceResultSet t: typeInterferenceResults){ - DHBWConstantPoolGen _cp = cg.getConstantPool(); - InstructionList il = new InstructionList(); - Class parentClass = this.getParentClass(); - - //Die Argumentliste generieren: - org.apache.commons.bcel6.generic.Type[] argumentTypes = org.apache.commons.bcel6.generic.Type.NO_ARGS; - String[] argumentNames = new String[]{}; - if(this.parameterlist != null && this.parameterlist.size() > 0){ - argumentTypes = new org.apache.commons.bcel6.generic.Type[this.parameterlist.size()]; - argumentNames = new String[this.parameterlist.size()]; - int i = 0; - for(FormalParameter parameter : this.parameterlist){ - argumentTypes[i] = parameter.getType().getBytecodeType(cg, t); - argumentNames[i] = parameter.getIdentifier(); - - - _factory.getStoreIndex(parameter.getIdentifier()); - - i++; - } - } - - String nameAndSignature = get_Method_Name()+Arrays.toString(argumentTypes); - - Logger.getLogger("nameAndSignature").error(nameAndSignature, Section.CODEGEN); - + addMethodToClassGenerator(cg, _factory, t); + } + } - short constants = Constants.ACC_PUBLIC; //Per Definition ist jede Methode public - if(this.modifiers != null && this.modifiers.includesModifier(new Static())) constants += Constants.ACC_STATIC; - - Type returnType = this.getType(); + private void addMethodToClassGenerator(ClassGenerator cg, DHBWInstructionFactory _factory, TypeinferenceResultSet t) { + DHBWConstantPoolGen _cp = cg.getConstantPool(); + InstructionList il = new InstructionList(); + + org.apache.commons.bcel6.generic.Type[] argumentTypes = org.apache.commons.bcel6.generic.Type.NO_ARGS; + String[] argumentNames = new String[]{}; + if(this.parameterlist != null && this.parameterlist.size() > 0){ + generateArgumentList(argumentTypes, argumentNames, cg, _factory, t); + } + + short constants = Constants.ACC_PUBLIC; + if(this.modifiers != null && this.modifiers.includesModifier(new Static())) constants += Constants.ACC_STATIC; + + Type returnType = this.getType(); + + MethodGenerator method = new MethodGenerator(constants, returnType.getBytecodeType(cg, t), argumentTypes , argumentNames, this.get_Method_Name(), getParentClass().name, il, _cp); + + cg.addMethod(method.createMethod(cg, getParameterList(), returnType, get_Block(), t)); + } + + private void generateArgumentList(org.apache.commons.bcel6.generic.Type[] argumentTypes, String[] argumentNames, ClassGenerator cg, DHBWInstructionFactory _factory, TypeinferenceResultSet t) { + argumentTypes = new org.apache.commons.bcel6.generic.Type[this.parameterlist.size()]; + argumentNames = new String[this.parameterlist.size()]; + int i = 0; + for(FormalParameter parameter : this.parameterlist){ + argumentTypes[i] = parameter.getType().getBytecodeType(cg, t); + argumentNames[i] = parameter.getIdentifier(); - //Methode generieren: - MethodGenerator method = new MethodGenerator(constants, returnType.getBytecodeType(cg, t), argumentTypes , argumentNames, this.get_Method_Name(), parentClass.name, il, _cp); + _factory.getStoreIndex(parameter.getIdentifier()); - //Methode generieren und anfügen: - cg.addMethod(method.createMethod(cg, getParameterList(), returnType, get_Block(), t)); - - Logger.getLogger("createMethod").debug(this.toString(), Section.CODEGEN); + i++; } } } From 362be98c30b33722d1eec8bed13e46bc8183c2aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Enrico=20Schr=C3=B6dter?= Date: Tue, 26 Apr 2016 15:52:22 +0200 Subject: [PATCH 2/7] =?UTF-8?q?-Test=20f=C3=BCr=20Stackmaptable=20ifstatem?= =?UTF-8?q?ent=20verbessert=20-=20IFStatementCreator=20erstellt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BCEL/bcelifier/IfStatement.java | 12 ++++ BCEL/bcelifier/IfStatementCreator.java | 71 +++++++++++++++++++ BCEL/bcelifier/JavaToBCEL.java | 20 +++--- test/bytecode/stackmaptable/IfStatement.jav | 10 +-- .../stackmaptable/IfStatementTest.java | 20 ++++-- 5 files changed, 112 insertions(+), 21 deletions(-) create mode 100644 BCEL/bcelifier/IfStatement.java create mode 100644 BCEL/bcelifier/IfStatementCreator.java diff --git a/BCEL/bcelifier/IfStatement.java b/BCEL/bcelifier/IfStatement.java new file mode 100644 index 00000000..8f16e0d4 --- /dev/null +++ b/BCEL/bcelifier/IfStatement.java @@ -0,0 +1,12 @@ +package bcelifier; + +class IfStatement{ + Integer methode(Boolean b){ + if(b){ + return 1; + }else{ + return 2; + } + } + +} \ No newline at end of file diff --git a/BCEL/bcelifier/IfStatementCreator.java b/BCEL/bcelifier/IfStatementCreator.java new file mode 100644 index 00000000..058ca8e9 --- /dev/null +++ b/BCEL/bcelifier/IfStatementCreator.java @@ -0,0 +1,71 @@ +package bcelifier; + +import org.apache.commons.bcel6.generic.*; + +import de.dhbwstuttgart.syntaxtree.type.RefType; +import de.dhbwstuttgart.bytecode.ClassGenerator; +import de.dhbwstuttgart.bytecode.MethodGenerator; +import de.dhbwstuttgart.typeinference.TypeinferenceResults; + +import org.apache.commons.bcel6.*; +import java.io.*; + +public class IfStatementCreator { + private InstructionFactory _factory; + private ConstantPoolGen _cp; + private ClassGen _cg; + + public IfStatementCreator() { + + TypeinferenceResults typeinferenceResults = null; + _cg = new ClassGenerator("bcelifier.IfStatement", new RefType("java.lang.Object", null, 0), "IfStatement.java", Const.ACC_SUPER, new String[] { }, typeinferenceResults); + + _cp = _cg.getConstantPool(); + _factory = new InstructionFactory(_cg, _cp); + } + + public void create(OutputStream out) throws IOException { + createMethod_0(); + createMethod_1(); + _cg.getJavaClass().dump(out); + } + + private void createMethod_0() { + InstructionList il = new InstructionList(); + MethodGen method = new MethodGen(0, Type.VOID, Type.NO_ARGS, new String[] { }, "", "bcelifier.IfStatement", il, _cp); + + InstructionHandle ih_0 = il.append(_factory.createLoad(Type.OBJECT, 0)); + il.append(_factory.createInvoke("java.lang.Object", "", Type.VOID, Type.NO_ARGS, Const.INVOKESPECIAL)); + InstructionHandle ih_4 = il.append(_factory.createReturn(Type.VOID)); + method.setMaxStack(); + method.setMaxLocals(); + _cg.addMethod(method.getMethod()); + } + + private void createMethod_1() { + InstructionList il = new InstructionList(); + MethodGen method = new MethodGenerator(0, new ObjectType("java.lang.Integer"), new Type[] { new ObjectType("java.lang.Boolean") }, new String[] { "arg0" }, "methode", "bcelifier.IfStatement", il, _cp); + + il.append(InstructionFactory.createLoad(Type.OBJECT, 1)); + il.append(_factory.createInvoke("java.lang.Boolean", "booleanValue", Type.BOOLEAN, Type.NO_ARGS, Const.INVOKEVIRTUAL)); + BranchInstruction ifeq_4 = InstructionFactory.createBranchInstruction(Const.IFEQ, null); + il.append(ifeq_4); + il.append(new PUSH(_cp, 1)); + il.append(_factory.createInvoke("java.lang.Integer", "valueOf", new ObjectType("java.lang.Integer"), new Type[] { Type.INT }, Const.INVOKESTATIC)); + il.append(InstructionFactory.createReturn(Type.OBJECT)); + InstructionHandle ih_12 = il.append(new PUSH(_cp, 2)); + il.append(_factory.createInvoke("java.lang.Integer", "valueOf", new ObjectType("java.lang.Integer"), new Type[] { Type.INT }, Const.INVOKESTATIC)); + il.append(InstructionFactory.createReturn(Type.OBJECT)); + ifeq_4.setTarget(ih_12); + method.setMaxStack(); + method.setMaxLocals(); + _cg.addMethod(method.getMethod()); + } + + public static void main(String[] args) throws Exception { + bcelifier.IfStatementCreator creator = new bcelifier.IfStatementCreator(); + creator.create(new FileOutputStream("bcelifier.IfStatement.class")); + + System.out.println("bcelifier.IfStatement.class"); + } +} diff --git a/BCEL/bcelifier/JavaToBCEL.java b/BCEL/bcelifier/JavaToBCEL.java index 2c87bc2f..0d162b00 100644 --- a/BCEL/bcelifier/JavaToBCEL.java +++ b/BCEL/bcelifier/JavaToBCEL.java @@ -24,16 +24,16 @@ public class JavaToBCEL { public JavaToBCEL(){ try { //new BCELifier(new ClassParser(rootDirectory+"Lambda1.class").parse(), new FileOutputStream(new File(rootDirectory+"Lambda1Creator.java"))).start(); - new BCELifier(new ClassParser(rootDirectory+"This.class").parse(), new FileOutputStream(new File(rootDirectory+"ThisCreator.java"))).start(); - new BCELifier(new ClassParser(rootDirectory+"IntLiteral.class").parse(), new FileOutputStream(new File(rootDirectory+"IntLiteralCreator.java"))).start(); - new BCELifier(new ClassParser(rootDirectory+"MethodCall.class").parse(), new FileOutputStream(new File(rootDirectory+"MethodCallCreator.java"))).start(); - new BCELifier(new ClassParser(rootDirectory+"FieldDeclaration.class").parse(), new FileOutputStream(new File(rootDirectory+"FieldDeclarationCreator.java"))).start(); - new BCELifier(new ClassParser(rootDirectory+"Null.class").parse(), new FileOutputStream(new File(rootDirectory+"NullCreator.java"))).start(); - new BCELifier(new ClassParser(rootDirectory+"LocalVarAccess.class").parse(), new FileOutputStream(new File(rootDirectory+"LocalVarAccessCreator.java"))).start(); - new BCELifier(new ClassParser(rootDirectory+"Wildcard.class").parse(), new FileOutputStream(new File(rootDirectory+"WildcardCreator.java"))).start(); - new BCELifier(new ClassParser(rootDirectory+"BooleanValue.class").parse(), new FileOutputStream(new File(rootDirectory+"BooleanValueCreator.java"))).start(); - new BCELifier(new ClassParser(rootDirectory+"NewClass.class").parse(), new FileOutputStream(new File(rootDirectory+"NewClassCreator.java"))).start(); - + //new BCELifier(new ClassParser(rootDirectory+"This.class").parse(), new FileOutputStream(new File(rootDirectory+"ThisCreator.java"))).start(); + //new BCELifier(new ClassParser(rootDirectory+"IntLiteral.class").parse(), new FileOutputStream(new File(rootDirectory+"IntLiteralCreator.java"))).start(); + //new BCELifier(new ClassParser(rootDirectory+"MethodCall.class").parse(), new FileOutputStream(new File(rootDirectory+"MethodCallCreator.java"))).start(); + //new BCELifier(new ClassParser(rootDirectory+"FieldDeclaration.class").parse(), new FileOutputStream(new File(rootDirectory+"FieldDeclarationCreator.java"))).start(); + //new BCELifier(new ClassParser(rootDirectory+"Null.class").parse(), new FileOutputStream(new File(rootDirectory+"NullCreator.java"))).start(); + //new BCELifier(new ClassParser(rootDirectory+"LocalVarAccess.class").parse(), new FileOutputStream(new File(rootDirectory+"LocalVarAccessCreator.java"))).start(); + //new BCELifier(new ClassParser(rootDirectory+"Wildcard.class").parse(), new FileOutputStream(new File(rootDirectory+"WildcardCreator.java"))).start(); + //new BCELifier(new ClassParser(rootDirectory+"BooleanValue.class").parse(), new FileOutputStream(new File(rootDirectory+"BooleanValueCreator.java"))).start(); + //new BCELifier(new ClassParser(rootDirectory+"NewClass.class").parse(), new FileOutputStream(new File(rootDirectory+"NewClassCreator.java"))).start(); + new BCELifier(new ClassParser(rootDirectory+"IfStatement.class").parse(), new FileOutputStream(new File(rootDirectory+"IfStatementCreator.java"))).start(); } catch (ClassFormatException | IOException e) { e.printStackTrace(); } diff --git a/test/bytecode/stackmaptable/IfStatement.jav b/test/bytecode/stackmaptable/IfStatement.jav index ba78a2be..1451af17 100644 --- a/test/bytecode/stackmaptable/IfStatement.jav +++ b/test/bytecode/stackmaptable/IfStatement.jav @@ -1,10 +1,10 @@ class IfStatement{ -Integer methode(Boolean b){ - if(b){ - return 1; + Integer methode(Boolean b){ + if(b){ + return 1; }else{ - return 2; + return 2; } -} + } } \ No newline at end of file diff --git a/test/bytecode/stackmaptable/IfStatementTest.java b/test/bytecode/stackmaptable/IfStatementTest.java index 18a0a046..7c10e42b 100644 --- a/test/bytecode/stackmaptable/IfStatementTest.java +++ b/test/bytecode/stackmaptable/IfStatementTest.java @@ -3,14 +3,22 @@ package bytecode.stackmaptable; import org.junit.Test; import bytecode.SingleClassTester; +import bytecode.SourceFileBytecodeTest; -public class IfStatementTest { - public final static String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/stackmaptable/"; - public final static String testFile = "IfStatement.jav"; - public final static String outputFile = "IfStatement.class"; +public class IfStatementTest extends SourceFileBytecodeTest{ + @Override + protected void init() { + testName = "IfStatement"; + rootDirectory = System.getProperty("user.dir")+"/test/bytecode/stackmaptable/"; + } @Test - public void test() { - SingleClassTester.compileToBytecode(rootDirectory+testFile, rootDirectory); + public void testConstruct() throws Exception{ + ClassLoader classLoader = getClassLoader(); + + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + assertTrue(true); } } From 5ac19d7a5950ff326c83221d8b225f13c0f22128 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Enrico=20Schr=C3=B6dter?= Date: Tue, 26 Apr 2016 16:15:53 +0200 Subject: [PATCH 3/7] - args_size bugfix --- BCEL/bcelifier/IfStatementCreator.java | 4 ++-- .../bytecode/DHBWInstructionFactory.java | 4 ++-- src/de/dhbwstuttgart/syntaxtree/Method.java | 21 ++++++++----------- 3 files changed, 13 insertions(+), 16 deletions(-) diff --git a/BCEL/bcelifier/IfStatementCreator.java b/BCEL/bcelifier/IfStatementCreator.java index 058ca8e9..88b43e39 100644 --- a/BCEL/bcelifier/IfStatementCreator.java +++ b/BCEL/bcelifier/IfStatementCreator.java @@ -13,7 +13,7 @@ import java.io.*; public class IfStatementCreator { private InstructionFactory _factory; private ConstantPoolGen _cp; - private ClassGen _cg; + private ClassGenerator _cg; public IfStatementCreator() { @@ -32,7 +32,7 @@ public class IfStatementCreator { private void createMethod_0() { InstructionList il = new InstructionList(); - MethodGen method = new MethodGen(0, Type.VOID, Type.NO_ARGS, new String[] { }, "", "bcelifier.IfStatement", il, _cp); + MethodGen method = new MethodGenerator(0, Type.VOID, new Type[] { new ObjectType("java.lang.Boolean") }, new String[] { "arg0" }, "", "bcelifier.IfStatement", il, _cp); InstructionHandle ih_0 = il.append(_factory.createLoad(Type.OBJECT, 0)); il.append(_factory.createInvoke("java.lang.Object", "", Type.VOID, Type.NO_ARGS, Const.INVOKESPECIAL)); diff --git a/src/de/dhbwstuttgart/bytecode/DHBWInstructionFactory.java b/src/de/dhbwstuttgart/bytecode/DHBWInstructionFactory.java index 6cf24c88..8b4b9929 100644 --- a/src/de/dhbwstuttgart/bytecode/DHBWInstructionFactory.java +++ b/src/de/dhbwstuttgart/bytecode/DHBWInstructionFactory.java @@ -139,7 +139,7 @@ public class DHBWInstructionFactory extends InstructionFactory{ return new INVOKEDYNAMIC(index); } - public LocalVariableInstruction createLoad(org.apache.commons.bcel6.generic.Type bytecodeType, String variableName) { + public static LocalVariableInstruction createLoad(org.apache.commons.bcel6.generic.Type bytecodeType, String variableName) { return InstructionFactory.createLoad(bytecodeType, getStoreIndex(variableName)); } @@ -147,7 +147,7 @@ public class DHBWInstructionFactory extends InstructionFactory{ return InstructionFactory.createStore(bytecodeType, getStoreIndex(variableName)); } - public Integer getStoreIndex(String variableName) { + public static Integer getStoreIndex(String variableName) { if(storeIndexes.get(variableName) == null){ Integer index = storeIndexes.size()+1; storeIndexes.put(variableName, index); diff --git a/src/de/dhbwstuttgart/syntaxtree/Method.java b/src/de/dhbwstuttgart/syntaxtree/Method.java index 3dcaf42a..56539df6 100755 --- a/src/de/dhbwstuttgart/syntaxtree/Method.java +++ b/src/de/dhbwstuttgart/syntaxtree/Method.java @@ -1,6 +1,7 @@ // ino.module.Method.8564.package package de.dhbwstuttgart.syntaxtree; +import java.util.ArrayList; import java.util.Arrays; // ino.end // ino.module.Method.8564.import @@ -620,9 +621,10 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable private void addMethodToClassGenerator(ClassGenerator cg, DHBWInstructionFactory _factory, TypeinferenceResultSet t) { DHBWConstantPoolGen _cp = cg.getConstantPool(); InstructionList il = new InstructionList(); - - org.apache.commons.bcel6.generic.Type[] argumentTypes = org.apache.commons.bcel6.generic.Type.NO_ARGS; - String[] argumentNames = new String[]{}; + + ArrayList argumentTypes = new ArrayList(); + ArrayList argumentNames = new ArrayList(); + if(this.parameterlist != null && this.parameterlist.size() > 0){ generateArgumentList(argumentTypes, argumentNames, cg, _factory, t); } @@ -632,22 +634,17 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable Type returnType = this.getType(); - MethodGenerator method = new MethodGenerator(constants, returnType.getBytecodeType(cg, t), argumentTypes , argumentNames, this.get_Method_Name(), getParentClass().name, il, _cp); + MethodGenerator method = new MethodGenerator(constants, returnType.getBytecodeType(cg, t), argumentTypes.toArray(new org.apache.commons.bcel6.generic.Type[parameterlist.size()]) , argumentNames.toArray(new String[parameterlist.size()]), this.get_Method_Name(), getParentClass().name, il, _cp); cg.addMethod(method.createMethod(cg, getParameterList(), returnType, get_Block(), t)); } - private void generateArgumentList(org.apache.commons.bcel6.generic.Type[] argumentTypes, String[] argumentNames, ClassGenerator cg, DHBWInstructionFactory _factory, TypeinferenceResultSet t) { - argumentTypes = new org.apache.commons.bcel6.generic.Type[this.parameterlist.size()]; - argumentNames = new String[this.parameterlist.size()]; - int i = 0; + private void generateArgumentList(ArrayList argumentTypes, ArrayList argumentNames, ClassGenerator cg, DHBWInstructionFactory _factory, TypeinferenceResultSet t) { for(FormalParameter parameter : this.parameterlist){ - argumentTypes[i] = parameter.getType().getBytecodeType(cg, t); - argumentNames[i] = parameter.getIdentifier(); + argumentTypes.add(parameter.getType().getBytecodeType(cg, t)); + argumentNames.add(parameter.getIdentifier()); _factory.getStoreIndex(parameter.getIdentifier()); - - i++; } } } From b3e13d09b924d169491d1f7cf2f6ac505a2187c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Enrico=20Schr=C3=B6dter?= Date: Wed, 27 Apr 2016 15:08:17 +0200 Subject: [PATCH 4/7] =?UTF-8?q?-=20Alle=20Operatoren=20implementiert=20-?= =?UTF-8?q?=20Tests=20f=C3=BCr=20Sub,=20Mul,=20Div?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../syntaxtree/operator/AddOp.java | 52 +++++++++++++++++- .../syntaxtree/operator/DivideOp.java | 10 ++-- .../syntaxtree/operator/EqualOp.java | 32 +---------- .../syntaxtree/operator/GreaterEquOp.java | 8 +++ .../syntaxtree/operator/GreaterOp.java | 8 +++ .../syntaxtree/operator/LessEquOp.java | 8 +++ .../syntaxtree/operator/LessOp.java | 7 +++ .../syntaxtree/operator/MinusOp.java | 8 ++- .../syntaxtree/operator/ModuloOp.java | 8 +++ .../syntaxtree/operator/MulOp.java | 53 ++++++++++++++++++- .../syntaxtree/operator/NotEqualOp.java | 17 +++--- .../syntaxtree/operator/Operator.java | 9 ++++ .../syntaxtree/operator/PlusOp.java | 49 +---------------- .../syntaxtree/operator/RelOp.java | 51 +++++++++++++++++- .../syntaxtree/operator/TimesOp.java | 8 +++ test/bytecode/operators/DivOperator.jav | 5 ++ test/bytecode/operators/DivOperatorTest.java | 53 +++++++++++++++++++ test/bytecode/operators/MulOperator.jav | 5 ++ test/bytecode/operators/MulOperatorTest.java | 53 +++++++++++++++++++ test/bytecode/operators/SubOperator.jav | 5 ++ test/bytecode/operators/SubOperatorTest.java | 53 +++++++++++++++++++ 21 files changed, 408 insertions(+), 94 deletions(-) create mode 100644 test/bytecode/operators/DivOperator.jav create mode 100644 test/bytecode/operators/DivOperatorTest.java create mode 100644 test/bytecode/operators/MulOperator.jav create mode 100644 test/bytecode/operators/MulOperatorTest.java create mode 100644 test/bytecode/operators/SubOperator.jav create mode 100644 test/bytecode/operators/SubOperatorTest.java diff --git a/src/de/dhbwstuttgart/syntaxtree/operator/AddOp.java b/src/de/dhbwstuttgart/syntaxtree/operator/AddOp.java index c9e95ee3..ac4ac40a 100755 --- a/src/de/dhbwstuttgart/syntaxtree/operator/AddOp.java +++ b/src/de/dhbwstuttgart/syntaxtree/operator/AddOp.java @@ -5,8 +5,17 @@ package de.dhbwstuttgart.syntaxtree.operator; import java.util.HashMap; import java.util.Hashtable; import java.util.Iterator; -import de.dhbwstuttgart.typeinference.Menge; +import org.apache.commons.bcel6.Constants; +import org.apache.commons.bcel6.generic.ArithmeticInstruction; +import org.apache.commons.bcel6.generic.IADD; +import org.apache.commons.bcel6.generic.InstructionList; +import org.apache.commons.bcel6.generic.InvokeInstruction; +import org.apache.commons.bcel6.generic.ObjectType; + +import de.dhbwstuttgart.typeinference.Menge; +import de.dhbwstuttgart.bytecode.ClassGenerator; +import de.dhbwstuttgart.bytecode.DHBWInstructionFactory; import de.dhbwstuttgart.myexception.CTypeReconstructionException; import de.dhbwstuttgart.myexception.JVMCodeException; import de.dhbwstuttgart.syntaxtree.statement.Binary; @@ -16,8 +25,10 @@ import de.dhbwstuttgart.syntaxtree.type.Type; import de.dhbwstuttgart.typeinference.ConstraintsSet; import de.dhbwstuttgart.typeinference.Pair; import de.dhbwstuttgart.typeinference.SingleConstraint; +import de.dhbwstuttgart.typeinference.TypeinferenceResultSet; import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions; import de.dhbwstuttgart.typeinference.exceptions.DebugException; +import de.dhbwstuttgart.typeinference.exceptions.NotImplementedException; import de.dhbwstuttgart.typeinference.unify.Unify; @@ -62,5 +73,44 @@ public abstract class AddOp extends Operator return ret; } + @Override + public InstructionList genByteCode(ClassGenerator _cg, TypeinferenceResultSet rs, Binary operator) { + // TODO Plus Operator ist bis jetzt nur für Integer implementiert + /* + 0: aload_1 + 1: invokevirtual #2 // Method java/lang/Integer.intValue:()I + 4: aload_1 + 5: invokevirtual #2 // Method java/lang/Integer.intValue:()I + 8: iadd + 9: invokestatic #3 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer; + 12: areturn + */ + DHBWInstructionFactory _factory = _cg.getInstructionFactory(); + + String returnType = getReturnType(operator.get_Expr1(), operator.get_Expr2()); + + InstructionList il = getInstructionListForOperand(_cg, rs, operator.get_Expr1(), returnType); + + il.append(getInstructionListForOperand(_cg, rs, operator.get_Expr2(), returnType)); + + il.append(getOperator(returnType)); + + il.append(convertValueToObject(_factory, returnType)); + return il; + } + + private String getReturnType(Expr expr1, Expr expr2) { + return "java.lang.Integer"; + } + + abstract ArithmeticInstruction getOperator(String returnType); + + private InvokeInstruction convertValueToObject(DHBWInstructionFactory _factory, String returnType) { + if(returnType.equals("java.lang.Integer")){ + return _factory.createInvoke("java.lang.Integer", "valueOf", new ObjectType("java.lang.Integer"), new org.apache.commons.bcel6.generic.Type[] {org.apache.commons.bcel6.generic.Type.INT}, Constants.INVOKESTATIC); + }else{ + throw new NotImplementedException(); + } + } } // ino.end diff --git a/src/de/dhbwstuttgart/syntaxtree/operator/DivideOp.java b/src/de/dhbwstuttgart/syntaxtree/operator/DivideOp.java index 4442e7a9..850d2ba0 100755 --- a/src/de/dhbwstuttgart/syntaxtree/operator/DivideOp.java +++ b/src/de/dhbwstuttgart/syntaxtree/operator/DivideOp.java @@ -4,6 +4,9 @@ package de.dhbwstuttgart.syntaxtree.operator; // ino.module.DivideOp.8596.import import de.dhbwstuttgart.typeinference.Menge; +import org.apache.commons.bcel6.generic.ArithmeticInstruction; +import org.apache.commons.bcel6.generic.IDIV; + import de.dhbwstuttgart.myexception.JVMCodeException; import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode; import de.dhbwstuttgart.syntaxtree.statement.Binary; @@ -26,8 +29,9 @@ public class DivideOp extends MulOp } // ino.end - - - + @Override + ArithmeticInstruction getOperator(String returnType) { + return new IDIV(); + } } // ino.end diff --git a/src/de/dhbwstuttgart/syntaxtree/operator/EqualOp.java b/src/de/dhbwstuttgart/syntaxtree/operator/EqualOp.java index 89285c6b..063be628 100755 --- a/src/de/dhbwstuttgart/syntaxtree/operator/EqualOp.java +++ b/src/de/dhbwstuttgart/syntaxtree/operator/EqualOp.java @@ -47,36 +47,8 @@ public class EqualOp extends RelOp // ino.end @Override - public InstructionList genByteCode(ClassGenerator _cg, TypeinferenceResultSet rs, Binary operator) { - DHBWInstructionFactory _factory = _cg.getInstructionFactory(); - - InstructionList linkeSeite = operator.expr1.genByteCode(_cg, rs); - linkeSeite.append(_factory.createInvoke("java.lang.Integer", "intValue", org.apache.commons.bcel6.generic.Type.INT, new org.apache.commons.bcel6.generic.Type[] {}, Constants.INVOKEVIRTUAL)); - - InstructionList rechteSeite = operator.expr2.genByteCode(_cg, rs); - rechteSeite.append(_factory.createInvoke("java.lang.Integer", "intValue", org.apache.commons.bcel6.generic.Type.INT, new org.apache.commons.bcel6.generic.Type[] {}, Constants.INVOKEVIRTUAL)); - - - if(operator.getReturnType().getName().equals(new JavaClassName("String"))){ - throw new TypeinferenceException("Zeichenketten zusammenfügen ist noch nicht unterstützt",this); - } - - linkeSeite.append(rechteSeite); - - //TODO: bytecode (Bis jetzt wird jeder Condition als EQUALS behandelt) - //TODO: bytecode autoboxing - - BranchInstruction if_icmpneInstruction = new IF_ICMPNE(null); - linkeSeite.append(if_icmpneInstruction); - linkeSeite.append(InstructionConstants.ICONST_1); - - BranchInstruction gotoInstruction = new GOTO(null); - - linkeSeite.append(gotoInstruction); - if_icmpneInstruction.setTarget(linkeSeite.append(InstructionConstants.ICONST_0)); - gotoInstruction.setTarget(linkeSeite.append(_factory.createInvoke("java.lang.Boolean", "valueOf", new ObjectType("java.lang.Boolean"), new org.apache.commons.bcel6.generic.Type[] {org.apache.commons.bcel6.generic.Type.BOOLEAN}, Constants.INVOKESTATIC))); - - return linkeSeite; + BranchInstruction getOperator() { + return new IF_ICMPNE(null); } } diff --git a/src/de/dhbwstuttgart/syntaxtree/operator/GreaterEquOp.java b/src/de/dhbwstuttgart/syntaxtree/operator/GreaterEquOp.java index a01e1285..588c2271 100755 --- a/src/de/dhbwstuttgart/syntaxtree/operator/GreaterEquOp.java +++ b/src/de/dhbwstuttgart/syntaxtree/operator/GreaterEquOp.java @@ -4,6 +4,9 @@ package de.dhbwstuttgart.syntaxtree.operator; // ino.module.GreaterEquOp.8598.import import de.dhbwstuttgart.typeinference.Menge; +import org.apache.commons.bcel6.generic.BranchInstruction; +import org.apache.commons.bcel6.generic.IF_ICMPLT; + import de.dhbwstuttgart.myexception.JVMCodeException; import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode; import de.dhbwstuttgart.syntaxtree.statement.Binary; @@ -25,6 +28,11 @@ public class GreaterEquOp extends RelOp super(offset,variableLength); } // ino.end + + @Override + BranchInstruction getOperator() { + return new IF_ICMPLT(null); + } } // ino.end diff --git a/src/de/dhbwstuttgart/syntaxtree/operator/GreaterOp.java b/src/de/dhbwstuttgart/syntaxtree/operator/GreaterOp.java index 97a66824..f6b037db 100755 --- a/src/de/dhbwstuttgart/syntaxtree/operator/GreaterOp.java +++ b/src/de/dhbwstuttgart/syntaxtree/operator/GreaterOp.java @@ -4,6 +4,9 @@ package de.dhbwstuttgart.syntaxtree.operator; // ino.module.GreaterOp.8599.import import de.dhbwstuttgart.typeinference.Menge; +import org.apache.commons.bcel6.generic.BranchInstruction; +import org.apache.commons.bcel6.generic.IF_ICMPLE; + import de.dhbwstuttgart.myexception.JVMCodeException; import de.dhbwstuttgart.syntaxtree.statement.Binary; import de.dhbwstuttgart.syntaxtree.statement.Expr; @@ -25,5 +28,10 @@ public class GreaterOp extends RelOp } // ino.end + @Override + BranchInstruction getOperator() { + return new IF_ICMPLE(null); + } + } // ino.end diff --git a/src/de/dhbwstuttgart/syntaxtree/operator/LessEquOp.java b/src/de/dhbwstuttgart/syntaxtree/operator/LessEquOp.java index cff4e504..7a60fa49 100755 --- a/src/de/dhbwstuttgart/syntaxtree/operator/LessEquOp.java +++ b/src/de/dhbwstuttgart/syntaxtree/operator/LessEquOp.java @@ -4,6 +4,9 @@ package de.dhbwstuttgart.syntaxtree.operator; // ino.module.LessEquOp.8600.import import de.dhbwstuttgart.typeinference.Menge; +import org.apache.commons.bcel6.generic.BranchInstruction; +import org.apache.commons.bcel6.generic.IF_ICMPGT; + import de.dhbwstuttgart.myexception.JVMCodeException; import de.dhbwstuttgart.syntaxtree.statement.Binary; import de.dhbwstuttgart.syntaxtree.statement.Expr; @@ -25,5 +28,10 @@ public class LessEquOp extends RelOp } // ino.end + @Override + BranchInstruction getOperator() { + return new IF_ICMPGT(null); + } + } // ino.end diff --git a/src/de/dhbwstuttgart/syntaxtree/operator/LessOp.java b/src/de/dhbwstuttgart/syntaxtree/operator/LessOp.java index 2fcc7f11..5b6722b3 100755 --- a/src/de/dhbwstuttgart/syntaxtree/operator/LessOp.java +++ b/src/de/dhbwstuttgart/syntaxtree/operator/LessOp.java @@ -3,6 +3,8 @@ package de.dhbwstuttgart.syntaxtree.operator; // ino.end // ino.module.LessOp.8601.import import de.dhbwstuttgart.typeinference.Menge; +import org.apache.commons.bcel6.generic.BranchInstruction; +import org.apache.commons.bcel6.generic.IF_ICMPGE; import de.dhbwstuttgart.myexception.JVMCodeException; import de.dhbwstuttgart.syntaxtree.statement.Binary; @@ -25,5 +27,10 @@ public class LessOp extends RelOp } // ino.end + @Override + BranchInstruction getOperator() { + return new IF_ICMPGE(null); + } + } // ino.end diff --git a/src/de/dhbwstuttgart/syntaxtree/operator/MinusOp.java b/src/de/dhbwstuttgart/syntaxtree/operator/MinusOp.java index 3cd233ad..72313dd6 100755 --- a/src/de/dhbwstuttgart/syntaxtree/operator/MinusOp.java +++ b/src/de/dhbwstuttgart/syntaxtree/operator/MinusOp.java @@ -4,6 +4,10 @@ package de.dhbwstuttgart.syntaxtree.operator; // ino.module.MinusOp.8603.import import de.dhbwstuttgart.typeinference.Menge; +import org.apache.commons.bcel6.generic.ArithmeticInstruction; +import org.apache.commons.bcel6.generic.IADD; +import org.apache.commons.bcel6.generic.ISUB; + import de.dhbwstuttgart.myexception.JVMCodeException; import de.dhbwstuttgart.syntaxtree.statement.Binary; import de.dhbwstuttgart.syntaxtree.statement.Expr; @@ -25,6 +29,8 @@ public class MinusOp extends AddOp } // ino.end - + ArithmeticInstruction getOperator(String returnType) { + return new ISUB(); + } } // ino.end diff --git a/src/de/dhbwstuttgart/syntaxtree/operator/ModuloOp.java b/src/de/dhbwstuttgart/syntaxtree/operator/ModuloOp.java index 57465f01..d387958e 100755 --- a/src/de/dhbwstuttgart/syntaxtree/operator/ModuloOp.java +++ b/src/de/dhbwstuttgart/syntaxtree/operator/ModuloOp.java @@ -4,6 +4,9 @@ package de.dhbwstuttgart.syntaxtree.operator; // ino.module.ModuloOp.8604.import import de.dhbwstuttgart.typeinference.Menge; +import org.apache.commons.bcel6.generic.ArithmeticInstruction; +import org.apache.commons.bcel6.generic.IREM; + import de.dhbwstuttgart.myexception.JVMCodeException; import de.dhbwstuttgart.syntaxtree.statement.Binary; import de.dhbwstuttgart.syntaxtree.statement.Expr; @@ -25,5 +28,10 @@ public class ModuloOp extends MulOp } // ino.end + @Override + ArithmeticInstruction getOperator(String returnType) { + return new IREM(); + } + } // ino.end diff --git a/src/de/dhbwstuttgart/syntaxtree/operator/MulOp.java b/src/de/dhbwstuttgart/syntaxtree/operator/MulOp.java index d031b647..aa1c3b4e 100755 --- a/src/de/dhbwstuttgart/syntaxtree/operator/MulOp.java +++ b/src/de/dhbwstuttgart/syntaxtree/operator/MulOp.java @@ -6,15 +6,26 @@ package de.dhbwstuttgart.syntaxtree.operator; import java.util.HashMap; import java.util.Hashtable; import java.util.Iterator; -import de.dhbwstuttgart.typeinference.Menge; +import org.apache.commons.bcel6.Constants; +import org.apache.commons.bcel6.generic.ArithmeticInstruction; +import org.apache.commons.bcel6.generic.InstructionList; +import org.apache.commons.bcel6.generic.InvokeInstruction; +import org.apache.commons.bcel6.generic.ObjectType; + +import de.dhbwstuttgart.typeinference.Menge; +import de.dhbwstuttgart.bytecode.ClassGenerator; +import de.dhbwstuttgart.bytecode.DHBWInstructionFactory; import de.dhbwstuttgart.myexception.CTypeReconstructionException; import de.dhbwstuttgart.syntaxtree.statement.Binary; +import de.dhbwstuttgart.syntaxtree.statement.Expr; import de.dhbwstuttgart.syntaxtree.type.RefType; import de.dhbwstuttgart.syntaxtree.type.Type; import de.dhbwstuttgart.typeinference.Pair; +import de.dhbwstuttgart.typeinference.TypeinferenceResultSet; import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions; import de.dhbwstuttgart.typeinference.exceptions.DebugException; +import de.dhbwstuttgart.typeinference.exceptions.NotImplementedException; import de.dhbwstuttgart.typeinference.unify.Unify; // ino.class.MulOp.24231.declaration @@ -50,6 +61,44 @@ public abstract class MulOp extends Operator return ret; } - + @Override + public InstructionList genByteCode(ClassGenerator _cg, TypeinferenceResultSet rs, Binary operator) { + // TODO Plus Operator ist bis jetzt nur für Integer implementiert + /* + 0: aload_1 + 1: invokevirtual #2 // Method java/lang/Integer.intValue:()I + 4: aload_1 + 5: invokevirtual #2 // Method java/lang/Integer.intValue:()I + 8: imul + 9: invokestatic #3 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer; + 12: areturn + */ + DHBWInstructionFactory _factory = _cg.getInstructionFactory(); + + String returnType = getReturnType(operator.get_Expr1(), operator.get_Expr2()); + + InstructionList il = getInstructionListForOperand(_cg, rs, operator.get_Expr1(), returnType); + + il.append(getInstructionListForOperand(_cg, rs, operator.get_Expr2(), returnType)); + + il.append(getOperator(returnType)); + + il.append(convertValueToObject(_factory, returnType)); + return il; + } + + private String getReturnType(Expr expr1, Expr expr2) { + return "java.lang.Integer"; + } + + abstract ArithmeticInstruction getOperator(String returnType); + + private InvokeInstruction convertValueToObject(DHBWInstructionFactory _factory, String returnType) { + if(returnType.equals("java.lang.Integer")){ + return _factory.createInvoke("java.lang.Integer", "valueOf", new ObjectType("java.lang.Integer"), new org.apache.commons.bcel6.generic.Type[] {org.apache.commons.bcel6.generic.Type.INT}, Constants.INVOKESTATIC); + }else{ + throw new NotImplementedException(); + } + } } // ino.end diff --git a/src/de/dhbwstuttgart/syntaxtree/operator/NotEqualOp.java b/src/de/dhbwstuttgart/syntaxtree/operator/NotEqualOp.java index 7cbe3936..0087c9ed 100755 --- a/src/de/dhbwstuttgart/syntaxtree/operator/NotEqualOp.java +++ b/src/de/dhbwstuttgart/syntaxtree/operator/NotEqualOp.java @@ -3,16 +3,10 @@ package de.dhbwstuttgart.syntaxtree.operator; // ino.end // ino.module.NotEqualOp.8606.import import java.util.Iterator; -import de.dhbwstuttgart.typeinference.Menge; -import de.dhbwstuttgart.myexception.CTypeReconstructionException; -import de.dhbwstuttgart.myexception.JVMCodeException; -import de.dhbwstuttgart.syntaxtree.statement.Binary; -import de.dhbwstuttgart.syntaxtree.statement.Expr; -import de.dhbwstuttgart.syntaxtree.statement.Null; -import de.dhbwstuttgart.syntaxtree.type.RefType; -import de.dhbwstuttgart.typeinference.Pair; -import de.dhbwstuttgart.typeinference.unify.Unify; +import org.apache.commons.bcel6.generic.BranchInstruction; +import org.apache.commons.bcel6.generic.IF_ACMPEQ; + // ino.class.NotEqualOp.24241.declaration public class NotEqualOp extends RelOp @@ -28,5 +22,10 @@ public class NotEqualOp extends RelOp } // ino.end + @Override + BranchInstruction getOperator() { + return new IF_ACMPEQ(null); + } + } // ino.end diff --git a/src/de/dhbwstuttgart/syntaxtree/operator/Operator.java b/src/de/dhbwstuttgart/syntaxtree/operator/Operator.java index 4a2573ba..25267dc1 100755 --- a/src/de/dhbwstuttgart/syntaxtree/operator/Operator.java +++ b/src/de/dhbwstuttgart/syntaxtree/operator/Operator.java @@ -6,6 +6,7 @@ import java.util.HashMap; import java.util.Hashtable; import java.util.Iterator; +import org.apache.commons.bcel6.Constants; import org.apache.commons.bcel6.generic.InstructionList; import de.dhbwstuttgart.typeinference.Menge; @@ -97,5 +98,13 @@ public abstract class Operator extends SyntaxTreeNode public Menge getChildren() { return new Menge<>(); } + + + protected InstructionList getInstructionListForOperand(ClassGenerator _cg, TypeinferenceResultSet rs, Expr operand, String returnType){ + InstructionList il = new InstructionList(); + il.append(operand.genByteCode(_cg, rs)); + il.append(_cg.getInstructionFactory().createInvoke("java.lang.Integer", "intValue", org.apache.commons.bcel6.generic.Type.INT, new org.apache.commons.bcel6.generic.Type[] {}, Constants.INVOKEVIRTUAL)); + return il; + } } // ino.end diff --git a/src/de/dhbwstuttgart/syntaxtree/operator/PlusOp.java b/src/de/dhbwstuttgart/syntaxtree/operator/PlusOp.java index 2c2c44aa..cff0e150 100755 --- a/src/de/dhbwstuttgart/syntaxtree/operator/PlusOp.java +++ b/src/de/dhbwstuttgart/syntaxtree/operator/PlusOp.java @@ -41,54 +41,9 @@ public class PlusOp extends AddOp super(offset,variableLength); } // ino.end - - @Override - public InstructionList genByteCode(ClassGenerator _cg, TypeinferenceResultSet rs, Binary operator) { - // TODO Plus Operator ist bis jetzt nur für Integer implementiert - /* - 0: aload_1 - 1: invokevirtual #2 // Method java/lang/Integer.intValue:()I - 4: aload_1 - 5: invokevirtual #2 // Method java/lang/Integer.intValue:()I - 8: iadd - 9: invokestatic #3 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer; - 12: areturn - */ - DHBWInstructionFactory _factory = _cg.getInstructionFactory(); - - String returnType = getReturnType(operator.get_Expr1(), operator.get_Expr2()); - - InstructionList il = getInstructionListForOperand(_cg, rs, operator.get_Expr1(), returnType); - - il.append(getInstructionListForOperand(_cg, rs, operator.get_Expr2(), returnType)); - - il.append(getOperator(returnType)); - - il.append(convertValueToObject(_factory, returnType)); - return il; - } - - private String getReturnType(Expr expr1, Expr expr2) { - return "java.lang.Integer"; - } - - private ArithmeticInstruction getOperator(String returnType) { + + ArithmeticInstruction getOperator(String returnType) { return new IADD(); } - private InvokeInstruction convertValueToObject(DHBWInstructionFactory _factory, String returnType) { - if(returnType.equals("java.lang.Integer")){ - return _factory.createInvoke("java.lang.Integer", "valueOf", new ObjectType("java.lang.Integer"), new org.apache.commons.bcel6.generic.Type[] {org.apache.commons.bcel6.generic.Type.INT}, Constants.INVOKESTATIC); - }else{ - throw new NotImplementedException(); - } - } - - private InstructionList getInstructionListForOperand(ClassGenerator _cg, TypeinferenceResultSet rs, Expr operand, String returnType){ - InstructionList il = new InstructionList(); - il.append(operand.genByteCode(_cg, rs)); - il.append(_cg.getInstructionFactory().createInvoke("java.lang.Integer", "intValue", org.apache.commons.bcel6.generic.Type.INT, new org.apache.commons.bcel6.generic.Type[] {}, Constants.INVOKEVIRTUAL)); - return il; - } - } // ino.end diff --git a/src/de/dhbwstuttgart/syntaxtree/operator/RelOp.java b/src/de/dhbwstuttgart/syntaxtree/operator/RelOp.java index eb9178d7..3080ddf2 100755 --- a/src/de/dhbwstuttgart/syntaxtree/operator/RelOp.java +++ b/src/de/dhbwstuttgart/syntaxtree/operator/RelOp.java @@ -6,14 +6,24 @@ package de.dhbwstuttgart.syntaxtree.operator; import java.util.HashMap; import java.util.Hashtable; import java.util.Iterator; -import de.dhbwstuttgart.typeinference.Menge; +import org.apache.commons.bcel6.Constants; +import org.apache.commons.bcel6.generic.BranchInstruction; +import org.apache.commons.bcel6.generic.GOTO; +import org.apache.commons.bcel6.generic.InstructionConstants; +import org.apache.commons.bcel6.generic.InstructionList; +import org.apache.commons.bcel6.generic.ObjectType; + +import de.dhbwstuttgart.typeinference.Menge; +import de.dhbwstuttgart.bytecode.ClassGenerator; +import de.dhbwstuttgart.bytecode.DHBWInstructionFactory; import de.dhbwstuttgart.myexception.CTypeReconstructionException; import de.dhbwstuttgart.myexception.JVMCodeException; import de.dhbwstuttgart.syntaxtree.statement.Binary; import de.dhbwstuttgart.syntaxtree.type.RefType; import de.dhbwstuttgart.syntaxtree.type.Type; import de.dhbwstuttgart.typeinference.Pair; +import de.dhbwstuttgart.typeinference.TypeinferenceResultSet; import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions; import de.dhbwstuttgart.typeinference.exceptions.DebugException; import de.dhbwstuttgart.typeinference.unify.Unify; @@ -54,6 +64,45 @@ public abstract class RelOp extends Operator return ret; } + + @Override + public InstructionList genByteCode(ClassGenerator _cg, TypeinferenceResultSet rs, Binary operator) { + /* + 0: aload_1 + 1: invokevirtual #3 // Method java/lang/Integer.intValue:()I + 4: aload_2 + 5: invokevirtual #3 // Method java/lang/Integer.intValue:()I + 8: if_icmplt 15 + 11: iconst_1 + 12: goto 16 + 15: iconst_0 + 16: invokestatic #2 // Method java/lang/Boolean.valueOf:(Z)Ljava/lang/Boolean; + 19: areturn + */ + + DHBWInstructionFactory _factory = _cg.getInstructionFactory(); + + InstructionList il = getInstructionListForOperand(_cg, rs, operator.get_Expr1(), "java.lang.Boolean"); + + il.append(getInstructionListForOperand(_cg, rs, operator.get_Expr2(), "java.lang.Boolean")); + + BranchInstruction operatorBranchInstruction = getOperator(); + + il.append(operatorBranchInstruction); + + il.append(InstructionConstants.ICONST_1); + + BranchInstruction gotoInstruction = new GOTO(null); + + il.append(gotoInstruction); + + operatorBranchInstruction.setTarget(il.append(InstructionConstants.ICONST_0)); + gotoInstruction.setTarget(il.append(_factory.createInvoke("java.lang.Boolean", "valueOf", new ObjectType("java.lang.Boolean"), new org.apache.commons.bcel6.generic.Type[] {org.apache.commons.bcel6.generic.Type.BOOLEAN}, Constants.INVOKESTATIC))); + + return il; + } + + abstract BranchInstruction getOperator(); } // ino.end diff --git a/src/de/dhbwstuttgart/syntaxtree/operator/TimesOp.java b/src/de/dhbwstuttgart/syntaxtree/operator/TimesOp.java index 6f47068d..c43ff29c 100755 --- a/src/de/dhbwstuttgart/syntaxtree/operator/TimesOp.java +++ b/src/de/dhbwstuttgart/syntaxtree/operator/TimesOp.java @@ -5,6 +5,9 @@ package de.dhbwstuttgart.syntaxtree.operator; // ino.module.TimesOp.8611.import import de.dhbwstuttgart.typeinference.Menge; +import org.apache.commons.bcel6.generic.ArithmeticInstruction; +import org.apache.commons.bcel6.generic.IMUL; + import de.dhbwstuttgart.myexception.JVMCodeException; import de.dhbwstuttgart.syntaxtree.statement.Binary; import de.dhbwstuttgart.syntaxtree.statement.Expr; @@ -23,5 +26,10 @@ public class TimesOp extends MulOp } // ino.end + @Override + ArithmeticInstruction getOperator(String returnType) { + return new IMUL(); + } + } // ino.end diff --git a/test/bytecode/operators/DivOperator.jav b/test/bytecode/operators/DivOperator.jav new file mode 100644 index 00000000..6ba3d4fe --- /dev/null +++ b/test/bytecode/operators/DivOperator.jav @@ -0,0 +1,5 @@ +class DivOperator{ + Integer method(Integer x, Integer y){ + return x / y; + } +} \ No newline at end of file diff --git a/test/bytecode/operators/DivOperatorTest.java b/test/bytecode/operators/DivOperatorTest.java new file mode 100644 index 00000000..6b7db4e0 --- /dev/null +++ b/test/bytecode/operators/DivOperatorTest.java @@ -0,0 +1,53 @@ +package bytecode.operators; + +import static org.junit.Assert.*; + +import java.io.File; +import java.lang.reflect.Method; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.Vector; + +import org.junit.Ignore; +import org.junit.Test; + +import bytecode.SourceFileBytecodeTest; + +public class DivOperatorTest extends SourceFileBytecodeTest{ + @Override + protected void init() { + testName = "DivOperator"; + rootDirectory = System.getProperty("user.dir")+"/test/bytecode/operators/"; + } + + @Test + public void testConstruct() throws Exception{ + ClassLoader classLoader = getClassLoader(); + + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + assertTrue(true); + } + + @Test + public void testTwoIntegers() throws Exception{ + ClassLoader classLoader = getClassLoader(); + + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + + Integer x = new Integer(1); + Integer y = new Integer(2); + + Class[] params = new Class[]{ + x.getClass(), + y.getClass(), + }; + + Method method = cls.getDeclaredMethod("method", params); + Integer returnValue = (Integer) method.invoke(obj, x, y); + assertEquals(new Integer(0), returnValue); + } +} diff --git a/test/bytecode/operators/MulOperator.jav b/test/bytecode/operators/MulOperator.jav new file mode 100644 index 00000000..dd08e82e --- /dev/null +++ b/test/bytecode/operators/MulOperator.jav @@ -0,0 +1,5 @@ +class MulOperator{ + Integer method(Integer x, Integer y){ + return x * y; + } +} \ No newline at end of file diff --git a/test/bytecode/operators/MulOperatorTest.java b/test/bytecode/operators/MulOperatorTest.java new file mode 100644 index 00000000..2c663021 --- /dev/null +++ b/test/bytecode/operators/MulOperatorTest.java @@ -0,0 +1,53 @@ +package bytecode.operators; + +import static org.junit.Assert.*; + +import java.io.File; +import java.lang.reflect.Method; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.Vector; + +import org.junit.Ignore; +import org.junit.Test; + +import bytecode.SourceFileBytecodeTest; + +public class MulOperatorTest extends SourceFileBytecodeTest{ + @Override + protected void init() { + testName = "MulOperator"; + rootDirectory = System.getProperty("user.dir")+"/test/bytecode/operators/"; + } + + @Test + public void testConstruct() throws Exception{ + ClassLoader classLoader = getClassLoader(); + + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + assertTrue(true); + } + + @Test + public void testTwoIntegers() throws Exception{ + ClassLoader classLoader = getClassLoader(); + + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + + Integer x = new Integer(1); + Integer y = new Integer(2); + + Class[] params = new Class[]{ + x.getClass(), + y.getClass(), + }; + + Method method = cls.getDeclaredMethod("method", params); + Integer returnValue = (Integer) method.invoke(obj, x, y); + assertEquals(new Integer(2), returnValue); + } +} diff --git a/test/bytecode/operators/SubOperator.jav b/test/bytecode/operators/SubOperator.jav new file mode 100644 index 00000000..1c591522 --- /dev/null +++ b/test/bytecode/operators/SubOperator.jav @@ -0,0 +1,5 @@ +class SubOperator{ + Integer method(Integer x, Integer y){ + return x - y; + } +} \ No newline at end of file diff --git a/test/bytecode/operators/SubOperatorTest.java b/test/bytecode/operators/SubOperatorTest.java new file mode 100644 index 00000000..a9b3294f --- /dev/null +++ b/test/bytecode/operators/SubOperatorTest.java @@ -0,0 +1,53 @@ +package bytecode.operators; + +import static org.junit.Assert.*; + +import java.io.File; +import java.lang.reflect.Method; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.Vector; + +import org.junit.Ignore; +import org.junit.Test; + +import bytecode.SourceFileBytecodeTest; + +public class SubOperatorTest extends SourceFileBytecodeTest{ + @Override + protected void init() { + testName = "SubOperator"; + rootDirectory = System.getProperty("user.dir")+"/test/bytecode/operators/"; + } + + @Test + public void testConstruct() throws Exception{ + ClassLoader classLoader = getClassLoader(); + + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + assertTrue(true); + } + + @Test + public void testTwoIntegers() throws Exception{ + ClassLoader classLoader = getClassLoader(); + + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + + Integer x = new Integer(1); + Integer y = new Integer(2); + + Class[] params = new Class[]{ + x.getClass(), + y.getClass(), + }; + + Method method = cls.getDeclaredMethod("method", params); + Integer returnValue = (Integer) method.invoke(obj, x, y); + assertEquals(new Integer(-1), returnValue); + } +} From bbb79b1a1da117e0821b839aba9fb525e1d1cf52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Enrico=20Schr=C3=B6dter?= Date: Wed, 27 Apr 2016 15:41:49 +0200 Subject: [PATCH 5/7] =?UTF-8?q?-=20Tests=20f=C3=BCr=20Vergleichsoperatoren?= =?UTF-8?q?=20angelegt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bytecode/operators/EqualOperatorTest.java | 28 +++--- .../operators/GreaterEqualOperator.jav | 5 ++ .../operators/GreaterEqualOperatorTest.java | 30 +++++++ test/bytecode/operators/GreaterOperator.jav | 5 ++ .../operators/GreaterOperatorTest.java | 30 +++++++ test/bytecode/operators/ModuloOperator.jav | 5 ++ .../operators/ModuloOperatorTest.java | 53 ++++++++++++ test/bytecode/operators/NotEqualOperator.jav | 5 ++ .../operators/NotEqualOperatorTest.java | 30 +++++++ ...ROperatorTest.java => OrOperatorTest.java} | 2 +- test/bytecode/operators/RelOperatorTest.java | 86 +++++++++++++++++++ .../operators/SmallerEqualOperator.jav | 5 ++ .../operators/SmallerEqualOperatorTest.java | 30 +++++++ test/bytecode/operators/SmallerOperator.jav | 5 ++ .../operators/SmallerOperatorTest.java | 30 +++++++ 15 files changed, 333 insertions(+), 16 deletions(-) create mode 100644 test/bytecode/operators/GreaterEqualOperator.jav create mode 100644 test/bytecode/operators/GreaterEqualOperatorTest.java create mode 100644 test/bytecode/operators/GreaterOperator.jav create mode 100644 test/bytecode/operators/GreaterOperatorTest.java create mode 100644 test/bytecode/operators/ModuloOperator.jav create mode 100644 test/bytecode/operators/ModuloOperatorTest.java create mode 100644 test/bytecode/operators/NotEqualOperator.jav create mode 100644 test/bytecode/operators/NotEqualOperatorTest.java rename test/bytecode/operators/{OROperatorTest.java => OrOperatorTest.java} (91%) create mode 100644 test/bytecode/operators/RelOperatorTest.java create mode 100644 test/bytecode/operators/SmallerEqualOperator.jav create mode 100644 test/bytecode/operators/SmallerEqualOperatorTest.java create mode 100644 test/bytecode/operators/SmallerOperator.jav create mode 100644 test/bytecode/operators/SmallerOperatorTest.java diff --git a/test/bytecode/operators/EqualOperatorTest.java b/test/bytecode/operators/EqualOperatorTest.java index b605799f..46720335 100644 --- a/test/bytecode/operators/EqualOperatorTest.java +++ b/test/bytecode/operators/EqualOperatorTest.java @@ -2,31 +2,29 @@ package bytecode.operators; import static org.junit.Assert.*; -import java.io.File; import java.lang.reflect.Method; -import java.net.URL; -import java.net.URLClassLoader; -import java.util.Vector; - -import org.junit.Ignore; import org.junit.Test; - import bytecode.SourceFileBytecodeTest; -public class EqualOperatorTest extends SourceFileBytecodeTest{ +public class EqualOperatorTest extends RelOperatorTest{ @Override protected void init() { testName = "EqualOperator"; rootDirectory = System.getProperty("user.dir")+"/test/bytecode/operators/"; } - @Test - public void testConstruct() throws Exception{ - ClassLoader classLoader = getClassLoader(); + @Override + protected Boolean getTest1x2ReturnValue() { + return new Boolean(false); + } + + @Override + protected Boolean getTest2x2ReturnValue() { + return new Boolean(true); + } - Class cls = classLoader.loadClass(testName); - - Object obj = cls.newInstance(); - assertTrue(true); + @Override + protected Boolean getTest2x1ReturnValue() { + return new Boolean(false); } } diff --git a/test/bytecode/operators/GreaterEqualOperator.jav b/test/bytecode/operators/GreaterEqualOperator.jav new file mode 100644 index 00000000..798891f9 --- /dev/null +++ b/test/bytecode/operators/GreaterEqualOperator.jav @@ -0,0 +1,5 @@ +class GreaterEqualOperator{ + Boolean method(Integer x, Integer y){ + return x >= y; + } +} \ No newline at end of file diff --git a/test/bytecode/operators/GreaterEqualOperatorTest.java b/test/bytecode/operators/GreaterEqualOperatorTest.java new file mode 100644 index 00000000..41834e73 --- /dev/null +++ b/test/bytecode/operators/GreaterEqualOperatorTest.java @@ -0,0 +1,30 @@ +package bytecode.operators; + +import static org.junit.Assert.*; + +import java.lang.reflect.Method; +import org.junit.Test; +import bytecode.SourceFileBytecodeTest; + +public class GreaterEqualOperatorTest extends RelOperatorTest{ + @Override + protected void init() { + testName = "GreaterEqualOperator"; + rootDirectory = System.getProperty("user.dir")+"/test/bytecode/operators/"; + } + + @Override + protected Boolean getTest1x2ReturnValue() { + return new Boolean(false); + } + + @Override + protected Boolean getTest2x2ReturnValue() { + return new Boolean(true); + } + + @Override + protected Boolean getTest2x1ReturnValue() { + return new Boolean(true); + } +} diff --git a/test/bytecode/operators/GreaterOperator.jav b/test/bytecode/operators/GreaterOperator.jav new file mode 100644 index 00000000..f2c28682 --- /dev/null +++ b/test/bytecode/operators/GreaterOperator.jav @@ -0,0 +1,5 @@ +class GreaterOperator{ + Boolean method(Integer x, Integer y){ + return x > y; + } +} \ No newline at end of file diff --git a/test/bytecode/operators/GreaterOperatorTest.java b/test/bytecode/operators/GreaterOperatorTest.java new file mode 100644 index 00000000..7a562461 --- /dev/null +++ b/test/bytecode/operators/GreaterOperatorTest.java @@ -0,0 +1,30 @@ +package bytecode.operators; + +import static org.junit.Assert.*; + +import java.lang.reflect.Method; +import org.junit.Test; +import bytecode.SourceFileBytecodeTest; + +public class GreaterOperatorTest extends RelOperatorTest{ + @Override + protected void init() { + testName = "GreaterOperator"; + rootDirectory = System.getProperty("user.dir")+"/test/bytecode/operators/"; + } + + @Override + protected Boolean getTest1x2ReturnValue() { + return new Boolean(false); + } + + @Override + protected Boolean getTest2x2ReturnValue() { + return new Boolean(false); + } + + @Override + protected Boolean getTest2x1ReturnValue() { + return new Boolean(true); + } +} diff --git a/test/bytecode/operators/ModuloOperator.jav b/test/bytecode/operators/ModuloOperator.jav new file mode 100644 index 00000000..6a17f28e --- /dev/null +++ b/test/bytecode/operators/ModuloOperator.jav @@ -0,0 +1,5 @@ +class ModuloOperator{ + Integer method(Integer x, Integer y){ + return x % y; + } +} \ No newline at end of file diff --git a/test/bytecode/operators/ModuloOperatorTest.java b/test/bytecode/operators/ModuloOperatorTest.java new file mode 100644 index 00000000..5c0c600f --- /dev/null +++ b/test/bytecode/operators/ModuloOperatorTest.java @@ -0,0 +1,53 @@ +package bytecode.operators; + +import static org.junit.Assert.*; + +import java.io.File; +import java.lang.reflect.Method; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.Vector; + +import org.junit.Ignore; +import org.junit.Test; + +import bytecode.SourceFileBytecodeTest; + +public class ModuloOperatorTest extends SourceFileBytecodeTest{ + @Override + protected void init() { + testName = "ModuloOperator"; + rootDirectory = System.getProperty("user.dir")+"/test/bytecode/operators/"; + } + + @Test + public void testConstruct() throws Exception{ + ClassLoader classLoader = getClassLoader(); + + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + assertTrue(true); + } + + @Test + public void testTwoIntegers() throws Exception{ + ClassLoader classLoader = getClassLoader(); + + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + + Integer x = new Integer(1); + Integer y = new Integer(2); + + Class[] params = new Class[]{ + x.getClass(), + y.getClass(), + }; + + Method method = cls.getDeclaredMethod("method", params); + Integer returnValue = (Integer) method.invoke(obj, x, y); + assertEquals(new Integer(1), returnValue); + } +} diff --git a/test/bytecode/operators/NotEqualOperator.jav b/test/bytecode/operators/NotEqualOperator.jav new file mode 100644 index 00000000..68c8a168 --- /dev/null +++ b/test/bytecode/operators/NotEqualOperator.jav @@ -0,0 +1,5 @@ +class NotEqualOperator{ + Boolean method(Integer x, Integer y){ + return x != y; + } +} \ No newline at end of file diff --git a/test/bytecode/operators/NotEqualOperatorTest.java b/test/bytecode/operators/NotEqualOperatorTest.java new file mode 100644 index 00000000..89b2d871 --- /dev/null +++ b/test/bytecode/operators/NotEqualOperatorTest.java @@ -0,0 +1,30 @@ +package bytecode.operators; + +import static org.junit.Assert.*; + +import java.lang.reflect.Method; +import org.junit.Test; +import bytecode.SourceFileBytecodeTest; + +public class NotEqualOperatorTest extends RelOperatorTest{ + @Override + protected void init() { + testName = "NotEqualOperator"; + rootDirectory = System.getProperty("user.dir")+"/test/bytecode/operators/"; + } + + @Override + protected Boolean getTest1x2ReturnValue() { + return new Boolean(true); + } + + @Override + protected Boolean getTest2x2ReturnValue() { + return new Boolean(false); + } + + @Override + protected Boolean getTest2x1ReturnValue() { + return new Boolean(true); + } +} diff --git a/test/bytecode/operators/OROperatorTest.java b/test/bytecode/operators/OrOperatorTest.java similarity index 91% rename from test/bytecode/operators/OROperatorTest.java rename to test/bytecode/operators/OrOperatorTest.java index 7c648e88..8d8faaa9 100644 --- a/test/bytecode/operators/OROperatorTest.java +++ b/test/bytecode/operators/OrOperatorTest.java @@ -13,7 +13,7 @@ import org.junit.Test; import bytecode.SourceFileBytecodeTest; -public class OROperatorTest extends SourceFileBytecodeTest{ +public class OrOperatorTest extends SourceFileBytecodeTest{ @Override protected void init() { testName = "OrOperator"; diff --git a/test/bytecode/operators/RelOperatorTest.java b/test/bytecode/operators/RelOperatorTest.java new file mode 100644 index 00000000..59f3ded7 --- /dev/null +++ b/test/bytecode/operators/RelOperatorTest.java @@ -0,0 +1,86 @@ +package bytecode.operators; + +import static org.junit.Assert.*; + +import java.lang.reflect.Method; +import org.junit.Test; +import bytecode.SourceFileBytecodeTest; + +public abstract class RelOperatorTest extends SourceFileBytecodeTest{ + @Test + public void testConstruct() throws Exception{ + ClassLoader classLoader = getClassLoader(); + + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + assertTrue(true); + } + + @Test + public void test1x2() throws Exception{ + ClassLoader classLoader = getClassLoader(); + + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + + Integer x = new Integer(1); + Integer y = new Integer(2); + + Class[] params = new Class[]{ + x.getClass(), + y.getClass(), + }; + + Method method = cls.getDeclaredMethod("method", params); + Boolean returnValue = (Boolean) method.invoke(obj, x, y); + assertEquals(getTest1x2ReturnValue(), returnValue); + } + + @Test + public void test2x2() throws Exception{ + ClassLoader classLoader = getClassLoader(); + + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + + Integer x = new Integer(2); + Integer y = new Integer(2); + + Class[] params = new Class[]{ + x.getClass(), + y.getClass(), + }; + + Method method = cls.getDeclaredMethod("method", params); + Boolean returnValue = (Boolean) method.invoke(obj, x, y); + assertEquals(getTest2x2ReturnValue(), returnValue); + } + + @Test + public void test2x1() throws Exception{ + ClassLoader classLoader = getClassLoader(); + + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + + Integer x = new Integer(2); + Integer y = new Integer(2); + + Class[] params = new Class[]{ + x.getClass(), + y.getClass(), + }; + + Method method = cls.getDeclaredMethod("method", params); + Boolean returnValue = (Boolean) method.invoke(obj, x, y); + assertEquals(getTest2x1ReturnValue(), returnValue); + } + + protected abstract Boolean getTest1x2ReturnValue(); + protected abstract Boolean getTest2x2ReturnValue(); + protected abstract Boolean getTest2x1ReturnValue(); +} diff --git a/test/bytecode/operators/SmallerEqualOperator.jav b/test/bytecode/operators/SmallerEqualOperator.jav new file mode 100644 index 00000000..b0448dba --- /dev/null +++ b/test/bytecode/operators/SmallerEqualOperator.jav @@ -0,0 +1,5 @@ +class SmallerEqualOperator{ + Boolean method(Integer x, Integer y){ + return x <= y; + } +} \ No newline at end of file diff --git a/test/bytecode/operators/SmallerEqualOperatorTest.java b/test/bytecode/operators/SmallerEqualOperatorTest.java new file mode 100644 index 00000000..d4da5f6f --- /dev/null +++ b/test/bytecode/operators/SmallerEqualOperatorTest.java @@ -0,0 +1,30 @@ +package bytecode.operators; + +import static org.junit.Assert.*; + +import java.lang.reflect.Method; +import org.junit.Test; +import bytecode.SourceFileBytecodeTest; + +public class SmallerEqualOperatorTest extends RelOperatorTest{ + @Override + protected void init() { + testName = "SmallerEqual"; + rootDirectory = System.getProperty("user.dir")+"/test/bytecode/operators/"; + } + + @Override + protected Boolean getTest1x2ReturnValue() { + return new Boolean(true); + } + + @Override + protected Boolean getTest2x2ReturnValue() { + return new Boolean(true); + } + + @Override + protected Boolean getTest2x1ReturnValue() { + return new Boolean(false); + } +} diff --git a/test/bytecode/operators/SmallerOperator.jav b/test/bytecode/operators/SmallerOperator.jav new file mode 100644 index 00000000..5ddc8c91 --- /dev/null +++ b/test/bytecode/operators/SmallerOperator.jav @@ -0,0 +1,5 @@ +class SmallerOperator{ + Boolean method(Integer x, Integer y){ + return x < y; + } +} \ No newline at end of file diff --git a/test/bytecode/operators/SmallerOperatorTest.java b/test/bytecode/operators/SmallerOperatorTest.java new file mode 100644 index 00000000..2609b70f --- /dev/null +++ b/test/bytecode/operators/SmallerOperatorTest.java @@ -0,0 +1,30 @@ +package bytecode.operators; + +import static org.junit.Assert.*; + +import java.lang.reflect.Method; +import org.junit.Test; +import bytecode.SourceFileBytecodeTest; + +public class SmallerOperatorTest extends RelOperatorTest{ + @Override + protected void init() { + testName = "Smaller"; + rootDirectory = System.getProperty("user.dir")+"/test/bytecode/operators/"; + } + + @Override + protected Boolean getTest1x2ReturnValue() { + return new Boolean(true); + } + + @Override + protected Boolean getTest2x2ReturnValue() { + return new Boolean(false); + } + + @Override + protected Boolean getTest2x1ReturnValue() { + return new Boolean(false); + } +} From dad06a562644e92500aad27aa234e729b0638c51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Enrico=20Schr=C3=B6dter?= Date: Fri, 29 Apr 2016 09:43:36 +0200 Subject: [PATCH 6/7] Alle Bytecode Tests in SourceBytecodeTests transformiert --- test/bytecode/AssignTest.java | 21 ++++++---- test/bytecode/BinaryTest.java | 23 ++++++----- test/bytecode/BinaryTest2.java | 21 ++++++---- test/bytecode/BoolLitTest.java | 23 ++++++----- test/bytecode/CharLitTest.java | 21 ++++++---- test/bytecode/ConditionTest.java | 21 ++++++---- test/bytecode/EmptyClassTest.java | 21 ++++++---- test/bytecode/FieldDeclarationTest.java | 21 ++++++---- test/bytecode/ForTest.java | 20 ++++++---- test/bytecode/IdTest.java | 21 ++++++---- test/bytecode/IdentityField.jav | 2 +- test/bytecode/IdentityFieldTest.java | 21 ++++++---- test/bytecode/IdentityTest.java | 21 ++++++---- test/bytecode/IfElseIfStatement.jav | 2 + test/bytecode/IfElseIfStatementTest.java | 19 ++++++--- test/bytecode/IfElseStatementTest.java | 19 ++++++--- test/bytecode/IfStatementTest.java | 19 ++++++--- ...{LambdaExpr2.java => LambdaExpr2Test.java} | 22 ++++++----- .../{LambdaExpr.java => LambdaExprTest.java} | 23 ++++++----- test/bytecode/MainTest.java | 21 ++++++---- test/bytecode/Matrix_lambda.jav | 2 +- test/bytecode/Matrix_lambda2.jav | 2 +- test/bytecode/Matrix_lambda3.jav | 2 +- test/bytecode/Matrix_lambdaTest.java | 21 ++++++---- test/bytecode/Matrix_lambdaTest2.java | 21 ++++++---- test/bytecode/Matrix_lambdaTest3.java | 21 ++++++---- test/bytecode/MethodCallTest.java | 21 ++++++---- test/bytecode/MethodEmpty.java | 23 ++++++----- test/bytecode/MethodEmptyRetType.java | 23 ++++++----- test/bytecode/NewStatementTest.java | 39 ++++++------------- test/bytecode/ParameterTest.java | 23 ++++++----- test/bytecode/PostDecrement.java | 24 +++++++----- test/bytecode/PostIncrement.java | 24 +++++++----- test/bytecode/ReturnTest.java | 23 ++++++----- test/bytecode/RunnableTest.java | 21 ++++++---- test/bytecode/StringLitTest.java | 23 ++++++----- test/bytecode/SystemOutPrintlnTest.java | 23 ++++++----- test/bytecode/Test3.java | 2 +- test/bytecode/WhileTest.java | 21 ++++++---- 39 files changed, 455 insertions(+), 286 deletions(-) rename test/bytecode/{LambdaExpr2.java => LambdaExpr2Test.java} (63%) rename test/bytecode/{LambdaExpr.java => LambdaExprTest.java} (62%) diff --git a/test/bytecode/AssignTest.java b/test/bytecode/AssignTest.java index 232564df..03a32865 100644 --- a/test/bytecode/AssignTest.java +++ b/test/bytecode/AssignTest.java @@ -20,15 +20,20 @@ import de.dhbwstuttgart.typeinference.Menge; import de.dhbwstuttgart.typeinference.TypeinferenceResultSet; import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertSet; -public class AssignTest { - - public final static String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; - public final static String testFile = "Assign.jav"; - public final static String outputFile = "Assign.class"; +public class AssignTest extends SourceFileBytecodeTest{ + @Override + protected void init() { + testName = "Assign"; + rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; + } @Test - public void test() { - SingleClassTester.compileToBytecode(rootDirectory+testFile, rootDirectory+outputFile); - } + public void testConstruct() throws Exception{ + ClassLoader classLoader = getClassLoader(); + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + assertTrue(true); + } } diff --git a/test/bytecode/BinaryTest.java b/test/bytecode/BinaryTest.java index 37b0ab82..3e73a2ea 100644 --- a/test/bytecode/BinaryTest.java +++ b/test/bytecode/BinaryTest.java @@ -20,15 +20,20 @@ import de.dhbwstuttgart.typeinference.Menge; import de.dhbwstuttgart.typeinference.TypeinferenceResultSet; import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertSet; -public class BinaryTest { - - public final static String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; - public final static String testFile = "Binary.jav"; - public final static String outputFile = "Binary.class"; +public class BinaryTest extends SourceFileBytecodeTest{ + @Override + protected void init() { + testName = "Binary"; + rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; + } @Test - public void test() { - SingleClassTester.compileToBytecode(rootDirectory+testFile, rootDirectory+outputFile); - } + public void testConstruct() throws Exception{ + ClassLoader classLoader = getClassLoader(); -} + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + assertTrue(true); + } +} \ No newline at end of file diff --git a/test/bytecode/BinaryTest2.java b/test/bytecode/BinaryTest2.java index 842af094..5ea33514 100644 --- a/test/bytecode/BinaryTest2.java +++ b/test/bytecode/BinaryTest2.java @@ -20,15 +20,20 @@ import de.dhbwstuttgart.typeinference.Menge; import de.dhbwstuttgart.typeinference.TypeinferenceResultSet; import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertSet; -public class BinaryTest2 { - - public final static String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; - public final static String testFile = "Binary2.jav"; - public final static String outputFile = "Binary2.class"; +public class BinaryTest2 extends SourceFileBytecodeTest{ + @Override + protected void init() { + testName = "Binary2"; + rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; + } @Test - public void test() { - SingleClassTester.compileToBytecode(rootDirectory+testFile, rootDirectory); - } + public void testConstruct() throws Exception{ + ClassLoader classLoader = getClassLoader(); + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + assertTrue(true); + } } diff --git a/test/bytecode/BoolLitTest.java b/test/bytecode/BoolLitTest.java index 75bd41ed..be459e8d 100644 --- a/test/bytecode/BoolLitTest.java +++ b/test/bytecode/BoolLitTest.java @@ -20,15 +20,20 @@ import de.dhbwstuttgart.typeinference.Menge; import de.dhbwstuttgart.typeinference.TypeinferenceResultSet; import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertSet; -public class BoolLitTest { - - public final static String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; - public final static String testFile = "BoolLit.jav"; - public final static String outputFile = "BoolLit.class"; +public class BoolLitTest extends SourceFileBytecodeTest{ + @Override + protected void init() { + testName = "BoolLit"; + rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; + } @Test - public void test() { - SingleClassTester.compileToBytecode(rootDirectory+testFile, rootDirectory+outputFile); - } + public void testConstruct() throws Exception{ + ClassLoader classLoader = getClassLoader(); -} + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + assertTrue(true); + } +} \ No newline at end of file diff --git a/test/bytecode/CharLitTest.java b/test/bytecode/CharLitTest.java index 60f2c4d5..87b35013 100644 --- a/test/bytecode/CharLitTest.java +++ b/test/bytecode/CharLitTest.java @@ -20,15 +20,20 @@ import de.dhbwstuttgart.typeinference.Menge; import de.dhbwstuttgart.typeinference.TypeinferenceResultSet; import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertSet; -public class CharLitTest { - - public final static String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; - public final static String testFile = "CharLitTest.jav"; - public final static String outputFile = "CharLitTest.class"; +public class CharLitTest extends SourceFileBytecodeTest{ + @Override + protected void init() { + testName = "CharLit"; + rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; + } @Test - public void test() { - SingleClassTester.compileToBytecode(rootDirectory+testFile, rootDirectory+outputFile); - } + public void testConstruct() throws Exception{ + ClassLoader classLoader = getClassLoader(); + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + assertTrue(true); + } } diff --git a/test/bytecode/ConditionTest.java b/test/bytecode/ConditionTest.java index 851d6426..dfbbadf9 100644 --- a/test/bytecode/ConditionTest.java +++ b/test/bytecode/ConditionTest.java @@ -20,15 +20,20 @@ import de.dhbwstuttgart.typeinference.Menge; import de.dhbwstuttgart.typeinference.TypeinferenceResultSet; import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertSet; -public class ConditionTest { - - public final static String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; - public final static String testFile = "Condition.jav"; - public final static String outputFile = "Condition.class"; +public class ConditionTest extends SourceFileBytecodeTest{ + @Override + protected void init() { + testName = "Condition"; + rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; + } @Test - public void test() { - SingleClassTester.compileToBytecode(rootDirectory+testFile, rootDirectory+outputFile); - } + public void testConstruct() throws Exception{ + ClassLoader classLoader = getClassLoader(); + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + assertTrue(true); + } } diff --git a/test/bytecode/EmptyClassTest.java b/test/bytecode/EmptyClassTest.java index de7d900a..6050dd37 100644 --- a/test/bytecode/EmptyClassTest.java +++ b/test/bytecode/EmptyClassTest.java @@ -20,15 +20,20 @@ import de.dhbwstuttgart.typeinference.Menge; import de.dhbwstuttgart.typeinference.TypeinferenceResultSet; import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertSet; -public class EmptyClassTest { - - public final static String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; - public final static String testFile = "EmptyClass.jav"; - public final static String outputFile = "EmptyClass.class"; +public class EmptyClassTest extends SourceFileBytecodeTest{ + @Override + protected void init() { + testName = "EmptyClass"; + rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; + } @Test - public void test() { - SingleClassTester.compileToBytecode(rootDirectory+testFile, rootDirectory+outputFile); - } + public void testConstruct() throws Exception{ + ClassLoader classLoader = getClassLoader(); + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + assertTrue(true); + } } diff --git a/test/bytecode/FieldDeclarationTest.java b/test/bytecode/FieldDeclarationTest.java index 7724c0e8..ea6b8062 100644 --- a/test/bytecode/FieldDeclarationTest.java +++ b/test/bytecode/FieldDeclarationTest.java @@ -2,13 +2,20 @@ package bytecode; import org.junit.Test; -public class FieldDeclarationTest { - public final static String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; - public final static String testFile = "FieldDeclaration.jav"; - public final static String outputFile = "FieldDeclaration.class"; +public class FieldDeclarationTest extends SourceFileBytecodeTest{ + @Override + protected void init() { + testName = "FieldDeclaration"; + rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; + } @Test - public void test() { - SingleClassTester.compileToBytecode(rootDirectory+testFile, rootDirectory+outputFile); + public void testConstruct() throws Exception{ + ClassLoader classLoader = getClassLoader(); + + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + assertTrue(true); } -} +} \ No newline at end of file diff --git a/test/bytecode/ForTest.java b/test/bytecode/ForTest.java index 497dc375..d34b2a63 100644 --- a/test/bytecode/ForTest.java +++ b/test/bytecode/ForTest.java @@ -3,14 +3,20 @@ package bytecode; import org.junit.Ignore; import org.junit.Test; -public class ForTest { - public final static String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; - public final static String testFile = "ForTest.jav"; - public final static String outputFile = "ForTest.class"; +public class ForTest extends SourceFileBytecodeTest{ + @Override + protected void init() { + testName = "ForTest"; + rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; + } @Test - @Ignore - public void test() { - SingleClassTester.compileToBytecode(rootDirectory+testFile, rootDirectory+outputFile); + public void testConstruct() throws Exception{ + ClassLoader classLoader = getClassLoader(); + + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + assertTrue(true); } } diff --git a/test/bytecode/IdTest.java b/test/bytecode/IdTest.java index f303e5d0..f5da1ab2 100644 --- a/test/bytecode/IdTest.java +++ b/test/bytecode/IdTest.java @@ -2,13 +2,20 @@ package bytecode; import org.junit.Test; -public class IdTest { - public final static String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; - public final static String testFile = "Id.jav"; - public final static String outputFile = "Id.class"; +public class IdTest extends SourceFileBytecodeTest{ + @Override + protected void init() { + testName = "Id"; + rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; + } @Test - public void test() { - SingleClassTester.compileToBytecode(rootDirectory+testFile, rootDirectory+outputFile); + public void testConstruct() throws Exception{ + ClassLoader classLoader = getClassLoader(); + + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + assertTrue(true); } -} +} \ No newline at end of file diff --git a/test/bytecode/IdentityField.jav b/test/bytecode/IdentityField.jav index 29781431..8063d0b3 100644 --- a/test/bytecode/IdentityField.jav +++ b/test/bytecode/IdentityField.jav @@ -1,3 +1,3 @@ -class Id { +class IdentityField { Fun1 op = (x) -> x; } \ No newline at end of file diff --git a/test/bytecode/IdentityFieldTest.java b/test/bytecode/IdentityFieldTest.java index e50b001e..2a6e7ecd 100644 --- a/test/bytecode/IdentityFieldTest.java +++ b/test/bytecode/IdentityFieldTest.java @@ -2,13 +2,20 @@ package bytecode; import org.junit.Test; -public class IdentityFieldTest { - public final static String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; - public final static String testFile = "IdentityField.jav"; - public final static String outputFile = "IdentityField.class"; +public class IdentityFieldTest extends SourceFileBytecodeTest{ + @Override + protected void init() { + testName = "IdentityField"; + rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; + } @Test - public void test() { - SingleClassTester.compileToBytecode(rootDirectory+testFile, rootDirectory+outputFile); + public void testConstruct() throws Exception{ + ClassLoader classLoader = getClassLoader(); + + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + assertTrue(true); } -} +} \ No newline at end of file diff --git a/test/bytecode/IdentityTest.java b/test/bytecode/IdentityTest.java index 7d5493ee..2aa2563e 100644 --- a/test/bytecode/IdentityTest.java +++ b/test/bytecode/IdentityTest.java @@ -2,13 +2,20 @@ package bytecode; import org.junit.Test; -public class IdentityTest { - public final static String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; - public final static String testFile = "Identity.jav"; - public final static String outputFile = "Identity.class"; +public class IdentityTest extends SourceFileBytecodeTest{ + @Override + protected void init() { + testName = "Identity"; + rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; + } @Test - public void test() { - SingleClassTester.compileToBytecode(rootDirectory+testFile, rootDirectory+outputFile); + public void testConstruct() throws Exception{ + ClassLoader classLoader = getClassLoader(); + + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + assertTrue(true); } -} +} \ No newline at end of file diff --git a/test/bytecode/IfElseIfStatement.jav b/test/bytecode/IfElseIfStatement.jav index 1b6fbb89..caf9d524 100644 --- a/test/bytecode/IfElseIfStatement.jav +++ b/test/bytecode/IfElseIfStatement.jav @@ -4,6 +4,8 @@ class IfElseIfStatement{ return 0; }else if(flag){ return 1; + }else{ + return 2; } } diff --git a/test/bytecode/IfElseIfStatementTest.java b/test/bytecode/IfElseIfStatementTest.java index 9ac14c4c..6e60d3a6 100644 --- a/test/bytecode/IfElseIfStatementTest.java +++ b/test/bytecode/IfElseIfStatementTest.java @@ -2,13 +2,20 @@ package bytecode; import org.junit.Test; -public class IfElseIfStatementTest { - public final static String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; - public final static String testFile = "IfElseIfStatement.jav"; - public final static String outputFile = "IfElseIfStatement.class"; +public class IfElseIfStatementTest extends SourceFileBytecodeTest{ + @Override + protected void init() { + testName = "IfElseIfStatement"; + rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; + } @Test - public void test() { - SingleClassTester.compileToBytecode(rootDirectory+testFile, rootDirectory); + public void testConstruct() throws Exception{ + ClassLoader classLoader = getClassLoader(); + + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + assertTrue(true); } } diff --git a/test/bytecode/IfElseStatementTest.java b/test/bytecode/IfElseStatementTest.java index 9b491a6b..3209b8d1 100644 --- a/test/bytecode/IfElseStatementTest.java +++ b/test/bytecode/IfElseStatementTest.java @@ -2,13 +2,20 @@ package bytecode; import org.junit.Test; -public class IfElseStatementTest { - public final static String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; - public final static String testFile = "IfElseStatement.jav"; - public final static String outputFile = "IfElseStatement.class"; +public class IfElseStatementTest extends SourceFileBytecodeTest{ + @Override + protected void init() { + testName = "IfElseStatement"; + rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; + } @Test - public void test() { - SingleClassTester.compileToBytecode(rootDirectory+testFile, rootDirectory); + public void testConstruct() throws Exception{ + ClassLoader classLoader = getClassLoader(); + + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + assertTrue(true); } } diff --git a/test/bytecode/IfStatementTest.java b/test/bytecode/IfStatementTest.java index 848f46d4..baa8b906 100644 --- a/test/bytecode/IfStatementTest.java +++ b/test/bytecode/IfStatementTest.java @@ -2,13 +2,20 @@ package bytecode; import org.junit.Test; -public class IfStatementTest { - public final static String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; - public final static String testFile = "IfStatement.jav"; - public final static String outputFile = "IfStatement.class"; +public class IfStatementTest extends SourceFileBytecodeTest{ + @Override + protected void init() { + testName = "IfStatement"; + rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; + } @Test - public void test() { - SingleClassTester.compileToBytecode(rootDirectory+testFile, rootDirectory); + public void testConstruct() throws Exception{ + ClassLoader classLoader = getClassLoader(); + + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + assertTrue(true); } } diff --git a/test/bytecode/LambdaExpr2.java b/test/bytecode/LambdaExpr2Test.java similarity index 63% rename from test/bytecode/LambdaExpr2.java rename to test/bytecode/LambdaExpr2Test.java index 83308ca5..ac85b8d0 100644 --- a/test/bytecode/LambdaExpr2.java +++ b/test/bytecode/LambdaExpr2Test.java @@ -21,16 +21,20 @@ import de.dhbwstuttgart.typeinference.Menge; import de.dhbwstuttgart.typeinference.TypeinferenceResultSet; import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertSet; -public class LambdaExpr2 { - - public final static String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; - public final static String testFile = "LambdaExpr2.jav"; - public final static String outputFile = "LambdaExpr2.class"; +public class LambdaExpr2Test extends SourceFileBytecodeTest{ + @Override + protected void init() { + testName = "LambdaExpr"; + rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; + } @Test - @Ignore - public void test() { - SingleClassTester.compileToBytecode(rootDirectory+testFile, rootDirectory+outputFile); - } + public void testConstruct() throws Exception{ + ClassLoader classLoader = getClassLoader(); + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + assertTrue(true); + } } diff --git a/test/bytecode/LambdaExpr.java b/test/bytecode/LambdaExprTest.java similarity index 62% rename from test/bytecode/LambdaExpr.java rename to test/bytecode/LambdaExprTest.java index c28dad56..c6b8e0f5 100644 --- a/test/bytecode/LambdaExpr.java +++ b/test/bytecode/LambdaExprTest.java @@ -20,15 +20,20 @@ import de.dhbwstuttgart.typeinference.Menge; import de.dhbwstuttgart.typeinference.TypeinferenceResultSet; import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertSet; -public class LambdaExpr { - - public final static String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; - public final static String testFile = "LambdaExpr.jav"; - public final static String outputFile = "LambdaExpr.class"; +public class LambdaExprTest extends SourceFileBytecodeTest{ + @Override + protected void init() { + testName = "LambdaExpr"; + rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; + } @Test - public void test() { - SingleClassTester.compileToBytecode(rootDirectory+testFile, rootDirectory+outputFile); - } + public void testConstruct() throws Exception{ + ClassLoader classLoader = getClassLoader(); -} + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + assertTrue(true); + } +} \ No newline at end of file diff --git a/test/bytecode/MainTest.java b/test/bytecode/MainTest.java index 768c2fca..97abece4 100644 --- a/test/bytecode/MainTest.java +++ b/test/bytecode/MainTest.java @@ -20,15 +20,20 @@ import de.dhbwstuttgart.typeinference.Menge; import de.dhbwstuttgart.typeinference.TypeinferenceResultSet; import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertSet; -public class MainTest { - - public final static String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; - public final static String testFile = "Main.jav"; - public final static String outputFile = "Main.class"; +public class MainTest extends SourceFileBytecodeTest{ + @Override + protected void init() { + testName = "Main"; + rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; + } @Test - public void test() { - SingleClassTester.compileToBytecode(rootDirectory+testFile, rootDirectory); - } + public void testConstruct() throws Exception{ + ClassLoader classLoader = getClassLoader(); + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + assertTrue(true); + } } diff --git a/test/bytecode/Matrix_lambda.jav b/test/bytecode/Matrix_lambda.jav index 293f776e..f531d2ba 100644 --- a/test/bytecode/Matrix_lambda.jav +++ b/test/bytecode/Matrix_lambda.jav @@ -1,5 +1,5 @@ import java.util.Vector; -class Matrix extends Vector> { +class Matrix_lambda extends Vector> { op = (Matrix m) -> (f) -> f.apply(this, m); } \ No newline at end of file diff --git a/test/bytecode/Matrix_lambda2.jav b/test/bytecode/Matrix_lambda2.jav index e67ce40c..667e02e2 100644 --- a/test/bytecode/Matrix_lambda2.jav +++ b/test/bytecode/Matrix_lambda2.jav @@ -1,4 +1,4 @@ -class Matrix2 { +class Matrix_lambda2 { op = (f) -> f.apply(2); } \ No newline at end of file diff --git a/test/bytecode/Matrix_lambda3.jav b/test/bytecode/Matrix_lambda3.jav index 7fc6dede..f0341cdc 100644 --- a/test/bytecode/Matrix_lambda3.jav +++ b/test/bytecode/Matrix_lambda3.jav @@ -1,4 +1,4 @@ -class Matrix3 { +class Matrix_lambda3 { op = (f) -> f.apply(); } \ No newline at end of file diff --git a/test/bytecode/Matrix_lambdaTest.java b/test/bytecode/Matrix_lambdaTest.java index 7cbf4932..5d8b4e39 100644 --- a/test/bytecode/Matrix_lambdaTest.java +++ b/test/bytecode/Matrix_lambdaTest.java @@ -2,13 +2,20 @@ package bytecode; import org.junit.Test; -public class Matrix_lambdaTest { - public final static String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; - public final static String testFile = "Matrix_lambda.jav"; - public final static String outputFile = "Matrix_lambda.class"; +public class Matrix_lambdaTest extends SourceFileBytecodeTest{ + @Override + protected void init() { + testName = "Matrix_lambda"; + rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; + } @Test - public void test() { - SingleClassTester.compileToBytecode(rootDirectory+testFile, rootDirectory+outputFile); + public void testConstruct() throws Exception{ + ClassLoader classLoader = getClassLoader(); + + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + assertTrue(true); } -} +} \ No newline at end of file diff --git a/test/bytecode/Matrix_lambdaTest2.java b/test/bytecode/Matrix_lambdaTest2.java index 3264bfa0..374802a3 100644 --- a/test/bytecode/Matrix_lambdaTest2.java +++ b/test/bytecode/Matrix_lambdaTest2.java @@ -2,13 +2,20 @@ package bytecode; import org.junit.Test; -public class Matrix_lambdaTest2 { - public final static String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; - public final static String testFile = "Matrix_lambda2.jav"; - public final static String outputFile = "Matrix2.class"; +public class Matrix_lambdaTest2 extends SourceFileBytecodeTest{ + @Override + protected void init() { + testName = "Matrix_lambda2"; + rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; + } @Test - public void test() { - SingleClassTester.compileToBytecode(rootDirectory+testFile, rootDirectory+outputFile); + public void testConstruct() throws Exception{ + ClassLoader classLoader = getClassLoader(); + + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + assertTrue(true); } -} +} \ No newline at end of file diff --git a/test/bytecode/Matrix_lambdaTest3.java b/test/bytecode/Matrix_lambdaTest3.java index a649ec93..6addc9fd 100644 --- a/test/bytecode/Matrix_lambdaTest3.java +++ b/test/bytecode/Matrix_lambdaTest3.java @@ -2,13 +2,20 @@ package bytecode; import org.junit.Test; -public class Matrix_lambdaTest3 { - public final static String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; - public final static String testFile = "Matrix_lambda3.jav"; - public final static String outputFile = "Matrix3.class"; +public class Matrix_lambdaTest3 extends SourceFileBytecodeTest{ + @Override + protected void init() { + testName = "Matrix_lambda3"; + rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; + } @Test - public void test() { - SingleClassTester.compileToBytecode(rootDirectory+testFile, rootDirectory+outputFile); + public void testConstruct() throws Exception{ + ClassLoader classLoader = getClassLoader(); + + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + assertTrue(true); } -} +} \ No newline at end of file diff --git a/test/bytecode/MethodCallTest.java b/test/bytecode/MethodCallTest.java index 96d23eee..c5bfa352 100644 --- a/test/bytecode/MethodCallTest.java +++ b/test/bytecode/MethodCallTest.java @@ -20,15 +20,20 @@ import de.dhbwstuttgart.typeinference.Menge; import de.dhbwstuttgart.typeinference.TypeinferenceResultSet; import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertSet; -public class MethodCallTest { - - public final static String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; - public final static String testFile = "MethodCall.jav"; - public final static String outputFile = "MethodCall.class"; +public class MethodCallTest extends SourceFileBytecodeTest{ + @Override + protected void init() { + testName = "MethodCall"; + rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; + } @Test - public void test() { - SingleClassTester.compileToBytecode(rootDirectory+testFile, rootDirectory+outputFile); - } + public void testConstruct() throws Exception{ + ClassLoader classLoader = getClassLoader(); + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + assertTrue(true); + } } diff --git a/test/bytecode/MethodEmpty.java b/test/bytecode/MethodEmpty.java index 1f6af8be..ce72531b 100644 --- a/test/bytecode/MethodEmpty.java +++ b/test/bytecode/MethodEmpty.java @@ -20,15 +20,20 @@ import de.dhbwstuttgart.typeinference.Menge; import de.dhbwstuttgart.typeinference.TypeinferenceResultSet; import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertSet; -public class MethodEmpty { - - public final static String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; - public final static String testFile = "MethodEmpty.jav"; - public final static String outputFile = "MethodEmpty.class"; +public class MethodEmpty extends SourceFileBytecodeTest{ + @Override + protected void init() { + testName = "MethodEmpty"; + rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; + } @Test - public void test() { - SingleClassTester.compileToBytecode(rootDirectory+testFile, rootDirectory+outputFile); - } + public void testConstruct() throws Exception{ + ClassLoader classLoader = getClassLoader(); -} + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + assertTrue(true); + } +} \ No newline at end of file diff --git a/test/bytecode/MethodEmptyRetType.java b/test/bytecode/MethodEmptyRetType.java index 272e3998..82f8848b 100644 --- a/test/bytecode/MethodEmptyRetType.java +++ b/test/bytecode/MethodEmptyRetType.java @@ -20,15 +20,20 @@ import de.dhbwstuttgart.typeinference.Menge; import de.dhbwstuttgart.typeinference.TypeinferenceResultSet; import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertSet; -public class MethodEmptyRetType { - - public final static String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; - public final static String testFile = "MethodEmptyRetType.jav"; - public final static String outputFile = "MethodEmptyRetType.class"; +public class MethodEmptyRetType extends SourceFileBytecodeTest{ + @Override + protected void init() { + testName = "MethodEmptyRetType"; + rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; + } @Test - public void test() { - SingleClassTester.compileToBytecode(rootDirectory+testFile, rootDirectory+outputFile); - } + public void testConstruct() throws Exception{ + ClassLoader classLoader = getClassLoader(); -} + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + assertTrue(true); + } +} \ No newline at end of file diff --git a/test/bytecode/NewStatementTest.java b/test/bytecode/NewStatementTest.java index 1272c626..6f930699 100644 --- a/test/bytecode/NewStatementTest.java +++ b/test/bytecode/NewStatementTest.java @@ -23,35 +23,20 @@ import de.dhbwstuttgart.typeinference.Menge; import de.dhbwstuttgart.typeinference.TypeinferenceResultSet; import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertSet; -public class NewStatementTest { - - public final static String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; - public final static String testFile = "NewStatement.jav"; - public final static String outputFile = "NewStatement.class"; +public class NewStatementTest extends SourceFileBytecodeTest{ + @Override + protected void init() { + testName = "NewStatement"; + rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; + } @Test - public void test() { - SingleClassTester.compileToBytecode(rootDirectory+testFile, rootDirectory); - } - /* - @Test - public void testUntypedVectorDeclaredMethods() { - try{ - File file = new File(System.getProperty("user.dir")+"/test/bytecode/types/"); - URL url = file.toURL(); - URL[] urls = new URL[]{url}; + public void testConstruct() throws Exception{ + ClassLoader classLoader = getClassLoader(); - ClassLoader classLoader = new URLClassLoader(urls); - - Class untypedVectorTest = classLoader.loadClass("UntypedVector"); - - for(Method method: untypedVectorTest.getDeclaredMethods()){ - System.out.println(method.toGenericString()); - } - }catch(Exception e){ - throw new RuntimeException(e); - } + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + assertTrue(true); } - */ - } diff --git a/test/bytecode/ParameterTest.java b/test/bytecode/ParameterTest.java index cd06eeef..09993db3 100644 --- a/test/bytecode/ParameterTest.java +++ b/test/bytecode/ParameterTest.java @@ -20,15 +20,20 @@ import de.dhbwstuttgart.typeinference.Menge; import de.dhbwstuttgart.typeinference.TypeinferenceResultSet; import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertSet; -public class ParameterTest { - - public final static String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; - public final static String testFile = "Parameter.jav"; - public final static String outputFile = "Parameter.class"; +public class ParameterTest extends SourceFileBytecodeTest{ + @Override + protected void init() { + testName = "Parameter"; + rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; + } @Test - public void test() { - SingleClassTester.compileToBytecode(rootDirectory+testFile, rootDirectory+outputFile); - } + public void testConstruct() throws Exception{ + ClassLoader classLoader = getClassLoader(); -} + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + assertTrue(true); + } +} \ No newline at end of file diff --git a/test/bytecode/PostDecrement.java b/test/bytecode/PostDecrement.java index b0dbee20..6ab8bbf3 100644 --- a/test/bytecode/PostDecrement.java +++ b/test/bytecode/PostDecrement.java @@ -21,16 +21,20 @@ import de.dhbwstuttgart.typeinference.Menge; import de.dhbwstuttgart.typeinference.TypeinferenceResultSet; import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertSet; -public class PostDecrement { - - public final static String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; - public final static String testFile = "PostDecrement.jav"; - public final static String outputFile = "PostDecrement.class"; +public class PostDecrement extends SourceFileBytecodeTest{ + @Override + protected void init() { + testName = "PostDecrement"; + rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; + } @Test - @Ignore - public void test() { - SingleClassTester.compileToBytecode(rootDirectory+testFile, rootDirectory+outputFile); - } + public void testConstruct() throws Exception{ + ClassLoader classLoader = getClassLoader(); -} + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + assertTrue(true); + } +} \ No newline at end of file diff --git a/test/bytecode/PostIncrement.java b/test/bytecode/PostIncrement.java index da1fe1e3..83f189dc 100644 --- a/test/bytecode/PostIncrement.java +++ b/test/bytecode/PostIncrement.java @@ -21,16 +21,20 @@ import de.dhbwstuttgart.typeinference.Menge; import de.dhbwstuttgart.typeinference.TypeinferenceResultSet; import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertSet; -public class PostIncrement { - - public final static String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; - public final static String testFile = "PostIncrement.jav"; - public final static String outputFile = "PostIncrement.class"; +public class PostIncrement extends SourceFileBytecodeTest{ + @Override + protected void init() { + testName = "PostIncrement"; + rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; + } @Test - @Ignore - public void test() { - SingleClassTester.compileToBytecode(rootDirectory+testFile, rootDirectory+outputFile); - } + public void testConstruct() throws Exception{ + ClassLoader classLoader = getClassLoader(); -} + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + assertTrue(true); + } +} \ No newline at end of file diff --git a/test/bytecode/ReturnTest.java b/test/bytecode/ReturnTest.java index a7179e11..cad56bfa 100644 --- a/test/bytecode/ReturnTest.java +++ b/test/bytecode/ReturnTest.java @@ -20,15 +20,20 @@ import de.dhbwstuttgart.typeinference.Menge; import de.dhbwstuttgart.typeinference.TypeinferenceResultSet; import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertSet; -public class ReturnTest { - - public final static String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; - public final static String testFile = "Return.jav"; - public final static String outputFile = "Return.class"; +public class ReturnTest extends SourceFileBytecodeTest{ + @Override + protected void init() { + testName = "Return"; + rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; + } @Test - public void test() { - SingleClassTester.compileToBytecode(rootDirectory+testFile, rootDirectory+outputFile); - } + public void testConstruct() throws Exception{ + ClassLoader classLoader = getClassLoader(); -} + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + assertTrue(true); + } +} \ No newline at end of file diff --git a/test/bytecode/RunnableTest.java b/test/bytecode/RunnableTest.java index 2eb55d85..82b6abc8 100644 --- a/test/bytecode/RunnableTest.java +++ b/test/bytecode/RunnableTest.java @@ -2,13 +2,20 @@ package bytecode; import org.junit.Test; -public class RunnableTest { - public final static String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; - public final static String testFile = "Runnable.jav"; - public final static String outputFile = "Runnable.class"; +public class RunnableTest extends SourceFileBytecodeTest{ + @Override + protected void init() { + testName = "Runnable"; + rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; + } @Test - public void test() { - SingleClassTester.compileToBytecode(rootDirectory+testFile, rootDirectory+outputFile); + public void testConstruct() throws Exception{ + ClassLoader classLoader = getClassLoader(); + + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + assertTrue(true); } -} +} \ No newline at end of file diff --git a/test/bytecode/StringLitTest.java b/test/bytecode/StringLitTest.java index d4d93f19..690968e4 100644 --- a/test/bytecode/StringLitTest.java +++ b/test/bytecode/StringLitTest.java @@ -20,15 +20,20 @@ import de.dhbwstuttgart.typeinference.Menge; import de.dhbwstuttgart.typeinference.TypeinferenceResultSet; import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertSet; -public class StringLitTest { - - public final static String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; - public final static String testFile = "StringLitTest.jav"; - public final static String outputFile = "StringLitTest.class"; +public class StringLitTest extends SourceFileBytecodeTest{ + @Override + protected void init() { + testName = "StringLitTest"; + rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; + } @Test - public void test() { - SingleClassTester.compileToBytecode(rootDirectory+testFile, rootDirectory+outputFile); - } + public void testConstruct() throws Exception{ + ClassLoader classLoader = getClassLoader(); -} + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + assertTrue(true); + } +} \ No newline at end of file diff --git a/test/bytecode/SystemOutPrintlnTest.java b/test/bytecode/SystemOutPrintlnTest.java index b42a21c1..39db74e3 100644 --- a/test/bytecode/SystemOutPrintlnTest.java +++ b/test/bytecode/SystemOutPrintlnTest.java @@ -20,15 +20,20 @@ import de.dhbwstuttgart.typeinference.Menge; import de.dhbwstuttgart.typeinference.TypeinferenceResultSet; import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertSet; -public class SystemOutPrintlnTest { - - public final static String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; - public final static String testFile = "SystemOutPrintln.jav"; - public final static String outputFile = "SystemOutPrintln.class"; +public class SystemOutPrintlnTest extends SourceFileBytecodeTest{ + @Override + protected void init() { + testName = "SystemOutPrintln"; + rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; + } @Test - public void test() { - SingleClassTester.compileToBytecode(rootDirectory+testFile, rootDirectory+outputFile); - } + public void testConstruct() throws Exception{ + ClassLoader classLoader = getClassLoader(); -} + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + assertTrue(true); + } +} \ No newline at end of file diff --git a/test/bytecode/Test3.java b/test/bytecode/Test3.java index 5c1fc6a3..6bc9a737 100644 --- a/test/bytecode/Test3.java +++ b/test/bytecode/Test3.java @@ -1,6 +1,6 @@ class Test3{ public static void main(String[] args){ -System.out.println(new LambdaExpr2().op.apply()); +System.out.println(new LambdaExpr2Test().op.apply()); } } diff --git a/test/bytecode/WhileTest.java b/test/bytecode/WhileTest.java index cd7e4f8f..be51a813 100644 --- a/test/bytecode/WhileTest.java +++ b/test/bytecode/WhileTest.java @@ -2,13 +2,20 @@ package bytecode; import org.junit.Test; -public class WhileTest { - public final static String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; - public final static String testFile = "WhileTest.jav"; - public final static String outputFile = "WhileTest.class"; +public class WhileTest extends SourceFileBytecodeTest{ + @Override + protected void init() { + testName = "WhileTest"; + rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; + } @Test - public void test() { - SingleClassTester.compileToBytecode(rootDirectory+testFile, rootDirectory+outputFile); + public void testConstruct() throws Exception{ + ClassLoader classLoader = getClassLoader(); + + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + assertTrue(true); } -} +} \ No newline at end of file From ba6ae74ad12db7715f6db60a29ff7cfa21ef9471 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Enrico=20Schr=C3=B6dter?= Date: Fri, 29 Apr 2016 10:00:33 +0200 Subject: [PATCH 7/7] =?UTF-8?q?-Tests=20f=C3=BCr=20for=20und=20While=20Sch?= =?UTF-8?q?leife=20korrigiert=20-=20While=20teilweise=20implementiert?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../syntaxtree/statement/ForStmt.java | 4 ---- .../syntaxtree/statement/WhileStmt.java | 20 +++++++++++++++++-- test/bytecode/ForTest.jav | 6 +++--- test/bytecode/WhileTest.jav | 10 ++++++---- 4 files changed, 27 insertions(+), 13 deletions(-) diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/ForStmt.java b/src/de/dhbwstuttgart/syntaxtree/statement/ForStmt.java index eeff85ba..69998638 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/ForStmt.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/ForStmt.java @@ -39,10 +39,6 @@ import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions; import de.dhbwstuttgart.typeinference.exceptions.NotImplementedException; import de.dhbwstuttgart.typeinference.unify.Unify; - - - - public class ForStmt extends Statement { diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/WhileStmt.java b/src/de/dhbwstuttgart/syntaxtree/statement/WhileStmt.java index dd95b912..f9816ade 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/WhileStmt.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/WhileStmt.java @@ -6,7 +6,11 @@ import java.util.Enumeration; import java.util.Hashtable; import java.util.Iterator; +import org.apache.commons.bcel6.generic.BranchInstruction; import org.apache.commons.bcel6.generic.ClassGen; +import org.apache.commons.bcel6.generic.DUP; +import org.apache.commons.bcel6.generic.GOTO; +import org.apache.commons.bcel6.generic.IFEQ; import org.apache.commons.bcel6.generic.InstructionList; import de.dhbwstuttgart.typeinference.Menge; @@ -139,8 +143,20 @@ public class WhileStmt extends Statement @Override public InstructionList genByteCode(ClassGenerator _cg, TypeinferenceResultSet rs) { - // TODO Bytecode - throw new NotImplementedException(); + //TOD: while Statement + InstructionList il = expr.genByteCode(_cg, rs); + + BranchInstruction ifeq = new IFEQ(null); + il.append(ifeq); + + il.append(loop_block.genByteCode(_cg, rs)); + + il.append(new GOTO(il.getStart())); + + ifeq.setTarget(il.append(new DUP())); + + + return il; } } // ino.end diff --git a/test/bytecode/ForTest.jav b/test/bytecode/ForTest.jav index 649b71b0..d2723cf4 100644 --- a/test/bytecode/ForTest.jav +++ b/test/bytecode/ForTest.jav @@ -1,6 +1,6 @@ -class IfElse{ - method(){ - for( i = 0; i < 10 ; i = i++){ +class ForTest{ + void method(){ + for(Integer i = 0; i < 10 ; i = i + 1){ } } diff --git a/test/bytecode/WhileTest.jav b/test/bytecode/WhileTest.jav index 7343a1b8..fa39c905 100644 --- a/test/bytecode/WhileTest.jav +++ b/test/bytecode/WhileTest.jav @@ -1,7 +1,9 @@ -class IfElse{ - method(){ - while(true){ - +class WhileTest{ + void method(){ + Integer i; + i = 1; + while(i < 10){ + i = i + 1; } } } \ No newline at end of file