diff --git a/bin/.gitignore b/bin/.gitignore index 5774d208..acd086ea 100644 --- a/bin/.gitignore +++ b/bin/.gitignore @@ -1,8 +1,8 @@ -/mycompiler -/typinferenz -/userinterface -/bytecode /myJvmDisassembler +/mycompiler /parser /plugindevelopment /syntaxTree +/typinferenz +/userinterface +/bytecode diff --git a/src/mycompiler/SourceFile.java b/src/mycompiler/SourceFile.java index dca19a11..1a4f2685 100755 --- a/src/mycompiler/SourceFile.java +++ b/src/mycompiler/SourceFile.java @@ -16,6 +16,7 @@ import mycompiler.myclass.Class; import mycompiler.myclass.Constructor; import mycompiler.myclass.Field; import mycompiler.myclass.FieldDeclaration; +import mycompiler.myclass.FormalParameter; import mycompiler.myclass.ImportDeclarations; import mycompiler.myclass.UsedId; import mycompiler.myexception.CTypeReconstructionException; @@ -1216,16 +1217,21 @@ public class SourceFile for(int j=0;j(),null); + ParameterList paraList = new ParameterList(); for(int k=0;k())); } //basicAssumptions.addMethodIntersectionType(new CIntersectionType(constructor)); Method constructorMethod = mycompiler.myclass.Method.createEmptyMethod(methodName, parentClass); + constructorMethod.parameterlist = paraList; parentClass.addField(new Constructor(constructorMethod)); } } @@ -1234,7 +1240,6 @@ public class SourceFile basicAssumptions.addClassAssumption(new ClassAssumption(parentClass)); imports.removeElement(importDecl); doneImports.addElement(importDecl); - } imports.addAll(doneImports); return basicAssumptions; diff --git a/src/mycompiler/myclass/FieldDeclaration.java b/src/mycompiler/myclass/FieldDeclaration.java index 694c9e35..91ef8382 100644 --- a/src/mycompiler/myclass/FieldDeclaration.java +++ b/src/mycompiler/myclass/FieldDeclaration.java @@ -128,7 +128,8 @@ public class FieldDeclaration extends Field{ } @Override public ConstraintsSet TYPE(TypeAssumptions publicAssumptions) { - if(this.wert == null)throw new TypeinferenceException("Typlose Felder müssen mit Wert initialisiert werden", this); + if(this.wert == null && (this.getType() == null || this.getType() instanceof TypePlaceholder)) + throw new TypeinferenceException("Typlose Felder müssen mit Wert initialisiert werden", this); ConstraintsSet ret = new ConstraintsSet(); TypeAssumptions localAssumptions = publicAssumptions.clone(); diff --git a/src/mycompiler/mystatement/PostIncExpr.java b/src/mycompiler/mystatement/PostIncExpr.java index 65e3e726..69d520b5 100755 --- a/src/mycompiler/mystatement/PostIncExpr.java +++ b/src/mycompiler/mystatement/PostIncExpr.java @@ -19,6 +19,7 @@ import mycompiler.mytype.GenericTypeVar; import mycompiler.mytype.Pair; import mycompiler.mytype.RefType; import mycompiler.mytype.Type; +import mycompiler.mytype.TypePlaceholder; import mycompiler.mytype.Void; import mycompiler.mytypereconstruction.CSupportData; import mycompiler.mytypereconstruction.CTriple; @@ -33,9 +34,14 @@ import org.apache.log4j.Logger; + + + import typinferenz.ConstraintsSet; import typinferenz.JavaCodeResult; +import typinferenz.OderConstraint; import typinferenz.ResultSet; +import typinferenz.UndConstraint; import typinferenz.assumptions.TypeAssumptions; @@ -172,10 +178,34 @@ public class PostIncExpr extends UnaryExpr expr.addOffsetsToExpression(localAssumption,NameVariable,isMemberVariable); } + private Vector getNumericTypes(){ + Vector ret = new Vector<>(); + ret.add(new RefType("Integer",-1)); + ret.add(new RefType("Long",-1)); + ret.add(new RefType("Double",-1)); + return ret ; + } + @Override public ConstraintsSet TYPEExpr(TypeAssumptions assumptions) { - // TODO Auto-generated method stub - return null; + if(this.getType() == null)this.setType(TypePlaceholder.fresh(this)); + ConstraintsSet ret = new ConstraintsSet(); + OderConstraint oderConstraint = new OderConstraint(); + ret.add(this.expr.TYPEExpr(assumptions)); + for(RefType t : getNumericTypes()){ + UndConstraint undConstraint = new UndConstraint(); + undConstraint.addConstraint(this.getType(), t); + undConstraint.addConstraint(this.expr.getType(), t); + + oderConstraint.addConstraint(undConstraint); + } + ret.add(oderConstraint); + return ret; + } + + @Override + public ConstraintsSet TYPEStmt(TypeAssumptions assumptions) { + return this.TYPEExpr(assumptions); } @Override diff --git a/src/typinferenz/assumptions/Assumption.java b/src/typinferenz/assumptions/Assumption.java index d370d85f..1d52b9d1 100644 --- a/src/typinferenz/assumptions/Assumption.java +++ b/src/typinferenz/assumptions/Assumption.java @@ -2,6 +2,7 @@ package typinferenz.assumptions; import typinferenz.TypeInsertable; import typinferenz.Typeable; +import mycompiler.myparser.JavaClassName; import mycompiler.mytype.*; import mycompiler.myclass.Class; @@ -23,8 +24,8 @@ public class Assumption { return this.typable.getType(); } - public String getIdentifier(){ - return typable.getIdentifier(); + public JavaClassName getIdentifier(){ + return new JavaClassName(typable.getIdentifier()); } } diff --git a/src/typinferenz/assumptions/FieldAssumption.java b/src/typinferenz/assumptions/FieldAssumption.java index 8e36d20d..46243e71 100644 --- a/src/typinferenz/assumptions/FieldAssumption.java +++ b/src/typinferenz/assumptions/FieldAssumption.java @@ -2,6 +2,7 @@ package typinferenz.assumptions; import mycompiler.myclass.Field; import mycompiler.myclass.Class; +import mycompiler.myparser.JavaClassName; import mycompiler.mytype.RefType; public class FieldAssumption extends Assumption { @@ -19,8 +20,8 @@ public class FieldAssumption extends Assumption { return this.parentClass; } - public String getIdentifier(){ - return this.field.getIdentifier(); + public JavaClassName getIdentifier(){ + return new JavaClassName(this.field.getIdentifier()); } @Override diff --git a/src/typinferenz/assumptions/GenericVarAssumption.java b/src/typinferenz/assumptions/GenericVarAssumption.java index b2fb2597..c564878a 100644 --- a/src/typinferenz/assumptions/GenericVarAssumption.java +++ b/src/typinferenz/assumptions/GenericVarAssumption.java @@ -1,5 +1,6 @@ package typinferenz.assumptions; +import mycompiler.myparser.JavaClassName; import mycompiler.mystatement.LocalVarDecl; import mycompiler.mytype.GenericTypeVar; import mycompiler.mytype.RefType; @@ -18,8 +19,8 @@ public class GenericVarAssumption extends Assumption{ return genericVar;//new RefType(this.getIdentifier(), -1); } - public String getIdentifier(){ - return genericVar.getName(); + public JavaClassName getIdentifier(){ + return new JavaClassName(genericVar.getName()); } public String toString(){ diff --git a/src/typinferenz/assumptions/TypeAssumptions.java b/src/typinferenz/assumptions/TypeAssumptions.java index 618725f0..e2df73ab 100755 --- a/src/typinferenz/assumptions/TypeAssumptions.java +++ b/src/typinferenz/assumptions/TypeAssumptions.java @@ -350,6 +350,7 @@ public class TypeAssumptions { */ public ConstructorAssumption getConstructorAssumption(String name, int size) { for(ConstructorAssumption ca : this.constructorAssumptions){ + System.out.println(ca.getIdentifier().toString() + ca.getParaCount()); if(ca.getParaCount()==size && ca.getIdentifier().equals(name))return ca; } return null; diff --git a/test/plugindevelopment/MartinTestCases/BoundedType1.jav b/test/plugindevelopment/MartinTestCases/BoundedType1.jav index af71bfa7..f56a643e 100755 --- a/test/plugindevelopment/MartinTestCases/BoundedType1.jav +++ b/test/plugindevelopment/MartinTestCases/BoundedType1.jav @@ -9,7 +9,7 @@ interface RR extends BB { class BoundedType1 { - m1(AA a) { + m1(AA a) { T1 b; a.AAm(b); } diff --git a/test/plugindevelopment/MartinTestCases/BoundedType2.jav b/test/plugindevelopment/MartinTestCases/BoundedType2.jav index 47602aba..ccb0d6a2 100755 --- a/test/plugindevelopment/MartinTestCases/BoundedType2.jav +++ b/test/plugindevelopment/MartinTestCases/BoundedType2.jav @@ -1,5 +1,5 @@ class BoundedType { - m(T x) { + m(T x) { r; r=x; return r; diff --git a/test/plugindevelopment/MartinTestCases/Plus1_Float_Double.jav b/test/plugindevelopment/MartinTestCases/Plus1_Float_Double.jav index 75c3baad..5291001c 100644 --- a/test/plugindevelopment/MartinTestCases/Plus1_Float_Double.jav +++ b/test/plugindevelopment/MartinTestCases/Plus1_Float_Double.jav @@ -1,3 +1,3 @@ class Plus1_Float_Double { - op = (x) -> x+1.0; + op = (x) -> x + 1.0; } \ No newline at end of file diff --git a/test/plugindevelopment/MartinTestCases/Tester.java b/test/plugindevelopment/MartinTestCases/Tester.java index 2f9778e0..ddea7b3b 100644 --- a/test/plugindevelopment/MartinTestCases/Tester.java +++ b/test/plugindevelopment/MartinTestCases/Tester.java @@ -54,9 +54,9 @@ public class Tester extends TypeInsertTester{ Vector testFiles = new Vector(); //testFiles.add("OL3.jav"); testFiles.add("Plus1_Float_Double.jav"); - /* + ///* testFiles.add("AchimTest1.jav"); - testFiles.add("MatrixWhile.jav"); + //testFiles.add("MatrixWhile.jav"); //testFiles.add("BoundedType1.jav"); testFiles.add("BoundedType2.jav"); testFiles.add("BoundedType.jav");