From bcbe82c64e349d8289ee6cf4e88214029cc3a016 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Enrico=20Schr=C3=B6dter?= Date: Tue, 13 Oct 2015 19:25:51 +0200 Subject: [PATCH 1/9] =?UTF-8?q?Tests=20f=C3=BCr=20verschiedene=20Statement?= =?UTF-8?q?s=20angelegt=20If,=20IfElse=20Implementiert=20Fehlende=20Interf?= =?UTF-8?q?ace=20Implementierungen=20mit=20NotImplementedException=20hinzu?= =?UTF-8?q?gef=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../myexception/NotImplementedException.java | 10 +++++ .../syntaxtree/statement/Binary.java | 11 +++--- .../syntaxtree/statement/BoolLiteral.java | 11 +++--- .../syntaxtree/statement/CastExpr.java | 11 +++--- .../syntaxtree/statement/CharLiteral.java | 11 ++++-- .../syntaxtree/statement/DoubleLiteral.java | 8 ++-- .../syntaxtree/statement/EmptyStmt.java | 9 +++-- .../syntaxtree/statement/FloatLiteral.java | 6 +-- .../syntaxtree/statement/ForStmt.java | 8 ++-- .../syntaxtree/statement/IfStmt.java | 39 +++++++++++++++++-- .../syntaxtree/statement/InstVar.java | 9 +++-- .../syntaxtree/statement/InstanceOf.java | 9 +++-- .../syntaxtree/statement/LongLiteral.java | 6 +-- .../syntaxtree/statement/NegativeExpr.java | 9 +++-- .../syntaxtree/statement/NewArray.java | 8 ++-- .../syntaxtree/statement/NewClass.java | 9 +++-- .../syntaxtree/statement/NotExpr.java | 9 +++-- .../syntaxtree/statement/PositivExpr.java | 9 +++-- .../syntaxtree/statement/PostDecExpr.java | 9 +++-- .../syntaxtree/statement/PostIncExpr.java | 6 ++- .../syntaxtree/statement/PreDecExpr.java | 10 +++-- .../syntaxtree/statement/PreIncExpr.java | 9 +++-- .../syntaxtree/statement/WhileStmt.java | 8 ++-- .../syntaxtree/type/FreshWildcardType.java | 8 +++- .../syntaxtree/type/GenericTypeVar.java | 7 ++++ test/bytecode/ForTest.jav | 7 ++++ test/bytecode/ForTest.java | 14 +++++++ test/bytecode/IfElseIfStatement.jav | 9 +++++ test/bytecode/IfElseIfStatementTest.java | 14 +++++++ test/bytecode/IfElseStatement.jav | 9 +++++ test/bytecode/IfElseStatementTest.java | 14 +++++++ test/bytecode/IfStatement.jav | 7 ++++ test/bytecode/IfStatementTest.java | 14 +++++++ test/bytecode/PostDecrement.jav | 6 +++ test/bytecode/PostDecrement.java | 34 ++++++++++++++++ test/bytecode/WhileTest.jav | 7 ++++ test/bytecode/WhileTest.java | 14 +++++++ 37 files changed, 321 insertions(+), 77 deletions(-) create mode 100644 src/de/dhbwstuttgart/myexception/NotImplementedException.java create mode 100644 test/bytecode/ForTest.jav create mode 100644 test/bytecode/ForTest.java create mode 100644 test/bytecode/IfElseIfStatement.jav create mode 100644 test/bytecode/IfElseIfStatementTest.java create mode 100644 test/bytecode/IfElseStatement.jav create mode 100644 test/bytecode/IfElseStatementTest.java create mode 100644 test/bytecode/IfStatement.jav create mode 100644 test/bytecode/IfStatementTest.java create mode 100644 test/bytecode/PostDecrement.jav create mode 100644 test/bytecode/PostDecrement.java create mode 100644 test/bytecode/WhileTest.jav create mode 100644 test/bytecode/WhileTest.java diff --git a/src/de/dhbwstuttgart/myexception/NotImplementedException.java b/src/de/dhbwstuttgart/myexception/NotImplementedException.java new file mode 100644 index 00000000..bbaf52c6 --- /dev/null +++ b/src/de/dhbwstuttgart/myexception/NotImplementedException.java @@ -0,0 +1,10 @@ +package de.dhbwstuttgart.myexception; + +public class NotImplementedException extends RuntimeException { + + /** + * + */ + private static final long serialVersionUID = 1L; + +} diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/Binary.java b/src/de/dhbwstuttgart/syntaxtree/statement/Binary.java index af54441d..60b2657b 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/Binary.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/Binary.java @@ -10,6 +10,7 @@ import org.apache.commons.bcel6.generic.ClassGen; import org.apache.commons.bcel6.generic.InstructionList; import de.dhbwstuttgart.typeinference.Menge; +import de.dhbwstuttgart.bytecode.ClassGenerator; import de.dhbwstuttgart.logger.Logger; import de.dhbwstuttgart.myexception.CTypeReconstructionException; import de.dhbwstuttgart.myexception.JVMCodeException; @@ -213,11 +214,15 @@ public JavaCodeResult printJavaCode(ResultSet resultSet) { ret.add(this.expr2); return ret; } + + private InstructionList genUnboxByteCode(ClassGen _cg, Type t){ + return null; + } @Override - public InstructionList genByteCode(ClassGen _cg, TypeAssumptions ass) { + public InstructionList genByteCode(ClassGenerator _cg) { InstructionList linkeSeite = this.expr1.genByteCode(_cg); InstructionList rechteSeite = this.expr2.genByteCode(_cg); if(this.getReturnType().getName().equals(new JavaClassName("String"))){ @@ -227,9 +232,5 @@ public JavaCodeResult printJavaCode(ResultSet resultSet) { return null; } - private InstructionList genUnboxByteCode(ClassGen _cg, Type t){ - return null; - } - } // ino.end diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/BoolLiteral.java b/src/de/dhbwstuttgart/syntaxtree/statement/BoolLiteral.java index 806bd1ac..88dcc204 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/BoolLiteral.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/BoolLiteral.java @@ -5,10 +5,12 @@ package de.dhbwstuttgart.syntaxtree.statement; import java.util.Hashtable; import org.apache.commons.bcel6.generic.ClassGen; +import org.apache.commons.bcel6.generic.InstructionConstants; import org.apache.commons.bcel6.generic.InstructionFactory; import org.apache.commons.bcel6.generic.InstructionList; import de.dhbwstuttgart.typeinference.Menge; +import de.dhbwstuttgart.bytecode.ClassGenerator; import de.dhbwstuttgart.logger.Logger; import de.dhbwstuttgart.myexception.CTypeReconstructionException; import de.dhbwstuttgart.myexception.JVMCodeException; @@ -128,17 +130,16 @@ public class BoolLiteral extends Literal } @Override - public InstructionList genByteCode(ClassGen cg) { - InstructionFactory _factory = new InstructionFactory(cg, cg.getConstantPool()); + public InstructionList genByteCode(ClassGenerator _cg) { + InstructionFactory _factory = new InstructionFactory(_cg, _cg.getConstantPool()); InstructionList il = new InstructionList(); if (Bool == true){ - il.append(_factory.ICONST_1); + il.append(InstructionConstants.ICONST_1); }else { - il.append(_factory.ICONST_0); + il.append(InstructionConstants.ICONST_0); } - return il; } diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/CastExpr.java b/src/de/dhbwstuttgart/syntaxtree/statement/CastExpr.java index 13d9c714..e711d876 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/CastExpr.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/CastExpr.java @@ -6,11 +6,14 @@ import java.util.Hashtable; import java.util.Iterator; import org.apache.commons.bcel6.generic.ClassGen; +import org.apache.commons.bcel6.generic.InstructionList; import de.dhbwstuttgart.typeinference.Menge; +import de.dhbwstuttgart.bytecode.ClassGenerator; import de.dhbwstuttgart.logger.Logger; import de.dhbwstuttgart.myexception.CTypeReconstructionException; import de.dhbwstuttgart.myexception.JVMCodeException; +import de.dhbwstuttgart.myexception.NotImplementedException; import de.dhbwstuttgart.myexception.SCExcept; import de.dhbwstuttgart.myexception.SCStatementException; import de.dhbwstuttgart.syntaxtree.Class; @@ -119,12 +122,10 @@ public class CastExpr extends UnaryExpr return ret; } - - @Override - public void genByteCode(ClassGen _cg) { - // TODO Auto-generated method stub - + public InstructionList genByteCode(ClassGenerator _cg) { + // TODO Bytecode + throw new NotImplementedException(); } diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/CharLiteral.java b/src/de/dhbwstuttgart/syntaxtree/statement/CharLiteral.java index c4c87e8e..ead6230b 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/CharLiteral.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/CharLiteral.java @@ -10,6 +10,7 @@ import org.apache.commons.bcel6.generic.InstructionFactory; import org.apache.commons.bcel6.generic.InstructionList; import de.dhbwstuttgart.typeinference.Menge; +import de.dhbwstuttgart.bytecode.ClassGenerator; import de.dhbwstuttgart.logger.Logger; import de.dhbwstuttgart.myexception.CTypeReconstructionException; import de.dhbwstuttgart.myexception.JVMCodeException; @@ -118,12 +119,14 @@ public class CharLiteral extends Literal public char get_Char() // ino.end // ino.method.get_Int.25463.body - { + { return Char; - } + } + + @Override - public InstructionList genByteCode(ClassGen cg) { - InstructionFactory _factory = new InstructionFactory(cg, cg.getConstantPool()); + public InstructionList genByteCode(ClassGenerator _cg) { + InstructionFactory _factory = new InstructionFactory(_cg, _cg.getConstantPool()); InstructionList il = new InstructionList(); il.append(new BIPUSH((byte) get_Char())); return il; diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/DoubleLiteral.java b/src/de/dhbwstuttgart/syntaxtree/statement/DoubleLiteral.java index 1ac8ee43..705f4305 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/DoubleLiteral.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/DoubleLiteral.java @@ -13,6 +13,7 @@ import org.apache.commons.bcel6.generic.LDC; import org.apache.commons.bcel6.generic.LDC2_W; import de.dhbwstuttgart.typeinference.Menge; +import de.dhbwstuttgart.bytecode.ClassGenerator; import de.dhbwstuttgart.logger.Logger; import de.dhbwstuttgart.myexception.CTypeReconstructionException; import de.dhbwstuttgart.myexception.JVMCodeException; @@ -142,17 +143,16 @@ public JavaCodeResult printJavaCode(ResultSet resultSet) { il.append(new BIPUSH(new Double(get_Double()).byteValue())); return il; }*/ - + @Override - public InstructionList genByteCode(ClassGen cg) { - ConstantPoolGen cp = cg.getConstantPool(); + public InstructionList genByteCode(ClassGenerator _cg) { + ConstantPoolGen cp = _cg.getConstantPool(); //InstructionFactory _factory = new InstructionFactory(cg, cp); InstructionList il = new InstructionList(); cp.addDouble(get_Double()); il.append(new LDC2_W(cp.getSize()-1)); return il; - } } diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/EmptyStmt.java b/src/de/dhbwstuttgart/syntaxtree/statement/EmptyStmt.java index 4eb7c37d..f1a96b3e 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/EmptyStmt.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/EmptyStmt.java @@ -5,8 +5,10 @@ package de.dhbwstuttgart.syntaxtree.statement; import java.util.Hashtable; import org.apache.commons.bcel6.generic.ClassGen; +import org.apache.commons.bcel6.generic.InstructionList; import de.dhbwstuttgart.typeinference.Menge; +import de.dhbwstuttgart.bytecode.ClassGenerator; import de.dhbwstuttgart.logger.Logger; import de.dhbwstuttgart.myexception.CTypeReconstructionException; import de.dhbwstuttgart.myexception.JVMCodeException; @@ -86,11 +88,10 @@ public class EmptyStmt extends Statement return new Menge(); } - @Override - public void genByteCode(ClassGen _cg) { - // TODO Auto-generated method stub - + public InstructionList genByteCode(ClassGenerator _cg) { + // TODO Bytecode + throw new NotImplementedException(); } } diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/FloatLiteral.java b/src/de/dhbwstuttgart/syntaxtree/statement/FloatLiteral.java index be8d12a8..55c26b41 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/FloatLiteral.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/FloatLiteral.java @@ -11,6 +11,7 @@ import org.apache.commons.bcel6.generic.LDC; import org.apache.commons.bcel6.generic.LDC2_W; import de.dhbwstuttgart.typeinference.Menge; +import de.dhbwstuttgart.bytecode.ClassGenerator; import de.dhbwstuttgart.logger.Logger; import de.dhbwstuttgart.myexception.CTypeReconstructionException; import de.dhbwstuttgart.myexception.JVMCodeException; @@ -132,14 +133,13 @@ public JavaCodeResult printJavaCode(ResultSet resultSet) { } @Override - public InstructionList genByteCode(ClassGen cg) { - ConstantPoolGen cp = cg.getConstantPool(); + public InstructionList genByteCode(ClassGenerator _cg) { + ConstantPoolGen cp = _cg.getConstantPool(); InstructionList il = new InstructionList(); cp.addFloat(get_Float()); il.append(new LDC(cp.getSize()-1)); return il; - } } // ino.end diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/ForStmt.java b/src/de/dhbwstuttgart/syntaxtree/statement/ForStmt.java index 72da14d6..6f5ab521 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/ForStmt.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/ForStmt.java @@ -5,8 +5,10 @@ import java.util.Hashtable; import java.util.Iterator; import org.apache.commons.bcel6.generic.ClassGen; +import org.apache.commons.bcel6.generic.InstructionList; import de.dhbwstuttgart.typeinference.Menge; +import de.dhbwstuttgart.bytecode.ClassGenerator; import de.dhbwstuttgart.logger.Logger; import de.dhbwstuttgart.myexception.CTypeReconstructionException; import de.dhbwstuttgart.myexception.JVMCodeException; @@ -118,8 +120,8 @@ public JavaCodeResult printJavaCode(ResultSet resultSet) { } @Override - public void genByteCode(ClassGen _cg) { - // TODO Auto-generated method stub - + public InstructionList genByteCode(ClassGenerator _cg) { + // TODO Bytecode + throw new NotImplementedException(); } } \ No newline at end of file diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/IfStmt.java b/src/de/dhbwstuttgart/syntaxtree/statement/IfStmt.java index b897ce02..a8eac123 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/IfStmt.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/IfStmt.java @@ -6,10 +6,26 @@ import java.util.Enumeration; import java.util.Hashtable; import java.util.Iterator; +import org.apache.commons.bcel6.Constants; +import org.apache.commons.bcel6.generic.ALOAD; +import org.apache.commons.bcel6.generic.ASTORE; +import org.apache.commons.bcel6.generic.BranchInstruction; import org.apache.commons.bcel6.generic.ClassGen; +import org.apache.commons.bcel6.generic.GOTO; +import org.apache.commons.bcel6.generic.GotoInstruction; +import org.apache.commons.bcel6.generic.IFEQ; +import org.apache.commons.bcel6.generic.IFNONNULL; +import org.apache.commons.bcel6.generic.IfInstruction; +import org.apache.commons.bcel6.generic.Instruction; +import org.apache.commons.bcel6.generic.InstructionFactory; +import org.apache.commons.bcel6.generic.InstructionHandle; +import org.apache.commons.bcel6.generic.InstructionList; +import org.apache.commons.bcel6.generic.NOP; import de.dhbwstuttgart.typeinference.Menge; +import de.dhbwstuttgart.bytecode.ClassGenerator; import de.dhbwstuttgart.logger.Logger; +import de.dhbwstuttgart.logger.Section; import de.dhbwstuttgart.myexception.CTypeReconstructionException; import de.dhbwstuttgart.myexception.JVMCodeException; import de.dhbwstuttgart.myexception.SCExcept; @@ -161,12 +177,27 @@ public class IfStmt extends Statement return ret; } - - @Override - public void genByteCode(ClassGen _cg) { - // TODO Auto-generated method stub + public InstructionList genByteCode(ClassGenerator _cg) { + InstructionFactory _factory = new InstructionFactory(_cg, _cg.getConstantPool()); + InstructionList il = new InstructionList(); + IfInstruction ifInstruction = new IFEQ(null); + + il.append(expr.genByteCode(_cg)); + il.append(ifInstruction); + il.append(then_block.genByteCode(_cg)); + + if(else_block != null && !(else_block instanceof EmptyStmt)){ + GotoInstruction gotoInstruction = new GOTO(null); + il.append(gotoInstruction); + ifInstruction.setTarget(il.append(else_block.genByteCode(_cg))); + gotoInstruction.setTarget(il.append(new NOP())); + }else{ + ifInstruction.setTarget(il.append(new NOP())); + } + + return il; } } // ino.end diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/InstVar.java b/src/de/dhbwstuttgart/syntaxtree/statement/InstVar.java index c2e09b72..368db431 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/InstVar.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/InstVar.java @@ -7,11 +7,14 @@ import java.util.Hashtable; import java.util.Iterator; import org.apache.commons.bcel6.generic.ClassGen; +import org.apache.commons.bcel6.generic.InstructionList; import de.dhbwstuttgart.typeinference.Menge; +import de.dhbwstuttgart.bytecode.ClassGenerator; import de.dhbwstuttgart.logger.Logger; import de.dhbwstuttgart.myexception.CTypeReconstructionException; import de.dhbwstuttgart.myexception.JVMCodeException; +import de.dhbwstuttgart.myexception.NotImplementedException; import de.dhbwstuttgart.syntaxtree.Class; import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode; import de.dhbwstuttgart.syntaxtree.misc.UsedId; @@ -217,9 +220,9 @@ public class InstVar extends Expr } @Override - public void genByteCode(ClassGen _cg) { - // TODO Auto-generated method stub - + public InstructionList genByteCode(ClassGenerator _cg) { + // TODO Bytecode + throw new NotImplementedException(); } } // ino.end diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/InstanceOf.java b/src/de/dhbwstuttgart/syntaxtree/statement/InstanceOf.java index c541a2ef..b3939f4c 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/InstanceOf.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/InstanceOf.java @@ -6,11 +6,14 @@ import java.util.Enumeration; import java.util.Hashtable; import org.apache.commons.bcel6.generic.ClassGen; +import org.apache.commons.bcel6.generic.InstructionList; import de.dhbwstuttgart.typeinference.Menge; +import de.dhbwstuttgart.bytecode.ClassGenerator; import de.dhbwstuttgart.logger.Logger; import de.dhbwstuttgart.myexception.CTypeReconstructionException; import de.dhbwstuttgart.myexception.JVMCodeException; +import de.dhbwstuttgart.myexception.NotImplementedException; import de.dhbwstuttgart.myexception.SCStatementException; import de.dhbwstuttgart.syntaxtree.Class; import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode; @@ -116,9 +119,9 @@ public JavaCodeResult printJavaCode(ResultSet resultSet) { } @Override - public void genByteCode(ClassGen _cg) { - // TODO Auto-generated method stub - + public InstructionList genByteCode(ClassGenerator _cg) { + // TODO Bytecode + throw new NotImplementedException(); } diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/LongLiteral.java b/src/de/dhbwstuttgart/syntaxtree/statement/LongLiteral.java index 8aac0961..2d3c7910 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/LongLiteral.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/LongLiteral.java @@ -10,6 +10,7 @@ import org.apache.commons.bcel6.generic.InstructionList; import org.apache.commons.bcel6.generic.LDC2_W; import de.dhbwstuttgart.typeinference.Menge; +import de.dhbwstuttgart.bytecode.ClassGenerator; import de.dhbwstuttgart.logger.Logger; import de.dhbwstuttgart.myexception.CTypeReconstructionException; import de.dhbwstuttgart.myexception.JVMCodeException; @@ -128,15 +129,14 @@ public JavaCodeResult printJavaCode(ResultSet resultSet) { } @Override - public InstructionList genByteCode(ClassGen cg) { - ConstantPoolGen cp = cg.getConstantPool(); + public InstructionList genByteCode(ClassGenerator _cg) { + ConstantPoolGen cp = _cg.getConstantPool(); //InstructionFactory _factory = new InstructionFactory(cg, cp); InstructionList il = new InstructionList(); cp.addLong(get_Long()); il.append(new LDC2_W(cp.getSize()-1)); return il; - } } // ino.end diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/NegativeExpr.java b/src/de/dhbwstuttgart/syntaxtree/statement/NegativeExpr.java index 2f19b975..b4f592a1 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/NegativeExpr.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/NegativeExpr.java @@ -6,11 +6,14 @@ import java.util.Hashtable; import java.util.Iterator; import org.apache.commons.bcel6.generic.ClassGen; +import org.apache.commons.bcel6.generic.InstructionList; import de.dhbwstuttgart.typeinference.Menge; +import de.dhbwstuttgart.bytecode.ClassGenerator; import de.dhbwstuttgart.logger.Logger; import de.dhbwstuttgart.myexception.CTypeReconstructionException; import de.dhbwstuttgart.myexception.JVMCodeException; +import de.dhbwstuttgart.myexception.NotImplementedException; import de.dhbwstuttgart.myexception.SCExcept; import de.dhbwstuttgart.myexception.SCStatementException; import de.dhbwstuttgart.syntaxtree.Class; @@ -109,9 +112,9 @@ public class NegativeExpr extends UnaryExpr } @Override - public void genByteCode(ClassGen _cg) { - // TODO Auto-generated method stub - + public InstructionList genByteCode(ClassGenerator _cg) { + // TODO Bytecode + throw new NotImplementedException(); } } diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/NewArray.java b/src/de/dhbwstuttgart/syntaxtree/statement/NewArray.java index 630ca25f..c99cfe6c 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/NewArray.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/NewArray.java @@ -9,6 +9,7 @@ import org.apache.commons.bcel6.generic.InstructionFactory; import org.apache.commons.bcel6.generic.InstructionList; import de.dhbwstuttgart.typeinference.Menge; +import de.dhbwstuttgart.bytecode.ClassGenerator; import de.dhbwstuttgart.logger.Logger; import de.dhbwstuttgart.myexception.CTypeReconstructionException; import de.dhbwstuttgart.myexception.JVMCodeException; @@ -146,12 +147,11 @@ public JavaCodeResult printJavaCode(ResultSet resultSet) { } @Override - public InstructionList genByteCode(ClassGen cg) { - - InstructionFactory _factory = new InstructionFactory(cg, cg.getConstantPool()); + public InstructionList genByteCode(ClassGenerator _cg) { + InstructionFactory _factory = new InstructionFactory(_cg, _cg.getConstantPool()); InstructionList il = new InstructionList(); - il.append(expr.elementAt(0).genByteCode(cg)); + il.append(expr.elementAt(0).genByteCode(_cg)); il.append(_factory.createNewArray( org.apache.commons.bcel6.generic.Type.getType(getTypeName()), (short)1)); diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/NewClass.java b/src/de/dhbwstuttgart/syntaxtree/statement/NewClass.java index 22fdf209..cc6d68b3 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/NewClass.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/NewClass.java @@ -7,11 +7,14 @@ import java.util.Hashtable; import java.util.Iterator; import org.apache.commons.bcel6.generic.ClassGen; +import org.apache.commons.bcel6.generic.InstructionList; import de.dhbwstuttgart.typeinference.Menge; +import de.dhbwstuttgart.bytecode.ClassGenerator; import de.dhbwstuttgart.logger.Logger; import de.dhbwstuttgart.myexception.CTypeReconstructionException; import de.dhbwstuttgart.myexception.JVMCodeException; +import de.dhbwstuttgart.myexception.NotImplementedException; import de.dhbwstuttgart.myexception.SCExcept; import de.dhbwstuttgart.myexception.SCStatementException; import de.dhbwstuttgart.syntaxtree.Class; @@ -204,9 +207,9 @@ public class NewClass extends Expr } @Override - public void genByteCode(ClassGen _cg) { - // TODO Auto-generated method stub - + public InstructionList genByteCode(ClassGenerator _cg) { + // TODO Bytecode + throw new NotImplementedException(); } diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/NotExpr.java b/src/de/dhbwstuttgart/syntaxtree/statement/NotExpr.java index ca22f922..8b3563c6 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/NotExpr.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/NotExpr.java @@ -6,11 +6,14 @@ import java.util.Hashtable; import java.util.Iterator; import org.apache.commons.bcel6.generic.ClassGen; +import org.apache.commons.bcel6.generic.InstructionList; import de.dhbwstuttgart.typeinference.Menge; +import de.dhbwstuttgart.bytecode.ClassGenerator; import de.dhbwstuttgart.logger.Logger; import de.dhbwstuttgart.myexception.CTypeReconstructionException; import de.dhbwstuttgart.myexception.JVMCodeException; +import de.dhbwstuttgart.myexception.NotImplementedException; import de.dhbwstuttgart.myexception.SCStatementException; import de.dhbwstuttgart.syntaxtree.Class; import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode; @@ -133,9 +136,9 @@ public JavaCodeResult printJavaCode(ResultSet resultSet) { } @Override - public void genByteCode(ClassGen _cg) { - // TODO Auto-generated method stub - + public InstructionList genByteCode(ClassGenerator _cg) { + // TODO Bytecode + throw new NotImplementedException(); } } diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/PositivExpr.java b/src/de/dhbwstuttgart/syntaxtree/statement/PositivExpr.java index 0ff9198f..2aa6ef6a 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/PositivExpr.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/PositivExpr.java @@ -5,11 +5,14 @@ package de.dhbwstuttgart.syntaxtree.statement; import java.util.Hashtable; import org.apache.commons.bcel6.generic.ClassGen; +import org.apache.commons.bcel6.generic.InstructionList; import de.dhbwstuttgart.typeinference.Menge; +import de.dhbwstuttgart.bytecode.ClassGenerator; import de.dhbwstuttgart.logger.Logger; import de.dhbwstuttgart.myexception.CTypeReconstructionException; import de.dhbwstuttgart.myexception.JVMCodeException; +import de.dhbwstuttgart.myexception.NotImplementedException; import de.dhbwstuttgart.syntaxtree.Class; import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode; import de.dhbwstuttgart.syntaxtree.type.GenericTypeVar; @@ -117,9 +120,9 @@ public JavaCodeResult printJavaCode(ResultSet resultSet) { } @Override - public void genByteCode(ClassGen _cg) { - // TODO Auto-generated method stub - + public InstructionList genByteCode(ClassGenerator _cg) { + // TODO Bytecode + throw new NotImplementedException(); } } diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/PostDecExpr.java b/src/de/dhbwstuttgart/syntaxtree/statement/PostDecExpr.java index c5fb39d8..1b327256 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/PostDecExpr.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/PostDecExpr.java @@ -6,11 +6,14 @@ import java.util.Hashtable; import java.util.Iterator; import org.apache.commons.bcel6.generic.ClassGen; +import org.apache.commons.bcel6.generic.InstructionList; import de.dhbwstuttgart.typeinference.Menge; +import de.dhbwstuttgart.bytecode.ClassGenerator; import de.dhbwstuttgart.logger.Logger; import de.dhbwstuttgart.myexception.CTypeReconstructionException; import de.dhbwstuttgart.myexception.JVMCodeException; +import de.dhbwstuttgart.myexception.NotImplementedException; import de.dhbwstuttgart.myexception.SCExcept; import de.dhbwstuttgart.myexception.SCStatementException; import de.dhbwstuttgart.syntaxtree.Class; @@ -90,9 +93,9 @@ public JavaCodeResult printJavaCode(ResultSet resultSet) { } @Override - public void genByteCode(ClassGen _cg) { - // TODO Auto-generated method stub - + public InstructionList genByteCode(ClassGenerator _cg) { + // TODO Bytecode + throw new NotImplementedException(); } } diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/PostIncExpr.java b/src/de/dhbwstuttgart/syntaxtree/statement/PostIncExpr.java index e8226319..2eab1c72 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/PostIncExpr.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/PostIncExpr.java @@ -12,6 +12,7 @@ import org.apache.commons.bcel6.generic.InstructionFactory; import org.apache.commons.bcel6.generic.InstructionList; import de.dhbwstuttgart.typeinference.Menge; +import de.dhbwstuttgart.bytecode.ClassGenerator; import de.dhbwstuttgart.logger.Logger; import de.dhbwstuttgart.myexception.CTypeReconstructionException; import de.dhbwstuttgart.myexception.JVMCodeException; @@ -100,9 +101,10 @@ public JavaCodeResult printJavaCode(ResultSet resultSet) { } public static int counterPostInc = 0; + @Override - public InstructionList genByteCode(ClassGen cg) { - InstructionFactory _factory = new InstructionFactory(cg, cg.getConstantPool()); + public InstructionList genByteCode(ClassGenerator _cg) { + InstructionFactory _factory = new InstructionFactory(_cg, _cg.getConstantPool()); InstructionList il = new InstructionList(); counterPostInc++; il.append(new IINC(counterPostInc,1)); diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/PreDecExpr.java b/src/de/dhbwstuttgart/syntaxtree/statement/PreDecExpr.java index 54d7abc9..00afda78 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/PreDecExpr.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/PreDecExpr.java @@ -6,11 +6,14 @@ import java.util.Hashtable; import java.util.Iterator; import org.apache.commons.bcel6.generic.ClassGen; +import org.apache.commons.bcel6.generic.InstructionList; import de.dhbwstuttgart.typeinference.Menge; +import de.dhbwstuttgart.bytecode.ClassGenerator; import de.dhbwstuttgart.logger.Logger; import de.dhbwstuttgart.myexception.CTypeReconstructionException; import de.dhbwstuttgart.myexception.JVMCodeException; +import de.dhbwstuttgart.myexception.NotImplementedException; import de.dhbwstuttgart.myexception.SCExcept; import de.dhbwstuttgart.myexception.SCStatementException; import de.dhbwstuttgart.syntaxtree.Class; @@ -87,10 +90,11 @@ public class PreDecExpr extends UnaryExpr ret.add(this.expr); return ret; } + @Override - public void genByteCode(ClassGen _cg) { - // TODO Auto-generated method stub - + public InstructionList genByteCode(ClassGenerator _cg) { + // TODO Bytecode + throw new NotImplementedException(); } } diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/PreIncExpr.java b/src/de/dhbwstuttgart/syntaxtree/statement/PreIncExpr.java index 49824e5a..4005523e 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/PreIncExpr.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/PreIncExpr.java @@ -6,11 +6,14 @@ import java.util.Hashtable; import java.util.Iterator; import org.apache.commons.bcel6.generic.ClassGen; +import org.apache.commons.bcel6.generic.InstructionList; import de.dhbwstuttgart.typeinference.Menge; +import de.dhbwstuttgart.bytecode.ClassGenerator; import de.dhbwstuttgart.logger.Logger; import de.dhbwstuttgart.myexception.CTypeReconstructionException; import de.dhbwstuttgart.myexception.JVMCodeException; +import de.dhbwstuttgart.myexception.NotImplementedException; import de.dhbwstuttgart.myexception.SCExcept; import de.dhbwstuttgart.myexception.SCStatementException; import de.dhbwstuttgart.syntaxtree.Class; @@ -91,9 +94,9 @@ public JavaCodeResult printJavaCode(ResultSet resultSet) { } @Override - public void genByteCode(ClassGen _cg) { - // TODO Auto-generated method stub - + public InstructionList genByteCode(ClassGenerator _cg) { + // TODO Bytecode + throw new NotImplementedException(); } } diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/WhileStmt.java b/src/de/dhbwstuttgart/syntaxtree/statement/WhileStmt.java index 29496d9d..771ea7ad 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/WhileStmt.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/WhileStmt.java @@ -7,8 +7,10 @@ import java.util.Hashtable; import java.util.Iterator; import org.apache.commons.bcel6.generic.ClassGen; +import org.apache.commons.bcel6.generic.InstructionList; import de.dhbwstuttgart.typeinference.Menge; +import de.dhbwstuttgart.bytecode.ClassGenerator; import de.dhbwstuttgart.logger.Logger; import de.dhbwstuttgart.myexception.CTypeReconstructionException; import de.dhbwstuttgart.myexception.JVMCodeException; @@ -135,9 +137,9 @@ public class WhileStmt extends Statement } @Override - public void genByteCode(ClassGen _cg) { - // TODO Auto-generated method stub - + public InstructionList genByteCode(ClassGenerator _cg) { + // TODO Bytecode + throw new NotImplementedException(); } } // ino.end diff --git a/src/de/dhbwstuttgart/syntaxtree/type/FreshWildcardType.java b/src/de/dhbwstuttgart/syntaxtree/type/FreshWildcardType.java index fc5c7338..33f153e0 100755 --- a/src/de/dhbwstuttgart/syntaxtree/type/FreshWildcardType.java +++ b/src/de/dhbwstuttgart/syntaxtree/type/FreshWildcardType.java @@ -1,7 +1,7 @@ package de.dhbwstuttgart.syntaxtree.type; import de.dhbwstuttgart.typeinference.Menge; - +import de.dhbwstuttgart.bytecode.ClassGenerator; import de.dhbwstuttgart.parser.JavaClassName; import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode; import de.dhbwstuttgart.typeinference.JavaCodeResult; @@ -170,4 +170,10 @@ public class FreshWildcardType extends Type { public JavaCodeResult printJavaCode(ResultSet resultSet) { throw new NotImplementedException(); } + + @Override + public org.apache.commons.bcel6.generic.Type getBytecodeType(ClassGenerator cg) { + // TODO: Bytecode + return null; + } } diff --git a/src/de/dhbwstuttgart/syntaxtree/type/GenericTypeVar.java b/src/de/dhbwstuttgart/syntaxtree/type/GenericTypeVar.java index f97dc6dd..9a4af3d1 100755 --- a/src/de/dhbwstuttgart/syntaxtree/type/GenericTypeVar.java +++ b/src/de/dhbwstuttgart/syntaxtree/type/GenericTypeVar.java @@ -17,6 +17,7 @@ import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions; import de.dhbwstuttgart.typeinference.exceptions.DebugException; import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException; import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertPoint; +import de.dhbwstuttgart.bytecode.ClassGenerator; import de.dhbwstuttgart.parser.JavaClassName; import de.dhbwstuttgart.syntaxtree.Class; import de.dhbwstuttgart.syntaxtree.GTVDeclarationContext; @@ -229,6 +230,12 @@ public class GenericTypeVar extends ObjectType public GTVDeclarationContext getDeclarationContext() { return this.getGTVDeclarationContext(); } + + @Override + public org.apache.commons.bcel6.generic.Type getBytecodeType(ClassGenerator cg) { + // TODO Bytecode + return null; + } } diff --git a/test/bytecode/ForTest.jav b/test/bytecode/ForTest.jav new file mode 100644 index 00000000..7343a1b8 --- /dev/null +++ b/test/bytecode/ForTest.jav @@ -0,0 +1,7 @@ +class IfElse{ + method(){ + while(true){ + + } + } +} \ No newline at end of file diff --git a/test/bytecode/ForTest.java b/test/bytecode/ForTest.java new file mode 100644 index 00000000..fea1e7c5 --- /dev/null +++ b/test/bytecode/ForTest.java @@ -0,0 +1,14 @@ +package bytecode; + +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"; + + @Test + public void test() { + SingleClassTester.compileToBytecode(rootDirectory+testFile, rootDirectory+outputFile); + } +} diff --git a/test/bytecode/IfElseIfStatement.jav b/test/bytecode/IfElseIfStatement.jav new file mode 100644 index 00000000..50ad49af --- /dev/null +++ b/test/bytecode/IfElseIfStatement.jav @@ -0,0 +1,9 @@ +class IfElseStatement{ + method(flag){ + if(flag){ + + }else if(flag){ + + } + } +} \ No newline at end of file diff --git a/test/bytecode/IfElseIfStatementTest.java b/test/bytecode/IfElseIfStatementTest.java new file mode 100644 index 00000000..0566b98f --- /dev/null +++ b/test/bytecode/IfElseIfStatementTest.java @@ -0,0 +1,14 @@ +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"; + + @Test + public void test() { + SingleClassTester.compileToBytecode(rootDirectory+testFile, rootDirectory+outputFile); + } +} diff --git a/test/bytecode/IfElseStatement.jav b/test/bytecode/IfElseStatement.jav new file mode 100644 index 00000000..82c9d5a8 --- /dev/null +++ b/test/bytecode/IfElseStatement.jav @@ -0,0 +1,9 @@ +class IfElseStatement{ + method(flag){ + if(flag){ + + }else{ + + } + } +} \ No newline at end of file diff --git a/test/bytecode/IfElseStatementTest.java b/test/bytecode/IfElseStatementTest.java new file mode 100644 index 00000000..4f8750a0 --- /dev/null +++ b/test/bytecode/IfElseStatementTest.java @@ -0,0 +1,14 @@ +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"; + + @Test + public void test() { + SingleClassTester.compileToBytecode(rootDirectory+testFile, rootDirectory+outputFile); + } +} diff --git a/test/bytecode/IfStatement.jav b/test/bytecode/IfStatement.jav new file mode 100644 index 00000000..476c9bc0 --- /dev/null +++ b/test/bytecode/IfStatement.jav @@ -0,0 +1,7 @@ +class IfStatement{ + method(flag){ + if(flag){ + + } + } +} \ No newline at end of file diff --git a/test/bytecode/IfStatementTest.java b/test/bytecode/IfStatementTest.java new file mode 100644 index 00000000..e38d5a1d --- /dev/null +++ b/test/bytecode/IfStatementTest.java @@ -0,0 +1,14 @@ +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"; + + @Test + public void test() { + SingleClassTester.compileToBytecode(rootDirectory+testFile, rootDirectory+outputFile); + } +} diff --git a/test/bytecode/PostDecrement.jav b/test/bytecode/PostDecrement.jav new file mode 100644 index 00000000..7622014f --- /dev/null +++ b/test/bytecode/PostDecrement.jav @@ -0,0 +1,6 @@ +class PostIncrement{ + +void method() {a; a = 20; a--;} + + +} \ No newline at end of file diff --git a/test/bytecode/PostDecrement.java b/test/bytecode/PostDecrement.java new file mode 100644 index 00000000..075cf135 --- /dev/null +++ b/test/bytecode/PostDecrement.java @@ -0,0 +1,34 @@ +package bytecode; + +import static org.junit.Assert.*; + +import java.io.File; +import java.io.IOException; + +import junit.framework.TestCase; + +import org.junit.Test; + +import plugindevelopment.TypeInsertTester; +import de.dhbwstuttgart.core.MyCompiler; +import de.dhbwstuttgart.core.MyCompilerAPI; +import de.dhbwstuttgart.logger.LoggerConfiguration; +import de.dhbwstuttgart.logger.Section; +import de.dhbwstuttgart.parser.JavaParser.yyException; +import de.dhbwstuttgart.typeinference.ByteCodeResult; +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"; + + @Test + public void test() { + SingleClassTester.compileToBytecode(rootDirectory+testFile, rootDirectory+outputFile); + } + +} diff --git a/test/bytecode/WhileTest.jav b/test/bytecode/WhileTest.jav new file mode 100644 index 00000000..7343a1b8 --- /dev/null +++ b/test/bytecode/WhileTest.jav @@ -0,0 +1,7 @@ +class IfElse{ + method(){ + while(true){ + + } + } +} \ No newline at end of file diff --git a/test/bytecode/WhileTest.java b/test/bytecode/WhileTest.java new file mode 100644 index 00000000..cd7e4f8f --- /dev/null +++ b/test/bytecode/WhileTest.java @@ -0,0 +1,14 @@ +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"; + + @Test + public void test() { + SingleClassTester.compileToBytecode(rootDirectory+testFile, rootDirectory+outputFile); + } +} From e104b2e37916d3e10c76c69ccfb860c2fcbefb0d Mon Sep 17 00:00:00 2001 From: JanUlrich Date: Thu, 15 Oct 2015 13:56:12 +0200 Subject: [PATCH 2/9] =?UTF-8?q?Test=20anf=C3=BCgen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../.LambdaTest2_3.jav.log.swp | Bin 0 -> 69632 bytes .../TypeInsertTests/LambdaTest2_3.jav | 5 ++++ .../TypeInsertTests/LambdaTest2_3.java | 23 ++++++++++++++++++ 3 files changed, 28 insertions(+) create mode 100644 test/plugindevelopment/TypeInsertTests/.LambdaTest2_3.jav.log.swp create mode 100644 test/plugindevelopment/TypeInsertTests/LambdaTest2_3.jav create mode 100644 test/plugindevelopment/TypeInsertTests/LambdaTest2_3.java diff --git a/test/plugindevelopment/TypeInsertTests/.LambdaTest2_3.jav.log.swp b/test/plugindevelopment/TypeInsertTests/.LambdaTest2_3.jav.log.swp new file mode 100644 index 0000000000000000000000000000000000000000..457a36417383307ca69e0830c90be29a51cf2880 GIT binary patch literal 69632 zcmeI&2XvIxy8rQ^s&r7m1`I_7flw6)Z9)hk5PImKgk(YjAqmNZ-V{ZOf`Eu12o?kp z3nBv26i`G|z=9M3u~96jAVu08oZoZK-Cxe-p1b~s|G8`3u-1_BndkZKcklhaGn1LV zHM_*L@zx8g>k0lV=J9-WpkSA%LP?&V@Ai25$ERhdW~L-0U$(3KOHEIRPfbqG3WWXj zU1Ivc_>{DNaR1SNYgnVXf3QC_J!7ChEl|UskeZT_4W=ape3eX9oUn&Ol*Lo!Yf(UOx7U70P>WEYbP@<}~CSbHzq@SOX7t_Sp z{1ld3|1fwF`BBx!!i&ncX`=hXPh1N9%dPv3mfO7iF27YiR&MwIOJN##OQ4LIY^ZW#_2LDlhyYge;$58KwAC=qqAA}!4{Q~%5)USj8fcky# z@8$J0{xk6JG}0 z1M+BjCGBI&-!E?}9{~Rfz68Ec?o<6y_+EJvc@oAKMej6`mcmfeR*@uPXj&R zSpIu*Tc1(z&G2{No6tXx9?ON73$@x2Hi179e&@o#{?Ah+x1 z1^Dym-{?j+|2fo;gg=Y=HSh&;8{awjeDrUiCn9$I&%lSm=gDpVu7uB(M`(V}!=IMh z^`~)3_xR_??fe-FpN;y>@TcUhm496+xBo1;txrezlkjQqnR1)o9q=bmU!=5~KLg$d zJ{|oZg-=8Mhw#VcJ{|uJH@o>$<&ESq@G0p3F#IujwCXp*A4UIyx48L}<+lFO@JVu8 z|4HzPsQ&~$0rkc8Ldy2{Bk<1f@p9WAv*8cJcf%i&+x(Ws>+o@??*xBPo=5XL9j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/null +++ b/test/plugindevelopment/TypeInsertTests/LambdaTest2_3.jav @@ -0,0 +1,5 @@ +class LambdaTest{ + +op = (m) -> (f) -> {f.apply(this,m); return this;}; + +} diff --git a/test/plugindevelopment/TypeInsertTests/LambdaTest2_3.java b/test/plugindevelopment/TypeInsertTests/LambdaTest2_3.java new file mode 100644 index 00000000..e7cfc2ca --- /dev/null +++ b/test/plugindevelopment/TypeInsertTests/LambdaTest2_3.java @@ -0,0 +1,23 @@ +package plugindevelopment.TypeInsertTests; + +import de.dhbwstuttgart.typeinference.Menge; + +import org.junit.Test; + +import de.dhbwstuttgart.logger.Logger; +import de.dhbwstuttgart.logger.LoggerConfiguration; +import de.dhbwstuttgart.logger.Section; + +public class LambdaTest2_3 { + + private static final String TEST_FILE = "LambdaTest2_3.jav"; + + @Test + public void run(){ + Menge mustContain = new Menge(); + //mustContain.add("S m"); + MultipleTypesInsertTester.test(this.TEST_FILE, mustContain, + new LoggerConfiguration().setOutput(Section.ASSUMPTIONS, System.out)); + } + +} From a541b353cd8609ce97811a8caafa8ea2f7ceab4b Mon Sep 17 00:00:00 2001 From: JanUlrich Date: Thu, 15 Oct 2015 16:15:13 +0200 Subject: [PATCH 3/9] =?UTF-8?q?=C3=84nderungen=20an=20IFStmt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BCEL/bcelifier/BooleanValue.java | 6 ++ BCEL/bcelifier/BooleanValueCreator.java | 63 +++++++++++++++++++ BCEL/bcelifier/JavaToBCEL.java | 1 + .../syntaxtree/statement/IfStmt.java | 2 + .../syntaxtree/type/RefType.java | 2 +- test/bytecode/IfElseStatement.jav | 4 +- test/bytecode/IfTest.java | 9 +++ 7 files changed, 84 insertions(+), 3 deletions(-) create mode 100644 BCEL/bcelifier/BooleanValue.java create mode 100644 BCEL/bcelifier/BooleanValueCreator.java create mode 100644 test/bytecode/IfTest.java diff --git a/BCEL/bcelifier/BooleanValue.java b/BCEL/bcelifier/BooleanValue.java new file mode 100644 index 00000000..f6859aeb --- /dev/null +++ b/BCEL/bcelifier/BooleanValue.java @@ -0,0 +1,6 @@ +package bcelifier; + +public class BooleanValue { + Boolean c = true; + Boolean b = c.booleanValue(); +} diff --git a/BCEL/bcelifier/BooleanValueCreator.java b/BCEL/bcelifier/BooleanValueCreator.java new file mode 100644 index 00000000..d019f948 --- /dev/null +++ b/BCEL/bcelifier/BooleanValueCreator.java @@ -0,0 +1,63 @@ +package bcelifier; + +import org.apache.commons.bcel6.generic.*; +import org.apache.commons.bcel6.classfile.*; +import org.apache.commons.bcel6.*; +import java.io.*; + +public class BooleanValueCreator implements Constants { + private InstructionFactory _factory; + private ConstantPoolGen _cp; + private ClassGen _cg; + + public BooleanValueCreator() { + _cg = new ClassGen("bcelifier.BooleanValue", "java.lang.Object", "BooleanValue.java", ACC_PUBLIC | ACC_SUPER, new String[] { }); + + _cp = _cg.getConstantPool(); + _factory = new InstructionFactory(_cg, _cp); + } + + public void create(OutputStream out) throws IOException { + createFields(); + createMethod_0(); + _cg.getJavaClass().dump(out); + } + + private void createFields() { + FieldGen field; + + field = new FieldGen(0, new ObjectType("java.lang.Boolean"), "c", _cp); + _cg.addField(field.getField()); + + field = new FieldGen(0, new ObjectType("java.lang.Boolean"), "b", _cp); + _cg.addField(field.getField()); + } + + private void createMethod_0() { + InstructionList il = new InstructionList(); + MethodGen method = new MethodGen(ACC_PUBLIC, Type.VOID, Type.NO_ARGS, new String[] { }, "", "bcelifier.BooleanValue", il, _cp); + + InstructionHandle ih_0 = il.append(_factory.createLoad(Type.OBJECT, 0)); + il.append(_factory.createInvoke("java.lang.Object", "", Type.VOID, Type.NO_ARGS, Constants.INVOKESPECIAL)); + InstructionHandle ih_4 = il.append(_factory.createLoad(Type.OBJECT, 0)); + il.append(new PUSH(_cp, 1)); + il.append(_factory.createInvoke("java.lang.Boolean", "valueOf", new ObjectType("java.lang.Boolean"), new Type[] { Type.BOOLEAN }, Constants.INVOKESTATIC)); + il.append(_factory.createFieldAccess("bcelifier.BooleanValue", "c", new ObjectType("java.lang.Boolean"), Constants.PUTFIELD)); + InstructionHandle ih_12 = il.append(_factory.createLoad(Type.OBJECT, 0)); + il.append(_factory.createLoad(Type.OBJECT, 0)); + il.append(_factory.createFieldAccess("bcelifier.BooleanValue", "c", new ObjectType("java.lang.Boolean"), Constants.GETFIELD)); + il.append(_factory.createInvoke("java.lang.Boolean", "booleanValue", Type.BOOLEAN, Type.NO_ARGS, Constants.INVOKEVIRTUAL)); + il.append(_factory.createInvoke("java.lang.Boolean", "valueOf", new ObjectType("java.lang.Boolean"), new Type[] { Type.BOOLEAN }, Constants.INVOKESTATIC)); + il.append(_factory.createFieldAccess("bcelifier.BooleanValue", "b", new ObjectType("java.lang.Boolean"), Constants.PUTFIELD)); + InstructionHandle ih_26 = il.append(_factory.createReturn(Type.VOID)); + method.setMaxStack(); + method.setMaxLocals(); + _cg.addMethod(method.getMethod()); + il.dispose(); + } + + public static void main(String[] args) throws Exception { + bcelifier.BooleanValueCreator creator = new bcelifier.BooleanValueCreator(); + creator.create(new FileOutputStream("bcelifier.BooleanValue.class")); + } +} diff --git a/BCEL/bcelifier/JavaToBCEL.java b/BCEL/bcelifier/JavaToBCEL.java index f4281a3c..10c74c32 100644 --- a/BCEL/bcelifier/JavaToBCEL.java +++ b/BCEL/bcelifier/JavaToBCEL.java @@ -31,6 +31,7 @@ public class JavaToBCEL { 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(); } catch (ClassFormatException | IOException e) { e.printStackTrace(); diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/IfStmt.java b/src/de/dhbwstuttgart/syntaxtree/statement/IfStmt.java index a8eac123..5a7488c7 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/IfStmt.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/IfStmt.java @@ -185,6 +185,8 @@ public class IfStmt extends Statement IfInstruction ifInstruction = new IFEQ(null); il.append(expr.genByteCode(_cg)); + //Anmerkung: expr ist vom Typ java.lang.Boolean (per Definition) + il.append(_factory.createInvoke("java.lang.Boolean", "booleanValue", org.apache.commons.bcel6.generic.Type.BOOLEAN, org.apache.commons.bcel6.generic.Type.NO_ARGS, Constants.INVOKEVIRTUAL)); il.append(ifInstruction); il.append(then_block.genByteCode(_cg)); diff --git a/src/de/dhbwstuttgart/syntaxtree/type/RefType.java b/src/de/dhbwstuttgart/syntaxtree/type/RefType.java index 097ed4e4..5b96e961 100755 --- a/src/de/dhbwstuttgart/syntaxtree/type/RefType.java +++ b/src/de/dhbwstuttgart/syntaxtree/type/RefType.java @@ -814,7 +814,7 @@ public class RefType extends ObjectType implements IMatchable } public org.apache.commons.bcel6.generic.Type getBytecodeType(ClassGenerator cg) { - return new org.apache.commons.bcel6.generic.ObjectType(this.getTypeName()); + return new org.apache.commons.bcel6.generic.ObjectType(this.getTypeName()); } @Override diff --git a/test/bytecode/IfElseStatement.jav b/test/bytecode/IfElseStatement.jav index 82c9d5a8..ee4c5eee 100644 --- a/test/bytecode/IfElseStatement.jav +++ b/test/bytecode/IfElseStatement.jav @@ -1,9 +1,9 @@ class IfElseStatement{ method(flag){ if(flag){ - + return 0; }else{ - + return 1; } } } \ No newline at end of file diff --git a/test/bytecode/IfTest.java b/test/bytecode/IfTest.java new file mode 100644 index 00000000..1c2c1464 --- /dev/null +++ b/test/bytecode/IfTest.java @@ -0,0 +1,9 @@ +class IfTest{ + +public static void main(String[] args){ + + System.out.println(new IfElseStatement().method(true)); + System.out.println(new IfElseStatement().method(false)); +} + +} From 88b1c3e57c98587842996dbc55bac1fbc9f75b19 Mon Sep 17 00:00:00 2001 From: JanUlrich Date: Thu, 15 Oct 2015 16:28:10 +0200 Subject: [PATCH 4/9] =?UTF-8?q?WriteLog=20anf=C3=BCgen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/bytecode/SingleClassTester.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/test/bytecode/SingleClassTester.java b/test/bytecode/SingleClassTester.java index d769fe98..bbee95d6 100644 --- a/test/bytecode/SingleClassTester.java +++ b/test/bytecode/SingleClassTester.java @@ -3,17 +3,21 @@ package bytecode; import java.io.File; import java.io.IOException; +import com.google.common.io.Files; + import junit.framework.TestCase; import de.dhbwstuttgart.core.MyCompiler; import de.dhbwstuttgart.core.MyCompilerAPI; +import de.dhbwstuttgart.logger.Logger; import de.dhbwstuttgart.logger.LoggerConfiguration; import de.dhbwstuttgart.logger.Section; +import de.dhbwstuttgart.logger.Timewatch; import de.dhbwstuttgart.parser.JavaParser.yyException; import de.dhbwstuttgart.typeinference.ByteCodeResult; import de.dhbwstuttgart.typeinference.Menge; public class SingleClassTester { - + public static void compileToBytecode(String inputFile, String outputFile){ LoggerConfiguration logConfig = new LoggerConfiguration().setOutput(Section.PARSER, System.out); MyCompilerAPI compiler = MyCompiler.getAPI(logConfig); @@ -25,7 +29,19 @@ public class SingleClassTester { } catch (IOException | yyException e) { e.printStackTrace(); TestCase.fail(); + }finally{ + writeLog(outputFile+".log"); } } + private static void writeLog(String toFile){ + String log = Logger.getWholeLog()+"\n"; + log+=Timewatch.getTimewatch().dumpTimeData(); + try { + Files.write(log.getBytes(),new File(toFile)); + } catch (IOException e) { + e.printStackTrace(); + TestCase.fail(); + } + } } From d6fb9ff2c7b5bd6a947e4a8e6462f674dd7ada13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Enrico=20Schr=C3=B6dter?= Date: Thu, 15 Oct 2015 17:46:13 +0200 Subject: [PATCH 5/9] ConditionTest angelegt ForTest gefixed --- src/de/dhbwstuttgart/syntaxtree/Method.java | 3 +- .../syntaxtree/statement/Binary.java | 23 +++++++- .../syntaxtree/statement/ForStmt.java | 54 ++++++++++++++++--- .../syntaxtree/statement/IfStmt.java | 2 - .../syntaxtree/statement/LocalOrFieldVar.java | 9 +++- test/bytecode/Condition.jav | 7 +++ test/bytecode/ConditionTest.java | 34 ++++++++++++ test/bytecode/ForTest.jav | 2 +- test/bytecode/IfStatement.jav | 2 +- test/bytecode/SingleClassTester.java | 2 +- 10 files changed, 121 insertions(+), 17 deletions(-) create mode 100644 test/bytecode/Condition.jav create mode 100644 test/bytecode/ConditionTest.java diff --git a/src/de/dhbwstuttgart/syntaxtree/Method.java b/src/de/dhbwstuttgart/syntaxtree/Method.java index ba8cba98..3d4a60ce 100755 --- a/src/de/dhbwstuttgart/syntaxtree/Method.java +++ b/src/de/dhbwstuttgart/syntaxtree/Method.java @@ -541,8 +541,7 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable ret.add(this.block.TYPEStmt(localAss)); // eine Verknüpfung mit der Type Assumption aus dem Assumption Set // und dem ermittelten Typ der Methode: - ret.add(new SingleConstraint(this.block.getType().TYPE(localAss, this), - this.returntype.TYPE(localAss, this))); + ret.add(new SingleConstraint(this.block.getType().TYPE(localAss, this), this.returntype.TYPE(localAss, this))); return ret; } diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/Binary.java b/src/de/dhbwstuttgart/syntaxtree/statement/Binary.java index 60b2657b..73467924 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/Binary.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/Binary.java @@ -6,8 +6,13 @@ import java.util.Enumeration; import java.util.HashMap; import java.util.Hashtable; +import org.apache.commons.bcel6.generic.BranchInstruction; import org.apache.commons.bcel6.generic.ClassGen; +import org.apache.commons.bcel6.generic.GOTO; +import org.apache.commons.bcel6.generic.IF_ICMPNE; +import org.apache.commons.bcel6.generic.InstructionConstants; import org.apache.commons.bcel6.generic.InstructionList; +import org.apache.commons.bcel6.generic.NOP; import de.dhbwstuttgart.typeinference.Menge; import de.dhbwstuttgart.bytecode.ClassGenerator; @@ -228,8 +233,22 @@ public JavaCodeResult printJavaCode(ResultSet resultSet) { if(this.getReturnType().getName().equals(new JavaClassName("String"))){ throw new TypeinferenceException("Zeichenketten zusammenfügen ist noch nicht unterstützt",this); } - //TODO: Je nachdem welches der Rückgabetyp ist, müssen die linke und rechte Seite unboxt und addiert werden. - return null; + + 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(new NOP())); + return linkeSeite; } } diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/ForStmt.java b/src/de/dhbwstuttgart/syntaxtree/statement/ForStmt.java index 6f5ab521..dc8526ae 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/ForStmt.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/ForStmt.java @@ -4,8 +4,13 @@ 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.GOTO; +import org.apache.commons.bcel6.generic.IF_ICMPGE; +import org.apache.commons.bcel6.generic.InstructionHandle; import org.apache.commons.bcel6.generic.InstructionList; +import org.apache.commons.bcel6.generic.NOP; import de.dhbwstuttgart.typeinference.Menge; import de.dhbwstuttgart.bytecode.ClassGenerator; @@ -22,10 +27,13 @@ import de.dhbwstuttgart.syntaxtree.operator.RelOp; import de.dhbwstuttgart.syntaxtree.type.GenericTypeVar; import de.dhbwstuttgart.syntaxtree.type.RefType; import de.dhbwstuttgart.syntaxtree.type.Type; +import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder; +import de.dhbwstuttgart.syntaxtree.type.Void; import de.dhbwstuttgart.typeinference.ConstraintsSet; import de.dhbwstuttgart.typeinference.JavaCodeResult; import de.dhbwstuttgart.typeinference.Pair; import de.dhbwstuttgart.typeinference.ResultSet; +import de.dhbwstuttgart.typeinference.SingleConstraint; import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions; import de.dhbwstuttgart.typeinference.exceptions.NotImplementedException; import de.dhbwstuttgart.typeinference.unify.Unify; @@ -91,8 +99,13 @@ public class ForStmt extends Statement @Override public ConstraintsSet TYPEStmt(TypeAssumptions assumptions) { - // TODO Auto-generated method stub - return null; + //TODO: TYPEStmt + ConstraintsSet ret = new ConstraintsSet(); + this.setType(TypePlaceholder.fresh(this)); + + ret.add(body_Loop_block.TYPEStmt(assumptions)); + + return ret; } public int getTypeLineNumber() { @@ -100,9 +113,9 @@ public class ForStmt extends Statement } @Override -public JavaCodeResult printJavaCode(ResultSet resultSet) { - // TODO Auto-generated method stub - throw new NotImplementedException(); + public JavaCodeResult printJavaCode(ResultSet resultSet) { + // TODO printJavaCode + return new JavaCodeResult(); } @Override @@ -121,7 +134,34 @@ public JavaCodeResult printJavaCode(ResultSet resultSet) { @Override public InstructionList genByteCode(ClassGenerator _cg) { - // TODO Bytecode - throw new NotImplementedException(); + /* + 0: iconst_0 + 1: istore_1 + 2: iload_1 + 3: bipush 10 + 5: if_icmpge 14 + 8: iinc 1, 1 + 11: goto 2 + 14: return + */ + + InstructionList il = new InstructionList(); + + il.append(head_Initializer.genByteCode(_cg)); + + InstructionHandle ih = il.append(head_Condition.genByteCode(_cg)); + + BranchInstruction branch = new IF_ICMPGE(null); + il.append(branch); + + il.append(body_Loop_block.genByteCode(_cg)); + + il.append(head_Loop_expr.genByteCode(_cg)); + + il.append(new GOTO(ih)); + + branch.setTarget(il.append(new NOP())); + + return il; } } \ No newline at end of file diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/IfStmt.java b/src/de/dhbwstuttgart/syntaxtree/statement/IfStmt.java index a8eac123..91cb548e 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/IfStmt.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/IfStmt.java @@ -179,8 +179,6 @@ public class IfStmt extends Statement @Override public InstructionList genByteCode(ClassGenerator _cg) { - InstructionFactory _factory = new InstructionFactory(_cg, _cg.getConstantPool()); - InstructionList il = new InstructionList(); IfInstruction ifInstruction = new IFEQ(null); diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/LocalOrFieldVar.java b/src/de/dhbwstuttgart/syntaxtree/statement/LocalOrFieldVar.java index 8a39cbd0..50c2bdf8 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/LocalOrFieldVar.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/LocalOrFieldVar.java @@ -13,6 +13,7 @@ import org.apache.commons.bcel6.generic.ObjectType; import de.dhbwstuttgart.typeinference.Menge; import de.dhbwstuttgart.bytecode.ClassGenerator; import de.dhbwstuttgart.logger.Logger; +import de.dhbwstuttgart.logger.Section; import de.dhbwstuttgart.myexception.CTypeReconstructionException; import de.dhbwstuttgart.myexception.JVMCodeException; import de.dhbwstuttgart.myexception.SCExcept; @@ -152,7 +153,13 @@ public class LocalOrFieldVar extends Expr if(this.isFieldAccess){ il.append(cg.getInstructionFactory().createFieldAccess(this.getParentClass().getName().toString(), this.get_Name(), this.getType().getBytecodeType(cg), Constants.GETFIELD)); } - il.append(cg.getInstructionFactory().createLoad(this.getType().getBytecodeType(cg), this.get_Name())); + + Type type = this.getType(); + org.apache.commons.bcel6.generic.Type byteCodeType = type.getBytecodeType(cg); + + String name = this.get_Name(); + + il.append(cg.getInstructionFactory().createLoad(byteCodeType, name)); return il; } diff --git a/test/bytecode/Condition.jav b/test/bytecode/Condition.jav new file mode 100644 index 00000000..4f68e8ab --- /dev/null +++ b/test/bytecode/Condition.jav @@ -0,0 +1,7 @@ +class Condition{ + + Boolean method() { + return 0 == 1; + } + +} \ No newline at end of file diff --git a/test/bytecode/ConditionTest.java b/test/bytecode/ConditionTest.java new file mode 100644 index 00000000..851d6426 --- /dev/null +++ b/test/bytecode/ConditionTest.java @@ -0,0 +1,34 @@ +package bytecode; + +import static org.junit.Assert.*; + +import java.io.File; +import java.io.IOException; + +import junit.framework.TestCase; + +import org.junit.Test; + +import plugindevelopment.TypeInsertTester; +import de.dhbwstuttgart.core.MyCompiler; +import de.dhbwstuttgart.core.MyCompilerAPI; +import de.dhbwstuttgart.logger.LoggerConfiguration; +import de.dhbwstuttgart.logger.Section; +import de.dhbwstuttgart.parser.JavaParser.yyException; +import de.dhbwstuttgart.typeinference.ByteCodeResult; +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"; + + @Test + public void test() { + SingleClassTester.compileToBytecode(rootDirectory+testFile, rootDirectory+outputFile); + } + +} diff --git a/test/bytecode/ForTest.jav b/test/bytecode/ForTest.jav index 7343a1b8..649b71b0 100644 --- a/test/bytecode/ForTest.jav +++ b/test/bytecode/ForTest.jav @@ -1,6 +1,6 @@ class IfElse{ method(){ - while(true){ + for( i = 0; i < 10 ; i = i++){ } } diff --git a/test/bytecode/IfStatement.jav b/test/bytecode/IfStatement.jav index 476c9bc0..d9fdb16c 100644 --- a/test/bytecode/IfStatement.jav +++ b/test/bytecode/IfStatement.jav @@ -1,7 +1,7 @@ class IfStatement{ method(flag){ if(flag){ - + } } } \ No newline at end of file diff --git a/test/bytecode/SingleClassTester.java b/test/bytecode/SingleClassTester.java index d769fe98..58dbae58 100644 --- a/test/bytecode/SingleClassTester.java +++ b/test/bytecode/SingleClassTester.java @@ -20,7 +20,7 @@ public class SingleClassTester { try { compiler.parse(new File(inputFile)); Menge bytecode = compiler.generateBytecode(compiler.typeReconstruction().firstElement()); - System.out.println(bytecode); + //System.out.println(bytecode); bytecode.firstElement().getByteCode().getJavaClass().dump(new File(outputFile)); } catch (IOException | yyException e) { e.printStackTrace(); From 0a17be3c4f61713cae02741f3a51200db16782d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Enrico=20Schr=C3=B6dter?= Date: Thu, 15 Oct 2015 19:12:38 +0200 Subject: [PATCH 6/9] =?UTF-8?q?Abstrakter=20Test=20f=C3=BCr=20BytecodeTest?= =?UTF-8?q?s=20TypedVectorTest=20angelegt:=20funktoniert=20schon=20Overloa?= =?UTF-8?q?dingTest=20angelegt:=20N=C3=A4chstes=20Ziel?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/bytecode/BytecodeTest.java | 57 ++++++++++++++++++++++++++++ test/bytecode/Overloading.jav | 12 ++++++ test/bytecode/OverloadingTest.java | 56 +++++++++++++++++++++++++++ test/bytecode/SingleClassTester.java | 1 + test/bytecode/TypedVector.jav | 7 ++++ test/bytecode/TypedVectorTest.java | 36 ++++++++++++++++++ 6 files changed, 169 insertions(+) create mode 100644 test/bytecode/BytecodeTest.java create mode 100644 test/bytecode/Overloading.jav create mode 100644 test/bytecode/OverloadingTest.java create mode 100644 test/bytecode/TypedVector.jav create mode 100644 test/bytecode/TypedVectorTest.java diff --git a/test/bytecode/BytecodeTest.java b/test/bytecode/BytecodeTest.java new file mode 100644 index 00000000..8fac8161 --- /dev/null +++ b/test/bytecode/BytecodeTest.java @@ -0,0 +1,57 @@ +package bytecode; + +import static org.junit.Assert.*; + +import java.io.File; +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLClassLoader; + +import junit.framework.TestCase; + +import org.junit.BeforeClass; +import org.junit.Test; + +public abstract class BytecodeTest extends TestCase{ + public final static String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; + public static String testFile; + public static String outputFile; + + protected String testName; + + public BytecodeTest(){ + init(); + + if(testName != null){ + + testFile = testName+".jav"; + outputFile = testName+".class"; + + SingleClassTester.compileToBytecode(rootDirectory+testFile, rootDirectory+outputFile); + }else{ + throw new RuntimeException("rootDirectory, testFile or outputFile is null."); + } + } + + protected abstract void init(); + + protected Class getClassToTest(){ + Class classToTest = null; + try { + File file = new File(rootDirectory); + URL url = file.toURL(); + URL[] urls = new URL[]{url}; + + ClassLoader classLoader = new URLClassLoader(urls); + + classToTest = classLoader.loadClass(testName); + + + } catch (Exception e) { + throw new RuntimeException(e); + } + + return classToTest; + } +} diff --git a/test/bytecode/Overloading.jav b/test/bytecode/Overloading.jav new file mode 100644 index 00000000..ce94fb7d --- /dev/null +++ b/test/bytecode/Overloading.jav @@ -0,0 +1,12 @@ +import java.util.Vector; + +class Overloading{ + + void method(Vector v) { + + } + + void method(Vector v) { + + } +} \ No newline at end of file diff --git a/test/bytecode/OverloadingTest.java b/test/bytecode/OverloadingTest.java new file mode 100644 index 00000000..4b348971 --- /dev/null +++ b/test/bytecode/OverloadingTest.java @@ -0,0 +1,56 @@ +package bytecode; + +import static org.junit.Assert.*; + +import java.lang.reflect.Method; +import java.util.Vector; + +import org.junit.Test; + +public class OverloadingTest extends BytecodeTest{ + @Override + protected void init() { + testName = "Overloading"; + } + + @Test + public void testString() { + try{ + Class cls = getClassToTest(); + Object obj = cls.newInstance(); + + Vector stringVector = new Vector(); + + Class[] params = new Class[1]; + params[0] = stringVector.getClass(); + + Method method = cls.getDeclaredMethod("method", params); + method.invoke(obj, stringVector); + assertTrue(true); + }catch(Exception e){ + e.printStackTrace(); + fail(); + } + } + + @Test + public void testInteger() { + try{ + Class cls = getClassToTest(); + Object obj = cls.newInstance(); + + Vector stringVector = new Vector(); + + Class[] params = new Class[1]; + params[0] = stringVector.getClass(); + + Method method = cls.getDeclaredMethod("method", params); + method.invoke(obj, stringVector); + assertTrue(true); + }catch(Exception e){ + e.printStackTrace(); + fail(); + } + } + +} diff --git a/test/bytecode/SingleClassTester.java b/test/bytecode/SingleClassTester.java index 34ff10a9..323aaf53 100644 --- a/test/bytecode/SingleClassTester.java +++ b/test/bytecode/SingleClassTester.java @@ -27,6 +27,7 @@ public class SingleClassTester { //System.out.println(bytecode); bytecode.firstElement().getByteCode().getJavaClass().dump(new File(outputFile)); } catch (IOException | yyException e) { + Logger.getLogger("SingleClassTester").error(e.toString(), Section.CODEGEN); e.printStackTrace(); TestCase.fail(); }finally{ diff --git a/test/bytecode/TypedVector.jav b/test/bytecode/TypedVector.jav new file mode 100644 index 00000000..a19b45bd --- /dev/null +++ b/test/bytecode/TypedVector.jav @@ -0,0 +1,7 @@ +import java.util.Stack; + +class TypedVector{ + public void method(Vector v) { + + } +} \ No newline at end of file diff --git a/test/bytecode/TypedVectorTest.java b/test/bytecode/TypedVectorTest.java new file mode 100644 index 00000000..f5c2a9e4 --- /dev/null +++ b/test/bytecode/TypedVectorTest.java @@ -0,0 +1,36 @@ +package bytecode; + +import static org.junit.Assert.*; + +import java.lang.reflect.Method; +import java.util.Stack; +import java.util.Vector; + +import org.junit.Test; + +public class TypedVectorTest extends BytecodeTest{ + @Override + protected void init() { + testName = "TypedVector"; + } + + @Test + public void test() { + try{ + Class cls = getClassToTest(); + Object obj = cls.newInstance(); + + Vector stringVector = new Vector(); + + Class[] params = new Class[1]; + params[0] = stringVector.getClass(); + + Method method = cls.getDeclaredMethod("method", params); + method.invoke(obj, stringVector); + assertTrue(true); + }catch(Exception e){ + e.printStackTrace(); + fail(); + } + } +} From 3a1808880135aa3e8e157074dc072b074419bd08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Enrico=20Schr=C3=B6dter?= Date: Thu, 15 Oct 2015 22:16:18 +0200 Subject: [PATCH 7/9] =?UTF-8?q?Erste=20=C3=84nderung=20an=20RefType=20Test?= =?UTF-8?q?s=20f=C3=BCr=20Extends=20angelegt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../syntaxtree/statement/IfStmt.java | 3 +- .../syntaxtree/type/RefType.java | 18 ++++++- test/bytecode/BytecodeTest.java | 6 +-- test/bytecode/ForTest.java | 2 + test/bytecode/LambdaExpr2.java | 2 + test/bytecode/PostDecrement.java | 2 + test/bytecode/PostIncrement.java | 2 + test/bytecode/types/ExtendsObject.jav | 3 ++ test/bytecode/types/ExtendsObjectTest.java | 48 +++++++++++++++++++ test/bytecode/types/ExtendsVector.jav | 4 ++ test/bytecode/types/ExtendsVectorString.jav | 5 ++ .../types/ExtendsVectorStringTest.java | 48 +++++++++++++++++++ test/bytecode/types/ExtendsVectorTest.java | 48 +++++++++++++++++++ test/bytecode/{ => types}/Overloading.jav | 0 .../bytecode/{ => types}/OverloadingTest.java | 5 +- test/bytecode/{ => types}/TypedVector.jav | 0 .../bytecode/{ => types}/TypedVectorTest.java | 5 +- 17 files changed, 194 insertions(+), 7 deletions(-) create mode 100644 test/bytecode/types/ExtendsObject.jav create mode 100644 test/bytecode/types/ExtendsObjectTest.java create mode 100644 test/bytecode/types/ExtendsVector.jav create mode 100644 test/bytecode/types/ExtendsVectorString.jav create mode 100644 test/bytecode/types/ExtendsVectorStringTest.java create mode 100644 test/bytecode/types/ExtendsVectorTest.java rename test/bytecode/{ => types}/Overloading.jav (100%) rename test/bytecode/{ => types}/OverloadingTest.java (89%) rename test/bytecode/{ => types}/TypedVector.jav (100%) rename test/bytecode/{ => types}/TypedVectorTest.java (84%) diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/IfStmt.java b/src/de/dhbwstuttgart/syntaxtree/statement/IfStmt.java index e0b4936f..0998e4d3 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/IfStmt.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/IfStmt.java @@ -178,7 +178,8 @@ public class IfStmt extends Statement } @Override - public InstructionList genByteCode(ClassGenerator _cg) { + public InstructionList genByteCode(ClassGenerator _cg) { + InstructionFactory _factory = _cg.getInstructionFactory(); InstructionList il = new InstructionList(); IfInstruction ifInstruction = new IFEQ(null); diff --git a/src/de/dhbwstuttgart/syntaxtree/type/RefType.java b/src/de/dhbwstuttgart/syntaxtree/type/RefType.java index 5b96e961..ac0577da 100755 --- a/src/de/dhbwstuttgart/syntaxtree/type/RefType.java +++ b/src/de/dhbwstuttgart/syntaxtree/type/RefType.java @@ -814,11 +814,24 @@ public class RefType extends ObjectType implements IMatchable } public org.apache.commons.bcel6.generic.Type getBytecodeType(ClassGenerator cg) { - return new org.apache.commons.bcel6.generic.ObjectType(this.getTypeName()); + return new org.apache.commons.bcel6.generic.ObjectType(this.getBytecodeSignature(cg)); } @Override public String getBytecodeSignature(ClassGenerator cg) { + //Bsp.: Ljava/util/Vector; + StringBuilder sb = new StringBuilder(); + + sb.append(getTypeName()); + + if(parameter != null){ + for(Type type: parameter){ + sb.append("%"); + sb.append(type.getBytecodeSignature(cg)); + } + } + + /* String paramString = ""; if(this.parameter != null && this.parameter.size()>0){ paramString+="<"; @@ -834,6 +847,9 @@ public class RefType extends ObjectType implements IMatchable String typeSignature = this.getBytecodeType(cg).getSignature(); typeSignature = typeSignature.substring(0, typeSignature.length()-1); return typeSignature+paramString+";"; + */ + + return sb.toString(); } } diff --git a/test/bytecode/BytecodeTest.java b/test/bytecode/BytecodeTest.java index 8fac8161..eb1c2aae 100644 --- a/test/bytecode/BytecodeTest.java +++ b/test/bytecode/BytecodeTest.java @@ -14,9 +14,9 @@ import org.junit.BeforeClass; import org.junit.Test; public abstract class BytecodeTest extends TestCase{ - public final static String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; - public static String testFile; - public static String outputFile; + public String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; + public String testFile; + public String outputFile; protected String testName; diff --git a/test/bytecode/ForTest.java b/test/bytecode/ForTest.java index fea1e7c5..497dc375 100644 --- a/test/bytecode/ForTest.java +++ b/test/bytecode/ForTest.java @@ -1,5 +1,6 @@ package bytecode; +import org.junit.Ignore; import org.junit.Test; public class ForTest { @@ -8,6 +9,7 @@ public class ForTest { public final static String outputFile = "ForTest.class"; @Test + @Ignore public void test() { SingleClassTester.compileToBytecode(rootDirectory+testFile, rootDirectory+outputFile); } diff --git a/test/bytecode/LambdaExpr2.java b/test/bytecode/LambdaExpr2.java index ff607c6c..83308ca5 100644 --- a/test/bytecode/LambdaExpr2.java +++ b/test/bytecode/LambdaExpr2.java @@ -7,6 +7,7 @@ import java.io.IOException; import junit.framework.TestCase; +import org.junit.Ignore; import org.junit.Test; import plugindevelopment.TypeInsertTester; @@ -27,6 +28,7 @@ public class LambdaExpr2 { public final static String outputFile = "LambdaExpr2.class"; @Test + @Ignore public void test() { SingleClassTester.compileToBytecode(rootDirectory+testFile, rootDirectory+outputFile); } diff --git a/test/bytecode/PostDecrement.java b/test/bytecode/PostDecrement.java index 075cf135..b0dbee20 100644 --- a/test/bytecode/PostDecrement.java +++ b/test/bytecode/PostDecrement.java @@ -7,6 +7,7 @@ import java.io.IOException; import junit.framework.TestCase; +import org.junit.Ignore; import org.junit.Test; import plugindevelopment.TypeInsertTester; @@ -27,6 +28,7 @@ public class PostDecrement { public final static String outputFile = "PostDecrement.class"; @Test + @Ignore public void test() { SingleClassTester.compileToBytecode(rootDirectory+testFile, rootDirectory+outputFile); } diff --git a/test/bytecode/PostIncrement.java b/test/bytecode/PostIncrement.java index 8c0b3930..da1fe1e3 100644 --- a/test/bytecode/PostIncrement.java +++ b/test/bytecode/PostIncrement.java @@ -7,6 +7,7 @@ import java.io.IOException; import junit.framework.TestCase; +import org.junit.Ignore; import org.junit.Test; import plugindevelopment.TypeInsertTester; @@ -27,6 +28,7 @@ public class PostIncrement { public final static String outputFile = "PostIncrement.class"; @Test + @Ignore public void test() { SingleClassTester.compileToBytecode(rootDirectory+testFile, rootDirectory+outputFile); } diff --git a/test/bytecode/types/ExtendsObject.jav b/test/bytecode/types/ExtendsObject.jav new file mode 100644 index 00000000..758def9c --- /dev/null +++ b/test/bytecode/types/ExtendsObject.jav @@ -0,0 +1,3 @@ +class ExtendsObject extends Object{ + +} \ No newline at end of file diff --git a/test/bytecode/types/ExtendsObjectTest.java b/test/bytecode/types/ExtendsObjectTest.java new file mode 100644 index 00000000..43648fdf --- /dev/null +++ b/test/bytecode/types/ExtendsObjectTest.java @@ -0,0 +1,48 @@ +package bytecode.types; + +import static org.junit.Assert.*; + +import java.io.File; +import java.io.IOException; +import java.lang.reflect.Constructor; +import java.lang.reflect.Method; +import java.util.Vector; + +import junit.framework.TestCase; + +import org.junit.Test; + +import bytecode.BytecodeTest; +import plugindevelopment.TypeInsertTester; +import de.dhbwstuttgart.core.MyCompiler; +import de.dhbwstuttgart.core.MyCompilerAPI; +import de.dhbwstuttgart.logger.LoggerConfiguration; +import de.dhbwstuttgart.logger.Section; +import de.dhbwstuttgart.parser.JavaParser.yyException; +import de.dhbwstuttgart.typeinference.ByteCodeResult; +import de.dhbwstuttgart.typeinference.Menge; +import de.dhbwstuttgart.typeinference.TypeinferenceResultSet; +import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertSet; + +public class ExtendsObjectTest extends BytecodeTest{ + @Override + protected void init() { + testName = "ExtendsObject"; + rootDirectory = System.getProperty("user.dir")+"/test/bytecode/types/"; + } + + @Test + public void testConstruct(){ + try{ + Class cls = getClassToTest(); + + Constructor method = cls.getConstructor(new Class[]{}); + method.newInstance(); + assertTrue(true); + }catch(Exception e){ + e.printStackTrace(); + fail(); + } + } + +} diff --git a/test/bytecode/types/ExtendsVector.jav b/test/bytecode/types/ExtendsVector.jav new file mode 100644 index 00000000..efd0240f --- /dev/null +++ b/test/bytecode/types/ExtendsVector.jav @@ -0,0 +1,4 @@ +import java.util.Vector; + +class ExtendsVector extends Vector{ +} \ No newline at end of file diff --git a/test/bytecode/types/ExtendsVectorString.jav b/test/bytecode/types/ExtendsVectorString.jav new file mode 100644 index 00000000..7829ecd0 --- /dev/null +++ b/test/bytecode/types/ExtendsVectorString.jav @@ -0,0 +1,5 @@ +import java.util.Vector; + +class ExtendsVectorString extends Vector{ + +} \ No newline at end of file diff --git a/test/bytecode/types/ExtendsVectorStringTest.java b/test/bytecode/types/ExtendsVectorStringTest.java new file mode 100644 index 00000000..10f4bdfe --- /dev/null +++ b/test/bytecode/types/ExtendsVectorStringTest.java @@ -0,0 +1,48 @@ +package bytecode.types; + +import static org.junit.Assert.*; + +import java.io.File; +import java.io.IOException; +import java.lang.reflect.Constructor; +import java.lang.reflect.Method; +import java.util.Vector; + +import junit.framework.TestCase; + +import org.junit.Test; + +import bytecode.BytecodeTest; +import plugindevelopment.TypeInsertTester; +import de.dhbwstuttgart.core.MyCompiler; +import de.dhbwstuttgart.core.MyCompilerAPI; +import de.dhbwstuttgart.logger.LoggerConfiguration; +import de.dhbwstuttgart.logger.Section; +import de.dhbwstuttgart.parser.JavaParser.yyException; +import de.dhbwstuttgart.typeinference.ByteCodeResult; +import de.dhbwstuttgart.typeinference.Menge; +import de.dhbwstuttgart.typeinference.TypeinferenceResultSet; +import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertSet; + +public class ExtendsVectorStringTest extends BytecodeTest{ + @Override + protected void init() { + testName = "ExtendsVectorString"; + rootDirectory = System.getProperty("user.dir")+"/test/bytecode/types/"; + } + + @Test + public void testConstruct(){ + try{ + Class cls = getClassToTest(); + + Constructor method = cls.getConstructor(new Class[]{}); + method.newInstance(); + assertTrue(true); + }catch(Exception e){ + e.printStackTrace(); + fail(); + } + } + +} diff --git a/test/bytecode/types/ExtendsVectorTest.java b/test/bytecode/types/ExtendsVectorTest.java new file mode 100644 index 00000000..aefe5d4b --- /dev/null +++ b/test/bytecode/types/ExtendsVectorTest.java @@ -0,0 +1,48 @@ +package bytecode.types; + +import static org.junit.Assert.*; + +import java.io.File; +import java.io.IOException; +import java.lang.reflect.Constructor; +import java.lang.reflect.Method; +import java.util.Vector; + +import junit.framework.TestCase; + +import org.junit.Test; + +import bytecode.BytecodeTest; +import plugindevelopment.TypeInsertTester; +import de.dhbwstuttgart.core.MyCompiler; +import de.dhbwstuttgart.core.MyCompilerAPI; +import de.dhbwstuttgart.logger.LoggerConfiguration; +import de.dhbwstuttgart.logger.Section; +import de.dhbwstuttgart.parser.JavaParser.yyException; +import de.dhbwstuttgart.typeinference.ByteCodeResult; +import de.dhbwstuttgart.typeinference.Menge; +import de.dhbwstuttgart.typeinference.TypeinferenceResultSet; +import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertSet; + +public class ExtendsVectorTest extends BytecodeTest{ + @Override + protected void init() { + testName = "ExtendsVector"; + rootDirectory = System.getProperty("user.dir")+"/test/bytecode/types/"; + } + + @Test + public void testConstruct(){ + try{ + Class cls = getClassToTest(); + + Constructor method = cls.getConstructor(new Class[]{}); + method.newInstance(); + assertTrue(true); + }catch(Exception e){ + e.printStackTrace(); + fail(); + } + } + +} diff --git a/test/bytecode/Overloading.jav b/test/bytecode/types/Overloading.jav similarity index 100% rename from test/bytecode/Overloading.jav rename to test/bytecode/types/Overloading.jav diff --git a/test/bytecode/OverloadingTest.java b/test/bytecode/types/OverloadingTest.java similarity index 89% rename from test/bytecode/OverloadingTest.java rename to test/bytecode/types/OverloadingTest.java index 4b348971..7c8ba2ce 100644 --- a/test/bytecode/OverloadingTest.java +++ b/test/bytecode/types/OverloadingTest.java @@ -1,4 +1,4 @@ -package bytecode; +package bytecode.types; import static org.junit.Assert.*; @@ -7,10 +7,13 @@ import java.util.Vector; import org.junit.Test; +import bytecode.BytecodeTest; + public class OverloadingTest extends BytecodeTest{ @Override protected void init() { testName = "Overloading"; + rootDirectory = System.getProperty("user.dir")+"/test/bytecode/types/"; } @Test diff --git a/test/bytecode/TypedVector.jav b/test/bytecode/types/TypedVector.jav similarity index 100% rename from test/bytecode/TypedVector.jav rename to test/bytecode/types/TypedVector.jav diff --git a/test/bytecode/TypedVectorTest.java b/test/bytecode/types/TypedVectorTest.java similarity index 84% rename from test/bytecode/TypedVectorTest.java rename to test/bytecode/types/TypedVectorTest.java index f5c2a9e4..5383b5b9 100644 --- a/test/bytecode/TypedVectorTest.java +++ b/test/bytecode/types/TypedVectorTest.java @@ -1,4 +1,4 @@ -package bytecode; +package bytecode.types; import static org.junit.Assert.*; @@ -8,10 +8,13 @@ import java.util.Vector; import org.junit.Test; +import bytecode.BytecodeTest; + public class TypedVectorTest extends BytecodeTest{ @Override protected void init() { testName = "TypedVector"; + rootDirectory = System.getProperty("user.dir")+"/test/bytecode/types/"; } @Test From 1a07c186a6b0d66643415426ae84ca58ee29c26c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Enrico=20Schr=C3=B6dter?= Date: Fri, 16 Oct 2015 10:39:34 +0200 Subject: [PATCH 8/9] =?UTF-8?q?generateBytecode=20von=20Class=20gibt=20ein?= =?UTF-8?q?e=20Menge=20an=20ByteCodeResults=20zur=C3=BCck,=20wird=20ben?= =?UTF-8?q?=C3=B6tigt=20um=20zus=C3=A4tzliche=20Klassen=20anzulegen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/de/dhbwstuttgart/core/MyCompiler.java | 4 +- src/de/dhbwstuttgart/core/MyCompilerAPI.java | 2 +- src/de/dhbwstuttgart/syntaxtree/Class.java | 389 ++---------------- .../dhbwstuttgart/syntaxtree/SourceFile.java | 4 +- .../syntaxtree/type/RefType.java | 12 +- .../typeinference/TypeinferenceResultSet.java | 2 +- test/bytecode/BytecodeTest.java | 6 +- test/bytecode/SingleClassTester.java | 18 +- test/bytecode/types/ExtendsVector.jav | 1 + test/bytecode/types/TypedVector.jav | 2 +- test/bytecode/types/TypedVectorTest.java | 4 +- 11 files changed, 61 insertions(+), 383 deletions(-) diff --git a/src/de/dhbwstuttgart/core/MyCompiler.java b/src/de/dhbwstuttgart/core/MyCompiler.java index 74099f38..7b72e79b 100755 --- a/src/de/dhbwstuttgart/core/MyCompiler.java +++ b/src/de/dhbwstuttgart/core/MyCompiler.java @@ -860,10 +860,10 @@ public class MyCompiler implements MyCompilerAPI } @Override - public Menge generateBytecode(TypeinferenceResultSet typeinferenceResult) { + public Menge> generateBytecode(TypeinferenceResultSet typeinferenceResult) { //SourceFile parsedFile = this.m_AbstractSyntaxTree.firstElement(); //Class parsedClass = parsedFile.KlassenVektor.firstElement(); - Menge ret = new Menge<>(); + Menge> ret = new Menge<>(); for(SourceFile sf : this.m_AbstractSyntaxTree){ ret.addAll(sf.generateBytecode(typeinferenceResult)); } diff --git a/src/de/dhbwstuttgart/core/MyCompilerAPI.java b/src/de/dhbwstuttgart/core/MyCompilerAPI.java index 9c5d2a57..78860de4 100755 --- a/src/de/dhbwstuttgart/core/MyCompilerAPI.java +++ b/src/de/dhbwstuttgart/core/MyCompilerAPI.java @@ -127,6 +127,6 @@ public interface MyCompilerAPI * Dafür müssen die Schritte Parsen und typeReconstruction ausgeführt werden. * @return */ - public Menge generateBytecode(TypeinferenceResultSet rs); + public Menge> generateBytecode(TypeinferenceResultSet rs); } // ino.end diff --git a/src/de/dhbwstuttgart/syntaxtree/Class.java b/src/de/dhbwstuttgart/syntaxtree/Class.java index 356e3298..b11ed15f 100755 --- a/src/de/dhbwstuttgart/syntaxtree/Class.java +++ b/src/de/dhbwstuttgart/syntaxtree/Class.java @@ -15,7 +15,6 @@ import org.apache.commons.bcel6.generic.InstructionHandle; import org.apache.commons.bcel6.generic.InstructionList; import org.apache.commons.bcel6.generic.MethodGen; -import de.dhbwstuttgart.typeinference.Menge; import de.dhbwstuttgart.logger.Logger; import de.dhbwstuttgart.logger.Section; import de.dhbwstuttgart.logger.SectionLogger; @@ -75,11 +74,13 @@ public class Class extends GTVDeclarationContext implements AClassOrInterface, I * @param resultSet - Fehlende Typen im Syntaxbaum werden nach diesem ResultSet aufgelöst * @return */ - public ByteCodeResult genByteCode(TypeinferenceResultSet resultSet) { + public Menge genByteCode(TypeinferenceResultSet resultSet) { InstructionFactory _factory; DHBWConstantPoolGen _cp; ClassGenerator _cg; + Menge results = new Menge(); + SectionLogger logger = Logger.getSectionLogger(this.getClass().getName(), Section.CODEGEN); logger.debug("Test"); @@ -112,10 +113,14 @@ public class Class extends GTVDeclarationContext implements AClassOrInterface, I } ByteCodeResult code = new ByteCodeResult(_cg); - return code; + results.add(code); + + results.addAll(getGenericClasses(_cg)); + + return results; } - private Menge superif = new Menge(); + private Menge superif = new Menge(); public UsedId getPackageName() { @@ -593,112 +598,6 @@ public class Class extends GTVDeclarationContext implements AClassOrInterface, I { return this.parahash; } - // ino.end - - - -/*static void string_rec(Hashtable ht){ - String record=""; - boolean isError=false; - record=record.concat("["); - for(Enumeration e=ht.elements(),k=ht.keys();e.hasMoreElements();){ - String s = (String)k.nextElement(); - Object o = e.nextElement(); - - record=record.concat(" "+s); - - if(o instanceof Type){ - record=record.concat(" = "+((Type)o).getName()); - } else if(o instanceof Hashtable){ - record=record.concat("= "); - string_rec((Hashtable)o); - if(e.hasMoreElements()) - record=record.concat(", "); - } else if(o instanceof String){ - record=record.concat(" = "+o); - if(e.hasMoreElements()) - record=record.concat(", "); - } - else { - record=("[FEHLER: string_rec: unbekannter Typ!!!!!!"); - isError=true; - } - } - record=record.concat("]"); - if(isError){ - parserlog.error(record); - }else{ - parserlog.debug(record); - } - }*/ - - /*static void string_rec(Menge v){ - String record=("{"); - for(Enumeration e=v.elements();e.hasMoreElements();){ - Type t = (Type)e.nextElement(); - record=record.concat(" "+t.getName()); - - if(e.hasMoreElements()) - record=record.concat(","); - } - record=record.concat("}"); - parserlog.debug(record); - }*/ - /*static void string_rec(String st, Hashtable ht){ - String record=(st); - boolean isError=false; - record=record.concat("["); - for(Enumeration e=ht.elements(),k=ht.keys();e.hasMoreElements();){ - String s = (String)k.nextElement(); - Object o = e.nextElement(); - - record=record.concat(" "+s); - - if(o instanceof Type){ - record=record.concat(" = "+((Type)o).getName()); - } - - else if(o instanceof Hashtable){ - record=record.concat("= "); - string_rec((Hashtable)o); - if(e.hasMoreElements()) - record=record.concat(", "); - } - else if(o instanceof String){ - record=record.concat(" = "+o); - if(e.hasMoreElements()) - record=record.concat(", "); - } - else { - record=("[FEHLER: string_rec: unbekannter Typ!!!!!! " +o); - isError = true; - } - } - record=record.concat("]"); - if(isError){ - parserlog.error(record); - }else{ - parserlog.debug(record); - } - }*/ - - /*static void string_rec(String st,Menge v) - { - String record=(st); - record=record.concat("{"); - for(Enumeration e=v.elements();e.hasMoreElements();) - { - Type t = (Type)e.nextElement(); - record=record.concat(" "+t.getName()); - if(e.hasMoreElements()) - { - record=record.concat(", "); - } - } - record=record.concat("}"); - parserlog.debug(record); - }*/ - ///////////////////////////////////////////////////////////////////////// // TypeReconstructionAlgorithmus @@ -771,165 +670,7 @@ public class Class extends GTVDeclarationContext implements AClassOrInterface, I typinferenzLog.debug("Erstellte Constraints: "+oderConstraints, Section.TYPEINFERENCE); return oderConstraints; - - - /* - CReconstructionTupleSet retTupleSet = this.TRStart(methodList, V, V_fields_methods, supportData); - inferencelog.debug("Bin aus TRStart() zur�ck in TRProg()."); - ////////////////////////////// - // Neu Ergebnismenge A aller - // Typannahmen erzeugen: - ////////////////////////////// - inferencelog.debug("Erstelle Ergebnismenge..."); - Menge newA = new Menge(); - - // Alle bisherigen M�glichkeiten an Typkombinationen durchgehen: - Menge oldA = supportData.getA(); - for(int i=0; i retTupleIt = retTupleSet.getIterator(); - while(retTupleIt.hasNext()){ - CReconstructionTuple possibleTuple = retTupleIt.next(); - this.clear(possibleTuple.getAssumSet(), rememberLocals); - - // Neue Typinformationen mit alten Typinformationen vereinigen: - CTypeReconstructionResult newReconResult = oneReconResult.shallowCopy(); - newReconResult.addDataFromTupel(possibleTuple); - - - //PL 05-08-02 eingefuegt - //Fuegt Klassen und GenericTypeVars zu A hinzu - newReconResult.addClassName(this.getName()); - Menge genericsList = new Menge(); - for(int ii =0; ii getMethodList() { - - - if(this.methodList != null) return this.methodList; - //TODO: Unnötige Berechnungen im folgenden Code rauskürzen: - ////////////////////////////// - // Die Eingabedaten bauen: - ////////////////////////////// - inferencelog.debug("Baue Eingabedaten..."); - TypeAssumptions V_fields_methods = new TypeAssumptions(this.getName()); - Menge methodList = new Menge(); - Menge V = new Menge(); - Menge rememberLocals = new Menge(); - - ////////////////////////////// - // Alle Felder durchgehen: - // Zuerst alle Attribute, dann Methoden - // ge�ndert: hoth 06.04.2006 - - ////////////////////////////// - for(Field field : this.getFields()) - { - ////////////////////////////// - // Attribut: - ////////////////////////////// - - } - - for(Field field : this.getFields()) - { - ////////////////////////////// - // Methode: - ////////////////////////////// - if(field instanceof Method){ - Method method = (Method)field; - //if(method.get_Method_Name().equals(this.getName()) && ((method.getReturnType().equals(new mycompiler.mytype.Void(0))) || method.getReturnType() instanceof TypePlaceholder)){ - if(method.get_Method_Name().equals(this.getName()) ){ - method.set_Method_Name(""); - } - //hoth: 06.04.2006 - //durchlaufe Block und suche nach Objektvariablen fuer Offset-Markierung - Iterator fieldVarIterator = V_fields_methods.iterator(); - while (fieldVarIterator.hasNext()) - { - //Wenn ObjektVariable - CTypeAssumption dieAssum = fieldVarIterator.next(); - if(dieAssum instanceof CInstVarTypeAssumption) - { - Class.isFirstLocalVarDecl=false; - if(method.get_Block() != null) - method.get_Block().addOffsetsToAssumption(dieAssum,dieAssum.getIdentifier(),true); - } - } - - methodList.addElement(method); - - // F�r V_fields_methods: - CMethodTypeAssumption methodAssum = new CMethodTypeAssumption(this.getType(), method.get_Method_Name(), method.getReturnType(), method.getParameterCount(),method.getLineNumber(),method.getOffset(),new Menge(),method.getGenericMethodParameters()); // Typannahme bauen... - - - // Methode in V_Fields_methods ablegen - // Dabei wird die OverloadedMethodID ermittelt !! - // => Method setzenuct - - - V_fields_methods.add(methodAssum); - method.setOverloadedID(methodAssum.getHashSetKey().getOverloadedMethodID()); - - - // F�r die V_i: - CTypeAssumptionSet localAssum = new CTypeAssumptionSet(); - - // Bauen... - ParameterList parameterList = method.getParameterList(); - if(parameterList!=null){ - for(int i=0; i()); - //fuege Offsets fuer Parameter hinzu, hoth: 06.04.2006 - Class.isFirstLocalVarDecl=false; - - if(method.get_Block() != null) - method.get_Block().addOffsetsToAssumption(paraAssum,paraAssum.getIdentifier(),true); - - methodAssum.addParaAssumption(paraAssum); - - - - - // F�r die V_i: - CLocalVarTypeAssumption varAssum = new CLocalVarTypeAssumption(this.getName(), method.get_Method_Name(), method.getParameterCount(), method.getOverloadedID(),"1", para.getIdentifier(),para.getType(), para.getLineNumber(),para.getOffset(),new Menge()); - localAssum.addElement(varAssum); - rememberLocals.addElement(varAssum); - } - } - // ...und hinzuf�gen: - - V.addElement(localAssum); - } - } - - this.methodList = methodList; - return methodList; - - } -*/ /** * Ermittelt alle privaten Felder und Methoden der Klasse und Erstellt eine Assumption für diese. @@ -957,49 +698,8 @@ public class Class extends GTVDeclarationContext implements AClassOrInterface, I this.typeAssumptions = assumptions; //Diese müssen anschließend nicht wieder generiert werden. return assumptions; -} - /* - public ConstraintsSet TYPE(Menge methodList, Menge fielddeclarationList, TypeAssumptions assumptions){ - ConstraintsSet ret = new ConstraintsSet(); - // Die Felddeklarationen werden zu den Assumptions hinzugefügt und gelten danach für jede Methode. - //TypeAssumptions assumptionsPlusFieldAssumptions = new TypeAssumptions(assumptions); - for(Expr expr : fielddeclarationList){ - //ret.add(expr.TYPEStmt(assumptionsPlusFieldAssumptions)); - ret.add(expr.TYPEStmt(assumptions)); - } - for(Method methode : methodList){ - //ret.add(methode.TYPE(assumptionsPlusFieldAssumptions)); - ret.add(methode.TYPE(assumptions)); - } - return ret; - } - */ + } - - // ino.method.RetType.23119.defdescription type=javadoc - /** - * Liefert den berechneten R�ckgabetyp f�r die �bergebene Methode zur�ck.
- * (siehe Algorithmus RetType, Martin Pl�micke) - *
Author: J�rg B�uerle - * @param me - * @param V - * @return - - // ino.end - // ino.method.RetType.23119.definition - private Type RetType(Method me, CTypeAssumptionSet V) - // ino.end - // ino.method.RetType.23119.body - { - CTypeAssumption assum = V.getElement(new CMethodKey(this.getName(), me.get_Method_Name(), me.getParameterCount(),me.getOverloadedID())); - if(assum instanceof CMethodTypeAssumption){ - return ((CMethodTypeAssumption)assum).getAssumedType(); - } - else return null; - } - // ino.end - - */ // ino.method.toString.23125.defdescription type=javadoc /** *
Author: Martin Pl�micke @@ -1037,48 +737,8 @@ public class Class extends GTVDeclarationContext implements AClassOrInterface, I for(Field f : this.getFields()){ //f.wandleRefTypeAttributes2GenericAttributes(paralist); } - /* - Menge fieldsAndMethods=this.getFields(); - - // Alle Methoden und Instanzvariablen durchgehen - for(int i=0;i enumer = V_last.getHashtable().keys(); -// while(enumer.hasMoreElements()){ -// CTypeAssumption currentAssum = V_last.getElement(enumer.nextElement()); -// if(currentAssum instanceof CLocalVarTypeAssumption){ -// V_i.removeElement(currentAssum); -// } -// } -// -// } - - - // ino.method.getSimpleName.23140.defdescription type=javadoc /** * HOTI * Liefert bei Klassen die fullyQualified angegeben wurden @@ -1115,18 +775,6 @@ public class Class extends GTVDeclarationContext implements AClassOrInterface, I */ public String printJavaCode(TypeinferenceResultSet reconstructionResult){ JavaCodeResult ret = new JavaCodeResult("class "); - - - - - //Generiere JavaCode der extends-Typen: - /* - String containedTypesJavaCode = ""; - for(Type containedType : containedTypes){ - containedTypesJavaCode += containedType.printJavaCode(resultSet)+ ", "; - } - if(containedTypesJavaCode.length()>1)containedTypesJavaCode = containedTypesJavaCode.substring(0, containedTypesJavaCode.length() -2); - */ JavaCodeResult classBodyCode = new JavaCodeResult(); if(this.modifiers!=null)classBodyCode.attach(this.modifiers.printJavaCode(reconstructionResult.getUnifiedConstraints())).attach(" "); @@ -1382,5 +1030,22 @@ public class Class extends GTVDeclarationContext implements AClassOrInterface, I public boolean isInterface(){ return false; } + + private Collection getGenericClasses(ClassGenerator _cg) { + Collection results = new Menge<>(); + + //Super Klasse + String name = "java/util/Vectorjava/lang/String"; //getParentClass().getType().getBytecodeSignature(_cg); + + Type superClass = new Class("java/util/Vector",-1).getType(); + + _cg = new ClassGenerator(name, superClass, name + ".java", Constants.ACC_PUBLIC , new String[] { }, new TypeinferenceResultSet(null, null, null)); + + ByteCodeResult code = new ByteCodeResult(_cg); + + results.add(code); + + return results; + } } // ino.end diff --git a/src/de/dhbwstuttgart/syntaxtree/SourceFile.java b/src/de/dhbwstuttgart/syntaxtree/SourceFile.java index f96cc32e..22c45fd7 100755 --- a/src/de/dhbwstuttgart/syntaxtree/SourceFile.java +++ b/src/de/dhbwstuttgart/syntaxtree/SourceFile.java @@ -1834,8 +1834,8 @@ public class SourceFile * Bisher wird nur der Bytecode der Klassen generiert. Nicht der Interfaces. * @return */ - public Collection generateBytecode(TypeinferenceResultSet rs) { - Menge ret = new Menge<>(); + public Menge> generateBytecode(TypeinferenceResultSet rs) { + Menge> ret = new Menge<>(); for(Class cl : this.KlassenVektor){ ret.add(cl.genByteCode(rs)); } diff --git a/src/de/dhbwstuttgart/syntaxtree/type/RefType.java b/src/de/dhbwstuttgart/syntaxtree/type/RefType.java index ac0577da..4f2e045d 100755 --- a/src/de/dhbwstuttgart/syntaxtree/type/RefType.java +++ b/src/de/dhbwstuttgart/syntaxtree/type/RefType.java @@ -814,11 +814,12 @@ public class RefType extends ObjectType implements IMatchable } public org.apache.commons.bcel6.generic.Type getBytecodeType(ClassGenerator cg) { - return new org.apache.commons.bcel6.generic.ObjectType(this.getBytecodeSignature(cg)); + return new org.apache.commons.bcel6.generic.ObjectType(this.get_Name()); } @Override public String getBytecodeSignature(ClassGenerator cg) { + /* //Bsp.: Ljava/util/Vector; StringBuilder sb = new StringBuilder(); @@ -826,12 +827,14 @@ public class RefType extends ObjectType implements IMatchable if(parameter != null){ for(Type type: parameter){ - sb.append("%"); + sb.append(""); //TODO: einen geeignete Delemiter suchen sb.append(type.getBytecodeSignature(cg)); } } - /* + return sb.toString(); + */ + String paramString = ""; if(this.parameter != null && this.parameter.size()>0){ paramString+="<"; @@ -847,9 +850,6 @@ public class RefType extends ObjectType implements IMatchable String typeSignature = this.getBytecodeType(cg).getSignature(); typeSignature = typeSignature.substring(0, typeSignature.length()-1); return typeSignature+paramString+";"; - */ - - return sb.toString(); } } diff --git a/src/de/dhbwstuttgart/typeinference/TypeinferenceResultSet.java b/src/de/dhbwstuttgart/typeinference/TypeinferenceResultSet.java index 9a38d298..819d310b 100755 --- a/src/de/dhbwstuttgart/typeinference/TypeinferenceResultSet.java +++ b/src/de/dhbwstuttgart/typeinference/TypeinferenceResultSet.java @@ -119,7 +119,7 @@ public class TypeinferenceResultSet * Dabei wird die codegen-Methode der inferierten Klasse mit diesem ResultSet aufgerufen. */ public ByteCodeResult codegen(){ - ByteCodeResult res = this.ownerOfResultSet.genByteCode(this); + ByteCodeResult res = this.ownerOfResultSet.genByteCode(this).firstElement(); return res; } diff --git a/test/bytecode/BytecodeTest.java b/test/bytecode/BytecodeTest.java index eb1c2aae..35b8dc33 100644 --- a/test/bytecode/BytecodeTest.java +++ b/test/bytecode/BytecodeTest.java @@ -16,7 +16,7 @@ import org.junit.Test; public abstract class BytecodeTest extends TestCase{ public String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; public String testFile; - public String outputFile; + public String outputDirectory; protected String testName; @@ -26,9 +26,9 @@ public abstract class BytecodeTest extends TestCase{ if(testName != null){ testFile = testName+".jav"; - outputFile = testName+".class"; + outputDirectory = ""; - SingleClassTester.compileToBytecode(rootDirectory+testFile, rootDirectory+outputFile); + SingleClassTester.compileToBytecode(rootDirectory+testFile, rootDirectory+outputDirectory); }else{ throw new RuntimeException("rootDirectory, testFile or outputFile is null."); } diff --git a/test/bytecode/SingleClassTester.java b/test/bytecode/SingleClassTester.java index 323aaf53..a5d958f0 100644 --- a/test/bytecode/SingleClassTester.java +++ b/test/bytecode/SingleClassTester.java @@ -3,6 +3,8 @@ package bytecode; import java.io.File; import java.io.IOException; +import org.apache.commons.bcel6.classfile.JavaClass; + import com.google.common.io.Files; import junit.framework.TestCase; @@ -18,20 +20,28 @@ import de.dhbwstuttgart.typeinference.Menge; public class SingleClassTester { - public static void compileToBytecode(String inputFile, String outputFile){ + public static void compileToBytecode(String inputFile, String outputDirectory){ LoggerConfiguration logConfig = new LoggerConfiguration().setOutput(Section.PARSER, System.out); MyCompilerAPI compiler = MyCompiler.getAPI(logConfig); try { compiler.parse(new File(inputFile)); - Menge bytecode = compiler.generateBytecode(compiler.typeReconstruction().firstElement()); + Menge> bytecode = compiler.generateBytecode(compiler.typeReconstruction().firstElement()); //System.out.println(bytecode); - bytecode.firstElement().getByteCode().getJavaClass().dump(new File(outputFile)); + + for(ByteCodeResult result: bytecode.firstElement()){ + JavaClass javaClass = result.getByteCode().getJavaClass(); + + Logger.getLogger("SingleClassTester").error(result.getByteCode().getJavaClass().toString(), Section.CODEGEN); + + javaClass.dump(new File(outputDirectory+javaClass.getClassName()+".class")); + } + } catch (IOException | yyException e) { Logger.getLogger("SingleClassTester").error(e.toString(), Section.CODEGEN); e.printStackTrace(); TestCase.fail(); }finally{ - writeLog(outputFile+".log"); + writeLog(outputDirectory+".log"); } } diff --git a/test/bytecode/types/ExtendsVector.jav b/test/bytecode/types/ExtendsVector.jav index efd0240f..fed1dd07 100644 --- a/test/bytecode/types/ExtendsVector.jav +++ b/test/bytecode/types/ExtendsVector.jav @@ -1,4 +1,5 @@ import java.util.Vector; class ExtendsVector extends Vector{ + } \ No newline at end of file diff --git a/test/bytecode/types/TypedVector.jav b/test/bytecode/types/TypedVector.jav index a19b45bd..d64e4f5f 100644 --- a/test/bytecode/types/TypedVector.jav +++ b/test/bytecode/types/TypedVector.jav @@ -1,4 +1,4 @@ -import java.util.Stack; +import java.util.Vector; class TypedVector{ public void method(Vector v) { diff --git a/test/bytecode/types/TypedVectorTest.java b/test/bytecode/types/TypedVectorTest.java index 5383b5b9..ef32180b 100644 --- a/test/bytecode/types/TypedVectorTest.java +++ b/test/bytecode/types/TypedVectorTest.java @@ -9,6 +9,8 @@ import java.util.Vector; import org.junit.Test; import bytecode.BytecodeTest; +import de.dhbwstuttgart.logger.Logger; +import de.dhbwstuttgart.logger.Section; public class TypedVectorTest extends BytecodeTest{ @Override @@ -32,7 +34,7 @@ public class TypedVectorTest extends BytecodeTest{ method.invoke(obj, stringVector); assertTrue(true); }catch(Exception e){ - e.printStackTrace(); + Logger.getLogger("SingleClassTester").error(e.toString(), Section.CODEGEN); fail(); } } From 6a8590ab0d0731365e024cbe856191670e43d916 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Enrico=20Schr=C3=B6dter?= Date: Fri, 16 Oct 2015 13:22:08 +0200 Subject: [PATCH 9/9] FreshWildcardType muss von ObjectType ableiten, damit der Unifikationsalgorithmus funktioniert --- src/de/dhbwstuttgart/syntaxtree/type/FreshWildcardType.java | 2 +- test/bytecode/types/ExtendsVector.jav | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/de/dhbwstuttgart/syntaxtree/type/FreshWildcardType.java b/src/de/dhbwstuttgart/syntaxtree/type/FreshWildcardType.java index 33f153e0..40ddb895 100755 --- a/src/de/dhbwstuttgart/syntaxtree/type/FreshWildcardType.java +++ b/src/de/dhbwstuttgart/syntaxtree/type/FreshWildcardType.java @@ -8,7 +8,7 @@ import de.dhbwstuttgart.typeinference.JavaCodeResult; import de.dhbwstuttgart.typeinference.ResultSet; import de.dhbwstuttgart.typeinference.exceptions.NotImplementedException; -public class FreshWildcardType extends Type { +public class FreshWildcardType extends ObjectType { private static String strNextName = "A"; private Menge upperBounds = new Menge(); diff --git a/test/bytecode/types/ExtendsVector.jav b/test/bytecode/types/ExtendsVector.jav index fed1dd07..f029967d 100644 --- a/test/bytecode/types/ExtendsVector.jav +++ b/test/bytecode/types/ExtendsVector.jav @@ -1,5 +1,5 @@ import java.util.Vector; -class ExtendsVector extends Vector{ +class ExtendsVector extends Vector{ } \ No newline at end of file