Subversion Repositories tendra.SVN

Rev

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

Rev Author Line No. Line
2 7u83 1
/*
7 7u83 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
 */
31
/*
2 7u83 32
    		 Crown Copyright (c) 1997, 1998
33
 
34
    This TenDRA(r) Computer Program is subject to Copyright
35
    owned by the United Kingdom Secretary of State for Defence
36
    acting through the Defence Evaluation and Research Agency
37
    (DERA).  It is made available to Recipients with a
38
    royalty-free licence for its use, reproduction, transfer
39
    to other parties and amendment for any purpose not excluding
40
    product development provided that any such use et cetera
41
    shall be deemed to be acceptance of the following conditions:-
42
 
43
        (1) Its Recipients shall ensure that this Notice is
44
        reproduced upon any copies or amended versions of it;
45
 
46
        (2) Any amended version of it shall be clearly marked to
47
        show both the nature of and the organisation responsible
48
        for the relevant amendment or amendments;
49
 
50
        (3) Its onward transfer from a recipient to another
51
        party shall be deemed to be that party's acceptance of
52
        these conditions;
53
 
54
        (4) DERA gives no warranty or assurance as to its
55
        quality or suitability for any purpose and DERA accepts
56
        no liability whatsoever in relation to any use to which
57
        it may be put.
58
*/
59
 
60
 
61
/*
7 7u83 62
 * TYPE SYSTEM SPECIFICATION
63
 *
64
 * The main type system for the program is specified using the calculus tool.
65
 * This generates two representations of the type algebra, c_class. The files
66
 * in obj_tok describe the output type system abstractly in terms of the TenDRA
67
 * '#pragma token' constructs. These may be used to apply extremely rigorous
68
 * type checking to the program. The files in obj_c give the implementation of
69
 * the type system in C terms. The implementation specific parts of the
70
 * program, including the memory management, is handled in obj_c/c_class.c.
71
 */
2 7u83 72
 
73
ALGEBRA c_class (1.1) :
74
 
75
 
76
/*
7 7u83 77
 * PRIMITIVE TYPES
78
 *
79
 * These are the primitive types from which the algebra is built. int, unsigned
80
 * and string are self-explanitory. BITSTREAM_P represents a series of bits,
81
 * and is used to hold any compiled code. PPTOKEN_P represents a list of
82
 * preprocessing tokens, and is used in macro definitions etc.
83
 */
2 7u83 84
 
85
int =			"int" ;
86
unsigned =		"unsigned" ;
87
string =		"character *" ;
88
ulong_type (ulong) =	"unsigned long" ;
89
BITSTREAM_P (bits) =	"struct bits_tag *" ;
90
PPTOKEN_P (pptok) =	"struct pptok_tag *" ;
91
 
92
 
93
/*
7 7u83 94
 * TYPE REPRESENTING A CONST-VOLATILE SPECIFIER
95
 *
96
 * The const and volatile type qualifiers are represented by an enumeration
97
 * type (which is actually a bit pattern). An additional value is used to
98
 * indicate lvalues. Type linkage specifiers are also included.
99
 */
2 7u83 100
 
101
enum !CV_SPEC (cv) = {
102
    none =		0,
103
    const =		1 << 0,
104
    volatile =		1 << 1,
105
    lvalue =		1 << 2,
106
 
107
    c =			1 << 3,
108
    cpp =		1 << 4,
109
 
110
    qual =		const | volatile,
111
    mask =		qual | lvalue,
112
    language =		c | cpp
113
} ;
114
 
115
 
116
/*
7 7u83 117
 * TYPE REPRESENTING A BUILT-IN TYPE
118
 *
119
 * The built-in types have two representations - as a BASE_TYPE (see below) or
120
 * as a BUILTIN_TYPE. The latter is used primarily as an index into various
121
 * tables.
122
 */
2 7u83 123
 
124
enum !BUILTIN_TYPE (ntype) = {
125
    none =		0,
126
    char =		1,
127
    schar =		2,
128
    uchar =		3,
129
    sshort =		4,
130
    ushort =		5,
131
    sint =		6,
132
    uint =		7,
133
    slong =		8,
134
    ulong =		9,
135
    sllong =		10,
136
    ullong =		11,
137
    float =		12,
138
    double =		13,
139
    ldouble =		14,
140
    void =		15,
141
    bottom =		16,
142
    bool =		17,
143
    ptrdiff_t =		18,
144
    size_t =		19,
145
    wchar_t =		20,
146
    ellipsis =		21
147
} ;
148
 
149
 
150
/*
7 7u83 151
 * TYPE REPRESENTING A BASIC TYPE
152
 *
153
 * The basic types are represented by an enumeration type (which is actually a
154
 * bit pattern except for the named type component). The composite bitpatterns
155
 * for the maximally valid combinations are also given. The elaborated type
156
 * keys are also represented by this type.
157
 */
2 7u83 158
 
159
enum !BASE_TYPE (btype) = {
160
    none =		0,
161
    class =		1,
162
    struct_ =		2,
163
    union_ =		3,
164
    enum_ =		4,
165
    alias =		5,
166
    any =		6,
167
    named =		7,
168
 
169
    signed =		1 << 3,
170
    unsigned =		1 << 4,
171
    char =		1 << 5,
172
    short =		1 << 6,
173
    int =		1 << 7,
174
    long =		1 << 8,
175
    long2 =		1 << 9,
176
    float =		1 << 10,
177
    double =		1 << 11,
178
    void =		1 << 12,
179
    bottom =		1 << 13,
180
    bool =		1 << 14,
181
    ptrdiff_t =		1 << 15,
182
    size_t =		1 << 16,
183
    wchar_t =		1 << 17,
184
 
185
    schar =		signed | char,
186
    uchar =		unsigned | char,
187
    sshort =		signed | short | int,
188
    ushort =		unsigned | short | int,
189
    sint =		signed | int,
190
    uint =		unsigned | int,
191
    slong =		signed | long | int,
192
    ulong =		unsigned | long | int,
193
    llong =		long | long2,
194
    sllong =		signed | llong | int,
195
    ullong =		unsigned | llong | int,
196
    ldouble =		long | double,
197
 
198
    ellipsis =		1 << 18,
199
    star =		1 << 19,
200
    template =		1 << 20,
201
    typename =		1 << 21,
202
    args =		1 << 22,
203
    keyword =		float | double | void | bool | wchar_t,
204
    other =		keyword | bottom | ptrdiff_t | size_t,
205
    arith =		int | float,
206
    scalar =		int | float | star
207
} ;
208
 
209
 
210
/*
7 7u83 211
 * TYPE REPRESENTING AN INTEGRAL TYPE
212
 *
213
 * An integral type can be one of the built-in types, an integral promotion
214
 * type or an arithmetic conversion type. The promotion type for each integral
215
 * type is stored as part of its definition.
216
 */
2 7u83 217
 
218
union INT_TYPE (itype) = {
219
    TYPE prom ;
220
    LIST TYPE cases ;
221
    BUILTIN_TYPE unprom = "ntype_none" ;
222
    ulong_type itok = "LINK_NONE" ;
223
    ulong_type ntok = "LINK_NONE" ;
224
    ulong_type diag = "LINK_NONE" ;
225
} + {
226
    basic -> {
227
	/* Built-in types */
228
	BASE_TYPE rep ;
229
	BUILTIN_TYPE no ;
230
    },
231
    bitfield -> {
232
	/* Bitfield types */
233
	TYPE sub ;
234
	BASE_TYPE rep ;
235
	NAT size ;
236
	DECL_SPEC info ;
237
    },
238
    promote -> {
239
	/* Promotion types */
240
	INT_TYPE arg ;
241
    },
242
    arith -> {
243
	/* Arithmetic conversion types */
244
	INT_TYPE arg1, arg2 ;
245
    },
246
    literal -> {
247
	/* Target dependent literal type */
248
	NAT nat ;
249
	int spec ;
250
	int form, suff ;
251
	IDENTIFIER tok ;
252
    },
253
    token -> {
254
	/* Tokenised integral type */
255
	IDENTIFIER tok ;
256
	LIST TOKEN args ;
257
    }
258
} ;
259
 
260
 
261
/*
7 7u83 262
 * TYPE REPRESENTING A FLOATING POINT TYPE
263
 *
264
 * A floating point type can be one of the built-in types or an arithmetic
265
 * conversion type. Note that all floating point types are their own arithmetic
266
 * promotions, but they do have distinct argument promotions.
267
 */
2 7u83 268
 
269
union FLOAT_TYPE (ftype) = {
270
    TYPE arg_prom ;
271
    ulong_type ftok = "LINK_NONE" ;
272
    ulong_type ntok = "LINK_NONE" ;
273
    ulong_type diag = "LINK_NONE" ;
274
    LIST FLOAT small = "NULL_list ( FLOAT )" ;
275
} + {
276
    basic -> {
277
	/* Built-in types */
278
	BASE_TYPE rep ;
279
	BUILTIN_TYPE no ;
280
    },
281
    arg_promote -> {
282
	/* Argument promotion types */
283
	FLOAT_TYPE arg ;
284
    },
285
    arith -> {
286
	/* Arithmetic conversion types */
287
	FLOAT_TYPE arg1, arg2 ;
288
    },
289
    token -> {
290
	/* Tokenised floating type */
291
	IDENTIFIER tok ;
292
	LIST TOKEN args ;
293
    }
294
} ;
295
 
296
 
297
/*
7 7u83 298
 * TYPE REPRESENTING CLASS INFORMATION
299
 *
300
 * This type is a bitpattern giving information about a class, for example, if
301
 * it is complete, whether it has base classes, non-static data members, and so
302
 * on.
303
 */
2 7u83 304
 
305
enum !CLASS_INFO (cinfo) = {
306
    none =		0,
307
    complete =		1 << 0,		/* completed definition */
308
    defined =		1 << 1,		/* started definition */
309
    struct_ =		1 << 2,		/* structure class */
310
    union_ =		1 << 3,		/* union class */
311
    template =		1 << 4,		/* template class */
312
    token =		1 << 5,		/* tokenised structure */
313
    pod =		1 << 6,		/* plain ol' data structure */
314
    nested =		1 << 7,		/* is nested class */
315
    rescan =		1 << 8,		/* expands by rescanning */
316
    recursive =		1 << 9,		/* recursively defined */
317
    incomplete =	1 << 10,	/* warn if not completed */
318
    base =		1 << 11,	/* has base class */
319
    multiple_base =	1 << 12,	/* multiple inheritance */
320
    virtual_base =	1 << 13,	/* has virtual base class */
321
    templ_base =	1 << 14,	/* has template base class */
322
    ambiguous =		1 << 15,	/* has ambiguous base class */
323
    empty =		1 << 16,	/* empty class */
324
    private =		1 << 17,	/* non-public data member */
325
    const =		1 << 18,	/* const data member */
326
    static =		1 << 19,	/* static data member */
327
    function =		1 << 20,	/* function member */
328
    params =		1 << 21,	/* layout dependent on parameters */
329
    polymorphic =	1 << 22,	/* virtual function */
330
    poly_base =		1 << 23,	/* polymorphic base class */
331
    abstract =		1 << 24,	/* pure function */
332
    trivial_constr =	1 << 25,	/* trivial constructor */
333
    trivial_destr =	1 << 26,	/* trivial destructor */
334
    trivial_copy =	1 << 27,	/* trivial copy constructor */
335
    trivial_assign =	1 << 28,	/* trivial assign operator */
336
    const_copy =	1 << 29,	/* const copy constructor */
337
    const_assign =	1 << 30,	/* const assign operator */
338
    usr_constr =	1 << 31,	/* user defined constructor */
339
 
340
    key =		struct_ | union_,
341
    non_aggregate =	private | usr_constr | base | polymorphic | token,
342
    force_copy =	static | function | params,
343
    trivial_make =	trivial_constr | trivial_copy | trivial_assign,
344
    trivial =		trivial_make | trivial_destr,
345
    implicit =		trivial | const_copy | const_assign,
346
    default =		implicit | empty | pod
347
} ;
348
 
349
 
350
/*
7 7u83 351
 * TYPE REPRESENTING CLASS USAGE INFORMATION
352
 *
353
 * This type is a bitpattern used to represent information on how a class is
354
 * used.
355
 */
2 7u83 356
 
357
enum !CLASS_USAGE (cusage) = {
358
    none =		0,
359
    address =		1 << 0,		/* address of incomplete */
360
    destr =		1 << 1,		/* destroyed incomplete */
361
    delete =		1 << 2,		/* deleted incomplete */
362
    delete_array =	1 << 3		/* deleted incomplete array */
363
} ;
364
 
365
 
366
/*
7 7u83 367
 * TYPE REPRESENTING A CLASS TYPE
368
 *
369
 * A class type has an associated type name, type key (class, struct or union),
370
 * and class information. The hash table entries for the constructors and
371
 * destructors, plus a list of the conversion functions on the class are
372
 * maintained within the class definition. The class members themselves are
373
 * just a namespace. The base classes are represented by a graph.
374
 */
2 7u83 375
 
376
union CLASS_TYPE (ctype) = {
377
    IDENTIFIER name ;
378
    CLASS_INFO info ;
379
    CLASS_USAGE usage ;
380
    NAMESPACE member ;
381
    GRAPH base ;
382
    unsigned no_bases ;
383
    TYPE prev ;
384
    TYPE form = "NULL_type" ;
385
    IDENTIFIER constr = "NULL_id" ;
386
    IDENTIFIER destr = "NULL_id" ;
387
    VIRTUAL virt = "NULL_virt" ;
388
    LIST GRAPH vbase = "NULL_list ( GRAPH )" ;
389
    LIST IDENTIFIER conv = "NULL_list ( IDENTIFIER )" ;
390
    LIST CLASS_TYPE chums = "NULL_list ( CLASS_TYPE )" ;
391
    LIST IDENTIFIER pals = "NULL_list ( IDENTIFIER )" ;
392
    LIST IDENTIFIER nest = "NULL_list ( IDENTIFIER )" ;
393
    ulong_type tok1 = "LINK_NONE" ;
394
    ulong_type tok2 = "LINK_NONE" ;
395
} + {
396
    basic -> {
397
	/* empty */
398
    }
399
} ;
400
 
401
 
402
/*
7 7u83 403
 * TYPE REPRESENTING A GRAPH OF DERIVED CLASSES
404
 *
405
 * This type is used to represent the directed acyclic graphs of base classes
406
 * associated with a class. Each node of this graph consists of a class and a
407
 * list of its base classes. The access of each base class, and other
408
 * information, is recorded. Identical virtual bases are linked using the equal
409
 * field. The next field is used to link all instances of a class within a
410
 * graph, whether virtual or not.
411
 */
2 7u83 412
 
413
union GRAPH (graph) = {
414
    CLASS_TYPE head ;
415
    DECL_SPEC access ;
416
    LIST GRAPH tails = "NULL_list ( GRAPH )" ;
417
    GRAPH top = "NULL_graph" ;
418
    GRAPH equal = "NULL_graph" ;
419
    GRAPH up = "NULL_graph" ;
420
    unsigned no = "0" ;
421
    OFFSET off = "NULL_off" ;
422
    LIST IDENTIFIER member = "NULL_list ( IDENTIFIER )" ;
423
    ulong_type tok1 = "LINK_NONE" ;
424
    ulong_type tok2 = "LINK_NONE" ;
425
} + {
426
    basic -> {
427
	/* empty */
428
    }
429
} ;
430
 
431
 
432
/*
7 7u83 433
 * TYPE REPRESENTING A VIRTUAL FUNCTION
434
 *
435
 * This type is used to represent a virtual function table or an entry of such
436
 * a table. Each table entry has an associated function plus information on
437
 * where this was inherited from and any difference in the return type of an
438
 * overriding function.
439
 */
2 7u83 440
 
441
union VIRTUAL (virt) = {
442
    IDENTIFIER func ;
443
    ulong_type no ;
444
    GRAPH base ;
445
    VIRTUAL next = "NULL_virt" ;
446
} + {
447
    table -> {
448
	/* Virtual function table */
449
	OFFSET off ;
450
	LIST VIRTUAL entries = "NULL_list ( VIRTUAL )" ;
451
	ulong_type tok = "LINK_NONE" ;
452
	ulong_type tbl = "LINK_NONE" ;
453
	ulong_type rtti = "LINK_NONE" ;
454
	int rtti_used = "0" ;
455
    },
456
    simple -> {
457
	/* New virtual function */
458
    },
459
    override -> {
460
	/* Overriding virtual function */
461
	GRAPH ret ;
462
	IDENTIFIER orig ;
463
	GRAPH src ;
464
    },
465
    inherit -> {
466
	/* Inherited primary function */
467
    },
468
    complex -> {
469
	/* Inherited overriding virtual function */
470
	GRAPH ret ;
471
	IDENTIFIER orig ;
472
	GRAPH src ;
473
    },
474
    link -> {
475
	/* Symbolic link */
476
	PTR VIRTUAL to ;
477
    }
478
} ;
479
 
480
 
481
/*
7 7u83 482
 * TYPE REPRESENTING AN ENUMERATION TYPE
483
 *
484
 * An enumeration type has an associated type name, a class information field
485
 * (which is only used to indicate whether the type is complete), and an
486
 * underlying integral type. The enumerators themselves are given as a simple
487
 * list (note that they do not form a namespace).
488
 */
2 7u83 489
 
490
union ENUM_TYPE (etype) = {
491
    IDENTIFIER name ;
492
    CLASS_INFO info ;
493
    TYPE rep ;
494
    TYPE form = "NULL_type" ;
495
    LIST IDENTIFIER values = "NULL_list ( IDENTIFIER )" ;
496
    EXP value = "NULL_exp" ;
497
    ulong_type plus = "0" ;
498
} + {
499
    basic -> {
500
	/* empty */
501
    }
502
} ;
503
 
504
 
505
/*
7 7u83 506
 * TYPE REPRESENTING A TYPE
507
 *
508
 * The types are represented by a union type, with one field per type
509
 * class. Any type may be qualified using const, volatile and lvalue.
510
 */
2 7u83 511
 
512
union TYPE (type) = {
513
    /* Type qualifiers */
514
    CV_SPEC qual ;
515
    IDENTIFIER name = "NULL_id" ;
516
} + {
517
    pre -> {
518
	/* Pre-types (used during parsing only) */
519
	BASE_TYPE rep ;
520
	QUALIFIER nqual ;
521
    },
522
    integer -> {
523
	/* Integer types */
524
	INT_TYPE rep ;
525
	INT_TYPE sem ;
526
    },
527
    floating -> {
528
	/* Floating point types */
529
	FLOAT_TYPE rep ;
530
	FLOAT_TYPE sem ;
531
    },
532
    top, bottom -> {
533
	/* The void types */
534
    },
535
    ptr, ref -> {
536
	/* Pointer and reference types */
537
	TYPE sub ;
538
    },
539
    ptr_mem -> {
540
	/* Pointer to member types */
541
	CLASS_TYPE of ;
542
	TYPE sub ;
543
    },
544
    func -> {
545
	/* Function types */
546
	TYPE ret ;
547
	LIST TYPE ptypes ;
548
	int ellipsis ;
549
	CV_SPEC mqual ;
550
	LIST TYPE mtypes ;
551
	NAMESPACE pars ;
552
	LIST IDENTIFIER pids ;
553
	LIST TYPE except ;
554
    },
555
    array -> {
556
	/* Array types */
557
	TYPE sub ;
558
	NAT size ;
559
    },
560
    bitfield -> {
561
	/* Bitfield types */
562
	INT_TYPE defn ;
563
    },
564
    compound -> {
565
	/* Class types */
566
	CLASS_TYPE defn ;
567
    },
568
    enumerate -> {
569
	/* Enumeration types */
570
	ENUM_TYPE defn ;
571
    },
572
    token -> {
573
	/* Tokenised type */
574
	IDENTIFIER tok ;
575
	LIST TOKEN args ;
576
	INSTANCE app = "NULL_inst" ;
577
    },
578
    templ -> {
579
	/* Template type */
580
	TOKEN sort ;
581
	TYPE defn ;
582
	int fix ;
583
    },
584
    instance -> {
585
	/* Template member type */
586
	IDENTIFIER id ;
587
	DECL_SPEC access ;
588
    },
589
    dummy -> {
590
	/* Dummy special token type */
591
	int tok ;
592
    },
593
    error -> {
594
	/* Error propagation type */
595
    }
596
} ;
597
 
598
 
599
/*
7 7u83 600
 * TYPE REPRESENTING A DECLARATION SPECIFIER
601
 *
602
 * The basic declaration specifiers (i.e. the storage class specifiers, the
603
 * function specifiers, friend and typedef) are represented by an enumeration
604
 * type (which is actually a bit pattern). Other declaration and linkage
605
 * information is also included, including access specifiers. The fact that
606
 * public < protected < private is used extensively. The values none, static
607
 * and extern are also used to specify the linkage of an object.
608
 */
2 7u83 609
 
610
enum DECL_SPEC (dspec) = {
611
    none =		0,
612
    used =		1 << 0,
613
    called =		1 << 1,
614
    defn =		1 << 2,
615
    inherit =		1 << 3,
616
    alias =		1 << 4,
617
    done =		1 << 5,
618
 
619
    static =		1 << 6,
620
    extern =		1 << 7,
621
    auto =		1 << 8,
622
    register =		1 << 9,
623
    mutable =		1 << 10,
624
    inline =		1 << 11,
625
    virtual =		1 << 12,
626
    explicit =		1 << 13,
627
    friend =		1 << 14,
628
    typedef =		1 << 15,
629
 
630
    public =		1 << 16,
631
    protected =		2 << 16,
632
    private =		3 << 16,
633
 
634
    public2 =		public << 2,
635
    protected2 =	protected << 2,
636
    private2 =		private << 2,
637
 
638
    c =			1 << 20,
639
    cpp =		1 << 21,
640
 
641
    ignore =		1 << 22,
642
    implicit =		1 << 23,
643
    instance =		1 << 24,
644
    main =		1 << 25,
645
    pure =		1 << 26,
646
    reserve =		1 << 27,
647
    temp =		1 << 28,
648
    template =		1 << 29,
649
    token =		1 << 30,
650
    trivial =		1 << 31,
651
 
652
    linkage =		static | extern,
653
    storage =		static | extern | auto | register | mutable,
654
    function =		inline | virtual | explicit,
655
    keyword =		storage | function | friend | typedef,
656
    duplicate =		keyword,
657
    access =		public | protected | private,
658
    access2 =		public2 | protected2 | private2,
659
    language =		c | cpp,
660
    other =		ignore | implicit | instance | main | pure |
661
			reserve | temp | template | token | trivial
662
} ;
663
 
664
 
665
/*
7 7u83 666
 * TYPE REPRESENTING A HASH TABLE ENTRY
667
 *
668
 * Identifier names are represented by a hash table entry. There are several
669
 * different types of names (simp1e strings, destructor names and so on). Each
670
 * hash table entry contains, in effect, a built-in namespace member indicating
671
 * the underlying meaning of this name. It also contains the hash value for
672
 * this entry.
673
 */
2 7u83 674
 
675
union HASHID (hashid) = {
676
    IDENTIFIER id = "NULL_id" ;
677
    IDENTIFIER cache = "NULL_id" ;
678
    HASHID next ;
679
    ulong_type hash ;
680
} + {
681
    name, ename -> {
682
	/* Simple and extended identifiers */
683
	string text ;
684
    },
685
    constr, destr, conv -> {
686
	/* Constructors, destructors and conversion functions */
687
	TYPE type ;
688
	IDENTIFIER tid ;
689
    },
690
    op -> {
691
	/* Overloaded operator name */
692
	int lex ;
693
    },
694
    anon -> {
695
	/* Unnamed identifier */
696
	ulong_type uniq ;
697
    }
698
} ;
699
 
700
 
701
/*
7 7u83 702
 * TYPE REPRESENTING AN IDENTIFIER QUALIFIER
703
 *
704
 * These values are used to identify how an identifier is qualified, either
705
 * unqualified, a nested qualifier (for example A::B::n), a full nested
706
 * qualifier (for example ::A::B::n), or a top nested qualifier (for example
707
 * ::n). A value to mark resolved overloaded functions is also included.
708
 */
2 7u83 709
 
710
enum !QUALIFIER (qual) = {
711
    none =		0,
712
    nested =		1,
713
    full =		2,
714
    top =		3,
715
    mark =		4,
716
    explicit =		nested | full | top
717
} ;
718
 
719
 
720
/*
7 7u83 721
 * TYPE REPRESENTING AN IDENTIFIER
722
 *
723
 * Identifiers have an associated hash table entry, indicating the identifier
724
 * name, plus a location indicating where the identifier was first declared.
725
 * The various things an identifier can represent are given by the different
726
 * fields of the union.
727
 */
2 7u83 728
 
729
union IDENTIFIER (id) = {
730
    HASHID name ;
731
    DECL_SPEC storage ;
732
    NAMESPACE parent ;
733
    LOCATION loc ;
734
    IDENTIFIER alias = "%0" ;
735
    ulong_type no = "LINK_NONE" ;
736
    ulong_type dump = "LINK_NONE" ;
737
} + {
738
    dummy -> {
739
	/* Undefined identifier */
740
    },
741
    keyword, iso_keyword, reserved -> {
742
	/* Keywords */
743
    },
744
    builtin -> {
745
	/* Built-in operators */
746
	TYPE ret ;
747
	LIST TYPE ptypes ;
748
    },
749
    obj_macro -> {
750
	/* Object-like macros */
751
	PPTOKEN_P defn ;
752
    },
753
    func_macro -> {
754
	/* Function-like macros */
755
	PPTOKEN_P defn ;
756
	LIST HASHID params ;
757
	unsigned no_params ;
758
    },
759
    predicate -> {
760
	/* Predicates */
761
	LIST PPTOKEN_P values = "NULL_list ( PPTOKEN_P )" ;
762
    },
763
    class_name, enum_name,
764
    class_alias, enum_alias, type_alias -> {
765
	/* Type names */
766
	TYPE defn ;
767
	BASE_TYPE rep = "btype_none" ;
768
    },
769
    nspace_name, nspace_alias -> {
770
	/* Namespace names */
771
	NAMESPACE defn ;
772
    },
773
    variable, parameter, stat_member -> {
774
	/* Variables (including static members) */
775
	TYPE type ;
776
	EXP init = "NULL_exp" ;
777
	EXP term = "NULL_exp" ;
778
    },
779
    weak_param -> {
780
	/* Non-prototype function parameters */
781
    },
782
    function, mem_func, stat_mem_func -> {
783
	/* Functions (including member functions) */
784
	TYPE type ;
785
	IDENTIFIER over ;
786
	TYPE form = "NULL_type" ;
787
	LIST CLASS_TYPE chums = "NULL_list ( CLASS_TYPE )" ;
788
	EXP defn = "NULL_exp" ;
789
    },
790
    member -> {
791
	/* Simple data member */
792
	TYPE type ;
793
	OFFSET off = "NULL_off" ;
794
	GRAPH base = "NULL_graph" ;
795
    },
796
    enumerator -> {
797
	/* Enumerators */
798
	TYPE etype ;
799
	EXP value ;
800
    },
801
    label -> {
802
	/* Labels */
803
	int op ;
804
	EXP stmt = "NULL_exp" ;
805
	EXP gotos = "NULL_exp" ;
806
	LIST VARIABLE vars = "NULL_list ( VARIABLE )" ;
807
    },
808
    token -> {
809
	/* Tokens */
810
	TOKEN sort ;
811
	IDENTIFIER alt ;
812
    },
813
    ambig -> {
814
	/* Ambiguous identifier */
815
	LIST IDENTIFIER ids ;
816
	int over ;
817
    },
818
    undef -> {
819
	/* Undefined identifier */
820
	TYPE form = "NULL_type" ;
821
    },
822
    pending -> {
823
	/* Pending identifier (used in spec input) */
824
	unsigned itag ;
825
	TYPE type ;
826
    }
827
} ;
828
 
829
 
830
/*
7 7u83 831
 * TYPE REPRESENTING A NAMESPACE MEMBER
832
 *
833
 * There are two kinds of namespace member, small and large, corresponding to
834
 * the two kinds of namespace. The important section consists of two
835
 * identifiers, giving the current meanings of a name in the namespace.
836
 * Everything else is just links to other members.
837
 */
2 7u83 838
 
839
union MEMBER (member) = {
840
    IDENTIFIER id = "NULL_id" ;
841
    IDENTIFIER alt = "NULL_id" ;
842
    MEMBER next ;
843
} + {
844
    small -> {
845
	/* empty */
846
    },
847
    large -> {
848
	MEMBER tnext ;
849
    }
850
} ;
851
 
852
 
853
/*
7 7u83 854
 * TYPE REPRESENTING A NAMESPACE
855
 *
856
 * There are two kinds of namespace, small and large. The small namespaces are
857
 * the block and parameter spaces, the large ones are the class and namespace
858
 * spaces. Every namespace has an associated namespace name (which may be the
859
 * null identifier). A small namespace consists of a simple linked list of
860
 * small members (in reverse order of declaration). A large namespace consists
861
 * of a hash table of large members, plus a list of all such members in order
862
 * of declaration. The distinct orders reflect the distinct purposes the two
863
 * kinds of namespace are put to.
864
 */
2 7u83 865
 
866
union NAMESPACE (nspace) = {
867
    IDENTIFIER name ;
868
    MEMBER last = "NULL_member" ;
869
    MEMBER prev = "NULL_member" ;
870
    NAMESPACE parent ;
871
    LIST NAMESPACE use = "NULL_list ( NAMESPACE )" ;
872
    LIST NAMESPACE join = "NULL_list ( NAMESPACE )" ;
873
    STACK IDENTIFIER set = "NULL_stack ( IDENTIFIER )" ;
874
    ulong_type dump = "LINK_NONE" ;
875
} + {
876
    block, param, dummy, label, templ -> {
877
	/* Member list */
878
    },
879
    named, unnamed, global, ctype -> {
880
	/* Member hash table */
881
	MEMBER first = "NULL_member" ;
882
	LIST IDENTIFIER extra = "NULL_list ( IDENTIFIER )" ;
883
	ulong_type size ;
884
	PTR MEMBER table ;
885
    }
886
} ;
887
 
888
 
889
/*
7 7u83 890
 * TYPE REPRESENTING AN INTEGER LITERAL
891
 *
892
 * An integer literal (or constant integral expression) is represented by a
893
 * sign and a list of numbers in the range [0,0xffff] representing the value
894
 * base 0x10000. The case where there is only one digit is dealt with
895
 * separately. It is also possible to form an integer literal from an
896
 * expression.
897
 */
2 7u83 898
 
899
union NAT (nat) = {
900
    /* empty */
901
} + {
902
    small -> {
903
	/* Single digit */
904
	unsigned value ;
905
    },
906
    large -> {
907
	/* Multiple digits */
908
	LIST unsigned values ;
909
    },
910
    calc -> {
911
	/* Calculated value */
912
	EXP value ;
913
	ulong_type tok = "LINK_NONE" ;
914
    },
915
    neg -> {
916
	/* Negation */
917
	NAT arg ;
918
    },
919
    token -> {
920
	/* Tokenised expression */
921
	IDENTIFIER tok ;
922
	LIST TOKEN args ;
923
    }
924
} ;
925
 
926
 
927
/*
7 7u83 928
 * TYPE REPRESENTING A FLOATING POINT LITERAL
929
 *
930
 * A floating point literal is represented by a sign, two strings giving the
931
 * digits before and after the decimal point, plus an exponent.
932
 */
2 7u83 933
 
934
union FLOAT (flt) = {
935
    ulong_type tok = "LINK_NONE" ;
936
} + {
937
    simple -> {
938
	/* Simple literal */
939
	string int_part ;
940
	string frac_part ;
941
	NAT exponent ;
942
    }
943
} ;
944
 
945
 
946
/*
7 7u83 947
 * TYPE REPRESENTING A STRING LITERAL
948
 *
949
 * A string literal consists of a sequence of characters of a given length.
950
 * Characters, wide characters, strings and wide strings are represented by
951
 * distinct fields of the union.
952
 */
2 7u83 953
 
954
union STRING (str) = {
955
    STRING next = "NULL_str" ;
956
} + {
957
    simple -> {
958
	/* Simple literals */
959
	ulong_type len ;
960
	string text ;
961
	unsigned kind ;
962
	ulong_type tok = "LINK_NONE" ;
963
    }
964
} ;
965
 
966
 
967
/*
7 7u83 968
 * TYPE REPRESENTING A TEST
969
 *
970
 * Test and comparison operators are represented by an enumeration type which
971
 * happen to be in the same order as the TDF encoding. Complementary tests
972
 * (for example '<' and '>=') always add up to the same value, negate.
973
 */
2 7u83 974
 
975
enum !NTEST (ntest) = {
976
    eq =		0,
977
    greater =		1,
978
    greater_eq =	2,
979
    less =		3,
980
    less_eq =		4,
981
    not_eq =		5,
982
    not_greater =	6,
983
    not_greater_eq =	7,
984
    not_less =		8,
985
    not_less_eq =	9,
986
    not_not_eq =	10,
987
    none =		11,
988
    negate =		eq + not_eq,
989
    not =		not_eq,
990
    not_not =		not_not_eq
991
} ;
992
 
993
 
994
/*
7 7u83 995
 * TYPE REPRESENTING A ROUNDING MODE
996
 *
997
 * Floating point rounding modes are represented by an enumeration type which
998
 * happen to be in the same order as the TDF encoding.
999
 */
2 7u83 1000
 
1001
enum !RMODE (rmode) = {
1002
    as_state =		0,
1003
    to_nearest =	1,
1004
    to_larger =		2,
1005
    to_smaller =	3,
1006
    to_zero =		4
1007
} ;
1008
 
1009
 
1010
/*
7 7u83 1011
 * TYPE REPRESENTING AN EXPRESSION OR STATEMENT
1012
 *
1013
 * The expressions and statements are represented by a union type, with one
1014
 * field per expression or statement class. Every expression has an associated
1015
 * type.
1016
 */
2 7u83 1017
 
1018
union EXP (exp) = {
1019
    /* Expression type */
1020
    TYPE type ;
1021
} + {
1022
    identifier, member, ambiguous, undeclared -> {
1023
	/* Identifiers */
1024
	IDENTIFIER id ;
1025
	QUALIFIER qual ;
1026
    },
1027
    int_lit -> {
1028
	/* Integer literal */
1029
	NAT nat ;
1030
	unsigned etag ;
1031
    },
1032
    float_lit -> {
1033
	/* Floating point literal */
1034
	FLOAT flt ;
1035
    },
1036
    char_lit -> {
1037
	/* Character literal */
1038
	STRING str ;
1039
	int digit ;
1040
    },
1041
    string_lit -> {
1042
	/* String literal */
1043
	STRING str ;
1044
    },
1045
    value -> {
1046
	/* Undefined value */
1047
    },
1048
    null, zero -> {
1049
	/* Null value (null pointer, zero etc.) */
1050
    },
1051
    paren, copy -> {
1052
	/* Identity operation (used for parentheses) */
1053
	EXP arg ;
1054
    },
1055
    assign -> {
1056
	/* Assignment */
1057
	EXP ref, arg ;
1058
    },
1059
    init -> {
1060
	/* Initialisation */
1061
	IDENTIFIER id ;
1062
	EXP arg ;
1063
    },
1064
    preinc -> {
1065
	/* Pre-increment */
1066
	EXP ref, op ;
1067
	int becomes ;
1068
    },
1069
    postinc -> {
1070
	/* Post-increment */
1071
	EXP ref, value, op ;
1072
    },
1073
    indir -> {
1074
	/* Indirection */
1075
	EXP ptr ;
1076
	int index = "0" ;
1077
    },
1078
    contents -> {
1079
	/* Contents */
1080
	EXP ptr ;
1081
    },
1082
    address -> {
1083
	/* Address of an object */
1084
	EXP arg ;
1085
    },
1086
    address_mem -> {
1087
	/* Address of a member */
1088
	EXP arg ;
1089
	int paren ;
1090
    },
1091
    func -> {
1092
	/* Function call */
1093
	EXP fn ;
1094
	LIST EXP args ;
1095
	unsigned extra = "0" ;
1096
    },
1097
    func_id -> {
1098
	/* Named function call */
1099
	IDENTIFIER id ;
1100
	LIST EXP args ;
1101
	EXP virt ;
1102
	unsigned extra = "0" ;
1103
    },
1104
    call -> {
1105
	/* Member function call */
1106
	EXP ptr, arg ;
1107
	GRAPH base ;
1108
    },
1109
    negate, compl, not, abs -> {
1110
	/* Simple unary operations */
1111
	EXP arg ;
1112
    },
1113
    plus, minus, mult, div, rem,
1114
    and, or, xor, log_and, log_or,
1115
    lshift, rshift, max, min -> {
1116
	/* Simple binary operations */
1117
	EXP arg1, arg2 ;
1118
    },
1119
    test -> {
1120
	/* Compare against null value */
1121
	NTEST tst ;
1122
	EXP arg ;
1123
    },
1124
    compare -> {
1125
	/* Compare two values */
1126
	NTEST tst ;
1127
	EXP arg1, arg2 ;
1128
    },
1129
    cast -> {
1130
	/* Casts */
1131
	unsigned conv ;
1132
	EXP arg ;
1133
    },
1134
    base_cast -> {
1135
	/* Base class conversion */
1136
	unsigned conv ;
1137
	EXP arg ;
1138
	OFFSET off ;
1139
    },
1140
    dyn_cast -> {
1141
	/* Dynamic cast */
1142
	EXP arg ;
1143
	EXP except ;
1144
    },
1145
    add_ptr -> {
1146
	/* Add a value to a pointer */
1147
	EXP ptr ;
1148
	OFFSET off ;
1149
	int virt ;
1150
    },
1151
    offset_size -> {
1152
	/* Size of offset */
1153
	OFFSET off ;
1154
	TYPE step ;
1155
	int pad ;
1156
    },
1157
    constr -> {
1158
	/* Constructor call */
1159
	EXP call, obj, alt ;
1160
	int info ;
1161
    },
1162
    destr -> {
1163
	/* Destructor call */
1164
	EXP call, obj ;
1165
	EXP count = "NULL_exp" ;
1166
    },
1167
    alloc -> {
1168
	/* Allocator call */
1169
	EXP call, init ;
1170
	EXP garbage, size ;
1171
    },
1172
    dealloc -> {
1173
	/* Deallocator call */
1174
	EXP term, call ;
1175
	EXP arg, size ;
1176
    },
1177
    rtti -> {
1178
	/* Run-time type information */
1179
	EXP arg ;
1180
	EXP except ;
1181
	int op ;
1182
    },
1183
    rtti_type -> {
1184
	/* Run-time type information */
1185
	TYPE arg ;
1186
	int op ;
1187
    },
1188
    rtti_no -> {
1189
	/* Arithmetic type number */
1190
	TYPE arg ;
1191
    },
1192
    dynamic -> {
1193
	/* Dynamic initialiser */
1194
	EXP arg ;
1195
    },
1196
    aggregate -> {
1197
	/* Aggregate initialisers */
1198
	LIST EXP args ;
1199
	LIST OFFSET offs ;
1200
    },
1201
    initialiser -> {
1202
	/* Compound initialisers */
1203
	LIST EXP args ;
1204
	LIST OFFSET offs ;
1205
	int kind ;
1206
	unsigned virt, base ;
1207
    },
1208
    nof -> {
1209
	/* Array initialisers */
1210
	EXP start ;
1211
	NAT size ;
1212
	EXP pad ;
1213
	EXP end ;
1214
    },
1215
    comma -> {
1216
	/* Comma operator */
1217
	LIST EXP args ;
1218
    },
1219
    set, unused -> {
1220
	/* Variable analysis operators */
1221
	EXP arg ;
1222
    },
1223
    reach, unreach -> {
1224
	/* Flow analysis operators */
1225
	EXP parent = "NULL_exp" ;
1226
	EXP body ;
1227
    },
1228
    sequence -> {
1229
	/* Sequence of statements */
1230
	EXP parent = "NULL_exp" ;
1231
	LIST EXP first, last ;
1232
	NAMESPACE decl ;
1233
	int block ;
1234
    },
1235
    solve_stmt -> {
1236
	/* Label complex */
1237
	EXP parent = "NULL_exp" ;
1238
	EXP body ;
1239
	LIST IDENTIFIER labels = "NULL_list ( IDENTIFIER )" ;
1240
	LIST IDENTIFIER vars = "NULL_list ( IDENTIFIER )" ;
1241
    },
1242
    decl_stmt -> {
1243
	/* Declaration statement */
1244
	EXP parent = "NULL_exp" ;
1245
	IDENTIFIER id ;
1246
	EXP body ;
1247
    },
1248
    if_stmt -> {
1249
	/* If statement */
1250
	EXP parent = "NULL_exp" ;
1251
	EXP cond ;
1252
	EXP true_code, false_code ;
1253
	IDENTIFIER label ;
1254
    },
1255
    while_stmt -> {
1256
	/* While and for statements */
1257
	EXP parent = "NULL_exp" ;
1258
	EXP cond ;
1259
	EXP body = "NULL_exp" ;
1260
	IDENTIFIER break_lab ;
1261
	IDENTIFIER cont_lab ;
1262
	IDENTIFIER loop_lab ;
1263
	LIST IDENTIFIER cond_id = "NULL_list ( IDENTIFIER )" ;
1264
    },
1265
    do_stmt -> {
1266
	/* Do statements */
1267
	EXP parent = "NULL_exp" ;
1268
	EXP cond ;
1269
	EXP body = "NULL_exp" ;
1270
	IDENTIFIER break_lab ;
1271
	IDENTIFIER cont_lab ;
1272
	IDENTIFIER loop_lab ;
1273
    },
1274
    switch_stmt -> {
1275
	/* Switch statement */
1276
	EXP parent = "NULL_exp" ;
1277
	EXP control ;
1278
	EXP body ;
1279
	LIST NAT cases = "NULL_list ( NAT )" ;
1280
	LIST IDENTIFIER case_labs = "NULL_list ( IDENTIFIER )" ;
1281
	IDENTIFIER default_lab = "NULL_id" ;
1282
	int exhaust ;
1283
	IDENTIFIER break_lab ;
1284
    },
1285
    hash_if -> {
1286
	/* #if statement */
1287
	EXP parent = "NULL_exp" ;
1288
	EXP cond ;
1289
	EXP true_code, false_code ;
1290
	EXP last = "NULL_exp" ;
1291
    },
1292
    return_stmt -> {
1293
	/* Return statement */
1294
	EXP parent = "NULL_exp" ;
1295
	EXP value ;
1296
    },
1297
    goto_stmt -> {
1298
	/* Goto statement (including break and continue statements) */
1299
	EXP parent = "NULL_exp" ;
1300
	IDENTIFIER label ;
1301
	EXP join ;
1302
	EXP next ;
1303
    },
1304
    label_stmt -> {
1305
	/* Labelled statement (including case and default statements) */
1306
	EXP parent = "NULL_exp" ;
1307
	IDENTIFIER label ;
1308
	EXP body ;
1309
	IDENTIFIER next = "NULL_id" ;
1310
    },
1311
    try_block -> {
1312
	/* Try block */
1313
	EXP parent = "NULL_exp" ;
1314
	EXP body ;
1315
	int func ;
1316
	LIST EXP handlers = "NULL_list ( EXP )" ;
1317
	LIST TYPE htypes = "NULL_list ( TYPE )" ;
1318
	EXP ellipsis = "NULL_exp" ;
1319
	LIST TYPE ttypes = "NULL_list ( TYPE )" ;
1320
	LIST LOCATION tlocs = "NULL_list ( LOCATION )" ;
1321
	ulong_type no = "LINK_NONE" ;
1322
    },
1323
    handler -> {
1324
	/* Exception handler */
1325
	EXP parent = "NULL_exp" ;
1326
	IDENTIFIER except ;
1327
	EXP body ;
1328
	ulong_type diag = "LINK_NONE" ;
1329
    },
1330
    exception -> {
1331
	/* Throw expression */
1332
	EXP arg ;
1333
	EXP size, destr ;
1334
	int expl ;
1335
    },
1336
    thrown -> {
1337
	/* Caught expression */
1338
	int done ;
1339
    },
1340
    op -> {
1341
	/* Undetermined operation */
1342
	int lex ;
1343
	EXP arg1, arg2 ;
1344
    },
1345
    opn -> {
1346
	/* Undetermined operation */
1347
	int lex ;
1348
	LIST EXP args ;
1349
    },
1350
    assembler -> {
1351
	/* asm expression */
1352
	STRING op ;
1353
	LIST EXP args ;
1354
    },
1355
    uncompiled -> {
1356
	/* Uncompiled expression */
1357
	LOCATION start ;
1358
	PPTOKEN_P defn ;
1359
    },
1360
    location -> {
1361
	/* Location expression */
1362
	LOCATION end ;
1363
	EXP arg ;
1364
    },
1365
    fail -> {
1366
	/* Install-time failure */
1367
	string msg ;
1368
    },
1369
    token -> {
1370
	/* Tokenised expression */
1371
	EXP parent = "NULL_exp" ;
1372
	IDENTIFIER tok ;
1373
	LIST TOKEN args ;
1374
    },
1375
    dummy -> {
1376
	/* Dummy expression */
1377
	EXP value ;
1378
	ulong_type no ;
1379
	OFFSET off ;
1380
	int virt = "0" ;
1381
	int cont ;
1382
    }
1383
} ;
1384
 
1385
 
1386
/*
7 7u83 1387
 * TYPE REPRESENTING AN OFFSET
1388
 *
1389
 * This type is used to represent an offset between two pointers. The type
1390
 * construct gives the offset between successive elements of an array of that
1391
 * type. The other constructs are fairly obvious.
1392
 */
2 7u83 1393
 
1394
union OFFSET (off) = {
1395
    /* empty */
1396
} + {
1397
    zero -> {
1398
	/* Zero offset */
1399
	TYPE type ;
1400
    },
1401
    type -> {
1402
	/* Type offset */
1403
	TYPE type ;
1404
    },
1405
    array -> {
1406
	/* Array offset */
1407
	TYPE type ;
1408
	unsigned arg ;
1409
    },
1410
    extra -> {
1411
	/* Extra offset for array allocator */
1412
	TYPE type ;
1413
	int scale ;
1414
    },
1415
    base -> {
1416
	/* Base class offset */
1417
	GRAPH graph ;
1418
    },
1419
    deriv -> {
1420
	/* Derived class offset */
1421
	GRAPH graph ;
1422
	OFFSET direct ;
1423
	OFFSET indirect ;
1424
    },
1425
    member -> {
1426
	/* Member offset */
1427
	IDENTIFIER id ;
1428
    },
1429
    ptr_mem -> {
1430
	/* Pointer member offset */
1431
	EXP arg ;
1432
    },
1433
    negate -> {
1434
	/* Offset negation */
1435
	OFFSET arg ;
1436
    },
1437
    plus -> {
1438
	/* Offset addition */
1439
	OFFSET arg1, arg2 ;
1440
    },
1441
    mult -> {
1442
	/* Offset multiplication */
1443
	OFFSET arg1 ;
1444
	EXP arg2 ;
1445
    },
1446
    ptr_diff -> {
1447
	/* Pointer difference */
1448
	EXP ptr1, ptr2 ;
1449
    },
1450
    token -> {
1451
	/* Tokenised offset */
1452
	IDENTIFIER tok ;
1453
	LIST TOKEN args ;
1454
    }
1455
} ;
1456
 
1457
 
1458
/*
7 7u83 1459
 * TYPE REPRESENTING A TOKEN
1460
 *
1461
 * This type is used to represent a TDF token. The various fields correspond to
1462
 * the kinds of token - expressions, statements, types etc. Each simple
1463
 * component also contains a field for holding a value of that kind, thus a
1464
 * list of token arguments can themselves be expressed as a list of tokens.
1465
 */
2 7u83 1466
 
1467
union TOKEN (tok) = {
1468
    /* empty */
1469
} + {
1470
    exp -> {
1471
	/* Expression tokens */
1472
	TYPE type ;
1473
	int constant ;
1474
	EXP value ;
1475
    },
1476
    stmt -> {
1477
	/* Statement tokens */
1478
	EXP value ;
1479
    },
1480
    nat, snat -> {
1481
	/* Integer constant tokens */
1482
	NAT value ;
1483
    },
1484
    type -> {
1485
	/* Type tokens */
1486
	BASE_TYPE kind ;
1487
	TYPE value ;
1488
	TYPE alt = "NULL_type" ;
1489
    },
1490
    func -> {
1491
	/* Function tokens */
1492
	TYPE type ;
1493
	IDENTIFIER defn = "NULL_id" ;
1494
	TOKEN proc = "NULL_tok" ;
1495
    },
1496
    member -> {
1497
	/* Class member tokens */
1498
	TYPE of ;
1499
	TYPE type ;
1500
	OFFSET value ;
1501
    },
1502
    class -> {
1503
	/* Template class tokens */
1504
	TYPE type ;
1505
	IDENTIFIER value ;
1506
	TYPE alt = "NULL_type" ;
1507
    },
1508
    proc -> {
1509
	/* Procedure tokens */
1510
	TOKEN res ;
1511
	NAMESPACE pars ;
1512
	int key ;
1513
	INSTANCE apps = "NULL_inst" ;
1514
	LIST IDENTIFIER bids = "NULL_list ( IDENTIFIER )" ;
1515
	LIST IDENTIFIER pids = "NULL_list ( IDENTIFIER )" ;
1516
    },
1517
    templ -> {
1518
	/* Template tokens */
1519
	DECL_SPEC usage ;
1520
	NAMESPACE pars ;
1521
	INSTANCE apps = "NULL_inst" ;
1522
	LIST IDENTIFIER pids = "NULL_list ( IDENTIFIER )" ;
1523
	LIST TOKEN dargs = "NULL_list ( TOKEN )" ;
1524
    }
1525
} ;
1526
 
1527
 
1528
/*
7 7u83 1529
 * TYPE REPRESENTING A TEMPLATE INSTANCE
1530
 *
1531
 * A template instance consists of an identifier, a type giving the template
1532
 * form and a specifier giving declaration information.
1533
 */
2 7u83 1534
 
1535
union INSTANCE (inst) = {
1536
    TYPE form ;
1537
    INSTANCE alias = "%0" ;
1538
    INSTANCE next ;
1539
} + {
1540
    templ -> {
1541
	/* Template instance */
1542
	IDENTIFIER id ;
1543
	TYPE spec = "NULL_type" ;
1544
	DECL_SPEC access ;
1545
	PPTOKEN_P mode = "NULL" ;
1546
	LIST IDENTIFIER mems = "NULL_list ( IDENTIFIER )" ;
1547
	INSTANCE prev ;
1548
    },
1549
    token -> {
1550
	/* Token type instance */
1551
	ulong_type no = "LINK_NONE" ;
1552
    }
1553
} ;
1554
 
1555
 
1556
/*
7 7u83 1557
 * TYPE REPRESENTING A VARIABLE ANALYSIS STATE
1558
 *
1559
 * This type is used in the variable analysis routines to record the state of a
1560
 * local variable.
1561
 */
2 7u83 1562
 
1563
struct VARIABLE (var) = {
1564
    IDENTIFIER id ;
1565
    DECL_SPEC info ;
1566
} ;
1567
 
1568
 
1569
/*
7 7u83 1570
 * TYPE REPRESENTING AN ERROR
1571
 *
1572
 * An error can be either a simple message, described by an error number, or a
1573
 * compound formed from two other errors. Some trickery is used to store the
1574
 * arguments for a simple error after its size field.
1575
 */
2 7u83 1576
 
1577
union ERROR (err) = {
1578
    int severity ;
1579
} + {
1580
    simple -> {
1581
	/* Simple errors */
1582
	int number ;
1583
	unsigned size = "0" ;
1584
	/* arguments ... */
1585
    },
1586
    compound -> {
1587
	/* Compound errors */
1588
	ERROR head, tail ;
1589
    }
1590
} ;
1591
 
1592
 
1593
/*
7 7u83 1594
 * TYPE REPRESENTING A FILE POSITION
1595
 *
1596
 * A file position consists of a line number plus a pointer to a type giving
1597
 * the file name.
1598
 */
2 7u83 1599
 
1600
struct LOCATION (loc) = {
1601
    ulong_type line ;
1602
    ulong_type column ;
1603
    PTR POSITION posn ;
1604
} ;
1605
 
1606
struct POSITION (posn) = {
1607
    string file ;
1608
    string input ;
1609
    string base ;
1610
    string dir ;
1611
    ulong_type offset ;
1612
    PTR LOCATION from ;
1613
    ulong_type datestamp ;
1614
    ulong_type tok = "LINK_NONE" ;
1615
} ;