simple.cc - generated code example
[prop.git] / prop-src / T2.cc
blob69681b2f4619522df2fbe3f1812721fb6ff3af8f
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
9 #include <propdefs.h>
10 #line 6 "T2.pcc"
11 ///////////////////////////////////////////////////////////////////////////////
13 // Forward class definition for Exp
15 ///////////////////////////////////////////////////////////////////////////////
16 #ifndef datatype_Exp_defined
17 #define datatype_Exp_defined
18 class a_Exp;
19 typedef a_Exp * Exp;
20 #endif
22 ///////////////////////////////////////////////////////////////////////////////
24 // Base class for datatype Exp
26 ///////////////////////////////////////////////////////////////////////////////
27 class a_Exp {
28 public:
29 enum Tag_Exp {
30 tag_INT = 0, tag_ADD = 1, tag_SUB = 2,
31 tag_MUL = 3, tag_DIV = 4
34 public:
35 const Tag_Exp tag__; // variant tag
36 protected:
37 inline a_Exp(Tag_Exp t__) : tag__(t__) {}
38 public:
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 ///////////////////////////////////////////////////////////////////////////////
47 class PrettyOStream;
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 {
56 public:
57 #line 1 "T2.pcc"
58 int INT;
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 {
71 public:
72 #line 1 "T2.pcc"
73 Exp _1; Exp _2;
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 {
86 public:
87 #line 2 "T2.pcc"
88 Exp _1; Exp _2;
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 {
101 public:
102 #line 3 "T2.pcc"
103 Exp _1; Exp _2;
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 {
116 public:
117 #line 4 "T2.pcc"
118 Exp _1; Exp _2;
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_; }
161 #line 6 "T2.pcc"
162 #line 6 "T2.pcc"
165 #line 8 "T2.pcc"
166 #line 13 "T2.pcc"
167 ///////////////////////////////////////////////////////////////////////////////
169 // Internal representation of nodes in graphtype Foo
171 ///////////////////////////////////////////////////////////////////////////////
172 class Foo_Node_node;
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&);
182 Exp the_label;
183 public:
184 Exp label() const { return the_label; }
185 operator Exp () const { return the_label; }
186 friend class Foo;
187 struct {
188 GraphType::Link dom_link;
189 Foo_Node_node * image;
190 GraphType::Link ran_link;
191 int ran_count;
192 } edge;
193 public:
194 Foo_Node_node();
195 ~Foo_Node_node();
198 ///////////////////////////////////////////////////////////////////////////////
200 // Definition of graphtype Foo
202 ///////////////////////////////////////////////////////////////////////////////
203 class Foo : public GraphType {
204 public:
205 typedef Foo_Node_node * Node;
206 class Node_set {
207 public:
208 friend class Node_iterator;
209 const GraphType::Link& link;
210 long offset;
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 {
217 long offset;
218 const GraphType::Link * cursor, * sentinel;
219 public:
220 Node_iterator(const Node_set& s) :
221 offset(s.offset), cursor(s.link.next),
222 sentinel(&s.link) {}
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; }
231 public:
232 ////////////////////////////////////////////////////////////////////////////
234 // Interface to node Node(Exp)
236 ////////////////////////////////////////////////////////////////////////////
237 protected:
238 // HashTable< Exp, Node, hash< Exp >, equal< Exp > > Node_table;
239 public:
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);
267 class edge_record {
268 protected:
269 friend class Foo;
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
275 public:
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;
291 if (z)
293 if(--z->edge.ran_count == 0)
294 { z->edge.ran_link.unlink();
295 --ran_count;
298 else
300 ++count;
301 ++dom_count;
302 domset.link(x->edge.dom_link);
304 x->edge.image = y;
305 if (++y->edge.ran_count == 1)
306 { ranset.link(y->edge.ran_link);
307 ++ran_count;
309 return true;
311 } edge;
313 #line 12 "T2.pcc"
315 #line 13 "T2.pcc"
317 #line 13 "T2.pcc"
318 #line 13 "T2.pcc"
321 #line 15 "T2.pcc"
322 #line 15 "T2.pcc"
323 ///////////////////////////////////////////////////////////////////////////////
325 // Interface specification of datatype Exp
327 ///////////////////////////////////////////////////////////////////////////////
328 #line 15 "T2.pcc"
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 ///////////////////////////////////////////////////////////////////////////////
342 #line 15 "T2.pcc"
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__))
355 case a_Exp::tag_INT:
356 strm__ << _INT(obj__)->INT; // int
357 break;
358 case a_Exp::tag_ADD:
359 strm__ << _ADD(obj__)->_1; // Exp
360 strm__ << '+';
361 strm__ << _ADD(obj__)->_2; // Exp
362 break;
363 case a_Exp::tag_SUB:
364 strm__ << _SUB(obj__)->_1; // Exp
365 strm__ << '-';
366 strm__ << _SUB(obj__)->_2; // Exp
367 break;
368 case a_Exp::tag_MUL:
369 strm__ << _MUL(obj__)->_1; // Exp
370 strm__ << '*';
371 strm__ << _MUL(obj__)->_2; // Exp
372 break;
373 case a_Exp::tag_DIV:
374 strm__ << _DIV(obj__)->_1; // Exp
375 strm__ << '/';
376 strm__ << _DIV(obj__)->_2; // Exp
377 break;
379 return strm__;
384 #line 15 "T2.pcc"
385 #line 15 "T2.pcc"
388 #line 17 "T2.pcc"
389 #line 21 "T2.pcc"