ConditionTest angelegt
ForTest gefixed
This commit is contained in:
parent
f23a341d72
commit
d6fb9ff2c7
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
@ -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);
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
7
test/bytecode/Condition.jav
Normal file
7
test/bytecode/Condition.jav
Normal file
@ -0,0 +1,7 @@
|
||||
class Condition{
|
||||
|
||||
Boolean method() {
|
||||
return 0 == 1;
|
||||
}
|
||||
|
||||
}
|
34
test/bytecode/ConditionTest.java
Normal file
34
test/bytecode/ConditionTest.java
Normal file
@ -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);
|
||||
}
|
||||
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
class IfElse{
|
||||
method(){
|
||||
while(true){
|
||||
for( i = 0; i < 10 ; i = i++){
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ public class SingleClassTester {
|
||||
try {
|
||||
compiler.parse(new File(inputFile));
|
||||
Menge<ByteCodeResult> 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();
|
||||
|
Loading…
Reference in New Issue
Block a user