package typinferenz; import java.util.Iterator; import java.util.Vector; import mycompiler.mytype.Pair; import mycompiler.mytype.Type; /** * Im Grunde Sammlung von Pair s mit Equal-Operatoren. * * @author Andreas Stadelmeier, a10023 * */ public class ResultSet implements Iterable { Vector resultPairs; public ResultSet(Vector resultSet){ resultPairs = resultSet; } public Vector getResultSet(){ return resultPairs; } /** * Löst den übergebenen Typ auf. Rückgabetyp ist ein Reftype oder Void * @param type * @return */ public Type getTypeEqualTo(Type type) { Type res = type; Vector modifiedResultPairs = (Vector) resultPairs.clone(); int i = findPairWithTypeEqualTo(type, modifiedResultPairs); while(i != -1){ res = modifiedResultPairs.get(i).TA2; modifiedResultPairs.remove(i); i = findPairWithTypeEqualTo(res, modifiedResultPairs); } return res; } private int findPairWithTypeEqualTo(Type type, Vector inResultPairs){ for(int i = 0; i iterator() { return this.getResultSet().iterator(); } /** * Durchsucht das ResultSet (die unifizierten Constraints des ResultSets) nach diesem Typ. Der Typ wird nicht aufgelöst. * Es spielt keine Rolle in welchem Kontext der Typ im ResultSet auftaucht. * @param tA1 * @return true, falls der gesuchte Typ enthalten ist. */ public boolean contains(Type tA1) { for(Pair p : this){ if(p.TA1.equals(tA1)||p.TA2.equals(tA1))return true; } return false; } @Override public String toString(){ return this.getResultSet().toString(); } @Override public boolean equals(Object obj){ return true; } }