// D import file generated from '../../../../libphobos/libdruntime/core/demangle.d'
module core.demangle;
debug (trace)
{
	import core.stdc.stdio : printf;
}
debug (info)
{
	import core.stdc.stdio : printf;
}
import core.stdc.stdio : snprintf;
import core.stdc.string : memmove;
import core.stdc.stdlib : strtold;
private struct Demangle
{
	enum AddType 
	{
		no,
		yes,
	}
	this(const(char)[] buf_, char[] dst_ = null);
	this(const(char)[] buf_, AddType addType_, char[] dst_ = null);
	enum size_t minBufSize = 4000;
	const(char)[] buf = null;
	char[] dst = null;
	size_t pos = 0;
	size_t len = 0;
	AddType addType = AddType.yes;
	static class ParseException : Exception
	{
		this(string msg);
	}

	static class OverflowException : Exception
	{
		this(string msg);
	}

	static void error(string msg = "Invalid symbol");

	static void overflow(string msg = "Buffer overflow");

	static bool isAlpha(char val);

	static bool isDigit(char val);

	static bool isHexDigit(char val);

	static ubyte ascii2hex(char val);

	static bool contains(const(char)[] a, const(char)[] b);

	char[] shift(const(char)[] val);
	char[] append(const(char)[] val);
	char[] put(const(char)[] val);
	char[] putAsHex(size_t val, int width = 0);
	void pad(const(char)[] val);
	void silent(lazy void dg);
	char tok();
	void test(char val);
	void next();
	void match(char val);
	void match(const(char)[] val);
	void eat(char val);
	const(char)[] sliceNumber();
	size_t decodeNumber();
	size_t decodeNumber(const(char)[] num);
	void parseReal();
	void parseLName();
	char[] parseType(char[] name = null);
	enum IsDelegate 
	{
		no,
		yes,
	}
	char[] parseTypeFunction(char[] name = null, IsDelegate isdg = IsDelegate.no);
	void parseValue(char[] name = null, char type = '\x00');
	void parseIntegerValue(char[] name = null, char type = '\x00');
	void parseTemplateArgs();
	void parseTemplateInstanceName();
	bool mayBeTemplateInstanceName();
	void parseSymbolName();
	char[] parseQualifiedName();
	void parseMangledName();
	char[] opCall();
}

char[] demangle(const(char)[] buf, char[] dst = null);
version (unittest)
{
	immutable string[2][] table = [["printf","printf"],["_foo","_foo"],["_D88","_D88"],["_D4test3fooAa","char[] test.foo"],["_D8demangle8demangleFAaZAa","char[] demangle.demangle(char[])"],["_D6object6Object8opEqualsFC6ObjectZi","int object.Object.opEquals(Object)"],["_D4test2dgDFiYd","double test.dg(int, ...)"],["_D4test34__T3barVG3uw3_616263VG3wd3_646566Z1xi","int test.bar!(\"abc\"w, \"def\"d).x"],["_D8demangle4testFLC6ObjectLDFLiZiZi","int demangle.test(lazy Object, lazy int delegate(lazy int))"],["_D8demangle4testFAiXi","int demangle.test(int[]...)"],["_D8demangle4testFAiYi","int demangle.test(int[], ...)"],["_D8demangle4testFLAiXi","int demangle.test(lazy int[]...)"],["_D8demangle4testFLAiYi","int demangle.test(lazy int[], ...)"],["_D6plugin8generateFiiZAya","immutable(char)[] plugin.generate(int, int)"],["_D6plugin8generateFiiZAxa","const(char)[] plugin.generate(int, int)"],["_D6plugin8generateFiiZAOa","shared(char)[] plugin.generate(int, int)"],["_D8demangle3fnAFZv3fnBMFZv","void demangle.fnA().void fnB()"],["_D8demangle4mainFZv1S3fnCFZv","void demangle.main().void S.fnC()"],["_D8demangle4mainFZv1S3fnDMFZv","void demangle.main().void S.fnD()"],["_D8demangle20__T2fnVAiA4i1i2i3i4Z2fnFZv","void demangle.fn!([1, 2, 3, 4]).fn()"],["_D8demangle10__T2fnVi1Z2fnFZv","void demangle.fn!(1).fn()"],["_D8demangle26__T2fnVS8demangle1SS2i1i2Z2fnFZv","void demangle.fn!(demangle.S(1, 2)).fn()"],["_D8demangle13__T2fnVeeNANZ2fnFZv","void demangle.fn!(real.nan).fn()"],["_D8demangle14__T2fnVeeNINFZ2fnFZv","void demangle.fn!(-real.infinity).fn()"],["_D8demangle13__T2fnVeeINFZ2fnFZv","void demangle.fn!(real.infinity).fn()"],["_D8demangle21__T2fnVHiiA2i1i2i3i4Z2fnFZv","void demangle.fn!([1:2, 3:4]).fn()"],["_D8demangle2fnFNgiZNgi","inout(int) demangle.fn(inout(int))"],["_D8demangle29__T2fnVa97Va9Va0Vu257Vw65537Z2fnFZv","void demangle.fn!('a', '\\t', \\x00, '\\u0101', '\\U00010001').fn()"]];

	template staticIota(int x)
	{
		template Seq(T...)
		{
			alias T Seq;
		}
		static if(x == 0)
		{
			alias Seq!() staticIota;
		}
		else
		{
			alias Seq!(staticIota!(x - 1), x - 1) staticIota;
		}
	}
}
string decodeDmdString(const(char)[] ln, ref size_t p);
