forked from JavaTX/JavaCompilerCore
Merge branch 'master' of ssh://gohorb.ba-horb.de/bahome/projekt/git/JavaCompilerCore
This commit is contained in:
commit
67b6d29ce8
@ -40,6 +40,17 @@ Die einzusetzenden Generischen Variablen werden erst beim Einsetzen eines Typs g
|
||||
* 5. Alle Unbekannten TPHs herausfiltern (von den Pairs nur TA2)
|
||||
* 6. Alle unbekannten TPHs + Pairs als GenericTypeInsertPoint deklarieren.
|
||||
|
||||
## Lambda Ausdrücke und FunN
|
||||
### Erstellen der Typconstraints für einen Lambda Ausdruck
|
||||
* Return-Type des Lambda Ausdrucks: retT
|
||||
* Parameter Typen: pT1 ... pTN
|
||||
* Für jeden Typ einen TPH generieren
|
||||
* für Return Typ: TPH R
|
||||
* für Parameter Typen: TPH P1 ... TPH PN
|
||||
* Es gilt:
|
||||
* TPH R < retT
|
||||
* pTN < TPH PN
|
||||
|
||||
## Ablauf Typinferenz:
|
||||
|
||||
1. Parsen
|
||||
|
@ -22,9 +22,11 @@ import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.SuperWildcardType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.Type;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
import de.dhbwstuttgart.syntaxtree.type.WildcardType;
|
||||
import de.dhbwstuttgart.typeinference.ConstraintsSet;
|
||||
import de.dhbwstuttgart.typeinference.FunN;
|
||||
import de.dhbwstuttgart.typeinference.JavaCodeResult;
|
||||
import de.dhbwstuttgart.typeinference.OderConstraint;
|
||||
import de.dhbwstuttgart.typeinference.ResultSet;
|
||||
import de.dhbwstuttgart.typeinference.SingleConstraint;
|
||||
import de.dhbwstuttgart.typeinference.Typeable;
|
||||
@ -152,27 +154,40 @@ public class LambdaExpression extends Expr{
|
||||
//ArgumentAssumptions + assumptions ergeben die Assumptions für die Statements innerhalb des Lambda-Bodys:
|
||||
ret.add(method_body.TYPEStmt(ArgumentAssumptions.add(assumptions))); //Es gibt die LambdaExpression nur mit einem Block als Method Body, nicht mit einer einzelnen Expression
|
||||
|
||||
//TODO: OderConstraint erstellen mit normalem Typ und ? extemds/super Type
|
||||
//Die Typen innerhalb von FunN anpassen:
|
||||
Vector<Type> superParamTypes = new Vector<>();
|
||||
//Die Constraints für ParameterTypen und Ret Typ erstellen:
|
||||
Vector<Type> tphParamTypes = new Vector<>();
|
||||
for(Type pT : paramTypes){
|
||||
if(pT instanceof ObjectType){
|
||||
superParamTypes.add(new SuperWildcardType(pT.getOffset(), (ObjectType) pT));
|
||||
}else{ //pT ist weder Void noch ein ObjectType (TPH, GTV, RefType)
|
||||
superParamTypes.add(pT);
|
||||
TypePlaceholder tph = TypePlaceholder.fresh(this);
|
||||
tphParamTypes.add(tph);
|
||||
// PN < TPH PN
|
||||
if(pT instanceof WildcardType){
|
||||
ret.add(new SingleConstraint(tph.TYPE(assumptions, this), pT.TYPE(assumptions, this)));
|
||||
}else{
|
||||
OderConstraint orCons = new OderConstraint();
|
||||
SuperWildcardType superpT = new SuperWildcardType(pT.getOffset(), (ObjectType) pT);
|
||||
SingleConstraint cons1 = new SingleConstraint(tph.TYPE(assumptions, this), superpT.TYPE(assumptions, this));
|
||||
SingleConstraint cons2 = new SingleConstraint(tph.TYPE(assumptions, this), pT.TYPE(assumptions, this));
|
||||
orCons.addConstraint(cons1);
|
||||
orCons.addConstraint(cons2);
|
||||
ret.add(orCons);
|
||||
}
|
||||
}
|
||||
Type retType = method_body.getType();
|
||||
Type extRetType = retType;
|
||||
if(!(retType instanceof de.dhbwstuttgart.syntaxtree.type.Void)){
|
||||
if(retType instanceof ObjectType){
|
||||
extRetType = new ExtendsWildcardType(retType.getOffset(), (ObjectType) retType);
|
||||
}else{ //retType ist weder Void noch ein ObjectType (TPH, GTV, RefType)
|
||||
extRetType = retType;
|
||||
}
|
||||
Type tphRetType = TypePlaceholder.fresh(this);
|
||||
// PN < TPH PN
|
||||
if(retType instanceof WildcardType){
|
||||
ret.add(new SingleConstraint(retType.TYPE(assumptions, this), tphRetType.TYPE(assumptions, this)));
|
||||
}else{
|
||||
OderConstraint orCons = new OderConstraint();
|
||||
SuperWildcardType superretType = new SuperWildcardType(retType.getOffset(), (ObjectType) retType);
|
||||
SingleConstraint cons1 = new SingleConstraint(tphRetType.TYPE(assumptions, this), superretType.TYPE(assumptions, this));
|
||||
SingleConstraint cons2 = new SingleConstraint(tphRetType.TYPE(assumptions, this), retType.TYPE(assumptions, this));
|
||||
orCons.addConstraint(cons1);
|
||||
orCons.addConstraint(cons2);
|
||||
ret.add(orCons);
|
||||
}
|
||||
|
||||
ret.add(new SingleConstraint(new FunN(extRetType, superParamTypes).TYPE(assumptions, this),this.getType().TYPE(assumptions, this)));
|
||||
ret.add(new SingleConstraint(new FunN(tphRetType, tphParamTypes).TYPE(assumptions, this),this.getType().TYPE(assumptions, this)));
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
class BoundedGenericTest<A extends String>{
|
||||
class BoundedGenericTest{
|
||||
var = "test";
|
||||
<B extends A> B methode(){
|
||||
methode(){
|
||||
return var;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user