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, 1998
32
    		 Crown Copyright (c) 1997, 1998
3
    
33
 
4
    This TenDRA(r) Computer Program is subject to Copyright
34
    This TenDRA(r) Computer Program is subject to Copyright
5
    owned by the United Kingdom Secretary of State for Defence
35
    owned by the United Kingdom Secretary of State for Defence
6
    acting through the Defence Evaluation and Research Agency
36
    acting through the Defence Evaluation and Research Agency
7
    (DERA).  It is made available to Recipients with a
37
    (DERA).  It is made available to Recipients with a
8
    royalty-free licence for its use, reproduction, transfer
38
    royalty-free licence for its use, reproduction, transfer
9
    to other parties and amendment for any purpose not excluding
39
    to other parties and amendment for any purpose not excluding
10
    product development provided that any such use et cetera
40
    product development provided that any such use et cetera
11
    shall be deemed to be acceptance of the following conditions:-
41
    shall be deemed to be acceptance of the following conditions:-
12
    
42
 
13
        (1) Its Recipients shall ensure that this Notice is
43
        (1) Its Recipients shall ensure that this Notice is
14
        reproduced upon any copies or amended versions of it;
44
        reproduced upon any copies or amended versions of it;
15
    
45
 
16
        (2) Any amended version of it shall be clearly marked to
46
        (2) Any amended version of it shall be clearly marked to
17
        show both the nature of and the organisation responsible
47
        show both the nature of and the organisation responsible
18
        for the relevant amendment or amendments;
48
        for the relevant amendment or amendments;
19
    
49
 
20
        (3) Its onward transfer from a recipient to another
50
        (3) Its onward transfer from a recipient to another
21
        party shall be deemed to be that party's acceptance of
51
        party shall be deemed to be that party's acceptance of
22
        these conditions;
52
        these conditions;
23
    
53
 
24
        (4) DERA gives no warranty or assurance as to its
54
        (4) DERA gives no warranty or assurance as to its
25
        quality or suitability for any purpose and DERA accepts
55
        quality or suitability for any purpose and DERA accepts
26
        no liability whatsoever in relation to any use to which
56
        no liability whatsoever in relation to any use to which
27
        it may be put.
57
        it may be put.
28
*/
58
*/
Line 71... Line 101...
71
    identifier.  The entries in this table correspond to the TOK values
101
    identifier.  The entries in this table correspond to the TOK values
72
    defined in tok.h.
102
    defined in tok.h.
73
*/
103
*/
74
 
104
 
75
static struct {
105
static struct {
76
    CONST char *name ;
106
	CONST char *name;
77
    CONST char *sorts ;
107
	CONST char *sorts;
78
    ulong no ;
108
	ulong no;
79
    ulong diag ;
109
	ulong diag;
80
    IDENTIFIER tok ;
110
	IDENTIFIER tok;
81
    int builtin ;
111
	int builtin;
82
} special_token [ TOK_no ] = {
112
} special_token[TOK_no] = {
83
    /* Built-in integral types */
113
	/* Built-in integral types */
84
    { "~char", "V", LINK_NONE, LINK_NONE, NULL_id, 0 },
114
	{ "~char", "V", LINK_NONE, LINK_NONE, NULL_id, 0 },
85
    { "~signed_char", "V", LINK_NONE, LINK_NONE, NULL_id, 0 },
115
	{ "~signed_char", "V", LINK_NONE, LINK_NONE, NULL_id, 0 },
86
    { "~unsigned_char", "V", LINK_NONE, LINK_NONE, NULL_id, 0 },
116
	{ "~unsigned_char", "V", LINK_NONE, LINK_NONE, NULL_id, 0 },
87
    { "~signed_short", "V", LINK_NONE, LINK_NONE, NULL_id, 0 },
117
	{ "~signed_short", "V", LINK_NONE, LINK_NONE, NULL_id, 0 },
88
    { "~unsigned_short", "V", LINK_NONE, LINK_NONE, NULL_id, 0 },
118
	{ "~unsigned_short", "V", LINK_NONE, LINK_NONE, NULL_id, 0 },
89
    { "~signed_int", "V", LINK_NONE, LINK_NONE, NULL_id, 0 },
119
	{ "~signed_int", "V", LINK_NONE, LINK_NONE, NULL_id, 0 },
90
    { "~unsigned_int", "V", LINK_NONE, LINK_NONE, NULL_id, 0 },
120
	{ "~unsigned_int", "V", LINK_NONE, LINK_NONE, NULL_id, 0 },
91
    { "~signed_long", "V", LINK_NONE, LINK_NONE, NULL_id, 0 },
121
	{ "~signed_long", "V", LINK_NONE, LINK_NONE, NULL_id, 0 },
92
    { "~unsigned_long", "V", LINK_NONE, LINK_NONE, NULL_id, 0 },
122
	{ "~unsigned_long", "V", LINK_NONE, LINK_NONE, NULL_id, 0 },
93
    { "~signed_longlong", "V", LINK_NONE, LINK_NONE, NULL_id, 0 },
123
	{ "~signed_longlong", "V", LINK_NONE, LINK_NONE, NULL_id, 0 },
94
    { "~unsigned_longlong", "V", LINK_NONE, LINK_NONE, NULL_id, 0 },
124
	{ "~unsigned_longlong", "V", LINK_NONE, LINK_NONE, NULL_id, 0 },
95
 
125
 
96
    /* Built-in floating-point types */
126
	/* Built-in floating-point types */
97
    { "~float", "F", LINK_NONE, LINK_NONE, NULL_id, 0 },
127
	{ "~float", "F", LINK_NONE, LINK_NONE, NULL_id, 0 },
98
    { "~double", "F", LINK_NONE, LINK_NONE, NULL_id, 0 },
128
	{ "~double", "F", LINK_NONE, LINK_NONE, NULL_id, 0 },
99
    { "~long_double", "F", LINK_NONE, LINK_NONE, NULL_id, 0 },
129
	{ "~long_double", "F", LINK_NONE, LINK_NONE, NULL_id, 0 },
100
 
130
 
101
    /* Standard integral types */
131
	/* Standard integral types */
102
    { "~cpp.bool", "Z", LINK_NONE, LINK_NONE, NULL_id, 0 },
132
	{ "~cpp.bool", "Z", LINK_NONE, LINK_NONE, NULL_id, 0 },
103
    { "ptrdiff_t", "Z", LINK_NONE, LINK_NONE, NULL_id, 0 },
133
	{ "ptrdiff_t", "Z", LINK_NONE, LINK_NONE, NULL_id, 0 },
104
    { "size_t", "Z", LINK_NONE, LINK_NONE, NULL_id, 0 },
134
	{ "size_t", "Z", LINK_NONE, LINK_NONE, NULL_id, 0 },
105
    { "__size_t", "Z", LINK_NONE, LINK_NONE, NULL_id, 0 },
135
	{ "__size_t", "Z", LINK_NONE, LINK_NONE, NULL_id, 0 },
106
    { "wchar_t", "Z", LINK_NONE, LINK_NONE, NULL_id, 0 },
136
	{ "wchar_t", "Z", LINK_NONE, LINK_NONE, NULL_id, 0 },
107
 
137
 
108
    /* Integral type conversions */
138
	/* Integral type conversions */
109
    { "~convert", "VZ", LINK_NONE, LINK_NONE, NULL_id, 0 },
139
	{ "~convert", "VZ", LINK_NONE, LINK_NONE, NULL_id, 0 },
110
    { "~arith_type", "ZZZ", LINK_NONE, LINK_NONE, NULL_id, 0 },
140
	{ "~arith_type", "ZZZ", LINK_NONE, LINK_NONE, NULL_id, 0 },
111
    { "~promote", "ZZ", LINK_NONE, LINK_NONE, NULL_id, 0 },
141
	{ "~promote", "ZZ", LINK_NONE, LINK_NONE, NULL_id, 0 },
112
    { "~sign_promote", "ZZ", LINK_NONE, LINK_NONE, NULL_id, 0 },
142
	{ "~sign_promote", "ZZ", LINK_NONE, LINK_NONE, NULL_id, 0 },
113
 
143
 
114
    /* Integer literal types */
144
	/* Integer literal types */
115
    { "~lit_int", "ZZ", LINK_NONE, LINK_NONE, NULL_id, 0 },
145
	{ "~lit_int", "ZZ", LINK_NONE, LINK_NONE, NULL_id, 0 },
116
    { "~lit_hex", "ZZ", LINK_NONE, LINK_NONE, NULL_id, 0 },
146
	{ "~lit_hex", "ZZ", LINK_NONE, LINK_NONE, NULL_id, 0 },
117
    { "~lit_unsigned", "ZZ", LINK_NONE, LINK_NONE, NULL_id, 0 },
147
	{ "~lit_unsigned", "ZZ", LINK_NONE, LINK_NONE, NULL_id, 0 },
118
    { "~lit_long", "ZZ", LINK_NONE, LINK_NONE, NULL_id, 0 },
148
	{ "~lit_long", "ZZ", LINK_NONE, LINK_NONE, NULL_id, 0 },
119
    { "~lit_ulong", "ZZ", LINK_NONE, LINK_NONE, NULL_id, 0 },
149
	{ "~lit_ulong", "ZZ", LINK_NONE, LINK_NONE, NULL_id, 0 },
120
    { "~lit_longlong", "ZZ", LINK_NONE, LINK_NONE, NULL_id, 0 },
150
	{ "~lit_longlong", "ZZ", LINK_NONE, LINK_NONE, NULL_id, 0 },
121
    { "~lit_ulonglong", "ZZ", LINK_NONE, LINK_NONE, NULL_id, 0 },
151
	{ "~lit_ulonglong", "ZZ", LINK_NONE, LINK_NONE, NULL_id, 0 },
122
 
152
 
123
    /* Bitfield types */
153
	/* Bitfield types */
124
    { "~cpp.bitf_sign", "BZ", LINK_NONE, LINK_NONE, NULL_id, 0 },
154
	{ "~cpp.bitf_sign", "BZ", LINK_NONE, LINK_NONE, NULL_id, 0 },
125
 
155
 
126
    /* Generic pointers */
156
	/* Generic pointers */
127
    { "~ptr_void", "S", LINK_NONE, LINK_NONE, NULL_id, 0 },
157
	{ "~ptr_void", "S", LINK_NONE, LINK_NONE, NULL_id, 0 },
128
    { "~null_pv", "E", LINK_NONE, LINK_NONE, NULL_id, 0 },
158
	{ "~null_pv", "E", LINK_NONE, LINK_NONE, NULL_id, 0 },
129
    { "~to_ptr_void", "EAE", LINK_NONE, LINK_NONE, NULL_id, 0 },
159
	{ "~to_ptr_void", "EAE", LINK_NONE, LINK_NONE, NULL_id, 0 },
130
    { "~from_ptr_void", "EAE", LINK_NONE, LINK_NONE, NULL_id, 0 },
160
	{ "~from_ptr_void", "EAE", LINK_NONE, LINK_NONE, NULL_id, 0 },
131
    { "~pv_test", "EELT", LINK_NONE, LINK_NONE, NULL_id, 0 },
161
	{ "~pv_test", "EELT", LINK_NONE, LINK_NONE, NULL_id, 0 },
132
    { "~cpp.pv_compare", "EEELT", LINK_NONE, LINK_NONE, NULL_id, 0 },
162
	{ "~cpp.pv_compare", "EEELT", LINK_NONE, LINK_NONE, NULL_id, 0 },
133
 
163
 
134
    /* Undefined conversions */
164
	/* Undefined conversions */
135
    { "~ptr_to_ptr", "EAAE", LINK_NONE, LINK_NONE, NULL_id, 0 },
165
	{ "~ptr_to_ptr", "EAAE", LINK_NONE, LINK_NONE, NULL_id, 0 },
136
    { "~f_to_pv", "EE", LINK_NONE, LINK_NONE, NULL_id, 0 },
166
	{ "~f_to_pv", "EE", LINK_NONE, LINK_NONE, NULL_id, 0 },
137
    { "~pv_to_f", "EE", LINK_NONE, LINK_NONE, NULL_id, 0 },
167
	{ "~pv_to_f", "EE", LINK_NONE, LINK_NONE, NULL_id, 0 },
138
    { "~i_to_p", "EVAE", LINK_NONE, LINK_NONE, NULL_id, 0 },
168
	{ "~i_to_p", "EVAE", LINK_NONE, LINK_NONE, NULL_id, 0 },
139
    { "~p_to_i", "EAVE", LINK_NONE, LINK_NONE, NULL_id, 0 },
169
	{ "~p_to_i", "EAVE", LINK_NONE, LINK_NONE, NULL_id, 0 },
140
    { "~i_to_pv", "EVE", LINK_NONE, LINK_NONE, NULL_id, 0 },
170
	{ "~i_to_pv", "EVE", LINK_NONE, LINK_NONE, NULL_id, 0 },
141
    { "~pv_to_i", "EVE", LINK_NONE, LINK_NONE, NULL_id, 0 },
171
	{ "~pv_to_i", "EVE", LINK_NONE, LINK_NONE, NULL_id, 0 },
142
    { "~cpp.ptr_rep", "Z", LINK_NONE, LINK_NONE, NULL_id, 0 },
172
	{ "~cpp.ptr_rep", "Z", LINK_NONE, LINK_NONE, NULL_id, 0 },
143
 
173
 
144
    /* Integer division */
174
	/* Integer division */
145
    { "~div", "EEE", LINK_NONE, LINK_NONE, NULL_id, 0 },
175
	{ "~div", "EEE", LINK_NONE, LINK_NONE, NULL_id, 0 },
146
    { "~rem", "EEE", LINK_NONE, LINK_NONE, NULL_id, 0 },
176
	{ "~rem", "EEE", LINK_NONE, LINK_NONE, NULL_id, 0 },
147
 
177
 
148
    /* Ellipsis functions */
178
	/* Ellipsis functions */
149
    { "~__va_t", "S", LINK_NONE, LINK_NONE, NULL_id, 0 },
179
	{ "~__va_t", "S", LINK_NONE, LINK_NONE, NULL_id, 0 },
150
 
180
 
151
    /* Pointers to data members */
181
	/* Pointers to data members */
152
    { "~cpp.pm.type", "S", LINK_NONE, LINK_NONE, NULL_id, 0 },
182
	{ "~cpp.pm.type", "S", LINK_NONE, LINK_NONE, NULL_id, 0 },
153
    { "~cpp.pm.make", "EE", LINK_NONE, LINK_NONE, NULL_id, 0 },
183
	{ "~cpp.pm.make", "EE", LINK_NONE, LINK_NONE, NULL_id, 0 },
154
    { "~cpp.pm.null", "E", LINK_NONE, LINK_NONE, NULL_id, 0 },
184
	{ "~cpp.pm.null", "E", LINK_NONE, LINK_NONE, NULL_id, 0 },
155
    { "~cpp.pm.offset", "EEA", LINK_NONE, LINK_NONE, NULL_id, 0 },
185
	{ "~cpp.pm.offset", "EEA", LINK_NONE, LINK_NONE, NULL_id, 0 },
156
    { "~cpp.pm.cast", "EEE", LINK_NONE, LINK_NONE, NULL_id, 0 },
186
	{ "~cpp.pm.cast", "EEE", LINK_NONE, LINK_NONE, NULL_id, 0 },
157
    { "~cpp.pm.uncast", "EEE", LINK_NONE, LINK_NONE, NULL_id, 0 },
187
	{ "~cpp.pm.uncast", "EEE", LINK_NONE, LINK_NONE, NULL_id, 0 },
158
    { "~cpp.pm.test", "EELT", LINK_NONE, LINK_NONE, NULL_id, 0 },
188
	{ "~cpp.pm.test", "EELT", LINK_NONE, LINK_NONE, NULL_id, 0 },
159
    { "~cpp.pm.compare", "EEELT", LINK_NONE, LINK_NONE, NULL_id, 0 },
189
	{ "~cpp.pm.compare", "EEELT", LINK_NONE, LINK_NONE, NULL_id, 0 },
160
 
190
 
161
    /* Pointers to function members */
191
	/* Pointers to function members */
162
    { "~cpp.pmf.type", "S", LINK_NONE, LINK_NONE, NULL_id, 0 },
192
	{ "~cpp.pmf.type", "S", LINK_NONE, LINK_NONE, NULL_id, 0 },
163
    { "~cpp.pmf.make", "EEEE", LINK_NONE, LINK_NONE, NULL_id, 0 },
193
	{ "~cpp.pmf.make", "EEEE", LINK_NONE, LINK_NONE, NULL_id, 0 },
164
    { "~cpp.pmf.vmake", "EZEEE", LINK_NONE, LINK_NONE, NULL_id, 0 },
194
	{ "~cpp.pmf.vmake", "EZEEE", LINK_NONE, LINK_NONE, NULL_id, 0 },
165
    { "~cpp.pmf.null", "E", LINK_NONE, LINK_NONE, NULL_id, 0 },
195
	{ "~cpp.pmf.null", "E", LINK_NONE, LINK_NONE, NULL_id, 0 },
166
    { "~cpp.pmf.null2", "E", LINK_NONE, LINK_NONE, NULL_id, 0 },
196
	{ "~cpp.pmf.null2", "E", LINK_NONE, LINK_NONE, NULL_id, 0 },
167
    { "~cpp.pmf.delta", "EAE", LINK_NONE, LINK_NONE, NULL_id, 0 },
197
	{ "~cpp.pmf.delta", "EAE", LINK_NONE, LINK_NONE, NULL_id, 0 },
168
    { "~cpp.pmf.func", "EE", LINK_NONE, LINK_NONE, NULL_id, 0 },
198
	{ "~cpp.pmf.func", "EE", LINK_NONE, LINK_NONE, NULL_id, 0 },
169
    { "~cpp.pmf.virt", "EEEA", LINK_NONE, LINK_NONE, NULL_id, 0 },
199
	{ "~cpp.pmf.virt", "EEEA", LINK_NONE, LINK_NONE, NULL_id, 0 },
170
    { "~cpp.pmf.cast", "EEEEE", LINK_NONE, LINK_NONE, NULL_id, 0 },
200
	{ "~cpp.pmf.cast", "EEEEE", LINK_NONE, LINK_NONE, NULL_id, 0 },
171
    { "~cpp.pmf.uncast", "EEEEE", LINK_NONE, LINK_NONE, NULL_id, 0 },
201
	{ "~cpp.pmf.uncast", "EEEEE", LINK_NONE, LINK_NONE, NULL_id, 0 },
172
    { "~cpp.pmf.test", "EELT", LINK_NONE, LINK_NONE, NULL_id, 0 },
202
	{ "~cpp.pmf.test", "EELT", LINK_NONE, LINK_NONE, NULL_id, 0 },
173
    { "~cpp.pmf.compare", "EEELT", LINK_NONE, LINK_NONE, NULL_id, 0 },
203
	{ "~cpp.pmf.compare", "EEELT", LINK_NONE, LINK_NONE, NULL_id, 0 },
174
 
204
 
175
    /* Class layout */
205
	/* Class layout */
176
    { "~comp_off", "EE", LINK_NONE, LINK_NONE, NULL_id, 0 },
206
	{ "~comp_off", "EE", LINK_NONE, LINK_NONE, NULL_id, 0 },
177
    { "~pad", "EESS", LINK_NONE, LINK_NONE, NULL_id, 0 },
207
	{ "~pad", "EESS", LINK_NONE, LINK_NONE, NULL_id, 0 },
178
    { "~cpp.empty.align", "A", LINK_NONE, LINK_NONE, NULL_id, 0 },
208
	{ "~cpp.empty.align", "A", LINK_NONE, LINK_NONE, NULL_id, 0 },
179
    { "~cpp.empty.shape", "S", LINK_NONE, LINK_NONE, NULL_id, 0 },
209
	{ "~cpp.empty.shape", "S", LINK_NONE, LINK_NONE, NULL_id, 0 },
180
    { "~cpp.empty.offset", "E", LINK_NONE, LINK_NONE, NULL_id, 0 },
210
	{ "~cpp.empty.offset", "E", LINK_NONE, LINK_NONE, NULL_id, 0 },
181
 
211
 
182
    /* Virtual function tables */
212
	/* Virtual function tables */
183
    { "~cpp.vtab.type", "SN", LINK_NONE, LINK_NONE, NULL_id, 0 },
213
	{ "~cpp.vtab.type", "SN", LINK_NONE, LINK_NONE, NULL_id, 0 },
184
    { "~cpp.vtab.diag", "S", LINK_NONE, LINK_NONE, NULL_id, 0 },
214
	{ "~cpp.vtab.diag", "S", LINK_NONE, LINK_NONE, NULL_id, 0 },
185
    { "~cpp.vtab.make", "EEENE", LINK_NONE, LINK_NONE, NULL_id, 0 },
215
	{ "~cpp.vtab.make", "EEENE", LINK_NONE, LINK_NONE, NULL_id, 0 },
186
    { "~cpp.vtab.pure", "E", LINK_NONE, LINK_NONE, NULL_id, 0 },
216
	{ "~cpp.vtab.pure", "E", LINK_NONE, LINK_NONE, NULL_id, 0 },
187
    { "~cpp.vtab.func", "EEZ", LINK_NONE, LINK_NONE, NULL_id, 0 },
217
	{ "~cpp.vtab.func", "EEZ", LINK_NONE, LINK_NONE, NULL_id, 0 },
188
    { "~cpp.vtab.off", "EZ", LINK_NONE, LINK_NONE, NULL_id, 0 },
218
	{ "~cpp.vtab.off", "EZ", LINK_NONE, LINK_NONE, NULL_id, 0 },
189
 
219
 
190
    /* Run-time type information */
220
	/* Run-time type information */
191
    { "~cpp.typeid.type", "S", LINK_NONE, LINK_NONE, NULL_id, 0 },
221
	{ "~cpp.typeid.type", "S", LINK_NONE, LINK_NONE, NULL_id, 0 },
192
    { "~cpp.typeid.make", "EZEE", LINK_NONE, LINK_NONE, NULL_id, 0 },
222
	{ "~cpp.typeid.make", "EZEE", LINK_NONE, LINK_NONE, NULL_id, 0 },
193
    { "~cpp.typeid.basic", "EZ", LINK_NONE, LINK_NONE, NULL_id, 0 },
223
	{ "~cpp.typeid.basic", "EZ", LINK_NONE, LINK_NONE, NULL_id, 0 },
194
    { "~cpp.typeid.ref", "EE", LINK_NONE, LINK_NONE, NULL_id, 0 },
224
	{ "~cpp.typeid.ref", "EE", LINK_NONE, LINK_NONE, NULL_id, 0 },
195
    { "~cpp.baseid.type", "S", LINK_NONE, LINK_NONE, NULL_id, 0 },
225
	{ "~cpp.baseid.type", "S", LINK_NONE, LINK_NONE, NULL_id, 0 },
196
    { "~cpp.baseid.make", "EEEEZZ", LINK_NONE, LINK_NONE, NULL_id, 0 },
226
	{ "~cpp.baseid.make", "EEEEZZ", LINK_NONE, LINK_NONE, NULL_id, 0 },
197
    { "~cpp.dynam.cast", "EEE", LINK_NONE, LINK_NONE, NULL_id, 0 },
227
	{ "~cpp.dynam.cast", "EEE", LINK_NONE, LINK_NONE, NULL_id, 0 },
198
 
228
 
199
    /* Dynamic initialisation */
229
	/* Dynamic initialisation */
200
    { "~cpp.destr.type", "S", LINK_NONE, LINK_NONE, NULL_id, 0 },
230
	{ "~cpp.destr.type", "S", LINK_NONE, LINK_NONE, NULL_id, 0 },
201
    { "~cpp.destr.global", "EEEE", LINK_NONE, LINK_NONE, NULL_id, 0 },
231
	{ "~cpp.destr.global", "EEEE", LINK_NONE, LINK_NONE, NULL_id, 0 },
202
    { "~cpp.destr.local", "EEEE", LINK_NONE, LINK_NONE, NULL_id, 0 },
232
	{ "~cpp.destr.local", "EEEE", LINK_NONE, LINK_NONE, NULL_id, 0 },
203
    { "~cpp.destr.end", "EE", LINK_NONE, LINK_NONE, NULL_id, 0 },
233
	{ "~cpp.destr.end", "EE", LINK_NONE, LINK_NONE, NULL_id, 0 },
204
    { "~cpp.destr.init", "E", LINK_NONE, LINK_NONE, NULL_id, 0 },
234
	{ "~cpp.destr.init", "E", LINK_NONE, LINK_NONE, NULL_id, 0 },
205
    { "~cpp.destr.null", "E", LINK_NONE, LINK_NONE, NULL_id, 0 },
235
	{ "~cpp.destr.null", "E", LINK_NONE, LINK_NONE, NULL_id, 0 },
206
    { "~cpp.destr.ptr", "EE", LINK_NONE, LINK_NONE, NULL_id, 0 },
236
	{ "~cpp.destr.ptr", "EE", LINK_NONE, LINK_NONE, NULL_id, 0 },
207
    { "~cpp.start", "E", LINK_NONE, LINK_NONE, NULL_id, 0 },
237
	{ "~cpp.start", "E", LINK_NONE, LINK_NONE, NULL_id, 0 },
208
 
238
 
209
    /* Exception handling */
239
	/* Exception handling */
210
    { "~cpp.try.type", "S", LINK_NONE, LINK_NONE, NULL_id, 0 },
240
	{ "~cpp.try.type", "S", LINK_NONE, LINK_NONE, NULL_id, 0 },
211
    { "~cpp.try.begin", "EEEE", LINK_NONE, LINK_NONE, NULL_id, 0 },
241
	{ "~cpp.try.begin", "EEEE", LINK_NONE, LINK_NONE, NULL_id, 0 },
212
    { "~cpp.try.end", "EE", LINK_NONE, LINK_NONE, NULL_id, 0 },
242
	{ "~cpp.try.end", "EE", LINK_NONE, LINK_NONE, NULL_id, 0 },
213
    { "~cpp.except.alloc", "EE", LINK_NONE, LINK_NONE, NULL_id, 0 },
243
	{ "~cpp.except.alloc", "EE", LINK_NONE, LINK_NONE, NULL_id, 0 },
214
    { "~cpp.except.throw", "EEEE", LINK_NONE, LINK_NONE, NULL_id, 0 },
244
	{ "~cpp.except.throw", "EEEE", LINK_NONE, LINK_NONE, NULL_id, 0 },
215
    { "~cpp.except.rethrow", "E", LINK_NONE, LINK_NONE, NULL_id, 0 },
245
	{ "~cpp.except.rethrow", "E", LINK_NONE, LINK_NONE, NULL_id, 0 },
216
    { "~cpp.except.catch", "EE", LINK_NONE, LINK_NONE, NULL_id, 0 },
246
	{ "~cpp.except.catch", "EE", LINK_NONE, LINK_NONE, NULL_id, 0 },
217
    { "~cpp.except.value", "E", LINK_NONE, LINK_NONE, NULL_id, 0 },
247
	{ "~cpp.except.value", "E", LINK_NONE, LINK_NONE, NULL_id, 0 },
218
    { "~cpp.except.caught", "E", LINK_NONE, LINK_NONE, NULL_id, 0 },
248
	{ "~cpp.except.caught", "E", LINK_NONE, LINK_NONE, NULL_id, 0 },
219
    { "~cpp.except.end", "E", LINK_NONE, LINK_NONE, NULL_id, 0 },
249
	{ "~cpp.except.end", "E", LINK_NONE, LINK_NONE, NULL_id, 0 },
220
    { "~cpp.except.bad", "EZ", LINK_NONE, LINK_NONE, NULL_id, 0 },
250
	{ "~cpp.except.bad", "EZ", LINK_NONE, LINK_NONE, NULL_id, 0 },
221
    { "~cpp.except.jump", "EEE", LINK_NONE, LINK_NONE, NULL_id, 1 },
251
	{ "~cpp.except.jump", "EEE", LINK_NONE, LINK_NONE, NULL_id, 1 },
222
    { "~cpp.ptr.code", "S", LINK_NONE, LINK_NONE, NULL_id, 1 },
252
	{ "~cpp.ptr.code", "S", LINK_NONE, LINK_NONE, NULL_id, 1 },
223
    { "~cpp.ptr.frame", "S", LINK_NONE, LINK_NONE, NULL_id, 1 },
253
	{ "~cpp.ptr.frame", "S", LINK_NONE, LINK_NONE, NULL_id, 1 },
224
 
254
 
225
    /* Assembler inserts */
255
	/* Assembler inserts */
226
    { "~asm_sequence", "EE", LINK_NONE, LINK_NONE, NULL_id, 0 },
256
	{ "~asm_sequence", "EE", LINK_NONE, LINK_NONE, NULL_id, 0 },
227
    { "~asm", "EC", LINK_NONE, LINK_NONE, NULL_id, 0 },
257
	{ "~asm", "EC", LINK_NONE, LINK_NONE, NULL_id, 0 },
228
    { "~asm_exp_input", "EE", LINK_NONE, LINK_NONE, NULL_id, 0 },
258
	{ "~asm_exp_input", "EE", LINK_NONE, LINK_NONE, NULL_id, 0 },
229
    { "~asm_exp_output", "EE", LINK_NONE, LINK_NONE, NULL_id, 0 },
259
	{ "~asm_exp_output", "EE", LINK_NONE, LINK_NONE, NULL_id, 0 },
230
    { "~asm_exp_address", "EE", LINK_NONE, LINK_NONE, NULL_id, 0 },
260
	{ "~asm_exp_address", "EE", LINK_NONE, LINK_NONE, NULL_id, 0 },
231
 
261
 
232
    /* Built-in shorthands */
262
	/* Built-in shorthands */
233
    { "~cpp.char_offset", "E", LINK_NONE, LINK_NONE, NULL_id, 2 },
263
	{ "~cpp.char_offset", "E", LINK_NONE, LINK_NONE, NULL_id, 2 },
234
    { "~cpp.shape_offset", "ES", LINK_NONE, LINK_NONE, NULL_id, 2 },
264
	{ "~cpp.shape_offset", "ES", LINK_NONE, LINK_NONE, NULL_id, 2 },
235
    { "~cpp.extra_offset", "EAE", LINK_NONE, LINK_NONE, NULL_id, 2 },
265
	{ "~cpp.extra_offset", "EAE", LINK_NONE, LINK_NONE, NULL_id, 2 },
236
    { "~cpp.down_cast", "EAEE", LINK_NONE, LINK_NONE, NULL_id, 2 },
266
	{ "~cpp.down_cast", "EAEE", LINK_NONE, LINK_NONE, NULL_id, 2 },
237
    { "~cpp.destr_cast", "EAE", LINK_NONE, LINK_NONE, NULL_id, 2 },
267
	{ "~cpp.destr_cast", "EAE", LINK_NONE, LINK_NONE, NULL_id, 2 },
238
    { "~cpp.destr_test", "EEL", LINK_NONE, LINK_NONE, NULL_id, 2 }
268
	{ "~cpp.destr_test", "EEL", LINK_NONE, LINK_NONE, NULL_id, 2 }
239
 
269
 
240
#if 0
270
#if 0
241
    /* Unused standard C tokens */
271
	/* Unused standard C tokens */
242
    { "~assign", "EEES", LINK_NONE, LINK_NONE, NULL_id, 0 },
272
	{ "~assign", "EEES", LINK_NONE, LINK_NONE, NULL_id, 0 },
243
    { "~assign_vol", "EEES", LINK_NONE, LINK_NONE, NULL_id, 0 },
273
	    { "~assign_vol", "EEES", LINK_NONE, LINK_NONE, NULL_id, 0 },
244
    { "~char_lit", "EEZV", LINK_NONE, LINK_NONE, NULL_id, 0 },
274
	    { "~char_lit", "EEZV", LINK_NONE, LINK_NONE, NULL_id, 0 },
245
    { "~checked_plus", "EEE", LINK_NONE, LINK_NONE, NULL_id, 0 },
275
	    { "~checked_plus", "EEE", LINK_NONE, LINK_NONE, NULL_id, 0 },
246
    { "~debug_exp", "ENE", LINK_NONE, LINK_NONE, NULL_id, 0 },
276
	    { "~debug_exp", "ENE", LINK_NONE, LINK_NONE, NULL_id, 0 },
247
    { "~debug_scope", "ENNE", LINK_NONE, LINK_NONE, NULL_id, 0 },
277
	    { "~debug_scope", "ENNE", LINK_NONE, LINK_NONE, NULL_id, 0 },
248
    { "~fn_scope", "EENN", LINK_NONE, LINK_NONE, NULL_id, 0 },
278
	    { "~fn_scope", "EENN", LINK_NONE, LINK_NONE, NULL_id, 0 },
249
    { "~int_promot", "Z", LINK_NONE, LINK_NONE, NULL_id, 0 },
279
	    { "~int_promot", "Z", LINK_NONE, LINK_NONE, NULL_id, 0 },
250
    { "~little_endian", "E", LINK_NONE, LINK_NONE, NULL_id, 0 },
280
	    { "~little_endian", "E", LINK_NONE, LINK_NONE, NULL_id, 0 },
251
    { "~ptr_add", "EEES", LINK_NONE, LINK_NONE, NULL_id, 0 },
281
	    { "~ptr_add", "EEES", LINK_NONE, LINK_NONE, NULL_id, 0 },
252
    { "~ptr_sub", "EEES", LINK_NONE, LINK_NONE, NULL_id, 0 },
282
	    { "~ptr_sub", "EEES", LINK_NONE, LINK_NONE, NULL_id, 0 },
253
    { "~sizeof", "ES", LINK_NONE, LINK_NONE, NULL_id, 0 },
283
	    { "~sizeof", "ES", LINK_NONE, LINK_NONE, NULL_id, 0 },
254
    { "~string_lit", "EEZV", LINK_NONE, LINK_NONE, NULL_id, 0 },
284
	    { "~string_lit", "EEZV", LINK_NONE, LINK_NONE, NULL_id, 0 },
255
    { "~wchar_lit", "EEZV", LINK_NONE, LINK_NONE, NULL_id, 0 },
285
	    { "~wchar_lit", "EEZV", LINK_NONE, LINK_NONE, NULL_id, 0 },
256
#endif
286
#endif
257
} ;
287
};
258
 
288
 
259
 
289
 
260
/*
290
/*
261
    TABLE OF BASIC TYPE TOKENS
291
    TABLE OF BASIC TYPE TOKENS
262
 
292
 
263
    This table gives the mapping from built-in type numbers to external
293
    This table gives the mapping from built-in type numbers to external
264
    token names.
294
    token names.
265
*/
295
*/
266
 
296
 
267
BASE_TOKEN base_token [ ORDER_ntype ] = {
297
BASE_TOKEN base_token[ORDER_ntype] = {
268
    { 0, ARITH_error, ARITH_error },			/* ntype_none */
298
    { 0, ARITH_error, ARITH_error },			/* ntype_none */
269
    { TOK_char, ARITH_char, ARITH_char },		/* ntype_char */
299
    { TOK_char, ARITH_char, ARITH_char },		/* ntype_char */
270
    { TOK_signed_char, ARITH_schar, ARITH_schar },	/* ntype_schar */
300
    { TOK_signed_char, ARITH_schar, ARITH_schar },	/* ntype_schar */
271
    { TOK_unsigned_char, ARITH_uchar, ARITH_uchar },	/* ntype_uchar */
301
    { TOK_unsigned_char, ARITH_uchar, ARITH_uchar },	/* ntype_uchar */
272
    { TOK_signed_short, ARITH_sshort, ARITH_sshort },	/* ntype_sshort */
302
    { TOK_signed_short, ARITH_sshort, ARITH_sshort },	/* ntype_sshort */
Line 285... Line 315...
285
    { TOK_bool, ARITH_none, ARITH_bool },		/* ntype_bool */
315
    { TOK_bool, ARITH_none, ARITH_bool },		/* ntype_bool */
286
    { TOK_ptrdiff_t, ARITH_none, ARITH_ptrdiff_t },	/* ntype_ptrdiff_t */
316
    { TOK_ptrdiff_t, ARITH_none, ARITH_ptrdiff_t },	/* ntype_ptrdiff_t */
287
    { TOK_size_t, ARITH_none, ARITH_size_t },		/* ntype_size_t */
317
    { TOK_size_t, ARITH_none, ARITH_size_t },		/* ntype_size_t */
288
    { TOK_wchar_t, ARITH_none, ARITH_wchar_t },		/* ntype_wchar_t */
318
    { TOK_wchar_t, ARITH_none, ARITH_wchar_t },		/* ntype_wchar_t */
289
    { 0, ARITH_ellipsis, ARITH_ellipsis }		/* ntype_ellipsis */
319
    { 0, ARITH_ellipsis, ARITH_ellipsis }		/* ntype_ellipsis */
290
} ;
320
};
291
 
321
 
292
 
322
 
293
/*
323
/*
294
    INITIALISE SPECIAL TOKENS
324
    INITIALISE SPECIAL TOKENS
295
 
325
 
296
    This routine initialises the special tokens.  This consists of
326
    This routine initialises the special tokens.  This consists of
297
    marking certain tokens which are used but not defined in C as being
327
    marking certain tokens which are used but not defined in C as being
298
    built-in.
328
    built-in.
299
*/
329
*/
300
 
330
 
301
void init_tok
331
void
302
    PROTO_N ( ( c ) )
-
 
303
    PROTO_T ( int c )
332
init_tok(int c)
304
{
333
{
305
    if ( output_std ) {
334
	if (output_std) {
306
	/* Backwards compatibility */
335
		/* Backwards compatibility */
307
	if ( c ) {
336
		if (c) {
308
	    special_token [ TOK_bitf_sign ].builtin = 2 ;
337
			special_token[TOK_bitf_sign].builtin = 2;
309
	    special_token [ TOK_pv_compare ].builtin = 2 ;
338
			special_token[TOK_pv_compare].builtin = 2;
310
	    special_token [ TOK_empty_align ].builtin = 2 ;
339
			special_token[TOK_empty_align].builtin = 2;
311
	    special_token [ TOK_empty_offset ].builtin = 2 ;
340
			special_token[TOK_empty_offset].builtin = 2;
312
	    special_token [ TOK_empty_shape ].builtin = 2 ;
341
			special_token[TOK_empty_shape].builtin = 2;
313
	}
342
		}
314
	special_token [ TOK_ptr_rep ].builtin = 2 ;
343
		special_token[TOK_ptr_rep].builtin = 2;
315
    }
344
	}
316
    if ( c ) {
345
	if (c) {
317
	special_token [ TOK_start ].builtin = 2 ;
346
		special_token[TOK_start].builtin = 2;
318
	base_token [ ntype_bool ].tok = TOK_signed_int ;
347
		base_token[ntype_bool].tok = TOK_signed_int;
319
	base_token [ ntype_bool ].no = ARITH_sint ;
348
		base_token[ntype_bool].no = ARITH_sint;
320
    }
349
	}
321
    return ;
350
	return;
322
}
351
}
323
 
352
 
324
 
353
 
325
/*
354
/*
326
    SET A SPECIAL TOKEN
355
    SET A SPECIAL TOKEN
327
 
356
 
328
    This routine sets the special token t to be id.
357
    This routine sets the special token t to be id.
329
*/
358
*/
330
 
359
 
331
void set_special
360
void
332
    PROTO_N ( ( t, id ) )
-
 
333
    PROTO_T ( int t X IDENTIFIER id )
361
set_special(int t, IDENTIFIER id)
334
{
362
{
335
    if ( !IS_NULL_id ( id ) ) {
363
	if (!IS_NULL_id(id)) {
336
	ulong n = DEREF_ulong ( id_no ( id ) ) ;
364
		ulong n = DEREF_ulong(id_no(id));
337
	ulong m = special_token [t].no ;
365
		ulong m = special_token[t].no;
338
	if ( n == LINK_NONE ) {
366
		if (n == LINK_NONE) {
339
	    COPY_ulong ( id_no ( id ), m ) ;
367
			COPY_ulong(id_no(id), m);
340
	    special_token [t].tok = id ;
368
			special_token[t].tok = id;
341
	} else if ( m == LINK_NONE ) {
369
		} else if (m == LINK_NONE) {
342
	    special_token [t].no = n ;
370
			special_token[t].no = n;
343
	    special_token [t].tok = id ;
371
			special_token[t].tok = id;
344
	} else {
372
		} else {
345
	    /* Should not happen */
373
			/* Should not happen */
346
	    /* EMPTY */
374
			/* EMPTY */
347
	}
375
		}
348
    }
376
	}
349
    return ;
377
	return;
350
}
378
}
351
 
379
 
352
 
380
 
353
/*
381
/*
354
    GET A SPECIAL TOKEN
382
    GET A SPECIAL TOKEN
355
 
383
 
356
    This routine returns the token identifier associated with special
384
    This routine returns the token identifier associated with special
357
    token t.  If force is true then this involves looking up the name
385
    token t.  If force is true then this involves looking up the name
358
    in the token namespace.  The null identifier is returned if there
386
    in the token namespace.  The null identifier is returned if there
359
    is no associated identifier.
387
    is no associated identifier.
360
*/
388
*/
361
 
389
 
362
IDENTIFIER get_special
390
IDENTIFIER
363
    PROTO_N ( ( t, force ) )
-
 
364
    PROTO_T ( int t X int force )
391
get_special(int t, int force)
365
{
392
{
366
    IDENTIFIER id = special_token [t].tok ;
393
	IDENTIFIER id = special_token[t].tok;
367
    if ( IS_NULL_id ( id ) && force ) {
394
	if (IS_NULL_id(id) && force) {
368
	if ( special_token [t].builtin != 2 ) {
395
		if (special_token[t].builtin != 2) {
369
	    string s = ustrlit ( special_token [t].name ) ;
396
			string s = ustrlit(special_token[t].name);
370
	    unsigned long h = hash ( s ) ;
397
			unsigned long h = hash(s);
371
	    HASHID nm = lookup_name ( s, h, 0, lex_identifier ) ;
398
			HASHID nm = lookup_name(s, h, 0, lex_identifier);
372
	    NAMESPACE ns = token_namespace ;
399
			NAMESPACE ns = token_namespace;
373
	    MEMBER mem = search_member ( ns, nm, 0 ) ;
400
			MEMBER mem = search_member(ns, nm, 0);
374
	    if ( !IS_NULL_member ( mem ) ) {
401
			if (!IS_NULL_member(mem)) {
375
		id = DEREF_id ( member_id ( mem ) ) ;
402
				id = DEREF_id(member_id(mem));
376
		set_special ( t, id ) ;
403
				set_special(t, id);
377
	    }
404
			}
378
	}
405
		}
379
    }
406
	}
380
    return ( id ) ;
407
	return (id);
381
}
408
}
382
 
409
 
383
 
410
 
384
/*
411
/*
385
    GET A SPECIAL TOKEN NAME
412
    GET A SPECIAL TOKEN NAME
386
 
413
 
387
    This routine returns the name of the special token t.
414
    This routine returns the name of the special token t.
388
*/
415
*/
389
 
416
 
390
string special_name
417
string
391
    PROTO_N ( ( t ) )
-
 
392
    PROTO_T ( int t )
418
special_name(int t)
393
{
419
{
394
    return ( ustrlit ( special_token [t].name ) ) ;
420
	return (ustrlit(special_token[t].name));
395
}
421
}
396
 
422
 
397
 
423
 
398
/*
424
/*
399
    FIND A TOKEN CODE LETTER
425
    FIND A TOKEN CODE LETTER
400
 
426
 
401
    This routine returns the token code letter corresponding to the token
427
    This routine returns the token code letter corresponding to the token
402
    tok.
428
    tok.
403
*/
429
*/
404
 
430
 
405
int token_code
431
int
406
    PROTO_N ( ( tok ) )
-
 
407
    PROTO_T ( TOKEN tok )
432
token_code(TOKEN tok)
408
{
433
{
409
    if ( !IS_NULL_tok ( tok ) ) {
434
	if (!IS_NULL_tok(tok)) {
410
	switch ( TAG_tok ( tok ) ) {
435
		switch (TAG_tok(tok)) {
411
	    case tok_exp_tag :
436
		case tok_exp_tag:
412
	    case tok_stmt_tag :
437
		case tok_stmt_tag:
413
	    case tok_func_tag :
438
		case tok_func_tag:
414
	    case tok_member_tag : {
439
		case tok_member_tag: {
415
		return ( 'E' ) ;
440
			return ('E');
416
	    }
441
		}
417
	    case tok_nat_tag : {
442
		case tok_nat_tag: {
418
		return ( 'N' ) ;
443
			return ('N');
419
	    }
444
		}
420
	    case tok_snat_tag : {
445
		case tok_snat_tag: {
421
		return ( 'Z' ) ;
446
			return ('Z');
422
	    }
447
		}
423
	    case tok_type_tag : {
448
		case tok_type_tag: {
424
		BASE_TYPE bt = DEREF_btype ( tok_type_kind ( tok ) ) ;
449
			BASE_TYPE bt = DEREF_btype(tok_type_kind(tok));
425
		if ( bt & btype_scalar ) return ( 'Z' ) ;
450
			if (bt & btype_scalar) {
-
 
451
				return ('Z');
-
 
452
			}
426
		return ( 'S' ) ;
453
			return ('S');
427
	    }
454
		}
428
	    case tok_proc_tag : {
455
		case tok_proc_tag: {
429
		TOKEN res = DEREF_tok ( tok_proc_res ( tok ) ) ;
456
			TOKEN res = DEREF_tok(tok_proc_res(tok));
430
		return ( token_code ( res ) ) ;
457
			return (token_code(res));
-
 
458
		}
431
	    }
459
		}
432
	}
460
	}
433
    }
-
 
434
    return ( '?' ) ;
461
	return ('?');
435
}
462
}
436
 
463
 
437
 
464
 
438
/*
465
/*
439
    CREATE A TOKEN SORT
466
    CREATE A TOKEN SORT
440
 
467
 
441
    This routine creates a token sort corresponding (more or less) to the
468
    This routine creates a token sort corresponding (more or less) to the
442
    string s.  If proc is true then the result is a procedure token.
469
    string s.  If proc is true then the result is a procedure token.
443
*/
470
*/
444
 
471
 
445
TOKEN make_sort
472
TOKEN
446
    PROTO_N ( ( s, proc ) )
-
 
447
    PROTO_T ( CONST char *s X int proc )
473
make_sort(CONST char *s, int proc)
448
{
474
{
449
    TOKEN tok ;
475
	TOKEN tok;
450
    if ( proc ) {
476
	if (proc) {
451
	unsigned i ;
477
		unsigned i;
452
	TOKEN ptok ;
478
		TOKEN ptok;
453
	unsigned n = ( unsigned ) strlen ( s ) ;
479
		unsigned n = (unsigned)strlen(s);
454
	LIST ( IDENTIFIER ) pids = NULL_list ( IDENTIFIER ) ;
480
		LIST(IDENTIFIER)pids = NULL_list(IDENTIFIER);
455
	tok = begin_proc_token () ;
481
		tok = begin_proc_token();
456
	for ( i = 1 ; i < n ; i++ ) {
482
		for (i = 1; i < n; i++) {
457
	    IDENTIFIER pid ;
483
			IDENTIFIER pid;
458
	    ptok = make_sort ( s + i, 0 ) ;
484
			ptok = make_sort(s + i, 0);
459
	    pid = make_tok_param ( ptok, 0, NULL_id ) ;
485
			pid = make_tok_param(ptok, 0, NULL_id);
460
	    CONS_id ( pid, pids, pids ) ;
486
			CONS_id(pid, pids, pids);
461
	}
487
		}
462
	pids = REVERSE_list ( pids ) ;
488
		pids = REVERSE_list(pids);
463
	tok = cont_proc_token ( tok, pids, pids ) ;
489
		tok = cont_proc_token(tok, pids, pids);
464
	ptok = make_sort ( s, 0 ) ;
490
		ptok = make_sort(s, 0);
465
	tok = end_proc_token ( tok, ptok ) ;
491
		tok = end_proc_token(tok, ptok);
466
    } else {
492
	} else {
467
	switch ( *s ) {
493
		switch (*s) {
468
	    case 'E' : {
494
		case 'E': {
469
		tok = make_exp_token ( type_error, 0, 0 ) ;
495
			tok = make_exp_token(type_error, 0, 0);
470
		break ;
496
			break;
471
	    }
497
		}
472
	    case 'N' : {
498
		case 'N': {
473
		MAKE_tok_nat ( NULL_nat, tok ) ;
499
			MAKE_tok_nat(NULL_nat, tok);
474
		break ;
500
			break;
475
	    }
501
		}
476
	    case 'S' : {
502
		case 'S': {
477
		tok = make_type_token ( btype_none ) ;
503
			tok = make_type_token(btype_none);
478
		break ;
504
			break;
479
	    }
505
		}
480
	    case 'Z' : {
506
		case 'Z': {
481
		tok = make_type_token ( btype_int ) ;
507
			tok = make_type_token(btype_int);
482
		break ;
508
			break;
483
	    }
509
		}
484
	    default : {
510
		default : {
485
		FAIL ( Unknown sort ) ;
511
			FAIL(Unknown sort);
486
		tok = NULL_tok ;
512
			tok = NULL_tok;
487
		break ;
513
			break;
-
 
514
		}
488
	    }
515
		}
489
	}
516
	}
490
    }
-
 
491
    return ( tok ) ;
517
	return (tok);
492
}
518
}
493
 
519
 
494
 
520
 
495
/*
521
/*
496
    CHECK A TOKEN SORT
522
    CHECK A TOKEN SORT
497
 
523
 
498
    This routine checks whether the sort of the token tok (either the
524
    This routine checks whether the sort of the token tok (either the
499
    program sort or the bound sort, depending on the value of prog)
525
    program sort or the bound sort, depending on the value of prog)
500
    corresponds to the string s.
526
    corresponds to the string s.
501
*/
527
*/
502
 
528
 
503
static int check_sort
529
static int
504
    PROTO_N ( ( tok, s, prog ) )
-
 
505
    PROTO_T ( TOKEN tok X CONST char *s X int prog )
530
check_sort(TOKEN tok, CONST char *s, int prog)
506
{
531
{
507
    char r = *( s++ ) ;
532
	char r = *(s++);
508
    unsigned tag = TAG_tok ( tok ) ;
533
	unsigned tag = TAG_tok(tok);
509
    if ( tag == tok_func_tag ) {
534
	if (tag == tok_func_tag) {
510
	/* Function tokens */
535
		/* Function tokens */
511
	tok = func_proc_token ( tok ) ;
536
		tok = func_proc_token(tok);
512
	tag = TAG_tok ( tok ) ;
537
		tag = TAG_tok(tok);
513
    }
538
	}
514
    if ( tag == tok_proc_tag ) {
539
	if (tag == tok_proc_tag) {
515
	/* Procedure tokens */
540
		/* Procedure tokens */
516
	LIST ( IDENTIFIER ) bids ;
541
		LIST(IDENTIFIER)bids;
517
	TOKEN res = DEREF_tok ( tok_proc_res ( tok ) ) ;
542
		TOKEN res = DEREF_tok(tok_proc_res(tok));
518
	char c = ( char ) token_code ( res ) ;
543
		char c = (char)token_code(res);
519
	if ( c != r ) return ( 0 ) ;
544
		if (c != r) {
-
 
545
			return (0);
-
 
546
		}
520
	r = *( s++ ) ;
547
		r = *(s++);
521
	if ( prog ) {
548
		if (prog) {
522
	    bids = DEREF_list ( tok_proc_pids ( tok ) ) ;
549
			bids = DEREF_list(tok_proc_pids(tok));
523
	} else {
550
		} else {
524
	    bids = DEREF_list ( tok_proc_bids ( tok ) ) ;
551
			bids = DEREF_list(tok_proc_bids(tok));
525
	}
552
		}
526
	while ( !IS_NULL_list ( bids ) ) {
553
		while (!IS_NULL_list(bids)) {
527
	    IDENTIFIER bid = DEREF_id ( HEAD_list ( bids ) ) ;
554
			IDENTIFIER bid = DEREF_id(HEAD_list(bids));
528
	    if ( !IS_NULL_id ( bid ) && IS_id_token ( bid ) ) {
555
			if (!IS_NULL_id(bid) && IS_id_token(bid)) {
529
		res = DEREF_tok ( id_token_sort ( bid ) ) ;
556
				res = DEREF_tok(id_token_sort(bid));
530
		c = ( char ) token_code ( res ) ;
557
				c = (char)token_code(res);
531
	    } else {
558
			} else {
532
		c = '?' ;
559
				c = '?';
533
	    }
560
			}
534
	    if ( c != r ) return ( 0 ) ;
561
			if (c != r) {
-
 
562
				return (0);
-
 
563
			}
535
	    c = *s ;
564
			c = *s;
536
	    if ( c == '*' ) {
565
			if (c == '*') {
537
		/* Don't advance after '*' */
566
				/* Don't advance after '*' */
538
		c = 0 ;
567
				c = 0;
539
	    } else {
568
			} else {
540
		r = c ;
569
				r = c;
541
		s++ ;
570
				s++;
542
	    }
571
			}
543
	    bids = TAIL_list ( bids ) ;
572
			bids = TAIL_list(bids);
544
	}
573
		}
545
	r = c ;
574
		r = c;
546
    } else {
575
	} else {
547
	/* Other tokens */
576
		/* Other tokens */
548
	char c = ( char ) token_code ( tok ) ;
577
		char c = (char)token_code(tok);
549
	if ( c != r ) return ( 0 ) ;
578
		if (c != r) {
-
 
579
			return (0);
-
 
580
		}
550
	r = *s ;
581
		r = *s;
551
    }
582
	}
-
 
583
	if (r) {
552
    if ( r ) return ( 0 ) ;
584
		return (0);
-
 
585
	}
553
    return ( 1 ) ;
586
	return (1);
554
}
587
}
555
 
588
 
556
 
589
 
557
/*
590
/*
558
    FIND A TOKEN WITH A GIVEN SORT
591
    FIND A TOKEN WITH A GIVEN SORT
559
 
592
 
560
    This routine checks whether id is a token with the given sort, giving
593
    This routine checks whether id is a token with the given sort, giving
561
    an error if id is not a token or has the wrong sort.
594
    an error if id is not a token or has the wrong sort.
562
*/
595
*/
563
 
596
 
564
IDENTIFIER resolve_token
597
IDENTIFIER
565
    PROTO_N ( ( id, s, prog ) )
-
 
566
    PROTO_T ( IDENTIFIER id X CONST char *s X int prog )
598
resolve_token(IDENTIFIER id, CONST char *s, int prog)
567
{
599
{
568
    int ok = 0 ;
600
	int ok = 0;
569
    IDENTIFIER rid = NULL_id ;
601
	IDENTIFIER rid = NULL_id;
570
    IDENTIFIER pid = id ;
602
	IDENTIFIER pid = id;
571
    while ( !IS_NULL_id ( pid ) ) {
603
	while (!IS_NULL_id(pid)) {
572
	IDENTIFIER tid = find_token ( pid ) ;
604
		IDENTIFIER tid = find_token(pid);
573
	if ( IS_id_token ( tid ) ) {
605
		if (IS_id_token(tid)) {
574
	    TOKEN tok = DEREF_tok ( id_token_sort ( tid ) ) ;
606
			TOKEN tok = DEREF_tok(id_token_sort(tid));
575
	    if ( check_sort ( tok, s, prog ) ) {
607
			if (check_sort(tok, s, prog)) {
576
		if ( !IS_NULL_id ( rid ) ) {
608
				if (!IS_NULL_id(rid)) {
-
 
609
					report(preproc_loc,
577
		    report ( preproc_loc, ERR_lookup_ambig_id ( pid ) ) ;
610
					       ERR_lookup_ambig_id(pid));
578
		    break ;
611
					break;
579
		}
612
				}
580
		rid = tid ;
613
				rid = tid;
581
	    } else {
614
			} else {
582
		report ( preproc_loc, ERR_pragma_token_sort ( pid ) ) ;
615
				report(preproc_loc, ERR_pragma_token_sort(pid));
583
	    }
616
			}
584
	    ok = 1 ;
617
			ok = 1;
585
	}
618
		}
586
	if ( !IS_id_function_etc ( pid ) ) break ;
619
		if (!IS_id_function_etc(pid)) {
-
 
620
			break;
-
 
621
		}
587
	pid = DEREF_id ( id_function_etc_over ( pid ) ) ;
622
		pid = DEREF_id(id_function_etc_over(pid));
588
    }
623
	}
589
    if ( !ok ) {
624
	if (!ok) {
590
	/* Token not found */
625
		/* Token not found */
591
	report ( preproc_loc, ERR_token_undecl ( id ) ) ;
626
		report(preproc_loc, ERR_token_undecl(id));
592
    }
627
	}
593
    return ( rid ) ;
628
	return (rid);
594
}
629
}
595
 
630
 
596
 
631
 
597
/*
632
/*
598
    CHECK WHETHER A TOKEN IS A BUILT-IN TOKEN
633
    CHECK WHETHER A TOKEN IS A BUILT-IN TOKEN
599
 
634
 
600
    This routine checks whether the token id is one of the built-in tokens
635
    This routine checks whether the token id is one of the built-in tokens
601
    listed above.  If so this definition is output, provided TDF output is
636
    listed above.  If so this definition is output, provided TDF output is
602
    enabled, and the routine returns the corresponding special token number.
637
    enabled, and the routine returns the corresponding special token number.
603
    Otherwise the routine returns -1.
638
    Otherwise the routine returns -1.
604
*/
639
*/
605
 
640
 
606
int builtin_token
641
int
607
    PROTO_N ( ( id ) )
-
 
608
    PROTO_T ( IDENTIFIER id )
642
builtin_token(IDENTIFIER id)
609
{
643
{
610
    int t = 0 ;
644
	int t = 0;
611
    string s ;
645
	string s;
612
    HASHID nm = DEREF_hashid ( id_name ( id ) ) ;
646
	HASHID nm = DEREF_hashid(id_name(id));
613
    if ( !IS_hashid_name_etc ( nm ) ) return ( -1 ) ;
647
	if (!IS_hashid_name_etc(nm)) {
614
    s = DEREF_string ( hashid_name_etc_text ( nm ) ) ;
-
 
615
    if ( s [0] != '~' ) {
-
 
616
	/* Only built-in types don't begin with '~' */
-
 
617
	switch ( find_hashid ( nm ) ) {
-
 
618
	    case lex_ptrdiff_Ht : t = TOK_ptrdiff_t ; break ;
-
 
619
	    case lex_size_Ht : t = TOK_size_t ; break ;
-
 
620
	    case lex_size_Ht_H2 : t = TOK_size_t_2 ; break ;
-
 
621
	    case lex_wchar_Ht : t = TOK_wchar_t ; break ;
-
 
622
	    default : return ( -1 ) ;
648
		return (-1);
623
	}
649
	}
624
    }
-
 
625
    while ( t < TOK_no ) {
-
 
626
	int b = special_token [t].builtin ;
650
	s = DEREF_string(hashid_name_etc_text(nm));
627
	if ( b != 2 ) {
651
	if (s[0]!= '~') {
628
	    string n = ustrlit ( special_token [t].name ) ;
652
		/* Only built-in types don't begin with '~' */
629
	    if ( ustreq ( s, n ) ) {
653
		switch (find_hashid(nm)) {
630
		CONST char *p = special_token [t].sorts ;
654
		case lex_ptrdiff_Ht:
631
		TOKEN sort = DEREF_tok ( id_token_sort ( id ) ) ;
655
			t = TOK_ptrdiff_t;
-
 
656
			break;
632
		if ( !check_sort ( sort, p, 0 ) ) {
657
		case lex_size_Ht:
-
 
658
			t = TOK_size_t;
-
 
659
			break;
633
		    /* Check that token sort matches */
660
		case lex_size_Ht_H2:
634
		    IDENTIFIER tid = DEREF_id ( id_token_alt ( id ) ) ;
661
			t = TOK_size_t_2;
-
 
662
			break;
-
 
663
		case lex_wchar_Ht:
635
		    report ( crt_loc, ERR_pragma_token_sort ( tid ) ) ;
664
			t = TOK_wchar_t;
-
 
665
			break;
-
 
666
		default:
636
		    return ( -1 ) ;
667
			return (-1);
637
		}
668
		}
-
 
669
	}
-
 
670
	while (t < TOK_no) {
-
 
671
		int b = special_token[t].builtin;
-
 
672
		if (b != 2) {
-
 
673
			string n = ustrlit(special_token[t].name);
-
 
674
			if (ustreq(s, n)) {
-
 
675
				CONST char *p = special_token[t].sorts;
-
 
676
				TOKEN sort = DEREF_tok(id_token_sort(id));
-
 
677
				if (!check_sort(sort, p, 0)) {
-
 
678
					/* Check that token sort matches */
-
 
679
					IDENTIFIER tid =
-
 
680
					    DEREF_id(id_token_alt(id));
-
 
681
					report(crt_loc,
-
 
682
					       ERR_pragma_token_sort(tid));
-
 
683
					return (-1);
-
 
684
				}
638
		set_special ( t, id ) ;
685
				set_special(t, id);
639
		if ( b ) {
686
				if (b) {
640
		    /* Define token if possible */
687
					/* Define token if possible */
-
 
688
					DECL_SPEC ds =
641
		    DECL_SPEC ds = DEREF_dspec ( id_storage ( id ) ) ;
689
					    DEREF_dspec(id_storage(id));
642
		    define_special ( t ) ;
690
					define_special(t);
643
		    ds |= ( dspec_defn | dspec_done ) ;
691
					ds |= (dspec_defn | dspec_done);
644
		    COPY_dspec ( id_storage ( id ), ds ) ;
692
					COPY_dspec(id_storage(id), ds);
-
 
693
				}
-
 
694
				return (t);
-
 
695
			}
645
		}
696
		}
646
		return ( t ) ;
-
 
647
	    }
697
		t++;
648
	}
698
	}
649
	t++ ;
-
 
650
    }
-
 
651
    return ( -1 ) ;
699
	return (-1);
652
}
700
}
653
 
701
 
654
 
702
 
655
/*
703
/*
656
    TDF ENCODING ROUTINES
704
    TDF ENCODING ROUTINES
Line 666... Line 714...
666
    ENCODE A FOREIGN SORT
714
    ENCODE A FOREIGN SORT
667
 
715
 
668
    This routine adds the foreign sort named s to the bitstream bs.
716
    This routine adds the foreign sort named s to the bitstream bs.
669
*/
717
*/
670
 
718
 
671
static BITSTREAM *enc_foreign_sort
719
static BITSTREAM *
672
    PROTO_N ( ( bs, s ) )
-
 
673
    PROTO_T ( BITSTREAM *bs X CONST char *s )
720
enc_foreign_sort(BITSTREAM *bs, CONST char *s)
674
{
721
{
675
    ENC_foreign_sort ( bs ) ;
722
	ENC_foreign_sort(bs);
676
    ENC_make_string ( bs ) ;
723
	ENC_make_string(bs);
677
    bs = enc_ustring ( bs, ustrlit ( s ) ) ;
724
	bs = enc_ustring(bs, ustrlit(s));
678
    return ( bs ) ;
725
	return (bs);
679
}
726
}
680
 
727
 
681
 
728
 
682
/*
729
/*
683
    ENCODE A SORT LETTER
730
    ENCODE A SORT LETTER
684
 
731
 
685
    This routine adds the TDF SORTNAME corresponding to the code letter s
732
    This routine adds the TDF SORTNAME corresponding to the code letter s
686
    to the bitstream bs.
733
    to the bitstream bs.
687
*/
734
*/
688
 
735
 
689
BITSTREAM *enc_sort
736
BITSTREAM *
690
    PROTO_N ( ( bs, s ) )
-
 
691
    PROTO_T ( BITSTREAM *bs X int s )
737
enc_sort(BITSTREAM *bs, int s)
692
{
738
{
693
    switch ( s ) {
739
	switch (s) {
-
 
740
	case 'A':
694
	case 'A' : ENC_alignment_sort ( bs ) ; break ;
741
		ENC_alignment_sort(bs);
-
 
742
		break;
-
 
743
	case 'B':
695
	case 'B' : ENC_bool ( bs ) ; break ;
744
		ENC_bool(bs);
-
 
745
		break;
-
 
746
	case 'C':
696
	case 'C' : ENC_string ( bs ) ; break ;
747
		ENC_string(bs);
-
 
748
		break;
-
 
749
	case 'E':
697
	case 'E' : ENC_exp ( bs ) ; break ;
750
		ENC_exp(bs);
-
 
751
		break;
-
 
752
	case 'F':
698
	case 'F' : ENC_floating_variety ( bs ) ; break ;
753
		ENC_floating_variety(bs);
-
 
754
		break;
-
 
755
	case 'L':
699
	case 'L' : ENC_label ( bs ) ; break ;
756
		ENC_label(bs);
-
 
757
		break;
-
 
758
	case 'N':
700
	case 'N' : ENC_nat ( bs ) ; break ;
759
		ENC_nat(bs);
-
 
760
		break;
-
 
761
	case 'S':
701
	case 'S' : ENC_shape ( bs ) ; break ;
762
		ENC_shape(bs);
-
 
763
		break;
-
 
764
	case 'T':
702
	case 'T' : ENC_ntest ( bs ) ; break ;
765
		ENC_ntest(bs);
-
 
766
		break;
-
 
767
	case 'U':
703
	case 'U' : ENC_bitfield_variety ( bs ) ; break ;
768
		ENC_bitfield_variety(bs);
-
 
769
		break;
-
 
770
	case 'V':
704
	case 'V' : ENC_variety ( bs ) ; break ;
771
		ENC_variety(bs);
-
 
772
		break;
-
 
773
	case 'Z':
705
	case 'Z' : ENC_signed_nat ( bs ) ; break ;
774
		ENC_signed_nat(bs);
-
 
775
		break;
706
	case 'P' : {
776
	case 'P': {
707
	    bs = enc_foreign_sort ( bs, LINK_filename ) ;
777
		bs = enc_foreign_sort(bs, LINK_filename);
708
	    break ;
778
		break;
709
	}
779
	}
710
#ifdef ENC_dg_filename_apply_token
780
#ifdef ENC_dg_filename_apply_token
711
	case 'Q' : {
781
	case 'Q': {
712
	    bs = enc_foreign_sort ( bs, LINK_dg_filename ) ;
782
		bs = enc_foreign_sort(bs, LINK_dg_filename);
713
	    break ;
783
		break;
714
	}
784
	}
715
#endif
785
#endif
716
	default : {
786
	default: {
717
	    FAIL ( Unknown sort ) ;
787
		FAIL(Unknown sort);
718
	    break ;
788
		break;
719
	}
789
	}
720
    }
790
	}
721
    return ( bs ) ;
791
	return (bs);
722
}
792
}
723
 
793
 
724
 
794
 
725
/*
795
/*
726
    ENCODE A TOKEN APPLICATION CONSTRUCT
796
    ENCODE A TOKEN APPLICATION CONSTRUCT
727
 
797
 
728
    This routine adds a token application construct for the sort with
798
    This routine adds a token application construct for the sort with
729
    code letter s to the bitstream bs.
799
    code letter s to the bitstream bs.
730
*/
800
*/
731
 
801
 
732
static BITSTREAM *enc_apply_token
802
static BITSTREAM *
733
    PROTO_N ( ( bs, s ) )
-
 
734
    PROTO_T ( BITSTREAM *bs X int s )
803
enc_apply_token(BITSTREAM *bs, int s)
735
{
804
{
736
    switch ( s ) {
805
	switch (s) {
-
 
806
	case 'A':
737
	case 'A' : ENC_alignment_apply_token ( bs ) ; break ;
807
		ENC_alignment_apply_token(bs);
-
 
808
		break;
-
 
809
	case 'B':
738
	case 'B' : ENC_bool_apply_token ( bs ) ; break ;
810
		ENC_bool_apply_token(bs);
-
 
811
		break;
-
 
812
	case 'C':
739
	case 'C' : ENC_string_apply_token ( bs ) ; break ;
813
		ENC_string_apply_token(bs);
-
 
814
		break;
-
 
815
	case 'E':
740
	case 'E' : ENC_exp_apply_token ( bs ) ; break ;
816
		ENC_exp_apply_token(bs);
-
 
817
		break;
-
 
818
	case 'F':
741
	case 'F' : ENC_flvar_apply_token ( bs ) ; break ;
819
		ENC_flvar_apply_token(bs);
-
 
820
		break;
-
 
821
	case 'L':
742
	case 'L' : ENC_label_apply_token ( bs ) ; break ;
822
		ENC_label_apply_token(bs);
-
 
823
		break;
-
 
824
	case 'N':
743
	case 'N' : ENC_nat_apply_token ( bs ) ; break ;
825
		ENC_nat_apply_token(bs);
-
 
826
		break;
-
 
827
	case 'S':
744
	case 'S' : ENC_shape_apply_token ( bs ) ; break ;
828
		ENC_shape_apply_token(bs);
-
 
829
		break;
-
 
830
	case 'T':
745
	case 'T' : ENC_ntest_apply_token ( bs ) ; break ;
831
		ENC_ntest_apply_token(bs);
-
 
832
		break;
-
 
833
	case 'U':
746
	case 'U' : ENC_bfvar_apply_token ( bs ) ; break ;
834
		ENC_bfvar_apply_token(bs);
-
 
835
		break;
-
 
836
	case 'V':
747
	case 'V' : ENC_var_apply_token ( bs ) ; break ;
837
		ENC_var_apply_token(bs);
-
 
838
		break;
-
 
839
	case 'Z':
748
	case 'Z' : ENC_signed_nat_apply_token ( bs ) ; break ;
840
		ENC_signed_nat_apply_token(bs);
-
 
841
		break;
-
 
842
	case 'P':
749
	case 'P' : ENC_filename_apply_token ( bs ) ; break ;
843
		ENC_filename_apply_token(bs);
-
 
844
		break;
750
#ifdef ENC_dg_filename_apply_token
845
#ifdef ENC_dg_filename_apply_token
-
 
846
	case 'Q':
751
	case 'Q' : ENC_dg_filename_apply_token ( bs ) ; break ;
847
		ENC_dg_filename_apply_token(bs);
-
 
848
		break;
752
#endif
849
#endif
-
 
850
	default:
753
	default : FAIL ( Unknown sort ) ; break ;
851
		FAIL(Unknown sort);
-
 
852
		break;
754
    }
853
	}
755
    return ( bs ) ;
854
	return (bs);
756
}
855
}
757
 
856
 
758
 
857
 
759
/*
858
/*
760
    FIND A SPECIAL TOKEN NUMBER
859
    FIND A SPECIAL TOKEN NUMBER
761
 
860
 
762
    This routine returns the external (capsule) token number of the
861
    This routine returns the external (capsule) token number of the
763
    special token given by t.
862
    special token given by t.
764
*/
863
*/
765
 
864
 
766
ulong special_no
865
ulong
767
    PROTO_N ( ( t ) )
-
 
768
    PROTO_T ( int t )
866
special_no(int t)
769
{
867
{
770
    ulong n = special_token [t].no ;
868
	ulong n = special_token[t].no;
771
    if ( n == LINK_NONE ) {
869
	if (n == LINK_NONE) {
772
	/* Declare token */
870
		/* Declare token */
773
	int def = 0 ;
871
		int def = 0;
774
	IDENTIFIER id = special_token [t].tok ;
872
		IDENTIFIER id = special_token[t].tok;
775
	if ( !IS_NULL_id ( id ) ) {
873
		if (!IS_NULL_id(id)) {
776
	    n = DEREF_ulong ( id_no ( id ) ) ;
874
			n = DEREF_ulong(id_no(id));
777
	    if ( n != LINK_NONE ) {
875
			if (n != LINK_NONE) {
778
		special_token [t].no = n ;
876
				special_token[t].no = n;
779
		return ( n ) ;
877
				return (n);
780
	    }
878
			}
781
	    IGNORE capsule_id ( id, VAR_token ) ;
879
			IGNORE capsule_id(id, VAR_token);
782
	    n = DEREF_ulong ( id_no ( id ) ) ;
880
			n = DEREF_ulong(id_no(id));
783
	} else {
881
		} else {
784
	    string s = ustrlit ( special_token [t].name ) ;
882
			string s = ustrlit(special_token[t].name);
785
	    if ( special_token [t].builtin == 2 ) {
883
			if (special_token[t].builtin == 2) {
786
		s = NULL ;
884
				s = NULL;
787
		def = 1 ;
885
				def = 1;
788
	    }
886
			}
789
	    n = capsule_no ( s, VAR_token ) ;
887
			n = capsule_no(s, VAR_token);
790
	}
888
		}
791
	special_token [t].no = n ;
889
		special_token[t].no = n;
792
	if ( tokdec_unit ) {
890
		if (tokdec_unit) {
793
	    /* Declare token */
891
			/* Declare token */
794
	    CONST char *sorts = special_token [t].sorts ;
892
			CONST char *sorts = special_token[t].sorts;
795
	    enc_tokdec ( n, sorts ) ;
893
			enc_tokdec(n, sorts);
796
	}
894
		}
797
	if ( def ) {
895
		if (def) {
798
	    /* Define token if necessary */
896
			/* Define token if necessary */
799
	    define_special ( t ) ;
897
			define_special(t);
-
 
898
		}
800
	}
899
	}
801
    }
-
 
802
    return ( n ) ;
900
	return (n);
803
}
901
}
804
 
902
 
805
 
903
 
806
/*
904
/*
807
    ENCODE A SPECIAL TOKEN
905
    ENCODE A SPECIAL TOKEN
808
 
906
 
809
    This routine adds an application of the special token given by t to
907
    This routine adds an application of the special token given by t to
810
    the bitstream bs.  If the token takes no arguments the zero value
908
    the bitstream bs.  If the token takes no arguments the zero value
811
    representing these arguments is added, otherwise the arguments must
909
    representing these arguments is added, otherwise the arguments must
812
    be encoded by hand.
910
    be encoded by hand.
813
*/
911
*/
814
 
912
 
815
BITSTREAM *enc_special
913
BITSTREAM *
816
    PROTO_N ( ( bs, t ) )
-
 
817
    PROTO_T ( BITSTREAM *bs X int t )
914
enc_special(BITSTREAM *bs, int t)
818
{
915
{
819
    ulong n ;
916
	ulong n;
820
    CONST char *sorts = special_token [t].sorts ;
917
	CONST char *sorts = special_token[t].sorts;
821
    bs = enc_apply_token ( bs, ( int ) sorts [0] ) ;
918
	bs = enc_apply_token(bs,(int)sorts[0]);
822
    n = special_no ( t ) ;
919
	n = special_no(t);
823
    n = link_no ( bs, n, VAR_token ) ;
920
	n = link_no(bs, n, VAR_token);
824
    ENC_make_tok ( bs, n ) ;
921
	ENC_make_tok(bs, n);
825
    if ( sorts [1] ) {
922
	if (sorts[1]) {
826
	/* Arguments must be encoded separately */
923
		/* Arguments must be encoded separately */
827
	/* EMPTY */
924
		/* EMPTY */
828
    } else {
925
	} else {
829
	ENC_LEN_SMALL ( bs, 0 ) ;
926
		ENC_LEN_SMALL(bs, 0);
830
    }
927
	}
831
    return ( bs ) ;
928
	return (bs);
832
}
929
}
833
 
930
 
834
 
931
 
835
/*
932
/*
836
    ENCODE A SPECIAL DIAGNOSTICS TAG
933
    ENCODE A SPECIAL DIAGNOSTICS TAG
837
 
934
 
838
    Certain of the special tokens which represent types also have diagnostic
935
    Certain of the special tokens which represent types also have diagnostic
839
    tag forms.  This routine adds a diagnostic tag for the special token t
936
    tag forms.  This routine adds a diagnostic tag for the special token t
840
    to the bitstream bs.
937
    to the bitstream bs.
841
*/
938
*/
842
 
939
 
843
BITSTREAM *enc_diag_special
940
BITSTREAM *
844
    PROTO_N ( ( bs, t, v ) )
-
 
845
    PROTO_T ( BITSTREAM *bs X int t X int v )
941
enc_diag_special(BITSTREAM *bs, int t, int v)
846
{
942
{
847
    ulong n = special_token [t].diag ;
943
	ulong n = special_token[t].diag;
848
    if ( n == LINK_NONE ) {
944
	if (n == LINK_NONE) {
849
	string s = ustrlit ( special_token [t].name ) ;
945
		string s = ustrlit(special_token[t].name);
850
	n = capsule_no ( s, v ) ;
946
		n = capsule_no(s, v);
851
	special_token [t].diag = n ;
947
		special_token[t].diag = n;
852
    }
948
	}
853
    n = link_no ( bs, n, v ) ;
949
	n = link_no(bs, n, v);
854
#if TDF_NEW_DIAG
950
#if TDF_NEW_DIAG
855
    if ( v == VAR_dgtag ) {
951
	if (v == VAR_dgtag) {
856
	ENC_dg_named_type ( bs ) ;
952
		ENC_dg_named_type(bs);
857
	ENC_make_dg_tag ( bs, n ) ;
953
		ENC_make_dg_tag(bs, n);
858
	return ( bs ) ;
954
		return (bs);
859
    }
955
	}
860
#endif
956
#endif
861
    ENC_use_diag_tag ( bs ) ;
957
	ENC_use_diag_tag(bs);
862
    ENC_make_diag_tag ( bs, n ) ;
958
	ENC_make_diag_tag(bs, n);
863
    return ( bs ) ;
959
	return (bs);
864
}
960
}
865
 
961
 
866
 
962
 
867
/*
963
/*
868
    ENCODE A TOKEN PARAMETER
964
    ENCODE A TOKEN PARAMETER
869
 
965
 
870
    This routine adds the nth parameter for a token with sort string sort
966
    This routine adds the nth parameter for a token with sort string sort
871
    and parameters pars to the bitstream bs.
967
    and parameters pars to the bitstream bs.
872
*/
968
*/
873
 
969
 
874
static BITSTREAM *enc_param
970
static BITSTREAM *
875
    PROTO_N ( ( bs, n, sorts, pars ) )
-
 
876
    PROTO_T ( BITSTREAM *bs X int n X CONST char *sorts X ulong *pars )
971
enc_param(BITSTREAM *bs, int n, CONST char *sorts, ulong *pars)
877
{
972
{
878
    bs = enc_apply_token ( bs, ( int ) sorts [ n + 1 ] ) ;
973
	bs = enc_apply_token(bs,(int)sorts[n + 1]);
879
    ENC_make_tok ( bs, pars [n] ) ;
974
	ENC_make_tok(bs, pars[n]);
880
    ENC_LEN_SMALL ( bs, 0 ) ;
975
	ENC_LEN_SMALL(bs, 0);
881
    return ( bs ) ;
976
	return (bs);
882
}
977
}
883
 
978
 
884
 
979
 
885
/*
980
/*
886
    ENCODE THE DEFINITION OF A BUILT-IN SPECIAL TOKEN
981
    ENCODE THE DEFINITION OF A BUILT-IN SPECIAL TOKEN
887
 
982
 
888
    Certain of the special tokens have built-in definitions.  This routine
983
    Certain of the special tokens have built-in definitions.  This routine
889
    outputs such a definition for the special token t.
984
    outputs such a definition for the special token t.
890
*/
985
*/
891
 
-
 
892
void define_special
-
 
893
    PROTO_N ( ( t ) )
-
 
894
    PROTO_T ( int t )
-
 
895
{
-
 
896
    BITSTREAM *bs ;
-
 
897
    ulong pars [10] ;
-
 
898
    CONST char *sorts ;
-
 
899
    TYPE s = NULL_type ;
-
 
900
    ulong n = special_no ( t ) ;
-
 
901
    unsigned acc = find_usage ( n, VAR_token ) ;
-
 
902
    if ( acc & USAGE_DEFN ) return ;
-
 
903
    sorts = special_token [t].sorts ;
-
 
904
    bs = enc_tokdef_start ( n, sorts, pars, 0 ) ;
-
 
905
    switch ( t ) {
-
 
906
 
-
 
907
	case TOK_bitf_sign : {
-
 
908
	    /* Bitfield sign (C version) */
-
 
909
	    BITSTREAM *ts ;
-
 
910
	    TYPE c = type_sint ;
-
 
911
	    ENC_bool_cond ( bs ) ;
-
 
912
	    ENC_and ( bs ) ;
-
 
913
	    ENC_make_int ( bs ) ;
-
 
914
	    bs = enc_variety ( bs, c ) ;
-
 
915
	    bs = enc_param ( bs, 0, sorts, pars ) ;
-
 
916
	    bs = enc_make_int ( bs, c, ARITH_uchar ) ;
-
 
917
	    ts = start_bitstream ( NIL ( FILE ), bs->link ) ;
-
 
918
	    ENC_false ( ts ) ;
-
 
919
	    bs = enc_bitstream ( bs, ts ) ;
-
 
920
	    ts = start_bitstream ( NIL ( FILE ), bs->link ) ;
-
 
921
	    ENC_true ( ts ) ;
-
 
922
	    bs = enc_bitstream ( bs, ts ) ;
-
 
923
	    break ;
-
 
924
	}
-
 
925
 
-
 
926
	case TOK_pv_compare : {
-
 
927
	    /* Comparison of pointer to void (C version) */
-
 
928
	    ENC_pointer_test ( bs ) ;
-
 
929
	    ENC_OFF ( bs ) ;
-
 
930
	    bs = enc_param ( bs, 3, sorts, pars ) ;
-
 
931
	    bs = enc_param ( bs, 2, sorts, pars ) ;
-
 
932
	    bs = enc_param ( bs, 0, sorts, pars ) ;
-
 
933
	    bs = enc_param ( bs, 1, sorts, pars ) ;
-
 
934
	    break ;
-
 
935
	}
-
 
936
 
-
 
937
	case TOK_ptr_rep : {
-
 
938
	    /* Integral type the same size as a pointer */
-
 
939
	    bs = enc_make_snat ( bs, ARITH_ulong ) ;
-
 
940
	    break ;
-
 
941
	}
-
 
942
 
-
 
943
	case TOK_empty_align : {
-
 
944
	    /* Alignment of empty class (C version) */
-
 
945
	    bs = enc_alignment ( bs, type_ldouble ) ;
-
 
946
	    break ;
-
 
947
	}
-
 
948
 
-
 
949
	case TOK_empty_offset : {
-
 
950
	    /* Offset of empty class (C version) */
-
 
951
	    BITSTREAM *ts ;
-
 
952
	    TYPE c = type_char ;
-
 
953
	    bs = enc_special ( bs, TOK_comp_off ) ;
-
 
954
	    ts = start_bitstream ( NIL ( FILE ), bs->link ) ;
-
 
955
	    ENC_offset_add ( ts ) ;
-
 
956
	    ENC_offset_zero ( ts ) ;
-
 
957
	    ts = enc_alignment ( ts, c ) ;
-
 
958
	    ENC_shape_offset ( ts ) ;
-
 
959
	    ts = enc_shape ( ts, c ) ;
-
 
960
	    bs = enc_bitstream ( bs, ts ) ;
-
 
961
	    break ;
-
 
962
	}
-
 
963
 
-
 
964
	case TOK_empty_shape : {
-
 
965
	    /* Shape of empty class (C version) */
-
 
966
	    ENC_compound ( bs ) ;
-
 
967
	    bs = enc_special ( bs, TOK_empty_offset ) ;
-
 
968
	    break ;
-
 
969
	}
-
 
970
 
-
 
971
	case TOK_start : {
-
 
972
	    /* Start of main routine (C version) */
-
 
973
	    ENC_make_top ( bs ) ;
-
 
974
	    break ;
-
 
975
	}
-
 
976
 
-
 
977
	case TOK_char_offset : {
-
 
978
	    /* Character offset */
-
 
979
	    TYPE c = type_char ;
-
 
980
	    ENC_offset_pad ( bs ) ;
-
 
981
	    ENC_alignment ( bs ) ;
-
 
982
	    bs = enc_shape ( bs, c ) ;
-
 
983
	    ENC_shape_offset ( bs ) ;
-
 
984
	    bs = enc_shape ( bs, c ) ;
-
 
985
	    break ;
-
 
986
	}
-
 
987
 
-
 
988
	case TOK_shape_offset : {
-
 
989
	    /* Shape offset */
-
 
990
	    ENC_offset_pad ( bs ) ;
-
 
991
	    ENC_alignment ( bs ) ;
-
 
992
	    bs = enc_param ( bs, 0, sorts, pars ) ;
-
 
993
	    ENC_shape_offset ( bs ) ;
-
 
994
	    bs = enc_param ( bs, 0, sorts, pars ) ;
-
 
995
	    break ;
-
 
996
	}
-
 
997
 
-
 
998
	case TOK_extra_offset : {
-
 
999
	    /* Offset padding */
-
 
1000
	    ENC_offset_subtract ( bs ) ;
-
 
1001
	    ENC_offset_pad ( bs ) ;
-
 
1002
	    bs = enc_param ( bs, 0, sorts, pars ) ;
-
 
1003
	    bs = enc_param ( bs, 1, sorts, pars ) ;
-
 
1004
	    ENC_offset_zero ( bs ) ;
-
 
1005
	    bs = enc_param ( bs, 0, sorts, pars ) ;
-
 
1006
	    break ;
-
 
1007
	}
-
 
1008
 
-
 
1009
	case TOK_down_cast : {
-
 
1010
	    /* Down cast from non-trivial base */
-
 
1011
	    BITSTREAM *ts, *us ;
-
 
1012
	    TYPE c = type_char ;
-
 
1013
	    bs = enc_special ( bs, TOK_ptr_to_ptr ) ;
-
 
1014
	    ts = start_bitstream ( NIL ( FILE ), bs->link ) ;
-
 
1015
	    ts = enc_alignment ( ts, c ) ;
-
 
1016
	    ts = enc_param ( ts, 0, sorts, pars ) ;
-
 
1017
	    ENC_add_to_ptr ( ts ) ;
-
 
1018
	    ts = enc_special ( ts, TOK_ptr_to_ptr ) ;
-
 
1019
	    us = start_bitstream ( NIL ( FILE ), ts->link ) ;
-
 
1020
	    us = enc_param ( us, 0, sorts, pars ) ;
-
 
1021
	    us = enc_alignment ( us, c ) ;
-
 
1022
	    us = enc_param ( us, 1, sorts, pars ) ;
-
 
1023
	    ts = enc_bitstream ( ts, us ) ;
-
 
1024
	    ENC_offset_negate ( ts ) ;
-
 
1025
	    ts = enc_special ( ts, TOK_extra_offset ) ;
-
 
1026
	    us = start_bitstream ( NIL ( FILE ), ts->link ) ;
-
 
1027
	    us = enc_alignment ( us, c ) ;
-
 
1028
	    us = enc_param ( us, 2, sorts, pars ) ;
-
 
1029
	    ts = enc_bitstream ( ts, us ) ;
-
 
1030
	    bs = enc_bitstream ( bs, ts ) ;
-
 
1031
	    break ;
-
 
1032
	}
-
 
1033
 
-
 
1034
	case TOK_destr_cast : {
-
 
1035
	    BITSTREAM *ts ;
-
 
1036
	    bs = enc_special ( bs, TOK_ptr_to_ptr ) ;
-
 
1037
	    ts = start_bitstream ( NIL ( FILE ), bs->link ) ;
-
 
1038
	    ts = enc_param ( ts, 0, sorts, pars ) ;
-
 
1039
	    ts = enc_special ( ts, TOK_empty_align ) ;
-
 
1040
	    ts = enc_param ( ts, 1, sorts, pars ) ;
-
 
1041
	    bs = enc_bitstream ( bs, ts ) ;
-
 
1042
	    break ;
-
 
1043
	}
-
 
1044
 
-
 
1045
	case TOK_destr_test : {
-
 
1046
	    BITSTREAM *ts ;
-
 
1047
	    ENC_pointer_test ( bs ) ;
-
 
1048
	    ENC_OFF ( bs ) ;
-
 
1049
	    bs = enc_ntest ( bs, ntest_not_eq ) ;
-
 
1050
	    bs = enc_param ( bs, 1, sorts, pars ) ;
-
 
1051
	    bs = enc_special ( bs, TOK_destr_ptr ) ;
-
 
1052
	    ts = start_bitstream ( NIL ( FILE ), bs->link ) ;
-
 
1053
	    ts = enc_param ( ts, 0, sorts, pars ) ;
-
 
1054
	    bs = enc_bitstream ( bs, ts ) ;
-
 
1055
	    ENC_make_null_ptr ( bs ) ;
-
 
1056
	    bs = enc_special ( bs, TOK_empty_align ) ;
-
 
1057
	    break ;
-
 
1058
	}
-
 
1059
 
-
 
1060
	case TOK_except_jump : {
-
 
1061
	    /* Long jump */
-
 
1062
	    ENC_long_jump ( bs ) ;
-
 
1063
	    bs = enc_param ( bs, 0, sorts, pars ) ;
-
 
1064
	    bs = enc_param ( bs, 1, sorts, pars ) ;
-
 
1065
	    break ;
-
 
1066
	}
-
 
1067
 
986
 
-
 
987
void
-
 
988
define_special(int t)
-
 
989
{
-
 
990
	BITSTREAM *bs;
-
 
991
	ulong pars[10];
-
 
992
	CONST char *sorts;
-
 
993
	TYPE s = NULL_type;
-
 
994
	ulong n = special_no(t);
-
 
995
	unsigned acc = find_usage(n, VAR_token);
-
 
996
	if (acc & USAGE_DEFN) {
-
 
997
		return;
-
 
998
	}
-
 
999
	sorts = special_token[t].sorts;
-
 
1000
	bs = enc_tokdef_start(n, sorts, pars, 0);
-
 
1001
	switch (t) {
-
 
1002
	case TOK_bitf_sign: {
-
 
1003
		/* Bitfield sign (C version) */
-
 
1004
		BITSTREAM *ts;
-
 
1005
		TYPE c = type_sint;
-
 
1006
		ENC_bool_cond(bs);
-
 
1007
		ENC_and(bs);
-
 
1008
		ENC_make_int(bs);
-
 
1009
		bs = enc_variety(bs, c);
-
 
1010
		bs = enc_param(bs, 0, sorts, pars);
-
 
1011
		bs = enc_make_int(bs, c, ARITH_uchar);
-
 
1012
		ts = start_bitstream(NIL(FILE), bs->link);
-
 
1013
		ENC_false(ts);
-
 
1014
		bs = enc_bitstream(bs, ts);
-
 
1015
		ts = start_bitstream(NIL(FILE), bs->link);
-
 
1016
		ENC_true(ts);
-
 
1017
		bs = enc_bitstream(bs, ts);
-
 
1018
		break;
-
 
1019
	}
-
 
1020
	case TOK_pv_compare: {
-
 
1021
		/* Comparison of pointer to void (C version) */
-
 
1022
		ENC_pointer_test(bs);
-
 
1023
		ENC_OFF(bs);
-
 
1024
		bs = enc_param(bs, 3, sorts, pars);
-
 
1025
		bs = enc_param(bs, 2, sorts, pars);
-
 
1026
		bs = enc_param(bs, 0, sorts, pars);
-
 
1027
		bs = enc_param(bs, 1, sorts, pars);
-
 
1028
		break;
-
 
1029
	}
-
 
1030
	case TOK_ptr_rep: {
-
 
1031
		/* Integral type the same size as a pointer */
-
 
1032
		bs = enc_make_snat(bs, ARITH_ulong);
-
 
1033
		break;
-
 
1034
	}
-
 
1035
	case TOK_empty_align: {
-
 
1036
		/* Alignment of empty class (C version) */
-
 
1037
		bs = enc_alignment(bs, type_ldouble);
-
 
1038
		break;
-
 
1039
	}
-
 
1040
	case TOK_empty_offset: {
-
 
1041
		/* Offset of empty class (C version) */
-
 
1042
		BITSTREAM *ts;
-
 
1043
		TYPE c = type_char;
-
 
1044
		bs = enc_special(bs, TOK_comp_off);
-
 
1045
		ts = start_bitstream(NIL(FILE), bs->link);
-
 
1046
		ENC_offset_add(ts);
-
 
1047
		ENC_offset_zero(ts);
-
 
1048
		ts = enc_alignment(ts, c);
-
 
1049
		ENC_shape_offset(ts);
-
 
1050
		ts = enc_shape(ts, c);
-
 
1051
		bs = enc_bitstream(bs, ts);
-
 
1052
		break;
-
 
1053
	}
-
 
1054
	case TOK_empty_shape: {
-
 
1055
		/* Shape of empty class (C version) */
-
 
1056
		ENC_compound(bs);
-
 
1057
		bs = enc_special(bs, TOK_empty_offset);
-
 
1058
		break;
-
 
1059
	}
-
 
1060
	case TOK_start: {
-
 
1061
		/* Start of main routine (C version) */
-
 
1062
		ENC_make_top(bs);
-
 
1063
		break;
-
 
1064
	}
-
 
1065
	case TOK_char_offset: {
-
 
1066
		/* Character offset */
-
 
1067
		TYPE c = type_char;
-
 
1068
		ENC_offset_pad(bs);
-
 
1069
		ENC_alignment(bs);
-
 
1070
		bs = enc_shape(bs, c);
-
 
1071
		ENC_shape_offset(bs);
-
 
1072
		bs = enc_shape(bs, c);
-
 
1073
		break;
-
 
1074
	}
-
 
1075
	case TOK_shape_offset: {
-
 
1076
		/* Shape offset */
-
 
1077
		ENC_offset_pad(bs);
-
 
1078
		ENC_alignment(bs);
-
 
1079
		bs = enc_param(bs, 0, sorts, pars);
-
 
1080
		ENC_shape_offset(bs);
-
 
1081
		bs = enc_param(bs, 0, sorts, pars);
-
 
1082
		break;
-
 
1083
	}
-
 
1084
	case TOK_extra_offset: {
-
 
1085
		/* Offset padding */
-
 
1086
		ENC_offset_subtract(bs);
-
 
1087
		ENC_offset_pad(bs);
-
 
1088
		bs = enc_param(bs, 0, sorts, pars);
-
 
1089
		bs = enc_param(bs, 1, sorts, pars);
-
 
1090
		ENC_offset_zero(bs);
-
 
1091
		bs = enc_param(bs, 0, sorts, pars);
-
 
1092
		break;
-
 
1093
	}
-
 
1094
	case TOK_down_cast: {
-
 
1095
		/* Down cast from non-trivial base */
-
 
1096
		BITSTREAM *ts, *us;
-
 
1097
		TYPE c = type_char;
-
 
1098
		bs = enc_special(bs, TOK_ptr_to_ptr);
-
 
1099
		ts = start_bitstream(NIL(FILE), bs->link);
-
 
1100
		ts = enc_alignment(ts, c);
-
 
1101
		ts = enc_param(ts, 0, sorts, pars);
-
 
1102
		ENC_add_to_ptr(ts);
-
 
1103
		ts = enc_special(ts, TOK_ptr_to_ptr);
-
 
1104
		us = start_bitstream(NIL(FILE), ts->link);
-
 
1105
		us = enc_param(us, 0, sorts, pars);
-
 
1106
		us = enc_alignment(us, c);
-
 
1107
		us = enc_param(us, 1, sorts, pars);
-
 
1108
		ts = enc_bitstream(ts, us);
-
 
1109
		ENC_offset_negate(ts);
-
 
1110
		ts = enc_special(ts, TOK_extra_offset);
-
 
1111
		us = start_bitstream(NIL(FILE), ts->link);
-
 
1112
		us = enc_alignment(us, c);
-
 
1113
		us = enc_param(us, 2, sorts, pars);
-
 
1114
		ts = enc_bitstream(ts, us);
-
 
1115
		bs = enc_bitstream(bs, ts);
-
 
1116
		break;
-
 
1117
	}
-
 
1118
	case TOK_destr_cast: {
-
 
1119
		BITSTREAM *ts;
-
 
1120
		bs = enc_special(bs, TOK_ptr_to_ptr);
-
 
1121
		ts = start_bitstream(NIL(FILE), bs->link);
-
 
1122
		ts = enc_param(ts, 0, sorts, pars);
-
 
1123
		ts = enc_special(ts, TOK_empty_align);
-
 
1124
		ts = enc_param(ts, 1, sorts, pars);
-
 
1125
		bs = enc_bitstream(bs, ts);
-
 
1126
		break;
-
 
1127
	}
-
 
1128
	case TOK_destr_test: {
-
 
1129
		BITSTREAM *ts;
-
 
1130
		ENC_pointer_test(bs);
-
 
1131
		ENC_OFF(bs);
-
 
1132
		bs = enc_ntest(bs, ntest_not_eq);
-
 
1133
		bs = enc_param(bs, 1, sorts, pars);
-
 
1134
		bs = enc_special(bs, TOK_destr_ptr);
-
 
1135
		ts = start_bitstream(NIL(FILE), bs->link);
-
 
1136
		ts = enc_param(ts, 0, sorts, pars);
-
 
1137
		bs = enc_bitstream(bs, ts);
-
 
1138
		ENC_make_null_ptr(bs);
-
 
1139
		bs = enc_special(bs, TOK_empty_align);
-
 
1140
		break;
-
 
1141
	}
-
 
1142
	case TOK_except_jump: {
-
 
1143
		/* Long jump */
-
 
1144
		ENC_long_jump(bs);
-
 
1145
		bs = enc_param(bs, 0, sorts, pars);
-
 
1146
		bs = enc_param(bs, 1, sorts, pars);
-
 
1147
		break;
-
 
1148
	}
1068
	case TOK_ptr_code : {
1149
	case TOK_ptr_code: {
1069
	    /* Local label value pointer */
1150
		/* Local label value pointer */
1070
	    ENC_pointer ( bs ) ;
1151
		ENC_pointer(bs);
1071
	    ENC_code_alignment ( bs ) ;
1152
		ENC_code_alignment(bs);
1072
	    s = type_void_star ;
1153
		s = type_void_star;
1073
	    break ;
1154
		break;
1074
	}
1155
	}
1075
 
-
 
1076
	case TOK_ptr_frame : {
1156
	case TOK_ptr_frame: {
1077
	    /* Procedure environment pointer */
1157
		/* Procedure environment pointer */
1078
	    ENC_pointer ( bs ) ;
1158
		ENC_pointer(bs);
1079
#if ( TDF_major >= 4 )
1159
#if (TDF_major >= 4)
1080
	    ENC_unite_alignments ( bs ) ;
1160
		ENC_unite_alignments(bs);
1081
	    ENC_locals_alignment ( bs ) ;
1161
		ENC_locals_alignment(bs);
1082
	    ENC_callers_alignment ( bs ) ;
1162
		ENC_callers_alignment(bs);
1083
	    ENC_false ( bs ) ;
1163
		ENC_false(bs);
1084
#else
1164
#else
1085
	    ENC_frame_alignment ( bs ) ;
1165
		ENC_frame_alignment(bs);
1086
#endif
1166
#endif
1087
	    s = type_void_star ;
1167
		s = type_void_star;
1088
	    break ;
1168
		break;
1089
	}
1169
	}
1090
 
-
 
1091
	default : {
1170
	default: {
1092
	    FAIL ( Unknown special token ) ;
1171
		FAIL(Unknown special token);
1093
	    break ;
1172
		break;
1094
	}
1173
	}
1095
    }
1174
	}
1096
    enc_tokdef_end ( n, bs ) ;
1175
	enc_tokdef_end(n, bs);
1097
    if ( output_all && special_token [t].builtin == 2 ) {
1176
	if (output_all && special_token[t].builtin == 2) {
1098
	string e = ustrlit ( special_token [t].name ) ;
1177
		string e = ustrlit(special_token[t].name);
1099
	IGNORE capsule_name ( n, &e, VAR_token ) ;
1178
		IGNORE capsule_name(n, &e, VAR_token);
1100
    }
1179
	}
1101
    if ( output_diag ) {
1180
	if (output_diag) {
1102
	/* Output token diagnostics */
1181
		/* Output token diagnostics */
1103
	IDENTIFIER id = special_token [t].tok ;
1182
		IDENTIFIER id = special_token[t].tok;
-
 
1183
		if (!IS_NULL_id(id)) {
1104
	if ( !IS_NULL_id ( id ) ) enc_diag_token ( id, s ) ;
1184
			enc_diag_token(id, s);
1105
    }
1185
		}
-
 
1186
	}
1106
    return ;
1187
	return;
1107
}
1188
}
1108
 
1189
 
1109
 
1190
 
1110
/*
1191
/*
1111
    ENCODE A TOKEN DEFINITION
1192
    ENCODE A TOKEN DEFINITION
1112
 
1193
 
1113
    This routine adds the definition of the token tok to the bitstream bs.
1194
    This routine adds the definition of the token tok to the bitstream bs.
1114
*/
1195
*/
1115
 
1196
 
1116
BITSTREAM *enc_tokdef_body
1197
BITSTREAM *
1117
    PROTO_N ( ( bs, id, tok ) )
-
 
1118
    PROTO_T ( BITSTREAM *bs X IDENTIFIER id X TOKEN tok )
1198
enc_tokdef_body(BITSTREAM *bs, IDENTIFIER id, TOKEN tok)
1119
{
1199
{
1120
    if ( !IS_NULL_tok ( tok ) ) {
1200
	if (!IS_NULL_tok(tok)) {
1121
	int uc = unreached_code ;
1201
		int uc = unreached_code;
1122
	unreached_code = 0 ;
1202
		unreached_code = 0;
1123
	switch ( TAG_tok ( tok ) ) {
1203
		switch (TAG_tok(tok)) {
1124
	    case tok_exp_tag : {
1204
		case tok_exp_tag: {
1125
		EXP e = DEREF_exp ( tok_exp_value ( tok ) ) ;
1205
			EXP e = DEREF_exp(tok_exp_value(tok));
-
 
1206
			if (IS_NULL_exp(e)) {
1126
		if ( IS_NULL_exp ( e ) ) goto undefined_token ;
1207
				goto undefined_token;
-
 
1208
			}
1127
		bs = enc_exp ( bs, e ) ;
1209
			bs = enc_exp(bs, e);
1128
		break ;
1210
			break;
1129
	    }
1211
		}
1130
	    case tok_stmt_tag : {
1212
		case tok_stmt_tag: {
1131
		EXP e = DEREF_exp ( tok_stmt_value ( tok ) ) ;
1213
			EXP e = DEREF_exp(tok_stmt_value(tok));
-
 
1214
			if (IS_NULL_exp(e)) {
1132
		if ( IS_NULL_exp ( e ) ) goto undefined_token ;
1215
				goto undefined_token;
-
 
1216
			}
1133
		bs = enc_stmt ( bs, e ) ;
1217
			bs = enc_stmt(bs, e);
1134
		break ;
1218
			break;
1135
	    }
1219
		}
1136
	    case tok_nat_tag : {
1220
		case tok_nat_tag: {
1137
		NAT n = DEREF_nat ( tok_nat_value ( tok ) ) ;
1221
			NAT n = DEREF_nat(tok_nat_value(tok));
1138
		if ( IS_NULL_nat ( n ) ) {
1222
			if (IS_NULL_nat(n)) {
1139
		    ENC_computed_nat ( bs ) ;
1223
				ENC_computed_nat(bs);
1140
		    goto undefined_token ;
1224
				goto undefined_token;
1141
		}
1225
			}
1142
		bs = enc_nat ( bs, n, 0 ) ;
1226
			bs = enc_nat(bs, n, 0);
1143
		break ;
1227
			break;
1144
	    }
1228
		}
1145
	    case tok_snat_tag : {
1229
		case tok_snat_tag: {
1146
		NAT n = DEREF_nat ( tok_snat_value ( tok ) ) ;
1230
			NAT n = DEREF_nat(tok_snat_value(tok));
1147
		if ( IS_NULL_nat ( n ) ) {
1231
			if (IS_NULL_nat(n)) {
1148
		    ENC_computed_signed_nat ( bs ) ;
1232
				ENC_computed_signed_nat(bs);
1149
		    goto undefined_token ;
1233
				goto undefined_token;
1150
		}
1234
			}
1151
		bs = enc_snat ( bs, n, 0, 0 ) ;
1235
			bs = enc_snat(bs, n, 0, 0);
1152
		break ;
1236
			break;
1153
	    }
1237
		}
1154
	    case tok_type_tag : {
1238
		case tok_type_tag: {
1155
		TYPE t = DEREF_type ( tok_type_value ( tok ) ) ;
1239
			TYPE t = DEREF_type(tok_type_value(tok));
1156
		BASE_TYPE bt = DEREF_btype ( tok_type_kind ( tok ) ) ;
1240
			BASE_TYPE bt = DEREF_btype(tok_type_kind(tok));
1157
		if ( bt & btype_scalar ) {
1241
			if (bt & btype_scalar) {
1158
		    if ( IS_NULL_type ( t ) ) {
1242
				if (IS_NULL_type(t)) {
1159
			ENC_computed_signed_nat ( bs ) ;
1243
					ENC_computed_signed_nat(bs);
1160
			goto undefined_token ;
1244
					goto undefined_token;
1161
		    }
1245
				}
1162
		    bs = enc_arith ( bs, t, 0 ) ;
1246
				bs = enc_arith(bs, t, 0);
1163
		} else {
1247
			} else {
1164
		    if ( IS_NULL_type ( t ) ) {
1248
				if (IS_NULL_type(t)) {
1165
			ENC_compound ( bs ) ;
1249
					ENC_compound(bs);
1166
			goto undefined_token ;
1250
					goto undefined_token;
1167
		    }
1251
				}
1168
		    bs = enc_shape ( bs, t ) ;
1252
				bs = enc_shape(bs, t);
1169
		}
1253
			}
1170
		break ;
1254
			break;
1171
	    }
1255
		}
1172
	    case tok_member_tag : {
1256
		case tok_member_tag: {
1173
		OFFSET off = DEREF_off ( tok_member_value ( tok ) ) ;
1257
			OFFSET off = DEREF_off(tok_member_value(tok));
1174
		if ( IS_NULL_off ( off ) ) goto undefined_token ;
1258
			if (IS_NULL_off(off)) {
-
 
1259
				goto undefined_token;
-
 
1260
			}
1175
		bs = enc_offset ( bs, off ) ;
1261
			bs = enc_offset(bs, off);
1176
		break ;
1262
			break;
1177
	    }
1263
		}
1178
	    case tok_proc_tag : {
1264
		case tok_proc_tag: {
1179
		TOKEN res = DEREF_tok ( tok_proc_res ( tok ) ) ;
1265
			TOKEN res = DEREF_tok(tok_proc_res(tok));
1180
		bs = enc_tokdef_body ( bs, id, res ) ;
1266
			bs = enc_tokdef_body(bs, id, res);
1181
		break ;
1267
			break;
1182
	    }
1268
		}
1183
	    undefined_token : {
1269
undefined_token: {
1184
		/* Output install-time error */
1270
			 /* Output install-time error */
1185
		EXP e ;
1271
			 EXP e;
1186
		ERROR err ;
1272
			 ERROR err;
1187
		OPTION opt = option ( OPT_token_undef ) ;
1273
			 OPTION opt = option(OPT_token_undef);
1188
		option ( OPT_token_undef ) = OPTION_ON ;
1274
			 option(OPT_token_undef) = OPTION_ON;
1189
		err = ERR_token_undef ( id ) ;
1275
			 err = ERR_token_undef(id);
1190
		e = install_error ( NIL ( LOCATION ), err ) ;
1276
			 e = install_error(NIL(LOCATION), err);
1191
		option ( OPT_token_undef ) = opt ;
1277
			 option(OPT_token_undef) = opt;
1192
		bs = enc_exp ( bs, e ) ;
1278
			 bs = enc_exp(bs, e);
1193
		break ;
1279
			 break;
1194
	    }
1280
		 }
1195
	    default : {
1281
		default: {
1196
		FAIL ( Bad token sort ) ;
1282
			FAIL(Bad token sort);
1197
		break ;
1283
			break;
1198
	    }
1284
		}
1199
	}
1285
		}
1200
	unreached_code = uc ;
1286
		unreached_code = uc;
1201
    }
1287
	}
1202
    return ( bs ) ;
1288
	return (bs);
1203
}
1289
}
1204
 
1290
 
1205
 
1291
 
1206
/*
1292
/*
1207
    ENCODE A TOKEN APPLICATION
1293
    ENCODE A TOKEN APPLICATION
1208
 
1294
 
1209
    This routine adds the application of the token id with arguments
1295
    This routine adds the application of the token id with arguments
1210
    args to the bitstream bs.
1296
    args to the bitstream bs.
1211
*/
1297
*/
1212
 
1298
 
1213
BITSTREAM *enc_token
1299
BITSTREAM *
1214
    PROTO_N ( ( bs, id, args ) )
-
 
1215
    PROTO_T ( BITSTREAM *bs X IDENTIFIER id X LIST ( TOKEN ) args )
1300
enc_token(BITSTREAM *bs, IDENTIFIER id, LIST(TOKEN)args)
1216
{
1301
{
1217
    int s = enc_tokdef ( id, 0 ) ;
1302
	int s = enc_tokdef(id, 0);
1218
    ulong n = unit_no ( bs, id, VAR_token, 0 ) ;
1303
	ulong n = unit_no(bs, id, VAR_token, 0);
1219
    bs = enc_apply_token ( bs, s ) ;
1304
	bs = enc_apply_token(bs, s);
1220
    ENC_make_tok ( bs, n ) ;
1305
	ENC_make_tok(bs, n);
1221
    if ( IS_NULL_list ( args ) ) {
1306
	if (IS_NULL_list(args)) {
1222
	ENC_LEN_SMALL ( bs, 0 ) ;
1307
		ENC_LEN_SMALL(bs, 0);
1223
    } else {
1308
	} else {
1224
	BITSTREAM *ts = start_bitstream ( NIL ( FILE ), bs->link ) ;
1309
		BITSTREAM *ts = start_bitstream(NIL(FILE), bs->link);
1225
	while ( !IS_NULL_list ( args ) ) {
1310
		while (!IS_NULL_list(args)) {
1226
	    TOKEN tok = DEREF_tok ( HEAD_list ( args ) ) ;
1311
			TOKEN tok = DEREF_tok(HEAD_list(args));
1227
	    ts = enc_tokdef_body ( ts, id, tok ) ;
1312
			ts = enc_tokdef_body(ts, id, tok);
1228
	    args = TAIL_list ( args ) ;
1313
			args = TAIL_list(args);
-
 
1314
		}
-
 
1315
		bs = enc_bitstream(bs, ts);
1229
	}
1316
	}
1230
	bs = enc_bitstream ( bs, ts ) ;
-
 
1231
    }
-
 
1232
    return ( bs ) ;
1317
	return (bs);
1233
}
1318
}
1234
 
1319
 
1235
 
1320
 
1236
/*
1321
/*
1237
    ENCODE AN ASM EXPRESSION
1322
    ENCODE AN ASM EXPRESSION
1238
 
1323
 
1239
    This routine adds the assembler directive e to the bitstream bs.
1324
    This routine adds the assembler directive e to the bitstream bs.
1240
*/
1325
*/
1241
 
1326
 
1242
BITSTREAM *enc_asm
1327
BITSTREAM *
1243
    PROTO_N ( ( bs, e ) )
-
 
1244
    PROTO_T ( BITSTREAM *bs X EXP e )
1328
enc_asm(BITSTREAM *bs, EXP e)
1245
{
1329
{
1246
    STRING op = DEREF_str ( exp_assembler_op ( e ) ) ;
1330
	STRING op = DEREF_str(exp_assembler_op(e));
1247
    unsigned long len = DEREF_ulong ( str_simple_len ( op ) ) ;
1331
	unsigned long len = DEREF_ulong(str_simple_len(op));
1248
    if ( len ) {
1332
	if (len) {
1249
	BITSTREAM *ts, *us ;
1333
		BITSTREAM *ts, *us;
1250
	bs = enc_special ( bs, TOK_asm_sequence ) ;
1334
		bs = enc_special(bs, TOK_asm_sequence);
1251
	ts = start_bitstream ( NIL ( FILE ), bs->link ) ;
1335
		ts = start_bitstream(NIL(FILE), bs->link);
1252
	ts = enc_special ( ts, TOK_asm ) ;
1336
		ts = enc_special(ts, TOK_asm);
1253
	us = start_bitstream ( NIL ( FILE ), ts->link ) ;
1337
		us = start_bitstream(NIL(FILE), ts->link);
1254
	us = enc_strlit ( us, op ) ;
1338
		us = enc_strlit(us, op);
1255
	ts = enc_bitstream ( ts, us ) ;
1339
		ts = enc_bitstream(ts, us);
1256
	bs = enc_bitstream ( bs, ts ) ;
1340
		bs = enc_bitstream(bs, ts);
1257
    } else {
1341
	} else {
1258
	ENC_make_top ( bs ) ;
1342
		ENC_make_top(bs);
1259
    }
1343
	}
1260
    return ( bs ) ;
1344
	return (bs);
1261
}
1345
}
1262
 
1346
 
1263
 
1347
 
1264
#else /* TDF_OUTPUT */
1348
#else /* TDF_OUTPUT */
1265
 
1349
 
Line 1269... Line 1353...
1269
 
1353
 
1270
    This routine is a dummy version of define_special used when TDF
1354
    This routine is a dummy version of define_special used when TDF
1271
    output is disabled.
1355
    output is disabled.
1272
*/
1356
*/
1273
 
1357
 
1274
void define_special
1358
void
1275
    PROTO_N ( ( t ) )
-
 
1276
    PROTO_T ( int t )
1359
define_special(int t)
1277
{
1360
{
1278
    UNUSED ( t ) ;
1361
	UNUSED(t);
1279
    return ;
1362
	return;
1280
}
1363
}
1281
 
1364
 
1282
 
1365
 
1283
#endif /* TDF_OUTPUT */
1366
#endif /* TDF_OUTPUT */