From 25195440f06b43559491e5827c90a2c7df50cf70 Mon Sep 17 00:00:00 2001 From: JanUlrich Date: Thu, 7 Aug 2014 11:07:11 +0200 Subject: [PATCH] Problem mit LocalVarDecl und setType behoben --- src/mycompiler/myclass/Constructor.java | 1 - src/mycompiler/mystatement/Block.java | 4 ++-- src/mycompiler/mystatement/LocalVarDecl.java | 5 ++++- src/mycompiler/mystatement/Return.java | 9 +++++++++ src/mycompiler/mystatement/Statement.java | 6 ++++++ .../TypeInsertTests/LambdaTest15.jav | 14 +++++--------- 6 files changed, 26 insertions(+), 13 deletions(-) diff --git a/src/mycompiler/myclass/Constructor.java b/src/mycompiler/myclass/Constructor.java index be857218..c978fccd 100644 --- a/src/mycompiler/myclass/Constructor.java +++ b/src/mycompiler/myclass/Constructor.java @@ -222,7 +222,6 @@ public class Constructor extends Method { public ConstraintsSet TYPE(TypeAssumptions ass) { ConstraintsSet ret = new ConstraintsSet(); - ret.add(this.methode.get_Block().TYPEStmt(ass)); return ret; } diff --git a/src/mycompiler/mystatement/Block.java b/src/mycompiler/mystatement/Block.java index f0eeda9f..efabb756 100755 --- a/src/mycompiler/mystatement/Block.java +++ b/src/mycompiler/mystatement/Block.java @@ -233,8 +233,8 @@ public class Block extends Statement for(int i= statements.size()-2; i >= 0; i--) { stmt = statements.elementAt(i); typinferenceLog.debug("Prozessing statement: "+stmt); - if (!(stmt.getType() instanceof Void)) - if (this.getType() instanceof Void) { + if (!(stmt.getReturnType() instanceof Void)) + if (this.getReturnType() instanceof Void) { //this.setTypeVariable(stmt.getTypeVariable()); throw new TypeinferenceException("Block besitzt falschen Rückgabetyp (fehlendes return-stmt)", this); } diff --git a/src/mycompiler/mystatement/LocalVarDecl.java b/src/mycompiler/mystatement/LocalVarDecl.java index bfcc8563..bbf420e6 100755 --- a/src/mycompiler/mystatement/LocalVarDecl.java +++ b/src/mycompiler/mystatement/LocalVarDecl.java @@ -42,10 +42,12 @@ import org.apache.log4j.Logger; + import typinferenz.ConstraintsSet; import typinferenz.FreshTypeVariable; import typinferenz.JavaCodeResult; import typinferenz.ResultSet; +import typinferenz.SingleConstraint; import typinferenz.TypeInsertable; import typinferenz.assumptions.LocalVarAssumption; import typinferenz.assumptions.TypeAssumptions; @@ -474,8 +476,9 @@ public class LocalVarDecl extends Statement implements TypeInsertable this.setType(replaceType); } assumptions.addAssumption(new LocalVarAssumption(this, this.getType())); //Bevor der Typ auf Void gesetzt wird. + ret.add(new SingleConstraint(this.getType(), this.getType())); //assumptions.remove(null); // falls Variable mit diesem Namen bereits vorhanden. - this.setType(new Void(0)); //Return typ einer Variablendeklaration ist Void + this.setReturnType(new Void(0)); //Return typ einer Variablendeklaration ist Void return ret; } diff --git a/src/mycompiler/mystatement/Return.java b/src/mycompiler/mystatement/Return.java index 50a5cc7a..5e9b7dd8 100755 --- a/src/mycompiler/mystatement/Return.java +++ b/src/mycompiler/mystatement/Return.java @@ -152,5 +152,14 @@ public class Return extends Statement return ret; } + @Override + public void setReturnType(Type t){ + this.setType(t); + } + + @Override + public Type getReturnType(){ + return this.getType(); + } } // ino.end diff --git a/src/mycompiler/mystatement/Statement.java b/src/mycompiler/mystatement/Statement.java index f7b16e4d..87478156 100755 --- a/src/mycompiler/mystatement/Statement.java +++ b/src/mycompiler/mystatement/Statement.java @@ -149,5 +149,11 @@ public abstract class Statement extends SyntaxTreeNode implements IItemWithOffse return this.printJavaCode(new ResultSet(new Vector())).toString(); } + public void setReturnType(Type t){ + } + + public Type getReturnType(){ + return new mycompiler.mytype.Void(-1); + } } // ino.end diff --git a/test/plugindevelopment/TypeInsertTests/LambdaTest15.jav b/test/plugindevelopment/TypeInsertTests/LambdaTest15.jav index 2f9256c3..ef93085f 100644 --- a/test/plugindevelopment/TypeInsertTests/LambdaTest15.jav +++ b/test/plugindevelopment/TypeInsertTests/LambdaTest15.jav @@ -1,11 +1,7 @@ -class Overload{ +class ConstructorTest1{ -void method( x ){ - String varS; - Integer varI; - - x.apply(varI); - x.apply(varS); +ConstructorTest1(){ +var; +var = 1; } - -} \ No newline at end of file +}