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);
|
||||
}
|
||||
|
||||
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() {
|
||||
@ -166,5 +166,11 @@ public class ClassGenerator extends ClassGen{
|
||||
public Map<String, ClassGenerator> getExtraClasses() {
|
||||
return extraClasses;
|
||||
}
|
||||
|
||||
public TypeinferenceResults getTypeinferenceResults() {
|
||||
return tiResult;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -746,34 +746,39 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable
|
||||
}
|
||||
|
||||
public void genByteCode(ClassGenerator cg) {
|
||||
DHBWConstantPoolGen _cp = cg.getConstantPool();
|
||||
DHBWInstructionFactory _factory = new DHBWInstructionFactory(cg, _cp);
|
||||
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;
|
||||
String[] argumentNames = new String[]{};
|
||||
if(this.parameterlist != null &&
|
||||
this.parameterlist.size() > 0){
|
||||
argumentTypes = new org.apache.commons.bcel6.generic.Type[this.parameterlist.size()];
|
||||
argumentNames = new String[this.parameterlist.size()];
|
||||
int i = 0;
|
||||
for(FormalParameter parameter : this.parameterlist){
|
||||
argumentTypes[i] = parameter.getType().getBytecodeType(cg);
|
||||
argumentNames[i] = parameter.getIdentifier();
|
||||
i++;
|
||||
for(int t = 0; t < cg.getTypeinferenceResults().getTypeReconstructions().size(); t++){
|
||||
DHBWConstantPoolGen _cp = cg.getConstantPool();
|
||||
DHBWInstructionFactory _factory = new DHBWInstructionFactory(cg, _cp);
|
||||
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;
|
||||
String[] argumentNames = new String[]{};
|
||||
if(this.parameterlist != null &&
|
||||
this.parameterlist.size() > 0){
|
||||
argumentTypes = new org.apache.commons.bcel6.generic.Type[this.parameterlist.size()];
|
||||
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++;
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
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);
|
||||
}
|
||||
|
||||
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
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -57,7 +57,7 @@ public class SingleClassTester {
|
||||
e.printStackTrace();
|
||||
TestCase.fail();
|
||||
}finally{
|
||||
writeLog(outputDirectory+".log");
|
||||
writeLog(outputDirectory+"bytecode.log");
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user