From e7034f82ce4ca468cf62abfa46c29d38398cf145 Mon Sep 17 00:00:00 2001 From: JanUlrich Date: Mon, 11 Aug 2014 14:35:33 +0200 Subject: [PATCH 1/5] Kleine Verbesserungen --- src/mycompiler/SourceFile.java | 4 +-- src/mycompiler/myoperator/AddOp.java | 10 ++++---- src/mycompiler/myoperator/LogOp.java | 2 +- src/mycompiler/myoperator/MulOp.java | 8 +++--- src/mycompiler/myoperator/RelOp.java | 8 +++--- src/mycompiler/mystatement/BoolLiteral.java | 2 +- src/mycompiler/mystatement/DoubleLiteral.java | 2 +- src/mycompiler/mystatement/IfStmt.java | 2 +- src/mycompiler/mystatement/IntLiteral.java | 2 +- src/mycompiler/mystatement/LocalVarDecl.java | 2 +- src/mycompiler/mystatement/NewClass.java | 2 +- src/mycompiler/mystatement/StringLiteral.java | 2 +- src/mycompiler/mystatement/WhileStmt.java | 2 +- .../mytype/BoundedGenericTypeVar.java | 4 +-- src/mycompiler/mytype/Type.java | 2 +- .../assumptions/TypeAssumptions.java | 5 ++-- .../exceptions/TypeinferenceException.java | 1 + .../TypeInsertTests/LambdaTest22.jav | 25 +++++++++++++++++++ .../TypeInsertTests/LambdaTest22.java | 16 ++++++++++++ .../TypeInsertTests/RelOpTest.jav | 3 +++ .../TypeInsertTests/RelOpTest.java | 16 ++++++++++++ 21 files changed, 91 insertions(+), 29 deletions(-) create mode 100644 test/plugindevelopment/TypeInsertTests/LambdaTest22.jav create mode 100644 test/plugindevelopment/TypeInsertTests/LambdaTest22.java create mode 100644 test/plugindevelopment/TypeInsertTests/RelOpTest.jav create mode 100644 test/plugindevelopment/TypeInsertTests/RelOpTest.java diff --git a/src/mycompiler/SourceFile.java b/src/mycompiler/SourceFile.java index 2697eb23b..dca19a116 100755 --- a/src/mycompiler/SourceFile.java +++ b/src/mycompiler/SourceFile.java @@ -737,7 +737,7 @@ public class SourceFile if(t!=null && (t instanceof RefType)&& !(t instanceof mycompiler.mytype.Void)){ Type replaceType = null; - replaceType = globalAssumptions.getTypeFor((RefType)t); + replaceType = globalAssumptions.getTypeFor((RefType)t, null); if(!(replaceType == null))p.TA1 = replaceType; } t = p.TA2; @@ -745,7 +745,7 @@ public class SourceFile if(t!=null && (t instanceof RefType)&& !(t instanceof mycompiler.mytype.Void)){ Type replaceType = null; - replaceType = globalAssumptions.getTypeFor((RefType)t); + replaceType = globalAssumptions.getTypeFor((RefType)t, null); if(!(replaceType == null))p.TA2 = replaceType; } } diff --git a/src/mycompiler/myoperator/AddOp.java b/src/mycompiler/myoperator/AddOp.java index e81767423..c472c504b 100755 --- a/src/mycompiler/myoperator/AddOp.java +++ b/src/mycompiler/myoperator/AddOp.java @@ -67,11 +67,11 @@ public abstract class AddOp extends Operator @Override public HashMap getReturnTypes(TypeAssumptions ass) { HashMap ret = new HashMap(); - ret.put(ass.getTypeFor(new RefType("java.lang.Integer",-1)), ass.getTypeFor(new RefType("java.lang.Integer",-1))); - ret.put(ass.getTypeFor(new RefType("java.lang.Double",-1)), ass.getTypeFor(new RefType("java.lang.Double",-1))); - ret.put(ass.getTypeFor(new RefType("java.lang.Float",-1)), ass.getTypeFor(new RefType("java.lang.Float",-1))); - ret.put(ass.getTypeFor(new RefType("java.lang.Long",-1)), ass.getTypeFor(new RefType("java.lang.Long",-1))); - ret.put(ass.getTypeFor(new RefType("java.lang.String",-1)), ass.getTypeFor(new RefType("java.lang.String",-1))); + ret.put(ass.getTypeFor(new RefType("java.lang.Integer",-1), this), ass.getTypeFor(new RefType("java.lang.Integer",-1),this)); + ret.put(ass.getTypeFor(new RefType("java.lang.Double",-1), this), ass.getTypeFor(new RefType("java.lang.Double",-1),this)); + ret.put(ass.getTypeFor(new RefType("java.lang.Float",-1), this), ass.getTypeFor(new RefType("java.lang.Float",-1),this)); + ret.put(ass.getTypeFor(new RefType("java.lang.Long",-1), this), ass.getTypeFor(new RefType("java.lang.Long",-1),this)); + ret.put(ass.getTypeFor(new RefType("java.lang.String",-1),this), ass.getTypeFor(new RefType("java.lang.String",-1),this)); return ret; } diff --git a/src/mycompiler/myoperator/LogOp.java b/src/mycompiler/myoperator/LogOp.java index c59fc4c82..13a52c997 100755 --- a/src/mycompiler/myoperator/LogOp.java +++ b/src/mycompiler/myoperator/LogOp.java @@ -237,7 +237,7 @@ public abstract class LogOp extends Operator @Override public HashMap getReturnTypes(TypeAssumptions ass) { HashMap ret = new HashMap(); - ret.put(ass.getTypeFor(new RefType("java.lang.Boolean",-1)), ass.getTypeFor(new RefType("java.lang.Boolean",-1))); + ret.put(ass.getTypeFor(new RefType("java.lang.Boolean",-1), this), ass.getTypeFor(new RefType("java.lang.Boolean",-1), this)); return ret; } diff --git a/src/mycompiler/myoperator/MulOp.java b/src/mycompiler/myoperator/MulOp.java index 8781b4a6d..40d160f3a 100755 --- a/src/mycompiler/myoperator/MulOp.java +++ b/src/mycompiler/myoperator/MulOp.java @@ -48,10 +48,10 @@ public abstract class MulOp extends Operator @Override public HashMap getReturnTypes(TypeAssumptions ass) { HashMap ret = new HashMap(); - ret.put(ass.getTypeFor(new RefType("java.lang.Integer",-1)), ass.getTypeFor(new RefType("java.lang.Integer",-1))); - ret.put(ass.getTypeFor(new RefType("java.lang.Double",-1)), ass.getTypeFor(new RefType("java.lang.Double",-1))); - ret.put(ass.getTypeFor(new RefType("java.lang.Float",-1)), ass.getTypeFor(new RefType("java.lang.Float",-1))); - ret.put(ass.getTypeFor(new RefType("java.lang.Long",-1)), ass.getTypeFor(new RefType("java.lang.Long",-1))); + ret.put(ass.getTypeFor(new RefType("java.lang.Integer",-1), this), ass.getTypeFor(new RefType("java.lang.Integer",-1), this)); + ret.put(ass.getTypeFor(new RefType("java.lang.Double",-1), this), ass.getTypeFor(new RefType("java.lang.Double",-1), this)); + ret.put(ass.getTypeFor(new RefType("java.lang.Float",-1), this), ass.getTypeFor(new RefType("java.lang.Float",-1), this)); + ret.put(ass.getTypeFor(new RefType("java.lang.Long",-1), this), ass.getTypeFor(new RefType("java.lang.Long",-1), this)); return ret; } diff --git a/src/mycompiler/myoperator/RelOp.java b/src/mycompiler/myoperator/RelOp.java index aa5f54b29..1b9e9f24b 100755 --- a/src/mycompiler/myoperator/RelOp.java +++ b/src/mycompiler/myoperator/RelOp.java @@ -60,10 +60,10 @@ public abstract class RelOp extends Operator @Override public HashMap getReturnTypes(TypeAssumptions ass) { HashMap ret = new HashMap(); - ret.put(ass.getTypeFor(new RefType("java.lang.Boolean",-1)), ass.getTypeFor(new RefType("java.lang.Integer",-1))); - ret.put(ass.getTypeFor(new RefType("java.lang.Boolean",-1)), ass.getTypeFor(new RefType("java.lang.Double",-1))); - ret.put(ass.getTypeFor(new RefType("java.lang.Boolean",-1)), ass.getTypeFor(new RefType("java.lang.Float",-1))); - ret.put(ass.getTypeFor(new RefType("java.lang.Boolean",-1)), ass.getTypeFor(new RefType("java.lang.Long",-1))); + ret.put(ass.getTypeFor(new RefType("java.lang.Boolean",-1), this), ass.getTypeFor(new RefType("java.lang.Integer",-1), this)); + ret.put(ass.getTypeFor(new RefType("java.lang.Boolean",-1), this), ass.getTypeFor(new RefType("java.lang.Double",-1), this)); + ret.put(ass.getTypeFor(new RefType("java.lang.Boolean",-1), this), ass.getTypeFor(new RefType("java.lang.Float",-1), this)); + ret.put(ass.getTypeFor(new RefType("java.lang.Boolean",-1), this), ass.getTypeFor(new RefType("java.lang.Long",-1), this)); return ret; } diff --git a/src/mycompiler/mystatement/BoolLiteral.java b/src/mycompiler/mystatement/BoolLiteral.java index 7c4c9a373..bdc1bb799 100755 --- a/src/mycompiler/mystatement/BoolLiteral.java +++ b/src/mycompiler/mystatement/BoolLiteral.java @@ -180,7 +180,7 @@ public class BoolLiteral extends Literal @Override public ConstraintsSet TYPEExpr(TypeAssumptions assumptions) { - this.type = assumptions.getTypeFor(new RefType("java.lang.Boolean",-1)); + this.type = assumptions.getTypeFor(new RefType("java.lang.Boolean",-1), this); return new ConstraintsSet(); } diff --git a/src/mycompiler/mystatement/DoubleLiteral.java b/src/mycompiler/mystatement/DoubleLiteral.java index 7a80f1c13..b3188d7ad 100755 --- a/src/mycompiler/mystatement/DoubleLiteral.java +++ b/src/mycompiler/mystatement/DoubleLiteral.java @@ -205,7 +205,7 @@ public class DoubleLiteral extends Literal @Override public ConstraintsSet TYPEExpr(TypeAssumptions assumptions) { - this.setType(assumptions.getTypeFor(new RefType("Double",this.getOffset()))); + this.setType(assumptions.getTypeFor(new RefType("Double",this.getOffset()), this)); return new ConstraintsSet(); } diff --git a/src/mycompiler/mystatement/IfStmt.java b/src/mycompiler/mystatement/IfStmt.java index 202cb6d15..421323af0 100755 --- a/src/mycompiler/mystatement/IfStmt.java +++ b/src/mycompiler/mystatement/IfStmt.java @@ -389,7 +389,7 @@ public class IfStmt extends Statement ret.add(this.else_block.TYPEStmt(assumptions)); if(!(else_block.getType() instanceof Void))ret.add(new SingleConstraint(else_block.getType(),this.getType())); } - ret.add(new SingleConstraint(expr.getType(),assumptions.getTypeFor(new RefType("Boolean",0)))); //(expressionDesIfStmt)<.boolean + ret.add(new SingleConstraint(expr.getType(),assumptions.getTypeFor(new RefType("Boolean",0), this))); //(expressionDesIfStmt)<.boolean if(!(then_block.getType() instanceof Void))ret.add(new SingleConstraint(then_block.getType(),this.getType())); if(then_block.getType() instanceof Void && (else_block == null || else_block.getType() instanceof Void))this.setType(new Void(this.getOffset())); diff --git a/src/mycompiler/mystatement/IntLiteral.java b/src/mycompiler/mystatement/IntLiteral.java index 4a71809da..4b486986f 100755 --- a/src/mycompiler/mystatement/IntLiteral.java +++ b/src/mycompiler/mystatement/IntLiteral.java @@ -207,7 +207,7 @@ public class IntLiteral extends Literal public ConstraintsSet TYPEExpr(TypeAssumptions assumptions) { ConstraintsSet ret = new ConstraintsSet(); //this.setType(new IntegerType()); - this.set_Type(assumptions.getTypeFor(new RefType("java.lang.Integer",-1))); + this.set_Type(assumptions.getTypeFor(new RefType("java.lang.Integer",-1), this)); return ret; } diff --git a/src/mycompiler/mystatement/LocalVarDecl.java b/src/mycompiler/mystatement/LocalVarDecl.java index bbf420e6e..76b19cd6a 100755 --- a/src/mycompiler/mystatement/LocalVarDecl.java +++ b/src/mycompiler/mystatement/LocalVarDecl.java @@ -470,7 +470,7 @@ public class LocalVarDecl extends Statement implements TypeInsertable ConstraintsSet ret = new ConstraintsSet(); if((this.getType() instanceof RefType)){ Type replaceType = null; - replaceType = assumptions.getTypeFor((RefType)this.getType()); + replaceType = assumptions.getTypeFor((RefType)this.getType(), this); if(replaceType == null) throw new TypeinferenceException("Der Typ "+this.getType().getName()+" ist nicht korrekt",this); this.setType(replaceType); diff --git a/src/mycompiler/mystatement/NewClass.java b/src/mycompiler/mystatement/NewClass.java index dddfb35d3..9f250fff6 100755 --- a/src/mycompiler/mystatement/NewClass.java +++ b/src/mycompiler/mystatement/NewClass.java @@ -255,7 +255,7 @@ public class NewClass extends Expr // ret.add(arg.TYPEExpr(assumptions)); //} - this.setType(assumptions.getTypeFor(new RefType(this.get_Name(),0))); + this.setType(assumptions.getTypeFor(new RefType(this.get_Name(),0), this)); /* diff --git a/src/mycompiler/mystatement/StringLiteral.java b/src/mycompiler/mystatement/StringLiteral.java index 247f8483c..9e56bc8aa 100755 --- a/src/mycompiler/mystatement/StringLiteral.java +++ b/src/mycompiler/mystatement/StringLiteral.java @@ -139,7 +139,7 @@ public class StringLiteral extends Literal @Override public ConstraintsSet TYPEExpr(TypeAssumptions assumptions) { - this.set_Type(assumptions.getTypeFor(new RefType("String",0))); + this.set_Type(assumptions.getTypeFor(new RefType("String",0), this)); if(this.getType() == null)throw new TypeinferenceException("java.lang.String nicht importiert",this); return new ConstraintsSet(); } diff --git a/src/mycompiler/mystatement/WhileStmt.java b/src/mycompiler/mystatement/WhileStmt.java index aa3824477..ee4e880df 100755 --- a/src/mycompiler/mystatement/WhileStmt.java +++ b/src/mycompiler/mystatement/WhileStmt.java @@ -182,7 +182,7 @@ public class WhileStmt extends Statement public ConstraintsSet TYPEStmt(TypeAssumptions assumptions) { ConstraintsSet ret = new ConstraintsSet(); ret.add(expr.TYPEExpr(assumptions)); - SingleConstraint exprMustBeBool = new SingleConstraint(expr.getType(), assumptions.getTypeFor(new RefType("Boolean", 0))); // while(expr){}; expr <. boolean + SingleConstraint exprMustBeBool = new SingleConstraint(expr.getType(), assumptions.getTypeFor(new RefType("Boolean", 0), this)); // while(expr){}; expr <. boolean ret.add(exprMustBeBool); ret.add(this.loop_block.TYPEStmt(assumptions)); this.setType(loop_block.getType()); diff --git a/src/mycompiler/mytype/BoundedGenericTypeVar.java b/src/mycompiler/mytype/BoundedGenericTypeVar.java index fee474b7b..80632722c 100755 --- a/src/mycompiler/mytype/BoundedGenericTypeVar.java +++ b/src/mycompiler/mytype/BoundedGenericTypeVar.java @@ -89,9 +89,9 @@ public class BoundedGenericTypeVar extends GenericTypeVar //Die Type methode der BoundedGenericTypeVar schreibt zusätzlich noch die Constraints für die bounds if(this.bounds != null){ for(Type ev : this.bounds){ - Type extendsType = ass.getTypeFor(ev); + Type extendsType = ass.getTypeFor(ev, this); if(extendsType == null)throw new TypeinferenceException("Der Typ "+ev.getName()+" ist nicht korrekt", this); - ret.add(new SingleConstraint(ass.getTypeFor(this), extendsType )); + ret.add(new SingleConstraint(ass.getTypeFor(this, this), extendsType )); } } return ret; diff --git a/src/mycompiler/mytype/Type.java b/src/mycompiler/mytype/Type.java index e95ed21ed..d5f7dcc05 100755 --- a/src/mycompiler/mytype/Type.java +++ b/src/mycompiler/mytype/Type.java @@ -286,7 +286,7 @@ public class Type implements IItemWithOffset * @param ass - Die Assumptions für den jeweiligen Kontext in dem sich der Typ befindet. */ public Type checkType(TypeAssumptions ass, IItemWithOffset parent){ - Type t = ass.getTypeFor(this); + Type t = ass.getTypeFor(this, this); if(t==null) throw new TypeinferenceException("Der Typ "+this.getName()+" ist nicht korrekt", parent); return t; diff --git a/src/typinferenz/assumptions/TypeAssumptions.java b/src/typinferenz/assumptions/TypeAssumptions.java index 1509f6edb..618725f03 100755 --- a/src/typinferenz/assumptions/TypeAssumptions.java +++ b/src/typinferenz/assumptions/TypeAssumptions.java @@ -295,7 +295,7 @@ public class TypeAssumptions { * @param t * @return null, falls der Typ nicht vorhanden ist. */ - public Type getTypeFor(Type t){ + public Type getTypeFor(Type t, IItemWithOffset inNode){ if(t instanceof TypePlaceholder) return t; //Handelt es sich um einen TypePlaceholder kann dieser nicht in den Assumptions vorkommen. @@ -327,7 +327,8 @@ public class TypeAssumptions { if(ass.getIdentifier().equals(t.getName()))return ass.getAssumedType(); } - return null; + //return null; + throw new TypeinferenceException("Der Typ "+t.getName()+" ist nicht korrekt",inNode); } /** diff --git a/src/typinferenz/exceptions/TypeinferenceException.java b/src/typinferenz/exceptions/TypeinferenceException.java index ef5d6c6fa..2fe6897e7 100755 --- a/src/typinferenz/exceptions/TypeinferenceException.java +++ b/src/typinferenz/exceptions/TypeinferenceException.java @@ -21,6 +21,7 @@ public class TypeinferenceException extends RuntimeException { { super(message); this.message=message; + if(problemSource == null)throw new DebugException("TypinferenzException ohne Offset: "+this.message); this.offset=problemSource.getOffset(); } diff --git a/test/plugindevelopment/TypeInsertTests/LambdaTest22.jav b/test/plugindevelopment/TypeInsertTests/LambdaTest22.jav new file mode 100644 index 000000000..e0d9849a1 --- /dev/null +++ b/test/plugindevelopment/TypeInsertTests/LambdaTest22.jav @@ -0,0 +1,25 @@ +import java.util.Vector; + +class Matrix extends Vector> { + + mvmul(Test v) { + i; + ele; + v.add(i); + return this; + } +} + +class Test{ + +void add(Integer i){ + +} + +elementAt(Integer i){ +return 1; +} +size(){ +return 1; +} +} \ No newline at end of file diff --git a/test/plugindevelopment/TypeInsertTests/LambdaTest22.java b/test/plugindevelopment/TypeInsertTests/LambdaTest22.java new file mode 100644 index 000000000..569bfb2f8 --- /dev/null +++ b/test/plugindevelopment/TypeInsertTests/LambdaTest22.java @@ -0,0 +1,16 @@ +package plugindevelopment.TypeInsertTests; + +import java.util.Vector; + +import org.junit.Test; + +public class LambdaTest22 { + private static final String TEST_FILE = "LambdaTest22.jav"; + + @Test + public void run(){ + Vector mustContain = new Vector(); + mustContain.add("TestIfStmt var"); + MultipleTypesInsertTester.testSingleInsert(this.TEST_FILE, mustContain); + } +} diff --git a/test/plugindevelopment/TypeInsertTests/RelOpTest.jav b/test/plugindevelopment/TypeInsertTests/RelOpTest.jav new file mode 100644 index 000000000..a481747d5 --- /dev/null +++ b/test/plugindevelopment/TypeInsertTests/RelOpTest.jav @@ -0,0 +1,3 @@ +class RelOpTest{ + i = 1 < 1; +} \ No newline at end of file diff --git a/test/plugindevelopment/TypeInsertTests/RelOpTest.java b/test/plugindevelopment/TypeInsertTests/RelOpTest.java new file mode 100644 index 000000000..76e264c02 --- /dev/null +++ b/test/plugindevelopment/TypeInsertTests/RelOpTest.java @@ -0,0 +1,16 @@ +package plugindevelopment.TypeInsertTests; + +import java.util.Vector; + +import org.junit.Test; + +public class RelOpTest { + private static final String TEST_FILE = "RelOpTest.jav"; + + @Test + public void run(){ + Vector mustContain = new Vector(); + mustContain.add("Boolean i"); + MultipleTypesInsertTester.testSingleInsert(this.TEST_FILE, mustContain); + } +} From d39aecff4dde339e5db47cd31a1499666c520cd1 Mon Sep 17 00:00:00 2001 From: JanUlrich Date: Thu, 14 Aug 2014 12:25:58 +0200 Subject: [PATCH 2/5] PrintJavaCode in PostIncExpr fixed --- src/mycompiler/mystatement/PostIncExpr.java | 6 ++- src/mycompiler/mytype/RefType.java | 1 + .../TypeInsertTests/LambdaTest22.jav | 48 +++++++++++-------- 3 files changed, 34 insertions(+), 21 deletions(-) diff --git a/src/mycompiler/mystatement/PostIncExpr.java b/src/mycompiler/mystatement/PostIncExpr.java index ae6ddbf54..65e3e7266 100755 --- a/src/mycompiler/mystatement/PostIncExpr.java +++ b/src/mycompiler/mystatement/PostIncExpr.java @@ -180,8 +180,10 @@ public class PostIncExpr extends UnaryExpr @Override public JavaCodeResult printJavaCode(ResultSet resultSet) { - // TODO Auto-generated method stub - return null; + JavaCodeResult ret = new JavaCodeResult(); + ret.attach(this.expr.printJavaCode(resultSet)); + ret.attach("++"); + return ret; } @Override diff --git a/src/mycompiler/mytype/RefType.java b/src/mycompiler/mytype/RefType.java index 72810d735..6cc1a93a7 100755 --- a/src/mycompiler/mytype/RefType.java +++ b/src/mycompiler/mytype/RefType.java @@ -91,6 +91,7 @@ public class RefType extends Type implements IMatchable @Override public int hashCode() { int hash = 0; + hash += super.hashCode(); hash += this.name.hashCode();//Nur den Name hashen. Sorgt für langsame, aber funktionierende HashMaps return hash; } diff --git a/test/plugindevelopment/TypeInsertTests/LambdaTest22.jav b/test/plugindevelopment/TypeInsertTests/LambdaTest22.jav index e0d9849a1..001e3d5bb 100644 --- a/test/plugindevelopment/TypeInsertTests/LambdaTest22.jav +++ b/test/plugindevelopment/TypeInsertTests/LambdaTest22.jav @@ -2,24 +2,34 @@ import java.util.Vector; class Matrix extends Vector> { - mvmul(Test v) { - i; - ele; - v.add(i); - return this; + Matrix mul(m){ + Vector> ret; + ret = new Matrix(); + i; + i = 0; + while(i < this.size()) { + v1; + v2; + v1 = this.elementAt(i); + v2 = new Vector(); + j; + j = 0; + while(j < v1.size()) { + erg; + erg = 0; + k; + k = 0; + while(k < v1.size()) { + erg = erg + v1.elementAt(k).intValue() * m.elementAt(k).elementAt(j).intValue(); + k++; + } + v2.addElement(new Integer(erg)); + j++; + } + ret.addElement(v2); + i++; + } + return ret; } -} - -class Test{ - -void add(Integer i){ - -} - -elementAt(Integer i){ -return 1; -} -size(){ -return 1; -} + } \ No newline at end of file From bd74b245004a83ab000c2bb1a69f6949c02d4838 Mon Sep 17 00:00:00 2001 From: JanUlrich Date: Thu, 28 Aug 2014 18:42:40 +0200 Subject: [PATCH 3/5] Fehler beseitigt --- bin/.gitignore | 8 ++--- src/mycompiler/SourceFile.java | 11 ++++-- src/mycompiler/myclass/FieldDeclaration.java | 3 +- src/mycompiler/mystatement/PostIncExpr.java | 34 +++++++++++++++++-- src/typinferenz/assumptions/Assumption.java | 5 +-- .../assumptions/FieldAssumption.java | 5 +-- .../assumptions/GenericVarAssumption.java | 5 +-- .../assumptions/TypeAssumptions.java | 1 + .../MartinTestCases/BoundedType1.jav | 2 +- .../MartinTestCases/BoundedType2.jav | 2 +- .../MartinTestCases/Plus1_Float_Double.jav | 2 +- .../MartinTestCases/Tester.java | 4 +-- 12 files changed, 61 insertions(+), 21 deletions(-) diff --git a/bin/.gitignore b/bin/.gitignore index 5774d208a..acd086ea2 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 dca19a116..1a4f26858 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 694c9e353..91ef8382b 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 65e3e7266..69d520b57 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 d370d85f3..1d52b9d15 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 8e36d20de..46243e71b 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 b2fb25971..c564878a4 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 618725f03..e2df73abd 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 af71bfa73..f56a643e0 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 47602aba5..ccb0d6a2f 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 75c3baad7..5291001cd 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 2f9778e06..ddea7b3b8 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"); From 25d61b703be663513c6bbb64524c78b1a672885f Mon Sep 17 00:00:00 2001 From: JanUlrich Date: Thu, 28 Aug 2014 18:42:54 +0200 Subject: [PATCH 4/5] =?UTF-8?q?JavaClassName=20eingef=C3=BChrt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/mycompiler/myparser/JavaClassName.java | 124 +++++++++++++++++++++ 1 file changed, 124 insertions(+) create mode 100644 src/mycompiler/myparser/JavaClassName.java diff --git a/src/mycompiler/myparser/JavaClassName.java b/src/mycompiler/myparser/JavaClassName.java new file mode 100644 index 000000000..adf9b0549 --- /dev/null +++ b/src/mycompiler/myparser/JavaClassName.java @@ -0,0 +1,124 @@ +package mycompiler.myparser; + +import java.util.Vector; + +import mycompiler.mytype.RefType; + +/** + * Stellt den Namen einer Java Klasse dar. + * Dieser kann auch den Packagenamen mit beinhalten: java.util.Vector + * + * @author janulrich + * + */ +public class JavaClassName { + + private String name; + private PackageName packageName; + + public JavaClassName(String name){ + String[] names = name.split("[.]"); + boolean match = true; + if(names.length == 1){ + packageName = new PackageName(); + this.name = name; + }else { + name = names[names.length-1]; + Vector packageNames = new Vector(); + for(int i = 0; i names = new Vector(); + + public PackageName(Vector packageNames) { + names = packageNames; + } + + public PackageName() { + //Do nothing + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((names == null) ? 0 : names.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + PackageName other = (PackageName) obj; + if (names == null) { + if (other.names != null) + return false; + } else if (!names.equals(other.names)) + return false; + return true; + } + + @Override + public String toString() { + String ret = ""; + if(names == null)return ""; + for(String n : names)ret+=n+"."; + return ret; + } +} From 55d40d14ad1cfcab26bb542949eb8199a9214ebf Mon Sep 17 00:00:00 2001 From: JanUlrich Date: Thu, 28 Aug 2014 19:05:57 +0200 Subject: [PATCH 5/5] =?UTF-8?q?UnaryExpr=20ver=C3=A4ndert?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/mycompiler/myclass/FormalParameter.java | 2 +- src/mycompiler/mystatement/PostDecExpr.java | 9 ----- src/mycompiler/mystatement/PostIncExpr.java | 34 +--------------- src/mycompiler/mystatement/PreDecExpr.java | 9 +---- src/mycompiler/mystatement/PreIncExpr.java | 9 ----- src/mycompiler/mystatement/UnaryExpr.java | 43 ++++++++++++++++++++- 6 files changed, 45 insertions(+), 61 deletions(-) diff --git a/src/mycompiler/myclass/FormalParameter.java b/src/mycompiler/myclass/FormalParameter.java index c3ef09f7c..cef327a54 100755 --- a/src/mycompiler/myclass/FormalParameter.java +++ b/src/mycompiler/myclass/FormalParameter.java @@ -60,7 +60,7 @@ public class FormalParameter extends SyntaxTreeNode implements ITypeReplacementL @Override public boolean equals(Object object) { - if(!super.equals(object))return false; + //if(!super.equals(object))return false; //Nicht die Position im SyntaxBaum prüfen. if(!(object instanceof FormalParameter))return false; FormalParameter equals = (FormalParameter)object; if((this.type==null)!=(equals.type == null))return false; diff --git a/src/mycompiler/mystatement/PostDecExpr.java b/src/mycompiler/mystatement/PostDecExpr.java index 2e9a10946..91c0f37c6 100755 --- a/src/mycompiler/mystatement/PostDecExpr.java +++ b/src/mycompiler/mystatement/PostDecExpr.java @@ -54,9 +54,6 @@ public class PostDecExpr extends UnaryExpr super(offset,variableLength); } // ino.end - // ino.attribute.expr.25994.declaration - public Expr expr; - // ino.end // ino.attribute.parserlog.25997.declaration protected static Logger parserlog = Logger.getLogger("parser"); // ino.end @@ -172,12 +169,6 @@ public class PostDecExpr extends UnaryExpr expr.addOffsetsToExpression(localAssumption,NameVariable,isMemberVariable); } - @Override - public ConstraintsSet TYPEExpr(TypeAssumptions assumptions) { - // TODO Auto-generated method stub - return null; - } - @Override public JavaCodeResult printJavaCode(ResultSet resultSet) { // TODO Auto-generated method stub diff --git a/src/mycompiler/mystatement/PostIncExpr.java b/src/mycompiler/mystatement/PostIncExpr.java index 69d520b57..c17300d04 100755 --- a/src/mycompiler/mystatement/PostIncExpr.java +++ b/src/mycompiler/mystatement/PostIncExpr.java @@ -60,9 +60,7 @@ public class PostIncExpr extends UnaryExpr super(offset,variableLength); } // ino.end - // ino.attribute.expr.26028.declaration - public Expr expr; - // ino.end + // ino.attribute.parserlog.26031.declaration protected static Logger parserlog = Logger.getLogger("parser"); // ino.end @@ -178,36 +176,6 @@ 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) { - 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 public JavaCodeResult printJavaCode(ResultSet resultSet) { JavaCodeResult ret = new JavaCodeResult(); diff --git a/src/mycompiler/mystatement/PreDecExpr.java b/src/mycompiler/mystatement/PreDecExpr.java index 0576c46de..5f0c07183 100755 --- a/src/mycompiler/mystatement/PreDecExpr.java +++ b/src/mycompiler/mystatement/PreDecExpr.java @@ -55,9 +55,6 @@ public class PreDecExpr extends UnaryExpr } // ino.end - // ino.attribute.expr.26062.declaration - public Expr expr; - // ino.end // ino.attribute.parserlog.26065.declaration protected static Logger parserlog = Logger.getLogger("parser"); // ino.end @@ -171,11 +168,7 @@ public class PreDecExpr extends UnaryExpr { expr.addOffsetsToExpression(localAssumption,NameVariable,isMemberVariable); } - @Override - public ConstraintsSet TYPEExpr(TypeAssumptions assumptions) { - // TODO Auto-generated method stub - return null; - } + @Override public JavaCodeResult printJavaCode(ResultSet resultSet) { // TODO Auto-generated method stub diff --git a/src/mycompiler/mystatement/PreIncExpr.java b/src/mycompiler/mystatement/PreIncExpr.java index 839b154fc..de1e4de5e 100755 --- a/src/mycompiler/mystatement/PreIncExpr.java +++ b/src/mycompiler/mystatement/PreIncExpr.java @@ -54,9 +54,6 @@ public class PreIncExpr extends UnaryExpr super(offset,variableLength); } // ino.end - // ino.attribute.expr.26096.declaration - public Expr expr; - // ino.end // ino.attribute.parserlog.26099.declaration protected static Logger parserlog = Logger.getLogger("parser"); // ino.end @@ -173,12 +170,6 @@ public class PreIncExpr extends UnaryExpr expr.addOffsetsToExpression(localAssumption,NameVariable,isMemberVariable); } - @Override - public ConstraintsSet TYPEExpr(TypeAssumptions assumptions) { - // TODO Auto-generated method stub - return null; - } - @Override public JavaCodeResult printJavaCode(ResultSet resultSet) { // TODO Auto-generated method stub diff --git a/src/mycompiler/mystatement/UnaryExpr.java b/src/mycompiler/mystatement/UnaryExpr.java index 6b990df1b..86b32dd3b 100755 --- a/src/mycompiler/mystatement/UnaryExpr.java +++ b/src/mycompiler/mystatement/UnaryExpr.java @@ -3,10 +3,17 @@ package mycompiler.mystatement; // ino.end // ino.module.UnaryExpr.8655.import import java.util.Vector; + +import typinferenz.ConstraintsSet; +import typinferenz.OderConstraint; +import typinferenz.UndConstraint; +import typinferenz.assumptions.TypeAssumptions; import mycompiler.mybytecode.ClassFile; import mycompiler.mybytecode.CodeAttribute; import mycompiler.myexception.JVMCodeException; // ino.end +import mycompiler.mytype.RefType; +import mycompiler.mytype.TypePlaceholder; @@ -16,7 +23,9 @@ public abstract class UnaryExpr extends Expr // ino.end // ino.class.UnaryExpr.26298.body { - // ino.method.UnaryExpr.26302.definition + public Expr expr; + + // ino.method.UnaryExpr.26302.definition public UnaryExpr(int offset,int variableLength) // ino.end // ino.method.UnaryExpr.26302.body @@ -29,5 +38,37 @@ public abstract class UnaryExpr extends Expr public abstract void codegen(ClassFile classfile, CodeAttribute code, Vector paralist) throws JVMCodeException; // ino.end + + 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) { + 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); + } + + } // ino.end