Merge branch 'bytecode' of ssh://gohorb.ba-horb.de/bahome/projekt/git/JavaCompilerCore into refactoring

This commit is contained in:
JanUlrich 2016-04-07 14:52:04 +02:00
commit 74c2b5e323
9 changed files with 105 additions and 44 deletions

View File

@ -2,6 +2,8 @@ package de.dhbwstuttgart.bytecode;
import java.awt.List;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import org.apache.commons.bcel6.Constants;
import org.apache.commons.bcel6.classfile.Attribute;
@ -32,6 +34,7 @@ public class DHBWInstructionFactory extends InstructionFactory{
private DHBWConstantPoolGen cp;
private ClassGenerator cg;
private static Map<String, Integer> storeIndexes = new HashMap<>();
public DHBWInstructionFactory(ClassGenerator cg, DHBWConstantPoolGen cp) {
super(cg, cp);
@ -137,8 +140,15 @@ public class DHBWInstructionFactory extends InstructionFactory{
}
public LocalVariableInstruction createLoad(org.apache.commons.bcel6.generic.Type bytecodeType, String variableName) {
int index = 1; //TODO: Hier muss ein Logger her, welcher aufzeichnet, an welcher Position welche Variable liegt.
return InstructionFactory.createLoad(bytecodeType, index);
return InstructionFactory.createLoad(bytecodeType, storeIndexes.get(variableName));
}
public Integer getStoreIndex(String variableName) {
if(!storeIndexes.containsKey(variableName)){
storeIndexes.put(variableName, storeIndexes.size()+1);
}
return storeIndexes.get(variableName);
}
public static Type createObjectType() {

View File

@ -183,8 +183,6 @@ public class FieldDeclaration extends Field{
if(wert != null){
il.append(this.wert.genByteCode(cg, rs));
}else{
//todo: default wert?
}
FieldInstruction putFieldInstruction =

View File

@ -17,6 +17,7 @@ import org.apache.commons.bcel6.generic.LSTORE;
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.bytecode.ClassGenerator;
import de.dhbwstuttgart.bytecode.DHBWInstructionFactory;
import de.dhbwstuttgart.logger.Logger;
import de.dhbwstuttgart.myexception.CTypeReconstructionException;
import de.dhbwstuttgart.myexception.JVMCodeException;
@ -175,18 +176,12 @@ public class Assign extends Expr
return ret;
}
public static int counterAssign = 0; //Zaehlvariable f<EFBFBD>r ISTORE
@Override
public InstructionList genByteCode(ClassGenerator cg, TypeinferenceResultSet rs) {
// TODO Auto-generated method stub
InstructionFactory _factory = new InstructionFactory(cg, cg.getConstantPool());
DHBWInstructionFactory _factory = new DHBWInstructionFactory(cg, cg.getConstantPool());
InstructionList il = expr2.genByteCode(cg, rs);//expr2 rechte expr
/*
String expr2Type = expr2.getType().get_Name().toString();
switch(expr2Type){
@ -212,10 +207,7 @@ public class Assign extends Expr
}
*/
//Es wird momentan immer von RefType ausgegangen:
il.append(new ASTORE(counterAssign));
//TODO: ^^
counterAssign++; //macht STORE f<EFBFBD>r meherere Variable nutzbar (nicht nur ISTORE_1, ISTORE_2, etc.)
il.append(new ASTORE(_factory.getStoreIndex(expr1.get_Name())));
return il;
}

View File

@ -16,35 +16,6 @@ public class TypeinferenceResults {
}
public TypeinferenceResults(Menge<TypeinferenceResultSet> typeReconstructions) {
//TODO: filter
int limit = typeReconstructions.size();
Logger.getLogger("TypeinferenceResults").error(new Integer(limit).toString(), Section.CODEGEN);
for(int i = 0; i < limit; i++){
Logger.getLogger("TypeinferenceResults").error(new Integer(i).toString(), Section.CODEGEN);
for(Pair p: typeReconstructions.get(i).getUnifiedConstraints()){
boolean flag = false;
Logger.getLogger("TypeinferenceResults").error(p.toString(), Section.CODEGEN);
if( p.TA1 instanceof SuperWildcardType ||
p.TA1 instanceof ExtendsWildcardType ||
p.TA2 instanceof SuperWildcardType ||
p.TA2 instanceof ExtendsWildcardType ||
flag){
Logger.getLogger("TypeinferenceResults").error("remove", Section.CODEGEN);
typeReconstructions.remove(i);
i--;
limit--;
flag = true;
}
}
}
this.typeReconstructions = typeReconstructions;
}

View File

@ -0,0 +1,5 @@
class SystemOutPrintln{
void method() {
System.out.println("Hello World");
}
}

View 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 SystemOutPrintlnTest {
public final static String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/";
public final static String testFile = "SystemOutPrintln.jav";
public final static String outputFile = "SystemOutPrintln.class";
@Test
public void test() {
SingleClassTester.compileToBytecode(rootDirectory+testFile, rootDirectory+outputFile);
}
}

View File

@ -9,4 +9,14 @@ class Overloading{
void method(Vector<Integer> v) {
}
main(String[] args) {
ol;
ol = new Overloading();
v;
v = new Vector<String> ();
ol.method(v);
}
}

View File

@ -0,0 +1,13 @@
import java.util.Vector;
class SuperType{
Vector<Number> numberVector;
void method() {
method(numberVector);
}
void method(Vector<? super Integer> v) {
}
}

View File

@ -0,0 +1,28 @@
package bytecode.types;
import static org.junit.Assert.*;
import org.junit.Test;
import bytecode.SourceFileBytecodeTest;
public class WildcardTest extends SourceFileBytecodeTest{
@Override
protected void init() {
testName = "Wildcard";
rootDirectory = System.getProperty("user.dir")+"/test/bytecode/types/";
}
@Test
public void testConstruct() throws Exception{
ClassLoader classLoader = getClassLoader();
Class cls = classLoader.loadClass(testName);
Object obj = cls.newInstance();
assertTrue(true);
}
}