diff --git a/mak/DOCS b/mak/DOCS index 707f8691a6..752d75263c 100644 --- a/mak/DOCS +++ b/mak/DOCS @@ -114,16 +114,7 @@ DOCS=\ $(DOCDIR)\rt_trace.html \ $(DOCDIR)\rt_tracegc.html \ \ - $(DOCDIR)\rt_typeinfo_ti_Acdouble.html \ - $(DOCDIR)\rt_typeinfo_ti_Acfloat.html \ - $(DOCDIR)\rt_typeinfo_ti_Acreal.html \ - $(DOCDIR)\rt_typeinfo_ti_Adouble.html \ - $(DOCDIR)\rt_typeinfo_ti_Afloat.html \ - $(DOCDIR)\rt_typeinfo_ti_Ag.html \ - $(DOCDIR)\rt_typeinfo_ti_Aint.html \ - $(DOCDIR)\rt_typeinfo_ti_Along.html \ - $(DOCDIR)\rt_typeinfo_ti_Areal.html \ - $(DOCDIR)\rt_typeinfo_ti_Ashort.html \ + $(DOCDIR)\rt_typeinfo_ti_A.html \ $(DOCDIR)\rt_typeinfo_ti_byte.html \ $(DOCDIR)\rt_typeinfo_ti_C.html \ $(DOCDIR)\rt_typeinfo_ti_cdouble.html \ diff --git a/mak/SRCS b/mak/SRCS index 4fa5f11f16..ed92c87aa4 100644 --- a/mak/SRCS +++ b/mak/SRCS @@ -452,16 +452,7 @@ SRCS=\ src\rt\util\container\hashtab.d \ src\rt\util\container\treap.d \ \ - src\rt\typeinfo\ti_Acdouble.d \ - src\rt\typeinfo\ti_Acfloat.d \ - src\rt\typeinfo\ti_Acreal.d \ - src\rt\typeinfo\ti_Adouble.d \ - src\rt\typeinfo\ti_Afloat.d \ - src\rt\typeinfo\ti_Ag.d \ - src\rt\typeinfo\ti_Aint.d \ - src\rt\typeinfo\ti_Along.d \ - src\rt\typeinfo\ti_Areal.d \ - src\rt\typeinfo\ti_Ashort.d \ + src\rt\typeinfo\ti_A.d \ src\rt\typeinfo\ti_byte.d \ src\rt\typeinfo\ti_C.d \ src\rt\typeinfo\ti_cdouble.d \ diff --git a/src/rt/typeinfo/ti_A.d b/src/rt/typeinfo/ti_A.d new file mode 100644 index 0000000000..7129a97ef9 --- /dev/null +++ b/src/rt/typeinfo/ti_A.d @@ -0,0 +1,127 @@ +/** + * TypeInfo support code. + * + * Copyright: Copyright Digital Mars 2004 - 2009. + * License: $(HTTP www.boost.org/LICENSE_1_0.txt, Boost License 1.0). + * Authors: Walter Bright + */ + +/* Copyright Digital Mars 2004 - 2019. + * Distributed under the Boost Software License, Version 1.0. + * (See accompanying file LICENSE or copy at + * http://www.boost.org/LICENSE_1_0.txt) + */ +module rt.typeinfo.ti_A; + +private import rt.util.typeinfo; + +// cdouble[] +class TypeInfo_Ar : Impl_TypeInfo_A!cdouble {} + +// cfloat[] +class TypeInfo_Aq : Impl_TypeInfo_A!cfloat {} + +// creal[] +class TypeInfo_Ac : Impl_TypeInfo_A!creal {} + +// double[] +class TypeInfo_Ad : Impl_TypeInfo_A!double {} + +// idouble[] +class TypeInfo_Ap : Impl_TypeInfo_A!idouble {} + +// float[] +class TypeInfo_Af : Impl_TypeInfo_A!float {} + +// ifloat[] +class TypeInfo_Ao : Impl_TypeInfo_A!ifloat {} + +// byte[] +class TypeInfo_Ag : Impl_TypeInfo_A!byte {} + +// ubyte[] +class TypeInfo_Ah : Impl_TypeInfo_A!ubyte {}; + +// void[] +class TypeInfo_Av : Impl_TypeInfo_A!void {} + +// bool[] +class TypeInfo_Ab : Impl_TypeInfo_A!bool {} + +// char[] +class TypeInfo_Aa : Impl_TypeInfo_A!char {} + +// string +class TypeInfo_Aya : Impl_TypeInfo_A!(immutable(char)) {} + +// const(char)[] +class TypeInfo_Axa : Impl_TypeInfo_A!(const(char)) {} + + +extern (C) void[] _adSort(void[] a, TypeInfo ti); + +// int[] +class TypeInfo_Ai : Impl_TypeInfo_A!int {} + +unittest +{ + int[][] a = [[5,3,8,7], [2,5,3,8,7]]; + _adSort(*cast(void[]*)&a, typeid(a[0])); + assert(a == [[2,5,3,8,7], [5,3,8,7]]); + + a = [[5,3,8,7], [5,3,8]]; + _adSort(*cast(void[]*)&a, typeid(a[0])); + assert(a == [[5,3,8], [5,3,8,7]]); +} + +unittest +{ + // Issue 13073: original code uses int subtraction which is susceptible to + // integer overflow, causing the following case to fail. + int[] a = [int.max, int.max]; + int[] b = [int.min, int.min]; + assert(a > b); + assert(b < a); +} + +// uint[] +class TypeInfo_Ak : Impl_TypeInfo_A!uint {} + +unittest +{ + // Original test case from issue 13073 + uint x = 0x22_DF_FF_FF; + uint y = 0xA2_DF_FF_FF; + assert(!(x < y && y < x)); + uint[] a = [x]; + uint[] b = [y]; + assert(!(a < b && b < a)); // Original failing case + uint[1] a1 = [x]; + uint[1] b1 = [y]; + assert(!(a1 < b1 && b1 < a1)); // Original failing case +} + +// dchar[] +class TypeInfo_Aw : Impl_TypeInfo_A!dchar {} + + +// long[] +class TypeInfo_Al : Impl_TypeInfo_A!long {} + +// ulong[] +class TypeInfo_Am : Impl_TypeInfo_A!ulong {} + +// real[] +class TypeInfo_Ae : Impl_TypeInfo_A!real {} + +// ireal[] +class TypeInfo_Aj : Impl_TypeInfo_A!ireal {} + +// short[] +class TypeInfo_As : Impl_TypeInfo_A!short {} + +// ushort[] +class TypeInfo_At : Impl_TypeInfo_A!ushort {} + +// wchar[] +class TypeInfo_Au : Impl_TypeInfo_A!wchar {} diff --git a/src/rt/typeinfo/ti_Acdouble.d b/src/rt/typeinfo/ti_Acdouble.d deleted file mode 100644 index 50debaca25..0000000000 --- a/src/rt/typeinfo/ti_Acdouble.d +++ /dev/null @@ -1,47 +0,0 @@ -/** - * TypeInfo support code. - * - * Copyright: Copyright Digital Mars 2004 - 2009. - * License: $(HTTP www.boost.org/LICENSE_1_0.txt, Boost License 1.0). - * Authors: Walter Bright - */ - -/* Copyright Digital Mars 2004 - 2009. - * Distributed under the Boost Software License, Version 1.0. - * (See accompanying file LICENSE or copy at - * http://www.boost.org/LICENSE_1_0.txt) - */ -module rt.typeinfo.ti_Acdouble; - -private import rt.util.typeinfo; - -// cdouble[] - -class TypeInfo_Ar : TypeInfo_Array -{ - alias F = cdouble; - - override bool opEquals(Object o) { return TypeInfo.opEquals(o); } - - override string toString() const { return (F[]).stringof; } - - override size_t getHash(scope const void* p) @trusted const - { - return Array!F.hashOf(*cast(F[]*)p); - } - - override bool equals(in void* p1, in void* p2) const - { - return Array!F.equals(*cast(F[]*)p1, *cast(F[]*)p2); - } - - override int compare(in void* p1, in void* p2) const - { - return Array!F.compare(*cast(F[]*)p1, *cast(F[]*)p2); - } - - override @property inout(TypeInfo) next() inout - { - return cast(inout)typeid(F); - } -} diff --git a/src/rt/typeinfo/ti_Acfloat.d b/src/rt/typeinfo/ti_Acfloat.d deleted file mode 100644 index dadec10df7..0000000000 --- a/src/rt/typeinfo/ti_Acfloat.d +++ /dev/null @@ -1,47 +0,0 @@ -/** - * TypeInfo support code. - * - * Copyright: Copyright Digital Mars 2004 - 2009. - * License: $(HTTP www.boost.org/LICENSE_1_0.txt, Boost License 1.0). - * Authors: Walter Bright - */ - -/* Copyright Digital Mars 2004 - 2009. - * Distributed under the Boost Software License, Version 1.0. - * (See accompanying file LICENSE or copy at - * http://www.boost.org/LICENSE_1_0.txt) - */ -module rt.typeinfo.ti_Acfloat; - -private import rt.util.typeinfo; - -// cfloat[] - -class TypeInfo_Aq : TypeInfo_Array -{ - alias F = cfloat; - - override bool opEquals(Object o) { return TypeInfo.opEquals(o); } - - override string toString() const { return (F[]).stringof; } - - override size_t getHash(scope const void* p) @trusted const - { - return Array!F.hashOf(*cast(F[]*)p); - } - - override bool equals(in void* p1, in void* p2) const - { - return Array!F.equals(*cast(F[]*)p1, *cast(F[]*)p2); - } - - override int compare(in void* p1, in void* p2) const - { - return Array!F.compare(*cast(F[]*)p1, *cast(F[]*)p2); - } - - override @property inout(TypeInfo) next() inout - { - return cast(inout)typeid(F); - } -} diff --git a/src/rt/typeinfo/ti_Acreal.d b/src/rt/typeinfo/ti_Acreal.d deleted file mode 100644 index 650b89b4ed..0000000000 --- a/src/rt/typeinfo/ti_Acreal.d +++ /dev/null @@ -1,47 +0,0 @@ -/** - * TypeInfo support code. - * - * Copyright: Copyright Digital Mars 2004 - 2009. - * License: $(HTTP www.boost.org/LICENSE_1_0.txt, Boost License 1.0). - * Authors: Walter Bright - */ - -/* Copyright Digital Mars 2004 - 2009. - * Distributed under the Boost Software License, Version 1.0. - * (See accompanying file LICENSE or copy at - * http://www.boost.org/LICENSE_1_0.txt) - */ -module rt.typeinfo.ti_Acreal; - -private import rt.util.typeinfo; - -// creal[] - -class TypeInfo_Ac : TypeInfo_Array -{ - alias F = creal; - - override bool opEquals(Object o) { return TypeInfo.opEquals(o); } - - override string toString() const { return (F[]).stringof; } - - override size_t getHash(scope const void* p) @trusted const - { - return Array!F.hashOf(*cast(F[]*)p); - } - - override bool equals(in void* p1, in void* p2) const - { - return Array!F.equals(*cast(F[]*)p1, *cast(F[]*)p2); - } - - override int compare(in void* p1, in void* p2) const - { - return Array!F.compare(*cast(F[]*)p1, *cast(F[]*)p2); - } - - override @property inout(TypeInfo) next() inout - { - return cast(inout)typeid(F); - } -} diff --git a/src/rt/typeinfo/ti_Adouble.d b/src/rt/typeinfo/ti_Adouble.d deleted file mode 100644 index 9712f8a822..0000000000 --- a/src/rt/typeinfo/ti_Adouble.d +++ /dev/null @@ -1,61 +0,0 @@ -/** - * TypeInfo support code. - * - * Copyright: Copyright Digital Mars 2004 - 2009. - * License: $(HTTP www.boost.org/LICENSE_1_0.txt, Boost License 1.0). - * Authors: Walter Bright - */ - -/* Copyright Digital Mars 2004 - 2009. - * Distributed under the Boost Software License, Version 1.0. - * (See accompanying file LICENSE or copy at - * http://www.boost.org/LICENSE_1_0.txt) - */ -module rt.typeinfo.ti_Adouble; - -private import rt.util.typeinfo; - -// double[] - -class TypeInfo_Ad : TypeInfo_Array -{ - alias F = double; - - override bool opEquals(Object o) { return TypeInfo.opEquals(o); } - - override string toString() const { return (F[]).stringof; } - - override size_t getHash(scope const void* p) @trusted const - { - return Array!F.hashOf(*cast(F[]*)p); - } - - override bool equals(in void* p1, in void* p2) const - { - return Array!F.equals(*cast(F[]*)p1, *cast(F[]*)p2); - } - - override int compare(in void* p1, in void* p2) const - { - return Array!F.compare(*cast(F[]*)p1, *cast(F[]*)p2); - } - - override @property inout(TypeInfo) next() inout - { - return cast(inout)typeid(F); - } -} - -// idouble[] - -class TypeInfo_Ap : TypeInfo_Ad -{ - alias F = idouble; - - override string toString() const { return (F[]).stringof; } - - override @property inout(TypeInfo) next() inout - { - return cast(inout)typeid(F); - } -} diff --git a/src/rt/typeinfo/ti_Afloat.d b/src/rt/typeinfo/ti_Afloat.d deleted file mode 100644 index 9a95abd3b5..0000000000 --- a/src/rt/typeinfo/ti_Afloat.d +++ /dev/null @@ -1,61 +0,0 @@ -/** - * TypeInfo support code. - * - * Copyright: Copyright Digital Mars 2004 - 2009. - * License: $(HTTP www.boost.org/LICENSE_1_0.txt, Boost License 1.0). - * Authors: Walter Bright - */ - -/* Copyright Digital Mars 2004 - 2009. - * Distributed under the Boost Software License, Version 1.0. - * (See accompanying file LICENSE or copy at - * http://www.boost.org/LICENSE_1_0.txt) - */ -module rt.typeinfo.ti_Afloat; - -private import rt.util.typeinfo; - -// float[] - -class TypeInfo_Af : TypeInfo_Array -{ - alias F = float; - - override bool opEquals(Object o) { return TypeInfo.opEquals(o); } - - override string toString() const { return (F[]).stringof; } - - override size_t getHash(scope const void* p) @trusted const - { - return Array!F.hashOf(*cast(F[]*)p); - } - - override bool equals(in void* p1, in void* p2) const - { - return Array!F.equals(*cast(F[]*)p1, *cast(F[]*)p2); - } - - override int compare(in void* p1, in void* p2) const - { - return Array!F.compare(*cast(F[]*)p1, *cast(F[]*)p2); - } - - override @property inout(TypeInfo) next() inout - { - return cast(inout)typeid(F); - } -} - -// ifloat[] - -class TypeInfo_Ao : TypeInfo_Af -{ - alias F = ifloat; - - override string toString() const { return (F[]).stringof; } - - override @property inout(TypeInfo) next() inout - { - return cast(inout)typeid(F); - } -} diff --git a/src/rt/typeinfo/ti_Ag.d b/src/rt/typeinfo/ti_Ag.d deleted file mode 100644 index bdb0553698..0000000000 --- a/src/rt/typeinfo/ti_Ag.d +++ /dev/null @@ -1,154 +0,0 @@ -/** - * TypeInfo support code. - * - * Copyright: Copyright Digital Mars 2004 - 2009. - * License: $(HTTP www.boost.org/LICENSE_1_0.txt, Boost License 1.0). - * Authors: Walter Bright - */ - -/* Copyright Digital Mars 2004 - 2009. - * Distributed under the Boost Software License, Version 1.0. - * (See accompanying file LICENSE or copy at - * http://www.boost.org/LICENSE_1_0.txt) - */ -module rt.typeinfo.ti_Ag; - -private import core.stdc.string; -private import core.internal.string; - -// byte[] - -class TypeInfo_Ag : TypeInfo_Array -{ - override bool opEquals(Object o) { return TypeInfo.opEquals(o); } - - override string toString() const { return "byte[]"; } - - override size_t getHash(scope const void* p) @trusted const - { - const s = *cast(const void[]*)p; - return hashOf(s); - } - - override bool equals(in void* p1, in void* p2) const - { - byte[] s1 = *cast(byte[]*)p1; - byte[] s2 = *cast(byte[]*)p2; - - return s1.length == s2.length && - memcmp(cast(byte *)s1, cast(byte *)s2, s1.length) == 0; - } - - override int compare(in void* p1, in void* p2) const - { - byte[] s1 = *cast(byte[]*)p1; - byte[] s2 = *cast(byte[]*)p2; - size_t len = s1.length; - - if (s2.length < len) - len = s2.length; - for (size_t u = 0; u < len; u++) - { - int result = s1[u] - s2[u]; - if (result) - return result; - } - if (s1.length < s2.length) - return -1; - else if (s1.length > s2.length) - return 1; - return 0; - } - - override @property inout(TypeInfo) next() inout - { - return cast(inout)typeid(byte); - } -} - - -// ubyte[] - -class TypeInfo_Ah : TypeInfo_Ag -{ - override string toString() const { return "ubyte[]"; } - - override int compare(in void* p1, in void* p2) const - { - char[] s1 = *cast(char[]*)p1; - char[] s2 = *cast(char[]*)p2; - - return dstrcmp(s1, s2); - } - - override @property inout(TypeInfo) next() inout - { - return cast(inout)typeid(ubyte); - } -} - -// void[] - -class TypeInfo_Av : TypeInfo_Ah -{ - override string toString() const { return "void[]"; } - - override @property inout(TypeInfo) next() inout - { - return cast(inout)typeid(void); - } -} - -// bool[] - -class TypeInfo_Ab : TypeInfo_Ah -{ - override string toString() const { return "bool[]"; } - - override @property inout(TypeInfo) next() inout - { - return cast(inout)typeid(bool); - } -} - -// char[] - -class TypeInfo_Aa : TypeInfo_Ah -{ - override string toString() const { return "char[]"; } - - override size_t getHash(scope const void* p) @trusted const - { - char[] s = *cast(char[]*)p; - return hashOf(s); - } - - override @property inout(TypeInfo) next() inout - { - return cast(inout)typeid(char); - } -} - -// string - -class TypeInfo_Aya : TypeInfo_Aa -{ - override string toString() const { return "immutable(char)[]"; } - - override @property inout(TypeInfo) next() inout - { - return cast(inout)typeid(immutable(char)); - } -} - -// const(char)[] - -class TypeInfo_Axa : TypeInfo_Aa -{ - override string toString() const { return "const(char)[]"; } - - override @property inout(TypeInfo) next() inout - { - return cast(inout)typeid(const(char)); - } -} diff --git a/src/rt/typeinfo/ti_Aint.d b/src/rt/typeinfo/ti_Aint.d deleted file mode 100644 index ebe8d80f93..0000000000 --- a/src/rt/typeinfo/ti_Aint.d +++ /dev/null @@ -1,151 +0,0 @@ -/** - * TypeInfo support code. - * - * Copyright: Copyright Digital Mars 2004 - 2009. - * License: $(HTTP www.boost.org/LICENSE_1_0.txt, Boost License 1.0). - * Authors: Walter Bright - */ - -/* Copyright Digital Mars 2004 - 2009. - * Distributed under the Boost Software License, Version 1.0. - * (See accompanying file LICENSE or copy at - * http://www.boost.org/LICENSE_1_0.txt) - */ -module rt.typeinfo.ti_Aint; - -private import core.stdc.string; - -extern (C) void[] _adSort(void[] a, TypeInfo ti); - -// int[] - -class TypeInfo_Ai : TypeInfo_Array -{ - override bool opEquals(Object o) { return TypeInfo.opEquals(o); } - - override string toString() const { return "int[]"; } - - override size_t getHash(scope const void* p) @trusted const - { - // Hash as if unsigned. - const s = *cast(const uint[]*)p; - return hashOf(s); - } - - override bool equals(in void* p1, in void* p2) const - { - int[] s1 = *cast(int[]*)p1; - int[] s2 = *cast(int[]*)p2; - - return s1.length == s2.length && - memcmp(cast(void *)s1, cast(void *)s2, s1.length * int.sizeof) == 0; - } - - override int compare(in void* p1, in void* p2) const - { - int[] s1 = *cast(int[]*)p1; - int[] s2 = *cast(int[]*)p2; - size_t len = s1.length; - - if (s2.length < len) - len = s2.length; - for (size_t u = 0; u < len; u++) - { - if (s1[u] < s2[u]) - return -1; - else if (s1[u] > s2[u]) - return 1; - } - if (s1.length < s2.length) - return -1; - else if (s1.length > s2.length) - return 1; - return 0; - } - - override @property inout(TypeInfo) next() inout - { - return cast(inout)typeid(int); - } -} - -unittest -{ - int[][] a = [[5,3,8,7], [2,5,3,8,7]]; - _adSort(*cast(void[]*)&a, typeid(a[0])); - assert(a == [[2,5,3,8,7], [5,3,8,7]]); - - a = [[5,3,8,7], [5,3,8]]; - _adSort(*cast(void[]*)&a, typeid(a[0])); - assert(a == [[5,3,8], [5,3,8,7]]); -} - -unittest -{ - // Issue 13073: original code uses int subtraction which is susceptible to - // integer overflow, causing the following case to fail. - int[] a = [int.max, int.max]; - int[] b = [int.min, int.min]; - assert(a > b); - assert(b < a); -} - -// uint[] - -class TypeInfo_Ak : TypeInfo_Ai -{ - override string toString() const { return "uint[]"; } - - override int compare(in void* p1, in void* p2) const - { - uint[] s1 = *cast(uint[]*)p1; - uint[] s2 = *cast(uint[]*)p2; - size_t len = s1.length; - - if (s2.length < len) - len = s2.length; - for (size_t u = 0; u < len; u++) - { - if (s1[u] < s2[u]) - return -1; - else if (s1[u] > s2[u]) - return 1; - } - if (s1.length < s2.length) - return -1; - else if (s1.length > s2.length) - return 1; - return 0; - } - - override @property inout(TypeInfo) next() inout - { - return cast(inout)typeid(uint); - } -} - -unittest -{ - // Original test case from issue 13073 - uint x = 0x22_DF_FF_FF; - uint y = 0xA2_DF_FF_FF; - assert(!(x < y && y < x)); - uint[] a = [x]; - uint[] b = [y]; - assert(!(a < b && b < a)); // Original failing case - uint[1] a1 = [x]; - uint[1] b1 = [y]; - assert(!(a1 < b1 && b1 < a1)); // Original failing case -} - -// dchar[] - -class TypeInfo_Aw : TypeInfo_Ak -{ - override string toString() const { return "dchar[]"; } - - override @property inout(TypeInfo) next() inout - { - return cast(inout)typeid(dchar); - } -} diff --git a/src/rt/typeinfo/ti_Along.d b/src/rt/typeinfo/ti_Along.d deleted file mode 100644 index b67bb995ba..0000000000 --- a/src/rt/typeinfo/ti_Along.d +++ /dev/null @@ -1,103 +0,0 @@ -/** - * TypeInfo support code. - * - * Copyright: Copyright Digital Mars 2004 - 2009. - * License: $(HTTP www.boost.org/LICENSE_1_0.txt, Boost License 1.0). - * Authors: Walter Bright - */ - -/* Copyright Digital Mars 2004 - 2009. - * Distributed under the Boost Software License, Version 1.0. - * (See accompanying file LICENSE or copy at - * http://www.boost.org/LICENSE_1_0.txt) - */ -module rt.typeinfo.ti_Along; - -private import core.stdc.string; - -// long[] - -class TypeInfo_Al : TypeInfo_Array -{ - override bool opEquals(Object o) { return TypeInfo.opEquals(o); } - - override string toString() const { return "long[]"; } - - override size_t getHash(scope const void* p) @trusted const - { - // Hash as if unsigned. - const s = *cast(const ulong[]*)p; - return hashOf(s); - } - - override bool equals(in void* p1, in void* p2) const - { - long[] s1 = *cast(long[]*)p1; - long[] s2 = *cast(long[]*)p2; - - return s1.length == s2.length && - memcmp(cast(void *)s1, cast(void *)s2, s1.length * long.sizeof) == 0; - } - - override int compare(in void* p1, in void* p2) const - { - long[] s1 = *cast(long[]*)p1; - long[] s2 = *cast(long[]*)p2; - size_t len = s1.length; - - if (s2.length < len) - len = s2.length; - for (size_t u = 0; u < len; u++) - { - if (s1[u] < s2[u]) - return -1; - else if (s1[u] > s2[u]) - return 1; - } - if (s1.length < s2.length) - return -1; - else if (s1.length > s2.length) - return 1; - return 0; - } - - override @property inout(TypeInfo) next() inout - { - return cast(inout)typeid(long); - } -} - - -// ulong[] - -class TypeInfo_Am : TypeInfo_Al -{ - override string toString() const { return "ulong[]"; } - - override int compare(in void* p1, in void* p2) const - { - ulong[] s1 = *cast(ulong[]*)p1; - ulong[] s2 = *cast(ulong[]*)p2; - size_t len = s1.length; - - if (s2.length < len) - len = s2.length; - for (size_t u = 0; u < len; u++) - { - if (s1[u] < s2[u]) - return -1; - else if (s1[u] > s2[u]) - return 1; - } - if (s1.length < s2.length) - return -1; - else if (s1.length > s2.length) - return 1; - return 0; - } - - override @property inout(TypeInfo) next() inout - { - return cast(inout)typeid(ulong); - } -} diff --git a/src/rt/typeinfo/ti_Areal.d b/src/rt/typeinfo/ti_Areal.d deleted file mode 100644 index 5280f81fe6..0000000000 --- a/src/rt/typeinfo/ti_Areal.d +++ /dev/null @@ -1,61 +0,0 @@ -/** - * TypeInfo support code. - * - * Copyright: Copyright Digital Mars 2004 - 2009. - * License: $(HTTP www.boost.org/LICENSE_1_0.txt, Boost License 1.0). - * Authors: Walter Bright - */ - -/* Copyright Digital Mars 2004 - 2009. - * Distributed under the Boost Software License, Version 1.0. - * (See accompanying file LICENSE or copy at - * http://www.boost.org/LICENSE_1_0.txt) - */ -module rt.typeinfo.ti_Areal; - -private import rt.util.typeinfo; - -// real[] - -class TypeInfo_Ae : TypeInfo_Array -{ - alias F = real; - - override bool opEquals(Object o) { return TypeInfo.opEquals(o); } - - override string toString() const { return (F[]).stringof; } - - override size_t getHash(scope const void* p) @trusted const - { - return Array!F.hashOf(*cast(F[]*)p); - } - - override bool equals(in void* p1, in void* p2) const - { - return Array!F.equals(*cast(F[]*)p1, *cast(F[]*)p2); - } - - override int compare(in void* p1, in void* p2) const - { - return Array!F.compare(*cast(F[]*)p1, *cast(F[]*)p2); - } - - override @property inout(TypeInfo) next() inout - { - return cast(inout)typeid(F); - } -} - -// ireal[] - -class TypeInfo_Aj : TypeInfo_Ae -{ - alias F = ireal; - - override string toString() const { return (F[]).stringof; } - - override @property inout(TypeInfo) next() inout - { - return cast(inout)typeid(F); - } -} diff --git a/src/rt/typeinfo/ti_Ashort.d b/src/rt/typeinfo/ti_Ashort.d deleted file mode 100644 index aea4be7704..0000000000 --- a/src/rt/typeinfo/ti_Ashort.d +++ /dev/null @@ -1,113 +0,0 @@ -/** - * TypeInfo support code. - * - * Copyright: Copyright Digital Mars 2004 - 2009. - * License: $(HTTP www.boost.org/LICENSE_1_0.txt, Boost License 1.0). - * Authors: Walter Bright - */ - -/* Copyright Digital Mars 2004 - 2009. - * Distributed under the Boost Software License, Version 1.0. - * (See accompanying file LICENSE or copy at - * http://www.boost.org/LICENSE_1_0.txt) - */ -module rt.typeinfo.ti_Ashort; - -private import core.stdc.string; - -// short[] - -class TypeInfo_As : TypeInfo_Array -{ - override bool opEquals(Object o) { return TypeInfo.opEquals(o); } - - override string toString() const { return "short[]"; } - - override size_t getHash(scope const void* p) @trusted const - { - // Hash as if unsigned. - const s = *cast(const ushort[]*)p; - return hashOf(s); - } - - override bool equals(in void* p1, in void* p2) const - { - short[] s1 = *cast(short[]*)p1; - short[] s2 = *cast(short[]*)p2; - - return s1.length == s2.length && - memcmp(cast(void *)s1, cast(void *)s2, s1.length * short.sizeof) == 0; - } - - override int compare(in void* p1, in void* p2) const - { - short[] s1 = *cast(short[]*)p1; - short[] s2 = *cast(short[]*)p2; - size_t len = s1.length; - - if (s2.length < len) - len = s2.length; - for (size_t u = 0; u < len; u++) - { - int result = s1[u] - s2[u]; - if (result) - return result; - } - if (s1.length < s2.length) - return -1; - else if (s1.length > s2.length) - return 1; - return 0; - } - - override @property inout(TypeInfo) next() inout - { - return cast(inout)typeid(short); - } -} - - -// ushort[] - -class TypeInfo_At : TypeInfo_As -{ - override string toString() const { return "ushort[]"; } - - override int compare(in void* p1, in void* p2) const - { - ushort[] s1 = *cast(ushort[]*)p1; - ushort[] s2 = *cast(ushort[]*)p2; - size_t len = s1.length; - - if (s2.length < len) - len = s2.length; - for (size_t u = 0; u < len; u++) - { - int result = s1[u] - s2[u]; - if (result) - return result; - } - if (s1.length < s2.length) - return -1; - else if (s1.length > s2.length) - return 1; - return 0; - } - - override @property inout(TypeInfo) next() inout - { - return cast(inout)typeid(ushort); - } -} - -// wchar[] - -class TypeInfo_Au : TypeInfo_At -{ - override string toString() const { return "wchar[]"; } - - override @property inout(TypeInfo) next() inout - { - return cast(inout)typeid(wchar); - } -} diff --git a/src/rt/util/typeinfo.d b/src/rt/util/typeinfo.d index 2cc1c236c1..32dd5a7a38 100644 --- a/src/rt/util/typeinfo.d +++ b/src/rt/util/typeinfo.d @@ -9,7 +9,8 @@ module rt.util.typeinfo; static import core.internal.hash; template Floating(T) -if (is(T == float) || is(T == double) || is(T == real)) +if (is(T == float) || is(T == double) || is(T == real) || + is(T == ifloat) || is(T == idouble) || is(T == ireal)) { pure nothrow @safe: @@ -35,6 +36,7 @@ if (is(T == float) || is(T == double) || is(T == real)) public alias hashOf = core.internal.hash.hashOf; } + template Floating(T) if (is(T == cfloat) || is(T == cdouble) || is(T == creal)) { @@ -65,9 +67,12 @@ if (is(T == cfloat) || is(T == cdouble) || is(T == creal)) public alias hashOf = core.internal.hash.hashOf; } -template Array(T) -if (is(T == float) || is(T == double) || is(T == real) || - is(T == cfloat) || is(T == cdouble) || is(T == creal)) +enum isFloatingTypeInfoT(T) = is(T == float) || is(T == double) || is(T == real) || + is(T == cfloat) || is(T == cdouble) || is(T == creal) || + is(T == ifloat) || is(T == idouble) || is(T == ireal); + +private template Array(T) +if (isFloatingTypeInfoT!T) { pure nothrow @safe: @@ -76,7 +81,7 @@ if (is(T == float) || is(T == double) || is(T == real) || size_t len = s1.length; if (len != s2.length) return false; - for (size_t u = 0; u < len; u++) + for (size_t u = 0; u < len; ++u) { if (!Floating!T.equals(s1[u], s2[u])) return false; @@ -89,7 +94,7 @@ if (is(T == float) || is(T == double) || is(T == real) || size_t len = s1.length; if (s2.length < len) len = s2.length; - for (size_t u = 0; u < len; u++) + for (size_t u = 0; u < len; ++u) { if (int c = Floating!T.compare(s1[u], s2[u])) return c; @@ -104,6 +109,131 @@ if (is(T == float) || is(T == double) || is(T == real) || public alias hashOf = core.internal.hash.hashOf; } +enum isIntegralTypeInfoT(T) = __traits(isIntegral, T) || is(T == void); + +private template Array(T) +if (isIntegralTypeInfoT!T) +{ + pure nothrow @safe: + + bool equals(T[] s1, T[] s2) + { + import core.stdc.string; + alias U = equalsBaseType!T; + + auto len = s1.length; + return len == s2.length && + (() @trusted => memcmp(cast(U*) s1, cast(U*) s2, len * U.sizeof) == 0)(); + } + + int compare(T[] ss1, T[] ss2) + { + alias U = compareBaseType!T; + U[] s1 = (() @trusted => cast(U[]) ss1)(); + U[] s2 = (() @trusted => cast(U[]) ss2)(); + + static if (is(U == char)) + { + import core.internal.string; + return dstrcmp(s1, s2); + } + else + { + size_t len1 = s1.length; + size_t len2 = s2.length; + size_t minLen = len1 < len2 ? len1 : len2; + + for (size_t u = 0; u < minLen; ++u) + { + if (s1[u] < s2[u]) + return -1; + else if (s1[u] > s2[u]) + return 1; + } + if (len1 < len2) + return -1; + else if (len1 > len2) + return 1; + return 0; + } + } + + public alias hashOf = core.internal.hash.hashOf; +} + +class Impl_TypeInfo_A(T) : TypeInfo_Array +if (isFloatingTypeInfoT!T || isIntegralTypeInfoT!T) +{ + override bool opEquals(Object o) { return TypeInfo.opEquals(o); } + + override string toString() const { return (T[]).stringof; } + + override size_t getHash(scope const void* p) @trusted const + { + alias U = hashBaseType!T; + return Array!U.hashOf(*cast(U[]*) p); + } + + override bool equals(in void* p1, in void* p2) const + { + return Array!T.equals(*cast(T[]*) p1, *cast(T[]*) p2); + } + + override int compare(in void* p1, in void* p2) const + { + return Array!T.compare(*cast(T[]*) p1, *cast(T[]*) p2); + } + + override @property inout(TypeInfo) next() inout + { + return cast(inout)typeid(T); + } +} + +private template hashBaseType(T) +{ + static if (is(T == int) || is(T == uint) || is(T == dchar)) + alias hashBaseType = uint; + else static if (is(T == long) || is(T == ulong)) + alias hashBaseType = ulong; + else static if (is(T == short) || is(T == ushort) || is(T == wchar)) + alias hashBaseType = ushort; + else static if (is(T == byte) || is(T == ubyte) || is(T == void) || is(T == bool)) + alias hashBaseType = void; + else static if (is(T == char) || is(T == immutable(char)) || is(T == const(char))) + alias hashBaseType = char; + else + alias hashBaseType = T; +} + +private template equalsBaseType(T) +{ + static if (is(T == int) || is(T == uint) || is(T == dchar)) + alias equalsBaseType = int; + else static if (is(T == long) || is(T == ulong)) + alias equalsBaseType = long; + else static if (is(T == short) || is(T == ushort) || is(T == wchar)) + alias equalsBaseType = short; + else static if (is(T == byte) || is(T == ubyte) || is(T == void) || is(T == bool) || + is(T == char) || is(T == immutable(char)) || is(T == const(char))) + alias equalsBaseType = byte; + else + alias equalsBaseType = T; +} + +private template compareBaseType(T) +{ + static if (is(T == ubyte) || is(T == void) || is(T == bool) || + is(T == char) || is(T == immutable(char)) || is(T == const(char))) + alias compareBaseType = char; + else static if (is(T == ushort) || is(T == wchar)) + alias compareBaseType = ushort; + else static if (is(T == uint) || is(T == dchar)) + alias compareBaseType = uint; + else // byte || short || int || long || ulong + alias compareBaseType = T; +} + version (unittest) { alias TypeTuple(T...) = T;