-
Notifications
You must be signed in to change notification settings - Fork 0
/
node.h
1273 lines (1082 loc) · 27.8 KB
/
node.h
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
/*************************************************************************/
/* bparser - a bison-based, C99 parser */
/* Copyright (C) 2015-2016 */
/* Johannes Lorenz (jlsf2013 @ sourceforge) */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License, or (at */
/* your option) any later version. */
/* This program 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 this program; if not, write to the Free Software */
/* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA */
/*************************************************************************/
/**
@file node.h
definition of a node of the resulting AST
A node is a node of the AST graph depicting a precompiled-ANSII-C99
program. Nodes can be declarations, definitions, expressions etc.
The header defines the basic node class and its derived classes.
*/
#ifndef NODE_H
#define NODE_H
#include <stdexcept>
#include <cstddef>
#include <list>
#include <string>
#include "node_fwd.h"
#include "tuple03.h"
#include "geom.h"
template<class P>
class safe_ptr
{
P* p;
static void assert_p(const P* p) {
if(!p) throw std::logic_error("pointer access");
}
public:
safe_ptr() : p(NULL) {}
safe_ptr(P* p) : p(p) {}
safe_ptr& operator=(P* _p) { return p = _p, *this; }
operator P*() { return p; }
operator P const*() const { return p; }
//bool operator==(const P* _p) const { return p == _p; }
P& operator*() { assert_p(p); return *p; }
P const& operator*() const { assert_p(p); return *p; }
P* operator->() { assert_p(p); return p; }
P const* operator->() const { assert_p(p); return p; }
bool operator!() const { return p == NULL; }
};
// FEATURE: not here?
enum lookup_type
{
lt_enumeration,
lt_typedef_name,
lt_identifier,
lt_identifier_list,
lt_struct_bound,
lt_undefined
};
void init_parser(const char* fname = NULL); //!< see node.cpp
class node_t
{
public:
null_type c; //!< base case, overwrite this
typedef std::size_t id_t;
span_t span; // FEATURE: not public
virtual void accept(class visitor_t& v) = 0;
node_t() {}
node_t(const geom_t& geom) : span(geom, geom_t()) {}
virtual ~node_t() {}
};
typedef node_t node_base;
template<class ParType = node_t>
class has_par
{
public:
typedef ParType parent_type;
ParType* parent;
};
#if 0
template<class First, class Next = null_type>
class node_ch : public node_t, public has_par<>
{
ptn<First, Next> c;
public:
node_ch() {}
node_ch(const geom_t& geom) : node_t<>(geom) {}
virtual ~node_ch() {}
void accept_children(visitor_t& v);
};
#endif
namespace nodes {
class terminal_t : public node_t, public has_par<>
{
int _value;
virtual std::size_t length() const = 0;
virtual std::size_t newlines() const = 0;
virtual std::size_t tablength() const = 0; //!< shall return 0 or 8
public:
int value() const { return _value; }
std::size_t get_tablength() const { return tablength(); }
std::size_t get_length() const { return length(); }
std::size_t get_newlines() const { return newlines(); }
terminal_t(const geom_t& geom, int _value) : node_t(geom), _value(_value) {}
};
struct token_t : public terminal_t
{
std::size_t length() const;
std::size_t tablength() const;
std::size_t newlines() const;
public:
token_t(const geom_t& pos, int value) : terminal_t(pos, value) {}
virtual void accept(class visitor_t& v);
friend std::ostream& operator<<(std::ostream& , const token_t& );
};
std::ostream& operator<<(std::ostream& , const token_t& );
struct noconst_terminal_t : public terminal_t
{
std::string raw;
noconst_terminal_t(const geom_t& geom, int value, const char* raw) :
terminal_t(geom, value),
raw(raw) {}
};
struct noconst_1line_terminal_t : public noconst_terminal_t
{
std::size_t length() const;
std::size_t tablength() const { return 0; /* no tabs */ }
std::size_t newlines() const;
public:
noconst_1line_terminal_t(const geom_t& geom, int value,
const char* raw) :
noconst_terminal_t(geom, value, raw) {}
};
struct defined_t : public noconst_1line_terminal_t
{
public:
safe_ptr<struct identifier_t> _definition;
defined_t(const geom_t& geom, int value,
const char* raw) :
noconst_1line_terminal_t(geom, value, raw),
_definition(NULL) {}
};
//! e.g. a variable or function
struct identifier_t : public defined_t
{
virtual void accept(class visitor_t& v);
identifier_t(const char* name, geom_t geom);
};
//! a previously defined type, defined by a typename
struct typedef_name_t : public defined_t
{
virtual void accept(class visitor_t& v);
typedef_name_t(const char* name, geom_t geom);
};
//! an enum constant value
struct enumeration_constant_t : public defined_t
{
virtual void accept(class visitor_t& v);
enumeration_constant_t(const char* name, geom_t geom);
};
struct string_base_t : public noconst_terminal_t
{
std::size_t _length, _newlines;
std::size_t length() const;
std::size_t tablength() const { return 0; /* no tabs */ }
std::size_t newlines() const;
public:
string_base_t(const char* value, geom_t geom, int tok);
};
struct string_literal_t : public string_base_t
{
std::string str;
void accept(class visitor_t& v);
string_literal_t(const char* value, geom_t geom);
};
struct comment_t : public string_base_t
{
void accept(class visitor_t& v);
comment_t(const std::string& value, geom_t geom);
};
struct func_name_t : public string_base_t
{
void accept(class visitor_t& v);
func_name_t(const std::string& value, geom_t geom);
};
struct declaration_specifier_type : public node_t, public has_par<> {
declaration_specifier_type() {}
declaration_specifier_type(const geom_t& geom) : node_t(geom) {}
};
#if 0
struct storage_class_specifier_t : public declaration_specifier_type {
virtual void accept(class visitor_t& v);
};
#endif
#if 0
enum type_specifier_id
{
t_void,
t_char,
t_short,
t_long,
t_int,
t_float,
t_double,
t_signed,
t_unsigned,
t_bool,
t_complex
};
enum struct_or_union_id
{
t_struct,
t_union
};
enum type_qualifier_id
{
t_const,
t_restrict,
t_volatile,
t_atomic
};
#endif
enum unary_op_t
{
op_addr,
op_ptr,
op_pos,
op_neg,
op_compl,
op_not,
op_inc_post,
op_dec_post,
op_inc_pre,
op_dec_pre,
};
enum binary_op_t
{
op_asn,
op_asn_mul,
op_asn_div,
op_asn_mod,
op_asn_add,
op_asn_sub,
op_asn_left,
op_asn_right,
op_asn_and,
op_asn_xor,
op_asn_or,
op_or,
op_and,
op_bor,
op_band,
op_xor,
op_lshift,
op_rshift,
op_lt,
op_gt,
op_le,
op_ge,
op_eq,
op_ne,
op_plus,
op_minus,
op_mult,
op_div,
op_mod,
op_com
};
inline bool makes_assignment(binary_op_t b) {
return b >= op_asn && b <= op_asn_or;
}
inline bool makes_assignment(unary_op_t u) {
return u >= op_inc_post && u <= op_dec_pre;
}
typedef ptn<token_t> end_token;
struct expression_t : public node_t, public has_par<> {};
struct unary_expression_r : public expression_t
{
unary_op_t op_id;
ptn< expression_t, // FEATURE: more exactly?
end_token > c;
virtual void accept(class visitor_t& v);
};
struct unary_expression_l : public expression_t
{
unary_op_t op_id;
ptn< token_t,
ptn< expression_t> > c;
virtual void accept(class visitor_t& v);
};
struct binary_expression_t : public expression_t
{
binary_op_t op_id;
ptn< expression_t,
ptn< token_t,
ptn< expression_t> > > c;
virtual void accept(class visitor_t& v);
};
struct ternary_expression_t : public expression_t
{
void accept_children(visitor_t& v);
virtual void accept(class visitor_t& v);
ptn< expression_t,
ptn< token_t,
ptn< expression_t,
ptn< token_t,
ptn< expression_t > > > > > c;
// expression_t(op_t op, token_t* op_token, token_t* op_token_2, node_t *n1, node_t* n2 = NULL, node_t* n3 = NULL) :
// op(op), op_token(op_token), op_token_2(op_token_2), n1(n1), n2(n2), n3(n3) {}
};
struct declarator_base : public node_t
{
};
struct abstract_declarator_t : public declarator_base, public has_par<>
{
ptn< struct pointer_t,
ptn< struct direct_abstract_declarator_t > > c;
void accept(class visitor_t& v);
};
struct type_specifier_t : public declaration_specifier_type
{
ptn< node_t> c; // FEATURE: more granular?
virtual void accept(class visitor_t& v);
};
struct type_specifier_complex_t : public type_specifier_t {
//virtual void accept(class visitor_t& v);
};
struct declaration_base : public virtual node_t
{
virtual declaration_specifiers_t& decl_spec() = 0;
virtual ~declaration_base() {}
virtual void accept(class visitor_t& v) = 0;
};
struct attr_name_t : public noconst_1line_terminal_t
{
virtual void accept(class visitor_t& v);
attr_name_t(const char* name, geom_t geom);
};
struct attr_list_t : public node_t, public has_par<>
{
ptn< struct attr_list_t,
ptn< token_t,
ptn< attr_name_t > > > c;
virtual void accept(class visitor_t& v);
};
struct attributes_t : public node_t, public has_par<>
{
virtual void accept(class visitor_t& v);
ptn< token_t,
ptn< token_t, // (
ptn< token_t, // (
ptn< attr_list_t,
ptn< token_t, // )
end_token // )
> > > > > c;
};
struct struct_or_union_specifier_t : public type_specifier_complex_t
{
bool is_union_type;
enum access_t {
keyword,
identifier,
lbrack,
declaration_list,
rbrack
};
ptn< token_t,
ptn< identifier_t,
ptn< token_t,
ptn< struct struct_declaration_list_t,
ptn< token_t,
ptn< attributes_t >
> > > > > c;
virtual void accept(class visitor_t& v);
};
struct struct_declaration_list_t : public node_t, public has_par<> // FEATURE: when alt list
{
std::list<struct struct_declaration_t*> c;
void accept(class visitor_t& v);
};
struct struct_declaration_t : public has_par<struct_declaration_list_t>,
public declaration_base
{
ptn< struct declaration_specifiers_t, // FEATURE: don't use node_base there
ptn< struct struct_declarator_list_t,
end_token > > c;
void accept(class visitor_t& v);
declaration_specifiers_t& decl_spec() { return *c.value; }
};
struct specifier_qualifier_list_t : public node_t, public has_par<>
{
std::list<declaration_specifier_type*> c;
void accept(class visitor_t& v);
};
struct struct_declarator_list_t : public node_t, public has_par<> // FEATURE: when alt list
{
ptn< struct struct_declarator_list_t,
ptn< token_t, // ,
ptn< struct struct_declarator_t
> > > c;
void accept(class visitor_t& v);
};
struct struct_declarator_t : public node_t, public has_par<struct_declarator_list_t>
{
// careful! all optional!
ptn< struct declarator_t,
ptn< token_t, // :
ptn< expression_t
> > > c;
void accept(class visitor_t& v);
};
struct enum_specifier_t : public type_specifier_complex_t
{
enum access_t {
enum_keyword,
identifier,
lbrack,
enum_list,
comma,
rbrack
};
ptn< token_t,
ptn< identifier_t,
ptn< token_t,
ptn< struct enumerator_list_t,
ptn< token_t,
end_token
> > > > > c;
void accept(class visitor_t& v);
};
struct enumerator_list_t : public node_t, public has_par<> // FEATURE: when alt list
{
ptn< enumerator_list_t,
ptn< token_t,
ptn< struct enumerator_t > > > c;
void accept(class visitor_t& v);
};
struct enumerator_t : public node_t, public has_par<enumerator_list_t>
{
ptn< identifier_t,
ptn< token_t, // =, optional
ptn< expression_t // optional
> > > c;
void accept(class visitor_t& v);
};
struct parameter_type_list_t : public node_t, public has_par<> // FEATURE: declar. or abstr. declar.
{
ptn< struct parameter_list_t,
ptn< token_t,
end_token > > c;
void accept(class visitor_t& v);
};
struct parameter_list_t : public node_t, public has_par<> // FEATURE: when alt list
{
ptn< parameter_list_t,
ptn< token_t,
ptn< struct parameter_declaration_t
> > > c;
void accept(class visitor_t& v);
};
struct parameter_declaration_t : public has_par<parameter_list_t>, public declaration_base
{
ptn< struct declaration_specifiers_t,
ptn< declarator_t,
ptn< abstract_declarator_t
> > > c;
declaration_specifiers_t& decl_spec() { return *c.get<0>(); }
void accept(class visitor_t& v);
};
struct identifier_list_t : public node_t, public has_par<> // FEATURE: when alt list
{
ptn< identifier_list_t,
ptn< token_t,
ptn< identifier_t
> > > c;
void accept(class visitor_t& v);
};
struct type_name_t : public node_t, public has_par<>
{
ptn< declaration_specifiers_t,
ptn< abstract_declarator_t > > c;
void accept(class visitor_t& v);
};
#if 0
template<class Next>
struct to
{
typedef ptn<token_t, Next> type;
};
#endif
struct sizeof_expression_t : public expression_t
{
void accept(class visitor_t& v);
/*tok sizeof_token, lbrace, rbrace;
ch<type_name_t> type_name;*/
//to< ptn< type_name_t, end_token > >::type c;
ptn< token_t,
ptn < token_t,
ptn < type_name_t,
ptn< expression_t,
end_token > > > > c;
};
enum constant_type
{
ct_int,
ct_float,
ct_enum
};
#if 0
struct constant_t : public node_t<struct primary_expression>
{
virtual void accept(class visitor_t& v);
constant_type type;
union {
int i;
float f;
} value;
ptn<identifier_t> c; //!< enumeration id
};
#endif
enum primary_type
{
pt_expression,
pt_constant,
pt_id,
pt_string
};
#if 0
// strings, ints, floats
template<class T>
struct constant_t : public terminal_t
{
std::string value;
// ptn<token_t> c;
// constant_t() {}
constant_t(const char* value, geom_t geom) : terminal_t(geom, 0), value(value) {}
virtual void accept(class visitor_t& v);
};
#endif
struct iconstant_t : public noconst_1line_terminal_t
{
long value;
//! canonical type of suffix, or prefix for char literals
enum suf_type_t
{
no_suffix,
suf_u,
suf_ul,
suf_ull,
suf_l,
suf_ll
} suf_type;
//! literal number system if an integer, otherwise 'character'
enum number_system_t
{
octal,
decimal,
hexadecimal,
character
} number_system;
//! returns the scanf 'type modifier character', as in scanf("%d", &value);
char scanf_modifier() const
{
switch(number_system)
{
case octal: return 'o';
case decimal: return 'd';
case hexadecimal: return 'x';
default: return 'c';
}
}
//! returns an equivalent, canonical suffix string, or prefix for char literals
const char* suffix() const
{
switch(suf_type)
{
case suf_u: return "u";
case suf_ul: return "ul";
case suf_ull: return "ull";
case suf_l: return "l";
case suf_ll: return "ll";
default: return "";
}
}
bool is_signed() const { return suf_type == no_suffix || suf_type == suf_l || suf_type == suf_ll; }
iconstant_t(const char* value, geom_t geom) :
noconst_1line_terminal_t(geom, 0, value) {}
virtual void accept(class visitor_t& v);
};
struct fconstant_t : public noconst_1line_terminal_t
{
fconstant_t(const char* value, geom_t geom) :
noconst_1line_terminal_t(geom, 0, value) {}
virtual void accept(class visitor_t& v);
};
struct primary_expression_t : public expression_t
{
ptn< noconst_terminal_t, // TODO: very bad name!!?
ptn< struct identifier_t, // variable or function
ptn< token_t,
ptn< expression_t,
end_token
> > > > c;
primary_type type;
virtual void accept(class visitor_t& v);
};
struct array_access_expression_t : public expression_t
{
ptn< expression_t,
ptn< token_t,
ptn< expression_t,
end_token > > > c;
virtual void accept(class visitor_t& v);
};
struct argument_expression_list_t : public node_t, public has_par<>
{
private:
expression_t& rget(std::size_t idx) {
return idx ? c.get<0>()->rget(idx-1) : *c.get<2>();
}
public:
ptn< argument_expression_list_t,
ptn< token_t,
ptn< expression_t> > > c;
expression_t& get(std::size_t idx) {
return rget(size() - 1 - idx);
}
std::size_t size() const {
return c.get<0>() ? (1 + c.get<0>()->size()) : 0;
}
virtual void accept(class visitor_t& v);
};
struct function_call_expression_t : public expression_t
{
ptn< expression_t,
ptn< token_t,
ptn< argument_expression_list_t,
end_token > > > c;
virtual void accept(class visitor_t& v);
};
// FEATURE: base for postfix expressions? probably not?
struct struct_access_expression_t : public expression_t
{
bool pointer_access;
ptn< expression_t,
ptn< token_t, // . or ->
ptn< identifier_t > > > c;
virtual void accept(class visitor_t& v);
};
struct compound_literal_t : public expression_t
{
ptn< token_t,
ptn< type_name_t,
ptn< token_t,
ptn< token_t,
ptn< struct initializer_list_t,
ptn< token_t,
end_token
> > > > > > c;
virtual void accept(class visitor_t& v);
};
struct cast_expression_t : public expression_t
{
ptn< token_t,
ptn< type_name_t,
ptn< token_t,
ptn< expression_t
> > > > c;
virtual void accept(class visitor_t& v);
};
/*struct type_specifier_token : public type_specifier_t
{
ptn<token_t> c;
virtual void accept(class visitor_t& v);
};
struct type_identifier : public type_specifier_t
{
ptn<identifier_t> c;
virtual void accept(class visitor_t& v);
};*/
#if 0
template<class IdType, class Base = node_t>
struct token_base : public Base
{
IdType id;
virtual void accept(class visitor_t& v);
token_base(geom_t pos, const IdType& id) : Base(pos), id(id) {}
};
typedef token_base<type_specifier_id, type_specifier_t> type_specifier_simple_t;
#endif
/*struct type_specifier_simple_t : public token_base
{
type_specifier_id id;
virtual void accept(class visitor_t& v);
};*/
/*struct type_specifier_t : public declaration_specifier_type
{
ch<type_specifier_simple_t> simple;
ch<type_specifier_complex_t> complex;
virtual void accept(class visitor_t& v);
};*/
struct type_qualifier_t : public declaration_specifier_type
{
ptn<token_t> c;
virtual void accept(class visitor_t& v);
};
#if 0
struct function_specifier_t : public declaration_specifier_type {
virtual void accept(class visitor_t& v);
};
// FEATURE: needed?
struct alignment_specifier_t : public declaration_specifier_type {
virtual void accept(class visitor_t& v);
};
#endif
struct declaration_list_t : public node_t, public has_par<struct function_definition_t>
{
virtual void accept(class visitor_t& v);
std::list<struct declaration_t*> c;
};
// FEATURE: use compound_statement_t here as a parent and put declaration into wrapper?
struct block_item_t : public virtual node_t, public has_par<> {
virtual void accept(class visitor_t& v);
};
struct statement_t : public block_item_t {};
/*struct conditional_expression_t : public expression_t
{
virtual void accept(class visitor_t& v);
};*/
struct labeled_statement_t : public statement_t
{
enum type_t {
case_label,
default_label,
jump_label
};
type_t type;
enum access {
keyword,
identifier,
case_expr,
colon,
statement
};
// WARNING:
// there may be multiple statements following
// this labeled statement, "statement" is just
// the first one
ptn< token_t, // keyword: case, default
ptn< identifier_t, // label: jump
ptn< expression_t, // case
ptn< token_t, // colon: all
ptn< statement_t // all
> > > > > c;
virtual void accept(class visitor_t& v);
};
struct expression_statement_t : public statement_t
{
virtual void accept(class visitor_t& v);
ptn< expression_t, // can be zero
end_token > c;
};
/**
represents one of the following rules:
IF ( expression ) statement ELSE statement
IF ( expression ) statement
SWITCH ( expression ) statement
*/
struct selection_statement_t : public statement_t
{
virtual void accept(class visitor_t& v);
ptn< token_t, // 1st keyword token
ptn< token_t, // (
ptn< expression_t,
ptn< token_t, // )
ptn< statement_t, // all
ptn< token_t, // else
ptn< statement_t
> > > > > > > c;
};
/**
represents one of the following rules:
WHILE ( expression ) statement
DO statement WHILE ( expression ) ;
FOR ( expression_statement expression_statement ) statement
FOR ( expression_statement expression_statement expression ) statement
FOR ( declaration expression_statement ) statement
FOR ( declaration expression_statement expression ) statement
*/
struct iteration_statement_t : public statement_t
{
virtual void accept(class visitor_t& v);
// careful! order of statement can differ!
enum type_t {
while_type,
do_type,
for_type
} type;
enum for_type_t
{
for_type_init_niter,
for_type_init_iter,
for_type_decl_niter,
for_type_decl_iter
} _for_type;
enum access {
do_keyword, // 2
keyword,
lbrace,
while_cond, // 1, 2
for_init, // 3, 4
for_decl, // 5, 6
for_cond, // 3-6
for_iter, // 4, 6
rbrace,
statement,
semicolon // 2
};
ptn< token_t,
ptn< token_t,
ptn< token_t,
ptn< expression_t,
ptn< expression_statement_t,
ptn< declaration_t,
ptn< expression_statement_t,
ptn< expression_t,
ptn< token_t,
ptn< statement_t,
end_token
> > > > > > > > > > c;
//! returns the conditional expression (can be NULL in for loops)
expression_t* condition();
};
struct designator_t : public node_t, public has_par<struct designator_list_t> {};
struct designator_id : public designator_t
{
ptn< token_t,
ptn< identifier_t > > c;
virtual void accept(class visitor_t& v);
};
struct designator_constant_expr : public designator_t
{
ptn< token_t,
ptn< expression_t,
end_token > > c;
virtual void accept(class visitor_t& v);
};
struct designator_list_t : public node_t, public has_par<struct initializer_list_t>
{
std::list<designator_t*> c;
virtual void accept(class visitor_t& v);
};