2013-10-18 11:33:46 +00:00
package typinferenz ;
import java.util.Vector ;
2014-03-18 19:18:57 +00:00
import typinferenz.exceptions.TypinferenzException ;
2013-10-18 11:33:46 +00:00
import mycompiler.mytype.Pair ;
import mycompiler.mytype.RefType ;
import mycompiler.mytype.Type ;
import mycompiler.mytype.TypePlaceholder ;
import mycompiler.mytypereconstruction.CTriple ;
import mycompiler.mytypereconstruction.set.CTripleSet ;
/ * *
* Beschreibung von Herrn Plümicke :
* " The set of constraints consists of constraints of the form θ R θ' , where θ and
* θ ' are Java types and R ( R ∈ { < , < ? , = } ) is a subtyping condition . "
*
* @author AI10023 - Andreas Stadelmeier
*
* Die Klasse stellt ein OderConstraint - Set dar , welches nur aus einem Constraint besteht .
*
* /
public class SingleConstraint extends UndConstraint {
private Pair constraintPair ; //entspricht θ condition θ'
//private R condition; //entspricht der condition (R)
public SingleConstraint ( Type p1 , Type p2 ) {
//super(p1,p2);
Pair constraintPair = new Pair ( p1 , p2 ) ; //super.getConstraintPairs().firstElement();
this . addConstraint ( constraintPair ) ;
}
public Pair getPair ( ) {
return constraintPair ;
}
@Override //Methode überschreiben, damit immer nur ein Vector mit nur einem Element zurückgeliefert wird.
public Vector < Pair > getConstraintPairs ( ) {
Vector < Pair > ret = new Vector < Pair > ( ) ;
ret . add ( constraintPair ) ;
return ret ;
}
public void addConstraint ( Pair toAdd ) {
if ( constraintPair ! = null ) throw new TypinferenzException ( " Ein Constraint darf nur aus einem ConstraintPair bestehen. Das hinzufügen von " + toAdd + " ist nicht möglich. " ) ;
Type p1 = toAdd . TA1 ;
Type p2 = toAdd . TA2 ;
if ( p1 = = null | | p2 = = null ) throw new NullPointerException ( ) ;
// BaseTypes werden in RefTypes umgewandelt. Constraints dürfen nur RefTypes oder TypePlaceholder enthalten, da sonst der Unify-Algorithmus nicht funktioniert.
if ( ! ( p1 instanceof RefType ) & & ! ( p1 instanceof TypePlaceholder ) ) p1 = new RefType ( p1 ) ;
if ( ! ( p2 instanceof RefType ) & & ! ( p2 instanceof TypePlaceholder ) ) p2 = new RefType ( p2 ) ;
//if(!(TypePlaceholder.class.isInstance(p1)) || !(RefType.class.isInstance(p1)) || !(TypePlaceholder.class.isInstance(p2)) || !(RefType.class.isInstance(p2)))
//{//Wenn die beiden übergebenen Typen weder RefTypes noch TypePlaceholder sind:
// throw new TypinferenzException("Ein Constraint darf nur aus TypePlaceholdern und Reftypes bestehen");
//}
constraintPair = new Pair ( p1 , p2 ) ;
}
@Override
public String toString ( ) {
return " " + constraintPair . TA1 . toString ( ) + " < " + constraintPair . TA2 . toString ( ) ;
}
}