From 5d46e1bcfc92bf06a9ca3b3f1c5bb1dc024d9ecd Mon Sep 17 00:00:00 2001 From: Haakan Younes Date: Mon, 7 Jan 2019 01:30:23 -0500 Subject: [PATCH] Add demangle support for ABI tags. (#416) Support ABI tags after in demangle.cc. Update the reference URL. Fixes #50 --- src/demangle.cc | 29 ++++++++++++++++++++++++----- src/demangle_unittest.txt | 4 ++++ 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/src/demangle.cc b/src/demangle.cc index dd26914d4..9369f9a65 100644 --- a/src/demangle.cc +++ b/src/demangle.cc @@ -30,7 +30,7 @@ // Author: Satoru Takabayashi // // For reference check out: -// http://www.codesourcery.com/public/cxx-abi/abi.html#mangling +// http://itanium-cxx-abi.github.io/cxx-abi/abi.html#mangling // // Note that we only have partial C++0x support yet. @@ -423,6 +423,8 @@ static bool ParseNumber(State *state, int *number_out); static bool ParseFloatNumber(State *state); static bool ParseSeqId(State *state); static bool ParseIdentifier(State *state, int length); +static bool ParseAbiTags(State *state); +static bool ParseAbiTag(State *state); static bool ParseOperatorName(State *state); static bool ParseSpecialName(State *state); static bool ParseCallOffset(State *state); @@ -594,13 +596,13 @@ static bool ParsePrefix(State *state) { // ::= // ::= -// ::= -// ::= +// ::= [] +// ::= [] static bool ParseUnqualifiedName(State *state) { return (ParseOperatorName(state) || ParseCtorDtorName(state) || - ParseSourceName(state) || - ParseLocalSourceName(state)); + (ParseSourceName(state) && Optional(ParseAbiTags(state))) || + (ParseLocalSourceName(state) && Optional(ParseAbiTags(state)))); } // ::= @@ -703,6 +705,23 @@ static bool ParseIdentifier(State *state, int length) { return true; } +// ::= [] +static bool ParseAbiTags(State *state) { + State copy = *state; + DisableAppend(state); + if (OneOrMore(ParseAbiTag, state)) { + RestoreAppend(state, copy.append); + return true; + } + *state = copy; + return false; +} + +// ::= B +static bool ParseAbiTag(State *state) { + return ParseOneCharToken(state, 'B') && ParseSourceName(state); +} + // ::= nw, and other two letters cases // ::= cv # (cast) // ::= v # vendor extended operator diff --git a/src/demangle_unittest.txt b/src/demangle_unittest.txt index fd6aca012..07e28bce2 100644 --- a/src/demangle_unittest.txt +++ b/src/demangle_unittest.txt @@ -43,6 +43,10 @@ _ZNcvT_IiEEv operator ?<>() # "<< <" case. _ZlsI3fooE operator<< <> +# ABI tags. +_Z1AB3barB3foo A +_ZN3fooL3barB5cxx11E foo::bar + # Random things we found interesting. _ZN3FooISt6vectorISsSaISsEEEclEv Foo<>::operator()() _ZTI9Callback1IiE Callback1<>