File: Synopsis/Parser.hh 1
2
3
4
5
6
7
8#ifndef Synopsis_Parser_hh_
9#define Synopsis_Parser_hh_
10
11#include <Synopsis/PTree.hh>
12#include <Synopsis/SymbolFactory.hh>
13#include <vector>
14
15namespace Synopsis
16{
17
18class Lexer;
19struct Token;
20
21
22
23
24
25
26
27
28
29class Parser
30{
31public:
32
33 enum RuleSet { CXX = 0x01, GCC = 0x02, MSVC = 0x04};
34
35
36
37 class Error
38 {
39 public:
40 virtual ~Error() {}
41 virtual void write(std::ostream &) const = 0;
42 };
43 typedef std::vector<Error *> ErrorList;
44
45 Parser(Lexer &lexer, SymbolFactory &symbols, int ruleset = CXX|GCC);
46 ~Parser();
47
48 ErrorList const &errors() const { return my_errors;}
49
50
51
52 unsigned long origin(const char *, std::string &) const;
53
54 PTree::Node *parse();
55
56private:
57 enum DeclKind { kDeclarator, kArgDeclarator, kCastDeclarator };
58 enum TemplateDeclKind { tdk_unknown, tdk_decl, tdk_instantiation,
59 tdk_specialization, num_tdks };
60
61 struct ScopeGuard;
62 friend struct ScopeGuard;
63
64
65
66
67
68 class StatusGuard
69 {
70 public:
71 StatusGuard(Parser &);
72 ~StatusGuard();
73 void commit() { my_committed = true;}
74
75 private:
76 Lexer & my_lexer;
77 char const * my_token_mark;
78 ErrorList my_errors;
79 Parser::ErrorList::size_type my_error_mark;
80 bool my_committed;
81 };
82 friend class StatusGuard;
83
84
85 bool mark_error();
86 template <typename T>
87 bool declare(T *);
88 void show_message_head(const char*);
89
90 bool definition(PTree::Node *&);
91 bool null_declaration(PTree::Node *&);
92 bool typedef_(PTree::Typedef *&);
93 bool type_specifier(PTree::Node *&, bool, PTree::Encoding&);
94 bool is_type_specifier();
95 bool metaclass_decl(PTree::Node *&);
96 bool meta_arguments(PTree::Node *&);
97 bool linkage_spec(PTree::Node *&);
98 bool namespace_spec(PTree::NamespaceSpec *&);
99 bool namespace_alias(PTree::NamespaceAlias *&);
100 bool using_directive(PTree::UsingDirective *&);
101 bool using_declaration(PTree::UsingDeclaration *&);
102 bool linkage_body(PTree::Node *&);
103 bool template_decl(PTree::Node *&);
104 bool template_decl2(PTree::TemplateDecl *&, TemplateDeclKind &kind);
105
106
107
108
109
110 bool template_parameter_list(PTree::List *&);
111
112
113
114
115
116 bool template_parameter(PTree::Node *&);
117
118
119
120
121
122
123
124
125
126 bool type_parameter(PTree::Node *&);
127
128
129
130
131
132 bool extern_template_decl(PTree::Node *&);
133
134 bool declaration(PTree::Declaration *&);
135 bool integral_declaration(PTree::Declaration *&, PTree::Encoding&, PTree::Node *, PTree::Node *, PTree::Node *);
136 bool const_declaration(PTree::Declaration *&, PTree::Encoding&, PTree::Node *, PTree::Node *);
137 bool other_declaration(PTree::Declaration *&, PTree::Encoding&, PTree::Node *, PTree::Node *, PTree::Node *);
138
139
140
141
142
143 bool condition(PTree::Node *&);
144
145 bool is_constructor_decl();
146 bool is_ptr_to_member(int);
147 bool opt_member_spec(PTree::Node *&);
148
149
150
151
152
153
154
155
156
157 bool opt_storage_spec(PTree::Node *&);
158
159
160
161
162
163
164 bool opt_cv_qualifier(PTree::Node *&);
165 bool opt_integral_type_or_class_spec(PTree::Node *&, PTree::Encoding&);
166 bool constructor_decl(PTree::Node *&, PTree::Encoding&);
167 bool opt_throw_decl(PTree::Node *&);
168
169
170 bool init_declarator_list(PTree::Node *&, PTree::Encoding&, bool, bool = false);
171 bool init_declarator(PTree::Node *&, PTree::Encoding&, bool, bool);
172 bool declarator(PTree::Node *&, DeclKind, bool,
173 PTree::Encoding&, PTree::Encoding&, bool,
174 bool = false);
175 bool declarator2(PTree::Node *&, DeclKind, bool,
176 PTree::Encoding&, PTree::Encoding&, bool,
177 bool, PTree::Node **);
178 bool opt_ptr_operator(PTree::Node *&, PTree::Encoding&);
179 bool member_initializers(PTree::Node *&);
180 bool member_init(PTree::Node *&);
181
182 bool name(PTree::Node *&, PTree::Encoding&);
183 bool operator_name(PTree::Node *&, PTree::Encoding&);
184 bool cast_operator_name(PTree::Node *&, PTree::Encoding&);
185 bool ptr_to_member(PTree::Node *&, PTree::Encoding&);
186 bool template_args(PTree::Node *&, PTree::Encoding&);
187
188 bool parameter_declaration_list_or_init(PTree::Node *&, bool&,
189 PTree::Encoding&, bool);
190 bool parameter_declaration_list(PTree::Node *&, PTree::Encoding&);
191
192
193
194
195
196
197
198 bool parameter_declaration(PTree::ParameterDeclaration *&, PTree::Encoding&);
199
200 bool function_arguments(PTree::Node *&);
201 bool designation(PTree::Node *&);
202 bool initialize_expr(PTree::Node *&);
203
204 bool enum_spec(PTree::EnumSpec *&, PTree::Encoding&);
205 bool enum_body(PTree::Node *&);
206 bool class_spec(PTree::ClassSpec *&, PTree::Encoding&);
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221 bool base_clause(PTree::Node *&);
222 bool class_body(PTree::ClassBody *&);
223 bool class_member(PTree::Node *&);
224 bool access_decl(PTree::Node *&);
225 bool user_access_spec(PTree::Node *&);
226
227
228
229
230
231 bool expression(PTree::Node *&);
232
233
234
235
236
237
238 bool assign_expr(PTree::Node *&);
239
240
241
242
243
244 bool conditional_expr(PTree::Node *&);
245
246
247
248
249
250 bool logical_or_expr(PTree::Node *&);
251
252
253
254
255
256 bool logical_and_expr(PTree::Node *&);
257
258
259
260
261
262 bool inclusive_or_expr(PTree::Node *&);
263
264
265
266
267
268 bool exclusive_or_expr(PTree::Node *&);
269
270
271
272
273
274 bool and_expr(PTree::Node *&);
275
276
277
278
279
280
281 bool equality_expr(PTree::Node *&);
282
283
284
285
286
287
288
289
290 bool relational_expr(PTree::Node *&);
291
292
293
294
295
296
297 bool shift_expr(PTree::Node *&);
298
299
300
301
302
303
304 bool additive_expr(PTree::Node *&);
305
306
307
308
309
310
311
312 bool multiplicative_expr(PTree::Node *&);
313
314
315
316
317
318
319 bool pm_expr(PTree::Node *&);
320
321
322
323
324
325 bool cast_expr(PTree::Node *&);
326
327
328
329
330 bool type_id(PTree::Node *&);
331 bool type_id(PTree::Node *&, PTree::Encoding&);
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352 bool unary_expr(PTree::Node *&);
353
354
355
356
357 bool throw_expr(PTree::Node *&);
358
359
360
361
362
363 bool sizeof_expr(PTree::Node *&);
364
365 bool offsetof_expr(PTree::Node *&);
366
367
368
369
370
371 bool typeid_expr(PTree::Node *&);
372 bool is_allocate_expr(Token::Type);
373 bool allocate_expr(PTree::Node *&);
374 bool userdef_keyword(PTree::Node *&);
375 bool allocate_type(PTree::Node *&);
376 bool new_declarator(PTree::Declarator *&, PTree::Encoding&);
377 bool allocate_initializer(PTree::Node *&);
378 bool postfix_expr(PTree::Node *&);
379 bool primary_expr(PTree::Node *&);
380 bool typeof_expr(PTree::Node *&);
381 bool userdef_statement(PTree::Node *&);
382 bool var_name(PTree::Node *&);
383 bool var_name_core(PTree::Node *&, PTree::Encoding&);
384 bool is_template_args();
385
386
387
388
389 bool function_body(PTree::Block *&);
390
391
392
393
394 bool compound_statement(PTree::Block *&, bool create_scope = false);
395 bool statement(PTree::Node *&);
396
397
398
399
400
401 bool if_statement(PTree::Node *&);
402
403
404
405
406 bool switch_statement(PTree::Node *&);
407
408
409
410
411 bool while_statement(PTree::Node *&);
412
413
414
415
416 bool do_statement(PTree::Node *&);
417 bool for_statement(PTree::Node *&);
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437 bool try_block(PTree::Node *&);
438
439 bool expr_statement(PTree::Node *&);
440 bool declaration_statement(PTree::Declaration *&);
441 bool integral_decl_statement(PTree::Declaration *&, PTree::Encoding&, PTree::Node *, PTree::Node *, PTree::Node *);
442 bool other_decl_statement(PTree::Declaration *&, PTree::Encoding&, PTree::Node *, PTree::Node *);
443
444 bool maybe_typename_or_class_template(Token&);
445 void skip_to(Token::Type token);
446
447private:
448 bool more_var_name();
449
450 Lexer & my_lexer;
451 int my_ruleset;
452 SymbolFactory & my_symbols;
453
454
455
456
457 bool my_scope_is_valid;
458 ErrorList my_errors;
459 PTree::Node * my_comments;
460
461
462 bool my_gt_is_operator;
463 bool my_in_template_decl;
464};
465
466}
467
468#endif
Generated on Thu Apr 16 16:28:04 2009 by
synopsis (version devel)