package typinferenz; import java.util.Vector; import typinferenz.exceptions.DebugException; import typinferenz.exceptions.TypeinferenceException; import mycompiler.mytype.GenericTypeVar; 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 ∈ { < , getConstraintPairs(){ Vector ret = new Vector(); ret.add(constraintPair); return ret; } public void addConstraint(Pair toAdd){ if(constraintPair != null)throw new DebugException("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(); //Hier werden die GTVs zu TPH gewandelt. if(p1 instanceof RefType)((RefType)p1).GTV2TPH(); if(p2 instanceof RefType)((RefType)p2).GTV2TPH(); if((p1 instanceof GenericTypeVar))p1 = ((GenericTypeVar)p1).getTypePlaceHolder();//throw new DebugException("GenericTypeVar sind in den Constraints nicht erlaubt");// if((p2 instanceof GenericTypeVar))p2 = ((GenericTypeVar)p2).getTypePlaceHolder();//throw new DebugException("GenericTypeVar sind in den Constraints nicht erlaubt");// // 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 instanceof GenericTypeVar))p1 = new RefType(p1); if(!(p2 instanceof RefType) && !(p2 instanceof TypePlaceholder) && !(p2 instanceof GenericTypeVar))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(); } }