On Wed, Jul 10, 2013 at 10:30 AM, Adam D. Ruppe <[email protected]>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. > also, can you push it to your misc-stuff-including-D-programming-language-web-stuff git repo?
