Beginn der Generierung der GenericKlasse, Problem ist der Konstruktor, dieser wird auf Objekt aufgerufen und nicht auf der SUperklasse

This commit is contained in:
Enrico Schrödter 2015-10-16 15:15:30 +02:00
parent 6a8590ab0d
commit 50dda3041f
3 changed files with 82 additions and 15 deletions

View File

@ -24,6 +24,7 @@ import de.dhbwstuttgart.bytecode.DHBWInstructionFactory;
import de.dhbwstuttgart.core.AClassOrInterface;
import de.dhbwstuttgart.core.IItemWithOffset;
import de.dhbwstuttgart.parser.JavaClassName;
import de.dhbwstuttgart.syntaxtree.misc.DeclId;
import de.dhbwstuttgart.syntaxtree.misc.UsedId;
import de.dhbwstuttgart.syntaxtree.modifier.Modifiers;
import de.dhbwstuttgart.syntaxtree.statement.Block;
@ -1035,11 +1036,65 @@ public class Class extends GTVDeclarationContext implements AClassOrInterface, I
Collection<ByteCodeResult> results = new Menge<>();
//Super Klasse
String name = "java/util/Vectorjava/lang/String"; //getParentClass().getType().getBytecodeSignature(_cg);
String name = getType().getCombinedType(_cg);
Type superClass = new Class("java/util/Vector",-1).getType();
Class superClass = new Class("java/util/Vector",-1);
Type superClassType = superClass.getType();
_cg = new ClassGenerator(name, superClass, name + ".java", Constants.ACC_PUBLIC , new String[] { }, new TypeinferenceResultSet(null, null, null));
//_cg = new ClassGenerator(name, superClassType, name + ".java", Constants.ACC_PUBLIC , new String[] { }, new TypeinferenceResultSet(null, null, null));
Class generatedClass = new Class(name, 0);
Block konstruktorBlock = new Block();
konstruktorBlock.statements.add(new SuperCall(konstruktorBlock));
Constructor standardKonstruktor = new Constructor(Method.createEmptyMethod(konstruktorBlock, name, superClass), superClass);
generatedClass.addField(standardKonstruktor);
results.addAll(generatedClass.genByteCode(new TypeinferenceResultSet(generatedClass, new Menge<>(), new ResultSet())));
/*
//Die Felder in Methoden Felder und Konstruktoren aufteilen:
Menge<FieldDeclaration> fieldDeclarations = new Menge<>();
Menge<Constructor> constructors = new Menge<>();
Block konstruktorBlock = new Block();
konstruktorBlock.statements.add(new SuperCall(konstruktorBlock));
Method constructorMethod = Method.createEmptyMethod(konstruktorBlock, name, superClass);
constructorMethod.parameterlist = new ParameterList();
Constructor constructor = new Constructor(constructorMethod, superClass);
constructor.parserPostProcessing(superClass);
constructors.add(constructor);
InstructionList fieldInitializations = new InstructionList();
for(FieldDeclaration f : fieldDeclarations){
fieldInitializations.append(f.genByteCode(_cg));
}
//Die Konstruktoren müssen die Feld initialisierungswerte beinhalten:
for(Constructor c : constructors){
c.genByteCode(_cg, fieldInitializations);
}
*/
/*
Block konstruktorBlock = new Block();
konstruktorBlock.statements.add(new SuperCall(konstruktorBlock));
Constructor standardKonstruktor = new Constructor(Method.createEmptyMethod(konstruktorBlock,name, superClass), superClass);
Menge<Constructor> constructors = new Menge<>();
constructors.add(standardKonstruktor);
//Die Konstruktoren müssen die Feld initialisierungswerte beinhalten:
for(Constructor c : constructors){
c.genByteCode(_cg, new InstructionList());
}
*/
ByteCodeResult code = new ByteCodeResult(_cg);

View File

@ -814,7 +814,7 @@ public class RefType extends ObjectType implements IMatchable
}
public org.apache.commons.bcel6.generic.Type getBytecodeType(ClassGenerator cg) {
return new org.apache.commons.bcel6.generic.ObjectType(this.get_Name());
return new org.apache.commons.bcel6.generic.ObjectType(getCombinedType(cg));
}
@Override
@ -852,6 +852,23 @@ public class RefType extends ObjectType implements IMatchable
return typeSignature+paramString+";";
}
public String getCombinedType(ClassGenerator cg){
//Bsp.: Ljava/util/Vector<Ljava/lang/String;>;
StringBuilder sb = new StringBuilder();
sb.append(this.get_Name().replace(".", "%"));
if(parameter != null){
sb.append("%%");
for(Type type: parameter){
sb.append(((RefType) type).getCombinedType(cg));
sb.append("%");
}
}
return sb.toString();
}
}
// ino.end

View File

@ -32,17 +32,12 @@ public class ExtendsVectorStringTest extends BytecodeTest{
}
@Test
public void testConstruct(){
try{
Class cls = getClassToTest();
Constructor method = cls.getConstructor(new Class[]{});
method.newInstance();
assertTrue(true);
}catch(Exception e){
e.printStackTrace();
fail();
}
public void testConstruct() throws Exception{
Class cls = getClassToTest();
Constructor method = cls.getConstructor(new Class[]{});
method.newInstance();
assertTrue(true);
}
}