Some thoughts on std.demangle
Jacob Carlborg
doob at me.com
Sat Apr 24 08:10:06 PDT 2010
I've been looking at the std.demangle code quite a lot lately (trying to
modify it to suit my needs). One thing I noted in particular, the
handling of floats/doubles/reals as template values seem to be
incorrect. For example, looking at the unittest in the bottom of the
file one of the tests looks like this:
"_D4test58__T9factorialVde67666666666666860140VG5aa5_68656c6c6fVPvnZ9factorialf",
"float test.factorial!(double 4.2, char[5] \"hello\"c, void*
null).factorial"
Where the first row is the mangled name and the second is the demangled
name. According to the ABI specification on mangled names the mangled
from of a template value that is a float/double/real looks like this:
Value:
e HexFloat
HexFloat:
N HexDigits P Exponent
HexDigits P Exponent
In the the above mangled name there is no 'P' and the exponent is
missing as far as I can see. According to the specification the mangled
name should look something like this:
_D4test58__T9factorialVde67666666666666860140P<exponent>VG5aa5_68656c6c6fVPvnZ9factorialf
Where <exponent> is the exponent. If I look at the mangled symbol
(produced by DMD) of a method like this:
module main;
class Foo
{
void fooBar (float f) ()
}
It has the right mangled name which is:
_D4main3Foo33__T6fooBarVde8666666666666667PN1Z6fooBarMFZv
With the 'P' and the exponent in place. If I try to demangle a correctly
mangled name like the one above std.demangle fails to demangle it. It
tries to convert the 'P' to a hex digit, which will fail and then i just
returns the mangled name.
Another thing is that std.demangle doesn't seem to handle newer D2
additions like function attributes (pure, ref, safe and so on), Wild and
TypeNewArray. I'm not quite sure what "Wild" is. I guess "TypeNewArray"
is the new arrays that are value types.
Should report these issues or am I missing something ?
/Jacob Carlborg
More information about the Digitalmars-d
mailing list