From 45d176aed27cd112d344c7824ee9e8c9defb70f2 Mon Sep 17 00:00:00 2001 From: JanUlrich Date: Wed, 16 Jul 2014 18:38:55 +0200 Subject: [PATCH] Fehler beseitigen --- src/mycompiler/myclass/Field.java | 7 +++++-- src/mycompiler/myclass/FieldDeclaration.java | 13 +++++++++++-- src/mycompiler/myclass/Method.java | 3 +++ src/mycompiler/mytype/BoundedGenericTypeVar.java | 7 +++++-- src/mycompiler/mytype/GenericTypeVar.java | 7 ++++++- src/mycompiler/mytype/Type.java | 3 ++- .../assumptions/GenericVarAssumption.java | 1 + src/typinferenz/assumptions/TypeAssumptions.java | 2 ++ .../typedeployment/GenericTypeInsertPoint.java | 9 +++++++-- .../typedeployment/SourcePatchPoint.java | 4 +--- src/typinferenz/typedeployment/TypeInsertSet.java | 4 ---- 11 files changed, 43 insertions(+), 17 deletions(-) diff --git a/src/mycompiler/myclass/Field.java b/src/mycompiler/myclass/Field.java index 35be7fcb..74364fd1 100644 --- a/src/mycompiler/myclass/Field.java +++ b/src/mycompiler/myclass/Field.java @@ -56,8 +56,10 @@ public abstract class Field extends SyntaxTreeNode implements TypeInsertable, Ty @Override public Iterable getGenericParameter() { - if(this.genericParameters == null)return new Vector(); - return this.genericParameters; + Vector ret = new Vector<>(); + if(this.genericParameters == null)return ret; + ret.addAll(this.genericParameters); + return ret; } public void set_DeclId(DeclId did) @@ -157,4 +159,5 @@ public abstract class Field extends SyntaxTreeNode implements TypeInsertable, Ty public void setGenericParameter(GenericDeclarationList params) { this.genericParameters = params; } + } diff --git a/src/mycompiler/myclass/FieldDeclaration.java b/src/mycompiler/myclass/FieldDeclaration.java index ec834600..39393a04 100644 --- a/src/mycompiler/myclass/FieldDeclaration.java +++ b/src/mycompiler/myclass/FieldDeclaration.java @@ -129,6 +129,15 @@ public class FieldDeclaration extends Field{ @Override public ConstraintsSet TYPE(TypeAssumptions publicAssumptions) { ConstraintsSet ret = new ConstraintsSet(); + TypeAssumptions localAssumptions = publicAssumptions.clone(); + + for(GenericTypeVar gp : this.getGenericParameter()){ + localAssumptions.add(gp.createAssumptions()); + } + + for(GenericTypeVar gp : this.getGenericParameter()){ + gp.TYPE(localAssumptions); + } /* if(this.getType() instanceof GenericTypeVar){ //Falls Typ ein GTV ist muss er syntaktisch kontrolliert werden... @@ -137,7 +146,7 @@ public class FieldDeclaration extends Field{ */ //TypeCheck, falls es sich um einen RefType handelt: - this.getType().checkType(publicAssumptions, this); + this.getType().checkType(localAssumptions, this); /* if(this.getType()!=null && (this.getType() instanceof RefType)){ Type replaceType = null; @@ -152,7 +161,7 @@ public class FieldDeclaration extends Field{ if(this.wert!=null){ //Falls bei der Deklaration ein Wert zugewiesen wird, verhält sich das Constraintserzeugen wie bei dem Assign-Statement: - ret.add(this.wert.TYPEExpr(publicAssumptions)); + ret.add(this.wert.TYPEExpr(localAssumptions)); ret.add(new SingleConstraint(this.wert.getType(), this.getType())); } return ret; diff --git a/src/mycompiler/myclass/Method.java b/src/mycompiler/myclass/Method.java index ffddc8ad..42ee79f0 100755 --- a/src/mycompiler/myclass/Method.java +++ b/src/mycompiler/myclass/Method.java @@ -553,6 +553,9 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable TypeAssumptions localAss = new TypeAssumptions(); localAss.add(ass); //Die globalen Assumptions anhängen //Generische Parameterdeklarationen den Assumptions anfügen: + for(GenericTypeVar gtv : this.getGenericParameter()){ + localAss.add(gtv.createAssumptions()); + } for(GenericTypeVar gtv : this.getGenericParameter()){ ret.add(gtv.TYPE(localAss)); } diff --git a/src/mycompiler/mytype/BoundedGenericTypeVar.java b/src/mycompiler/mytype/BoundedGenericTypeVar.java index fa866190..8c4ce540 100755 --- a/src/mycompiler/mytype/BoundedGenericTypeVar.java +++ b/src/mycompiler/mytype/BoundedGenericTypeVar.java @@ -11,6 +11,7 @@ import sun.reflect.generics.reflectiveObjects.NotImplementedException; import typinferenz.ConstraintsSet; import typinferenz.SingleConstraint; import typinferenz.assumptions.TypeAssumptions; +import typinferenz.exceptions.TypeinferenceException; // ino.class.BoundedGenericTypeVar.26464.description type=javadoc /** @@ -75,11 +76,13 @@ public class BoundedGenericTypeVar extends GenericTypeVar @Override public ConstraintsSet TYPE(TypeAssumptions ass) { ConstraintsSet ret = super.TYPE(ass); - ass.addGenericVarAssumption(this); + //ass.addGenericVarAssumption(this); //Die Type methode der BoundedGenericTypeVar schreibt zusätzlich noch die Constraints für die bounds if(this.bounds != null){ for(Type ev : this.bounds){ - ret.add(new SingleConstraint(ass.getTypeFor(this), ass.getTypeFor(ev))); + Type extendsType = ass.getTypeFor(ev); + if(extendsType == null)throw new TypeinferenceException("Der Typ "+ev.getName()+" ist nicht korrekt", this); + ret.add(new SingleConstraint(ass.getTypeFor(this), extendsType )); } } return ret; diff --git a/src/mycompiler/mytype/GenericTypeVar.java b/src/mycompiler/mytype/GenericTypeVar.java index 0bac7807..0d3ab9a8 100755 --- a/src/mycompiler/mytype/GenericTypeVar.java +++ b/src/mycompiler/mytype/GenericTypeVar.java @@ -199,6 +199,12 @@ public class GenericTypeVar extends Type return this.name; } + public TypeAssumptions createAssumptions(){ + TypeAssumptions ret = new TypeAssumptions(); + ret.addGenericVarAssumption(this); + return ret; + } + /** * Die Type Methode auf generische Variablen angewandt sorgt für deren Eintragung in die TypeAssumptions. * @param ass @@ -206,7 +212,6 @@ public class GenericTypeVar extends Type */ public ConstraintsSet TYPE(TypeAssumptions ass){ ConstraintsSet ret = new ConstraintsSet(); - ass.addGenericVarAssumption(this); return ret; } diff --git a/src/mycompiler/mytype/Type.java b/src/mycompiler/mytype/Type.java index 7db9ba13..e95ed21e 100755 --- a/src/mycompiler/mytype/Type.java +++ b/src/mycompiler/mytype/Type.java @@ -287,7 +287,8 @@ public class Type implements IItemWithOffset */ public Type checkType(TypeAssumptions ass, IItemWithOffset parent){ Type t = ass.getTypeFor(this); - if(t==null)throw new TypeinferenceException("Der Typ "+this.getName()+" ist nicht korrekt", parent); + if(t==null) + throw new TypeinferenceException("Der Typ "+this.getName()+" ist nicht korrekt", parent); return t; } diff --git a/src/typinferenz/assumptions/GenericVarAssumption.java b/src/typinferenz/assumptions/GenericVarAssumption.java index f0cda2cf..b2fb2597 100644 --- a/src/typinferenz/assumptions/GenericVarAssumption.java +++ b/src/typinferenz/assumptions/GenericVarAssumption.java @@ -25,4 +25,5 @@ public class GenericVarAssumption extends Assumption{ public String toString(){ return this.getIdentifier() +"::"+this.getAssumedType(); } + } diff --git a/src/typinferenz/assumptions/TypeAssumptions.java b/src/typinferenz/assumptions/TypeAssumptions.java index a7e0795d..1509f6ed 100755 --- a/src/typinferenz/assumptions/TypeAssumptions.java +++ b/src/typinferenz/assumptions/TypeAssumptions.java @@ -323,6 +323,7 @@ public class TypeAssumptions { } //Auch die generischen Variablen durchsuchen: for(GenericVarAssumption ass : this.genericVarAssumptions){ + //if(ass.inheritsType(t))return t; if(ass.getIdentifier().equals(t.getName()))return ass.getAssumedType(); } @@ -355,6 +356,7 @@ public class TypeAssumptions { public void addGenericVarAssumption( GenericTypeVar genericTypeVar) { + //TODO: Hier müssen alle Bounds einzeln geaddet werden. Die Bounds müssen hierbei nicht gespeichert werden, deren Constraints generiert die TYPE-Methode der GenericVarDeclarations this.genericVarAssumptions.add(new GenericVarAssumption(genericTypeVar)); } diff --git a/src/typinferenz/typedeployment/GenericTypeInsertPoint.java b/src/typinferenz/typedeployment/GenericTypeInsertPoint.java index ceaba466..7f566ef7 100644 --- a/src/typinferenz/typedeployment/GenericTypeInsertPoint.java +++ b/src/typinferenz/typedeployment/GenericTypeInsertPoint.java @@ -53,7 +53,7 @@ public class GenericTypeInsertPoint extends SourcePatchPoint { public String getTypeInsertString() { String genericVar = this.patch.getInsertString(this.resultSet); if(genericVar.length()==0)return ""; - return this.genericInsertPoint.getGenericVarDeclarationString(genericVar); + return this.genericInsertPoint.getGenericVarDeclarationString(genericVar)+" "; } /* @@ -98,7 +98,7 @@ public class GenericTypeInsertPoint extends SourcePatchPoint { @Override public int compareTo(SourcePatchPoint arg0) { int ret = super.compareTo(arg0); - if(ret == 0)ret = -1;//Hack der dazu führt, dass GTIP vor anderen InsertTypes eingesetzt werden. + if(ret == 0)ret = -666;//Hack der dazu führt, dass GTIP vor anderen InsertTypes eingesetzt werden. return ret; } @@ -163,6 +163,11 @@ public class GenericTypeInsertPoint extends SourcePatchPoint { public int getOffset() { return genericInsertPoint.getGenericVarDeclarationOffset(); } + + @Override + public int getInsertLength() { + return this.getTypeInsertString().length(); + } } /** diff --git a/src/typinferenz/typedeployment/SourcePatchPoint.java b/src/typinferenz/typedeployment/SourcePatchPoint.java index 813e987d..b6139669 100644 --- a/src/typinferenz/typedeployment/SourcePatchPoint.java +++ b/src/typinferenz/typedeployment/SourcePatchPoint.java @@ -17,8 +17,6 @@ public abstract class SourcePatchPoint implements Comparable{ } public abstract JavaCodeResult patch(String fileContent, int additionalOffset); - public int getInsertLength() { - return 0; - } + public abstract int getInsertLength(); } diff --git a/src/typinferenz/typedeployment/TypeInsertSet.java b/src/typinferenz/typedeployment/TypeInsertSet.java index def14326..802d4100 100644 --- a/src/typinferenz/typedeployment/TypeInsertSet.java +++ b/src/typinferenz/typedeployment/TypeInsertSet.java @@ -66,9 +66,7 @@ public class TypeInsertSet { */ public String insertType(TypeInsertPoint tip, String fileContent){ TypePatchJob tpj = new TypePatchJob(); - this.insertType(tip, tpj); - return tpj.run(fileContent); } @@ -87,8 +85,6 @@ public class TypeInsertSet { tpj.add(gip); } - - /** * Fügt alle Typen dieses TypeInsertSets in den übergebenen Quellcode ein * @param fileContent