This file is indexed.

/usr/include/Synopsis/Parser.hh is in libsynopsis0.12-dev 0.12-10.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
//
// Copyright (C) 1997 Shigeru Chiba
// Copyright (C) 2000 Stefan Seefeld
// All rights reserved.
// Licensed to the public under the terms of the GNU LGPL (>= 2),
// see the file COPYING for details.
//
#ifndef Synopsis_Parser_hh_
#define Synopsis_Parser_hh_

#include <Synopsis/PTree.hh>
#include <Synopsis/SymbolFactory.hh>
#include <vector>

namespace Synopsis
{

class Lexer;
struct Token;

//. C++ Parser
//.
//. This parser is a LL(k) parser with ad hoc rules such as
//. backtracking.
//.
//. <name>() is the grammer rule for a non-terminal <name>.
//. opt_<name>() is the grammer rule for an optional non-terminal <name>.
//. is_<name>() looks ahead and returns true if the next symbol is <name>.
class Parser
{
public:
  //. RuleSet defines non-standard optional rules that can be chosen at runtime.
  enum RuleSet { CXX = 0x01, GCC = 0x02, MSVC = 0x04};

  //. Error is used to cache parse errors encountered during the execution
  //. of the parse method.
  class Error
  {
  public:
    virtual ~Error() {}
    virtual void write(std::ostream &) const = 0;
  };
  typedef std::vector<Error *> ErrorList;

  Parser(Lexer &lexer, SymbolFactory &symbols, int ruleset = CXX|GCC);
  ~Parser();

  ErrorList const &errors() const { return my_errors;}

  //. Return the origin of the given pointer
  //. (filename and line number)
  unsigned long origin(const char *, std::string &) const;

  PTree::Node *parse();

private:
  enum DeclKind { kDeclarator, kArgDeclarator, kCastDeclarator };
  enum TemplateDeclKind { tdk_unknown, tdk_decl, tdk_instantiation, 
			  tdk_specialization, num_tdks };

  struct ScopeGuard;
  friend struct ScopeGuard;

  //. A StatusGuard manages a tentative parse.
  //. All actions invoked after its instantiation
  //. will be rolled back in the destructor unless
  //. 'commit' has been called before.
  class StatusGuard
  {
  public:
    StatusGuard(Parser &);
    ~StatusGuard();
    void commit() { my_committed = true;}

  private:
    Lexer &                      my_lexer;
    char const *                 my_token_mark;
    ErrorList                    my_errors;
    Parser::ErrorList::size_type my_error_mark;
    bool                         my_committed;
  };
  friend class StatusGuard;


  bool mark_error();
  template <typename T>
  bool declare(T *);
  void show_message_head(const char*);

  bool definition(PTree::Node *&);
  bool null_declaration(PTree::Node *&);
  bool typedef_(PTree::Typedef *&);
  bool type_specifier(PTree::Node *&, bool, PTree::Encoding&);
  bool is_type_specifier();
  bool metaclass_decl(PTree::Node *&);
  bool meta_arguments(PTree::Node *&);
  bool linkage_spec(PTree::Node *&);
  bool namespace_spec(PTree::NamespaceSpec *&);
  bool namespace_alias(PTree::NamespaceAlias *&);
  bool using_directive(PTree::UsingDirective *&);
  bool using_declaration(PTree::UsingDeclaration *&);
  bool linkage_body(PTree::Node *&);
  bool template_decl(PTree::Node *&);
  bool template_decl2(PTree::TemplateDecl *&, TemplateDeclKind &kind);

  //. template-parameter-list:
  //.
  //. - template-parameter
  //. - template-parameter-list `,` template-parameter
  bool template_parameter_list(PTree::List *&);

  //. template-parameter:
  //.
  //. - type-parameter
  //. - parameter-declaration
  bool template_parameter(PTree::Node *&);

  //. type-parameter:
  //.
  //. - class identifier [opt]
  //. - class identifier [opt] `=` type-id
  //. - typename identifier [opt]
  //. - typename identifier [opt] `=` type-id
  //. - template  `<` template-parameter-list `>` class identifier [opt]
  //. - template  `<` template-parameter-list `>` class identifier [opt] `=` id-expression
  bool type_parameter(PTree::Node *&);
  
  //. GNU extension:
  //. extern-template-decl:
  //.
  //. - extern template declaration
  bool extern_template_decl(PTree::Node *&);

  bool declaration(PTree::Declaration *&);
  bool integral_declaration(PTree::Declaration *&, PTree::Encoding&, PTree::Node *, PTree::Node *, PTree::Node *);
  bool const_declaration(PTree::Declaration *&, PTree::Encoding&, PTree::Node *, PTree::Node *);
  bool other_declaration(PTree::Declaration *&, PTree::Encoding&, PTree::Node *, PTree::Node *, PTree::Node *);

  //. condition:
  //.
  //. - expression
  //. - type-specifier-seq declarator `=` assignment-expression
  bool condition(PTree::Node *&);

  bool is_constructor_decl();
  bool is_ptr_to_member(int);
  bool opt_member_spec(PTree::Node *&);

  //. storage-spec:
  //.
  //. - empty
  //. - static
  //. - extern
  //. - auto
  //. - register
  //. - mutable
  bool opt_storage_spec(PTree::Node *&);

  //. cv-qualifier:
  //.
  //. - empty
  //. - const
  //. - volatile
  bool opt_cv_qualifier(PTree::Node *&);
  bool opt_integral_type_or_class_spec(PTree::Node *&, PTree::Encoding&);
  bool constructor_decl(PTree::Node *&, PTree::Encoding&);
  bool opt_throw_decl(PTree::Node *&);
  
  //. [gram.dcl.decl]
  bool init_declarator_list(PTree::Node *&, PTree::Encoding&, bool, bool = false);
  bool init_declarator(PTree::Node *&, PTree::Encoding&, bool, bool);
  bool declarator(PTree::Node *&, DeclKind, bool,
		  PTree::Encoding&, PTree::Encoding&, bool,
		  bool = false);
  bool declarator2(PTree::Node *&, DeclKind, bool,
		   PTree::Encoding&, PTree::Encoding&, bool,
		   bool, PTree::Node **);
  bool opt_ptr_operator(PTree::Node *&, PTree::Encoding&);
  bool member_initializers(PTree::Node *&);
  bool member_init(PTree::Node *&);
  
  bool name(PTree::Node *&, PTree::Encoding&);
  bool operator_name(PTree::Node *&, PTree::Encoding&);
  bool cast_operator_name(PTree::Node *&, PTree::Encoding&);
  bool ptr_to_member(PTree::Node *&, PTree::Encoding&);
  bool template_args(PTree::Node *&, PTree::Encoding&);
  
  bool parameter_declaration_list_or_init(PTree::Node *&, bool&,
					  PTree::Encoding&, bool);
  bool parameter_declaration_list(PTree::Node *&, PTree::Encoding&);

  //. parameter-declaration:
  //.
  //. - decl-specifier-seq declarator
  //. - decl-specifier-seq declarator `=` assignment-expression
  //. - decl-specifier-seq abstract-declarator [opt]
  //. - decl-specifier-seq abstract-declarator [opt] `=` assignment-expression
  bool parameter_declaration(PTree::ParameterDeclaration *&, PTree::Encoding&);
  
  bool function_arguments(PTree::Node *&);
  bool designation(PTree::Node *&);
  bool initialize_expr(PTree::Node *&);
  
  bool enum_spec(PTree::EnumSpec *&, PTree::Encoding&);
  bool enum_body(PTree::Node *&);
  bool class_spec(PTree::ClassSpec *&, PTree::Encoding&);

  //. base-clause:
  //.
  //. - `:` base-specifier-list
  //.
  //. base-specifier-list:
  //.
  //. - base-specifier
  //. - base-specifier-list `,` base-specifier
  //.
  //. base-specifier:
  //.
  //. - virtual access-specifier [opt] `::` [opt] nested-name-specifier [opt] class-name
  //. - access-specifier virtual [opt] `::` [opt] nested-name-specifier [opt] class-name
  bool base_clause(PTree::Node *&);
  bool class_body(PTree::ClassBody *&);
  bool class_member(PTree::Node *&);
  bool access_decl(PTree::Node *&);
  bool user_access_spec(PTree::Node *&);
  
  //. expression:
  //.
  //. - assignment-expression
  //. - expression `,` assignment-expression
  bool expression(PTree::Node *&);

  //. assignment-expression:
  //.
  //. - conditional-expression
  //. - logical-or-expression assignment-operator assignment-expression
  //. - throw-expression
  bool assign_expr(PTree::Node *&);

  //. conditional-expression:
  //.
  //. - logical-or-expression
  //. - logical-or-expression `?` expression `:` assignment-expression
  bool conditional_expr(PTree::Node *&);

  //. logical-or-expression:
  //.
  //. - logical-and-expression
  //. - logical-or-expression `||` logical-and-expression
  bool logical_or_expr(PTree::Node *&);

  //. logical-and-expression:
  //.
  //. - inclusive-or-expression
  //. - logical-and-expr `&&` inclusive-or-expression
  bool logical_and_expr(PTree::Node *&);

  //. inclusive-or-expression:
  //.
  //. - exclusive-or-expression
  //. - inclusive-or-expression `|` exclusive-or-expression
  bool inclusive_or_expr(PTree::Node *&);

  //. exclusive-or-expression:
  //.
  //. - and-expression
  //. - exclusive-or-expression `^` and-expression
  bool exclusive_or_expr(PTree::Node *&);

  //. and-expression:
  //.
  //. - equality-expression
  //. - and-expression `&` equality-expression
  bool and_expr(PTree::Node *&);

  //. equality-expression:
  //.
  //. - relational-expression
  //. - equality-expression `==` relational-expression
  //. - equality-expression `!=` relational-expression
  bool equality_expr(PTree::Node *&);

  //. relational-expression:
  //.
  //. - shift-expression
  //. - relational-expression `<` shift-expression
  //. - relational-expression `>` shift-expression
  //. - relational-expression `<=` shift-expression
  //. - relational-expression `>=` shift-expression
  bool relational_expr(PTree::Node *&);

  //. shift-expression:
  //.
  //. - additive-expression
  //. - shift-expression `<<` additive-expression
  //. - shift-expression `>>` additive-expression
  bool shift_expr(PTree::Node *&);

  //. additive-expression:
  //.
  //. - multiplicative-expression
  //. - additive-expression `+` multiplicative-expression
  //. - additive-expression `-` multiplicative-expression
  bool additive_expr(PTree::Node *&);

  //. multiplicative-expression:
  //.
  //. - pm-expression
  //. - multiplicative-expression `*` pm-expression
  //. - multiplicative-expression `/` pm-expression
  //. - multiplicative-expression `%` pm-expression
  bool multiplicative_expr(PTree::Node *&);

  //. pm-expression:
  //.
  //. - cast-expression
  //. - pm-expression `.*` cast-expression
  //. - pm-expression `->*` cast-expression
  bool pm_expr(PTree::Node *&);

  //. cast-expression:
  //.
  //. - unary-expression
  //. - `(` type-id `)` cast-expression
  bool cast_expr(PTree::Node *&);

  //. type-id:
  //.
  //. - type-specifier-seq abstract-declarator [opt]
  bool type_id(PTree::Node *&);
  bool type_id(PTree::Node *&, PTree::Encoding&);

  //. unary-expression:
  //.
  //. - postfix-expression
  //. - `++` cast-expression
  //. - `--` cast-expression
  //. - unary-operator cast-expression
  //. - `sizeof` unary-expression
  //. - `sizeof` `(` unary-expression `)`
  //. - new-expression
  //. - delete-expression
  //.
  //. unary-operator:
  //.
  //. - `*`
  //. - `&`
  //. - `+`
  //. - `-`
  //. - `!`
  //. - `~`
  bool unary_expr(PTree::Node *&);

  //. throw-expression:
  //.
  //. - `throw` assignment-expression
  bool throw_expr(PTree::Node *&);

  //. sizeof-expression:
  //.
  //. - `sizeof` unary-expression
  //. - `sizeof` `(` type-id `)`
  bool sizeof_expr(PTree::Node *&);

  bool offsetof_expr(PTree::Node *&);

  //. typeid-expression:
  //.
  //. - typeid `(` type-id `)`
  //. - typeid `(` expression `)`
  bool typeid_expr(PTree::Node *&);
  bool is_allocate_expr(Token::Type);
  bool allocate_expr(PTree::Node *&);
  bool userdef_keyword(PTree::Node *&);
  bool allocate_type(PTree::Node *&);
  bool new_declarator(PTree::Declarator *&, PTree::Encoding&);
  bool allocate_initializer(PTree::Node *&);
  bool postfix_expr(PTree::Node *&);
  bool primary_expr(PTree::Node *&);
  bool typeof_expr(PTree::Node *&);
  bool userdef_statement(PTree::Node *&);
  bool var_name(PTree::Node *&);
  bool var_name_core(PTree::Node *&, PTree::Encoding&);
  bool is_template_args();
  
  //. function-body:
  //.
  //. - compound-statement
  bool function_body(PTree::Block *&);

  //. compound-statement:
  //.
  //. - `{` statement [opt] `}`
  bool compound_statement(PTree::Block *&, bool create_scope = false);
  bool statement(PTree::Node *&);

  //. if-statement:
  //.
  //. - `if` `(` condition `)` statement
  //. - `if` `(` condition `)` statement else statement
  bool if_statement(PTree::Node *&);

  //. switch-statement:
  //.
  //. - `switch` `(` condition `)` statement
  bool switch_statement(PTree::Node *&);

  //. while-statement:
  //.
  //. - `while` `(` condition `)` statement
  bool while_statement(PTree::Node *&);

  //. do-statement:
  //.
  //. - `do` statement `while` `(` condition `)` `;`
  bool do_statement(PTree::Node *&);
  bool for_statement(PTree::Node *&);

  //. try-block:
  //.
  //. - `try` compound-statement handler-seq
  //.
  //. handler-seq:
  //.
  //. - handler handler-seq [opt]
  //.
  //. handler:
  //.
  //. - `catch` `(` exception-declaration `)` compound-statement
  //.
  //. exception-declaration:
  //.
  //. - type-specifier-seq declarator
  //. - type-specifier-seq abstract-declarator
  //. - type-specifier-seq
  //. - `...`
  bool try_block(PTree::Node *&);
  
  bool expr_statement(PTree::Node *&);
  bool declaration_statement(PTree::Declaration *&);
  bool integral_decl_statement(PTree::Declaration *&, PTree::Encoding&, PTree::Node *, PTree::Node *, PTree::Node *);
  bool other_decl_statement(PTree::Declaration *&, PTree::Encoding&, PTree::Node *, PTree::Node *);

  bool maybe_typename_or_class_template(Token&);
  void skip_to(Token::Type token);
  
private:
  bool more_var_name();

  Lexer &         my_lexer;
  int             my_ruleset;
  SymbolFactory & my_symbols;
  //. Record whether the current scope is valid.
  //. This allows the parser to continue parsing even after
  //. it was unable to enter a scope (such as in a function definition
  //. with a qualified name that wasn't declared before).
  bool            my_scope_is_valid;
  ErrorList       my_errors;
  PTree::Node *   my_comments;
  //. If true, `>` is interpreted as ther greater-than operator.
  //. If false, it marks the end of a template-id or template-parameter-list.
  bool            my_gt_is_operator;
  bool            my_in_template_decl;
};

}

#endif