Skip to content

Commit c885157

Browse files
committed
Change pointsTo to mayPointTo and doesPointTo
1 parent 0fa82b2 commit c885157

File tree

2 files changed

+67
-60
lines changed

2 files changed

+67
-60
lines changed

std/algorithm.d

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2391,7 +2391,7 @@ unittest
23912391

23922392
unittest // 9975
23932393
{
2394-
import std.exception : pointsTo;
2394+
import std.exception : doesPointTo, mayPointTo;
23952395
static struct S2
23962396
{
23972397
union
@@ -2402,7 +2402,8 @@ unittest // 9975
24022402
}
24032403
S2 a , b;
24042404
a.sz = -1;
2405-
assert(pointsTo(a, b));
2405+
assert(!doesPointTo(a, b));
2406+
assert( mayPointTo(a, b));
24062407
swap(a, b);
24072408
}
24082409

std/exception.d

Lines changed: 64 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,9 +1051,9 @@ unittest
10511051
{
10521052
int i = 0;
10531053
int* p = null;
1054-
assert(!p.pointsTo(i));
1054+
assert(!p.doesPointTo(i));
10551055
p = &i;
1056-
assert( p.pointsTo(i));
1056+
assert( p.doesPointTo(i));
10571057
}
10581058

10591059
/// Structs and Unions
@@ -1069,9 +1069,9 @@ unittest
10691069

10701070
//structs and unions "own" their members
10711071
//pointsTo will answer true if one of the members pointsTo.
1072-
assert(!s.pointsTo(s.v)); //s.v is just v member of s, so not pointed.
1073-
assert( s.p.pointsTo(i)); //i is pointed by s.p.
1074-
assert( s .pointsTo(i)); //which means i is pointed by s itself.
1072+
assert(!s.doesPointTo(s.v)); //s.v is just v member of s, so not pointed.
1073+
assert( s.p.doesPointTo(i)); //i is pointed by s.p.
1074+
assert( s .doesPointTo(i)); //which means i is pointed by s itself.
10751075

10761076
//Unions will behave exactly the same. Points to will check each "member"
10771077
//individually, even if they share the same memory
@@ -1087,23 +1087,23 @@ unittest
10871087
int*[1] arrp = [&i];
10881088

10891089
//A slice points to all of its members:
1090-
assert( slice.pointsTo(slice[3]));
1091-
assert(!slice[0 .. 2].pointsTo(slice[3])); //Object 3 is outside of the slice [0 .. 2]
1090+
assert( slice.doesPointTo(slice[3]));
1091+
assert(!slice[0 .. 2].doesPointTo(slice[3])); //Object 3 is outside of the slice [0 .. 2]
10921092

10931093
//Note that a slice will not take into account what its members point to.
1094-
assert( slicep[0].pointsTo(i));
1095-
assert(!slicep .pointsTo(i));
1094+
assert( slicep[0].doesPointTo(i));
1095+
assert(!slicep .doesPointTo(i));
10961096

10971097
//static arrays are objects that own their members, just like structs:
1098-
assert(!arr.pointsTo(arr[0])); //arr[0] is just a member of arr, so not pointed.
1099-
assert( arrp[0].pointsTo(i)); //i is pointed by arrp[0].
1100-
assert( arrp .pointsTo(i)); //which means i is pointed by arrp itslef.
1098+
assert(!arr.doesPointTo(arr[0])); //arr[0] is just a member of arr, so not pointed.
1099+
assert( arrp[0].doesPointTo(i)); //i is pointed by arrp[0].
1100+
assert( arrp .doesPointTo(i)); //which means i is pointed by arrp itslef.
11011101

11021102
//Notice the difference between static and dynamic arrays:
1103-
assert(!arr .pointsTo(arr[0]));
1104-
assert( arr[].pointsTo(arr[0]));
1105-
assert( arrp .pointsTo(i));
1106-
assert(!arrp[].pointsTo(i));
1103+
assert(!arr .doesPointTo(arr[0]));
1104+
assert( arr[].doesPointTo(arr[0]));
1105+
assert( arrp .doesPointTo(i));
1106+
assert(!arrp[].doesPointTo(i));
11071107
}
11081108

11091109
/// Classes
@@ -1119,71 +1119,71 @@ unittest
11191119
C b = a;
11201120
//Classes are a bit particular, as they are treated like simple pointers
11211121
//to a class payload.
1122-
assert( a.p.pointsTo(i)); //a.p points to i.
1123-
assert(!a .pointsTo(i)); //Yet a itself does not point i.
1122+
assert( a.p.doesPointTo(i)); //a.p points to i.
1123+
assert(!a .doesPointTo(i)); //Yet a itself does not point i.
11241124

11251125
//To check the class payload itself, iterate on its members:
11261126
()
11271127
{
11281128
foreach (index, _; FieldTypeTuple!C)
1129-
if (pointsTo(a.tupleof[index], i))
1129+
if (doesPointTo(a.tupleof[index], i))
11301130
return;
11311131
assert(0);
11321132
}();
11331133

11341134
//To check if a class points a specific payload, a direct memmory check can be done:
11351135
auto aLoc = cast(ubyte[__traits(classInstanceSize, C)]*) a;
1136-
assert(b.pointsTo(*aLoc)); //b points to where a is pointing
1136+
assert(b.doesPointTo(*aLoc)); //b points to where a is pointing
11371137
}
11381138

11391139
unittest
11401140
{
11411141
struct S1 { int a; S1 * b; }
11421142
S1 a1;
11431143
S1 * p = &a1;
1144-
assert(pointsTo(p, a1));
1144+
assert(doesPointTo(p, a1));
11451145

11461146
S1 a2;
11471147
a2.b = &a1;
1148-
assert(pointsTo(a2, a1));
1148+
assert(doesPointTo(a2, a1));
11491149

11501150
struct S3 { int[10] a; }
11511151
S3 a3;
11521152
auto a4 = a3.a[2 .. 3];
1153-
assert(pointsTo(a4, a3));
1153+
assert(doesPointTo(a4, a3));
11541154

11551155
auto a5 = new double[4];
11561156
auto a6 = a5[1 .. 2];
1157-
assert(!pointsTo(a5, a6));
1157+
assert(!doesPointTo(a5, a6));
11581158

11591159
auto a7 = new double[3];
11601160
auto a8 = new double[][1];
11611161
a8[0] = a7;
1162-
assert(!pointsTo(a8[0], a8[0]));
1162+
assert(!doesPointTo(a8[0], a8[0]));
11631163

11641164
// don't invoke postblit on subobjects
11651165
{
11661166
static struct NoCopy { this(this) { assert(0); } }
11671167
static struct Holder { NoCopy a, b, c; }
11681168
Holder h;
1169-
cast(void)pointsTo(h, h);
1169+
cast(void)doesPointTo(h, h);
11701170
}
11711171

11721172
shared S3 sh3;
11731173
shared sh3sub = sh3.a[];
1174-
assert(pointsTo(sh3sub, sh3));
1174+
assert(doesPointTo(sh3sub, sh3));
11751175

11761176
int[] darr = [1, 2, 3, 4];
11771177

11781178
//dynamic arrays don't point to each other, or slices of themselves
1179-
assert(!pointsTo(darr, darr));
1180-
assert(!pointsTo(darr[0 .. 1], darr));
1179+
assert(!doesPointTo(darr, darr));
1180+
assert(!doesPointTo(darr[0 .. 1], darr));
11811181

11821182
//But they do point their elements
11831183
foreach(i; 0 .. 4)
1184-
assert(pointsTo(darr, darr[i]));
1185-
assert(pointsTo(darr[0..3], darr[2]));
1186-
assert(!pointsTo(darr[0..3], darr[3]));
1184+
assert(doesPointTo(darr, darr[i]));
1185+
assert(doesPointTo(darr[0..3], darr[2]));
1186+
assert(!doesPointTo(darr[0..3], darr[3]));
11871187
}
11881188

11891189
unittest
@@ -1195,22 +1195,22 @@ unittest
11951195

11961196
//Standard array
11971197
int[2] k;
1198-
assert(!pointsTo(k, k)); //an array doesn't point to itself
1198+
assert(!doesPointTo(k, k)); //an array doesn't point to itself
11991199
//Technically, k doesn't point its elements, although it does alias them
1200-
assert(!pointsTo(k, k[0]));
1201-
assert(!pointsTo(k, k[1]));
1200+
assert(!doesPointTo(k, k[0]));
1201+
assert(!doesPointTo(k, k[1]));
12021202
//But an extracted slice will point to the same array.
1203-
assert(pointsTo(k[], k));
1204-
assert(pointsTo(k[], k[1]));
1203+
assert(doesPointTo(k[], k));
1204+
assert(doesPointTo(k[], k[1]));
12051205

12061206
//An array of pointers
12071207
int*[2] pp;
12081208
int a;
12091209
int b;
12101210
pp[0] = &a;
1211-
assert( pointsTo(pp, a)); //The array contains a pointer to a
1212-
assert(!pointsTo(pp, b)); //The array does NOT contain a pointer to b
1213-
assert(!pointsTo(pp, pp)); //The array does not point itslef
1211+
assert( doesPointTo(pp, a)); //The array contains a pointer to a
1212+
assert(!doesPointTo(pp, b)); //The array does NOT contain a pointer to b
1213+
assert(!doesPointTo(pp, pp)); //The array does not point itslef
12141214

12151215
//A struct containing a static array of pointers
12161216
static struct S
@@ -1219,19 +1219,19 @@ unittest
12191219
}
12201220
S s;
12211221
s.p[0] = &a;
1222-
assert( pointsTo(s, a)); //The struct contains an array that points a
1223-
assert(!pointsTo(s, b)); //But doesn't point b
1224-
assert(!pointsTo(s, s)); //The struct doesn't actually point itslef.
1222+
assert( doesPointTo(s, a)); //The struct contains an array that points a
1223+
assert(!doesPointTo(s, b)); //But doesn't point b
1224+
assert(!doesPointTo(s, s)); //The struct doesn't actually point itslef.
12251225

12261226
//An array containing structs that have pointers
12271227
static struct SS
12281228
{
12291229
int* p;
12301230
}
12311231
SS[2] ss = [SS(&a), SS(null)];
1232-
assert( pointsTo(ss, a)); //The array contains a struct that points to a
1233-
assert(!pointsTo(ss, b)); //The array doesn't contains a struct that points to b
1234-
assert(!pointsTo(ss, ss)); //The array doesn't point itself.
1232+
assert( doesPointTo(ss, a)); //The array contains a struct that points to a
1233+
assert(!doesPointTo(ss, b)); //The array doesn't contains a struct that points to b
1234+
assert(!doesPointTo(ss, ss)); //The array doesn't point itself.
12351235
}
12361236

12371237

@@ -1254,18 +1254,24 @@ unittest //Unions
12541254

12551255
U u;
12561256
S s;
1257-
assert(!pointsTo(u, i));
1258-
assert(!pointsTo(s, i));
1257+
assert(!doesPointTo(u, i));
1258+
assert(!doesPointTo(s, i));
1259+
assert(!mayPointTo(u, i));
1260+
assert(!mayPointTo(s, i));
12591261

12601262
u.asPointer = &i;
12611263
s.asPointer = &i;
1262-
assert( pointsTo(u, i));
1263-
assert( pointsTo(s, i));
1264+
assert(!doesPointTo(u, i));
1265+
assert(!doesPointTo(s, i));
1266+
assert( mayPointTo(u, i));
1267+
assert( mayPointTo(s, i));
12641268

12651269
u.asInt = cast(size_t)&i;
12661270
s.asInt = cast(size_t)&i;
1267-
assert( pointsTo(u, i)); //logical false positive
1268-
assert( pointsTo(s, i)); //logical false positive
1271+
assert(!doesPointTo(u, i));
1272+
assert(!doesPointTo(s, i));
1273+
assert( mayPointTo(u, i));
1274+
assert( mayPointTo(s, i));
12691275
}
12701276

12711277
unittest //Classes
@@ -1276,9 +1282,9 @@ unittest //Classes
12761282
int* p;
12771283
}
12781284
A a = new A, b = a;
1279-
assert(!pointsTo(a, b)); //a does not point to b
1285+
assert(!doesPointTo(a, b)); //a does not point to b
12801286
a.p = &i;
1281-
assert(!pointsTo(a, i)); //a does not point to i
1287+
assert(!doesPointTo(a, i)); //a does not point to i
12821288
}
12831289
unittest //alias this test
12841290
{
@@ -1292,10 +1298,10 @@ unittest //alias this test
12921298
}
12931299
assert(is(S : int*));
12941300
S s = S(&j);
1295-
assert(!pointsTo(s, i));
1296-
assert( pointsTo(s, j));
1297-
assert( pointsTo(cast(int*)s, i));
1298-
assert(!pointsTo(cast(int*)s, j));
1301+
assert(!doesPointTo(s, i));
1302+
assert( doesPointTo(s, j));
1303+
assert( doesPointTo(cast(int*)s, i));
1304+
assert(!doesPointTo(cast(int*)s, j));
12991305
}
13001306

13011307
/*********************

0 commit comments

Comments
 (0)