diff options
author | ian <ian@138bc75d-0d04-0410-961f-82ee72b054a4> | 2004-02-24 02:49:24 +0000 |
---|---|---|
committer | ian <ian@138bc75d-0d04-0410-961f-82ee72b054a4> | 2004-02-24 02:49:24 +0000 |
commit | dbe9febb2d1cf84b4ccea91708a5e911ffc2ba0e (patch) | |
tree | bc72851c9f3e87d5398c7bdd12449baa2f2afa7b /libiberty/cp-demangle.c | |
parent | 0765a988107643715d97ce1e022f7fd5cb9df134 (diff) | |
download | gcc-dbe9febb2d1cf84b4ccea91708a5e911ffc2ba0e.tar.gz |
2004-02-23 Ian Lance Taylor <ian@wasabisystems.com>
* cp-demangle.c (__cxa_demangle): It is not an error if status is
not NULL. It is an error if the mangled name is the same as a
built-in type name.
(main): If IN_GLIBCPP_V3 is defined, test __cxa_demangle rather
than cplus_demangle_v3.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@78348 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libiberty/cp-demangle.c')
-rw-r--r-- | libiberty/cp-demangle.c | 57 |
1 files changed, 46 insertions, 11 deletions
diff --git a/libiberty/cp-demangle.c b/libiberty/cp-demangle.c index 19f191ed8b8..4d0dd7e5b70 100644 --- a/libiberty/cp-demangle.c +++ b/libiberty/cp-demangle.c @@ -3944,18 +3944,32 @@ __cxa_demangle (mangled_name, output_buffer, length, status) char *demangled; size_t alc; - if (status == NULL) - return NULL; - if (mangled_name == NULL) { - *status = -3; + if (status != NULL) + *status = -3; return NULL; } if (output_buffer != NULL && length == NULL) { - *status = -3; + if (status != NULL) + *status = -3; + return NULL; + } + + /* The specification for __cxa_demangle() is that if the mangled + name could be either an extern "C" identifier, or an internal + built-in type name, then we resolve it as the identifier. All + internal built-in type names are a single lower case character. + Frankly, this simplistic disambiguation doesn't make sense to me, + but it is documented, so we implement it here. */ + if (mangled_name[1] == '\0' + && IS_LOWER (mangled_name[0]) + && cplus_demangle_builtin_types[mangled_name[0] - 'a'].name != NULL) + { + if (status != NULL) + *status = -2; return NULL; } @@ -3963,10 +3977,13 @@ __cxa_demangle (mangled_name, output_buffer, length, status) if (demangled == NULL) { - if (alc == 1) - *status = -1; - else - *status = -2; + if (status != NULL) + { + if (alc == 1) + *status = -1; + else + *status = -2; + } return NULL; } @@ -3990,7 +4007,8 @@ __cxa_demangle (mangled_name, output_buffer, length, status) } } - *status = 0; + if (status != NULL) + *status = 0; return demangled; } @@ -4296,7 +4314,11 @@ main (argc, argv) if (dyn_string_length (mangled) > 0) { +#ifdef IN_GLIBCPP_V3 + s = __cxa_demangle (dyn_string_buf (mangled), NULL, NULL, NULL); +#else s = cplus_demangle_v3 (dyn_string_buf (mangled), options); +#endif if (s != NULL) { @@ -4328,9 +4350,16 @@ main (argc, argv) for (i = optind; i < argc; ++i) { char *s; +#ifdef IN_GLIBCPP_V3 + int status; +#endif /* Attempt to demangle. */ +#ifdef IN_GLIBCPP_V3 + s = __cxa_demangle (argv[i], NULL, NULL, &status); +#else s = cplus_demangle_v3 (argv[i], options); +#endif /* If it worked, print the demangled name. */ if (s != NULL) @@ -4339,7 +4368,13 @@ main (argc, argv) free (s); } else - fprintf (stderr, "Failed: %s\n", argv[i]); + { +#ifdef IN_GLIBCPP_V3 + fprintf (stderr, "Failed: %s (status %d)\n", argv[i], status); +#else + fprintf (stderr, "Failed: %s\n", argv[i]); +#endif + } } } |