Subversion Repositories tendra.SVN

Rev

Rev 2 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 7u83 1
%prefixes%
2
 
3
 
4
/*
5
    TERMINAL PREFIX
6
 
7
    This prefix is used to identify lexical token numbers in syntax.h
8
    (see also symbols.h).
9
*/
10
 
11
terminal = lex_ ;
12
 
13
 
14
%maps%
15
 
16
 
17
/*
18
    PARSER ENTRY POINTS
19
 
20
    There are a number of entry points into the parser.  The main ones
21
    are translation-unit which is used to parse an entire translation
22
    unit and hash-if-expression which is used to parse expressions in
23
    #if preprocessing directives.
24
*/
25
 
26
translation-unit -> parse_file ;
27
expression-entry -> parse_exp ;
28
id-entry -> parse_id ;
29
operator-id -> parse_operator ;
30
declaration-entry -> parse_decl ;
31
function-definition-entry -> parse_func ;
32
type-id-entry -> parse_type ;
33
token-type-id -> parse_tok_type ;
34
member-type-id -> parse_mem_type ;
35
parameter-entry -> parse_param ;
36
statement-entry -> parse_stmt ;
37
initialiser-entry -> parse_init ;
38
hash-if-expression -> parse_nat ;
39
template-type-param -> parse_type_param ;
40
constant-offset -> parse_offset ;
41
 
42
 
43
/*
44
    BASIC TYPES
45
 
46
    The type BOOL is used to hold the predicate values, true and false.
47
    The type COUNT is used to hold the various counters maintained (see
48
    predict.c).  The type LEX is used to hold a lexical token number
49
    (i.e.  one of the values defined in syntax.h).  The other types used
50
    in the parser map in a simple fashion to the main program types.
51
    Note that it is necessary to use aliases for compound types because
52
    of the restrictions imposed by sid.
53
*/
54
 
55
ACCESS -> DECL_SPEC ;
56
ACCESSES -> ACCESS_LIST ;
57
BOOL -> int ;
58
BTYPE -> BASE_TYPE ;
59
CONDITION -> unsigned ;
60
COUNT -> int ;
61
CV -> CV_SPEC ;
62
DECL -> IDENTIFIER ;
63
DSPEC -> DECL_SPEC ;
64
EXP -> EXP ;
65
IDENTIFIER -> IDENTIFIER ;
66
KEY -> BASE_TYPE ;
67
LEX -> int ;
68
LINKAGE -> DECL_SPEC ;
69
LIST-EXP -> SID_LIST_EXP ;
70
LIST-TYPE -> SID_LIST_TYPE ;
71
NAMESPACE -> NAMESPACE ;
72
NUMBER -> int ;
73
OFFSET -> OFFSET ;
74
QUALIFIER -> QUALIFIER ;
75
TEMPLATE -> TOKEN ;
76
TYPE -> TYPE ;
77
 
78
 
79
/*
80
    FILE HEADERS
81
 
82
    These headers are prepended to the parser definition and declaration
83
    output files.  Because of the simple file splitting algorithm applied
84
    to the output this should contain only declarations and not definitions.
85
*/
86
 
87
%header% @{
88
/*
89
    		 Crown Copyright (c) 1997, 1998
90
 
91
    This TenDRA(r) Computer Program is subject to Copyright
92
    owned by the United Kingdom Secretary of State for Defence
93
    acting through the Defence Evaluation and Research Agency
94
    (DERA).  It is made available to Recipients with a
95
    royalty-free licence for its use, reproduction, transfer
96
    to other parties and amendment for any purpose not excluding
97
    product development provided that any such use et cetera
98
    shall be deemed to be acceptance of the following conditions:-
99
 
100
        (1) Its Recipients shall ensure that this Notice is
101
        reproduced upon any copies or amended versions of it;
102
 
103
        (2) Any amended version of it shall be clearly marked to
104
        show both the nature of and the organisation responsible
105
        for the relevant amendment or amendments;
106
 
107
        (3) Its onward transfer from a recipient to another
108
        party shall be deemed to be that party's acceptance of
109
        these conditions;
110
 
111
        (4) DERA gives no warranty or assurance as to its
112
        quality or suitability for any purpose and DERA accepts
113
        no liability whatsoever in relation to any use to which
114
        it may be put.
115
*/
116
 
117
 
118
#include "config.h"
119
#include "c_types.h"
120
#include "ctype_ops.h"
121
#include "exp_ops.h"
122
#include "hashid_ops.h"
123
#include "id_ops.h"
124
#include "nspace_ops.h"
125
#include "type_ops.h"
126
#include "error.h"
127
#include "catalog.h"
128
#include "option.h"
129
#include "access.h"
130
#include "allocate.h"
131
#include "assign.h"
132
#include "basetype.h"
133
#include "cast.h"
134
#include "chktype.h"
135
#include "class.h"
136
#include "constant.h"
137
#include "construct.h"
138
#include "convert.h"
139
#include "declare.h"
140
#include "derive.h"
141
#include "dump.h"
142
#include "exception.h"
143
#include "expression.h"
144
#include "function.h"
145
#include "hash.h"
146
#include "identifier.h"
147
#include "initialise.h"
148
#include "inttype.h"
149
#include "label.h"
150
#include "lex.h"
151
#include "literal.h"
152
#include "member.h"
153
#include "namespace.h"
154
#include "parse.h"
155
#include "pragma.h"
156
#include "predict.h"
157
#include "preproc.h"
158
#include "redeclare.h"
159
#include "rewrite.h"
160
#include "statement.h"
161
#include "symbols.h"
162
#include "template.h"
163
#include "tokdef.h"
164
#include "token.h"
165
#include "typeid.h"
166
#include "variable.h"
167
 
168
 
169
/*
170
    COMPOUND TYPE ALIASES
171
 
172
    These are the aliases for the compound types used in the parser.
173
*/
174
 
175
typedef LIST ( EXP ) SID_LIST_EXP ;
176
typedef LIST ( TYPE ) SID_LIST_TYPE ;
177
 
178
 
179
/*
180
    FUNCTION DECLARATIONS
181
 
182
    The function declarations are included at this point so that the
183
    type definitions are in scope.
184
*/
185
 
186
#include "syntax.h"
187
 
188
 
189
/*
190
    COMPILATION MODE
191
 
192
    The output of sid is automatically generated.  Hence it is not
193
    necessarily appropriate to apply the same level of checking to this
194
    as to the rest of the program.  These pragmas describe the relaxations
195
    allowed for the sid output.
196
*/
197
 
198
#if FS_TENDRA
199
#pragma TenDRA begin
200
#pragma TenDRA const conditional allow
201
#pragma TenDRA unreachable code allow
202
#pragma TenDRA variable analysis off
203
#endif
204
 
205
 
206
@}, @{
207
/*
208
    		 Crown Copyright (c) 1997, 1998
209
 
210
    This TenDRA(r) Computer Program is subject to Copyright
211
    owned by the United Kingdom Secretary of State for Defence
212
    acting through the Defence Evaluation and Research Agency
213
    (DERA).  It is made available to Recipients with a
214
    royalty-free licence for its use, reproduction, transfer
215
    to other parties and amendment for any purpose not excluding
216
    product development provided that any such use et cetera
217
    shall be deemed to be acceptance of the following conditions:-
218
 
219
        (1) Its Recipients shall ensure that this Notice is
220
        reproduced upon any copies or amended versions of it;
221
 
222
        (2) Any amended version of it shall be clearly marked to
223
        show both the nature of and the organisation responsible
224
        for the relevant amendment or amendments;
225
 
226
        (3) Its onward transfer from a recipient to another
227
        party shall be deemed to be that party's acceptance of
228
        these conditions;
229
 
230
        (4) DERA gives no warranty or assurance as to its
231
        quality or suitability for any purpose and DERA accepts
232
        no liability whatsoever in relation to any use to which
233
        it may be put.
234
*/
235
 
236
 
237
#ifndef SYNTAX_INCLUDED
238
#define SYNTAX_INCLUDED
239
 
240
@} ;
241
 
242
 
243
%terminals%
244
 
245
 
246
/*
247
    IDENTIFIER TERMINALS
248
 
249
    Identifiers and related terminals (type names, namespace names and
250
    destructor names) are identified by means of an identifier stored in
251
    crt_token by expand_token.
252
*/
253
 
254
identifier : () -> ( id ) = @{
255
    @id = crt_token->pp_data.id.use ;
256
@} ;
257
 
258
type-name : () -> ( id ) = @{
259
    @id = crt_token->pp_data.id.use ;
260
@} ;
261
 
262
namespace-name : () -> ( id ) = @{
263
    @id = crt_token->pp_data.id.use ;
264
@} ;
265
 
266
statement-name : () -> ( id ) = @{
267
    @id = crt_token->pp_data.id.use ;
268
@} ;
269
 
270
destructor-name : () -> ( id ) = @{
271
    @id = crt_token->pp_data.id.use ;
272
@} ;
273
 
274
template-id : () -> ( id ) = @{
275
    IDENTIFIER id = crt_token->pp_data.tok.id ;
276
    PPTOKEN *args = crt_token->pp_data.tok.args ;
277
    @id = parse_id_template ( id, args, 0 ) ;
278
    crt_templ_qualifier = 1 ;
279
    RESCAN_LEXER ;
280
@} ;
281
 
282
template-type : () -> ( id ) = @{
283
    IDENTIFIER id = crt_token->pp_data.tok.id ;
284
    PPTOKEN *args = crt_token->pp_data.tok.args ;
285
    @id = parse_type_template ( id, args, 0 ) ;
286
    crt_templ_qualifier = 1 ;
287
    RESCAN_LEXER ;
288
@} ;
289
 
290
 
291
/*
292
    NAMESPACE SPECIFIER TERMINALS
293
 
294
    Namespace specifiers (i.e. sequences of namespace or class names
295
    separated using '::') are identified by expand_token.  The full nested
296
    names are those which begin with the global namespace.
297
*/
298
 
299
nested-name : () -> ( ns ) = @{
300
    @ns = crt_token->pp_data.ns ;
301
@} ;
302
 
303
full-name : () -> ( ns ) = @{
304
    @ns = crt_token->pp_data.ns ;
305
@} ;
306
 
307
 
308
/*
309
    POINTER TO MEMBER TERMINALS
310
 
311
    Pointer to member specifiers (such as 'C::*') are identified by
312
    expand_token.  The identifier corresponding to the given class is
313
    stored in crt_token.
314
*/
315
 
316
nested-name-star : () -> ( id ) = @{
317
    @id = crt_token->pp_data.id.use ;
318
@} ;
319
 
320
full-name-star : () -> ( id ) = @{
321
    @id = crt_token->pp_data.id.use ;
322
@} ;
323
 
324
 
325
/*
326
    INTEGER AND FLOATING-POINT LITERAL TERMINALS
327
 
328
    Integer and floating-point literal tokens have already been transformed
329
    into their corresponding expressions by expand_token, which stores this
330
    information in crt_token.
331
*/
332
 
333
integer-exp : () -> ( e ) = @{
334
    @e = crt_token->pp_data.exp ;
335
@} ;
336
 
337
floating-exp : () -> ( e ) = @{
338
    @e = crt_token->pp_data.exp ;
339
@} ;
340
 
341
 
342
/*
343
    STRING AND CHARACTER LITERAL TERMINALS
344
 
345
    String and character literal tokens have already been transformed
346
    into their corresponding expressions by expand_token, which stores this
347
    information in crt_token.
348
*/
349
 
350
char-exp : () -> ( e ) = @{
351
    @e = crt_token->pp_data.exp ;
352
@} ;
353
 
354
wchar-exp : () -> ( e ) = @{
355
    @e = crt_token->pp_data.exp ;
356
@} ;
357
 
358
string-exp : () -> ( e ) = @{
359
    @e = crt_token->pp_data.exp ;
360
@} ;
361
 
362
wstring-exp : () -> ( e ) = @{
363
    @e = crt_token->pp_data.exp ;
364
@} ;
365
 
366
 
367
/*
368
    CONDITIONAL COMPILATION TERMINALS
369
 
370
    Any target dependent conditional compilation expressions are stored
371
    in crt_token by the preprocessing routines.
372
*/
373
 
374
hash-if : () -> ( e ) = @{
375
    @e = crt_token->pp_data.exp ;
376
@} ;
377
 
378
hash-elif : () -> ( e ) = @{
379
    @e = crt_token->pp_data.exp ;
380
@} ;
381
 
382
 
383
/*
384
    COMPLEX EXPRESSION AND TYPE TERMINALS
385
 
386
    These terminals are used to handle complex expressions and types
387
    such as token applications.
388
*/
389
 
390
complex-exp : () -> ( e ) = @{
391
    IDENTIFIER id = crt_token->pp_data.tok.id ;
392
    PPTOKEN *args = crt_token->pp_data.tok.args ;
393
    @e = parse_exp_token ( id, args ) ;
394
    RESCAN_LEXER ;
395
@} ;
396
 
397
complex-stmt : () -> ( e ) = @{
398
    IDENTIFIER id = crt_token->pp_data.tok.id ;
399
    PPTOKEN *args = crt_token->pp_data.tok.args ;
400
    @e = parse_exp_token ( id, args ) ;
401
    RESCAN_LEXER ;
402
@} ;
403
 
404
complex-type : () -> ( t ) = @{
405
    IDENTIFIER id = crt_token->pp_data.tok.id ;
406
    PPTOKEN *args = crt_token->pp_data.tok.args ;
407
    @t = parse_type_token ( id, args ) ;
408
    have_type_declaration = TYPE_DECL_NONE ;
409
    have_type_specifier = 1 ;
410
    RESCAN_LEXER ;
411
@} ;
412
 
413
 
414
%actions%
415
 
416
 
417
/*
418
    LEXICAL TOKENS
419
 
420
    These actions give the basic values for the type LEX.  They are used
421
    primarily in overloaded operator function names, but they are also used
422
    to distinguish closely related groups of expressions, such as relational
423
    expressions.  Note that the primary form of the token has been given
424
    whenever there is a choice, otherwise the actions are very dull.
425
*/
426
 
427
<lex_crt> : () -> ( t ) = @{ @t = crt_lex_token ; @} ;
428
<lex_close_round> : () -> ( t ) = @{ @t = lex_close_Hround ; @} ;
429
<lex_close_square> : () -> ( t ) = @{ @t = lex_close_Hsquare_H1 ; @} ;
430
<lex_colon> : () -> ( t ) = @{ @t = lex_colon ; @} ;
431
<lex_cond_op> : () -> ( t ) = @{ @t = lex_cond_Hop ; @} ;
432
<lex_open_round> : () -> ( t ) = @{ @t = lex_open_Hround ; @} ;
433
<lex_semicolon> : () -> ( t ) = @{ @t = lex_semicolon ; @} ;
434
<lex_alignof> : () -> ( t ) = @{ @t = lex_alignof ; @} ;
435
<lex_array_op> : () -> ( t ) = @{ @t = lex_array_Hop ; @} ;
436
<lex_func_op> : () -> ( t ) = @{ @t = lex_func_Hop ; @} ;
437
<lex_new> : () -> ( t ) = @{ @t = lex_new ; @} ;
438
<lex_delete> : () -> ( t ) = @{ @t = lex_delete ; @} ;
439
<lex_new_array> : () -> ( t ) = @{ @t = lex_new_Harray ; @} ;
440
<lex_delete_array> : () -> ( t ) = @{ @t = lex_delete_Harray ; @} ;
441
<lex_sizeof> : () -> ( t ) = @{ @t = lex_sizeof ; @} ;
442
<lex_typeid> : () -> ( t ) = @{ @t = lex_typeid ; @} ;
443
<lex_vtable> : () -> ( t ) = @{ @t = lex_vtable ; @} ;
444
 
445
 
446
/*
447
    SPECIAL FUNCTION IDENTIFIERS
448
 
449
    These actions are used to construct the identifiers corresponding to
450
    the operator-function-ids and conversion-function-ids.  In addition,
451
    id_none gives the null identifier and id_anon generates a unique
452
    anonymous identifier.
453
*/
454
 
455
<type_decl_begin> : () -> ( td ) = @{
456
    @td = have_type_declaration ;
457
    have_type_declaration = TYPE_DECL_NONE ;
458
@} ;
459
 
460
<type_decl_end> : ( td ) -> ( d ) = @{
461
    int td = have_type_declaration ;
462
    @d = 0 ;
463
    if ( td != TYPE_DECL_NONE ) {
464
	if ( td == TYPE_DECL_ELABORATE && found_elaborate_type ) {
465
	    /* This is allowed */
466
	    /* EMPTY */
467
	} else {
468
	    @d = 1 ;
469
	}
470
    }
471
    have_type_declaration = @td ;
472
@} ;
473
 
474
<type_decl_quit> : ( td ) -> () = @{
475
    have_type_declaration = @td ;
476
@} ;
477
 
478
<operator_func> : ( op ) -> ( id ) = @{
479
    /* op will be in its primary form */
480
    HASHID nm = lookup_op ( @op ) ;
481
    @id = DEREF_id ( hashid_id ( nm ) ) ;
482
    set_hashid_loc ( @id, underlying_op ) ;
483
@} ;
484
 
485
<conversion_func> : ( t, d ) -> ( id ) = @{
486
    HASHID nm = lookup_conv ( @t ) ;
487
    if ( @d ) report ( crt_loc, ERR_class_conv_fct_typedef ( nm ) ) ;
488
    @id = DEREF_id ( hashid_id ( nm ) ) ;
489
    set_hashid_loc ( @id, underlying_op ) ;
490
@} ;
491
 
492
<pseudo_destructor> : ( t1, b1, t2, b2 ) -> ( id ) = @{
493
    @id = make_pseudo_destr ( @t1, @b1, @t2, @b2 ) ;
494
@} ;
495
 
496
<id_none> : () -> ( id ) = @{
497
    @id = NULL_id ;
498
    crt_id_qualifier = qual_none ;
499
    qual_namespace = NULL_nspace ;
500
@} ;
501
 
502
<id_anon> : () -> ( id ) = @{
503
    HASHID nm = lookup_anon () ;
504
    @id = DEREF_id ( hashid_id ( nm ) ) ;
505
    crt_id_qualifier = qual_none ;
506
    qual_namespace = NULL_nspace ;
507
@} ;
508
 
509
 
510
/*
511
    NAMESPACES AND IDENTIFIER LOOK-UP
512
 
513
    These actions are used to identify namespaces and identifiers within
514
    those namespaces.
515
*/
516
 
517
<namespace_none> : () -> ( ns ) = @{
518
    @ns = NULL_nspace ;
519
    crt_id_qualifier = qual_none ;
520
    qual_namespace = NULL_nspace ;
521
@} ;
522
 
523
<namespace_global> : () -> ( ns ) = @{
524
    @ns = global_namespace ;
525
    crt_id_qualifier = qual_top ;
526
    qual_namespace = @ns ;
527
@} ;
528
 
529
<namespace_nested> : ( ns ) -> () = @{
530
    crt_id_qualifier = qual_nested ;
531
    qual_namespace = @ns ;
532
@} ;
533
 
534
<namespace_full> : ( ns ) -> () = @{
535
    crt_id_qualifier = qual_full ;
536
    qual_namespace = @ns ;
537
@} ;
538
 
539
<namespace_id> : ( ns, id ) -> ( n ) = @{
540
    @n = check_id ( @ns, @id, 0 ) ;
541
    last_namespace = @ns ;
542
@} ;
543
 
544
<namespace_simple> : ( id ) -> ( n ) = @{
545
    @n = @id ;
546
    crt_id_qualifier = qual_none ;
547
    last_namespace = crt_namespace ;
548
@} ;
549
 
550
<namespace_complex> : ( id ) -> ( n ) = @{
551
    @n = check_id ( NULL_nspace, @id, 0 ) ;
552
    crt_id_qualifier = qual_none ;
553
    last_namespace = crt_namespace ;
554
@} ;
555
 
556
<namespace_templ> : ( ns, id, q ) -> ( n ) = @{
557
    @n = check_id ( @ns, @id, @q ) ;
558
    last_namespace = @ns ;
559
@} ;
560
 
561
<namespace_type> : ( ns ) -> ( id ) = @{
562
    @id = DEREF_id ( nspace_name ( @ns ) ) ;
563
@} ;
564
 
565
 
566
/*
567
    IDENTIFIER QUALIFIERS
568
 
569
    These actions are used to set crt_id_qualifier to the qualifier of an
570
    identifier.
571
*/
572
 
573
<qual_get> : () -> ( i, b ) = @{
574
    @i = crt_id_qualifier ;
575
    @b = crt_templ_qualifier ;
576
@} ;
577
 
578
<qual_set> : ( i, b ) -> () = @{
579
    crt_id_qualifier = @i ;
580
    crt_templ_qualifier = @b ;
581
@} ;
582
 
583
<qual_none> : () -> () = @{
584
    crt_id_qualifier = qual_none ;
585
    crt_templ_qualifier = 0 ;
586
    qual_namespace = NULL_nspace ;
587
@} ;
588
 
589
 
590
/*
591
    LISTS OF EXPRESSIONS
592
 
593
    These actions give the basic constructs for building up lists of
594
    expressions.  They map directly to the calculus list operations.
595
*/
596
 
597
<list_exp_null> : () -> ( p ) = @{
598
    @p = NULL_list ( EXP ) ;
599
@} ;
600
 
601
<list_exp_cons> : ( e, q ) -> ( p ) = @{
602
    CONS_exp ( @e, @q, @p ) ;
603
@} ;
604
 
605
 
606
/*
607
    EXPRESSION CONSTRUCTORS
608
 
609
    These actions describe how to build up expressions from more primitive
610
    expressions.  The null expression, exp_none, is used to indicate that
611
    an optional expression is absent.  Most of the actions are very
612
    straightforward, either directly calling a calculus EXP constructor
613
    or the appropriate expression construction function.
614
*/
615
 
616
<exp_none> : () -> ( e ) = @{
617
    @e = NULL_exp ;
618
@} ;
619
 
620
<exp_aggregate> : ( p ) -> ( e ) = @{
621
    /* The expression type is a dummy */
622
    MAKE_exp_aggregate ( type_void, @p, NULL_list ( OFFSET ), @e ) ;
623
@} ;
624
 
625
<exp_and> : ( a, b ) -> ( e ) = @{
626
    @e = make_and_exp ( @a, @b ) ;
627
@} ;
628
 
629
<exp_arrow_begin> : ( a ) -> ( e, t, ns ) = @{
630
    @e = begin_field_exp ( lex_arrow, @a, &@t, &@ns ) ;
631
@} ;
632
 
633
<exp_arrow_end> : ( a, t, ns, id, q ) -> ( e ) = @{
634
    @e = end_field_exp ( lex_arrow, @a, @t, @ns, @id, @q ) ;
635
@} ;
636
 
637
<exp_arrow_star> : ( a, b ) -> ( e ) = @{
638
    @e = make_member_exp ( lex_arrow_Hstar, @a, @b ) ;
639
    in_ptr_mem_selector-- ;
640
@} ;
641
 
642
<exp_assign> : ( a, b ) -> ( e ) = @{
643
    @e = make_assign_exp ( @a, @b, 0 ) ;
644
@} ;
645
 
646
<exp_assign_op> : ( op, a, b ) -> ( e ) = @{
647
    /* op will be in its primary form */
648
    @e = make_become_exp ( @op, @a, @b ) ;
649
@} ;
650
 
651
<exp_cast> : ( t, a, n ) -> ( e ) = @{
652
    /* n is the number of type definitions in t */
653
    @e = make_cast_exp ( @t, @a, @n ) ;
654
@} ;
655
 
656
<exp_comma> : ( p ) -> ( e ) = @{
657
    @e = make_comma_exp ( @p ) ;
658
@} ;
659
 
660
<exp_cond> : ( a, b, c ) -> ( e ) = @{
661
    @e = make_cond_exp ( @a, @b, @c ) ;
662
@} ;
663
 
664
<exp_const_cast> : ( t, a, n ) -> ( e ) = @{
665
    /* n is the number of type definitions in t */
666
    @e = make_const_cast_exp ( @t, @a, @n ) ;
667
@} ;
668
 
669
<exp_delete> : ( b, op, a ) -> ( e ) = @{
670
    @e = make_delete_exp ( @op, @b, @a ) ;
671
@} ;
672
 
673
<exp_div> : ( a, b ) -> ( e ) = @{
674
    @e = make_mult_exp ( lex_div, @a, @b ) ;
675
@} ;
676
 
677
<exp_dot_begin> : ( a ) -> ( e, t, ns ) = @{
678
    @e = begin_field_exp ( lex_dot, @a, &@t, &@ns ) ;
679
@} ;
680
 
681
<exp_dot_end> : ( a, t, ns, id, q ) -> ( e ) = @{
682
    @e = end_field_exp ( lex_dot, @a, @t, @ns, @id, @q ) ;
683
@} ;
684
 
685
<exp_dot_star> : ( a, b ) -> ( e ) = @{
686
    @e = make_member_exp ( lex_dot_Hstar, @a, @b ) ;
687
    in_ptr_mem_selector-- ;
688
@} ;
689
 
690
<exp_dynamic_cast> : ( t, a, n ) -> ( e ) = @{
691
    /* n is the number of type definitions in t */
692
    @e = make_dynamic_cast_exp ( @t, @a, @n ) ;
693
@} ;
694
 
695
<exp_ellipsis> : () -> ( e ) = @{
696
    @e = make_ellipsis_exp () ;
697
@} ;
698
 
699
<exp_equality> : ( op, a, b ) -> ( e ) = @{
700
    /* op will be in its primary form */
701
    @e = make_equality_exp ( @op, @a, @b ) ;
702
@} ;
703
 
704
<exp_eval> : ( a ) -> ( e ) = @{
705
    @e = convert_reference ( @a, REF_NORMAL ) ;
706
    @e = convert_lvalue ( @e ) ;
707
@} ;
708
 
709
<exp_false> : () -> ( e ) = @{
710
    @e = make_bool_exp ( BOOL_FALSE, exp_int_lit_tag ) ;
711
@} ;
712
 
713
<exp_func> : ( a, p ) -> ( e ) = @{
714
    @e = make_func_exp ( @a, @p, 0 ) ;
715
@} ;
716
 
717
<exp_func_cast> : ( t, p ) -> ( e ) = @{
718
    @e = make_func_cast_exp ( @t, @p ) ;
719
@} ;
720
 
721
<exp_identifier> : ( id ) -> ( e ) = @{
722
    @e = make_id_exp ( @id ) ;
723
@} ;
724
 
725
<exp_ignore> : ( a ) -> ( e ) = @{
726
    @e = make_cast_exp ( type_void, @a, 0 ) ;
727
@} ;
728
 
729
<exp_index> : ( a, b ) -> ( e ) = @{
730
    @e = make_index_exp ( @a, @b ) ;
731
@} ;
732
 
733
<exp_indir> : ( a ) -> ( e ) = @{
734
    @e = make_indir_exp ( @a ) ;
735
@} ;
736
 
737
<exp_initialiser> : ( p ) -> ( e ) = @{
738
    MAKE_exp_initialiser ( type_void, @p, NULL_list ( OFFSET ), 0, 0, 0, @e ) ;
739
@} ;
740
 
741
<exp_location> : ( a ) -> ( e ) = @{
742
    MAKE_exp_location ( type_void, crt_loc, @a, @e ) ;
743
@} ;
744
 
745
<exp_log_and> : ( a, b ) -> ( e ) = @{
746
    @e = make_log_and_exp ( @a, @b ) ;
747
@} ;
748
 
749
<exp_log_or> : ( a, b ) -> ( e ) = @{
750
    @e = make_log_or_exp ( @a, @b ) ;
751
@} ;
752
 
753
<exp_lshift> : ( a, b ) -> ( e ) = @{
754
    @e = make_shift_exp ( lex_lshift, @a, @b ) ;
755
@} ;
756
 
757
<exp_maxmin> : ( op, a, b ) -> ( e ) = @{
758
    @e = make_mult_exp ( @op, @a, @b ) ;
759
@} ;
760
 
761
<exp_minus> : ( a, b ) -> ( e ) = @{
762
    @e = make_minus_exp ( @a, @b ) ;
763
@} ;
764
 
765
<exp_mult> : ( a, b ) -> ( e ) = @{
766
    @e = make_mult_exp ( lex_star, @a, @b ) ;
767
@} ;
768
 
769
<exp_new> : ( b, p, t, n, d, i ) -> ( e ) = @{
770
    @e = make_new_exp ( @t, @n + @d, @b, @p, @i ) ;
771
@} ;
772
 
773
<exp_new_init> : ( t, p ) -> ( e ) = @{
774
    @e = make_new_init ( @t, @p, 1 ) ;
775
@} ;
776
 
777
<exp_new_none> : ( t ) -> ( e ) = @{
778
    @e = make_new_init ( @t, NULL_list ( EXP ), 0 ) ;
779
@} ;
780
 
781
<exp_new_start> : () -> ( e ) = @{
782
    @e = begin_new_try () ;
783
@} ;
784
 
785
<exp_new_end> : ( a, b ) -> ( e ) = @{
786
    @e = end_new_try ( @a, @b ) ;
787
@} ;
788
 
789
<exp_not> : ( a ) -> ( e ) = @{
790
    @e = make_not_exp ( @a ) ;
791
@} ;
792
 
793
<exp_or> : ( a, b ) -> ( e ) = @{
794
    @e = make_or_exp ( @a, @b ) ;
795
@} ;
796
 
797
<exp_paren_begin> : () -> () = @{
798
    IGNORE incr_value ( OPT_VAL_paren_depth ) ;
799
@} ;
800
 
801
<exp_paren_end> : ( a ) -> ( e ) = @{
802
    @e = make_paren_exp ( @a ) ;
803
    decr_value ( OPT_VAL_paren_depth ) ;
804
@} ;
805
 
806
<exp_plus> : ( a, b ) -> ( e ) = @{
807
    @e = make_plus_exp ( @a, @b ) ;
808
@} ;
809
 
810
<exp_postdec> : ( a ) -> ( e ) = @{
811
    @e = make_postfix_exp ( lex_minus_Hminus, @a ) ;
812
@} ;
813
 
814
<exp_postinc> : ( a ) -> ( e ) = @{
815
    @e = make_postfix_exp ( lex_plus_Hplus, @a ) ;
816
@} ;
817
 
818
<exp_predec> : ( a ) -> ( e ) = @{
819
    @e = make_prefix_exp ( lex_minus_Hminus, @a ) ;
820
@} ;
821
 
822
<exp_preinc> : ( a ) -> ( e ) = @{
823
    @e = make_prefix_exp ( lex_plus_Hplus, @a ) ;
824
@} ;
825
 
826
<exp_ptr_mem> : () -> () = @{
827
    in_ptr_mem_selector++ ;
828
@} ;
829
 
830
<exp_ref> : ( a ) -> ( e ) = @{
831
    @e = make_ref_exp ( @a, 0 ) ;
832
@} ;
833
 
834
<exp_reinterpret_cast> : ( t, a, n ) -> ( e ) = @{
835
    /* n is the number of type definitions in t */
836
    @e = make_reinterp_cast_exp ( @t, @a, @n ) ;
837
@} ;
838
 
839
<exp_relation> : ( op, a, b ) -> ( e ) = @{
840
    /* op will be in its primary form */
841
    @e = make_relation_exp ( @op, @a, @b ) ;
842
@} ;
843
 
844
<exp_rem> : ( a, b ) -> ( e ) = @{
845
    @e = make_rem_exp ( @a, @b ) ;
846
@} ;
847
 
848
<exp_rshift> : ( a, b ) -> ( e ) = @{
849
    @e = make_shift_exp ( lex_rshift, @a, @b ) ;
850
@} ;
851
 
852
<exp_set> : ( a ) -> ( e ) = @{
853
    @e = make_set_exp ( @a ) ;
854
@} ;
855
 
856
<exp_sizeof> : ( op, t, a, n ) -> ( e ) = @{
857
    @e = make_sizeof_exp ( @t, @a, @n, @op ) ;
858
@} ;
859
 
860
<exp_static_cast> : ( t, a, n ) -> ( e ) = @{
861
    @e = make_static_cast_exp ( @t, @a, @n ) ;
862
@} ;
863
 
864
<exp_this> : () -> ( e ) = @{
865
    @e = make_this_exp () ;
866
@} ;
867
 
868
<exp_throw> : ( a ) -> ( e ) = @{
869
    @e = make_throw_exp ( @a, 1 ) ;
870
@} ;
871
 
872
<exp_throw_type> : ( t, n ) -> ( e ) = @{
873
    @e = make_throw_arg ( @t, @n ) ;
874
@} ;
875
 
876
<exp_true> : () -> ( e ) = @{
877
    @e = make_bool_exp ( BOOL_TRUE, exp_int_lit_tag ) ;
878
@} ;
879
 
880
<exp_typeid_exp> : ( a, op, n ) -> ( e ) = @{
881
    @e = make_typeid_exp ( @op, @a, @n ) ;
882
@} ;
883
 
884
<exp_typeid_type> : ( t, op, n ) -> ( e ) = @{
885
    @e = make_typeid_type ( @op, @t, @n ) ;
886
@} ;
887
 
888
<exp_unary> : ( op, a ) -> ( e ) = @{
889
    @e = make_uminus_exp ( @op, @a ) ;
890
@} ;
891
 
892
<exp_unused> : ( a ) -> ( e ) = @{
893
    @e = make_unused_exp ( @a ) ;
894
@} ;
895
 
896
<exp_xor> : ( a, b ) -> ( e ) = @{
897
    @e = make_xor_exp ( @a, @b ) ;
898
@} ;
899
 
900
 
901
/*
902
    STATEMENT CONSTRUCTORS
903
 
904
    These actions describe how to build up statements from expressions,
905
    declarations, and more primitive statements.  The empty statement is
906
    represented by the null expression, stmt_none.  The other statement
907
    constructors map directly onto constructor functions.
908
*/
909
 
910
<stmt_none> : () -> ( e ) = @{
911
    @e = NULL_exp ;
912
@} ;
913
 
914
<stmt_break> : () -> ( e ) = @{
915
    @e = make_break_stmt () ;
916
@} ;
917
 
918
<stmt_case_begin> : ( a ) -> ( e ) = @{
919
    @e = begin_case_stmt ( @a, 0 ) ;
920
@} ;
921
 
922
<stmt_case_end> : ( a, b ) -> ( e ) = @{
923
    @e = end_case_stmt ( @a, @b ) ;
924
@} ;
925
 
926
<stmt_catch_begin> : ( a, d ) -> ( e ) = @{
927
    @e = begin_catch_stmt ( @a, @d ) ;
928
@} ;
929
 
930
<stmt_catch_end> : ( a, b ) -> () = @{
931
    IGNORE end_catch_stmt ( @a, @b ) ;
932
@} ;
933
 
934
<stmt_caught> : () -> ( e ) = @{
935
    MAKE_exp_thrown ( type_void, 1, @e ) ;
936
@} ;
937
 
938
<stmt_compound_begin> : () -> ( e ) = @{
939
    @e = begin_compound_stmt ( 1 ) ;
940
@} ;
941
 
942
<stmt_compound_block> : ( a ) -> () = @{
943
    COPY_int ( exp_sequence_block ( @a ), 2 ) ;
944
@} ;
945
 
946
<stmt_compound_mark> : ( a ) -> () = @{
947
    mark_compound_stmt ( @a ) ;
948
@} ;
949
 
950
<stmt_compound_add> : ( a, b ) -> ( e ) = @{
951
    @e = add_compound_stmt ( @a, @b ) ;
952
@} ;
953
 
954
<stmt_compound_end> : ( a ) -> ( e ) = @{
955
    @e = end_compound_stmt ( @a ) ;
956
@} ;
957
 
958
<stmt_continue> : () -> ( e ) = @{
959
    @e = make_continue_stmt () ;
960
@} ;
961
 
962
<stmt_decl> : ( a ) -> ( e ) = @{
963
    @e = @a ;
964
    in_declaration-- ;
965
@} ;
966
 
967
<stmt_default_begin> : () -> ( e ) = @{
968
    @e = begin_default_stmt ( 0 ) ;
969
@} ;
970
 
971
<stmt_default_end> : ( a, b ) -> ( e ) = @{
972
    @e = end_default_stmt ( @a, @b ) ;
973
@} ;
974
 
975
<stmt_do_begin> : () -> ( e ) = @{
976
    @e = begin_do_stmt () ;
977
@} ;
978
 
979
<stmt_do_end> : ( a, b, c ) -> ( e ) = @{
980
    @e = end_do_stmt ( @a, @b, @c ) ;
981
@} ;
982
 
983
<stmt_exp> : ( a ) -> ( e ) = @{
984
    @e = make_exp_stmt ( @a ) ;
985
@} ;
986
 
987
<stmt_for_begin> : () -> ( e ) = @{
988
    @e = begin_for_stmt () ;
989
@} ;
990
 
991
<stmt_for_init> : ( a, b ) -> ( e ) = @{
992
    @e = init_for_stmt ( @a, &@b ) ;
993
@} ;
994
 
995
<stmt_for_cond> : ( a, b, c ) -> ( e ) = @{
996
    @e = cond_for_stmt ( @a, @b, @c ) ;
997
@} ;
998
 
999
<stmt_for_end> : ( a, b ) -> ( e ) = @{
1000
    @e = end_for_stmt ( @a, @b ) ;
1001
@} ;
1002
 
1003
<stmt_goto> : ( id ) -> ( e ) = @{
1004
    @e = make_goto_stmt ( @id ) ;
1005
@} ;
1006
 
1007
<stmt_goto_case> : ( a ) -> ( e ) = @{
1008
    report ( crt_loc, ERR_stmt_goto_case ( lex_case ) ) ;
1009
    @e = begin_case_stmt ( @a, 1 ) ;
1010
@} ;
1011
 
1012
<stmt_goto_default> : () -> ( e ) = @{
1013
    report ( crt_loc, ERR_stmt_goto_case ( lex_default ) ) ;
1014
    @e = begin_default_stmt ( 1 ) ;
1015
@} ;
1016
 
1017
<stmt_if_begin> : ( a ) -> ( e ) = @{
1018
    @e = begin_if_stmt ( @a ) ;
1019
@} ;
1020
 
1021
<stmt_if_cont> : ( a, b ) -> ( e ) = @{
1022
    @e = cont_if_stmt ( @a, @b ) ;
1023
@} ;
1024
 
1025
<stmt_if_end> : ( a, b ) -> ( e ) = @{
1026
    @e = end_if_stmt ( @a, @b ) ;
1027
@} ;
1028
 
1029
<stmt_else> : () -> () = @{
1030
    check_empty_stmt ( lex_else ) ;
1031
@} ;
1032
 
1033
<stmt_no_else> : () -> ( e ) = @{
1034
    report ( crt_loc, ERR_stmt_if_no_else () ) ;
1035
    @e = NULL_exp ;
1036
@} ;
1037
 
1038
<stmt_label_begin> : ( id ) -> ( e ) = @{
1039
    @e = begin_label_stmt ( @id, lex_identifier ) ;
1040
@} ;
1041
 
1042
<stmt_label_end> : ( a, b ) -> ( e ) = @{
1043
    @e = end_label_stmt ( @a, @b ) ;
1044
@} ;
1045
 
1046
<stmt_label_set> : () -> () = @{
1047
    unreached_fall = 0 ;
1048
@} ;
1049
 
1050
<stmt_label_clear> : () -> () = @{
1051
    unreached_fall = 1 ;
1052
@} ;
1053
 
1054
<stmt_label_mod> : () -> () = @{
1055
    if ( unreached_code ) unreached_fall = 0 ;
1056
@} ;
1057
 
1058
<stmt_return> : ( a ) -> ( e ) = @{
1059
    @e = make_return_stmt ( @a, lex_return ) ;
1060
@} ;
1061
 
1062
<stmt_switch_begin> : ( a ) -> ( e ) = @{
1063
    @e = begin_switch_stmt ( @a ) ;
1064
@} ;
1065
 
1066
<stmt_switch_end> : ( a, b, ex ) -> ( e ) = @{
1067
    @e = end_switch_stmt ( @a, @b, @ex ) ;
1068
@} ;
1069
 
1070
<stmt_try_begin> : () -> ( e ) = @{
1071
    @e = begin_try_stmt ( 0 ) ;
1072
@} ;
1073
 
1074
<stmt_try_func> : () -> ( e ) = @{
1075
    @e = begin_try_stmt ( 1 ) ;
1076
@} ;
1077
 
1078
<stmt_try_inject> : ( a ) -> () = @{
1079
    inject_try_stmt ( @a ) ;
1080
@} ;
1081
 
1082
<stmt_try_cont> : ( a, b ) -> ( e ) = @{
1083
    @e = cont_try_stmt ( @a, @b ) ;
1084
@} ;
1085
 
1086
<stmt_try_end> : ( a ) -> ( e ) = @{
1087
    @e = end_try_stmt ( @a, 0 ) ;
1088
@} ;
1089
 
1090
<stmt_while_begin> : ( a ) -> ( e ) = @{
1091
    @e = begin_while_stmt ( @a ) ;
1092
@} ;
1093
 
1094
<stmt_while_end> : ( a, b ) -> ( e ) = @{
1095
    @e = end_while_stmt ( @a, @b ) ;
1096
@} ;
1097
 
1098
<stmt_hash_if> : ( a, b ) -> ( e ) = @{
1099
    @e = begin_hash_if_stmt ( @a, @b ) ;
1100
@} ;
1101
 
1102
<stmt_hash_elif> : ( a, b, c ) -> ( e ) = @{
1103
    @e = cont_hash_if_stmt ( @a, @b, @c ) ;
1104
@} ;
1105
 
1106
<stmt_hash_endif> : ( a, b ) -> ( e ) = @{
1107
    @e = end_hash_if_stmt ( @a, @b ) ;
1108
@} ;
1109
 
1110
<stmt_reach> : ( a ) -> ( e ) = @{
1111
    @e = make_reach_stmt ( @a, 1 ) ;
1112
@} ;
1113
 
1114
<stmt_unreach> : ( a ) -> ( e ) = @{
1115
    @e = make_reach_stmt ( @a, 0 ) ;
1116
@} ;
1117
 
1118
<bind_temporary> : ( a ) -> ( e ) = @{
1119
    @e = bind_temporary ( @a ) ;
1120
@} ;
1121
 
1122
<cond_start> : () -> () = @{
1123
    begin_cond () ;
1124
@} ;
1125
 
1126
<cond_end> : () -> ( e ) = @{
1127
    @e = end_cond () ;
1128
    in_declaration-- ;
1129
@} ;
1130
 
1131
<cond_type> : ( s ) -> ( t ) = @{
1132
    @t = make_cond_type ( @s ) ;
1133
@} ;
1134
 
1135
<cond_inject> : ( a, b ) -> ( e ) = @{
1136
    @e = inject_cond ( @a, @b ) ;
1137
@} ;
1138
 
1139
<loop_inject> : ( a, b ) -> ( e ) = @{
1140
    @e = inject_cond ( @a, @b ) ;
1141
@} ;
1142
 
1143
<init_inject> : ( a, b ) -> ( e ) = @{
1144
    @e = inject_cond ( @a, @b ) ;
1145
@} ;
1146
 
1147
 
1148
/*
1149
    FLOW ANALYSIS
1150
 
1151
    These actions are concerned with flow and variable analysis.
1152
*/
1153
 
1154
<reach_check> : () -> ( r ) = @{
1155
    @r = unreached_code ;
1156
    if ( @r ) {
1157
	if ( !unreached_last ) {
1158
	    report ( crt_loc, ERR_stmt_stmt_unreach () ) ;
1159
	    unreached_last = 1 ;
1160
	}
1161
    } else {
1162
	unreached_last = 0 ;
1163
    }
1164
@} ;
1165
 
1166
<reach_prev> : ( r ) -> () = @{ unreached_prev = @r ; @} ;
1167
<reach_set> : () -> () = @{ unreached_code = 0 ; @} ;
1168
<reach_unset> : () -> () = @{ unreached_code = 1 ; @} ;
1169
 
1170
<condition_get> : () -> ( c ) = @{ @c = crt_condition ; @} ;
1171
<condition_set> : ( c ) -> () = @{ crt_condition = @c ; @} ;
1172
 
1173
 
1174
/*
1175
    FUNCTION DEFINITIONS CONSTRUCTORS
1176
 
1177
    These actions are called at the start and the end of a function
1178
    definition.  Most of the work is done by construction functions, but
1179
    the flags have_type_declaration and in_function_defn are handled
1180
    locally.
1181
*/
1182
 
1183
<function_begin> : ( d ) -> ( b ) = @{
1184
    @b = in_class_defn ;
1185
    in_class_defn = 0 ;
1186
    in_function_defn++ ;
1187
    really_in_function_defn++ ;
1188
    begin_function ( @d ) ;
1189
@} ;
1190
 
1191
<function_end> : ( d, a, b ) -> () = @{
1192
    IGNORE end_function ( @d, @a ) ;
1193
    in_class_defn = @b ;
1194
    in_function_defn-- ;
1195
    really_in_function_defn-- ;
1196
@} ;
1197
 
1198
<function_skip> : ( d ) -> () = @{
1199
    skip_function ( @d ) ;
1200
@} ;
1201
 
1202
<default_arg_skip> : ( d ) -> ( e ) = @{
1203
    @e = skip_default_arg ( @d ) ;
1204
@} ;
1205
 
1206
<decl_none> : () -> ( d ) = @{
1207
    @d = NULL_id ;
1208
@} ;
1209
 
1210
<ctor_begin> : () -> ( ns ) = @{
1211
    @ns = ctor_begin () ;
1212
@} ;
1213
 
1214
<ctor_end> : ( ns, c, b ) -> ( e ) = @{
1215
    @e = ctor_end ( @ns, @c, @b ) ;
1216
@} ;
1217
 
1218
<ctor_initialise> : ( ns, id, e ) -> () = @{
1219
    ctor_initialise ( @ns, @id, @e ) ;
1220
@} ;
1221
 
1222
<ctor_none> : ( c ) -> ( e, d ) = @{
1223
    @d = NULL_exp ;
1224
    @e = ctor_none ( @c, &@d ) ;
1225
@} ;
1226
 
1227
<ctor_postlude> : ( a, b ) -> ( e ) = @{
1228
    @e = ctor_postlude ( @a, @b ) ;
1229
@} ;
1230
 
1231
<param_begin> : ( id ) -> () = @{
1232
    func_type_defn ( 0 ) ;
1233
    begin_param ( @id ) ;
1234
    have_type_declaration = TYPE_DECL_NONE ;
1235
    have_func_declarator = 0 ;
1236
@} ;
1237
 
1238
<param_end> : () -> () = @{
1239
    end_param () ;
1240
    have_type_declaration = TYPE_DECL_NONE ;
1241
    have_func_declarator = 1 ;
1242
@} ;
1243
 
1244
 
1245
/*
1246
    CONST-VOLATILE QUALIFIERS
1247
 
1248
    These actions describe how to construct and combine the const and
1249
    volatile type qualifiers.  The main action is cv_join which combines
1250
    two CV bitmasks by bitwise or'ing them.  It also checks for
1251
    duplicate qualifiers.
1252
*/
1253
 
1254
<cv_none> : () -> ( cv ) = @{ @cv = cv_none ; @} ;
1255
<cv_const> : () -> ( cv ) = @{ @cv = cv_const ; @} ;
1256
<cv_volatile> : () -> ( cv ) = @{ @cv = cv_volatile ; @} ;
1257
 
1258
<cv_join> : ( a, b ) -> ( cv ) = @{
1259
    CV_SPEC c = ( @a & @b ) ;
1260
    if ( c ) report ( crt_loc, ERR_dcl_type_cv_dup ( c ) ) ;
1261
    @cv = ( @a | @b ) ;
1262
@} ;
1263
 
1264
 
1265
/*
1266
    BASIC TYPES
1267
 
1268
    These actions describe the basic type specifiers, char, short, int,
1269
    and so on.  This is a simple map onto the calculus type BTYPE.
1270
*/
1271
 
1272
<btype_char> : () -> ( bt ) = @{ @bt = btype_char ; @} ;
1273
<btype_short> : () -> ( bt ) = @{ @bt = btype_short ; @} ;
1274
<btype_int> : () -> ( bt ) = @{ @bt = btype_int ; @} ;
1275
<btype_long> : () -> ( bt ) = @{ @bt = btype_long ; @} ;
1276
<btype_signed> : () -> ( bt ) = @{ @bt = btype_signed ; @} ;
1277
<btype_unsigned> : () -> ( bt ) = @{ @bt = btype_unsigned ; @} ;
1278
<btype_float> : () -> ( bt ) = @{ @bt = btype_float ; @} ;
1279
<btype_double> : () -> ( bt ) = @{ @bt = btype_double ; @} ;
1280
<btype_bool> : () -> ( bt ) = @{ @bt = btype_bool ; @} ;
1281
<btype_wchar_t> : () -> ( bt ) = @{ @bt = btype_wchar_t ; @} ;
1282
<btype_size_t> : () -> ( bt ) = @{ @bt = btype_size_t ; @} ;
1283
<btype_ptrdiff_t> : () -> ( bt ) = @{ @bt = btype_ptrdiff_t ; @} ;
1284
<btype_void> : () -> ( bt ) = @{ @bt = btype_void ; @} ;
1285
<btype_bottom> : () -> ( bt ) = @{ @bt = btype_bottom ; @} ;
1286
<btype_none> : () -> ( bt ) = @{ @bt = btype_none ; @} ;
1287
 
1288
<btype_join> : ( b1, b2 ) -> ( bt ) = @{
1289
    if ( @b1 & @b2 ) {
1290
	@bt = join_pre_types ( @b1, @b2 ) ;
1291
    } else {
1292
	@bt = ( @b1 | @b2 ) ;
1293
    }
1294
@} ;
1295
 
1296
 
1297
/*
1298
    BASIC TYPE CONSTRUCTORS
1299
 
1300
    These actions describe how to combine the basic types into real type
1301
    descriptors.  The null type, type_none, is used to indicate the absence
1302
    of an optional type.  A base type specifier can be transformed into a
1303
    partial type by type_pre, and a type name by type_name.  Two partial
1304
    types may be combined using type_join.  A partial type may be turned
1305
    into a real type by type_complete, which also checks that the resultant
1306
    type is not an inferred type (also see dspec_complete).
1307
*/
1308
 
1309
<type_none> : () -> ( t ) = @{
1310
    @t = NULL_type ;
1311
@} ;
1312
 
1313
<type_pre> : () -> ( t ) = @{
1314
    @t = NULL_type ;
1315
    have_type_specifier = 1 ;
1316
@} ;
1317
 
1318
<type_name> : ( id ) -> ( t ) = @{
1319
    MAKE_type_pre ( cv_none, btype_alias, crt_id_qualifier, @t ) ;
1320
    COPY_id ( type_name ( @t ), @id ) ;
1321
    have_type_specifier = 1 ;
1322
@} ;
1323
 
1324
<type_elaborate> : ( id, k ) -> ( t ) = @{
1325
    MAKE_type_pre ( cv_none, @k, crt_id_qualifier, @t ) ;
1326
    COPY_id ( type_name ( @t ), @id ) ;
1327
    if ( have_type_declaration == TYPE_DECL_NONE ) {
1328
	have_type_declaration = TYPE_DECL_ELABORATE ;
1329
    }
1330
    have_type_specifier = 1 ;
1331
@} ;
1332
 
1333
<type_typename> : ( ns, id ) -> ( t ) = @{
1334
    @t = make_typename ( @ns, @id ) ;
1335
    if ( have_type_declaration == TYPE_DECL_NONE ) {
1336
	have_type_declaration = TYPE_DECL_ELABORATE ;
1337
	found_elaborate_type = 1 ;
1338
    }
1339
    have_type_specifier = 1 ;
1340
@} ;
1341
 
1342
<type_join> : ( a, b ) -> ( t ) = @{
1343
    /* Join two partial types */
1344
    if ( IS_NULL_type ( @a ) ) {
1345
	@t = @b ;
1346
    } else if ( IS_NULL_type ( @b ) ) {
1347
	@t = @a ;
1348
    } else {
1349
	report ( crt_loc, ERR_dcl_type_simple_many ( @a, @b ) ) ;
1350
	@t = @b ;
1351
    }
1352
@} ;
1353
 
1354
<type_complete> : ( bt, t, cv ) -> ( c ) = @{
1355
    @c = complete_pre_type ( @bt, @t, @cv, 1 ) ;
1356
    have_type_specifier = 0 ;
1357
@} ;
1358
 
1359
<type_of> : ( op, e, n ) -> ( t ) = @{
1360
    @t = typeof_exp ( &@e, @n, @op ) ;
1361
@} ;
1362
 
1363
<type_check> : ( t ) -> () = @{
1364
    object_type ( @t, null_tag ) ;
1365
@} ;
1366
 
1367
 
1368
/*
1369
    COMPOSITE TYPE CONSTRUCTORS
1370
 
1371
    These actions describe how to build up composite types from simpler
1372
    types.  Except in bitfield types, the type formed is, for example,
1373
    pointer to null type, the type being pointed to only being filled in
1374
    later by type_inject.  Note that type_new_array differs from type_array
1375
    in that the bound expression does not need to be constant.
1376
*/
1377
 
1378
<type_ptr> : ( cv ) -> ( p ) = @{
1379
    MAKE_type_ptr ( @cv, NULL_type, @p ) ;
1380
@} ;
1381
 
1382
<type_ref> : ( cv ) -> ( p ) = @{
1383
    /* Can't have const-volatile qualified references */
1384
    if ( @cv ) report ( crt_loc, ERR_dcl_ref_cv ( @cv ) ) ;
1385
    MAKE_type_ref ( cv_none, NULL_type, @p ) ;
1386
@} ;
1387
 
1388
<type_ptr_mem> : ( id, cv ) -> ( p ) = @{
1389
    CLASS_TYPE ct = find_class ( @id ) ;
1390
    if ( IS_NULL_ctype ( ct ) ) {
1391
	report ( crt_loc, ERR_dcl_mptr_type ( @id ) ) ;
1392
	MAKE_type_ptr ( @cv, NULL_type, @p ) ;
1393
    } else {
1394
	MAKE_type_ptr_mem ( @cv, ct, NULL_type, @p ) ;
1395
    }
1396
@} ;
1397
 
1398
<type_func> : ( e, w, cv, ex ) -> ( f ) = @{
1399
    CV_SPEC cv = func_linkage ( @cv ) ;
1400
    if ( @w ) @e |= FUNC_WEAK ;
1401
    @f = make_func_type ( NULL_type, @e, cv, @ex ) ;
1402
@} ;
1403
 
1404
<type_array> : ( e ) -> ( a ) = @{
1405
    NAT n = make_array_dim ( @e ) ;
1406
    MAKE_type_array ( cv_none, NULL_type, n, @a ) ;
1407
@} ;
1408
 
1409
<type_new_array> : ( e ) -> ( a ) = @{
1410
    /* First array bound in a new-declarator */
1411
    NAT n = make_new_array_dim ( @e ) ;
1412
    MAKE_type_array ( cv_none, NULL_type, n, @a ) ;
1413
@} ;
1414
 
1415
<type_bitfield> : ( p, q, e ) -> ( a ) = @{
1416
    @a = make_bitfield_type ( @p, @q, @e, 0 ) ;
1417
@} ;
1418
 
1419
<type_bitfield_mem> : ( p, q, e, id ) -> ( a ) = @{
1420
    /* Check for anonymous bitfields */
1421
    HASHID nm = DEREF_hashid ( id_name ( @id ) ) ;
1422
    int z = IS_hashid_anon ( nm ) ;
1423
    @a = make_bitfield_type ( @p, @q, @e, z ) ;
1424
@} ;
1425
 
1426
<type_inject> : ( p, t ) -> ( c ) = @{
1427
    @c = ( IS_NULL_type ( @p ) ? @t : inject_pre_type ( @p, @t, 1 ) ) ;
1428
@} ;
1429
 
1430
<type_build> : ( p, t ) -> ( c ) = @{
1431
    @c = ( IS_NULL_type ( @p ) ? @t : inject_pre_type ( @p, @t, 0 ) ) ;
1432
@} ;
1433
 
1434
 
1435
/*
1436
    LISTS OF TYPES
1437
 
1438
    These actions give the basic constructs for building up lists of
1439
    types.  They map directly to the calculus list operations.
1440
*/
1441
 
1442
<list_type_null> : () -> ( p ) = @{
1443
    @p = NULL_list ( TYPE ) ;
1444
@} ;
1445
 
1446
<list_type_cons> : ( t, q ) -> ( p ) = @{
1447
    @p = cons_type_set ( @q, @t ) ;
1448
@} ;
1449
 
1450
<list_type_all> : () -> ( p ) = @{
1451
    @p = empty_type_set ;
1452
@} ;
1453
 
1454
<list_type_ellipsis> : () -> ( p ) = @{
1455
    report ( crt_loc, ERR_except_spec_ellipsis () ) ;
1456
    @p = univ_type_set ;
1457
@} ;
1458
 
1459
 
1460
/*
1461
    CLASS KEYS
1462
 
1463
    These actions describe the class key qualifiers, class, struct, union
1464
    and enum.  These are representing by the corresponding lexical token
1465
    numbers.
1466
*/
1467
 
1468
<key_class> : () -> ( key ) = @{ @key = btype_class ; @} ;
1469
<key_struct> : () -> ( key ) = @{ @key = btype_struct ; @} ;
1470
<key_union> : () -> ( key ) = @{ @key = btype_union ; @} ;
1471
<key_enum> : () -> ( key ) = @{ @key = btype_enum ; @} ;
1472
 
1473
 
1474
/*
1475
    ACCESS SPECIFIERS
1476
 
1477
    These actions describe the access specifiers, private, protected and
1478
    public.  Each access specifier is represented by the corresponding
1479
    lexical token number.  The current access specifier is held in the
1480
    crt_access variable, which is initialised in begin_class_defn.
1481
*/
1482
 
1483
<access_private> : () -> ( a ) = @{ @a = dspec_private ; @} ;
1484
<access_protected> : () -> ( a ) = @{ @a = dspec_protected ; @} ;
1485
<access_public> : () -> ( a ) = @{ @a = dspec_public ; @} ;
1486
<access_none> : () -> ( a ) = @{ @a = dspec_none ; @} ;
1487
<access_get> : () -> ( a ) = @{ @a = crt_access ; @} ;
1488
<access_set> : ( a ) -> () = @{ crt_access = @a ; @} ;
1489
 
1490
<access_check> : () -> () = @{
1491
    if ( crt_access_list.pending ) {
1492
	IGNORE report_access ( crt_func_id ) ;
1493
    }
1494
@} ;
1495
 
1496
<access_check_class> : () -> () = @{
1497
    if ( crt_access_list.pending ) {
1498
	IDENTIFIER id = DEREF_id ( ctype_name ( crt_class ) ) ;
1499
	IGNORE report_access ( id ) ;
1500
    }
1501
@} ;
1502
 
1503
<access_check_decl> : ( d ) -> () = @{
1504
    if ( crt_access_list.pending ) {
1505
	IGNORE report_access ( @d ) ;
1506
    }
1507
@} ;
1508
 
1509
<access_check_ret> : ( d, r ) -> () = @{
1510
    IGNORE clear_access ( @d, &@r ) ;
1511
@} ;
1512
 
1513
<access_return> : () -> ( r ) = @{
1514
    save_access ( &@r ) ;
1515
@} ;
1516
 
1517
<access_free> : ( r ) -> () = @{
1518
    free_access ( &@r ) ;
1519
@} ;
1520
 
1521
 
1522
/*
1523
    CLASS AND ENUMERATION TYPE CONSTRUCTORS
1524
 
1525
    These actions describe how to build up class and enumeration types.
1526
    They also include the elaborated type specifiers.  Note that the value
1527
    of have_type_declaration is set according to the declaration processed.
1528
*/
1529
 
1530
<type_class_begin> : ( id, k, q ) -> ( t, b ) = @{
1531
    IDENTIFIER id = constr_name ( last_namespace, @id ) ;
1532
    @t = begin_class_defn ( id, @k, cinfo_none, @q ) ;
1533
    @b = in_function_defn ;
1534
    in_function_defn = 0 ;
1535
    in_class_defn++ ;
1536
    really_in_class_defn++ ;
1537
    no_type_defns++ ;
1538
@} ;
1539
 
1540
<type_class_end> : ( p, b ) -> ( t ) = @{
1541
    @t = end_class_defn ( @p ) ;
1542
    in_function_defn = @b ;
1543
    in_class_defn-- ;
1544
    really_in_class_defn-- ;
1545
@} ;
1546
 
1547
<class_base> : ( id, a, v ) -> () = @{
1548
    add_base_class ( @id, @a, @v ) ;
1549
@} ;
1550
 
1551
<class_base_end> : ( t ) -> () = @{
1552
    end_base_class ( crt_class, @t ) ;
1553
@} ;
1554
 
1555
<type_enum_begin> : ( id, q ) -> ( t ) = @{
1556
    IDENTIFIER id = constr_name ( last_namespace, @id ) ;
1557
    @t = begin_enum_defn ( id, @q ) ;
1558
    no_type_defns++ ;
1559
@} ;
1560
 
1561
<type_enum_end> : ( p ) -> ( t ) = @{
1562
    @t = end_enum_defn ( @p ) ;
1563
@} ;
1564
 
1565
 
1566
/*
1567
    DECLARATION SPECIFIERS
1568
 
1569
    These actions describe how to construct and combine declaration
1570
    specifiers.  These include the storage class specifiers, the function
1571
    specifiers, friend and typedef.  The action dspec_join combines two
1572
    declaration specifiers by bitwise or'ing them and checking for
1573
    duplications.  The action dspec_complete is analogous to tspec_complete
1574
    but also checks any associated declaration specifiers.  It also does
1575
    not check for inferred types.
1576
*/
1577
 
1578
<dspec_none> : () -> ( ds ) = @{ @ds = dspec_none ; @} ;
1579
<dspec_auto> : () -> ( ds ) = @{ @ds = dspec_auto ; @} ;
1580
<dspec_register> : () -> ( ds ) = @{ @ds = dspec_register ; @} ;
1581
<dspec_static> : () -> ( ds ) = @{ @ds = dspec_static ; @} ;
1582
<dspec_extern> : () -> ( ds ) = @{ @ds = dspec_extern ; @} ;
1583
<dspec_mutable> : () -> ( ds ) = @{ @ds = dspec_mutable ; @} ;
1584
<dspec_inline> : () -> ( ds ) = @{ @ds = dspec_inline ; @} ;
1585
<dspec_virtual> : () -> ( ds ) = @{ @ds = dspec_virtual ; @} ;
1586
<dspec_explicit> : () -> ( ds ) = @{ @ds = dspec_explicit ; @} ;
1587
<dspec_overload> : () -> ( ds ) = @{ @ds = dspec_none ; @} ;
1588
<dspec_friend> : () -> ( ds ) = @{ @ds = dspec_friend ; @} ;
1589
<dspec_typedef> : () -> ( ds ) = @{ @ds = dspec_typedef ; @} ;
1590
<dspec_linkage> : () -> ( ds ) = @{ @ds = ( dspec_extern | dspec_c ) ; @} ;
1591
 
1592
<dspec_join> : ( a, b ) -> ( ds ) = @{
1593
    /* Combine two declaration specifiers */
1594
    DECL_SPEC d = ( ( @a & @b ) & dspec_duplicate ) ;
1595
    if ( d ) report ( crt_loc, ERR_dcl_spec_dup ( d ) ) ;
1596
    @ds = ( @a | @b ) ;
1597
@} ;
1598
 
1599
<dspec_check> : ( ds ) -> () = @{
1600
    if ( have_type_specifier ) report ( crt_loc, ERR_dcl_spec_order ( @ds ) ) ;
1601
@} ;
1602
 
1603
<dspec_complete> : ( bt, t, cv, ds ) -> ( c, d ) = @{
1604
    /* Complete a declaration specifier and a type */
1605
    @d = complete_dspec ( @ds, @bt, @t, @cv ) ;
1606
    @c = complete_pre_type ( @bt, @t, @cv, 0 ) ;
1607
    have_type_specifier = 0 ;
1608
@} ;
1609
 
1610
 
1611
/*
1612
    LINKAGE SPECIFIERS
1613
 
1614
    These actions describe the linkage specifiers.  These are implemented
1615
    by a simple global variable, crt_linkage.  The action linkage_string
1616
    translates a string literal expression into a linkage specifier.
1617
*/
1618
 
1619
<linkage_string> : ( s ) -> ( a ) = @{
1620
    @a = find_linkage ( @s ) ;
1621
@} ;
1622
 
1623
<linkage_begin> : ( a ) -> ( b ) = @{
1624
    @b = crt_linkage ;
1625
    crt_linkage = @a ;
1626
    IGNORE incr_value ( OPT_VAL_external_specs ) ;
1627
@} ;
1628
 
1629
<linkage_end> : ( a ) -> () = @{
1630
    decr_value ( OPT_VAL_external_specs ) ;
1631
    crt_linkage = @a ;
1632
@} ;
1633
 
1634
 
1635
/*
1636
    OBJECT DECLARATIONS
1637
 
1638
    These actions describe how to construct an object declaration.
1639
*/
1640
 
1641
<declare_id> : ( ds, bt, t, id ) -> ( d ) = @{
1642
    if ( type_tag ( @t ) == type_func_tag ) {
1643
	/* Look ahead for function definitions */
1644
	int def = predict_func_defn () ;
1645
	if ( def & !have_func_declarator ) adjust_param ( @t ) ;
1646
	@d = make_func_decl ( @ds, @t, @id, def ) ;
1647
	is_function_next = def ;
1648
    } else {
1649
	int def = predict_obj_defn () ;
1650
	@d = make_object_decl ( @ds, @t, @id, def ) ;
1651
	is_function_next = 0 ;
1652
    }
1653
    if ( IS_id_type_alias ( @d ) ) {
1654
	BASE_TYPE bs = DEREF_btype ( id_type_alias_rep ( @d ) ) ;
1655
	bs |= @bt ;
1656
	COPY_btype ( id_type_alias_rep ( @d ), bs ) ;
1657
    }
1658
    have_type_declaration = TYPE_DECL_NONE ;
1659
    have_func_declarator = 0 ;
1660
@} ;
1661
 
1662
<declare_id_empty> : ( ds, s, bt, t, cv ) -> () = @{
1663
    IGNORE empty_decl ( @ds, @s, @bt, @t, @cv, last_lex_token, 0 ) ;
1664
    have_type_declaration = TYPE_DECL_NONE ;
1665
    have_func_declarator = 0 ;
1666
    have_type_specifier = 0 ;
1667
@} ;
1668
 
1669
<declare_param> : ( ds, t, id, p ) -> ( d ) = @{
1670
    @d = make_param_decl ( @ds, @t, @id, @p ) ;
1671
    have_type_declaration = TYPE_DECL_NONE ;
1672
    have_func_declarator = 0 ;
1673
@} ;
1674
 
1675
<declare_member> : ( ds, bt, t, id, f ) -> ( d, fr ) = @{
1676
    DECL_SPEC ds = @ds ;
1677
    if ( type_tag ( @t ) == type_func_tag ) {
1678
	/* Look ahead for function definitions */
1679
	int def = predict_func_defn () ;
1680
	if ( def & !have_func_declarator ) adjust_param ( @t ) ;
1681
	if ( ds & dspec_friend ) {
1682
	    @d = make_friend_decl ( ds, @t, @id, def, 1 ) ;
1683
	    @fr = 1 ;
1684
	} else {
1685
	    @d = make_func_mem_decl ( ds, @t, @id, def ) ;
1686
	    @fr = 0 ;
1687
	}
1688
	is_function_next = def ;
1689
    } else {
1690
	int f = ( @f && ( crt_lex_token == lex_semicolon ) ) ;
1691
	@d = make_member_decl ( ds, @t, @id, f ) ;
1692
	@fr = 0 ;
1693
	is_function_next = 0 ;
1694
    }
1695
    if ( IS_id_type_alias ( @d ) ) {
1696
	BASE_TYPE bs = DEREF_btype ( id_type_alias_rep ( @d ) ) ;
1697
	bs |= @bt ;
1698
	COPY_btype ( id_type_alias_rep ( @d ), bs ) ;
1699
    }
1700
    have_type_declaration = TYPE_DECL_NONE ;
1701
    have_func_declarator = 0 ;
1702
@} ;
1703
 
1704
<declare_member_empty> : ( ds, s, bt, t, cv ) -> () = @{
1705
    IGNORE empty_decl ( @ds, @s, @bt, @t, @cv, last_lex_token, 1 ) ;
1706
    have_type_declaration = TYPE_DECL_NONE ;
1707
    have_func_declarator = 0 ;
1708
    have_type_specifier = 0 ;
1709
@} ;
1710
 
1711
<declare_bitfield> : ( ds, t, id ) -> ( d ) = @{
1712
    IDENTIFIER id = make_member_decl ( @ds, @t, @id, 0 ) ;
1713
    int def = init_member ( id, NULL_exp ) ;
1714
    if ( do_dump ) dump_declare ( id, &decl_loc, def ) ;
1715
    have_type_declaration = TYPE_DECL_NONE ;
1716
    have_func_declarator = 0 ;
1717
    is_function_next = 0 ;
1718
    @d = id ;
1719
@} ;
1720
 
1721
<declare_enum> : ( t, id, e ) -> () = @{
1722
    IDENTIFIER id = constr_name ( last_namespace, @id ) ;
1723
    IGNORE make_enumerator ( @t, id, @e ) ;
1724
@} ;
1725
 
1726
<declare_except> : ( ds, t, id, n ) -> ( d ) = @{
1727
    @d = make_except_decl ( @ds, @t, @id, @n ) ;
1728
    have_type_declaration = TYPE_DECL_NONE ;
1729
    have_func_declarator = 0 ;
1730
@} ;
1731
 
1732
<declare_none> : () -> ( d ) = @{
1733
    @d = NULL_id ;
1734
@} ;
1735
 
1736
<declarator_start> : () -> () = @{
1737
    crt_templ_qualifier = 0 ;
1738
@} ;
1739
 
1740
<declarator_begin> : ( id ) -> () = @{
1741
    begin_declarator ( @id, crt_id_qualifier, qual_namespace, 1 ) ;
1742
@} ;
1743
 
1744
<declarator_end> : ( d ) -> () = @{
1745
    end_declarator ( @d, 1 ) ;
1746
@} ;
1747
 
1748
<declarator_posn> : ( id ) -> () = @{
1749
    IDENTIFIER pid = underlying_id ( @id ) ;
1750
    DEREF_loc ( id_loc ( pid ), decl_loc ) ;
1751
@} ;
1752
 
1753
<decl_nspace_begin> : ( ns ) -> () = @{
1754
    if ( add_nested_nspace ( @ns ) ) {
1755
	RESCAN_LEXER ;
1756
    }
1757
@} ;
1758
 
1759
<decl_nspace_end> : ( ns ) -> () = @{
1760
    if ( remove_nested_nspace ( @ns ) ) {
1761
	RESCAN_LEXER ;
1762
    }
1763
@} ;
1764
 
1765
<declarator_type> : ( id ) -> ( cid ) = @{
1766
    @cid = constr_name ( last_namespace, @id ) ;
1767
@} ;
1768
 
1769
<declarator_bad> : ( t ) -> () = @{
1770
    if ( IS_NULL_type ( @t ) ) {
1771
	report ( crt_loc, ERR_dcl_meaning_paren () ) ;
1772
    }
1773
@} ;
1774
 
1775
<declare_extern> : ( e ) -> () = @{
1776
    external_declaration ( @e, 1 ) ;
1777
@} ;
1778
 
1779
<param_func> : () -> ( p ) = @{
1780
    @p = CONTEXT_PARAMETER ;
1781
@} ;
1782
 
1783
 
1784
/*
1785
    INITIALISERS
1786
 
1787
    These actions describe the object initialisers.  The main action is
1788
    initialise_id which initialises d to e (which can be the null expression).
1789
    The action initialiser_bad is used to weed out badly placed function
1790
    style initialisers caused by their inclusion in the declarators.
1791
*/
1792
 
1793
<initialise_id> : ( d, e ) -> () = @{
1794
    int def = init_object ( @d, @e ) ;
1795
    if ( do_dump ) dump_declare ( @d, &decl_loc, def ) ;
1796
@} ;
1797
 
1798
<initialise_param> : ( d, e ) -> () = @{
1799
    init_param ( @d, @e ) ;
1800
@} ;
1801
 
1802
<initialise_member> : ( d, e, f ) -> () = @{
1803
    int def = ( @f ? init_object ( @d, @e ) : init_member ( @d, @e ) ) ;
1804
    if ( do_dump ) dump_declare ( @d, &decl_loc, def ) ;
1805
@} ;
1806
 
1807
<initialiser_bad> : ( b ) -> () = @{
1808
    if ( @b ) report ( crt_loc, ERR_dcl_init_bad () ) ;
1809
@} ;
1810
 
1811
 
1812
/*
1813
    NAMESPACES
1814
 
1815
    These actions describe the namespace and using declarations.
1816
*/
1817
 
1818
<namespace_begin> : ( id ) -> () = @{
1819
    begin_namespace ( @id, 0 ) ;
1820
@} ;
1821
 
1822
<namespace_end> : () -> () = @{
1823
    end_namespace ( 0 ) ;
1824
@} ;
1825
 
1826
<namespace_begin_anon> : () -> () = @{
1827
    decl_loc = crt_loc ;
1828
    begin_namespace ( NULL_id, 1 ) ;
1829
@} ;
1830
 
1831
<namespace_end_anon> : () -> () = @{
1832
    end_namespace ( 1 ) ;
1833
@} ;
1834
 
1835
<namespace_name> : ( id ) -> ( ns ) = @{
1836
    @ns = find_nspace_id ( @id ) ;
1837
@} ;
1838
 
1839
<namespace_alias> : ( id, ns ) -> () = @{
1840
    alias_namespace ( @id, @ns ) ;
1841
@} ;
1842
 
1843
<using_identifier> : ( id ) -> () = @{
1844
    IGNORE using_identifier ( @id ) ;
1845
@} ;
1846
 
1847
<using_typename> : ( t ) -> () = @{
1848
    using_typename ( @t ) ;
1849
@} ;
1850
 
1851
<using_namespace> : ( ns ) -> () = @{
1852
    using_namespace ( @ns ) ;
1853
@} ;
1854
 
1855
 
1856
/*
1857
    TEMPLATES
1858
 
1859
    These actions describe the template declarations.
1860
*/
1861
 
1862
<template_type> : ( p, t ) -> ( s ) = @{
1863
    @s = make_template_type ( @p, @t ) ;
1864
@} ;
1865
 
1866
<template_end> : ( p ) -> () = @{
1867
    end_template ( @p ) ;
1868
@} ;
1869
 
1870
<template_params> : ( e ) -> ( p ) = @{
1871
    @p = template_params ( @e ) ;
1872
    RESCAN_LEXER ;
1873
@} ;
1874
 
1875
<template_param_type> : ( id ) -> ( d ) = @{
1876
    @d = make_type_param ( @id ) ;
1877
@} ;
1878
 
1879
<template_init_type> : ( d, t ) -> () = @{
1880
    init_type_param ( @d, @t ) ;
1881
@} ;
1882
 
1883
<template_param_name> : ( t, id, ds ) -> ( d ) = @{
1884
    @d = make_template_param ( @t, @id ) ;
1885
    UNUSED ( @ds ) ;
1886
@} ;
1887
 
1888
<template_init_name> : ( d, id ) -> () = @{
1889
    init_template_param ( @d, @id ) ;
1890
@} ;
1891
 
1892
<template_check> : ( t, ds ) -> () = @{
1893
    if ( !IS_NULL_type ( @t ) ) report ( crt_loc, ERR_temp_decl_bad () ) ;
1894
    UNUSED ( @ds ) ;
1895
@} ;
1896
 
1897
<template_decl> : ( t ) -> () = @{
1898
    if ( !IS_NULL_type ( @t ) ) template_decl ( @t ) ;
1899
@} ;
1900
 
1901
 
1902
/*
1903
    OFFSETS
1904
 
1905
    These actions describe the constant offset expressions.
1906
*/
1907
 
1908
<offset_nspace> : ( t ) -> ( ns ) = @{
1909
    @ns = offset_nspace ( @t ) ;
1910
@} ;
1911
 
1912
<offset_member> : ( b, s, id, ns ) -> ( a, t ) = @{
1913
    OFFSET off = offset_member ( @s, @id, &@t, @ns, 1 ) ;
1914
    @a = offset_add ( @b, off ) ;
1915
@} ;
1916
 
1917
<offset_index> : ( b, s, e ) -> ( a, t ) = @{
1918
    OFFSET off = offset_index ( @s, @e, &@t ) ;
1919
    @a = offset_add ( @b, off ) ;
1920
@} ;
1921
 
1922
 
1923
/*
1924
    OTHER DECLARATIONS
1925
 
1926
    These actions describe the declarations not covered above.
1927
*/
1928
 
1929
<declare_asm> : ( a, p ) -> ( e ) = @{
1930
    @e = make_asm ( @a, @p ) ;
1931
@} ;
1932
 
1933
<decl_hash_if> : ( a ) -> () = @{
1934
    target_decl ( lex_if, @a ) ;
1935
@} ;
1936
 
1937
<decl_hash_elif> : ( a ) -> () = @{
1938
    target_decl ( lex_elif, @a ) ;
1939
@} ;
1940
 
1941
<decl_hash_else> : () -> () = @{
1942
    target_decl ( lex_else, NULL_exp ) ;
1943
@} ;
1944
 
1945
<decl_hash_endif> : () -> () = @{
1946
    target_decl ( lex_endif, NULL_exp ) ;
1947
@} ;
1948
 
1949
<cond_hash_if> : ( a ) -> ( c ) = @{
1950
    EXP c = crt_hash_cond ;
1951
    crt_hash_cond = make_if_cond ( @a, c ) ;
1952
    @c = c ;
1953
@} ;
1954
 
1955
<cond_hash_elif> : ( a ) -> () = @{
1956
    EXP c = make_else_cond ( crt_hash_cond ) ;
1957
    crt_hash_cond = make_if_cond ( @a, c ) ;
1958
@} ;
1959
 
1960
<cond_hash_else> : () -> () = @{
1961
    crt_hash_cond = make_else_cond ( crt_hash_cond ) ;
1962
@} ;
1963
 
1964
<cond_hash_endif> : ( a ) -> () = @{
1965
    crt_hash_cond = @a ;
1966
@} ;
1967
 
1968
 
1969
/*
1970
    EXCEPTION SPECIFIERS
1971
 
1972
    These actions deal with the exception specifiers.
1973
*/
1974
 
1975
<exception_check> : ( s, n ) -> ( t ) = @{
1976
    @t = check_except_type ( @s, @n ) ;
1977
@} ;
1978
 
1979
 
1980
/*
1981
    ANACHRONISMS
1982
 
1983
    The following rules deal with various anachronistic constructs which
1984
    have been included in the grammar.
1985
*/
1986
 
1987
<anachronism_delete> : ( e ) -> () = @{
1988
    /* Array size in 'delete []' */
1989
    old_delete_array ( @e ) ;
1990
@} ;
1991
 
1992
 
1993
/*
1994
    ERROR REPORTING
1995
 
1996
    These actions describe the error reporting functions for syntax errors
1997
    and for weeding out extra constructs which have been allowed in the
1998
    grammar to permit for better error reporting.
1999
*/
2000
 
2001
<error_fatal> : () -> () = @{
2002
    /* Unrecoverable syntax errors */
2003
    ERROR err = ERR_lex_parse ( crt_token ) ;
2004
    err = concat_error ( err, ERR_lex_abort () ) ;
2005
    report ( crt_loc, err ) ;
2006
    have_syntax_error = 1 ;
2007
@} ;
2008
 
2009
<error_syntax> : () -> () = @{
2010
    /* Syntax errors */
2011
    ERROR err = ERR_lex_parse ( crt_token ) ;
2012
    report ( crt_loc, err ) ;
2013
    have_syntax_error = 1 ;
2014
@} ;
2015
 
2016
<error_comma> : () -> () = @{
2017
    /* Extra comma at the end of a list */
2018
    report ( crt_loc, ERR_lex_extra_comma () ) ;
2019
@} ;
2020
 
2021
<error_overload> : ( t ) -> () = @{
2022
    /* Illegal overloaded operator */
2023
    report ( crt_loc, ERR_over_oper_bad ( @t ) ) ;
2024
@} ;
2025
 
2026
<expected> : ( t ) -> () = @{
2027
    /* Expected symbol */
2028
    int p = primary_form ( crt_lex_token ) ;
2029
    if ( p != @t ) report ( crt_loc, ERR_lex_expect ( @t ) ) ;
2030
@} ;
2031
 
2032
 
2033
 
2034
/*
2035
    PARSER COUNTERS
2036
 
2037
    These actions correspond to the various parser counters defined in
2038
    predict.c.  For example no_side_effects gives the total number of side
2039
    effects encountered, while diff_side_effects gives the number defined
2040
    since a previous call of no_side_effects.
2041
*/
2042
 
2043
<no_side_effects> : () -> ( n ) = @{
2044
    @n = no_side_effects ;
2045
@} ;
2046
 
2047
<no_type_defns> : () -> ( n ) = @{
2048
    @n = no_type_defns ;
2049
@} ;
2050
 
2051
<diff_side_effects> : ( m ) -> ( n ) = @{
2052
    @n = no_side_effects - @m ;
2053
@} ;
2054
 
2055
<diff_type_defns> : ( m ) -> ( n ) = @{
2056
    @n = no_type_defns - @m ;
2057
@} ;
2058
 
2059
<default_arg_begin> : () -> () = @{
2060
    in_default_arg++ ;
2061
@} ;
2062
 
2063
<default_arg_end> : () -> () = @{
2064
    in_default_arg-- ;
2065
@} ;
2066
 
2067
<sizeof_begin> : () -> () = @{
2068
    suppress_usage++ ;
2069
@} ;
2070
 
2071
<sizeof_end> : () -> () = @{
2072
    suppress_usage-- ;
2073
@} ;
2074
 
2075
 
2076
/*
2077
    PREDICATE LITERALS
2078
 
2079
    These actions give the basic values, true and false, for the type
2080
    BOOL.
2081
*/
2082
 
2083
<bool_false> : () -> ( b ) = @{ @b = 0 ; @} ;
2084
<bool_true> : () -> ( b ) = @{ @b = 1 ; @} ;
2085
 
2086
 
2087
/*
2088
    PARSER PREDICATES
2089
 
2090
    In several places the parser needs some help in order to resolve
2091
    ambiguities by means of look-ahead etc.  This help is provided by
2092
    means of the following predicates.  See predict.c for more details.
2093
*/
2094
 
2095
<is_true> : ( c ) -> ( b ) = @{
2096
    @b = @c ;
2097
@} ;
2098
 
2099
<is_class_spec> : () -> ( b ) = @{
2100
    /* Resolve class-specifiers from elaborated-type-specifiers */
2101
    @b = predict_class ( 1 ) ;
2102
@} ;
2103
 
2104
<is_function> : () -> ( b ) = @{
2105
    /* Resolve function definitions from other declarations */
2106
    @b = is_function_next ;
2107
@} ;
2108
 
2109
<is_decl_specifier> : () -> ( b ) = @{
2110
    /* Resolve declaration-specifiers from other declarators */
2111
    @b = predict_dspec ( 0 ) ;
2112
@} ;
2113
 
2114
<is_decl_statement> : () -> ( b ) = @{
2115
    /* Resolve declaration-statements from expression-statements */
2116
    int b = predict_decl () ;
2117
    if ( b ) in_declaration++ ;
2118
    @b = b ;
2119
@} ;
2120
 
2121
<is_enum_spec> : () -> ( b ) = @{
2122
    /* Resolve enum-specifiers from elaborated-type-specifiers */
2123
    @b = predict_class ( 0 ) ;
2124
@} ;
2125
 
2126
<is_initialiser> : () -> ( b ) = @{
2127
    /* Resolve function-style initialisers from function declarators */
2128
    @b = predict_init () ;
2129
@} ;
2130
 
2131
<is_new_ptr_operator> : () -> ( b ) = @{
2132
    /* Resolve pointer declarators from expressions */
2133
    @b = predict_ptr ( 0 ) ;
2134
@} ;
2135
 
2136
<is_ptr_operator> : () -> ( b ) = @{
2137
    /* Resolve pointer or reference declarators from expressions */
2138
    @b = predict_ptr ( 1 ) ;
2139
@} ;
2140
 
2141
<is_array> : () -> ( b ) = @{
2142
    /* Resolve 'operator new []' from 'operator new [3]' */
2143
    @b = predict_array () ;
2144
@} ;
2145
 
2146
<is_type_id_false> : () -> ( b ) = @{
2147
    /* Resolve type-ids from expressions */
2148
    @b = predict_typeid ( 0 ) ;
2149
@} ;
2150
 
2151
<is_type_id_true> : () -> ( b ) = @{
2152
    /* Resolve type-ids from expressions */
2153
    @b = predict_typeid ( 1 ) ;
2154
@} ;
2155
 
2156
<is_type_specifier> : () -> ( b ) = @{
2157
    /* Resolve type-specifiers from other declarators */
2158
    @b = predict_tspec ( 0 ) ;
2159
@} ;
2160
 
2161
<is_parameter> : () -> ( b ) = @{
2162
    /* Resolve parameter declarators from type names */
2163
    @b = predict_param () ;
2164
@} ;
2165
 
2166
<is_skipped> : ( p ) -> ( b ) = @{
2167
    @b = ( in_class_defn && @p == CONTEXT_PARAMETER ) ;
2168
@} ;
2169
 
2170
 
2171
/*
2172
    PARSER HACKS AND PATCHES
2173
 
2174
    In a couple of places it is necessary to fool the parser by changing
2175
    the next token (or even inserting an extra token) depending on the
2176
    current state.
2177
*/
2178
 
2179
<rescan_token> : () -> () = @{
2180
    RESCAN_LEXER ;
2181
@} ;
2182
 
2183
<rescan_template> : ( ns ) -> () = @{
2184
    rescan_template ( @ns ) ;
2185
@} ;
2186
 
2187
<rescan_init> : () -> () = @{
2188
    if ( crt_lex_token == lex_open_Hinit ) {
2189
	crt_lex_token = lex_open_Hround ;
2190
    } else {
2191
	RESCAN_LEXER ;
2192
    }
2193
@} ;
2194
 
2195
<check_decl_specifier> : () -> () = @{
2196
    /* A type-name can be a declarator-id */
2197
    if ( have_type_specifier && crt_lex_token == lex_type_Hname ) {
2198
	crt_lex_token = lex_identifier ;
2199
    }
2200
@} ;
2201
 
2202
 
2203
/*
2204
    FILE TRAILERS
2205
 
2206
    These trailers are appended to the parser definition and declaration
2207
    output files.
2208
*/
2209
 
2210
%trailer% @{
2211
@}, @{
2212
 
2213
 
2214
/*
2215
    DUMMY LEXICAL TOKEN VALUES
2216
 
2217
    These values are used as lexical token values in certain circumstances
2218
    but do not represent actual tokens.  Note that they are all negative.
2219
*/
2220
 
2221
#define lex_ignore_token	-1
2222
#define lex_end_condition	-2
2223
#define lex_included		-3
2224
 
2225
 
2226
#endif
2227
@} ;