01: // This file is part of KeY - Integrated Deductive Software Design
02: // Copyright (C) 2001-2007 Universitaet Karlsruhe, Germany
03: // Universitaet Koblenz-Landau, Germany
04: // Chalmers University of Technology, Sweden
05: //
06: // The KeY system is protected by the GNU General Public License.
07: // See LICENSE.TXT for details.
08: //
09: //
10:
11: package de.uka.ilkd.key.logic.op.oclop;
12:
13: import de.uka.ilkd.key.logic.Name;
14: import de.uka.ilkd.key.logic.Term;
15: import de.uka.ilkd.key.logic.op.TermSymbol;
16: import de.uka.ilkd.key.logic.sort.Sort;
17: import de.uka.ilkd.key.logic.sort.oclsort.CollectionSort;
18: import de.uka.ilkd.key.logic.sort.oclsort.OclSort;
19:
20: /**
21: * Super class for all OCL operators that handles one
22: * iteration variable: any(), collect(), exists(), forAll(),
23: * isUnique(), one(), reject(), select(), sortedBy()
24: */
25: public abstract class OclCollOpBound extends TermSymbol {
26:
27: private Sort expressionSort;
28:
29: public OclCollOpBound(Name name, Sort expressionSort,
30: Sort resultSort) {
31: super (name, resultSort);
32: this .expressionSort = expressionSort;
33: }
34:
35: /** @return arity of the Function as int */
36: public int arity() {
37: return 2;
38: }
39:
40: /*
41: * checks if the given term is syntactically valid at its top
42: * level assumed the top level operator were this, i.e. if the
43: * direct subterms can be subterms of a term with this top level
44: * operator, the method returns true. Furthermore, it is checked
45: * that no variables are bound for none of the subterms.
46: * @param the Term to be checked.
47: * @return true iff the given term has
48: * subterms that are suitable for this function.
49: */
50: public boolean validTopLevel(Term term) {
51: if (term.arity() != arity()) {
52: return false;
53: }
54: if (term.varsBoundHere(0).size() != 0
55: || term.varsBoundHere(1).size() != 1) {
56: return false;
57: }
58: if (!(term.sub(0).sort() instanceof CollectionSort)) {
59: return false;
60: }
61: CollectionSort collSort = (CollectionSort) term.sub(0).sort();
62: Sort iterVariableSort = term.varsBoundHere(1)
63: .getQuantifiableVariable(0).sort();
64: Sort exprSort = term.sub(1).sort();
65: if (!collSort.getElemSort().extendsTrans(iterVariableSort)) {
66: return false;
67: }
68: if (!exprSort.extendsTrans(this .expressionSort)) {
69: return false;
70: }
71: return true;
72: }
73:
74: public void helpSort(Term[] subTerm) {
75: if (subTerm.length != arity()) {
76: throw new IllegalArgumentException(
77: "Cannot determine sort of "
78: + "invalid term (Wrong arity).");
79: }
80: if (!(subTerm[0].sort() instanceof CollectionSort)) {
81: throw new IllegalArgumentException(
82: "Cannot determine sort of "
83: + "invalid term (First argument must be a Collection).");
84: }
85: }
86:
87: public String toString() {
88: return (name() + ":" + OclSort.OCLGENERIC);
89: }
90:
91: public String proofToString() {
92: String s = OclSort.OCLGENERIC + " " + name();
93: s += "(" + OclSort.COLLECTION_OF_OCLANY + ","
94: + OclSort.OCLGENERIC + "," + OclSort.OCLGENERIC;
95: s += ");\n";
96: return s;
97: }
98: }
|