Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Issue 1824 - Object not const correct #72

Merged
merged 6 commits into from

5 participants

Hara Kenji Daniel Murphy Jonathan M Davis Andrei Alexandrescu Adam Wilson
Hara Kenji
Collaborator

http://d.puremagic.com/issues/show_bug.cgi?id=1824
D-Programming-Language/dmd#387
#72
D-Programming-Language/phobos#262

  1. Change Object.opEquals, opCmp, toHash and toString to const member functions.
  2. Change using TypeInfo objects to const.
Daniel Murphy
Collaborator

You're missing a const in a couple of opApply signatures: http://yebblies.com/results/dmd_387_9rnsr_constApply_druntimebuild.txt

Jonathan M Davis
Collaborator

Personally, I'd argue that all of those consts should go after the functions that they're on. Putting them in front risks confusion, since then it looks like they're marking the return types and not the functions.

Jonathan M Davis
Collaborator

Another thing to consider (though it shouldn't be dealt with in this pull request regardless) is whether some of Object's functions should be pure as well. I'm not sure if we can for sure or not, but their lack of purity could be a problem. If opEquals isn't pure, can objects be compared for equality within a pure function? And not being to use toString in a pure function could be really annoying (though as long as format isn't pure, there's no way that toString could be). To some extent, the problem is solved by the fact that you can override Object's functions with versions with stricter attributes, so as long as you do that and specifically use the derived type, then you should be okay. But if it's actually reasonably to require that functions such as toString be pure, then we should do it. The question though is whether that's reasonable or not. I should probably bring it up in the newsgroup. Regardless, it's not something that should be dealt with in this pull request.

Jonathan M Davis
Collaborator

Another thing, we need to have non-const versions of Object's const functions, so that those who want caching and the like in those functions can have it with non-const objects.

And again, I would strongly argue that const should go after the functions and not before. It's bad enough that it's even legal D to put it in front. It's not something that we should be doing.

Hara Kenji
Collaborator

Hmm, I had not focused so much that ambiguity, but also I can agree to your point.
OK. I'll fix it after a while.

Hara Kenji
Collaborator

Change prefix const to suffix.
And add feature for opEquals migration. See discussion in D-Programming-Language/phobos#262

Hara Kenji
Collaborator

Updated for interface and typedef'ed class/interface comparison for fixing issue 4088.

Andrei Alexandrescu
Owner

rebase? I'll also pull the Phobos request.

Hara Kenji
Collaborator

Rebased.

Jonathan M Davis
Collaborator

According to the pull tester, these changes are currently failing.

Andrei Alexandrescu andralex was assigned
Andrei Alexandrescu
Owner

Yah, @9rnsr - this seems to be failing, and is out of sync again. Could you please take a look? I'll be back on this in a week if not earlier. Thanks!

Hara Kenji
Collaborator

OK. Rebased and fixed for git head.

Adam Wilson

@9rnsr, this needs another rebase, we've been doing merges all day and something got changed in object_.d

Hara Kenji
Collaborator

Thanks for the info. Re-rebasing is done.

Andrei Alexandrescu andralex merged commit d39bd49 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 594 additions and 345 deletions.
  1. +152 −30 import/object.di
  2. +1 −1  src/core/demangle.d
  3. +3 −3 src/core/runtime.d
  4. +3 −3 src/core/sys/windows/stacktrace.d
  5. +272 −178 src/object_.d
  6. +21 −21 src/rt/lifetime.d
  7. +8 −5 src/rt/typeinfo/ti_AC.d
  8. +4 −3 src/rt/typeinfo/ti_Acdouble.d
  9. +4 −3 src/rt/typeinfo/ti_Acfloat.d
  10. +4 −3 src/rt/typeinfo/ti_Acreal.d
  11. +5 −4 src/rt/typeinfo/ti_Adouble.d
  12. +5 −4 src/rt/typeinfo/ti_Afloat.d
  13. +11 −9 src/rt/typeinfo/ti_Ag.d
  14. +6 −5 src/rt/typeinfo/ti_Aint.d
  15. +5 −4 src/rt/typeinfo/ti_Along.d
  16. +5 −4 src/rt/typeinfo/ti_Areal.d
  17. +6 −5 src/rt/typeinfo/ti_Ashort.d
  18. +4 −3 src/rt/typeinfo/ti_C.d
  19. +1 −1  src/rt/typeinfo/ti_byte.d
  20. +9 −6 src/rt/typeinfo/ti_cdouble.d
  21. +9 −6 src/rt/typeinfo/ti_cfloat.d
  22. +4 −3 src/rt/typeinfo/ti_char.d
  23. +9 −6 src/rt/typeinfo/ti_creal.d
  24. +4 −3 src/rt/typeinfo/ti_dchar.d
  25. +2 −2 src/rt/typeinfo/ti_delegate.d
  26. +7 −5 src/rt/typeinfo/ti_double.d
  27. +6 −4 src/rt/typeinfo/ti_float.d
  28. +1 −1  src/rt/typeinfo/ti_int.d
  29. +2 −2 src/rt/typeinfo/ti_long.d
  30. +2 −2 src/rt/typeinfo/ti_ptr.d
  31. +7 −5 src/rt/typeinfo/ti_real.d
  32. +1 −1  src/rt/typeinfo/ti_short.d
  33. +1 −1  src/rt/typeinfo/ti_ubyte.d
  34. +1 −1  src/rt/typeinfo/ti_uint.d
  35. +2 −2 src/rt/typeinfo/ti_ulong.d
  36. +1 −1  src/rt/typeinfo/ti_ushort.d
  37. +2 −2 src/rt/typeinfo/ti_void.d
  38. +4 −3 src/rt/typeinfo/ti_wchar.d
182 import/object.di
View
@@ -30,11 +30,11 @@ alias immutable(dchar)[] dstring;
class Object
{
- string toString();
- hash_t toHash() @trusted nothrow;
- int opCmp(Object o);
- equals_t opEquals(Object o);
- equals_t opEquals(Object lhs, Object rhs);
+ string toString() const;
+ hash_t toHash() @trusted nothrow const;
+ int opCmp(const Object o) const;
+ equals_t opEquals(const Object o) const;
+ equals_t opEquals(const Object lhs, const Object rhs) const;
interface Monitor
{
@@ -45,9 +45,131 @@ class Object
static Object factory(string classname);
}
-bool opEquals(const Object lhs, const Object rhs);
-bool opEquals(Object lhs, Object rhs);
-//bool opEquals(TypeInfo lhs, TypeInfo rhs);
+bool opEquals(Lhs, Rhs)(Lhs lhs, Rhs rhs)
+ if (is(Lhs == class) && is(Rhs == class))
+{
+ // If aliased to the same object or both null => equal
+ if (lhs is rhs) return true;
+
+ static if (is(Lhs == shared) || is(Rhs == shared))
+ {
+ // If either is shared, is defined only equality comparisons.
+ return false;
+ }
+ else
+ {
+ version (all) // allow direct comparison
+ {
+ // If either is null => non-equal
+ if (lhs is null || rhs is null) return false;
+
+ // If same exact type => one call to method opEquals
+ if (typeid(lhs) is typeid(rhs) || typeid(lhs).opEquals(typeid(rhs)))
+ return lhs.opEquals(rhs);
+
+ // General case => symmetric calls to method opEquals
+ return lhs.opEquals(rhs) && rhs.opEquals(lhs);
+ }
+ else // always compare with const(Object)
+ {
+ return _ObjectEq(lhs, rhs);
+ }
+ }
+}
+
+bool opEquals(Lhs, Rhs)(Lhs lhs, Rhs rhs)
+ if (is(Lhs == interface) || is(Rhs == interface))
+{
+ // If aliased to the same object or both null => equal
+ static if (is(typeof(lhs is rhs)))
+ {
+ if (lhs is rhs) return true;
+ }
+
+ static if (is(Lhs == shared) || is(Rhs == shared))
+ {
+ // If either is shared, is defined only equality comparisons.
+ return false;
+ }
+ else
+ {
+ // If either is interface, downcast to Object and keep qualifier
+ static if (is(Lhs == interface))
+ {
+ static if (is(Lhs == shared))
+ auto lho = cast(shared const(Object))lhs;
+ else
+ auto lho = cast(const Object)lhs;
+ // If C++ interface, result is null
+ }
+ else
+ alias lhs lho;
+
+ static if (is(Rhs == interface))
+ {
+ static if (is(Rhs == shared))
+ auto rho = cast(shared const(Object))rhs;
+ else
+ auto rho = cast(const Object)rhs;
+ }
+ else
+ alias rhs rho;
+
+ return _ObjectEq(lho, rho);
+ }
+}
+
+deprecated bool opEquals(Lhs, Rhs)(Lhs lhs, Rhs rhs)
+ if (is(Lhs == typedef) || is(Rhs == typedef))
+{
+ static if (is(Lhs LhsB == typedef))
+ {
+ static if (is(Lhs == immutable))
+ alias immutable(LhsB) Lhs2;
+ else static if (is(Lhs == const))
+ {
+ static if (is(Lhs == shared))
+ alias const(shared(LhsB)) Lhs2;
+ else
+ alias const(LhsB) Lhs2;
+ }
+ else
+ {
+ static if (is(Lhs == shared))
+ alias shared(LhsB) Lhs2;
+ else
+ alias LhsB Lhs2;
+ }
+ }
+ else
+ alias Lhs Lhs2;
+
+ static if (is(Rhs RhsB == typedef))
+ {
+ static if (is(Rhs == immutable))
+ alias immutable(RhsB) Rhs2;
+ else static if (is(Rhs == const))
+ {
+ static if (is(Rhs == shared))
+ alias const(shared(RhsB)) Rhs2;
+ else
+ alias const(RhsB) Rhs2;
+ }
+ else
+ {
+ static if (is(Rhs == shared))
+ alias shared(RhsB) Rhs2;
+ else
+ alias RhsB Rhs2;
+ }
+ }
+ else
+ alias Rhs Rhs2;
+
+ return opEquals(cast(Lhs2)lhs, cast(Rhs2)rhs);
+}
+
+private bool _ObjectEq(const Object lhs, const Object rhs);
void setSameMutex(shared Object ownee, shared Object owner);
@@ -66,18 +188,18 @@ struct OffsetTypeInfo
class TypeInfo
{
- hash_t getHash(in void* p) @trusted nothrow;
- equals_t equals(in void* p1, in void* p2);
- int compare(in void* p1, in void* p2);
+ hash_t getHash(in void* p) @trusted nothrow const;
+ equals_t equals(in void* p1, in void* p2) const;
+ int compare(in void* p1, in void* p2) const;
@property size_t tsize() nothrow pure const @safe;
- void swap(void* p1, void* p2);
- @property TypeInfo next() nothrow pure;
+ void swap(void* p1, void* p2) const;
+ @property TypeInfo next() nothrow pure const;
const(void)[] init() nothrow pure const @safe; // TODO: make this a property, but may need to be renamed to diambiguate with T.init...
@property uint flags() nothrow pure const @safe;
// 1: // has possible pointers into GC memory
- OffsetTypeInfo[] offTi();
- void destroy(void* p);
- void postblit(void* p);
+ const(OffsetTypeInfo)[] offTi() const;
+ void destroy(void* p) const;
+ void postblit(void* p) const;
@property size_t talign() nothrow pure const @safe;
version (X86_64) int argTypes(out TypeInfo arg1, out TypeInfo arg2) @safe nothrow;
@property immutable(void)* rtInfo() nothrow pure const @safe;
@@ -103,15 +225,15 @@ class TypeInfo_Pointer : TypeInfo
class TypeInfo_Array : TypeInfo
{
override string toString();
- override equals_t opEquals(Object o);
+ override equals_t opEquals(const Object o);
override hash_t getHash(in void* p) @trusted;
override equals_t equals(in void* p1, in void* p2);
override int compare(in void* p1, in void* p2);
- @property override size_t tsize() nothrow pure;
+ override @property size_t tsize() nothrow pure;
override void swap(void* p1, void* p2);
- @property override TypeInfo next() nothrow pure;
- @property override uint flags() nothrow pure;
- @property override size_t talign() nothrow pure;
+ override @property TypeInfo next() nothrow pure;
+ override @property uint flags() nothrow pure;
+ override @property size_t talign() nothrow pure;
version (X86_64) override int argTypes(out TypeInfo arg1, out TypeInfo arg2);
TypeInfo value;
@@ -147,8 +269,8 @@ class TypeInfo_Delegate : TypeInfo
class TypeInfo_Class : TypeInfo
{
- @property auto info() @safe nothrow pure { return this; }
- @property auto typeinfo() @safe nothrow pure { return this; }
+ @property auto info() @safe nothrow pure const { return this; }
+ @property auto typeinfo() @safe nothrow pure const { return this; }
byte[] init; // class static initializer
string name; // class name
@@ -169,8 +291,8 @@ class TypeInfo_Class : TypeInfo
void* defaultConstructor;
immutable(void)* m_rtInfo; // data for precise GC
- static TypeInfo_Class find(in char[] classname);
- Object create();
+ static const(TypeInfo_Class) find(in char[] classname);
+ Object create() const;
}
alias TypeInfo_Class ClassInfo;
@@ -239,7 +361,7 @@ class MemberInfo_field : MemberInfo
{
this(string name, TypeInfo ti, size_t offset);
- @property override string name() nothrow pure;
+ override @property string name() nothrow pure;
@property TypeInfo typeInfo() nothrow pure;
@property size_t offset() nothrow pure;
}
@@ -255,7 +377,7 @@ class MemberInfo_function : MemberInfo
this(string name, TypeInfo ti, void* fp, uint flags);
- @property override string name() nothrow pure;
+ override @property string name() nothrow pure;
@property TypeInfo typeInfo() nothrow pure;
@property void* fp() nothrow pure;
@property uint flags() nothrow pure;
@@ -316,9 +438,9 @@ class Throwable : Object
{
interface TraceInfo
{
- int opApply(scope int delegate(ref char[]));
- int opApply(scope int delegate(ref size_t, ref char[]));
- string toString();
+ int opApply(scope int delegate(ref const(char[]))) const;
+ int opApply(scope int delegate(ref size_t, ref const(char[]))) const;
+ string toString() const;
}
string msg;
2  src/core/demangle.d
View
@@ -1450,7 +1450,7 @@ private struct Demangle
{
debug(info)
{
- auto msg = e.toString;
+ auto msg = e.toString();
printf( "error: %.*s\n", cast(int) msg.length, msg.ptr );
}
if( dst.length < buf.length )
6 src/core/runtime.d
View
@@ -420,15 +420,15 @@ Throwable.TraceInfo defaultTraceHandler( void* ptr = null )
free( framelist );
}
- override int opApply( scope int delegate(ref char[]) dg )
+ override int opApply( scope int delegate(ref const(char[])) dg ) const
{
- return opApply( (ref size_t, ref char[] buf)
+ return opApply( (ref size_t, ref const(char[]) buf)
{
return dg( buf );
} );
}
- override int opApply( scope int delegate(ref size_t, ref char[]) dg )
+ override int opApply( scope int delegate(ref size_t, ref const(char[])) dg ) const
{
version( Posix )
{
6 src/core/sys/windows/stacktrace.d
View
@@ -42,16 +42,16 @@ public:
}
- int opApply( scope int delegate(ref char[]) dg )
+ int opApply( scope int delegate(ref const(char[])) dg ) const
{
- return opApply( (ref size_t, ref char[] buf)
+ return opApply( (ref size_t, ref const(char[]) buf)
{
return dg( buf );
});
}
- int opApply( scope int delegate(ref size_t, ref char[]) dg )
+ int opApply( scope int delegate(ref size_t, ref const(char[])) dg ) const
{
int result;
450 src/object_.d
View
@@ -31,9 +31,9 @@ private
debug(PRINTF) import core.stdc.stdio;
extern (C) void onOutOfMemoryError();
- extern (C) Object _d_newclass(TypeInfo_Class ci);
- extern (C) void _d_arrayshrinkfit(TypeInfo ti, void[] arr);
- extern (C) size_t _d_arraysetcapacity(TypeInfo ti, size_t newcapacity, void *arrptr) pure nothrow;
+ extern (C) Object _d_newclass(const TypeInfo_Class ci);
+ extern (C) void _d_arrayshrinkfit(const TypeInfo ti, void[] arr);
+ extern (C) size_t _d_arraysetcapacity(const TypeInfo ti, size_t newcapacity, void *arrptr) pure nothrow;
extern (C) void rt_finalize(void *data, bool det=true);
}
@@ -76,7 +76,7 @@ class Object
/**
* Convert Object to a human readable string.
*/
- string toString()
+ string toString() const
{
return this.classinfo.name;
}
@@ -84,7 +84,7 @@ class Object
/**
* Compute hash function for Object.
*/
- hash_t toHash() @trusted nothrow
+ hash_t toHash() @trusted nothrow const
{
// BUG: this prevents a compacting GC from working, needs to be fixed
return cast(hash_t)cast(void*)this;
@@ -99,7 +99,7 @@ class Object
* $(TR $(TD this &gt; obj) $(TD &gt; 0))
* )
*/
- int opCmp(Object o)
+ int opCmp(const Object o) const
{
// BUG: this prevents a compacting GC from working, needs to be fixed
//return cast(int)cast(void*)this - cast(int)cast(void*)o;
@@ -111,12 +111,12 @@ class Object
/**
* Returns !=0 if this object does have the same contents as obj.
*/
- equals_t opEquals(Object o)
+ equals_t opEquals(const Object o) const
{
return this is o;
}
- equals_t opEquals(Object lhs, Object rhs)
+ equals_t opEquals(const Object lhs, const Object rhs) const
{
if (lhs is rhs)
return true;
@@ -155,49 +155,138 @@ class Object
/************************
* Returns true if lhs and rhs are equal.
*/
-bool opEquals(const Object lhs, const Object rhs)
+bool opEquals(Lhs, Rhs)(Lhs lhs, Rhs rhs)
+ if (is(Lhs == class) && is(Rhs == class))
{
- // A hack for the moment.
- return opEquals(cast()lhs, cast()rhs);
+ // If aliased to the same object or both null => equal
+ if (lhs is rhs) return true;
+
+ static if (is(Lhs == shared) || is(Rhs == shared))
+ {
+ // If either is shared, is defined only equality comparisons.
+ return false;
+ }
+ else
+ {
+ version (all) // allow direct comparison
+ {
+ // If either is null => non-equal
+ if (lhs is null || rhs is null) return false;
+
+ // If same exact type => one call to method opEquals
+ if (typeid(lhs) is typeid(rhs) || typeid(lhs).opEquals(typeid(rhs)))
+ return lhs.opEquals(rhs);
+
+ // General case => symmetric calls to method opEquals
+ return lhs.opEquals(rhs) && rhs.opEquals(lhs);
+ }
+ else // always compare with const(Object)
+ {
+ return _ObjectEq(lhs, rhs);
+ }
+ }
}
-bool opEquals(Object lhs, Object rhs)
+bool opEquals(Lhs, Rhs)(Lhs lhs, Rhs rhs)
+ if (is(Lhs == interface) || is(Rhs == interface))
{
// If aliased to the same object or both null => equal
- if (lhs is rhs) return true;
+ static if (is(typeof(lhs is rhs)))
+ {
+ if (lhs is rhs) return true;
+ }
- // If either is null => non-equal
- if (lhs is null || rhs is null) return false;
+ static if (is(Lhs == shared) || is(Rhs == shared))
+ {
+ // If either is shared, is defined only equality comparisons.
+ return false;
+ }
+ else
+ {
+ // If either is interface, downcast to Object and keep qualifier
+ static if (is(Lhs == interface))
+ {
+ static if (is(Lhs == shared))
+ auto lho = cast(shared const(Object))lhs;
+ else
+ auto lho = cast(const Object)lhs;
+ // If C++ interface, result is null
+ }
+ else
+ alias lhs lho;
- // If same exact type => one call to method opEquals
- if (typeid(lhs) is typeid(rhs) || typeid(lhs).opEquals(typeid(rhs)))
- return lhs.opEquals(rhs);
+ static if (is(Rhs == interface))
+ {
+ static if (is(Rhs == shared))
+ auto rho = cast(shared const(Object))rhs;
+ else
+ auto rho = cast(const Object)rhs;
+ }
+ else
+ alias rhs rho;
- // General case => symmetric calls to method opEquals
- return lhs.opEquals(rhs) && rhs.opEquals(lhs);
+ return _ObjectEq(lho, rho);
+ }
}
-bool opEquals(TypeInfo lhs, TypeInfo rhs)
+deprecated bool opEquals(Lhs, Rhs)(Lhs lhs, Rhs rhs)
+ if (is(Lhs == typedef) || is(Rhs == typedef))
{
- // If aliased to the same object or both null => equal
- if (lhs is rhs) return true;
+ static if (is(Lhs LhsB == typedef))
+ {
+ static if (is(Lhs == immutable))
+ alias immutable(LhsB) Lhs2;
+ else static if (is(Lhs == const))
+ {
+ static if (is(Lhs == shared))
+ alias const(shared(LhsB)) Lhs2;
+ else
+ alias const(LhsB) Lhs2;
+ }
+ else
+ {
+ static if (is(Lhs == shared))
+ alias shared(LhsB) Lhs2;
+ else
+ alias LhsB Lhs2;
+ }
+ }
+ else
+ alias Lhs Lhs2;
+
+ static if (is(Rhs RhsB == typedef))
+ {
+ static if (is(Rhs == immutable))
+ alias immutable(RhsB) Rhs2;
+ else static if (is(Rhs == const))
+ {
+ static if (is(Rhs == shared))
+ alias const(shared(RhsB)) Rhs2;
+ else
+ alias const(RhsB) Rhs2;
+ }
+ else
+ {
+ static if (is(Rhs == shared))
+ alias shared(RhsB) Rhs2;
+ else
+ alias RhsB Rhs2;
+ }
+ }
+ else
+ alias Rhs Rhs2;
+ return opEquals(cast(Lhs2)lhs, cast(Rhs2)rhs);
+}
+
+private bool _ObjectEq(const Object lhs, const Object rhs)
+{
// If either is null => non-equal
if (lhs is null || rhs is null) return false;
// If same exact type => one call to method opEquals
- if (typeid(lhs) == typeid(rhs)) return lhs.opEquals(rhs);
-
- //printf("%.*s and %.*s, %d %d\n", lhs.toString(), rhs.toString(), lhs.opEquals(rhs), rhs.opEquals(lhs));
-
- // Factor out top level const
- // (This still isn't right, should follow same rules as compiler does for type equality.)
- TypeInfo_Const c = cast(TypeInfo_Const) lhs;
- if (c)
- lhs = c.base;
- c = cast(TypeInfo_Const) rhs;
- if (c)
- rhs = c.base;
+ if (typeid(lhs) is typeid(rhs) || typeid(lhs).opEquals(typeid(rhs)))
+ return lhs.opEquals(rhs);
// General case => symmetric calls to method opEquals
return lhs.opEquals(rhs) && rhs.opEquals(lhs);
@@ -239,7 +328,7 @@ struct OffsetTypeInfo
*/
class TypeInfo
{
- override hash_t toHash() @trusted
+ override hash_t toHash() @trusted const
{
try
{
@@ -255,7 +344,7 @@ class TypeInfo
}
}
- override int opCmp(Object o)
+ override int opCmp(const Object o) const
{
if (this is o)
return 0;
@@ -265,7 +354,7 @@ class TypeInfo
return dstrcmp(this.toString(), ti.toString());
}
- override equals_t opEquals(Object o)
+ override equals_t opEquals(const Object o) const
{
/* TypeInfo instances are singletons, but duplicates can exist
* across DLL's. Therefore, comparing for a name match is
@@ -273,24 +362,24 @@ class TypeInfo
*/
if (this is o)
return true;
- TypeInfo ti = cast(TypeInfo)o;
+ auto ti = cast(const TypeInfo)o;
return ti && this.toString() == ti.toString();
}
/// Returns a hash of the instance of a type.
- hash_t getHash(in void* p) @trusted nothrow { return cast(hash_t)p; }
+ hash_t getHash(in void* p) @trusted nothrow const { return cast(hash_t)p; }
/// Compares two instances for equality.
- equals_t equals(in void* p1, in void* p2) { return p1 == p2; }
+ equals_t equals(in void* p1, in void* p2) const { return p1 == p2; }
/// Compares two instances for &lt;, ==, or &gt;.
- int compare(in void* p1, in void* p2) { return 0; }
+ int compare(in void* p1, in void* p2) const { return 0; }
/// Returns size of the type.
@property size_t tsize() nothrow pure const @safe { return 0; }
/// Swaps two instances of the type.
- void swap(void* p1, void* p2)
+ void swap(void* p1, void* p2) const
{
size_t n = tsize;
for (size_t i = 0; i < n; i++)
@@ -303,7 +392,7 @@ class TypeInfo
/// Get TypeInfo for 'next' type, as defined by what kind of type this is,
/// null if none.
- @property TypeInfo next() nothrow pure { return null; }
+ @property const(TypeInfo) next() nothrow pure const { return null; }
/// Return default initializer. If the type should be initialized to all zeros,
/// an array with a null ptr and a length equal to the type size will be returned.
@@ -314,11 +403,11 @@ class TypeInfo
@property uint flags() nothrow pure const @safe { return 0; }
/// Get type information on the contents of the type; null if not available
- OffsetTypeInfo[] offTi() { return null; }
+ const(OffsetTypeInfo)[] offTi() const { return null; }
/// Run the destructor on the object and all its sub-objects
- void destroy(void* p) {}
+ void destroy(void* p) const {}
/// Run the postblit on the object and all its sub-objects
- void postblit(void* p) {}
+ void postblit(void* p) const {}
/// Return alignment of type
@@ -328,7 +417,8 @@ class TypeInfo
* See X86-64 ABI 3.2.3
*/
version (X86_64) int argTypes(out TypeInfo arg1, out TypeInfo arg2) @safe nothrow
- { arg1 = this;
+ {
+ arg1 = this;
return 0;
}
@@ -341,25 +431,25 @@ class TypeInfo_Vector : TypeInfo
{
override string toString() { return "__vector(" ~ base.toString() ~ ")"; }
- override equals_t opEquals(Object o)
+ override equals_t opEquals(const Object o)
{
- TypeInfo_Vector c;
- return this is o ||
- ((c = cast(TypeInfo_Vector)o) !is null &&
- this.base == c.base);
+ if (this is o)
+ return true;
+ auto c = cast(const TypeInfo_Vector)o;
+ return c && this.base == c.base;
}
override hash_t getHash(in void* p) { return base.getHash(p); }
override equals_t equals(in void* p1, in void* p2) { return base.equals(p1, p2); }
override int compare(in void* p1, in void* p2) { return base.compare(p1, p2); }
- @property override size_t tsize() nothrow pure { return base.tsize; }
+ override @property size_t tsize() nothrow pure { return base.tsize; }
override void swap(void* p1, void* p2) { return base.swap(p1, p2); }
- @property override TypeInfo next() nothrow pure { return base.next; }
- @property override uint flags() nothrow pure { return base.flags; }
+ override @property const(TypeInfo) next() nothrow pure { return base.next; }
+ override @property uint flags() nothrow pure { return base.flags; }
override const(void)[] init() nothrow pure { return base.init(); }
- @property override size_t talign() nothrow pure { return 16; }
+ override @property size_t talign() nothrow pure { return 16; }
version (X86_64) override int argTypes(out TypeInfo arg1, out TypeInfo arg2)
{ return base.argTypes(arg1, arg2);
@@ -372,32 +462,33 @@ class TypeInfo_Typedef : TypeInfo
{
override string toString() { return name; }
- override equals_t opEquals(Object o)
+ override equals_t opEquals(const Object o)
{
- TypeInfo_Typedef c;
- return this is o ||
- ((c = cast(TypeInfo_Typedef)o) !is null &&
- this.name == c.name &&
- this.base == c.base);
+ if (this is o)
+ return true;
+ auto c = cast(const TypeInfo_Typedef)o;
+ return c && this.name == c.name &&
+ this.base == c.base;
}
override hash_t getHash(in void* p) { return base.getHash(p); }
override equals_t equals(in void* p1, in void* p2) { return base.equals(p1, p2); }
override int compare(in void* p1, in void* p2) { return base.compare(p1, p2); }
- @property override size_t tsize() nothrow pure { return base.tsize; }
+ override @property size_t tsize() nothrow pure { return base.tsize; }
override void swap(void* p1, void* p2) { return base.swap(p1, p2); }
- @property override TypeInfo next() nothrow pure { return base.next; }
- @property override uint flags() nothrow pure { return base.flags; }
+ override @property const(TypeInfo) next() nothrow pure { return base.next; }
+ override @property uint flags() nothrow pure { return base.flags; }
override const(void)[] init() nothrow pure const @safe { return m_init.length ? m_init : base.init(); }
- @property override size_t talign() nothrow pure { return base.talign; }
+ override @property size_t talign() nothrow pure { return base.talign; }
version (X86_64) override int argTypes(out TypeInfo arg1, out TypeInfo arg2)
- { return base.argTypes(arg1, arg2);
+ {
+ return base.argTypes(arg1, arg2);
}
- @property override immutable(void)* rtInfo() { return base.rtInfo; }
+ override @property immutable(void)* rtInfo() { return base.rtInfo; }
TypeInfo base;
string name;
@@ -413,12 +504,12 @@ class TypeInfo_Pointer : TypeInfo
{
override string toString() { return m_next.toString() ~ "*"; }
- override equals_t opEquals(Object o)
+ override equals_t opEquals(const Object o)
{
- TypeInfo_Pointer c;
- return this is o ||
- ((c = cast(TypeInfo_Pointer)o) !is null &&
- this.m_next == c.m_next);
+ if (this is o)
+ return true;
+ auto c = cast(const TypeInfo_Pointer)o;
+ return c && this.m_next == c.m_next;
}
override hash_t getHash(in void* p) @trusted
@@ -441,7 +532,7 @@ class TypeInfo_Pointer : TypeInfo
return 0;
}
- @property override size_t tsize() nothrow pure
+ override @property size_t tsize() nothrow pure
{
return (void*).sizeof;
}
@@ -453,8 +544,8 @@ class TypeInfo_Pointer : TypeInfo
*cast(void**)p2 = tmp;
}
- @property override TypeInfo next() nothrow pure { return m_next; }
- @property override uint flags() nothrow pure { return 1; }
+ override @property const(TypeInfo) next() nothrow pure { return m_next; }
+ override @property uint flags() nothrow pure { return 1; }
TypeInfo m_next;
}
@@ -463,12 +554,12 @@ class TypeInfo_Array : TypeInfo
{
override string toString() { return value.toString() ~ "[]"; }
- override equals_t opEquals(Object o)
+ override equals_t opEquals(const Object o)
{
- TypeInfo_Array c;
- return this is o ||
- ((c = cast(TypeInfo_Array)o) !is null &&
- this.value == c.value);
+ if (this is o)
+ return true;
+ auto c = cast(const TypeInfo_Array)o;
+ return c && this.value == c.value;
}
override hash_t getHash(in void* p) @trusted
@@ -510,7 +601,7 @@ class TypeInfo_Array : TypeInfo
return cast(int)a1.length - cast(int)a2.length;
}
- @property override size_t tsize() nothrow pure
+ override @property size_t tsize() nothrow pure
{
return (void[]).sizeof;
}
@@ -524,20 +615,21 @@ class TypeInfo_Array : TypeInfo
TypeInfo value;
- @property override TypeInfo next() nothrow pure
+ override @property const(TypeInfo) next() nothrow pure
{
return value;
}
- @property override uint flags() nothrow pure { return 1; }
+ override @property uint flags() nothrow pure { return 1; }
- @property override size_t talign() nothrow pure
+ override @property size_t talign() nothrow pure
{
return (void[]).alignof;
}
version (X86_64) override int argTypes(out TypeInfo arg1, out TypeInfo arg2)
- { arg1 = typeid(size_t);
+ {
+ arg1 = typeid(size_t);
arg2 = typeid(void*);
return 0;
}
@@ -551,13 +643,13 @@ class TypeInfo_StaticArray : TypeInfo
return cast(string)(value.toString() ~ "[" ~ tmp.intToString(len) ~ "]");
}
- override equals_t opEquals(Object o)
+ override equals_t opEquals(const Object o)
{
- TypeInfo_StaticArray c;
- return this is o ||
- ((c = cast(TypeInfo_StaticArray)o) !is null &&
- this.len == c.len &&
- this.value == c.value);
+ if (this is o)
+ return true;
+ auto c = cast(const TypeInfo_StaticArray)o;
+ return c && this.len == c.len &&
+ this.value == c.value;
}
override hash_t getHash(in void* p) @trusted
@@ -594,7 +686,7 @@ class TypeInfo_StaticArray : TypeInfo
return 0;
}
- @property override size_t tsize() nothrow pure
+ override @property size_t tsize() nothrow pure
{
return len * value.tsize;
}
@@ -612,7 +704,8 @@ class TypeInfo_StaticArray : TypeInfo
tmp = pbuffer = (new void[sz]).ptr;
for (size_t u = 0; u < len; u += sz)
- { size_t o = u * sz;
+ {
+ size_t o = u * sz;
memcpy(tmp, p1 + o, sz);
memcpy(p1 + o, p2 + o, sz);
memcpy(p2 + o, tmp, sz);
@@ -622,8 +715,8 @@ class TypeInfo_StaticArray : TypeInfo
}
override const(void)[] init() nothrow pure { return value.init(); }
- @property override TypeInfo next() nothrow pure { return value; }
- @property override uint flags() nothrow pure { return value.flags(); }
+ override @property const(TypeInfo) next() nothrow pure { return value; }
+ override @property uint flags() nothrow pure { return value.flags; }
override void destroy(void* p)
{
@@ -649,13 +742,14 @@ class TypeInfo_StaticArray : TypeInfo
TypeInfo value;
size_t len;
- @property override size_t talign() nothrow pure
+ override @property size_t talign() nothrow pure
{
return value.talign;
}
version (X86_64) override int argTypes(out TypeInfo arg1, out TypeInfo arg2)
- { arg1 = typeid(void*);
+ {
+ arg1 = typeid(void*);
return 0;
}
}
@@ -667,37 +761,38 @@ class TypeInfo_AssociativeArray : TypeInfo
return cast(string)(next.toString() ~ "[" ~ key.toString() ~ "]");
}
- override equals_t opEquals(Object o)
+ override equals_t opEquals(const Object o)
{
- TypeInfo_AssociativeArray c;
- return this is o ||
- ((c = cast(TypeInfo_AssociativeArray)o) !is null &&
- this.key == c.key &&
- this.value == c.value);
+ if (this is o)
+ return true;
+ auto c = cast(const TypeInfo_AssociativeArray)o;
+ return c && this.key == c.key &&
+ this.value == c.value;
}
// BUG: need to add the rest of the functions
- @property override size_t tsize() nothrow pure
+ override @property size_t tsize() nothrow pure
{
return (char[int]).sizeof;
}
- @property override TypeInfo next() nothrow pure { return value; }
- @property override uint flags() nothrow pure { return 1; }
+ override @property const(TypeInfo) next() nothrow pure { return value; }
+ override @property uint flags() nothrow pure { return 1; }
TypeInfo value;
TypeInfo key;
TypeInfo impl;
- @property override size_t talign() nothrow pure
+ override @property size_t talign() nothrow pure
{
return (char[int]).alignof;
}
version (X86_64) override int argTypes(out TypeInfo arg1, out TypeInfo arg2)
- { arg1 = typeid(void*);
+ {
+ arg1 = typeid(void*);
return 0;
}
}
@@ -709,17 +804,17 @@ class TypeInfo_Function : TypeInfo
return cast(string)(next.toString() ~ "()");
}
- override equals_t opEquals(Object o)
+ override equals_t opEquals(const Object o)
{
- TypeInfo_Function c;
- return this is o ||
- ((c = cast(TypeInfo_Function)o) !is null &&
- this.deco == c.deco);
+ if (this is o)
+ return true;
+ auto c = cast(const TypeInfo_Function)o;
+ return c && this.deco == c.deco;
}
// BUG: need to add the rest of the functions
- @property override size_t tsize() nothrow pure
+ override @property size_t tsize() nothrow pure
{
return 0; // no size for functions
}
@@ -735,34 +830,35 @@ class TypeInfo_Delegate : TypeInfo
return cast(string)(next.toString() ~ " delegate()");
}
- override equals_t opEquals(Object o)
+ override equals_t opEquals(const Object o)
{
- TypeInfo_Delegate c;
- return this is o ||
- ((c = cast(TypeInfo_Delegate)o) !is null &&
- this.deco == c.deco);
+ if (this is o)
+ return true;
+ auto c = cast(const TypeInfo_Delegate)o;
+ return c && this.deco == c.deco;
}
// BUG: need to add the rest of the functions
- @property override size_t tsize() nothrow pure
+ override @property size_t tsize() nothrow pure
{
alias int delegate() dg;
return dg.sizeof;
}
- @property override uint flags() nothrow pure { return 1; }
+ override @property uint flags() nothrow pure { return 1; }
TypeInfo next;
string deco;
- @property override size_t talign() nothrow pure
+ override @property size_t talign() nothrow pure
{ alias int delegate() dg;
return dg.alignof;
}
version (X86_64) override int argTypes(out TypeInfo arg1, out TypeInfo arg2)
- { arg1 = typeid(void*);
+ {
+ arg1 = typeid(void*);
arg2 = typeid(void*);
return 0;
}
@@ -777,17 +873,17 @@ class TypeInfo_Class : TypeInfo
{
override string toString() { return info.name; }
- override equals_t opEquals(Object o)
+ override equals_t opEquals(const Object o)
{
- TypeInfo_Class c;
- return this is o ||
- ((c = cast(TypeInfo_Class)o) !is null &&
- this.info.name == c.info.name);
+ if (this is o)
+ return true;
+ auto c = cast(const TypeInfo_Class)o;
+ return c && this.info.name == c.info.name;
}
override hash_t getHash(in void* p) @trusted
{
- Object o = *cast(Object*)p;
+ auto o = *cast(const Object*)p;
return o ? o.toHash() : 0;
}
@@ -821,20 +917,20 @@ class TypeInfo_Class : TypeInfo
return c;
}
- @property override size_t tsize() nothrow pure
+ override @property size_t tsize() nothrow pure
{
return Object.sizeof;
}
- @property override uint flags() nothrow pure { return 1; }
+ override @property uint flags() nothrow pure { return 1; }
- @property override OffsetTypeInfo[] offTi() nothrow pure
+ override @property const(OffsetTypeInfo)[] offTi() nothrow pure
{
return m_offTi;
}
- @property auto info() @safe nothrow pure { return this; }
- @property auto typeinfo() @safe nothrow pure { return this; }
+ @property auto info() @safe nothrow pure const { return this; }
+ @property auto typeinfo() @safe nothrow pure const { return this; }
byte[] init; /** class static initializer
* (init.length gives size in bytes of class)
@@ -858,13 +954,13 @@ class TypeInfo_Class : TypeInfo
void function(Object) defaultConstructor; // default Constructor
immutable(void)* m_RTInfo; // data for precise GC
- @property override immutable(void)* rtInfo() { return m_RTInfo; }
+ override @property immutable(void)* rtInfo() { return m_RTInfo; }
/**
* Search all modules for TypeInfo_Class corresponding to classname.
* Returns: null if not found
*/
- static TypeInfo_Class find(in char[] classname)
+ static const(TypeInfo_Class) find(in char[] classname)
{
foreach (m; ModuleInfo)
{
@@ -883,7 +979,7 @@ class TypeInfo_Class : TypeInfo
/**
* Create instance of Object represented by 'this'.
*/
- Object create()
+ Object create() const
{
if (m_flags & 8 && !defaultConstructor)
return null;
@@ -904,12 +1000,12 @@ class TypeInfo_Interface : TypeInfo
{
override string toString() { return info.name; }
- override equals_t opEquals(Object o)
+ override equals_t opEquals(const Object o)
{
- TypeInfo_Interface c;
- return this is o ||
- ((c = cast(TypeInfo_Interface)o) !is null &&
- this.info.name == c.classinfo.name);
+ if (this is o)
+ return true;
+ auto c = cast(const TypeInfo_Interface)o;
+ return c && this.info.name == c.classinfo.name;
}
override hash_t getHash(in void* p) @trusted
@@ -954,12 +1050,12 @@ class TypeInfo_Interface : TypeInfo
return c;
}
- @property override size_t tsize() nothrow pure
+ override @property size_t tsize() nothrow pure
{
return Object.sizeof;
}
- @property override uint flags() nothrow pure { return 1; }
+ override @property uint flags() nothrow pure { return 1; }
TypeInfo_Class info;
}
@@ -968,13 +1064,13 @@ class TypeInfo_Struct : TypeInfo
{
override string toString() { return name; }
- override equals_t opEquals(Object o)
+ override equals_t opEquals(const Object o)
{
- TypeInfo_Struct s;
- return this is o ||
- ((s = cast(TypeInfo_Struct)o) !is null &&
- this.name == s.name &&
- this.init().length == s.init().length);
+ if (this is o)
+ return true;
+ auto s = cast(const TypeInfo_Struct)o;
+ return s && this.name == s.name &&
+ this.init().length == s.init().length;
}
override hash_t getHash(in void* p) @safe pure nothrow const
@@ -1026,16 +1122,16 @@ class TypeInfo_Struct : TypeInfo
return 0;
}
- @property override size_t tsize() nothrow pure
+ override @property size_t tsize() nothrow pure
{
return init().length;
}
override const(void)[] init() nothrow pure const @safe { return m_init; }
- @property override uint flags() nothrow pure { return m_flags; }
+ override @property uint flags() nothrow pure { return m_flags; }
- @property override size_t talign() nothrow pure { return m_align; }
+ override @property size_t talign() nothrow pure { return m_align; }
override void destroy(void* p)
{
@@ -1066,12 +1162,13 @@ class TypeInfo_Struct : TypeInfo
uint m_align;
- @property override immutable(void)* rtInfo() { return m_RTInfo; }
+ override @property immutable(void)* rtInfo() { return m_RTInfo; }
version (X86_64)
{
override int argTypes(out TypeInfo arg1, out TypeInfo arg2)
- { arg1 = m_arg1;
+ {
+ arg1 = m_arg1;
arg2 = m_arg2;
return 0;
}
@@ -1111,12 +1208,12 @@ class TypeInfo_Tuple : TypeInfo
return s;
}
- override equals_t opEquals(Object o)
+ override equals_t opEquals(const Object o)
{
if (this is o)
return true;
- auto t = cast(TypeInfo_Tuple)o;
+ auto t = cast(const TypeInfo_Tuple)o;
if (t && elements.length == t.elements.length)
{
for (size_t i = 0; i < elements.length; i++)
@@ -1144,7 +1241,7 @@ class TypeInfo_Tuple : TypeInfo
assert(0);
}
- @property override size_t tsize() nothrow pure
+ override @property size_t tsize() nothrow pure
{
assert(0);
}
@@ -1164,7 +1261,7 @@ class TypeInfo_Tuple : TypeInfo
assert(0);
}
- @property override size_t talign() nothrow pure
+ override @property size_t talign() nothrow pure
{
assert(0);
}
@@ -1183,7 +1280,7 @@ class TypeInfo_Const : TypeInfo
}
//override equals_t opEquals(Object o) { return base.opEquals(o); }
- override equals_t opEquals(Object o)
+ override equals_t opEquals(const Object o)
{
if (this is o)
return true;
@@ -1191,28 +1288,25 @@ class TypeInfo_Const : TypeInfo
if (typeid(this) != typeid(o))
return false;
- auto t = cast(TypeInfo_Const)o;
- if (base.opEquals(t.base))
- {
- return true;
- }
- return false;
+ auto t = cast(const TypeInfo_Const)o;
+ return base.opEquals(t.base);
}
override hash_t getHash(in void *p) { return base.getHash(p); }
override equals_t equals(in void *p1, in void *p2) { return base.equals(p1, p2); }
override int compare(in void *p1, in void *p2) { return base.compare(p1, p2); }
- @property override size_t tsize() nothrow pure { return base.tsize; }
+ override @property size_t tsize() nothrow pure { return base.tsize; }
override void swap(void *p1, void *p2) { return base.swap(p1, p2); }
- @property override TypeInfo next() nothrow pure { return base.next; }
- @property override uint flags() nothrow pure { return base.flags; }
+ override @property const(TypeInfo) next() nothrow pure { return base.next; }
+ override @property uint flags() nothrow pure { return base.flags; }
override const(void)[] init() nothrow pure { return base.init(); }
- @property override size_t talign() nothrow pure { return base.talign(); }
+ override @property size_t talign() nothrow pure { return base.talign(); }
version (X86_64) override int argTypes(out TypeInfo arg1, out TypeInfo arg2)
- { return base.argTypes(arg1, arg2);
+ {
+ return base.argTypes(arg1, arg2);
}
TypeInfo base;
@@ -1256,7 +1350,7 @@ class MemberInfo_field : MemberInfo
m_offset = offset;
}
- @property override string name() nothrow pure { return m_name; }
+ override @property string name() nothrow pure { return m_name; }
@property TypeInfo typeInfo() nothrow pure { return m_typeinfo; }
@property size_t offset() nothrow pure { return m_offset; }
@@ -1275,7 +1369,7 @@ class MemberInfo_function : MemberInfo
m_flags = flags;
}
- @property override string name() nothrow pure { return m_name; }
+ override @property string name() nothrow pure { return m_name; }
@property TypeInfo typeInfo() nothrow pure { return m_typeinfo; }
@property void* fp() nothrow pure { return m_fp; }
@property uint flags() nothrow pure { return m_flags; }
@@ -1296,9 +1390,9 @@ class Throwable : Object
{
interface TraceInfo
{
- int opApply(scope int delegate(ref char[]));
- int opApply(scope int delegate(ref size_t, ref char[]));
- string toString();
+ int opApply(scope int delegate(ref const(char[]))) const;
+ int opApply(scope int delegate(ref size_t, ref const(char[]))) const;
+ string toString() const;
}
string msg;
42 src/rt/lifetime.d
View
@@ -95,7 +95,7 @@ extern (C) void* _d_allocmemory(size_t sz)
/**
*
*/
-extern (C) Object _d_newclass(ClassInfo ci)
+extern (C) Object _d_newclass(const ClassInfo ci)
{
void* p;
@@ -546,7 +546,7 @@ void __insertBlkInfoCache(BlkInfo bi, BlkInfo *curpos)
* It doesn't matter what the current allocated length of the array is, the
* user is telling the runtime that he knows what he is doing.
*/
-extern(C) void _d_arrayshrinkfit(TypeInfo ti, void[] arr)
+extern(C) void _d_arrayshrinkfit(const TypeInfo ti, void[] arr)
{
// note, we do not care about shared. We are setting the length no matter
// what, so no lock is required.
@@ -565,7 +565,7 @@ extern(C) void _d_arrayshrinkfit(TypeInfo ti, void[] arr)
}
}
-void __doPostblit(void *ptr, size_t len, TypeInfo ti)
+void __doPostblit(void *ptr, size_t len, const TypeInfo ti)
{
// optimize out any type info that does not need postblit.
//if((&ti.postblit).funcptr is &TypeInfo.postblit) // compiler doesn't like this
@@ -606,7 +606,7 @@ void __doPostblit(void *ptr, size_t len, TypeInfo ti)
* of 0 to get the current capacity. Returns the number of elements that can
* actually be stored once the resizing is done.
*/
-extern(C) size_t _d_arraysetcapacity(TypeInfo ti, size_t newcapacity, void[]* p)
+extern(C) size_t _d_arraysetcapacity(const TypeInfo ti, size_t newcapacity, void[]* p)
in
{
assert(ti);
@@ -761,7 +761,7 @@ Loverflow:
* ti is the type of the resulting array, or pointer to element.
* (For when the array is initialized to 0)
*/
-extern (C) void[] _d_newarrayT(TypeInfo ti, size_t length)
+extern (C) void[] _d_newarrayT(const TypeInfo ti, size_t length)
{
void[] result;
auto size = ti.next.tsize(); // array element size
@@ -820,7 +820,7 @@ Loverflow:
/**
* For when the array has a non-zero initializer.
*/
-extern (C) void[] _d_newarrayiT(TypeInfo ti, size_t length)
+extern (C) void[] _d_newarrayiT(const TypeInfo ti, size_t length)
{
void[] result;
auto size = ti.next.tsize(); // array element size
@@ -899,14 +899,14 @@ Loverflow:
/**
*
*/
-void[] _d_newarrayOpT(alias op)(TypeInfo ti, size_t ndims, va_list q)
+void[] _d_newarrayOpT(alias op)(const TypeInfo ti, size_t ndims, va_list q)
{
debug(PRINTF) printf("_d_newarrayOpT(ndims = %d)\n", ndims);
if (ndims == 0)
return null;
else
{
- void[] foo(TypeInfo ti, va_list ap, size_t ndims)
+ void[] foo(const TypeInfo ti, va_list ap, size_t ndims)
{
size_t dim;
va_arg(ap, dim);
@@ -966,7 +966,7 @@ void[] _d_newarrayOpT(alias op)(TypeInfo ti, size_t ndims, va_list q)
/**
*
*/
-extern (C) void[] _d_newarraymT(TypeInfo ti, size_t ndims, ...)
+extern (C) void[] _d_newarraymT(const TypeInfo ti, size_t ndims, ...)
{
debug(PRINTF) printf("_d_newarraymT(ndims = %d)\n", ndims);
@@ -989,7 +989,7 @@ extern (C) void[] _d_newarraymT(TypeInfo ti, size_t ndims, ...)
/**
*
*/
-extern (C) void[] _d_newarraymiT(TypeInfo ti, size_t ndims, ...)
+extern (C) void[] _d_newarraymiT(const TypeInfo ti, size_t ndims, ...)
{
debug(PRINTF) printf("_d_newarraymiT(ndims = %d)\n", ndims);
@@ -1112,7 +1112,7 @@ debug(PRINTF)
/**
*
*/
-extern (C) void _d_delarray_t(void[]* p, TypeInfo ti)
+extern (C) void _d_delarray_t(void[]* p, const TypeInfo ti)
{
if (p)
{
@@ -1288,7 +1288,7 @@ extern (C) void rt_finalize_gc(void* p)
/**
* Resize dynamic arrays with 0 initializers.
*/
-extern (C) void[] _d_arraysetlengthT(TypeInfo ti, size_t newlength, void[]* p)
+extern (C) void[] _d_arraysetlengthT(const TypeInfo ti, size_t newlength, void[]* p)
in
{
assert(ti);
@@ -1466,7 +1466,7 @@ Loverflow:
* initsize size of initializer
* ... initializer
*/
-extern (C) void[] _d_arraysetlengthiT(TypeInfo ti, size_t newlength, void[]* p)
+extern (C) void[] _d_arraysetlengthiT(const TypeInfo ti, size_t newlength, void[]* p)
in
{
assert(!(*p).length || (*p).ptr);
@@ -1658,7 +1658,7 @@ Loverflow:
/**
* Append y[] to array x[]
*/
-extern (C) void[] _d_arrayappendT(TypeInfo ti, ref byte[] x, byte[] y)
+extern (C) void[] _d_arrayappendT(const TypeInfo ti, ref byte[] x, byte[] y)
{
auto length = x.length;
auto sizeelem = ti.next.tsize(); // array element size
@@ -1755,7 +1755,7 @@ size_t newCapacity(size_t newlength, size_t size)
/**
* Obsolete, replaced with _d_arrayappendcTX()
*/
-extern (C) void[] _d_arrayappendcT(TypeInfo ti, ref byte[] x, ...)
+extern (C) void[] _d_arrayappendcT(const TypeInfo ti, ref byte[] x, ...)
{
version(X86)
{
@@ -1796,7 +1796,7 @@ extern (C) void[] _d_arrayappendcT(TypeInfo ti, ref byte[] x, ...)
* Caller must initialize those elements.
*/
extern (C)
-byte[] _d_arrayappendcTX(TypeInfo ti, ref byte[] px, size_t n)
+byte[] _d_arrayappendcTX(const TypeInfo ti, ref byte[] px, size_t n)
{
// This is a cut&paste job from _d_arrayappendT(). Should be refactored.
@@ -1973,7 +1973,7 @@ extern (C) void[] _d_arrayappendwd(ref byte[] x, dchar c)
/**
*
*/
-extern (C) byte[] _d_arraycatT(TypeInfo ti, byte[] x, byte[] y)
+extern (C) byte[] _d_arraycatT(const TypeInfo ti, byte[] x, byte[] y)
out (result)
{
auto sizeelem = ti.next.tsize(); // array element size
@@ -2037,7 +2037,7 @@ body
/**
*
*/
-extern (C) void[] _d_arraycatnT(TypeInfo ti, uint n, ...)
+extern (C) void[] _d_arraycatnT(const TypeInfo ti, uint n, ...)
{
size_t length;
auto size = ti.next.tsize(); // array element size
@@ -2117,7 +2117,7 @@ extern (C) void[] _d_arraycatnT(TypeInfo ti, uint n, ...)
* Allocate the array, rely on the caller to do the initialization of the array.
*/
extern (C)
-void* _d_arrayliteralTX(TypeInfo ti, size_t length)
+void* _d_arrayliteralTX(const TypeInfo ti, size_t length)
{
auto sizeelem = ti.next.tsize(); // array element size
void* result;
@@ -2139,7 +2139,7 @@ void* _d_arrayliteralTX(TypeInfo ti, size_t length)
/**
* The old way, obsolete.
*/
-extern (C) void* _d_arrayliteralT(TypeInfo ti, size_t length, ...)
+extern (C) void* _d_arrayliteralT(const TypeInfo ti, size_t length, ...)
{
auto sizeelem = ti.next.tsize(); // array element size
void* result;
@@ -2205,7 +2205,7 @@ struct Array2
/**
*
*/
-extern (C) void[] _adDupT(TypeInfo ti, void[] a)
+extern (C) void[] _adDupT(const TypeInfo ti, void[] a)
out (result)
{
auto sizeelem = ti.next.tsize(); // array element size
13 src/rt/typeinfo/ti_AC.d
View
@@ -19,7 +19,7 @@ class TypeInfo_AC : TypeInfo_Array
{
override string toString() { return TypeInfo.toString(); }
- override equals_t opEquals(Object o) { return TypeInfo.opEquals(o); }
+ override equals_t opEquals(const Object o) { return TypeInfo.opEquals(o); }
@trusted:
const:
@@ -27,7 +27,8 @@ class TypeInfo_AC : TypeInfo_Array
//nothrow:
override hash_t getHash(in void* p)
- { Object[] s = *cast(Object[]*)p;
+ {
+ Object[] s = *cast(Object[]*)p;
hash_t hash = 0;
foreach (Object o; s)
@@ -46,7 +47,8 @@ class TypeInfo_AC : TypeInfo_Array
if (s1.length == s2.length)
{
for (size_t u = 0; u < s1.length; u++)
- { Object o1 = s1[u];
+ {
+ Object o1 = s1[u];
Object o2 = s2[u];
// Do not pass null's to Object.opEquals()
@@ -68,7 +70,8 @@ class TypeInfo_AC : TypeInfo_Array
if (c == 0)
{
for (size_t u = 0; u < s1.length; u++)
- { Object o1 = s1[u];
+ {
+ Object o1 = s1[u];
Object o2 = s2[u];
if (o1 is o2)
@@ -93,7 +96,7 @@ class TypeInfo_AC : TypeInfo_Array
return c < 0 ? -1 : c > 0 ? 1 : 0;
}
- @property override TypeInfo next() nothrow pure
+ override @property const(TypeInfo) next() nothrow pure
{
return typeid(Object);
}
7 src/rt/typeinfo/ti_Acdouble.d
View
@@ -20,7 +20,7 @@ private import rt.util.hash;
class TypeInfo_Ar : TypeInfo_Array
{
- override equals_t opEquals(Object o) { return TypeInfo.opEquals(o); }
+ override equals_t opEquals(const Object o) { return TypeInfo.opEquals(o); }
@trusted:
const:
@@ -30,7 +30,8 @@ class TypeInfo_Ar : TypeInfo_Array
override string toString() const pure nothrow @safe { return "cdouble[]"; }
override hash_t getHash(in void* p)
- { cdouble[] s = *cast(cdouble[]*)p;
+ {
+ cdouble[] s = *cast(cdouble[]*)p;
return hashOf(s.ptr, s.length * cdouble.sizeof);
}
@@ -71,7 +72,7 @@ class TypeInfo_Ar : TypeInfo_Array
return 0;
}
- @property override TypeInfo next() nothrow pure
+ override @property const(TypeInfo) next() nothrow pure
{
return typeid(cdouble);
}
7 src/rt/typeinfo/ti_Acfloat.d
View
@@ -20,7 +20,7 @@ private import rt.util.hash;
class TypeInfo_Aq : TypeInfo_Array
{
- override equals_t opEquals(Object o) { return TypeInfo.opEquals(o); }
+ override equals_t opEquals(const Object o) { return TypeInfo.opEquals(o); }
@trusted:
const:
@@ -30,7 +30,8 @@ class TypeInfo_Aq : TypeInfo_Array
override string toString() const pure nothrow @safe { return "cfloat[]"; }
override hash_t getHash(in void* p)
- { cfloat[] s = *cast(cfloat[]*)p;
+ {
+ cfloat[] s = *cast(cfloat[]*)p;
return hashOf(s.ptr, s.length * cfloat.sizeof);
}
@@ -71,7 +72,7 @@ class TypeInfo_Aq : TypeInfo_Array
return 0;
}
- @property override TypeInfo next() nothrow pure
+ override @property const(TypeInfo) next() nothrow pure
{
return typeid(cfloat);
}
7 src/rt/typeinfo/ti_Acreal.d
View
@@ -20,7 +20,7 @@ private import rt.util.hash;
class TypeInfo_Ac : TypeInfo_Array
{
- override equals_t opEquals(Object o) { return TypeInfo.opEquals(o); }
+ override equals_t opEquals(const Object o) { return TypeInfo.opEquals(o); }
@trusted:
const:
@@ -30,7 +30,8 @@ class TypeInfo_Ac : TypeInfo_Array
override string toString() const pure nothrow @safe { return "creal[]"; }
override hash_t getHash(in void* p)
- { creal[] s = *cast(creal[]*)p;
+ {
+ creal[] s = *cast(creal[]*)p;
return hashOf(s.ptr, s.length * creal.sizeof);
}
@@ -71,7 +72,7 @@ class TypeInfo_Ac : TypeInfo_Array
return 0;
}
- @property override TypeInfo next() nothrow pure
+ override @property const(TypeInfo) next() nothrow pure
{
return typeid(creal);
}
9 src/rt/typeinfo/ti_Adouble.d
View
@@ -20,7 +20,7 @@ private import rt.util.hash;
class TypeInfo_Ad : TypeInfo_Array
{
- override equals_t opEquals(Object o) { return TypeInfo.opEquals(o); }
+ override equals_t opEquals(const Object o) { return TypeInfo.opEquals(o); }
@trusted:
const:
@@ -30,7 +30,8 @@ class TypeInfo_Ad : TypeInfo_Array
override string toString() const pure nothrow @safe { return "double[]"; }
override hash_t getHash(in void* p)
- { double[] s = *cast(double[]*)p;
+ {
+ double[] s = *cast(double[]*)p;
return hashOf(s.ptr, s.length * double.sizeof);
}
@@ -71,7 +72,7 @@ class TypeInfo_Ad : TypeInfo_Array
return 0;
}
- @property override TypeInfo next() nothrow pure
+ override @property const(TypeInfo) next() nothrow pure
{
return typeid(double);
}
@@ -88,7 +89,7 @@ class TypeInfo_Ap : TypeInfo_Ad
override string toString() const pure nothrow @safe { return "idouble[]"; }
- @property override TypeInfo next() nothrow pure
+ override @property const(TypeInfo) next() nothrow pure
{
return typeid(idouble);
}
9 src/rt/typeinfo/ti_Afloat.d
View
@@ -20,7 +20,7 @@ private import rt.util.hash;
class TypeInfo_Af : TypeInfo_Array
{
- override equals_t opEquals(Object o) { return TypeInfo.opEquals(o); }
+ override equals_t opEquals(const Object o) { return TypeInfo.opEquals(o); }
@trusted:
const:
@@ -30,7 +30,8 @@ class TypeInfo_Af : TypeInfo_Array
override string toString() const pure nothrow @safe { return "float[]"; }
override hash_t getHash(in void* p)
- { float[] s = *cast(float[]*)p;
+ {
+ float[] s = *cast(float[]*)p;
return hashOf(s.ptr, s.length * float.sizeof);
}
@@ -71,7 +72,7 @@ class TypeInfo_Af : TypeInfo_Array
return 0;
}
- @property override TypeInfo next() nothrow pure
+ override @property const(TypeInfo) next() nothrow pure
{
return typeid(float);
}
@@ -88,7 +89,7 @@ class TypeInfo_Ao : TypeInfo_Af
override string toString() const pure nothrow @safe { return "ifloat[]"; }
- @property override TypeInfo next() nothrow pure
+ override @property const(TypeInfo) next() nothrow pure
{
return typeid(ifloat);
}
20 src/rt/typeinfo/ti_Ag.d
View
@@ -21,7 +21,7 @@ private import rt.util.string;
class TypeInfo_Ag : TypeInfo_Array
{
- override equals_t opEquals(Object o) { return TypeInfo.opEquals(o); }
+ override equals_t opEquals(const Object o) { return TypeInfo.opEquals(o); }
@trusted:
const:
@@ -31,7 +31,8 @@ class TypeInfo_Ag : TypeInfo_Array
override string toString() const pure nothrow @safe { return "byte[]"; }
override hash_t getHash(in void* p)
- { byte[] s = *cast(byte[]*)p;
+ {
+ byte[] s = *cast(byte[]*)p;
return hashOf(s.ptr, s.length * byte.sizeof);
}
@@ -65,7 +66,7 @@ class TypeInfo_Ag : TypeInfo_Array
return 0;
}
- @property override TypeInfo next() nothrow pure
+ override @property const(TypeInfo) next() nothrow pure
{
return typeid(byte);
}
@@ -91,7 +92,7 @@ class TypeInfo_Ah : TypeInfo_Ag
return dstrcmp(s1, s2);
}
- @property override TypeInfo next() nothrow pure
+ override @property const(TypeInfo) next() nothrow pure
{
return typeid(ubyte);
}
@@ -108,7 +109,7 @@ class TypeInfo_Av : TypeInfo_Ah
override string toString() const pure nothrow @safe { return "void[]"; }
- @property override TypeInfo next() nothrow pure
+ override @property const(TypeInfo) next() nothrow pure
{
return typeid(void);
}
@@ -125,7 +126,7 @@ class TypeInfo_Ab : TypeInfo_Ah
override string toString() const pure nothrow @safe { return "bool[]"; }
- @property override TypeInfo next() nothrow pure
+ override @property const(TypeInfo) next() nothrow pure
{
return typeid(bool);
}
@@ -143,7 +144,8 @@ class TypeInfo_Aa : TypeInfo_Ag
override string toString() const pure nothrow @safe { return "char[]"; }
override hash_t getHash(in void* p)
- { char[] s = *cast(char[]*)p;
+ {
+ char[] s = *cast(char[]*)p;
hash_t hash = 0;
version (all)
@@ -191,7 +193,7 @@ else
return hash;
}
- @property override TypeInfo next() nothrow pure
+ override @property const(TypeInfo) next() nothrow pure
{
return typeid(char);
}
@@ -208,7 +210,7 @@ class TypeInfo_Aya : TypeInfo_Aa
override string toString() const pure nothrow @safe { return "immutable(char)[]"; }
- @property override TypeInfo next() nothrow pure
+ override @property const(TypeInfo) next() nothrow pure
{
return typeid(immutable(char));
}
11 src/rt/typeinfo/ti_Aint.d
View
@@ -20,7 +20,7 @@ private import rt.util.hash;
class TypeInfo_Ai : TypeInfo_Array
{
- override equals_t opEquals(Object o) { return TypeInfo.opEquals(o); }
+ override equals_t opEquals(const Object o) { return TypeInfo.opEquals(o); }
@trusted:
const:
@@ -30,7 +30,8 @@ class TypeInfo_Ai : TypeInfo_Array
override string toString() const pure nothrow @safe { return "int[]"; }
override hash_t getHash(in void* p)
- { int[] s = *cast(int[]*)p;
+ {
+ int[] s = *cast(int[]*)p;
return hashOf(s.ptr, s.length * int.sizeof);
}
@@ -64,7 +65,7 @@ class TypeInfo_Ai : TypeInfo_Array
return 0;
}
- @property override TypeInfo next() nothrow pure
+ override @property const(TypeInfo) next() nothrow pure
{
return typeid(int);
}
@@ -113,7 +114,7 @@ class TypeInfo_Ak : TypeInfo_Ai
return 0;
}
- @property override TypeInfo next() nothrow pure
+ override @property const(TypeInfo) next() nothrow pure
{
return typeid(uint);
}
@@ -130,7 +131,7 @@ class TypeInfo_Aw : TypeInfo_Ak
override string toString() const pure nothrow @safe { return "dchar[]"; }
- @property override TypeInfo next() nothrow pure
+ override @property const(TypeInfo) next() nothrow pure
{
return typeid(dchar);
}
9 src/rt/typeinfo/ti_Along.d
View
@@ -20,7 +20,7 @@ private import rt.util.hash;
class TypeInfo_Al : TypeInfo_Array
{
- override equals_t opEquals(Object o) { return TypeInfo.opEquals(o); }
+ override equals_t opEquals(const Object o) { return TypeInfo.opEquals(o); }
@trusted:
const:
@@ -30,7 +30,8 @@ class TypeInfo_Al : TypeInfo_Array
override string toString() const pure nothrow @safe { return "long[]"; }
override hash_t getHash(in void* p)
- { long[] s = *cast(long[]*)p;
+ {
+ long[] s = *cast(long[]*)p;
return hashOf(s.ptr, s.length * long.sizeof);
}
@@ -65,7 +66,7 @@ class TypeInfo_Al : TypeInfo_Array
return 0;
}
- @property override TypeInfo next() nothrow pure
+ override @property const(TypeInfo) next() nothrow pure
{
return typeid(long);
}
@@ -105,7 +106,7 @@ class TypeInfo_Am : TypeInfo_Al
return 0;
}
- @property override TypeInfo next() nothrow pure
+ override @property const(TypeInfo) next() nothrow pure
{
return typeid(ulong);
}
9 src/rt/typeinfo/ti_Areal.d
View
@@ -20,7 +20,7 @@ private import rt.util.hash;
class TypeInfo_Ae : TypeInfo_Array
{
- override equals_t opEquals(Object o) { return TypeInfo.opEquals(o); }
+ override equals_t opEquals(const Object o) { return TypeInfo.opEquals(o); }
@trusted:
const:
@@ -30,7 +30,8 @@ class TypeInfo_Ae : TypeInfo_Array
override string toString() const pure nothrow @safe { return "real[]"; }
override hash_t getHash(in void* p)
- { real[] s = *cast(real[]*)p;
+ {
+ real[] s = *cast(real[]*)p;
return hashOf(s.ptr, s.length * real.sizeof);
}
@@ -71,7 +72,7 @@ class TypeInfo_Ae : TypeInfo_Array
return 0;
}
- @property override TypeInfo next() nothrow pure
+ override @property const(TypeInfo) next() nothrow pure
{
return typeid(real);
}
@@ -88,7 +89,7 @@ class TypeInfo_Aj : TypeInfo_Ae
override string toString() const pure nothrow @safe { return "ireal[]"; }
- @property override TypeInfo next() nothrow pure
+ override @property const(TypeInfo) next() nothrow pure
{
return typeid(ireal);
}
11 src/rt/typeinfo/ti_Ashort.d
View
@@ -20,7 +20,7 @@ private import rt.util.hash;
class TypeInfo_As : TypeInfo_Array
{
- override equals_t opEquals(Object o) { return TypeInfo.opEquals(o); }
+ override equals_t opEquals(const Object o) { return TypeInfo.opEquals(o); }
@trusted:
const:
@@ -30,7 +30,8 @@ class TypeInfo_As : TypeInfo_Array
override string toString() const pure nothrow @safe { return "short[]"; }
override hash_t getHash(in void* p)
- { short[] s = *cast(short[]*)p;
+ {
+ short[] s = *cast(short[]*)p;
return hashOf(s.ptr, s.length * short.sizeof);
}
@@ -64,7 +65,7 @@ class TypeInfo_As : TypeInfo_Array
return 0;
}
- @property override TypeInfo next() nothrow pure
+ override @property const(TypeInfo) next() nothrow pure
{
return typeid(short);
}
@@ -103,7 +104,7 @@ class TypeInfo_At : TypeInfo_As
return 0;
}
- @property override TypeInfo next() nothrow pure
+ override @property const(TypeInfo) next() nothrow pure
{
return typeid(ushort);
}
@@ -120,7 +121,7 @@ class TypeInfo_Au : TypeInfo_At
override string toString() const pure nothrow @safe { return "wchar[]"; }
- @property override TypeInfo next() nothrow pure
+ override @property const(TypeInfo) next() nothrow pure
{
return typeid(wchar);
}
7 src/rt/typeinfo/ti_C.d
View
@@ -46,7 +46,8 @@ class TypeInfo_C : TypeInfo
if (!(o1 is o2))
{
if (o1)
- { if (!o2)
+ {
+ if (!o2)
c = 1;
else
c = o1.opCmp(o2);
@@ -57,12 +58,12 @@ class TypeInfo_C : TypeInfo
return c;
}
- @property override size_t tsize() nothrow pure
+ override @property size_t tsize() nothrow pure
{
return Object.sizeof;
}
- @property override uint flags() nothrow pure
+ override @property uint flags() nothrow pure
{
return 1;
}
2  src/rt/typeinfo/ti_byte.d
View
@@ -39,7 +39,7 @@ class TypeInfo_g : TypeInfo
return *cast(byte