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: * Represents the OCL operations: - and symmetricDifference()
22: */
23: public class OclDifference extends TermSymbol {
24:
25: public OclDifference(Name name) {
26: super (name, OclSort.SET_OF_OCLANY);
27: }
28:
29: /** @return arity of the Function as int */
30: public int arity() {
31: return 2;
32: }
33:
34: /*
35: * checks if the given term is syntactically valid at its top
36: * level assumed the top level operator were this, i.e. if the
37: * direct subterms can be subterms of a term with this top level
38: * operator, the method returns true. Furthermore, it is checked
39: * that no variables are bound for none of the subterms.
40: * @param the Term to be checked.
41: * @return true iff the given term has
42: * subterms that are suitable for this function.
43: */
44: public boolean validTopLevel(Term term) {
45: if (term.arity() != arity()) {
46: return false;
47: }
48: if (!(term.sub(0).sort() instanceof CollectionSort)
49: || !(term.sub(1).sort() instanceof CollectionSort)) {
50: return false;
51: }
52: CollectionSort collSort0 = (CollectionSort) term.sub(0).sort();
53: CollectionSort collSort1 = (CollectionSort) term.sub(1).sort();
54: if (collSort0.getCollectionKind() != CollectionSort.SET
55: || collSort1.getCollectionKind() != CollectionSort.SET) {
56: return false;
57: }
58: if (!collSort0.getElemSort().extendsTrans(
59: collSort1.getElemSort())
60: && !collSort1.getElemSort().extendsTrans(
61: collSort0.getElemSort())) {
62: return false;
63: }
64: return true;
65: }
66:
67: public Sort sort(Term[] subTerm) {
68: OclSort resultElemSort = null;
69: OclSort elemSort0 = ((CollectionSort) subTerm[0].sort())
70: .getElemSort();
71: OclSort elemSort1 = ((CollectionSort) subTerm[1].sort())
72: .getElemSort();
73: if (elemSort0.extendsTrans(elemSort1)) {
74: resultElemSort = elemSort1;
75: } else {
76: resultElemSort = elemSort0;
77: }
78:
79: return CollectionSort.getCollectionSort(CollectionSort.SET,
80: resultElemSort);
81: }
82:
83: public String toString() {
84: return (name() + ":" + OclSort.OCLGENERIC);
85: }
86:
87: public String proofToString() {
88: String s = OclSort.OCLGENERIC + " " + name();
89: s += "(" + OclSort.BOOLEAN + "," + OclSort.OCLGENERIC + ","
90: + OclSort.OCLGENERIC;
91: s += ");\n";
92: return s;
93: }
94: }
|