Mehrere Lösungen in einer Class file

This commit is contained in:
Enrico Schrödter 2015-11-09 09:38:49 +01:00
parent 87e49a692a
commit 54a11c8779
5 changed files with 72 additions and 45 deletions

View File

@ -69,12 +69,12 @@ public class ClassGenerator extends ClassGen{
return this.getNearestUsedType(toTPH, null);
}
public Menge<Type> resolveTPH(TypePlaceholder typePlaceholder) {
return resolveTPH(typePlaceholder, null);
public Type resolveTPH(TypePlaceholder typePlaceholder, Integer typeinferenceResultSetIndex) {
return resolveTPH(typePlaceholder, typeinferenceResultSetIndex, null);
}
public Menge<Type> resolveTPH(TypePlaceholder typePlaceholder, Menge<TypePlaceholder> toOneOfTheseTypes) {
return tiResult.getTypeOfPlaceholder(typePlaceholder, toOneOfTheseTypes);
public Type resolveTPH(TypePlaceholder typePlaceholder, Integer typeinferenceResultSetIndex, Menge<TypePlaceholder> toOneOfTheseTypes) {
return tiResult.getTypeOfPlaceholder(typePlaceholder, typeinferenceResultSetIndex, toOneOfTheseTypes);
}
public String createLambdaMethodName() {
@ -167,4 +167,10 @@ public class ClassGenerator extends ClassGen{
return extraClasses;
}
public TypeinferenceResults getTypeinferenceResults() {
return tiResult;
}
}

View File

@ -746,6 +746,7 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable
}
public void genByteCode(ClassGenerator cg) {
for(int t = 0; t < cg.getTypeinferenceResults().getTypeReconstructions().size(); t++){
DHBWConstantPoolGen _cp = cg.getConstantPool();
DHBWInstructionFactory _factory = new DHBWInstructionFactory(cg, _cp);
InstructionList il = new InstructionList();
@ -760,7 +761,11 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable
argumentNames = new String[this.parameterlist.size()];
int i = 0;
for(FormalParameter parameter : this.parameterlist){
if(parameter.getType() instanceof TypePlaceholder){
argumentTypes[i] = ((TypePlaceholder) parameter.getType()).getBytecodeType(cg, t);
}else{
argumentTypes[i] = parameter.getType().getBytecodeType(cg);
}
argumentNames[i] = parameter.getIdentifier();
i++;
}
@ -773,7 +778,7 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable
//Methode generieren und anfügen:
cg.addMethod(method.createMethod(cg, getParameterList(), getType(), get_Block()));
}
}
}

View File

@ -437,21 +437,33 @@ public class TypePlaceholder extends ObjectType
@Override
public org.apache.commons.bcel6.generic.Type getBytecodeType(ClassGenerator cg) {
Menge<Type> resolvedType = cg.resolveTPH(this);
if(resolvedType.firstElement() instanceof TypePlaceholder){
Type resolvedType = cg.resolveTPH(this, 0);
if(resolvedType instanceof TypePlaceholder){
return DHBWInstructionFactory.createObjectType();
}
return resolvedType.firstElement().getBytecodeType(cg);
return resolvedType.getBytecodeType(cg);
}
public org.apache.commons.bcel6.generic.Type getBytecodeType(ClassGenerator cg, Integer typeReconstructionSetIndex) {
Type resolvedType = cg.resolveTPH(this, typeReconstructionSetIndex);
if(resolvedType instanceof TypePlaceholder){
return DHBWInstructionFactory.createObjectType();
}
return resolvedType.getBytecodeType(cg);
}
@Override
public String getBytecodeSignature(ClassGenerator cg) {
Menge<Type> resolvedType = cg.resolveTPH(this);
if(resolvedType.firstElement() instanceof TypePlaceholder){
cg.addUsedTPH((TypePlaceholder)resolvedType.firstElement());
return new TypePlaceholderType((TypePlaceholder)resolvedType.firstElement()).getSignature();
return getBytecodeSignature(cg, 0);
}
return resolvedType.firstElement().getBytecodeSignature(cg);
public String getBytecodeSignature(ClassGenerator cg, Integer typeReconstructionSetIndex) {
Type resolvedType = cg.resolveTPH(this, typeReconstructionSetIndex);
if(resolvedType instanceof TypePlaceholder){
cg.addUsedTPH((TypePlaceholder)resolvedType);
return new TypePlaceholderType((TypePlaceholder)resolvedType).getSignature();
}
return resolvedType.getBytecodeSignature(cg);
}
@Override

View File

@ -5,17 +5,21 @@ import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
public class TypeinferenceResults {
private Menge<TypeinferenceResultSet> typeReconstructions;
public TypeinferenceResults() {
// TODO Auto-generated constructor stub
typeReconstructions = new Menge<>();
}
public TypeinferenceResults(Menge<TypeinferenceResultSet> typeReconstruction) {
// TODO Auto-generated constructor stub
public TypeinferenceResults(Menge<TypeinferenceResultSet> typeReconstructions) {
this.typeReconstructions = typeReconstructions;
}
public Menge<Type> getTypeOfPlaceholder(TypePlaceholder typePlaceholder, Menge<TypePlaceholder> toOneOfTheseTypes) {
// TODO Auto-generated method stub
return null;
public Type getTypeOfPlaceholder(TypePlaceholder typePlaceholder, Integer typeinferenceResultSetIndex, Menge<TypePlaceholder> toOneOfTheseTypes) {
return typeReconstructions.get(typeinferenceResultSetIndex).getTypeOfPlaceholder(typePlaceholder, toOneOfTheseTypes);
}
public Menge<TypeinferenceResultSet> getTypeReconstructions() {
return typeReconstructions;
}
}

View File

@ -57,7 +57,7 @@ public class SingleClassTester {
e.printStackTrace();
TestCase.fail();
}finally{
writeLog(outputDirectory+".log");
writeLog(outputDirectory+"bytecode.log");
}
}