forked from JavaTX/JavaCompilerCore
Merge branch 'bytecode' of ssh://gohorb.ba-horb.de/bahome/projekt/git/JavaCompilerCore into bytecode
This commit is contained in:
commit
7530e01ea9
@ -65,8 +65,8 @@ public class Constructor extends Method {
|
|||||||
this.method = new MethodGen(Constants.ACC_PUBLIC, this.getType().getBytecodeType(), org.apache.bcel.generic.Type.NO_ARGS , new String[] { }, "<init>", parentClass.name, il, _cp);
|
this.method = new MethodGen(Constants.ACC_PUBLIC, this.getType().getBytecodeType(), org.apache.bcel.generic.Type.NO_ARGS , new String[] { }, "<init>", parentClass.name, il, _cp);
|
||||||
|
|
||||||
//Iteration <EFBFBD>ber Block starten
|
//Iteration <EFBFBD>ber Block starten
|
||||||
Block instructions = this.get_Block();
|
Block block = this.get_Block();
|
||||||
InstructionList blockInstructions = instructions.genByteCode(cg);
|
InstructionList blockInstructions = block.genByteCode(cg);
|
||||||
|
|
||||||
il.append(blockInstructions);//Die vom Block generierten Instructions an die InstructionList der Methode anfügen
|
il.append(blockInstructions);//Die vom Block generierten Instructions an die InstructionList der Methode anfügen
|
||||||
|
|
||||||
|
@ -741,19 +741,27 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void genByteCode(ClassGen cg) {
|
public void genByteCode(ClassGen cg) {
|
||||||
/*ConstantPoolGen _cp = cg.getConstantPool();
|
ConstantPoolGen _cp = cg.getConstantPool();
|
||||||
* InstructionFactory _factory = new InstructionFactory(cg, _cp);
|
InstructionFactory _factory = new InstructionFactory(cg, _cp);
|
||||||
* InstructionList il = new InstructionList();
|
InstructionList il = new InstructionList();
|
||||||
* Class parentClass = this.getParentClass();
|
Class parentClass = this.getParentClass();
|
||||||
*/
|
|
||||||
|
MethodGen method = new MethodGen(Constants.ACC_PUBLIC, this.getType().getBytecodeType(), org.apache.bcel.generic.Type.NO_ARGS , new String[] { }, this.get_Method_Name(), parentClass.name, il, _cp);
|
||||||
|
|
||||||
//oben steht MethodGen method als Variable (Z. 71)
|
Block block = this.get_Block();
|
||||||
|
InstructionList blockInstructions = block.genByteCode(cg);
|
||||||
|
|
||||||
// <EFBFBD>ber Statements iterieren um Block abzurufen
|
il.append(blockInstructions);//Die vom Block generierten Instructions an die InstructionList der Methode anfügen
|
||||||
for (Statement statements : block.get_Statement()) {
|
|
||||||
statements.genByteCode(cg);
|
if (block.get_Statement().size() == 0) { il.append(_factory.createReturn(org.apache.bcel.generic.Type.VOID)); }
|
||||||
|
else {
|
||||||
|
if (!(block.get_Statement().lastElement() instanceof Return)) { il.append(_factory.createReturn(org.apache.bcel.generic.Type.VOID)); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
method.setMaxStack(); //Die Stack Größe automatisch berechnen lassen (erst nach dem alle Instructions angehängt wurden)
|
||||||
|
|
||||||
|
cg.addMethod(method.getMethod());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,9 @@ package de.dhbwstuttgart.syntaxtree.statement;
|
|||||||
// ino.module.Return.8651.import
|
// ino.module.Return.8651.import
|
||||||
import java.util.Hashtable;
|
import java.util.Hashtable;
|
||||||
|
|
||||||
|
import org.apache.bcel.generic.ConstantPoolGen;
|
||||||
|
import org.apache.bcel.generic.InstructionFactory;
|
||||||
|
import org.apache.bcel.generic.InstructionList;
|
||||||
import org.apache.bcel.generic.ClassGen;
|
import org.apache.bcel.generic.ClassGen;
|
||||||
|
|
||||||
import de.dhbwstuttgart.typeinference.Menge;
|
import de.dhbwstuttgart.typeinference.Menge;
|
||||||
@ -130,9 +133,13 @@ public class Return extends Statement
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void genByteCode(ClassGen _cg) {
|
public InstructionList genByteCode(ClassGen cg) {
|
||||||
// TODO Auto-generated method stub
|
InstructionFactory _factory = new InstructionFactory(cg, cg.getConstantPool());
|
||||||
|
InstructionList il = new InstructionList();
|
||||||
|
il.append(_factory.createReturn(org.apache.bcel.generic.Type.VOID));
|
||||||
|
//TO BE DONE
|
||||||
|
|
||||||
|
return il;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// ino.end
|
// ino.end
|
||||||
|
@ -810,6 +810,10 @@ public class RefType extends ObjectType implements IMatchable
|
|||||||
param.parserPostProcessing(this);
|
param.parserPostProcessing(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public org.apache.bcel.generic.Type getBytecodeType() {
|
||||||
|
return new org.apache.bcel.generic.ObjectType(this.getTypeName());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
// ino.end
|
// ino.end
|
||||||
|
7
test/bytecode/MethodEmpty.jav
Normal file
7
test/bytecode/MethodEmpty.jav
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
class MethodEmpty{
|
||||||
|
|
||||||
|
|
||||||
|
void method() { }
|
||||||
|
|
||||||
|
|
||||||
|
}
|
45
test/bytecode/MethodEmpty.java
Normal file
45
test/bytecode/MethodEmpty.java
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
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 MethodEmpty {
|
||||||
|
|
||||||
|
public final static String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/";
|
||||||
|
public final static String testFile = "MethodEmpty.jav";
|
||||||
|
public final static String outputFile = "MethodEmpty.class";
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test() {
|
||||||
|
LoggerConfiguration logConfig = new LoggerConfiguration().setOutput(Section.PARSER, System.out);
|
||||||
|
MyCompilerAPI compiler = MyCompiler.getAPI(logConfig);
|
||||||
|
try {
|
||||||
|
compiler.parse(new File(rootDirectory + testFile));
|
||||||
|
compiler.typeReconstruction();
|
||||||
|
ByteCodeResult bytecode = compiler.generateBytecode();
|
||||||
|
System.out.println(bytecode);
|
||||||
|
bytecode.getByteCode().getJavaClass().dump(new File(rootDirectory + outputFile));
|
||||||
|
} catch (IOException | yyException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
TestCase.fail();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
7
test/bytecode/MethodEmptyRetType.jav
Normal file
7
test/bytecode/MethodEmptyRetType.jav
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
class MethodEmptyRetType{
|
||||||
|
|
||||||
|
|
||||||
|
Object method() { return null; }
|
||||||
|
|
||||||
|
|
||||||
|
}
|
45
test/bytecode/MethodEmptyRetType.java
Normal file
45
test/bytecode/MethodEmptyRetType.java
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
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 MethodEmptyRetType {
|
||||||
|
|
||||||
|
public final static String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/";
|
||||||
|
public final static String testFile = "MethodEmptyRetType.jav";
|
||||||
|
public final static String outputFile = "MethodEmptyRetType.class";
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test() {
|
||||||
|
LoggerConfiguration logConfig = new LoggerConfiguration().setOutput(Section.PARSER, System.out);
|
||||||
|
MyCompilerAPI compiler = MyCompiler.getAPI(logConfig);
|
||||||
|
try {
|
||||||
|
compiler.parse(new File(rootDirectory + testFile));
|
||||||
|
compiler.typeReconstruction();
|
||||||
|
ByteCodeResult bytecode = compiler.generateBytecode();
|
||||||
|
System.out.println(bytecode);
|
||||||
|
bytecode.getByteCode().getJavaClass().dump(new File(rootDirectory + outputFile));
|
||||||
|
} catch (IOException | yyException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
TestCase.fail();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user