wined3d: Use a separate STATE_TRANSFORM(WINED3D_TS_VIEW) state handler in the GLSL...
[wine/multimedia.git] / dlls / msvcrt / undname.c
blobbeaec4f1369ad14ba4e42942063330e8655e18d3
1 /*
2 * Demangle VC++ symbols into C function prototypes
4 * Copyright 2000 Jon Griffiths
5 * 2004 Eric Pouech
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "config.h"
23 #include "wine/port.h"
25 #include <assert.h>
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include "msvcrt.h"
30 #include "wine/debug.h"
32 WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
34 /* TODO:
35 * - document a bit (grammar + functions)
36 * - back-port this new code into tools/winedump/msmangle.c
39 /* How data types modifiers are stored:
40 * M (in the following definitions) is defined for
41 * 'A', 'B', 'C' and 'D' as follows
42 * {<A>}: ""
43 * {<B>}: "const "
44 * {<C>}: "volatile "
45 * {<D>}: "const volatile "
47 * in arguments:
48 * P<M>x {<M>}x*
49 * Q<M>x {<M>}x* const
50 * A<M>x {<M>}x&
51 * in data fields:
52 * same as for arguments and also the following
53 * ?<M>x {<M>}x
57 struct array
59 unsigned start; /* first valid reference in array */
60 unsigned num; /* total number of used elts */
61 unsigned max;
62 unsigned alloc;
63 char** elts;
66 /* Structure holding a parsed symbol */
67 struct parsed_symbol
69 unsigned flags; /* the UNDNAME_ flags used for demangling */
70 malloc_func_t mem_alloc_ptr; /* internal allocator */
71 free_func_t mem_free_ptr; /* internal deallocator */
73 const char* current; /* pointer in input (mangled) string */
74 char* result; /* demangled string */
76 struct array names; /* array of names for back reference */
77 struct array stack; /* stack of parsed strings */
79 void* alloc_list; /* linked list of allocated blocks */
80 unsigned avail_in_first; /* number of available bytes in head block */
83 /* Type for parsing mangled types */
84 struct datatype_t
86 const char* left;
87 const char* right;
90 static BOOL symbol_demangle(struct parsed_symbol* sym);
92 /******************************************************************
93 * und_alloc
95 * Internal allocator. Uses a simple linked list of large blocks
96 * where we use a poor-man allocator. It's fast, and since all
97 * allocation is pool, memory management is easy (esp. freeing).
99 static void* und_alloc(struct parsed_symbol* sym, unsigned int len)
101 void* ptr;
103 #define BLOCK_SIZE 1024
104 #define AVAIL_SIZE (1024 - sizeof(void*))
106 if (len > AVAIL_SIZE)
108 /* allocate a specific block */
109 ptr = sym->mem_alloc_ptr(sizeof(void*) + len);
110 if (!ptr) return NULL;
111 *(void**)ptr = sym->alloc_list;
112 sym->alloc_list = ptr;
113 sym->avail_in_first = 0;
114 ptr = (char*)sym->alloc_list + sizeof(void*);
116 else
118 if (len > sym->avail_in_first)
120 /* add a new block */
121 ptr = sym->mem_alloc_ptr(BLOCK_SIZE);
122 if (!ptr) return NULL;
123 *(void**)ptr = sym->alloc_list;
124 sym->alloc_list = ptr;
125 sym->avail_in_first = AVAIL_SIZE;
127 /* grab memory from head block */
128 ptr = (char*)sym->alloc_list + BLOCK_SIZE - sym->avail_in_first;
129 sym->avail_in_first -= len;
131 return ptr;
132 #undef BLOCK_SIZE
133 #undef AVAIL_SIZE
136 /******************************************************************
137 * und_free
138 * Frees all the blocks in the list of large blocks allocated by
139 * und_alloc.
141 static void und_free_all(struct parsed_symbol* sym)
143 void* next;
145 while (sym->alloc_list)
147 next = *(void**)sym->alloc_list;
148 if(sym->mem_free_ptr) sym->mem_free_ptr(sym->alloc_list);
149 sym->alloc_list = next;
151 sym->avail_in_first = 0;
154 /******************************************************************
155 * str_array_init
156 * Initialises an array of strings
158 static void str_array_init(struct array* a)
160 a->start = a->num = a->max = a->alloc = 0;
161 a->elts = NULL;
164 /******************************************************************
165 * str_array_push
166 * Adding a new string to an array
168 static BOOL str_array_push(struct parsed_symbol* sym, const char* ptr, int len,
169 struct array* a)
171 char** new;
173 assert(ptr);
174 assert(a);
176 if (!a->alloc)
178 new = und_alloc(sym, (a->alloc = 32) * sizeof(a->elts[0]));
179 if (!new) return FALSE;
180 a->elts = new;
182 else if (a->max >= a->alloc)
184 new = und_alloc(sym, (a->alloc * 2) * sizeof(a->elts[0]));
185 if (!new) return FALSE;
186 memcpy(new, a->elts, a->alloc * sizeof(a->elts[0]));
187 a->alloc *= 2;
188 a->elts = new;
190 if (len == -1) len = strlen(ptr);
191 a->elts[a->num] = und_alloc(sym, len + 1);
192 assert(a->elts[a->num]);
193 memcpy(a->elts[a->num], ptr, len);
194 a->elts[a->num][len] = '\0';
195 if (++a->num >= a->max) a->max = a->num;
197 int i;
198 char c;
200 for (i = a->max - 1; i >= 0; i--)
202 c = '>';
203 if (i < a->start) c = '-';
204 else if (i >= a->num) c = '}';
205 TRACE("%p\t%d%c %s\n", a, i, c, a->elts[i]);
209 return TRUE;
212 /******************************************************************
213 * str_array_get_ref
214 * Extracts a reference from an existing array (doing proper type
215 * checking)
217 static char* str_array_get_ref(struct array* cref, unsigned idx)
219 assert(cref);
220 if (cref->start + idx >= cref->max)
222 WARN("Out of bounds: %p %d + %d >= %d\n",
223 cref, cref->start, idx, cref->max);
224 return NULL;
226 TRACE("Returning %p[%d] => %s\n",
227 cref, idx, cref->elts[cref->start + idx]);
228 return cref->elts[cref->start + idx];
231 /******************************************************************
232 * str_printf
233 * Helper for printf type of command (only %s and %c are implemented)
234 * while dynamically allocating the buffer
236 static char* str_printf(struct parsed_symbol* sym, const char* format, ...)
238 va_list args;
239 unsigned int len = 1, i, sz;
240 char* tmp;
241 char* p;
242 char* t;
244 va_start(args, format);
245 for (i = 0; format[i]; i++)
247 if (format[i] == '%')
249 switch (format[++i])
251 case 's': t = va_arg(args, char*); if (t) len += strlen(t); break;
252 case 'c': (void)va_arg(args, int); len++; break;
253 default: i--; /* fall through */
254 case '%': len++; break;
257 else len++;
259 va_end(args);
260 if (!(tmp = und_alloc(sym, len))) return NULL;
261 va_start(args, format);
262 for (p = tmp, i = 0; format[i]; i++)
264 if (format[i] == '%')
266 switch (format[++i])
268 case 's':
269 t = va_arg(args, char*);
270 if (t)
272 sz = strlen(t);
273 memcpy(p, t, sz);
274 p += sz;
276 break;
277 case 'c':
278 *p++ = (char)va_arg(args, int);
279 break;
280 default: i--; /* fall through */
281 case '%': *p++ = '%'; break;
284 else *p++ = format[i];
286 va_end(args);
287 *p = '\0';
288 return tmp;
291 /* forward declaration */
292 static BOOL demangle_datatype(struct parsed_symbol* sym, struct datatype_t* ct,
293 struct array* pmt, BOOL in_args);
295 static const char* get_number(struct parsed_symbol* sym)
297 char* ptr;
298 BOOL sgn = FALSE;
300 if (*sym->current == '?')
302 sgn = TRUE;
303 sym->current++;
305 if (*sym->current >= '0' && *sym->current <= '8')
307 ptr = und_alloc(sym, 3);
308 if (sgn) ptr[0] = '-';
309 ptr[sgn ? 1 : 0] = *sym->current + 1;
310 ptr[sgn ? 2 : 1] = '\0';
311 sym->current++;
313 else if (*sym->current == '9')
315 ptr = und_alloc(sym, 4);
316 if (sgn) ptr[0] = '-';
317 ptr[sgn ? 1 : 0] = '1';
318 ptr[sgn ? 2 : 1] = '0';
319 ptr[sgn ? 3 : 2] = '\0';
320 sym->current++;
322 else if (*sym->current >= 'A' && *sym->current <= 'P')
324 int ret = 0;
326 while (*sym->current >= 'A' && *sym->current <= 'P')
328 ret *= 16;
329 ret += *sym->current++ - 'A';
331 if (*sym->current != '@') return NULL;
333 ptr = und_alloc(sym, 17);
334 sprintf(ptr, "%s%u", sgn ? "-" : "", ret);
335 sym->current++;
337 else return NULL;
338 return ptr;
341 /******************************************************************
342 * get_args
343 * Parses a list of function/method arguments, creates a string corresponding
344 * to the arguments' list.
346 static char* get_args(struct parsed_symbol* sym, struct array* pmt_ref, BOOL z_term,
347 char open_char, char close_char)
350 struct datatype_t ct;
351 struct array arg_collect;
352 char* args_str = NULL;
353 char* last;
354 unsigned int i;
356 str_array_init(&arg_collect);
358 /* Now come the function arguments */
359 while (*sym->current)
361 /* Decode each data type and append it to the argument list */
362 if (*sym->current == '@')
364 sym->current++;
365 break;
367 if (!demangle_datatype(sym, &ct, pmt_ref, TRUE))
368 return NULL;
369 /* 'void' terminates an argument list in a function */
370 if (z_term && !strcmp(ct.left, "void")) break;
371 if (!str_array_push(sym, str_printf(sym, "%s%s", ct.left, ct.right), -1,
372 &arg_collect))
373 return NULL;
374 if (!strcmp(ct.left, "...")) break;
376 /* Functions are always terminated by 'Z'. If we made it this far and
377 * don't find it, we have incorrectly identified a data type.
379 if (z_term && *sym->current++ != 'Z') return NULL;
381 if (arg_collect.num == 0 ||
382 (arg_collect.num == 1 && !strcmp(arg_collect.elts[0], "void")))
383 return str_printf(sym, "%cvoid%c", open_char, close_char);
384 for (i = 1; i < arg_collect.num; i++)
386 args_str = str_printf(sym, "%s,%s", args_str, arg_collect.elts[i]);
389 last = args_str ? args_str : arg_collect.elts[0];
390 if (close_char == '>' && last[strlen(last) - 1] == '>')
391 args_str = str_printf(sym, "%c%s%s %c",
392 open_char, arg_collect.elts[0], args_str, close_char);
393 else
394 args_str = str_printf(sym, "%c%s%s%c",
395 open_char, arg_collect.elts[0], args_str, close_char);
397 return args_str;
400 /******************************************************************
401 * get_modifier
402 * Parses the type modifier. Always returns static strings.
404 static BOOL get_modifier(struct parsed_symbol *sym, const char **ret, const char **ptr_modif)
406 *ptr_modif = NULL;
407 if (*sym->current == 'E')
409 if (!(sym->flags & UNDNAME_NO_MS_KEYWORDS))
411 *ptr_modif = "__ptr64";
412 if (sym->flags & UNDNAME_NO_LEADING_UNDERSCORES)
413 *ptr_modif = *ptr_modif + 2;
415 sym->current++;
417 switch (*sym->current++)
419 case 'A': *ret = NULL; break;
420 case 'B': *ret = "const"; break;
421 case 'C': *ret = "volatile"; break;
422 case 'D': *ret = "const volatile"; break;
423 default: return FALSE;
425 return TRUE;
428 static BOOL get_modified_type(struct datatype_t *ct, struct parsed_symbol* sym,
429 struct array *pmt_ref, char modif, BOOL in_args)
431 const char* modifier;
432 const char* str_modif;
433 const char *ptr_modif = "";
435 if (*sym->current == 'E')
437 if (!(sym->flags & UNDNAME_NO_MS_KEYWORDS))
439 if (sym->flags & UNDNAME_NO_LEADING_UNDERSCORES)
440 ptr_modif = " ptr64";
441 else
442 ptr_modif = " __ptr64";
444 sym->current++;
447 switch (modif)
449 case 'A': str_modif = str_printf(sym, " &%s", ptr_modif); break;
450 case 'B': str_modif = str_printf(sym, " &%s volatile", ptr_modif); break;
451 case 'P': str_modif = str_printf(sym, " *%s", ptr_modif); break;
452 case 'Q': str_modif = str_printf(sym, " *%s const", ptr_modif); break;
453 case 'R': str_modif = str_printf(sym, " *%s volatile", ptr_modif); break;
454 case 'S': str_modif = str_printf(sym, " *%s const volatile", ptr_modif); break;
455 case '?': str_modif = ""; break;
456 default: return FALSE;
459 if (get_modifier(sym, &modifier, &ptr_modif))
461 unsigned mark = sym->stack.num;
462 struct datatype_t sub_ct;
464 /* multidimensional arrays */
465 if (*sym->current == 'Y')
467 const char* n1;
468 int num;
470 sym->current++;
471 if (!(n1 = get_number(sym))) return FALSE;
472 num = atoi(n1);
474 if (str_modif[0] == ' ' && !modifier)
475 str_modif++;
477 if (modifier)
479 str_modif = str_printf(sym, " (%s%s)", modifier, str_modif);
480 modifier = NULL;
482 else
483 str_modif = str_printf(sym, " (%s)", str_modif);
485 while (num--)
486 str_modif = str_printf(sym, "%s[%s]", str_modif, get_number(sym));
489 /* Recurse to get the referred-to type */
490 if (!demangle_datatype(sym, &sub_ct, pmt_ref, FALSE))
491 return FALSE;
492 if (modifier)
493 ct->left = str_printf(sym, "%s %s%s", sub_ct.left, modifier, str_modif );
494 else
496 /* don't insert a space between duplicate '*' */
497 if (!in_args && str_modif[0] && str_modif[1] == '*' && sub_ct.left[strlen(sub_ct.left)-1] == '*')
498 str_modif++;
499 ct->left = str_printf(sym, "%s%s", sub_ct.left, str_modif );
501 ct->right = sub_ct.right;
502 sym->stack.num = mark;
504 return TRUE;
507 /******************************************************************
508 * get_literal_string
509 * Gets the literal name from the current position in the mangled
510 * symbol to the first '@' character. It pushes the parsed name to
511 * the symbol names stack and returns a pointer to it or NULL in
512 * case of an error.
514 static char* get_literal_string(struct parsed_symbol* sym)
516 const char *ptr = sym->current;
518 do {
519 if (!((*sym->current >= 'A' && *sym->current <= 'Z') ||
520 (*sym->current >= 'a' && *sym->current <= 'z') ||
521 (*sym->current >= '0' && *sym->current <= '9') ||
522 *sym->current == '_' || *sym->current == '$')) {
523 TRACE("Failed at '%c' in %s\n", *sym->current, ptr);
524 return NULL;
526 } while (*++sym->current != '@');
527 sym->current++;
528 if (!str_array_push(sym, ptr, sym->current - 1 - ptr, &sym->names))
529 return NULL;
531 return str_array_get_ref(&sym->names, sym->names.num - sym->names.start - 1);
534 /******************************************************************
535 * get_template_name
536 * Parses a name with a template argument list and returns it as
537 * a string.
538 * In a template argument list the back reference to the names
539 * table is separately created. '0' points to the class component
540 * name with the template arguments. We use the same stack array
541 * to hold the names but save/restore the stack state before/after
542 * parsing the template argument list.
544 static char* get_template_name(struct parsed_symbol* sym)
546 char *name, *args;
547 unsigned num_mark = sym->names.num;
548 unsigned start_mark = sym->names.start;
549 unsigned stack_mark = sym->stack.num;
550 struct array array_pmt;
552 sym->names.start = sym->names.num;
553 if (!(name = get_literal_string(sym))) {
554 sym->names.start = start_mark;
555 return FALSE;
557 str_array_init(&array_pmt);
558 args = get_args(sym, &array_pmt, FALSE, '<', '>');
559 if (args != NULL)
560 name = str_printf(sym, "%s%s", name, args);
561 sym->names.num = num_mark;
562 sym->names.start = start_mark;
563 sym->stack.num = stack_mark;
564 return name;
567 /******************************************************************
568 * get_class
569 * Parses class as a list of parent-classes, terminated by '@' and stores the
570 * result in 'a' array. Each parent-classes, as well as the inner element
571 * (either field/method name or class name), are represented in the mangled
572 * name by a literal name ([a-zA-Z0-9_]+ terminated by '@') or a back reference
573 * ([0-9]) or a name with template arguments ('?$' literal name followed by the
574 * template argument list). The class name components appear in the reverse
575 * order in the mangled name, e.g aaa@bbb@ccc@@ will be demangled to
576 * ccc::bbb::aaa
577 * For each of these class name components a string will be allocated in the
578 * array.
580 static BOOL get_class(struct parsed_symbol* sym)
582 const char* name = NULL;
584 while (*sym->current != '@')
586 switch (*sym->current)
588 case '\0': return FALSE;
590 case '0': case '1': case '2': case '3':
591 case '4': case '5': case '6': case '7':
592 case '8': case '9':
593 name = str_array_get_ref(&sym->names, *sym->current++ - '0');
594 break;
595 case '?':
596 switch (*++sym->current)
598 case '$':
599 sym->current++;
600 if ((name = get_template_name(sym)) &&
601 !str_array_push(sym, name, -1, &sym->names))
602 return FALSE;
603 break;
604 case '?':
606 struct array stack = sym->stack;
607 unsigned int start = sym->names.start;
608 unsigned int num = sym->names.num;
610 str_array_init( &sym->stack );
611 if (symbol_demangle( sym )) name = str_printf( sym, "`%s'", sym->result );
612 sym->names.start = start;
613 sym->names.num = num;
614 sym->stack = stack;
616 break;
617 default:
618 if (!(name = get_number( sym ))) return FALSE;
619 name = str_printf( sym, "`%s'", name );
620 break;
622 break;
623 default:
624 name = get_literal_string(sym);
625 break;
627 if (!name || !str_array_push(sym, name, -1, &sym->stack))
628 return FALSE;
630 sym->current++;
631 return TRUE;
634 /******************************************************************
635 * get_class_string
636 * From an array collected by get_class in sym->stack, constructs the
637 * corresponding (allocated) string
639 static char* get_class_string(struct parsed_symbol* sym, int start)
641 int i;
642 unsigned int len, sz;
643 char* ret;
644 struct array *a = &sym->stack;
646 for (len = 0, i = start; i < a->num; i++)
648 assert(a->elts[i]);
649 len += 2 + strlen(a->elts[i]);
651 if (!(ret = und_alloc(sym, len - 1))) return NULL;
652 for (len = 0, i = a->num - 1; i >= start; i--)
654 sz = strlen(a->elts[i]);
655 memcpy(ret + len, a->elts[i], sz);
656 len += sz;
657 if (i > start)
659 ret[len++] = ':';
660 ret[len++] = ':';
663 ret[len] = '\0';
664 return ret;
667 /******************************************************************
668 * get_class_name
669 * Wrapper around get_class and get_class_string.
671 static char* get_class_name(struct parsed_symbol* sym)
673 unsigned mark = sym->stack.num;
674 char* s = NULL;
676 if (get_class(sym))
677 s = get_class_string(sym, mark);
678 sym->stack.num = mark;
679 return s;
682 /******************************************************************
683 * get_calling_convention
684 * Returns a static string corresponding to the calling convention described
685 * by char 'ch'. Sets export to TRUE iff the calling convention is exported.
687 static BOOL get_calling_convention(char ch, const char** call_conv,
688 const char** exported, unsigned flags)
690 *call_conv = *exported = NULL;
692 if (!(flags & (UNDNAME_NO_MS_KEYWORDS | UNDNAME_NO_ALLOCATION_LANGUAGE)))
694 if (flags & UNDNAME_NO_LEADING_UNDERSCORES)
696 if (((ch - 'A') % 2) == 1) *exported = "dll_export ";
697 switch (ch)
699 case 'A': case 'B': *call_conv = "cdecl"; break;
700 case 'C': case 'D': *call_conv = "pascal"; break;
701 case 'E': case 'F': *call_conv = "thiscall"; break;
702 case 'G': case 'H': *call_conv = "stdcall"; break;
703 case 'I': case 'J': *call_conv = "fastcall"; break;
704 case 'K': case 'L': break;
705 case 'M': *call_conv = "clrcall"; break;
706 default: ERR("Unknown calling convention %c\n", ch); return FALSE;
709 else
711 if (((ch - 'A') % 2) == 1) *exported = "__dll_export ";
712 switch (ch)
714 case 'A': case 'B': *call_conv = "__cdecl"; break;
715 case 'C': case 'D': *call_conv = "__pascal"; break;
716 case 'E': case 'F': *call_conv = "__thiscall"; break;
717 case 'G': case 'H': *call_conv = "__stdcall"; break;
718 case 'I': case 'J': *call_conv = "__fastcall"; break;
719 case 'K': case 'L': break;
720 case 'M': *call_conv = "__clrcall"; break;
721 default: ERR("Unknown calling convention %c\n", ch); return FALSE;
725 return TRUE;
728 /*******************************************************************
729 * get_simple_type
730 * Return a string containing an allocated string for a simple data type
732 static const char* get_simple_type(char c)
734 const char* type_string;
736 switch (c)
738 case 'C': type_string = "signed char"; break;
739 case 'D': type_string = "char"; break;
740 case 'E': type_string = "unsigned char"; break;
741 case 'F': type_string = "short"; break;
742 case 'G': type_string = "unsigned short"; break;
743 case 'H': type_string = "int"; break;
744 case 'I': type_string = "unsigned int"; break;
745 case 'J': type_string = "long"; break;
746 case 'K': type_string = "unsigned long"; break;
747 case 'M': type_string = "float"; break;
748 case 'N': type_string = "double"; break;
749 case 'O': type_string = "long double"; break;
750 case 'X': type_string = "void"; break;
751 case 'Z': type_string = "..."; break;
752 default: type_string = NULL; break;
754 return type_string;
757 /*******************************************************************
758 * get_extended_type
759 * Return a string containing an allocated string for a simple data type
761 static const char* get_extended_type(char c)
763 const char* type_string;
765 switch (c)
767 case 'D': type_string = "__int8"; break;
768 case 'E': type_string = "unsigned __int8"; break;
769 case 'F': type_string = "__int16"; break;
770 case 'G': type_string = "unsigned __int16"; break;
771 case 'H': type_string = "__int32"; break;
772 case 'I': type_string = "unsigned __int32"; break;
773 case 'J': type_string = "__int64"; break;
774 case 'K': type_string = "unsigned __int64"; break;
775 case 'L': type_string = "__int128"; break;
776 case 'M': type_string = "unsigned __int128"; break;
777 case 'N': type_string = "bool"; break;
778 case 'W': type_string = "wchar_t"; break;
779 default: type_string = NULL; break;
781 return type_string;
784 /*******************************************************************
785 * demangle_datatype
787 * Attempt to demangle a C++ data type, which may be datatype.
788 * a datatype type is made up of a number of simple types. e.g:
789 * char** = (pointer to (pointer to (char)))
791 static BOOL demangle_datatype(struct parsed_symbol* sym, struct datatype_t* ct,
792 struct array* pmt_ref, BOOL in_args)
794 char dt;
795 BOOL add_pmt = TRUE;
797 assert(ct);
798 ct->left = ct->right = NULL;
800 switch (dt = *sym->current++)
802 case '_':
803 /* MS type: __int8,__int16 etc */
804 ct->left = get_extended_type(*sym->current++);
805 break;
806 case 'C': case 'D': case 'E': case 'F': case 'G':
807 case 'H': case 'I': case 'J': case 'K': case 'M':
808 case 'N': case 'O': case 'X': case 'Z':
809 /* Simple data types */
810 ct->left = get_simple_type(dt);
811 add_pmt = FALSE;
812 break;
813 case 'T': /* union */
814 case 'U': /* struct */
815 case 'V': /* class */
816 case 'Y': /* cointerface */
817 /* Class/struct/union/cointerface */
819 const char* struct_name = NULL;
820 const char* type_name = NULL;
822 if (!(struct_name = get_class_name(sym)))
823 goto done;
824 if (!(sym->flags & UNDNAME_NO_COMPLEX_TYPE))
826 switch (dt)
828 case 'T': type_name = "union "; break;
829 case 'U': type_name = "struct "; break;
830 case 'V': type_name = "class "; break;
831 case 'Y': type_name = "cointerface "; break;
834 ct->left = str_printf(sym, "%s%s", type_name, struct_name);
836 break;
837 case '?':
838 /* not all the time is seems */
839 if (in_args)
841 const char* ptr;
842 if (!(ptr = get_number(sym))) goto done;
843 ct->left = str_printf(sym, "`template-parameter-%s'", ptr);
845 else
847 if (!get_modified_type(ct, sym, pmt_ref, '?', in_args)) goto done;
849 break;
850 case 'A': /* reference */
851 case 'B': /* volatile reference */
852 if (!get_modified_type(ct, sym, pmt_ref, dt, in_args)) goto done;
853 break;
854 case 'Q': /* const pointer */
855 case 'R': /* volatile pointer */
856 case 'S': /* const volatile pointer */
857 if (!get_modified_type(ct, sym, pmt_ref, in_args ? dt : 'P', in_args)) goto done;
858 break;
859 case 'P': /* Pointer */
860 if (isdigit(*sym->current))
862 /* FIXME: P6 = Function pointer, others who knows.. */
863 if (*sym->current++ == '6')
865 char* args = NULL;
866 const char* call_conv;
867 const char* exported;
868 struct datatype_t sub_ct;
869 unsigned mark = sym->stack.num;
871 if (!get_calling_convention(*sym->current++,
872 &call_conv, &exported,
873 sym->flags & ~UNDNAME_NO_ALLOCATION_LANGUAGE) ||
874 !demangle_datatype(sym, &sub_ct, pmt_ref, FALSE))
875 goto done;
877 args = get_args(sym, pmt_ref, TRUE, '(', ')');
878 if (!args) goto done;
879 sym->stack.num = mark;
881 ct->left = str_printf(sym, "%s%s (%s*",
882 sub_ct.left, sub_ct.right, call_conv);
883 ct->right = str_printf(sym, ")%s", args);
885 else goto done;
887 else if (!get_modified_type(ct, sym, pmt_ref, 'P', in_args)) goto done;
888 break;
889 case 'W':
890 if (*sym->current == '4')
892 char* enum_name;
893 sym->current++;
894 if (!(enum_name = get_class_name(sym)))
895 goto done;
896 if (sym->flags & UNDNAME_NO_COMPLEX_TYPE)
897 ct->left = enum_name;
898 else
899 ct->left = str_printf(sym, "enum %s", enum_name);
901 else goto done;
902 break;
903 case '0': case '1': case '2': case '3': case '4':
904 case '5': case '6': case '7': case '8': case '9':
905 /* Referring back to previously parsed type */
906 /* left and right are pushed as two separate strings */
907 ct->left = str_array_get_ref(pmt_ref, (dt - '0') * 2);
908 ct->right = str_array_get_ref(pmt_ref, (dt - '0') * 2 + 1);
909 if (!ct->left) goto done;
910 add_pmt = FALSE;
911 break;
912 case '$':
913 switch (*sym->current++)
915 case '0':
916 if (!(ct->left = get_number(sym))) goto done;
917 break;
918 case 'D':
920 const char* ptr;
921 if (!(ptr = get_number(sym))) goto done;
922 ct->left = str_printf(sym, "`template-parameter%s'", ptr);
924 break;
925 case 'F':
927 const char* p1;
928 const char* p2;
929 if (!(p1 = get_number(sym))) goto done;
930 if (!(p2 = get_number(sym))) goto done;
931 ct->left = str_printf(sym, "{%s,%s}", p1, p2);
933 break;
934 case 'G':
936 const char* p1;
937 const char* p2;
938 const char* p3;
939 if (!(p1 = get_number(sym))) goto done;
940 if (!(p2 = get_number(sym))) goto done;
941 if (!(p3 = get_number(sym))) goto done;
942 ct->left = str_printf(sym, "{%s,%s,%s}", p1, p2, p3);
944 break;
945 case 'Q':
947 const char* ptr;
948 if (!(ptr = get_number(sym))) goto done;
949 ct->left = str_printf(sym, "`non-type-template-parameter%s'", ptr);
951 break;
952 case '$':
953 if (*sym->current == 'C')
955 const char *ptr, *ptr_modif;
957 sym->current++;
958 if (!get_modifier(sym, &ptr, &ptr_modif)) goto done;
959 if (!demangle_datatype(sym, ct, pmt_ref, in_args)) goto done;
960 ct->left = str_printf(sym, "%s %s", ct->left, ptr);
962 break;
964 break;
965 default :
966 ERR("Unknown type %c\n", dt);
967 break;
969 if (add_pmt && pmt_ref && in_args)
971 /* left and right are pushed as two separate strings */
972 if (!str_array_push(sym, ct->left ? ct->left : "", -1, pmt_ref) ||
973 !str_array_push(sym, ct->right ? ct->right : "", -1, pmt_ref))
974 return FALSE;
976 done:
978 return ct->left != NULL;
981 /******************************************************************
982 * handle_data
983 * Does the final parsing and handling for a variable or a field in
984 * a class.
986 static BOOL handle_data(struct parsed_symbol* sym)
988 const char* access = NULL;
989 const char* member_type = NULL;
990 const char* modifier = NULL;
991 const char* ptr_modif;
992 struct datatype_t ct;
993 char* name = NULL;
994 BOOL ret = FALSE;
996 /* 0 private static
997 * 1 protected static
998 * 2 public static
999 * 3 private non-static
1000 * 4 protected non-static
1001 * 5 public non-static
1002 * 6 ?? static
1003 * 7 ?? static
1006 if (!(sym->flags & UNDNAME_NO_ACCESS_SPECIFIERS))
1008 /* we only print the access for static members */
1009 switch (*sym->current)
1011 case '0': access = "private: "; break;
1012 case '1': access = "protected: "; break;
1013 case '2': access = "public: "; break;
1017 if (!(sym->flags & UNDNAME_NO_MEMBER_TYPE))
1019 if (*sym->current >= '0' && *sym->current <= '2')
1020 member_type = "static ";
1023 name = get_class_string(sym, 0);
1025 switch (*sym->current++)
1027 case '0': case '1': case '2':
1028 case '3': case '4': case '5':
1030 unsigned mark = sym->stack.num;
1031 struct array pmt;
1033 str_array_init(&pmt);
1035 if (!demangle_datatype(sym, &ct, &pmt, FALSE)) goto done;
1036 if (!get_modifier(sym, &modifier, &ptr_modif)) goto done;
1037 if (modifier && ptr_modif) modifier = str_printf(sym, "%s %s", modifier, ptr_modif);
1038 else if (!modifier) modifier = ptr_modif;
1039 sym->stack.num = mark;
1041 break;
1042 case '6' : /* compiler generated static */
1043 case '7' : /* compiler generated static */
1044 ct.left = ct.right = NULL;
1045 if (!get_modifier(sym, &modifier, &ptr_modif)) goto done;
1046 if (*sym->current != '@')
1048 char* cls = NULL;
1050 if (!(cls = get_class_name(sym)))
1051 goto done;
1052 ct.right = str_printf(sym, "{for `%s'}", cls);
1054 break;
1055 case '8':
1056 case '9':
1057 modifier = ct.left = ct.right = NULL;
1058 break;
1059 default: goto done;
1061 if (sym->flags & UNDNAME_NAME_ONLY) ct.left = ct.right = modifier = NULL;
1063 sym->result = str_printf(sym, "%s%s%s%s%s%s%s%s", access,
1064 member_type, ct.left,
1065 modifier && ct.left ? " " : NULL, modifier,
1066 modifier || ct.left ? " " : NULL, name, ct.right);
1067 ret = TRUE;
1068 done:
1069 return ret;
1072 /******************************************************************
1073 * handle_method
1074 * Does the final parsing and handling for a function or a method in
1075 * a class.
1077 static BOOL handle_method(struct parsed_symbol* sym, BOOL cast_op)
1079 char accmem;
1080 const char* access = NULL;
1081 int access_id = -1;
1082 const char* member_type = NULL;
1083 struct datatype_t ct_ret;
1084 const char* call_conv;
1085 const char* modifier = NULL;
1086 const char* exported;
1087 const char* args_str = NULL;
1088 const char* name = NULL;
1089 BOOL ret = FALSE, has_args = TRUE, has_ret = TRUE;
1090 unsigned mark;
1091 struct array array_pmt;
1093 /* FIXME: why 2 possible letters for each option?
1094 * 'A' private:
1095 * 'B' private:
1096 * 'C' private: static
1097 * 'D' private: static
1098 * 'E' private: virtual
1099 * 'F' private: virtual
1100 * 'G' private: thunk
1101 * 'H' private: thunk
1102 * 'I' protected:
1103 * 'J' protected:
1104 * 'K' protected: static
1105 * 'L' protected: static
1106 * 'M' protected: virtual
1107 * 'N' protected: virtual
1108 * 'O' protected: thunk
1109 * 'P' protected: thunk
1110 * 'Q' public:
1111 * 'R' public:
1112 * 'S' public: static
1113 * 'T' public: static
1114 * 'U' public: virtual
1115 * 'V' public: virtual
1116 * 'W' public: thunk
1117 * 'X' public: thunk
1118 * 'Y'
1119 * 'Z'
1120 * "$0" private: thunk vtordisp
1121 * "$1" private: thunk vtordisp
1122 * "$2" protected: thunk vtordisp
1123 * "$3" protected: thunk vtordisp
1124 * "$4" public: thunk vtordisp
1125 * "$5" public: thunk vtordisp
1126 * "$B" vcall thunk
1127 * "$R" thunk vtordispex
1129 accmem = *sym->current++;
1130 if (accmem == '$')
1132 if (*sym->current >= '0' && *sym->current <= '5')
1133 access_id = (*sym->current - '0') / 2;
1134 else if (*sym->current == 'R')
1135 access_id = (sym->current[1] - '0') / 2;
1136 else if (*sym->current != 'B')
1137 goto done;
1139 else if (accmem >= 'A' && accmem <= 'Z')
1140 access_id = (accmem - 'A') / 8;
1141 else
1142 goto done;
1144 switch (access_id)
1146 case 0: access = "private: "; break;
1147 case 1: access = "protected: "; break;
1148 case 2: access = "public: "; break;
1150 if (accmem == '$' || (accmem - 'A') % 8 == 6 || (accmem - 'A') % 8 == 7)
1151 access = str_printf(sym, "[thunk]:%s", access ? access : " ");
1153 if (accmem == '$' && *sym->current != 'B')
1154 member_type = "virtual ";
1155 else if (accmem <= 'X')
1157 switch ((accmem - 'A') % 8)
1159 case 2: case 3: member_type = "static "; break;
1160 case 4: case 5: case 6: case 7: member_type = "virtual "; break;
1164 if (sym->flags & UNDNAME_NO_ACCESS_SPECIFIERS)
1165 access = NULL;
1166 if (sym->flags & UNDNAME_NO_MEMBER_TYPE)
1167 member_type = NULL;
1169 name = get_class_string(sym, 0);
1171 if (accmem == '$' && *sym->current == 'B') /* vcall thunk */
1173 const char *n;
1175 sym->current++;
1176 n = get_number(sym);
1178 if(!n || *sym->current++ != 'A') goto done;
1179 name = str_printf(sym, "%s{%s,{flat}}' }'", name, n);
1180 has_args = FALSE;
1181 has_ret = FALSE;
1183 else if (accmem == '$' && *sym->current == 'R') /* vtordispex thunk */
1185 const char *n1, *n2, *n3, *n4;
1187 sym->current += 2;
1188 n1 = get_number(sym);
1189 n2 = get_number(sym);
1190 n3 = get_number(sym);
1191 n4 = get_number(sym);
1193 if(!n1 || !n2 || !n3 || !n4) goto done;
1194 name = str_printf(sym, "%s`vtordispex{%s,%s,%s,%s}' ", name, n1, n2, n3, n4);
1196 else if (accmem == '$') /* vtordisp thunk */
1198 const char *n1, *n2;
1200 sym->current++;
1201 n1 = get_number(sym);
1202 n2 = get_number(sym);
1204 if (!n1 || !n2) goto done;
1205 name = str_printf(sym, "%s`vtordisp{%s,%s}' ", name, n1, n2);
1207 else if ((accmem - 'A') % 8 == 6 || (accmem - 'A') % 8 == 7) /* a thunk */
1208 name = str_printf(sym, "%s`adjustor{%s}' ", name, get_number(sym));
1210 if (has_args && (accmem == '$' ||
1211 (accmem <= 'X' && (accmem - 'A') % 8 != 2 && (accmem - 'A') % 8 != 3)))
1213 const char *ptr_modif;
1214 /* Implicit 'this' pointer */
1215 /* If there is an implicit this pointer, const modifier follows */
1216 if (!get_modifier(sym, &modifier, &ptr_modif)) goto done;
1217 if (modifier || ptr_modif) modifier = str_printf(sym, "%s %s", modifier, ptr_modif);
1220 if (!get_calling_convention(*sym->current++, &call_conv, &exported,
1221 sym->flags))
1222 goto done;
1224 str_array_init(&array_pmt);
1226 /* Return type, or @ if 'void' */
1227 if (has_ret && *sym->current == '@')
1229 ct_ret.left = "void";
1230 ct_ret.right = NULL;
1231 sym->current++;
1233 else if (has_ret)
1235 if (!demangle_datatype(sym, &ct_ret, &array_pmt, FALSE))
1236 goto done;
1238 if (!has_ret || sym->flags & UNDNAME_NO_FUNCTION_RETURNS)
1239 ct_ret.left = ct_ret.right = NULL;
1240 if (cast_op)
1242 name = str_printf(sym, "%s%s%s", name, ct_ret.left, ct_ret.right);
1243 ct_ret.left = ct_ret.right = NULL;
1246 mark = sym->stack.num;
1247 if (has_args && !(args_str = get_args(sym, &array_pmt, TRUE, '(', ')'))) goto done;
1248 if (sym->flags & UNDNAME_NAME_ONLY) args_str = modifier = NULL;
1249 if (sym->flags & UNDNAME_NO_THISTYPE) modifier = NULL;
1250 sym->stack.num = mark;
1252 /* Note: '()' after 'Z' means 'throws', but we don't care here
1253 * Yet!!! FIXME
1255 sym->result = str_printf(sym, "%s%s%s%s%s%s%s%s%s%s%s",
1256 access, member_type, ct_ret.left,
1257 (ct_ret.left && !ct_ret.right) ? " " : NULL,
1258 call_conv, call_conv ? " " : NULL, exported,
1259 name, args_str, modifier, ct_ret.right);
1260 ret = TRUE;
1261 done:
1262 return ret;
1265 /*******************************************************************
1266 * symbol_demangle
1267 * Demangle a C++ linker symbol
1269 static BOOL symbol_demangle(struct parsed_symbol* sym)
1271 BOOL ret = FALSE;
1272 unsigned do_after = 0;
1273 static CHAR dashed_null[] = "--null--";
1275 /* FIXME seems wrong as name, as it demangles a simple data type */
1276 if (sym->flags & UNDNAME_NO_ARGUMENTS)
1278 struct datatype_t ct;
1280 if (demangle_datatype(sym, &ct, NULL, FALSE))
1282 sym->result = str_printf(sym, "%s%s", ct.left, ct.right);
1283 ret = TRUE;
1285 goto done;
1288 /* MS mangled names always begin with '?' */
1289 if (*sym->current != '?') return FALSE;
1290 sym->current++;
1292 /* Then function name or operator code */
1293 if (*sym->current == '?' && (sym->current[1] != '$' || sym->current[2] == '?'))
1295 const char* function_name = NULL;
1297 if (sym->current[1] == '$')
1299 do_after = 6;
1300 sym->current += 2;
1303 /* C++ operator code (one character, or two if the first is '_') */
1304 switch (*++sym->current)
1306 case '0': do_after = 1; break;
1307 case '1': do_after = 2; break;
1308 case '2': function_name = "operator new"; break;
1309 case '3': function_name = "operator delete"; break;
1310 case '4': function_name = "operator="; break;
1311 case '5': function_name = "operator>>"; break;
1312 case '6': function_name = "operator<<"; break;
1313 case '7': function_name = "operator!"; break;
1314 case '8': function_name = "operator=="; break;
1315 case '9': function_name = "operator!="; break;
1316 case 'A': function_name = "operator[]"; break;
1317 case 'B': function_name = "operator "; do_after = 3; break;
1318 case 'C': function_name = "operator->"; break;
1319 case 'D': function_name = "operator*"; break;
1320 case 'E': function_name = "operator++"; break;
1321 case 'F': function_name = "operator--"; break;
1322 case 'G': function_name = "operator-"; break;
1323 case 'H': function_name = "operator+"; break;
1324 case 'I': function_name = "operator&"; break;
1325 case 'J': function_name = "operator->*"; break;
1326 case 'K': function_name = "operator/"; break;
1327 case 'L': function_name = "operator%"; break;
1328 case 'M': function_name = "operator<"; break;
1329 case 'N': function_name = "operator<="; break;
1330 case 'O': function_name = "operator>"; break;
1331 case 'P': function_name = "operator>="; break;
1332 case 'Q': function_name = "operator,"; break;
1333 case 'R': function_name = "operator()"; break;
1334 case 'S': function_name = "operator~"; break;
1335 case 'T': function_name = "operator^"; break;
1336 case 'U': function_name = "operator|"; break;
1337 case 'V': function_name = "operator&&"; break;
1338 case 'W': function_name = "operator||"; break;
1339 case 'X': function_name = "operator*="; break;
1340 case 'Y': function_name = "operator+="; break;
1341 case 'Z': function_name = "operator-="; break;
1342 case '_':
1343 switch (*++sym->current)
1345 case '0': function_name = "operator/="; break;
1346 case '1': function_name = "operator%="; break;
1347 case '2': function_name = "operator>>="; break;
1348 case '3': function_name = "operator<<="; break;
1349 case '4': function_name = "operator&="; break;
1350 case '5': function_name = "operator|="; break;
1351 case '6': function_name = "operator^="; break;
1352 case '7': function_name = "`vftable'"; break;
1353 case '8': function_name = "`vbtable'"; break;
1354 case '9': function_name = "`vcall'"; break;
1355 case 'A': function_name = "`typeof'"; break;
1356 case 'B': function_name = "`local static guard'"; break;
1357 case 'C': function_name = "`string'"; do_after = 4; break;
1358 case 'D': function_name = "`vbase destructor'"; break;
1359 case 'E': function_name = "`vector deleting destructor'"; break;
1360 case 'F': function_name = "`default constructor closure'"; break;
1361 case 'G': function_name = "`scalar deleting destructor'"; break;
1362 case 'H': function_name = "`vector constructor iterator'"; break;
1363 case 'I': function_name = "`vector destructor iterator'"; break;
1364 case 'J': function_name = "`vector vbase constructor iterator'"; break;
1365 case 'K': function_name = "`virtual displacement map'"; break;
1366 case 'L': function_name = "`eh vector constructor iterator'"; break;
1367 case 'M': function_name = "`eh vector destructor iterator'"; break;
1368 case 'N': function_name = "`eh vector vbase constructor iterator'"; break;
1369 case 'O': function_name = "`copy constructor closure'"; break;
1370 case 'R':
1371 sym->flags |= UNDNAME_NO_FUNCTION_RETURNS;
1372 switch (*++sym->current)
1374 case '0':
1376 struct datatype_t ct;
1377 struct array pmt;
1379 sym->current++;
1380 str_array_init(&pmt);
1381 demangle_datatype(sym, &ct, &pmt, FALSE);
1382 function_name = str_printf(sym, "%s%s `RTTI Type Descriptor'",
1383 ct.left, ct.right);
1384 sym->current--;
1386 break;
1387 case '1':
1389 const char* n1, *n2, *n3, *n4;
1390 sym->current++;
1391 n1 = get_number(sym);
1392 n2 = get_number(sym);
1393 n3 = get_number(sym);
1394 n4 = get_number(sym);
1395 sym->current--;
1396 function_name = str_printf(sym, "`RTTI Base Class Descriptor at (%s,%s,%s,%s)'",
1397 n1, n2, n3, n4);
1399 break;
1400 case '2': function_name = "`RTTI Base Class Array'"; break;
1401 case '3': function_name = "`RTTI Class Hierarchy Descriptor'"; break;
1402 case '4': function_name = "`RTTI Complete Object Locator'"; break;
1403 default:
1404 ERR("Unknown RTTI operator: _R%c\n", *sym->current);
1405 break;
1407 break;
1408 case 'S': function_name = "`local vftable'"; break;
1409 case 'T': function_name = "`local vftable constructor closure'"; break;
1410 case 'U': function_name = "operator new[]"; break;
1411 case 'V': function_name = "operator delete[]"; break;
1412 case 'X': function_name = "`placement delete closure'"; break;
1413 case 'Y': function_name = "`placement delete[] closure'"; break;
1414 default:
1415 ERR("Unknown operator: _%c\n", *sym->current);
1416 return FALSE;
1418 break;
1419 default:
1420 /* FIXME: Other operators */
1421 ERR("Unknown operator: %c\n", *sym->current);
1422 return FALSE;
1424 sym->current++;
1425 switch (do_after)
1427 case 1: case 2:
1428 if (!str_array_push(sym, dashed_null, -1, &sym->stack))
1429 return FALSE;
1430 break;
1431 case 4:
1432 sym->result = (char*)function_name;
1433 ret = TRUE;
1434 goto done;
1435 case 6:
1437 char *args;
1438 struct array array_pmt;
1440 str_array_init(&array_pmt);
1441 args = get_args(sym, &array_pmt, FALSE, '<', '>');
1442 if (args != NULL) function_name = str_printf(sym, "%s%s", function_name, args);
1443 sym->names.num = 0;
1445 /* fall through */
1446 default:
1447 if (!str_array_push(sym, function_name, -1, &sym->stack))
1448 return FALSE;
1449 break;
1452 else if (*sym->current == '$')
1454 /* Strange construct, it's a name with a template argument list
1455 and that's all. */
1456 sym->current++;
1457 ret = (sym->result = get_template_name(sym)) != NULL;
1458 goto done;
1460 else if (*sym->current == '?' && sym->current[1] == '$')
1461 do_after = 5;
1463 /* Either a class name, or '@' if the symbol is not a class member */
1464 switch (*sym->current)
1466 case '@': sym->current++; break;
1467 case '$': break;
1468 default:
1469 /* Class the function is associated with, terminated by '@@' */
1470 if (!get_class(sym)) goto done;
1471 break;
1474 switch (do_after)
1476 case 0: default: break;
1477 case 1: case 2:
1478 /* it's time to set the member name for ctor & dtor */
1479 if (sym->stack.num <= 1) goto done;
1480 if (do_after == 1)
1481 sym->stack.elts[0] = sym->stack.elts[1];
1482 else
1483 sym->stack.elts[0] = str_printf(sym, "~%s", sym->stack.elts[1]);
1484 /* ctors and dtors don't have return type */
1485 sym->flags |= UNDNAME_NO_FUNCTION_RETURNS;
1486 break;
1487 case 3:
1488 sym->flags &= ~UNDNAME_NO_FUNCTION_RETURNS;
1489 break;
1490 case 5:
1491 sym->names.start++;
1492 break;
1495 /* Function/Data type and access level */
1496 if (*sym->current >= '0' && *sym->current <= '9')
1497 ret = handle_data(sym);
1498 else if ((*sym->current >= 'A' && *sym->current <= 'Z') || *sym->current == '$')
1499 ret = handle_method(sym, do_after == 3);
1500 else ret = FALSE;
1501 done:
1502 if (ret) assert(sym->result);
1503 else WARN("Failed at %s\n", sym->current);
1505 return ret;
1508 /*********************************************************************
1509 * __unDNameEx (MSVCRT.@)
1511 * Demangle a C++ identifier.
1513 * PARAMS
1514 * buffer [O] If not NULL, the place to put the demangled string
1515 * mangled [I] Mangled name of the function
1516 * buflen [I] Length of buffer
1517 * memget [I] Function to allocate memory with
1518 * memfree [I] Function to free memory with
1519 * unknown [?] Unknown, possibly a call back
1520 * flags [I] Flags determining demangled format
1522 * RETURNS
1523 * Success: A string pointing to the unmangled name, allocated with memget.
1524 * Failure: NULL.
1526 char* CDECL __unDNameEx(char* buffer, const char* mangled, int buflen,
1527 malloc_func_t memget, free_func_t memfree,
1528 void* unknown, unsigned short int flags)
1530 struct parsed_symbol sym;
1531 const char* result;
1533 TRACE("(%p,%s,%d,%p,%p,%p,%x)\n",
1534 buffer, mangled, buflen, memget, memfree, unknown, flags);
1536 /* The flags details is not documented by MS. However, it looks exactly
1537 * like the UNDNAME_ manifest constants from imagehlp.h and dbghelp.h
1538 * So, we copied those (on top of the file)
1540 memset(&sym, 0, sizeof(struct parsed_symbol));
1541 if (flags & UNDNAME_NAME_ONLY)
1542 flags |= UNDNAME_NO_FUNCTION_RETURNS | UNDNAME_NO_ACCESS_SPECIFIERS |
1543 UNDNAME_NO_MEMBER_TYPE | UNDNAME_NO_ALLOCATION_LANGUAGE |
1544 UNDNAME_NO_COMPLEX_TYPE;
1546 sym.flags = flags;
1547 sym.mem_alloc_ptr = memget;
1548 sym.mem_free_ptr = memfree;
1549 sym.current = mangled;
1550 str_array_init( &sym.names );
1551 str_array_init( &sym.stack );
1553 result = symbol_demangle(&sym) ? sym.result : mangled;
1554 if (buffer && buflen)
1556 lstrcpynA( buffer, result, buflen);
1558 else
1560 buffer = memget(strlen(result) + 1);
1561 if (buffer) strcpy(buffer, result);
1564 und_free_all(&sym);
1566 return buffer;
1570 /*********************************************************************
1571 * __unDName (MSVCRT.@)
1573 char* CDECL __unDName(char* buffer, const char* mangled, int buflen,
1574 malloc_func_t memget, free_func_t memfree,
1575 unsigned short int flags)
1577 return __unDNameEx(buffer, mangled, buflen, memget, memfree, NULL, flags);