Subversion Repositories tendra.SVN

Rev

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

Rev 2 Rev 7
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, 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
Line 27... Line 57...
27
        it may be put.
57
        it may be put.
28
*/
58
*/
29
 
59
 
30
 
60
 
31
/*
61
/*
32
    TYPE SYSTEM SPECIFICATION
62
 * TYPE SYSTEM SPECIFICATION
33
 
63
 *
34
    The main type system for the program is specified using the calculus
64
 * The main type system for the program is specified using the calculus tool.
35
    tool.  This generates two representations of the type algebra, c_class.
65
 * This generates two representations of the type algebra, c_class. The files
36
    The files in obj_tok describe the output type system abstractly in terms
66
 * in obj_tok describe the output type system abstractly in terms of the TenDRA
37
    of the TenDRA '#pragma token' constructs.  These may be used to apply
67
 * '#pragma token' constructs. These may be used to apply extremely rigorous
38
    extremely rigorous type checking to the program.  The files in obj_c
68
 * type checking to the program. The files in obj_c give the implementation of
39
    give the implementation of the type system in C terms.  The
69
 * the type system in C terms. The implementation specific parts of the
40
    implementation specific parts of the program, including the memory
-
 
41
    management, is handled in obj_c/c_class.c.
70
 * program, including the memory management, is handled in obj_c/c_class.c.
42
*/
71
 */
43
 
72
 
44
ALGEBRA c_class (1.1) :
73
ALGEBRA c_class (1.1) :
45
 
74
 
46
 
75
 
47
/*
76
/*
48
    PRIMITIVE TYPES
77
 * PRIMITIVE TYPES
49
 
78
 *
50
    These are the primitive types from which the algebra is built.  int,
79
 * These are the primitive types from which the algebra is built. int, unsigned
51
    unsigned and string are self-explanitory.  BITSTREAM_P represents a
80
 * and string are self-explanitory. BITSTREAM_P represents a series of bits,
52
    series of bits, and is used to hold any compiled code.  PPTOKEN_P
81
 * and is used to hold any compiled code. PPTOKEN_P represents a list of
53
    represents a list of preprocessing tokens, and is used in macro
82
 * preprocessing tokens, and is used in macro definitions etc.
54
    definitions etc.
-
 
55
*/
83
 */
56
 
84
 
57
int =			"int" ;
85
int =			"int" ;
58
unsigned =		"unsigned" ;
86
unsigned =		"unsigned" ;
59
string =		"character *" ;
87
string =		"character *" ;
60
ulong_type (ulong) =	"unsigned long" ;
88
ulong_type (ulong) =	"unsigned long" ;
61
BITSTREAM_P (bits) =	"struct bits_tag *" ;
89
BITSTREAM_P (bits) =	"struct bits_tag *" ;
62
PPTOKEN_P (pptok) =	"struct pptok_tag *" ;
90
PPTOKEN_P (pptok) =	"struct pptok_tag *" ;
63
 
91
 
64
 
92
 
65
/*
93
/*
66
    TYPE REPRESENTING A CONST-VOLATILE SPECIFIER
94
 * TYPE REPRESENTING A CONST-VOLATILE SPECIFIER
67
 
95
 *
68
    The const and volatile type qualifiers are represented by an
96
 * The const and volatile type qualifiers are represented by an enumeration
69
    enumeration type (which is actually a bit pattern).  An additional
97
 * type (which is actually a bit pattern). An additional value is used to
70
    value is used to indicate lvalues.  Type linkage specifiers are also
98
 * indicate lvalues. Type linkage specifiers are also included.
71
    included.
-
 
72
*/
99
 */
73
 
100
 
74
enum !CV_SPEC (cv) = {
101
enum !CV_SPEC (cv) = {
75
    none =		0,
102
    none =		0,
76
    const =		1 << 0,
103
    const =		1 << 0,
77
    volatile =		1 << 1,
104
    volatile =		1 << 1,
78
    lvalue =		1 << 2,
105
    lvalue =		1 << 2,
79
 
106
 
80
    c =			1 << 3,
107
    c =			1 << 3,
81
    cpp =		1 << 4,
108
    cpp =		1 << 4,
82
 
109
 
83
    qual =		const | volatile,
110
    qual =		const | volatile,
84
    mask =		qual | lvalue,
111
    mask =		qual | lvalue,
85
    language =		c | cpp
112
    language =		c | cpp
86
} ;
113
} ;
87
 
114
 
88
 
115
 
89
/*
116
/*
90
    TYPE REPRESENTING A BUILT-IN TYPE
117
 * TYPE REPRESENTING A BUILT-IN TYPE
91
 
118
 *
92
    The built-in types have two representations - as a BASE_TYPE (see below)
119
 * The built-in types have two representations - as a BASE_TYPE (see below) or
93
    or as a BUILTIN_TYPE.  The latter is used primarily as an index into
120
 * as a BUILTIN_TYPE. The latter is used primarily as an index into various
94
    various tables.
121
 * tables.
95
*/
122
 */
96
 
123
 
97
enum !BUILTIN_TYPE (ntype) = {
124
enum !BUILTIN_TYPE (ntype) = {
98
    none =		0,
125
    none =		0,
99
    char =		1,
126
    char =		1,
100
    schar =		2,
127
    schar =		2,
101
    uchar =		3,
128
    uchar =		3,
Line 119... Line 146...
119
    ellipsis =		21
146
    ellipsis =		21
120
} ;
147
} ;
121
 
148
 
122
 
149
 
123
/*
150
/*
124
    TYPE REPRESENTING A BASIC TYPE
151
 * TYPE REPRESENTING A BASIC TYPE
125
 
152
 *
126
    The basic types are represented by an enumeration type (which is
153
 * The basic types are represented by an enumeration type (which is actually a
127
    actually a bit pattern except for the named type component).  The
154
 * bit pattern except for the named type component). The composite bitpatterns
128
    composite bitpatterns for the maximally valid combinations are also
155
 * for the maximally valid combinations are also given. The elaborated type
129
    given.  The elaborated type keys are also represented by this type.
156
 * keys are also represented by this type.
130
*/
157
 */
131
 
158
 
132
enum !BASE_TYPE (btype) = {
159
enum !BASE_TYPE (btype) = {
133
    none =		0,
160
    none =		0,
134
    class =		1,
161
    class =		1,
135
    struct_ =		2,
162
    struct_ =		2,
Line 179... Line 206...
179
    scalar =		int | float | star
206
    scalar =		int | float | star
180
} ;
207
} ;
181
 
208
 
182
 
209
 
183
/*
210
/*
184
    TYPE REPRESENTING AN INTEGRAL TYPE
211
 * TYPE REPRESENTING AN INTEGRAL TYPE
185
 
212
 *
186
    An integral type can be one of the built-in types, an integral promotion
213
 * An integral type can be one of the built-in types, an integral promotion
187
    type or an arithmetic conversion type.  The promotion type for each
214
 * type or an arithmetic conversion type. The promotion type for each integral
188
    integral type is stored as part of its definition.
215
 * type is stored as part of its definition.
189
*/
216
 */
190
 
217
 
191
union INT_TYPE (itype) = {
218
union INT_TYPE (itype) = {
192
    TYPE prom ;
219
    TYPE prom ;
193
    LIST TYPE cases ;
220
    LIST TYPE cases ;
194
    BUILTIN_TYPE unprom = "ntype_none" ;
221
    BUILTIN_TYPE unprom = "ntype_none" ;
Line 208... Line 235...
208
	NAT size ;
235
	NAT size ;
209
	DECL_SPEC info ;
236
	DECL_SPEC info ;
210
    },
237
    },
211
    promote -> {
238
    promote -> {
212
	/* Promotion types */
239
	/* Promotion types */
213
	INT_TYPE arg ;
240
	INT_TYPE arg ;
214
    },
241
    },
215
    arith -> {
242
    arith -> {
216
	/* Arithmetic conversion types */
243
	/* Arithmetic conversion types */
217
	INT_TYPE arg1, arg2 ;
244
	INT_TYPE arg1, arg2 ;
218
    },
245
    },
219
    literal -> {
246
    literal -> {
220
	/* Target dependent literal type */
247
	/* Target dependent literal type */
221
	NAT nat ;
248
	NAT nat ;
222
	int spec ;
249
	int spec ;
223
	int form, suff ;
250
	int form, suff ;
224
	IDENTIFIER tok ;
251
	IDENTIFIER tok ;
225
    },
252
    },
226
    token -> {
253
    token -> {
227
	/* Tokenised integral type */
254
	/* Tokenised integral type */
228
	IDENTIFIER tok ;
255
	IDENTIFIER tok ;
229
	LIST TOKEN args ;
256
	LIST TOKEN args ;
230
    }
257
    }
231
} ;
258
} ;
232
 
259
 
233
 
260
 
234
/*
261
/*
235
    TYPE REPRESENTING A FLOATING POINT TYPE
262
 * TYPE REPRESENTING A FLOATING POINT TYPE
236
 
263
 *
237
    A floating point type can be one of the built-in types or an arithmetic
264
 * A floating point type can be one of the built-in types or an arithmetic
238
    conversion type.  Note that all floating point types are their own
265
 * conversion type. Note that all floating point types are their own arithmetic
239
    arithmetic promotions, but they do have distinct argument promotions.
266
 * promotions, but they do have distinct argument promotions.
240
*/
267
 */
241
 
268
 
242
union FLOAT_TYPE (ftype) = {
269
union FLOAT_TYPE (ftype) = {
243
    TYPE arg_prom ;
270
    TYPE arg_prom ;
244
    ulong_type ftok = "LINK_NONE" ;
271
    ulong_type ftok = "LINK_NONE" ;
245
    ulong_type ntok = "LINK_NONE" ;
272
    ulong_type ntok = "LINK_NONE" ;
246
    ulong_type diag = "LINK_NONE" ;
273
    ulong_type diag = "LINK_NONE" ;
Line 266... Line 293...
266
    }
293
    }
267
} ;
294
} ;
268
 
295
 
269
 
296
 
270
/*
297
/*
271
    TYPE REPRESENTING CLASS INFORMATION
298
 * TYPE REPRESENTING CLASS INFORMATION
272
 
299
 *
273
    This type is a bitpattern giving information about a class, for example,
300
 * This type is a bitpattern giving information about a class, for example, if
274
    if it is complete, whether it has base classes, non-static data members,
301
 * it is complete, whether it has base classes, non-static data members, and so
275
    and so on.
302
 * on.
276
*/
303
 */
277
 
304
 
278
enum !CLASS_INFO (cinfo) = {
305
enum !CLASS_INFO (cinfo) = {
279
    none =		0,
306
    none =		0,
280
    complete =		1 << 0,		/* completed definition */
307
    complete =		1 << 0,		/* completed definition */
281
    defined =		1 << 1,		/* started definition */
308
    defined =		1 << 1,		/* started definition */
Line 319... Line 346...
319
    default =		implicit | empty | pod
346
    default =		implicit | empty | pod
320
} ;
347
} ;
321
 
348
 
322
 
349
 
323
/*
350
/*
324
    TYPE REPRESENTING CLASS USAGE INFORMATION
351
 * TYPE REPRESENTING CLASS USAGE INFORMATION
325
 
352
 *
326
    This type is a bitpattern used to represent information on how a class
353
 * This type is a bitpattern used to represent information on how a class is
327
    is used.
354
 * used.
328
*/
355
 */
329
 
356
 
330
enum !CLASS_USAGE (cusage) = {
357
enum !CLASS_USAGE (cusage) = {
331
    none =		0,
358
    none =		0,
332
    address =		1 << 0,		/* address of incomplete */
359
    address =		1 << 0,		/* address of incomplete */
333
    destr =		1 << 1,		/* destroyed incomplete */
360
    destr =		1 << 1,		/* destroyed incomplete */
Line 335... Line 362...
335
    delete_array =	1 << 3		/* deleted incomplete array */
362
    delete_array =	1 << 3		/* deleted incomplete array */
336
} ;
363
} ;
337
 
364
 
338
 
365
 
339
/*
366
/*
340
    TYPE REPRESENTING A CLASS TYPE
367
 * TYPE REPRESENTING A CLASS TYPE
341
 
368
 *
342
    A class type has an associated type name, type key (class, struct or
369
 * A class type has an associated type name, type key (class, struct or union),
343
    union), and class information.  The hash table entries for the
370
 * and class information. The hash table entries for the constructors and
344
    constructors and destructors, plus a list of the conversion functions
371
 * destructors, plus a list of the conversion functions on the class are
345
    on the class are maintained within the class definition.  The class
372
 * maintained within the class definition. The class members themselves are
346
    members themselves are just a namespace.  The base classes are
373
 * just a namespace. The base classes are represented by a graph.
347
    represented by a graph.
-
 
348
*/
374
 */
349
 
375
 
350
union CLASS_TYPE (ctype) = {
376
union CLASS_TYPE (ctype) = {
351
    IDENTIFIER name ;
377
    IDENTIFIER name ;
352
    CLASS_INFO info ;
378
    CLASS_INFO info ;
353
    CLASS_USAGE usage ;
379
    CLASS_USAGE usage ;
Line 372... Line 398...
372
    }
398
    }
373
} ;
399
} ;
374
 
400
 
375
 
401
 
376
/*
402
/*
377
    TYPE REPRESENTING A GRAPH OF DERIVED CLASSES
403
 * TYPE REPRESENTING A GRAPH OF DERIVED CLASSES
378
 
404
 *
379
    This type is used to represent the directed acyclic graphs of base
405
 * This type is used to represent the directed acyclic graphs of base classes
380
    classes associated with a class.  Each node of this graph consists
406
 * associated with a class. Each node of this graph consists of a class and a
381
    of a class and a list of its base classes.  The access of each base
407
 * list of its base classes. The access of each base class, and other
382
    class, and other information, is recorded.  Identical virtual bases
408
 * information, is recorded. Identical virtual bases are linked using the equal
383
    are linked using the equal field.  The next field is used to link
409
 * field. The next field is used to link all instances of a class within a
384
    all instances of a class within a graph, whether virtual or not.
410
 * graph, whether virtual or not.
385
*/
411
 */
386
 
412
 
387
union GRAPH (graph) = {
413
union GRAPH (graph) = {
388
    CLASS_TYPE head ;
414
    CLASS_TYPE head ;
389
    DECL_SPEC access ;
415
    DECL_SPEC access ;
390
    LIST GRAPH tails = "NULL_list ( GRAPH )" ;
416
    LIST GRAPH tails = "NULL_list ( GRAPH )" ;
Line 402... Line 428...
402
    }
428
    }
403
} ;
429
} ;
404
 
430
 
405
 
431
 
406
/*
432
/*
407
    TYPE REPRESENTING A VIRTUAL FUNCTION
433
 * TYPE REPRESENTING A VIRTUAL FUNCTION
408
 
434
 *
409
    This type is used to represent a virtual function table or an entry
435
 * This type is used to represent a virtual function table or an entry of such
410
    of such a table.  Each table entry has an associated function plus
436
 * a table. Each table entry has an associated function plus information on
411
    information on where this was inherited from and any difference in
437
 * where this was inherited from and any difference in the return type of an
412
    the return type of an overriding function.
438
 * overriding function.
413
*/
439
 */
414
 
440
 
415
union VIRTUAL (virt) = {
441
union VIRTUAL (virt) = {
416
    IDENTIFIER func ;
442
    IDENTIFIER func ;
417
    ulong_type no ;
443
    ulong_type no ;
418
    GRAPH base ;
444
    GRAPH base ;
Line 451... Line 477...
451
    }
477
    }
452
} ;
478
} ;
453
 
479
 
454
 
480
 
455
/*
481
/*
456
    TYPE REPRESENTING AN ENUMERATION TYPE
482
 * TYPE REPRESENTING AN ENUMERATION TYPE
457
 
483
 *
458
    An enumeration type has an associated type name, a class information
484
 * An enumeration type has an associated type name, a class information field
459
    field (which is only used to indicate whether the type is complete),
485
 * (which is only used to indicate whether the type is complete), and an
460
    and an underlying integral type.  The enumerators themselves are given
486
 * underlying integral type. The enumerators themselves are given as a simple
461
    as a simple list (note that they do not form a namespace).
487
 * list (note that they do not form a namespace).
462
*/
488
 */
463
 
489
 
464
union ENUM_TYPE (etype) = {
490
union ENUM_TYPE (etype) = {
465
    IDENTIFIER name ;
491
    IDENTIFIER name ;
466
    CLASS_INFO info ;
492
    CLASS_INFO info ;
467
    TYPE rep ;
493
    TYPE rep ;
Line 470... Line 496...
470
    EXP value = "NULL_exp" ;
496
    EXP value = "NULL_exp" ;
471
    ulong_type plus = "0" ;
497
    ulong_type plus = "0" ;
472
} + {
498
} + {
473
    basic -> {
499
    basic -> {
474
	/* empty */
500
	/* empty */
475
    }
501
    }
476
} ;
502
} ;
477
 
503
 
478
 
504
 
479
/*
505
/*
480
    TYPE REPRESENTING A TYPE
506
 * TYPE REPRESENTING A TYPE
481
 
507
 *
482
    The types are represented by a union type, with one field per type
508
 * The types are represented by a union type, with one field per type
483
    class.  Any type may be qualified using const, volatile and lvalue.
509
 * class. Any type may be qualified using const, volatile and lvalue.
484
*/
510
 */
485
 
511
 
486
union TYPE (type) = {
512
union TYPE (type) = {
487
    /* Type qualifiers */
513
    /* Type qualifiers */
488
    CV_SPEC qual ;
514
    CV_SPEC qual ;
489
    IDENTIFIER name = "NULL_id" ;
515
    IDENTIFIER name = "NULL_id" ;
490
} + {
516
} + {
491
    pre -> {
517
    pre -> {
492
	/* Pre-types (used during parsing only) */
518
	/* Pre-types (used during parsing only) */
493
	BASE_TYPE rep ;
519
	BASE_TYPE rep ;
494
	QUALIFIER nqual ;
520
	QUALIFIER nqual ;
495
    },
521
    },
496
    integer -> {
522
    integer -> {
497
	/* Integer types */
523
	/* Integer types */
498
	INT_TYPE rep ;
524
	INT_TYPE rep ;
499
	INT_TYPE sem ;
525
	INT_TYPE sem ;
500
    },
526
    },
Line 503... Line 529...
503
	FLOAT_TYPE rep ;
529
	FLOAT_TYPE rep ;
504
	FLOAT_TYPE sem ;
530
	FLOAT_TYPE sem ;
505
    },
531
    },
506
    top, bottom -> {
532
    top, bottom -> {
507
	/* The void types */
533
	/* The void types */
508
    },
534
    },
509
    ptr, ref -> {
535
    ptr, ref -> {
510
	/* Pointer and reference types */
536
	/* Pointer and reference types */
511
	TYPE sub ;
537
	TYPE sub ;
512
    },
538
    },
513
    ptr_mem -> {
539
    ptr_mem -> {
Line 569... Line 595...
569
    }
595
    }
570
} ;
596
} ;
571
 
597
 
572
 
598
 
573
/*
599
/*
574
    TYPE REPRESENTING A DECLARATION SPECIFIER
600
 * TYPE REPRESENTING A DECLARATION SPECIFIER
575
 
601
 *
576
    The basic declaration specifiers (i.e. the storage class specifiers,
602
 * The basic declaration specifiers (i.e. the storage class specifiers, the
577
    the function specifiers, friend and typedef) are represented by an
603
 * function specifiers, friend and typedef) are represented by an enumeration
578
    enumeration type (which is actually a bit pattern).  Other declaration
604
 * type (which is actually a bit pattern). Other declaration and linkage
579
    and linkage information is also included, including access specifiers.
605
 * information is also included, including access specifiers. The fact that
580
    The fact that public < protected < private is used extensively.  The
606
 * public < protected < private is used extensively. The values none, static
581
    values none, static and extern are also used to specify the linkage of
607
 * and extern are also used to specify the linkage of an object.
582
    an object.
-
 
583
*/
608
 */
584
 
609
 
585
enum DECL_SPEC (dspec) = {
610
enum DECL_SPEC (dspec) = {
586
    none =		0,
611
    none =		0,
587
    used =		1 << 0,
612
    used =		1 << 0,
588
    called =		1 << 1,
613
    called =		1 << 1,
Line 636... Line 661...
636
			reserve | temp | template | token | trivial
661
			reserve | temp | template | token | trivial
637
} ;
662
} ;
638
 
663
 
639
 
664
 
640
/*
665
/*
641
    TYPE REPRESENTING A HASH TABLE ENTRY
666
 * TYPE REPRESENTING A HASH TABLE ENTRY
642
 
667
 *
643
    Identifier names are represented by a hash table entry.  There are
668
 * Identifier names are represented by a hash table entry. There are several
644
    several different types of names (simp1e strings, destructor names and
669
 * different types of names (simp1e strings, destructor names and so on). Each
645
    so on).  Each hash table entry contains, in effect, a built-in namespace
670
 * hash table entry contains, in effect, a built-in namespace member indicating
646
    member indicating the underlying meaning of this name.  It also contains
671
 * the underlying meaning of this name. It also contains the hash value for
647
    the hash value for this entry.
672
 * this entry.
648
*/
673
 */
649
 
674
 
650
union HASHID (hashid) = {
675
union HASHID (hashid) = {
651
    IDENTIFIER id = "NULL_id" ;
676
    IDENTIFIER id = "NULL_id" ;
652
    IDENTIFIER cache = "NULL_id" ;
677
    IDENTIFIER cache = "NULL_id" ;
653
    HASHID next ;
678
    HASHID next ;
Line 672... Line 697...
672
    }
697
    }
673
} ;
698
} ;
674
 
699
 
675
 
700
 
676
/*
701
/*
677
    TYPE REPRESENTING AN IDENTIFIER QUALIFIER
702
 * TYPE REPRESENTING AN IDENTIFIER QUALIFIER
678
 
703
 *
679
    These values are used to identify how an identifier is qualified,
704
 * These values are used to identify how an identifier is qualified, either
680
    either unqualified, a nested qualifier (for example A::B::n), a full
705
 * unqualified, a nested qualifier (for example A::B::n), a full nested
681
    nested qualifier (for example ::A::B::n), or a top nested qualifier
706
 * qualifier (for example ::A::B::n), or a top nested qualifier (for example
682
    (for example ::n).  A value to mark resolved overloaded functions
707
 * ::n). A value to mark resolved overloaded functions is also included.
683
    is also included.
-
 
684
*/
708
 */
685
 
709
 
686
enum !QUALIFIER (qual) = {
710
enum !QUALIFIER (qual) = {
687
    none =		0,
711
    none =		0,
688
    nested =		1,
712
    nested =		1,
689
    full =		2,
713
    full =		2,
690
    top =		3,
714
    top =		3,
691
    mark =		4,
715
    mark =		4,
692
    explicit =		nested | full | top
716
    explicit =		nested | full | top
693
} ;
717
} ;
694
 
718
 
695
 
719
 
696
/*
720
/*
697
    TYPE REPRESENTING AN IDENTIFIER
721
 * TYPE REPRESENTING AN IDENTIFIER
698
 
722
 *
699
    Identifiers have an associated hash table entry, indicating the
723
 * Identifiers have an associated hash table entry, indicating the identifier
700
    identifier name, plus a location indicating where the identifier was
724
 * name, plus a location indicating where the identifier was first declared.
701
    first declared.  The various things an identifier can represent are
725
 * The various things an identifier can represent are given by the different
702
    given by the different fields of the union.
726
 * fields of the union.
703
*/
727
 */
704
 
728
 
705
union IDENTIFIER (id) = {
729
union IDENTIFIER (id) = {
706
    HASHID name ;
730
    HASHID name ;
707
    DECL_SPEC storage ;
731
    DECL_SPEC storage ;
708
    NAMESPACE parent ;
732
    NAMESPACE parent ;
Line 766... Line 790...
766
    member -> {
790
    member -> {
767
	/* Simple data member */
791
	/* Simple data member */
768
	TYPE type ;
792
	TYPE type ;
769
	OFFSET off = "NULL_off" ;
793
	OFFSET off = "NULL_off" ;
770
	GRAPH base = "NULL_graph" ;
794
	GRAPH base = "NULL_graph" ;
771
    },
795
    },
772
    enumerator -> {
796
    enumerator -> {
773
	/* Enumerators */
797
	/* Enumerators */
774
	TYPE etype ;
798
	TYPE etype ;
775
	EXP value ;
799
	EXP value ;
776
    },
800
    },
Line 802... Line 826...
802
    }
826
    }
803
} ;
827
} ;
804
 
828
 
805
 
829
 
806
/*
830
/*
807
    TYPE REPRESENTING A NAMESPACE MEMBER
831
 * TYPE REPRESENTING A NAMESPACE MEMBER
808
 
832
 *
809
    There are two kinds of namespace member, small and large, corresponding
833
 * There are two kinds of namespace member, small and large, corresponding to
810
    to the two kinds of namespace.  The important section consists of two
834
 * the two kinds of namespace. The important section consists of two
811
    identifiers, giving the current meanings of a name in the namespace.
835
 * identifiers, giving the current meanings of a name in the namespace.
812
    Everything else is just links to other members.
836
 * Everything else is just links to other members.
813
*/
837
 */
814
 
838
 
815
union MEMBER (member) = {
839
union MEMBER (member) = {
816
    IDENTIFIER id = "NULL_id" ;
840
    IDENTIFIER id = "NULL_id" ;
817
    IDENTIFIER alt = "NULL_id" ;
841
    IDENTIFIER alt = "NULL_id" ;
818
    MEMBER next ;
842
    MEMBER next ;
Line 825... Line 849...
825
    }
849
    }
826
} ;
850
} ;
827
 
851
 
828
 
852
 
829
/*
853
/*
830
    TYPE REPRESENTING A NAMESPACE
854
 * TYPE REPRESENTING A NAMESPACE
831
 
855
 *
832
    There are two kinds of namespace, small and large.  The small namespaces
856
 * There are two kinds of namespace, small and large. The small namespaces are
833
    are the block and parameter spaces, the large ones are the class and
857
 * the block and parameter spaces, the large ones are the class and namespace
834
    namespace spaces.  Every namespace has an associated namespace name
858
 * spaces. Every namespace has an associated namespace name (which may be the
835
    (which may be the null identifier).  A small namespace consists of a
859
 * null identifier). A small namespace consists of a simple linked list of
836
    simple linked list of small members (in reverse order of declaration).
860
 * small members (in reverse order of declaration). A large namespace consists
837
    A large namespace consists of a hash table of large members, plus a list
861
 * of a hash table of large members, plus a list of all such members in order
838
    of all such members in order of declaration.  The distinct orders reflect
862
 * of declaration. The distinct orders reflect the distinct purposes the two
839
    the distinct purposes the two kinds of namespace are put to.
863
 * kinds of namespace are put to.
840
*/
864
 */
841
 
865
 
842
union NAMESPACE (nspace) = {
866
union NAMESPACE (nspace) = {
843
    IDENTIFIER name ;
867
    IDENTIFIER name ;
844
    MEMBER last = "NULL_member" ;
868
    MEMBER last = "NULL_member" ;
845
    MEMBER prev = "NULL_member" ;
869
    MEMBER prev = "NULL_member" ;
Line 861... Line 885...
861
    }
885
    }
862
} ;
886
} ;
863
 
887
 
864
 
888
 
865
/*
889
/*
866
    TYPE REPRESENTING AN INTEGER LITERAL
890
 * TYPE REPRESENTING AN INTEGER LITERAL
867
 
891
 *
868
    An integer literal (or constant integral expression) is represented by
892
 * An integer literal (or constant integral expression) is represented by a
869
    a sign and a list of numbers in the range [0,0xffff] representing the
893
 * sign and a list of numbers in the range [0,0xffff] representing the value
870
    value base 0x10000.  The case where there is only one digit is dealt
894
 * base 0x10000. The case where there is only one digit is dealt with
871
    with separately.  It is also possible to form an integer literal from
895
 * separately. It is also possible to form an integer literal from an
872
    an expression.
896
 * expression.
873
*/
897
 */
874
 
898
 
875
union NAT (nat) = {
899
union NAT (nat) = {
876
    /* empty */
900
    /* empty */
877
} + {
901
} + {
878
    small -> {
902
    small -> {
Line 899... Line 923...
899
    }
923
    }
900
} ;
924
} ;
901
 
925
 
902
 
926
 
903
/*
927
/*
904
    TYPE REPRESENTING A FLOATING POINT LITERAL
928
 * TYPE REPRESENTING A FLOATING POINT LITERAL
905
 
929
 *
906
    A floating point literal is represented by a sign, two strings giving
930
 * A floating point literal is represented by a sign, two strings giving the
907
    the digits before and after the decimal point, plus an exponent.
931
 * digits before and after the decimal point, plus an exponent.
908
*/
932
 */
909
 
933
 
910
union FLOAT (flt) = {
934
union FLOAT (flt) = {
911
    ulong_type tok = "LINK_NONE" ;
935
    ulong_type tok = "LINK_NONE" ;
912
} + {
936
} + {
913
    simple -> {
937
    simple -> {
914
	/* Simple literal */
938
	/* Simple literal */
915
	string int_part ;
939
	string int_part ;
916
	string frac_part ;
940
	string frac_part ;
917
	NAT exponent ;
941
	NAT exponent ;
918
    }
942
    }
919
} ;
943
} ;
920
 
944
 
921
 
945
 
922
/*
946
/*
923
    TYPE REPRESENTING A STRING LITERAL
947
 * TYPE REPRESENTING A STRING LITERAL
924
 
948
 *
925
    A string literal consists of a sequence of characters of a given length.
949
 * A string literal consists of a sequence of characters of a given length.
926
    Characters, wide characters, strings and wide strings are represented
950
 * Characters, wide characters, strings and wide strings are represented by
927
    by distinct fields of the union.
951
 * distinct fields of the union.
928
*/
952
 */
929
 
953
 
930
union STRING (str) = {
954
union STRING (str) = {
931
    STRING next = "NULL_str" ;
955
    STRING next = "NULL_str" ;
932
} + {
956
} + {
933
    simple -> {
957
    simple -> {
Line 939... Line 963...
939
    }
963
    }
940
} ;
964
} ;
941
 
965
 
942
 
966
 
943
/*
967
/*
944
    TYPE REPRESENTING A TEST
968
 * TYPE REPRESENTING A TEST
945
 
969
 *
946
    Test and comparison operators are represented by an enumeration type
970
 * Test and comparison operators are represented by an enumeration type which
947
    which happen to be in the same order as the TDF encoding.  Complementary
971
 * happen to be in the same order as the TDF encoding. Complementary tests
948
    tests (for example '<' and '>=') always add up to the same value, negate.
972
 * (for example '<' and '>=') always add up to the same value, negate.
949
*/
973
 */
950
 
974
 
951
enum !NTEST (ntest) = {
975
enum !NTEST (ntest) = {
952
    eq =		0,
976
    eq =		0,
953
    greater =		1,
977
    greater =		1,
954
    greater_eq =	2,
978
    greater_eq =	2,
Line 962... Line 986...
962
    not_not_eq =	10,
986
    not_not_eq =	10,
963
    none =		11,
987
    none =		11,
964
    negate =		eq + not_eq,
988
    negate =		eq + not_eq,
965
    not =		not_eq,
989
    not =		not_eq,
966
    not_not =		not_not_eq
990
    not_not =		not_not_eq
967
} ;
991
} ;
968
 
992
 
969
 
993
 
970
/*
994
/*
971
    TYPE REPRESENTING A ROUNDING MODE
995
 * TYPE REPRESENTING A ROUNDING MODE
972
 
996
 *
973
    Floating point rounding modes are represented by an enumeration type
997
 * Floating point rounding modes are represented by an enumeration type which
974
    which happen to be in the same order as the TDF encoding.
998
 * happen to be in the same order as the TDF encoding.
975
*/
999
 */
976
 
1000
 
977
enum !RMODE (rmode) = {
1001
enum !RMODE (rmode) = {
978
    as_state =		0,
1002
    as_state =		0,
979
    to_nearest =	1,
1003
    to_nearest =	1,
980
    to_larger =		2,
1004
    to_larger =		2,
981
    to_smaller =	3,
1005
    to_smaller =	3,
982
    to_zero =		4
1006
    to_zero =		4
983
} ;
1007
} ;
984
 
1008
 
985
 
1009
 
986
/*
1010
/*
987
    TYPE REPRESENTING AN EXPRESSION OR STATEMENT
1011
 * TYPE REPRESENTING AN EXPRESSION OR STATEMENT
988
 
1012
 *
989
    The expressions and statements are represented by a union type, with one
1013
 * The expressions and statements are represented by a union type, with one
990
    field per expression or statement class.  Every expression has an
1014
 * field per expression or statement class. Every expression has an associated
991
    associated type.
1015
 * type.
992
*/
1016
 */
993
 
1017
 
994
union EXP (exp) = {
1018
union EXP (exp) = {
995
    /* Expression type */
1019
    /* Expression type */
996
    TYPE type ;
1020
    TYPE type ;
997
} + {
1021
} + {
Line 1196... Line 1220...
1196
	/* Variable analysis operators */
1220
	/* Variable analysis operators */
1197
	EXP arg ;
1221
	EXP arg ;
1198
    },
1222
    },
1199
    reach, unreach -> {
1223
    reach, unreach -> {
1200
	/* Flow analysis operators */
1224
	/* Flow analysis operators */
1201
	EXP parent = "NULL_exp" ;
1225
	EXP parent = "NULL_exp" ;
1202
	EXP body ;
1226
	EXP body ;
1203
    },
1227
    },
1204
    sequence -> {
1228
    sequence -> {
1205
	/* Sequence of statements */
1229
	/* Sequence of statements */
1206
	EXP parent = "NULL_exp" ;
1230
	EXP parent = "NULL_exp" ;
1207
	LIST EXP first, last ;
1231
	LIST EXP first, last ;
Line 1303... Line 1327...
1303
	EXP body ;
1327
	EXP body ;
1304
	ulong_type diag = "LINK_NONE" ;
1328
	ulong_type diag = "LINK_NONE" ;
1305
    },
1329
    },
1306
    exception -> {
1330
    exception -> {
1307
	/* Throw expression */
1331
	/* Throw expression */
1308
	EXP arg ;
1332
	EXP arg ;
1309
	EXP size, destr ;
1333
	EXP size, destr ;
1310
	int expl ;
1334
	int expl ;
1311
    },
1335
    },
1312
    thrown -> {
1336
    thrown -> {
1313
	/* Caught expression */
1337
	/* Caught expression */
Line 1358... Line 1382...
1358
    }
1382
    }
1359
} ;
1383
} ;
1360
 
1384
 
1361
 
1385
 
1362
/*
1386
/*
1363
    TYPE REPRESENTING AN OFFSET
1387
 * TYPE REPRESENTING AN OFFSET
1364
 
1388
 *
1365
    This type is used to represent an offset between two pointers.  The
1389
 * This type is used to represent an offset between two pointers. The type
1366
    type construct gives the offset between successive elements of an
1390
 * construct gives the offset between successive elements of an array of that
1367
    array of that type.  The other constructs are fairly obvious.
1391
 * type. The other constructs are fairly obvious.
1368
*/
1392
 */
1369
 
1393
 
1370
union OFFSET (off) = {
1394
union OFFSET (off) = {
1371
    /* empty */
1395
    /* empty */
1372
} + {
1396
} + {
1373
    zero -> {
1397
    zero -> {
1374
	/* Zero offset */
1398
	/* Zero offset */
1375
	TYPE type ;
1399
	TYPE type ;
1376
    },
1400
    },
1377
    type -> {
1401
    type -> {
1378
	/* Type offset */
1402
	/* Type offset */
1379
	TYPE type ;
1403
	TYPE type ;
1380
    },
1404
    },
1381
    array -> {
1405
    array -> {
1382
	/* Array offset */
1406
	/* Array offset */
Line 1430... Line 1454...
1430
    }
1454
    }
1431
} ;
1455
} ;
1432
 
1456
 
1433
 
1457
 
1434
/*
1458
/*
1435
    TYPE REPRESENTING A TOKEN
1459
 * TYPE REPRESENTING A TOKEN
1436
 
1460
 *
1437
    This type is used to represent a TDF token.  The various fields
1461
 * This type is used to represent a TDF token. The various fields correspond to
1438
    correspond to the kinds of token - expressions, statements, types etc.
1462
 * the kinds of token - expressions, statements, types etc. Each simple
1439
    Each simple component also contains a field for holding a value of
1463
 * component also contains a field for holding a value of that kind, thus a
1440
    that kind, thus a list of token arguments can themselves be expressed
1464
 * list of token arguments can themselves be expressed as a list of tokens.
1441
    as a list of tokens.
-
 
1442
*/
1465
 */
1443
 
1466
 
1444
union TOKEN (tok) = {
1467
union TOKEN (tok) = {
1445
    /* empty */
1468
    /* empty */
1446
} + {
1469
} + {
1447
    exp -> {
1470
    exp -> {
1448
	/* Expression tokens */
1471
	/* Expression tokens */
1449
	TYPE type ;
1472
	TYPE type ;
1450
	int constant ;
1473
	int constant ;
1451
	EXP value ;
1474
	EXP value ;
1452
    },
1475
    },
1453
    stmt -> {
1476
    stmt -> {
1454
	/* Statement tokens */
1477
	/* Statement tokens */
Line 1501... Line 1524...
1501
    }
1524
    }
1502
} ;
1525
} ;
1503
 
1526
 
1504
 
1527
 
1505
/*
1528
/*
1506
    TYPE REPRESENTING A TEMPLATE INSTANCE
1529
 * TYPE REPRESENTING A TEMPLATE INSTANCE
1507
 
1530
 *
1508
    A template instance consists of an identifier, a type giving the
1531
 * A template instance consists of an identifier, a type giving the template
1509
    template form and a specifier giving declaration information.
1532
 * form and a specifier giving declaration information.
1510
*/
1533
 */
1511
 
1534
 
1512
union INSTANCE (inst) = {
1535
union INSTANCE (inst) = {
1513
    TYPE form ;
1536
    TYPE form ;
1514
    INSTANCE alias = "%0" ;
1537
    INSTANCE alias = "%0" ;
1515
    INSTANCE next ;
1538
    INSTANCE next ;
Line 1529... Line 1552...
1529
    }
1552
    }
1530
} ;
1553
} ;
1531
 
1554
 
1532
 
1555
 
1533
/*
1556
/*
1534
    TYPE REPRESENTING A VARIABLE ANALYSIS STATE
1557
 * TYPE REPRESENTING A VARIABLE ANALYSIS STATE
1535
 
1558
 *
1536
    This type is used in the variable analysis routines to record the
1559
 * This type is used in the variable analysis routines to record the state of a
1537
    state of a local variable.
1560
 * local variable.
1538
*/
1561
 */
1539
 
1562
 
1540
struct VARIABLE (var) = {
1563
struct VARIABLE (var) = {
1541
    IDENTIFIER id ;
1564
    IDENTIFIER id ;
1542
    DECL_SPEC info ;
1565
    DECL_SPEC info ;
1543
} ;
1566
} ;
1544
 
1567
 
1545
 
1568
 
1546
/*
1569
/*
1547
    TYPE REPRESENTING AN ERROR
1570
 * TYPE REPRESENTING AN ERROR
1548
 
1571
 *
1549
    An error can be either a simple message, described by an error number,
1572
 * An error can be either a simple message, described by an error number, or a
1550
    or a compound formed from two other errors.  Some trickery is used to
1573
 * compound formed from two other errors. Some trickery is used to store the
1551
    store the arguments for a simple error after its size field.
1574
 * arguments for a simple error after its size field.
1552
*/
1575
 */
1553
 
1576
 
1554
union ERROR (err) = {
1577
union ERROR (err) = {
1555
    int severity ;
1578
    int severity ;
1556
} + {
1579
} + {
1557
    simple -> {
1580
    simple -> {
Line 1563... Line 1586...
1563
    compound -> {
1586
    compound -> {
1564
	/* Compound errors */
1587
	/* Compound errors */
1565
	ERROR head, tail ;
1588
	ERROR head, tail ;
1566
    }
1589
    }
1567
} ;
1590
} ;
1568
 
1591
 
1569
 
1592
 
1570
/*
1593
/*
1571
    TYPE REPRESENTING A FILE POSITION
1594
 * TYPE REPRESENTING A FILE POSITION
1572
 
1595
 *
1573
    A file position consists of a line number plus a pointer to a type
1596
 * A file position consists of a line number plus a pointer to a type giving
1574
    giving the file name.
1597
 * the file name.
1575
*/
1598
 */
1576
 
1599
 
1577
struct LOCATION (loc) = {
1600
struct LOCATION (loc) = {
1578
    ulong_type line ;
1601
    ulong_type line ;
1579
    ulong_type column ;
1602
    ulong_type column ;
1580
    PTR POSITION posn ;
1603
    PTR POSITION posn ;