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); return this.getNearestUsedType(toTPH, null);
} }
public Menge<Type> resolveTPH(TypePlaceholder typePlaceholder) { public Type resolveTPH(TypePlaceholder typePlaceholder, Integer typeinferenceResultSetIndex) {
return resolveTPH(typePlaceholder, null); return resolveTPH(typePlaceholder, typeinferenceResultSetIndex, null);
} }
public Menge<Type> resolveTPH(TypePlaceholder typePlaceholder, Menge<TypePlaceholder> toOneOfTheseTypes) { public Type resolveTPH(TypePlaceholder typePlaceholder, Integer typeinferenceResultSetIndex, Menge<TypePlaceholder> toOneOfTheseTypes) {
return tiResult.getTypeOfPlaceholder(typePlaceholder, toOneOfTheseTypes); return tiResult.getTypeOfPlaceholder(typePlaceholder, typeinferenceResultSetIndex, toOneOfTheseTypes);
} }
public String createLambdaMethodName() { public String createLambdaMethodName() {
@ -167,4 +167,10 @@ public class ClassGenerator extends ClassGen{
return extraClasses; 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) { public void genByteCode(ClassGenerator cg) {
for(int t = 0; t < cg.getTypeinferenceResults().getTypeReconstructions().size(); t++){
DHBWConstantPoolGen _cp = cg.getConstantPool(); DHBWConstantPoolGen _cp = cg.getConstantPool();
DHBWInstructionFactory _factory = new DHBWInstructionFactory(cg, _cp); DHBWInstructionFactory _factory = new DHBWInstructionFactory(cg, _cp);
InstructionList il = new InstructionList(); InstructionList il = new InstructionList();
@ -760,7 +761,11 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable
argumentNames = new String[this.parameterlist.size()]; argumentNames = new String[this.parameterlist.size()];
int i = 0; int i = 0;
for(FormalParameter parameter : this.parameterlist){ 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); argumentTypes[i] = parameter.getType().getBytecodeType(cg);
}
argumentNames[i] = parameter.getIdentifier(); argumentNames[i] = parameter.getIdentifier();
i++; i++;
} }
@ -773,7 +778,7 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable
//Methode generieren und anfügen: //Methode generieren und anfügen:
cg.addMethod(method.createMethod(cg, getParameterList(), getType(), get_Block())); cg.addMethod(method.createMethod(cg, getParameterList(), getType(), get_Block()));
}
} }
} }

View File

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

View File

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

View File

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