forked from JavaTX/JavaCompilerCore
Bugfix: Store and Load
This commit is contained in:
parent
336dc52be6
commit
7b78cf8471
@ -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() {
|
||||
|
@ -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 =
|
||||
|
@ -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;
|
||||
@ -176,18 +177,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){
|
||||
@ -213,10 +208,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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
||||
}
|
||||
|
||||
}
|
13
test/bytecode/types/WildcardTest.jav
Normal file
13
test/bytecode/types/WildcardTest.jav
Normal file
@ -0,0 +1,13 @@
|
||||
import java.util.Vector;
|
||||
|
||||
class SuperType{
|
||||
Vector<Number> numberVector;
|
||||
|
||||
void method() {
|
||||
method(numberVector);
|
||||
}
|
||||
|
||||
void method(Vector<? super Integer> v) {
|
||||
|
||||
}
|
||||
}
|
28
test/bytecode/types/WildcardTest.java
Normal file
28
test/bytecode/types/WildcardTest.java
Normal 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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user