Subversion Repositories tendra.SVN

Rev

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

Rev 5 Rev 6
Line -... Line 1...
-
 
1
/*
-
 
2
 * Copyright (c) 2002-2006 The TenDRA Project <http://www.tendra.org/>.
-
 
3
 * All rights reserved.
-
 
4
 *
-
 
5
 * Redistribution and use in source and binary forms, with or without
-
 
6
 * modification, are permitted provided that the following conditions are met:
-
 
7
 *
-
 
8
 * 1. Redistributions of source code must retain the above copyright notice,
-
 
9
 *    this list of conditions and the following disclaimer.
-
 
10
 * 2. Redistributions in binary form must reproduce the above copyright notice,
-
 
11
 *    this list of conditions and the following disclaimer in the documentation
-
 
12
 *    and/or other materials provided with the distribution.
-
 
13
 * 3. Neither the name of The TenDRA Project nor the names of its contributors
-
 
14
 *    may be used to endorse or promote products derived from this software
-
 
15
 *    without specific, prior written permission.
-
 
16
 *
-
 
17
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
-
 
18
 * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
-
 
19
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-
 
20
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
-
 
21
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
-
 
22
 * EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-
 
23
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
-
 
24
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-
 
25
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
-
 
26
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
-
 
27
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
 
28
 *
-
 
29
 * $Id$
-
 
30
 */
1
/*
31
/*
2
    		 Crown Copyright (c) 1997
32
    		 Crown Copyright (c) 1997
3
    
33
 
4
    This TenDRA(r) Computer Program is subject to Copyright
34
    This TenDRA(r) Computer Program is subject to Copyright
5
    owned by the United Kingdom Secretary of State for Defence
35
    owned by the United Kingdom Secretary of State for Defence
6
    acting through the Defence Evaluation and Research Agency
36
    acting through the Defence Evaluation and Research Agency
7
    (DERA).  It is made available to Recipients with a
37
    (DERA).  It is made available to Recipients with a
8
    royalty-free licence for its use, reproduction, transfer
38
    royalty-free licence for its use, reproduction, transfer
9
    to other parties and amendment for any purpose not excluding
39
    to other parties and amendment for any purpose not excluding
10
    product development provided that any such use et cetera
40
    product development provided that any such use et cetera
11
    shall be deemed to be acceptance of the following conditions:-
41
    shall be deemed to be acceptance of the following conditions:-
12
    
42
 
13
        (1) Its Recipients shall ensure that this Notice is
43
        (1) Its Recipients shall ensure that this Notice is
14
        reproduced upon any copies or amended versions of it;
44
        reproduced upon any copies or amended versions of it;
15
    
45
 
16
        (2) Any amended version of it shall be clearly marked to
46
        (2) Any amended version of it shall be clearly marked to
17
        show both the nature of and the organisation responsible
47
        show both the nature of and the organisation responsible
18
        for the relevant amendment or amendments;
48
        for the relevant amendment or amendments;
19
    
49
 
20
        (3) Its onward transfer from a recipient to another
50
        (3) Its onward transfer from a recipient to another
21
        party shall be deemed to be that party's acceptance of
51
        party shall be deemed to be that party's acceptance of
22
        these conditions;
52
        these conditions;
23
    
53
 
24
        (4) DERA gives no warranty or assurance as to its
54
        (4) DERA gives no warranty or assurance as to its
25
        quality or suitability for any purpose and DERA accepts
55
        quality or suitability for any purpose and DERA accepts
26
        no liability whatsoever in relation to any use to which
56
        no liability whatsoever in relation to any use to which
27
        it may be put.
57
        it may be put.
28
*/
58
*/
Line 77... Line 107...
77
    MANGLED FORMS OF BASIC TYPES
107
    MANGLED FORMS OF BASIC TYPES
78
 
108
 
79
    This table gives the mangled forms of the built-in types.
109
    This table gives the mangled forms of the built-in types.
80
*/
110
*/
81
 
111
 
82
char mangle_ntype [ ORDER_ntype ] [3] = {
112
char mangle_ntype[ORDER_ntype][3] = {
83
    { MANGLE_error, 0, 0 },			/* ntype_none */
113
	{ MANGLE_error, 0, 0 },			/* ntype_none */
84
    { MANGLE_char, 0, 0 },			/* ntype_char */
114
	{ MANGLE_char, 0, 0 },			/* ntype_char */
85
    { MANGLE_signed, MANGLE_char, 0 },		/* ntype_schar */
115
	{ MANGLE_signed, MANGLE_char, 0 },	/* ntype_schar */
86
    { MANGLE_unsigned, MANGLE_char, 0 },	/* ntype_uchar */
116
	{ MANGLE_unsigned, MANGLE_char, 0 },	/* ntype_uchar */
87
    { MANGLE_short, 0, 0 },			/* ntype_sshort */
117
	{ MANGLE_short, 0, 0 },			/* ntype_sshort */
88
    { MANGLE_unsigned, MANGLE_short, 0 },	/* ntype_ushort */
118
	{ MANGLE_unsigned, MANGLE_short, 0 },	/* ntype_ushort */
89
    { MANGLE_int, 0, 0 },			/* ntype_sint */
119
	{ MANGLE_int, 0, 0 },			/* ntype_sint */
90
    { MANGLE_unsigned, MANGLE_int, 0 },		/* ntype_uint */
120
	{ MANGLE_unsigned, MANGLE_int, 0 },	/* ntype_uint */
91
    { MANGLE_long, 0, 0 },			/* ntype_slong */
121
	{ MANGLE_long, 0, 0 },			/* ntype_slong */
92
    { MANGLE_unsigned, MANGLE_long, 0 },	/* ntype_ulong */
122
	{ MANGLE_unsigned, MANGLE_long, 0 },	/* ntype_ulong */
93
    { MANGLE_llong, 0, 0 },			/* ntype_sllong */
123
	{ MANGLE_llong, 0, 0 },			/* ntype_sllong */
94
    { MANGLE_unsigned, MANGLE_llong, 0 },	/* ntype_ullong */
124
	{ MANGLE_unsigned, MANGLE_llong, 0 },	/* ntype_ullong */
95
    { MANGLE_float, 0, 0 },			/* ntype_float */
125
	{ MANGLE_float, 0, 0 },			/* ntype_float */
96
    { MANGLE_double, 0, 0 },			/* ntype_double */
126
	{ MANGLE_double, 0, 0 },		/* ntype_double */
97
    { MANGLE_ldouble, 0, 0 },			/* ntype_ldouble */
127
	{ MANGLE_ldouble, 0, 0 },		/* ntype_ldouble */
98
    { MANGLE_void, 0, 0 },			/* ntype_void */
128
	{ MANGLE_void, 0, 0 },			/* ntype_void */
99
    { MANGLE_bottom, 0, 0 },			/* ntype_bottom */
129
	{ MANGLE_bottom, 0, 0 },		/* ntype_bottom */
100
    { MANGLE_bool, 0, 0 },			/* ntype_bool */
130
	{ MANGLE_bool, 0, 0 },			/* ntype_bool */
101
    { MANGLE_ptrdiff_t, 0, 0 },			/* ntype_ptrdiff_t */
131
	{ MANGLE_ptrdiff_t, 0, 0 },		/* ntype_ptrdiff_t */
102
    { MANGLE_size_t, 0, 0 },			/* ntype_size_t */
132
	{ MANGLE_size_t, 0, 0 },		/* ntype_size_t */
103
    { MANGLE_wchar_t, 0, 0 },			/* ntype_wchar_t */
133
	{ MANGLE_wchar_t, 0, 0 },		/* ntype_wchar_t */
104
    { MANGLE_ellipsis, 0, 0 }			/* ntype_ellipsis */
134
	{ MANGLE_ellipsis, 0, 0 }		/* ntype_ellipsis */
105
} ;
135
};
106
 
136
 
107
 
137
 
108
/*
138
/*
109
    NAME MANGLING FLAGS
139
    NAME MANGLING FLAGS
110
 
140
 
111
    The following flags are used to control the form of the mangled names.
141
    The following flags are used to control the form of the mangled names.
112
*/
142
*/
113
 
143
 
114
int mangle_objects = 1 ;
144
int mangle_objects = 1;
115
int mangle_signature = 1 ;
145
int mangle_signature = 1;
116
unsigned long mangle_length = ULONG_MAX ;
146
unsigned long mangle_length = ULONG_MAX;
117
 
147
 
118
 
148
 
119
/*
149
/*
120
    FORWARD DECLARATIONS
150
    FORWARD DECLARATIONS
121
 
151
 
122
    A couple of forward declarations are necessary because of the
152
    A couple of forward declarations are necessary because of the
123
    recursive nature of many of the routines.
153
    recursive nature of many of the routines.
124
*/
154
*/
125
 
155
 
126
static int nspace_depth PROTO_S ( ( NAMESPACE ) ) ;
156
static int nspace_depth(NAMESPACE);
127
static string mangle_op PROTO_S ( ( int ) ) ;
157
static string mangle_op(int);
128
static string mangle_hashid PROTO_S ( ( HASHID, int *, int ) ) ;
158
static string mangle_hashid(HASHID, int *, int);
129
static void mangle_exp PROTO_S ( ( BUFFER *, EXP, int ) ) ;
159
static void mangle_exp(BUFFER *, EXP, int);
130
static void mangle_nat PROTO_S ( ( BUFFER *, NAT, int ) ) ;
160
static void mangle_nat(BUFFER *, NAT, int);
131
static void mangle_nspace PROTO_S ( ( BUFFER *, NAMESPACE, int ) ) ;
161
static void mangle_nspace(BUFFER *, NAMESPACE, int);
132
static void mangle_ctype PROTO_S ( ( BUFFER *, CLASS_TYPE, int ) ) ;
162
static void mangle_ctype(BUFFER *, CLASS_TYPE, int);
133
static void mangle_token PROTO_S ( ( BUFFER *, IDENTIFIER, LIST ( TOKEN ), int, int ) ) ;
163
static void mangle_token(BUFFER *, IDENTIFIER, LIST(TOKEN), int, int);
134
static void mangle_type PROTO_S ( ( BUFFER *, TYPE, int, int ) ) ;
164
static void mangle_type(BUFFER *, TYPE, int, int);
135
 
165
 
136
 
166
 
137
/*
167
/*
138
    CURRENT CLASS TYPE
168
    CURRENT CLASS TYPE
139
 
169
 
140
    This variable is used to hold the parent class of an identifier during
170
    This variable is used to hold the parent class of an identifier during
141
    name mangling.
171
    name mangling.
142
*/
172
*/
143
 
173
 
144
static CLASS_TYPE crt_mangle_class = NULL_ctype ;
174
static CLASS_TYPE crt_mangle_class = NULL_ctype;
145
 
175
 
146
 
176
 
147
/*
177
/*
148
    FIND AN IDENTIFIER DEPTH
178
    FIND AN IDENTIFIER DEPTH
149
 
179
 
150
    This routine finds the depth of the identifier id.  This is one more
180
    This routine finds the depth of the identifier id.  This is one more
151
    than the depth of the enclosing namespace if id is a simple identifier
181
    than the depth of the enclosing namespace if id is a simple identifier
152
    and -1 otherwise.
182
    and -1 otherwise.
153
*/
183
*/
154
 
184
 
155
static int ident_depth
185
static int
156
    PROTO_N ( ( id ) )
-
 
157
    PROTO_T ( IDENTIFIER id )
186
ident_depth(IDENTIFIER id)
158
{
187
{
159
    if ( !IS_NULL_id ( id ) ) {
188
	if (!IS_NULL_id(id)) {
160
	HASHID nm = DEREF_hashid ( id_name ( id ) ) ;
189
		HASHID nm = DEREF_hashid(id_name(id));
161
	if ( !IS_hashid_anon ( nm ) ) {
190
		if (!IS_hashid_anon(nm)) {
162
	    /* Simple identifiers */
191
			/* Simple identifiers */
163
	    NAMESPACE ns = DEREF_nspace ( id_parent ( id ) ) ;
192
			NAMESPACE ns = DEREF_nspace(id_parent(id));
164
	    int n = nspace_depth ( ns ) ;
193
			int n = nspace_depth(ns);
-
 
194
			if (n >= 0) {
165
	    if ( n >= 0 ) return ( n + 1 ) ;
195
				return (n + 1);
-
 
196
			}
-
 
197
		}
166
	}
198
	}
167
    }
-
 
168
    return ( -1 ) ;
199
	return (-1);
169
}
200
}
170
 
201
 
171
 
202
 
172
/*
203
/*
173
    FIND A NAMESPACE DEPTH
204
    FIND A NAMESPACE DEPTH
174
 
205
 
175
    This routine finds the depth of the namespace ns - that is the number
206
    This routine finds the depth of the namespace ns - that is the number
176
    of namespaces lying between it and its enclosing global namespace.
207
    of namespaces lying between it and its enclosing global namespace.
177
    The routine returns -1 if any intermediate namespace is unnamed.
208
    The routine returns -1 if any intermediate namespace is unnamed.
178
*/
209
*/
179
 
210
 
180
static int nspace_depth
211
static int
181
    PROTO_N ( ( ns ) )
-
 
182
    PROTO_T ( NAMESPACE ns )
212
nspace_depth(NAMESPACE ns)
183
{
213
{
184
    if ( !IS_NULL_nspace ( ns ) ) {
214
	if (!IS_NULL_nspace(ns)) {
185
	switch ( TAG_nspace ( ns ) ) {
215
		switch (TAG_nspace(ns)) {
186
	    case nspace_named_tag :
216
		case nspace_named_tag:
187
	    case nspace_ctype_tag : {
217
		case nspace_ctype_tag: {
188
		/* Named and class namespaces */
218
			/* Named and class namespaces */
189
		IDENTIFIER id = DEREF_id ( nspace_name ( ns ) ) ;
219
			IDENTIFIER id = DEREF_id(nspace_name(ns));
190
		int n = ident_depth ( id ) ;
220
			int n = ident_depth(id);
191
		return ( n ) ;
221
			return (n);
192
	    }
222
		}
193
	    case nspace_global_tag : {
223
		case nspace_global_tag: {
194
		/* The global namespace */
224
			/* The global namespace */
195
		return ( 0 ) ;
225
			return (0);
196
	    }
226
		}
197
	    case nspace_unnamed_tag : {
227
		case nspace_unnamed_tag: {
198
		/* Unnamed namespaces */
228
			/* Unnamed namespaces */
199
		if ( output_all ) {
229
			if (output_all) {
200
		    IDENTIFIER id = DEREF_id ( nspace_name ( ns ) ) ;
230
				IDENTIFIER id = DEREF_id(nspace_name(ns));
201
		    NAMESPACE pns = DEREF_nspace ( id_parent ( id ) ) ;
231
				NAMESPACE pns = DEREF_nspace(id_parent(id));
202
		    int n = nspace_depth ( pns ) ;
232
				int n = nspace_depth(pns);
-
 
233
				if (n >= 0) {
203
		    if ( n >= 0 ) return ( n + 1 ) ;
234
					return (n + 1);
-
 
235
				}
-
 
236
			}
-
 
237
			break;
-
 
238
		}
204
		}
239
		}
205
		break ;
-
 
206
	    }
-
 
207
	}
240
	}
208
    }
-
 
209
    return ( -1 ) ;
241
	return (-1);
210
}
242
}
211
 
243
 
212
 
244
 
213
/*
245
/*
214
    NAME MANGLING BUFFER
246
    NAME MANGLING BUFFER
215
 
247
 
216
    This buffer is used to build up the mangled names.
248
    This buffer is used to build up the mangled names.
217
*/
249
*/
218
 
250
 
219
BUFFER mangle_buff = NULL_buff ;
251
BUFFER mangle_buff = NULL_buff;
220
static BUFFER name_buff = NULL_buff ;
252
static BUFFER name_buff = NULL_buff;
221
 
253
 
222
 
254
 
223
/*
255
/*
224
    ADD A NUMBER TO THE BUFFER
256
    ADD A NUMBER TO THE BUFFER
225
 
257
 
226
    This routine adds the number n to the buffer position given by bf.
258
    This routine adds the number n to the buffer position given by bf.
227
*/
259
*/
228
 
260
 
229
static void mangle_number
261
static void
230
    PROTO_N ( ( bf, n, e ) )
-
 
231
    PROTO_T ( BUFFER *bf X unsigned long n X int e )
262
mangle_number(BUFFER *bf, unsigned long n, int e)
232
{
263
{
233
    if ( n < 10 ) {
264
	if (n < 10) {
234
	int d = '0' + ( int ) n ;
265
		int d = '0' + (int)n;
235
	bfputc ( bf, d ) ;
266
		bfputc(bf, d);
236
    } else {
267
	} else {
-
 
268
		if (e > 1) {
237
	if ( e > 1 ) bfputc ( bf, MANGLE_sep ) ;
269
			bfputc(bf, MANGLE_sep);
-
 
270
		}
238
	bfprintf ( bf, "%lu", n ) ;
271
		bfprintf(bf, "%lu", n);
-
 
272
		if (e > 0) {
239
	if ( e > 0 ) bfputc ( bf, MANGLE_sep ) ;
273
			bfputc(bf, MANGLE_sep);
240
    }
274
		}
-
 
275
	}
241
    return ;
276
	return;
242
}
277
}
243
 
278
 
244
 
279
 
245
/*
280
/*
246
    ADD AN IDENTIFIER NAME TO THE BUFFER
281
    ADD AN IDENTIFIER NAME TO THE BUFFER
247
 
282
 
248
    This routine adds the mangled form of the identifier id to the buffer
283
    This routine adds the mangled form of the identifier id to the buffer
249
    position given by bf.  d gives the associated identifier depth.
284
    position given by bf.  d gives the associated identifier depth.
250
*/
285
*/
251
 
286
 
252
static void mangle_id
287
static void
253
    PROTO_N ( ( bf, id, d ) )
-
 
254
    PROTO_T ( BUFFER *bf X IDENTIFIER id X int d )
288
mangle_id(BUFFER *bf, IDENTIFIER id, int d)
255
{
289
{
256
    if ( d >= 0 ) {
290
	if (d >= 0) {
257
	int copy = 0 ;
291
		int copy = 0;
258
	HASHID nm = DEREF_hashid ( id_name ( id ) ) ;
292
		HASHID nm = DEREF_hashid(id_name(id));
259
	string s = mangle_hashid ( nm, &copy, 1 ) ;
293
		string s = mangle_hashid(nm, &copy, 1);
260
	if ( s ) {
294
		if (s) {
261
	    unsigned long n = ( unsigned long ) ustrlen ( s ) ;
295
			unsigned long n = (unsigned long)ustrlen(s);
262
	    if ( d > 1 ) {
296
			if (d > 1) {
263
		/* Output name qualifier */
297
				/* Output name qualifier */
264
		NAMESPACE ns = DEREF_nspace ( id_parent ( id ) ) ;
298
				NAMESPACE ns = DEREF_nspace(id_parent(id));
265
		bfputc ( bf, MANGLE_qual ) ;
299
				bfputc(bf, MANGLE_qual);
266
		mangle_number ( bf, ( unsigned long ) d, 2 ) ;
300
				mangle_number(bf,(unsigned long)d, 2);
267
		mangle_nspace ( bf, ns, d - 1 ) ;
301
				mangle_nspace(bf, ns, d - 1);
268
	    }
302
			}
269
	    mangle_number ( bf, n, 0 ) ;
303
			mangle_number(bf, n, 0);
270
	    bfputs ( bf, s ) ;
304
			bfputs(bf, s);
-
 
305
		} else {
-
 
306
			/* Invalid identifier */
-
 
307
			bfputc(bf, MANGLE_error);
-
 
308
		}
271
	} else {
309
	} else {
272
	    /* Invalid identifier */
310
		/* Invalid identifier */
273
	    bfputc ( bf, MANGLE_error ) ;
311
		bfputc(bf, MANGLE_error);
274
	}
312
	}
275
    } else {
-
 
276
	/* Invalid identifier */
-
 
277
	bfputc ( bf, MANGLE_error ) ;
-
 
278
    }
-
 
279
    return ;
313
	return;
280
}
314
}
281
 
315
 
282
 
316
 
283
/*
317
/*
284
    ADD A NAMESPACE NAME TO THE BUFFER
318
    ADD A NAMESPACE NAME TO THE BUFFER
285
 
319
 
286
    This routine adds the mangled form of the name of the namespace ns
320
    This routine adds the mangled form of the name of the namespace ns
287
    to the buffer position given by bf.  d gives the associated namespace
321
    to the buffer position given by bf.  d gives the associated namespace
288
    depth.
322
    depth.
289
*/
323
*/
290
 
324
 
291
static void mangle_nspace
325
static void
292
    PROTO_N ( ( bf, ns, d ) )
-
 
293
    PROTO_T ( BUFFER *bf X NAMESPACE ns X int d )
326
mangle_nspace(BUFFER *bf, NAMESPACE ns, int d)
294
{
327
{
295
    if ( !IS_nspace_global ( ns ) ) {
328
	if (!IS_nspace_global(ns)) {
296
	IDENTIFIER id = DEREF_id ( nspace_name ( ns ) ) ;
329
		IDENTIFIER id = DEREF_id(nspace_name(ns));
297
	if ( IS_id_class_name ( id ) ) {
330
		if (IS_id_class_name(id)) {
298
	    TYPE t = DEREF_type ( id_class_name_defn ( id ) ) ;
331
			TYPE t = DEREF_type(id_class_name_defn(id));
299
	    if ( IS_type_compound ( t ) ) {
332
			if (IS_type_compound(t)) {
-
 
333
				CLASS_TYPE ct =
300
		CLASS_TYPE ct = DEREF_ctype ( type_compound_defn ( t ) ) ;
334
				    DEREF_ctype(type_compound_defn(t));
301
		mangle_ctype ( bf, ct, d ) ;
335
				mangle_ctype(bf, ct, d);
302
		return ;
336
				return;
303
	    }
337
			}
304
	}
338
		}
305
	mangle_id ( bf, id, d ) ;
339
		mangle_id(bf, id, d);
306
    }
340
	}
307
    return ;
341
	return;
308
}
342
}
309
 
343
 
310
 
344
 
311
/*
345
/*
312
    ADD AN EXPRESSION OPERATION TO THE BUFFER
346
    ADD AN EXPRESSION OPERATION TO THE BUFFER
313
 
347
 
314
    This routine adds the binary expression operation 'a op b' to the
348
    This routine adds the binary expression operation 'a op b' to the
315
    buffer position given by bf.
349
    buffer position given by bf.
316
*/
350
*/
317
 
351
 
318
static void mangle_exp_op
352
static void
319
    PROTO_N ( ( bf, op, a, b, n, rec ) )
-
 
320
    PROTO_T ( BUFFER *bf X int op X EXP a X EXP b X int n X int rec )
353
mangle_exp_op(BUFFER *bf, int op, EXP a, EXP b, int n, int rec)
321
{
354
{
322
    string s = mangle_op ( op ) ;
355
	string s = mangle_op(op);
323
    bfputc ( bf, MANGLE_op ) ;
356
	bfputc(bf, MANGLE_op);
324
    bfprintf ( bf, "%s%d", s + 2, n ) ;
357
	bfprintf(bf, "%s%d", s + 2, n);
-
 
358
	if (!IS_NULL_exp(a)) {
325
    if ( !IS_NULL_exp ( a ) ) mangle_exp ( bf, a, rec ) ;
359
		mangle_exp(bf, a, rec);
-
 
360
	}
-
 
361
	if (!IS_NULL_exp(b)) {
326
    if ( !IS_NULL_exp ( b ) ) mangle_exp ( bf, b, rec ) ;
362
		mangle_exp(bf, b, rec);
-
 
363
	}
327
    return ;
364
	return;
328
}
365
}
329
 
366
 
330
 
367
 
331
/*
368
/*
332
    ADD AN EXPRESSION TO THE BUFFER
369
    ADD AN EXPRESSION TO THE BUFFER
333
 
370
 
334
    This routine adds the expression e to the buffer position given by bf.
371
    This routine adds the expression e to the buffer position given by bf.
335
*/
372
*/
336
 
373
 
337
static void mangle_exp
374
static void
338
    PROTO_N ( ( bf, e, rec ) )
-
 
339
    PROTO_T ( BUFFER *bf X EXP e X int rec )
375
mangle_exp(BUFFER *bf, EXP e, int rec)
340
{
376
{
341
    if ( !IS_NULL_exp ( e ) ) {
377
	if (!IS_NULL_exp(e)) {
342
	ASSERT ( ORDER_exp == 88 ) ;
378
		ASSERT(ORDER_exp == 88);
343
	switch ( TAG_exp ( e ) ) {
379
		switch (TAG_exp(e)) {
344
	    case exp_identifier_tag :
380
		case exp_identifier_tag:
345
	    case exp_member_tag :
381
		case exp_member_tag:
346
	    case exp_ambiguous_tag :
382
		case exp_ambiguous_tag:
347
	    case exp_undeclared_tag : {
383
		case exp_undeclared_tag: {
348
		/* Identifier expressions */
384
			/* Identifier expressions */
349
		IDENTIFIER id = DEREF_id ( exp_identifier_etc_id ( e ) ) ;
385
			IDENTIFIER id = DEREF_id(exp_identifier_etc_id(e));
350
		int d = ident_depth ( id ) ;
386
			int d = ident_depth(id);
351
		bfputc ( bf, MANGLE_sep ) ;
387
			bfputc(bf, MANGLE_sep);
352
		mangle_id ( bf, id, d ) ;
388
			mangle_id(bf, id, d);
353
		break ;
389
			break;
354
	    }
390
		}
355
	    case exp_int_lit_tag : {
391
		case exp_int_lit_tag: {
356
		/* Integer literals */
392
			/* Integer literals */
357
		NAT n = DEREF_nat ( exp_int_lit_nat ( e ) ) ;
393
			NAT n = DEREF_nat(exp_int_lit_nat(e));
358
		mangle_nat ( bf, n, rec ) ;
394
			mangle_nat(bf, n, rec);
359
		break ;
395
			break;
360
	    }
396
		}
361
	    case exp_char_lit_tag : {
397
		case exp_char_lit_tag: {
362
		/* Character literals */
398
			/* Character literals */
363
		STRING s = DEREF_str ( exp_char_lit_str ( e ) ) ;
399
			STRING s = DEREF_str(exp_char_lit_str(e));
364
		NAT n = eval_char_lit ( s ) ;
400
			NAT n = eval_char_lit(s);
365
		mangle_nat ( bf, n, rec ) ;
401
			mangle_nat(bf, n, rec);
366
		break ;
402
			break;
367
	    }
403
		}
368
	    case exp_float_lit_tag : {
404
		case exp_float_lit_tag: {
369
		/* Floating-point literals */
405
			/* Floating-point literals */
370
		FLOAT flt = DEREF_flt ( exp_float_lit_flt ( e ) ) ;
406
			FLOAT flt = DEREF_flt(exp_float_lit_flt(e));
371
		string i = DEREF_string ( flt_simple_int_part ( flt ) ) ;
407
			string i = DEREF_string(flt_simple_int_part(flt));
372
		string d = DEREF_string ( flt_simple_frac_part ( flt ) ) ;
408
			string d = DEREF_string(flt_simple_frac_part(flt));
373
		NAT n = DEREF_nat ( flt_simple_exponent ( flt ) ) ;
409
			NAT n = DEREF_nat(flt_simple_exponent(flt));
374
		bfputc ( bf, MANGLE_op ) ;
410
			bfputc(bf, MANGLE_op);
375
		bfprintf ( bf, "f%sd%s", i, d ) ;
411
			bfprintf(bf, "f%sd%s", i, d);
376
		if ( is_zero_nat ( n ) ) {
412
			if (is_zero_nat(n)) {
377
		    bfputc ( bf, MANGLE_sep ) ;
413
				bfputc(bf, MANGLE_sep);
378
		} else {
414
			} else {
379
		    bfputc ( bf, 'e' ) ;
415
				bfputc(bf, 'e');
380
		    mangle_nat ( bf, n, 0 ) ;
416
				mangle_nat(bf, n, 0);
-
 
417
			}
-
 
418
			break;
-
 
419
		}
-
 
420
		case exp_null_tag:
-
 
421
		case exp_zero_tag:
-
 
422
		case exp_value_tag: {
-
 
423
			/* Null pointers */
-
 
424
			mangle_nat(bf, small_nat[0], 0);
-
 
425
			break;
-
 
426
		}
-
 
427
		case exp_paren_tag:
-
 
428
		case exp_copy_tag: {
-
 
429
			/* Parenthesised expressions */
-
 
430
			EXP a = DEREF_exp(exp_paren_etc_arg(e));
-
 
431
			mangle_exp(bf, a, rec);
-
 
432
			break;
-
 
433
		}
-
 
434
		case exp_indir_tag: {
-
 
435
			/* Indirection expressions */
-
 
436
			EXP a = DEREF_exp(exp_indir_ptr(e));
-
 
437
			mangle_exp(bf, a, rec);
-
 
438
			break;
-
 
439
		}
-
 
440
		case exp_address_tag: {
-
 
441
			/* Address expressions */
-
 
442
			EXP a = DEREF_exp(exp_address_arg(e));
-
 
443
			mangle_exp(bf, a, rec);
-
 
444
			break;
-
 
445
		}
-
 
446
		case exp_address_mem_tag: {
-
 
447
			/* Address expressions */
-
 
448
			EXP a = DEREF_exp(exp_address_mem_arg(e));
-
 
449
			mangle_exp(bf, a, rec);
-
 
450
			break;
-
 
451
		}
-
 
452
		case exp_negate_tag:
-
 
453
		case exp_compl_tag:
-
 
454
		case exp_not_tag:
-
 
455
		case exp_abs_tag: {
-
 
456
			/* Unary expressions */
-
 
457
			int op = op_token(e, lex_unknown);
-
 
458
			EXP a = DEREF_exp(exp_negate_etc_arg(e));
-
 
459
			mangle_exp_op(bf, op, a, NULL_exp, 1, rec);
-
 
460
			break;
-
 
461
		}
-
 
462
		case exp_plus_tag:
-
 
463
		case exp_minus_tag:
-
 
464
		case exp_mult_tag:
-
 
465
		case exp_div_tag:
-
 
466
		case exp_rem_tag:
-
 
467
		case exp_and_tag:
-
 
468
		case exp_or_tag:
-
 
469
		case exp_xor_tag:
-
 
470
		case exp_log_and_tag:
-
 
471
		case exp_log_or_tag:
-
 
472
		case exp_lshift_tag:
-
 
473
		case exp_rshift_tag:
-
 
474
		case exp_max_tag:
-
 
475
		case exp_min_tag: {
-
 
476
			/* Binary expressions */
-
 
477
			int op = op_token(e, lex_unknown);
-
 
478
			EXP a = DEREF_exp(exp_plus_etc_arg1(e));
-
 
479
			EXP b = DEREF_exp(exp_plus_etc_arg2(e));
-
 
480
			mangle_exp_op(bf, op, a, b, 2, rec);
-
 
481
			break;
-
 
482
		}
-
 
483
		case exp_test_tag: {
-
 
484
			/* Test expressions */
-
 
485
			int op = op_token(e, lex_unknown);
-
 
486
			EXP a = DEREF_exp(exp_test_arg(e));
-
 
487
			mangle_exp_op(bf, op, a, NULL_exp, 1, rec);
-
 
488
			break;
-
 
489
		}
-
 
490
		case exp_compare_tag: {
-
 
491
			/* Comparison expressions */
-
 
492
			int op = op_token(e, lex_unknown);
-
 
493
			EXP a = DEREF_exp(exp_compare_arg1(e));
-
 
494
			EXP b = DEREF_exp(exp_compare_arg2(e));
-
 
495
			mangle_exp_op(bf, op, a, b, 2, rec);
-
 
496
			break;
-
 
497
		}
-
 
498
		case exp_cast_tag: {
-
 
499
			/* Cast expressions */
-
 
500
			EXP a = DEREF_exp(exp_cast_arg(e));
-
 
501
			mangle_exp(bf, a, rec);
-
 
502
			break;
-
 
503
		}
-
 
504
		case exp_base_cast_tag: {
-
 
505
			/* Base cast expressions */
-
 
506
			EXP a = DEREF_exp(exp_base_cast_arg(e));
-
 
507
			mangle_exp(bf, a, rec);
-
 
508
			break;
-
 
509
		}
-
 
510
		case exp_add_ptr_tag: {
-
 
511
			/* Pointer addition */
-
 
512
			EXP a = DEREF_exp(exp_add_ptr_ptr(e));
-
 
513
			/* NOT YET IMPLEMENTED */
-
 
514
			mangle_exp(bf, a, rec);
-
 
515
			break;
-
 
516
		}
-
 
517
		case exp_offset_size_tag: {
-
 
518
			/* Offset size */
-
 
519
			OFFSET a = DEREF_off(exp_offset_size_off(e));
-
 
520
			if (IS_off_type(a)) {
-
 
521
				/* Allow for sizeof expressions */
-
 
522
				TYPE s = DEREF_type(exp_offset_size_step(e));
-
 
523
				if (EQ_type(s, type_char)) {
-
 
524
					int op = lex_sizeof;
-
 
525
					mangle_exp_op(bf, op, NULL_exp,
-
 
526
						      NULL_exp, 1, rec);
-
 
527
					s = DEREF_type(off_type_type(a));
-
 
528
					mangle_type(bf, s, 2, 1);
-
 
529
					break;
-
 
530
				}
-
 
531
			}
-
 
532
			/* NOT YET IMPLEMENTED */
-
 
533
			bfputc(bf, MANGLE_error);
-
 
534
			break;
-
 
535
		}
-
 
536
		case exp_comma_tag: {
-
 
537
			/* Comma expressions */
-
 
538
			LIST(EXP)p = DEREF_list(exp_comma_args(e));
-
 
539
			while (!IS_NULL_list(p)) {
-
 
540
				EXP a = DEREF_exp(HEAD_list(p));
-
 
541
				p = TAIL_list(p);
-
 
542
				if (IS_NULL_list(p)) {
-
 
543
					mangle_exp(bf, a, rec);
-
 
544
				} else {
-
 
545
					mangle_exp_op(bf, lex_comma, a,
-
 
546
						      NULL_exp, 2, rec);
-
 
547
				}
-
 
548
			}
-
 
549
			break;
-
 
550
		}
-
 
551
		case exp_if_stmt_tag: {
-
 
552
			/* Conditional expressions */
-
 
553
			EXP c = DEREF_exp(exp_if_stmt_cond(e));
-
 
554
			EXP a = DEREF_exp(exp_if_stmt_true_code(e));
-
 
555
			EXP b = DEREF_exp(exp_if_stmt_false_code(e));
-
 
556
			mangle_exp_op(bf, lex_cond_Hop, c, a, 3, rec);
-
 
557
			mangle_exp(bf, b, rec);
-
 
558
			break;
-
 
559
		}
-
 
560
		case exp_rtti_type_tag: {
-
 
561
			/* Run-time type information expressions */
-
 
562
			TYPE s = DEREF_type(exp_rtti_type_arg(e));
-
 
563
			int op = DEREF_int(exp_rtti_type_op(e));
-
 
564
			mangle_exp_op(bf, op, NULL_exp, NULL_exp, 1, rec);
-
 
565
			mangle_type(bf, s, 2, 1);
-
 
566
			break;
-
 
567
		}
-
 
568
		case exp_token_tag: {
-
 
569
			/* Tokenised expressions */
-
 
570
			IDENTIFIER id = DEREF_id(exp_token_tok(e));
-
 
571
			LIST(TOKEN)args = DEREF_list(exp_token_args(e));
-
 
572
			mangle_token(bf, id, args, -2, 1);
-
 
573
			break;
-
 
574
		}
-
 
575
		case exp_location_tag: {
-
 
576
			/* Location expressions */
-
 
577
			EXP a = DEREF_exp(exp_location_arg(e));
-
 
578
			mangle_exp(bf, a, rec);
-
 
579
			break;
-
 
580
		}
-
 
581
		case exp_dummy_tag: {
-
 
582
			/* Dummy expressions */
-
 
583
			EXP a = DEREF_exp(exp_dummy_value(e));
-
 
584
			mangle_exp(bf, a, rec);
-
 
585
			break;
381
		}
586
		}
382
		break ;
-
 
383
	    }
-
 
384
	    case exp_null_tag :
-
 
385
	    case exp_zero_tag :
-
 
386
	    case exp_value_tag : {
-
 
387
		/* Null pointers */
-
 
388
		mangle_nat ( bf, small_nat [0], 0 ) ;
-
 
389
		break ;
-
 
390
	    }
-
 
391
	    case exp_paren_tag :
-
 
392
	    case exp_copy_tag : {
-
 
393
		/* Parenthesised expressions */
-
 
394
		EXP a = DEREF_exp ( exp_paren_etc_arg ( e ) ) ;
-
 
395
		mangle_exp ( bf, a, rec ) ;
-
 
396
		break ;
-
 
397
	    }
-
 
398
	    case exp_indir_tag : {
-
 
399
		/* Indirection expressions */
-
 
400
		EXP a = DEREF_exp ( exp_indir_ptr ( e ) ) ;
-
 
401
		mangle_exp ( bf, a, rec ) ;
-
 
402
		break ;
-
 
403
	    }
-
 
404
	    case exp_address_tag : {
-
 
405
		/* Address expressions */
-
 
406
		EXP a = DEREF_exp ( exp_address_arg ( e ) ) ;
-
 
407
		mangle_exp ( bf, a, rec ) ;
-
 
408
		break ;
-
 
409
	    }
-
 
410
	    case exp_address_mem_tag : {
-
 
411
		/* Address expressions */
-
 
412
		EXP a = DEREF_exp ( exp_address_mem_arg ( e ) ) ;
-
 
413
		mangle_exp ( bf, a, rec ) ;
-
 
414
		break ;
-
 
415
	    }
-
 
416
	    case exp_negate_tag :
-
 
417
	    case exp_compl_tag :
-
 
418
	    case exp_not_tag :
-
 
419
	    case exp_abs_tag : {
-
 
420
		/* Unary expressions */
-
 
421
		int op = op_token ( e, lex_unknown ) ;
-
 
422
		EXP a = DEREF_exp ( exp_negate_etc_arg ( e ) ) ;
-
 
423
		mangle_exp_op ( bf, op, a, NULL_exp, 1, rec ) ;
-
 
424
		break ;
-
 
425
	    }
-
 
426
	    case exp_plus_tag :
-
 
427
	    case exp_minus_tag :
-
 
428
	    case exp_mult_tag :
-
 
429
	    case exp_div_tag :
-
 
430
	    case exp_rem_tag :
-
 
431
	    case exp_and_tag :
-
 
432
	    case exp_or_tag :
-
 
433
	    case exp_xor_tag :
-
 
434
	    case exp_log_and_tag :
-
 
435
	    case exp_log_or_tag :
-
 
436
	    case exp_lshift_tag :
-
 
437
	    case exp_rshift_tag :
-
 
438
	    case exp_max_tag :
-
 
439
	    case exp_min_tag : {
-
 
440
		/* Binary expressions */
-
 
441
		int op = op_token ( e, lex_unknown ) ;
-
 
442
		EXP a = DEREF_exp ( exp_plus_etc_arg1 ( e ) ) ;
-
 
443
		EXP b = DEREF_exp ( exp_plus_etc_arg2 ( e ) ) ;
-
 
444
		mangle_exp_op ( bf, op, a, b, 2, rec ) ;
-
 
445
		break ;
-
 
446
	    }
-
 
447
	    case exp_test_tag : {
-
 
448
		/* Test expressions */
-
 
449
		int op = op_token ( e, lex_unknown ) ;
-
 
450
		EXP a = DEREF_exp ( exp_test_arg ( e ) ) ;
-
 
451
		mangle_exp_op ( bf, op, a, NULL_exp, 1, rec ) ;
-
 
452
		break ;
-
 
453
	    }
-
 
454
	    case exp_compare_tag : {
-
 
455
		/* Comparison expressions */
-
 
456
		int op = op_token ( e, lex_unknown ) ;
-
 
457
		EXP a = DEREF_exp ( exp_compare_arg1 ( e ) ) ;
-
 
458
		EXP b = DEREF_exp ( exp_compare_arg2 ( e ) ) ;
-
 
459
		mangle_exp_op ( bf, op, a, b, 2, rec ) ;
-
 
460
		break ;
-
 
461
	    }
-
 
462
	    case exp_cast_tag : {
-
 
463
		/* Cast expressions */
-
 
464
		EXP a = DEREF_exp ( exp_cast_arg ( e ) ) ;
-
 
465
		mangle_exp ( bf, a, rec ) ;
-
 
466
		break ;
-
 
467
	    }
-
 
468
	    case exp_base_cast_tag : {
-
 
469
		/* Base cast expressions */
-
 
470
		EXP a = DEREF_exp ( exp_base_cast_arg ( e ) ) ;
-
 
471
		mangle_exp ( bf, a, rec ) ;
-
 
472
		break ;
-
 
473
	    }
-
 
474
	    case exp_add_ptr_tag : {
-
 
475
		/* Pointer addition */
-
 
476
		EXP a = DEREF_exp ( exp_add_ptr_ptr ( e ) ) ;
-
 
477
		/* NOT YET IMPLEMENTED */
-
 
478
		mangle_exp ( bf, a, rec ) ;
-
 
479
		break ;
587
		default: {
480
	    }
-
 
481
	    case exp_offset_size_tag : {
-
 
482
		/* Offset size */
-
 
483
		OFFSET a = DEREF_off ( exp_offset_size_off ( e ) ) ;
-
 
484
		if ( IS_off_type ( a ) ) {
-
 
485
		    /* Allow for sizeof expressions */
-
 
486
		    TYPE s = DEREF_type ( exp_offset_size_step ( e ) ) ;
-
 
487
		    if ( EQ_type ( s, type_char ) ) {
-
 
488
			int op = lex_sizeof ;
588
			bfputc(bf, MANGLE_error);
489
			mangle_exp_op ( bf, op, NULL_exp, NULL_exp, 1, rec ) ;
-
 
490
			s = DEREF_type ( off_type_type ( a ) ) ;
-
 
491
			mangle_type ( bf, s, 2, 1 ) ;
-
 
492
			break ;
589
			break;
493
		    }
-
 
494
		}
590
		}
495
		/* NOT YET IMPLEMENTED */
-
 
496
		bfputc ( bf, MANGLE_error ) ;
-
 
497
		break ;
-
 
498
	    }
-
 
499
	    case exp_comma_tag : {
-
 
500
		/* Comma expressions */
-
 
501
		LIST ( EXP ) p = DEREF_list ( exp_comma_args ( e ) ) ;
-
 
502
		while ( !IS_NULL_list ( p ) ) {
-
 
503
		    EXP a = DEREF_exp ( HEAD_list ( p ) ) ;
-
 
504
		    p = TAIL_list ( p ) ;
-
 
505
		    if ( IS_NULL_list ( p ) ) {
-
 
506
			mangle_exp ( bf, a, rec ) ;
-
 
507
		    } else {
-
 
508
			mangle_exp_op ( bf, lex_comma, a, NULL_exp, 2, rec ) ;
-
 
509
		    }
-
 
510
		}
591
		}
511
		break ;
-
 
512
	    }
-
 
513
	    case exp_if_stmt_tag : {
-
 
514
		/* Conditional expressions */
-
 
515
		EXP c = DEREF_exp ( exp_if_stmt_cond ( e ) ) ;
-
 
516
		EXP a = DEREF_exp ( exp_if_stmt_true_code ( e ) ) ;
-
 
517
		EXP b = DEREF_exp ( exp_if_stmt_false_code ( e ) ) ;
-
 
518
		mangle_exp_op ( bf, lex_cond_Hop, c, a, 3, rec ) ;
-
 
519
		mangle_exp ( bf, b, rec ) ;
-
 
520
		break ;
-
 
521
	    }
-
 
522
	    case exp_rtti_type_tag : {
-
 
523
		/* Run-time type information expressions */
-
 
524
		TYPE s = DEREF_type ( exp_rtti_type_arg ( e ) ) ;
-
 
525
		int op = DEREF_int ( exp_rtti_type_op ( e ) ) ;
-
 
526
		mangle_exp_op ( bf, op, NULL_exp, NULL_exp, 1, rec ) ;
-
 
527
		mangle_type ( bf, s, 2, 1 ) ;
-
 
528
		break ;
-
 
529
	    }
-
 
530
	    case exp_token_tag : {
-
 
531
		/* Tokenised expressions */
-
 
532
		IDENTIFIER id = DEREF_id ( exp_token_tok ( e ) ) ;
-
 
533
		LIST ( TOKEN ) args = DEREF_list ( exp_token_args ( e ) ) ;
-
 
534
		mangle_token ( bf, id, args, -2, 1 ) ;
-
 
535
		break ;
-
 
536
	    }
-
 
537
	    case exp_location_tag : {
-
 
538
		/* Location expressions */
-
 
539
		EXP a = DEREF_exp ( exp_location_arg ( e ) ) ;
-
 
540
		mangle_exp ( bf, a, rec ) ;
-
 
541
		break ;
-
 
542
	    }
-
 
543
	    case exp_dummy_tag : {
-
 
544
		/* Dummy expressions */
-
 
545
		EXP a = DEREF_exp ( exp_dummy_value ( e ) ) ;
-
 
546
		mangle_exp ( bf, a, rec ) ;
-
 
547
		break ;
-
 
548
	    }
-
 
549
	    default : {
-
 
550
		bfputc ( bf, MANGLE_error ) ;
-
 
551
		break ;
-
 
552
	    }
-
 
553
	}
592
	}
554
    }
-
 
555
    return ;
593
	return;
556
}
594
}
557
 
595
 
558
 
596
 
559
/*
597
/*
560
    ADD AN INTEGER CONSTANT TO THE BUFFER
598
    ADD AN INTEGER CONSTANT TO THE BUFFER
561
 
599
 
562
    This routine adds the integer constant n to the buffer position given
600
    This routine adds the integer constant n to the buffer position given
563
    by bf.
601
    by bf.
564
*/
602
*/
565
 
603
 
566
static void mangle_nat
604
static void
567
    PROTO_N ( ( bf, n, rec ) )
-
 
568
    PROTO_T ( BUFFER *bf X NAT n X int rec )
605
mangle_nat(BUFFER *bf, NAT n, int rec)
569
{
606
{
570
    if ( IS_NULL_nat ( n ) ) {
607
	if (IS_NULL_nat(n)) {
571
	bfputc ( bf, MANGLE_sep ) ;
608
		bfputc(bf, MANGLE_sep);
572
    } else {
609
	} else {
573
	unsigned tag = TAG_nat ( n ) ;
610
		unsigned tag = TAG_nat(n);
574
	if ( tag == nat_neg_tag ) {
611
		if (tag == nat_neg_tag) {
575
	    /* Negative values */
612
			/* Negative values */
576
	    bfputc ( bf, MANGLE_neg ) ;
613
			bfputc(bf, MANGLE_neg);
577
	    n = DEREF_nat ( nat_neg_arg ( n ) ) ;
614
			n = DEREF_nat(nat_neg_arg(n));
578
	    tag = TAG_nat ( n ) ;
615
			tag = TAG_nat(n);
579
	}
616
		}
580
	switch ( tag ) {
617
		switch (tag) {
581
	    case nat_calc_tag : {
618
		case nat_calc_tag: {
582
		/* Calculated values */
619
			/* Calculated values */
583
		EXP e = DEREF_exp ( nat_calc_value ( n ) ) ;
620
			EXP e = DEREF_exp(nat_calc_value(n));
-
 
621
			if (rec) {
584
		if ( rec ) e = eval_exp ( e, 1 ) ;
622
				e = eval_exp(e, 1);
-
 
623
			}
585
		mangle_exp ( bf, e, 0 ) ;
624
			mangle_exp(bf, e, 0);
586
		break ;
625
			break;
587
	    }
626
		}
588
	    case nat_token_tag : {
627
		case nat_token_tag: {
589
		/* Tokenised values */
628
			/* Tokenised values */
590
		IDENTIFIER id = DEREF_id ( nat_token_tok ( n ) ) ;
629
			IDENTIFIER id = DEREF_id(nat_token_tok(n));
591
		LIST ( TOKEN ) args = DEREF_list ( nat_token_args ( n ) ) ;
630
			LIST(TOKEN)args = DEREF_list(nat_token_args(n));
592
		mangle_token ( bf, id, args, -2, 1 ) ;
631
			mangle_token(bf, id, args, -2, 1);
593
		break ;
632
			break;
594
	    }
633
		}
595
	    default : {
634
		default: {
596
		/* Simple values */
635
			/* Simple values */
597
		unsigned long v = get_nat_value ( n ) ;
636
			unsigned long v = get_nat_value(n);
598
		if ( v == EXTENDED_MAX ) {
637
			if (v == EXTENDED_MAX) {
599
		    /* Really large values */
638
				/* Really large values */
600
		    IGNORE print_nat ( n, 0, bf, 0 ) ;
639
				IGNORE print_nat(n, 0, bf, 0);
601
		} else {
640
			} else {
602
		    mangle_number ( bf, v, 0 ) ;
641
				mangle_number(bf, v, 0);
603
		}
642
			}
604
		bfputc ( bf, MANGLE_sep ) ;
643
			bfputc(bf, MANGLE_sep);
605
		break ;
644
			break;
606
	    }
645
		}
607
	}
646
		}
608
    }
647
	}
609
    return ;
648
	return;
610
}
649
}
611
 
650
 
612
 
651
 
613
/*
652
/*
614
    FIND THE MANGLED FORM OF A LITERAL TYPE
653
    FIND THE MANGLED FORM OF A LITERAL TYPE
615
 
654
 
616
    This routine finds the mangled form of the integer literal type it.
655
    This routine finds the mangled form of the integer literal type it.
617
*/
656
*/
618
 
657
 
619
string mangle_literal
658
string
620
    PROTO_N ( ( it ) )
-
 
621
    PROTO_T ( INT_TYPE it )
659
mangle_literal(INT_TYPE it)
622
{
660
{
623
    static character buff [20] ;
661
	static character buff[20];
624
    string s = buff ;
662
	string s = buff;
625
    int form = DEREF_int ( itype_literal_form ( it ) ) ;
663
	int form = DEREF_int(itype_literal_form(it));
626
    int suff = DEREF_int ( itype_literal_suff ( it ) ) ;
664
	int suff = DEREF_int(itype_literal_suff(it));
627
    *( s++ ) = MANGLE_literal ;
665
	*(s++) = MANGLE_literal;
628
    if ( form == BASE_OCTAL ) {
666
	if (form == BASE_OCTAL) {
629
	*( s++ ) = MANGLE_octal ;
667
		*(s++) = MANGLE_octal;
630
    } else if ( form == BASE_HEXADECIMAL ) {
668
	} else if (form == BASE_HEXADECIMAL) {
631
	*( s++ ) = MANGLE_hex ;
669
		*(s++) = MANGLE_hex;
632
    }
670
	}
-
 
671
	if (suff & SUFFIX_U) {
633
    if ( suff & SUFFIX_U ) *( s++ ) = MANGLE_unsigned ;
672
		*(s++) = MANGLE_unsigned;
-
 
673
	}
-
 
674
	if (suff & SUFFIX_L) {
-
 
675
		*(s++) = MANGLE_long;
-
 
676
	}
634
    if ( suff & SUFFIX_L ) *( s++ ) = MANGLE_long ;
677
	if (suff & SUFFIX_LL) {
635
    if ( suff & SUFFIX_LL ) *( s++ ) = MANGLE_llong ;
678
		*(s++) = MANGLE_llong;
-
 
679
	}
636
    *s = 0 ;
680
	*s = 0;
637
    return ( buff ) ;
681
	return (buff);
638
}
682
}
639
 
683
 
640
 
684
 
641
/*
685
/*
642
    ADD AN INTEGRAL TYPE TO THE BUFFER
686
    ADD AN INTEGRAL TYPE TO THE BUFFER
643
 
687
 
644
    This routine adds the mangled form of the integral type it to the
688
    This routine adds the mangled form of the integral type it to the
645
    buffer position given by bf.
689
    buffer position given by bf.
646
*/
690
*/
647
 
691
 
648
static void mangle_itype
692
static void
649
    PROTO_N ( ( bf, it ) )
-
 
650
    PROTO_T ( BUFFER *bf X INT_TYPE it )
693
mangle_itype(BUFFER *bf, INT_TYPE it)
651
{
694
{
652
    switch ( TAG_itype ( it ) ) {
695
	switch (TAG_itype(it)) {
653
	case itype_basic_tag : {
696
	case itype_basic_tag: {
654
	    /* Basic integral types */
697
		/* Basic integral types */
655
	    BUILTIN_TYPE n = DEREF_ntype ( itype_basic_no ( it ) ) ;
698
		BUILTIN_TYPE n = DEREF_ntype(itype_basic_no(it));
656
	    bfputs ( bf, ustrlit ( mangle_ntype [n] ) ) ;
699
		bfputs(bf, ustrlit(mangle_ntype[n]));
657
	    break ;
700
		break;
658
	}
701
	}
659
	case itype_bitfield_tag : {
702
	case itype_bitfield_tag: {
660
	    /* Bitfield types */
703
		/* Bitfield types */
661
	    TYPE s = DEREF_type ( itype_bitfield_sub ( it ) ) ;
704
		TYPE s = DEREF_type(itype_bitfield_sub(it));
662
	    NAT n = DEREF_nat ( itype_bitfield_size ( it ) ) ;
705
		NAT n = DEREF_nat(itype_bitfield_size(it));
663
	    BASE_TYPE rep = DEREF_btype ( itype_bitfield_rep ( it ) ) ;
706
		BASE_TYPE rep = DEREF_btype(itype_bitfield_rep(it));
664
	    bfputc ( bf, MANGLE_bitfield ) ;
707
		bfputc(bf, MANGLE_bitfield);
665
	    mangle_nat ( bf, n, 1 ) ;
708
		mangle_nat(bf, n, 1);
666
	    if ( rep & btype_signed ) {
709
		if (rep & btype_signed) {
667
		bfputc ( bf, MANGLE_signed ) ;
710
			bfputc(bf, MANGLE_signed);
668
		if ( rep & btype_char ) s = type_char ;
711
			if (rep & btype_char) {
-
 
712
				s = type_char;
669
	    }
713
			}
-
 
714
		}
670
	    mangle_type ( bf, s, 2, 1 ) ;
715
		mangle_type(bf, s, 2, 1);
671
	    break ;
716
		break;
672
	}
717
	}
673
	case itype_promote_tag : {
718
	case itype_promote_tag: {
674
	    /* Promotion types */
719
		/* Promotion types */
675
	    INT_TYPE is = DEREF_itype ( itype_promote_arg ( it ) ) ;
720
		INT_TYPE is = DEREF_itype(itype_promote_arg(it));
676
	    bfputc ( bf, MANGLE_promote ) ;
721
		bfputc(bf, MANGLE_promote);
677
	    mangle_itype ( bf, is ) ;
722
		mangle_itype(bf, is);
678
	    break ;
723
		break;
679
	}
724
	}
680
	case itype_arith_tag : {
725
	case itype_arith_tag: {
681
	    /* Arithmetic types */
726
		/* Arithmetic types */
682
	    INT_TYPE is = DEREF_itype ( itype_arith_arg1 ( it ) ) ;
727
		INT_TYPE is = DEREF_itype(itype_arith_arg1(it));
683
	    INT_TYPE ir = DEREF_itype ( itype_arith_arg2 ( it ) ) ;
728
		INT_TYPE ir = DEREF_itype(itype_arith_arg2(it));
684
	    bfputc ( bf, MANGLE_arith ) ;
729
		bfputc(bf, MANGLE_arith);
685
	    mangle_itype ( bf, is ) ;
730
		mangle_itype(bf, is);
686
	    mangle_itype ( bf, ir ) ;
731
		mangle_itype(bf, ir);
687
	    break ;
732
		break;
688
	}
733
	}
689
	case itype_literal_tag : {
734
	case itype_literal_tag: {
690
	    /* Literal types */
735
		/* Literal types */
691
	    NAT n = DEREF_nat ( itype_literal_nat ( it ) ) ;
736
		NAT n = DEREF_nat(itype_literal_nat(it));
692
	    string s = mangle_literal ( it ) ;
737
		string s = mangle_literal(it);
693
	    bfputs ( bf, s ) ;
738
		bfputs(bf, s);
694
	    mangle_nat ( bf, n, 1 ) ;
739
		mangle_nat(bf, n, 1);
695
	    break ;
740
		break;
696
	}
741
	}
697
	case itype_token_tag : {
742
	case itype_token_tag: {
698
	    /* Tokenised types */
743
		/* Tokenised types */
699
	    BUILTIN_TYPE n = DEREF_ntype ( itype_unprom ( it ) ) ;
744
		BUILTIN_TYPE n = DEREF_ntype(itype_unprom(it));
700
	    if ( n == ntype_none || n == ntype_ellipsis ) {
745
		if (n == ntype_none || n == ntype_ellipsis) {
701
		IDENTIFIER id ;
746
			IDENTIFIER id;
702
		LIST ( TOKEN ) args ;
747
			LIST(TOKEN)args;
703
		id = DEREF_id ( itype_token_tok ( it ) ) ;
748
			id = DEREF_id(itype_token_tok(it));
704
		args = DEREF_list ( itype_token_args ( it ) ) ;
749
			args = DEREF_list(itype_token_args(it));
705
		mangle_token ( bf, id, args, -2, 0 ) ;
750
			mangle_token(bf, id, args, -2, 0);
706
	    } else {
751
		} else {
707
		bfputc ( bf, MANGLE_promote ) ;
752
			bfputc(bf, MANGLE_promote);
708
		bfputs ( bf, ustrlit ( mangle_ntype [n] ) ) ;
753
			bfputs(bf, ustrlit(mangle_ntype[n]));
709
	    }
754
		}
710
	    break ;
755
		break;
711
	}
756
	}
712
    }
757
	}
713
    return ;
758
	return;
714
}
759
}
715
 
760
 
716
 
761
 
717
/*
762
/*
718
    ADD A FLOATING TYPE TO THE BUFFER
763
    ADD A FLOATING TYPE TO THE BUFFER
719
 
764
 
720
    This routine adds the mangled form of the floating-point type ft to
765
    This routine adds the mangled form of the floating-point type ft to
721
    the buffer position given by bf.
766
    the buffer position given by bf.
722
*/
767
*/
723
 
768
 
724
static void mangle_ftype
769
static void
725
    PROTO_N ( ( bf, ft ) )
-
 
726
    PROTO_T ( BUFFER *bf X FLOAT_TYPE ft )
770
mangle_ftype(BUFFER *bf, FLOAT_TYPE ft)
727
{
771
{
728
    switch ( TAG_ftype ( ft ) ) {
772
	switch (TAG_ftype(ft)) {
729
	case ftype_basic_tag : {
773
	case ftype_basic_tag: {
730
	    /* Basic floating types */
774
		/* Basic floating types */
731
	    BUILTIN_TYPE n = DEREF_ntype ( ftype_basic_no ( ft ) ) ;
775
		BUILTIN_TYPE n = DEREF_ntype(ftype_basic_no(ft));
732
	    bfputs ( bf, ustrlit ( mangle_ntype [n] ) ) ;
776
		bfputs(bf, ustrlit(mangle_ntype[n]));
733
	    break ;
777
		break;
734
	}
778
	}
735
	case ftype_arg_promote_tag : {
779
	case ftype_arg_promote_tag: {
736
	    /* Promotion types */
780
		/* Promotion types */
737
	    FLOAT_TYPE fs = DEREF_ftype ( ftype_arg_promote_arg ( ft ) ) ;
781
		FLOAT_TYPE fs = DEREF_ftype(ftype_arg_promote_arg(ft));
738
	    bfputc ( bf, MANGLE_promote ) ;
782
		bfputc(bf, MANGLE_promote);
739
	    mangle_ftype ( bf, fs ) ;
783
		mangle_ftype(bf, fs);
740
	    break ;
784
		break;
741
	}
785
	}
742
	case ftype_arith_tag : {
786
	case ftype_arith_tag: {
743
	    /* Arithmetic types */
787
		/* Arithmetic types */
744
	    FLOAT_TYPE fs = DEREF_ftype ( ftype_arith_arg1 ( ft ) ) ;
788
		FLOAT_TYPE fs = DEREF_ftype(ftype_arith_arg1(ft));
745
	    FLOAT_TYPE fr = DEREF_ftype ( ftype_arith_arg2 ( ft ) ) ;
789
		FLOAT_TYPE fr = DEREF_ftype(ftype_arith_arg2(ft));
746
	    bfputc ( bf, MANGLE_arith ) ;
790
		bfputc(bf, MANGLE_arith);
747
	    mangle_ftype ( bf, fs ) ;
791
		mangle_ftype(bf, fs);
748
	    mangle_ftype ( bf, fr ) ;
792
		mangle_ftype(bf, fr);
749
	    break ;
793
		break;
750
	}
794
	}
751
	case ftype_token_tag : {
795
	case ftype_token_tag: {
752
	    /* Tokenised types */
796
		/* Tokenised types */
753
	    IDENTIFIER id = DEREF_id ( ftype_token_tok ( ft ) ) ;
797
		IDENTIFIER id = DEREF_id(ftype_token_tok(ft));
754
	    LIST ( TOKEN ) args = DEREF_list ( ftype_token_args ( ft ) ) ;
798
		LIST(TOKEN)args = DEREF_list(ftype_token_args(ft));
755
	    mangle_token ( bf, id, args, -2, 0 ) ;
799
		mangle_token(bf, id, args, -2, 0);
756
	    break ;
800
		break;
757
	}
801
	}
758
    }
802
	}
759
    return ;
803
	return;
760
}
804
}
761
 
805
 
762
 
806
 
763
/*
807
/*
764
    ADD A CV-QUALIFIER TO THE BUFFER
808
    ADD A CV-QUALIFIER TO THE BUFFER
765
 
809
 
766
    This routine adds the mangled form of the cv-qualifiers cv to the
810
    This routine adds the mangled form of the cv-qualifiers cv to the
767
    buffer position given by bf.  Note that this mangling scheme maps
811
    buffer position given by bf.  Note that this mangling scheme maps
768
    'volatile unsigned char *' to 'PVUc' rather than the ARM's 'PUVc'.
812
    'volatile unsigned char *' to 'PVUc' rather than the ARM's 'PUVc'.
769
*/
813
*/
770
 
814
 
771
static void mangle_cv
815
static void
772
    PROTO_N ( ( bf, cv ) )
-
 
773
    PROTO_T ( BUFFER *bf X CV_SPEC cv )
816
mangle_cv(BUFFER *bf, CV_SPEC cv)
774
{
817
{
-
 
818
	if (cv & cv_const) {
775
    if ( cv & cv_const ) bfputc ( bf, MANGLE_const ) ;
819
		bfputc(bf, MANGLE_const);
-
 
820
	}
-
 
821
	if (cv & cv_volatile) {
776
    if ( cv & cv_volatile ) bfputc ( bf, MANGLE_volatile ) ;
822
		bfputc(bf, MANGLE_volatile);
-
 
823
	}
-
 
824
	if (cv & cv_c) {
777
    if ( cv & cv_c ) bfputc ( bf, MANGLE_c_lang ) ;
825
		bfputc(bf, MANGLE_c_lang);
-
 
826
	}
778
    return ;
827
	return;
779
}
828
}
780
 
829
 
781
 
830
 
782
/*
831
/*
783
    ADD A TYPE NAME TO THE BUFFER
832
    ADD A TYPE NAME TO THE BUFFER
784
 
833
 
785
    This routine adds the mangled form of the name of the type t to the
834
    This routine adds the mangled form of the name of the type t to the
786
    buffer position given by bf.  The printing of function types (for
835
    buffer position given by bf.  The printing of function types (for
787
    example whether the return type is included) is controlled by fn
836
    example whether the return type is included) is controlled by fn
788
    and that of array types by arr.
837
    and that of array types by arr.
789
*/
838
*/
790
 
839
 
791
static void mangle_type
840
static void
792
    PROTO_N ( ( bf, t, fn, arr ) )
-
 
793
    PROTO_T ( BUFFER *bf X TYPE t X int fn X int arr )
841
mangle_type(BUFFER *bf, TYPE t, int fn, int arr)
794
{
842
{
795
    /* Output cv-qualifier */
843
	/* Output cv-qualifier */
796
    CV_SPEC qual = DEREF_cv ( type_qual ( t ) ) ;
844
	CV_SPEC qual = DEREF_cv(type_qual(t));
797
    mangle_cv ( bf, qual ) ;
845
	mangle_cv(bf, qual);
798
 
846
 
799
    /* Output main type information */
847
	/* Output main type information */
800
    switch ( TAG_type ( t ) ) {
848
	switch (TAG_type(t)) {
801
 
-
 
802
	case type_integer_tag : {
849
	case type_integer_tag: {
803
	    /* Integral types */
850
		/* Integral types */
804
	    INT_TYPE it = DEREF_itype ( type_integer_rep ( t ) ) ;
851
		INT_TYPE it = DEREF_itype(type_integer_rep(t));
805
	    mangle_itype ( bf, it ) ;
852
		mangle_itype(bf, it);
806
	    break ;
853
		break;
807
	}
854
	}
808
 
-
 
809
	case type_floating_tag : {
855
	case type_floating_tag: {
810
	    /* Floating-point types */
856
		/* Floating-point types */
811
	    FLOAT_TYPE ft = DEREF_ftype ( type_floating_rep ( t ) ) ;
857
		FLOAT_TYPE ft = DEREF_ftype(type_floating_rep(t));
812
	    mangle_ftype ( bf, ft ) ;
858
		mangle_ftype(bf, ft);
813
	    break ;
859
		break;
814
	}
860
	}
815
 
-
 
816
	case type_top_tag : {
861
	case type_top_tag: {
817
	    /* Top type */
862
		/* Top type */
818
	    bfputc ( bf, MANGLE_void ) ;
863
		bfputc(bf, MANGLE_void);
819
	    break ;
864
		break;
820
	}
865
	}
821
 
-
 
822
	case type_bottom_tag : {
866
	case type_bottom_tag: {
823
	    /* Bottom type */
867
		/* Bottom type */
824
	    bfputc ( bf, MANGLE_bottom ) ;
868
		bfputc(bf, MANGLE_bottom);
825
	    break ;
869
		break;
826
	}
870
	}
827
 
-
 
828
	case type_ptr_tag : {
871
	case type_ptr_tag: {
829
	    /* Pointer types */
872
		/* Pointer types */
830
	    bfputc ( bf, MANGLE_ptr ) ;
873
		bfputc(bf, MANGLE_ptr);
831
	    t = DEREF_type ( type_ptr_sub ( t ) ) ;
874
		t = DEREF_type(type_ptr_sub(t));
832
	    mangle_type ( bf, t, 2, 1 ) ;
875
		mangle_type(bf, t, 2, 1);
833
	    break ;
876
		break;
834
	}
877
	}
835
 
-
 
836
	case type_ref_tag : {
878
	case type_ref_tag: {
837
	    /* Reference types */
879
		/* Reference types */
838
	    bfputc ( bf, MANGLE_ref ) ;
880
		bfputc(bf, MANGLE_ref);
839
	    t = DEREF_type ( type_ref_sub ( t ) ) ;
881
		t = DEREF_type(type_ref_sub(t));
840
	    mangle_type ( bf, t, 2, 1 ) ;
882
		mangle_type(bf, t, 2, 1);
841
	    break ;
883
		break;
842
	}
884
	}
843
 
-
 
844
	case type_ptr_mem_tag : {
885
	case type_ptr_mem_tag: {
845
	    /* Pointer to member types */
886
		/* Pointer to member types */
846
	    CLASS_TYPE ct = DEREF_ctype ( type_ptr_mem_of ( t ) ) ;
887
		CLASS_TYPE ct = DEREF_ctype(type_ptr_mem_of(t));
847
	    bfputc ( bf, MANGLE_ptr_mem ) ;
888
		bfputc(bf, MANGLE_ptr_mem);
848
	    mangle_ctype ( bf, ct, -2 ) ;
889
		mangle_ctype(bf, ct, -2);
849
	    t = DEREF_type ( type_ptr_mem_sub ( t ) ) ;
890
		t = DEREF_type(type_ptr_mem_sub(t));
850
	    mangle_type ( bf, t, 2, 1 ) ;
-
 
851
	    break ;
-
 
852
	}
-
 
853
 
-
 
854
	case type_func_tag : {
-
 
855
	    /* Function types */
-
 
856
	    LIST ( TYPE ) p = DEREF_list ( type_func_ptypes ( t ) ) ;
-
 
857
	    int ell = DEREF_int ( type_func_ellipsis ( t ) ) ;
-
 
858
 
-
 
859
	    /* Include any cv-qualifiers */
-
 
860
	    qual = DEREF_cv ( type_func_mqual ( t ) ) ;
-
 
861
	    mangle_cv ( bf, qual ) ;
-
 
862
 
-
 
863
	    /* Include parameter types */
-
 
864
	    if ( fn ) bfputc ( bf, MANGLE_func ) ;
-
 
865
	    if ( IS_NULL_list ( p ) ) {
-
 
866
		if ( fn && !ell ) bfputc ( bf, MANGLE_void ) ;
-
 
867
	    } else {
-
 
868
		LIST ( TYPE ) q = p ;
-
 
869
		unsigned left = LENGTH_list ( q ) ;
-
 
870
		while ( !IS_NULL_list ( q ) ) {
-
 
871
		    int worth = 1 ;
-
 
872
		    unsigned long n = 0 ;
-
 
873
		    TYPE r = DEREF_type ( HEAD_list ( q ) ) ;
-
 
874
		    switch ( TAG_type ( r ) ) {
-
 
875
			case type_integer_tag :
-
 
876
			case type_floating_tag : {
-
 
877
			    /* Only check for long runs */
-
 
878
			    if ( left > MANGLE_WORTH ) {
-
 
879
				worth = 0 ;
-
 
880
				goto default_lab ;
-
 
881
			    }
-
 
882
			    break ;
-
 
883
			}
-
 
884
			case type_top_tag :
-
 
885
			case type_bottom_tag :
-
 
886
			case type_error_tag : {
-
 
887
			    /* Don't bother in these cases */
-
 
888
			    break ;
-
 
889
			}
-
 
890
			default :
-
 
891
			default_lab : {
-
 
892
			    /* Check previous parameter types */
-
 
893
			    unsigned long m = 1 ;
-
 
894
			    LIST ( TYPE ) q1 = p ;
-
 
895
			    while ( !EQ_list ( q1, q ) ) {
-
 
896
				TYPE r1 = DEREF_type ( HEAD_list ( q1 ) ) ;
-
 
897
				if ( eq_type ( r1, r ) ) {
-
 
898
				    /* Match found */
-
 
899
				    n = m ;
-
 
900
				    break ;
-
 
901
				}
-
 
902
				q1 = TAIL_list ( q1 ) ;
-
 
903
				m++ ;
-
 
904
			    }
-
 
905
			    break ;
-
 
906
			}
-
 
907
		    }
-
 
908
		    if ( n ) {
-
 
909
			/* Previous match found */
-
 
910
			TYPE nr ;
-
 
911
			unsigned long m = 0 ;
-
 
912
			do {
-
 
913
			    /* Step over equal parameters */
-
 
914
			    m++ ;
-
 
915
			    left-- ;
-
 
916
			    q = TAIL_list ( q ) ;
-
 
917
			    if ( IS_NULL_list ( q ) ) break ;
-
 
918
			    nr = DEREF_type ( HEAD_list ( q ) ) ;
-
 
919
			} while ( eq_type ( r, nr ) ) ;
-
 
920
			if ( m == 1 ) {
-
 
921
			    /* Single equal parameter */
-
 
922
			    if ( worth ) {
-
 
923
				bfputc ( bf, MANGLE_repeat ) ;
-
 
924
				mangle_number ( bf, n, 2 ) ;
-
 
925
			    } else {
-
 
926
				mangle_type ( bf, r, 2, 1 ) ;
-
 
927
			    }
-
 
928
			} else {
-
 
929
			    /* Multiple equal parameters */
-
 
930
			    if ( worth || m > MANGLE_WORTH ) {
-
 
931
				bfputc ( bf, MANGLE_multi ) ;
-
 
932
				mangle_number ( bf, m, 2 ) ;
-
 
933
				mangle_number ( bf, n, 1 ) ;
-
 
934
			    } else {
-
 
935
				while ( m ) {
-
 
936
				    mangle_type ( bf, r, 2, 1 ) ;
-
 
937
				    m-- ;
-
 
938
				}
-
 
939
			    }
-
 
940
			}
-
 
941
		    } else {
-
 
942
			/* No previous match found */
-
 
943
			mangle_type ( bf, r, 2, 1 ) ;
-
 
944
			left-- ;
-
 
945
			q = TAIL_list ( q ) ;
-
 
946
		    }
-
 
947
		}
-
 
948
	    }
-
 
949
	    if ( ell ) bfputc ( bf, MANGLE_ellipsis ) ;
-
 
950
 
-
 
951
	    /* Include return type if necessary */
-
 
952
	    if ( fn == 2 ) {
-
 
953
		t = DEREF_type ( type_func_ret ( t ) ) ;
-
 
954
		bfputc ( bf, MANGLE_sep ) ;
-
 
955
		mangle_type ( bf, t, 2, 1 ) ;
891
		mangle_type(bf, t, 2, 1);
956
	    }
-
 
957
	    break ;
892
		break;
958
	}
893
	}
-
 
894
	case type_func_tag: {
-
 
895
		/* Function types */
-
 
896
		LIST(TYPE)p = DEREF_list(type_func_ptypes(t));
-
 
897
		int ell = DEREF_int(type_func_ellipsis(t));
959
 
898
 
-
 
899
		/* Include any cv-qualifiers */
-
 
900
		qual = DEREF_cv(type_func_mqual(t));
-
 
901
		mangle_cv(bf, qual);
-
 
902
 
-
 
903
		/* Include parameter types */
-
 
904
		if (fn) {
-
 
905
			bfputc(bf, MANGLE_func);
-
 
906
		}
-
 
907
		if (IS_NULL_list(p)) {
-
 
908
			if (fn && !ell) {
-
 
909
				bfputc(bf, MANGLE_void);
-
 
910
			}
-
 
911
		} else {
-
 
912
			LIST(TYPE)q = p;
-
 
913
			unsigned left = LENGTH_list(q);
-
 
914
			while (!IS_NULL_list(q)) {
-
 
915
				int worth = 1;
-
 
916
				unsigned long n = 0;
-
 
917
				TYPE r = DEREF_type(HEAD_list(q));
-
 
918
				switch (TAG_type(r)) {
-
 
919
				case type_integer_tag:
-
 
920
				case type_floating_tag: {
-
 
921
					/* Only check for long runs */
-
 
922
					if (left > MANGLE_WORTH) {
-
 
923
						worth = 0;
-
 
924
						goto default_lab;
-
 
925
					}
-
 
926
					break;
-
 
927
				}
-
 
928
				case type_top_tag:
-
 
929
				case type_bottom_tag:
960
	case type_array_tag : {
930
				case type_error_tag: {
-
 
931
					/* Don't bother in these cases */
-
 
932
					break;
-
 
933
				}
-
 
934
				default:
-
 
935
default_lab: {
-
 
936
		     /* Check previous parameter types */
-
 
937
		     unsigned long m = 1;
-
 
938
		     LIST(TYPE)q1 = p;
-
 
939
		     while (!EQ_list(q1, q)) {
-
 
940
			     TYPE r1 = DEREF_type(HEAD_list(q1));
-
 
941
			     if (eq_type(r1, r)) {
961
	    /* Array types */
942
				     /* Match found */
-
 
943
				     n = m;
-
 
944
				     break;
-
 
945
			     }
962
	    NAT n = NULL_nat ;
946
			     q1 = TAIL_list(q1);
-
 
947
			     m++;
-
 
948
		     }
-
 
949
		     break;
-
 
950
	     }
-
 
951
				}
-
 
952
				if (n) {
-
 
953
					/* Previous match found */
-
 
954
					TYPE nr;
-
 
955
					unsigned long m = 0;
-
 
956
					do {
-
 
957
						/* Step over equal parameters */
-
 
958
						m++;
-
 
959
						left--;
-
 
960
						q = TAIL_list(q);
-
 
961
						if (IS_NULL_list(q)) {
-
 
962
							break;
-
 
963
						}
963
	    if ( arr ) n = DEREF_nat ( type_array_size ( t ) ) ;
964
						nr = DEREF_type(HEAD_list(q));
-
 
965
					} while (eq_type(r, nr));
-
 
966
					if (m == 1) {
-
 
967
						/* Single equal parameter */
-
 
968
						if (worth) {
-
 
969
							bfputc(bf,
964
	    bfputc ( bf, MANGLE_array ) ;
970
							       MANGLE_repeat);
-
 
971
							mangle_number(bf, n, 2);
-
 
972
						} else {
-
 
973
							mangle_type(bf, r, 2,
-
 
974
								    1);
-
 
975
						}
-
 
976
					} else {
-
 
977
						/* Multiple equal parameters */
-
 
978
						if (worth || m > MANGLE_WORTH) {
-
 
979
							bfputc(bf,
-
 
980
							       MANGLE_multi);
-
 
981
							mangle_number(bf, m, 2);
965
	    mangle_nat ( bf, n, 1 ) ;
982
							mangle_number(bf, n, 1);
-
 
983
						} else {
-
 
984
							while (m) {
966
	    t = DEREF_type ( type_array_sub ( t ) ) ;
985
								mangle_type(bf, r, 2, 1);
-
 
986
								m--;
-
 
987
							}
-
 
988
						}
-
 
989
					}
-
 
990
				} else {
-
 
991
					/* No previous match found */
967
	    mangle_type ( bf, t, 2, 1 ) ;
992
					mangle_type(bf, r, 2, 1);
-
 
993
					left--;
-
 
994
					q = TAIL_list(q);
-
 
995
				}
-
 
996
			}
-
 
997
		}
968
	    break ;
998
		if (ell) {
-
 
999
			bfputc(bf, MANGLE_ellipsis);
969
	}
1000
		}
970
 
1001
 
971
	case type_bitfield_tag : {
1002
		/* Include return type if necessary */
972
	    /* Bitfield types */
1003
		if (fn == 2) {
973
	    INT_TYPE it = DEREF_itype ( type_bitfield_defn ( t ) ) ;
1004
			t = DEREF_type(type_func_ret(t));
-
 
1005
			bfputc(bf, MANGLE_sep);
974
	    mangle_itype ( bf, it ) ;
1006
			mangle_type(bf, t, 2, 1);
-
 
1007
		}
975
	    break ;
1008
		break;
976
	}
1009
	}
-
 
1010
	case type_array_tag: {
-
 
1011
		/* Array types */
-
 
1012
		NAT n = NULL_nat;
-
 
1013
		if (arr) {
-
 
1014
			n = DEREF_nat(type_array_size(t));
-
 
1015
		}
-
 
1016
		bfputc(bf, MANGLE_array);
-
 
1017
		mangle_nat(bf, n, 1);
-
 
1018
		t = DEREF_type(type_array_sub(t));
-
 
1019
		mangle_type(bf, t, 2, 1);
-
 
1020
		break;
977
 
1021
	}
978
	case type_compound_tag : {
1022
	case type_bitfield_tag: {
979
	    /* Class types */
1023
		/* Bitfield types */
980
	    CLASS_TYPE ct = DEREF_ctype ( type_compound_defn ( t ) ) ;
1024
		INT_TYPE it = DEREF_itype(type_bitfield_defn(t));
981
	    mangle_ctype ( bf, ct, -2 ) ;
1025
		mangle_itype(bf, it);
982
	    break ;
1026
		break;
983
	}
1027
	}
-
 
1028
	case type_compound_tag: {
-
 
1029
		/* Class types */
-
 
1030
		CLASS_TYPE ct = DEREF_ctype(type_compound_defn(t));
-
 
1031
		mangle_ctype(bf, ct, -2);
-
 
1032
		break;
984
 
1033
	}
985
	case type_enumerate_tag : {
1034
	case type_enumerate_tag: {
986
	    /* Enumeration types */
1035
		/* Enumeration types */
987
	    ENUM_TYPE et = DEREF_etype ( type_enumerate_defn ( t ) ) ;
1036
		ENUM_TYPE et = DEREF_etype(type_enumerate_defn(t));
988
#if LANGUAGE_C
1037
#if LANGUAGE_C
989
	    t = DEREF_type ( etype_rep ( et ) ) ;
1038
		t = DEREF_type(etype_rep(et));
990
	    mangle_type ( bf, t, fn, arr ) ;
1039
		mangle_type(bf, t, fn, arr);
991
#else
1040
#else
992
	    IDENTIFIER eid = DEREF_id ( etype_name ( et ) ) ;
1041
		IDENTIFIER eid = DEREF_id(etype_name(et));
993
	    int d = ident_depth ( eid ) ;
1042
		int d = ident_depth(eid);
994
	    mangle_id ( bf, eid, d ) ;
1043
		mangle_id(bf, eid, d);
995
#endif
1044
#endif
996
	    break ;
1045
		break;
997
	}
1046
	}
998
 
-
 
999
	case type_token_tag : {
1047
	case type_token_tag: {
1000
	    /* Tokenised types */
1048
		/* Tokenised types */
1001
	    IDENTIFIER id = DEREF_id ( type_token_tok ( t ) ) ;
1049
		IDENTIFIER id = DEREF_id(type_token_tok(t));
1002
	    LIST ( TOKEN ) args = DEREF_list ( type_token_args ( t ) ) ;
1050
		LIST(TOKEN)args = DEREF_list(type_token_args(t));
1003
	    mangle_token ( bf, id, args, -2, 0 ) ;
1051
		mangle_token(bf, id, args, -2, 0);
-
 
1052
		break;
-
 
1053
	}
-
 
1054
	case type_templ_tag: {
-
 
1055
		/* Template types */
-
 
1056
		t = DEREF_type(type_templ_defn(t));
-
 
1057
		mangle_type(bf, t, fn, arr);
1004
	    break ;
1058
		break;
1005
	}
1059
	}
1006
 
-
 
1007
	case type_templ_tag : {
1060
	default: {
1008
	    /* Template types */
1061
		/* Illegal types */
1009
	    t = DEREF_type ( type_templ_defn ( t ) ) ;
-
 
1010
	    mangle_type ( bf, t, fn, arr ) ;
1062
		bfputc(bf, MANGLE_error);
1011
	    break ;
1063
		break;
1012
	}
1064
	}
1013
 
-
 
1014
	default : {
-
 
1015
	    /* Illegal types */
-
 
1016
	    bfputc ( bf, MANGLE_error ) ;
-
 
1017
	    break ;
-
 
1018
	}
1065
	}
1019
    }
-
 
1020
    return ;
1066
	return;
1021
}
1067
}
1022
 
1068
 
1023
 
1069
 
1024
/*
1070
/*
1025
    ADD A CLASS NAME TO THE BUFFER
1071
    ADD A CLASS NAME TO THE BUFFER
1026
 
1072
 
1027
    This routine adds the mangled form of the class type ct to the
1073
    This routine adds the mangled form of the class type ct to the
1028
    buffer position given by bf.
1074
    buffer position given by bf.
1029
*/
1075
*/
1030
 
1076
 
1031
static void mangle_ctype
1077
static void
1032
    PROTO_N ( ( bf, ct, d ) )
-
 
1033
    PROTO_T ( BUFFER *bf X CLASS_TYPE ct X int d )
1078
mangle_ctype(BUFFER *bf, CLASS_TYPE ct, int d)
1034
{
1079
{
1035
    CLASS_TYPE cs = crt_mangle_class ;
1080
	CLASS_TYPE cs = crt_mangle_class;
1036
    if ( !IS_NULL_ctype ( cs ) && eq_ctype ( ct, cs ) ) {
1081
	if (!IS_NULL_ctype(cs) && eq_ctype(ct, cs)) {
1037
	bfputc ( bf, MANGLE_self ) ;
1082
		bfputc(bf, MANGLE_self);
1038
    } else {
-
 
1039
	TYPE t = DEREF_type ( ctype_form ( ct ) ) ;
-
 
1040
	if ( !IS_NULL_type ( t ) && IS_type_token ( t ) ) {
-
 
1041
	    IDENTIFIER tid = DEREF_id ( type_token_tok ( t ) ) ;
-
 
1042
	    LIST ( TOKEN ) args = DEREF_list ( type_token_args ( t ) ) ;
-
 
1043
	    mangle_token ( bf, tid, args, d, 0 ) ;
-
 
1044
	} else {
1083
	} else {
-
 
1084
		TYPE t = DEREF_type(ctype_form(ct));
-
 
1085
		if (!IS_NULL_type(t) && IS_type_token(t)) {
-
 
1086
			IDENTIFIER tid = DEREF_id(type_token_tok(t));
-
 
1087
			LIST(TOKEN)args = DEREF_list(type_token_args(t));
-
 
1088
			mangle_token(bf, tid, args, d, 0);
-
 
1089
		} else {
1045
	    IDENTIFIER cid = DEREF_id ( ctype_name ( ct ) ) ;
1090
			IDENTIFIER cid = DEREF_id(ctype_name(ct));
-
 
1091
			if (d == -2) {
1046
	    if ( d == -2 ) d = ident_depth ( cid ) ;
1092
				d = ident_depth(cid);
-
 
1093
			}
1047
	    mangle_id ( bf, cid, d ) ;
1094
			mangle_id(bf, cid, d);
-
 
1095
		}
1048
	}
1096
	}
1049
    }
-
 
1050
    return ;
1097
	return;
1051
}
1098
}
1052
 
1099
 
1053
 
1100
 
1054
/*
1101
/*
1055
    ADD A BASE CLASS GRAPH TO THE BUFFER
1102
    ADD A BASE CLASS GRAPH TO THE BUFFER
1056
 
1103
 
1057
    This routine adds the mangled form of the base class graph gr to the
1104
    This routine adds the mangled form of the base class graph gr to the
1058
    buffer bf.  first is true for the top node.
1105
    buffer bf.  first is true for the top node.
1059
*/
1106
*/
1060
 
1107
 
1061
static void mangle_graph
1108
static void
1062
    PROTO_N ( ( bf, gr ) )
-
 
1063
    PROTO_T ( BUFFER *bf X GRAPH gr )
1109
mangle_graph(BUFFER *bf, GRAPH gr)
1064
{
1110
{
1065
    int d = -2 ;
1111
	int d = -2;
1066
    GRAPH gu = DEREF_graph ( graph_up ( gr ) ) ;
1112
	GRAPH gu = DEREF_graph(graph_up(gr));
1067
    CLASS_TYPE ct = DEREF_ctype ( graph_head ( gr ) ) ;
1113
	CLASS_TYPE ct = DEREF_ctype(graph_head(gr));
1068
    if ( !IS_NULL_graph ( gu ) ) {
1114
	if (!IS_NULL_graph(gu)) {
1069
	mangle_graph ( bf, gu ) ;
1115
		mangle_graph(bf, gu);
1070
	d = 1 ;
1116
		d = 1;
1071
    }
1117
	}
1072
    mangle_ctype ( bf, ct, d ) ;
1118
	mangle_ctype(bf, ct, d);
1073
    return ;
1119
	return;
1074
}
1120
}
1075
 
1121
 
1076
 
1122
 
1077
/*
1123
/*
1078
    ADD A TOKEN ARGUMENT TO THE BUFFER
1124
    ADD A TOKEN ARGUMENT TO THE BUFFER
1079
 
1125
 
1080
    This routine adds the mangled form of the token argument tok to the
1126
    This routine adds the mangled form of the token argument tok to the
1081
    buffer position given by bf.
1127
    buffer position given by bf.
1082
*/
1128
*/
1083
 
1129
 
1084
static void mangle_token_arg
1130
static void
1085
    PROTO_N ( ( bf, tok ) )
-
 
1086
    PROTO_T ( BUFFER *bf X TOKEN tok )
1131
mangle_token_arg(BUFFER *bf, TOKEN tok)
1087
{
1132
{
1088
    if ( !IS_NULL_tok ( tok ) ) {
1133
	if (!IS_NULL_tok(tok)) {
1089
	switch ( TAG_tok ( tok ) ) {
1134
		switch (TAG_tok(tok)) {
1090
	    case tok_exp_tag : {
1135
		case tok_exp_tag: {
1091
		EXP e = DEREF_exp ( tok_exp_value ( tok ) ) ;
1136
			EXP e = DEREF_exp(tok_exp_value(tok));
1092
		TYPE t = DEREF_type ( tok_exp_type ( tok ) ) ;
1137
			TYPE t = DEREF_type(tok_exp_type(tok));
1093
		mangle_type ( bf, t, 2, 1 ) ;
1138
			mangle_type(bf, t, 2, 1);
1094
		mangle_exp ( bf, e, 1 ) ;
1139
			mangle_exp(bf, e, 1);
1095
		break ;
1140
			break;
1096
	    }
1141
		}
1097
	    case tok_stmt_tag : {
1142
		case tok_stmt_tag: {
1098
		EXP e = DEREF_exp ( tok_stmt_value ( tok ) ) ;
1143
			EXP e = DEREF_exp(tok_stmt_value(tok));
1099
		bfputc ( bf, MANGLE_stmt ) ;
1144
			bfputc(bf, MANGLE_stmt);
1100
		mangle_exp ( bf, e, 1 ) ;
1145
			mangle_exp(bf, e, 1);
1101
		break ;
1146
			break;
1102
	    }
1147
		}
1103
	    case tok_nat_tag : {
1148
		case tok_nat_tag: {
1104
		NAT n = DEREF_nat ( tok_nat_value ( tok ) ) ;
1149
			NAT n = DEREF_nat(tok_nat_value(tok));
1105
		bfputc ( bf, MANGLE_nat ) ;
1150
			bfputc(bf, MANGLE_nat);
1106
		mangle_nat ( bf, n, 1 ) ;
1151
			mangle_nat(bf, n, 1);
1107
		break ;
1152
			break;
1108
	    }
1153
		}
1109
	    case tok_snat_tag : {
1154
		case tok_snat_tag: {
1110
		NAT n = DEREF_nat ( tok_snat_value ( tok ) ) ;
1155
			NAT n = DEREF_nat(tok_snat_value(tok));
1111
		bfputc ( bf, MANGLE_nat ) ;
1156
			bfputc(bf, MANGLE_nat);
1112
		mangle_nat ( bf, n, 1 ) ;
1157
			mangle_nat(bf, n, 1);
1113
		break ;
1158
			break;
1114
	    }
1159
		}
1115
	    case tok_type_tag : {
1160
		case tok_type_tag: {
1116
		TYPE t = DEREF_type ( tok_type_value ( tok ) ) ;
1161
			TYPE t = DEREF_type(tok_type_value(tok));
1117
		bfputc ( bf, MANGLE_type ) ;
1162
			bfputc(bf, MANGLE_type);
1118
		mangle_type ( bf, t, 2, 1 ) ;
1163
			mangle_type(bf, t, 2, 1);
1119
		break ;
1164
			break;
1120
	    }
1165
		}
1121
	    case tok_class_tag : {
1166
		case tok_class_tag: {
1122
		IDENTIFIER id = DEREF_id ( tok_class_value ( tok ) ) ;
1167
			IDENTIFIER id = DEREF_id(tok_class_value(tok));
1123
		int d = ident_depth ( id ) ;
1168
			int d = ident_depth(id);
1124
		bfputc ( bf, MANGLE_type ) ;
1169
			bfputc(bf, MANGLE_type);
1125
		mangle_id ( bf, id, d ) ;
1170
			mangle_id(bf, id, d);
1126
		break ;
1171
			break;
1127
	    }
1172
		}
1128
	    default : {
1173
		default: {
1129
		/* NOT YET IMPLEMENTED */
1174
			/* NOT YET IMPLEMENTED */
1130
		bfputc ( bf, MANGLE_error ) ;
1175
			bfputc(bf, MANGLE_error);
1131
		break ;
1176
			break;
-
 
1177
		}
1132
	    }
1178
		}
1133
	}
1179
	}
1134
    }
-
 
1135
    return ;
1180
	return;
1136
}
1181
}
1137
 
1182
 
1138
 
1183
 
1139
/*
1184
/*
1140
    ADD A LIST OF TOKEN ARGUMENT TO THE BUFFER
1185
    ADD A LIST OF TOKEN ARGUMENT TO THE BUFFER
1141
 
1186
 
1142
    This routine adds the mangled form of the token arguments args to the
1187
    This routine adds the mangled form of the token arguments args to the
1143
    buffer position given by bf.
1188
    buffer position given by bf.
1144
*/
1189
*/
1145
 
1190
 
1146
static void mangle_token_args
1191
static void
1147
    PROTO_N ( ( bf, args ) )
-
 
1148
    PROTO_T ( BUFFER *bf X LIST ( TOKEN ) args )
1192
mangle_token_args(BUFFER *bf, LIST(TOKEN)args)
1149
{
1193
{
1150
    unsigned m = LENGTH_list ( args ) ;
1194
	unsigned m = LENGTH_list(args);
1151
    mangle_number ( bf, ( unsigned long ) m, 2 ) ;
1195
	mangle_number(bf,(unsigned long)m, 2);
1152
    while ( !IS_NULL_list ( args ) ) {
1196
	while (!IS_NULL_list(args)) {
1153
	TOKEN tok = DEREF_tok ( HEAD_list ( args ) ) ;
1197
		TOKEN tok = DEREF_tok(HEAD_list(args));
1154
	mangle_token_arg ( bf, tok ) ;
1198
		mangle_token_arg(bf, tok);
1155
	args = TAIL_list ( args ) ;
1199
		args = TAIL_list(args);
1156
    }
1200
	}
1157
    return ;
1201
	return;
1158
}
1202
}
1159
 
1203
 
1160
 
1204
 
1161
/*
1205
/*
1162
    ADD A TOKEN APPLICATION TO THE BUFFER
1206
    ADD A TOKEN APPLICATION TO THE BUFFER
1163
 
1207
 
1164
    This routine adds the token application 'id ( args )' to the buffer
1208
    This routine adds the token application 'id ( args )' to the buffer
1165
    position given by bf.
1209
    position given by bf.
1166
*/
1210
*/
1167
 
1211
 
1168
static void mangle_token
1212
static void
1169
    PROTO_N ( ( bf, id, args, d, force ) )
-
 
1170
    PROTO_T ( BUFFER *bf X IDENTIFIER id X LIST ( TOKEN ) args X
1213
mangle_token(BUFFER *bf, IDENTIFIER id, LIST(TOKEN)args, int d, int force)
1171
	      int d X int force )
-
 
1172
{
1214
{
1173
    IDENTIFIER alt ;
1215
	IDENTIFIER alt;
1174
    DECL_SPEC ds = DEREF_dspec ( id_storage ( id ) ) ;
1216
	DECL_SPEC ds = DEREF_dspec(id_storage(id));
1175
    if ( IS_id_token ( id ) ) {
1217
	if (IS_id_token(id)) {
1176
	if ( !IS_NULL_list ( args ) ) force = 1 ;
1218
		if (!IS_NULL_list(args)) {
-
 
1219
			force = 1;
-
 
1220
		}
1177
	alt = DEREF_id ( id_token_alt ( id ) ) ;
1221
		alt = DEREF_id(id_token_alt(id));
1178
    } else {
1222
	} else {
1179
	force = 1 ;
1223
		force = 1;
1180
	alt = id ;
1224
		alt = id;
1181
    }
1225
	}
1182
    if ( d == -2 ) {
1226
	if (d == -2) {
1183
	if ( ds & dspec_auto ) {
1227
		if (ds & dspec_auto) {
1184
	    /* Template parameter */
1228
			/* Template parameter */
1185
	    ulong n = DEREF_ulong ( id_no ( id ) ) ;
1229
			ulong n = DEREF_ulong(id_no(id));
1186
	    if ( ds & dspec_register ) {
1230
			if (ds & dspec_register) {
1187
		/* This shouldn't happen */
1231
				/* This shouldn't happen */
1188
		n = 0 ;
1232
				n = 0;
1189
	    }
1233
			}
1190
	    if ( ds & dspec_template ) {
1234
			if (ds & dspec_template) {
1191
		/* Template template parameter */
1235
				/* Template template parameter */
1192
		if ( !IS_NULL_list ( args ) ) {
1236
				if (!IS_NULL_list(args)) {
1193
		    bfputc ( bf, MANGLE_template ) ;
1237
					bfputc(bf, MANGLE_template);
1194
		    bfputc ( bf, MANGLE_templ_param ) ;
1238
					bfputc(bf, MANGLE_templ_param);
1195
		    mangle_number ( bf, n, 2 ) ;
1239
					mangle_number(bf, n, 2);
1196
		    mangle_token_args ( bf, args ) ;
1240
					mangle_token_args(bf, args);
1197
		    return ;
1241
					return;
1198
		}
1242
				}
1199
	    }
1243
			}
1200
	    bfputc ( bf, MANGLE_templ_param ) ;
1244
			bfputc(bf, MANGLE_templ_param);
1201
	    mangle_number ( bf, n, 2 ) ;
1245
			mangle_number(bf, n, 2);
1202
	    return ;
1246
			return;
1203
	}
1247
		}
1204
	d = ident_depth ( alt ) ;
1248
		d = ident_depth(alt);
1205
    }
1249
	}
-
 
1250
	if (force) {
1206
    if ( force ) bfputc ( bf, MANGLE_template ) ;
1251
		bfputc(bf, MANGLE_template);
-
 
1252
	}
1207
    mangle_id ( bf, alt, d ) ;
1253
	mangle_id(bf, alt, d);
1208
    if ( !IS_NULL_list ( args ) ) {
1254
	if (!IS_NULL_list(args)) {
1209
	/* Token arguments */
1255
		/* Token arguments */
1210
	mangle_token_args ( bf, args ) ;
1256
		mangle_token_args(bf, args);
1211
    }
1257
	}
1212
    return ;
1258
	return;
1213
}
1259
}
1214
 
1260
 
1215
 
1261
 
1216
/*
1262
/*
1217
    FIND A MANGLED OPERATOR NAME
1263
    FIND A MANGLED OPERATOR NAME
1218
 
1264
 
1219
    This routine finds the mangled function name for 'operator op'.  Note
1265
    This routine finds the mangled function name for 'operator op'.  Note
1220
    that op will always be in its primary form.
1266
    that op will always be in its primary form.
1221
*/
1267
*/
1222
 
1268
 
1223
static string mangle_op
1269
static string
1224
    PROTO_N ( ( op ) )
-
 
1225
    PROTO_T ( int op )
1270
mangle_op(int op)
1226
{
1271
{
1227
    CONST char *s ;
1272
	CONST char *s;
1228
    switch ( op ) {
1273
	switch (op) {
1229
	/* Standard operator names */
1274
		/* Standard operator names */
1230
	case lex_abs : s = "__ab" ; break ;
1275
	case lex_abs:
-
 
1276
		s = "__ab";
-
 
1277
		break;
1231
	case lex_and_H1 : s = "__ad" ; break ;
1278
	case lex_and_H1:
-
 
1279
		s = "__ad";
-
 
1280
		break;
1232
	case lex_and_Heq_H1 : s = "__aad" ; break ;
1281
	case lex_and_Heq_H1:
-
 
1282
		s = "__aad";
-
 
1283
		break;
1233
	case lex_array_Hop : s = "__vc" ; break ;
1284
	case lex_array_Hop:
-
 
1285
		s = "__vc";
-
 
1286
		break;
1234
	case lex_arrow : s = "__rf" ; break ;
1287
	case lex_arrow:
-
 
1288
		s = "__rf";
-
 
1289
		break;
1235
	case lex_arrow_Hstar : s = "__rm" ; break ;
1290
	case lex_arrow_Hstar:
-
 
1291
		s = "__rm";
-
 
1292
		break;
1236
	case lex_assign : s = "__as" ; break ;
1293
	case lex_assign:
-
 
1294
		s = "__as";
-
 
1295
		break;
1237
	case lex_comma : s = "__cm" ; break ;
1296
	case lex_comma:
-
 
1297
		s = "__cm";
-
 
1298
		break;
1238
	case lex_compl_H1 : s = "__co" ; break ;
1299
	case lex_compl_H1:
-
 
1300
		s = "__co";
-
 
1301
		break;
1239
	case lex_delete : s = "__dl" ; break ;
1302
	case lex_delete:
-
 
1303
		s = "__dl";
-
 
1304
		break;
1240
	case lex_delete_Harray : s = "__vd" ; break ;
1305
	case lex_delete_Harray:
-
 
1306
		s = "__vd";
-
 
1307
		break;
1241
	case lex_div : s = "__dv" ; break ;
1308
	case lex_div:
-
 
1309
		s = "__dv";
-
 
1310
		break;
1242
	case lex_div_Heq : s = "__adv" ; break ;
1311
	case lex_div_Heq:
-
 
1312
		s = "__adv";
-
 
1313
		break;
1243
	case lex_eq : s = "__eq" ; break ;
1314
	case lex_eq:
-
 
1315
		s = "__eq";
-
 
1316
		break;
1244
	case lex_func_Hop : s = "__cl" ; break ;
1317
	case lex_func_Hop:
-
 
1318
		s = "__cl";
-
 
1319
		break;
1245
	case lex_greater : s = "__gt" ; break ;
1320
	case lex_greater:
-
 
1321
		s = "__gt";
-
 
1322
		break;
1246
	case lex_greater_Heq : s = "__ge" ; break ;
1323
	case lex_greater_Heq:
-
 
1324
		s = "__ge";
-
 
1325
		break;
1247
	case lex_less : s = "__lt" ; break ;
1326
	case lex_less:
-
 
1327
		s = "__lt";
-
 
1328
		break;
1248
	case lex_less_Heq : s = "__le" ; break ;
1329
	case lex_less_Heq:
-
 
1330
		s = "__le";
-
 
1331
		break;
1249
	case lex_logical_Hand_H1 : s = "__aa" ; break ;
1332
	case lex_logical_Hand_H1:
-
 
1333
		s = "__aa";
-
 
1334
		break;
1250
	case lex_logical_Hor_H1 : s = "__oo" ; break ;
1335
	case lex_logical_Hor_H1:
-
 
1336
		s = "__oo";
-
 
1337
		break;
1251
	case lex_lshift : s = "__ls" ; break ;
1338
	case lex_lshift:
-
 
1339
		s = "__ls";
-
 
1340
		break;
1252
	case lex_lshift_Heq : s = "__als" ; break ;
1341
	case lex_lshift_Heq:
-
 
1342
		s = "__als";
-
 
1343
		break;
1253
	case lex_max : s = "__mx" ; break ;
1344
	case lex_max:
-
 
1345
		s = "__mx";
-
 
1346
		break;
1254
	case lex_min : s = "__mn" ; break ;
1347
	case lex_min:
-
 
1348
		s = "__mn";
-
 
1349
		break;
1255
	case lex_minus : s = "__mi" ; break ;
1350
	case lex_minus:
-
 
1351
		s = "__mi";
-
 
1352
		break;
1256
	case lex_minus_Heq : s = "__ami" ; break ;
1353
	case lex_minus_Heq:
-
 
1354
		s = "__ami";
-
 
1355
		break;
1257
	case lex_minus_Hminus : s = "__mm" ; break ;
1356
	case lex_minus_Hminus:
-
 
1357
		s = "__mm";
-
 
1358
		break;
1258
	case lex_new : s = "__nw" ; break ;
1359
	case lex_new:
-
 
1360
		s = "__nw";
-
 
1361
		break;
1259
	case lex_new_Harray : s = "__vn" ; break ;
1362
	case lex_new_Harray:
-
 
1363
		s = "__vn";
-
 
1364
		break;
1260
	case lex_not_H1 : s = "__nt" ; break ;
1365
	case lex_not_H1:
-
 
1366
		s = "__nt";
-
 
1367
		break;
1261
	case lex_not_Heq_H1 : s = "__ne" ; break ;
1368
	case lex_not_Heq_H1:
-
 
1369
		s = "__ne";
-
 
1370
		break;
1262
	case lex_or_H1 : s = "__or" ; break ;
1371
	case lex_or_H1:
-
 
1372
		s = "__or";
-
 
1373
		break;
1263
	case lex_or_Heq_H1 : s = "__aor" ; break ;
1374
	case lex_or_Heq_H1:
-
 
1375
		s = "__aor";
-
 
1376
		break;
1264
	case lex_plus : s = "__pl" ; break ;
1377
	case lex_plus:
-
 
1378
		s = "__pl";
-
 
1379
		break;
1265
	case lex_plus_Heq : s = "__apl" ; break ;
1380
	case lex_plus_Heq:
-
 
1381
		s = "__apl";
-
 
1382
		break;
1266
	case lex_plus_Hplus : s = "__pp" ; break ;
1383
	case lex_plus_Hplus:
-
 
1384
		s = "__pp";
-
 
1385
		break;
1267
	case lex_rem : s = "__md" ; break ;
1386
	case lex_rem:
-
 
1387
		s = "__md";
-
 
1388
		break;
1268
	case lex_rem_Heq : s = "__amd" ; break ;
1389
	case lex_rem_Heq:
-
 
1390
		s = "__amd";
-
 
1391
		break;
1269
	case lex_rshift : s = "__rs" ; break ;
1392
	case lex_rshift:
-
 
1393
		s = "__rs";
-
 
1394
		break;
1270
	case lex_rshift_Heq : s = "__ars" ; break ;
1395
	case lex_rshift_Heq:
-
 
1396
		s = "__ars";
-
 
1397
		break;
1271
	case lex_star : s = "__ml" ; break ;
1398
	case lex_star:
-
 
1399
		s = "__ml";
-
 
1400
		break;
1272
	case lex_star_Heq : s = "__aml" ; break ;
1401
	case lex_star_Heq:
-
 
1402
		s = "__aml";
-
 
1403
		break;
1273
	case lex_xor_H1 : s = "__er" ; break ;
1404
	case lex_xor_H1:
-
 
1405
		s = "__er";
-
 
1406
		break;
1274
	case lex_xor_Heq_H1 : s = "__aer" ; break ;
1407
	case lex_xor_Heq_H1:
-
 
1408
		s = "__aer";
-
 
1409
		break;
1275
 
1410
 
1276
	/* Invalid operator names */
1411
	/* Invalid operator names */
1277
	case lex_cond_Hop : s = "__cn" ; break ;
1412
	case lex_cond_Hop:
-
 
1413
		s = "__cn";
-
 
1414
		break;
1278
	case lex_colon : s = "__cs" ; break ;
1415
	case lex_colon:
-
 
1416
		s = "__cs";
-
 
1417
		break;
1279
	case lex_colon_Hcolon : s = "__cc" ; break ;
1418
	case lex_colon_Hcolon:
-
 
1419
		s = "__cc";
-
 
1420
		break;
1280
	case lex_dot : s = "__df" ; break ;
1421
	case lex_dot:
-
 
1422
		s = "__df";
-
 
1423
		break;
1281
	case lex_dot_Hstar : s = "__dm" ; break ;
1424
	case lex_dot_Hstar:
-
 
1425
		s = "__dm";
-
 
1426
		break;
1282
	case lex_sizeof : s = "__sz" ; break ;
1427
	case lex_sizeof:
-
 
1428
		s = "__sz";
-
 
1429
		break;
1283
	case lex_typeid : s = "__td" ; break ;
1430
	case lex_typeid:
-
 
1431
		s = "__td";
-
 
1432
		break;
1284
	case lex_vtable : s = "__tb" ; break ;
1433
	case lex_vtable:
-
 
1434
		s = "__tb";
-
 
1435
		break;
-
 
1436
	default:
1285
	default : s = mangle_ntype [0] ; break ;
1437
		s = mangle_ntype[0];
-
 
1438
		break;
1286
    }
1439
	}
1287
    return ( ustrlit ( s ) ) ;
1440
	return (ustrlit(s));
1288
}
1441
}
1289
 
1442
 
1290
 
1443
 
1291
/*
1444
/*
1292
    MANGLE AN EXTENDED NAME
1445
    MANGLE AN EXTENDED NAME
1293
 
1446
 
1294
    This routine mangles the extended identifier name s into the buffer
1447
    This routine mangles the extended identifier name s into the buffer
1295
    bf.  It returns true if the result differs from s.
1448
    bf.  It returns true if the result differs from s.
1296
*/
1449
*/
1297
 
1450
 
1298
static int mangle_ename
1451
static int
1299
    PROTO_N ( ( bf, s ) )
-
 
1300
    PROTO_T ( BUFFER *bf X string s )
1452
mangle_ename(BUFFER *bf, string s)
1301
{
1453
{
1302
    int u = 0 ;
1454
	int u = 0;
1303
    character c ;
1455
	character c;
1304
    while ( c = *( s++ ), c != 0 ) {
1456
	while (c = *(s++), c != 0) {
1305
	if ( c == char_backslash ) {
1457
		if (c == char_backslash) {
1306
	    c = *( s++ ) ;
1458
			c = *(s++);
1307
	    bfputc ( bf, MANGLE_sep ) ;
1459
			bfputc(bf, MANGLE_sep);
1308
	    bfputc ( bf, MANGLE_sep ) ;
1460
			bfputc(bf, MANGLE_sep);
1309
	    if ( c == char_U ) {
1461
			if (c == char_U) {
1310
		bfputc ( bf, MANGLE_unicode8 ) ;
1462
				bfputc(bf, MANGLE_unicode8);
1311
	    } else {
1463
			} else {
1312
		bfputc ( bf, MANGLE_unicode4 ) ;
1464
				bfputc(bf, MANGLE_unicode4);
1313
	    }
1465
			}
1314
	    u = 1 ;
1466
			u = 1;
1315
	    if ( c == 0 ) break ;
1467
			if (c == 0) {
-
 
1468
				break;
-
 
1469
			}
1316
	} else {
1470
		} else {
1317
	    bfputc ( bf, ( int ) c ) ;
1471
			bfputc(bf,(int)c);
-
 
1472
		}
1318
	}
1473
	}
1319
    }
-
 
1320
    return ( u ) ;
1474
	return (u);
1321
}
1475
}
1322
 
1476
 
1323
 
1477
 
1324
/*
1478
/*
1325
    FIND A MANGLED NAME
1479
    FIND A MANGLED NAME
1326
 
1480
 
1327
    This routine returns the mangled form of the identifier name nm.
1481
    This routine returns the mangled form of the identifier name nm.
1328
    For conversion functions and extended names the name is built into
1482
    For conversion functions and extended names the name is built into
1329
    name_buff and pcopy is set to true.
1483
    name_buff and pcopy is set to true.
1330
*/
1484
*/
1331
 
1485
 
1332
static string mangle_hashid
1486
static string
1333
    PROTO_N ( ( nm, pcopy, force ) )
-
 
1334
    PROTO_T ( HASHID nm X int *pcopy X int force )
1487
mangle_hashid(HASHID nm, int *pcopy, int force)
1335
{
1488
{
1336
    string s = NULL ;
1489
	string s = NULL;
1337
    switch ( TAG_hashid ( nm ) ) {
1490
	switch (TAG_hashid(nm)) {
1338
	case hashid_name_tag : {
1491
	case hashid_name_tag: {
1339
	    /* Simple identifiers */
1492
		/* Simple identifiers */
1340
	    s = DEREF_string ( hashid_name_text ( nm ) ) ;
1493
		s = DEREF_string(hashid_name_text(nm));
1341
	    break ;
1494
		break;
1342
	}
1495
	}
1343
	case hashid_ename_tag : {
1496
	case hashid_ename_tag: {
1344
	    /* Extended identifiers */
1497
		/* Extended identifiers */
1345
	    BUFFER *bf = &name_buff ;
1498
		BUFFER *bf = &name_buff;
1346
	    unsigned n = ( unsigned ) ( bf->posn - bf->start ) ;
1499
		unsigned n = (unsigned)(bf->posn - bf->start);
1347
	    s = DEREF_string ( hashid_ename_text ( nm ) ) ;
1500
		s = DEREF_string(hashid_ename_text(nm));
1348
	    if ( mangle_ename ( bf, s ) ) {
1501
		if (mangle_ename(bf, s)) {
1349
		bfputc ( bf, 0 ) ;
1502
			bfputc(bf, 0);
1350
		s = bf->start + n ;
1503
			s = bf->start + n;
1351
		*pcopy = 1 ;
1504
			*pcopy = 1;
1352
	    }
1505
		}
1353
	    break ;
1506
		break;
1354
	}
1507
	}
1355
	case hashid_constr_tag : {
1508
	case hashid_constr_tag: {
1356
	    /* Constructor names */
1509
		/* Constructor names */
1357
	    s = ustrlit ( "__ct" ) ;
1510
		s = ustrlit("__ct");
1358
	    break ;
1511
		break;
1359
	}
1512
	}
1360
	case hashid_destr_tag : {
1513
	case hashid_destr_tag: {
1361
	    /* Destructor names */
1514
		/* Destructor names */
1362
	    s = ustrlit ( "__dt" ) ;
1515
		s = ustrlit("__dt");
1363
	    break ;
1516
		break;
1364
	}
1517
	}
1365
	case hashid_conv_tag : {
1518
	case hashid_conv_tag: {
1366
	    /* Conversion names */
1519
		/* Conversion names */
1367
	    BUFFER *bf = &name_buff ;
1520
		BUFFER *bf = &name_buff;
1368
	    unsigned n = ( unsigned ) ( bf->posn - bf->start ) ;
1521
		unsigned n = (unsigned)(bf->posn - bf->start);
1369
	    TYPE t = DEREF_type ( hashid_conv_type ( nm ) ) ;
1522
		TYPE t = DEREF_type(hashid_conv_type(nm));
1370
	    bfprintf ( bf, "__op" ) ;
1523
		bfprintf(bf, "__op");
1371
	    mangle_type ( bf, t, 2, 1 ) ;
1524
		mangle_type(bf, t, 2, 1);
1372
	    bfputc ( bf, 0 ) ;
1525
		bfputc(bf, 0);
1373
	    s = bf->start + n ;
1526
		s = bf->start + n;
1374
	    *pcopy = 1 ;
1527
		*pcopy = 1;
-
 
1528
		break;
-
 
1529
	}
-
 
1530
	case hashid_op_tag: {
-
 
1531
		/* Operator names */
-
 
1532
		int op = DEREF_int(hashid_op_lex(nm));
-
 
1533
		s = mangle_op(op);
1375
	    break ;
1534
		break;
1376
	}
1535
	}
1377
	case hashid_op_tag : {
1536
	case hashid_anon_tag: {
1378
	    /* Operator names */
1537
		/* Anonymous names */
1379
	    int op = DEREF_int ( hashid_op_lex ( nm ) ) ;
1538
		if (force && output_all) {
1380
	    s = mangle_op ( op ) ;
1539
			s = ustrlit("");
-
 
1540
		}
1381
	    break ;
1541
		break;
1382
	}
1542
	}
1383
	case hashid_anon_tag : {
-
 
1384
	    /* Anonymous names */
-
 
1385
	    if ( force && output_all ) s = ustrlit ( "" ) ;
-
 
1386
	    break ;
-
 
1387
	}
1543
	}
1388
    }
-
 
1389
    return ( s ) ;
1544
	return (s);
1390
}
1545
}
1391
 
1546
 
1392
 
1547
 
1393
/*
1548
/*
1394
    FIND THE EXTERNAL NAME OF AN IDENTIFIER
1549
    FIND THE EXTERNAL NAME OF AN IDENTIFIER
1395
 
1550
 
1396
    This routine finds the external (mangled) name of the identifier id
1551
    This routine finds the external (mangled) name of the identifier id
1397
    of type v returning the result.  ext determines the treatment of inline
1552
    of type v returning the result.  ext determines the treatment of inline
1398
    functions with external linkage.  The null string is returned for local
1553
    functions with external linkage.  The null string is returned for local
1399
    identifiers.
1554
    identifiers.
1400
*/
1555
*/
1401
 
1556
 
1402
string mangle_name
1557
string
1403
    PROTO_N ( ( id, v, ext ) )
-
 
1404
    PROTO_T ( IDENTIFIER id X int v X int ext )
1558
mangle_name(IDENTIFIER id, int v, int ext)
1405
{
1559
{
1406
    int d ;
1560
	int d;
1407
    string s ;
1561
	string s;
1408
    HASHID nm ;
1562
	HASHID nm;
1409
    BUFFER *bf ;
1563
	BUFFER *bf;
1410
    int copy = 0 ;
1564
	int copy = 0;
1411
    NAMESPACE ns ;
1565
	NAMESPACE ns;
1412
    string pre = NULL ;
1566
	string pre = NULL;
1413
    TYPE t = NULL_type ;
1567
	TYPE t = NULL_type;
1414
    TYPE f = NULL_type ;
1568
	TYPE f = NULL_type;
1415
    CLASS_TYPE cs = NULL_ctype ;
1569
	CLASS_TYPE cs = NULL_ctype;
1416
 
1570
 
1417
    /* Check for internal linkage */
1571
	/* Check for internal linkage */
1418
    DECL_SPEC ds = DEREF_dspec ( id_storage ( id ) ) ;
1572
	DECL_SPEC ds = DEREF_dspec(id_storage(id));
1419
    if ( !( ds & dspec_extern ) ) {
1573
	if (!(ds & dspec_extern)) {
1420
	if ( ds & dspec_static ) {
1574
		if (ds & dspec_static) {
1421
	    if ( !output_all ) return ( NULL ) ;
1575
			if (!output_all) {
-
 
1576
				return (NULL);
-
 
1577
			}
1422
	} else if ( IS_id_enumerator ( id ) ) {
1578
		} else if (IS_id_enumerator(id)) {
1423
	    if ( !output_all ) return ( NULL ) ;
1579
			if (!output_all) {
-
 
1580
				return (NULL);
-
 
1581
			}
1424
	} else {
1582
		} else {
1425
	    return ( NULL ) ;
1583
			return (NULL);
1426
	}
1584
		}
1427
    }
1585
	}
1428
    if ( ( ds & dspec_instance ) && !is_exported ( id ) ) {
1586
	if ((ds & dspec_instance) && !is_exported(id)) {
1429
	/* Non-exported templates */
1587
		/* Non-exported templates */
1430
	if ( !output_all ) return ( NULL ) ;
1588
		if (!output_all) {
-
 
1589
			return (NULL);
1431
    }
1590
		}
-
 
1591
	}
1432
    if ( output_all ) ext = 1 ;
1592
	if (output_all)ext = 1;
1433
 
1593
 
1434
    /* Find the basic name */
1594
	/* Find the basic name */
1435
    name_buff.posn = name_buff.start ;
1595
	name_buff.posn = name_buff.start;
1436
    nm = DEREF_hashid ( id_name ( id ) ) ;
1596
	nm = DEREF_hashid(id_name(id));
1437
    s = mangle_hashid ( nm, &copy, 0 ) ;
1597
	s = mangle_hashid(nm, &copy, 0);
1438
    if ( s == NULL ) return ( NULL ) ;
1598
	if (s == NULL) {
-
 
1599
		return (NULL);
-
 
1600
	}
1439
 
1601
 
1440
    /* Find the namespace depth */
1602
	/* Find the namespace depth */
1441
    ns = DEREF_nspace ( id_parent ( id ) ) ;
1603
	ns = DEREF_nspace(id_parent(id));
1442
    d = nspace_depth ( ns ) ;
1604
	d = nspace_depth(ns);
1443
 
1605
 
1444
    /* Find any type qualifier */
1606
	/* Find any type qualifier */
1445
    switch ( TAG_id ( id ) ) {
1607
	switch (TAG_id(id)) {
1446
	case id_variable_tag : {
1608
	case id_variable_tag: {
1447
	    /* Simple variables */
1609
		/* Simple variables */
1448
	    if ( ds & dspec_c ) {
1610
		if (ds & dspec_c) {
1449
		/* C linkage */
1611
			/* C linkage */
1450
		if ( d > 0 || !anon_c_linkage ) d = 0 ;
1612
			if (d > 0 || !anon_c_linkage) {
1451
	    } else if ( mangle_objects ) {
-
 
1452
		/* C++ linkage */
-
 
1453
		t = DEREF_type ( id_variable_type ( id ) ) ;
-
 
1454
	    }
1613
				d = 0;
1455
	    break ;
-
 
1456
	}
1614
			}
1457
	case id_stat_member_tag : {
1615
		} else if (mangle_objects) {
1458
	    /* Static data members */
1616
			/* C++ linkage */
1459
	    if ( mangle_objects ) {
-
 
1460
		t = DEREF_type ( id_stat_member_type ( id ) ) ;
1617
			t = DEREF_type(id_variable_type(id));
1461
		cs = parent_class ( id ) ;
-
 
1462
	    }
1618
		}
1463
	    break ;
1619
		break;
1464
	}
1620
	}
-
 
1621
	case id_stat_member_tag: {
-
 
1622
		/* Static data members */
-
 
1623
		if (mangle_objects) {
-
 
1624
			t = DEREF_type(id_stat_member_type(id));
-
 
1625
			cs = parent_class(id);
-
 
1626
		}
-
 
1627
		break;
-
 
1628
	}
1465
	case id_function_tag : {
1629
	case id_function_tag: {
1466
	    /* Simple functions */
1630
		/* Simple functions */
1467
	    if ( ( ds & dspec_inline ) && !ext ) {
1631
		if ((ds & dspec_inline) && !ext) {
1468
		/* Inline functions */
1632
			/* Inline functions */
1469
		d = -1 ;
1633
			d = -1;
1470
	    } else if ( ds & dspec_main ) {
1634
		} else if (ds & dspec_main) {
1471
		/* The main function */
1635
			/* The main function */
1472
#if LANGUAGE_CPP && ( TDF_major < 4 )
1636
#if LANGUAGE_CPP && (TDF_major < 4)
1473
		s = ustrlit ( "__MAIN__" ) ;
1637
			s = ustrlit("__MAIN__");
1474
#endif
1638
#endif
1475
		d = 0 ;
1639
			d = 0;
1476
	    } else if ( ds & dspec_c ) {
1640
		} else if (ds & dspec_c) {
1477
		/* C linkage */
1641
			/* C linkage */
1478
		if ( d > 0 || !anon_c_linkage ) d = 0 ;
1642
			if (d > 0 || !anon_c_linkage)d = 0;
1479
	    } else {
1643
		} else {
1480
		/* C++ linkage */
1644
			/* C++ linkage */
1481
		t = DEREF_type ( id_function_type ( id ) ) ;
1645
			t = DEREF_type(id_function_type(id));
1482
		f = DEREF_type ( id_function_form ( id ) ) ;
1646
			f = DEREF_type(id_function_form(id));
-
 
1647
		}
-
 
1648
		break;
-
 
1649
	}
-
 
1650
	case id_mem_func_tag:
-
 
1651
	case id_stat_mem_func_tag: {
-
 
1652
		/* Member functions */
-
 
1653
		if ((ds & dspec_implicit) && !output_all) {
-
 
1654
			/* Implicitly defined functions */
-
 
1655
			d = -1;
-
 
1656
		} else if ((ds & dspec_inline) && !ext) {
-
 
1657
			/* Inline functions */
-
 
1658
			d = -1;
-
 
1659
		} else {
-
 
1660
			t = DEREF_type(id_function_etc_type(id));
-
 
1661
			f = DEREF_type(id_function_etc_form(id));
-
 
1662
			cs = parent_class(id);
1483
	    }
1663
		}
-
 
1664
		break;
-
 
1665
	}
-
 
1666
	case id_member_tag: {
-
 
1667
		/* Data members */
-
 
1668
		pre = ustrlit("~cpp.mem.");
-
 
1669
		t = DEREF_type(id_member_type(id));
-
 
1670
		cs = parent_class(id);
-
 
1671
		break;
-
 
1672
	}
-
 
1673
	case id_enumerator_tag: {
-
 
1674
		/* Enumerators */
-
 
1675
		t = DEREF_type(id_enumerator_etype(id));
1484
	    break ;
1676
		break;
-
 
1677
	}
-
 
1678
	}
-
 
1679
 
-
 
1680
	/* Check for the simple cases */
-
 
1681
	if (d < 0) {
-
 
1682
		return (NULL);
-
 
1683
	}
-
 
1684
	if (d == 0 && IS_NULL_type(t) && pre == NULL) {
-
 
1685
		if (copy) {
-
 
1686
			if (ustrchr(s, MANGLE_error)) {
-
 
1687
				return (NULL);
-
 
1688
			}
-
 
1689
			s = xustrcpy(s);
-
 
1690
		}
-
 
1691
		return (s);
1485
	}
1692
	}
1486
	case id_mem_func_tag :
-
 
1487
	case id_stat_mem_func_tag : {
-
 
1488
	    /* Member functions */
-
 
1489
	    if ( ( ds & dspec_implicit ) && !output_all ) {
-
 
1490
		/* Implicitly defined functions */
-
 
1491
		d = -1 ;
-
 
1492
	    } else if ( ( ds & dspec_inline ) && !ext ) {
-
 
1493
		/* Inline functions */
-
 
1494
		d = -1 ;
-
 
1495
	    } else {
-
 
1496
		t = DEREF_type ( id_function_etc_type ( id ) ) ;
-
 
1497
		f = DEREF_type ( id_function_etc_form ( id ) ) ;
-
 
1498
		cs = parent_class ( id ) ;
-
 
1499
	    }
-
 
1500
	    break ;
-
 
1501
	}
-
 
1502
	case id_member_tag : {
-
 
1503
	    /* Data members */
-
 
1504
	    pre = ustrlit ( "~cpp.mem." ) ;
-
 
1505
	    t = DEREF_type ( id_member_type ( id ) ) ;
-
 
1506
	    cs = parent_class ( id ) ;
-
 
1507
	    break ;
-
 
1508
	}
-
 
1509
	case id_enumerator_tag : {
-
 
1510
	    /* Enumerators */
-
 
1511
	    t = DEREF_type ( id_enumerator_etype ( id ) ) ;
-
 
1512
	    break ;
-
 
1513
	}
-
 
1514
    }
-
 
1515
 
-
 
1516
    /* Check for the simple cases */
-
 
1517
    if ( d < 0 ) return ( NULL ) ;
-
 
1518
    if ( d == 0 && IS_NULL_type ( t ) && pre == NULL ) {
-
 
1519
	if ( copy ) {
-
 
1520
	    if ( ustrchr ( s, MANGLE_error ) ) return ( NULL ) ;
-
 
1521
	    s = xustrcpy ( s ) ;
-
 
1522
	}
-
 
1523
	return ( s ) ;
-
 
1524
    }
-
 
1525
 
1693
 
1526
    /* Deal with the complex case */
1694
	/* Deal with the complex case */
1527
    bf = clear_buffer ( &mangle_buff, NIL ( FILE ) ) ;
1695
	bf = clear_buffer(&mangle_buff, NIL(FILE));
1528
    if ( pre ) bfputs ( bf, pre ) ;
-
 
1529
    bfputs ( bf, s ) ;
-
 
1530
    if ( v == VAR_token ) {
-
 
1531
	bfputc ( bf, MANGLE_dot ) ;
-
 
1532
    } else {
1696
	if (pre) {
1533
	bfputc ( bf, MANGLE_sep ) ;
-
 
1534
	bfputc ( bf, MANGLE_sep ) ;
-
 
1535
    }
-
 
1536
    if ( d ) mangle_nspace ( bf, ns, d ) ;
-
 
1537
    if ( !IS_NULL_type ( f ) && IS_type_token ( f ) ) {
-
 
1538
	/* Check for template functions */
-
 
1539
	if ( mangle_signature ) {
-
 
1540
	    IDENTIFIER fid = DEREF_id ( type_token_tok ( f ) ) ;
-
 
1541
	    LIST ( TOKEN ) args = DEREF_list ( type_token_args ( f ) ) ;
-
 
1542
	    if ( !IS_id_token ( fid ) ) {
-
 
1543
		if ( IS_id_function_etc ( fid ) ) {
-
 
1544
		    /* Use template function type */
-
 
1545
		    t = DEREF_type ( id_function_etc_type ( fid ) ) ;
-
 
1546
		}
-
 
1547
		bfputc ( bf, MANGLE_func_templ ) ;
-
 
1548
		mangle_token_args ( bf, args ) ;
-
 
1549
		bfputc ( bf, MANGLE_sep ) ;
1697
		bfputs(bf, pre);
1550
	    }
-
 
1551
	}
1698
	}
-
 
1699
	bfputs(bf, s);
-
 
1700
	if (v == VAR_token) {
-
 
1701
		bfputc(bf, MANGLE_dot);
-
 
1702
	} else {
-
 
1703
		bfputc(bf, MANGLE_sep);
-
 
1704
		bfputc(bf, MANGLE_sep);
-
 
1705
	}
-
 
1706
	if (d) {
-
 
1707
		mangle_nspace(bf, ns, d);
-
 
1708
	}
-
 
1709
	if (!IS_NULL_type(f) && IS_type_token(f)) {
-
 
1710
		/* Check for template functions */
-
 
1711
		if (mangle_signature) {
-
 
1712
			IDENTIFIER fid = DEREF_id(type_token_tok(f));
-
 
1713
			LIST(TOKEN)args = DEREF_list(type_token_args(f));
-
 
1714
			if (!IS_id_token(fid)) {
-
 
1715
				if (IS_id_function_etc(fid)) {
-
 
1716
					/* Use template function type */
-
 
1717
					t = DEREF_type(id_function_etc_type(fid));
1552
    }
1718
				}
-
 
1719
				bfputc(bf, MANGLE_func_templ);
-
 
1720
				mangle_token_args(bf, args);
-
 
1721
				bfputc(bf, MANGLE_sep);
-
 
1722
			}
-
 
1723
		}
-
 
1724
	}
1553
    if ( !IS_NULL_type ( t ) ) {
1725
	if (!IS_NULL_type(t)) {
1554
	/* Output function type */
1726
		/* Output function type */
1555
	int fn = 1 ;
1727
		int fn = 1;
1556
	if ( !IS_hashid_name_etc ( nm ) ) fn = 0 ;
1728
		if (!IS_hashid_name_etc(nm)) {
-
 
1729
			fn = 0;
-
 
1730
		}
-
 
1731
		if (v == VAR_token) {
1557
	if ( v == VAR_token ) bfputc ( bf, MANGLE_dot ) ;
1732
			bfputc(bf, MANGLE_dot);
-
 
1733
		}
1558
	crt_mangle_class = cs ;
1734
		crt_mangle_class = cs;
1559
	mangle_type ( bf, t, fn, 0 ) ;
1735
		mangle_type(bf, t, fn, 0);
1560
	crt_mangle_class = NULL_ctype ;
1736
		crt_mangle_class = NULL_ctype;
1561
    }
1737
	}
1562
    bfputc ( bf, 0 ) ;
1738
	bfputc(bf, 0);
1563
 
1739
 
1564
    /* Check for illegal names */
1740
	/* Check for illegal names */
1565
    s = bf->start ;
1741
	s = bf->start;
1566
    if ( ustrchr ( s, MANGLE_error ) ) return ( NULL ) ;
1742
	if (ustrchr(s, MANGLE_error)) {
-
 
1743
		return (NULL);
-
 
1744
	}
1567
    s = xustrcpy ( s ) ;
1745
	s = xustrcpy(s);
1568
    return ( s ) ;
1746
	return (s);
1569
}
1747
}
1570
 
1748
 
1571
 
1749
 
1572
/*
1750
/*
1573
    COMMON TAG COUNTER
1751
    COMMON TAG COUNTER
1574
 
1752
 
1575
    This variable is used by mangle_common to ensure that each call
1753
    This variable is used by mangle_common to ensure that each call
1576
    generates a unique name.
1754
    generates a unique name.
1577
*/
1755
*/
1578
 
1756
 
1579
ulong common_no = 0 ;
1757
ulong common_no = 0;
1580
 
1758
 
1581
 
1759
 
1582
/*
1760
/*
1583
    CREATE A LOCAL STATIC NAME
1761
    CREATE A LOCAL STATIC NAME
1584
 
1762
 
1585
    This routine creates a mangled name for the local static variable id
1763
    This routine creates a mangled name for the local static variable id
1586
    from the function with mangled name s.
1764
    from the function with mangled name s.
1587
*/
1765
*/
1588
 
1766
 
1589
string mangle_common
1767
string
1590
    PROTO_N ( ( s, id ) )
-
 
1591
    PROTO_T ( string s X IDENTIFIER id )
1768
mangle_common(string s, IDENTIFIER id)
1592
{
1769
{
1593
    string t = NULL ;
1770
	string t = NULL;
1594
    if ( s ) {
1771
	if (s) {
1595
	BUFFER *bf = clear_buffer ( &mangle_buff, NIL ( FILE ) ) ;
1772
		BUFFER *bf = clear_buffer(&mangle_buff, NIL(FILE));
1596
	bfprintf ( bf, "__v_" ) ;
1773
		bfprintf(bf, "__v_");
1597
	if ( !IS_NULL_id ( id ) ) {
1774
		if (!IS_NULL_id(id)) {
1598
	    int copy = 0 ;
1775
			int copy = 0;
1599
	    HASHID nm = DEREF_hashid ( id_name ( id ) ) ;
1776
			HASHID nm = DEREF_hashid(id_name(id));
1600
	    name_buff.posn = name_buff.start ;
1777
			name_buff.posn = name_buff.start;
1601
	    t = mangle_hashid ( nm, &copy, 0 ) ;
1778
			t = mangle_hashid(nm, &copy, 0);
1602
	    bfputs ( bf, t ) ;
1779
			bfputs(bf, t);
-
 
1780
		}
-
 
1781
		bfprintf(bf, "%lu", common_no++);
-
 
1782
		bfputc(bf, MANGLE_sep);
-
 
1783
		bfputc(bf, MANGLE_sep);
-
 
1784
		bfputs(bf, s);
-
 
1785
		t = bf->start;
-
 
1786
		if (ustrchr(t, MANGLE_error)) {
-
 
1787
			return (NULL);
-
 
1788
		}
-
 
1789
		t = xustrcpy(t);
1603
	}
1790
	}
1604
	bfprintf ( bf, "%lu", common_no++ ) ;
-
 
1605
	bfputc ( bf, MANGLE_sep ) ;
-
 
1606
	bfputc ( bf, MANGLE_sep ) ;
-
 
1607
	bfputs ( bf, s ) ;
-
 
1608
	t = bf->start ;
-
 
1609
	if ( ustrchr ( t, MANGLE_error ) ) return ( NULL ) ;
-
 
1610
	t = xustrcpy ( t ) ;
-
 
1611
    }
-
 
1612
    return ( t ) ;
1791
	return (t);
1613
}
1792
}
1614
 
1793
 
1615
 
1794
 
1616
/*
1795
/*
1617
    CREATE A VIRTUAL FUNCTION TABLE NAME
1796
    CREATE A VIRTUAL FUNCTION TABLE NAME
1618
 
1797
 
1619
    This routine creates a mangled name for the virtual function table
1798
    This routine creates a mangled name for the virtual function table
1620
    associated with the base class graph gr.
1799
    associated with the base class graph gr.
1621
*/
1800
*/
1622
 
1801
 
1623
string mangle_vtable
1802
string
1624
    PROTO_N ( ( pre, gr ) )
-
 
1625
    PROTO_T ( CONST char *pre X GRAPH gr )
1803
mangle_vtable(CONST char *pre, GRAPH gr)
1626
{
1804
{
1627
    string s ;
1805
	string s;
1628
    BUFFER *bf = clear_buffer ( &mangle_buff, NIL ( FILE ) ) ;
1806
	BUFFER *bf = clear_buffer(&mangle_buff, NIL(FILE));
1629
    name_buff.posn = name_buff.start ;
1807
	name_buff.posn = name_buff.start;
1630
    bfputs ( bf, ustrlit ( pre ) ) ;
1808
	bfputs(bf, ustrlit(pre));
1631
    mangle_graph ( bf, gr ) ;
1809
	mangle_graph(bf, gr);
1632
    bfputc ( bf, 0 ) ;
1810
	bfputc(bf, 0);
1633
    s = bf->start ;
1811
	s = bf->start;
1634
    if ( ustrchr ( s, MANGLE_error ) ) return ( NULL ) ;
1812
	if (ustrchr(s, MANGLE_error)) {
-
 
1813
		return (NULL);
-
 
1814
	}
1635
    s = xustrcpy ( s ) ;
1815
	s = xustrcpy(s);
1636
    return ( s ) ;
1816
	return (s);
1637
}
1817
}
1638
 
1818
 
1639
 
1819
 
1640
/*
1820
/*
1641
    CREATE A TYPE INFORMATION STRUCTURE NAME
1821
    CREATE A TYPE INFORMATION STRUCTURE NAME
1642
 
1822
 
1643
    This routine creates a mangled name for the type information structure
1823
    This routine creates a mangled name for the type information structure
1644
    associated with the polymorphic class type ct.
1824
    associated with the polymorphic class type ct.
1645
*/
1825
*/
1646
 
1826
 
1647
string mangle_typeid
1827
string
1648
    PROTO_N ( ( pre, ct ) )
-
 
1649
    PROTO_T ( CONST char *pre X CLASS_TYPE ct )
1828
mangle_typeid(CONST char *pre, CLASS_TYPE ct)
1650
{
1829
{
1651
    string s ;
1830
	string s;
1652
    BUFFER *bf = clear_buffer ( &mangle_buff, NIL ( FILE ) ) ;
1831
	BUFFER *bf = clear_buffer(&mangle_buff, NIL(FILE));
1653
    name_buff.posn = name_buff.start ;
1832
	name_buff.posn = name_buff.start;
1654
    bfputs ( bf, ustrlit ( pre ) ) ;
1833
	bfputs(bf, ustrlit(pre));
1655
    mangle_ctype ( bf, ct, -2 ) ;
1834
	mangle_ctype(bf, ct, -2);
1656
    bfputc ( bf, 0 ) ;
1835
	bfputc(bf, 0);
1657
    s = bf->start ;
1836
	s = bf->start;
1658
    if ( ustrchr ( s, MANGLE_error ) ) return ( NULL ) ;
1837
	if (ustrchr(s, MANGLE_error)) {
-
 
1838
		return (NULL);
-
 
1839
	}
1659
    s = xustrcpy ( s ) ;
1840
	s = xustrcpy(s);
1660
    return ( s ) ;
1841
	return (s);
1661
}
1842
}
1662
 
1843
 
1663
 
1844
 
1664
/*
1845
/*
1665
    CREATE A TYPE TOKEN NAME
1846
    CREATE A TYPE TOKEN NAME
1666
 
1847
 
1667
    This routine creates a mangled name for the type token name associated
1848
    This routine creates a mangled name for the type token name associated
1668
    with the type t.
1849
    with the type t.
1669
*/
1850
*/
1670
 
1851
 
1671
string mangle_tname
1852
string
1672
    PROTO_N ( ( pre, t ) )
-
 
1673
    PROTO_T ( CONST char *pre X TYPE t )
1853
mangle_tname(CONST char *pre, TYPE t)
1674
{
1854
{
1675
    string s ;
1855
	string s;
1676
    BUFFER *bf = clear_buffer ( &mangle_buff, NIL ( FILE ) ) ;
1856
	BUFFER *bf = clear_buffer(&mangle_buff, NIL(FILE));
1677
    name_buff.posn = name_buff.start ;
1857
	name_buff.posn = name_buff.start;
1678
    bfputs ( bf, ustrlit ( pre ) ) ;
1858
	bfputs(bf, ustrlit(pre));
1679
    mangle_type ( bf, t, 2, 1 ) ;
1859
	mangle_type(bf, t, 2, 1);
1680
    bfputc ( bf, 0 ) ;
1860
	bfputc(bf, 0);
1681
    s = bf->start ;
1861
	s = bf->start;
1682
    if ( ustrchr ( s, MANGLE_error ) ) return ( NULL ) ;
1862
	if (ustrchr(s, MANGLE_error)) {
-
 
1863
		return (NULL);
-
 
1864
	}
1683
    s = xustrcpy ( s ) ;
1865
	s = xustrcpy(s);
1684
    return ( s ) ;
1866
	return (s);
1685
}
1867
}
1686
 
1868
 
1687
 
1869
 
1688
/*
1870
/*
1689
    CREATE AN INITIALISER FUNCTION NAME
1871
    CREATE AN INITIALISER FUNCTION NAME
Line 1691... Line 1873...
1691
    This routine creates a dynamic initialiser function name.  For TDF 4.0
1873
    This routine creates a dynamic initialiser function name.  For TDF 4.0
1692
    and later this can be the null string since there is direct support
1874
    and later this can be the null string since there is direct support
1693
    for dynamic initialisation.
1875
    for dynamic initialisation.
1694
*/
1876
*/
1695
 
1877
 
1696
string mangle_init
1878
string
1697
    PROTO_Z ()
1879
mangle_init(void)
1698
{
1880
{
1699
#if ( TDF_major >= 4 )
1881
#if (TDF_major >= 4)
1700
    return ( NULL ) ;
1882
	return (NULL);
1701
#else
1883
#else
1702
    char buff [50] ;
1884
	char buff[50];
1703
    output_init = 1 ;
1885
	output_init = 1;
1704
    sprintf_v ( buff, "_GLOBAL_$I$%s", uniq_string ) ;
1886
	sprintf_v(buff, "_GLOBAL_$I$%s", uniq_string);
1705
    return ( xustrcpy ( ustrlit ( buff ) ) ) ;
1887
	return (xustrcpy(ustrlit(buff)));
1706
#endif
1888
#endif
1707
}
1889
}
1708
 
1890
 
1709
 
1891
 
1710
/*
1892
/*
1711
    CREATE A UNIQUE IDENTIFIER NAME
1893
    CREATE A UNIQUE IDENTIFIER NAME
1712
 
1894
 
1713
    This routine creates a unique identifier name distinct from every other
1895
    This routine creates a unique identifier name distinct from every other
1714
    identifier name.
1896
    identifier name.
1715
*/
1897
*/
1716
 
1898
 
1717
string mangle_anon
1899
string
1718
    PROTO_Z ()
1900
mangle_anon(void)
1719
{
1901
{
1720
    char buff [50] ;
1902
	char buff[50];
1721
    static unsigned long anon_no = 0 ;
1903
	static unsigned long anon_no = 0;
1722
    sprintf_v ( buff, "__%lu_%s", anon_no++, uniq_string ) ;
1904
	sprintf_v(buff, "__%lu_%s", anon_no++, uniq_string);
1723
    return ( xustrcpy ( ustrlit ( buff ) ) ) ;
1905
	return (xustrcpy(ustrlit(buff)));
1724
}
1906
}
1725
 
1907
 
1726
 
1908
 
1727
/*
1909
/*
1728
    ADD A DIAGNOSTIC NAME QUALIFIER TO THE BUFFER
1910
    ADD A DIAGNOSTIC NAME QUALIFIER TO THE BUFFER
1729
 
1911
 
1730
    This routine adds the name of the namespace ns to the buffer bf.
1912
    This routine adds the name of the namespace ns to the buffer bf.
1731
*/
1913
*/
1732
 
1914
 
1733
static void mangle_diag_nspace
1915
static void
1734
    PROTO_N ( ( bf, ns ) )
-
 
1735
    PROTO_T ( BUFFER *bf X NAMESPACE ns )
1916
mangle_diag_nspace(BUFFER *bf, NAMESPACE ns)
1736
{
1917
{
1737
    if ( !IS_NULL_nspace ( ns ) ) {
1918
	if (!IS_NULL_nspace(ns)) {
1738
	switch ( TAG_nspace ( ns ) ) {
1919
		switch (TAG_nspace(ns)) {
1739
	    case nspace_named_tag :
1920
		case nspace_named_tag:
1740
	    case nspace_ctype_tag : {
1921
		case nspace_ctype_tag: {
1741
		int copy = 0 ;
1922
			int copy = 0;
1742
		IDENTIFIER id = DEREF_id ( nspace_name ( ns ) ) ;
1923
			IDENTIFIER id = DEREF_id(nspace_name(ns));
1743
		HASHID nm = DEREF_hashid ( id_name ( id ) ) ;
1924
			HASHID nm = DEREF_hashid(id_name(id));
1744
		string s = mangle_hashid ( nm, &copy, 0 ) ;
1925
			string s = mangle_hashid(nm, &copy, 0);
1745
		ns = DEREF_nspace ( id_parent ( id ) ) ;
1926
			ns = DEREF_nspace(id_parent(id));
1746
		mangle_diag_nspace ( bf, ns ) ;
1927
			mangle_diag_nspace(bf, ns);
-
 
1928
			if (s) {
1747
		if ( s ) bfputs ( bf, s ) ;
1929
				bfputs(bf, s);
-
 
1930
			}
1748
		bfputc ( bf, MANGLE_sep ) ;
1931
			bfputc(bf, MANGLE_sep);
1749
		bfputc ( bf, MANGLE_sep ) ;
1932
			bfputc(bf, MANGLE_sep);
1750
		break ;
1933
			break;
1751
	    }
1934
		}
1752
	    case nspace_unnamed_tag : {
1935
		case nspace_unnamed_tag: {
1753
		IDENTIFIER id = DEREF_id ( nspace_name ( ns ) ) ;
1936
			IDENTIFIER id = DEREF_id(nspace_name(ns));
1754
		ns = DEREF_nspace ( id_parent ( id ) ) ;
1937
			ns = DEREF_nspace(id_parent(id));
1755
		mangle_diag_nspace ( bf, ns ) ;
1938
			mangle_diag_nspace(bf, ns);
1756
		break ;
1939
			break;
-
 
1940
		}
1757
	    }
1941
		}
1758
	}
1942
	}
1759
    }
-
 
1760
    return ;
1943
	return;
1761
}
1944
}
1762
 
1945
 
1763
 
1946
 
1764
/*
1947
/*
1765
    FIND THE DIAGNOSTIC NAME FOR AN IDENTIFIER
1948
    FIND THE DIAGNOSTIC NAME FOR AN IDENTIFIER
1766
 
1949
 
1767
    This routine creates the name used for the identifier id in the
1950
    This routine creates the name used for the identifier id in the
1768
    diagnostic output.  If q is false then no qualifiers are output.
1951
    diagnostic output.  If q is false then no qualifiers are output.
1769
*/
1952
*/
1770
 
1953
 
1771
string mangle_diag
1954
string
1772
    PROTO_N ( ( id, q ) )
-
 
1773
    PROTO_T ( IDENTIFIER id X int q )
1955
mangle_diag(IDENTIFIER id, int q)
1774
{
1956
{
1775
    int fn = 0 ;
1957
	int fn = 0;
1776
    TYPE t = NULL_type ;
1958
	TYPE t = NULL_type;
1777
    HASHID nm = DEREF_hashid ( id_name ( id ) ) ;
1959
	HASHID nm = DEREF_hashid(id_name(id));
1778
    unsigned tag = TAG_hashid ( nm ) ;
1960
	unsigned tag = TAG_hashid(nm);
1779
    BUFFER *bf = clear_buffer ( &mangle_buff, NIL ( FILE ) ) ;
1961
	BUFFER *bf = clear_buffer(&mangle_buff, NIL(FILE));
1780
    name_buff.posn = name_buff.start ;
1962
	name_buff.posn = name_buff.start;
1781
    if ( q ) {
1963
	if (q) {
1782
	DECL_SPEC ds = DEREF_dspec ( id_storage ( id ) ) ;
1964
		DECL_SPEC ds = DEREF_dspec(id_storage(id));
1783
	if ( ds & dspec_c ) {
1965
		if (ds & dspec_c) {
1784
	    /* Ignore C linkage objects */
1966
			/* Ignore C linkage objects */
1785
	    /* EMPTY */
1967
			/* EMPTY */
1786
	} else if ( ( ds & dspec_main ) && tag == hashid_name_tag ) {
1968
		} else if ((ds & dspec_main) && tag == hashid_name_tag) {
1787
	    /* Ignore main function */
1969
			/* Ignore main function */
1788
	    /* EMPTY */
1970
			/* EMPTY */
1789
	} else {
1971
		} else {
1790
	    /* Namespace qualifiers */
1972
			/* Namespace qualifiers */
1791
	    NAMESPACE ns = DEREF_nspace ( id_parent ( id ) ) ;
1973
			NAMESPACE ns = DEREF_nspace(id_parent(id));
1792
	    mangle_diag_nspace ( bf, ns ) ;
1974
			mangle_diag_nspace(bf, ns);
1793
	    if ( IS_id_function_etc ( id ) ) {
1975
			if (IS_id_function_etc(id)) {
1794
		t = DEREF_type ( id_function_etc_type ( id ) ) ;
1976
				t = DEREF_type(id_function_etc_type(id));
1795
	    }
1977
			}
1796
	}
1978
		}
1797
    }
1979
	}
1798
    switch ( tag ) {
1980
	switch (tag) {
1799
	case hashid_name_tag : {
1981
	case hashid_name_tag: {
1800
	    string s = DEREF_string ( hashid_name_text ( nm ) ) ;
1982
		string s = DEREF_string(hashid_name_text(nm));
1801
	    bfputs ( bf, s ) ;
1983
		bfputs(bf, s);
-
 
1984
		fn = 1;
-
 
1985
		break;
-
 
1986
	}
-
 
1987
	case hashid_ename_tag: {
-
 
1988
		if (EQ_KEYWORD(nm, lex_this_Hname)) {
-
 
1989
			bfprintf(bf, "this");
-
 
1990
		} else {
-
 
1991
			string s = DEREF_string(hashid_ename_text(nm));
-
 
1992
			IGNORE mangle_ename(bf, s);
-
 
1993
		}
1802
	    fn = 1 ;
1994
		fn = 1;
-
 
1995
		break;
-
 
1996
	}
-
 
1997
	case hashid_constr_tag: {
-
 
1998
		bfprintf(bf, "1");
-
 
1999
		break;
-
 
2000
	}
-
 
2001
	case hashid_destr_tag: {
-
 
2002
		bfprintf(bf, "0");
1803
	    break ;
2003
		break;
1804
	}
2004
	}
1805
	case hashid_ename_tag : {
2005
	case hashid_conv_tag: {
1806
	    if ( EQ_KEYWORD ( nm, lex_this_Hname ) ) {
2006
		t = DEREF_type(hashid_conv_type(nm));
1807
		bfprintf ( bf, "this" ) ;
2007
		bfprintf(bf, "operator__T");
1808
	    } else {
-
 
1809
		string s = DEREF_string ( hashid_ename_text ( nm ) ) ;
-
 
1810
		IGNORE mangle_ename ( bf, s ) ;
2008
		mangle_type(bf, t, 2, 1);
1811
	    }
-
 
1812
	    fn = 1 ;
2009
		t = NULL_type;
1813
	    break ;
2010
		break;
1814
	}
2011
	}
1815
	case hashid_constr_tag : {
2012
	case hashid_op_tag: {
-
 
2013
		int op = DEREF_int(hashid_op_lex(nm));
-
 
2014
		string s = mangle_op(op);
1816
	    bfprintf ( bf, "1" ) ;
2015
		bfprintf(bf, "operator");
1817
	    break ;
2016
		if (s) {
-
 
2017
			bfputs(bf, s);
1818
	}
2018
		}
1819
	case hashid_destr_tag : {
-
 
1820
	    bfprintf ( bf, "0" ) ;
-
 
1821
	    break ;
2019
		break;
1822
	}
2020
	}
1823
	case hashid_conv_tag : {
2021
	case hashid_anon_tag: {
1824
	    t = DEREF_type ( hashid_conv_type ( nm ) ) ;
2022
		ulong u = DEREF_ulong(hashid_anon_uniq(nm));
1825
	    bfprintf ( bf, "operator__T" ) ;
2023
		bfprintf(bf, "__anon%lu", u);
1826
	    mangle_type ( bf, t, 2, 1 ) ;
-
 
1827
	    t = NULL_type ;
2024
		fn = 1;
1828
	    break ;
2025
		break;
1829
	}
2026
	}
1830
	case hashid_op_tag : {
-
 
1831
	    int op = DEREF_int ( hashid_op_lex ( nm ) ) ;
-
 
1832
	    string s = mangle_op ( op ) ;
-
 
1833
	    bfprintf ( bf, "operator" ) ;
-
 
1834
	    if ( s ) bfputs ( bf, s ) ;
-
 
1835
	    break ;
-
 
1836
	}
2027
	}
1837
	case hashid_anon_tag : {
2028
	if (!IS_NULL_type(t)) {
1838
	    ulong u = DEREF_ulong ( hashid_anon_uniq ( nm ) ) ;
2029
		/* Mangled function type */
1839
	    bfprintf ( bf, "__anon%lu", u ) ;
2030
		bfputc(bf, MANGLE_sep);
1840
	    fn = 1 ;
2031
		bfputc(bf, MANGLE_sep);
1841
	    break ;
2032
		mangle_type(bf, t, fn, 0);
1842
	}
2033
	}
1843
    }
-
 
1844
    if ( !IS_NULL_type ( t ) ) {
-
 
1845
	/* Mangled function type */
-
 
1846
	bfputc ( bf, MANGLE_sep ) ;
-
 
1847
	bfputc ( bf, MANGLE_sep ) ;
-
 
1848
	mangle_type ( bf, t, fn, 0 ) ;
-
 
1849
    }
-
 
1850
    bfputc ( bf, 0 ) ;
2034
	bfputc(bf, 0);
1851
    return ( bf->start ) ;
2035
	return (bf->start);
1852
}
2036
}