From 54a11c877970b0e234717c8e6f304ee4f73ad827 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Enrico=20Schr=C3=B6dter?= Date: Mon, 9 Nov 2015 09:38:49 +0100 Subject: [PATCH] =?UTF-8?q?Mehrere=20L=C3=B6sungen=20in=20einer=20Class=20?= =?UTF-8?q?file?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bytecode/ClassGenerator.java | 14 +++-- src/de/dhbwstuttgart/syntaxtree/Method.java | 57 ++++++++++--------- .../syntaxtree/type/TypePlaceholder.java | 28 ++++++--- .../typeinference/TypeinferenceResults.java | 16 ++++-- test/bytecode/SingleClassTester.java | 2 +- 5 files changed, 72 insertions(+), 45 deletions(-) diff --git a/src/de/dhbwstuttgart/bytecode/ClassGenerator.java b/src/de/dhbwstuttgart/bytecode/ClassGenerator.java index 54246610..59e65397 100644 --- a/src/de/dhbwstuttgart/bytecode/ClassGenerator.java +++ b/src/de/dhbwstuttgart/bytecode/ClassGenerator.java @@ -69,12 +69,12 @@ public class ClassGenerator extends ClassGen{ return this.getNearestUsedType(toTPH, null); } - public Menge resolveTPH(TypePlaceholder typePlaceholder) { - return resolveTPH(typePlaceholder, null); + public Type resolveTPH(TypePlaceholder typePlaceholder, Integer typeinferenceResultSetIndex) { + return resolveTPH(typePlaceholder, typeinferenceResultSetIndex, null); } - public Menge resolveTPH(TypePlaceholder typePlaceholder, Menge toOneOfTheseTypes) { - return tiResult.getTypeOfPlaceholder(typePlaceholder, toOneOfTheseTypes); + public Type resolveTPH(TypePlaceholder typePlaceholder, Integer typeinferenceResultSetIndex, Menge toOneOfTheseTypes) { + return tiResult.getTypeOfPlaceholder(typePlaceholder, typeinferenceResultSetIndex, toOneOfTheseTypes); } public String createLambdaMethodName() { @@ -166,5 +166,11 @@ public class ClassGenerator extends ClassGen{ public Map getExtraClasses() { return extraClasses; } + + public TypeinferenceResults getTypeinferenceResults() { + return tiResult; + } + + } diff --git a/src/de/dhbwstuttgart/syntaxtree/Method.java b/src/de/dhbwstuttgart/syntaxtree/Method.java index e7aeb1ff..567a3607 100755 --- a/src/de/dhbwstuttgart/syntaxtree/Method.java +++ b/src/de/dhbwstuttgart/syntaxtree/Method.java @@ -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())); - } } diff --git a/src/de/dhbwstuttgart/syntaxtree/type/TypePlaceholder.java b/src/de/dhbwstuttgart/syntaxtree/type/TypePlaceholder.java index 1f9d2621..00fe6aa7 100755 --- a/src/de/dhbwstuttgart/syntaxtree/type/TypePlaceholder.java +++ b/src/de/dhbwstuttgart/syntaxtree/type/TypePlaceholder.java @@ -437,21 +437,33 @@ public class TypePlaceholder extends ObjectType @Override public org.apache.commons.bcel6.generic.Type getBytecodeType(ClassGenerator cg) { - Menge 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 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 diff --git a/src/de/dhbwstuttgart/typeinference/TypeinferenceResults.java b/src/de/dhbwstuttgart/typeinference/TypeinferenceResults.java index 7cce5b67..e132e27e 100644 --- a/src/de/dhbwstuttgart/typeinference/TypeinferenceResults.java +++ b/src/de/dhbwstuttgart/typeinference/TypeinferenceResults.java @@ -5,17 +5,21 @@ import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder; public class TypeinferenceResults { + private Menge typeReconstructions; + public TypeinferenceResults() { - // TODO Auto-generated constructor stub + typeReconstructions = new Menge<>(); } - public TypeinferenceResults(Menge typeReconstruction) { - // TODO Auto-generated constructor stub + public TypeinferenceResults(Menge typeReconstructions) { + this.typeReconstructions = typeReconstructions; } - public Menge getTypeOfPlaceholder(TypePlaceholder typePlaceholder, Menge toOneOfTheseTypes) { - // TODO Auto-generated method stub - return null; + public Type getTypeOfPlaceholder(TypePlaceholder typePlaceholder, Integer typeinferenceResultSetIndex, Menge toOneOfTheseTypes) { + return typeReconstructions.get(typeinferenceResultSetIndex).getTypeOfPlaceholder(typePlaceholder, toOneOfTheseTypes); } + public Menge getTypeReconstructions() { + return typeReconstructions; + } } diff --git a/test/bytecode/SingleClassTester.java b/test/bytecode/SingleClassTester.java index 7b336bfb..f36d98af 100644 --- a/test/bytecode/SingleClassTester.java +++ b/test/bytecode/SingleClassTester.java @@ -57,7 +57,7 @@ public class SingleClassTester { e.printStackTrace(); TestCase.fail(); }finally{ - writeLog(outputDirectory+".log"); + writeLog(outputDirectory+"bytecode.log"); } }