Skip to content

Commit

Permalink
Add demangle support for ABI tags. (#416)
Browse files Browse the repository at this point in the history
Support ABI tags after <local-source-name> in demangle.cc.
Update the reference URL.

Fixes #50
  • Loading branch information
hlsyounes authored and ukai committed Jan 7, 2019
1 parent 7fcb278 commit 5d46e1b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
29 changes: 24 additions & 5 deletions src/demangle.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -594,13 +596,13 @@ static bool ParsePrefix(State *state) {

// <unqualified-name> ::= <operator-name>
// ::= <ctor-dtor-name>
// ::= <source-name>
// ::= <local-source-name>
// ::= <source-name> [<abi-tags>]
// ::= <local-source-name> [<abi-tags>]
static bool ParseUnqualifiedName(State *state) {
return (ParseOperatorName(state) ||
ParseCtorDtorName(state) ||
ParseSourceName(state) ||
ParseLocalSourceName(state));
(ParseSourceName(state) && Optional(ParseAbiTags(state))) ||
(ParseLocalSourceName(state) && Optional(ParseAbiTags(state))));
}

// <source-name> ::= <positive length number> <identifier>
Expand Down Expand Up @@ -703,6 +705,23 @@ static bool ParseIdentifier(State *state, int length) {
return true;
}

// <abi-tags> ::= <abi-tag> [<abi-tags>]
static bool ParseAbiTags(State *state) {
State copy = *state;
DisableAppend(state);
if (OneOrMore(ParseAbiTag, state)) {
RestoreAppend(state, copy.append);
return true;
}
*state = copy;
return false;
}

// <abi-tag> ::= B <source-name>
static bool ParseAbiTag(State *state) {
return ParseOneCharToken(state, 'B') && ParseSourceName(state);
}

// <operator-name> ::= nw, and other two letters cases
// ::= cv <type> # (cast)
// ::= v <digit> <source-name> # vendor extended operator
Expand Down
4 changes: 4 additions & 0 deletions src/demangle_unittest.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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<>
Expand Down

0 comments on commit 5d46e1b

Please sign in to comment.