1 ///////////////////////////////////////////////////////////////////////////////
2 // This file is generated automatically using Prop (version 2.3.1),
3 // last updated on Mar 13, 1997.
4 // The original source file is "poly1.pcc".
5 ///////////////////////////////////////////////////////////////////////////////
7 #define PROP_GARBAGE_COLLECTION_USED
8 #define PROP_REFCOUNT_USED
9 #define PROP_PRINTER_USED
12 /////////////////////////////////////////////////////////////////////////////
13 // Testing polymorphic datatypes.
14 // (and garbage collection, reference counting etc.)
15 /////////////////////////////////////////////////////////////////////////////
18 // Define some polymorphic datatypes
19 // Polymorphic datatypes are not restricted to one type parameter.
20 // We test the ability to use these types in the context
24 ///////////////////////////////////////////////////////////////////////////////
26 // Forward class definition for TREE<X, Y>
28 ///////////////////////////////////////////////////////////////////////////////
29 #ifndef datatype_TREE_defined
30 #define datatype_TREE_defined
31 template <class X
, class Y
> class a_TREE
;
32 #define TREE(X, Y) a_TREE<X, Y> *
37 ///////////////////////////////////////////////////////////////////////////////
39 // Forward class definition for LIST<T>
41 ///////////////////////////////////////////////////////////////////////////////
42 #ifndef datatype_LIST_defined
43 #define datatype_LIST_defined
44 template <class T
> class a_LIST
;
45 #define LIST(T) a_LIST<T> *
50 ///////////////////////////////////////////////////////////////////////////////
52 // Forward class definition for EXP
54 ///////////////////////////////////////////////////////////////////////////////
55 #ifndef datatype_EXP_defined
56 #define datatype_EXP_defined
61 ///////////////////////////////////////////////////////////////////////////////
63 // Base class for datatype TREE<X, Y>
65 ///////////////////////////////////////////////////////////////////////////////
66 template <class X
, class Y
> class a_TREE
: public GCObject
{
69 tag_leaf
= 0, tag_node
= 1
73 const Tag_TREE tag__
; // variant tag
75 inline a_TREE(Tag_TREE t__
) : tag__(t__
) {}
77 inline virtual ~a_TREE()
80 ////////////////////////////////////////////////////////////////////////////
82 // Method for garbage collection tracing
84 ////////////////////////////////////////////////////////////////////////////
86 virtual void trace(GC
*);
89 template <class X
, class Y
> inline int boxed(const a_TREE
<X
, Y
> * x
) { return x
!= 0; }
90 template <class X
, class Y
> inline int untag(const a_TREE
<X
, Y
> * x
) { return x
? (x
->tag__
+1) : 0; }
92 ///////////////////////////////////////////////////////////////////////////////
94 // Pretty printing methods for TREE<X, Y>
96 ///////////////////////////////////////////////////////////////////////////////
98 template <class X
, class Y
> extern ostream
& operator<<(ostream
&, TREE(X
, Y
));
99 template <class X
, class Y
> extern PrettyOStream
& operator<<(PrettyOStream
&, TREE(X
, Y
));
100 ///////////////////////////////////////////////////////////////////////////////
102 // Class for datatype constructor TREE<X, Y>::leaf
104 ///////////////////////////////////////////////////////////////////////////////
105 template <class X
, class Y
> class TREE_leaf
: public a_TREE
<X
, Y
> {
109 inline TREE_leaf (X x_leaf
)
110 : a_TREE
<X
, Y
>(tag_leaf
), leaf(x_leaf
)
116 ////////////////////////////////////////////////////////////////////////////
118 // Method for garbage collection tracing
120 ////////////////////////////////////////////////////////////////////////////
122 virtual void trace(GC
*);
126 ///////////////////////////////////////////////////////////////////////////////
128 // Class for datatype constructor TREE<X, Y>::node
130 ///////////////////////////////////////////////////////////////////////////////
131 template <class X
, class Y
> class TREE_node
: public a_TREE
<X
, Y
> {
134 a_TREE
<X
, Y
> * _1
; Y _2
; a_TREE
<X
, Y
> * _3
;
135 inline TREE_node (a_TREE
<X
, Y
> * x_1
, Y x_2
, a_TREE
<X
, Y
> * x_3
)
136 : a_TREE
<X
, Y
>(tag_node
), _1(x_1
), _2(x_2
), _3(x_3
)
142 ////////////////////////////////////////////////////////////////////////////
144 // Method for garbage collection tracing
146 ////////////////////////////////////////////////////////////////////////////
148 virtual void trace(GC
*);
152 ///////////////////////////////////////////////////////////////////////////////
154 // Datatype constructor functions for TREE<X, Y>
156 ///////////////////////////////////////////////////////////////////////////////
157 template <class X
, class Y
> inline a_TREE
<X
, Y
> * leaf (X x_leaf
) { return new TREE_leaf
<X
, Y
> (x_leaf
); }
158 template <class X
, class Y
> inline a_TREE
<X
, Y
> * node (a_TREE
<X
, Y
> * x_1
, Y x_2
, a_TREE
<X
, Y
> * x_3
) { return new TREE_node
<X
, Y
> (x_1
, x_2
, x_3
); }
159 ///////////////////////////////////////////////////////////////////////////////
161 // Downcasting functions for TREE<X, Y>
163 ///////////////////////////////////////////////////////////////////////////////
164 template <class X
, class Y
> inline TREE_leaf
<X
, Y
> * _leaf(const a_TREE
<X
, Y
> * _x_
) { return (TREE_leaf
<X
, Y
> *)_x_
; }
165 template <class X
, class Y
> inline TREE_node
<X
, Y
> * _node(const a_TREE
<X
, Y
> * _x_
) { return (TREE_node
<X
, Y
> *)_x_
; }
167 ///////////////////////////////////////////////////////////////////////////////
169 // Class for datatype constructor LIST<T>::#[...]
171 ///////////////////////////////////////////////////////////////////////////////
172 template <class T
> class a_LIST
: public GCObject
{
175 T _1
; a_LIST
<T
> * _2
;
176 inline a_LIST (T x_1
, a_LIST
<T
> * x_2
= 0)
180 inline virtual ~a_LIST()
183 ////////////////////////////////////////////////////////////////////////////
185 // Method for garbage collection tracing
187 ////////////////////////////////////////////////////////////////////////////
189 virtual void trace(GC
*);
192 template <class T
> inline int boxed(const a_LIST
<T
> * x
) { return x
!= 0; }
193 template <class T
> inline int untag(const a_LIST
<T
> * x
) { return x
? 1 : 0; }
195 ///////////////////////////////////////////////////////////////////////////////
197 // Pretty printing methods for LIST<T>
199 ///////////////////////////////////////////////////////////////////////////////
201 template <class T
> extern ostream
& operator<<(ostream
&, LIST(T
));
202 template <class T
> extern PrettyOStream
& operator<<(PrettyOStream
&, LIST(T
));
203 ///////////////////////////////////////////////////////////////////////////////
205 // Datatype constructor functions for LIST<T>
207 ///////////////////////////////////////////////////////////////////////////////
208 template <class T
> inline a_LIST
<T
> * list_1_ (T x_1
, a_LIST
<T
> * x_2
= 0) { return new a_LIST
<T
> (x_1
, x_2
); }
209 ///////////////////////////////////////////////////////////////////////////////
211 // Downcasting functions for LIST<T>
213 ///////////////////////////////////////////////////////////////////////////////
216 ///////////////////////////////////////////////////////////////////////////////
218 // Base class for datatype EXP
220 ///////////////////////////////////////////////////////////////////////////////
224 tag_num
= 0, tag_var
= 1, tag_add
= 2,
225 tag_sub
= 3, tag_mul
= 4, tag_div
= 5,
230 const Tag_EXP tag__
; // variant tag
232 inline a_EXP(Tag_EXP t__
) : tag__(t__
) {}
235 inline int boxed(const a_EXP
* x
) { return 1; }
236 inline int untag(const a_EXP
* x
) { return x
->tag__
; }
238 ///////////////////////////////////////////////////////////////////////////////
240 // Pretty printing methods for EXP
242 ///////////////////////////////////////////////////////////////////////////////
244 extern ostream
& operator<<(ostream
&, EXP
);
245 extern PrettyOStream
& operator<<(PrettyOStream
&, EXP
);
246 ///////////////////////////////////////////////////////////////////////////////
248 // Class for datatype constructor EXP::num
250 ///////////////////////////////////////////////////////////////////////////////
251 class EXP_num
: public a_EXP
{
255 inline EXP_num (int x_num
)
256 : a_EXP(tag_num
), num(x_num
)
261 ///////////////////////////////////////////////////////////////////////////////
263 // Class for datatype constructor EXP::var
265 ///////////////////////////////////////////////////////////////////////////////
266 class EXP_var
: public a_EXP
{
270 inline EXP_var (char const * x_var
)
271 : a_EXP(tag_var
), var(x_var
)
276 ///////////////////////////////////////////////////////////////////////////////
278 // Class for datatype constructor EXP::add
280 ///////////////////////////////////////////////////////////////////////////////
281 class EXP_add
: public a_EXP
{
285 inline EXP_add (EXP x_1
, EXP x_2
)
286 : a_EXP(tag_add
), _1(x_1
), _2(x_2
)
291 ///////////////////////////////////////////////////////////////////////////////
293 // Class for datatype constructor EXP::sub
295 ///////////////////////////////////////////////////////////////////////////////
296 class EXP_sub
: public a_EXP
{
300 inline EXP_sub (EXP x_1
, EXP x_2
)
301 : a_EXP(tag_sub
), _1(x_1
), _2(x_2
)
306 ///////////////////////////////////////////////////////////////////////////////
308 // Class for datatype constructor EXP::mul
310 ///////////////////////////////////////////////////////////////////////////////
311 class EXP_mul
: public a_EXP
{
315 inline EXP_mul (EXP x_1
, EXP x_2
)
316 : a_EXP(tag_mul
), _1(x_1
), _2(x_2
)
321 ///////////////////////////////////////////////////////////////////////////////
323 // Class for datatype constructor EXP::div
325 ///////////////////////////////////////////////////////////////////////////////
326 class EXP_div
: public a_EXP
{
330 inline EXP_div (EXP x_1
, EXP x_2
)
331 : a_EXP(tag_div
), _1(x_1
), _2(x_2
)
336 ///////////////////////////////////////////////////////////////////////////////
338 // Class for datatype constructor EXP::list
340 ///////////////////////////////////////////////////////////////////////////////
341 class EXP_list
: public a_EXP
{
345 inline EXP_list (a_LIST
<EXP
> * x_list
)
346 : a_EXP(tag_list
), list(x_list
)
351 ///////////////////////////////////////////////////////////////////////////////
353 // Datatype constructor functions for EXP
355 ///////////////////////////////////////////////////////////////////////////////
356 inline a_EXP
* num (int x_num
) { return new EXP_num (x_num
); }
357 inline a_EXP
* var (char const * x_var
) { return new EXP_var (x_var
); }
358 inline a_EXP
* add (EXP x_1
, EXP x_2
) { return new EXP_add (x_1
, x_2
); }
359 inline a_EXP
* sub (EXP x_1
, EXP x_2
) { return new EXP_sub (x_1
, x_2
); }
360 inline a_EXP
* mul (EXP x_1
, EXP x_2
) { return new EXP_mul (x_1
, x_2
); }
361 inline a_EXP
* div (EXP x_1
, EXP x_2
) { return new EXP_div (x_1
, x_2
); }
362 inline a_EXP
* list (a_LIST
<EXP
> * x_list
) { return new EXP_list (x_list
); }
363 ///////////////////////////////////////////////////////////////////////////////
365 // Downcasting functions for EXP
367 ///////////////////////////////////////////////////////////////////////////////
368 inline EXP_num
* _num(const a_EXP
* _x_
) { return (EXP_num
*)_x_
; }
369 inline EXP_var
* _var(const a_EXP
* _x_
) { return (EXP_var
*)_x_
; }
370 inline EXP_add
* _add(const a_EXP
* _x_
) { return (EXP_add
*)_x_
; }
371 inline EXP_sub
* _sub(const a_EXP
* _x_
) { return (EXP_sub
*)_x_
; }
372 inline EXP_mul
* _mul(const a_EXP
* _x_
) { return (EXP_mul
*)_x_
; }
373 inline EXP_div
* _div(const a_EXP
* _x_
) { return (EXP_div
*)_x_
; }
374 inline EXP_list
* _list(const a_EXP
* _x_
) { return (EXP_list
*)_x_
; }
380 /////////////////////////////////////////////////////////////////////////////
381 // Instantiate the datatypes.
382 // This will generate a bunch of methods, functions and classes
383 // to implement printing and garbage collection.
384 /////////////////////////////////////////////////////////////////////////////
387 ///////////////////////////////////////////////////////////////////////////////
388 // Instantiation of datatype TREE<int, char const *>
389 ///////////////////////////////////////////////////////////////////////////////
391 ///////////////////////////////////////////////////////////////////////////////
393 // Pretty printing methods for TREE<int, char const *>
395 ///////////////////////////////////////////////////////////////////////////////
396 ostream
& operator << (ostream
& strm__
, TREE(int, char const *) obj__
);
397 PrettyOStream
& operator << (PrettyOStream
& strm__
, TREE(int, char const *) obj__
);
399 ///////////////////////////////////////////////////////////////////////////////
400 // Instantiation of datatype LIST<int>
401 ///////////////////////////////////////////////////////////////////////////////
403 ///////////////////////////////////////////////////////////////////////////////
405 // Pretty printing methods for LIST<int>
407 ///////////////////////////////////////////////////////////////////////////////
408 ostream
& operator << (ostream
& strm__
, LIST(int) obj__
);
409 PrettyOStream
& operator << (PrettyOStream
& strm__
, LIST(int) obj__
);
411 ///////////////////////////////////////////////////////////////////////////////
412 // Instantiation of datatype LIST<EXP>
413 ///////////////////////////////////////////////////////////////////////////////
415 ///////////////////////////////////////////////////////////////////////////////
417 // Pretty printing methods for LIST<EXP>
419 ///////////////////////////////////////////////////////////////////////////////
420 ostream
& operator << (ostream
& strm__
, LIST(EXP
) obj__
);
421 PrettyOStream
& operator << (PrettyOStream
& strm__
, LIST(EXP
) obj__
);
428 ///////////////////////////////////////////////////////////////////////////////
429 // Instantiation of datatype TREE<int, char const *>
430 ///////////////////////////////////////////////////////////////////////////////
432 void a_TREE
<int, char const *>::trace(GC
* gc__
)
436 ///////////////////////////////////////////////////////////////////////////////
438 // Pretty printing methods for TREE<int, char const *>
440 ///////////////////////////////////////////////////////////////////////////////
441 ostream
& operator << (ostream
& strm__
, TREE(int, char const *) obj__
)
442 { PrettyOStream
S(strm__
); S
<< obj__
; return strm__
; }
444 PrettyOStream
& operator << (PrettyOStream
& strm__
, TREE(int, char const *) obj__
)
446 switch (untag(obj__
))
454 strm__
<< _leaf(obj__
)->leaf
; // int
459 strm__
<< _node(obj__
)->_1
; // TREE<int, char const *>
461 strm__
<< _node(obj__
)->_2
; // char const *
463 strm__
<< _node(obj__
)->_3
; // TREE<int, char const *>
471 void TREE_leaf
<int, char const *>::trace(GC
* gc__
)
473 // call to method a_TREE<int, char const *>::trace() has been optimized out
477 void TREE_node
<int, char const *>::trace(GC
* gc__
)
479 // call to method a_TREE<int, char const *>::trace() has been optimized out
480 this->_1
= (TREE(int, char const *) )gc__
->trace(this->_1
); // TREE<int, char const *>
481 // omitted char const *
482 this->_3
= (TREE(int, char const *) )gc__
->trace(this->_3
); // TREE<int, char const *>
487 ///////////////////////////////////////////////////////////////////////////////
488 // Instantiation of datatype LIST<int>
489 ///////////////////////////////////////////////////////////////////////////////
491 void a_LIST
<int>::trace(GC
* gc__
)
494 this->_2
= (LIST(int) )gc__
->trace(this->_2
); // LIST<int> = 0
497 ///////////////////////////////////////////////////////////////////////////////
499 // Pretty printing methods for LIST<int>
501 ///////////////////////////////////////////////////////////////////////////////
502 ostream
& operator << (ostream
& strm__
, LIST(int) obj__
)
503 { PrettyOStream
S(strm__
); S
<< obj__
; return strm__
; }
505 PrettyOStream
& operator << (PrettyOStream
& strm__
, LIST(int) obj__
)
507 switch (untag(obj__
))
514 strm__
<< obj__
->_1
; // int
516 strm__
<< obj__
->_2
; // LIST<int> = 0
526 ///////////////////////////////////////////////////////////////////////////////
527 // Instantiation of datatype LIST<EXP>
528 ///////////////////////////////////////////////////////////////////////////////
530 void a_LIST
<EXP
>::trace(GC
* gc__
)
533 this->_2
= (LIST(EXP
) )gc__
->trace(this->_2
); // LIST<EXP> = 0
536 ///////////////////////////////////////////////////////////////////////////////
538 // Pretty printing methods for LIST<EXP>
540 ///////////////////////////////////////////////////////////////////////////////
541 ostream
& operator << (ostream
& strm__
, LIST(EXP
) obj__
)
542 { PrettyOStream
S(strm__
); S
<< obj__
; return strm__
; }
544 PrettyOStream
& operator << (PrettyOStream
& strm__
, LIST(EXP
) obj__
)
546 switch (untag(obj__
))
553 strm__
<< obj__
->_1
; // EXP
555 strm__
<< obj__
->_2
; // LIST<EXP> = 0
565 ///////////////////////////////////////////////////////////////////////////////
566 // Instantiation of datatype EXP
567 ///////////////////////////////////////////////////////////////////////////////
569 ///////////////////////////////////////////////////////////////////////////////
571 // Pretty printing methods for EXP
573 ///////////////////////////////////////////////////////////////////////////////
574 ostream
& operator << (ostream
& strm__
, EXP obj__
)
575 { PrettyOStream
S(strm__
); S
<< obj__
; return strm__
; }
577 PrettyOStream
& operator << (PrettyOStream
& strm__
, EXP obj__
)
579 switch (untag(obj__
))
582 strm__
<< _num(obj__
)->num
; // int
585 strm__
<< _var(obj__
)->var
; // char const *
589 strm__
<< _add(obj__
)->_1
; // EXP
591 strm__
<< _add(obj__
)->_2
; // EXP
596 strm__
<< _sub(obj__
)->_1
; // EXP
598 strm__
<< _sub(obj__
)->_2
; // EXP
603 strm__
<< _mul(obj__
)->_1
; // EXP
605 strm__
<< _mul(obj__
)->_2
; // EXP
610 strm__
<< _div(obj__
)->_1
; // EXP
612 strm__
<< _div(obj__
)->_2
; // EXP
615 case a_EXP::tag_list
:
616 strm__
<< _list(obj__
)->list
; // LIST<EXP>
628 /////////////////////////////////////////////////////////////////////////////
629 // Define functions to test pattern matching
630 /////////////////////////////////////////////////////////////////////////////
642 return 1 + length(l
->_2
);
655 /////////////////////////////////////////////////////////////////////////////
656 // Sum an integer list
657 /////////////////////////////////////////////////////////////////////////////
668 return l
->_1
+ sum(l
->_2
);
681 /////////////////////////////////////////////////////////////////////////////
683 /////////////////////////////////////////////////////////////////////////////
702 list_1_(x
->_1
,append(x
->_2
,y
))
720 /////////////////////////////////////////////////////////////////////////////
721 // Exercise the list patterns
722 /////////////////////////////////////////////////////////////////////////////
735 if (l
->_2
->_2
->_2
->_2
) {
770 /////////////////////////////////////////////////////////////////////////////
772 /////////////////////////////////////////////////////////////////////////////
773 template <class X
, class Y
>
786 int a
= depth(_node(t
)->_1
), b
= depth(_node(t
)->_3
);
787 return 1 + (a
> b
? a
: b
);
812 // Due to a compiler problem in g++ 2.5.8, I'm unable to use a
813 // typedef to abbreviate TREE<int, const char *>.
815 #line 100 "poly1.pcc"
816 a_TREE
<int, char const *> *
817 #line 100 "poly1.pcc"
819 const char * This
= "this";
820 const char * That
= "that";
821 a_TREE
<int, char const *> *
822 #line 103 "poly1.pcc"
823 tree1
= node( E
, This
, leaf(2) );
824 a_TREE
<int, char const *> *
825 #line 104 "poly1.pcc"
826 tree2
= node( E
, That
, E
);
828 EXP e1
= add(var("x"),num(1));
829 EXP e2
= sub(var("y"),num(2));
832 #line 109 "poly1.pcc"
834 #line 109 "poly1.pcc"
835 list_1_(1,list_1_(2))
836 #line 109 "poly1.pcc"
837 #line 109 "poly1.pcc"
840 #line 110 "poly1.pcc"
842 #line 110 "poly1.pcc"
844 #line 110 "poly1.pcc"
845 list_1_(e1
,list_1_(e2
,list_1_(var("z"))))
846 #line 110 "poly1.pcc"
847 #line 110 "poly1.pcc"
850 #line 111 "poly1.pcc"
852 #line 111 "poly1.pcc"
854 #line 111 "poly1.pcc"
855 list_1_(num((- 1)),list_1_(list(list2
),list_1_(list(list2
))))
856 #line 111 "poly1.pcc"
857 #line 111 "poly1.pcc"
860 cout
<< "tree1 = " << tree1
<< "\tdepth = " << depth(tree1
) << '\n';
861 cout
<< "tree2 = " << tree2
<< "\tdepth = " << depth(tree2
) << '\n';
863 cout
<< "list1 = " << list1
864 << "\tlength = " << length(list1
)
865 << "\tsum = " << sum(list1
) << '\n';
866 cout
<< "list2 = " << list2
<< "\tlength = " << length(list2
) << '\n';
867 cout
<< "list3 = " << list3
<< "\tlength = " << length(list3
) << '\n';
868 cout
<< "list1 + list1 = " << append(list1
, list1
) << '\n';
869 cout
<< "list2 + list3 = " << append(list2
, list3
) << '\n';
873 #line 126 "poly1.pcc"
875 ------------------------------- Statistics -------------------------------
876 Merge matching rules = yes
877 Number of DFA nodes merged = 4
878 Number of ifs generated = 10
879 Number of switches generated = 0
882 Adaptive matching = disabled
883 Fast string matching = disabled
884 Inline downcasts = disabled
885 --------------------------------------------------------------------------