summaryrefslogtreecommitdiffstats
path: root/debian/uncrustify-trinity/uncrustify-trinity-0.78.0/src/parsing_frame.h
blob: 1431b43d7afbc6ceb23d1ead3f6f04f0e791d3d2 (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
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
/**
 * @file parsing_frame.h
 *
 * Holds data needed for indenting and brace parsing
 *
 * @author  Daniel Chumak
 * @license GPL v2+
 */

#ifndef PARSING_FRAME_H_INCLUDED
#define PARSING_FRAME_H_INCLUDED

#include "uncrustify_types.h"

#include <vector>


//! Class describing a parenthesis stack entry and its information
class ParenStackEntry
{
public:
   ParenStackEntry();

   // --------- Access methods

   /**
    * @brief returns the token that opened the entry
    */
   E_Token GetOpenToken() const;

   /**
    * @brief Sets the token that opened the entry
    * @param token the token to set
    */
   void SetOpenToken(const E_Token token);

   /**
    * @brief returns the chunk that opened the entry
    */
   Chunk *GetOpenChunk() const;

   /**
    * @brief Sets the chunk that opened the entry
    * @param chunk the chunk to set
    */
   void SetOpenChunk(Chunk *chunk);

   /**
    * @brief returns the level that opened the entry
    */
   size_t GetOpenLevel() const;

   /**
    * @brief Sets the level that opened the entry
    * @param level the level to set
    */
   void SetOpenLevel(size_t level);

   /**
    * @brief returns the line that opened the entry
    */
   size_t GetOpenLine() const;

   /**
    * @brief Sets the line that opened the entry
    * @param line the line to set
    */
   void SetOpenLine(size_t line);

   /**
    * @brief returns the column that opened the entry
    */
   size_t GetOpenCol() const;

   /**
    * @brief Sets the column that opened the entry
    * @param column the column to set
    */
   void SetOpenCol(size_t column);

   /**
    * @brief returns the indent for braces
    */
   size_t GetBraceIndent() const;

   /**
    * @brief Sets the indent for braces
    * @param indent the indent for braces
    */
   void SetBraceIndent(size_t indent);

   /**
    * @brief returns the indent level
    */
   size_t GetIndent() const;

   /**
    * @brief Sets the indent level
    * @param level the indent level
    */
   void SetIndent(size_t level);

   /**
    * @brief returns the temporary indent level
    */
   size_t GetIndentTmp() const;

   /**
    * @brief Sets the temporary indent level
    * @param level the temporary indent level
    */
   void SetIndentTmp(size_t level);

   /**
    * @brief returns the tab indent level
    */
   size_t GetIndentTab() const;

   /**
    * @brief Sets the tab indent level
    * @param level the tab indent level
    */
   void SetIndentTab(size_t level);

   /**
    * @brief returns the consecutive namespace levels
    */
   size_t GetNsCount() const;

   /**
    * @brief Sets the consecutive namespace levels
    * @param count the consecutive namespace levels
    */
   void SetNsCount(size_t count);

   /**
    * @brief returns whether indent_continue was applied
    */
   bool GetIndentContinue() const;

   /**
    * @brief Sets whether indent_continue was applied
    * @param cont new value
    */
   void SetIndentContinue(bool cont);

   /**
    * @brief returns whether this was created in a preprocessor
    */
   bool GetInPreproc() const;

   /**
    * @brief Sets whether this was created in a preprocessor
    * @param preproc new value
    */
   void SetInPreproc(bool preproc);

   /**
    * @brief returns whether a non-vardef line was hit
    */
   bool GetNonVardef() const;

   /**
    * @brief Sets whether a non-vardef line was hit
    * @param vardef new value
    */
   void SetNonVardef(bool vardef);

   /**
    * @brief returns the parent token (if, for, function, etc)
    */
   E_Token GetParent() const;

   /**
    * @brief Sets the parent token (if, for, function, etc)
    * @param parent the token to set
    */
   void SetParent(const E_Token parent);

   /**
    * @brief returns the stage used to check progression of complex statements
    */
   E_BraceStage GetStage() const;

   /**
    * @brief Sets the stage used to check progression of complex statements
    * @param stage the new value
    */
   void SetStage(const E_BraceStage stage);

   /**
    * @brief Returns the associated indentation data as a const reference
    */
   const IndentationData &GetIndentData() const;

   /**
    * @brief Returns the associated indentation data as a modifiable reference
    */
   IndentationData &IndentData();

   /**
    * @brief returns the pop chunk
    */
   Chunk *GetPopChunk() const;

   /**
    * @brief Sets the pop chunk
    * @param chunk the new chunk
    */
   void SetPopChunk(Chunk *chunk);


protected:
   E_Token         m_openToken;       // the type that opened the entry
   Chunk           *m_openChunk;      // chunk that opened the level
   size_t          m_openLevel;       // level of opening type
   size_t          m_openLine;        // line that open symbol is on, only for logging purposes
   size_t          m_openCol;         // column that open symbol is on, only for logging purposes
   size_t          m_braceIndent;     // indent for braces - may not relate to indent
   size_t          m_indent;          // indent level (depends on use)
   size_t          m_indentTmp;       // temporary indent level (depends on use)
   size_t          m_indentTab;       // the 'tab' indent (always <= real column)
   size_t          m_nsCount;         // Number of consecutive namespace levels
   bool            m_indentContinue;  // indent_continue was applied
   bool            m_inPreproc;       // whether this was created in a preprocessor
   bool            m_nonVardef;       // Hit a non-vardef line
   E_Token         m_parent;          // if, for, function, etc
   E_BraceStage    m_stage;           // used to check progression of complex statements.
   IndentationData m_indentationData; // Indentation data
   Chunk           *m_popChunk;       // Pop chunk
};


//! Class describing a parsing frame and its information
class ParsingFrame
{
public:
   ParsingFrame();
   virtual ~ParsingFrame() = default;

   /**
    * @brief Returns whether the frame paren stack is empty or not
    */
   bool empty() const;

   /**
    * @brief Returns the size of the frame paren stack
    */
   size_t size() const;

   /**
    * @brief Returns the last popped entry from the frame paren stack
    */
   const ParenStackEntry &lastPopped() const;

   /**
    * @brief Returns the frame reference number
    */
   size_t GetRefNumber() const;

   /**
    * @brief Set the frame reference number
    * @param the new reference number
    */
   void SetRefNumber(const size_t refNo);

   /**
    * @brief Returns the frame parenthesis level
    */
   size_t GetParenLevel() const;

   /**
    * @brief Set the frame parenthesis level
    * @param the new parenthesis level
    */
   void SetParenLevel(const size_t parenLevel);

   /**
    * @brief Returns the frame brace level
    */
   size_t GetBraceLevel() const;

   /**
    * @brief Set the frame brace level
    * @param the new brace level
    */
   void SetBraceLevel(const size_t braceLevel);

   /**
    * @brief Returns the frame preprocessor level
    */
   size_t GetPpLevel() const;

   /**
    * @brief Set the frame preprocessor level
    * @param the new preprocessor level
    */
   void SetPpLevel(const size_t ppLevel);

   /**
    * @brief Returns the count of special parenthesis
    */
   size_t GetSParenCount() const;

   /**
    * @brief Set the count of special parenthesis
    * @param the new special parenthesis count value
    */
   void SetSParenCount(const size_t sParenCount);

   /**
    * @brief Returns the count of parenthesis
    */
   size_t GetParenCount() const;

   /**
    * @brief Set the count of parenthesis
    * @param the new parenthesis count value
    */
   void SetParenCount(const size_t parenCount);

   /**
    * @brief Returns the count of statements
    */
   size_t GetStmtCount() const;

   /**
    * @brief Set the count of statements
    * @param the new statement count value
    */
   void SetStmtCount(const size_t stmtCount);

   /**
    * @brief Returns the count of statements
    */
   size_t GetExprCount() const;

   /**
    * @brief Set the count of statements
    * @param the new statement count value
    */
   void SetExprCount(const size_t exprCount);

   /**
    * @brief Returns the ifdef type
    */
   E_Token GetIfdefType() const;

   /**
    * @brief Set the ifdef type
    * @param the new type
    */
   void SetIfdefType(const E_Token inIfdef);

   ParenStackEntry &at(size_t idx);
   const ParenStackEntry &at(size_t idx) const;

   ParenStackEntry &prev(size_t idx = 1);
   const ParenStackEntry &prev(size_t idx = 1) const;

   ParenStackEntry &top();
   const ParenStackEntry &top() const;

   void push(Chunk *pc, const char *func, int line, E_BraceStage stage = E_BraceStage::NONE);
   void pop(const char *func, int line, Chunk *pc);

   using iterator = std::vector<ParenStackEntry>::iterator;
   iterator begin();
   iterator end();

   using const_iterator = std::vector<ParenStackEntry>::const_iterator;
   const_iterator begin() const;
   const_iterator end() const;

   using reverse_iterator = std::vector<ParenStackEntry>::reverse_iterator;
   reverse_iterator rbegin();
   reverse_iterator rend();

   using const_reverse_iterator = std::vector<ParenStackEntry>::const_reverse_iterator;
   const_reverse_iterator rbegin() const;
   const_reverse_iterator rend() const;


protected:
   // Members
   std::vector<ParenStackEntry> m_parenStack;  //! The parenthesis stack
   ParenStackEntry              m_lastPopped;  //! last popped frame or nullptr

   size_t                       m_refNumber;   //! frame reference number
   size_t                       m_parenLevel;  //! level of parens/square/angle/brace
   size_t                       m_braceLevel;  //! level of brace/vbrace
   size_t                       m_ppLevel;     //! level of preproc #if stuff
   size_t                       m_sParenCount; //! count of special parenthesis
   size_t                       m_parenCount;  //! count of parenthesis
   size_t                       m_stmtCount;   //! count of statements
   size_t                       m_exprCount;   //! count of expressions
   E_Token                      m_ifdefType;   //! the ifdef type
};


// ------------------------------
// ParenStackEntry inline methods
// ------------------------------
inline E_Token ParenStackEntry::GetOpenToken() const
{
   return(m_openToken);
}


inline void ParenStackEntry::SetOpenToken(const E_Token token)
{
   m_openToken = token;
}


inline Chunk *ParenStackEntry::GetOpenChunk() const
{
   return(m_openChunk);
}


inline void ParenStackEntry::SetOpenChunk(Chunk *chunk)
{
   m_openChunk = chunk;
}


inline size_t ParenStackEntry::GetOpenLevel() const
{
   return(m_openLevel);
}


inline void ParenStackEntry::SetOpenLevel(size_t level)
{
   m_openLevel = level;
}


inline size_t ParenStackEntry::GetOpenLine() const
{
   return(m_openLine);
}


inline void ParenStackEntry::SetOpenLine(size_t line)
{
   m_openLine = line;
}


inline size_t ParenStackEntry::GetOpenCol() const
{
   return(m_openCol);
}


inline void ParenStackEntry::SetOpenCol(size_t column)
{
   m_openCol = column;
}


inline size_t ParenStackEntry::GetBraceIndent() const
{
   return(m_braceIndent);
}


inline void ParenStackEntry::SetBraceIndent(size_t indent)
{
   m_braceIndent = indent;
}


inline size_t ParenStackEntry::GetIndent() const
{
   return(m_indent);
}


inline void ParenStackEntry::SetIndent(size_t level)
{
   m_indent = level;
}


inline size_t ParenStackEntry::GetIndentTmp() const
{
   return(m_indentTmp);
}


inline void ParenStackEntry::SetIndentTmp(size_t level)
{
   m_indentTmp = level;
}


inline size_t ParenStackEntry::GetIndentTab() const
{
   return(m_indentTab);
}


inline void ParenStackEntry::SetIndentTab(size_t level)
{
   m_indentTab = level;
}


inline size_t ParenStackEntry::GetNsCount() const
{
   return(m_nsCount);
}


inline void ParenStackEntry::SetNsCount(size_t count)
{
   m_nsCount = count;
}


inline bool ParenStackEntry::GetIndentContinue() const
{
   return(m_indentContinue);
}


inline void ParenStackEntry::SetIndentContinue(bool cont)
{
   m_indentContinue = cont;
}


inline bool ParenStackEntry::GetInPreproc() const
{
   return(m_inPreproc);
}


inline void ParenStackEntry::SetInPreproc(bool preproc)
{
   m_inPreproc = preproc;
}


inline bool ParenStackEntry::GetNonVardef() const
{
   return(m_nonVardef);
}


inline void ParenStackEntry::SetNonVardef(bool vardef)
{
   m_nonVardef = vardef;
}


inline E_Token ParenStackEntry::GetParent() const
{
   return(m_parent);
}


inline void ParenStackEntry::SetParent(const E_Token parent)
{
   m_parent = parent;
}


inline E_BraceStage ParenStackEntry::GetStage() const
{
   return(m_stage);
}


inline void ParenStackEntry::SetStage(const E_BraceStage stage)
{
   m_stage = stage;
}


inline const IndentationData &ParenStackEntry::GetIndentData() const
{
   return(m_indentationData);
}


inline IndentationData &ParenStackEntry::IndentData()
{
   return(m_indentationData);
}


inline Chunk *ParenStackEntry::GetPopChunk() const
{
   return(m_popChunk);
}


inline void ParenStackEntry::SetPopChunk(Chunk *chunk)
{
   m_popChunk = chunk;
}


// ------------------------------
// ParsingFrame inline methods
// ------------------------------
inline bool ParsingFrame::empty() const
{
   return(m_parenStack.empty());
}


inline size_t ParsingFrame::size() const
{
   return(m_parenStack.size());
}


inline const ParenStackEntry &ParsingFrame::lastPopped() const
{
   return(m_lastPopped);
}


inline size_t ParsingFrame::GetRefNumber() const
{
   return(m_refNumber);
}


inline void ParsingFrame::SetRefNumber(const size_t refNo)
{
   m_refNumber = refNo;
}


inline size_t ParsingFrame::GetParenLevel() const
{
   return(m_parenLevel);
}


inline void ParsingFrame::SetParenLevel(const size_t parenLevel)
{
   m_parenLevel = parenLevel;
}


inline size_t ParsingFrame::GetBraceLevel() const
{
   return(m_braceLevel);
}


inline void ParsingFrame::SetBraceLevel(const size_t braceLevel)
{
   m_braceLevel = braceLevel;
}


inline size_t ParsingFrame::GetPpLevel() const
{
   return(m_ppLevel);
}


inline void ParsingFrame::SetPpLevel(const size_t ppLevel)
{
   m_ppLevel = ppLevel;
}


inline size_t ParsingFrame::GetSParenCount() const
{
   return(m_sParenCount);
}


inline void ParsingFrame::SetSParenCount(const size_t sParenCount)
{
   m_sParenCount = sParenCount;
}


inline size_t ParsingFrame::GetParenCount() const
{
   return(m_parenCount);
}


inline void ParsingFrame::SetParenCount(const size_t parenCount)
{
   m_parenCount = parenCount;
}


inline size_t ParsingFrame::GetStmtCount() const
{
   return(m_stmtCount);
}


inline void ParsingFrame::SetStmtCount(const size_t stmtCount)
{
   m_stmtCount = stmtCount;
}


inline size_t ParsingFrame::GetExprCount() const
{
   return(m_exprCount);
}


inline void ParsingFrame::SetExprCount(const size_t exprCount)
{
   m_exprCount = exprCount;
}


inline E_Token ParsingFrame::GetIfdefType() const
{
   return(m_ifdefType);
}


inline void ParsingFrame::SetIfdefType(const E_Token inIfdef)
{
   m_ifdefType = inIfdef;
}


inline ParenStackEntry &ParsingFrame::at(size_t idx)
{
   return(m_parenStack.at(idx));
}


inline const ParenStackEntry &ParsingFrame::at(size_t idx) const
{
   return(m_parenStack.at(idx));
}


inline ParsingFrame::iterator ParsingFrame::begin()
{
   return(std::begin(m_parenStack));
}


inline ParsingFrame::const_iterator ParsingFrame::begin() const
{
   return(std::begin(m_parenStack));
}


inline ParsingFrame::reverse_iterator ParsingFrame::rbegin()
{
   return(m_parenStack.rbegin());
}


inline ParsingFrame::const_reverse_iterator ParsingFrame::rbegin() const
{
   return(m_parenStack.rbegin());
}


inline ParsingFrame::iterator ParsingFrame::end()
{
   return(std::end(m_parenStack));
}


inline ParsingFrame::const_iterator ParsingFrame::end() const
{
   return(std::end(m_parenStack));
}


inline ParsingFrame::reverse_iterator ParsingFrame::rend()
{
   return(m_parenStack.rend());
}


inline ParsingFrame::const_reverse_iterator ParsingFrame::rend() const
{
   return(m_parenStack.rend());
}


#endif /* PARSING_FRAME_H_INCLUDED */