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

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/construct/basetype.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-2006 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
32
    		 Crown Copyright (c) 1997
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 53... Line 83...
53
#include "preproc.h"
83
#include "preproc.h"
54
#include "redeclare.h"
84
#include "redeclare.h"
55
#include "syntax.h"
85
#include "syntax.h"
56
#include "template.h"
86
#include "template.h"
57
#include "token.h"
87
#include "token.h"
58
 
88
 
59
 
89
 
60
/*
90
/*
61
    CREATE A QUALIFIED TYPE
91
    CREATE A QUALIFIED TYPE
62
 
92
 
63
    This routine creates a type consisting of t qualified by the const-
93
    This routine creates a type consisting of t qualified by the const-
64
    volatile qualifiers cv.  Note that the existing qualifiers for t are
94
    volatile qualifiers cv.  Note that the existing qualifiers for t are
65
    not taken into account in the result.  If t already has qualifier cv
95
    not taken into account in the result.  If t already has qualifier cv
66
    and force is false then t itself is returned, otherwise a copy of t
96
    and force is false then t itself is returned, otherwise a copy of t
67
    with the appropriate qualifier is constructed.
97
    with the appropriate qualifier is constructed.
258
}
290
}
259
 
291
 
260
 
292
 
261
/*
293
/*
262
    COPY A TYPEDEF TYPE
294
    COPY A TYPEDEF TYPE
Line 270... Line 302...
270
		const array var ;
302
		const array var ;
271
 
303
 
272
    the type of var is 'const int [3]'.  Also any qualifiers applied to
304
    the type of var is 'const int [3]'.  Also any qualifiers applied to
273
    reference and function types are ignored.
305
    reference and function types are ignored.
274
*/
306
*/
275
 
307
 
276
TYPE copy_typedef
308
TYPE
277
    PROTO_N ( ( id, t, cv ) )
-
 
278
    PROTO_T ( IDENTIFIER id X TYPE t X CV_SPEC cv )
309
copy_typedef(IDENTIFIER id, TYPE t, CV_SPEC cv)
279
{
310
{
280
    CV_SPEC qual = DEREF_cv ( type_qual ( t ) ) ;
311
	CV_SPEC qual = DEREF_cv(type_qual(t));
281
    CV_SPEC qual_new = ( qual | cv ) ;
312
	CV_SPEC qual_new = (qual | cv);
282
    CV_SPEC qual_join = ( qual & cv ) ;
313
	CV_SPEC qual_join = (qual & cv);
283
    if ( qual_join && !IS_NULL_id ( id ) ) {
314
	if (qual_join && !IS_NULL_id(id)) {
284
	/* Warn about duplicate qualifiers */
315
		/* Warn about duplicate qualifiers */
285
	report ( crt_loc, ERR_dcl_type_type_cv ( id, qual_join ) ) ;
316
		report(crt_loc, ERR_dcl_type_type_cv(id, qual_join));
286
    }
317
	}
287
 
318
 
288
    /* Check types */
319
	/* Check types */
289
    switch ( TAG_type ( t ) ) {
320
	switch (TAG_type(t)) {
290
 
-
 
291
	case type_ptr_tag : {
321
	case type_ptr_tag: {
292
	    /* Copy pointer types */
322
		/* Copy pointer types */
293
	    TYPE s = DEREF_type ( type_ptr_sub ( t ) ) ;
323
		TYPE s = DEREF_type(type_ptr_sub(t));
294
	    TYPE r = copy_typedef ( id, s, cv_none ) ;
324
		TYPE r = copy_typedef(id, s, cv_none);
295
	    if ( !EQ_type ( r, s ) || qual_new != qual ) {
325
		if (!EQ_type(r, s) || qual_new != qual) {
296
		IDENTIFIER tid = DEREF_id ( type_name ( t ) ) ;
326
			IDENTIFIER tid = DEREF_id(type_name(t));
297
		MAKE_type_ptr ( qual_new, r, t ) ;
327
			MAKE_type_ptr(qual_new, r, t);
298
		COPY_id ( type_name ( t ), tid ) ;
328
			COPY_id(type_name(t), tid);
299
	    }
-
 
300
	    break ;
-
 
301
	}
329
		}
302
 
-
 
303
	case type_ref_tag : {
-
 
304
	    /* Ignore qualifiers for references */
-
 
305
	    TYPE s, r ;
-
 
306
	    if ( cv && !IS_NULL_id ( id ) ) {
-
 
307
		report ( crt_loc, ERR_dcl_ref_cv_type ( cv, id ) ) ;
-
 
308
	    }
-
 
309
	    s = DEREF_type ( type_ref_sub ( t ) ) ;
-
 
310
	    r = copy_typedef ( id, s, cv_none ) ;
-
 
311
	    if ( !EQ_type ( r, s ) ) {
-
 
312
		IDENTIFIER tid = DEREF_id ( type_name ( t ) ) ;
-
 
313
		MAKE_type_ref ( qual, r, t ) ;
-
 
314
		COPY_id ( type_name ( t ), tid ) ;
-
 
315
	    }
-
 
316
	    break ;
330
		break;
317
	}
331
	}
-
 
332
	case type_ref_tag: {
-
 
333
		/* Ignore qualifiers for references */
-
 
334
		TYPE s, r;
-
 
335
		if (cv && !IS_NULL_id(id)) {
-
 
336
			report(crt_loc, ERR_dcl_ref_cv_type(cv, id));
-
 
337
		}
-
 
338
		s = DEREF_type(type_ref_sub(t));
-
 
339
		r = copy_typedef(id, s, cv_none);
-
 
340
		if (!EQ_type(r, s)) {
-
 
341
			IDENTIFIER tid = DEREF_id(type_name(t));
-
 
342
			MAKE_type_ref(qual, r, t);
-
 
343
			COPY_id(type_name(t), tid);
-
 
344
		}
-
 
345
		break;
318
 
346
	}
319
#if LANGUAGE_CPP
347
#if LANGUAGE_CPP
320
	case type_ptr_mem_tag : {
348
	case type_ptr_mem_tag: {
321
	    /* Copy pointer member types */
349
		/* Copy pointer member types */
322
	    TYPE s = DEREF_type ( type_ptr_mem_sub ( t ) ) ;
350
		TYPE s = DEREF_type(type_ptr_mem_sub(t));
323
	    TYPE r = copy_typedef ( id, s, cv_none ) ;
351
		TYPE r = copy_typedef(id, s, cv_none);
324
	    if ( !EQ_type ( r, s ) || qual_new != qual ) {
352
		if (!EQ_type(r, s) || qual_new != qual) {
325
		IDENTIFIER tid = DEREF_id ( type_name ( t ) ) ;
353
			IDENTIFIER tid = DEREF_id(type_name(t));
326
		CLASS_TYPE of = DEREF_ctype ( type_ptr_mem_of ( t ) ) ;
354
			CLASS_TYPE of = DEREF_ctype(type_ptr_mem_of(t));
327
		MAKE_type_ptr_mem ( qual_new, of, r, t ) ;
355
			MAKE_type_ptr_mem(qual_new, of, r, t);
328
		COPY_id ( type_name ( t ), tid ) ;
356
			COPY_id(type_name(t), tid);
329
	    }
357
		}
330
	    break ;
358
		break;
331
	}
359
	}
332
#endif
360
#endif
-
 
361
	case type_func_tag: {
-
 
362
		/* Ignore qualifiers for functions */
-
 
363
		int ell;
-
 
364
		TYPE ret;
-
 
365
		CV_SPEC mqual;
-
 
366
		IDENTIFIER tid;
-
 
367
		NAMESPACE pars;
-
 
368
		LIST(TYPE)except;
-
 
369
		LIST(TYPE)ptypes;
-
 
370
		LIST(TYPE)mtypes;
-
 
371
		LIST(IDENTIFIER)pids;
-
 
372
		LIST(TYPE)mtypes_new;
-
 
373
		LIST(TYPE)ptypes_new = NULL_list(TYPE);
-
 
374
		LIST(IDENTIFIER)pids_new = NULL_list(IDENTIFIER);
333
 
375
 
334
	case type_func_tag : {
-
 
335
	    /* Ignore qualifiers for functions */
-
 
336
	    int ell ;
-
 
337
	    TYPE ret ;
-
 
338
	    CV_SPEC mqual ;
-
 
339
	    IDENTIFIER tid ;
-
 
340
	    NAMESPACE pars ;
-
 
341
	    LIST ( TYPE ) except ;
-
 
342
	    LIST ( TYPE ) ptypes ;
-
 
343
	    LIST ( TYPE ) mtypes ;
-
 
344
	    LIST ( IDENTIFIER ) pids ;
-
 
345
	    LIST ( TYPE ) mtypes_new ;
-
 
346
	    LIST ( TYPE ) ptypes_new = NULL_list ( TYPE ) ;
-
 
347
	    LIST ( IDENTIFIER ) pids_new = NULL_list ( IDENTIFIER ) ;
-
 
348
 
-
 
349
	    /* Warn about qualifiers */
376
		/* Warn about qualifiers */
350
	    if ( cv && !IS_NULL_id ( id ) ) {
377
		if (cv && !IS_NULL_id(id)) {
351
		report ( crt_loc, ERR_dcl_fct_qual ( cv, id ) ) ;
378
			report(crt_loc, ERR_dcl_fct_qual(cv, id));
352
	    }
379
		}
353
 
380
 
354
	    /* Decompose old function type */
381
		/* Decompose old function type */
355
	    DECONS_type_func ( qual, tid, ret, ptypes, ell, mqual,
382
		DECONS_type_func(qual, tid, ret, ptypes, ell, mqual,
356
			       mtypes, pars, pids, except, t ) ;
383
				 mtypes, pars, pids, except, t);
357
 
384
 
358
	    /* Copy appropriate components */
385
		/* Copy appropriate components */
359
	    ret = copy_typedef ( id, ret, cv_none ) ;
386
		ret = copy_typedef(id, ret, cv_none);
360
	    while ( !IS_NULL_list ( pids ) ) {
387
		while (!IS_NULL_list(pids)) {
361
		/* Redeclare each parameter */
388
			/* Redeclare each parameter */
362
		TYPE s ;
389
			TYPE s;
363
		IDENTIFIER pid = DEREF_id ( HEAD_list ( pids ) ) ;
390
			IDENTIFIER pid = DEREF_id(HEAD_list(pids));
364
		pid = copy_id ( pid, 1 ) ;
391
			pid = copy_id(pid, 1);
365
		CONS_id ( pid, pids_new, pids_new ) ;
392
			CONS_id(pid, pids_new, pids_new);
366
		s = DEREF_type ( id_parameter_type ( pid ) ) ;
393
			s = DEREF_type(id_parameter_type(pid));
367
		s = qualify_type ( s, cv_none, 0 ) ;
394
			s = qualify_type(s, cv_none, 0);
368
		CONS_type ( s, ptypes_new, ptypes_new ) ;
395
			CONS_type(s, ptypes_new, ptypes_new);
369
		pids = TAIL_list ( pids ) ;
396
			pids = TAIL_list(pids);
370
	    }
397
		}
371
	    pids_new = REVERSE_list ( pids_new ) ;
398
		pids_new = REVERSE_list(pids_new);
372
	    ptypes_new = REVERSE_list ( ptypes_new ) ;
399
		ptypes_new = REVERSE_list(ptypes_new);
373
	    if ( EQ_list ( ptypes, mtypes ) ) {
400
		if (EQ_list(ptypes, mtypes)) {
374
		mtypes_new = ptypes_new ;
401
			mtypes_new = ptypes_new;
375
	    } else {
402
		} else {
376
		TYPE r = DEREF_type ( HEAD_list ( mtypes ) ) ;
403
			TYPE r = DEREF_type(HEAD_list(mtypes));
377
		CONS_type ( r, ptypes_new, mtypes_new ) ;
404
			CONS_type(r, ptypes_new, mtypes_new);
378
	    }
-
 
379
 
-
 
380
	    /* Construct new function type */
-
 
381
	    MAKE_type_func ( qual, ret, ptypes_new, ell, mqual,
-
 
382
			     mtypes_new, pars, pids_new, except, t ) ;
-
 
383
	    COPY_id ( type_name ( t ), tid ) ;
-
 
384
	    break ;
-
 
385
	}
-
 
386
 
-
 
387
	case type_array_tag : {
-
 
388
	    /* Qualify the base type of an array */
-
 
389
	    NAT n = DEREF_nat ( type_array_size ( t ) ) ;
-
 
390
	    TYPE s = DEREF_type ( type_array_sub ( t ) ) ;
-
 
391
	    TYPE r = copy_typedef ( id, s, cv ) ;
-
 
392
	    IDENTIFIER tid = DEREF_id ( type_name ( t ) ) ;
-
 
393
	    MAKE_type_array ( qual, r, n, t ) ;
-
 
394
	    COPY_id ( type_name ( t ), tid ) ;
-
 
395
	    break ;
-
 
396
	}
-
 
397
 
-
 
398
	case type_token_tag : {
-
 
399
	    /* Tokenised types */
-
 
400
	    IDENTIFIER tok = DEREF_id ( type_token_tok ( t ) ) ;
-
 
401
	    DECL_SPEC ds = DEREF_dspec ( id_storage ( tok ) ) ;
-
 
402
	    if ( !( ds & dspec_defn ) ) goto default_lab ;
-
 
403
	    t = expand_type ( t, 0 ) ;
-
 
404
	    t = qualify_type ( t, qual_new, 0 ) ;
-
 
405
	    break ;
-
 
406
	}
405
		}
407
 
406
 
408
	case type_templ_tag : {
-
 
409
	    /* Template types */
407
		/* Construct new function type */
410
	    TYPE s = DEREF_type ( type_templ_defn ( t ) ) ;
408
		MAKE_type_func(qual, ret, ptypes_new, ell, mqual,
411
	    TOKEN tok = DEREF_tok ( type_templ_sort ( t ) ) ;
-
 
412
	    IDENTIFIER tid = DEREF_id ( type_name ( t ) ) ;
-
 
413
	    MAKE_type_templ ( qual_new, tok, s, 1, t ) ;
409
			       mtypes_new, pars, pids_new, except, t);
414
	    COPY_id ( type_name ( t ), tid ) ;
410
		COPY_id(type_name(t), tid);
415
	    break ;
411
		break;
416
	}
412
	}
-
 
413
	case type_array_tag: {
-
 
414
		/* Qualify the base type of an array */
-
 
415
		NAT n = DEREF_nat(type_array_size(t));
-
 
416
		TYPE s = DEREF_type(type_array_sub(t));
-
 
417
		TYPE r = copy_typedef(id, s, cv);
-
 
418
		IDENTIFIER tid = DEREF_id(type_name(t));
-
 
419
		MAKE_type_array(qual, r, n, t);
-
 
420
		COPY_id(type_name(t), tid);
-
 
421
		break;
417
 
422
	}
-
 
423
	case type_token_tag: {
-
 
424
		/* Tokenised types */
-
 
425
		IDENTIFIER tok = DEREF_id(type_token_tok(t));
-
 
426
		DECL_SPEC ds = DEREF_dspec(id_storage(tok));
-
 
427
		if (!(ds & dspec_defn))goto default_lab;
-
 
428
		t = expand_type(t, 0);
-
 
429
		t = qualify_type(t, qual_new, 0);
-
 
430
		break;
-
 
431
	}
-
 
432
	case type_templ_tag: {
-
 
433
		/* Template types */
-
 
434
		TYPE s = DEREF_type(type_templ_defn(t));
-
 
435
		TOKEN tok = DEREF_tok(type_templ_sort(t));
-
 
436
		IDENTIFIER tid = DEREF_id(type_name(t));
-
 
437
		MAKE_type_templ(qual_new, tok, s, 1, t);
-
 
438
		COPY_id(type_name(t), tid);
-
 
439
		break;
-
 
440
	}
418
	default :
441
	default:
419
	default_lab : {
442
default_lab:
420
	    /* Other types */
443
		/* Other types */
421
	    if ( qual_new != qual ) {
444
		if (qual_new != qual) {
422
		t = qualify_type ( t, qual_new, 0 ) ;
445
			t = qualify_type(t, qual_new, 0);
423
	    }
446
		}
424
	    break ;
447
		break;
425
	}
448
	}
426
    }
-
 
427
    return ( t ) ;
449
	return (t);
428
}
450
}
429
 
451
 
430
 
452
 
431
/*
453
/*
432
    CREATE AN LVALUE TYPE
454
    CREATE AN LVALUE TYPE
433
 
455
 
434
    This routine creates a type which is an lvalue qualified version of t
456
    This routine creates a type which is an lvalue qualified version of t
435
    (also preserving any other type qualifiers).
457
    (also preserving any other type qualifiers).
436
*/
458
*/
437
 
459
 
438
TYPE lvalue_type
460
TYPE
439
    PROTO_N ( ( t ) )
-
 
440
    PROTO_T ( TYPE t )
461
lvalue_type(TYPE t)
441
{
462
{
442
    CV_SPEC qual = DEREF_cv ( type_qual ( t ) ) ;
463
	CV_SPEC qual = DEREF_cv(type_qual(t));
443
    if ( qual & cv_lvalue ) return ( t ) ;
464
	if (qual & cv_lvalue) {
-
 
465
		return (t);
-
 
466
	}
444
    qual |= cv_lvalue ;
467
	qual |= cv_lvalue;
445
    return ( qualify_type ( t, qual, 0 ) ) ;
468
	return (qualify_type(t, qual, 0));
446
}
469
}
447
 
470
 
448
 
471
 
449
/*
472
/*
450
    CREATE AN RVALUE TYPE
473
    CREATE AN RVALUE TYPE
451
 
474
 
452
    This routine creates a type which is identical to t except that it
475
    This routine creates a type which is identical to t except that it
453
    is an rvalue rather than an lvalue.
476
    is an rvalue rather than an lvalue.
454
*/
477
*/
455
 
478
 
456
TYPE rvalue_type
479
TYPE
457
    PROTO_N ( ( t ) )
-
 
458
    PROTO_T ( TYPE t )
480
rvalue_type(TYPE t)
459
{
481
{
460
    CV_SPEC qual = DEREF_cv ( type_qual ( t ) ) ;
482
	CV_SPEC qual = DEREF_cv(type_qual(t));
461
    if ( !( qual & cv_lvalue ) ) return ( t ) ;
483
	if (!(qual & cv_lvalue)) {
-
 
484
		return (t);
-
 
485
	}
462
    qual &= ~cv_lvalue ;
486
	qual &= ~cv_lvalue;
463
    return ( qualify_type ( t, qual, 0 ) ) ;
487
	return (qualify_type(t, qual, 0));
464
}
488
}
465
 
489
 
466
 
490
 
467
/*
491
/*
468
    COMBINE TWO PRE-TYPES
492
    COMBINE TWO PRE-TYPES
469
 
493
 
470
    The pre-types are a construction mechanism for allowing built-in types
494
    The pre-types are a construction mechanism for allowing built-in types
471
    such as 'unsigned long int' to be built up.  Each pre-type is associated
495
    such as 'unsigned long int' to be built up.  Each pre-type is associated
472
    with a bitmask giving the basic keywords used in defining the type.
496
    with a bitmask giving the basic keywords used in defining the type.
473
    This routine is the main constructor function, which combines two
497
    This routine is the main constructor function, which combines two
474
    pre-types and returns the result.
498
    pre-types and returns the result.
475
*/
499
*/
476
 
500
 
477
BASE_TYPE join_pre_types
501
BASE_TYPE
478
    PROTO_N ( ( b1, b2 ) )
-
 
479
    PROTO_T ( BASE_TYPE b1 X BASE_TYPE b2 )
502
join_pre_types(BASE_TYPE b1, BASE_TYPE b2)
480
{
503
{
481
    BASE_TYPE bt = ( b1 | b2 ) ;
504
	BASE_TYPE bt = (b1 | b2);
482
    BASE_TYPE bs = ( b1 & b2 ) ;
505
	BASE_TYPE bs = (b1 & b2);
483
    if ( bs ) {
506
	if (bs) {
484
	if ( bs == btype_long ) {
507
		if (bs == btype_long) {
485
	    if ( !( bt & btype_long2 ) ) {
508
			if (!(bt & btype_long2)) {
486
		/* Allow 'long long' */
509
				/* Allow 'long long' */
487
		bt |= btype_long2 ;
510
				bt |= btype_long2;
488
		return ( bt ) ;
511
				return (bt);
489
	    }
512
			}
-
 
513
		}
-
 
514
		report(crt_loc, ERR_dcl_type_simple_dup(bs));
490
	}
515
	}
491
	report ( crt_loc, ERR_dcl_type_simple_dup ( bs ) ) ;
-
 
492
    }
-
 
493
    return ( bt ) ;
516
	return (bt);
494
}
517
}
495
 
518
 
496
 
519
 
497
/*
520
/*
498
    INJECT A TYPE INTO A PRE-TYPE
521
    INJECT A TYPE INTO A PRE-TYPE
499
 
522
 
500
    This routine injects the type t into the pre-type p, returning the
523
    This routine injects the type t into the pre-type p, returning the
501
    result.  p will be built up of pointers, arrays etc. but its base
524
    result.  p will be built up of pointers, arrays etc. but its base
Line 503... Line 526...
503
    It also checks for illegal type constructions.  Note that p itself
526
    It also checks for illegal type constructions.  Note that p itself
504
    is built up using inject_pre_type, so all such illegal constructions
527
    is built up using inject_pre_type, so all such illegal constructions
505
    will be detected.  Some of the error recovery for such constructions
528
    will be detected.  Some of the error recovery for such constructions
506
    is mildly interesting.  Also note that bitfields are handled by a
529
    is mildly interesting.  Also note that bitfields are handled by a
507
    separate routine, make_bitfield_type.
530
    separate routine, make_bitfield_type.
782
 
837
 
783
	    default : {
838
		default: {
784
		/* Only the types above should appear */
839
			/* Only the types above should appear */
785
		q = NULL_type ;
840
			q = NULL_type;
786
		n-- ;
841
			n--;
787
		break ;
842
			break;
-
 
843
		}
788
	    }
844
		}
-
 
845
		n++;
-
 
846
	} while (!IS_NULL_type(q));
-
 
847
	if (chk) {
-
 
848
		IGNORE check_value(OPT_VAL_declarator_max, n);
789
	}
849
	}
790
	n++ ;
-
 
791
    } while ( !IS_NULL_type ( q ) ) ;
-
 
792
    if ( chk ) IGNORE check_value ( OPT_VAL_declarator_max, n ) ;
-
 
793
    return ( p ) ;
850
	return (p);
794
}
851
}
795
 
852
 
796
 
853
 
797
/*
854
/*
798
    CHECK FOR INFERRED TYPES
855
    CHECK FOR INFERRED TYPES
799
 
856
 
800
    This routine checks whether the type t is formed from the inferred
857
    This routine checks whether the type t is formed from the inferred
801
    type type_inferred.  It returns INFERRED_EMPTY if there were no
858
    type type_inferred.  It returns INFERRED_EMPTY if there were no
802
    specifiers or qualifiers in the description of p,  INFERRED_QUAL if
859
    specifiers or qualifiers in the description of p,  INFERRED_QUAL if
803
    the only type specifiers were const or volatile, INFERRED_SPEC for
860
    the only type specifiers were const or volatile, INFERRED_SPEC for
804
    other inferred types, and INFERRED_NOT for non-inferred types.
861
    other inferred types, and INFERRED_NOT for non-inferred types.
805
*/
862
*/
806
 
863
 
-
 
864
int
807
int is_type_inferred
865
is_type_inferred(TYPE t)
-
 
866
{
-
 
867
	if (EQ_type(t, type_inferred)) {
-
 
868
		return (INFERRED_EMPTY);
-
 
869
	}
-
 
870
	while (!IS_NULL_type(t)) {
-
 
871
		switch (TAG_type(t)) {
-
 
872
		case type_integer_tag: {
-
 
873
			/* Check integer types */
-
 
874
			if (EQ_type(t, type_inferred)) {
-
 
875
				return (INFERRED_SPEC);
-
 
876
			} else {
-
 
877
				INT_TYPE it = DEREF_itype(type_integer_rep(t));
-
 
878
				t = DEREF_type(itype_prom(it));
-
 
879
				if (EQ_type(t, type_inferred)) {
-
 
880
					/* Qualified inferred type */
-
 
881
					return (INFERRED_QUAL);
-
 
882
				}
-
 
883
			}
-
 
884
			return (INFERRED_NOT);
-
 
885
		}
-
 
886
		case type_ptr_tag:
-
 
887
		case type_ref_tag: {
-
 
888
			/* Check pointer and reference types */
-
 
889
			t = DEREF_type(type_ptr_etc_sub(t));
-
 
890
			break;
-
 
891
		}
-
 
892
#if LANGUAGE_CPP
-
 
893
		case type_ptr_mem_tag: {
-
 
894
			/* Check pointer to member types */
-
 
895
			t = DEREF_type(type_ptr_mem_sub(t));
-
 
896
			break;
-
 
897
		}
-
 
898
#endif
-
 
899
		case type_func_tag: {
-
 
900
			/* Check function return types only */
-
 
901
			t = DEREF_type(type_func_ret(t));
-
 
902
			break;
-
 
903
		}
-
 
904
		case type_array_tag: {
-
 
905
			/* Check array types */
-
 
906
			t = DEREF_type(type_array_sub(t));
-
 
907
			break;
-
 
908
		}
-
 
909
		case type_bitfield_tag: {
-
 
910
			/* Check bitfield types */
-
 
911
			t = find_bitfield_type(t);
-
 
912
			break;
-
 
913
		}
-
 
914
		case type_templ_tag: {
-
 
915
			/* Check template types */
-
 
916
			t = DEREF_type(type_templ_defn(t));
-
 
917
			break;
-
 
918
		}
-
 
919
		default : {
-
 
920
			/* Other types are not inferred */
-
 
921
			return (INFERRED_NOT);
-
 
922
		}
-
 
923
		}
-
 
924
	}
-
 
925
	return (INFERRED_QUAL);
-
 
926
}
-
 
927
 
-
 
928
 
-
 
929
/*
808
    PROTO_N ( ( t ) )
930
    CLEAN AN INFERRED TYPE
-
 
931
 
-
 
932
    This routine returns an equivalent type to the inferred type t, but
-
 
933
    with any inferred components replaced by 'signed int'.
-
 
934
*/
-
 
935
 
-
 
936
TYPE
809
    PROTO_T ( TYPE t )
937
clean_inferred_type(TYPE t)
810
{
938
{
-
 
939
	TYPE sub;
811
    if ( EQ_type ( t, type_inferred ) ) return ( INFERRED_EMPTY ) ;
940
	CV_SPEC qual;
812
    while ( !IS_NULL_type ( t ) ) {
941
	IDENTIFIER tid;
813
	switch ( TAG_type ( t ) ) {
942
	switch (TAG_type(t)) {
814
	    case type_integer_tag : {
943
	case type_integer_tag: {
815
		/* Check integer types */
944
		if (EQ_type(t, type_inferred)) {
816
		if ( EQ_type ( t, type_inferred ) ) {
945
			/* Simple inferred type */
817
		    return ( INFERRED_SPEC ) ;
946
			t = type_sint;
818
		} else {
947
		} else {
819
		    INT_TYPE it = DEREF_itype ( type_integer_rep ( t ) ) ;
948
			INT_TYPE it = DEREF_itype(type_integer_rep(t));
820
		    t = DEREF_type ( itype_prom ( it ) ) ;
949
			TYPE pt = DEREF_type(itype_prom(it));
821
		    if ( EQ_type ( t, type_inferred ) ) {
950
			if (EQ_type(pt, type_inferred)) {
822
			/* Qualified inferred type */
951
				/* Qualified inferred type */
823
			return ( INFERRED_QUAL ) ;
952
				qual = DEREF_cv(type_qual(t));
-
 
953
				t = qualify_type(type_sint, qual, 0);
824
		    }
954
			}
825
		}
955
		}
826
		return ( INFERRED_NOT ) ;
956
		break;
827
	    }
957
	}
828
	    case type_ptr_tag :
958
	case type_ptr_tag: {
-
 
959
		DECONS_type_ptr(qual, tid, sub, t);
-
 
960
		sub = clean_inferred_type(sub);
-
 
961
		MAKE_type_ptr(qual, sub, t);
-
 
962
		COPY_id(type_name(t), tid);
-
 
963
		break;
-
 
964
	}
829
	    case type_ref_tag : {
965
	case type_ref_tag: {
-
 
966
		DECONS_type_ref(qual, tid, sub, t);
830
		/* Check pointer and reference types */
967
		sub = clean_inferred_type(sub);
831
		t = DEREF_type ( type_ptr_etc_sub ( t ) ) ;
968
		MAKE_type_ref(qual, sub, t);
-
 
969
		COPY_id(type_name(t), tid);
832
		break ;
970
		break;
833
	    }
971
	}
834
#if LANGUAGE_CPP
972
#if LANGUAGE_CPP
835
	    case type_ptr_mem_tag : {
973
	case type_ptr_mem_tag: {
836
		/* Check pointer to member types */
-
 
837
		t = DEREF_type ( type_ptr_mem_sub ( t ) ) ;
-
 
838
		break ;
-
 
839
	    }
-
 
840
#endif
-
 
841
	    case type_func_tag : {
-
 
842
		/* Check function return types only */
-
 
843
		t = DEREF_type ( type_func_ret ( t ) ) ;
-
 
844
		break ;
974
		CLASS_TYPE of;
845
	    }
-
 
846
	    case type_array_tag : {
-
 
847
		/* Check array types */
-
 
848
		t = DEREF_type ( type_array_sub ( t ) ) ;
975
		DECONS_type_ptr_mem(qual, tid, of, sub, t);
849
		break ;
-
 
850
	    }
-
 
851
	    case type_bitfield_tag : {
-
 
852
		/* Check bitfield types */
-
 
853
		t = find_bitfield_type ( t ) ;
976
		sub = clean_inferred_type(sub);
854
		break ;
-
 
855
	    }
-
 
856
	    case type_templ_tag : {
-
 
857
		/* Check template types */
977
		MAKE_type_ptr_mem(qual, of, sub, t);
858
		t = DEREF_type ( type_templ_defn ( t ) ) ;
978
		COPY_id(type_name(t), tid);
859
		break ;
979
		break;
860
	    }
-
 
861
	    default : {
-
 
862
		/* Other types are not inferred */
-
 
863
		return ( INFERRED_NOT ) ;
-
 
864
	    }
-
 
865
	}
980
	}
866
    }
981
#endif
867
    return ( INFERRED_QUAL ) ;
-
 
868
}
-
 
869
 
-
 
870
 
-
 
871
/*
-
 
872
    CLEAN AN INFERRED TYPE
-
 
873
 
-
 
874
    This routine returns an equivalent type to the inferred type t, but
-
 
875
    with any inferred components replaced by 'signed int'.
-
 
876
*/
-
 
877
 
-
 
878
TYPE clean_inferred_type
-
 
879
    PROTO_N ( ( t ) )
982
	case type_func_tag: {
880
    PROTO_T ( TYPE t )
-
 
881
{
-
 
882
    TYPE sub ;
983
		int ell;
883
    CV_SPEC qual ;
984
		CV_SPEC mqual;
884
    IDENTIFIER tid ;
985
		NAMESPACE pars;
885
    switch ( TAG_type ( t ) ) {
-
 
886
	case type_integer_tag : {
986
		LIST(TYPE)ptypes;
887
	    if ( EQ_type ( t, type_inferred ) ) {
-
 
888
		/* Simple inferred type */
987
		LIST(TYPE)mtypes;
889
		t = type_sint ;
988
		LIST(TYPE)except;
890
	    } else {
989
		LIST(IDENTIFIER)pids;
891
		INT_TYPE it = DEREF_itype ( type_integer_rep ( t ) ) ;
990
		DECONS_type_func(qual, tid, sub, ptypes, ell, mqual,
892
		TYPE pt = DEREF_type ( itype_prom ( it ) ) ;
-
 
893
		if ( EQ_type ( pt, type_inferred ) ) {
991
				 mtypes, pars, pids, except, t);
894
		    /* Qualified inferred type */
992
		sub = clean_inferred_type(sub);
895
		    qual = DEREF_cv ( type_qual ( t ) ) ;
-
 
896
		    t = qualify_type ( type_sint, qual, 0 ) ;
-
 
897
		}
-
 
898
	    }
-
 
899
	    break ;
-
 
900
	}
-
 
901
	case type_ptr_tag : {
-
 
902
	    DECONS_type_ptr ( qual, tid, sub, t ) ;
993
		MAKE_type_func(qual, sub, ptypes, ell, mqual,
903
	    sub = clean_inferred_type ( sub ) ;
-
 
904
	    MAKE_type_ptr ( qual, sub, t ) ;
994
			       mtypes, pars, pids, except, t);
905
	    COPY_id ( type_name ( t ), tid ) ;
995
		COPY_id(type_name(t), tid);
906
	    break ;
996
		break;
907
	}
997
	}
908
	case type_ref_tag : {
998
	case type_array_tag: {
-
 
999
		NAT size;
909
	    DECONS_type_ref ( qual, tid, sub, t ) ;
1000
		DECONS_type_array(qual, tid, sub, size, t);
910
	    sub = clean_inferred_type ( sub ) ;
1001
		sub = clean_inferred_type(sub);
911
	    MAKE_type_ref ( qual, sub, t ) ;
1002
		MAKE_type_array(qual, sub, size, t);
912
	    COPY_id ( type_name ( t ), tid ) ;
1003
		COPY_id(type_name(t), tid);
913
	    break ;
1004
		break;
914
	}
1005
	}
915
#if LANGUAGE_CPP
-
 
916
	case type_ptr_mem_tag : {
1006
	case type_bitfield_tag: {
917
	    CLASS_TYPE of ;
1007
		INT_TYPE bf;
918
	    DECONS_type_ptr_mem ( qual, tid, of, sub, t ) ;
1008
		DECONS_type_bitfield(qual, tid, bf, t);
919
	    sub = clean_inferred_type ( sub ) ;
1009
		sub = DEREF_type(itype_bitfield_sub(bf));
920
	    MAKE_type_ptr_mem ( qual, of, sub, t ) ;
-
 
921
	    COPY_id ( type_name ( t ), tid ) ;
-
 
922
	    break ;
-
 
923
	}
-
 
924
#endif
-
 
925
	case type_func_tag : {
-
 
926
	    int ell ;
-
 
927
	    CV_SPEC mqual ;
-
 
928
	    NAMESPACE pars ;
-
 
929
	    LIST ( TYPE ) ptypes ;
-
 
930
	    LIST ( TYPE ) mtypes ;
-
 
931
	    LIST ( TYPE ) except ;
-
 
932
	    LIST ( IDENTIFIER ) pids ;
-
 
933
	    DECONS_type_func ( qual, tid, sub, ptypes, ell, mqual,
-
 
934
			       mtypes, pars, pids, except, t ) ;
-
 
935
	    sub = clean_inferred_type ( sub ) ;
1010
		sub = clean_inferred_type(sub);
936
	    MAKE_type_func ( qual, sub, ptypes, ell, mqual,
-
 
937
			     mtypes, pars, pids, except, t ) ;
-
 
938
	    COPY_id ( type_name ( t ), tid ) ;
1011
		COPY_type(itype_bitfield_sub(bf), sub);
939
	    break ;
-
 
940
	}
-
 
941
	case type_array_tag : {
-
 
942
	    NAT size ;
-
 
943
	    DECONS_type_array ( qual, tid, sub, size, t ) ;
-
 
944
	    sub = clean_inferred_type ( sub ) ;
-
 
945
	    MAKE_type_array ( qual, sub, size, t ) ;
1012
		MAKE_type_bitfield(qual, bf, t);
946
	    COPY_id ( type_name ( t ), tid ) ;
1013
		COPY_id(type_name(t), tid);
947
	    break ;
1014
		break;
948
	}
1015
	}
949
	case type_bitfield_tag : {
1016
	case type_templ_tag: {
-
 
1017
		int fix;
950
	    INT_TYPE bf ;
1018
		TOKEN sort;
951
	    DECONS_type_bitfield ( qual, tid, bf, t ) ;
1019
		DECONS_type_templ(qual, tid, sort, sub, fix, t);
952
	    sub = DEREF_type ( itype_bitfield_sub ( bf ) ) ;
-
 
953
	    sub = clean_inferred_type ( sub ) ;
1020
		sub = clean_inferred_type(sub);
954
	    COPY_type ( itype_bitfield_sub ( bf ), sub ) ;
-
 
955
	    MAKE_type_bitfield ( qual, bf, t ) ;
1021
		MAKE_type_templ(qual, sort, sub, fix, t);
956
	    COPY_id ( type_name ( t ), tid ) ;
1022
		COPY_id(type_name(t), tid);
957
	    break ;
1023
		break;
958
	}
1024
	}
959
	case type_templ_tag : {
-
 
960
	    int fix ;
-
 
961
	    TOKEN sort ;
-
 
962
	    DECONS_type_templ ( qual, tid, sort, sub, fix, t ) ;
-
 
963
	    sub = clean_inferred_type ( sub ) ;
-
 
964
	    MAKE_type_templ ( qual, sort, sub, fix, t ) ;
-
 
965
	    COPY_id ( type_name ( t ), tid ) ;
-
 
966
	    break ;
-
 
967
	}
1025
	}
968
    }
-
 
969
    return ( t ) ;
1026
	return (t);
970
}
1027
}
971
 
1028
 
972
 
1029
 
973
/*
1030
/*
974
    REPORT AN INFERRED TYPE
1031
    REPORT AN INFERRED TYPE
975
 
1032
 
976
    This routine returns an error suitable for the inferred type t.
1033
    This routine returns an error suitable for the inferred type t.
977
    infer gives the value of is_type_inferred on t.
1034
    infer gives the value of is_type_inferred on t.
978
*/
1035
*/
979
 
1036
 
980
ERROR report_inferred_type
1037
ERROR
981
    PROTO_N ( ( t, infer ) )
-
 
982
    PROTO_T ( TYPE t X int infer )
1038
report_inferred_type(TYPE t, int infer)
983
{
1039
{
984
    ERROR err = NULL_err ;
1040
	ERROR err = NULL_err;
985
    switch ( infer ) {
1041
	switch (infer) {
986
	case INFERRED_EMPTY :
1042
	case INFERRED_EMPTY:
987
	case INFERRED_SPEC : {
1043
	case INFERRED_SPEC:
988
	    err = ERR_dcl_type_none () ;
1044
		err = ERR_dcl_type_none();
989
	    break ;
1045
		break;
990
	}
-
 
991
	case INFERRED_QUAL : {
1046
	case INFERRED_QUAL:
992
	    err = ERR_dcl_type_qual () ;
1047
		err = ERR_dcl_type_qual();
993
	    break ;
1048
		break;
994
	}
1049
	}
995
    }
-
 
996
    err = concat_error ( err, ERR_dcl_type_infer ( t ) ) ;
1050
	err = concat_error(err, ERR_dcl_type_infer(t));
997
    return ( err ) ;
1051
	return (err);
998
}
1052
}
999
 
1053
 
1000
 
1054
 
1001
/*
1055
/*
1002
    BASE TYPE SHIFT
1056
    BASE TYPE SHIFT
1003
 
1057
 
1004
    This macro is used to shift a base type specifier into a more sensible
1058
    This macro is used to shift a base type specifier into a more sensible
1005
    range for use in a switch statement.
1059
    range for use in a switch statement.
1006
*/
1060
*/
1007
 
1061
 
1008
#define BTYPE( B )		( ( B ) >> 3 )
1062
#define BTYPE(B)	((B) >> 3)
1009
 
1063
 
1010
 
1064
 
1011
/*
1065
/*
1012
    FIND A BASE TYPE
1066
    FIND A BASE TYPE
1013
 
1067
 
1014
    This routine determines the type given by the base type specifiers bt.
1068
    This routine determines the type given by the base type specifiers bt.
1191
		}
1128
		}
-
 
1129
	} else {
1192
	    }
1130
		do {
-
 
1131
			/* Deal with obvious integral cases */
-
 
1132
			switch (BTYPE(bm)) {
-
 
1133
			case BTYPE(btype_char): {
-
 
1134
				bm = btype_char;
-
 
1135
				t = type_char;
-
 
1136
				break;
-
 
1137
			}
-
 
1138
			case BTYPE(btype_signed | btype_char): {
-
 
1139
				bm = btype_schar;
-
 
1140
				t = type_schar;
-
 
1141
				break;
-
 
1142
			}
-
 
1143
			case BTYPE(btype_unsigned | btype_char): {
-
 
1144
				bm = btype_uchar;
-
 
1145
				t = type_uchar;
-
 
1146
				break;
-
 
1147
			}
-
 
1148
			case BTYPE(btype_short):
-
 
1149
			case BTYPE(btype_short | btype_int):
-
 
1150
			case BTYPE(btype_signed | btype_short):
-
 
1151
			case BTYPE(btype_signed | btype_short | btype_int): {
-
 
1152
				bm = btype_sshort;
-
 
1153
				t = type_sshort;
-
 
1154
				break;
-
 
1155
			}
-
 
1156
			case BTYPE(btype_unsigned | btype_short):
-
 
1157
			case BTYPE(btype_unsigned | btype_short | btype_int): {
-
 
1158
				bm = btype_ushort;
-
 
1159
				t = type_ushort;
-
 
1160
				break;
-
 
1161
			}
-
 
1162
			case BTYPE(btype_int):
-
 
1163
			case BTYPE(btype_none):
-
 
1164
			case BTYPE(btype_signed):
-
 
1165
			case BTYPE(btype_signed | btype_int): {
-
 
1166
				bm = btype_sint;
-
 
1167
				t = type_sint;
-
 
1168
				break;
-
 
1169
			}
-
 
1170
			case BTYPE(btype_unsigned):
-
 
1171
			case BTYPE(btype_unsigned | btype_int): {
-
 
1172
				bm = btype_uint;
-
 
1173
				t = type_uint;
-
 
1174
				break;
-
 
1175
			}
-
 
1176
			case BTYPE(btype_long):
-
 
1177
			case BTYPE(btype_long | btype_int):
-
 
1178
			case BTYPE(btype_signed | btype_long):
-
 
1179
			case BTYPE(btype_signed | btype_long | btype_int): {
-
 
1180
				bm = btype_slong;
-
 
1181
				t = type_slong;
-
 
1182
				break;
-
 
1183
			}
-
 
1184
			case BTYPE(btype_unsigned | btype_long):
-
 
1185
			case BTYPE(btype_unsigned | btype_long | btype_int): {
-
 
1186
				bm = btype_ulong;
-
 
1187
				t = type_ulong;
-
 
1188
				break;
-
 
1189
			}
-
 
1190
			case BTYPE(btype_llong):
-
 
1191
			case BTYPE(btype_llong | btype_int):
-
 
1192
			case BTYPE(btype_signed | btype_llong):
-
 
1193
			case BTYPE(btype_signed | btype_llong | btype_int): {
-
 
1194
				/* Allow for 'signed long long' */
-
 
1195
				if (basetype_info[ntype_sllong].key) {
-
 
1196
					report(crt_loc,
-
 
1197
					       ERR_dcl_type_simple_llong(bm));
-
 
1198
					bm = btype_sllong;
-
 
1199
					t = type_sllong;
-
 
1200
				} else {
-
 
1201
					bm = btype_slong;
-
 
1202
					t = type_slong;
-
 
1203
				}
-
 
1204
				break;
-
 
1205
			}
-
 
1206
			case BTYPE(btype_unsigned | btype_llong):
-
 
1207
			case BTYPE(btype_unsigned | btype_llong | btype_int): {
-
 
1208
				/* Allow for 'unsigned long long' */
-
 
1209
				if (basetype_info[ntype_sllong].key) {
-
 
1210
					report(crt_loc,
-
 
1211
					       ERR_dcl_type_simple_llong(bm));
-
 
1212
					bm = btype_ullong;
-
 
1213
					t = type_ullong;
-
 
1214
				} else {
-
 
1215
					bm = btype_ulong;
-
 
1216
					t = type_ulong;
-
 
1217
				}
-
 
1218
				break;
-
 
1219
			}
-
 
1220
			case BTYPE(btype_long | btype_char): {
-
 
1221
				/* Map 'long char' to 'wchar_t' */
-
 
1222
				bm = (btype_long | btype_char);
-
 
1223
				bo = btype_wchar_t;
-
 
1224
				t = type_wchar_t;
-
 
1225
				break;
-
 
1226
			}
-
 
1227
			default : {
-
 
1228
				/* Invalid type specifier */
-
 
1229
				bm = btype_none;
-
 
1230
				if (bt & btype_signed) {
-
 
1231
					bm |= btype_signed;
-
 
1232
				} else if (bt & btype_unsigned) {
-
 
1233
					bm |= btype_unsigned;
-
 
1234
				}
-
 
1235
				if (bt & btype_char) {
-
 
1236
					bm |= btype_char;
-
 
1237
				} else if (bt & btype_short) {
-
 
1238
					bm |= btype_short;
-
 
1239
				} else if (bt & btype_long2) {
-
 
1240
					bm |= btype_llong;
-
 
1241
				} else if (bt & btype_long) {
-
 
1242
					bm |= btype_long;
-
 
1243
				}
-
 
1244
				t = NULL_type;
-
 
1245
				break;
-
 
1246
			}
-
 
1247
			}
1193
	} while ( IS_NULL_type ( t ) ) ;
1248
		} while (IS_NULL_type(t));
1194
    }
1249
	}
1195
 
1250
 
1196
    /* Check result */
1251
	/* Check result */
1197
    if ( bt & ~bm ) {
1252
	if (bt & ~bm) {
1198
	/* Report excess type specifiers */
1253
		/* Report excess type specifiers */
1199
	if ( bo == btype_none ) bo = ( bt & bm ) ;
1254
		if (bo == btype_none) {
-
 
1255
			bo = (bt & bm);
-
 
1256
		}
1200
	report ( crt_loc, ERR_dcl_type_simple_bad ( bt, bo ) ) ;
1257
		report(crt_loc, ERR_dcl_type_simple_bad(bt, bo));
1201
    } else if ( bo ) {
1258
	} else if (bo) {
1202
	/* Report non-standard type specifiers */
1259
		/* Report non-standard type specifiers */
1203
	report ( crt_loc, ERR_dcl_type_simple_bad ( bt, bo ) ) ;
1260
		report(crt_loc, ERR_dcl_type_simple_bad(bt, bo));
1204
    }
1261
	}
1205
    return ( t ) ;
1262
	return (t);
1206
}
1263
}
1207
 
1264
 
1208
 
1265
 
1209
/*
1266
/*
1210
    SHOULD A TYPE NAME BE MARKED AS USED?
1267
    SHOULD A TYPE NAME BE MARKED AS USED?
1211
 
1268
 
1212
    This flag is used by complete_pre_type to decide whether a type
1269
    This flag is used by complete_pre_type to decide whether a type
1213
    name should be marked as having been used.  This is not the case,
1270
    name should be marked as having been used.  This is not the case,
1214
    for example, in a class definition.
1271
    for example, in a class definition.
1215
*/
1272
*/
1216
 
1273
 
1217
static int use_type_name = 1 ;
1274
static int use_type_name = 1;
1218
 
1275
 
1219
 
1276
 
1220
/*
1277
/*
1221
    COMPLETE A PRE-TYPE
1278
    COMPLETE A PRE-TYPE
1222
 
1279
 
1223
    This routine turns a pre-type comprising the base type qualifiers bt
1280
    This routine turns a pre-type comprising the base type qualifiers bt
1224
    and the type specifier t, used during the type construction routines,
1281
    and the type specifier t, used during the type construction routines,
1225
    into a genuine type.  The original type is destroyed.  The routine
1282
    into a genuine type.  The original type is destroyed.  The routine
1226
    also assigns the const-volatile qualifier cv to the output type.
1283
    also assigns the const-volatile qualifier cv to the output type.
1227
*/
1284
*/
1228
 
1285
 
1229
TYPE complete_pre_type
1286
TYPE
1230
    PROTO_N ( ( bt, t, cv, infer ) )
-
 
1231
    PROTO_T ( BASE_TYPE bt X TYPE t X CV_SPEC cv X int infer )
1287
complete_pre_type(BASE_TYPE bt, TYPE t, CV_SPEC cv, int infer)
1232
{
1288
{
1233
    /* Deal with named types */
1289
	/* Deal with named types */
1234
    if ( !IS_NULL_type ( t ) ) {
1290
	if (!IS_NULL_type(t)) {
1235
	if ( bt ) report ( crt_loc, ERR_dcl_type_simple_undecl ( bt, t ) ) ;
-
 
1236
	if ( IS_type_pre ( t ) ) {
-
 
1237
	    CV_SPEC qual ;
-
 
1238
	    QUALIFIER it ;
-
 
1239
	    IDENTIFIER id ;
-
 
1240
	    DESTROY_type_pre ( destroy, qual, id, bt, it, t ) ;
-
 
1241
	    qual |= cv ;
-
 
1242
	    switch ( bt ) {
1291
		if (bt) {
1243
		case btype_class :
-
 
1244
		case btype_struct :
-
 
1245
		case btype_union :
-
 
1246
		case btype_enum : {
-
 
1247
		    /* Deal with elaborated types */
-
 
1248
		    DECL_SPEC mode = dspec_used ;
-
 
1249
		    if ( it != qual_none ) mode = dspec_alias ;
1292
			report(crt_loc, ERR_dcl_type_simple_undecl(bt, t));
1250
		    id = find_elaborate_type ( id, bt, NULL_type, mode ) ;
-
 
1251
		    break ;
-
 
1252
		}
1293
		}
-
 
1294
		if (IS_type_pre(t)) {
-
 
1295
			CV_SPEC qual;
-
 
1296
			QUALIFIER it;
-
 
1297
			IDENTIFIER id;
-
 
1298
			DESTROY_type_pre(destroy, qual, id, bt, it, t);
-
 
1299
			qual |= cv;
-
 
1300
			switch (bt) {
-
 
1301
			case btype_class:
-
 
1302
			case btype_struct:
-
 
1303
			case btype_union:
-
 
1304
			case btype_enum: {
-
 
1305
				/* Deal with elaborated types */
-
 
1306
				DECL_SPEC mode = dspec_used;
-
 
1307
				if (it != qual_none) {
-
 
1308
					mode = dspec_alias;
1253
	    }
1309
				}
-
 
1310
				id = find_elaborate_type(id, bt, NULL_type,
-
 
1311
							 mode);
-
 
1312
				break;
-
 
1313
			}
-
 
1314
			}
1254
	    if ( IS_id_class_name_etc ( id ) ) {
1315
			if (IS_id_class_name_etc(id)) {
1255
		t = DEREF_type ( id_class_name_etc_defn ( id ) ) ;
1316
				t = DEREF_type(id_class_name_etc_defn(id));
1256
		if ( IS_type_templ ( t ) ) {
1317
				if (IS_type_templ(t)) {
1257
		    t = deduce_type_template ( id, use_type_name ) ;
1318
					t = deduce_type_template(id,
-
 
1319
								 use_type_name);
1258
		}
1320
				}
1259
		t = copy_typedef ( id, t, qual ) ;
1321
				t = copy_typedef(id, t, qual);
1260
		COPY_id ( type_name ( t ), id ) ;
1322
				COPY_id(type_name(t), id);
1261
		if ( use_type_name ) use_id ( id, 0 ) ;
1323
				if (use_type_name) {
-
 
1324
					use_id(id, 0);
-
 
1325
				}
1262
	    } else {
1326
			} else {
1263
		report ( crt_loc, ERR_dcl_type_simple_undef ( id ) ) ;
1327
				report(crt_loc, ERR_dcl_type_simple_undef(id));
1264
		t = type_error ;
1328
				t = type_error;
1265
	    }
1329
			}
-
 
1330
		} else {
-
 
1331
			t = copy_typedef(NULL_id, t, cv);
-
 
1332
		}
-
 
1333
		return (t);
-
 
1334
	}
-
 
1335
 
-
 
1336
	/* Deal with type specifiers */
-
 
1337
	if (bt == btype_none) {
-
 
1338
		t = type_inferred;
1266
	} else {
1339
	} else {
1267
	    t = copy_typedef ( NULL_id, t, cv ) ;
1340
		t = make_base_type(bt);
1268
	}
1341
	}
1269
	return ( t ) ;
1342
	if (cv) {
1270
    }
-
 
1271
 
-
 
1272
    /* Deal with type specifiers */
-
 
1273
    if ( bt == btype_none ) {
-
 
1274
	t = type_inferred ;
-
 
1275
    } else {
-
 
1276
	t = make_base_type ( bt ) ;
1343
		t = qualify_type(t, cv, 0);
1277
    }
1344
	}
1278
    if ( cv ) t = qualify_type ( t, cv, 0 ) ;
-
 
1279
    if ( infer ) {
1345
	if (infer) {
1280
	/* Check for inferred types */
1346
		/* Check for inferred types */
1281
	int i = is_type_inferred ( t ) ;
1347
		int i = is_type_inferred(t);
1282
	if ( i != INFERRED_NOT ) {
1348
		if (i != INFERRED_NOT) {
1283
	    ERROR err ;
1349
			ERROR err;
1284
	    t = clean_inferred_type ( t ) ;
1350
			t = clean_inferred_type(t);
1285
	    err = report_inferred_type ( t, i ) ;
1351
			err = report_inferred_type(t, i);
1286
	    report ( crt_loc, err ) ;
1352
			report(crt_loc, err);
-
 
1353
		}
1287
	}
1354
	}
1288
    }
-
 
1289
    return ( t ) ;
1355
	return (t);
1290
}
1356
}
1291
 
1357
 
1292
 
1358
 
1293
/*
1359
/*
1294
    COMPLETE A NON-ELABORATED PRE-TYPE
1360
    COMPLETE A NON-ELABORATED PRE-TYPE
Line 1297... Line 1363...
1297
    elaborated type declarations (such as 'struct s') as pre-types.  It is
1363
    elaborated type declarations (such as 'struct s') as pre-types.  It is
1298
    used in declarations without declarators where such declarations
1364
    used in declarations without declarators where such declarations
1299
    resolve differently than in the main case.
1365
    resolve differently than in the main case.
1300
*/
1366
*/
1301
 
1367
 
1302
TYPE empty_complete_pre_type
1368
TYPE
1303
    PROTO_N ( ( bt, t, cv, infer ) )
-
 
1304
    PROTO_T ( BASE_TYPE bt X TYPE t X CV_SPEC cv X int infer )
1369
empty_complete_pre_type(BASE_TYPE bt, TYPE t, CV_SPEC cv, int infer)
1305
{
1370
{
1306
    /* Check for elaborated type declarations */
1371
	/* Check for elaborated type declarations */
1307
    if ( !IS_NULL_type ( t ) && IS_type_pre ( t ) ) {
1372
	if (!IS_NULL_type(t) && IS_type_pre(t)) {
1308
	BASE_TYPE key = DEREF_btype ( type_pre_rep ( t ) ) ;
1373
		BASE_TYPE key = DEREF_btype(type_pre_rep(t));
1309
	switch ( key ) {
1374
		switch (key) {
1310
	    case btype_class :
1375
		case btype_class:
1311
	    case btype_struct :
1376
		case btype_struct:
1312
	    case btype_union :
1377
		case btype_union:
1313
	    case btype_enum : {
1378
		case btype_enum: {
1314
		if ( bt ) {
1379
			if (bt) {
1315
		    ERROR err = ERR_dcl_type_simple_undecl ( bt, t ) ;
1380
				ERROR err = ERR_dcl_type_simple_undecl(bt, t);
1316
		    report ( crt_loc, err ) ;
1381
				report(crt_loc, err);
-
 
1382
			}
-
 
1383
			COPY_cv(type_qual(t), cv);
-
 
1384
			COPY_btype(type_pre_rep(t), key);
-
 
1385
			return (t);
-
 
1386
		}
1317
		}
1387
		}
1318
		COPY_cv ( type_qual ( t ), cv ) ;
-
 
1319
		COPY_btype ( type_pre_rep ( t ), key ) ;
-
 
1320
		return ( t ) ;
-
 
1321
	    }
-
 
1322
	}
1388
	}
1323
    }
-
 
1324
 
1389
 
1325
    /* Otherwise obtain the completed type */
1390
	/* Otherwise obtain the completed type */
1326
    use_type_name = 0 ;
1391
	use_type_name = 0;
1327
    t = complete_pre_type ( bt, t, cv, infer ) ;
1392
	t = complete_pre_type(bt, t, cv, infer);
1328
    use_type_name = 1 ;
1393
	use_type_name = 1;
1329
    return ( t ) ;
1394
	return (t);
1330
}
1395
}
1331
 
1396
 
1332
 
1397
 
1333
/*
1398
/*
1334
    FIND UNDERLYING BITFIELD TYPE
1399
    FIND UNDERLYING BITFIELD TYPE
1335
 
1400
 
1336
    This routine returns the type underlying the bitfield type t.
1401
    This routine returns the type underlying the bitfield type t.
1337
*/
1402
*/
1338
 
1403
 
1339
TYPE find_bitfield_type
1404
TYPE
1340
    PROTO_N ( ( t ) )
-
 
1341
    PROTO_T ( TYPE t )
1405
find_bitfield_type(TYPE t)
1342
{
1406
{
1343
    INT_TYPE it = DEREF_itype ( type_bitfield_defn ( t ) ) ;
1407
	INT_TYPE it = DEREF_itype(type_bitfield_defn(t));
1344
    t = DEREF_type ( itype_bitfield_sub ( it ) ) ;
1408
	t = DEREF_type(itype_bitfield_sub(it));
1345
    return ( t ) ;
1409
	return (t);
1346
}
1410
}
1347
 
1411
 
1348
 
1412
 
1349
/*
1413
/*
1350
    FIND A BITFIELD REPRESENTATION
1414
    FIND A BITFIELD REPRESENTATION
1351
 
1415
 
1352
    This routine finds the bitfield representation for a bitfield originally
1416
    This routine finds the bitfield representation for a bitfield originally
1353
    declared with representation bt which expands to the type t.
1417
    declared with representation bt which expands to the type t.
1354
*/
1418
*/
1355
 
1419
 
1356
BASE_TYPE get_bitfield_rep
1420
BASE_TYPE
1357
    PROTO_N ( ( t, bt ) )
-
 
1358
    PROTO_T ( TYPE t X BASE_TYPE bt )
1421
get_bitfield_rep(TYPE t, BASE_TYPE bt)
1359
{
1422
{
1360
    int depth = 0 ;
1423
	int depth = 0;
1361
    IDENTIFIER id = DEREF_id ( type_name ( t ) ) ;
1424
	IDENTIFIER id = DEREF_id(type_name(t));
1362
    while ( !IS_NULL_id ( id ) && depth < 100 ) {
1425
	while (!IS_NULL_id(id) && depth < 100) {
1363
	/* Scan down to original typedef definition */
1426
		/* Scan down to original typedef definition */
1364
	bt = DEREF_btype ( id_class_name_etc_rep ( id ) ) ;
1427
		bt = DEREF_btype(id_class_name_etc_rep(id));
1365
	t = DEREF_type ( id_class_name_etc_defn ( id ) ) ;
1428
		t = DEREF_type(id_class_name_etc_defn(id));
1366
	id = DEREF_id ( type_name ( t ) ) ;
1429
		id = DEREF_id(type_name(t));
1367
	depth++ ;
1430
		depth++;
1368
    }
1431
	}
1369
    if ( IS_type_integer ( t ) ) {
1432
	if (IS_type_integer(t)) {
1370
	INT_TYPE it = DEREF_itype ( type_integer_rep ( t ) ) ;
1433
		INT_TYPE it = DEREF_itype(type_integer_rep(t));
1371
	if ( IS_itype_basic ( it ) ) {
1434
		if (IS_itype_basic(it)) {
1372
	    BASE_TYPE br = DEREF_btype ( itype_basic_rep ( it ) ) ;
1435
			BASE_TYPE br = DEREF_btype(itype_basic_rep(it));
1373
	    if ( bt & br ) {
1436
			if (bt & br) {
1374
		if ( !( br & btype_char ) ) br &= ~btype_signed ;
1437
				if (!(br & btype_char)) {
-
 
1438
					br &= ~btype_signed;
-
 
1439
				}
1375
		if ( bt & btype_signed ) br |= btype_signed ;
1440
				if (bt & btype_signed) {
-
 
1441
					br |= btype_signed;
1376
	    }
1442
				}
-
 
1443
			}
1377
	    bt = br ;
1444
			bt = br;
-
 
1445
		}
1378
	}
1446
	}
1379
    }
-
 
1380
    return ( bt ) ;
1447
	return (bt);
1381
}
1448
}
1382
 
1449
 
1383
 
1450
 
1384
/*
1451
/*
1385
    CHECK A BITFIELD TYPE
1452
    CHECK A BITFIELD TYPE
Line 1390... Line 1457...
1390
    the pre-type which gave rise to t, bt (in this case 'int'), is also
1457
    the pre-type which gave rise to t, bt (in this case 'int'), is also
1391
    given.  The zero argument is true if zero sized bitfields are
1458
    given.  The zero argument is true if zero sized bitfields are
1392
    allowed.
1459
    allowed.
1393
*/
1460
*/
1394
 
1461
 
1395
TYPE check_bitfield_type
1462
TYPE
1396
    PROTO_N ( ( cv, t, bt, n, zero ) )
-
 
1397
    PROTO_T ( CV_SPEC cv X TYPE t X BASE_TYPE bt X NAT n X int zero )
1463
check_bitfield_type(CV_SPEC cv, TYPE t, BASE_TYPE bt, NAT n, int zero)
1398
{
1464
{
1399
    INT_TYPE bf ;
1465
	INT_TYPE bf;
1400
    TYPE p = NULL_type ;
1466
	TYPE p = NULL_type;
1401
    DECL_SPEC info = dspec_none ;
1467
	DECL_SPEC info = dspec_none;
1402
    CV_SPEC qual = DEREF_cv ( type_qual ( t ) ) ;
1468
	CV_SPEC qual = DEREF_cv(type_qual(t));
1403
    if ( qual ) {
1469
	if (qual) {
1404
	/* Move any cv-qualifiers to top level */
1470
		/* Move any cv-qualifiers to top level */
1405
	t = qualify_type ( t, cv_none, 0 ) ;
1471
		t = qualify_type(t, cv_none, 0);
1406
	cv |= qual ;
1472
		cv |= qual;
1407
    }
-
 
1408
    switch ( TAG_type ( t ) ) {
-
 
1409
	case type_integer_tag :
-
 
1410
	case type_enumerate_tag : {
-
 
1411
	    /* Integral types are allowed */
-
 
1412
	    int ok = 1 ;
-
 
1413
	    bt = get_bitfield_rep ( t, bt ) ;
-
 
1414
	    if ( bt & btype_int ) {
-
 
1415
		if ( bt & ( btype_short | btype_long ) ) ok = 0 ;
-
 
1416
	    } else {
-
 
1417
		ok = 0 ;
-
 
1418
	    }
-
 
1419
	    if ( !ok ) {
-
 
1420
		/* Only 'int' types allowed in C */
-
 
1421
		report ( crt_loc, ERR_class_bit_base_int ( t ) ) ;
-
 
1422
	    }
-
 
1423
	    if ( !( bt & ( btype_signed | btype_unsigned ) ) ) {
-
 
1424
		/* No sign given in type specifier */
-
 
1425
		report ( crt_loc, ERR_class_bit_sign ( bt ) ) ;
-
 
1426
	    }
-
 
1427
	    break ;
-
 
1428
	}
1473
	}
-
 
1474
	switch (TAG_type(t)) {
-
 
1475
	case type_integer_tag:
-
 
1476
	case type_enumerate_tag: {
-
 
1477
		/* Integral types are allowed */
-
 
1478
		int ok = 1;
-
 
1479
		bt = get_bitfield_rep(t, bt);
-
 
1480
		if (bt & btype_int) {
-
 
1481
			if (bt & (btype_short | btype_long)) {
-
 
1482
				ok = 0;
-
 
1483
			}
-
 
1484
		} else {
-
 
1485
			ok = 0;
-
 
1486
		}
-
 
1487
		if (!ok) {
-
 
1488
			/* Only 'int' types allowed in C */
-
 
1489
			report(crt_loc, ERR_class_bit_base_int(t));
-
 
1490
		}
-
 
1491
		if (!(bt & (btype_signed | btype_unsigned))) {
-
 
1492
			/* No sign given in type specifier */
-
 
1493
			report(crt_loc, ERR_class_bit_sign(bt));
-
 
1494
		}
-
 
1495
		break;
-
 
1496
	}
1429
	case type_token_tag : {
1497
	case type_token_tag: {
1430
	    /* Allow template parameter types */
1498
		/* Allow template parameter types */
1431
	    if ( is_templ_type ( t ) ) {
1499
		if (is_templ_type(t)) {
1432
		IDENTIFIER id = DEREF_id ( type_token_tok ( t ) ) ;
1500
			IDENTIFIER id = DEREF_id(type_token_tok(t));
1433
		LIST ( TOKEN ) args = DEREF_list ( type_token_args ( t ) ) ;
1501
			LIST(TOKEN)args = DEREF_list(type_token_args(t));
1434
		t = apply_itype_token ( id, args ) ;
1502
			t = apply_itype_token(id, args);
1435
		bt = ( btype_named | btype_template ) ;
1503
			bt = (btype_named | btype_template);
1436
		break ;
1504
			break;
1437
	    }
1505
		}
1438
	    report ( crt_loc, ERR_class_bit_base ( t ) ) ;
1506
		report(crt_loc, ERR_class_bit_base(t));
1439
	    return ( t ) ;
1507
		return (t);
1440
	}
1508
	}
1441
	case type_error_tag : {
1509
	case type_error_tag: {
1442
	    /* Ignore error types */
1510
		/* Ignore error types */
1443
	    return ( t ) ;
1511
		return (t);
-
 
1512
	}
-
 
1513
	default: {
-
 
1514
		/* Other types are not allowed */
-
 
1515
		report(crt_loc, ERR_class_bit_base(t));
-
 
1516
		return (t);
-
 
1517
	}
-
 
1518
	}
-
 
1519
 
-
 
1520
	/* Check the range of n */
-
 
1521
	if (IS_NULL_nat(n) || is_zero_nat(n)) {
-
 
1522
		/* Only anonymous bitfields can have size zero */
-
 
1523
		if (!zero) {
-
 
1524
			report(crt_loc, ERR_class_bit_dim_zero());
-
 
1525
		}
-
 
1526
		info |= dspec_pure;
-
 
1527
		n = small_nat[0];
-
 
1528
		p = type_sint;
-
 
1529
	} else {
-
 
1530
		if (is_negative_nat(n)) {
-
 
1531
			/* Bitfield size cannot be negative */
-
 
1532
			report(crt_loc, ERR_class_bit_dim_neg(n));
-
 
1533
			n = negate_nat(n);
-
 
1534
		}
-
 
1535
		if (check_type_size(t, n) > 0) {
-
 
1536
			report(crt_loc, ERR_class_bit_dim_big(n, t));
-
 
1537
		}
-
 
1538
		if (IS_nat_small(n)) {
-
 
1539
			unsigned sz = DEREF_unsigned(nat_small_value(n));
-
 
1540
			unsigned si = basetype_info[ntype_sint].min_bits;
-
 
1541
			if (sz < si) {
-
 
1542
				/* Fits into 'signed int' */
-
 
1543
				p = type_sint;
-
 
1544
			} else if (sz == si && (bt & btype_unsigned)) {
-
 
1545
				/* Fits into 'unsigned int' */
-
 
1546
				p = type_uint;
-
 
1547
			}
-
 
1548
		}
1444
	}
1549
	}
1445
	default : {
1550
	if (IS_NULL_type(p)) {
1446
	    /* Other types are not allowed */
1551
		/* NOT YET IMPLEMENTED */
1447
	    report ( crt_loc, ERR_class_bit_base ( t ) ) ;
-
 
1448
	    return ( t ) ;
1552
		p = promote_type(t);
1449
	}
1553
	}
1450
    }
-
 
1451
 
1554
 
1452
    /* Check the range of n */
-
 
1453
    if ( IS_NULL_nat ( n ) || is_zero_nat ( n ) ) {
-
 
1454
	/* Only anonymous bitfields can have size zero */
1555
	/* Construct bitfield type */
1455
	if ( !zero ) report ( crt_loc, ERR_class_bit_dim_zero () ) ;
-
 
1456
	info |= dspec_pure ;
-
 
1457
	n = small_nat [0] ;
-
 
1458
	p = type_sint ;
-
 
1459
    } else {
1556
	if (zero) {
1460
	if ( is_negative_nat ( n ) ) {
-
 
1461
	    /* Bitfield size cannot be negative */
-
 
1462
	    report ( crt_loc, ERR_class_bit_dim_neg ( n ) ) ;
-
 
1463
	    n = negate_nat ( n ) ;
1557
		info |= dspec_ignore;
1464
	}
-
 
1465
	if ( check_type_size ( t, n ) > 0 ) {
-
 
1466
	    report ( crt_loc, ERR_class_bit_dim_big ( n, t ) ) ;
-
 
1467
	}
1558
	}
1468
	if ( IS_nat_small ( n ) ) {
-
 
1469
	    unsigned sz = DEREF_unsigned ( nat_small_value ( n ) ) ;
-
 
1470
	    unsigned si = basetype_info [ ntype_sint ].min_bits ;
-
 
1471
	    if ( sz < si ) {
-
 
1472
		/* Fits into 'signed int' */
-
 
1473
		p = type_sint ;
-
 
1474
	    } else if ( sz == si && ( bt & btype_unsigned ) ) {
-
 
1475
		/* Fits into 'unsigned int' */
-
 
1476
		p = type_uint ;
-
 
1477
	    }
-
 
1478
	}
-
 
1479
    }
-
 
1480
    if ( IS_NULL_type ( p ) ) {
-
 
1481
	/* NOT YET IMPLEMENTED */
-
 
1482
	p = promote_type ( t ) ;
-
 
1483
    }
-
 
1484
 
-
 
1485
    /* Construct bitfield type */
-
 
1486
    if ( zero ) info |= dspec_ignore ;
-
 
1487
    MAKE_itype_bitfield ( p, NULL_list ( TYPE ), t, bt, n, info, bf ) ;
1559
	MAKE_itype_bitfield(p, NULL_list(TYPE), t, bt, n, info, bf);
1488
    MAKE_type_bitfield ( cv, bf, t ) ;
1560
	MAKE_type_bitfield(cv, bf, t);
1489
    return ( t ) ;
1561
	return (t);
1490
}
1562
}
1491
 
1563
 
1492
 
1564
 
1493
/*
1565
/*
1494
    CREATE A BITFIELD TYPE
1566
    CREATE A BITFIELD TYPE
1495
 
1567
 
1496
    This routine is identical to check_bitfield_type except that it
1568
    This routine is identical to check_bitfield_type except that it
1497
    takes a constant-expression e rather than the integer constant n.
1569
    takes a constant-expression e rather than the integer constant n.
1498
*/
1570
*/
1499
 
1571
 
1500
TYPE make_bitfield_type
1572
TYPE
1501
    PROTO_N ( ( t, bt, e, zero ) )
-
 
1502
    PROTO_T ( TYPE t X BASE_TYPE bt X EXP e X int zero )
1573
make_bitfield_type(TYPE t, BASE_TYPE bt, EXP e, int zero)
1503
{
1574
{
1504
    ERROR err = NULL_err ;
1575
	ERROR err = NULL_err;
1505
    NAT n = make_nat_exp ( e, &err ) ;
1576
	NAT n = make_nat_exp(e, &err);
1506
    if ( !IS_NULL_err ( err ) ) {
1577
	if (!IS_NULL_err(err)) {
1507
	err = concat_error ( err, ERR_class_bit_dim_const () ) ;
1578
		err = concat_error(err, ERR_class_bit_dim_const());
1508
	report ( crt_loc, err ) ;
1579
		report(crt_loc, err);
1509
    }
1580
	}
1510
    t = check_bitfield_type ( cv_none, t, bt, n, zero ) ;
1581
	t = check_bitfield_type(cv_none, t, bt, n, zero);
1511
    return ( t ) ;
1582
	return (t);
1512
}
1583
}
1513
 
1584
 
1514
 
1585
 
1515
/*
1586
/*
1516
    CHECK AN ARRAY BOUND
1587
    CHECK AN ARRAY BOUND
1517
 
1588
 
1518
    This routine checks the array bound n.  n can be null, indicating an
1589
    This routine checks the array bound n.  n can be null, indicating an
1519
    unbounded array, or a positive constant.
1590
    unbounded array, or a positive constant.
1520
*/
1591
*/
1521
 
1592
 
1522
NAT check_array_dim
1593
NAT
1523
    PROTO_N ( ( n ) )
-
 
1524
    PROTO_T ( NAT n )
1594
check_array_dim(NAT n)
1525
{
1595
{
1526
    if ( !IS_NULL_nat ( n ) ) {
1596
	if (!IS_NULL_nat(n)) {
1527
	if ( is_zero_nat ( n ) ) {
1597
		if (is_zero_nat(n)) {
1528
	    report ( crt_loc, ERR_dcl_array_dim_zero () ) ;
1598
			report(crt_loc, ERR_dcl_array_dim_zero());
1529
	} else if ( is_negative_nat ( n ) ) {
1599
		} else if (is_negative_nat(n)) {
1530
	    report ( crt_loc, ERR_dcl_array_dim_neg ( n ) ) ;
1600
			report(crt_loc, ERR_dcl_array_dim_neg(n));
1531
	    n = negate_nat ( n ) ;
1601
			n = negate_nat(n);
-
 
1602
		}
1532
	}
1603
	}
1533
    }
-
 
1534
    return ( n ) ;
1604
	return (n);
1535
}
1605
}
1536
 
1606
 
1537
 
1607
 
1538
/*
1608
/*
1539
    CREATE AN ARRAY BOUND
1609
    CREATE AN ARRAY BOUND
1540
 
1610
 
1541
    This routine turns the integer constant expression e into an array
1611
    This routine turns the integer constant expression e into an array
1542
    bound.  e may also be the null expression, indicating an unbounded
1612
    bound.  e may also be the null expression, indicating an unbounded
1543
    array.
1613
    array.
1544
*/
1614
*/
1545
 
1615
 
1546
NAT make_array_dim
1616
NAT
1547
    PROTO_N ( ( e ) )
-
 
1548
    PROTO_T ( EXP e )
1617
make_array_dim(EXP e)
1549
{
1618
{
1550
    if ( !IS_NULL_exp ( e ) ) {
1619
	if (!IS_NULL_exp(e)) {
1551
	ERROR err = NULL_err ;
1620
		ERROR err = NULL_err;
1552
	NAT n = make_nat_exp ( e, &err ) ;
1621
		NAT n = make_nat_exp(e, &err);
1553
	if ( !IS_NULL_err ( err ) ) {
1622
		if (!IS_NULL_err(err)) {
1554
	    err = concat_error ( err, ERR_dcl_array_dim_const () ) ;
1623
			err = concat_error(err, ERR_dcl_array_dim_const());
1555
	    report ( crt_loc, err ) ;
1624
			report(crt_loc, err);
1556
	}
1625
		}
1557
	n = check_array_dim ( n ) ;
1626
		n = check_array_dim(n);
1558
	return ( n ) ;
1627
		return (n);
1559
    }
1628
	}
1560
    return ( NULL_nat ) ;
1629
	return (NULL_nat);
1561
}
1630
}
1562
 
1631
 
1563
 
1632
 
1564
/*
1633
/*
1565
    CHECK AN INTEGER TYPE
1634
    CHECK AN INTEGER TYPE
1566
 
1635
 
1567
    This routine checks whether t is an integral type containing the base
1636
    This routine checks whether t is an integral type containing the base
1568
    type specifiers m.  It is used to spot signed types, unsigned types,
1637
    type specifiers m.  It is used to spot signed types, unsigned types,
1569
    character types and so on.
1638
    character types and so on.
1570
*/
1639
*/
1571
 
1640
 
1572
int check_int_type
1641
int
1573
    PROTO_N ( ( t, m ) )
-
 
1574
    PROTO_T ( TYPE t X BASE_TYPE m )
1642
check_int_type(TYPE t, BASE_TYPE m)
1575
{
1643
{
1576
    if ( IS_type_integer ( t ) ) {
1644
	if (IS_type_integer(t)) {
1577
	INT_TYPE it = DEREF_itype ( type_integer_rep ( t ) ) ;
1645
		INT_TYPE it = DEREF_itype(type_integer_rep(t));
1578
	switch ( TAG_itype ( it ) ) {
1646
		switch (TAG_itype(it)) {
1579
	    case itype_basic_tag : {
1647
		case itype_basic_tag: {
1580
		BASE_TYPE bt = DEREF_btype ( itype_basic_rep ( it ) ) ;
1648
			BASE_TYPE bt = DEREF_btype(itype_basic_rep(it));
1581
		if ( ( bt & m ) == m ) return ( 1 ) ;
1649
			if ((bt & m) == m) {
-
 
1650
				return (1);
-
 
1651
			}
1582
		break ;
1652
			break;
1583
	    }
1653
		}
1584
	    case itype_token_tag : {
1654
		case itype_token_tag: {
1585
		/* Tokenised types */
1655
			/* Tokenised types */
1586
		IDENTIFIER tid = DEREF_id ( itype_token_tok ( it ) ) ;
1656
			IDENTIFIER tid = DEREF_id(itype_token_tok(it));
1587
		TOKEN tok = DEREF_tok ( id_token_sort ( tid ) ) ;
1657
			TOKEN tok = DEREF_tok(id_token_sort(tid));
1588
		if ( IS_tok_proc ( tok ) ) {
1658
			if (IS_tok_proc(tok)) {
1589
		    tok = DEREF_tok ( tok_proc_res ( tok ) ) ;
1659
				tok = DEREF_tok(tok_proc_res(tok));
-
 
1660
			}
-
 
1661
			if (IS_tok_type(tok)) {
-
 
1662
				BASE_TYPE bt = DEREF_btype(tok_type_kind(tok));
-
 
1663
				if ((bt & m) == m) {
-
 
1664
					return (1);
-
 
1665
				}
-
 
1666
			}
-
 
1667
			break;
1590
		}
1668
		}
1591
		if ( IS_tok_type ( tok ) ) {
-
 
1592
		    BASE_TYPE bt = DEREF_btype ( tok_type_kind ( tok ) ) ;
-
 
1593
		    if ( ( bt & m ) == m ) return ( 1 ) ;
-
 
1594
		}
1669
		}
1595
		break ;
-
 
1596
	    }
-
 
1597
	}
1670
	}
1598
    }
-
 
1599
    return ( 0 ) ;
1671
	return (0);
1600
}
1672
}
1601
 
1673
 
1602
 
1674
 
1603
/*
1675
/*
1604
    LISTS OF COMPATIBLE TYPES
1676
    LISTS OF COMPATIBLE TYPES
1605
 
1677
 
1606
    These lists are used to record the compatible types set by the
1678
    These lists are used to record the compatible types set by the
1607
    routines below.
1679
    routines below.
1608
*/
1680
*/
1609
 
1681
 
1610
static LIST ( TYPE ) arg1_types = NULL_list ( TYPE ) ;
1682
static LIST(TYPE) arg1_types = NULL_list(TYPE);
1611
static LIST ( TYPE ) arg2_types = NULL_list ( TYPE ) ;
1683
static LIST(TYPE) arg2_types = NULL_list(TYPE);
1612
static LIST ( TYPE ) ell_types = NULL_list ( TYPE ) ;
1684
static LIST(TYPE) ell_types = NULL_list(TYPE);
1613
 
1685
 
1614
 
1686
 
1615
/*
1687
/*
1616
    SET TWO TYPES TO BE COMPATIBLE
1688
    SET TWO TYPES TO BE COMPATIBLE
1617
 
1689
 
1618
    This routine sets the types t and s to be compatible with option
1690
    This routine sets the types t and s to be compatible with option
1619
    level opt.
1691
    level opt.
1620
*/
1692
*/
1621
 
1693
 
1622
void set_compatible_type
1694
void
1623
    PROTO_N ( ( t, s, opt ) )
-
 
1624
    PROTO_T ( TYPE t X TYPE s X unsigned opt )
1695
set_compatible_type(TYPE t, TYPE s, unsigned opt)
1625
{
1696
{
1626
    TYPE pt = type_char_star ;
1697
	TYPE pt = type_char_star;
1627
    TYPE ps = type_void_star ;
1698
	TYPE ps = type_void_star;
1628
    if ( eq_type ( t, pt ) && eq_type ( s, ps ) ) {
1699
	if (eq_type(t, pt) && eq_type(s, ps)) {
1629
	set_option ( OPT_gen_ptr_char, opt ) ;
1700
		set_option(OPT_gen_ptr_char, opt);
1630
    } else {
1701
	} else {
1631
	report ( preproc_loc, ERR_pragma_compat_type () ) ;
1702
		report(preproc_loc, ERR_pragma_compat_type());
1632
    }
1703
	}
1633
    return ;
1704
	return;
1634
}
1705
}
1635
 
1706
 
1636
 
1707
 
1637
/*
1708
/*
1638
    FIND CANONICAL ARGUMENT TYPE
1709
    FIND CANONICAL ARGUMENT TYPE
1639
 
1710
 
1640
    This routine finds the canonical argument type for the type t by
1711
    This routine finds the canonical argument type for the type t by
1641
    chasing down the lists of compatible argument types.  It returns
1712
    chasing down the lists of compatible argument types.  It returns
1642
    the null type if t is not compatible with a type from this list.
1713
    the null type if t is not compatible with a type from this list.
1643
*/
1714
*/
1644
 
1715
 
1645
static TYPE find_arg_type
1716
static
1646
    PROTO_N ( ( t ) )
-
 
1647
    PROTO_T ( TYPE t )
1717
TYPE find_arg_type(TYPE t)
1648
{
1718
{
1649
    LIST ( TYPE ) p = arg1_types ;
1719
	LIST(TYPE)p = arg1_types;
1650
    LIST ( TYPE ) q = arg2_types ;
1720
	LIST(TYPE)q = arg2_types;
1651
    while ( !IS_NULL_list ( p ) ) {
1721
	while (!IS_NULL_list(p)) {
1652
	TYPE r = DEREF_type ( HEAD_list ( p ) ) ;
1722
		TYPE r = DEREF_type(HEAD_list(p));
1653
	r = type_composite ( t, r, 0, 1, KILL_err, 0 ) ;
1723
		r = type_composite(t, r, 0, 1, KILL_err, 0);
1654
	if ( !IS_NULL_type ( r ) ) {
1724
		if (!IS_NULL_type(r)) {
1655
	    r = DEREF_type ( HEAD_list ( q ) ) ;
1725
			r = DEREF_type(HEAD_list(q));
1656
	    return ( r ) ;
1726
			return (r);
-
 
1727
		}
-
 
1728
		q = TAIL_list(q);
-
 
1729
		p = TAIL_list(p);
1657
	}
1730
	}
1658
	q = TAIL_list ( q ) ;
-
 
1659
	p = TAIL_list ( p ) ;
-
 
1660
    }
-
 
1661
    return ( NULL_type ) ;
1731
	return (NULL_type);
1662
}
1732
}
1663
 
1733
 
1664
 
1734
 
1665
/*
1735
/*
1666
    SET TWO TYPES TO BE ARGUMENT COMPATIBLE
1736
    SET TWO TYPES TO BE ARGUMENT COMPATIBLE
1667
 
1737
 
1668
    This routine sets the types t and s to be compatible as function
1738
    This routine sets the types t and s to be compatible as function
1669
    parameters.
1739
    parameters.
1670
*/
1740
*/
1671
 
1741
 
1672
void accept_argument
-
 
1673
    PROTO_N ( ( t, s ) )
-
 
1674
    PROTO_T ( TYPE t X TYPE s )
-
 
1675
{
-
 
1676
    TYPE pt, ps ;
-
 
1677
    LIST ( TYPE ) p ;
-
 
1678
    t = qualify_type ( t, cv_none, 0 ) ;
-
 
1679
    t = make_param_type ( t, CONTEXT_PARAMETER ) ;
-
 
1680
    s = qualify_type ( s, cv_none, 0 ) ;
-
 
1681
    s = make_param_type ( s, CONTEXT_PARAMETER ) ;
-
 
1682
    pt = find_arg_type ( t ) ;
-
 
1683
    ps = find_arg_type ( s ) ;
-
 
1684
    if ( IS_NULL_type ( ps ) ) ps = s ;
-
 
1685
    if ( !IS_NULL_type ( pt ) ) {
-
 
1686
	/* Already have entry for t */
-
 
1687
	if ( !eq_type ( ps, pt ) ) {
-
 
1688
	    report ( preproc_loc, ERR_pragma_arg_dup ( t ) ) ;
-
 
1689
	}
-
 
1690
	return ;
-
 
1691
    }
-
 
1692
    pt = type_composite ( ps, t, 0, 1, KILL_err, 0 ) ;
-
 
1693
    if ( !IS_NULL_type ( pt ) ) {
-
 
1694
	report ( preproc_loc, ERR_pragma_arg_cycle () ) ;
-
 
1695
	return ;
-
 
1696
    }
-
 
1697
    p = arg2_types ;
-
 
1698
    CONS_type ( t, arg1_types, arg1_types ) ;
-
 
1699
    CONS_type ( ps, p, arg2_types ) ;
-
 
1700
    while ( !IS_NULL_list ( p ) ) {
-
 
1701
	pt = DEREF_type ( HEAD_list ( p ) ) ;
-
 
1702
	pt = type_composite ( pt, t, 0, 1, KILL_err, 0 ) ;
-
 
1703
	if ( !IS_NULL_type ( pt ) ) COPY_type ( HEAD_list ( p ), ps ) ;
-
 
1704
	p = TAIL_list ( p ) ;
-
 
1705
    }
1742
void
1706
    return ;
-
 
1707
}
-
 
1708
 
-
 
1709
 
-
 
1710
/*
-
 
1711
    SET A TYPE TO BE ELLIPSIS COMPATIBLE
-
 
1712
 
-
 
1713
    This routine sets the type t to be compatible with an ellipsis in
-
 
1714
    function parameters.
-
 
1715
*/
-
 
1716
 
-
 
1717
void accept_ellipsis
-
 
1718
    PROTO_N ( ( t ) )
-
 
1719
    PROTO_T ( TYPE t )
1743
accept_argument(TYPE t, TYPE s)
1720
{
1744
{
-
 
1745
	TYPE pt, ps;
1721
    TYPE r ;
1746
	LIST(TYPE)p;
1722
    t = qualify_type ( t, cv_none, 0 ) ;
1747
	t = qualify_type(t, cv_none, 0);
1723
    t = make_param_type ( t, CONTEXT_PARAMETER ) ;
1748
	t = make_param_type(t, CONTEXT_PARAMETER);
-
 
1749
	s = qualify_type(s, cv_none, 0);
-
 
1750
	s = make_param_type(s, CONTEXT_PARAMETER);
-
 
1751
	pt = find_arg_type(t);
-
 
1752
	ps = find_arg_type(s);
-
 
1753
	if (IS_NULL_type(ps)) {
-
 
1754
		ps = s;
-
 
1755
	}
-
 
1756
	if (!IS_NULL_type(pt)) {
-
 
1757
		/* Already have entry for t */
1724
    r = eq_ellipsis ( t ) ;
1758
		if (!eq_type(ps, pt)) {
-
 
1759
			report(preproc_loc, ERR_pragma_arg_dup(t));
-
 
1760
		}
-
 
1761
		return;
-
 
1762
	}
-
 
1763
	pt = type_composite(ps, t, 0, 1, KILL_err, 0);
1725
    if ( IS_NULL_type ( r ) ) {
1764
	if (!IS_NULL_type(pt)) {
-
 
1765
		report(preproc_loc, ERR_pragma_arg_cycle());
-
 
1766
		return;
-
 
1767
	}
-
 
1768
	p = arg2_types;
1726
	CONS_type ( t, ell_types, ell_types ) ;
1769
	CONS_type(t, arg1_types, arg1_types);
-
 
1770
	CONS_type(ps, p, arg2_types);
-
 
1771
	while (!IS_NULL_list(p)) {
-
 
1772
		pt = DEREF_type(HEAD_list(p));
-
 
1773
		pt = type_composite(pt, t, 0, 1, KILL_err, 0);
-
 
1774
		if (!IS_NULL_type(pt)) {
-
 
1775
			COPY_type(HEAD_list(p), ps);
1727
    }
1776
		}
-
 
1777
		p = TAIL_list(p);
-
 
1778
	}
1728
    return ;
1779
	return;
1729
}
1780
}
1730
 
1781
 
1731
 
1782
 
-
 
1783
/*
-
 
1784
    SET A TYPE TO BE ELLIPSIS COMPATIBLE
-
 
1785
 
-
 
1786
    This routine sets the type t to be compatible with an ellipsis in
-
 
1787
    function parameters.
-
 
1788
*/
-
 
1789
 
-
 
1790
void
-
 
1791
accept_ellipsis(TYPE t)
-
 
1792
{
-
 
1793
	TYPE r;
-
 
1794
	t = qualify_type(t, cv_none, 0);
-
 
1795
	t = make_param_type(t, CONTEXT_PARAMETER);
-
 
1796
	r = eq_ellipsis(t);
-
 
1797
	if (IS_NULL_type(r)) {
-
 
1798
		CONS_type(t, ell_types, ell_types);
-
 
1799
	}
-
 
1800
	return;
-
 
1801
}
-
 
1802
 
-
 
1803
 
1732
/*
1804
/*
1733
    ARE TWO TYPES ARGUMENT COMPATIBLE?
1805
    ARE TWO TYPES ARGUMENT COMPATIBLE?
1734
 
1806
 
1735
    This routine checks whether the types t and s are compatible as
1807
    This routine checks whether the types t and s are compatible as
1736
    function parameters.  If eq is true then compatibility is only
1808
    function parameters.  If eq is true then compatibility is only
1737
    checked if one of the types appears in the list of types.  The
1809
    checked if one of the types appears in the list of types.  The
1738
    routine returns the composite type.
1810
    routine returns the composite type.
1739
*/
1811
*/
1740
 
1812
 
1741
TYPE eq_argument
1813
TYPE
1742
    PROTO_N ( ( t, s, eq ) )
-
 
1743
    PROTO_T ( TYPE t X TYPE s X int eq )
1814
eq_argument(TYPE t, TYPE s, int eq)
1744
{
1815
{
1745
    TYPE pt = find_arg_type ( t ) ;
1816
	TYPE pt = find_arg_type(t);
1746
    TYPE ps = find_arg_type ( s ) ;
1817
	TYPE ps = find_arg_type(s);
1747
    if ( EQ_type ( pt, ps ) ) {
1818
	if (EQ_type(pt, ps)) {
1748
	if ( !IS_NULL_type ( pt ) ) return ( pt ) ;
1819
		if (!IS_NULL_type(pt)) {
-
 
1820
			return (pt);
-
 
1821
		}
-
 
1822
		if (eq) {
1749
	if ( eq ) return ( NULL_type ) ;
1823
			return (NULL_type);
1750
    }
1824
		}
-
 
1825
	}
1751
    if ( IS_NULL_type ( pt ) ) pt = t ;
1826
	if (IS_NULL_type(pt)) {
-
 
1827
		pt = t;
-
 
1828
	}
1752
    if ( IS_NULL_type ( ps ) ) ps = s ;
1829
	if (IS_NULL_type(ps)) {
-
 
1830
		ps = s;
-
 
1831
	}
1753
    pt = type_composite ( pt, ps, 0, 1, KILL_err, 1 ) ;
1832
	pt = type_composite(pt, ps, 0, 1, KILL_err, 1);
1754
    return ( pt ) ;
1833
	return (pt);
1755
}
1834
}
1756
 
1835
 
1757
 
1836
 
1758
/*
1837
/*
1759
    IS A TYPE ELLIPSIS COMPATIBLE?
1838
    IS A TYPE ELLIPSIS COMPATIBLE?
1760
 
1839
 
1761
    This routine checks whether the type t is compatible with an ellipsis
1840
    This routine checks whether the type t is compatible with an ellipsis
1762
    in function parameters.
1841
    in function parameters.
1763
*/
1842
*/
1764
 
1843
 
1765
TYPE eq_ellipsis
1844
TYPE
1766
    PROTO_N ( ( t ) )
-
 
1767
    PROTO_T ( TYPE t )
1845
eq_ellipsis(TYPE t)
1768
{
1846
{
1769
    LIST ( TYPE ) p = ell_types ;
1847
	LIST(TYPE)p = ell_types;
1770
    while ( !IS_NULL_list ( p ) ) {
1848
	while (!IS_NULL_list(p)) {
1771
	TYPE r = DEREF_type ( HEAD_list ( p ) ) ;
1849
		TYPE r = DEREF_type(HEAD_list(p));
1772
	TYPE s = eq_argument ( t, r, 0 ) ;
1850
		TYPE s = eq_argument(t, r, 0);
1773
	if ( !IS_NULL_type ( s ) ) return ( s ) ;
1851
		if (!IS_NULL_type(s)) {
-
 
1852
			return (s);
-
 
1853
		}
1774
	p = TAIL_list ( p ) ;
1854
		p = TAIL_list(p);
1775
    }
1855
	}
1776
    return ( NULL_type ) ;
1856
	return (NULL_type);
1777
}
1857
}
1778
 
1858
 
1779
 
1859
 
1780
/*
1860
/*
1781
    BASIC TYPES
1861
    BASIC TYPES
1782
 
1862
 
1783
    These variables stand for the basic types which arise naturally in
1863
    These variables stand for the basic types which arise naturally in
1784
    C and C++.  This includes the basic integer and floating-point types,
1864
    C and C++.  This includes the basic integer and floating-point types,
1785
    bool, size_t and related construct types, void and bottom (the type
1865
    bool, size_t and related construct types, void and bottom (the type
1786
    of an expression which does not return), plus a few useful composite
1866
    of an expression which does not return), plus a few useful composite
1787
    types.
1867
    types.
1788
*/
1868
*/
1789
 
1869
 
1790
TYPE type_builtin [ ORDER_ntype ] ;
1870
TYPE type_builtin[ORDER_ntype];
1791
TYPE ptr_type_builtin [ ORDER_ntype ] ;
1871
TYPE ptr_type_builtin[ORDER_ntype];
1792
TYPE type_func_void ;
1872
TYPE type_func_void;
1793
TYPE type_temp_func ;
1873
TYPE type_temp_func;
1794
TYPE type_ellipsis ;
1874
TYPE type_ellipsis;
1795
TYPE type_error ;
1875
TYPE type_error;
1796
 
1876
 
1797
 
1877
 
1798
/*
1878
/*
1799
    INITIALISE BASIC TYPES
1879
    INITIALISE BASIC TYPES
1800
 
1880
 
1801
    This routine initialises the basic types above.
1881
    This routine initialises the basic types above.
1802
*/
1882
*/
1803
 
1883
 
1804
void init_types
1884
void
1805
    PROTO_Z ()
1885
init_types(void)
1806
{
1886
{
1807
    unsigned long n ;
1887
	unsigned long n;
1808
    init_itypes ( 1 ) ;
1888
	init_itypes(1);
1809
    for ( n = 0 ; n < ORDER_ntype ; n++ ) {
1889
	for (n = 0; n < ORDER_ntype; n++) {
1810
	MAKE_type_ptr ( cv_none, type_builtin [n], ptr_type_builtin [n] ) ;
1890
		MAKE_type_ptr(cv_none, type_builtin[n], ptr_type_builtin[n]);
1811
    }
1891
	}
1812
    MAKE_type_func ( cv_lvalue, type_void, NULL_list ( TYPE ), 0, cv_lang,
1892
	MAKE_type_func(cv_lvalue, type_void, NULL_list(TYPE), 0, cv_lang,
1813
		     NULL_list ( TYPE ), NULL_nspace, NULL_list ( IDENTIFIER ),
1893
		       NULL_list(TYPE), NULL_nspace, NULL_list(IDENTIFIER),
1814
		     NULL_list ( TYPE ), type_func_void ) ;
1894
		       NULL_list(TYPE), type_func_void);
1815
    MAKE_type_func ( cv_none, type_void, NULL_list ( TYPE ), 0, cv_lang,
1895
	MAKE_type_func(cv_none, type_void, NULL_list(TYPE), 0, cv_lang,
1816
		     NULL_list ( TYPE ), NULL_nspace, NULL_list ( IDENTIFIER ),
1896
		       NULL_list(TYPE), NULL_nspace, NULL_list(IDENTIFIER),
1817
		     NULL_list ( TYPE ), type_temp_func ) ;
1897
		       NULL_list(TYPE), type_temp_func);
1818
    MAKE_type_error ( cv_none, type_error ) ;
1898
	MAKE_type_error(cv_none, type_error);
1819
    type_ellipsis = NULL_type ;
1899
	type_ellipsis = NULL_type;
1820
    return ;
1900
	return;
1821
}
1901
}