Merge remote branch 'master'
[prop.git] / tests / poly1.cc
blobd186846085b8ae283a7b687ac4b4286ac94cd7ee
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
10 #include <propdefs.h>
11 #line 1 "poly1.pcc"
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
22 #line 11 "poly1.pcc"
23 #line 26 "poly1.pcc"
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> *
33 #endif
35 # define empty 0
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> *
46 #endif
48 # define nil_1_ 0
50 ///////////////////////////////////////////////////////////////////////////////
52 // Forward class definition for EXP
54 ///////////////////////////////////////////////////////////////////////////////
55 #ifndef datatype_EXP_defined
56 #define datatype_EXP_defined
57 class a_EXP;
58 typedef a_EXP * EXP;
59 #endif
61 ///////////////////////////////////////////////////////////////////////////////
63 // Base class for datatype TREE<X, Y>
65 ///////////////////////////////////////////////////////////////////////////////
66 template <class X, class Y> class a_TREE : public GCObject {
67 public:
68 enum Tag_TREE {
69 tag_leaf = 0, tag_node = 1
72 public:
73 const Tag_TREE tag__; // variant tag
74 protected:
75 inline a_TREE(Tag_TREE t__) : tag__(t__) {}
76 public:
77 inline virtual ~a_TREE()
80 ////////////////////////////////////////////////////////////////////////////
82 // Method for garbage collection tracing
84 ////////////////////////////////////////////////////////////////////////////
85 protected:
86 virtual void trace(GC *);
87 public:
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 ///////////////////////////////////////////////////////////////////////////////
97 class PrettyOStream;
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> {
106 public:
107 #line 12 "poly1.pcc"
108 X leaf;
109 inline TREE_leaf (X x_leaf)
110 : a_TREE<X, Y>(tag_leaf), leaf(x_leaf)
113 inline ~TREE_leaf()
116 ////////////////////////////////////////////////////////////////////////////
118 // Method for garbage collection tracing
120 ////////////////////////////////////////////////////////////////////////////
121 protected:
122 virtual void trace(GC *);
123 public:
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> {
132 public:
133 #line 12 "poly1.pcc"
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)
139 inline ~TREE_node()
142 ////////////////////////////////////////////////////////////////////////////
144 // Method for garbage collection tracing
146 ////////////////////////////////////////////////////////////////////////////
147 protected:
148 virtual void trace(GC *);
149 public:
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 {
173 public:
174 #line 15 "poly1.pcc"
175 T _1; a_LIST<T> * _2;
176 inline a_LIST (T x_1, a_LIST<T> * x_2 = 0)
177 : _1(x_1), _2(x_2)
180 inline virtual ~a_LIST()
183 ////////////////////////////////////////////////////////////////////////////
185 // Method for garbage collection tracing
187 ////////////////////////////////////////////////////////////////////////////
188 protected:
189 virtual void trace(GC *);
190 public:
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 ///////////////////////////////////////////////////////////////////////////////
200 class PrettyOStream;
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 ///////////////////////////////////////////////////////////////////////////////
221 class a_EXP {
222 public:
223 enum Tag_EXP {
224 tag_num = 0, tag_var = 1, tag_add = 2,
225 tag_sub = 3, tag_mul = 4, tag_div = 5,
226 tag_list = 6
229 public:
230 const Tag_EXP tag__; // variant tag
231 protected:
232 inline a_EXP(Tag_EXP t__) : tag__(t__) {}
233 public:
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 ///////////////////////////////////////////////////////////////////////////////
243 class PrettyOStream;
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 {
252 public:
253 #line 17 "poly1.pcc"
254 int num;
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 {
267 public:
268 #line 18 "poly1.pcc"
269 char const * var;
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 {
282 public:
283 #line 19 "poly1.pcc"
284 EXP _1; EXP _2;
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 {
297 public:
298 #line 20 "poly1.pcc"
299 EXP _1; EXP _2;
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 {
312 public:
313 #line 21 "poly1.pcc"
314 EXP _1; EXP _2;
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 {
327 public:
328 #line 22 "poly1.pcc"
329 EXP _1; EXP _2;
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 {
342 public:
343 #line 23 "poly1.pcc"
344 a_LIST<EXP> * list;
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_; }
376 #line 26 "poly1.pcc"
377 #line 26 "poly1.pcc"
380 /////////////////////////////////////////////////////////////////////////////
381 // Instantiate the datatypes.
382 // This will generate a bunch of methods, functions and classes
383 // to implement printing and garbage collection.
384 /////////////////////////////////////////////////////////////////////////////
385 #line 33 "poly1.pcc"
386 #line 33 "poly1.pcc"
387 ///////////////////////////////////////////////////////////////////////////////
388 // Instantiation of datatype TREE<int, char const *>
389 ///////////////////////////////////////////////////////////////////////////////
390 #line 33 "poly1.pcc"
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 ///////////////////////////////////////////////////////////////////////////////
402 #line 33 "poly1.pcc"
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 ///////////////////////////////////////////////////////////////////////////////
414 #line 33 "poly1.pcc"
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__);
423 #line 33 "poly1.pcc"
424 #line 33 "poly1.pcc"
426 #line 34 "poly1.pcc"
427 #line 34 "poly1.pcc"
428 ///////////////////////////////////////////////////////////////////////////////
429 // Instantiation of datatype TREE<int, char const *>
430 ///////////////////////////////////////////////////////////////////////////////
431 #line 34 "poly1.pcc"
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__))
448 case (int)empty:
449 strm__ << "empty";
450 break;
451 case 0 + 1:
452 strm__ << "leaf";
453 strm__ << "(";
454 strm__ << _leaf(obj__)->leaf; // int
455 strm__ << ")";
456 break;
457 case 1 + 1:
458 strm__ << ")";
459 strm__ << _node(obj__)->_1; // TREE<int, char const *>
460 strm__ << ",";
461 strm__ << _node(obj__)->_2; // char const *
462 strm__ << ",";
463 strm__ << _node(obj__)->_3; // TREE<int, char const *>
464 strm__ << "node";
465 strm__ << "(";
466 break;
468 return strm__;
471 void TREE_leaf<int, char const *>::trace(GC * gc__)
473 // call to method a_TREE<int, char const *>::trace() has been optimized out
474 // omitted int
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 ///////////////////////////////////////////////////////////////////////////////
490 #line 34 "poly1.pcc"
491 void a_LIST<int>::trace(GC * gc__)
493 // omitted int
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__))
509 case (int)nil_1_:
510 strm__ << "#[]";
511 break;
512 case 1:
513 strm__ << ")";
514 strm__ << obj__->_1; // int
515 strm__ << ",";
516 strm__ << obj__->_2; // LIST<int> = 0
517 strm__ << "#[...]";
518 strm__ << "(";
519 break;
521 return strm__;
526 ///////////////////////////////////////////////////////////////////////////////
527 // Instantiation of datatype LIST<EXP>
528 ///////////////////////////////////////////////////////////////////////////////
529 #line 34 "poly1.pcc"
530 void a_LIST<EXP>::trace(GC * gc__)
532 // omitted EXP
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__))
548 case (int)nil_1_:
549 strm__ << "#[]";
550 break;
551 case 1:
552 strm__ << ")";
553 strm__ << obj__->_1; // EXP
554 strm__ << ",";
555 strm__ << obj__->_2; // LIST<EXP> = 0
556 strm__ << "#[...]";
557 strm__ << "(";
558 break;
560 return strm__;
565 ///////////////////////////////////////////////////////////////////////////////
566 // Instantiation of datatype EXP
567 ///////////////////////////////////////////////////////////////////////////////
568 #line 34 "poly1.pcc"
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__))
581 case a_EXP::tag_num:
582 strm__ << _num(obj__)->num; // int
583 break;
584 case a_EXP::tag_var:
585 strm__ << _var(obj__)->var; // char const *
586 break;
587 case a_EXP::tag_add:
588 strm__ << "(";
589 strm__ << _add(obj__)->_1; // EXP
590 strm__ << " + ";
591 strm__ << _add(obj__)->_2; // EXP
592 strm__ << ")";
593 break;
594 case a_EXP::tag_sub:
595 strm__ << "(";
596 strm__ << _sub(obj__)->_1; // EXP
597 strm__ << " - ";
598 strm__ << _sub(obj__)->_2; // EXP
599 strm__ << ")";
600 break;
601 case a_EXP::tag_mul:
602 strm__ << "(";
603 strm__ << _mul(obj__)->_1; // EXP
604 strm__ << " * ";
605 strm__ << _mul(obj__)->_2; // EXP
606 strm__ << ")";
607 break;
608 case a_EXP::tag_div:
609 strm__ << "(";
610 strm__ << _div(obj__)->_1; // EXP
611 strm__ << " / ";
612 strm__ << _div(obj__)->_2; // EXP
613 strm__ << ")";
614 break;
615 case a_EXP::tag_list:
616 strm__ << _list(obj__)->list; // LIST<EXP>
617 break;
619 return strm__;
624 #line 34 "poly1.pcc"
625 #line 34 "poly1.pcc"
628 /////////////////////////////////////////////////////////////////////////////
629 // Define functions to test pattern matching
630 /////////////////////////////////////////////////////////////////////////////
631 template <class T>
632 int length(
633 #line 40 "poly1.pcc"
634 a_LIST<T> *
635 #line 40 "poly1.pcc"
638 #line 43 "poly1.pcc"
640 if (l) {
641 #line 43 "poly1.pcc"
642 return 1 + length(l->_2);
643 #line 43 "poly1.pcc"
644 } else {
645 #line 42 "poly1.pcc"
646 return 0;
647 #line 42 "poly1.pcc"
650 #line 44 "poly1.pcc"
651 #line 44 "poly1.pcc"
655 /////////////////////////////////////////////////////////////////////////////
656 // Sum an integer list
657 /////////////////////////////////////////////////////////////////////////////
658 int sum (
659 #line 50 "poly1.pcc"
660 a_LIST<int> *
661 #line 50 "poly1.pcc"
664 #line 53 "poly1.pcc"
666 if (l) {
667 #line 53 "poly1.pcc"
668 return l->_1 + sum(l->_2);
669 #line 53 "poly1.pcc"
670 } else {
671 #line 52 "poly1.pcc"
672 return 0;
673 #line 52 "poly1.pcc"
676 #line 54 "poly1.pcc"
677 #line 54 "poly1.pcc"
681 /////////////////////////////////////////////////////////////////////////////
682 // Append two lists
683 /////////////////////////////////////////////////////////////////////////////
684 template <class T>
686 #line 61 "poly1.pcc"
687 a_LIST<T> *
688 #line 61 "poly1.pcc"
689 append (a_LIST<T> *
690 #line 61 "poly1.pcc"
691 x, a_LIST<T> *
692 #line 61 "poly1.pcc"
695 #line 65 "poly1.pcc"
697 if (x) {
698 #line 64 "poly1.pcc"
699 return
700 #line 64 "poly1.pcc"
701 #line 64 "poly1.pcc"
702 list_1_(x->_1,append(x->_2,y))
703 #line 64 "poly1.pcc"
704 #line 64 "poly1.pcc"
707 #line 65 "poly1.pcc"
708 } else {
709 #line 63 "poly1.pcc"
710 return y;
712 #line 64 "poly1.pcc"
715 #line 65 "poly1.pcc"
716 #line 65 "poly1.pcc"
720 /////////////////////////////////////////////////////////////////////////////
721 // Exercise the list patterns
722 /////////////////////////////////////////////////////////////////////////////
723 int dummy_len (
724 #line 71 "poly1.pcc"
725 a_LIST<int> *
726 #line 71 "poly1.pcc"
729 #line 78 "poly1.pcc"
731 if (l) {
732 if (l->_2) {
733 if (l->_2->_2) {
734 if (l->_2->_2->_2) {
735 if (l->_2->_2->_2->_2) {
736 #line 78 "poly1.pcc"
737 return 5;
738 #line 78 "poly1.pcc"
739 } else {
740 #line 77 "poly1.pcc"
741 return 4;
742 #line 77 "poly1.pcc"
744 } else {
745 #line 76 "poly1.pcc"
746 return 3;
747 #line 76 "poly1.pcc"
749 } else {
750 #line 75 "poly1.pcc"
751 return 2;
752 #line 75 "poly1.pcc"
754 } else {
755 #line 74 "poly1.pcc"
756 return 1;
757 #line 74 "poly1.pcc"
759 } else {
760 #line 73 "poly1.pcc"
761 return 0;
762 #line 73 "poly1.pcc"
765 #line 79 "poly1.pcc"
766 #line 79 "poly1.pcc"
770 /////////////////////////////////////////////////////////////////////////////
771 // Depth of a tree
772 /////////////////////////////////////////////////////////////////////////////
773 template <class X, class Y>
774 int depth (
775 #line 86 "poly1.pcc"
776 a_TREE<X, Y> *
777 #line 86 "poly1.pcc"
780 #line 92 "poly1.pcc"
782 if (t) {
783 if (t->tag__) {
785 #line 90 "poly1.pcc"
786 int a = depth(_node(t)->_1), b = depth(_node(t)->_3);
787 return 1 + (a > b ? a : b);
789 #line 92 "poly1.pcc"
790 } else {
792 #line 89 "poly1.pcc"
793 return 1;
795 #line 90 "poly1.pcc"
797 } else {
798 #line 88 "poly1.pcc"
799 return 0;
801 #line 89 "poly1.pcc"
804 #line 92 "poly1.pcc"
805 #line 92 "poly1.pcc"
810 int main()
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"
818 E = empty;
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));
831 a_LIST<int> *
832 #line 109 "poly1.pcc"
833 list1 =
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"
841 a_LIST<EXP> *
842 #line 110 "poly1.pcc"
843 list2 =
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"
851 a_LIST<EXP> *
852 #line 111 "poly1.pcc"
853 list3 =
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';
871 return 0;
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
880 Number of labels = 0
881 Number of gotos = 0
882 Adaptive matching = disabled
883 Fast string matching = disabled
884 Inline downcasts = disabled
885 --------------------------------------------------------------------------