forked from JavaTX/JavaCompilerCore
Mehrere Lösungen in einer Class file
This commit is contained in:
parent
87e49a692a
commit
54a11c8779
@ -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() {
|
||||||
@ -166,5 +166,11 @@ public class ClassGenerator extends ClassGen{
|
|||||||
public Map<String, ClassGenerator> getExtraClasses() {
|
public Map<String, ClassGenerator> getExtraClasses() {
|
||||||
return extraClasses;
|
return extraClasses;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public TypeinferenceResults getTypeinferenceResults() {
|
||||||
|
return tiResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -746,34 +746,39 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void genByteCode(ClassGenerator cg) {
|
public void genByteCode(ClassGenerator cg) {
|
||||||
DHBWConstantPoolGen _cp = cg.getConstantPool();
|
for(int t = 0; t < cg.getTypeinferenceResults().getTypeReconstructions().size(); t++){
|
||||||
DHBWInstructionFactory _factory = new DHBWInstructionFactory(cg, _cp);
|
DHBWConstantPoolGen _cp = cg.getConstantPool();
|
||||||
InstructionList il = new InstructionList();
|
DHBWInstructionFactory _factory = new DHBWInstructionFactory(cg, _cp);
|
||||||
Class parentClass = this.getParentClass();
|
InstructionList il = new InstructionList();
|
||||||
|
Class parentClass = this.getParentClass();
|
||||||
//Die Argumentliste generieren:
|
|
||||||
org.apache.commons.bcel6.generic.Type[] argumentTypes = org.apache.commons.bcel6.generic.Type.NO_ARGS;
|
//Die Argumentliste generieren:
|
||||||
String[] argumentNames = new String[]{};
|
org.apache.commons.bcel6.generic.Type[] argumentTypes = org.apache.commons.bcel6.generic.Type.NO_ARGS;
|
||||||
if(this.parameterlist != null &&
|
String[] argumentNames = new String[]{};
|
||||||
this.parameterlist.size() > 0){
|
if(this.parameterlist != null &&
|
||||||
argumentTypes = new org.apache.commons.bcel6.generic.Type[this.parameterlist.size()];
|
this.parameterlist.size() > 0){
|
||||||
argumentNames = new String[this.parameterlist.size()];
|
argumentTypes = new org.apache.commons.bcel6.generic.Type[this.parameterlist.size()];
|
||||||
int i = 0;
|
argumentNames = new String[this.parameterlist.size()];
|
||||||
for(FormalParameter parameter : this.parameterlist){
|
int i = 0;
|
||||||
argumentTypes[i] = parameter.getType().getBytecodeType(cg);
|
for(FormalParameter parameter : this.parameterlist){
|
||||||
argumentNames[i] = parameter.getIdentifier();
|
if(parameter.getType() instanceof TypePlaceholder){
|
||||||
i++;
|
argumentTypes[i] = ((TypePlaceholder) parameter.getType()).getBytecodeType(cg, t);
|
||||||
|
}else{
|
||||||
|
argumentTypes[i] = parameter.getType().getBytecodeType(cg);
|
||||||
|
}
|
||||||
|
argumentNames[i] = parameter.getIdentifier();
|
||||||
|
i++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
short constants = Constants.ACC_PUBLIC; //Per Definition ist jede Methode public
|
||||||
|
if(this.modifiers != null && this.modifiers.includesModifier(new Static())) constants += Constants.ACC_STATIC;
|
||||||
|
//Methode generieren:
|
||||||
|
MethodGenerator method = new MethodGenerator(constants, this.getType().getBytecodeType(cg), argumentTypes , argumentNames, this.get_Method_Name(), parentClass.name, il, _cp);
|
||||||
|
|
||||||
|
//Methode generieren und anfügen:
|
||||||
|
cg.addMethod(method.createMethod(cg, getParameterList(), getType(), get_Block()));
|
||||||
}
|
}
|
||||||
|
|
||||||
short constants = Constants.ACC_PUBLIC; //Per Definition ist jede Methode public
|
|
||||||
if(this.modifiers != null && this.modifiers.includesModifier(new Static())) constants += Constants.ACC_STATIC;
|
|
||||||
//Methode generieren:
|
|
||||||
MethodGenerator method = new MethodGenerator(constants, this.getType().getBytecodeType(cg), argumentTypes , argumentNames, this.get_Method_Name(), parentClass.name, il, _cp);
|
|
||||||
|
|
||||||
//Methode generieren und anfügen:
|
|
||||||
cg.addMethod(method.createMethod(cg, getParameterList(), getType(), get_Block()));
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -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();
|
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.firstElement().getBytecodeSignature(cg);
|
return resolvedType.getBytecodeSignature(cg);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -57,7 +57,7 @@ public class SingleClassTester {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
TestCase.fail();
|
TestCase.fail();
|
||||||
}finally{
|
}finally{
|
||||||
writeLog(outputDirectory+".log");
|
writeLog(outputDirectory+"bytecode.log");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user