summaryrefslogtreecommitdiffstats
path: root/debian/uncrustify-trinity/uncrustify-trinity-0.78.1/src/EnumStructUnionParser.h
blob: 136a0eb77624c05645f21eb035e13542af653317 (plain)
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
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
/**
 * @file combine_fix_mark_enum_struct_union.h
 *
 * @author  Joshua Parker
 * @license GPL v2+
 * extract from combine_fix_mark.h
 */

#ifndef ENUM_STRUCT_UNION_PARSER_H_INCLUDED
#define ENUM_STRUCT_UNION_PARSER_H_INCLUDED

#include "pcf_flags.h"
#include "token_enum.h"
#include "uncrustify_types.h"
#include <map>


/**
 * Class EnumStructUnionParser : This class facilitates the parsing and interpretation
 *                               of ALL instances of the class, enum, union, and
 *                               struct keywords, including user-defined types with
 *                               a body {} and any trailing inline variable declarations
 *                               that may follow the definition (as permitted by
 *                               the coding language in question). The class also
 *                               interprets variable declarations preceded by one
 *                               of those keywords, as well as any C/C++ forward
 *                               declarations
 */
class EnumStructUnionParser
{
public:
   /**
    * Constructor
    */
   EnumStructUnionParser();


   /**
    * Destructor
    */
   ~EnumStructUnionParser();


private:
   /**
    * Analyzes all identifiers (marked as CT_WORD) between the starting and
    * ending chunks and changes CT_WORD to one of CT_TYPE, CT_MACRO_FUNC_CALL,
    * etc. and sets flags (PCF_VAR_1ST, PCF_VAR_1ST_DEF, PCF_VAR_INLINE, etc.)
    * for variable identifiers accordingly. Flags C++ forward declarations as
    * PCF_INCOMPLETE
    */
   void analyze_identifiers();


   /**
    * Returns true if a pair of braces were both detected AND determined to be
    * part of a class/enum/struct/union body
    */
   bool body_detected() const;


   /**
    * Returns true if comma-separated values were detected during parsing
    */
   bool comma_separated_values_detected() const;


   /**
    * Returns true if an enumerated integral type was detected during parsing
    */
   bool enum_base_detected() const;


   /**
    * Returns the end chunk of a class/enum/struct/union body, if detected
    * during parsing
    */
   Chunk *get_body_end() const;


   /**
    * Returns the starting chunk of a class/enum/struct/union body, if detected
    * during parsing
    */
   Chunk *get_body_start() const;


   /**
    * Returns the starting chunk associated with an enumerated type's base
    * specifier statement, if detected during parsing
    */
   Chunk *get_enum_base_start() const;


   /**
    * Returns the first comma encountered at the level of the starting chunk,
    * if detected during parsing
    */
   Chunk *get_first_top_level_comma() const;


   /**
    * Returns the ending chunk associated with an class/struct inheritance
    * list, if detected during parsing
    */
   Chunk *get_inheritance_end() const;


   /**
    * Returns the starting chunk associated with an class/struct inheritance
    * list, if detected during parsing
    */
   Chunk *get_inheritance_start() const;


   /**
    * Returns a numerically-indexed map of all question operators encountered
    * during parsing
    */
   std::map<std::size_t, Chunk *> get_question_operators() const;


   /**
    * Returns the end chunk associated with a template parameter list, if
    * detected during parsing
    */
   Chunk *get_template_end() const;


   /**
    * Return the starting chunk associated with a template parameter list, if
    * detected during parsing
    */
   Chunk *get_template_start() const;


   /**
    * Returns a numerically-indexed map of all top-level commas encountered
    * during parsing
    */
   std::map<std::size_t, Chunk *> get_top_level_commas() const;


   /**
    * Return the starting chunk associated with a where clause, if
    * detected during parsing
    */
   Chunk *get_where_end() const;


   /**
    * Return the starting chunk associated with a where clause, if
    * detected during parsing
    */
   Chunk *get_where_start() const;


   /**
    * Returns true if an inheritance list associated with a class or struct was
    * discovered during parsing
    */
   bool inheritance_detected() const;


public:
   /**
    * Performs object initialization prior to parsing
    */
   void initialize(Chunk *pc);


private:
   /**
    * Returns true if the chunk under test represents a potential end chunk past
    * which further parsing is not likely warranted
    */
   bool is_potential_end_chunk(Chunk *pc) const;


   /**
    * Returns true if the chunk under test is deemed to be located within a
    * conditional/ternary statement
    */
   bool is_within_conditional(Chunk *pc) const;


   /**
    * Returns true if the chunk under test is deemed to be located within an
    * inheritance list
    */
   bool is_within_inheritance_list(Chunk *pc) const;


   /**
    * Returns true if the chunk under test is deemed to be located within a
    * where clause
    */
   bool is_within_where_clause(Chunk *pc) const;


   /**
    * Marks all base classes that appear as part of an inheritance list
    */
   void mark_base_classes(Chunk *pc);


   /**
    * Marks pairs of braces associated with the body of a class/enum/struct/union,
    * and additionally calls a separate routine to mark any base classes for that
    * may precede the opening brace
    */
   void mark_braces(Chunk *start);


   /**
    * Marks the beginning chunk of an inheritance list
    */
   void mark_class_colon(Chunk *colon);


   /**
    * Mark a colon as a conditional
    */
   void mark_conditional_colon(Chunk *colon);


   /**
    * Mark any struct/class constructor declarations/definitions
    */
   void mark_constructors();


   /**
    * Marks the beginning chunk of an enumerated integral type specification
    */
   void mark_enum_integral_type(Chunk *colon);


   /**
    * Scan chunks outside the definition body and mark lvalues accordingly
    */
   void mark_extracorporeal_lvalues();


   /**
    * Mark nested name specifiers preceding qualified identifiers
    */
   void mark_nested_name_specifiers(Chunk *pc);


   /**
    * Marks pointer operators preceding a variable identifier
    */
   void mark_pointer_types(Chunk *pc);


   /**
    * Marks the beginning and ending chunks associated with a template
    * (templates may appear after the identifier type name as part of a class
    * specialization)
    */
   void mark_template(Chunk *start) const;


   /**
    * Marks the arguments within a template argument list bounded by the
    * starting and ending chunks
    */
   void mark_template_args(Chunk *start, Chunk *end) const;


   /**
    * Marks the type identifier associated with the class/enum/struct/union,
    * if not anonymously defined
    */
   void mark_type(Chunk *pc);


   /**
    * Marks all variable identifiers associated with the class/enum/struct/union
    */
   void mark_variable(Chunk *variable, PcfFlags flags);


   /**
    * Marks all chunks belonging to a c# where clause
    */
   void mark_where_clause(Chunk *where);


   /**
    * Marks the beginning of a where clause
    */
   void mark_where_colon(Chunk *colon);


public:
   /**
    * Parses the class/enum/struct/union and all associated chunks
    */
   void parse(Chunk *pc);


private:
   /**
    * Parses closing and opening angle brackets
    */
   Chunk *parse_angles(Chunk *angle_open);


   /**
    * Parses closing and opening braces
    */
   Chunk *parse_braces(Chunk *brace_open);


   /**
    * Parses a single colon, which may precede an inheritance list or
    * enumerated integral type specification
    */
   void parse_colon(Chunk *colon);


   /**
    * Parses a double colon, which may indicate a scope resolution chain
    */
   Chunk *parse_double_colon(Chunk *double_colon);


   /**
    * Returns the parsing error status
    */
   bool parse_error_detected() const;


   /**
    * Sets the parsing error status
    */
   void parse_error_detected(bool status);


   /**
    * Records all question operators encountered during parsing
    */
   void record_question_operator(Chunk *question);


   /**
    * Records a comma chunk given one the following conditions are satisfied:
    * 1) it is encountered at the level of the starting chunk
    * 2) it is not part of a right-hand side assignment
    * 3) it is not part of an inheritance list
    * 4) it is not part of a conditional/ternary expression
    */
   void record_top_level_comma(Chunk *comma);


   /**
    * Adjusts the end chunk returned by the try_find_end_chunk() function
    * for any potential trailing inline variable declarations that may follow
    * the body of a class/enum/struct/union definition
    */
   Chunk *refine_end_chunk(Chunk *pc);


   /**
    * Sets the chunk associated with the end of a class/enum/struct/union
    * body
    */
   void set_body_end(Chunk *body_end);


   /**
    * Sets the chunk associated with the start of a class/enum/struct/union
    * body
    */
   void set_body_start(Chunk *body_start);


   /**
    * Sets the chunk associated with the start of an enumerated integral
    * base type specification
    */
   void set_enum_base_start(Chunk *enum_base_start);


   /**
    * Sets the chunk associated with the start of an inheritance list
    */
   void set_inheritance_start(Chunk *inheritance_start);


   /**
    * Sets the chunk associated with the end of a template
    */
   void set_template_end(Chunk *template_end);


   /**
    * Sets the chunk associated with the start of a template
    */
   void set_template_start(Chunk *template_start);


   /**
    * Return the ending chunk associated with a where clause, if
    * detected during parsing
    */
   void set_where_end(Chunk *where_end);


   /**
    * Return the starting chunk associated with a where clause, if
    * detected during parsing
    */
   void set_where_start(Chunk *where_start);


   /**
    * Returns true if a template was detected during parsing
    */
   bool template_detected() const;


   /**
    * Attempts to find the last chunk associated with the class/enum/struct/union
    */
   Chunk *try_find_end_chunk(Chunk *pc);


   /**
    * Attempts to identify any function-like macro calls which may precede the
    * actual type identifier
    */
   void try_post_identify_macro_calls();


   /**
    * Attempts to find the identifier type name (if not anonymously-defined) post
    * variable identifier interpretation
    */
   void try_post_identify_type();


   /**
    * Attempts to find the identifier type name prior to variable identifier
    * interpretation
    */
   bool try_pre_identify_type();


   /**
    * Returns true if a corresponding type was identified for the class/enum/struct/union
    */
   bool type_identified() const;


   /**
    * Returns true if a where clause was detected during parsing
    */
   bool where_clause_detected() const;


   /**
    * Map of token-type, chunk pairs
    */
   std::map<E_Token, std::map<std::size_t, Chunk *> > m_chunk_map;


   /**
    * Indicates the last chunk associated with the class/enum/struct/union keyword
    */
   Chunk *m_end;


   /**
    * Indicates whether or not a parse error has occurred
    */
   bool m_parse_error;


   /**
    * Stores a pointer to the class/enum/struct/union keyword chunk with which the
    * parse() routine was invoked
    */
   Chunk *m_start;


   /**
    * Stores a pointer to the type identifier associated with the class/enum/struct/union,
    * if not anonymously defined
    */
   Chunk *m_type;
};


#endif