simple.cc - generated code example
[prop.git] / prop-src / simple.cc
blobc257ddbdbadca3b6813dd23253a42dd516cb282a
1 ///////////////////////////////////////////////////////////////////////////////
2 // This file is generated automatically using Prop (version 2.3.7),
3 // last updated on Oct 21, 2008.
4 // The original source file is "simple.pcc".
5 ///////////////////////////////////////////////////////////////////////////////
7 #line 1 "simple.pcc"
8 #include <iostream>
9 #include <memory>
11 #line 4 "simple.pcc"
12 #line 9 "simple.pcc"
13 ///////////////////////////////////////////////////////////////////////////////
15 // Forward class definition for Exp
17 ///////////////////////////////////////////////////////////////////////////////
18 #ifndef datatype_Exp_defined
19 #define datatype_Exp_defined
20 class a_Exp;
21 typedef a_Exp * Exp;
22 #endif
24 ///////////////////////////////////////////////////////////////////////////////
26 // Base class for datatype Exp
28 ///////////////////////////////////////////////////////////////////////////////
29 class a_Exp {
30 public:
31 enum Tag_Exp {
32 tag_INT = 0, tag_ADD = 1, tag_SUB = 2,
33 tag_MUL = 3, tag_DIV = 4
36 public:
37 const Tag_Exp tag__; // variant tag
38 protected:
39 inline a_Exp(Tag_Exp t__) : tag__(t__) {}
40 public:
42 inline int boxed(const a_Exp *) { return 1; }
43 inline int untag(const a_Exp * x) { return x->tag__; }
44 ///////////////////////////////////////////////////////////////////////////////
46 // Class for datatype constructor Exp::INT
48 ///////////////////////////////////////////////////////////////////////////////
49 class Exp_INT : public a_Exp {
50 public:
51 #line 4 "simple.pcc"
52 int INT;
53 inline Exp_INT (int x_INT)
54 : a_Exp(tag_INT), INT(x_INT)
59 ///////////////////////////////////////////////////////////////////////////////
61 // Class for datatype constructor Exp::ADD
63 ///////////////////////////////////////////////////////////////////////////////
64 class Exp_ADD : public a_Exp {
65 public:
66 #line 5 "simple.pcc"
67 Exp _1; Exp _2;
68 inline Exp_ADD (Exp x_1, Exp x_2)
69 : a_Exp(tag_ADD), _1(x_1), _2(x_2)
74 ///////////////////////////////////////////////////////////////////////////////
76 // Class for datatype constructor Exp::SUB
78 ///////////////////////////////////////////////////////////////////////////////
79 class Exp_SUB : public a_Exp {
80 public:
81 #line 6 "simple.pcc"
82 Exp _1; Exp _2;
83 inline Exp_SUB (Exp x_1, Exp x_2)
84 : a_Exp(tag_SUB), _1(x_1), _2(x_2)
89 ///////////////////////////////////////////////////////////////////////////////
91 // Class for datatype constructor Exp::MUL
93 ///////////////////////////////////////////////////////////////////////////////
94 class Exp_MUL : public a_Exp {
95 public:
96 #line 7 "simple.pcc"
97 Exp _1; Exp _2;
98 inline Exp_MUL (Exp x_1, Exp x_2)
99 : a_Exp(tag_MUL), _1(x_1), _2(x_2)
104 ///////////////////////////////////////////////////////////////////////////////
106 // Class for datatype constructor Exp::DIV
108 ///////////////////////////////////////////////////////////////////////////////
109 class Exp_DIV : public a_Exp {
110 public:
111 #line 8 "simple.pcc"
112 Exp _1; Exp _2;
113 inline Exp_DIV (Exp x_1, Exp x_2)
114 : a_Exp(tag_DIV), _1(x_1), _2(x_2)
119 ///////////////////////////////////////////////////////////////////////////////
121 // Datatype constructor functions for Exp
123 ///////////////////////////////////////////////////////////////////////////////
124 inline a_Exp * INT (int x_INT)
126 return new Exp_INT (x_INT);
128 inline a_Exp * ADD (Exp x_1, Exp x_2)
130 return new Exp_ADD (x_1, x_2);
132 inline a_Exp * SUB (Exp x_1, Exp x_2)
134 return new Exp_SUB (x_1, x_2);
136 inline a_Exp * MUL (Exp x_1, Exp x_2)
138 return new Exp_MUL (x_1, x_2);
140 inline a_Exp * DIV (Exp x_1, Exp x_2)
142 return new Exp_DIV (x_1, x_2);
144 ///////////////////////////////////////////////////////////////////////////////
146 // Downcasting functions for Exp
148 ///////////////////////////////////////////////////////////////////////////////
149 inline Exp_INT * _INT(const a_Exp * _x_) { return (Exp_INT *)_x_; }
150 inline Exp_ADD * _ADD(const a_Exp * _x_) { return (Exp_ADD *)_x_; }
151 inline Exp_SUB * _SUB(const a_Exp * _x_) { return (Exp_SUB *)_x_; }
152 inline Exp_MUL * _MUL(const a_Exp * _x_) { return (Exp_MUL *)_x_; }
153 inline Exp_DIV * _DIV(const a_Exp * _x_) { return (Exp_DIV *)_x_; }
155 #line 9 "simple.pcc"
156 #line 9 "simple.pcc"
159 #line 11 "simple.pcc"
160 #line 11 "simple.pcc"
161 ///////////////////////////////////////////////////////////////////////////////
163 // Forward class definition for Q
165 ///////////////////////////////////////////////////////////////////////////////
166 #ifndef datatype_Q_defined
167 #define datatype_Q_defined
168 class a_Q;
169 typedef a_Q * Q;
170 #endif
172 ///////////////////////////////////////////////////////////////////////////////
174 // Base class for datatype Q
176 ///////////////////////////////////////////////////////////////////////////////
177 class a_Q {
178 public:
179 enum Tag_Q {
180 tag_Expr = 0, tag_Str = 1
183 public:
184 const Tag_Q tag__; // variant tag
185 protected:
186 inline a_Q(Tag_Q t__) : tag__(t__) {}
187 public:
189 inline int boxed(const a_Q *) { return 1; }
190 inline int untag(const a_Q * x) { return x->tag__; }
191 ///////////////////////////////////////////////////////////////////////////////
193 // Class for datatype constructor Q::Expr
195 ///////////////////////////////////////////////////////////////////////////////
196 class Q_Expr : public a_Q {
197 public:
198 #line 11 "simple.pcc"
199 Exp Expr;
200 inline Q_Expr (Exp x_Expr)
201 : a_Q(tag_Expr), Expr(x_Expr)
206 ///////////////////////////////////////////////////////////////////////////////
208 // Class for datatype constructor Q::Str
210 ///////////////////////////////////////////////////////////////////////////////
211 class Q_Str : public a_Q {
212 public:
213 #line 11 "simple.pcc"
214 std::string Str;
215 inline Q_Str (std::string x_Str)
216 : a_Q(tag_Str), Str(x_Str)
221 ///////////////////////////////////////////////////////////////////////////////
223 // Datatype constructor functions for Q
225 ///////////////////////////////////////////////////////////////////////////////
226 inline a_Q * Expr (Exp x_Expr)
228 return new Q_Expr (x_Expr);
230 inline a_Q * Str (std::string x_Str)
232 return new Q_Str (x_Str);
234 ///////////////////////////////////////////////////////////////////////////////
236 // Downcasting functions for Q
238 ///////////////////////////////////////////////////////////////////////////////
239 inline Q_Expr * _Expr(const a_Q * _x_) { return (Q_Expr *)_x_; }
240 inline Q_Str * _Str(const a_Q * _x_) { return (Q_Str *)_x_; }
242 #line 11 "simple.pcc"
243 #line 11 "simple.pcc"
246 int main()
248 std::auto_ptr<a_Q> q(Expr(ADD(INT(2),INT(3))));
251 #line 17 "simple.pcc"
252 #line 19 "simple.pcc"
254 Q _V1 = q.get();
255 if (_V1->tag__) {
257 #line 19 "simple.pcc"
258 std::cout << _Str(_V1)->Str << std::endl;
259 #line 19 "simple.pcc"
260 } else {
262 #line 18 "simple.pcc"
263 std::cout << "expr" << std::endl;
264 #line 18 "simple.pcc"
267 #line 20 "simple.pcc"
268 #line 20 "simple.pcc"
271 return 0;
273 #line 24 "simple.pcc"
275 ------------------------------- Statistics -------------------------------
276 Merge matching rules = yes
277 Number of DFA nodes merged = 0
278 Number of ifs generated = 1
279 Number of switches generated = 0
280 Number of labels = 0
281 Number of gotos = 0
282 Adaptive matching = disabled
283 Fast string matching = disabled
284 Inline downcasts = disabled
285 --------------------------------------------------------------------------