From ba6ae74ad12db7715f6db60a29ff7cfa21ef9471 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Enrico=20Schr=C3=B6dter?= Date: Fri, 29 Apr 2016 10:00:33 +0200 Subject: [PATCH] =?UTF-8?q?-Tests=20f=C3=BCr=20for=20und=20While=20Schleif?= =?UTF-8?q?e=20korrigiert=20-=20While=20teilweise=20implementiert?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../syntaxtree/statement/ForStmt.java | 4 ---- .../syntaxtree/statement/WhileStmt.java | 20 +++++++++++++++++-- test/bytecode/ForTest.jav | 6 +++--- test/bytecode/WhileTest.jav | 10 ++++++---- 4 files changed, 27 insertions(+), 13 deletions(-) diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/ForStmt.java b/src/de/dhbwstuttgart/syntaxtree/statement/ForStmt.java index eeff85ba..69998638 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/ForStmt.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/ForStmt.java @@ -39,10 +39,6 @@ import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions; import de.dhbwstuttgart.typeinference.exceptions.NotImplementedException; import de.dhbwstuttgart.typeinference.unify.Unify; - - - - public class ForStmt extends Statement { diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/WhileStmt.java b/src/de/dhbwstuttgart/syntaxtree/statement/WhileStmt.java index dd95b912..f9816ade 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/WhileStmt.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/WhileStmt.java @@ -6,7 +6,11 @@ import java.util.Enumeration; import java.util.Hashtable; import java.util.Iterator; +import org.apache.commons.bcel6.generic.BranchInstruction; import org.apache.commons.bcel6.generic.ClassGen; +import org.apache.commons.bcel6.generic.DUP; +import org.apache.commons.bcel6.generic.GOTO; +import org.apache.commons.bcel6.generic.IFEQ; import org.apache.commons.bcel6.generic.InstructionList; import de.dhbwstuttgart.typeinference.Menge; @@ -139,8 +143,20 @@ public class WhileStmt extends Statement @Override public InstructionList genByteCode(ClassGenerator _cg, TypeinferenceResultSet rs) { - // TODO Bytecode - throw new NotImplementedException(); + //TOD: while Statement + InstructionList il = expr.genByteCode(_cg, rs); + + BranchInstruction ifeq = new IFEQ(null); + il.append(ifeq); + + il.append(loop_block.genByteCode(_cg, rs)); + + il.append(new GOTO(il.getStart())); + + ifeq.setTarget(il.append(new DUP())); + + + return il; } } // ino.end diff --git a/test/bytecode/ForTest.jav b/test/bytecode/ForTest.jav index 649b71b0..d2723cf4 100644 --- a/test/bytecode/ForTest.jav +++ b/test/bytecode/ForTest.jav @@ -1,6 +1,6 @@ -class IfElse{ - method(){ - for( i = 0; i < 10 ; i = i++){ +class ForTest{ + void method(){ + for(Integer i = 0; i < 10 ; i = i + 1){ } } diff --git a/test/bytecode/WhileTest.jav b/test/bytecode/WhileTest.jav index 7343a1b8..fa39c905 100644 --- a/test/bytecode/WhileTest.jav +++ b/test/bytecode/WhileTest.jav @@ -1,7 +1,9 @@ -class IfElse{ - method(){ - while(true){ - +class WhileTest{ + void method(){ + Integer i; + i = 1; + while(i < 10){ + i = i + 1; } } } \ No newline at end of file