Skip to content

Commit 688da30

Browse files
authored
Merge pull request #6334 from JackStouffer/demangle-modernize
Modernize std.demangle merged-on-behalf-of: Jack Stouffer <[email protected]>
2 parents 0d77663 + 8c84c58 commit 688da30

File tree

3 files changed

+42
-63
lines changed

3 files changed

+42
-63
lines changed

.dscanner.ini

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,6 @@ has_public_example="-etc.c.curl,\
141141
-std.datetime.stopwatch,\
142142
-std.datetime.systime,\
143143
-std.datetime.timezone,\
144-
-std.demangle,\
145144
-std.digest,\
146145
-std.digest.hmac,\
147146
-std.digest.murmurhash,\
@@ -219,7 +218,7 @@ object_const_check="-std.algorithm.searching,-std.array,-std.bitmanip,-std.concu
219218
; Checks that opEquals and toHash are both defined or neither are defined
220219
opequals_tohash_check="-std.algorithm.searching,-std.array,-std.complex,-std.container.array,-std.container.dlist,-std.container.rbtree,-std.container.slist,-std.datetime,-std.datetime.date,-std.experimental.checkedint,-std.functional,-std.internal.test.dummyrange,-std.json,-std.numeric,-std.random,-std.range,-std.socket,-std.traits,-std.typecons,-std.uni"
221220
; Check for properly documented public functions (Returns, Params)
222-
properly_documented_public_functions="-etc.c.odbc.sql,-etc.c.odbc.sqlext,-etc.c.zlib,-std.algorithm.comparison,-std.algorithm.iteration,-std.algorithm.mutation,-std.algorithm.searching,-std.algorithm.setops,-std.algorithm.sorting,-std.array,-std.ascii,-std.base64,-std.bigint,-std.bitmanip,-std.complex,-std.container,-std.container.array,-std.container.binaryheap,-std.container.dlist,-std.container.rbtree,-std.container.slist,-std.container.util,-std.csv,-std.datetime,-std.datetime.date,-std.datetime.interval,-std.datetime.stopwatch,-std.datetime.systime,-std.datetime.timezone,-std.demangle,-std.digest.crc,-std.digest,-std.digest.hmac,-std.digest.md,-std.digest.murmurhash,-std.digest.ripemd,-std.digest.sha,-std.encoding,-std.exception,-std.experimental.allocator,-std.experimental.allocator.building_blocks.affix_allocator,-std.experimental.allocator.building_blocks.allocator_list,-std.experimental.allocator.building_blocks.bitmapped_block,-std.experimental.allocator.building_blocks.bucketizer,-std.experimental.allocator.building_blocks.fallback_allocator,-std.experimental.allocator.building_blocks.free_list,-std.experimental.allocator.building_blocks.free_tree,-std.experimental.allocator.building_blocks.kernighan_ritchie,-std.experimental.allocator.building_blocks.null_allocator,-std.experimental.allocator.building_blocks.quantizer,-std.experimental.allocator.building_blocks.region,-std.experimental.allocator.building_blocks.scoped_allocator,-std.experimental.allocator.building_blocks.segregator,-std.experimental.allocator.building_blocks.stats_collector,-std.experimental.allocator.common,-std.experimental.allocator.gc_allocator,-std.experimental.allocator.mallocator,-std.experimental.allocator.showcase,-std.experimental.allocator.typed,-std.experimental.checkedint,-std.experimental.logger.core,-std.experimental.logger.filelogger,-std.file,-std.format,-std.functional,-std.getopt,-std.internal.cstring,-std.internal.math.biguintcore,-std.internal.math.biguintnoasm,-std.internal.scopebuffer,-std.internal.test.dummyrange,-std.internal.unicode_tables,-std.json,-std.math,-std.mathspecial,-std.meta,-std.mmfile,-std.net.curl,-std.net.isemail,-std.numeric,-std.outbuffer,-std.parallelism,-std.path,-std.random,-std.range,-std.range.interfaces,-std.range.primitives,-std.regex,-std.regex.internal.backtracking,-std.regex.internal.ir,-std.regex.internal.kickstart,-std.regex.internal.parser,-std.regex.internal.thompson,-std.signals,-std.socket,-std.stdio,-std.string,-std.traits,-std.typecons,-std.uni,-std.uri,-std.utf,-std.uuid,-std.variant,-std.xml,-std.zip,-std.zlib"
221+
properly_documented_public_functions="-etc.c.odbc.sql,-etc.c.odbc.sqlext,-etc.c.zlib,-std.algorithm.comparison,-std.algorithm.iteration,-std.algorithm.mutation,-std.algorithm.searching,-std.algorithm.setops,-std.algorithm.sorting,-std.array,-std.ascii,-std.base64,-std.bigint,-std.bitmanip,-std.complex,-std.container,-std.container.array,-std.container.binaryheap,-std.container.dlist,-std.container.rbtree,-std.container.slist,-std.container.util,-std.csv,-std.datetime,-std.datetime.date,-std.datetime.interval,-std.datetime.stopwatch,-std.datetime.systime,-std.datetime.timezone,-std.digest.crc,-std.digest,-std.digest.hmac,-std.digest.md,-std.digest.murmurhash,-std.digest.ripemd,-std.digest.sha,-std.encoding,-std.exception,-std.experimental.allocator,-std.experimental.allocator.building_blocks.affix_allocator,-std.experimental.allocator.building_blocks.allocator_list,-std.experimental.allocator.building_blocks.bitmapped_block,-std.experimental.allocator.building_blocks.bucketizer,-std.experimental.allocator.building_blocks.fallback_allocator,-std.experimental.allocator.building_blocks.free_list,-std.experimental.allocator.building_blocks.free_tree,-std.experimental.allocator.building_blocks.kernighan_ritchie,-std.experimental.allocator.building_blocks.null_allocator,-std.experimental.allocator.building_blocks.quantizer,-std.experimental.allocator.building_blocks.region,-std.experimental.allocator.building_blocks.scoped_allocator,-std.experimental.allocator.building_blocks.segregator,-std.experimental.allocator.building_blocks.stats_collector,-std.experimental.allocator.common,-std.experimental.allocator.gc_allocator,-std.experimental.allocator.mallocator,-std.experimental.allocator.showcase,-std.experimental.allocator.typed,-std.experimental.checkedint,-std.experimental.logger.core,-std.experimental.logger.filelogger,-std.file,-std.format,-std.functional,-std.getopt,-std.internal.cstring,-std.internal.math.biguintcore,-std.internal.math.biguintnoasm,-std.internal.scopebuffer,-std.internal.test.dummyrange,-std.internal.unicode_tables,-std.json,-std.math,-std.mathspecial,-std.meta,-std.mmfile,-std.net.curl,-std.net.isemail,-std.numeric,-std.outbuffer,-std.parallelism,-std.path,-std.random,-std.range,-std.range.interfaces,-std.range.primitives,-std.regex,-std.regex.internal.backtracking,-std.regex.internal.ir,-std.regex.internal.kickstart,-std.regex.internal.parser,-std.regex.internal.thompson,-std.signals,-std.socket,-std.stdio,-std.string,-std.traits,-std.typecons,-std.uni,-std.uri,-std.utf,-std.uuid,-std.variant,-std.xml,-std.zip,-std.zlib"
223222
; Check for redundant attributes
224223
redundant_attributes_check="-std.concurrency,-std.digest.md,-std.digest.ripemd,-std.digest.sha,-std.internal.math.biguintcore,-std.math,-std.meta,-std.range,-std.regex.internal.ir,-std.uni,-std.windows.registry"
225224
; Check variable, class, struct, interface, union, and function names against

std/demangle.d

Lines changed: 40 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -18,72 +18,52 @@
1818
*/
1919
module std.demangle;
2020

21-
/+
22-
private class MangleException : Exception
21+
/**
22+
Demangle D mangled names.
23+
24+
Params:
25+
name = the mangled name
26+
Returns:
27+
A `string`. If it is not a D mangled name, it returns its argument name.
28+
*/
29+
string demangle(string name) @safe pure nothrow
2330
{
24-
this()
25-
{
26-
super("MangleException");
27-
}
31+
import core.demangle : demangle;
32+
import std.exception : assumeUnique;
33+
auto ret = demangle(name);
34+
return () @trusted { return ret.assumeUnique; } ();
2835
}
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;
4336

44-
void test(int x, float y) { }
37+
///
38+
@safe pure unittest
39+
{
40+
// int b in module a
41+
assert(demangle("_D1a1bi") == "int a.b");
42+
// char array foo in module test
43+
assert(demangle("_D4test3fooAa") == "char[] test.foo");
44+
}
4545

46-
int main()
46+
/**
47+
This program reads standard in and writes it to standard out,
48+
pretty-printing any found D mangled names.
49+
*/
50+
@system unittest
4751
{
48-
string buffer;
49-
bool inword;
50-
int c;
52+
import std.ascii : isAlphaNum;
53+
import std.algorithm.iteration : chunkBy, joiner, map;
54+
import std.algorithm.mutation : copy;
55+
import std.conv : to;
56+
import std.demangle : demangle;
57+
import std.functional : pipe;
58+
import std.stdio : stdin, stdout;
5159

52-
writefln("Try typing in: %s", test.mangleof);
53-
while ((c = fgetc(stdin)) != EOF)
60+
void main()
5461
{
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-
}
62+
stdin.byLineCopy
63+
.map!(
64+
l => l.chunkBy!(a => isAlphaNum(a) || a == '_')
65+
.map!(a => a[1].pipe!(to!string, demangle)).joiner
66+
)
67+
.copy(stdout.lockingTextWriter);
7568
}
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);
8969
}

unittest.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ int main(string[] args)
9797
cast(void) std.math.sin(3.0);
9898
cast(void) std.mathspecial.gamma(6.2);
9999

100-
std.demangle.demangle("hello");
100+
cast(void) std.demangle.demangle("hello");
101101

102102
cast(void) std.uni.isAlpha('A');
103103

0 commit comments

Comments
 (0)