www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Some thoughts on std.demangle

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:

"float test.factorial!(double 4.2, char[5] \"hello\"c, void* 

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:

	e 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:


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:


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
Apr 24 2010