Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Tentative fix for Issue 7270 - needless qualifiers in TypeInfo.toString #2374

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 78 additions & 23 deletions src/object.d
Original file line number Diff line number Diff line change
Expand Up @@ -1028,18 +1028,31 @@ struct OffsetTypeInfo
TypeInfo ti; /// TypeInfo for this member
}

enum ToStringContext
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DDOC comments

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, will do.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

{
none = 0x00,
const_ = 0x01,
shared_ = 0x02,
inout_ = 0x04,
}

/**
* Runtime type information about a type.
* Can be retrieved for any type using a
* $(GLINK2 expression,TypeidExpression, TypeidExpression).
*/
class TypeInfo
{
override string toString() const pure @safe nothrow
string toStringImpl(ToStringContext flags) const pure @safe nothrow
{
return typeid(this).name;
}

override final string toString() const pure @safe nothrow
{
return toStringImpl(ToStringContext.init);
}

override size_t toHash() @trusted const nothrow
{
return hashOf(this.toString());
Expand Down Expand Up @@ -1147,7 +1160,7 @@ class TypeInfo

class TypeInfo_Enum : TypeInfo
{
override string toString() const { return name; }
override string toStringImpl(ToStringContext) const { return name; }

override bool opEquals(Object o)
{
Expand Down Expand Up @@ -1196,7 +1209,7 @@ unittest // issue 12233
// Please make sure to keep this in sync with TypeInfo_P (src/rt/typeinfo/ti_ptr.d)
class TypeInfo_Pointer : TypeInfo
{
override string toString() const { return m_next.toString() ~ "*"; }
override string toStringImpl(ToStringContext) const { return m_next.toString() ~ "*"; }

override bool opEquals(Object o)
{
Expand Down Expand Up @@ -1252,7 +1265,7 @@ class TypeInfo_Pointer : TypeInfo

class TypeInfo_Array : TypeInfo
{
override string toString() const { return value.toString() ~ "[]"; }
override string toStringImpl(ToStringContext flags) const { return value.toStringImpl(flags) ~ "[]"; }

override bool opEquals(Object o)
{
Expand Down Expand Up @@ -1342,12 +1355,12 @@ class TypeInfo_Array : TypeInfo

class TypeInfo_StaticArray : TypeInfo
{
override string toString() const
override string toStringImpl(ToStringContext flags) const
{
import core.internal.string : unsignedToTempString;

char[20] tmpBuff = void;
return value.toString() ~ "[" ~ unsignedToTempString(len, tmpBuff, 10) ~ "]";
return value.toStringImpl(flags) ~ "[" ~ unsignedToTempString(len, tmpBuff, 10) ~ "]";
}

override bool opEquals(Object o)
Expand Down Expand Up @@ -1466,9 +1479,12 @@ class TypeInfo_StaticArray : TypeInfo

class TypeInfo_AssociativeArray : TypeInfo
{
override string toString() const
override string toStringImpl(ToStringContext flags) const
{
return value.toString() ~ "[" ~ key.toString() ~ "]";
if (flags & ToStringContext.const_)
return value.toStringImpl(ToStringContext.const_) ~ "[" ~ key.toString() ~ "]";
else
return value.toString() ~ "[" ~ key.toString() ~ "]";
}

override bool opEquals(Object o)
Expand Down Expand Up @@ -1522,7 +1538,7 @@ class TypeInfo_AssociativeArray : TypeInfo

class TypeInfo_Vector : TypeInfo
{
override string toString() const { return "__vector(" ~ base.toString() ~ ")"; }
override string toStringImpl(ToStringContext flags) const { return "__vector(" ~ base.toStringImpl(flags) ~ ")"; }

override bool opEquals(Object o)
{
Expand Down Expand Up @@ -1558,7 +1574,7 @@ class TypeInfo_Vector : TypeInfo

class TypeInfo_Function : TypeInfo
{
override string toString() const
override string toStringImpl(ToStringContext) const
{
import core.demangle : demangleType;

Expand Down Expand Up @@ -1613,7 +1629,7 @@ unittest

class TypeInfo_Delegate : TypeInfo
{
override string toString() const
override string toStringImpl(ToStringContext) const
{
return cast(string)(next.toString() ~ " delegate()");
}
Expand Down Expand Up @@ -1688,7 +1704,7 @@ class TypeInfo_Delegate : TypeInfo
*/
class TypeInfo_Class : TypeInfo
{
override string toString() const { return info.name; }
override string toStringImpl(ToStringContext) const { return info.name; }

override bool opEquals(Object o)
{
Expand Down Expand Up @@ -1843,7 +1859,7 @@ unittest

class TypeInfo_Interface : TypeInfo
{
override string toString() const { return info.name; }
override string toStringImpl(ToStringContext) const { return info.name; }

override bool opEquals(Object o)
{
Expand Down Expand Up @@ -1916,7 +1932,7 @@ class TypeInfo_Interface : TypeInfo

class TypeInfo_Struct : TypeInfo
{
override string toString() const { return name; }
override string toStringImpl(ToStringContext) const { return name; }

override bool opEquals(Object o)
{
Expand Down Expand Up @@ -2068,7 +2084,7 @@ class TypeInfo_Tuple : TypeInfo
{
TypeInfo[] elements;

override string toString() const
override string toStringImpl(ToStringContext) const
{
string s = "(";
foreach (i, element; elements)
Expand Down Expand Up @@ -2152,9 +2168,12 @@ class TypeInfo_Tuple : TypeInfo

class TypeInfo_Const : TypeInfo
{
override string toString() const
override string toStringImpl(ToStringContext flags) const pure @safe nothrow
{
return cast(string) ("const(" ~ base.toString() ~ ")");
if (flags & ToStringContext.const_)
return base.toStringImpl(flags);
else
return cast(string) ("const(" ~ base.toStringImpl(flags | ToStringContext.const_) ~ ")");
}

//override bool opEquals(Object o) { return base.opEquals(o); }
Expand Down Expand Up @@ -2194,27 +2213,63 @@ class TypeInfo_Const : TypeInfo
TypeInfo base;
}

unittest
{
alias A = const(int[]);
alias B = const(const(int)[]);
assert(typeid(A) == typeid(B));
assert(typeid(A).toString() == typeid(B).toString());
}

class TypeInfo_Invariant : TypeInfo_Const
{
override string toString() const
override string toStringImpl(ToStringContext flags) const
{
return cast(string) ("immutable(" ~ base.toString() ~ ")");
if (flags & ToStringContext.const_)
return base.toStringImpl(flags);
else
return cast(string) ("immutable(" ~ base.toStringImpl(flags | ToStringContext.const_) ~ ")");
}
}

unittest
{
alias A = immutable(int[]);
alias B = immutable(const(int)[]);
alias C = immutable(immutable(int)[]);
assert(typeid(A) == typeid(B));
assert(typeid(B) == typeid(C));
assert(typeid(A).toString() == typeid(B).toString());
assert(typeid(B).toString() == typeid(C).toString());
}

class TypeInfo_Shared : TypeInfo_Const
{
override string toString() const
override string toStringImpl(ToStringContext flags) const
{
return cast(string) ("shared(" ~ base.toString() ~ ")");
if (flags & ToStringContext.shared_)
return base.toStringImpl(flags);
else
return cast(string) ("shared(" ~ base.toStringImpl(flags | ToStringContext.shared_) ~ ")");
}
}

unittest
{
alias A = shared(int[]);
alias B = shared(shared(int)[]);
assert(typeid(A) == typeid(B));
assert(typeid(A).toString() == typeid(B).toString());
}

class TypeInfo_Inout : TypeInfo_Const
{
override string toString() const
override string toStringImpl(ToStringContext flags) const
{
return cast(string) ("inout(" ~ base.toString() ~ ")");
if (flags & ToStringContext.inout_)
return base.toStringImpl(flags);
else
return cast(string) ("inout(" ~ base.toStringImpl(flags | ToStringContext.inout_) ~ ")");
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/rt/typeinfo/ti_Acdouble.d
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class TypeInfo_Ar : TypeInfo_Array

override bool opEquals(Object o) { return TypeInfo.opEquals(o); }

override string toString() const { return (F[]).stringof; }
override string toStringImpl(ToStringContext) const { return (F[]).stringof; }

override size_t getHash(scope const void* p) @trusted const
{
Expand Down
2 changes: 1 addition & 1 deletion src/rt/typeinfo/ti_Acfloat.d
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class TypeInfo_Aq : TypeInfo_Array

override bool opEquals(Object o) { return TypeInfo.opEquals(o); }

override string toString() const { return (F[]).stringof; }
override string toStringImpl(ToStringContext) const { return (F[]).stringof; }

override size_t getHash(scope const void* p) @trusted const
{
Expand Down
2 changes: 1 addition & 1 deletion src/rt/typeinfo/ti_Acreal.d
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class TypeInfo_Ac : TypeInfo_Array

override bool opEquals(Object o) { return TypeInfo.opEquals(o); }

override string toString() const { return (F[]).stringof; }
override string toStringImpl(ToStringContext) const { return (F[]).stringof; }

override size_t getHash(scope const void* p) @trusted const
{
Expand Down
4 changes: 2 additions & 2 deletions src/rt/typeinfo/ti_Adouble.d
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class TypeInfo_Ad : TypeInfo_Array

override bool opEquals(Object o) { return TypeInfo.opEquals(o); }

override string toString() const { return (F[]).stringof; }
override string toStringImpl(ToStringContext) const { return (F[]).stringof; }

override size_t getHash(scope const void* p) @trusted const
{
Expand Down Expand Up @@ -52,7 +52,7 @@ class TypeInfo_Ap : TypeInfo_Ad
{
alias F = idouble;

override string toString() const { return (F[]).stringof; }
override string toStringImpl(ToStringContext) const { return (F[]).stringof; }

override @property inout(TypeInfo) next() inout
{
Expand Down
4 changes: 2 additions & 2 deletions src/rt/typeinfo/ti_Afloat.d
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class TypeInfo_Af : TypeInfo_Array

override bool opEquals(Object o) { return TypeInfo.opEquals(o); }

override string toString() const { return (F[]).stringof; }
override string toStringImpl(ToStringContext) const { return (F[]).stringof; }

override size_t getHash(scope const void* p) @trusted const
{
Expand Down Expand Up @@ -52,7 +52,7 @@ class TypeInfo_Ao : TypeInfo_Af
{
alias F = ifloat;

override string toString() const { return (F[]).stringof; }
override string toStringImpl(ToStringContext) const { return (F[]).stringof; }

override @property inout(TypeInfo) next() inout
{
Expand Down
14 changes: 7 additions & 7 deletions src/rt/typeinfo/ti_Ag.d
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class TypeInfo_Ag : TypeInfo_Array
{
override bool opEquals(Object o) { return TypeInfo.opEquals(o); }

override string toString() const { return "byte[]"; }
override string toStringImpl(ToStringContext) const { return "byte[]"; }

override size_t getHash(scope const void* p) @trusted const
{
Expand Down Expand Up @@ -71,7 +71,7 @@ class TypeInfo_Ag : TypeInfo_Array

class TypeInfo_Ah : TypeInfo_Ag
{
override string toString() const { return "ubyte[]"; }
override string toStringImpl(ToStringContext) const { return "ubyte[]"; }

override int compare(in void* p1, in void* p2) const
{
Expand All @@ -91,7 +91,7 @@ class TypeInfo_Ah : TypeInfo_Ag

class TypeInfo_Av : TypeInfo_Ah
{
override string toString() const { return "void[]"; }
override string toStringImpl(ToStringContext) const { return "void[]"; }

override @property inout(TypeInfo) next() inout
{
Expand All @@ -103,7 +103,7 @@ class TypeInfo_Av : TypeInfo_Ah

class TypeInfo_Ab : TypeInfo_Ah
{
override string toString() const { return "bool[]"; }
override string toStringImpl(ToStringContext) const { return "bool[]"; }

override @property inout(TypeInfo) next() inout
{
Expand All @@ -115,7 +115,7 @@ class TypeInfo_Ab : TypeInfo_Ah

class TypeInfo_Aa : TypeInfo_Ah
{
override string toString() const { return "char[]"; }
override string toStringImpl(ToStringContext) const { return "char[]"; }

override size_t getHash(scope const void* p) @trusted const
{
Expand All @@ -133,7 +133,7 @@ class TypeInfo_Aa : TypeInfo_Ah

class TypeInfo_Aya : TypeInfo_Aa
{
override string toString() const { return "immutable(char)[]"; }
override string toStringImpl(ToStringContext) const { return "immutable(char)[]"; }

override @property inout(TypeInfo) next() inout
{
Expand All @@ -145,7 +145,7 @@ class TypeInfo_Aya : TypeInfo_Aa

class TypeInfo_Axa : TypeInfo_Aa
{
override string toString() const { return "const(char)[]"; }
override string toStringImpl(ToStringContext) const { return "const(char)[]"; }

override @property inout(TypeInfo) next() inout
{
Expand Down
6 changes: 3 additions & 3 deletions src/rt/typeinfo/ti_Aint.d
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class TypeInfo_Ai : TypeInfo_Array
{
override bool opEquals(Object o) { return TypeInfo.opEquals(o); }

override string toString() const { return "int[]"; }
override string toStringImpl(ToStringContext) const { return "int[]"; }

override size_t getHash(scope const void* p) @trusted const
{
Expand Down Expand Up @@ -94,7 +94,7 @@ unittest

class TypeInfo_Ak : TypeInfo_Ai
{
override string toString() const { return "uint[]"; }
override string toStringImpl(ToStringContext) const { return "uint[]"; }

override int compare(in void* p1, in void* p2) const
{
Expand Down Expand Up @@ -142,7 +142,7 @@ unittest

class TypeInfo_Aw : TypeInfo_Ak
{
override string toString() const { return "dchar[]"; }
override string toStringImpl(ToStringContext) const { return "dchar[]"; }

override @property inout(TypeInfo) next() inout
{
Expand Down
Loading