From 61a4bc3cd7473b2997f32a31a2aa60a5a1f7c843 Mon Sep 17 00:00:00 2001 From: JanUlrich Date: Wed, 23 Sep 2015 17:22:01 +0200 Subject: [PATCH] Fehler in Lambda2_2 gefixt --- .../syntaxtree/statement/MethodCall.java | 13 +++++-- .../syntaxtree/statement/Receiver.java | 35 ++++++++++++++++--- .../assumptions/TypeAssumptions.java | 2 +- .../MultipleTypesInsertTester.java | 6 +--- 4 files changed, 42 insertions(+), 14 deletions(-) diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/MethodCall.java b/src/de/dhbwstuttgart/syntaxtree/statement/MethodCall.java index 4ab7c857..4b66f0d4 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/MethodCall.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/MethodCall.java @@ -26,6 +26,7 @@ import de.dhbwstuttgart.typeinference.JavaCodeResult; import de.dhbwstuttgart.typeinference.OderConstraint; import de.dhbwstuttgart.typeinference.ResultSet; import de.dhbwstuttgart.typeinference.UndConstraint; +import de.dhbwstuttgart.typeinference.assumptions.ClassAssumption; import de.dhbwstuttgart.typeinference.assumptions.MethodAssumption; import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions; import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException; @@ -210,8 +211,14 @@ public class MethodCall extends Expr //Noch das Overloading-Constraint anhängen: ret.add(overloading(assumptions)); - de.dhbwstuttgart.syntaxtree.Class receiverCl = assumptions.getClassAssumptionFor(receiver.get_Expr().getType()).getAssumedClass(); + /* + //Die Klasse für den Receiver setzen: Das ist für die Bytecodegenerierung notwendig. + ClassAssumption receiverClassAssumption = assumptions.getClassAssumptionFor(receiver.get_Expr().getType()); + de.dhbwstuttgart.syntaxtree.Class receiverCl = receiverClassAssumption.getAssumedClass(); this.receiver.setClass(receiverCl); + */ + //Die Assumptions für den Receiver setzen: + this.receiver.setAssumptions(assumptions); return ret; } @@ -322,7 +329,7 @@ public class MethodCall extends Expr //Herausfinden, ob eine Methode oder ein Interface aufgerufen wird: Type receiverType = this.receiver.get_Expr().getType(); - de.dhbwstuttgart.syntaxtree.Class receiverClass = this.receiver.getReceiverClass(); + de.dhbwstuttgart.syntaxtree.Class receiverClass = this.receiver.getReceiverClass(cg); short kind = 0; if(receiverClass.isInterface()){ kind = Constants.INVOKEINTERFACE; @@ -343,7 +350,7 @@ public class MethodCall extends Expr } org.apache.commons.bcel6.generic.Type returnType = this.getType().getBytecodeType(cg); - il.append(_factory.createInvoke(receiver.getReceiverClass().getName().toString(), this.get_Name(), returnType , argumentTypen, kind)); + il.append(_factory.createInvoke(receiver.getReceiverClass(cg).getName().toString(), this.get_Name(), returnType , argumentTypen, kind)); return il; } diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/Receiver.java b/src/de/dhbwstuttgart/syntaxtree/statement/Receiver.java index 304639a6..7c0e70ce 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/Receiver.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/Receiver.java @@ -4,7 +4,7 @@ package de.dhbwstuttgart.syntaxtree.statement; // ino.module.Receiver.8650.import import java.util.Hashtable; import de.dhbwstuttgart.typeinference.Menge; - +import de.dhbwstuttgart.bytecode.ClassGenerator; import de.dhbwstuttgart.logger.Logger; // ino.end @@ -14,8 +14,13 @@ import de.dhbwstuttgart.logger.Logger; import de.dhbwstuttgart.myexception.SCStatementException; import de.dhbwstuttgart.syntaxtree.Class; +import de.dhbwstuttgart.syntaxtree.type.RefType; +import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder; import de.dhbwstuttgart.typeinference.JavaCodeResult; import de.dhbwstuttgart.typeinference.ResultSet; +import de.dhbwstuttgart.typeinference.assumptions.ClassAssumption; +import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions; +import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException; @@ -27,7 +32,7 @@ public class Receiver { // ino.attribute.expr.26126.declaration private Expr expr; - private de.dhbwstuttgart.syntaxtree.Class receiverClass; + private TypeAssumptions typeAssumptions; // ino.end // ino.attribute.parserlog.26129.declaration protected static Logger parserlog = Logger.getLogger("parser"); @@ -90,14 +95,34 @@ public class Receiver } // ino.end + /* public void setClass(Class cl){ this.receiverClass = cl; } + */ - public Class getReceiverClass(){ - return this.receiverClass; + public Class getReceiverClass(ClassGenerator cg){ + de.dhbwstuttgart.syntaxtree.type.Type receiverType = this.get_Expr().getType(); + if(receiverType instanceof TypePlaceholder){ + receiverType = cg.resolveTPH((TypePlaceholder)receiverType); + } + if(!(receiverType instanceof RefType)){ + throw new TypeinferenceException("Typ des Receivers nicht eindeutig",this.get_Expr()); + } + ClassAssumption receiverClassAssumption = typeAssumptions.getClassAssumptionFor((RefType)receiverType); + de.dhbwstuttgart.syntaxtree.Class receiverCl = receiverClassAssumption.getAssumedClass(); + return receiverCl; } - + + /** + * Setzt die TypeAssumptions für diesen Receiver. + * Das ist notwendig für die Bytecodegenerierung + * @param ass + */ + public void setAssumptions(TypeAssumptions ass){ + this.typeAssumptions = ass; + } + public JavaCodeResult printJavaCode(ResultSet resultSet) { return new JavaCodeResult().attach(this.get_Expr().printJavaCode(resultSet)); } diff --git a/src/de/dhbwstuttgart/typeinference/assumptions/TypeAssumptions.java b/src/de/dhbwstuttgart/typeinference/assumptions/TypeAssumptions.java index 2c68bd87..9fba5a92 100755 --- a/src/de/dhbwstuttgart/typeinference/assumptions/TypeAssumptions.java +++ b/src/de/dhbwstuttgart/typeinference/assumptions/TypeAssumptions.java @@ -408,7 +408,7 @@ public class TypeAssumptions { return this.classAssumptions; } - public ClassAssumption getClassAssumptionFor(Type t){ + public ClassAssumption getClassAssumptionFor(RefType t){ for(ClassAssumption cA : this.getClassAssumptions()){ if(cA.getAssumedClass().getType().equals(t))return cA; } diff --git a/test/plugindevelopment/TypeInsertTests/MultipleTypesInsertTester.java b/test/plugindevelopment/TypeInsertTests/MultipleTypesInsertTester.java index 90f9ab6a..80628a37 100755 --- a/test/plugindevelopment/TypeInsertTests/MultipleTypesInsertTester.java +++ b/test/plugindevelopment/TypeInsertTests/MultipleTypesInsertTester.java @@ -102,10 +102,7 @@ public class MultipleTypesInsertTester extends TypeInsertTester{ for(String containString : mustContain){ TestCase.assertTrue("\""+containString+"\" muss in den inferierten Lösungen vorkommen",gesamterSrc.contains(containString)); } -<<<<<<< HEAD - try { - Files.write(Logger.getWholeLog().getBytes(),new File(rootDirectory+sourceFileToInfere+".log")); -======= + writeLog(sourceFileToInfere+".log"); } @@ -114,7 +111,6 @@ public class MultipleTypesInsertTester extends TypeInsertTester{ log+=Timewatch.getTimewatch().dumpTimeData(); try { Files.write(log.getBytes(),new File(rootDirectory+toFile)); ->>>>>>> master } catch (IOException e) { e.printStackTrace(); TestCase.fail();