inverse of std.demangle?
Timothee Cour
thelastmammoth at gmail.com
Wed Jul 10 10:44:37 PDT 2013
Thanks much, that's a good start.
Template support would definitely be needed as it's so common.
This should go in std.demangle (or maybe a new std.mangle)
* One use case is using it in shared libraries:
user asks for a symbol via its demangled string representation (which is
most natural for user), then the string is mangled, and then calls dlsym to
retrieve the actual pointer to symbol in the shared lib.
* Another is in REPL where we can optimize certain calls by bypassing the
compiler, when the symbol already exists in main executable.
* There are other use cases
So this is worth doing.
On Wed, Jul 10, 2013 at 10:30 AM, Adam D. Ruppe
<destructionator at gmail.com>wrote:
> On Wednesday, 10 July 2013 at 16:30:25 UTC, Timothee Cour wrote:
>
>> Do you have a pointer for that function in dmd ?
>>
>
> The compiler doesn't do it as one function, I mean it can parse as string
> and mangle it in the process of compiling code.
>
> To go from demangled string => mangled string, you'd first parse the
> demangled string as a declaration and turn it into a symbol, then mangle
> that symbol.
>
>
> But.... if you just want to do really simple cases, maybe this isn't too
> hard. I just quickly slapped this file together:
>
> http://arsdnet.net/dcode/**mangle.d <http://arsdnet.net/dcode/mangle.d>
>
>
> It is very basic, but might work for a lot of cases - it handled some
> basic functions I tried. Perhaps not too hard to add support for more from
> here.
>
> As you can see by looking at the code, the way it works is:
>
> 1) tokenize the input string (it does this in a stupid way, and doesn't
> know all of D's symbols and keywords, but it doesn't have to be too smart
> since demangle produces fairly predictable input, so I think it will be ok).
>
> 2) runs a simple, stupid parser to get the components of the function -
> return type, name, and arguments. To add support for templates, extern(C),
> and so on, this would need to be expanded.
>
> 3) put the pieces back together in a wholly mangled form, borrowing one
> helper array from core.demangle.
>
>
>
> There's a main function at the bottom of the file that does one of the few
> tests I tried with it.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20130710/43a24a86/attachment.html>
More information about the Digitalmars-d-learn
mailing list