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.sort;
12:
13: import java.util.Vector;
14:
15: import de.uka.ilkd.key.logic.Name;
16: import de.uka.ilkd.key.logic.op.ConstructorFunction;
17:
18: /**
19: * GenSort extends the class <code>Sort</code> with features
20: * needed for the counterexample package. A vector of constructors is
21: * added and a couple of functions to add, return and print
22: * the constructors. At the moment there is no equality for generated sorts.
23: *
24: * To get a useful GenSort object you initialize it via
25: * <code>new GenSort(name)</code> and then add the constructors with
26: * <code>addConstructor(...)</code>
27: *
28: * @author Sonja Pieper
29: * @version 0.1, 07/08/01
30: **/
31:
32: public class GenSort extends de.uka.ilkd.key.logic.sort.PrimitiveSort {
33:
34: private Vector constructors;
35:
36: /**
37: * creates a new GenSort with a Name and no constructors.
38: *
39: * @param name the name of the new sort
40: */
41: public GenSort(Name name) {
42: super (name);
43: constructors = new Vector();
44: }
45:
46: /**
47: * With this method you can add a constructor to any <code>GenSort</code>.
48: * This is where the actual constructor objects are generated.
49: *
50: * @param name the name of the new constructor
51: * @param aos the sorts of the parameters
52: */
53: public void addConstructor(Name name, ArrayOfGenSort aos) {
54: ConstructorFunction c = new ConstructorFunction(name, this , aos);
55: constructors.addElement(c);
56: }
57:
58: public void addConstructor(ConstructorFunction cf) {
59: constructors.addElement(cf);
60: }
61:
62: // the rest is just candy:
63:
64: /**
65: * This function comes in useful if you need to do something with
66: * the constructors of the sort you are working on.
67: *
68: * @return The constructors of the generated sort as a vector.
69: */
70: public Vector getConstructors() {
71: return constructors;
72: }
73:
74: /**
75: * Prints the sort together with its constructors.
76: * The toString() functions is inherited from sort,
77: * so if you want to printout the sort with its
78: * constructors (for whatever reason) use this function.
79: *
80: * @return something like "sortname genby { con1 con2 }"
81: */
82: public String toString() {
83: String s = new String(this .name() + " genby { ");
84: for (int i = 0; i < constructors.size(); i++) {
85: s = s + constructors.elementAt(i);
86: }
87: s = s + "}";
88: return s;
89: }
90:
91: }
|