From c9477705cc92bc50cdef72ec4ef5371b3de73223 Mon Sep 17 00:00:00 2001 From: JanUlrich Date: Wed, 23 Apr 2014 15:19:56 +0200 Subject: [PATCH] =?UTF-8?q?Typen=20in=20Parameterlisten=20von=20Lambda=20A?= =?UTF-8?q?usdr=C3=BCcken=20werden=20nicht=20mehr=20eingesetzt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/mycompiler/myclass/FormalParameter.java | 8 ++++- .../mystatement/LambdaExpression.java | 6 +++- .../mystatement/LambdaParameter.java | 30 +++++++++++++++++++ .../TypeinferenceResultSet.java | 3 +- src/typinferenz/TypeInsertSet.java | 10 +++++-- 5 files changed, 52 insertions(+), 5 deletions(-) create mode 100644 src/mycompiler/mystatement/LambdaParameter.java diff --git a/src/mycompiler/myclass/FormalParameter.java b/src/mycompiler/myclass/FormalParameter.java index 06aabbcd..d9c787b7 100755 --- a/src/mycompiler/myclass/FormalParameter.java +++ b/src/mycompiler/myclass/FormalParameter.java @@ -259,7 +259,8 @@ public class FormalParameter extends SyntaxTreeNode implements ITypeReplacementL public TypeInsertPoint createTypeInsertPoint(TypePlaceholder tph, ResultSet resultSet) { if(this.getOffset()<=0)return null; - return new TypeInsertPoint(this, resultSet.getTypeEqualTo(tph), resultSet); + Type t = resultSet.getTypeEqualTo(tph); + return new TypeInsertPoint(this, t, resultSet); } @@ -272,5 +273,10 @@ public class FormalParameter extends SyntaxTreeNode implements ITypeReplacementL } + public DeclId getDeclId() { + return this.declid; + } + + } // ino.end diff --git a/src/mycompiler/mystatement/LambdaExpression.java b/src/mycompiler/mystatement/LambdaExpression.java index b2df8159..3374ecfb 100755 --- a/src/mycompiler/mystatement/LambdaExpression.java +++ b/src/mycompiler/mystatement/LambdaExpression.java @@ -67,7 +67,11 @@ public class LambdaExpression extends Expr{ } public void setParameterList(ParameterList params){ - this.params = params; + ParameterList lambdaParameter = new ParameterList(); + for(FormalParameter fp : params){ + lambdaParameter.formalparameter.add(new LambdaParameter(fp)); + } + this.params = lambdaParameter; } diff --git a/src/mycompiler/mystatement/LambdaParameter.java b/src/mycompiler/mystatement/LambdaParameter.java new file mode 100644 index 00000000..46a116d8 --- /dev/null +++ b/src/mycompiler/mystatement/LambdaParameter.java @@ -0,0 +1,30 @@ +package mycompiler.mystatement; + +import typinferenz.ResultSet; +import typinferenz.TypeInsertPoint; +import mycompiler.myclass.DeclId; +import mycompiler.myclass.FormalParameter; +import mycompiler.mytype.Type; +import mycompiler.mytype.TypePlaceholder; + +/** + * Der FormalParameter einer LambdaExpression hat gesonderte Eigenschaften. + * @author janulrich + * + */ +public class LambdaParameter extends FormalParameter { + + public LambdaParameter(FormalParameter fp) { + super(fp.getDeclId()); + this.setType(fp.getType()); + this.parent = fp.getParent(); + this.inferencelog = fp.inferencelog; + } + + @Override + public TypeInsertPoint createTypeInsertPoint(TypePlaceholder tph, + ResultSet resultSet) { + return null;//Ein LambdaParameter darf keine Typen einsetzen. + } + +} diff --git a/src/mycompiler/mytypereconstruction/TypeinferenceResultSet.java b/src/mycompiler/mytypereconstruction/TypeinferenceResultSet.java index 45d69e4c..ba1dd17c 100755 --- a/src/mycompiler/mytypereconstruction/TypeinferenceResultSet.java +++ b/src/mycompiler/mytypereconstruction/TypeinferenceResultSet.java @@ -139,7 +139,8 @@ public class TypeinferenceResultSet for(int i = 0; i genericTIPs = new Vector(); + + //Alle gebrauchten Generischen Variablen ermitteln: for(TypeInsertPoint p : points){ GenericTypeInsertPoint toAdd = new GenericTypeInsertPoint(p); for(Pair genericPair : p.getResultSet().getConstraintsFor(p.getUnresolvedTPH())){ @@ -60,15 +62,19 @@ public class TypeInsertSet { } genericTIPs.add(toAdd); } - + //... und dem TypeInsertSet anfügen: for(GenericTypeInsertPoint p : genericTIPs){ for(GenericTypeInsertPoint p2 : genericTIPs){ //Doppelte Generische Variablen definitionen ausschließen: - for(TypeInsertPoint toAdd : p.merge(p2))this.add(toAdd); + for(TypeInsertPoint toAdd : p.merge(p2)){ + this.add(toAdd); + //TODO: Alle Typen, welche die einzusetzenden Generischen Typen beinhalten, müssen ebenfalls eingesetzt werden. + } } //this.add(p); } + //Anschließend sortieren: Collections.sort(points); for(TypeInsertPoint p : points){