1 ///////////////////////////////////////////////////////////////////////////////
2 // This file is generated automatically using Prop (version 2.3.3),
3 // last updated on Mar 23, 1997.
4 // The original source file is "T2.pcc".
5 ///////////////////////////////////////////////////////////////////////////////
7 #define PROP_PRINTER_USED
8 #define PROP_GRAPHTYPE_USED
11 ///////////////////////////////////////////////////////////////////////////////
13 // Forward class definition for Exp
15 ///////////////////////////////////////////////////////////////////////////////
16 #ifndef datatype_Exp_defined
17 #define datatype_Exp_defined
22 ///////////////////////////////////////////////////////////////////////////////
24 // Base class for datatype Exp
26 ///////////////////////////////////////////////////////////////////////////////
30 tag_INT
= 0, tag_ADD
= 1, tag_SUB
= 2,
31 tag_MUL
= 3, tag_DIV
= 4
35 const Tag_Exp tag__
; // variant tag
37 inline a_Exp(Tag_Exp t__
) : tag__(t__
) {}
40 inline int boxed(const a_Exp
*) { return 1; }
41 inline int untag(const a_Exp
* x
) { return x
->tag__
; }
42 ///////////////////////////////////////////////////////////////////////////////
44 // Pretty printing methods for Exp
46 ///////////////////////////////////////////////////////////////////////////////
48 extern std::ostream
& operator<<(std::ostream
&, Exp
);
49 extern PrettyOStream
& operator<<(PrettyOStream
&, Exp
);
50 ///////////////////////////////////////////////////////////////////////////////
52 // Class for datatype constructor Exp::INT
54 ///////////////////////////////////////////////////////////////////////////////
55 class Exp_INT
: public a_Exp
{
59 inline Exp_INT (int x_INT
)
60 : a_Exp(tag_INT
), INT(x_INT
)
65 ///////////////////////////////////////////////////////////////////////////////
67 // Class for datatype constructor Exp::ADD
69 ///////////////////////////////////////////////////////////////////////////////
70 class Exp_ADD
: public a_Exp
{
74 inline Exp_ADD (Exp x_1
, Exp x_2
)
75 : a_Exp(tag_ADD
), _1(x_1
), _2(x_2
)
80 ///////////////////////////////////////////////////////////////////////////////
82 // Class for datatype constructor Exp::SUB
84 ///////////////////////////////////////////////////////////////////////////////
85 class Exp_SUB
: public a_Exp
{
89 inline Exp_SUB (Exp x_1
, Exp x_2
)
90 : a_Exp(tag_SUB
), _1(x_1
), _2(x_2
)
95 ///////////////////////////////////////////////////////////////////////////////
97 // Class for datatype constructor Exp::MUL
99 ///////////////////////////////////////////////////////////////////////////////
100 class Exp_MUL
: public a_Exp
{
104 inline Exp_MUL (Exp x_1
, Exp x_2
)
105 : a_Exp(tag_MUL
), _1(x_1
), _2(x_2
)
110 ///////////////////////////////////////////////////////////////////////////////
112 // Class for datatype constructor Exp::DIV
114 ///////////////////////////////////////////////////////////////////////////////
115 class Exp_DIV
: public a_Exp
{
119 inline Exp_DIV (Exp x_1
, Exp x_2
)
120 : a_Exp(tag_DIV
), _1(x_1
), _2(x_2
)
125 ///////////////////////////////////////////////////////////////////////////////
127 // Datatype constructor functions for Exp
129 ///////////////////////////////////////////////////////////////////////////////
130 inline a_Exp
* INT (int x_INT
)
132 return new Exp_INT (x_INT
);
134 inline a_Exp
* ADD (Exp x_1
, Exp x_2
)
136 return new Exp_ADD (x_1
, x_2
);
138 inline a_Exp
* SUB (Exp x_1
, Exp x_2
)
140 return new Exp_SUB (x_1
, x_2
);
142 inline a_Exp
* MUL (Exp x_1
, Exp x_2
)
144 return new Exp_MUL (x_1
, x_2
);
146 inline a_Exp
* DIV (Exp x_1
, Exp x_2
)
148 return new Exp_DIV (x_1
, x_2
);
150 ///////////////////////////////////////////////////////////////////////////////
152 // Downcasting functions for Exp
154 ///////////////////////////////////////////////////////////////////////////////
155 inline Exp_INT
* _INT(const a_Exp
* _x_
) { return (Exp_INT
*)_x_
; }
156 inline Exp_ADD
* _ADD(const a_Exp
* _x_
) { return (Exp_ADD
*)_x_
; }
157 inline Exp_SUB
* _SUB(const a_Exp
* _x_
) { return (Exp_SUB
*)_x_
; }
158 inline Exp_MUL
* _MUL(const a_Exp
* _x_
) { return (Exp_MUL
*)_x_
; }
159 inline Exp_DIV
* _DIV(const a_Exp
* _x_
) { return (Exp_DIV
*)_x_
; }
167 ///////////////////////////////////////////////////////////////////////////////
169 // Internal representation of nodes in graphtype Foo
171 ///////////////////////////////////////////////////////////////////////////////
173 ///////////////////////////////////////////////////////////////////////////////
175 // Representation of node Foo::Node(Exp)
177 ///////////////////////////////////////////////////////////////////////////////
178 class Foo_Node_node
{
179 // no copy constructor or assignment
180 Foo_Node_node(const Foo_Node_node
&);
181 void operator = (const Foo_Node_node
&);
184 Exp
label() const { return the_label
; }
185 operator Exp () const { return the_label
; }
188 GraphType::Link dom_link
;
189 Foo_Node_node
* image
;
190 GraphType::Link ran_link
;
198 ///////////////////////////////////////////////////////////////////////////////
200 // Definition of graphtype Foo
202 ///////////////////////////////////////////////////////////////////////////////
203 class Foo
: public GraphType
{
205 typedef Foo_Node_node
* Node
;
208 friend class Node_iterator
;
209 const GraphType::Link
& link
;
211 Node_set(const GraphType::Link
& l
, long n
= 0)
212 : link(l
), offset(n
) {}
213 Bool
is_empty() const { return link
.is_empty(); }
214 operator Bool () const { return link
.is_empty(); }
216 class Node_iterator
{
218 const GraphType::Link
* cursor
, * sentinel
;
220 Node_iterator(const Node_set
& s
) :
221 offset(s
.offset
), cursor(s
.link
.next
),
223 operator Bool () const { return cursor
!= sentinel
; }
224 Node
operator * () const
225 { return (Node
)(((char *)cursor
) - offset
); }
226 Node
operator -> () const
227 { return (Node
)(((char *)cursor
) - offset
); }
228 void operator ++ () { cursor
= cursor
->next
; }
229 void operator ++ (int) { cursor
= cursor
->next
; }
232 ////////////////////////////////////////////////////////////////////////////
234 // Interface to node Node(Exp)
236 ////////////////////////////////////////////////////////////////////////////
238 // HashTable< Exp, Node, hash< Exp >, equal< Exp > > Node_table;
240 // Create a new node, or lookup an existing node.
241 // The node is now attached to the graph.
242 virtual Node
create_Node(Exp
);
244 // Lookup a node by its label.
245 // Returns nil if no such node exists.
246 Node
lookup_Node(Exp
) const;
248 // Does a node of a certain label exists?
249 Bool
has_Node(Exp l
) const { return lookup_Node(l
) != 0; }
251 // Insert a new node into the graph by label.
252 // A no-op if the graph with the label already exists
253 Node
insert_Node(Exp l
) { return create_Node(l
); }
255 // Remove a node by label.
256 // Returns true if the graph is changed.
257 Bool
remove_Node(Exp l
) { return remove(lookup_Node(l
)); }
259 // Insert a node into the graph.
260 // Returns true if the graph is changed.
261 virtual Bool
insert(Node
);
263 // Remove a node from the graph.
264 // The node is destroyed.
265 // Returns true if the graph is changed.
266 virtual Bool
remove(Node
);
270 int count
; // number of edges
271 GraphType::Link domset
; // the domain
272 int dom_count
; // size of domain
273 GraphType::Link ranset
; // the range
274 int ran_count
; // size of range
276 Node_set
domain() const { return Node_set(domset
); }
277 Node_set
range() const { return Node_set(ranset
); }
278 Bool
domain_has (Node x
) const
279 { return x
->edge
.dom_link
.non_nil(); }
280 Bool
has (Node x
, Node y
) const
281 { return x
->edge
.image
&& x
->edge
.image
== y
; }
282 int size () const { return count
; }
283 int domain_size () const { return dom_count
; }
284 int range_size () const { return ran_count
; }
285 Node
operator () (Node x
) const
286 { return x
->edge
.image
; }
287 Bool
update(Node x
, Node y
)
289 Node z
= x
->edge
.image
;
290 if (z
== y
) return false;
293 if(--z
->edge
.ran_count
== 0)
294 { z
->edge
.ran_link
.unlink();
302 domset
.link(x
->edge
.dom_link
);
305 if (++y
->edge
.ran_count
== 1)
306 { ranset
.link(y
->edge
.ran_link
);
323 ///////////////////////////////////////////////////////////////////////////////
325 // Interface specification of datatype Exp
327 ///////////////////////////////////////////////////////////////////////////////
329 ///////////////////////////////////////////////////////////////////////////////
331 // Pretty printing methods for Exp
333 ///////////////////////////////////////////////////////////////////////////////
334 std::ostream
& operator << (std::ostream
& strm__
, Exp obj__
);
335 PrettyOStream
& operator << (PrettyOStream
& strm__
, Exp obj__
);
337 ///////////////////////////////////////////////////////////////////////////////
339 // Instantiation of datatype Exp
341 ///////////////////////////////////////////////////////////////////////////////
343 ///////////////////////////////////////////////////////////////////////////////
345 // Pretty printing methods for Exp
347 ///////////////////////////////////////////////////////////////////////////////
348 std::ostream
& operator << (std::ostream
& strm__
, Exp obj__
)
349 { PrettyOStream
S(strm__
); S
<< obj__
; return strm__
; }
351 PrettyOStream
& operator << (PrettyOStream
& strm__
, Exp obj__
)
353 switch (untag(obj__
))
356 strm__
<< _INT(obj__
)->INT
; // int
359 strm__
<< _ADD(obj__
)->_1
; // Exp
361 strm__
<< _ADD(obj__
)->_2
; // Exp
364 strm__
<< _SUB(obj__
)->_1
; // Exp
366 strm__
<< _SUB(obj__
)->_2
; // Exp
369 strm__
<< _MUL(obj__
)->_1
; // Exp
371 strm__
<< _MUL(obj__
)->_2
; // Exp
374 strm__
<< _DIV(obj__
)->_1
; // Exp
376 strm__
<< _DIV(obj__
)->_2
; // Exp