Modernize std.demangle

This commit is contained in:
Jack Stouffer 2018-03-23 13:51:29 -04:00
parent 4ac4a06ace
commit 8c84c58f70
3 changed files with 44 additions and 65 deletions

View file

@ -139,7 +139,6 @@ has_public_example="-etc.c.curl,\
-std.datetime.stopwatch,\
-std.datetime.systime,\
-std.datetime.timezone,\
-std.demangle,\
-std.digest,\
-std.digest.hmac,\
-std.digest.murmurhash,\
@ -219,7 +218,7 @@ object_const_check="-std.algorithm.searching,-std.array,-std.bitmanip,-std.concu
; Checks that opEquals and toHash are both defined or neither are defined
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"
; Check for properly documented public functions (Returns, Params)
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"
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"
; Check for redundant attributes
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"
; Check variable, class, struct, interface, union, and function names against

View file

@ -18,72 +18,52 @@
*/
module std.demangle;
/+
private class MangleException : Exception
{
this()
{
super("MangleException");
}
}
+/
/**
Demangle D mangled names.
/*****************************
* Demangle D mangled names.
*
* If it is not a D mangled name, it returns its argument name.
* Example:
* This program reads standard in and writes it to standard out,
* pretty-printing any found D mangled names.
-------------------
import core.stdc.stdio : stdin;
import std.stdio;
import std.ascii;
import std.demangle;
void test(int x, float y) { }
int main()
{
string buffer;
bool inword;
int c;
writefln("Try typing in: %s", test.mangleof);
while ((c = fgetc(stdin)) != EOF)
{
if (inword)
{
if (c == '_' || isAlphaNum(c))
buffer ~= cast(char) c;
else
{
inword = false;
write(demangle(buffer), cast(char) c);
}
}
else
{ if (c == '_' || isAlpha(c))
{
inword = true;
buffer.length = 0;
buffer ~= cast(char) c;
}
else
write(cast(char) c);
}
}
if (inword)
write(demangle(buffer));
return 0;
}
-------------------
Params:
name = the mangled name
Returns:
A `string`. If it is not a D mangled name, it returns its argument name.
*/
string demangle(string name)
string demangle(string name) @safe pure nothrow
{
import core.demangle : demangle;
import std.exception : assumeUnique;
auto ret = demangle(name);
return assumeUnique(ret);
return () @trusted { return ret.assumeUnique; } ();
}
///
@safe pure unittest
{
// int b in module a
assert(demangle("_D1a1bi") == "int a.b");
// char array foo in module test
assert(demangle("_D4test3fooAa") == "char[] test.foo");
}
/**
This program reads standard in and writes it to standard out,
pretty-printing any found D mangled names.
*/
@system unittest
{
import std.ascii : isAlphaNum;
import std.algorithm.iteration : chunkBy, joiner, map;
import std.algorithm.mutation : copy;
import std.conv : to;
import std.demangle : demangle;
import std.functional : pipe;
import std.stdio : stdin, stdout;
void main()
{
stdin.byLineCopy
.map!(
l => l.chunkBy!(a => isAlphaNum(a) || a == '_')
.map!(a => a[1].pipe!(to!string, demangle)).joiner
)
.copy(stdout.lockingTextWriter);
}
}

View file

@ -97,7 +97,7 @@ int main(string[] args)
cast(void) std.math.sin(3.0);
cast(void) std.mathspecial.gamma(6.2);
std.demangle.demangle("hello");
cast(void) std.demangle.demangle("hello");
cast(void) std.uni.isAlpha('A');