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.
41 * The variable "hold" contains the pointer to the array initially
42 * handed to demangle. It is returned if it is not possible to
43 * demangle the string. NULL is returned if a memory allocation
44 * problem is encountered. Thus one can do the following:
46 * char *mn = "Some mangled name";
47 * char *dm = mangle(mn);
49 * printf("allocation error\n");
51 * printf("name could not be demangled\n");
53 * printf("demangled name is: %s\n",dm);
58 * this String is the working buffer for the demangle
59 * routine. A pointer into this String is returned
60 * from demangle when it is possible to demangle the
61 * String. For this reason, the pointer should not
62 * be saved between calls of demangle(), nor freed.
69 return (strtol(*c
, c
, 10));
73 * If a mangled name has a __
74 * that is not at the very beginning
75 * of the string, then this routine
76 * is called to demangle that part
77 * of the name. All overloaded functions,
78 * and class members fall into this category.
80 * c should start with two underscores followed by a non-zero digit or an F.
86 if (strncmp(c
, MSG_ORIG(MSG_STR_DBLUNDBAR
), 2))
90 if (!(isdigit(*c
) || *c
== 'F'))
96 if (n
== 0 || (int)strlen(c
) < n
)
98 s
= prep_String(MSG_ORIG(MSG_STR_DBLCOL
), s
);
99 s
= nprep_String(c
, s
, n
);
103 /* an overloaded function */
108 s
= app_String(s
, MSG_ORIG(MSG_STR_OPENCLOSEPAR
));
111 if (demangle_doargs(&s
, c
) < 0)
123 static mutex_t mlock
= DEFAULTMUTEX
;
125 (void) mutex_lock(&mlock
);
128 (void) mutex_unlock(&mlock
);
134 s
= set_String(s
, MSG_ORIG(MSG_STR_EMPTY
));
136 if (c
== 0 || *c
== 0) {
138 (void) mutex_unlock(&mlock
);
142 if (strncmp(c
, MSG_ORIG(MSG_STR_DBLUNDBAR
), 2) != 0) {
144 * If a name does not begin with a __
145 * but it does contain one, it is either
146 * a member or an overloaded function.
148 while (c
[i
] && strncmp(c
+i
, MSG_ORIG(MSG_STR_DBLUNDBAR
), 2))
151 /* Advance to first non-underscore */
152 while (c
[i
+2] == '_')
155 if (strncmp(c
+i
, MSG_ORIG(MSG_STR_DBLUNDBAR
), 2) == 0) {
156 /* Copy the simple name */
157 s
= napp_String(s
, c
, i
);
158 /* Process the signature */
160 (void) mutex_unlock(&mlock
);
164 (void) mutex_unlock(&mlock
);
174 * For automatic variables, or internal static
175 * variables, a __(number) is prepended to the
176 * name. If this is encountered, strip this off
182 (void) mutex_unlock(&mlock
);
187 * Handle operator functions -- this
188 * automatically calls second, since
189 * all operator functions are overloaded.
191 if (x
= findop(c
, &oplen
)) {
192 s
= app_String(s
, MSG_ORIG(MSG_STR_OPERATOR_1
));
193 s
= app_String(s
, x
);
196 (void) mutex_unlock(&mlock
);
201 * Operator cast does not fit the mould
202 * of the other operators. Its type name
203 * is encoded. The cast function must
204 * take a void as an argument.
206 if (strncmp(c
, MSG_ORIG(MSG_STR_OP
), 2) == 0) {
208 s
= app_String(s
, MSG_ORIG(MSG_STR_OPERATOR_2
));
210 r
= demangle_doarg(&s
, c
);
213 (void) mutex_unlock(&mlock
);
218 (void) mutex_unlock(&mlock
);
223 * Constructors and Destructors are also
224 * a special case of operator name. Note
225 * that the destructor, while overloaded,
226 * must always take the same arguments --
229 if ((*c
== 'c' || *c
== 'd') &&
230 strncmp(c
+1, MSG_ORIG(MSG_STR_TDBLUNDBAR
), 3) == 0) {
238 (void) mutex_unlock(&mlock
);
241 s
= napp_String(s
, c
, n
);
243 s
= prep_String(MSG_ORIG(MSG_STR_TILDE
), s
);
245 (void) mutex_unlock(&mlock
);
249 (void) mutex_unlock(&mlock
);