1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
|
#ifndef __SITECING_SITECING_PARSER_H
#define __SITECING_SITECING_PARSER_H
#include <string>
#include <list>
#include <map>
#include <stdexcept>
using namespace std;
#include "sitecing/component_factory.h"
using namespace sitecing;
/**
* @file
* @brief The component source parser.
*/
#ifndef sitecing_parser_flexlexer_once
#define sitecing_parser_flexlexer_once
#undef yyFlexLexer
#define yyFlexLexer sitecing_parserFlexLexer
#include <FlexLexer.h>
#undef yyFlexLexerOnce
#endif
/**
* The component source parser.
*/
class sitecing_parser : public sitecing_parserFlexLexer {
public:
/**
* The ancestor class definition.
*/
class ancestor_class {
public:
/**
* The class name.
*/
string name;
/**
* The source component path.
*/
string path;
/**
* @param n the class name.
* @param p the component path.
*/
ancestor_class(const string& n,const string& p)
: name(n), path(p) { }
};
/**
* The list of ancestor classes.
*/
typedef list<ancestor_class> ancestor_classes_t;
/**
* The ancestor classes.
*/
ancestor_classes_t ancestor_classes;
/**
* The member variable definition.
*/
class member_variable {
public:
/**
* The member variable type.
*/
string type;
/**
* The member variable name.
*/
string name;
/**
* The member variable is a component.
*/
bool bComponent;
/**
* The variable initializer.
*/
string initializer;
/**
* @todo TODO: wish I could remember -- document me.
*/
bool bTypeOnly;
/**
* @param t type.
* @param n name.
* @param i initializer.
* @param bc whether it is a component.
* @param bto @todo TODO: @see bTypeOnly.
*/
member_variable(const string& t,const string& n,const string& i,bool bc = false,bool bto = false)
: type(t), name(n), initializer(i), bComponent(bc), bTypeOnly(bto) { }
};
/**
* The list of member variables.
*/
typedef list<member_variable> member_variables_t;
/**
* Member variables.
*/
member_variables_t member_variables;
/**
* @todo TODO: wish I could remember the details -- document me.
*/
bool have_initializers;
/**
* Whether the component has a constructor defined.
*/
bool have_constructor;
/**
* Member function definition.
*/
class member_function {
public:
/**
* Return type.
*/
string type;
/**
* Function name.
*/
string name;
/**
* Arguments declaration.
*/
string args;
/**
* Function body.
*/
string body;
/**
* @param t type.
* @param n name.
* @param a arguments.
* @param b body.
*/
member_function(const string& t,const string& n,const string& a,const string& b)
: type(t), name(n), args(a), body(b) { }
};
/**
* The list of member functions.
*/
typedef list<member_function> member_functions_t;
/**
* Member functions.
*/
member_functions_t member_functions;
/**
* Current mode of operation.
*/
class modus_operandi {
public:
/**
* The state enumeration.
*/
enum modus_t {
/**
* Building the code.
*/
modus_code = 0,
/**
* Ready to do the '<<' thing.
*/
modus_preop,
/**
* Just made a '<<'.
*/
modus_postop,
/**
* Outputting raw output data.
*/
modus_text,
/**
* The number of modes.
*/
modi
};
/**
* Processing flags enumeration.
*/
enum {
/**
* Eat the comments.
*/
flag_devour_comments = 0x0001,
/**
* Eat whitespace.
*/
flag_devour_whitespace = 0x0002
};
/**
* The processing mode.
*/
modus_t modus;
/**
* The processing flags.
*/
int flags;
/**
* Output being built.
*/
string output;
/**
* The type for compound modes.
*/
string _type;
/**
* The last id encountered.
*/
string _lastid;
/**
* The name for compound modes.
*/
string _name;
/**
* The argument declaration. Obviously for member functions.
*/
string _args;
/**
* @param flags.
* @see flags
*/
modus_operandi(int f = 0)
: modus(modus_code), flags(f) { }
/**
* Change the processing mode.
*/
void modify(modus_t m);
/**
* See if we're eating up whitespaces.
*/
bool devour_whitespace() { return flags&flag_devour_whitespace; }
/**
* See if we're eating up the comments.
*/
bool devour_comments() { return flags&flag_devour_comments; }
};
/**
* The modes stack type.
*/
typedef list<modus_operandi> modi_operandi;
/**
* The modes stack.
*/
modi_operandi modi;
/**
* Input file name.
*/
string input_file;
/**
* Base class name.
*/
string base_class;
/**
* Base class header.
*/
string base_header;
/**
* Component's basename.
* @todo TODO: wish I could remember the details -- document me.
*/
string component_basename;
/**
* The skeleton file name.
*/
string skeleton;
/**
* The component class name.
*/
string class_name;
/**
* Output basename.
* @todo TODO: wish I could remember the details -- document me.
*/
string output_basename;
/**
* Verbatim declaration part.
*/
string decl;
/**
* Verbatim implementation part.
*/
string impl;
/**
* The reference to the component factory object.
*/
component_factory& factory;
/**
* @param f the component factory.
*/
sitecing_parser(component_factory& f);
/**
* Preprocess file.
* @param in input file name.
*/
void preprocess(const string& in);
virtual void LexerOutput(const char *buf,int size);
virtual int yylex();
/**
* Retrieve reference to the to of the modes stack.
* @return the reference in question.
*/
modus_operandi& M() {
return modi.front();
}
/**
* Anchor the output with the #line, if we're not in the text output mode.
*/
void soft_anchor();
/**
* Anchor the output with the #line directive, changing to the appropriate output mode if needed.
*/
void anchor();
};
#endif /* __SITECING_SITECING_PARSER_H */
|