Warning: Undefined variable $n in /usr/local/www/websvn.planix.org/include/diff_util.php on line 243

Warning: Undefined variable $n in /usr/local/www/websvn.planix.org/include/diff_util.php on line 247

Warning: Undefined variable $m in /usr/local/www/websvn.planix.org/include/diff_util.php on line 251

Warning: Undefined variable $n in /usr/local/www/websvn.planix.org/include/diff_util.php on line 243

Warning: Undefined variable $n in /usr/local/www/websvn.planix.org/include/diff_util.php on line 247

Warning: Undefined variable $m in /usr/local/www/websvn.planix.org/include/diff_util.php on line 251
WebSVN – tendra.SVN – Diff – /branches/tendra5/src/producers/common/parse/predict.c – Rev 5 and 6

Subversion Repositories tendra.SVN

Rev

Rev 5 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 5 Rev 6
Line -... Line 1...
-
 
1
/*
-
 
2
 * Copyright (c) 2002-2005 The TenDRA Project <http://www.tendra.org/>.
-
 
3
 * All rights reserved.
-
 
4
 *
-
 
5
 * Redistribution and use in source and binary forms, with or without
-
 
6
 * modification, are permitted provided that the following conditions are met:
-
 
7
 *
-
 
8
 * 1. Redistributions of source code must retain the above copyright notice,
-
 
9
 *    this list of conditions and the following disclaimer.
-
 
10
 * 2. Redistributions in binary form must reproduce the above copyright notice,
-
 
11
 *    this list of conditions and the following disclaimer in the documentation
-
 
12
 *    and/or other materials provided with the distribution.
-
 
13
 * 3. Neither the name of The TenDRA Project nor the names of its contributors
-
 
14
 *    may be used to endorse or promote products derived from this software
-
 
15
 *    without specific, prior written permission.
-
 
16
 *
-
 
17
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
-
 
18
 * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
-
 
19
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-
 
20
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
-
 
21
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
-
 
22
 * EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-
 
23
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
-
 
24
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-
 
25
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
-
 
26
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
-
 
27
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
 
28
 *
-
 
29
 * $Id$
-
 
30
 */
1
/*
31
/*
2
    		 Crown Copyright (c) 1997, 1998
32
    		 Crown Copyright (c) 1997, 1998
3
    
33
 
4
    This TenDRA(r) Computer Program is subject to Copyright
34
    This TenDRA(r) Computer Program is subject to Copyright
5
    owned by the United Kingdom Secretary of State for Defence
35
    owned by the United Kingdom Secretary of State for Defence
6
    acting through the Defence Evaluation and Research Agency
36
    acting through the Defence Evaluation and Research Agency
7
    (DERA).  It is made available to Recipients with a
37
    (DERA).  It is made available to Recipients with a
8
    royalty-free licence for its use, reproduction, transfer
38
    royalty-free licence for its use, reproduction, transfer
9
    to other parties and amendment for any purpose not excluding
39
    to other parties and amendment for any purpose not excluding
10
    product development provided that any such use et cetera
40
    product development provided that any such use et cetera
11
    shall be deemed to be acceptance of the following conditions:-
41
    shall be deemed to be acceptance of the following conditions:-
12
    
42
 
13
        (1) Its Recipients shall ensure that this Notice is
43
        (1) Its Recipients shall ensure that this Notice is
14
        reproduced upon any copies or amended versions of it;
44
        reproduced upon any copies or amended versions of it;
15
    
45
 
16
        (2) Any amended version of it shall be clearly marked to
46
        (2) Any amended version of it shall be clearly marked to
17
        show both the nature of and the organisation responsible
47
        show both the nature of and the organisation responsible
18
        for the relevant amendment or amendments;
48
        for the relevant amendment or amendments;
19
    
49
 
20
        (3) Its onward transfer from a recipient to another
50
        (3) Its onward transfer from a recipient to another
21
        party shall be deemed to be that party's acceptance of
51
        party shall be deemed to be that party's acceptance of
22
        these conditions;
52
        these conditions;
23
    
53
 
24
        (4) DERA gives no warranty or assurance as to its
54
        (4) DERA gives no warranty or assurance as to its
25
        quality or suitability for any purpose and DERA accepts
55
        quality or suitability for any purpose and DERA accepts
26
        no liability whatsoever in relation to any use to which
56
        no liability whatsoever in relation to any use to which
27
        it may be put.
57
        it may be put.
28
*/
58
*/
Line 86... Line 116...
86
#define TOK_ASM				TOK_DECLARATION
116
#define TOK_ASM				TOK_DECLARATION
87
#else
117
#else
88
#define TOK_ASM				TOK_STATEMENT
118
#define TOK_ASM				TOK_STATEMENT
89
#endif
119
#endif
90
 
120
 
91
#define lookup_token( T )		( ( int ) tokens [ ( T ) ] )
121
#define lookup_token(T)			((int)tokens[(T)])
92
 
122
 
93
static unsigned char tokens [] = {
123
static unsigned char tokens[] = {
94
#define LEX_TOKEN( A, B, C )		( C ),
124
#define LEX_TOKEN(A, B, C)		(C),
95
#include "symbols.h"
125
#include "symbols.h"
96
#undef LEX_TOKEN
126
#undef LEX_TOKEN
97
    TOK_NONE
127
	TOK_NONE
98
} ;
128
};
99
 
129
 
100
 
130
 
101
/*
131
/*
102
    PARSER STATE FLAGS
132
    PARSER STATE FLAGS
103
 
133
 
Line 107... Line 137...
107
    than a cv-qualifier) has been read.  Similarly have_type_declaration
137
    than a cv-qualifier) has been read.  Similarly have_type_declaration
108
    is set to indicate an elaborated-type-specifier.  in_function_defn
138
    is set to indicate an elaborated-type-specifier.  in_function_defn
109
    is used to count nested function definitions.
139
    is used to count nested function definitions.
110
*/
140
*/
111
 
141
 
112
int have_type_specifier = 0 ;
142
int have_type_specifier = 0;
113
int have_type_declaration = TYPE_DECL_NONE ;
143
int have_type_declaration = TYPE_DECL_NONE;
114
int have_func_declarator = 0 ;
144
int have_func_declarator = 0;
115
int in_function_defn = 0 ;
145
int in_function_defn = 0;
116
int in_class_defn = 0 ;
146
int in_class_defn = 0;
117
int in_declaration = 0 ;
147
int in_declaration = 0;
118
int in_default_arg = 0 ;
148
int in_default_arg = 0;
119
int in_weak_param = 0 ;
149
int in_weak_param = 0;
120
int in_ptr_mem_selector = 0 ;
150
int in_ptr_mem_selector = 0;
121
int in_token_decl = 0 ;
151
int in_token_decl = 0;
122
int in_template_decl = 0 ;
152
int in_template_decl = 0;
123
int really_in_function_defn = 0 ;
153
int really_in_function_defn = 0;
124
int really_in_class_defn = 0 ;
154
int really_in_class_defn = 0;
125
int is_function_next = 0 ;
155
int is_function_next = 0;
126
int is_constructor_next = 0 ;
156
int is_constructor_next = 0;
127
 
157
 
128
 
158
 
129
/*
159
/*
130
    PARSER STATE COUNTERS
160
    PARSER STATE COUNTERS
131
 
161
 
132
    These variables are used to keep count of various items of interest
162
    These variables are used to keep count of various items of interest
133
    in the parser, such as the number of expressions which have side
163
    in the parser, such as the number of expressions which have side
134
    effects and the number of type definitions.
164
    effects and the number of type definitions.
135
*/
165
*/
136
 
166
 
137
int no_side_effects = 0 ;
167
int no_side_effects = 0;
138
int no_type_defns = 0 ;
168
int no_type_defns = 0;
139
int have_destructor = 0 ;
169
int have_destructor = 0;
140
unsigned long no_declarations = 0 ;
170
unsigned long no_declarations = 0;
141
unsigned long no_token_defns = 0 ;
171
unsigned long no_token_defns = 0;
142
 
172
 
143
 
173
 
144
/*
174
/*
145
    FEATURE USE FLAGS
175
    FEATURE USE FLAGS
146
 
176
 
147
    These flags are set to indicate that certain features, which require
177
    These flags are set to indicate that certain features, which require
148
    the program to perform extra checks, have been used.
178
    the program to perform extra checks, have been used.
149
*/
179
*/
150
 
180
 
151
int used_extern_volatile = 0 ;
181
int used_extern_volatile = 0;
152
int used_register = 0 ;
182
int used_register = 0;
153
 
183
 
154
 
184
 
155
/*
185
/*
156
    FORWARD DECLARATIONS
186
    FORWARD DECLARATIONS
157
 
187
 
158
    The following look-ahead functions need to be declared in advance.
188
    The following look-ahead functions need to be declared in advance.
159
*/
189
*/
160
 
190
 
161
#if LANGUAGE_CPP
191
#if LANGUAGE_CPP
162
static int predict_declarator PROTO_S ( ( int, int, int ) ) ;
192
static int predict_declarator(int, int, int);
163
#endif
193
#endif
164
 
194
 
165
 
195
 
166
/*
196
/*
167
    SKIP OVER A BRACKETED SEQUENCE
197
    SKIP OVER A BRACKETED SEQUENCE
168
 
198
 
169
    This routine is called after reading an open bracket to skip to the
199
    This routine is called after reading an open bracket to skip to the
170
    corresponding close bracket.  It returns the number of tokens skipped.
200
    corresponding close bracket.  It returns the number of tokens skipped.
171
*/
201
*/
172
 
202
 
173
#if LANGUAGE_CPP
203
#if LANGUAGE_CPP
174
 
204
 
175
static int skip_brackets
205
static int
176
    PROTO_Z ()
206
skip_brackets(void)
177
{
207
{
178
    int n = 0 ;
208
	int n = 0;
179
    int brackets = 1 ;
209
	int brackets = 1;
180
    for ( ; ; ) {
210
	for (;;) {
181
	int t = next_token () ;
211
		int t = next_token();
182
	n++ ;
212
		n++;
183
	switch ( t ) {
213
		switch (t) {
184
	    case lex_open_Hround :
214
		case lex_open_Hround:
185
	    case lex_open_Hsquare_H1 :
215
		case lex_open_Hsquare_H1:
186
	    case lex_open_Hbrace_H1 : {
216
		case lex_open_Hbrace_H1:
187
		/* Open bracket */
217
			/* Open bracket */
188
		brackets++ ;
218
			brackets++;
189
		break ;
219
			break;
190
	    }
-
 
191
	    case lex_close_Hround :
220
		case lex_close_Hround:
192
	    case lex_close_Hsquare_H1 :
221
		case lex_close_Hsquare_H1:
193
	    case lex_close_Hbrace_H1 : {
222
		case lex_close_Hbrace_H1:
194
		/* Close bracket */
223
			/* Close bracket */
195
		if ( --brackets == 0 ) return ( n ) ;
224
			if (--brackets == 0) {
196
		break ;
225
				return(n);
197
	    }
226
			}
-
 
227
			break;
198
	    case lex_eof : {
228
		case lex_eof:
199
		/* Premature end of file */
229
			/* Premature end of file */
200
		return ( n ) ;
230
			return(n);
201
	    }
231
		}
202
	}
232
	}
203
    }
-
 
204
    /* NOTREACHED */
233
	/* NOTREACHED */
205
}
234
}
206
 
235
 
207
#endif
236
#endif
208
 
237
 
209
 
238
 
210
/*
239
/*
211
    SKIP OVER AN OPERATOR NAME
240
    SKIP OVER AN OPERATOR NAME
212
 
241
 
213
    This routine is called after 'operator' has been read to return the
242
    This routine is called after 'operator' has been read to return the
214
    token immediately following.  It has to deal with both overloaded
243
    token immediately following.  It has to deal with both overloaded
215
    operator function names and conversion function names.  Note that
244
    operator function names and conversion function names.  Note that
216
    class and enumeration definitions are allowed in a conversion function
245
    class and enumeration definitions are allowed in a conversion function
217
    name by the syntax, but are weeded out later.  Skipping over them
246
    name by the syntax, but are weeded out later.  Skipping over them
218
    here would therefore seem to be a lot of effort for something which
247
    here would therefore seem to be a lot of effort for something which
219
    is going to prove illegal however it is interpreted.
248
    is going to prove illegal however it is interpreted.
366
		}
387
		}
367
	    }
-
 
368
	    break ;
388
		break;
369
	}
389
	}
370
    }
-
 
371
    return ( t ) ;
390
	return(t);
372
}
391
}
373
 
392
 
374
#endif
393
#endif
375
 
394
 
376
 
395
 
Line 381... Line 400...
381
    lists of expressions (such as function arguments or function style
400
    lists of expressions (such as function arguments or function style
382
    initialisers.  It is called after an initial open bracket has been
401
    initialisers.  It is called after an initial open bracket has been
383
    read.  It returns 1 if the following list definitely consists of
402
    read.  It returns 1 if the following list definitely consists of
384
    function parameters, 0 if it definitely consists of expressions,
403
    function parameters, 0 if it definitely consists of expressions,
385
    and 2 if it could be either.
404
    and 2 if it could be either.
386
*/
405
*/
387
 
406
 
388
#if LANGUAGE_CPP
407
#if LANGUAGE_CPP
389
 
408
 
390
static int predict_func_params
409
static int
391
    PROTO_N ( ( t, empty, depth ) )
-
 
392
    PROTO_T ( int t X int empty X int depth )
410
predict_func_params(int t, int empty, int depth)
393
{
411
{
394
    int c = lookup_token ( t ) ;
412
	int c = lookup_token(t);
395
    switch ( c ) {
413
	switch (c) {
396
	case TOK_DECLARATION :
414
	case TOK_DECLARATION:
397
	case TOK_DECL_SPEC :
415
	case TOK_DECL_SPEC:
398
	case TOK_EXTERN :
416
	case TOK_EXTERN:
399
	case TOK_TYPE_KEY :
417
	case TOK_TYPE_KEY:
400
	case TOK_TYPE_SPEC : {
418
	case TOK_TYPE_SPEC:
401
	    /* These are all obviously parameter declarations */
419
		/* These are all obviously parameter declarations */
402
	    return ( 1 ) ;
420
		return(1);
-
 
421
	case TOK_SIMPLE_TYPE:
-
 
422
	case TOK_TYPE:
-
 
423
		/* These are simple-type-specifiers */
-
 
424
		t = next_token();
-
 
425
		if (t == lex_open_Hround) {
-
 
426
			t = next_token();
-
 
427
			return(predict_func_params(t, 1, 1));
403
	}
428
		}
-
 
429
		return(1);
404
	case TOK_SIMPLE_TYPE :
430
	case TOK_NESTED_NAME:
405
	case TOK_TYPE : {
431
	case TOK_FULL_NAME:
406
	    /* These are simple-type-specifiers */
432
		/* Look for nested type-names */
-
 
433
		t = next_token();
-
 
434
		c = lookup_token(t);
-
 
435
		if (c == TOK_TYPE) {
407
	    t = next_token () ;
436
			t = next_token();
408
	    if ( t == lex_open_Hround ) {
437
			if (t == lex_open_Hround) {
409
		t = next_token () ;
438
				t = next_token();
410
		return ( predict_func_params ( t, 1, 1 ) ) ;
439
				return(predict_func_params(t, 1, 1));
411
	    }
440
			}
412
	    return ( 1 ) ;
441
			return(1);
-
 
442
		}
-
 
443
		return(0);
-
 
444
	}
-
 
445
	if (t == lex_ellipsis) {
-
 
446
		return(1);
-
 
447
	}
-
 
448
	if (t == lex_ellipsis_Hexp) {
-
 
449
		return(1);
-
 
450
	}
-
 
451
	if (t == lex_close_Hround) {
-
 
452
		/* Empty pair of brackets */
-
 
453
		return(empty);
413
	}
454
	}
414
	case TOK_NESTED_NAME :
-
 
415
	case TOK_FULL_NAME : {
-
 
416
	    /* Look for nested type-names */
-
 
417
	    t = next_token () ;
455
	if (depth) {
418
	    c = lookup_token ( t ) ;
456
		int d = predict_declarator(t, 2, 1);
419
	    if ( c == TOK_TYPE ) {
457
		if (d == 0) {
420
		t = next_token () ;
458
			return(0);
421
		if ( t == lex_open_Hround ) {
-
 
422
		    t = next_token () ;
-
 
423
		    return ( predict_func_params ( t, 1, 1 ) ) ;
-
 
424
		}
459
		}
-
 
460
		if (d == 2) {
-
 
461
			/* Comma - check next parameter */
-
 
462
			t = next_token();
-
 
463
			return(predict_func_params(t, 1, 0));
-
 
464
		}
-
 
465
		if (d == 3) {
425
		return ( 1 ) ;
466
			return(2);
426
	    }
467
		}
427
	    return ( 0 ) ;
468
		return(1);
428
	}
469
	}
429
    }
-
 
430
    if ( t == lex_ellipsis ) return ( 1 ) ;
-
 
431
    if ( t == lex_ellipsis_Hexp ) return ( 1 ) ;
-
 
432
    if ( t == lex_close_Hround ) {
-
 
433
	/* Empty pair of brackets */
-
 
434
	return ( empty ) ;
-
 
435
    }
-
 
436
    if ( depth ) {
-
 
437
	int d = predict_declarator ( t, 2, 1 ) ;
-
 
438
	if ( d == 0 ) return ( 0 ) ;
-
 
439
	if ( d == 2 ) {
-
 
440
	    /* Comma - check next parameter */
-
 
441
	    t = next_token () ;
-
 
442
	    return ( predict_func_params ( t, 1, 0 ) ) ;
-
 
443
	}
-
 
444
	if ( d == 3 ) return ( 2 ) ;
-
 
445
	return ( 1 ) ;
470
	return(0);
446
    }
-
 
447
    return ( 0 ) ;
-
 
448
}
471
}
449
 
472
 
450
#endif
473
#endif
451
 
474
 
452
 
475
 
453
/*
476
/*
454
    LOOK-AHEAD FOR DECLARATORS
477
    LOOK-AHEAD FOR DECLARATORS
Line 460... Line 483...
460
    abstract declarators and 2 to indicate parameter declarators.  The
483
    abstract declarators and 2 to indicate parameter declarators.  The
461
    return value is 0 if this is definitely not a declarator, and 1 if it
484
    return value is 0 if this is definitely not a declarator, and 1 if it
462
    definitely is.  The return values 2 and 3 are used to indicate possible
485
    definitely is.  The return values 2 and 3 are used to indicate possible
463
    declarators in the parameter case, with 2 indicating a following comma
486
    declarators in the parameter case, with 2 indicating a following comma
464
    and 3 a close bracket.
487
    and 3 a close bracket.
640
				}
676
				}
641
			    }
-
 
642
			    break ;
677
				t = next_token();
643
			}
678
			}
644
			case lex_ellipsis :
-
 
645
			case lex_ellipsis_Hexp : {
-
 
646
			    /* Ellipsis */
-
 
647
			    if ( loc == 2 && brackets <= 0 ) res = 1 ;
-
 
648
			    break ;
679
			break;
649
			}
-
 
650
			case lex_eof : {
-
 
651
			    /* Premature end of file */
-
 
652
			    res = 1 ;
-
 
653
			    break ;
-
 
654
			}
-
 
655
		    }
-
 
656
		    if ( res != -1 ) break ;
-
 
657
		    t = next_token () ;
-
 
658
		}
680
		}
659
		break ;
-
 
660
	    }
-
 
661
 
-
 
662
	    case lex_semicolon :
-
 
663
	    case lex_close_Htemplate : {
-
 
664
		/* End of declaration (don't worry about depth) */
-
 
665
		res = 3 ;
-
 
666
		break ;
-
 
667
	    }
-
 
668
 
681
 
-
 
682
		case lex_semicolon:
-
 
683
		case lex_close_Htemplate:
-
 
684
			/* End of declaration (don't worry about depth) */
-
 
685
			res = 3;
-
 
686
			break;
-
 
687
 
669
	    case lex_comma : {
688
		case lex_comma:
670
		/* Comma */
689
			/* Comma */
671
		if ( depth <= 0 ) {
690
			if (depth <= 0) {
672
		    /* Check rest of declaration */
691
				/* Check rest of declaration */
673
		    if ( loc == 1 ) {
692
				if (loc == 1) {
674
			res = 1 ;
693
					res = 1;
675
		    } else if ( loc == 2 ) {
694
				} else if (loc == 2) {
676
			res = 2 ;
695
					res = 2;
677
		    } else {
696
				} else {
678
			t = next_token () ;
697
					t = next_token();
679
			res = predict_declarator ( t, 0, 0 ) ;
698
					res = predict_declarator(t, 0, 0);
680
		    }
699
				}
-
 
700
			} else {
-
 
701
				res = 0;
-
 
702
			}
-
 
703
			break;
-
 
704
 
-
 
705
		case lex_ellipsis:
-
 
706
		case lex_ellipsis_Hexp:
-
 
707
			/* Ellipsis */
-
 
708
			if (depth <= 0 && loc == 2) {
-
 
709
				res = 1;
681
		} else {
710
			} else {
682
		    res = 0 ;
711
				res = 0;
683
		}
712
			}
684
		break ;
713
			break;
-
 
714
 
-
 
715
		case lex_close_Hround: {
-
 
716
			/* Declarator close bracket */
-
 
717
			depth--;
-
 
718
			if (depth < 0) {
-
 
719
				if (loc == 1) {
-
 
720
					res = 1;
-
 
721
				} else if (loc == 2) {
-
 
722
					res = 3;
685
	    }
723
				}
-
 
724
			}
-
 
725
			break;
-
 
726
		}
686
 
727
 
687
	    case lex_ellipsis :
-
 
688
	    case lex_ellipsis_Hexp : {
-
 
689
		/* Ellipsis */
728
		default:
690
		if ( depth <= 0 && loc == 2 ) {
729
			/* Nothing else can appear in a declaration */
691
		    res = 1 ;
730
			res = 0;
692
		} else {
731
			break;
693
		    res = 0 ;
-
 
694
		}
732
		}
695
		break ;
-
 
696
	    }
-
 
697
 
-
 
698
	    case lex_close_Hround : {
-
 
699
		/* Declarator close bracket */
-
 
700
		depth-- ;
-
 
701
		if ( depth < 0 ) {
733
		if (res != -1) {
702
		    if ( loc == 1 ) {
-
 
703
			res = 1 ;
-
 
704
		    } else if ( loc == 2 ) {
-
 
705
			res = 3 ;
-
 
706
		    }
-
 
707
		}
-
 
708
		break ;
-
 
709
	    }
-
 
710
 
-
 
711
	    default : {
-
 
712
		/* Nothing else can appear in a declaration */
-
 
713
		res = 0 ;
-
 
714
		break ;
734
			break;
715
	    }
-
 
716
	}
735
		}
717
	if ( res != -1 ) break ;
-
 
718
	t = next_token () ;
736
		t = next_token();
719
    }
737
	}
720
    if ( !IS_NULL_nspace ( ns ) ) {
738
	if (!IS_NULL_nspace(ns)) {
721
	IGNORE remove_nested_nspace ( ns ) ;
739
		IGNORE remove_nested_nspace(ns);
722
    }
740
	}
723
    return ( res ) ;
741
	return(res);
724
}
742
}
725
 
743
 
726
#endif
744
#endif
727
 
745
 
728
 
746
 
Line 736... Line 754...
736
    classified as an expression-statement.  Actually the real answer to
754
    classified as an expression-statement.  Actually the real answer to
737
    questions like is 'int ( a ) ;' a declaration or an expression is,
755
    questions like is 'int ( a ) ;' a declaration or an expression is,
738
    are flying pigs kosher?
756
    are flying pigs kosher?
739
*/
757
*/
740
 
758
 
741
int predict_decl
759
int
742
    PROTO_Z ()
760
predict_decl(void)
743
{
761
{
744
    int t = crt_lex_token ;
762
	int t = crt_lex_token;
745
    int c = lookup_token ( t ) ;
763
	int c = lookup_token(t);
746
    switch ( c ) {
764
	switch (c) {
747
	case TOK_DECLARATION :
765
	case TOK_DECLARATION:
748
	case TOK_DECL_SPEC :
766
	case TOK_DECL_SPEC:
749
	case TOK_EXTERN :
767
	case TOK_EXTERN:
750
	case TOK_TYPE_KEY :
768
	case TOK_TYPE_KEY:
751
	case TOK_TYPE_SPEC : {
769
	case TOK_TYPE_SPEC:
752
	    /* These are all obviously declarations */
770
		/* These are all obviously declarations */
753
	    return ( 1 ) ;
771
		return(1);
754
	}
-
 
755
	case TOK_SIMPLE_TYPE :
772
	case TOK_SIMPLE_TYPE:
756
	case TOK_TYPE : {
773
	case TOK_TYPE: {
757
	    /* These are simple-type-specifiers */
774
		/* These are simple-type-specifiers */
758
	    int d = 1 ;
775
		int d = 1;
759
	    PPTOKEN *p = crt_token ;
776
		PPTOKEN *p = crt_token;
760
	    NAMESPACE np = crt_lookup ;
777
		NAMESPACE np = crt_lookup;
761
	    t = next_token () ;
778
		t = next_token();
762
#if LANGUAGE_CPP
779
#if LANGUAGE_CPP
763
	    if ( t == lex_open_Hround ) {
780
		if (t == lex_open_Hround) {
764
		/* This is the tricky case, 'T ( ...' */
781
			/* This is the tricky case, 'T ( ...' */
765
		t = next_token () ;
782
			t = next_token();
766
		d = predict_declarator ( t, 0, 1 ) ;
783
			d = predict_declarator(t, 0, 1);
767
	    } else /* continued ... */
784
		} else /* continued ... */
768
#endif
785
#endif
769
	    if ( t == lex_colon ) {
786
			if (t == lex_colon) {
770
		/* Check for labels */
787
				/* Check for labels */
771
		if ( c == TOK_TYPE ) d = 0 ;
788
				if (c == TOK_TYPE) {
-
 
789
					d = 0;
772
	    }
790
				}
-
 
791
			}
773
	    crt_lookup = np ;
792
		crt_lookup = np;
774
	    crt_token = p ;
793
		crt_token = p;
775
	    return ( d ) ;
794
		return(d);
776
	}
795
	}
777
#if LANGUAGE_CPP
796
#if LANGUAGE_CPP
778
	case TOK_NESTED_NAME :
797
	case TOK_NESTED_NAME:
779
	case TOK_FULL_NAME : {
798
	case TOK_FULL_NAME: {
780
	    /* Look for nested type-names */
799
		/* Look for nested type-names */
781
	    int d = 0 ;
800
		int d = 0;
782
	    PPTOKEN *p = crt_token ;
801
		PPTOKEN *p = crt_token;
783
	    NAMESPACE np = crt_lookup ;
802
		NAMESPACE np = crt_lookup;
784
	    t = next_token () ;
803
		t = next_token();
785
	    c = lookup_token ( t ) ;
804
		c = lookup_token(t);
786
	    if ( c == TOK_TYPE ) {
805
		if (c == TOK_TYPE) {
787
		d = 1 ;
806
			d = 1;
788
		t = next_token () ;
807
			t = next_token();
789
		if ( t == lex_open_Hround ) {
808
			if (t == lex_open_Hround) {
790
		    /* This is the tricky case, 'N::T ( ...' */
809
				/* This is the tricky case, 'N::T ( ...' */
791
		    t = next_token () ;
810
				t = next_token();
792
		    d = predict_declarator ( t, 0, 1 ) ;
811
				d = predict_declarator(t, 0, 1);
-
 
812
			}
793
		}
813
		}
794
	    }
-
 
795
	    crt_lookup = np ;
814
		crt_lookup = np;
796
	    crt_token = p ;
815
		crt_token = p;
797
	    return ( d ) ;
816
		return(d);
798
	}
817
	}
799
#endif
818
#endif
800
    }
819
	}
801
    /* Nothing else is a declaration */
820
	/* Nothing else is a declaration */
802
    return ( 0 ) ;
821
	return(0);
803
}
822
}
804
 
823
 
805
 
824
 
806
/*
825
/*
807
    LOOK-AHEAD FOR UNDECLARED TYPES
826
    LOOK-AHEAD FOR UNDECLARED TYPES
808
 
827
 
809
    This look-ahead is used to handle syntax errors following undeclared
828
    This look-ahead is used to handle syntax errors following undeclared
810
    types.  The context is in a sequence of declaration specifiers in
829
    types.  The context is in a sequence of declaration specifiers in
811
    which no type specifier has been encountered.  t gives the token read.
830
    which no type specifier has been encountered.  t gives the token read.
812
*/
831
*/
813
 
832
 
814
static int predict_undecl_type
833
static int
815
    PROTO_N ( ( t, force ) )
-
 
816
    PROTO_T ( int t X int force )
834
predict_undecl_type(int t, int force)
817
{
835
{
818
    switch ( t ) {
836
	switch (t) {
819
	case lex_identifier :
837
	case lex_identifier:
820
	case lex_type_Hname :
838
	case lex_type_Hname:
821
	case lex_namespace_Hname :
839
	case lex_namespace_Hname:
822
	case lex_statement_Hname : {
840
	case lex_statement_Hname: {
823
	    int d = force ;
841
		int d = force;
824
	    PPTOKEN *p = crt_token ;
842
		PPTOKEN *p = crt_token;
825
	    NAMESPACE np = crt_lookup ;
843
		NAMESPACE np = crt_lookup;
826
	    if ( !d ) {
844
		if (!d) {
827
		t = next_token () ;
845
			t = next_token();
828
		switch ( t ) {
846
			switch (t) {
829
#if LANGUAGE_CPP
847
#if LANGUAGE_CPP
830
		    case lex_and_H1 :
848
			case lex_and_H1:
831
		    case lex_full_Hname_Hstar :
849
			case lex_full_Hname_Hstar:
832
		    case lex_nested_Hname_Hstar :
850
			case lex_nested_Hname_Hstar:
833
#endif
851
#endif
834
		    case lex_star : {
852
			case lex_star:
835
			/* These are ptr-operators */
853
				/* These are ptr-operators */
836
			d = 1 ;
854
				d = 1;
837
			break ;
855
				break;
838
		    }
-
 
839
		    case lex_open_Hround : {
856
			case lex_open_Hround:
840
			/* This is stretching the bounds of possibility */
857
				/* This is stretching the bounds of
841
			break ;
858
				 * possibility */
842
		    }
859
				break;
843
		    case lex_identifier :
860
			case lex_identifier:
844
		    case lex_type_Hname :
861
			case lex_type_Hname:
845
		    case lex_namespace_Hname :
862
			case lex_namespace_Hname:
846
		    case lex_statement_Hname :
863
			case lex_statement_Hname:
847
		    case lex_template_Htype :
864
			case lex_template_Htype:
848
		    case lex_template_Hid :
865
			case lex_template_Hid:
849
		    case lex_full_Hname :
866
			case lex_full_Hname:
850
		    case lex_nested_Hname : {
867
			case lex_nested_Hname:
851
			/* The identifier can't be a declarator */
868
				/* The identifier can't be a declarator */
852
			d = 1 ;
869
				d = 1;
853
			break ;
870
				break;
854
		    }
-
 
855
		    default : {
871
			default: {
856
			/* Check for further declaration specifiers */
872
				/* Check for further declaration specifiers */
857
			int c = lookup_token ( t ) ;
873
				int c = lookup_token(t);
858
			switch ( c ) {
874
				switch (c) {
859
			    case TOK_DECL_SPEC :
875
				case TOK_DECL_SPEC:
860
			    case TOK_SIMPLE_TYPE :
876
				case TOK_SIMPLE_TYPE:
861
			    case TOK_TYPE_KEY :
877
				case TOK_TYPE_KEY:
862
			    case TOK_TYPE_SPEC :
878
				case TOK_TYPE_SPEC:
863
			    case TOK_EXTERN :
879
				case TOK_EXTERN:
864
			    case TOK_TYPE : {
880
				case TOK_TYPE: {
865
				d = 1 ;
881
					d = 1;
866
				break ;
882
					break;
867
			    }
883
				}
868
			}
884
				}
869
			break ;
885
				break;
-
 
886
			}
870
		    }
887
			}
871
		}
888
		}
872
	    }
889
		if (d) {
873
	    if ( d ) p->tok = lex_type_Hname ;
890
			p->tok = lex_type_Hname;
-
 
891
		}
874
	    crt_lookup = np ;
892
		crt_lookup = np;
875
	    crt_token = p ;
893
		crt_token = p;
876
	    return ( d ) ;
894
		return(d);
-
 
895
	}
877
	}
896
	}
878
    }
-
 
879
    return ( 0 ) ;
897
	return(0);
880
}
898
}
881
 
899
 
882
 
900
 
883
/*
901
/*
884
    LOOK-AHEAD FOR DECLARATION SPECIFIERS
902
    LOOK-AHEAD FOR DECLARATION SPECIFIERS
Line 887... Line 905...
887
    declarators or other constructs.  Note that linkage-specifications are
905
    declarators or other constructs.  Note that linkage-specifications are
888
    spotted at this stage.  In addition type names are not always what
906
    spotted at this stage.  In addition type names are not always what
889
    they seem.  For example in:
907
    they seem.  For example in:
890
 
908
 
891
		typedef int t ;
909
		typedef int t ;
892
		typedef int t ;
910
		typedef int t ;
893
 
911
 
894
    the second t is a type-name, but needs to be recognised as a declarator-id
912
    the second t is a type-name, but needs to be recognised as a declarator-id
895
    rather than a decl-specifier.  Similarly in:
913
    rather than a decl-specifier.  Similarly in:
896
 
914
 
897
		class c {
915
		class c {
898
		    c () ;
916
		    c () ;
899
		} ;
917
		} ;
900
 
918
 
901
    the second c is a class-name, but is actually a constructor name rather
919
    the second c is a class-name, but is actually a constructor name rather
902
    than a decl-specifier.
920
    than a decl-specifier.
903
*/
921
*/
904
 
922
 
905
int predict_dspec
923
int
906
    PROTO_N ( ( force ) )
-
 
907
    PROTO_T ( int force )
924
predict_dspec(int force)
908
{
925
{
909
    int d = 0 ;
926
	int d = 0;
910
    int t = crt_lex_token ;
927
	int t = crt_lex_token;
911
    int c = lookup_token ( t ) ;
928
	int c = lookup_token(t);
912
#if LANGUAGE_CPP
929
#if LANGUAGE_CPP
913
    is_constructor_next = 0 ;
930
	is_constructor_next = 0;
914
#endif
931
#endif
915
    switch ( c ) {
932
	switch (c) {
916
	case TOK_DECL_SPEC :
933
	case TOK_DECL_SPEC:
917
	case TOK_SIMPLE_TYPE :
934
	case TOK_SIMPLE_TYPE:
918
	case TOK_TYPE_KEY :
935
	case TOK_TYPE_KEY:
919
	case TOK_TYPE_SPEC : {
936
	case TOK_TYPE_SPEC:
920
	    /* These are declaration-specifiers */
937
		/* These are declaration-specifiers */
921
	    d = 1 ;
938
		d = 1;
922
	    break ;
939
		break;
923
	}
-
 
924
	case TOK_EXTERN : {
940
	case TOK_EXTERN: {
925
#if LANGUAGE_CPP
941
#if LANGUAGE_CPP
926
	    /* Explicitly check for linkage-specifications */
942
		/* Explicitly check for linkage-specifications */
927
	    PPTOKEN *p = crt_token ;
943
		PPTOKEN *p = crt_token;
928
	    NAMESPACE np = crt_lookup ;
944
		NAMESPACE np = crt_lookup;
929
	    t = next_token () ;
945
		t = next_token();
930
	    if ( t != lex_string_Hexp && t != lex_wstring_Hexp ) d = 1 ;
946
		if (t != lex_string_Hexp && t != lex_wstring_Hexp)d = 1;
931
	    crt_lookup = np ;
947
		crt_lookup = np;
932
	    crt_token = p ;
948
		crt_token = p;
933
#else
949
#else
934
	    d = 1 ;
950
		d = 1;
935
#endif
951
#endif
936
	    break ;
952
		break;
937
	}
953
	}
938
	case TOK_TYPE : {
954
	case TOK_TYPE:
939
	    /* Only the first type name is counted */
955
		/* Only the first type name is counted */
940
	    if ( t == lex_type_Hname || t == lex_template_Htype ) {
956
		if (t == lex_type_Hname || t == lex_template_Htype) {
941
		if ( !have_type_specifier ) {
957
			if (!have_type_specifier) {
942
#if LANGUAGE_CPP
958
#if LANGUAGE_CPP
943
		    PPTOKEN *p = crt_token ;
959
				PPTOKEN *p = crt_token;
944
		    NAMESPACE np = crt_lookup ;
960
				NAMESPACE np = crt_lookup;
945
		    d = 1 ;
961
				d = 1;
946
		    t = next_token () ;
962
				t = next_token();
947
		    if ( t == lex_open_Hround ) {
963
				if (t == lex_open_Hround) {
948
			/* Allow for constructors */
964
					/* Allow for constructors */
949
			t = next_token () ;
965
					t = next_token();
950
			if ( predict_func_params ( t, 1, 0 ) ) {
966
					if (predict_func_params(t, 1, 0)) {
951
			    is_constructor_next = 1 ;
967
						is_constructor_next = 1;
952
			    d = 0 ;
968
						d = 0;
953
			}
969
					}
954
		    }
970
				}
955
		    crt_lookup = np ;
971
				crt_lookup = np;
956
		    crt_token = p ;
972
				crt_token = p;
957
#else
973
#else
958
		    d = 1 ;
974
				d = 1;
959
#endif
975
#endif
960
		}
-
 
961
	    } else {
-
 
962
		d = 1 ;
-
 
963
	    }
-
 
964
	    break ;
-
 
965
	}
-
 
966
#if LANGUAGE_CPP
-
 
967
	case TOK_NESTED_NAME :
-
 
968
	case TOK_FULL_NAME : {
-
 
969
	    /* Look for nested type names */
-
 
970
	    if ( !have_type_specifier ) {
-
 
971
		PPTOKEN *p = crt_token ;
-
 
972
		NAMESPACE np = crt_lookup ;
-
 
973
		t = next_token () ;
-
 
974
		c = lookup_token ( t ) ;
-
 
975
		if ( c == TOK_TYPE ) {
-
 
976
		    /* These are simple-type-specifiers */
-
 
977
		    d = 1 ;
-
 
978
		    t = next_token () ;
-
 
979
		    if ( t == lex_open_Hround ) {
-
 
980
			/* Allow for constructors */
-
 
981
			IGNORE add_nested_nspace ( np ) ;
-
 
982
			t = next_token () ;
-
 
983
			if ( predict_func_params ( t, 1, 0 ) ) {
-
 
984
			    is_constructor_next = 1 ;
-
 
985
			    d = 0 ;
-
 
986
			}
976
			}
987
			IGNORE remove_nested_nspace ( np ) ;
-
 
988
		    }
-
 
989
		} else {
977
		} else {
990
		    d = predict_undecl_type ( t, force ) ;
-
 
991
		}
-
 
992
		crt_lookup = np ;
-
 
993
		crt_token = p ;
-
 
994
	    }
978
			d = 1;
995
	    break ;
-
 
996
	}
979
		}
997
#endif
-
 
998
	default : {
-
 
999
	    /* Check for undefined types */
-
 
1000
	    if ( !have_type_specifier ) {
-
 
1001
		d = predict_undecl_type ( t, force ) ;
-
 
1002
		if ( d ) crt_lex_token = lex_type_Hname ;
-
 
1003
	    }
-
 
1004
	    break ;
-
 
1005
	}
-
 
1006
    }
-
 
1007
    return ( d ) ;
-
 
1008
}
-
 
1009
 
-
 
1010
 
-
 
1011
/*
-
 
1012
    LOOK-AHEAD FOR TYPE SPECIFIERS
-
 
1013
 
-
 
1014
    A look-ahead is needed to distinguish type-specifiers from following
-
 
1015
    declarators or other constructs.
-
 
1016
*/
-
 
1017
 
-
 
1018
int predict_tspec
-
 
1019
    PROTO_N ( ( force ) )
-
 
1020
    PROTO_T ( int force )
-
 
1021
{
-
 
1022
    int d = 0 ;
-
 
1023
    int t = crt_lex_token ;
-
 
1024
    int c = lookup_token ( t ) ;
-
 
1025
    switch ( c ) {
-
 
1026
	case TOK_SIMPLE_TYPE :
-
 
1027
	case TOK_TYPE_KEY :
-
 
1028
	case TOK_TYPE_SPEC :
-
 
1029
	case TOK_TYPE : {
-
 
1030
	    /* These are type-specifiers */
-
 
1031
	    d = 1 ;
-
 
1032
	    break ;
980
		break;
1033
	}
-
 
1034
#if LANGUAGE_CPP
981
#if LANGUAGE_CPP
1035
	case TOK_NESTED_NAME :
982
	case TOK_NESTED_NAME:
1036
	case TOK_FULL_NAME : {
983
	case TOK_FULL_NAME:
1037
	    /* Look for nested type names */
984
		/* Look for nested type names */
-
 
985
		if (!have_type_specifier) {
1038
	    PPTOKEN *p = crt_token ;
986
			PPTOKEN *p = crt_token;
1039
	    NAMESPACE np = crt_lookup ;
987
			NAMESPACE np = crt_lookup;
1040
	    t = next_token () ;
988
			t = next_token();
1041
	    c = lookup_token ( t ) ;
989
			c = lookup_token(t);
1042
	    if ( c == TOK_TYPE ) {
990
			if (c == TOK_TYPE) {
-
 
991
				/* These are simple-type-specifiers */
1043
		d = 1 ;
992
				d = 1;
1044
	    } else {
993
				t = next_token();
1045
		if ( !have_type_specifier ) {
994
				if (t == lex_open_Hround) {
-
 
995
					/* Allow for constructors */
-
 
996
					IGNORE add_nested_nspace(np);
-
 
997
					t = next_token();
-
 
998
					if (predict_func_params(t, 1, 0)) {
-
 
999
						is_constructor_next = 1;
-
 
1000
						d = 0;
-
 
1001
					}
-
 
1002
					IGNORE remove_nested_nspace(np);
-
 
1003
				}
-
 
1004
			} else {
1046
		    d = predict_undecl_type ( t, force ) ;
1005
				d = predict_undecl_type(t, force);
-
 
1006
			}
-
 
1007
			crt_lookup = np;
-
 
1008
			crt_token = p;
1047
		}
1009
		}
1048
	    }
-
 
1049
	    crt_lookup = np ;
-
 
1050
	    crt_token = p ;
-
 
1051
	    break ;
1010
		break;
1052
	}
-
 
1053
#endif
1011
#endif
1054
	default : {
1012
	default:
1055
	    /* Check for undefined types */
1013
		/* Check for undefined types */
1056
	    if ( !have_type_specifier ) {
1014
		if (!have_type_specifier) {
1057
		d = predict_undecl_type ( t, force ) ;
1015
			d = predict_undecl_type(t, force);
1058
		if ( d ) crt_lex_token = lex_type_Hname ;
1016
			if (d)crt_lex_token = lex_type_Hname;
1059
	    }
1017
		}
1060
	    break ;
1018
		break;
1061
	}
1019
	}
1062
    }
-
 
1063
    return ( d ) ;
1020
	return(d);
1064
}
1021
}
1065
 
1022
 
1066
 
1023
 
1067
/*
1024
/*
-
 
1025
    LOOK-AHEAD FOR TYPE SPECIFIERS
-
 
1026
 
-
 
1027
    A look-ahead is needed to distinguish type-specifiers from following
-
 
1028
    declarators or other constructs.
-
 
1029
*/
-
 
1030
 
-
 
1031
int
-
 
1032
predict_tspec(int force)
-
 
1033
{
-
 
1034
	int d = 0;
-
 
1035
	int t = crt_lex_token;
-
 
1036
	int c = lookup_token(t);
-
 
1037
	switch (c) {
-
 
1038
	case TOK_SIMPLE_TYPE:
-
 
1039
	case TOK_TYPE_KEY:
-
 
1040
	case TOK_TYPE_SPEC:
-
 
1041
	case TOK_TYPE:
-
 
1042
		/* These are type-specifiers */
-
 
1043
		d = 1;
-
 
1044
		break;
-
 
1045
#if LANGUAGE_CPP
-
 
1046
	case TOK_NESTED_NAME:
-
 
1047
	case TOK_FULL_NAME: {
-
 
1048
		/* Look for nested type names */
-
 
1049
		PPTOKEN *p = crt_token;
-
 
1050
		NAMESPACE np = crt_lookup;
-
 
1051
		t = next_token();
-
 
1052
		c = lookup_token(t);
-
 
1053
		if (c == TOK_TYPE) {
-
 
1054
			d = 1;
-
 
1055
		} else {
-
 
1056
			if (!have_type_specifier) {
-
 
1057
				d = predict_undecl_type(t, force);
-
 
1058
			}
-
 
1059
		}
-
 
1060
		crt_lookup = np;
-
 
1061
		crt_token = p;
-
 
1062
		break;
-
 
1063
	}
-
 
1064
#endif
-
 
1065
	default:
-
 
1066
		/* Check for undefined types */
-
 
1067
		if (!have_type_specifier) {
-
 
1068
			d = predict_undecl_type(t, force);
-
 
1069
			if (d)crt_lex_token = lex_type_Hname;
-
 
1070
		}
-
 
1071
		break;
-
 
1072
	}
-
 
1073
	return(d);
-
 
1074
}
-
 
1075
 
-
 
1076
 
-
 
1077
/*
1068
    LOOK-AHEAD FOR FUNCTION QUALIFIERS
1078
    LOOK-AHEAD FOR FUNCTION QUALIFIERS
1069
 
1079
 
1070
    A further look-ahead is required when distinguishing type-ids from
1080
    A further look-ahead is required when distinguishing type-ids from
1071
    expressions after 'T ()' has been read for some type.  If the next
1081
    expressions after 'T ()' has been read for some type.  If the next
1072
    token is '+' for example it is an expression, if it is 'const' it
1082
    token is '+' for example it is an expression, if it is 'const' it
1073
    is a declaration.  t gives the next token and e gives the default
1083
    is a declaration.  t gives the next token and e gives the default
1074
    value.
1084
    value.
1075
*/
1085
*/
1076
 
1086
 
1077
#if LANGUAGE_CPP
1087
#if LANGUAGE_CPP
1078
 
1088
 
1079
static int predict_qual
1089
static int
1080
    PROTO_N ( ( t, e ) )
-
 
1081
    PROTO_T ( int t X int e )
1090
predict_qual(int t, int e)
1082
{
1091
{
1083
    switch ( t ) {
1092
	switch (t) {
1084
	case lex_const :
1093
	case lex_const:
1085
	case lex_volatile :
1094
	case lex_volatile:
1086
	case lex_throw : {
1095
	case lex_throw:
1087
	    /* Function qualifiers */
1096
		/* Function qualifiers */
1088
	    e = 1 ;
1097
		e = 1;
1089
	    break ;
1098
		break;
1090
	}
-
 
1091
	case lex_and_H1 :
1099
	case lex_and_H1:
1092
	case lex_and_Heq_H1 :
1100
	case lex_and_Heq_H1:
1093
	case lex_arrow :
1101
	case lex_arrow:
1094
	case lex_arrow_Hstar :
1102
	case lex_arrow_Hstar:
1095
	case lex_assign :
1103
	case lex_assign:
1096
	case lex_div :
1104
	case lex_div:
1097
	case lex_div_Heq :
1105
	case lex_div_Heq:
1098
	case lex_dot :
1106
	case lex_dot:
1099
	case lex_dot_Hstar :
1107
	case lex_dot_Hstar:
1100
	case lex_eq :
1108
	case lex_eq:
1101
	case lex_greater :
1109
	case lex_greater:
1102
	case lex_greater_Heq :
1110
	case lex_greater_Heq:
1103
	case lex_less :
1111
	case lex_less:
1104
	case lex_less_Heq :
1112
	case lex_less_Heq:
1105
	case lex_logical_Hand_H1 :
1113
	case lex_logical_Hand_H1:
1106
	case lex_logical_Hor_H1 :
1114
	case lex_logical_Hor_H1:
1107
	case lex_lshift :
1115
	case lex_lshift:
1108
	case lex_lshift_Heq :
1116
	case lex_lshift_Heq:
1109
	case lex_minus :
1117
	case lex_minus:
1110
	case lex_minus_Heq :
1118
	case lex_minus_Heq:
1111
	case lex_minus_Hminus :
1119
	case lex_minus_Hminus:
1112
	case lex_not_Heq_H1 :
1120
	case lex_not_Heq_H1:
1113
	case lex_or_H1 :
1121
	case lex_or_H1:
1114
	case lex_or_Heq_H1 :
1122
	case lex_or_Heq_H1:
1115
	case lex_plus :
1123
	case lex_plus:
1116
	case lex_plus_Heq :
1124
	case lex_plus_Heq:
1117
	case lex_plus_Hplus :
1125
	case lex_plus_Hplus:
1118
	case lex_question :
1126
	case lex_question:
1119
	case lex_rem :
1127
	case lex_rem:
1120
	case lex_rem_Heq :
1128
	case lex_rem_Heq:
1121
	case lex_rshift :
1129
	case lex_rshift:
1122
	case lex_rshift_Heq :
1130
	case lex_rshift_Heq:
1123
	case lex_star :
1131
	case lex_star:
1124
	case lex_star_Heq :
1132
	case lex_star_Heq:
1125
	case lex_xor_H1 :
1133
	case lex_xor_H1:
1126
	case lex_xor_Heq_H1 :
1134
	case lex_xor_Heq_H1:
1127
	case lex_abs :
1135
	case lex_abs:
1128
	case lex_max :
1136
	case lex_max:
1129
	case lex_min : {
1137
	case lex_min:
1130
	    /* Binary expression operators */
1138
		/* Binary expression operators */
1131
	    e = 0 ;
1139
		e = 0;
1132
	    break ;
1140
		break;
1133
	}
-
 
1134
	case lex_comma : {
1141
	case lex_comma:
1135
	    /* Comma operators */
1142
		/* Comma operators */
1136
	    if ( e == 1 ) e = 0 ;
1143
		if (e == 1) {
1137
	    break ;
1144
			e = 0;
1138
	}
1145
		}
-
 
1146
		break;
1139
    }
1147
	}
1140
    return ( e ) ;
1148
	return(e);
1141
}
1149
}
1142
 
1150
 
1143
#endif
1151
#endif
1144
 
1152
 
1145
 
1153
 
1146
/*
1154
/*
1147
    LOOK-AHEAD FOR TYPE IDENTIFIERS
1155
    LOOK-AHEAD FOR TYPE IDENTIFIERS
1148
 
1156
 
1149
    A look-ahead is needed to distinguish type-ids from expressions in,
1157
    A look-ahead is needed to distinguish type-ids from expressions in,
1150
    for example, sizeof expressions.  A type-id consists of a sequence
1158
    for example, sizeof expressions.  A type-id consists of a sequence
1151
    of type-specifiers followed by an optional abstract-declarator,
1159
    of type-specifiers followed by an optional abstract-declarator,
1152
    whereas the only tricky expressions are those consisting of a
1160
    whereas the only tricky expressions are those consisting of a
1153
    simple-type-specifier followed by a bracketed list of expressions.
1161
    simple-type-specifier followed by a bracketed list of expressions.
1154
    e gives the value to be returned if the result could be either.
1162
    e gives the value to be returned if the result could be either.
1155
*/
1163
*/
1156
 
1164
 
1157
int predict_typeid
1165
int
1158
    PROTO_N ( ( e ) )
-
 
1159
    PROTO_T ( int e )
1166
predict_typeid(int e)
1160
{
1167
{
1161
    int t = crt_lex_token ;
1168
	int t = crt_lex_token;
1162
    int c = lookup_token ( t ) ;
1169
	int c = lookup_token(t);
1163
    switch ( c ) {
1170
	switch (c) {
1164
	case TOK_TYPE_KEY :
1171
	case TOK_TYPE_KEY:
1165
	case TOK_TYPE_SPEC : {
1172
	case TOK_TYPE_SPEC:
1166
	    /* These are type-specifiers */
1173
		/* These are type-specifiers */
1167
	    return ( 1 ) ;
1174
		return(1);
1168
	}
-
 
1169
	case TOK_SIMPLE_TYPE :
1175
	case TOK_SIMPLE_TYPE:
1170
	case TOK_TYPE : {
1176
	case TOK_TYPE: {
1171
	    /* These are simple-type-specifiers */
1177
		/* These are simple-type-specifiers */
1172
	    int d = 1 ;
1178
		int d = 1;
1173
#if LANGUAGE_CPP
1179
#if LANGUAGE_CPP
1174
	    PPTOKEN *p = crt_token ;
1180
		PPTOKEN *p = crt_token;
1175
	    NAMESPACE np = crt_lookup ;
1181
		NAMESPACE np = crt_lookup;
1176
	    t = next_token () ;
1182
		t = next_token();
1177
	    if ( t == lex_open_Hround ) {
1183
		if (t == lex_open_Hround) {
1178
		/* This is the tricky case 'T ( ...' */
1184
			/* This is the tricky case 'T ( ...' */
1179
		PPTOKEN *q ;
1185
			PPTOKEN *q;
1180
		NAMESPACE nq ;
1186
			NAMESPACE nq;
1181
		t = next_token () ;
1187
			t = next_token();
1182
		q = crt_token ;
1188
			q = crt_token;
1183
		nq = crt_lookup ;
1189
			nq = crt_lookup;
1184
		d = predict_func_params ( t, 2, 0 ) ;
1190
			d = predict_func_params(t, 2, 0);
1185
		if ( d != 1 ) {
1191
			if (d != 1) {
1186
		    if ( t == lex_close_Hround ) {
1192
				if (t == lex_close_Hround) {
1187
			t = next_token () ;
1193
					t = next_token();
1188
			d = predict_qual ( t, e ) ;
1194
					d = predict_qual(t, e);
1189
		    } else {
1195
				} else {
1190
			crt_lookup = nq ;
1196
					crt_lookup = nq;
1191
			crt_token = q ;
1197
					crt_token = q;
1192
			d = predict_declarator ( t, 1, 1 ) ;
1198
					d = predict_declarator(t, 1, 1);
1193
		    }
1199
				}
-
 
1200
			}
1194
		}
1201
		}
1195
	    }
-
 
1196
	    crt_lookup = np ;
1202
		crt_lookup = np;
1197
	    crt_token = p ;
1203
		crt_token = p;
1198
#else
1204
#else
1199
	    UNUSED ( e ) ;
1205
		UNUSED(e);
1200
#endif
1206
#endif
1201
	    return ( d ) ;
1207
		return(d);
1202
	}
1208
	}
1203
#if LANGUAGE_CPP
1209
#if LANGUAGE_CPP
1204
	case TOK_NESTED_NAME :
1210
	case TOK_NESTED_NAME:
1205
	case TOK_FULL_NAME : {
1211
	case TOK_FULL_NAME: {
1206
	    /* Look for nested type-names */
1212
		/* Look for nested type-names */
1207
	    int d = 0 ;
1213
		int d = 0;
1208
	    PPTOKEN *p = crt_token ;
1214
		PPTOKEN *p = crt_token;
1209
	    NAMESPACE np = crt_lookup ;
1215
		NAMESPACE np = crt_lookup;
1210
	    t = next_token () ;
1216
		t = next_token();
1211
	    c = lookup_token ( t ) ;
1217
		c = lookup_token(t);
1212
	    if ( c == TOK_TYPE ) {
1218
		if (c == TOK_TYPE) {
1213
		d = 1 ;
1219
			d = 1;
1214
		t = next_token () ;
1220
			t = next_token();
1215
		if ( t == lex_open_Hround ) {
1221
			if (t == lex_open_Hround) {
1216
		    /* This is the tricky case 'N::T ( ...' */
1222
				/* This is the tricky case 'N::T ( ...' */
1217
		    PPTOKEN *q ;
1223
				PPTOKEN *q;
1218
		    NAMESPACE nq ;
1224
				NAMESPACE nq;
1219
		    t = next_token () ;
1225
				t = next_token();
1220
		    q = crt_token ;
1226
				q = crt_token;
1221
		    nq = crt_lookup ;
1227
				nq = crt_lookup;
1222
		    d = predict_func_params ( t, 2, 0 ) ;
1228
				d = predict_func_params(t, 2, 0);
1223
		    if ( d != 1 ) {
1229
				if (d != 1) {
1224
			if ( t == lex_close_Hround ) {
1230
					if (t == lex_close_Hround) {
1225
			    t = next_token () ;
1231
						t = next_token();
1226
			    d = predict_qual ( t, e ) ;
1232
						d = predict_qual(t, e);
1227
			} else {
1233
					} else {
1228
			    crt_lookup = nq ;
1234
						crt_lookup = nq;
1229
			    crt_token = q ;
1235
						crt_token = q;
1230
			    d = predict_declarator ( t, 1, 1 ) ;
1236
						d = predict_declarator(t, 1, 1);
-
 
1237
					}
-
 
1238
				}
1231
			}
1239
			}
1232
		    }
-
 
1233
		}
1240
		}
1234
	    }
-
 
1235
	    crt_lookup = np ;
1241
		crt_lookup = np;
1236
	    crt_token = p ;
1242
		crt_token = p;
1237
	    return ( d ) ;
1243
		return(d);
1238
	}
1244
	}
1239
#endif
1245
#endif
1240
    }
1246
	}
1241
    return ( 0 ) ;
1247
	return(0);
1242
}
1248
}
1243
 
1249
 
1244
 
1250
 
1245
/*
1251
/*
1246
    LOOK-AHEAD FOR TEMPLATE TYPE NAMES
1252
    LOOK-AHEAD FOR TEMPLATE TYPE NAMES
1247
 
1253
 
1248
    A look-ahead is needed to distinguish template type names from other
1254
    A look-ahead is needed to distinguish template type names from other
1249
    types when parsing template arguments.
1255
    types when parsing template arguments.
1250
*/
1256
*/
1251
 
1257
 
-
 
1258
int
1252
int predict_typename
1259
predict_typename(void)
1253
    PROTO_Z ()
-
 
1254
{
1260
{
1255
    int d = 0 ;
1261
	int d = 0;
1256
    int t = crt_lex_token ;
1262
	int t = crt_lex_token;
1257
    if ( t == lex_type_Hname ) {
1263
	if (t == lex_type_Hname) {
1258
	/* Unqualified type names */
1264
		/* Unqualified type names */
1259
	IDENTIFIER id = crt_token->pp_data.id.use ;
1265
		IDENTIFIER id = crt_token->pp_data.id.use;
1260
	DECL_SPEC ds = DEREF_dspec ( id_storage ( id ) ) ;
1266
		DECL_SPEC ds = DEREF_dspec(id_storage(id));
1261
	if ( ds & dspec_template ) d = 1 ;
1267
		if (ds & dspec_template) {
-
 
1268
			d = 1;
1262
    }
1269
		}
-
 
1270
	}
1263
#if LANGUAGE_CPP
1271
#if LANGUAGE_CPP
1264
    if ( t == lex_full_Hname || t == lex_nested_Hname || t == lex_colon_Hcolon ) {
1272
	if (t == lex_full_Hname || t == lex_nested_Hname ||
-
 
1273
	    t == lex_colon_Hcolon) {
1265
	PPTOKEN *p = crt_token ;
1274
		PPTOKEN *p = crt_token;
1266
	NAMESPACE np = crt_lookup ;
1275
		NAMESPACE np = crt_lookup;
1267
	t = next_token () ;
1276
		t = next_token();
1268
	if ( t == lex_type_Hname ) {
1277
		if (t == lex_type_Hname) {
1269
	    /* Qualified type names */
1278
			/* Qualified type names */
1270
	    IDENTIFIER id = crt_token->pp_data.id.use ;
1279
			IDENTIFIER id = crt_token->pp_data.id.use;
1271
	    DECL_SPEC ds = DEREF_dspec ( id_storage ( id ) ) ;
1280
			DECL_SPEC ds = DEREF_dspec(id_storage(id));
1272
	    if ( ds & dspec_template ) d = 1 ;
1281
			if (ds & dspec_template) {
-
 
1282
				d = 1;
-
 
1283
			}
-
 
1284
		}
-
 
1285
		crt_lookup = np;
-
 
1286
		crt_token = p;
1273
	}
1287
	}
1274
	crt_lookup = np ;
-
 
1275
	crt_token = p ;
-
 
1276
    }
-
 
1277
#endif
1288
#endif
1278
    return ( d ) ;
1289
	return(d);
1279
}
1290
}
1280
 
1291
 
1281
 
1292
 
1282
/*
1293
/*
1283
    LOOK-AHEAD FOR INITIALISERS
1294
    LOOK-AHEAD FOR INITIALISERS
Line 1286... Line 1297...
1286
    init-declarator from function declarators.  This predicate is called
1297
    init-declarator from function declarators.  This predicate is called
1287
    immediately after an open bracket.  Note that anything which could
1298
    immediately after an open bracket.  Note that anything which could
1288
    possibly be a function declarator is.  If the result is an initialiser
1299
    possibly be a function declarator is.  If the result is an initialiser
1289
    beginning with '(' then this first token is replaced by a dummy to
1300
    beginning with '(' then this first token is replaced by a dummy to
1290
    prevent further calls to predict_init.
1301
    prevent further calls to predict_init.
1291
*/
1302
*/
1292
 
1303
 
1293
int predict_init
1304
int
1294
    PROTO_Z ()
1305
predict_init(void)
1295
{
1306
{
1296
#if LANGUAGE_CPP
1307
#if LANGUAGE_CPP
1297
    PPTOKEN *p = crt_token ;
1308
	PPTOKEN *p = crt_token;
1298
    NAMESPACE np = crt_lookup ;
1309
	NAMESPACE np = crt_lookup;
1299
    int t = crt_lex_token ;
1310
	int t = crt_lex_token;
1300
    int d = predict_func_params ( t, 1, 0 ) ;
1311
	int d = predict_func_params(t, 1, 0);
1301
    crt_lookup = np ;
1312
	crt_lookup = np;
1302
    crt_token = p ;
1313
	crt_token = p;
1303
    if ( d == 0 ) {
1314
	if (d == 0) {
1304
	/* Definitely doesn't look like a function declarator */
1315
		/* Definitely doesn't look like a function declarator */
1305
	if ( t == lex_open_Hround ) {
1316
		if (t == lex_open_Hround) {
1306
	    t = lex_open_Hinit ;
1317
			t = lex_open_Hinit;
1307
	    crt_lex_token = t ;
1318
			crt_lex_token = t;
1308
	    p->tok = t ;
1319
			p->tok = t;
1309
	}
1320
		}
1310
	return ( 1 ) ;
1321
		return(1);
1311
    }
1322
	}
1312
    if ( t == lex_ellipsis_Hexp ) {
1323
	if (t == lex_ellipsis_Hexp) {
1313
	t = lex_ellipsis ;
1324
		t = lex_ellipsis;
1314
	crt_lex_token = t ;
1325
		crt_lex_token = t;
1315
	p->tok = t ;
1326
		p->tok = t;
1316
    }
1327
	}
1317
#endif
1328
#endif
1318
    return ( 0 ) ;
1329
	return(0);
1319
}
1330
}
1320
 
1331
 
1321
 
1332
 
1322
/*
1333
/*
1323
    LOOK-AHEAD FOR DESTRUCTORS
1334
    LOOK-AHEAD FOR DESTRUCTORS
1324
 
1335
 
Line 1326... Line 1337...
1326
    complement operator followed by a class-name.  The latter is only the
1337
    complement operator followed by a class-name.  The latter is only the
1327
    case if it is followed by a bracketed list of expressions.  The
1338
    case if it is followed by a bracketed list of expressions.  The
1328
    really difficult case is when this list is empty.  The return value
1339
    really difficult case is when this list is empty.  The return value
1329
    is 2 following '::', 3 following '->' or '.', and 1 for other
1340
    is 2 following '::', 3 following '->' or '.', and 1 for other
1330
    destructors.
1341
    destructors.
1331
*/
1342
*/
1332
 
1343
 
1333
int predict_destr
1344
int
1334
    PROTO_N ( ( ns ) )
-
 
1335
    PROTO_T ( NAMESPACE ns )
1345
predict_destr(NAMESPACE ns)
1336
{
1346
{
1337
#if LANGUAGE_CPP
1347
#if LANGUAGE_CPP
1338
    int d = 1 ;
1348
	int d = 1;
1339
    int t = last_lex_token ;
1349
	int t = last_lex_token;
1340
    if ( !IS_NULL_nspace ( ns ) ) {
1350
	if (!IS_NULL_nspace(ns)) {
1341
	if ( EQ_nspace ( ns, global_namespace ) ) {
1351
		if (EQ_nspace(ns, global_namespace)) {
1342
	    t = lex_colon_Hcolon ;
1352
			t = lex_colon_Hcolon;
1343
	} else {
1353
		} else {
1344
	    t = lex_nested_Hname ;
1354
			t = lex_nested_Hname;
1345
	}
1355
		}
1346
    }
1356
	}
1347
    switch ( t ) {
1357
	switch (t) {
1348
	case lex_nested_Hname :
1358
	case lex_nested_Hname:
1349
	case lex_full_Hname : {
1359
	case lex_full_Hname:
1350
	    /* Always have destructor names after these */
1360
		/* Always have destructor names after these */
1351
	    if ( cache_lookup ) {
1361
		if (cache_lookup) {
1352
		d = 2 ;
1362
			d = 2;
1353
	    } else {
-
 
1354
		/* Can only happen after '.' or '->' */
-
 
1355
		d = 3 ;
-
 
1356
	    }
-
 
1357
	    break ;
-
 
1358
	}
-
 
1359
	case lex_colon_Hcolon : {
-
 
1360
	    /* Never have destructor name after this */
-
 
1361
	    d = 0 ;
-
 
1362
	    break ;
-
 
1363
	}
-
 
1364
	case lex_arrow :
-
 
1365
	case lex_dot : {
-
 
1366
	    /* Always have destructor names after these */
-
 
1367
	    d = 3 ;
-
 
1368
	    break ;
-
 
1369
	}
-
 
1370
	default : {
-
 
1371
	    PPTOKEN *p = crt_token ;
-
 
1372
	    NAMESPACE np = crt_lookup ;
-
 
1373
	    t = next_token () ;
-
 
1374
	    if ( t == lex_open_Hround ) {
-
 
1375
		t = next_token () ;
-
 
1376
		if ( t == lex_close_Hround ) {
-
 
1377
		    /* This is the commonest case */
-
 
1378
		    if ( in_function_defn ) d = 0 ;
-
 
1379
		} else {
1363
		} else {
1380
		    d = predict_func_params ( t, 1, 0 ) ;
1364
			/* Can only happen after '.' or '->' */
1381
		    if ( d ) d = 1 ;
1365
			d = 3;
1382
		}
1366
		}
-
 
1367
		break;
-
 
1368
	case lex_colon_Hcolon:
-
 
1369
		/* Never have destructor name after this */
1383
	    }
1370
		d = 0;
-
 
1371
		break;
-
 
1372
	case lex_arrow:
-
 
1373
	case lex_dot:
-
 
1374
		/* Always have destructor names after these */
-
 
1375
		d = 3;
-
 
1376
		break;
-
 
1377
	default: {
-
 
1378
		PPTOKEN *p = crt_token;
-
 
1379
		NAMESPACE np = crt_lookup;
-
 
1380
		t = next_token();
-
 
1381
		if (t == lex_open_Hround) {
-
 
1382
			t = next_token();
-
 
1383
			if (t == lex_close_Hround) {
-
 
1384
				/* This is the commonest case */
-
 
1385
				if (in_function_defn)d = 0;
-
 
1386
			} else {
-
 
1387
				d = predict_func_params(t, 1, 0);
-
 
1388
				if (d)d = 1;
-
 
1389
			}
-
 
1390
		}
1384
	    crt_lookup = np ;
1391
		crt_lookup = np;
1385
	    crt_token = p ;
1392
		crt_token = p;
1386
	    break ;
1393
		break;
1387
	}
1394
	}
1388
    }
1395
	}
1389
    return ( d ) ;
1396
	return(d);
1390
#else
1397
#else
1391
    UNUSED ( ns ) ;
1398
	UNUSED(ns);
1392
    return ( 0 ) ;
1399
	return(0);
1393
#endif
1400
#endif
1394
}
1401
}
1395
 
1402
 
1396
 
1403
 
1397
/*
1404
/*
1398
    LOOK-AHEAD FOR FUNCTION PARAMETERS
1405
    LOOK-AHEAD FOR FUNCTION PARAMETERS
1399
 
1406
 
1400
    A look-ahead is needed to distinguish a declarator-id representing a
1407
    A look-ahead is needed to distinguish a declarator-id representing a
1401
    function parameter from a type-specifier.  The only difficult case is
1408
    function parameter from a type-specifier.  The only difficult case is
1402
    a type-name immediately after an open bracket.
1409
    a type-name immediately after an open bracket.
1403
*/
1410
*/
1404
 
1411
 
1405
int predict_param
1412
int
1406
    PROTO_Z ()
1413
predict_param(void)
1407
{
1414
{
1408
    int t = crt_lex_token ;
1415
	int t = crt_lex_token;
1409
    switch ( t ) {
1416
	switch (t) {
1410
	case lex_identifier :
1417
	case lex_identifier:
1411
	case lex_namespace_Hname :
1418
	case lex_namespace_Hname:
1412
	case lex_statement_Hname :
1419
	case lex_statement_Hname:
1413
	case lex_destructor_Hname :
1420
	case lex_destructor_Hname:
1414
	case lex_template_Hid :
1421
	case lex_template_Hid:
1415
	case lex_operator : {
1422
	case lex_operator:
1416
	    /* These are all unqualified-ids */
1423
		/* These are all unqualified-ids */
1417
	    return ( 1 ) ;
1424
		return(1);
1418
	}
-
 
1419
	case lex_type_Hname :
1425
	case lex_type_Hname:
1420
	case lex_template_Htype : {
1426
	case lex_template_Htype:
1421
	    /* Check for type names */
1427
		/* Check for type names */
1422
	    if ( last_lex_token != lex_open_Hround ) return ( 1 ) ;
1428
		if (last_lex_token != lex_open_Hround) {
1423
	    break ;
1429
			return(1);
1424
	}
1430
		}
-
 
1431
		break;
1425
#if LANGUAGE_CPP
1432
#if LANGUAGE_CPP
1426
	case lex_full_Hname :
1433
	case lex_full_Hname:
1427
	case lex_nested_Hname :
1434
	case lex_nested_Hname:
1428
	case lex_colon_Hcolon : {
1435
	case lex_colon_Hcolon: {
1429
	    /* Check token after a nested name */
1436
		/* Check token after a nested name */
1430
	    int d ;
1437
		int d;
1431
	    PPTOKEN *p = crt_token ;
1438
		PPTOKEN *p = crt_token;
1432
	    NAMESPACE np = crt_lookup ;
1439
		NAMESPACE np = crt_lookup;
1433
	    crt_lex_token = next_token () ;
1440
		crt_lex_token = next_token();
1434
	    d = predict_param () ;
1441
		d = predict_param();
1435
	    crt_lex_token = t ;
1442
		crt_lex_token = t;
1436
	    crt_lookup = np ;
1443
		crt_lookup = np;
1437
	    crt_token = p ;
1444
		crt_token = p;
1438
	    return ( d ) ;
1445
		return(d);
1439
	}
1446
	}
1440
#endif
1447
#endif
1441
    }
1448
	}
1442
    return ( 0 ) ;
1449
	return(0);
1443
}
1450
}
1444
 
1451
 
1445
 
1452
 
1446
/*
1453
/*
1447
    LOOK-AHEAD FOR CLASS SPECIFICATIONS
1454
    LOOK-AHEAD FOR CLASS SPECIFICATIONS
Line 1452... Line 1459...
1452
    or an enum-specifier.  This is recognised by an optional qualified
1459
    or an enum-specifier.  This is recognised by an optional qualified
1453
    identifier followed by an open brace (for the class body) or a colon
1460
    identifier followed by an open brace (for the class body) or a colon
1454
    (for a base-clause, if col is true).
1461
    (for a base-clause, if col is true).
1455
*/
1462
*/
1456
 
1463
 
1457
int predict_class
1464
int
1458
    PROTO_N ( ( col ) )
-
 
1459
    PROTO_T ( int col )
1465
predict_class(int col)
1460
{
1466
{
1461
    int t = crt_lex_token ;
1467
	int t = crt_lex_token;
1462
 
1468
 
1463
    /* Examine the name */
1469
	/* Examine the name */
1464
    switch ( t ) {
1470
	switch (t) {
1465
	case lex_identifier :
1471
	case lex_identifier:
1466
	case lex_type_Hname :
1472
	case lex_type_Hname:
1467
	case lex_namespace_Hname :
1473
	case lex_namespace_Hname:
1468
	case lex_statement_Hname :
1474
	case lex_statement_Hname:
1469
	case lex_template_Htype : {
1475
	case lex_template_Htype: {
1470
	    /* Name present */
1476
		/* Name present */
1471
	    PPTOKEN *p = crt_token ;
1477
		PPTOKEN *p = crt_token;
1472
	    NAMESPACE np = crt_lookup ;
1478
		NAMESPACE np = crt_lookup;
1473
	    t = next_token () ;
1479
		t = next_token();
1474
	    crt_lookup = np ;
1480
		crt_lookup = np;
1475
	    crt_token = p ;
1481
		crt_token = p;
1476
	    break ;
1482
		break;
1477
	}
1483
	}
1478
#if LANGUAGE_CPP
1484
#if LANGUAGE_CPP
1479
	case lex_full_Hname :
1485
	case lex_full_Hname:
1480
	case lex_nested_Hname :
1486
	case lex_nested_Hname:
1481
	case lex_colon_Hcolon : {
1487
	case lex_colon_Hcolon: {
1482
	    /* Allow for nested names */
1488
		/* Allow for nested names */
1483
	    PPTOKEN *p = crt_token ;
1489
		PPTOKEN *p = crt_token;
1484
	    NAMESPACE np = crt_lookup ;
1490
		NAMESPACE np = crt_lookup;
1485
	    t = next_token () ;
1491
		t = next_token();
1486
	    switch ( t ) {
1492
		switch (t) {
1487
		case lex_identifier :
1493
		case lex_identifier:
1488
		case lex_type_Hname :
1494
		case lex_type_Hname:
1489
		case lex_namespace_Hname :
1495
		case lex_namespace_Hname:
1490
		case lex_statement_Hname :
1496
		case lex_statement_Hname:
1491
		case lex_template_Htype : {
1497
		case lex_template_Htype:
1492
		    /* Nested name present */
1498
			/* Nested name present */
1493
		    t = next_token () ;
1499
			t = next_token();
1494
		    crt_lookup = np ;
1500
			crt_lookup = np;
1495
		    crt_token = p ;
1501
			crt_token = p;
1496
		    break ;
1502
			break;
-
 
1503
		default:
-
 
1504
			/* Invalid name */
-
 
1505
			crt_lookup = np;
-
 
1506
			crt_token = p;
-
 
1507
			return(0);
1497
		}
1508
		}
1498
		default : {
-
 
1499
		    /* Invalid name */
-
 
1500
		    crt_lookup = np ;
-
 
1501
		    crt_token = p ;
-
 
1502
		    return ( 0 ) ;
-
 
1503
		}
-
 
1504
	    }
-
 
1505
	    break ;
1509
		break;
1506
	}
1510
	}
1507
#endif
1511
#endif
1508
    }
1512
	}
1509
 
1513
 
1510
    /* Examine the token following the name */
1514
	/* Examine the token following the name */
1511
    if ( t == lex_open_Hbrace_H1 ) return ( 1 ) ;
1515
	if (t == lex_open_Hbrace_H1) {
-
 
1516
		return(1);
-
 
1517
	}
1512
    if ( t == lex_colon && !in_token_decl ) return ( col ) ;
1518
	if (t == lex_colon && !in_token_decl) {
-
 
1519
		return(col);
-
 
1520
	}
1513
    return ( 0 ) ;
1521
	return(0);
1514
}
1522
}
1515
 
1523
 
1516
 
1524
 
1517
/*
1525
/*
1518
    LOOK-AHEAD FOR FUNCTION DEFINITIONS
1526
    LOOK-AHEAD FOR FUNCTION DEFINITIONS
Line 1522... Line 1530...
1522
    (starting a function-body), a ':' (starting a ctor-initialiser), or
1530
    (starting a function-body), a ':' (starting a ctor-initialiser), or
1523
    a 'try' (starting a function-try-block).  It has already been checked
1531
    a 'try' (starting a function-try-block).  It has already been checked
1524
    whether the type of the current declarator is a function.
1532
    whether the type of the current declarator is a function.
1525
*/
1533
*/
1526
 
1534
 
-
 
1535
int
1527
int predict_func_defn
1536
predict_func_defn(void)
1528
    PROTO_Z ()
-
 
1529
{
1537
{
1530
    int t = crt_lex_token ;
1538
	int t = crt_lex_token;
1531
    if ( t == lex_open_Hbrace_H1 ) return ( 1 ) ;
1539
	if (t == lex_open_Hbrace_H1) {
-
 
1540
		return(1);
-
 
1541
	}
1532
#if LANGUAGE_CPP
1542
#if LANGUAGE_CPP
1533
    if ( t == lex_try ) return ( 1 ) ;
1543
	if (t == lex_try) {
-
 
1544
		return(1);
-
 
1545
	}
1534
    if ( t == lex_colon && !in_token_decl ) return ( 1 ) ;
1546
	if (t == lex_colon && !in_token_decl) {
-
 
1547
		return(1);
-
 
1548
	}
1535
#endif
1549
#endif
1536
    return ( 0 ) ;
1550
	return(0);
1537
}
1551
}
1538
 
1552
 
1539
 
1553
 
1540
/*
1554
/*
1541
    LOOK-AHEAD FOR OBJECT INITIALISERS
1555
    LOOK-AHEAD FOR OBJECT INITIALISERS
1542
 
1556
 
1543
    A predicate is needed to determine whether an object declaration
1557
    A predicate is needed to determine whether an object declaration
1544
    is followed by an initialising expression.  Note this is not the
1558
    is followed by an initialising expression.  Note this is not the
1545
    same as the object being defined.
1559
    same as the object being defined.
1546
*/
1560
*/
1547
 
1561
 
-
 
1562
int
1548
int predict_obj_defn
1563
predict_obj_defn(void)
1549
    PROTO_Z ()
-
 
1550
{
1564
{
1551
    int t = crt_lex_token ;
1565
	int t = crt_lex_token;
1552
    if ( t == lex_assign ) return ( 1 ) ;
1566
	if (t == lex_assign) {
-
 
1567
		return(1);
-
 
1568
	}
1553
#if LANGUAGE_CPP
1569
#if LANGUAGE_CPP
1554
    if ( t == lex_open_Hround ) return ( 1 ) ;
1570
	if (t == lex_open_Hround) {
-
 
1571
		return(1);
-
 
1572
	}
1555
#endif
1573
#endif
1556
    return ( 0 ) ;
1574
	return(0);
1557
}
1575
}
1558
 
1576
 
1559
 
1577
 
1560
/*
1578
/*
1561
    LOOK-AHEAD FOR POINTER OPERATORS
1579
    LOOK-AHEAD FOR POINTER OPERATORS
1562
 
1580
 
1563
    A look-ahead is needed following a conversion-function-id for possible
1581
    A look-ahead is needed following a conversion-function-id for possible
Line 1565... Line 1583...
1565
    to be resolved as the conversion function for 'int *' rather than as
1583
    to be resolved as the conversion function for 'int *' rather than as
1566
    the conversion function for 'int' times something.  The argument ref
1584
    the conversion function for 'int' times something.  The argument ref
1567
    indicates whether '&' is a valid pointer operator.
1585
    indicates whether '&' is a valid pointer operator.
1568
*/
1586
*/
1569
 
1587
 
1570
int predict_ptr
1588
int
1571
    PROTO_N ( ( ref ) )
-
 
1572
    PROTO_T ( int ref )
1589
predict_ptr(int ref)
1573
{
1590
{
1574
    int t = crt_lex_token ;
1591
	int t = crt_lex_token;
1575
    if ( t == lex_star ) return ( 1 ) ;
1592
	if (t == lex_star) {
-
 
1593
		return(1);
-
 
1594
	}
1576
#if LANGUAGE_CPP
1595
#if LANGUAGE_CPP
1577
    if ( t == lex_full_Hname_Hstar || t == lex_nested_Hname_Hstar ) return ( 1 ) ;
1596
	if (t == lex_full_Hname_Hstar || t == lex_nested_Hname_Hstar) {
-
 
1597
		return(1);
-
 
1598
	}
1578
    if ( t == lex_and_H1 ) return ( ref ) ;
1599
	if (t == lex_and_H1) {
-
 
1600
		return(ref);
-
 
1601
	}
1579
#else
1602
#else
1580
    UNUSED ( ref ) ;
1603
	UNUSED(ref);
1581
#endif
1604
#endif
1582
    return ( 0 ) ;
1605
	return(0);
1583
}
1606
}
1584
 
1607
 
1585
 
1608
 
1586
/*
1609
/*
1587
    LOOK-AHEAD FOR OPERATOR NAMES
1610
    LOOK-AHEAD FOR OPERATOR NAMES
1588
 
1611
 
1589
    A look-ahead is needed in the token syntax for overloaded operator
1612
    A look-ahead is needed in the token syntax for overloaded operator
1590
    and conversion function names.
1613
    and conversion function names.
1591
*/
1614
*/
1592
 
1615
 
-
 
1616
int
1593
int predict_operator
1617
predict_operator(void)
1594
    PROTO_Z ()
-
 
1595
{
1618
{
1596
#if LANGUAGE_CPP
1619
#if LANGUAGE_CPP
1597
    int t = crt_lex_token ;
1620
	int t = crt_lex_token;
1598
    if ( t == lex_operator ) return ( 1 ) ;
1621
	if (t == lex_operator) {
-
 
1622
		return(1);
-
 
1623
	}
1599
#endif
1624
#endif
1600
    return ( 0 ) ;
1625
	return(0);
1601
}
1626
}
1602
 
1627
 
1603
 
1628
 
1604
/*
1629
/*
1605
    LOOK-AHEAD FOR ARRAY OPERATORS
1630
    LOOK-AHEAD FOR ARRAY OPERATORS
Line 1608... Line 1633...
1608
    'operator delete'.  A following '[' might be the start of an array index,
1633
    'operator delete'.  A following '[' might be the start of an array index,
1609
    or it may introduce 'operator new []' or 'operator delete []'.  This
1634
    or it may introduce 'operator new []' or 'operator delete []'.  This
1610
    routine returns true in the latter case.
1635
    routine returns true in the latter case.
1611
*/
1636
*/
1612
 
1637
 
1613
int predict_array
1638
int
1614
    PROTO_Z ()
1639
predict_array(void)
1615
{
1640
{
1616
    PPTOKEN *p ;
1641
	PPTOKEN *p;
1617
    NAMESPACE np ;
1642
	NAMESPACE np;
1618
    int t = crt_lex_token ;
1643
	int t = crt_lex_token;
1619
    if ( t != lex_open_Hsquare_H1 ) return ( 0 ) ;
1644
	if (t != lex_open_Hsquare_H1) {
-
 
1645
		return(0);
-
 
1646
	}
1620
    p = crt_token ;
1647
	p = crt_token;
1621
    np = crt_lookup ;
1648
	np = crt_lookup;
1622
    t = next_token () ;
1649
	t = next_token();
1623
    crt_lookup = np ;
1650
	crt_lookup = np;
1624
    crt_token = p ;
1651
	crt_token = p;
1625
    if ( t != lex_close_Hsquare_H1 ) return ( 0 ) ;
1652
	if (t != lex_close_Hsquare_H1) {
-
 
1653
		return(0);
-
 
1654
	}
1626
    return ( 1 ) ;
1655
	return(1);
1627
}
1656
}
1628
 
1657
 
1629
 
1658
 
1630
/*
1659
/*
1631
    LOOK-AHEAD FOR TEMPLATE PARAMETERS
1660
    LOOK-AHEAD FOR TEMPLATE PARAMETERS
1632
 
1661
 
1633
    A look-ahead is required to distinguish type template parameters from
1662
    A look-ahead is required to distinguish type template parameters from
1634
    non-type template parameters.
1663
    non-type template parameters.
1635
*/
1664
*/
1636
 
1665
 
-
 
1666
int
1637
int predict_template
1667
predict_template(void)
1638
    PROTO_Z ()
-
 
1639
{
1668
{
1640
    int d = 0 ;
1669
	int d = 0;
1641
    int t = crt_lex_token ;
1670
	int t = crt_lex_token;
1642
    if ( t == lex_class || t == lex_typename ) {
1671
	if (t == lex_class || t == lex_typename) {
1643
	int have_id = 0 ;
1672
		int have_id = 0;
1644
	PPTOKEN *p = crt_token ;
1673
		PPTOKEN *p = crt_token;
1645
	int s = next_token () ;
1674
		int s = next_token();
1646
	switch ( s ) {
1675
		switch (s) {
1647
	    case lex_identifier :
1676
		case lex_identifier:
1648
	    case lex_type_Hname :
1677
		case lex_type_Hname:
1649
	    case lex_namespace_Hname :
1678
		case lex_namespace_Hname:
1650
	    case lex_statement_Hname : {
1679
		case lex_statement_Hname:
1651
		s = next_token () ;
1680
			s = next_token();
1652
		have_id = 1 ;
1681
			have_id = 1;
1653
		break ;
1682
			break;
1654
	    }
-
 
1655
	}
1683
		}
1656
	if ( s == lex_comma || s == lex_close_Htemplate ) {
1684
		if (s == lex_comma || s == lex_close_Htemplate) {
1657
	    d = 1 ;
1685
			d = 1;
1658
	} else if ( s == lex_assign ) {
1686
		} else if (s == lex_assign) {
1659
	    if ( have_id ) {
1687
			if (have_id) {
1660
		s = next_token () ;
1688
				s = next_token();
1661
		crt_lex_token = s ;
1689
				crt_lex_token = s;
1662
		d = predict_typeid ( 2 ) ;
1690
				d = predict_typeid(2);
1663
	    } else {
1691
			} else {
1664
		d = 1 ;
1692
				d = 1;
-
 
1693
			}
-
 
1694
		}
-
 
1695
		crt_lex_token = t;
-
 
1696
		crt_token = p;
-
 
1697
	} else if (t == lex_template) {
1665
	    }
1698
		d = 1;
1666
	}
1699
	}
1667
	crt_lex_token = t ;
-
 
1668
	crt_token = p ;
-
 
1669
    } else if ( t == lex_template ) {
-
 
1670
	d = 1 ;
-
 
1671
    }
-
 
1672
    return ( d ) ;
1700
	return(d);
1673
}
1701
}