diff --git a/.classpath b/.classpath index 7e0def40..a3ee86df 100755 --- a/.classpath +++ b/.classpath @@ -6,7 +6,7 @@ - + diff --git a/.gitignore b/.gitignore index 10266eb8..98b5964b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ CVS bin *.class +*.log # Mobile Tools for Java (J2ME) .mtj.tmp/ diff --git a/lib/guava-10.0.1.jar b/lib/guava-10.0.1.jar new file mode 100644 index 00000000..d107c0f3 Binary files /dev/null and b/lib/guava-10.0.1.jar differ diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/Binary.java b/src/de/dhbwstuttgart/syntaxtree/statement/Binary.java index 9e7d1acf..21b01773 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/Binary.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/Binary.java @@ -7,6 +7,7 @@ import java.util.HashMap; import java.util.Hashtable; import org.apache.bcel.generic.ClassGen; +import org.apache.bcel.generic.InstructionList; import de.dhbwstuttgart.typeinference.Menge; import de.dhbwstuttgart.logger.Logger; @@ -14,6 +15,7 @@ import de.dhbwstuttgart.myexception.CTypeReconstructionException; import de.dhbwstuttgart.myexception.JVMCodeException; import de.dhbwstuttgart.myexception.SCExcept; import de.dhbwstuttgart.myexception.SCStatementException; +import de.dhbwstuttgart.parser.JavaClassName; import de.dhbwstuttgart.syntaxtree.Class; import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode; import de.dhbwstuttgart.syntaxtree.operator.AddOp; @@ -33,6 +35,7 @@ import de.dhbwstuttgart.typeinference.ResultSet; import de.dhbwstuttgart.typeinference.SingleConstraint; import de.dhbwstuttgart.typeinference.UndConstraint; import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions; +import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException; import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet; @@ -214,11 +217,19 @@ public JavaCodeResult printJavaCode(ResultSet resultSet) { @Override - public void genByteCode(ClassGen _cg) { - // TODO Auto-generated method stub - + public InstructionList genByteCode(ClassGen _cg) { + InstructionList linkeSeite = this.expr1.genByteCode(_cg); + InstructionList rechteSeite = this.expr2.genByteCode(_cg); + if(this.getReturnType().getName().equals(new JavaClassName("String"))){ + throw new TypeinferenceException("Zeichenketten zusammenfügen ist noch nicht unterstützt",this); + } + //TODO: Je nachdem welches der Rückgabetyp ist, müssen die linke und rechte Seite unboxt und addiert werden. + return null; } + private InstructionList genUnboxByteCode(ClassGen _cg, Type t){ + return null; + } } // ino.end diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/LambdaExpression.java b/src/de/dhbwstuttgart/syntaxtree/statement/LambdaExpression.java index 62c3c761..c4aacb12 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/LambdaExpression.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/LambdaExpression.java @@ -14,6 +14,7 @@ import de.dhbwstuttgart.typeinference.Menge; import de.dhbwstuttgart.myexception.CTypeReconstructionException; import de.dhbwstuttgart.myexception.JVMCodeException; import de.dhbwstuttgart.myexception.SCStatementException; +import de.dhbwstuttgart.parser.JavaClassName; import de.dhbwstuttgart.syntaxtree.Class; import de.dhbwstuttgart.syntaxtree.ClassHelper; import de.dhbwstuttgart.syntaxtree.FormalParameter; @@ -177,6 +178,10 @@ public class LambdaExpression extends Expr{ retType = new ExtendsWildcardType((ObjectType) retType); } + //Die LambdaExpression kann zu diesem Zeit schon feststellen, ob der Return-Type Void ist (Kein Return-Statement): + if(retType.getName().equals(new JavaClassName("Void"))){ + System.out.println("Void rettype"); + } ret.add(new SingleConstraint(new FunN(retType, modifiedParamTypes).TYPE(assumptions, this),this.getType().TYPE(assumptions, this))); return ret; } diff --git a/src/de/dhbwstuttgart/typeinference/ConstraintsSet.java b/src/de/dhbwstuttgart/typeinference/ConstraintsSet.java index 032b8f56..5c8524a8 100755 --- a/src/de/dhbwstuttgart/typeinference/ConstraintsSet.java +++ b/src/de/dhbwstuttgart/typeinference/ConstraintsSet.java @@ -36,6 +36,10 @@ public class ConstraintsSet extends UndMenge implements Iterable extends Vector{ +public class Menge extends Vector implements Set{ } diff --git a/src/de/dhbwstuttgart/typeinference/OderConstraint.java b/src/de/dhbwstuttgart/typeinference/OderConstraint.java index 686a3eb9..3896b115 100755 --- a/src/de/dhbwstuttgart/typeinference/OderConstraint.java +++ b/src/de/dhbwstuttgart/typeinference/OderConstraint.java @@ -81,10 +81,15 @@ public class OderConstraint extends OderMenge{ */ } - public void addConstraint(UndConstraint methodConstraint) { - oderConstraintPairs.add(methodConstraint); + public void addConstraint(UndConstraint constraint) { + oderConstraintPairs.add(constraint); } + /** + * Filtert die Constraints in diesem ODER-Verknüpften Constraint aus, + * welche keinen Sinn ergeben, also beim unifizieren scheitern. + * @param unifier - Wird für die Unifizierung benutzt + */ void filterWrongConstraints(Unifier unifier) { Menge filteredConstraints = new Menge<>(); for(UndConstraint cons : this.getUndConstraints()){ diff --git a/src/de/dhbwstuttgart/typeinference/UndConstraint.java b/src/de/dhbwstuttgart/typeinference/UndConstraint.java index a6deb253..a30e4127 100755 --- a/src/de/dhbwstuttgart/typeinference/UndConstraint.java +++ b/src/de/dhbwstuttgart/typeinference/UndConstraint.java @@ -34,6 +34,13 @@ public class UndConstraint extends UndMenge { Pair p = new Pair(type, rT); this.set.add(new EinzelElement(p)); } + + @Override + public String toString() { + String ret = this.getConstraintPairs().toString(); + return ret; + } + /* public UndConstraint(ConstraintType p1, ConstraintType p2) { diff --git a/src/de/dhbwstuttgart/typeinference/typedeployment/TypeInsertSet.java b/src/de/dhbwstuttgart/typeinference/typedeployment/TypeInsertSet.java index 6510d90e..2e02352f 100644 --- a/src/de/dhbwstuttgart/typeinference/typedeployment/TypeInsertSet.java +++ b/src/de/dhbwstuttgart/typeinference/typedeployment/TypeInsertSet.java @@ -224,3 +224,41 @@ class TypePatchJob{ return fileContent; } } + +class TypedJavaSource{ + public TypedJavaSource(String source, int offset){ + + } + + public void addInsert(GenericVarInsert genericVar, int offset){ + + } + + public void addInsert(VarInsert var, int offset){ + + } +} + +class VarInsert{ + public VarInsert(String var){ + + } +} + +class GenericVarInsert{ + public GenericVarInsert(String varName){ + + } +} + +class GenericVarExtendsInsert extends GenericVarInsert{ + public GenericVarExtendsInsert(String varName, String extendsVarName){ + super(varName); + } +} + +class GenericVarSuperInsert extends GenericVarInsert{ + public GenericVarSuperInsert(String varName, String superVarName){ + super(varName); + } +} diff --git a/src/de/dhbwstuttgart/typeinference/unify/Unify.java b/src/de/dhbwstuttgart/typeinference/unify/Unify.java index 8e54398a..bd10be77 100755 --- a/src/de/dhbwstuttgart/typeinference/unify/Unify.java +++ b/src/de/dhbwstuttgart/typeinference/unify/Unify.java @@ -6,11 +6,17 @@ package de.dhbwstuttgart.typeinference.unify; import java.util.Enumeration; import java.util.Hashtable; import java.util.Iterator; +import java.util.List; +import java.util.Set; import de.dhbwstuttgart.typeinference.Menge; import java.util.stream.Stream; +import com.google.common.collect.Sets; +import com.google.common.collect.Sets.SetView; +import com.rits.cloning.Cloner; + import de.dhbwstuttgart.logger.Logger; import de.dhbwstuttgart.logger.Section; import de.dhbwstuttgart.logger.SectionLogger; @@ -634,40 +640,82 @@ public class Unify //TODO: Vor der Bildung des Karthesischen Produkts unmögliche Kombinationen ausfiltern //cartProduktSets kontrollieren: ConstraintsSet cSet = new ConstraintsSet(); - for (Menge> vecvecpair : cartProduktSets){ + UndConstraint eq1cons = new UndConstraint(); + for(Pair p : Eq1){ + eq1cons.addConstraint(p.TA1, p.TA2); + } + cSet.add(eq1cons); + for(Menge> vecvecpair : cartProduktSets){ OderConstraint orConstraints = new OderConstraint(); for(Menge pairs : vecvecpair){ UndConstraint uCons = new UndConstraint(); for(Pair p : pairs){ - uCons.addConstraint(new ConstraintPair(p)); + uCons.addConstraint(p.TA1, p.TA2); } orConstraints.addConstraint(uCons); } - cSet.addItems(orConstraints); + cSet.add(orConstraints); } + Menge> bigCartProductErg3 = cSet.cartesianProduct(); + if(filter)log.debug("Karthesisches Produkt nach Filterung: "+bigCartProductErg3); + Sets.cartesianProduct(bigCartProductErg3); + */ SectionLogger log = Logger.getSectionLogger(Unify.class.getName(), Section.UNIFY); if(filter){ - Unifier filterUnify = (pairs)->{ + Cloner cloner = new Cloner(); + Menge>> temp = new Menge<>(); //hier werden gefilterte Constraints gesammelt + Menge undMenge = new Menge(); //Die Menge von Pairs, welche in jedem Kartesischen Produkt enthalten sind. + undMenge.addAll(cloner.deepClone(Eq1)); + Menge>> oderConstraints = new Menge<>();//Die zu filternden Constraints + for (Menge> vecvecpair : cartProduktSets){ + if(vecvecpair.size() == 1){//gibt es nur eine UndMenge in diesem Set, dann kommt diese in jedem Karthesischen Produkt vor: + undMenge.addAll(cloner.deepClone(vecvecpair.firstElement())); + temp.add(vecvecpair); + }else{//gibt es mehrere Mengen, kann gefiltert werden: + oderConstraints.add(vecvecpair); //die Menge zu den zu filternden OderConstraints anfügen + } + } + //Filtere die OderConstraints: + for(Menge> oderConstraint : oderConstraints){ + Menge> filteredOCons = new Menge<>(); //diese Menge sammelt nur Cons + for(Menge pairs : oderConstraint){ + Menge testMenge = new Menge(); + testMenge.addAll(cloner.deepClone(undMenge)); + testMenge.addAll(cloner.deepClone(pairs)); + Menge> test = Unify.unifyFiltered(testMenge, fc_tto, false); + if(test.size()>0){ + filteredOCons.add(pairs); + } + else{ + log.debug("Ausgesondertes Constraint: "+pairs); + } + } + temp.add(filteredOCons); + } + SetView>> difference = Sets.difference(cartProduktSets, temp); + log.debug("Ausgelöschte Constraints: "+difference.toString()); + //cartProduktSets = temp; + /* + Unifier filterUnify = (pairs)->{ String pairsString = pairs.toString(); Menge> retValue = new Menge<>(); retValue = Unify.unifyFiltered(pairs,fc_tto,false); //Unify.unify(pairs, fc_tto, (i)->{}); log.debug("Filtere Constraints:\n"+pairsString); log.debug("Ergebnis: "+ retValue); - return retValue;}; + return retValue; + }; log.debug("Filtere mithilfe von 'filterWrongConstraints': "+cSet); cSet.filterWrongConstraints(filterUnify); + */ } + //*/ - Menge> bigCartProductErg = cSet.cartesianProduct(); - if(filter)log.debug("Karthesisches Produkt nach Filterung: "+bigCartProductErg); - */ - - ///* + ///* Altes Karthesisches Produkt: Auskommentiert durch Andreas Stadelmeier //Hier wird aus den in Schritt 4, Teil 1 erzeugten Vektoren das Kartesische Produkt gebildet. Menge helpvp; Menge> bigCartProductErg = new Menge>(); @@ -687,14 +735,30 @@ public class Unify } } } + + /* + if(! bigCartProductErg.equals(bigCartProductErg3)){ + for(int i = 0; i> changedSets = new Menge>(); Menge> notChangedSets = new Menge>(); + int counter = 0; for(Menge vecpair : bigCartProductErg) { + counter++; + if(counter > 1000){ + System.out.println(counter + " von "+bigCartProductErg.size()); + } boolean change = false; //eingefuegt PL 13-05-22 Pair substPair = null; do diff --git a/test/plugindevelopment/TypeInsertTests/GenericTypeVarTest2.java b/test/plugindevelopment/TypeInsertTests/GenericTypeVarTest2.java index 810219c2..10aad9ab 100644 --- a/test/plugindevelopment/TypeInsertTests/GenericTypeVarTest2.java +++ b/test/plugindevelopment/TypeInsertTests/GenericTypeVarTest2.java @@ -1,5 +1,11 @@ package plugindevelopment.TypeInsertTests; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.PrintStream; + +import de.dhbwstuttgart.logger.LoggerConfiguration; +import de.dhbwstuttgart.logger.Section; import de.dhbwstuttgart.typeinference.Menge; import org.junit.Test; @@ -7,11 +13,17 @@ import org.junit.Test; public class GenericTypeVarTest2 { private static final String TEST_FILE2 = "GenericTypeVarTest2.jav"; + private static final String LOGFILE = "GenericTypeVarTest2.log"; + @Test - public void run2(){ + public void run2() throws FileNotFoundException{ Menge mustContain = new Menge(); mustContain.add("String var2"); - MultipleTypesInsertTester.test(TEST_FILE2, mustContain); + File logFile = new File(MultipleTypesInsertTester.rootDirectory+this.LOGFILE); + LoggerConfiguration lConf = new LoggerConfiguration(); + + lConf.setOutput(Section.TYPEINFERENCE, new PrintStream(logFile)); + MultipleTypesInsertTester.test(TEST_FILE2, mustContain, lConf); } } diff --git a/test/plugindevelopment/TypeInsertTests/LambdaTest26.java b/test/plugindevelopment/TypeInsertTests/LambdaTest26.java index 183dd938..fdca0e67 100644 --- a/test/plugindevelopment/TypeInsertTests/LambdaTest26.java +++ b/test/plugindevelopment/TypeInsertTests/LambdaTest26.java @@ -1,13 +1,20 @@ package plugindevelopment.TypeInsertTests; +import java.io.File; +import java.io.IOException; + +import de.dhbwstuttgart.logger.Logger; import de.dhbwstuttgart.typeinference.Menge; import org.junit.Test; +import com.google.common.io.Files; + public class LambdaTest26 { private static final String TEST_FILE = "LambdaTest26.jav"; + @Test public void run(){ Menge mustContain = new Menge(); diff --git a/test/plugindevelopment/TypeInsertTests/MultipleTypesInsertTester.java b/test/plugindevelopment/TypeInsertTests/MultipleTypesInsertTester.java index 29331173..1dca7ed6 100755 --- a/test/plugindevelopment/TypeInsertTests/MultipleTypesInsertTester.java +++ b/test/plugindevelopment/TypeInsertTests/MultipleTypesInsertTester.java @@ -2,13 +2,16 @@ package plugindevelopment.TypeInsertTests; import java.io.File; import java.io.IOException; -import de.dhbwstuttgart.typeinference.Menge; +import com.google.common.io.Files; + +import de.dhbwstuttgart.typeinference.Menge; import de.dhbwstuttgart.core.MyCompiler; import de.dhbwstuttgart.core.MyCompilerAPI; import de.dhbwstuttgart.logger.Logger; import de.dhbwstuttgart.logger.LoggerConfiguration; import de.dhbwstuttgart.logger.Section; +import de.dhbwstuttgart.logger.SectionLogger; import de.dhbwstuttgart.parser.JavaParser.yyException; import de.dhbwstuttgart.typeinference.TypeinferenceResultSet; import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertPoint; @@ -38,6 +41,8 @@ public class MultipleTypesInsertTester extends TypeInsertTester{ public static void test(String sourceFileToInfere, Menge mustContain){ String gesamterSrc = ""; String inferedSource = ""; + SectionLogger log = Logger.getSectionLogger(MultipleTypesInsertTester.class.getName(), Section.TYPEINFERENCE); + MyCompilerAPI compiler = MyCompiler.getAPI(logConfig); try { compiler.parse(new File(rootDirectory + sourceFileToInfere)); @@ -51,7 +56,7 @@ public class MultipleTypesInsertTester extends TypeInsertTester{ //TestCase.assertTrue("Es muss mindestens ein TypeInsertPoint vorhanden sein", point.points.size()>0); if(point.points.size()>0){ inferedSource = point.insertAllTypes(TypeInsertTester.getFileContent(rootDirectory + sourceFileToInfere)); - System.out.println(inferedSource); + log.debug(inferedSource); gesamterSrc += inferedSource; } @@ -64,6 +69,12 @@ public class MultipleTypesInsertTester extends TypeInsertTester{ for(String containString : mustContain){ TestCase.assertTrue("\""+containString+"\" muss in den inferierten Lösungen vorkommen",gesamterSrc.contains(containString)); } + try { + Files.write(Logger.getWholeLog().getBytes(),new File(rootDirectory+sourceFileToInfere+".log")); + } catch (IOException e) { + e.printStackTrace(); + TestCase.fail(); + } } public static void testSingleInsert(String sourceFileToInfere, Menge mustContain){ diff --git a/test/plugindevelopment/TypeInsertTests/OverloadingInMethod2.java b/test/plugindevelopment/TypeInsertTests/OverloadingInMethod2.java index 1db86fb9..dc911c2b 100644 --- a/test/plugindevelopment/TypeInsertTests/OverloadingInMethod2.java +++ b/test/plugindevelopment/TypeInsertTests/OverloadingInMethod2.java @@ -1,5 +1,7 @@ package plugindevelopment.TypeInsertTests; +import de.dhbwstuttgart.logger.LoggerConfiguration; +import de.dhbwstuttgart.logger.Section; import de.dhbwstuttgart.typeinference.Menge; import org.junit.Test; @@ -13,7 +15,7 @@ public class OverloadingInMethod2 { Menge mustContain = new Menge(); //mustContain.add("Fun0>> op"); - MultipleTypesInsertTester.test(this.TEST_FILE, mustContain); + MultipleTypesInsertTester.test(this.TEST_FILE, mustContain, new LoggerConfiguration().setOutput(Section.UNIFY, System.out)); } } diff --git a/test/plugindevelopment/TypeInsertTests/ThisTest.java b/test/plugindevelopment/TypeInsertTests/ThisTest.java index 2ebe429a..5a64a069 100644 --- a/test/plugindevelopment/TypeInsertTests/ThisTest.java +++ b/test/plugindevelopment/TypeInsertTests/ThisTest.java @@ -1,5 +1,7 @@ package plugindevelopment.TypeInsertTests; +import de.dhbwstuttgart.logger.LoggerConfiguration; +import de.dhbwstuttgart.logger.Section; import de.dhbwstuttgart.typeinference.Menge; import org.junit.Test; @@ -12,7 +14,7 @@ public class ThisTest { public void run(){ Menge mustContain = new Menge(); - MultipleTypesInsertTester.test(this.TEST_FILE, mustContain); + MultipleTypesInsertTester.test(this.TEST_FILE, mustContain, new LoggerConfiguration().setOutput(Section.UNIFY, System.out)); } } diff --git a/test/unify/UnifyFilter.java b/test/unify/UnifyFilter.java index 3897ca31..3c50bafe 100644 --- a/test/unify/UnifyFilter.java +++ b/test/unify/UnifyFilter.java @@ -8,6 +8,7 @@ import java.io.UnsupportedEncodingException; import org.junit.Test; +import plugindevelopment.TypeInsertTester; import de.dhbwstuttgart.core.MyCompiler; import de.dhbwstuttgart.core.MyCompilerAPI; import de.dhbwstuttgart.logger.Logger; @@ -17,6 +18,8 @@ import de.dhbwstuttgart.parser.JavaParser.yyException; import de.dhbwstuttgart.syntaxtree.SourceFile; import de.dhbwstuttgart.typeinference.Menge; import de.dhbwstuttgart.typeinference.TypeinferenceResultSet; +import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertPoint; +import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertSet; public class UnifyFilter { public final static String rootDirectory = System.getProperty("user.dir")+"/test/unify/"; @@ -32,6 +35,7 @@ public class UnifyFilter { //Nichts weiter unternehmen. Nur die Ausgabe des Unifikationsalgorithmus anzeigen. String log = Logger.getWholeLog(); //System.out.println(log); + writeLogFile(log); } catch (Exception e){ e.printStackTrace();