forked from JavaTX/JavaCompilerCore
Änderungen an IFStmt
This commit is contained in:
parent
f23a341d72
commit
a541b353cd
6
BCEL/bcelifier/BooleanValue.java
Normal file
6
BCEL/bcelifier/BooleanValue.java
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
package bcelifier;
|
||||||
|
|
||||||
|
public class BooleanValue {
|
||||||
|
Boolean c = true;
|
||||||
|
Boolean b = c.booleanValue();
|
||||||
|
}
|
63
BCEL/bcelifier/BooleanValueCreator.java
Normal file
63
BCEL/bcelifier/BooleanValueCreator.java
Normal file
@ -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[] { }, "<init>", "bcelifier.BooleanValue", il, _cp);
|
||||||
|
|
||||||
|
InstructionHandle ih_0 = il.append(_factory.createLoad(Type.OBJECT, 0));
|
||||||
|
il.append(_factory.createInvoke("java.lang.Object", "<init>", 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"));
|
||||||
|
}
|
||||||
|
}
|
@ -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+"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+"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+"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) {
|
} catch (ClassFormatException | IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -185,6 +185,8 @@ public class IfStmt extends Statement
|
|||||||
IfInstruction ifInstruction = new IFEQ(null);
|
IfInstruction ifInstruction = new IFEQ(null);
|
||||||
|
|
||||||
il.append(expr.genByteCode(_cg));
|
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(ifInstruction);
|
||||||
il.append(then_block.genByteCode(_cg));
|
il.append(then_block.genByteCode(_cg));
|
||||||
|
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
class IfElseStatement{
|
class IfElseStatement{
|
||||||
method(flag){
|
method(flag){
|
||||||
if(flag){
|
if(flag){
|
||||||
|
return 0;
|
||||||
}else{
|
}else{
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
9
test/bytecode/IfTest.java
Normal file
9
test/bytecode/IfTest.java
Normal file
@ -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));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user