145
|
1 // Written in the D programming language.
|
|
2
|
|
3 /**
|
|
4 * Demangle D mangled names.
|
|
5 *
|
|
6 * Copyright: Copyright Digital Mars 2000 - 2009.
|
|
7 * License: $(HTTP www.boost.org/LICENSE_1_0.txt, Boost License 1.0).
|
|
8 * Authors: $(HTTP digitalmars.com, Walter Bright),
|
|
9 * Thomas K$(UUML)hne, Frits van Bommel
|
|
10 * Source: $(PHOBOSSRC std/_demangle.d)
|
|
11 * $(SCRIPT inhibitQuickIndex = 1;)
|
|
12 */
|
|
13 /*
|
|
14 * Copyright Digital Mars 2000 - 2009.
|
|
15 * Distributed under the Boost Software License, Version 1.0.
|
|
16 * (See accompanying file LICENSE_1_0.txt or copy at
|
|
17 * http://www.boost.org/LICENSE_1_0.txt)
|
|
18 */
|
|
19 module std.demangle;
|
|
20
|
|
21 /+
|
|
22 private class MangleException : Exception
|
|
23 {
|
|
24 this()
|
|
25 {
|
|
26 super("MangleException");
|
|
27 }
|
|
28 }
|
|
29 +/
|
|
30
|
|
31 /*****************************
|
|
32 * Demangle D mangled names.
|
|
33 *
|
|
34 * If it is not a D mangled name, it returns its argument name.
|
|
35 * Example:
|
|
36 * This program reads standard in and writes it to standard out,
|
|
37 * pretty-printing any found D mangled names.
|
|
38 -------------------
|
|
39 import core.stdc.stdio : stdin;
|
|
40 import std.stdio;
|
|
41 import std.ascii;
|
|
42 import std.demangle;
|
|
43
|
|
44 void test(int x, float y) { }
|
|
45
|
|
46 int main()
|
|
47 {
|
|
48 string buffer;
|
|
49 bool inword;
|
|
50 int c;
|
|
51
|
|
52 writefln("Try typing in: %s", test.mangleof);
|
|
53 while ((c = fgetc(stdin)) != EOF)
|
|
54 {
|
|
55 if (inword)
|
|
56 {
|
|
57 if (c == '_' || isAlphaNum(c))
|
|
58 buffer ~= cast(char) c;
|
|
59 else
|
|
60 {
|
|
61 inword = false;
|
|
62 write(demangle(buffer), cast(char) c);
|
|
63 }
|
|
64 }
|
|
65 else
|
|
66 { if (c == '_' || isAlpha(c))
|
|
67 {
|
|
68 inword = true;
|
|
69 buffer.length = 0;
|
|
70 buffer ~= cast(char) c;
|
|
71 }
|
|
72 else
|
|
73 write(cast(char) c);
|
|
74 }
|
|
75 }
|
|
76 if (inword)
|
|
77 write(demangle(buffer));
|
|
78 return 0;
|
|
79 }
|
|
80 -------------------
|
|
81 */
|
|
82
|
|
83 string demangle(string name)
|
|
84 {
|
|
85 import core.demangle : demangle;
|
|
86 import std.exception : assumeUnique;
|
|
87 auto ret = demangle(name);
|
|
88 return assumeUnique(ret);
|
|
89 }
|