-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathast.hh
5143 lines (3802 loc) · 139 KB
/
ast.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 AST_HH
#define AST_HH
#include <vector>
#include <cassert>
#include <initializer_list>
#include <functional>
#include <memory>
#include <utility>
#include "type_set.hh"
#include "pp_tokens.hh"
#include "code_remarks.hh"
#include "types.hh"
#include "builtins.hh"
#include "pp_tokens_range.hh"
#include "pp_result.hh"
namespace klp
{
namespace ccp
{
class target;
namespace ast
{
template<typename ret_type>
class processor;
template<typename ret_type>
class const_processor;
class constexpr_value;
class ast;
template<typename derived>
class ast_entity;
class _ast_entity
{
public:
_ast_entity(const pp_tokens_range &tr) noexcept;
_ast_entity(const _ast_entity &ae) noexcept;
virtual ~_ast_entity() noexcept;
const pp_tokens_range& get_tokens_range() const noexcept
{ return _tokens_range; }
_ast_entity* get_parent() noexcept
{ return _parent; }
const _ast_entity* get_parent() const noexcept
{ return _parent; }
template <typename ret_type, typename handled_types,
typename callables_wrapper_type>
ret_type process(callables_wrapper_type &&c) const;
template <typename ret_type, typename handled_types,
typename callables_wrapper_type>
ret_type process(callables_wrapper_type &&c);
template<typename... types>
bool is_any_of() const noexcept;
template <typename handled_types_pre,
typename handled_types_post,
typename callables_wrapper_type_pre,
typename callables_wrapper_type_post>
void for_each_dfs_pre_and_po(callables_wrapper_type_pre &&c_pre,
callables_wrapper_type_post &&c_post);
template <typename handled_types_pre,
typename handled_types_post,
typename callables_wrapper_type_pre,
typename callables_wrapper_type_post>
void for_each_dfs_pre_and_po(callables_wrapper_type_pre &&c_pre,
callables_wrapper_type_post &&c_post)
const;
template <typename handled_types, typename callables_wrapper_type>
void for_each_dfs_po(callables_wrapper_type &&c);
template <typename handled_types, typename callables_wrapper_type>
void for_each_dfs_po(callables_wrapper_type &&c) const;
protected:
void _extend_tokens_range(const pp_tokens_range &tr) noexcept;
_ast_entity *_parent;
private:
template<typename derived>
friend class ast_entity;
virtual _ast_entity* _get_child(const size_t i) const noexcept = 0;
virtual void _process(processor<void> &p) = 0;
virtual void _process(const_processor<void> &p) const = 0;
virtual bool _process(processor<bool> &p) = 0;
virtual bool _process(const_processor<bool> &p) const = 0;
template<typename callable_type_pre,
typename callable_type_post>
void _for_each_dfs_pre_and_po(callable_type_pre &&c_pre,
callable_type_post &&c_post);
template<typename callable_type_pre,
typename callable_type_post>
void _for_each_dfs_pre_and_po(callable_type_pre &&c_pre,
callable_type_post &&c_post) const;
template <typename callable_type>
void _for_each_dfs_po(callable_type &&c);
template <typename callable_type>
void _for_each_dfs_po(callable_type &&c) const;
pp_tokens_range _tokens_range;
};
template <typename derived>
class ast_entity : public _ast_entity
{
public:
ast_entity(const pp_tokens_range &tr) noexcept;
ast_entity(const ast_entity &ae) noexcept;
virtual ~ast_entity() noexcept = default;
template<typename boundary_type_set, typename callable_type>
void for_each_ancestor(callable_type &&c);
template<typename boundary_type_set, typename callable_type>
void for_each_ancestor(callable_type &&c) const;
template <typename callable_type>
void process_parent(callable_type &&c) const;
template <typename parent_type>
const parent_type& get_unique_parent() const noexcept
{
static_assert((derived::parent_types::size() == 1 &&
derived::parent_types::template is_member<parent_type>()),
"parent type not unique");
assert(_parent);
return dynamic_cast<const parent_type&>(*_parent);
}
template <typename parent_type>
parent_type& get_unique_parent() noexcept
{
static_assert((derived::parent_types::size() == 1 &&
derived::parent_types::template is_member<parent_type>()),
"parent type not unique");
assert(_parent);
return dynamic_cast<parent_type&>(*_parent);
}
template<typename parent_type>
void _set_parent(parent_type &p) noexcept
{
static_assert(
derived::parent_types::template is_member<parent_type>(),
"attempted to set non-listed parent");
assert(!_parent);
_parent = &p;
}
template<typename parent_type>
void _reset_parent(parent_type &p, const parent_type &old_p) noexcept
{
static_assert(
derived::parent_types::template is_member<parent_type>(),
"attempted to set non-listed parent");
assert(_parent == &old_p);
_parent = &p;
}
};
class _typed
{
public:
virtual ~_typed() noexcept;
virtual void evaluate_type(ast &a, const target &tgt) = 0;
virtual bool is_evaluated() const noexcept = 0;
protected:
_typed() noexcept = default;
};
template <typename derived, typename type>
class typed_ast_entity : public ast_entity<derived>, public _typed
{
public:
virtual ~typed_ast_entity() noexcept;
const std::shared_ptr<const type>& get_type() const noexcept;
virtual bool is_evaluated() const noexcept override;
protected:
typed_ast_entity(const pp_tokens_range &tr) noexcept;
void _set_type(std::shared_ptr<const type> &&t) noexcept;
void _set_type(const std::shared_ptr<const type> &t) noexcept;
void _reset_type(std::shared_ptr<const type> &&t) noexcept;
private:
std::shared_ptr<const type> _type;
};
class ast;
class expr;
class expr_list;
class attribute;
class attribute_list;
class attribute_specifier;
class storage_class_specifier;
class type_qualifier;
class type_qualifier_list;
class type_specifier;
class struct_declaration;
class struct_declaration_list;
class enumerator;
class enumerator_list;
class function_specifier;
class pointer;
class abstract_declarator;
class type_name;
class direct_declarator;
class direct_declarator_parenthesized;
class direct_declarator_id;
class declarator;
class initializer;
class designator;
class designator_list;
class designation;
class asm_label;
class init_declarator_list;
class declaration;
class static_assertion;
class parameter_declaration;
class parameter_declaration_declarator;
class parameter_declaration_abstract;
class identifier_list;
class declaration_list;
class stmt;
class local_label_declaration;
class block_item;
class block_item_list;
class asm_qualifier_list;
class asm_operand_name;
class asm_operand;
class asm_operand_list;
class asm_clobber_list;
class asm_jump_to_label_list;
class function_definition;
class translation_unit;
class external_declaration;
class external_declaration_asm;
class expr;
class expr_list;
class expr_comma;
class expr_assignment;
class expr_conditional;
class expr_binop;
class expr_cast;
class expr_unop_pre;
class expr_sizeof_expr;
class expr_alignof_expr;
class generic_association;
class generic_association_list;
class expr_generic;
class expr_builtin_choose_expr;
class offset_member_designator;
class expr_builtin_offsetof;
class expr_builtin_va_arg;
class expr_sizeof_type_name;
class expr_array_subscript;
class expr_func_invocation;
class expr_member_deref;
class expr_unop_post;
class expr_compound_literal;
class expr_statement;
class expr_id;
class expr_constant;
class expr_string_literal;
class expr_parenthesized;
class attribute;
class attribute_list;
class attribute_specifier;
class attribute_specifier_list;
class storage_class_specifier;
class type_qualifier;
class type_qualifier_list;
class type_specifier;
class type_specifier_pod;
class struct_declaration;
class struct_declarator;
class struct_declarator_list;
class struct_declaration_c99;
class unnamed_struct_or_union;
class struct_declaration_unnamed_sou;
class struct_declaration_static_assert;
class struct_declaration_list;
class struct_or_union_def;
class struct_or_union_ref;
class enumerator;
class enumerator_list;
class enum_def;
class enum_ref;
class typeof_expr;
class typeof_type_name;
class function_specifier;
class specifier_qualifier_list;
class declaration_specifiers;
class pointer;
class direct_abstract_declarator;
class direct_abstract_declarator_parenthesized;
class direct_abstract_declarator_array;
class direct_abstract_declarator_func;
class abstract_declarator;
class type_name;
class direct_declarator;
class direct_declarator_array;
class direct_declarator_func;
class declarator;
class initializer;
class initializer_expr;
class designator;
class designator_member;
class designator_array;
class designator_list;
class designation;
class initializer_list;
class asm_label;
class init_declarator;
class init_declarator_list;
class declaration;
class parameter_declaration;
class parameter_declaration_list;
class identifier_list;
class declaration_list;
class stmt;
class stmt_labeled;
class stmt_case;
class stmt_case_range;
class stmt_default;
class local_label_declaration;
class local_label_declaration_list;
class block_item;
class block_item_decl;
class block_item_static_assert;
class block_item_stmt;
class block_item_function_definition;
class block_item_list;
class stmt_compound;
class stmt_expr;
class stmt_if;
class stmt_switch;
class stmt_while;
class stmt_do;
class stmt_for;
class stmt_for_init_expr;
class stmt_for_init_decl;
class stmt_for_init_static_assert;
class stmt_goto;
class stmt_continue;
class stmt_break;
class stmt_return;
class asm_qualifier_list;
class asm_operand_name;
class asm_operand;
class asm_operand_list;
class asm_clobber_list;
class asm_jump_to_label_list;
class asm_directive;
class function_definition;
class translation_unit;
class external_declaration;
class external_declaration_decl;
class external_declaration_static_assert;
class external_declaration_func;
class expr_list final : public ast_entity<expr_list>
{
public:
typedef type_set<attribute, expr_func_invocation> parent_types;
expr_list(expr* &&e);
expr_list(expr_list &&el);
virtual ~expr_list() noexcept override;
void extend(expr* &&e);
std::size_t size() const noexcept
{ return _exprs.size(); }
expr& operator[](const std::size_t i) noexcept;
const expr& operator[](const std::size_t i) const noexcept;
void apply_lvalue_conversions(const bool only_decay);
private:
virtual _ast_entity* _get_child(const size_t i) const noexcept override;
virtual void _process(processor<void> &p) override;
virtual void _process(const_processor<void> &p) const override;
virtual bool _process(processor<bool> &p) override;
virtual bool _process(const_processor<bool> &p) const override;
std::vector<std::reference_wrapper<expr> > _exprs;
};
class expr : public typed_ast_entity<expr, types::type>
{
public:
typedef type_set<expr_list,
expr_cast, expr_unop_pre,
expr_sizeof_expr, expr_alignof_expr,
generic_association, expr_generic,
expr_builtin_choose_expr,
offset_member_designator, expr_array_subscript,
expr_func_invocation, expr_member_deref,
expr_unop_post, expr_parenthesized, expr_comma,
expr_assignment, expr_conditional, expr_binop,
expr_builtin_va_arg,
direct_abstract_declarator_array,
direct_declarator_array,
struct_declarator,
enumerator,
typeof_expr,
initializer_expr,
designator_array,
static_assertion,
stmt_case, stmt_case_range,
stmt_expr, stmt_if, stmt_switch,
stmt_while, stmt_do,
stmt_for, stmt_for_init_expr,
stmt_goto, stmt_return,
asm_operand> parent_types;
expr(expr&&) = delete;
virtual ~expr() noexcept = 0;
bool is_constexpr() const noexcept;
bool is_dereferenced_const_addr() const noexcept;
const constexpr_value&
get_constexpr_value() const noexcept;
virtual const expr& skip_parens_down() const noexcept;
virtual const _ast_entity* skip_parens_up() const noexcept;
virtual const _ast_entity* skip_parens_up() noexcept;
const _ast_entity* get_non_parens_parent() const noexcept;
_ast_entity* get_non_parens_parent() noexcept;
bool is_lvalue() const noexcept;
void apply_lvalue_conversion(const bool only_decay);
protected:
expr(const pp_tokens_range &tr) noexcept;
void _set_value(std::unique_ptr<constexpr_value> &&cv);
template<typename... args_types>
void _set_value(args_types&&... args);
void _set_lvalue(const bool is_lvalue) noexcept;
private:
std::unique_ptr<constexpr_value> _value;
bool _is_lvalue;
};
class expr_comma final : public expr
{
public:
expr_comma(expr* &&l, expr* &&r) noexcept;
virtual ~expr_comma() noexcept override;
virtual void evaluate_type(ast&, const target&) override;
const expr& get_left() const noexcept
{ return _left; }
private:
virtual _ast_entity* _get_child(const size_t i) const noexcept override;
virtual void _process(processor<void> &p) override;
virtual void _process(const_processor<void> &p) const override;
virtual bool _process(processor<bool> &p) override;
virtual bool _process(const_processor<bool> &p) const override;
expr &_left;
expr &_right;
};
enum class assign_op
{
set,
mul,
div,
mod,
add,
sub,
lshift,
rshift,
bin_and,
bin_xor,
bin_or,
};
class expr_assignment final : public expr
{
public:
expr_assignment(const assign_op op, expr* &&lhs, expr* &&rhs) noexcept;
virtual ~expr_assignment() noexcept override;
assign_op get_op() const noexcept
{ return _op; }
const expr& get_lhs() const noexcept
{ return _lhs; }
const expr& get_rhs() const noexcept
{ return _rhs; }
virtual void evaluate_type(ast &a, const target &tgt) override;
private:
virtual _ast_entity* _get_child(const size_t i) const noexcept override;
virtual void _process(processor<void> &p) override;
virtual void _process(const_processor<void> &p) const override;
virtual bool _process(processor<bool> &p) override;
virtual bool _process(const_processor<bool> &p) const override;
assign_op _op;
expr &_lhs;
expr &_rhs;
};
class expr_conditional final : public expr
{
public:
expr_conditional(expr* &&cond, expr* &&expr_true, expr* &&expr_false)
noexcept;
expr_conditional(expr* &&cond, expr* &&expr_false) noexcept;
virtual ~expr_conditional() noexcept override;
virtual void evaluate_type(ast &a, const target &tgt) override;
const expr& get_cond() const noexcept
{ return _cond; }
const expr* get_expr_true() const noexcept
{ return _expr_true; }
const expr& get_expr_false() const noexcept
{ return _expr_false; }
private:
virtual _ast_entity* _get_child(const size_t i) const noexcept override;
virtual void _process(processor<void> &p) override;
virtual void _process(const_processor<void> &p) const override;
virtual bool _process(processor<bool> &p) override;
virtual bool _process(const_processor<bool> &p) const override;
expr &_cond;
expr *_expr_true;
expr &_expr_false;
};
enum class binary_op
{
mul,
div,
mod,
add,
sub,
lshift,
rshift,
bin_and,
bin_xor,
bin_or,
logical_and,
logical_or,
eq,
neq,
lt,
gt,
leq,
geq,
};
class expr_binop final : public expr
{
public:
expr_binop(const binary_op op, expr* &&l, expr* &&r) noexcept;
virtual ~expr_binop() noexcept override;
virtual void evaluate_type(ast &a, const target &tgt) override;
binary_op get_op() const noexcept
{ return _op; }
const expr& get_left_expr() const noexcept
{ return _left; }
const expr& get_right_expr() const noexcept
{ return _right; }
private:
virtual _ast_entity* _get_child(const size_t i) const noexcept override;
virtual void _process(processor<void> &p) override;
virtual void _process(const_processor<void> &p) const override;
virtual bool _process(processor<bool> &p) override;
virtual bool _process(const_processor<bool> &p) const override;
void _evaluate_arith_binop(const types::arithmetic_type &at_left,
const types::arithmetic_type &at_right,
ast &a, const target &tgt);
void _evaluate_ptr_sub(const types::pointer_type &pt_left,
const types::pointer_type &pt_right,
ast &a, const target &tgt);
void _evaluate_shift(const types::int_type &it_left,
const types::int_type &it_right,
ast &a, const target &tgt);
void _evaluate_bin_binop(const types::int_type &it_left,
const types::int_type &it_right,
ast &a, const target &tgt);
void _evaluate_logical_binop(const ast &a, const target &tgt);
void _evaluate_cmp(const types::pointer_type &pt_left,
const types::pointer_type &pt_right,
ast &a, const target &tgt);
void _evaluate_cmp(const types::pointer_type &pt_left,
const types::int_type &it_right,
ast &a, const target &tgt);
void _evaluate_cmp(const types::int_type &it_left,
const types::pointer_type &pt_right,
ast &a, const target &tgt);
void _evaluate_cmp(const types::arithmetic_type &at_left,
const types::arithmetic_type &at_right,
ast &a, const target &tgt);
binary_op _op;
expr &_left;
expr &_right;
};
class expr_cast final : public expr
{
public:
expr_cast(const pp_tokens_range &tr, type_name* &&tn, expr* &&e)
noexcept;
virtual ~expr_cast() noexcept override;
virtual void evaluate_type(ast &a, const target &tgt) override;
const type_name& get_type_name() const noexcept
{ return _tn; }
const expr& get_expr() const noexcept
{ return _e; }
private:
virtual _ast_entity* _get_child(const size_t i) const noexcept override;
virtual void _process(processor<void> &p) override;
virtual void _process(const_processor<void> &p) const override;
virtual bool _process(processor<bool> &p) override;
virtual bool _process(const_processor<bool> &p) const override;
type_name &_tn;
expr &_e;
};
enum class unary_op_pre
{
inc,
dec,
addr,
deref,
plus,
neg,
bin_neg,
logical_not,
};
class expr_label_addr final : public expr
{
public:
expr_label_addr(const pp_tokens_range &tr,
const pp_token_index label_tok) noexcept;
virtual ~expr_label_addr() noexcept override;
pp_token_index get_label_tok() const noexcept
{ return _label_tok; }
void set_resolved(const stmt_labeled &resolved) noexcept;
virtual void evaluate_type(ast&, const target&) override;
private:
virtual _ast_entity* _get_child(const size_t) const noexcept override;
virtual void _process(processor<void> &p) override;
virtual void _process(const_processor<void> &p) const override;
virtual bool _process(processor<bool> &p) override;
virtual bool _process(const_processor<bool> &p) const override;
pp_token_index _label_tok;
const stmt_labeled *_resolved;
};
class expr_unop_pre final : public expr
{
public:
expr_unop_pre(const pp_tokens_range &tr,
const unary_op_pre op, expr* &&e) noexcept;
virtual ~expr_unop_pre() noexcept override;
unary_op_pre get_op() const noexcept
{ return _op; }
virtual void evaluate_type(ast &a, const target &tgt) override;
const expr& get_expr() const noexcept
{ return _e; }
private:
virtual _ast_entity* _get_child(const size_t i) const noexcept override;
virtual void _process(processor<void> &p) override;
virtual void _process(const_processor<void> &p) const override;
virtual bool _process(processor<bool> &p) override;
virtual bool _process(const_processor<bool> &p) const override;
unary_op_pre _op;
expr &_e;
};
class expr_sizeof_expr final : public expr
{
public:
expr_sizeof_expr(const pp_tokens_range &tr, expr* &&e) noexcept;
virtual ~expr_sizeof_expr() noexcept override;
virtual void evaluate_type(ast &a, const target &tgt) override;
private:
virtual _ast_entity* _get_child(const size_t i) const noexcept override;
virtual void _process(processor<void> &p) override;
virtual void _process(const_processor<void> &p) const override;
virtual bool _process(processor<bool> &p) override;
virtual bool _process(const_processor<bool> &p) const override;
expr &_e;
};
class expr_sizeof_type_name final : public expr
{
public:
expr_sizeof_type_name(const pp_tokens_range &tr, type_name* &&tn)
noexcept;
virtual ~expr_sizeof_type_name() noexcept override;
virtual void evaluate_type(ast &a, const target &tgt) override;
const type_name& get_type_name() const noexcept
{ return _tn; }
private:
virtual _ast_entity* _get_child(const size_t i) const noexcept override;
virtual void _process(processor<void> &p) override;
virtual void _process(const_processor<void> &p) const override;
virtual bool _process(processor<bool> &p) override;
virtual bool _process(const_processor<bool> &p) const override;
type_name &_tn;
};
class expr_alignof_expr final : public expr
{
public:
expr_alignof_expr(const pp_tokens_range &tr, expr* &&e) noexcept;
virtual ~expr_alignof_expr() noexcept override;
virtual void evaluate_type(ast &a, const target &tgt) override;
private:
virtual _ast_entity* _get_child(const size_t i) const noexcept override;
virtual void _process(processor<void> &p) override;
virtual void _process(const_processor<void> &p) const override;
virtual bool _process(processor<bool> &p) override;
virtual bool _process(const_processor<bool> &p) const override;
expr &_e;
};
class expr_alignof_type_name final : public expr
{
public:
expr_alignof_type_name(const pp_tokens_range &tr, type_name* &&tn)
noexcept;
virtual ~expr_alignof_type_name() noexcept override;
virtual void evaluate_type(ast &a, const target &tgt) override;
const type_name& get_type_name() const noexcept
{ return _tn; }
private:
virtual _ast_entity* _get_child(const size_t i) const noexcept override;
virtual void _process(processor<void> &p) override;
virtual void _process(const_processor<void> &p) const override;
virtual bool _process(processor<bool> &p) override;
virtual bool _process(const_processor<bool> &p) const override;
type_name &_tn;
};
class generic_association final : public ast_entity<generic_association>
{
public:
typedef type_set<generic_association_list> parent_types;
generic_association(const pp_tokens_range &tr,
type_name* &&tn, expr *&&e) noexcept;
generic_association(const pp_tokens_range &tr, expr *&&e) noexcept;
generic_association(generic_association&&) = delete;
virtual ~generic_association() noexcept override;
const type_name *get_type_name() const noexcept
{ return _tn; }
const expr& get_expr() const noexcept
{ return _e; }
private:
virtual _ast_entity* _get_child(const size_t i) const noexcept override;
virtual void _process(processor<void> &p) override;
virtual void _process(const_processor<void> &p) const override;
virtual bool _process(processor<bool> &p) override;
virtual bool _process(const_processor<bool> &p) const override;
type_name *_tn;
expr &_e;
};
class generic_association_list final :
public ast_entity<generic_association_list>
{
public:
typedef type_set<expr_generic> parent_types;
generic_association_list(generic_association *&&ga);
generic_association_list(generic_association_list&&) = delete;
virtual ~generic_association_list() noexcept override;
void extend(generic_association *&&ga);
template <typename callable_type>
void for_each(callable_type &&c) const;
private:
virtual _ast_entity* _get_child(const size_t i) const noexcept override;
virtual void _process(processor<void> &p) override;
virtual void _process(const_processor<void> &p) const override;
virtual bool _process(processor<bool> &p) override;
virtual bool _process(const_processor<bool> &p) const override;
std::vector<std::reference_wrapper<generic_association> > _gas;
};
class expr_generic final : public expr
{
public:
expr_generic(const pp_tokens_range &tr,
expr *&&ctrl_e,
generic_association_list *&&gal) noexcept;
virtual ~expr_generic() noexcept override;
virtual void evaluate_type(ast &a, const target &tgt) override;
const expr& get_control_expr() const noexcept
{ return _ctrl_e; }
const generic_association_list& get_association_list() const noexcept
{ return _gal; }
const expr& get_match() const noexcept;
private:
virtual _ast_entity* _get_child(const size_t i) const noexcept override;
virtual void _process(processor<void> &p) override;
virtual void _process(const_processor<void> &p) const override;
virtual bool _process(processor<bool> &p) override;
virtual bool _process(const_processor<bool> &p) const override;
expr &_ctrl_e;
generic_association_list &_gal;
const expr *_match;
};
class expr_builtin_choose_expr final : public expr
{
public:
expr_builtin_choose_expr(const pp_tokens_range &tr, expr *&&cond,
expr *&&expr_true, expr *&&expr_false)
noexcept;
virtual ~expr_builtin_choose_expr() noexcept override;
virtual void evaluate_type(ast &a, const target &tgt) override;
const expr& get_cond() const noexcept
{ return _cond; }
const expr& get_expr_true() const noexcept
{ return _expr_true; }
const expr& get_expr_false() const noexcept
{ return _expr_false; }
private:
virtual _ast_entity* _get_child(const size_t i) const noexcept override;
virtual void _process(processor<void> &p) override;
virtual void _process(const_processor<void> &p) const override;
virtual bool _process(processor<bool> &p) override;
virtual bool _process(const_processor<bool> &p) const override;
expr &_cond;
expr &_expr_true;
expr &_expr_false;