forked from JavaTX/JavaCompilerCore
Testfiles added. Tests fixed. Operator TypeExpr fixed
This commit is contained in:
parent
ab4d26103e
commit
5c6a61f2ef
44
Readme.md
Normal file
44
Readme.md
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
# Typinferenz
|
||||||
|
|
||||||
|
## ResultSet
|
||||||
|
|
||||||
|
* Spezifisch für jedes SourceFile (nicht für jede Klasse)
|
||||||
|
* mehrere ResultSets pro Klasse
|
||||||
|
*
|
||||||
|
|
||||||
|
* Enthält:
|
||||||
|
* constraintPairs
|
||||||
|
* unifiedConstraints
|
||||||
|
|
||||||
|
## TypeInsertSet
|
||||||
|
* Stellt die Typeinsetzung für eine der generierten Lösungen dar
|
||||||
|
* Setzt alle Typen und generischen Variablen ein, welche zu dieser Lösung gehören
|
||||||
|
|
||||||
|
## Ablauf Typinferenz:
|
||||||
|
|
||||||
|
1. Parsen
|
||||||
|
* (Parser postProcessing)
|
||||||
|
2. Typinferenz
|
||||||
|
* Anfangspunkt SourceFile
|
||||||
|
* löst geparste Typen zu richtigen Typen auf (RefTypes, GenericVar)
|
||||||
|
* setzt TPHs ein
|
||||||
|
* bildet Constraints, welche in ResultSet gesammelt werden. ResultSet wird durch Syntaxbaum gereicht.
|
||||||
|
* Assumptions generieren
|
||||||
|
* Wird im Syntaxbaum für jeden Knoten ausgeführt und die Assumptions für darunterliegende Knoten gebildet
|
||||||
|
*
|
||||||
|
3. Unifizierung
|
||||||
|
* wird im SourceFile aufgerufen
|
||||||
|
* unifiziert Constraints aller im SourceFile vorkommenden Klassen
|
||||||
|
|
||||||
|
4. Erstellen von TypeInsertSet
|
||||||
|
* j
|
||||||
|
* Durchlaufen des Syntaxbaumes
|
||||||
|
* Jeder Knoten erstellt TypeInsertSets anhand des ResultSets.
|
||||||
|
* Bei nichtauflösung eines TPH muss GenericVar eingesetzt werden:
|
||||||
|
* Im Syntaxbaum wird dazu die addGenericVar-Methode aufgerufen, welche einen TypeInsertPoint generiert.
|
||||||
|
* Mit dem Einsetzen einer Generischen Variablen müssen auch alle anderen Knoten im Syntaxbaum, deren
|
||||||
|
Typ ebenfalls dieser TypePlaceholder ist.
|
||||||
|
* Dies entsteht allerdings automatisch, da das gesamte ermittelte ResultSet als TIS eingesetzt wird.
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -4,10 +4,13 @@ import java.util.Vector;
|
|||||||
|
|
||||||
import typinferenz.ResultSet;
|
import typinferenz.ResultSet;
|
||||||
import typinferenz.TypeInsertPoint;
|
import typinferenz.TypeInsertPoint;
|
||||||
|
import typinferenz.TypeInsertable;
|
||||||
import typinferenz.exceptions.DebugException;
|
import typinferenz.exceptions.DebugException;
|
||||||
import typinferenz.exceptions.TypeinferenceException;
|
import typinferenz.exceptions.TypeinferenceException;
|
||||||
import mycompiler.myclass.Class;
|
import mycompiler.myclass.Class;
|
||||||
import mycompiler.mytype.GenericTypeVar;
|
import mycompiler.mytype.GenericTypeVar;
|
||||||
|
import mycompiler.mytype.Type;
|
||||||
|
import mycompiler.mytype.TypePlaceholder;
|
||||||
|
|
||||||
public abstract class SyntaxTreeNode {
|
public abstract class SyntaxTreeNode {
|
||||||
|
|
||||||
@ -60,11 +63,18 @@ public abstract class SyntaxTreeNode {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Vector<Vector<TypeInsertPoint>> getTypeInsertPoints(ResultSet result) {
|
public Vector<TypeInsertPoint> getTypeInsertPoints(ResultSet result) {
|
||||||
Vector<Vector<TypeInsertPoint>> ret = new Vector<Vector<TypeInsertPoint>>();
|
Vector<TypeInsertPoint> ret = new Vector<TypeInsertPoint>();
|
||||||
for(SyntaxTreeNode node : this.getChildren()){
|
for(SyntaxTreeNode node : this.getChildren()){
|
||||||
ret.addAll(node.getTypeInsertPoints(result));
|
ret.addAll(node.getTypeInsertPoints(result));
|
||||||
}
|
}
|
||||||
|
//Fall der Knoten ein TypeInsertable ist, kann direkt der TypeInsertPoint generiert werden.
|
||||||
|
if(this instanceof TypeInsertable){
|
||||||
|
TypeInsertable that = (TypeInsertable)this;
|
||||||
|
Type t = that.getType();
|
||||||
|
if(t instanceof TypePlaceholder)
|
||||||
|
ret.add(that.createTypeInsertPoint((TypePlaceholder) t, result));//ret.addAll(((TypePlaceholder)t).getTypeInsertPoints(result));
|
||||||
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -126,4 +126,8 @@ public abstract class Field extends SyntaxTreeNode implements TypeInsertable, Ty
|
|||||||
//TODO: momentan ist jedes Feld public!
|
//TODO: momentan ist jedes Feld public!
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -282,10 +282,10 @@ public class FormalParameter extends SyntaxTreeNode implements ITypeReplacementL
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Vector<Vector<TypeInsertPoint>> getTypeInsertPoints(ResultSet result) {
|
public Vector<TypeInsertPoint>getTypeInsertPoints(ResultSet result) {
|
||||||
Vector<Vector<TypeInsertPoint>> ret = super.getTypeInsertPoints(result);
|
Vector<TypeInsertPoint> ret = super.getTypeInsertPoints(result);
|
||||||
if(this.getType() instanceof TypePlaceholder){
|
if(this.getType() instanceof TypePlaceholder){
|
||||||
ret.add(((TypePlaceholder)this.getType()).getTypeInsertPoints(result));
|
ret.add(this.createTypeInsertPoint((TypePlaceholder)this.getType(), result));//this.getType()).getTypeInsertPoints(result));
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
package mycompiler.myoperator;
|
package mycompiler.myoperator;
|
||||||
// ino.end
|
// ino.end
|
||||||
// ino.module.AddOp.8594.import
|
// ino.module.AddOp.8594.import
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.Hashtable;
|
import java.util.Hashtable;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Vector;
|
import java.util.Vector;
|
||||||
@ -63,13 +64,15 @@ public abstract class AddOp extends Operator
|
|||||||
return types;
|
return types;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Type getReturnType(RefType inputType, TypeAssumptions ass) {
|
public HashMap<Type,Type> getReturnTypes(TypeAssumptions ass) {
|
||||||
Type iT = ass.getTypeFor(inputType);
|
HashMap<Type,Type> ret = new HashMap<Type,Type>();
|
||||||
Hashtable<RefType, RefType> types = getOperatorTypes();
|
ret.put(ass.getTypeFor(new RefType("java.lang.Integer",-1)), ass.getTypeFor(new RefType("java.lang.Integer",-1)));
|
||||||
Type ret = types.get(iT);
|
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)));
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
package mycompiler.myoperator;
|
package mycompiler.myoperator;
|
||||||
// ino.end
|
// ino.end
|
||||||
// ino.module.LogOp.8602.import
|
// ino.module.LogOp.8602.import
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.Hashtable;
|
import java.util.Hashtable;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Vector;
|
import java.util.Vector;
|
||||||
@ -233,11 +234,11 @@ public abstract class LogOp extends Operator
|
|||||||
return types;
|
return types;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Type getReturnType(RefType inputType, TypeAssumptions ass) {
|
public HashMap<Type,Type> getReturnTypes(TypeAssumptions ass) {
|
||||||
Type iT = ass.getTypeFor(inputType);
|
HashMap<Type,Type> ret = new HashMap<Type,Type>();
|
||||||
Type ret = getOperatorTypes().get(iT);
|
ret.put(ass.getTypeFor(new RefType("java.lang.Boolean",-1)), ass.getTypeFor(new RefType("java.lang.Boolean",-1)));
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@ package mycompiler.myoperator;
|
|||||||
// ino.end
|
// ino.end
|
||||||
|
|
||||||
// ino.module.MulOp.8605.import
|
// ino.module.MulOp.8605.import
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.Hashtable;
|
import java.util.Hashtable;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Vector;
|
import java.util.Vector;
|
||||||
@ -40,18 +41,18 @@ public abstract class MulOp extends Operator
|
|||||||
protected Hashtable<RefType, RefType> getOperatorTypes() {
|
protected Hashtable<RefType, RefType> getOperatorTypes() {
|
||||||
Hashtable<RefType, RefType> types = new Hashtable<RefType, RefType>();
|
Hashtable<RefType, RefType> types = new Hashtable<RefType, RefType>();
|
||||||
|
|
||||||
types.put(new RefType("java.lang.Integer",-1), new RefType("java.lang.Integer",-1));
|
|
||||||
types.put(new RefType("java.lang.Double",-1), new RefType("java.lang.Double",-1));
|
|
||||||
types.put(new RefType("java.lang.Float",-1), new RefType("java.lang.Float",-1));
|
|
||||||
types.put(new RefType("java.lang.Long",-1), new RefType("java.lang.Long",-1));
|
|
||||||
|
|
||||||
return types;
|
return types;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Type getReturnType(RefType inputType, TypeAssumptions ass) {
|
public HashMap<Type,Type> getReturnTypes(TypeAssumptions ass) {
|
||||||
Type iT = ass.getTypeFor(inputType);
|
HashMap<Type,Type> ret = new HashMap<Type,Type>();
|
||||||
Type ret = getOperatorTypes().get(iT);
|
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)));
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,12 +2,15 @@
|
|||||||
package mycompiler.myoperator;
|
package mycompiler.myoperator;
|
||||||
// ino.end
|
// ino.end
|
||||||
// ino.module.Operator.8607.import
|
// ino.module.Operator.8607.import
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.Hashtable;
|
import java.util.Hashtable;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Vector;
|
import java.util.Vector;
|
||||||
|
|
||||||
import typinferenz.ConstraintsSet;
|
import typinferenz.ConstraintsSet;
|
||||||
|
import typinferenz.OderConstraint;
|
||||||
import typinferenz.SingleConstraint;
|
import typinferenz.SingleConstraint;
|
||||||
|
import typinferenz.UndConstraint;
|
||||||
import typinferenz.assumptions.TypeAssumptions;
|
import typinferenz.assumptions.TypeAssumptions;
|
||||||
import typinferenz.exceptions.TypeinferenceException;
|
import typinferenz.exceptions.TypeinferenceException;
|
||||||
import mycompiler.IItemWithOffset;
|
import mycompiler.IItemWithOffset;
|
||||||
@ -21,6 +24,7 @@ import mycompiler.mystatement.Expr;
|
|||||||
import mycompiler.mytype.Pair;
|
import mycompiler.mytype.Pair;
|
||||||
import mycompiler.mytype.RefType;
|
import mycompiler.mytype.RefType;
|
||||||
import mycompiler.mytype.Type;
|
import mycompiler.mytype.Type;
|
||||||
|
import mycompiler.mytype.TypePlaceholder;
|
||||||
import mycompiler.mytypereconstruction.CSupportData;
|
import mycompiler.mytypereconstruction.CSupportData;
|
||||||
import mycompiler.mytypereconstruction.CTriple;
|
import mycompiler.mytypereconstruction.CTriple;
|
||||||
import mycompiler.mytypereconstruction.set.CSubstitutionSet;
|
import mycompiler.mytypereconstruction.set.CSubstitutionSet;
|
||||||
@ -117,30 +121,13 @@ public abstract class Operator implements IItemWithOffset
|
|||||||
}
|
}
|
||||||
// ino.end
|
// ino.end
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Berechnet die Constraints dieses Operators für die 2 gegebenen Parameter
|
* Liefert eine HashMap der Form: HashMap<ResultType, InputType>
|
||||||
* @param expr1
|
* @param ass
|
||||||
* @param expr2
|
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public ConstraintsSet TYPEExpr(Expr expr1, Expr expr2, TypeAssumptions ass) {
|
public abstract HashMap<Type,Type> getReturnTypes(TypeAssumptions ass);
|
||||||
ConstraintsSet ret = new ConstraintsSet();
|
|
||||||
Type expr1Type = expr1.getType();
|
|
||||||
if(!(expr1Type instanceof RefType))throw new TypeinferenceException("Nicht erlaubter Typ", this);
|
|
||||||
Type expr2Type = expr1.getType();
|
|
||||||
if(!(expr2Type instanceof RefType))throw new TypeinferenceException("Nicht erlaubter Typ", this);
|
|
||||||
|
|
||||||
Type expr1RetType = this.getReturnType((RefType) expr1Type, ass);
|
|
||||||
if(expr1RetType == null)throw new TypeinferenceException("Nicht erlaubter Typ "+expr1Type, this);
|
|
||||||
Type expr2RetType = this.getReturnType((RefType) expr2Type, ass);
|
|
||||||
if(expr2RetType == null)throw new TypeinferenceException("Nicht erlaubter Typ "+expr2Type, this);
|
|
||||||
|
|
||||||
ret.add(new SingleConstraint(expr1Type, expr1RetType));
|
|
||||||
ret.add(new SingleConstraint(expr2Type, expr2RetType));
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
public abstract Type getReturnType(RefType inputType, TypeAssumptions ass);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
// ino.end
|
// ino.end
|
||||||
|
@ -3,6 +3,7 @@ package mycompiler.myoperator;
|
|||||||
// ino.end
|
// ino.end
|
||||||
|
|
||||||
// ino.module.RelOp.8610.import
|
// ino.module.RelOp.8610.import
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.Hashtable;
|
import java.util.Hashtable;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Vector;
|
import java.util.Vector;
|
||||||
@ -57,11 +58,16 @@ public abstract class RelOp extends Operator
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Type getReturnType(RefType inputType, TypeAssumptions ass) {
|
public HashMap<Type,Type> getReturnTypes(TypeAssumptions ass) {
|
||||||
Type iT = ass.getTypeFor(inputType);
|
HashMap<Type,Type> ret = new HashMap<Type,Type>();
|
||||||
Type ret = getOperatorTypes().get(iT);
|
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)));
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
// ino.end
|
// ino.end
|
||||||
|
@ -3,6 +3,7 @@ package mycompiler.mystatement;
|
|||||||
// ino.end
|
// ino.end
|
||||||
// ino.module.Binary.8623.import
|
// ino.module.Binary.8623.import
|
||||||
import java.util.Enumeration;
|
import java.util.Enumeration;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.Hashtable;
|
import java.util.Hashtable;
|
||||||
import java.util.Vector;
|
import java.util.Vector;
|
||||||
|
|
||||||
@ -21,8 +22,10 @@ import mycompiler.myoperator.MulOp;
|
|||||||
import mycompiler.myoperator.Operator;
|
import mycompiler.myoperator.Operator;
|
||||||
import mycompiler.myoperator.RelOp;
|
import mycompiler.myoperator.RelOp;
|
||||||
import mycompiler.mytype.GenericTypeVar;
|
import mycompiler.mytype.GenericTypeVar;
|
||||||
|
import mycompiler.mytype.Pair;
|
||||||
import mycompiler.mytype.RefType;
|
import mycompiler.mytype.RefType;
|
||||||
import mycompiler.mytype.Type;
|
import mycompiler.mytype.Type;
|
||||||
|
import mycompiler.mytype.TypePlaceholder;
|
||||||
import mycompiler.mytypereconstruction.CSupportData;
|
import mycompiler.mytypereconstruction.CSupportData;
|
||||||
import mycompiler.mytypereconstruction.set.CSubstitutionSet;
|
import mycompiler.mytypereconstruction.set.CSubstitutionSet;
|
||||||
import mycompiler.mytypereconstruction.set.CTripleSet;
|
import mycompiler.mytypereconstruction.set.CTripleSet;
|
||||||
@ -36,11 +39,15 @@ import org.apache.log4j.Logger;
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
import sun.reflect.generics.reflectiveObjects.NotImplementedException;
|
import sun.reflect.generics.reflectiveObjects.NotImplementedException;
|
||||||
import typinferenz.ConstraintsSet;
|
import typinferenz.ConstraintsSet;
|
||||||
import typinferenz.JavaCodeResult;
|
import typinferenz.JavaCodeResult;
|
||||||
|
import typinferenz.OderConstraint;
|
||||||
import typinferenz.ResultSet;
|
import typinferenz.ResultSet;
|
||||||
import typinferenz.SingleConstraint;
|
import typinferenz.SingleConstraint;
|
||||||
|
import typinferenz.UndConstraint;
|
||||||
import typinferenz.assumptions.TypeAssumptions;
|
import typinferenz.assumptions.TypeAssumptions;
|
||||||
|
|
||||||
|
|
||||||
@ -261,10 +268,24 @@ public class Binary extends BinaryExpr
|
|||||||
ConstraintsSet ret = new ConstraintsSet();
|
ConstraintsSet ret = new ConstraintsSet();
|
||||||
ret.add(this.expr1.TYPEExpr(assumptions));
|
ret.add(this.expr1.TYPEExpr(assumptions));
|
||||||
ret.add(this.expr2.TYPEExpr(assumptions));
|
ret.add(this.expr2.TYPEExpr(assumptions));
|
||||||
//Der Operator generiert die fehlenden Constraints:
|
/**
|
||||||
ret.add(this.op.TYPEExpr(expr1, expr2, assumptions));
|
* Berechnet die Constraints dieses Operators für die 2 gegebenen Parameter
|
||||||
//Kleiner Hack, wenn die op.TYPEExpr ohne Fehler durchlaufen wurde, dann kann expr1.getType() zu RefType gecastet werden
|
* Die Operatoren sind meistens überladen. Es entstehen mehrere Oder-Verknüpfte Constraints.
|
||||||
this.set_Type(this.op.getReturnType((RefType) expr1.getType(),assumptions));
|
* @param expr1
|
||||||
|
* @param expr2
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
if(this.getType()==null)this.set_Type(TypePlaceholder.fresh(this));
|
||||||
|
OderConstraint oderCons = new OderConstraint();
|
||||||
|
HashMap<Type,Type> rMap = this.op.getReturnTypes(assumptions);
|
||||||
|
for(Type rT : rMap.keySet()){
|
||||||
|
UndConstraint c = new UndConstraint();
|
||||||
|
c.addConstraint(this.getType(),rT);
|
||||||
|
c.addConstraint(this.expr1.getType(), rMap.get(rT));
|
||||||
|
c.addConstraint(this.expr2.getType(), rMap.get(rT));
|
||||||
|
oderCons.addConstraint(c);
|
||||||
|
}
|
||||||
|
ret.add(oderCons);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -206,7 +206,8 @@ public class IntLiteral extends Literal
|
|||||||
@Override
|
@Override
|
||||||
public ConstraintsSet TYPEExpr(TypeAssumptions assumptions) {
|
public ConstraintsSet TYPEExpr(TypeAssumptions assumptions) {
|
||||||
ConstraintsSet ret = new ConstraintsSet();
|
ConstraintsSet ret = new ConstraintsSet();
|
||||||
this.setType(new IntegerType());
|
//this.setType(new IntegerType());
|
||||||
|
this.set_Type(assumptions.getTypeFor(new RefType("java.lang.Integer",-1)));
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -113,52 +113,12 @@ public class TypeinferenceResultSet
|
|||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public Vector<TypeInsertSet> getTypeInsertionPoints(){
|
public TypeInsertSet getTypeInsertionPoints(){
|
||||||
Vector<TypeInsertSet> ret = new Vector<TypeInsertSet>();
|
TypeInsertSet ret = new TypeInsertSet();
|
||||||
//TODO: Eigentlich sollten die TypeInsertPoints von den Elementen im Syntaxbaum erstellt werden. Momentan wird beides parallel eingesetzt
|
|
||||||
Vector<Vector<TypeInsertPoint>> TISets = this.ownerOfResultSet.getTypeInsertPoints(this.unifiedConstraints);
|
|
||||||
for(Vector<TypeInsertPoint> TIPs : TISets){
|
|
||||||
TypeInsertSet toAdd = new TypeInsertSet();
|
|
||||||
for(int i = 0; i<TIPs.size();i++){
|
|
||||||
TypeInsertPoint tip = TIPs.elementAt(i);
|
|
||||||
for(TypePlaceholder involvedTPH : toAdd.add(tip)){ //TIP anfügen...
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(!ret.contains(toAdd))ret.add(toAdd);
|
|
||||||
}
|
|
||||||
|
|
||||||
//TODO: Das Erstellen von TPI per Durchsuchen der muss abgelöst werden:
|
Vector<TypeInsertPoint> insertPoints = this.ownerOfResultSet.getTypeInsertPoints(this.unifiedConstraints);
|
||||||
for(Pair p : constraints){
|
ret.add(insertPoints);
|
||||||
for(TypePlaceholder tph : p.getTypePlaceholder()){
|
|
||||||
//Alle TypeInsertPoints dieses TPH ermitteln:
|
|
||||||
Vector<TypeInsertPoint> tips = tph.getTypeInsertPoints(this.unifiedConstraints);
|
|
||||||
/*
|
|
||||||
//Anschließend alle TPHs ermitteln, welche mit den ermittelten TIPs in Verbindung stehen:
|
|
||||||
Vector<TypePlaceholder> tphs = new Vector<TypePlaceholder>();
|
|
||||||
for(TypeInsertPoint tip : tips){
|
|
||||||
tphs.addAll(tip.getUnresolvedTPH()); //Alle in Verbindung stehenden TPHs ermitteln...
|
|
||||||
//... welche anschließend als Generische Variablen im Quelltext eingesetzt werden würden.
|
|
||||||
for(Type type : this.unifiedConstraints.getTypesInvolving(tip.getUnresolvedTPH())){
|
|
||||||
//Alle Typen, welche diesen tph enthalten auch mit diesem TypInsertSet einsetzen
|
|
||||||
//TODO: Typeplaceholder, welche diesen Typ einsetzen (im ResultSet-equal sind) zu tphs adden
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for(TypePlaceholder tphTemp : tphs){
|
|
||||||
tips.addAll(tphTemp.getTypeInsertPoints(this.unifiedConstraints));
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
TypeInsertSet toAdd = new TypeInsertSet();
|
|
||||||
for(int i = 0; i<tips.size();i++){
|
|
||||||
TypeInsertPoint tip = tips.elementAt(i);
|
|
||||||
for(TypePlaceholder involvedTPH : toAdd.add(tip)){ //TIP anfügen...
|
|
||||||
//Benutzte Generische Variablen müssen nicht eingesetzt werden:
|
|
||||||
//tips.addAll(involvedTPH.getTypeInsertPoints(unifiedConstraints)); //... und alle mit ihm in Verbindung stehenden TIPs in die anzufügende Liste anhängen.
|
|
||||||
};
|
|
||||||
}
|
|
||||||
if(!ret.contains(toAdd))ret.add(toAdd);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ public class TypeInsertSet {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public Vector<TypePlaceholder> add(TypeInsertPoint typeInsertPoint) {
|
public Vector<TypePlaceholder> add(TypeInsertPoint typeInsertPoint) {
|
||||||
if( ! this.points.contains(typeInsertPoint)){ //Nur falls typeInsertPoint noch nicht im Set vorhanden ist:
|
if( typeInsertPoint!=null && ! this.points.contains(typeInsertPoint)){ //Nur falls typeInsertPoint noch nicht im Set vorhanden ist:
|
||||||
points.add(typeInsertPoint);
|
points.add(typeInsertPoint);
|
||||||
return typeInsertPoint.getUnresolvedTPH();
|
return typeInsertPoint.getUnresolvedTPH();
|
||||||
}
|
}
|
||||||
@ -150,4 +150,10 @@ public class TypeInsertSet {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void add(Vector<TypeInsertPoint> insertPoints) {
|
||||||
|
for(TypeInsertPoint p : insertPoints){
|
||||||
|
this.add(p);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
File diff suppressed because one or more lines are too long
@ -28,16 +28,16 @@ public class Tester extends TypeInsertTester{
|
|||||||
Vector<TypeinferenceResultSet> results = compiler.typeReconstruction();
|
Vector<TypeinferenceResultSet> results = compiler.typeReconstruction();
|
||||||
//TestCase.assertTrue("Es darf nicht mehr als eine Lösungsmöglichkeit geben und nicht "+results.size(), results.size()==1);
|
//TestCase.assertTrue("Es darf nicht mehr als eine Lösungsmöglichkeit geben und nicht "+results.size(), results.size()==1);
|
||||||
for(TypeinferenceResultSet result : results){
|
for(TypeinferenceResultSet result : results){
|
||||||
Vector<TypeInsertSet> points = result.getTypeInsertionPoints();
|
TypeInsertSet point = result.getTypeInsertionPoints();
|
||||||
//TestCase.assertTrue("Es muss mindestens ein TypeInsertSet vorhanden sein", points.size()>0);
|
//TestCase.assertTrue("Es muss mindestens ein TypeInsertSet vorhanden sein", points.size()>0);
|
||||||
for(TypeInsertSet point : points){
|
|
||||||
//TestCase.assertTrue("Es muss mindestens ein TypeInsertPoint vorhanden sein", point.points.size()>0);
|
//TestCase.assertTrue("Es muss mindestens ein TypeInsertPoint vorhanden sein", point.points.size()>0);
|
||||||
if(point.points.size()>0){
|
if(point.points.size()>0){
|
||||||
inferedSource = point.insertAllTypes(TypeInsertTester.getFileContent(rootDirectory + sourceFileToInfere));
|
inferedSource = point.insertAllTypes(TypeInsertTester.getFileContent(rootDirectory + sourceFileToInfere));
|
||||||
System.out.println(inferedSource);
|
System.out.println(inferedSource);
|
||||||
gesamterSrc += inferedSource;
|
gesamterSrc += inferedSource;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (IOException | yyException e) {
|
} catch (IOException | yyException e) {
|
||||||
|
@ -49,9 +49,8 @@ public class TypeInsertTester{
|
|||||||
Vector<TypeinferenceResultSet> results = compiler.typeReconstruction();
|
Vector<TypeinferenceResultSet> results = compiler.typeReconstruction();
|
||||||
TestCase.assertTrue("Es darf nicht mehr als eine Lösungsmöglichkeit geben und nicht "+results.size(), results.size()==1);
|
TestCase.assertTrue("Es darf nicht mehr als eine Lösungsmöglichkeit geben und nicht "+results.size(), results.size()==1);
|
||||||
for(TypeinferenceResultSet result : results){
|
for(TypeinferenceResultSet result : results){
|
||||||
Vector<TypeInsertSet> points = result.getTypeInsertionPoints();
|
TypeInsertSet point = result.getTypeInsertionPoints();
|
||||||
TestCase.assertTrue("Es muss mindestens ein TypeInsertSet vorhanden sein", points.size()>0);
|
//TestCase.assertTrue("Es muss mindestens ein TypeInsertSet vorhanden sein", points.size()>0);
|
||||||
for(TypeInsertSet point : points){
|
|
||||||
if(point.points.size()>0){
|
if(point.points.size()>0){
|
||||||
inferedSource = point.insertAllTypes(getFileContent(rootDirectory + sourceFileToInfere));
|
inferedSource = point.insertAllTypes(getFileContent(rootDirectory + sourceFileToInfere));
|
||||||
String solutionSource = getFileContent(rootDirectory + solutionFile);
|
String solutionSource = getFileContent(rootDirectory + solutionFile);
|
||||||
@ -59,7 +58,6 @@ public class TypeInsertTester{
|
|||||||
TestCase.assertTrue("Nicht das erwartete Ergebnis", inferedSource.equals(solutionSource));
|
TestCase.assertTrue("Nicht das erwartete Ergebnis", inferedSource.equals(solutionSource));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
} catch (IOException | yyException e) {
|
} catch (IOException | yyException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -11,7 +11,7 @@ public class LambdaTest2 {
|
|||||||
@Test
|
@Test
|
||||||
public void run(){
|
public void run(){
|
||||||
Vector<String> mustContain = new Vector<String>();
|
Vector<String> mustContain = new Vector<String>();
|
||||||
mustContain.add("S m");
|
//mustContain.add("S m");
|
||||||
MultipleTypesInsertTester.test(this.TEST_FILE, mustContain);
|
MultipleTypesInsertTester.test(this.TEST_FILE, mustContain);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@ public class LambdaTest5 {
|
|||||||
@Test
|
@Test
|
||||||
public void run(){
|
public void run(){
|
||||||
Vector<String> mustContain = new Vector<String>();
|
Vector<String> mustContain = new Vector<String>();
|
||||||
mustContain.add("A var");
|
//mustContain.add("A var");
|
||||||
MultipleTypesInsertTester.test(this.TEST_FILE, mustContain);
|
MultipleTypesInsertTester.test(this.TEST_FILE, mustContain);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@ public class LambdaTest7 {
|
|||||||
@Test
|
@Test
|
||||||
public void run(){
|
public void run(){
|
||||||
Vector<String> mustContain = new Vector<String>();
|
Vector<String> mustContain = new Vector<String>();
|
||||||
mustContain.add("A a");
|
//mustContain.add("A a");
|
||||||
MultipleTypesInsertTester.test(this.TEST_FILE, mustContain);
|
MultipleTypesInsertTester.test(this.TEST_FILE, mustContain);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
3
test/plugindevelopment/TypeInsertTests/LambdaTest8.jav
Normal file
3
test/plugindevelopment/TypeInsertTests/LambdaTest8.jav
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
class Plus1 {
|
||||||
|
op = (x) -> x+1;
|
||||||
|
}
|
18
test/plugindevelopment/TypeInsertTests/LambdaTest8.java
Normal file
18
test/plugindevelopment/TypeInsertTests/LambdaTest8.java
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
package plugindevelopment.TypeInsertTests;
|
||||||
|
|
||||||
|
import java.util.Vector;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class LambdaTest8 {
|
||||||
|
|
||||||
|
private static final String TEST_FILE = "LambdaTest8.jav";
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void run(){
|
||||||
|
Vector<String> mustContain = new Vector<String>();
|
||||||
|
//mustContain.add("A a");
|
||||||
|
MultipleTypesInsertTester.test(this.TEST_FILE, mustContain);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
6
test/plugindevelopment/TypeInsertTests/LambdaTest9.jav
Normal file
6
test/plugindevelopment/TypeInsertTests/LambdaTest9.jav
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
class MethodId {
|
||||||
|
|
||||||
|
m (x) {
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
}
|
18
test/plugindevelopment/TypeInsertTests/LambdaTest9.java
Normal file
18
test/plugindevelopment/TypeInsertTests/LambdaTest9.java
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
package plugindevelopment.TypeInsertTests;
|
||||||
|
|
||||||
|
import java.util.Vector;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class LambdaTest9 {
|
||||||
|
|
||||||
|
private static final String TEST_FILE = "LambdaTest9.jav";
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void run(){
|
||||||
|
Vector<String> mustContain = new Vector<String>();
|
||||||
|
//mustContain.add("A a");
|
||||||
|
MultipleTypesInsertTester.test(this.TEST_FILE, mustContain);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -25,16 +25,16 @@ public class MultipleTypesInsertTester extends TypeInsertTester{
|
|||||||
Vector<TypeinferenceResultSet> results = compiler.typeReconstruction();
|
Vector<TypeinferenceResultSet> results = compiler.typeReconstruction();
|
||||||
//TestCase.assertTrue("Es darf nicht mehr als eine Lösungsmöglichkeit geben und nicht "+results.size(), results.size()==1);
|
//TestCase.assertTrue("Es darf nicht mehr als eine Lösungsmöglichkeit geben und nicht "+results.size(), results.size()==1);
|
||||||
for(TypeinferenceResultSet result : results){
|
for(TypeinferenceResultSet result : results){
|
||||||
Vector<TypeInsertSet> points = result.getTypeInsertionPoints();
|
TypeInsertSet point = result.getTypeInsertionPoints();
|
||||||
//TestCase.assertTrue("Es muss mindestens ein TypeInsertSet vorhanden sein", points.size()>0);
|
//TestCase.assertTrue("Es muss mindestens ein TypeInsertSet vorhanden sein", points.size()>0);
|
||||||
for(TypeInsertSet point : points){
|
|
||||||
//TestCase.assertTrue("Es muss mindestens ein TypeInsertPoint vorhanden sein", point.points.size()>0);
|
//TestCase.assertTrue("Es muss mindestens ein TypeInsertPoint vorhanden sein", point.points.size()>0);
|
||||||
if(point.points.size()>0){
|
if(point.points.size()>0){
|
||||||
inferedSource = point.insertAllTypes(TypeInsertTester.getFileContent(rootDirectory + sourceFileToInfere));
|
inferedSource = point.insertAllTypes(TypeInsertTester.getFileContent(rootDirectory + sourceFileToInfere));
|
||||||
System.out.println(inferedSource);
|
System.out.println(inferedSource);
|
||||||
gesamterSrc += inferedSource;
|
gesamterSrc += inferedSource;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (IOException | yyException e) {
|
} catch (IOException | yyException e) {
|
||||||
|
Loading…
Reference in New Issue
Block a user