From 55e77ee698e9839c529bc97be77d917c5a4cb3e6 Mon Sep 17 00:00:00 2001 From: Walter Bright Date: Thu, 16 Feb 2012 18:56:44 -0800 Subject: [PATCH] move towards const correctness --- src/core/exception.d | 10 ++++---- src/core/sync/mutex.d | 4 +-- src/core/sync/rwmutex.d | 8 +++--- src/core/sys/windows/stacktrace.d | 6 ++--- src/rt/typeinfo/ti_AC.d | 5 ++++ src/rt/typeinfo/ti_Acdouble.d | 7 +++++- src/rt/typeinfo/ti_Acfloat.d | 7 +++++- src/rt/typeinfo/ti_Acreal.d | 7 +++++- src/rt/typeinfo/ti_Adouble.d | 14 +++++++++-- src/rt/typeinfo/ti_Afloat.d | 14 +++++++++-- src/rt/typeinfo/ti_Ag.d | 42 ++++++++++++++++++++++++++----- src/rt/typeinfo/ti_Aint.d | 21 +++++++++++++--- src/rt/typeinfo/ti_Along.d | 14 +++++++++-- src/rt/typeinfo/ti_Areal.d | 14 +++++++++-- src/rt/typeinfo/ti_Ashort.d | 21 +++++++++++++--- src/rt/typeinfo/ti_C.d | 5 ++++ src/rt/typeinfo/ti_byte.d | 7 +++++- src/rt/typeinfo/ti_cdouble.d | 18 ++++++++----- src/rt/typeinfo/ti_cfloat.d | 18 ++++++++----- src/rt/typeinfo/ti_char.d | 7 +++++- src/rt/typeinfo/ti_creal.d | 18 ++++++++----- src/rt/typeinfo/ti_dchar.d | 7 +++++- src/rt/typeinfo/ti_delegate.d | 5 ++++ src/rt/typeinfo/ti_double.d | 18 ++++++++----- src/rt/typeinfo/ti_float.d | 18 ++++++++----- src/rt/typeinfo/ti_idouble.d | 7 +++++- src/rt/typeinfo/ti_ifloat.d | 7 +++++- src/rt/typeinfo/ti_int.d | 7 +++++- src/rt/typeinfo/ti_ireal.d | 7 +++++- src/rt/typeinfo/ti_long.d | 7 +++++- src/rt/typeinfo/ti_ptr.d | 5 ++++ src/rt/typeinfo/ti_real.d | 18 ++++++++----- src/rt/typeinfo/ti_short.d | 7 +++++- src/rt/typeinfo/ti_ubyte.d | 14 +++++++++-- src/rt/typeinfo/ti_uint.d | 7 +++++- src/rt/typeinfo/ti_ulong.d | 7 +++++- src/rt/typeinfo/ti_ushort.d | 7 +++++- src/rt/typeinfo/ti_void.d | 7 +++++- src/rt/typeinfo/ti_wchar.d | 9 +++++-- src/rt/util/hash.d | 5 ++-- src/rt/util/string.d | 4 +++ 41 files changed, 348 insertions(+), 92 deletions(-) diff --git a/src/core/exception.d b/src/core/exception.d index ee531e39b47..b28124ec400 100644 --- a/src/core/exception.d +++ b/src/core/exception.d @@ -151,7 +151,7 @@ class FinalizeError : Error info = ci; } - override string toString() + @safe override const string toString() { return "An exception was thrown while finalizing an instance of class " ~ info.name; } @@ -234,9 +234,9 @@ class OutOfMemoryError : Error super( "Memory allocation failed", file, line, next ); } - override string toString() + @trusted override const string toString() { - return msg ? super.toString() : "Memory allocation failed"; + return msg ? (cast()super).toString() : "Memory allocation failed"; } } @@ -275,9 +275,9 @@ class InvalidMemoryOperationError : Error super( "Invalid memory operation", file, line, next ); } - override string toString() + @trusted override const string toString() { - return msg ? super.toString() : "Invalid memory operation"; + return msg ? (cast()super).toString() : "Invalid memory operation"; } } diff --git a/src/core/sync/mutex.d b/src/core/sync/mutex.d index da02281fa37..124919383fa 100644 --- a/src/core/sync/mutex.d +++ b/src/core/sync/mutex.d @@ -128,7 +128,7 @@ class Mutex : * Throws: * SyncException on error. */ - void lock() + @trusted void lock() { version( Windows ) { @@ -150,7 +150,7 @@ class Mutex : * Throws: * SyncException on error. */ - void unlock() + @trusted void unlock() { version( Windows ) { diff --git a/src/core/sync/rwmutex.d b/src/core/sync/rwmutex.d index a635a650dcf..f044bf1a292 100644 --- a/src/core/sync/rwmutex.d +++ b/src/core/sync/rwmutex.d @@ -183,7 +183,7 @@ class ReadWriteMutex /** * Acquires a read lock on the enclosing mutex. */ - void lock() + @trusted void lock() { synchronized( m_commonMutex ) { @@ -200,7 +200,7 @@ class ReadWriteMutex /** * Releases a read lock on the enclosing mutex. */ - void unlock() + @trusted void unlock() { synchronized( m_commonMutex ) { @@ -286,7 +286,7 @@ class ReadWriteMutex /** * Acquires a write lock on the enclosing mutex. */ - void lock() + @trusted void lock() { synchronized( m_commonMutex ) { @@ -303,7 +303,7 @@ class ReadWriteMutex /** * Releases a write lock on the enclosing mutex. */ - void unlock() + @trusted void unlock() { synchronized( m_commonMutex ) { diff --git a/src/core/sys/windows/stacktrace.d b/src/core/sys/windows/stacktrace.d index 15eca92cb74..e5896802a2d 100644 --- a/src/core/sys/windows/stacktrace.d +++ b/src/core/sys/windows/stacktrace.d @@ -249,7 +249,7 @@ public: } - override string toString() + @safe override string toString() const pure nothrow { string result; @@ -272,8 +272,8 @@ private: return traceNoSync(); } } - - + + static char[][] traceNoSync() { auto dbghelp = DbgHelp.get(); diff --git a/src/rt/typeinfo/ti_AC.d b/src/rt/typeinfo/ti_AC.d index 8cc7c2b69a1..4d50ee3544c 100644 --- a/src/rt/typeinfo/ti_AC.d +++ b/src/rt/typeinfo/ti_AC.d @@ -17,6 +17,11 @@ module rt.typeinfo.ti_AC; class TypeInfo_AC : TypeInfo { + @trusted: + const: + //pure: + //nothrow: + override hash_t getHash(in void* p) { Object[] s = *cast(Object[]*)p; hash_t hash = 0; diff --git a/src/rt/typeinfo/ti_Acdouble.d b/src/rt/typeinfo/ti_Acdouble.d index 5a8470ea5c8..d32f8a1066f 100644 --- a/src/rt/typeinfo/ti_Acdouble.d +++ b/src/rt/typeinfo/ti_Acdouble.d @@ -20,7 +20,12 @@ private import rt.util.hash; class TypeInfo_Ar : TypeInfo { - override string toString() { return "cdouble[]"; } + @trusted: + const: + pure: + nothrow: + + override string toString() const pure nothrow @safe { return "cdouble[]"; } override hash_t getHash(in void* p) { cdouble[] s = *cast(cdouble[]*)p; diff --git a/src/rt/typeinfo/ti_Acfloat.d b/src/rt/typeinfo/ti_Acfloat.d index 3c16f5aad30..1e16a6c1913 100644 --- a/src/rt/typeinfo/ti_Acfloat.d +++ b/src/rt/typeinfo/ti_Acfloat.d @@ -20,7 +20,12 @@ private import rt.util.hash; class TypeInfo_Aq : TypeInfo { - override string toString() { return "cfloat[]"; } + @trusted: + const: + pure: + nothrow: + + override string toString() const pure nothrow @safe { return "cfloat[]"; } override hash_t getHash(in void* p) { cfloat[] s = *cast(cfloat[]*)p; diff --git a/src/rt/typeinfo/ti_Acreal.d b/src/rt/typeinfo/ti_Acreal.d index 1680b447c61..89b08aaaefd 100644 --- a/src/rt/typeinfo/ti_Acreal.d +++ b/src/rt/typeinfo/ti_Acreal.d @@ -20,7 +20,12 @@ private import rt.util.hash; class TypeInfo_Ac : TypeInfo { - override string toString() { return "creal[]"; } + @trusted: + const: + pure: + nothrow: + + override string toString() const pure nothrow @safe { return "creal[]"; } override hash_t getHash(in void* p) { creal[] s = *cast(creal[]*)p; diff --git a/src/rt/typeinfo/ti_Adouble.d b/src/rt/typeinfo/ti_Adouble.d index 236c0f918a2..eefd5ddc27b 100644 --- a/src/rt/typeinfo/ti_Adouble.d +++ b/src/rt/typeinfo/ti_Adouble.d @@ -20,7 +20,12 @@ private import rt.util.hash; class TypeInfo_Ad : TypeInfo { - override string toString() { return "double[]"; } + @trusted: + const: + pure: + nothrow: + + override string toString() const pure nothrow @safe { return "double[]"; } override hash_t getHash(in void* p) { double[] s = *cast(double[]*)p; @@ -96,7 +101,12 @@ class TypeInfo_Ad : TypeInfo class TypeInfo_Ap : TypeInfo_Ad { - override string toString() { return "idouble[]"; } + @trusted: + const: + pure: + nothrow: + + override string toString() const pure nothrow @safe { return "idouble[]"; } @property override TypeInfo next() nothrow pure { diff --git a/src/rt/typeinfo/ti_Afloat.d b/src/rt/typeinfo/ti_Afloat.d index 11bfdcc168d..e1b66c71431 100644 --- a/src/rt/typeinfo/ti_Afloat.d +++ b/src/rt/typeinfo/ti_Afloat.d @@ -20,7 +20,12 @@ private import rt.util.hash; class TypeInfo_Af : TypeInfo { - override string toString() { return "float[]"; } + @trusted: + const: + pure: + nothrow: + + override string toString() const pure nothrow @safe { return "float[]"; } override hash_t getHash(in void* p) { float[] s = *cast(float[]*)p; @@ -96,7 +101,12 @@ class TypeInfo_Af : TypeInfo class TypeInfo_Ao : TypeInfo_Af { - override string toString() { return "ifloat[]"; } + @trusted: + const: + pure: + nothrow: + + override string toString() const pure nothrow @safe { return "ifloat[]"; } @property override TypeInfo next() nothrow pure { diff --git a/src/rt/typeinfo/ti_Ag.d b/src/rt/typeinfo/ti_Ag.d index ec959bc9feb..b18b91fa703 100644 --- a/src/rt/typeinfo/ti_Ag.d +++ b/src/rt/typeinfo/ti_Ag.d @@ -21,7 +21,12 @@ private import rt.util.string; class TypeInfo_Ag : TypeInfo { - override string toString() { return "byte[]"; } + @trusted: + const: + pure: + nothrow: + + override string toString() const pure nothrow @safe { return "byte[]"; } override hash_t getHash(in void* p) { byte[] s = *cast(byte[]*)p; @@ -91,7 +96,12 @@ class TypeInfo_Ag : TypeInfo class TypeInfo_Ah : TypeInfo_Ag { - override string toString() { return "ubyte[]"; } + @trusted: + const: + pure: + nothrow: + + override string toString() const pure nothrow @safe { return "ubyte[]"; } override int compare(in void* p1, in void* p2) { @@ -111,7 +121,12 @@ class TypeInfo_Ah : TypeInfo_Ag class TypeInfo_Av : TypeInfo_Ah { - override string toString() { return "void[]"; } + @trusted: + const: + pure: + nothrow: + + override string toString() const pure nothrow @safe { return "void[]"; } @property override TypeInfo next() nothrow pure { @@ -123,7 +138,12 @@ class TypeInfo_Av : TypeInfo_Ah class TypeInfo_Ab : TypeInfo_Ah { - override string toString() { return "bool[]"; } + @trusted: + const: + pure: + nothrow: + + override string toString() const pure nothrow @safe { return "bool[]"; } @property override TypeInfo next() nothrow pure { @@ -135,7 +155,12 @@ class TypeInfo_Ab : TypeInfo_Ah class TypeInfo_Aa : TypeInfo_Ag { - override string toString() { return "char[]"; } + @trusted: + const: + pure: + nothrow: + + override string toString() const pure nothrow @safe { return "char[]"; } override hash_t getHash(in void* p) { char[] s = *cast(char[]*)p; @@ -196,7 +221,12 @@ else class TypeInfo_Aya : TypeInfo_Aa { - override string toString() { return "immutable(char)[]"; } + @trusted: + const: + pure: + nothrow: + + override string toString() const pure nothrow @safe { return "immutable(char)[]"; } @property override TypeInfo next() nothrow pure { diff --git a/src/rt/typeinfo/ti_Aint.d b/src/rt/typeinfo/ti_Aint.d index 7a198bb29e2..25094b5d16c 100644 --- a/src/rt/typeinfo/ti_Aint.d +++ b/src/rt/typeinfo/ti_Aint.d @@ -20,7 +20,12 @@ private import rt.util.hash; class TypeInfo_Ai : TypeInfo { - override string toString() { return "int[]"; } + @trusted: + const: + pure: + nothrow: + + override string toString() const pure nothrow @safe { return "int[]"; } override hash_t getHash(in void* p) { int[] s = *cast(int[]*)p; @@ -100,7 +105,12 @@ unittest class TypeInfo_Ak : TypeInfo_Ai { - override string toString() { return "uint[]"; } + @trusted: + const: + pure: + nothrow: + + override string toString() const pure nothrow @safe { return "uint[]"; } override int compare(in void* p1, in void* p2) { @@ -133,7 +143,12 @@ class TypeInfo_Ak : TypeInfo_Ai class TypeInfo_Aw : TypeInfo_Ak { - override string toString() { return "dchar[]"; } + @trusted: + const: + pure: + nothrow: + + override string toString() const pure nothrow @safe { return "dchar[]"; } @property override TypeInfo next() nothrow pure { diff --git a/src/rt/typeinfo/ti_Along.d b/src/rt/typeinfo/ti_Along.d index 0fab74560eb..183ade9e74b 100644 --- a/src/rt/typeinfo/ti_Along.d +++ b/src/rt/typeinfo/ti_Along.d @@ -20,7 +20,12 @@ private import rt.util.hash; class TypeInfo_Al : TypeInfo { - override string toString() { return "long[]"; } + @trusted: + const: + pure: + nothrow: + + override string toString() const pure nothrow @safe { return "long[]"; } override hash_t getHash(in void* p) { long[] s = *cast(long[]*)p; @@ -91,7 +96,12 @@ class TypeInfo_Al : TypeInfo class TypeInfo_Am : TypeInfo_Al { - override string toString() { return "ulong[]"; } + @trusted: + const: + pure: + nothrow: + + override string toString() const pure nothrow @safe { return "ulong[]"; } override int compare(in void* p1, in void* p2) { diff --git a/src/rt/typeinfo/ti_Areal.d b/src/rt/typeinfo/ti_Areal.d index 7700e5c4e49..a01c1965477 100644 --- a/src/rt/typeinfo/ti_Areal.d +++ b/src/rt/typeinfo/ti_Areal.d @@ -20,7 +20,12 @@ private import rt.util.hash; class TypeInfo_Ae : TypeInfo { - override string toString() { return "real[]"; } + @trusted: + const: + pure: + nothrow: + + override string toString() const pure nothrow @safe { return "real[]"; } override hash_t getHash(in void* p) { real[] s = *cast(real[]*)p; @@ -96,7 +101,12 @@ class TypeInfo_Ae : TypeInfo class TypeInfo_Aj : TypeInfo_Ae { - override string toString() { return "ireal[]"; } + @trusted: + const: + pure: + nothrow: + + override string toString() const pure nothrow @safe { return "ireal[]"; } @property override TypeInfo next() nothrow pure { diff --git a/src/rt/typeinfo/ti_Ashort.d b/src/rt/typeinfo/ti_Ashort.d index 3c74fe7b41c..0516ca312aa 100644 --- a/src/rt/typeinfo/ti_Ashort.d +++ b/src/rt/typeinfo/ti_Ashort.d @@ -20,7 +20,12 @@ private import rt.util.hash; class TypeInfo_As : TypeInfo { - override string toString() { return "short[]"; } + @trusted: + const: + pure: + nothrow: + + override string toString() const pure nothrow @safe { return "short[]"; } override hash_t getHash(in void* p) { short[] s = *cast(short[]*)p; @@ -89,7 +94,12 @@ class TypeInfo_As : TypeInfo class TypeInfo_At : TypeInfo_As { - override string toString() { return "ushort[]"; } + @trusted: + const: + pure: + nothrow: + + override string toString() const pure nothrow @safe { return "ushort[]"; } override int compare(in void* p1, in void* p2) { @@ -122,7 +132,12 @@ class TypeInfo_At : TypeInfo_As class TypeInfo_Au : TypeInfo_At { - override string toString() { return "wchar[]"; } + @trusted: + const: + pure: + nothrow: + + override string toString() const pure nothrow @safe { return "wchar[]"; } @property override TypeInfo next() nothrow pure { diff --git a/src/rt/typeinfo/ti_C.d b/src/rt/typeinfo/ti_C.d index 845b158f992..85bbf99354d 100644 --- a/src/rt/typeinfo/ti_C.d +++ b/src/rt/typeinfo/ti_C.d @@ -17,6 +17,11 @@ module rt.typeinfo.ti_C; class TypeInfo_C : TypeInfo { + @trusted: + const: + //pure: + //nothrow: + override hash_t getHash(in void* p) { Object o = *cast(Object*)p; diff --git a/src/rt/typeinfo/ti_byte.d b/src/rt/typeinfo/ti_byte.d index 367f1022be0..809473343c6 100644 --- a/src/rt/typeinfo/ti_byte.d +++ b/src/rt/typeinfo/ti_byte.d @@ -17,7 +17,12 @@ module rt.typeinfo.ti_byte; class TypeInfo_g : TypeInfo { - override string toString() { return "byte"; } + @trusted: + const: + pure: + nothrow: + + override string toString() const pure nothrow @safe { return "byte"; } override hash_t getHash(in void* p) { diff --git a/src/rt/typeinfo/ti_cdouble.d b/src/rt/typeinfo/ti_cdouble.d index 32b7dacd2ec..15bba902aae 100644 --- a/src/rt/typeinfo/ti_cdouble.d +++ b/src/rt/typeinfo/ti_cdouble.d @@ -19,12 +19,9 @@ private import rt.util.hash; class TypeInfo_r : TypeInfo { - override string toString() { return "cdouble"; } - - override hash_t getHash(in void* p) - { - return hashOf(p, cdouble.sizeof); - } + @trusted: + pure: + nothrow: static equals_t _equals(cdouble f1, cdouble f2) { @@ -47,6 +44,15 @@ class TypeInfo_r : TypeInfo return result; } + const: + + override string toString() const pure nothrow @safe { return "cdouble"; } + + override hash_t getHash(in void* p) + { + return hashOf(p, cdouble.sizeof); + } + override equals_t equals(in void* p1, in void* p2) { return _equals(*cast(cdouble *)p1, *cast(cdouble *)p2); diff --git a/src/rt/typeinfo/ti_cfloat.d b/src/rt/typeinfo/ti_cfloat.d index c3788d90dad..3c370c5befe 100644 --- a/src/rt/typeinfo/ti_cfloat.d +++ b/src/rt/typeinfo/ti_cfloat.d @@ -19,12 +19,9 @@ private import rt.util.hash; class TypeInfo_q : TypeInfo { - override string toString() { return "cfloat"; } - - override hash_t getHash(in void* p) - { - return hashOf(p, cfloat.sizeof); - } + @trusted: + pure: + nothrow: static equals_t _equals(cfloat f1, cfloat f2) { @@ -47,6 +44,15 @@ class TypeInfo_q : TypeInfo return result; } + const: + + override string toString() const pure nothrow @safe { return "cfloat"; } + + override hash_t getHash(in void* p) + { + return hashOf(p, cfloat.sizeof); + } + override equals_t equals(in void* p1, in void* p2) { return _equals(*cast(cfloat *)p1, *cast(cfloat *)p2); diff --git a/src/rt/typeinfo/ti_char.d b/src/rt/typeinfo/ti_char.d index 80de47ede7a..094745f45ca 100644 --- a/src/rt/typeinfo/ti_char.d +++ b/src/rt/typeinfo/ti_char.d @@ -17,7 +17,12 @@ module rt.typeinfo.ti_char; class TypeInfo_a : TypeInfo { - override string toString() { return "char"; } + @trusted: + const: + pure: + nothrow: + + override string toString() const pure nothrow @safe { return "char"; } override hash_t getHash(in void* p) { diff --git a/src/rt/typeinfo/ti_creal.d b/src/rt/typeinfo/ti_creal.d index 76af151727e..3bbb7580482 100644 --- a/src/rt/typeinfo/ti_creal.d +++ b/src/rt/typeinfo/ti_creal.d @@ -19,12 +19,9 @@ private import rt.util.hash; class TypeInfo_c : TypeInfo { - override string toString() { return "creal"; } - - override hash_t getHash(in void* p) - { - return hashOf(p, creal.sizeof); - } + @trusted: + pure: + nothrow: static equals_t _equals(creal f1, creal f2) { @@ -47,6 +44,15 @@ class TypeInfo_c : TypeInfo return result; } + const: + + override string toString() const pure nothrow @safe { return "creal"; } + + override hash_t getHash(in void* p) + { + return hashOf(p, creal.sizeof); + } + override equals_t equals(in void* p1, in void* p2) { return _equals(*cast(creal *)p1, *cast(creal *)p2); diff --git a/src/rt/typeinfo/ti_dchar.d b/src/rt/typeinfo/ti_dchar.d index 66c56f7a329..93a30dc47d4 100644 --- a/src/rt/typeinfo/ti_dchar.d +++ b/src/rt/typeinfo/ti_dchar.d @@ -17,7 +17,12 @@ module rt.typeinfo.ti_dchar; class TypeInfo_w : TypeInfo { - override string toString() { return "dchar"; } + @trusted: + const: + pure: + nothrow: + + override string toString() const pure nothrow @safe { return "dchar"; } override hash_t getHash(in void* p) { diff --git a/src/rt/typeinfo/ti_delegate.d b/src/rt/typeinfo/ti_delegate.d index 3060ea718b0..c4d9e45337b 100644 --- a/src/rt/typeinfo/ti_delegate.d +++ b/src/rt/typeinfo/ti_delegate.d @@ -21,6 +21,11 @@ alias void delegate(int) dg; class TypeInfo_D : TypeInfo { + @trusted: + const: + pure: + nothrow: + override hash_t getHash(in void* p) { return hashOf(p, dg.sizeof); diff --git a/src/rt/typeinfo/ti_double.d b/src/rt/typeinfo/ti_double.d index 6219c76cdfd..89eb667961d 100644 --- a/src/rt/typeinfo/ti_double.d +++ b/src/rt/typeinfo/ti_double.d @@ -19,12 +19,9 @@ private import rt.util.hash; class TypeInfo_d : TypeInfo { - override string toString() { return "double"; } - - override hash_t getHash(in void* p) - { - return hashOf(p, double.sizeof); - } + @trusted: + pure: + nothrow: static equals_t _equals(double f1, double f2) { @@ -46,6 +43,15 @@ class TypeInfo_d : TypeInfo return (d1 == d2) ? 0 : ((d1 < d2) ? -1 : 1); } + const: + + override string toString() const pure nothrow @safe { return "double"; } + + override hash_t getHash(in void* p) + { + return hashOf(p, double.sizeof); + } + override equals_t equals(in void* p1, in void* p2) { return _equals(*cast(double *)p1, *cast(double *)p2); diff --git a/src/rt/typeinfo/ti_float.d b/src/rt/typeinfo/ti_float.d index 5d533f1820c..c2620818c92 100644 --- a/src/rt/typeinfo/ti_float.d +++ b/src/rt/typeinfo/ti_float.d @@ -17,12 +17,9 @@ module rt.typeinfo.ti_float; class TypeInfo_f : TypeInfo { - override string toString() { return "float"; } - - override hash_t getHash(in void* p) - { - return *cast(uint *)p; - } + @trusted: + pure: + nothrow: static equals_t _equals(float f1, float f2) { @@ -44,6 +41,15 @@ class TypeInfo_f : TypeInfo return (d1 == d2) ? 0 : ((d1 < d2) ? -1 : 1); } + const: + + override string toString() const pure nothrow @safe { return "float"; } + + override hash_t getHash(in void* p) + { + return *cast(uint *)p; + } + override equals_t equals(in void* p1, in void* p2) { return _equals(*cast(float *)p1, *cast(float *)p2); diff --git a/src/rt/typeinfo/ti_idouble.d b/src/rt/typeinfo/ti_idouble.d index da9f44981c0..e0895d7d0ce 100644 --- a/src/rt/typeinfo/ti_idouble.d +++ b/src/rt/typeinfo/ti_idouble.d @@ -19,5 +19,10 @@ private import rt.typeinfo.ti_double; class TypeInfo_p : TypeInfo_d { - override string toString() { return "idouble"; } + @trusted: + const: + pure: + nothrow: + + override string toString() const pure nothrow @safe { return "idouble"; } } diff --git a/src/rt/typeinfo/ti_ifloat.d b/src/rt/typeinfo/ti_ifloat.d index dd773b92223..e1e905a840a 100644 --- a/src/rt/typeinfo/ti_ifloat.d +++ b/src/rt/typeinfo/ti_ifloat.d @@ -19,5 +19,10 @@ private import rt.typeinfo.ti_float; class TypeInfo_o : TypeInfo_f { - override string toString() { return "ifloat"; } + @trusted: + const: + pure: + nothrow: + + override string toString() const pure nothrow @safe { return "ifloat"; } } diff --git a/src/rt/typeinfo/ti_int.d b/src/rt/typeinfo/ti_int.d index 6c4ff64f4de..06c00291c5e 100644 --- a/src/rt/typeinfo/ti_int.d +++ b/src/rt/typeinfo/ti_int.d @@ -17,7 +17,12 @@ module rt.typeinfo.ti_int; class TypeInfo_i : TypeInfo { - override string toString() { return "int"; } + @trusted: + const: + pure: + nothrow: + + override string toString() const pure nothrow @safe { return "int"; } override hash_t getHash(in void* p) { diff --git a/src/rt/typeinfo/ti_ireal.d b/src/rt/typeinfo/ti_ireal.d index b8f24d4f697..207294f46ce 100644 --- a/src/rt/typeinfo/ti_ireal.d +++ b/src/rt/typeinfo/ti_ireal.d @@ -19,5 +19,10 @@ private import rt.typeinfo.ti_real; class TypeInfo_j : TypeInfo_e { - override string toString() { return "ireal"; } + @trusted: + const: + pure: + nothrow: + + override string toString() const pure nothrow @safe { return "ireal"; } } diff --git a/src/rt/typeinfo/ti_long.d b/src/rt/typeinfo/ti_long.d index c59ede2b259..eeb308d0388 100644 --- a/src/rt/typeinfo/ti_long.d +++ b/src/rt/typeinfo/ti_long.d @@ -19,7 +19,12 @@ private import rt.util.hash; class TypeInfo_l : TypeInfo { - override string toString() { return "long"; } + @trusted: + const: + pure: + nothrow: + + override string toString() const pure nothrow @safe { return "long"; } override hash_t getHash(in void* p) { diff --git a/src/rt/typeinfo/ti_ptr.d b/src/rt/typeinfo/ti_ptr.d index 8b5b9a3839f..85db0ee5698 100644 --- a/src/rt/typeinfo/ti_ptr.d +++ b/src/rt/typeinfo/ti_ptr.d @@ -17,6 +17,11 @@ module rt.typeinfo.ti_ptr; class TypeInfo_P : TypeInfo { + @trusted: + const: + pure: + nothrow: + override hash_t getHash(in void* p) { return cast(uint)*cast(void* *)p; diff --git a/src/rt/typeinfo/ti_real.d b/src/rt/typeinfo/ti_real.d index d14a0e86fd0..0ed103807bb 100644 --- a/src/rt/typeinfo/ti_real.d +++ b/src/rt/typeinfo/ti_real.d @@ -19,12 +19,9 @@ private import rt.util.hash; class TypeInfo_e : TypeInfo { - override string toString() { return "real"; } - - override hash_t getHash(in void* p) - { - return hashOf(p, real.sizeof); - } + @trusted: + pure: + nothrow: static equals_t _equals(real f1, real f2) { @@ -46,6 +43,15 @@ class TypeInfo_e : TypeInfo return (d1 == d2) ? 0 : ((d1 < d2) ? -1 : 1); } + const: + + override string toString() const pure nothrow @safe { return "real"; } + + override hash_t getHash(in void* p) + { + return hashOf(p, real.sizeof); + } + override equals_t equals(in void* p1, in void* p2) { return _equals(*cast(real *)p1, *cast(real *)p2); diff --git a/src/rt/typeinfo/ti_short.d b/src/rt/typeinfo/ti_short.d index 30ba11b7fc8..101340ef47f 100644 --- a/src/rt/typeinfo/ti_short.d +++ b/src/rt/typeinfo/ti_short.d @@ -17,7 +17,12 @@ module rt.typeinfo.ti_short; class TypeInfo_s : TypeInfo { - override string toString() { return "short"; } + @trusted: + const: + pure: + nothrow: + + override string toString() const pure nothrow @safe { return "short"; } override hash_t getHash(in void* p) { diff --git a/src/rt/typeinfo/ti_ubyte.d b/src/rt/typeinfo/ti_ubyte.d index da7bf631f11..9779d4c7885 100644 --- a/src/rt/typeinfo/ti_ubyte.d +++ b/src/rt/typeinfo/ti_ubyte.d @@ -17,7 +17,12 @@ module rt.typeinfo.ti_ubyte; class TypeInfo_h : TypeInfo { - override string toString() { return "ubyte"; } + @trusted: + const: + pure: + nothrow: + + override string toString() const pure nothrow @safe { return "ubyte"; } override hash_t getHash(in void* p) { @@ -51,5 +56,10 @@ class TypeInfo_h : TypeInfo class TypeInfo_b : TypeInfo_h { - override string toString() { return "bool"; } + @trusted: + const: + pure: + nothrow: + + override string toString() const pure nothrow @safe { return "bool"; } } diff --git a/src/rt/typeinfo/ti_uint.d b/src/rt/typeinfo/ti_uint.d index 46dda8dc21c..28d3651287f 100644 --- a/src/rt/typeinfo/ti_uint.d +++ b/src/rt/typeinfo/ti_uint.d @@ -17,7 +17,12 @@ module rt.typeinfo.ti_uint; class TypeInfo_k : TypeInfo { - override string toString() { return "uint"; } + @trusted: + const: + pure: + nothrow: + + override string toString() const pure nothrow @safe { return "uint"; } override hash_t getHash(in void* p) { diff --git a/src/rt/typeinfo/ti_ulong.d b/src/rt/typeinfo/ti_ulong.d index 12e23dd082a..85381f1e353 100644 --- a/src/rt/typeinfo/ti_ulong.d +++ b/src/rt/typeinfo/ti_ulong.d @@ -19,7 +19,12 @@ private import rt.util.hash; class TypeInfo_m : TypeInfo { - override string toString() { return "ulong"; } + @trusted: + const: + pure: + nothrow: + + override string toString() const pure nothrow @safe { return "ulong"; } override hash_t getHash(in void* p) { diff --git a/src/rt/typeinfo/ti_ushort.d b/src/rt/typeinfo/ti_ushort.d index abc8c21ab69..fe759f60743 100644 --- a/src/rt/typeinfo/ti_ushort.d +++ b/src/rt/typeinfo/ti_ushort.d @@ -17,7 +17,12 @@ module rt.typeinfo.ti_ushort; class TypeInfo_t : TypeInfo { - override string toString() { return "ushort"; } + @trusted: + const: + pure: + nothrow: + + override string toString() const pure nothrow @safe { return "ushort"; } override hash_t getHash(in void* p) { diff --git a/src/rt/typeinfo/ti_void.d b/src/rt/typeinfo/ti_void.d index 5555624b812..66bbc2a1eea 100644 --- a/src/rt/typeinfo/ti_void.d +++ b/src/rt/typeinfo/ti_void.d @@ -17,7 +17,12 @@ module rt.typeinfo.ti_void; class TypeInfo_v : TypeInfo { - override string toString() { return "void"; } + @trusted: + const: + pure: + nothrow: + + override string toString() const pure nothrow @safe { return "void"; } override hash_t getHash(in void* p) { diff --git a/src/rt/typeinfo/ti_wchar.d b/src/rt/typeinfo/ti_wchar.d index 9fa0ee85864..35188b19aeb 100644 --- a/src/rt/typeinfo/ti_wchar.d +++ b/src/rt/typeinfo/ti_wchar.d @@ -17,6 +17,11 @@ module rt.typeinfo.ti_wchar; class TypeInfo_u : TypeInfo { + @trusted: + const: + pure: + nothrow: + override string toString() { return "wchar"; } override hash_t getHash(in void* p) @@ -34,7 +39,7 @@ class TypeInfo_u : TypeInfo return *cast(wchar *)p1 - *cast(wchar *)p2; } - @property override size_t tsize() nothrow pure + @property override size_t tsize() { return wchar.sizeof; } @@ -48,7 +53,7 @@ class TypeInfo_u : TypeInfo *cast(wchar *)p2 = t; } - override void[] init() nothrow pure + override void[] init() { static immutable wchar c; return (cast(wchar *)&c)[0 .. 1]; diff --git a/src/rt/util/hash.d b/src/rt/util/hash.d index 9613678b4c4..c88448a22b0 100644 --- a/src/rt/util/hash.d +++ b/src/rt/util/hash.d @@ -22,6 +22,7 @@ version( AnyX86 ) version = HasUnalignedOps; +@trusted pure nothrow hash_t hashOf( const (void)* buf, size_t len, hash_t seed = 0 ) { /* @@ -32,14 +33,14 @@ hash_t hashOf( const (void)* buf, size_t len, hash_t seed = 0 ) */ version( HasUnalignedOps ) { - static uint get16bits( const (ubyte)* x ) + static uint get16bits( const (ubyte)* x ) pure nothrow { return *cast(ushort*) x; } } else { - static uint get16bits( const (ubyte)* x ) + static uint get16bits( const (ubyte)* x ) pure nothrow { return ((cast(uint) x[1]) << 8) + (cast(uint) x[0]); } diff --git a/src/rt/util/string.d b/src/rt/util/string.d index 550b6900696..eeeaf9b3ba4 100644 --- a/src/rt/util/string.d +++ b/src/rt/util/string.d @@ -15,6 +15,10 @@ module rt.util.string; private import core.stdc.string; +@trusted: +pure: +nothrow: + // This should be renamed to uintToString() char[] intToString( char[] buf, uint val ) {