On 14 May 2015 at 15:24, Jeff Law <l...@redhat.com> wrote:
> On 05/13/2015 02:51 AM, Iain Buclaw wrote:
>>
>> In my tests, this gives the demangler near-complete support.  Of a
>> sample of about 75k symbols pulled from the standard library
>> unittester, all but 20 were successfully parsed.
>>
>> ---
>> libiberty/ChangeLog:
>>
>> 2015-05-13 Iain Buclaw<ibuc...@gdcproject.org>
>>
>>      * d-demangle.c (dlang_symbol_kinds): New enum.
>>      (dlang_parse_symbol): Update signature.  Handle an ambiguity between
>> mangle
>>      symbol for pascal and template value arguments.  Only check for a
>> type
>>      if parsing a function, or at the top level.  Return failure if the
>>      entire symbol was not successfully demangled.
>>      (dlang_identifier): Update signature.  Handle an ambiguity between
>> two
>>      adjacent digits in a mangled symbol string.
>>      (dlang_type): Update call to dlang_parse_symbol.
>>      (dlang_template_args): Likewise.
>>      (dlang_parse_template): Likewise.
>>      (dlang_demangle): Likewise.
>>      * testsuite/d-demangle-expected: Fix bad tests found, and add
>> problematic
>>      examples to the unittests.
>
> OK.
>
> I'm going to trust the code to dis-ambiguate the adjacent digits in
> dlang_identifier is correct.  The rest of the changes were pretty easy to
> follow :-0
>

This was the hardest one to get right! ;-)

In the briefest of possible explanations, for the following symbol:

S213std11parallelism3run

We go through the following loop:

(ptr = std11parallelism3run, len = 213)
  => Pointer doesn't start with a digit or _D, move back by 1.
(ptr = 3std11parallelism3run, len = 21)
  => Parse returns std.parallelism.run, length matches, return success!

In a fail example, for instance if we instead had 214:

(ptr = std11parallelism3run, len = 214)
  => Pointer doesn't start with a digit or _D, move back by 1.
(ptr = 4std11parallelism3run, len = 21)
  => Parse returns std1.p, length doesn't match, move pointer back by 1.
(ptr = 14std11parallelism3run, len = 2)
  => Parse returns std11paralleli, length doesn't match, move pointer back by 1.
(ptr = 214std11parallelism3run, len = 214)
  => Reached the beginning, reset length and parse the entire symbol.
Length is too big, return NULL.


Granted, there could be some very small room for false positives, but
if we find an match that succeeds incorrectly, there is very little
change that the rest of the symbol will be demangled correctly.

Regards
Iain.

Reply via email to