4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright (c) 1988 AT&T
27 * Copyright (c) 1998 by Sun Microsystems, Inc.
28 * All rights reserved.
30 #pragma ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.2 */
39 /* This structure is used to keep
40 * track of pointers to argument
41 * descriptions in the mangled string.
42 * This is needed for N and T encodings
52 /* Strings and flags needed by the argument demangles. The declarator
53 * is built up in ptr. Type modifiers are held in the flag fields.
54 * The type itself is passed in separately.
58 int Sign
,Uns
,Cons
,Vol
;
61 /* initialize Arg_Remem */
66 r
->ptr
= mk_String((String
*)0);
67 r
->Sign
= r
->Uns
= r
->Cons
= r
->Vol
= 0;
70 /* free data for Arg_Remem */
78 /* This routine formats a single argument
80 * c is the type or class name, n is its length.
83 nsetarg(String
** sptr
, Arg_Remem
* r
, const char * c
, int n
)
85 r
->ptr
= nprep_String(c
, r
->ptr
, n
);
87 r
->ptr
= prep_String(MSG_ORIG(MSG_STR_CONST_1
), r
->ptr
);
89 r
->ptr
= prep_String(MSG_ORIG(MSG_STR_VOLATILE_1
), r
->ptr
);
91 r
->ptr
= prep_String(MSG_ORIG(MSG_STR_UNSIGNED
), r
->ptr
);
93 r
->ptr
= prep_String(MSG_ORIG(MSG_STR_SIGNED
), r
->ptr
);
94 *sptr
= app_String(*sptr
,PTR(r
->ptr
));
98 /* This routine formats a single argument
100 * c is the null terminated type or class name.
103 setarg(String
** sptr
, Arg_Remem
* r
, const char * c
)
105 nsetarg(sptr
, r
, c
, ID_NAME_MAX
);
109 /* Demangle a single function argument.
110 * Returns the number of characters processed from c.
113 demangle_doarg(sptr
,c
)
121 if(here
.pos
< 10 && here
.pos
>= 0)
122 here
.list
[here
.pos
++] = c
;
125 /* Loop until you find a type.
126 Then call setarg and return.
134 here
.pos
= c
[1] - '1';
135 if(here
.pos
< 0 || here
.pos
>= tmp
.pos
-1) {
139 (void) demangle_doarg(sptr
,here
.list
[here
.pos
]);
148 cycles
= c
[1] - '0'; pos
= c
[2] - '1';
149 here
.pos
+= cycles
- 1;
151 if(cycles
<= 1 || cycles
> 9 || pos
< 0 || pos
>= tmp
.pos
-1) {
158 (void) demangle_doarg(sptr
,here
.list
[here
.pos
]);
159 (*sptr
) = app_String(*sptr
,
160 MSG_ORIG(MSG_STR_COMMA
));
162 *sptr
= trunc_String(*sptr
, 1);
168 /* Qualifiers to type names */
182 /* Pointers, references, and Member Pointers */
187 ar
.ptr
= prep_String(MSG_ORIG(MSG_STR_CONST_2
),
193 prep_String(MSG_ORIG(MSG_STR_VOLATILE_2
),
198 ar
.ptr
= prep_String(MSG_ORIG(MSG_STR_STAR
),
201 ar
.ptr
= prep_String(MSG_ORIG(MSG_STR_AMP
),
207 prep_String(MSG_ORIG(MSG_STR_DBLCOLSTAR
),
209 /* Skip over the 'M' */
211 cnt
= strtol(c
+i
, &s
, 10);
213 ar
.ptr
= nprep_String(c
+i
,ar
.ptr
,cnt
);
214 ar
.ptr
= prep_String(MSG_ORIG(MSG_STR_SPACE
),
217 /* The loop increments i */
222 /* Demangle for basic built-in types */
224 setarg(sptr
, &ar
, MSG_ORIG(MSG_STR_INT
));
227 setarg(sptr
, &ar
, MSG_ORIG(MSG_STR_CHAR
));
230 setarg(sptr
, &ar
, MSG_ORIG(MSG_STR_SHORT
));
233 setarg(sptr
, &ar
, MSG_ORIG(MSG_STR_LONG
));
236 setarg(sptr
, &ar
, MSG_ORIG(MSG_STR_FLOAT
));
239 setarg(sptr
, &ar
, MSG_ORIG(MSG_STR_DOUBLE
));
242 setarg(sptr
, &ar
, MSG_ORIG(MSG_STR_LONGDOUBLE
));
245 /* Class encodings */
246 case '1': case '2': case '3':
247 case '4': case '5': case '6':
248 case '7': case '8': case '9':
252 cnt
= strtol(c
+i
, &s
, 10);
254 if ((int) strlen(c
+i
) < cnt
) {
258 nsetarg(sptr
,&ar
,c
+i
,cnt
);
262 /* Ellipsis and void */
264 setarg(sptr
, &ar
, MSG_ORIG(MSG_STR_ELIPSE
));
267 setarg(sptr
, &ar
, MSG_ORIG(MSG_STR_VOID
));
273 ar
.ptr
= prep_String(MSG_ORIG(MSG_STR_OPENPAR
),
275 ar
.ptr
= app_String(ar
.ptr
,
276 MSG_ORIG(MSG_STR_CLOSEPAR
));
278 ar
.ptr
= app_String(ar
.ptr
, MSG_ORIG(MSG_STR_OPENBRAK
));
282 while(isdigit(c
[i
+cnt
]))
284 ar
.ptr
= napp_String(ar
.ptr
,c
+i
,cnt
);
291 ar
.ptr
= app_String(ar
.ptr
,
292 MSG_ORIG(MSG_STR_CLOSEBRAK
));
296 * This will always be called as a pointer
300 ar
.ptr
= prep_String(MSG_ORIG(MSG_STR_OPENPAR
), ar
.ptr
);
301 ar
.ptr
= app_String(ar
.ptr
, MSG_ORIG(MSG_STR_CLOSEPAR
));
306 i
+= demangle_doargs(&ar
.ptr
,c
+i
);
315 /* Needed when this is called to demangle
316 * an argument of a pointer to a function.
328 /* Did the argument list terminate properly? */
331 if(*PTR(ar
.ptr
) || ar
.Uns
|| ar
.Sign
|| ar
.Cons
|| ar
.Vol
)
338 /* This function is called to demangle
340 * Returns the number of characters processed from c.
343 demangle_doargs(sptr
,c
)
350 *sptr
= app_String(*sptr
,MSG_ORIG(MSG_STR_OPENPAR
));
351 while(*c
&& (i
= demangle_doarg(sptr
,c
)) > 0) {
354 (*sptr
) = app_String(*sptr
,(*c
&& *c
== 'e') ?
355 MSG_ORIG(MSG_STR_SPACE
) : MSG_ORIG(MSG_STR_COMMA
));
361 *sptr
= app_String(trunc_String(*sptr
, 1), MSG_ORIG(MSG_STR_CLOSEPAR
));