-
Notifications
You must be signed in to change notification settings - Fork 2
/
pp_result.hh
1548 lines (1152 loc) · 39.9 KB
/
pp_result.hh
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
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (C) 2019 SUSE Software Solutions Germany GmbH
*
* This file is part of klp-ccp.
*
* klp-ccp is free software: you can redistribute it and/or modify it
* under the terms of version 2 of the GNU General Public License as
* published by the Free Software Foundation.
*
* klp-ccp is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with klp-ccp. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef PP_RESULT_HH
#define PP_RESULT_HH
#include <vector>
#include <memory>
#include <utility>
#include <set>
#include "raw_pp_tokens.hh"
#include "raw_pp_tokens_range.hh"
#include "pp_token.hh"
#include "pp_tokens.hh"
#include "pp_tokens_range.hh"
#include "offset_to_line_col_map.hh"
namespace klp
{
namespace ccp
{
class source_reader;
class pp_result
{
public:
class directive
{
public:
directive(const raw_pp_tokens_range &directive_range) noexcept;
bool operator<(const raw_pp_tokens_range &r) const noexcept
{ return _directive_range < r; }
const raw_pp_tokens_range& get_source_range() const noexcept
{ return _directive_range; }
private:
raw_pp_tokens_range _directive_range;
};
private:
typedef std::vector<directive> _directives_container_type;
public:
typedef _directives_container_type::const_iterator
const_directive_iterator;
const_directive_iterator directives_begin() const noexcept
{ return _directives.begin(); }
const_directive_iterator directives_end() const noexcept
{ return _directives.end(); }
std::pair<const_directive_iterator, const_directive_iterator>
find_overlapping_directives(const raw_pp_tokens_range &r) const noexcept;
class macro
{
private:
enum class _origin
{
o_builtin,
o_builtin_special,
o_predefined_user,
o_source,
};
public:
struct builtin_special_tag {};
struct builtin_tag {};
struct predefined_user_tag {};
bool operator==(const macro &rhs) const noexcept;
bool operator!=(const macro &rhs) const noexcept
{ return !(*this == rhs); }
bool operator<(const raw_pp_tokens_range &r) const noexcept
{
if (!is_predefined())
return _directive_range < r;
else
return true;
}
bool is_func_like() const noexcept
{ return _func_like; }
bool is_variadic() const noexcept
{ return _variadic; }
const std::vector<std::string>& get_arg_names() const noexcept;
size_t non_va_arg_count() const noexcept;
bool shall_expand_arg(const size_t pos) const noexcept;
const std::string& get_name() const noexcept
{ return _name; }
bool is_predefined() const noexcept
{
return (_o == _origin::o_builtin ||
_o == _origin::o_builtin_special ||
_o == _origin::o_predefined_user);
}
bool is_builtin() const noexcept
{
return (_o == _origin::o_builtin ||
_o == _origin::o_builtin_special);
}
bool is_builtin_special() const noexcept
{
return _o == _origin::o_builtin_special;
}
const raw_pp_tokens_range& get_directive_range() const noexcept
{
assert(!is_predefined());
return _directive_range;
}
unsigned long get_predefinition_pos() const noexcept
{
assert(is_predefined());
return _predefinition_pos;
}
const raw_pp_tokens& get_repl() const noexcept
{ return _repl; }
private:
friend class pp_result;
macro(const std::string &name,
const bool func_like,
const bool variadic,
std::vector<std::string> &&arg_names,
raw_pp_tokens &&repl,
const raw_pp_tokens_range &directive_range);
macro(const std::string &name,
const unsigned long predefinition_pos,
const builtin_special_tag&);
macro(const std::string &name,
const bool func_like,
const bool variadic,
std::vector<std::string> &&arg_names,
raw_pp_tokens &&repl,
const unsigned long predefinition_pos,
const builtin_tag&);
macro(const std::string &name,
const bool func_like,
const bool variadic,
std::vector<std::string> &&arg_names,
raw_pp_tokens &&repl,
const unsigned long predefinition_pos,
const predefined_user_tag&);
macro(const std::string &name,
const bool func_like,
const bool variadic,
std::vector<std::string> &&arg_names,
raw_pp_tokens &&repl,
const unsigned long predefinition_pos,
const _origin o);
void _init_do_expand_args();
raw_pp_tokens::const_iterator
_next_non_ws_repl(const raw_pp_tokens::const_iterator it)
const noexcept;
raw_pp_tokens::const_iterator
_skip_stringification_or_single(const raw_pp_tokens::const_iterator &it)
const noexcept;
bool _is_concat_op(const raw_pp_tokens::const_iterator &it)
const noexcept;
std::string _name;
std::vector<std::string> _arg_names;
raw_pp_tokens _repl;
_origin _o;
union
{
raw_pp_tokens_range _directive_range;
unsigned long _predefinition_pos;
};
std::vector<bool> _do_expand_args;
bool _func_like;
bool _variadic;
};
private:
typedef std::vector<std::unique_ptr<const macro>>
_macros_container_type;
public:
class const_macro_iterator
: public std::iterator<std::random_access_iterator_tag,
const macro>
{
public:
bool operator==(const const_macro_iterator &rhs)
const noexcept
{ return this->_it == rhs._it; }
bool operator!=(const const_macro_iterator &rhs)
const noexcept
{ return !(*this == rhs); }
reference operator*() const noexcept
{ return **_it; }
pointer operator->() const noexcept
{ return (*_it).get(); }
const_macro_iterator& operator++() noexcept
{ ++_it; return *this; }
const const_macro_iterator operator++(int) noexcept
{ return const_macro_iterator{_it++}; }
const_macro_iterator& operator--() noexcept
{ --_it; return *this; }
const const_macro_iterator operator--(int) noexcept
{ return const_macro_iterator{_it--}; }
const_macro_iterator&
operator+=(const difference_type n) noexcept
{ _it += n; return *this; }
const_macro_iterator&
operator-=(const difference_type n) noexcept
{ _it -= n; return *this; }
const const_macro_iterator
operator+(const difference_type n) const noexcept
{ return const_macro_iterator(_it + n); }
const const_macro_iterator
operator-(const difference_type n) const noexcept
{ return const_macro_iterator(_it - n); }
const difference_type
operator-(const const_macro_iterator &op) const noexcept
{ return this->_it - op._it; }
reference operator[](const difference_type n) const noexcept
{ return *(*this + n); }
bool operator<(const const_macro_iterator &op) const noexcept
{ return this->_it < op._it; }
bool operator>(const const_macro_iterator &op) const noexcept
{ return this->_it > op._it; }
bool operator<=(const const_macro_iterator &op) const noexcept
{ return this->_it <= op._it; }
bool operator>=(const const_macro_iterator &op) const noexcept
{ return this->_it >= op._it; }
private:
friend class pp_result;
const_macro_iterator(const _macros_container_type::const_iterator &it)
noexcept
: _it(it)
{}
_macros_container_type::const_iterator _it;
};
const_macro_iterator macros_begin() const noexcept
{ return const_macro_iterator{_macros.begin()}; }
const_macro_iterator macros_end() const noexcept
{ return const_macro_iterator{_macros.end()}; }
std::pair<const_macro_iterator, const_macro_iterator>
find_overlapping_macros(const raw_pp_tokens_range &r) const noexcept;
class macro_undef
{
private:
enum class _origin
{
o_predefined_user,
o_source,
};
public:
struct predefined_user_tag{};
macro_undef(const std::string &name,
const raw_pp_tokens_range &directive_range);
macro_undef(const std::string &name,
const unsigned long predefinition_pos,
const predefined_user_tag&);
bool operator<(const raw_pp_tokens_range &r) const noexcept
{
if (!is_predefined())
return _directive_range < r;
else
return true;
}
const std::string& get_name() const noexcept
{ return _name; }
bool is_predefined() const noexcept
{ return _o == _origin::o_predefined_user; }
const raw_pp_tokens_range& get_directive_range() const noexcept
{
assert(!is_predefined());
return _directive_range;
}
unsigned long get_predefinition_pos() const noexcept
{
assert(is_predefined());
return _predefinition_pos;
}
private:
std::string _name;
_origin _o;
union
{
raw_pp_tokens_range _directive_range;
unsigned long _predefinition_pos;
};
};
private:
typedef std::vector<macro_undef> _macro_undefs_container_type;
public:
typedef _macro_undefs_container_type::const_iterator
const_macro_undef_iterator;
const_macro_undef_iterator macro_undefs_begin() const noexcept
{ return _macro_undefs.begin(); }
const_macro_undef_iterator macro_undefs_end() const noexcept
{ return _macro_undefs.end(); }
std::pair<const_macro_undef_iterator, const_macro_undef_iterator>
find_overlapping_macro_undefs(const raw_pp_tokens_range &r)
const noexcept;
class used_macros
{
private:
struct _compare
{
bool operator()(const std::reference_wrapper<const macro> a,
const std::reference_wrapper<const macro> b)
const noexcept;
};
typedef std::set<std::reference_wrapper<const macro>, _compare>
_used_macros_type;
public:
class const_iterator :
public std::iterator<std::forward_iterator_tag, const macro>
{
public:
bool operator==(const const_iterator &rhs) const noexcept
{ return this->_it == rhs._it; }
bool operator!=(const const_iterator &rhs) const noexcept
{
return !(*this == rhs);
}
reference operator*() const noexcept
{ return _it->get(); }
pointer operator->() const noexcept
{ return &_it->get(); }
const_iterator& operator++() noexcept
{ ++_it; return *this; }
const const_iterator operator++(int) noexcept
{ return const_iterator{_it++}; }
private:
friend class used_macros;
const_iterator(const _used_macros_type::const_iterator &it) noexcept
: _it(it)
{}
_used_macros_type::const_iterator _it;
};
used_macros() = default;
bool empty() const noexcept
{ return _used_macros.empty(); }
void clear() noexcept;
std::size_t count(const macro &m) const noexcept;
used_macros& operator+=(const used_macros &rhs);
used_macros& operator+=(const pp_result::macro &rhs);
const_iterator begin() const noexcept
{ return const_iterator{_used_macros.begin()}; }
const_iterator end() const noexcept
{ return const_iterator{_used_macros.end()}; }
private:
used_macros(_used_macros_type &&um);
_used_macros_type _used_macros;
};
class macro_nondef_constraint
{
public:
macro_nondef_constraint(const std::string &id,
bool func_like_allowed = false);
bool operator<(const macro_nondef_constraint &rhs) const;
const std::string& get_name() const noexcept
{ return _id; }
bool is_func_like_allowed() const noexcept
{ return _func_like_allowed; }
private:
std::string _id;
bool _func_like_allowed;
};
class macro_nondef_constraints
{
private:
typedef std::set<macro_nondef_constraint>
_macro_nondef_constraints_type;
public:
class const_iterator :
public std::iterator<std::forward_iterator_tag,
const macro_nondef_constraint>
{
public:
bool operator==(const const_iterator &rhs) const noexcept
{ return this->_it == rhs._it; }
bool operator!=(const const_iterator &rhs) const noexcept
{
return !(*this == rhs);
}
reference operator*() const noexcept
{ return *_it; }
pointer operator->() const noexcept
{ return &*_it; }
const_iterator& operator++() noexcept
{ ++_it; return *this; }
const const_iterator operator++(int) noexcept
{ return const_iterator{_it++}; }
private:
friend class macro_nondef_constraints;
const_iterator
(const _macro_nondef_constraints_type::const_iterator &it)
noexcept
: _it(it)
{}
_macro_nondef_constraints_type::const_iterator _it;
};
macro_nondef_constraints() = default;
macro_nondef_constraints(macro_nondef_constraints &&mnc);
macro_nondef_constraints& operator=(macro_nondef_constraints &&rhs);
macro_nondef_constraints&
operator+=(const macro_nondef_constraints &rhs);
macro_nondef_constraints&
operator+=(const macro_nondef_constraint &rhs);
const_iterator begin() const noexcept
{ return const_iterator{_macro_nondef_constraints.begin()}; }
const_iterator end() const noexcept
{ return const_iterator{_macro_nondef_constraints.end()}; }
const_iterator find(const std::string &id) const noexcept;
_macro_nondef_constraints_type::size_type size() const noexcept
{ return _macro_nondef_constraints.size(); }
private:
_macro_nondef_constraints_type _macro_nondef_constraints;
};
class macro_invocation
{
public:
class passed_through_arg_token
{
public:
typedef std::vector<pp_token_index> emerged_tokens_type;
bool operator<(const raw_pp_token_index rhs) const noexcept;
const raw_pp_token_index get_arg_tok_raw() const noexcept
{ return _arg_tok_raw; }
const emerged_tokens_type& get_emerged_tokens() const noexcept
{ return _emerged_tokens; }
private:
friend class macro_invocation;
passed_through_arg_token(const raw_pp_token_index arg_tok_raw)
noexcept;
void _add_emerged_tok(const pp_token_index tok);
raw_pp_token_index _arg_tok_raw;
emerged_tokens_type _emerged_tokens;
};
typedef std::vector<passed_through_arg_token>
passed_through_arg_tokens_type;
const raw_pp_tokens_range& get_source_range() const noexcept
{ return _invocation_range; }
bool operator<(const raw_pp_tokens_range &r) const noexcept
{ return _invocation_range < r; }
const used_macros& get_used_macros() const noexcept
{ return _used_macros; }
const macro_nondef_constraints& get_macro_nondef_constraints()
const noexcept
{ return _macro_nondef_constraints; }
const passed_through_arg_token*
lookup_passed_through_arg_token(const pp_token_index tok)
const noexcept;
private:
friend class pp_result;
friend class preprocessor;
macro_invocation(const macro &m,
const raw_pp_tokens_range &invocation_range);
void _add_passed_through_macro_arg_token
(const raw_pp_token_index arg_tok_raw,
const pp_token_index emerged_token);
void _add_non_passthrough_macro_arg_token
(const raw_pp_token_index arg_tok_raw);
raw_pp_tokens_range _invocation_range;
used_macros _used_macros;
macro_nondef_constraints _macro_nondef_constraints;
passed_through_arg_tokens_type _passed_through_arg_tokens;
};
private:
typedef std::vector<std::unique_ptr<macro_invocation>>
_macro_invocations_container_type;
public:
class const_macro_invocation_iterator
: public std::iterator<std::random_access_iterator_tag,
const macro_invocation>
{
public:
bool operator==(const const_macro_invocation_iterator &rhs)
const noexcept
{ return this->_it == rhs._it; }
bool operator!=(const const_macro_invocation_iterator &rhs)
const noexcept
{ return !(*this == rhs); }
reference operator*() const noexcept
{ return **_it; }
pointer operator->() const noexcept
{ return (*_it).get(); }
const_macro_invocation_iterator& operator++() noexcept
{ ++_it; return *this; }
const const_macro_invocation_iterator operator++(int) noexcept
{ return const_macro_invocation_iterator{_it++}; }
const_macro_invocation_iterator& operator--() noexcept
{ --_it; return *this; }
const const_macro_invocation_iterator operator--(int) noexcept
{ return const_macro_invocation_iterator{_it--}; }
const_macro_invocation_iterator&
operator+=(const difference_type n) noexcept
{ _it += n; return *this; }
const_macro_invocation_iterator&
operator-=(const difference_type n) noexcept
{ _it -= n; return *this; }
const const_macro_invocation_iterator
operator+(const difference_type n) const noexcept
{ return const_macro_invocation_iterator(_it + n); }
const const_macro_invocation_iterator
operator-(const difference_type n) const noexcept
{ return const_macro_invocation_iterator(_it - n); }
const difference_type
operator-(const const_macro_invocation_iterator &op) const noexcept
{ return this->_it - op._it; }
reference operator[](const difference_type n) const noexcept
{ return *(*this + n); }
bool operator<(const const_macro_invocation_iterator &op) const noexcept
{ return this->_it < op._it; }
bool operator>(const const_macro_invocation_iterator &op) const noexcept
{ return this->_it > op._it; }
bool operator<=(const const_macro_invocation_iterator &op)
const noexcept
{ return this->_it <= op._it; }
bool operator>=(const const_macro_invocation_iterator &op)
const noexcept
{ return this->_it >= op._it; }
private:
friend class pp_result;
const_macro_invocation_iterator
(const _macro_invocations_container_type::const_iterator &it)
noexcept
: _it(it)
{}
_macro_invocations_container_type::const_iterator _it;
};
const const_macro_invocation_iterator
macro_invocations_begin() const noexcept
{ return const_macro_invocation_iterator(_macro_invocations.cbegin()); }
const const_macro_invocation_iterator
macro_invocations_end() const noexcept
{ return const_macro_invocation_iterator(_macro_invocations.cend()); }
std::pair<const_macro_invocation_iterator,
const_macro_invocation_iterator>
find_overlapping_macro_invocations(const raw_pp_tokens_range &r)
const noexcept;
class header_inclusion_node;
class header_inclusion_child;
class conditional_inclusion_node;
class const_intersecting_source_iterator;
class inclusion_node
{
private:
friend class const_intersecting_source_iterator;
struct _child
{
_child(std::unique_ptr<header_inclusion_child> &&_h) noexcept;
_child(std::unique_ptr<conditional_inclusion_node> &&_c) noexcept;
_child(_child &&chld) noexcept;
~_child() noexcept;
const inclusion_node& get_inclusion_node() const noexcept;
enum class kind
{
header,
conditional,
};
kind k;
union
{
std::unique_ptr<header_inclusion_child> h;
std::unique_ptr<conditional_inclusion_node> c;
};
};
typedef std::vector<_child> _children_container_type;
class _recursive_child_iterator :
public std::iterator<std::forward_iterator_tag, const _child>
{
public:
_recursive_child_iterator();
_recursive_child_iterator(const inclusion_node &n);
bool operator==(const _recursive_child_iterator &rhs) const noexcept
{ return this->_walk_stack == rhs._walk_stack; }
bool operator!=(const _recursive_child_iterator &rhs) const noexcept
{
return !(*this == rhs);
}
reference operator*() const noexcept
{
return *_walk_stack.back().first;
}
pointer operator->() const noexcept
{
return &*_walk_stack.back().first;
}
_recursive_child_iterator& operator++();
const _recursive_child_iterator operator++(int);
bool is_end() noexcept
{ return _walk_stack.empty(); }
private:
std::vector<std::pair<_children_container_type::const_iterator,
_children_container_type::const_iterator> >
_walk_stack;
};
public:
template<typename callable_type>
void for_each_descendant_inclusion_node(callable_type &&c) const;
class recursive_header_inclusion_iterator :
public std::iterator<std::forward_iterator_tag,
const header_inclusion_child>
{
public:
recursive_header_inclusion_iterator();
bool operator==(const recursive_header_inclusion_iterator &rhs)
const noexcept
{ return this->_it == rhs._it; }
bool operator!=(const recursive_header_inclusion_iterator &rhs)
const noexcept
{
return !(*this == rhs);
}
reference operator*() const noexcept
{
return *_it->h;
}
pointer operator->() const noexcept
{
return _it->h.get();;
}
recursive_header_inclusion_iterator& operator++();
const recursive_header_inclusion_iterator operator++(int);
private:
friend class inclusion_node;
recursive_header_inclusion_iterator(_recursive_child_iterator &&it);
void _skip_non_headers();
_recursive_child_iterator _it;
};
inclusion_node(const inclusion_node&) = delete;
inclusion_node(inclusion_node&&) = delete;
virtual ~inclusion_node() noexcept;
virtual const header_inclusion_node&
get_containing_header() const noexcept = 0;
virtual const conditional_inclusion_node*
get_containing_conditional_inclusion() const noexcept = 0;
const raw_pp_tokens_range& get_range() const noexcept
{ return _range; }
recursive_header_inclusion_iterator
header_inclusions_recursive_begin() const;
recursive_header_inclusion_iterator
header_inclusions_recursive_end() const;
const inclusion_node *
get_parent() const noexcept
{ return _parent; }
protected:
inclusion_node();
inclusion_node(inclusion_node * const parent,
const raw_pp_token_index range_begin);
inclusion_node * const _parent;
private:
friend class pp_result;
friend class preprocessor;
header_inclusion_child&
_add_header_inclusion(const std::string &filename,
const raw_pp_tokens_range &directive_range,
used_macros &&used_macros,
macro_nondef_constraints &¯o_nondef_constraints,
pp_result &container);
conditional_inclusion_node&
_add_conditional_inclusion(const raw_pp_token_index range_begin);
void _set_range_begin(const raw_pp_token_index range_begin) noexcept;
void _set_range_end(const raw_pp_token_index range_end) noexcept;
_children_container_type _children;
raw_pp_tokens_range _range;
};
class header_inclusion_node : public inclusion_node
{
public:
virtual ~header_inclusion_node() noexcept = 0;
virtual const header_inclusion_node&
get_containing_header() const noexcept override;
const std::string& get_filename() const noexcept
{
return _filename;
}
void add_line(const std::streamoff length);
std::pair<std::streamoff, std::streamoff>
offset_to_line_col(const std::streamoff off) const noexcept;
std::unique_ptr<source_reader> create_source_reader() const;
unsigned long get_id() const noexcept;
protected:
header_inclusion_node(const std::string &filename);
header_inclusion_node(inclusion_node &parent,
const raw_pp_token_index range_begin,
const std::string &filename,
const unsigned long id);
private:
friend class pp_result;
void _set_id(const unsigned long id) noexcept;
const std::string _filename;
offset_to_line_col_map _offset_to_line_col_map;
unsigned long _id;
};
class header_inclusion_root final : public header_inclusion_node
{
public:
header_inclusion_root(const std::string &filename,
const bool is_preinclude);
virtual ~header_inclusion_root() noexcept;
virtual const conditional_inclusion_node*
get_containing_conditional_inclusion() const noexcept override;
bool is_preinclude() const noexcept
{ return _is_preinclude; }
private:
bool _is_preinclude;
};
class header_inclusion_child final : public header_inclusion_node
{
public:
virtual ~header_inclusion_child() noexcept;
virtual const conditional_inclusion_node*
get_containing_conditional_inclusion() const noexcept override;
const raw_pp_tokens_range& get_directive_range() const noexcept
{ return _directive_range; }
const used_macros& get_used_macros() const noexcept
{ return _used_macros; }
const macro_nondef_constraints& get_macro_nondef_constraints()
const noexcept
{ return _macro_nondef_constraints; }
private:
friend class inclusion_node;
header_inclusion_child(inclusion_node &parent,
const std::string &filename,
const raw_pp_tokens_range &directive_range,
used_macros &&used_macros,
macro_nondef_constraints &¯o_nondef_constraints,
const unsigned long id);
raw_pp_tokens_range _directive_range;
used_macros _used_macros;
macro_nondef_constraints _macro_nondef_constraints;
};
class conditional_inclusion_node final : public inclusion_node
{
public:
typedef std::vector<raw_pp_tokens_range> directive_ranges_type;
virtual ~conditional_inclusion_node();
virtual const header_inclusion_node&
get_containing_header() const noexcept override;
virtual const conditional_inclusion_node*
get_containing_conditional_inclusion() const noexcept override;
const raw_pp_token_index get_directive_begin() const noexcept
{ return this->get_range().begin; }
const used_macros& get_used_macros() const noexcept
{ return _used_macros; }
const macro_nondef_constraints& get_macro_nondef_constraints()
const noexcept
{ return _macro_nondef_constraints; }
directive_ranges_type::size_type nbranches() const noexcept;
const raw_pp_tokens_range&
get_branch_directive_range(const directive_ranges_type::size_type i)
const noexcept;