From d4b9ea9a73d90162b566ac665cb53f9f2dd83695 Mon Sep 17 00:00:00 2001 From: JanUlrich Date: Tue, 18 Mar 2014 20:18:57 +0100 Subject: [PATCH] =?UTF-8?q?ConstuctorAssumption=20angef=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/mycompiler/MyCompiler.java | 7 +- src/mycompiler/SourceFile.java | 9 +- src/mycompiler/SyntaxTreeNode.java | 2 +- src/mycompiler/myclass/Class.java | 14 ++- src/mycompiler/myclass/Constructor.java | 15 ++- src/mycompiler/myclass/FieldDeclaration.java | 4 +- src/mycompiler/myclass/FormalParameter.java | 3 +- src/mycompiler/myclass/Method.java | 2 +- src/mycompiler/myclass/UsedId.java | 2 +- src/mycompiler/mystatement/Block.java | 3 +- .../mystatement/LambdaExpression.java | 4 +- src/mycompiler/mystatement/MethodCall.java | 1 - src/mycompiler/mystatement/This.java | 3 +- src/mycompiler/mytest/LambdaTest.java | 2 +- .../TypeinferenceResultSet.java | 2 +- src/typinferenz/OderConstraint.java | 4 +- src/typinferenz/SingleConstraint.java | 1 + src/typinferenz/UndConstraint.java | 10 +- .../assumptions/CopyOfTypeAssumptions.java | 3 +- .../assumptions/TypeAssumptions.java | 25 +++- .../TypinferenzException.java | 2 +- src/userinterface/ConsoleInterface.java | 3 +- .../test/lambda/OverloadingTest.jav | 4 +- .../test/lambda/testResults/LambdaTest.log | 115 +++--------------- .../TestAbstractInferenceTest.java | 3 - .../OverloadingInsertTest.java | 47 ++++++- test/plugindevelopment/TypeInsertTester.java | 6 +- 27 files changed, 144 insertions(+), 152 deletions(-) rename src/typinferenz/{ => exceptions}/TypinferenzException.java (92%) diff --git a/src/mycompiler/MyCompiler.java b/src/mycompiler/MyCompiler.java index 7d511bb4..a373f7e6 100755 --- a/src/mycompiler/MyCompiler.java +++ b/src/mycompiler/MyCompiler.java @@ -42,9 +42,10 @@ import org.apache.log4j.xml.DOMConfigurator; import com.sun.corba.se.spi.orbutil.fsm.Guard.Result; import com.sun.org.apache.xerces.internal.impl.xs.identity.Field; -import typinferenz.TypinferenzException; // ino.end import typinferenz.assumptions.TypeAssumptions; +import typinferenz.exceptions.ParserException; +import typinferenz.exceptions.TypinferenzException; @@ -752,8 +753,8 @@ public class MyCompiler implements MyCompilerAPI try { srcFile = (SourceFile) parser.yyparse( scanner ); } catch (IOException | yyException e) { - // TODO Auto-generated catch block e.printStackTrace(); + if(e instanceof yyException)throw new ParserException((yyException)e); } ////////////////////////////////////// // Postprocessing: @@ -786,7 +787,6 @@ public class MyCompiler implements MyCompilerAPI } reader.close(); } catch (IOException e) { - // TODO Auto-generated catch block e.printStackTrace(); } @@ -812,7 +812,6 @@ public class MyCompiler implements MyCompilerAPI reader.close(); gesamterSrc += fileData.toString() + "\n"; // Alle Dateien nacheinander hintereinander anhängen... } catch (Exception e) { - // TODO Auto-generated catch block e.printStackTrace(); throw new TypinferenzException("Die übergebenen Dateien konnten nicht zum Parsen eingelesen werden."); } diff --git a/src/mycompiler/SourceFile.java b/src/mycompiler/SourceFile.java index 0eb90859..41bdf506 100755 --- a/src/mycompiler/SourceFile.java +++ b/src/mycompiler/SourceFile.java @@ -43,9 +43,9 @@ import sun.reflect.generics.reflectiveObjects.TypeVariableImpl; import typinferenz.ConstraintsSet; import typinferenz.FunN; import typinferenz.ResultSet; -import typinferenz.TypinferenzException; import typinferenz.UndConstraint; import typinferenz.assumptions.TypeAssumptions; +import typinferenz.exceptions.TypinferenzException; @@ -741,7 +741,7 @@ public class SourceFile TypeAssumptions basics; - basics = this.makeBasicAssumptions(); //TODO: Diese Funktion ändern, dass nur noch TypeAssumptions zurückgegeben werden. Diese sind wichtig, da hier die Standard-Library von Java als Assumptions generiert wird. + basics = this.makeBasicAssumptions(); //A.addElement(basics); //auskommentiert von Andreas Stadelmeier @@ -1376,7 +1376,9 @@ public class SourceFile return foo; */ - return new TypeAssumptions(null); //TODO: Diese TypeAssumptions mit basic-Assumptions füllen + TypeAssumptions ret = new TypeAssumptions(); + + return ret; //TODO: Diese TypeAssumptions mit basic-Assumptions füllen } // ino.end @@ -1515,7 +1517,6 @@ public class SourceFile @Override public SyntaxTreeNode getParent() { - // TODO Auto-generated method stub return null; } diff --git a/src/mycompiler/SyntaxTreeNode.java b/src/mycompiler/SyntaxTreeNode.java index 91249ef9..54dd0a74 100644 --- a/src/mycompiler/SyntaxTreeNode.java +++ b/src/mycompiler/SyntaxTreeNode.java @@ -2,7 +2,7 @@ package mycompiler; import java.util.Vector; -import typinferenz.TypinferenzException; +import typinferenz.exceptions.TypinferenzException; import mycompiler.myclass.Class; public abstract class SyntaxTreeNode { diff --git a/src/mycompiler/myclass/Class.java b/src/mycompiler/myclass/Class.java index 35f9dbfe..ac2c923d 100755 --- a/src/mycompiler/myclass/Class.java +++ b/src/mycompiler/myclass/Class.java @@ -57,15 +57,16 @@ import org.apache.log4j.Logger; + import sun.reflect.generics.reflectiveObjects.NotImplementedException; import typinferenz.ConstraintsSet; import typinferenz.JavaCodeResult; import typinferenz.OderConstraint; import typinferenz.ResultSet; -import typinferenz.TypinferenzException; import typinferenz.UndConstraint; import typinferenz.FunN; import typinferenz.assumptions.TypeAssumptions; +import typinferenz.exceptions.TypinferenzException; @@ -1156,11 +1157,6 @@ public class Class extends SyntaxTreeNode implements AClassOrInterface JavaCodeResult classBodyCode = new JavaCodeResult(); if(this.modifiers!=null)classBodyCode.attach(this.modifiers.printJavaCode(reconstructionResult.getUnifiedConstraints())).attach(" "); - - if(superclassid == null || superclassid.get_Name().size()<1){ - int superclassidOffset = superclassid == null ? 0 : superclassid.getOffset(); - superclassid = new UsedId("Object", superclassidOffset); - } classBodyCode.attach(this.name + " extends ").attach(superclassid.printJavaCode(reconstructionResult.getUnifiedConstraints())).attach("\n"); @@ -1262,6 +1258,12 @@ public class Class extends SyntaxTreeNode implements AClassOrInterface public void parserPostProcessing(SyntaxTreeNode parent) { super.parserPostProcessing(parent); + //Wenn keine Superklasse, dann erbt die Klasse zwangsweise von Object: + if(superclassid == null || superclassid.get_Name().size()<1){ + int superclassidOffset = superclassid == null ? 0 : superclassid.getOffset(); + superclassid = new UsedId("Object", superclassidOffset); + } + //Alle Methoden auf Konstruktoren durchsuchen und diese umwandeln: Vector tempFields = new Vector(); for(Field f : this.getFields()){ diff --git a/src/mycompiler/myclass/Constructor.java b/src/mycompiler/myclass/Constructor.java index 2eb1259e..543e813d 100644 --- a/src/mycompiler/myclass/Constructor.java +++ b/src/mycompiler/myclass/Constructor.java @@ -15,8 +15,10 @@ import typinferenz.ConstraintsSet; import typinferenz.JavaCodeResult; import typinferenz.ResultSet; import typinferenz.SingleConstraint; -import typinferenz.TypinferenzException; +import typinferenz.assumptions.ConstructorAssumption; +import typinferenz.assumptions.MethodAssumption; import typinferenz.assumptions.TypeAssumptions; +import typinferenz.exceptions.TypinferenzException; public class Constructor extends Method { private Method methode; @@ -238,10 +240,17 @@ public class Constructor extends Method { @Override public TypeAssumptions createTypeAssumptions(Class classmember) { - - return this.methode.createTypeAssumptions(classmember); + Class parentClass = this.getParentClass(); + TypeAssumptions ret = new TypeAssumptions(); + ret.addConstructorAssumption(new ConstructorAssumption(this, parentClass)); + return ret; } + @Override + public SyntaxTreeNode getParent(){ + return this.methode.getParent(); + } + @Override public void parserPostProcessing(SyntaxTreeNode parent) { diff --git a/src/mycompiler/myclass/FieldDeclaration.java b/src/mycompiler/myclass/FieldDeclaration.java index 51f4afd4..60ef42ca 100644 --- a/src/mycompiler/myclass/FieldDeclaration.java +++ b/src/mycompiler/myclass/FieldDeclaration.java @@ -7,9 +7,9 @@ import typinferenz.JavaCodeResult; import typinferenz.OderConstraint; import typinferenz.ResultSet; import typinferenz.SingleConstraint; -import typinferenz.TypinferenzException; import typinferenz.assumptions.FieldAssumption; import typinferenz.assumptions.TypeAssumptions; +import typinferenz.exceptions.TypinferenzException; import mycompiler.SyntaxTreeNode; import mycompiler.mybytecode.ClassFile; import mycompiler.myexception.JVMCodeException; @@ -75,7 +75,7 @@ public class FieldDeclaration extends Field{ ////////////////////////////// TypeAssumptions assumptions = new TypeAssumptions(); /* - * TODO: Der Feld-Assumption muss ein TPH als Typ hinzugefügt werden, falls er Typlos initialisiert wurde. Dies kann auch der Type-Algorithmus der Inst/FieldVar - Klasse machen. + * Der Feld-Assumption muss ein TPH als Typ hinzugefügt werden, falls er Typlos initialisiert wurde. Dies kann auch der Type-Algorithmus der Inst/FieldVar - Klasse machen. * Wird das Feld mit einem Typ initialisiert so muss dieser auch in die Assumptions. */ if(this.getType() == null)throw new TypinferenzException("Der Typ eines Feldes darf nicht null sein"); diff --git a/src/mycompiler/myclass/FormalParameter.java b/src/mycompiler/myclass/FormalParameter.java index e49dbef2..853356b7 100755 --- a/src/mycompiler/myclass/FormalParameter.java +++ b/src/mycompiler/myclass/FormalParameter.java @@ -22,12 +22,13 @@ import org.apache.log4j.Logger; + import sun.reflect.generics.reflectiveObjects.NotImplementedException; import typinferenz.JavaCodeResult; import typinferenz.ResultSet; import typinferenz.Typeable; import typinferenz.TypeInsertable; -import typinferenz.TypinferenzException; +import typinferenz.exceptions.TypinferenzException; // ino.class.FormalParameter.23391.declaration public class FormalParameter extends SyntaxTreeNode implements ITypeReplacementListener, Typeable, TypeInsertable diff --git a/src/mycompiler/myclass/Method.java b/src/mycompiler/myclass/Method.java index 7de29dc7..f770a066 100755 --- a/src/mycompiler/myclass/Method.java +++ b/src/mycompiler/myclass/Method.java @@ -563,7 +563,7 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable @Override public JavaCodeResult printJavaCode(ResultSet resultSet) { JavaCodeResult ret = new JavaCodeResult(); - ret.attach(this.getType().printJavaCode(resultSet)).attach(" ").attach(this.get_Method_Name()).attach("()\n"); //TODO: hier müssen auch noch die Parameter ausgegeben werden! + ret.attach(this.getType().printJavaCode(resultSet)).attach(" ").attach(this.get_Method_Name()).attach("(").attach(this.getParameterList().printJavaCode(resultSet)).attach(")\n"); ret.attach(this.block.printJavaCode(resultSet)); return ret; diff --git a/src/mycompiler/myclass/UsedId.java b/src/mycompiler/myclass/UsedId.java index a16db852..b6f022da 100755 --- a/src/mycompiler/myclass/UsedId.java +++ b/src/mycompiler/myclass/UsedId.java @@ -7,7 +7,7 @@ import java.util.Vector; import typinferenz.JavaCodeResult; import typinferenz.ResultSet; -import typinferenz.TypinferenzException; +import typinferenz.exceptions.TypinferenzException; import mycompiler.IItemWithOffset; import mycompiler.mybytecode.JVMCode; import mycompiler.mytype.Type; diff --git a/src/mycompiler/mystatement/Block.java b/src/mycompiler/mystatement/Block.java index a4b6ea16..9546246d 100755 --- a/src/mycompiler/mystatement/Block.java +++ b/src/mycompiler/mystatement/Block.java @@ -32,14 +32,15 @@ import org.apache.log4j.Logger; + import sun.reflect.generics.reflectiveObjects.NotImplementedException; import typinferenz.JavaCodeResult; import typinferenz.SingleConstraint; import typinferenz.ConstraintsSet; import typinferenz.FreshTypeVariable; import typinferenz.ResultSet; -import typinferenz.TypinferenzException; import typinferenz.assumptions.TypeAssumptions; +import typinferenz.exceptions.TypinferenzException; diff --git a/src/mycompiler/mystatement/LambdaExpression.java b/src/mycompiler/mystatement/LambdaExpression.java index c5a24d0d..d3181b84 100755 --- a/src/mycompiler/mystatement/LambdaExpression.java +++ b/src/mycompiler/mystatement/LambdaExpression.java @@ -10,9 +10,9 @@ import typinferenz.FreshTypeVariable; import typinferenz.FunN; import typinferenz.ResultSet; import typinferenz.Typeable; -import typinferenz.TypinferenzException; import typinferenz.assumptions.ParameterAssumption; import typinferenz.assumptions.TypeAssumptions; +import typinferenz.exceptions.TypinferenzException; import mycompiler.SyntaxTreeNode; import mycompiler.mybytecode.ClassFile; import mycompiler.mybytecode.CodeAttribute; @@ -124,7 +124,7 @@ public class LambdaExpression extends Expr{ public ConstraintsSet TYPEExpr(TypeAssumptions assumptions) { ConstraintsSet ret = new ConstraintsSet(); //Die Assumptions für die Parameter der LambdaExpression - TypeAssumptions ArgumentAssumptions = new TypeAssumptions(assumptions.getThisValue().getName()); + TypeAssumptions ArgumentAssumptions = new TypeAssumptions(this.getParentClass().getName()); Vector paramTypes = new Vector(); for(FormalParameter param : params.formalparameter){ diff --git a/src/mycompiler/mystatement/MethodCall.java b/src/mycompiler/mystatement/MethodCall.java index fcebc774..6b9d2eb7 100755 --- a/src/mycompiler/mystatement/MethodCall.java +++ b/src/mycompiler/mystatement/MethodCall.java @@ -664,7 +664,6 @@ public class MethodCall extends Expr */ @Override public ConstraintsSet TYPEExpr(TypeAssumptions assumptions) { - //TODO hier muss unterschieden werden zwischen einem Konstruktor und einer Methode. //Hier der Ablauf für einen Methodenaufruf: ConstraintsSet ret = new ConstraintsSet(); //Der Return-Type des MEthodenaufrufs ist zunächst unbekannt: diff --git a/src/mycompiler/mystatement/This.java b/src/mycompiler/mystatement/This.java index 04c0bf91..39aa5f07 100755 --- a/src/mycompiler/mystatement/This.java +++ b/src/mycompiler/mystatement/This.java @@ -170,7 +170,8 @@ public class This extends Expr public ConstraintsSet TYPEExpr(TypeAssumptions assumptions) { ConstraintsSet ret = new ConstraintsSet(); //this.set_Type(new); - this.setType(assumptions.getThisValue());//Die Assumption für this als TypeVariable setzen. + //this.setType(assumptions.getThisValue());//Die Assumption für this als TypeVariable setzen. + this.setType(new RefType(this.getParentClass().getName(),0)); return ret; } diff --git a/src/mycompiler/mytest/LambdaTest.java b/src/mycompiler/mytest/LambdaTest.java index 519886f7..7bde818d 100755 --- a/src/mycompiler/mytest/LambdaTest.java +++ b/src/mycompiler/mytest/LambdaTest.java @@ -15,8 +15,8 @@ import org.apache.log4j.Logger; import org.apache.log4j.PatternLayout; import org.apache.log4j.SimpleLayout; -import typinferenz.TypinferenzException; import typinferenz.assumptions.TypeAssumptions; +import typinferenz.exceptions.TypinferenzException; import mycompiler.MyCompiler; import mycompiler.MyCompilerAPI; import mycompiler.mytype.Type; diff --git a/src/mycompiler/mytypereconstruction/TypeinferenceResultSet.java b/src/mycompiler/mytypereconstruction/TypeinferenceResultSet.java index 933e8985..a5b8b121 100755 --- a/src/mycompiler/mytypereconstruction/TypeinferenceResultSet.java +++ b/src/mycompiler/mytypereconstruction/TypeinferenceResultSet.java @@ -11,8 +11,8 @@ import typinferenz.ConstraintsSet; import typinferenz.ResultSet; import typinferenz.TypeInsertPoint; import typinferenz.TypeInsertSet; -import typinferenz.TypinferenzException; import typinferenz.assumptions.TypeAssumptions; +import typinferenz.exceptions.TypinferenzException; import mycompiler.mytype.GenericTypeVar; import mycompiler.mytype.Pair; import mycompiler.mytype.RefType; diff --git a/src/typinferenz/OderConstraint.java b/src/typinferenz/OderConstraint.java index d6a198c8..61aff4fe 100755 --- a/src/typinferenz/OderConstraint.java +++ b/src/typinferenz/OderConstraint.java @@ -59,8 +59,8 @@ public class OderConstraint{ @Override public String toString(){ String ret = "["; - for(Pair p : this.getConstraintPairs()){ - ret += p.toString()+ ", "; + for(UndConstraint p : this.getUndConstraints()){ + ret += p.toString()+ "| "; } return ret+"]"; } diff --git a/src/typinferenz/SingleConstraint.java b/src/typinferenz/SingleConstraint.java index e15b921b..c365e0af 100755 --- a/src/typinferenz/SingleConstraint.java +++ b/src/typinferenz/SingleConstraint.java @@ -2,6 +2,7 @@ package typinferenz; import java.util.Vector; +import typinferenz.exceptions.TypinferenzException; import mycompiler.mytype.Pair; import mycompiler.mytype.RefType; import mycompiler.mytype.Type; diff --git a/src/typinferenz/UndConstraint.java b/src/typinferenz/UndConstraint.java index ceb4e388..f5dc8808 100755 --- a/src/typinferenz/UndConstraint.java +++ b/src/typinferenz/UndConstraint.java @@ -27,9 +27,15 @@ public class UndConstraint extends OderConstraint { return ret; } + @Override public String toString(){ - String ret = super.toString(); - return ret.replace(',', '|'); + //String ret = super.toString(); + //return ret.replace('|', ','); + String ret = "["; + for(Pair p : this.getConstraintPairs()){ + ret += p.toString()+ ", "; + } + return ret+"]"; } } diff --git a/src/typinferenz/assumptions/CopyOfTypeAssumptions.java b/src/typinferenz/assumptions/CopyOfTypeAssumptions.java index d18d2623..53672cac 100644 --- a/src/typinferenz/assumptions/CopyOfTypeAssumptions.java +++ b/src/typinferenz/assumptions/CopyOfTypeAssumptions.java @@ -5,7 +5,7 @@ import java.util.Vector; import sun.reflect.generics.reflectiveObjects.NotImplementedException; import typinferenz.FunN; -import typinferenz.TypinferenzException; +import typinferenz.exceptions.TypinferenzException; import mycompiler.mytype.GenericTypeVar; import mycompiler.mytype.RefType; import mycompiler.mytype.Type; @@ -155,6 +155,7 @@ public class CopyOfTypeAssumptions implements Iterable { } //TODO: Dann die lokalen Variablen // ... (noch nicht implementiert) + //und zuletzt die Felder der Klasse in dessen Namensraum sich dieses AssumptionSet befindet. for(CTypeAssumption ass : this.getInstVarAssumptions()){ if(ass.getIdentifier().equals(variableName))return ass.getAssumedType(); diff --git a/src/typinferenz/assumptions/TypeAssumptions.java b/src/typinferenz/assumptions/TypeAssumptions.java index 3c1ce434..b718fa27 100755 --- a/src/typinferenz/assumptions/TypeAssumptions.java +++ b/src/typinferenz/assumptions/TypeAssumptions.java @@ -1,14 +1,16 @@ package typinferenz.assumptions; import java.util.Iterator; + import mycompiler.myclass.Class; + import java.util.Vector; import sun.reflect.generics.reflectiveObjects.NotImplementedException; import typinferenz.FunN; import typinferenz.FunNInterface; import typinferenz.FunNMethod; -import typinferenz.TypinferenzException; +import typinferenz.exceptions.TypinferenzException; import mycompiler.mytype.GenericTypeVar; import mycompiler.mytype.RefType; import mycompiler.mytype.Type; @@ -46,6 +48,7 @@ public class TypeAssumptions { private Vector methodAssumptions = new Vector(); + private Vector constructorAssumptions = new Vector(); private Vector fieldAssumptions = new Vector(); private Vector localVarAssumptions = new Vector(); private Vector parameterAssumptions = new Vector(); @@ -67,7 +70,12 @@ public class TypeAssumptions { public void addMethodAssumption(MethodAssumption mAss){ this.methodAssumptions.add(mAss); } - + + public void addConstructorAssumption( + ConstructorAssumption constructorAssumption) { + this.constructorAssumptions.add(constructorAssumption); + } + public void addFieldAssumption(FieldAssumption ass){ this.fieldAssumptions.add(ass); } @@ -87,10 +95,11 @@ public class TypeAssumptions { */ public Vector getFieldVars(String withName){ //TODO: Implementieren - return null; + return new Vector(); } public Type getTypeOfFieldVar(String withName, Class inClass){ + //TODO: Implementieren return null; } @@ -100,7 +109,8 @@ public class TypeAssumptions { * @return */ public Vector getMethods(String withName){ - return null; + //TODO: Implementieren + return new Vector(); } /** @@ -109,6 +119,7 @@ public class TypeAssumptions { * @return */ public Type getTypeOfLocalVar(String withName){ + //TODO: Implementieren return null; } @@ -243,9 +254,13 @@ public class TypeAssumptions { return ret; } - public Type getThisValue() { + @Deprecated + public Type getThisValue2() { + if(thisClassName == null)throw new TypinferenzException("Kein Wert für this vorhanden, in diesem Kontext"); return new RefType(thisClassName, 0); } + + } diff --git a/src/typinferenz/TypinferenzException.java b/src/typinferenz/exceptions/TypinferenzException.java similarity index 92% rename from src/typinferenz/TypinferenzException.java rename to src/typinferenz/exceptions/TypinferenzException.java index aa0e082f..0146c4be 100755 --- a/src/typinferenz/TypinferenzException.java +++ b/src/typinferenz/exceptions/TypinferenzException.java @@ -1,4 +1,4 @@ -package typinferenz; +package typinferenz.exceptions; /** * Eine RuntimeException, welche bei einem Fehler während des Typinferenzalgorithmus ausgelöst wird. diff --git a/src/userinterface/ConsoleInterface.java b/src/userinterface/ConsoleInterface.java index 045f9532..4e1c4360 100755 --- a/src/userinterface/ConsoleInterface.java +++ b/src/userinterface/ConsoleInterface.java @@ -8,7 +8,8 @@ import java.util.Vector; import mycompiler.MyCompiler; import mycompiler.MyCompilerAPI; import mycompiler.mytypereconstruction.TypeinferenceResultSet; -import typinferenz.TypinferenzException; +import typinferenz.exceptions.TypinferenzException; + import java.util.*; import org.apache.log4j.Logger; diff --git a/test/mycompiler/test/lambda/OverloadingTest.jav b/test/mycompiler/test/lambda/OverloadingTest.jav index bed6f960..bdcba2bc 100755 --- a/test/mycompiler/test/lambda/OverloadingTest.jav +++ b/test/mycompiler/test/lambda/OverloadingTest.jav @@ -2,7 +2,7 @@ class OverloadingTest{ var; - public Object clone(){ + public clone(){ return this; } @@ -14,7 +14,7 @@ class OverloadingTest{ class OverloadingTest2{ - public Object clone(){ + public clone(){ return this; } diff --git a/test/mycompiler/test/lambda/testResults/LambdaTest.log b/test/mycompiler/test/lambda/testResults/LambdaTest.log index 2e415098..aff7b526 100644 --- a/test/mycompiler/test/lambda/testResults/LambdaTest.log +++ b/test/mycompiler/test/lambda/testResults/LambdaTest.log @@ -1,123 +1,36 @@ -Class DEBUG [Typeinference] Erstellte Assumptions: this: MatrixMethod Assumptions: -[MethodAssumption: Matrix null { []] +Class DEBUG [Typeinference] Erstellte Assumptions: this: ThisTestMethod Assumptions: +[] FieldVar Assumptions: -[typinferenz.assumptions.FieldAssumption@15502c5e] +[typinferenz.assumptions.FieldAssumption@6d657803] LocalVar Assumptions: [] Parameter Assumptions: [] -Block DEBUG [Typeinference] Prozessing statement: null Return null (( [ f, ]) -> null { [null Return null (f.apply( [ null (this(null)), m, ]))]) -Block DEBUG [Typeinference] Prozessing statement: null Return null (f.apply( [ null (this(null)), m, ])) -Block DEBUG [Typeinference] Prozessing statement: TPH K Return TPH G (f: TPH E.apply( [ Matrix (this(null)), m: TPH C, ])) -Block DEBUG [Typeinference] Prozessing statement: TPH L Return TPH F (( [ TPH E f, ]) -> TPH K { [TPH K Return TPH G (f: TPH E.apply( [ Matrix (this(null)), m: TPH C, ]))]) Class DEBUG [Typeinference] Erstellte Constraints: TPH A < TPH A -[(TPH H <. TPH G), (Matrix <. TPH I), (TPH C <. TPH J), (TPH E <. FunN), ] -TPH G < TPH K -Fun1< TPH K, TPH E > < TPH F -TPH F < TPH L -Fun1< TPH L, TPH C > < TPH D -TPH D < TPH A +ThisTest < TPH A -SourceFile DEBUG [Typeinference] Karthesisches Produkt der Constraints: [[(TPH A <. TPH A), (TPH H <. TPH G), (Matrix <. TPH I), (TPH C <. TPH J), (TPH E <. FunN), (TPH G <. TPH K), (Fun1< TPH K, TPH E > <. TPH F), (TPH F <. TPH L), (Fun1< TPH L, TPH C > <. TPH D), (TPH D <. TPH A)]] -SourceFile DEBUG [Typeinference] Unifiziertes Ergebnis: [[(TPH H <. TPH G), (TPH C <. TPH J), (TPH G <. TPH K), (TPH L = Fun1< TPH K, FunN >), (TPH A = Fun1< Fun1< TPH K, FunN >, TPH C >), (TPH I = Matrix), (TPH E = FunN), (TPH F = Fun1< TPH K, FunN >), (TPH D = Fun1< Fun1< TPH K, FunN >, TPH C >)], [(TPH H <. TPH G), (TPH C <. TPH J), (TPH G <. TPH K), (TPH L = Fun1< TPH K, FunN >), (TPH A = Fun1< Fun1< TPH K, FunN >, TPH C >), (TPH I = Vector< Vector< GTV Integer > >), (TPH E = FunN), (TPH F = Fun1< TPH K, FunN >), (TPH D = Fun1< Fun1< TPH K, FunN >, TPH C >)], [(TPH H <. TPH G), (TPH C <. TPH J), (TPH G <. TPH K), (TPH L = Fun1< TPH K, FunN >), (TPH A = Fun1< Fun1< TPH K, FunN >, TPH C >), (TPH I = Vector< ? extends Vector< GTV Integer > >), (TPH E = FunN), (TPH F = Fun1< TPH K, FunN >), (TPH D = Fun1< Fun1< TPH K, FunN >, TPH C >)], [(TPH H <. TPH G), (TPH C <. TPH J), (TPH G <. TPH K), (TPH L = Fun1< TPH K, FunN >), (TPH A = Fun1< Fun1< TPH K, FunN >, TPH C >), (TPH I = Vector< ? extends Vector< ? extends GTV Integer > >), (TPH E = FunN), (TPH F = Fun1< TPH K, FunN >), (TPH D = Fun1< Fun1< TPH K, FunN >, TPH C >)], [(TPH H <. TPH G), (TPH C <. TPH J), (TPH G <. TPH K), (TPH L = Fun1< TPH K, FunN >), (TPH A = Fun1< Fun1< TPH K, FunN >, TPH C >), (TPH I = Vector< ? extends Vector< ? super GTV Integer > >), (TPH E = FunN), (TPH F = Fun1< TPH K, FunN >), (TPH D = Fun1< Fun1< TPH K, FunN >, TPH C >)], [(TPH H <. TPH G), (TPH C <. TPH J), (TPH G <. TPH K), (TPH L = Fun1< TPH K, FunN >), (TPH A = Fun1< Fun1< TPH K, FunN >, TPH C >), (TPH I = Vector< ? super Vector< GTV Integer > >), (TPH E = FunN), (TPH F = Fun1< TPH K, FunN >), (TPH D = Fun1< Fun1< TPH K, FunN >, TPH C >)], [(TPH H <. TPH G), (TPH C <. TPH J), (TPH G <. TPH K), (TPH L = Fun1< TPH K, FunN >), (TPH A = Fun1< Fun1< TPH K, FunN >, TPH C >), (TPH I = Vector< ? super Matrix >), (TPH E = FunN), (TPH F = Fun1< TPH K, FunN >), (TPH D = Fun1< Fun1< TPH K, FunN >, TPH C >)]] +SourceFile DEBUG [Typeinference] Karthesisches Produkt der Constraints: [[(TPH A <. TPH A), (ThisTest <. TPH A)]] +SourceFile DEBUG [Typeinference] Unifiziertes Ergebnis: [[(TPH A = ThisTest)], [(TPH A = Object)]] SourceFile DEBUG [Typeinference] JavaFiles: -SourceFile DEBUG [Typeinference] JavaFile für ResultSet Unified Constraints: [(TPH H <. TPH G), (TPH C <. TPH J), (TPH G <. TPH K), (TPH L = Fun1< TPH K, FunN >), (TPH A = Fun1< Fun1< TPH K, FunN >, TPH C >), (TPH I = Matrix), (TPH E = FunN), (TPH F = Fun1< TPH K, FunN >), (TPH D = Fun1< Fun1< TPH K, FunN >, TPH C >)] +SourceFile DEBUG [Typeinference] JavaFile für ResultSet Unified Constraints: [(TPH A = ThisTest)] -SourceFile DEBUG [Typeinference] class Matrix extends Vector> +SourceFile DEBUG [Typeinference] class ThisTest extends Object { -Fun1, C> op = (C m) -> { -return (FunN f) -> { -return f.apply(this, m);; -}; -}; -Matrix Matrix() +ThisTest thisVar = this; +ThisTest ThisTest() { } } -SourceFile DEBUG [Typeinference] JavaFile für ResultSet Unified Constraints: [(TPH H <. TPH G), (TPH C <. TPH J), (TPH G <. TPH K), (TPH L = Fun1< TPH K, FunN >), (TPH A = Fun1< Fun1< TPH K, FunN >, TPH C >), (TPH I = Vector< Vector< GTV Integer > >), (TPH E = FunN), (TPH F = Fun1< TPH K, FunN >), (TPH D = Fun1< Fun1< TPH K, FunN >, TPH C >)] +SourceFile DEBUG [Typeinference] JavaFile für ResultSet Unified Constraints: [(TPH A = Object)] -SourceFile DEBUG [Typeinference] class Matrix extends Vector> +SourceFile DEBUG [Typeinference] class ThisTest extends Object { -Fun1, C> op = (C m) -> { -return (FunN f) -> { -return f.apply(this, m);; -}; -}; -Matrix Matrix() -{ -} -} - -SourceFile DEBUG [Typeinference] JavaFile für ResultSet Unified Constraints: [(TPH H <. TPH G), (TPH C <. TPH J), (TPH G <. TPH K), (TPH L = Fun1< TPH K, FunN >), (TPH A = Fun1< Fun1< TPH K, FunN >, TPH C >), (TPH I = Vector< ? extends Vector< GTV Integer > >), (TPH E = FunN), (TPH F = Fun1< TPH K, FunN >), (TPH D = Fun1< Fun1< TPH K, FunN >, TPH C >)] - -SourceFile DEBUG [Typeinference] class Matrix extends Vector> -{ -Fun1, C> op = (C m) -> { -return (FunN f) -> { -return f.apply(this, m);; -}; -}; -Matrix Matrix() -{ -} -} - -SourceFile DEBUG [Typeinference] JavaFile für ResultSet Unified Constraints: [(TPH H <. TPH G), (TPH C <. TPH J), (TPH G <. TPH K), (TPH L = Fun1< TPH K, FunN >), (TPH A = Fun1< Fun1< TPH K, FunN >, TPH C >), (TPH I = Vector< ? extends Vector< ? extends GTV Integer > >), (TPH E = FunN), (TPH F = Fun1< TPH K, FunN >), (TPH D = Fun1< Fun1< TPH K, FunN >, TPH C >)] - -SourceFile DEBUG [Typeinference] class Matrix extends Vector> -{ -Fun1, C> op = (C m) -> { -return (FunN f) -> { -return f.apply(this, m);; -}; -}; -Matrix Matrix() -{ -} -} - -SourceFile DEBUG [Typeinference] JavaFile für ResultSet Unified Constraints: [(TPH H <. TPH G), (TPH C <. TPH J), (TPH G <. TPH K), (TPH L = Fun1< TPH K, FunN >), (TPH A = Fun1< Fun1< TPH K, FunN >, TPH C >), (TPH I = Vector< ? extends Vector< ? super GTV Integer > >), (TPH E = FunN), (TPH F = Fun1< TPH K, FunN >), (TPH D = Fun1< Fun1< TPH K, FunN >, TPH C >)] - -SourceFile DEBUG [Typeinference] class Matrix extends Vector> -{ -Fun1, C> op = (C m) -> { -return (FunN f) -> { -return f.apply(this, m);; -}; -}; -Matrix Matrix() -{ -} -} - -SourceFile DEBUG [Typeinference] JavaFile für ResultSet Unified Constraints: [(TPH H <. TPH G), (TPH C <. TPH J), (TPH G <. TPH K), (TPH L = Fun1< TPH K, FunN >), (TPH A = Fun1< Fun1< TPH K, FunN >, TPH C >), (TPH I = Vector< ? super Vector< GTV Integer > >), (TPH E = FunN), (TPH F = Fun1< TPH K, FunN >), (TPH D = Fun1< Fun1< TPH K, FunN >, TPH C >)] - -SourceFile DEBUG [Typeinference] class Matrix extends Vector> -{ -Fun1, C> op = (C m) -> { -return (FunN f) -> { -return f.apply(this, m);; -}; -}; -Matrix Matrix() -{ -} -} - -SourceFile DEBUG [Typeinference] JavaFile für ResultSet Unified Constraints: [(TPH H <. TPH G), (TPH C <. TPH J), (TPH G <. TPH K), (TPH L = Fun1< TPH K, FunN >), (TPH A = Fun1< Fun1< TPH K, FunN >, TPH C >), (TPH I = Vector< ? super Matrix >), (TPH E = FunN), (TPH F = Fun1< TPH K, FunN >), (TPH D = Fun1< Fun1< TPH K, FunN >, TPH C >)] - -SourceFile DEBUG [Typeinference] class Matrix extends Vector> -{ -Fun1, C> op = (C m) -> { -return (FunN f) -> { -return f.apply(this, m);; -}; -}; -Matrix Matrix() +Object thisVar = this; +ThisTest ThisTest() { } } diff --git a/test/mycompiler/test/notUsedAnymore/TestAbstractInferenceTest.java b/test/mycompiler/test/notUsedAnymore/TestAbstractInferenceTest.java index e373a052..a3d26b7e 100755 --- a/test/mycompiler/test/notUsedAnymore/TestAbstractInferenceTest.java +++ b/test/mycompiler/test/notUsedAnymore/TestAbstractInferenceTest.java @@ -7,9 +7,6 @@ import mycompiler.mytypereconstruction.typeassumption.CLocalVarTypeAssumption; import mycompiler.mytypereconstruction.typeassumption.CMethodTypeAssumption; -/*TODO: -*/ - public class TestAbstractInferenceTest extends AbstractInferenceTestOLD_2 { private final static String TESTEDCLASSNAME="TestAbstractInferenceTest"; diff --git a/test/plugindevelopment/OverloadingInsertTest.java b/test/plugindevelopment/OverloadingInsertTest.java index 5843d424..49f99f3f 100644 --- a/test/plugindevelopment/OverloadingInsertTest.java +++ b/test/plugindevelopment/OverloadingInsertTest.java @@ -1,5 +1,50 @@ package plugindevelopment; -public class OverloadingInsertTest { +import java.io.File; +import java.io.IOException; +import java.util.Vector; +import junit.framework.TestCase; +import mycompiler.MyCompiler; +import mycompiler.MyCompilerAPI; +import mycompiler.myparser.JavaParser.yyException; +import mycompiler.mytypereconstruction.TypeinferenceResultSet; + +import org.junit.Test; + +import typinferenz.TypeInsertSet; + +public class OverloadingInsertTest { + private static final String TEST_FILE = "OverloadingInsertTest.jav"; + + @Test + public void run(){ + this.test(this.TEST_FILE); + } + + public static void test(String sourceFileToInfere){ + String inferedSource = ""; + MyCompilerAPI compiler = MyCompiler.getAPI(); + try { + compiler.parse(new File(TypeInsertTester.rootDirectory + sourceFileToInfere)); + Vector results = compiler.typeReconstruction(); + //TestCase.assertTrue("Es darf nicht mehr als eine Lösungsmöglichkeit geben und nicht "+results.size(), results.size()==1); + for(TypeinferenceResultSet result : results){ + Vector points = result.getTypeInsertionPoints(); + TestCase.assertTrue("Es muss mindestens ein TypeInsertSet vorhanden sein", points.size()>0); + for(TypeInsertSet point : points){ + TestCase.assertTrue("Es muss mindestens ein TypeInsertPoint vorhanden sein", point.points.size()>0); + if(point.points.size()>0){ + inferedSource = point.insertAllTypes(TypeInsertTester.getFileContent(TypeInsertTester.rootDirectory + sourceFileToInfere)); + System.out.println(inferedSource); + } + } + } + + } catch (IOException | yyException e) { + e.printStackTrace(); + TestCase.fail(); + } + } + } diff --git a/test/plugindevelopment/TypeInsertTester.java b/test/plugindevelopment/TypeInsertTester.java index 4e8d42ae..febaa105 100644 --- a/test/plugindevelopment/TypeInsertTester.java +++ b/test/plugindevelopment/TypeInsertTester.java @@ -39,7 +39,7 @@ public class TypeInsertTester{ inferencelog.addAppender(logAppender); //Bei den Tests wird der Log auch in System.out geschrieben. } } - private static final String rootDirectory = System.getProperty("user.dir")+"/test/plugindevelopment/"; + static final String rootDirectory = System.getProperty("user.dir")+"/test/plugindevelopment/"; public static void test(String sourceFileToInfere, String solutionFile){ String inferedSource = ""; @@ -47,7 +47,7 @@ public class TypeInsertTester{ try { compiler.parse(new File(rootDirectory + sourceFileToInfere)); Vector results = compiler.typeReconstruction(); - TestCase.assertTrue("Es darf nicht mehr als eine Lösungsmöglichkeit geben", results.size()==1); + TestCase.assertTrue("Es darf nicht mehr als eine Lösungsmöglichkeit geben und nicht "+results.size(), results.size()==1); for(TypeinferenceResultSet result : results){ Vector points = result.getTypeInsertionPoints(); TestCase.assertTrue("Es muss mindestens ein TypeInsertSet vorhanden sein", points.size()>0); @@ -68,7 +68,7 @@ public class TypeInsertTester{ } //Source: https://stackoverflow.com/questions/326390/how-to-create-a-java-string-from-the-contents-of-a-file - private static String getFileContent(String path)throws IOException + static String getFileContent(String path)throws IOException { byte[] encoded = Files.readAllBytes(Paths.get(path)); return StandardCharsets.UTF_8.decode(ByteBuffer.wrap(encoded)).toString();