Skip to content

Commit

Permalink
Fix @Property annotations and incorrect parenthesis
Browse files Browse the repository at this point in the history
  • Loading branch information
9rnsr committed Jul 15, 2013
1 parent 50c7b20 commit 30356d6
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 20 deletions.
12 changes: 8 additions & 4 deletions std/algorithm.d
Expand Up @@ -339,6 +339,8 @@ version(unittest)
mixin(dummyRanges);
}

private T* addressOf(T)(ref T val) { return &val; }

/**
$(D auto map(Range)(Range r) if (isInputRange!(Unqual!Range));)
Expand Down Expand Up @@ -1163,9 +1165,11 @@ void uninitializedFill(Range, Value)(Range range, Value filler)
{
alias ElementType!Range T;
static if (hasElaborateAssign!T)
{
// Must construct stuff by the book
for (; !range.empty; range.popFront())
emplace(&range.front(), filler);
emplace(addressOf(range.front), filler);
}
else
// Doesn't matter whether fill is initialized or not
return fill(range, filler);
Expand Down Expand Up @@ -1208,13 +1212,13 @@ void initializeAll(Range)(Range range)
auto p = typeid(T).init().ptr;
if (p)
for ( ; !range.empty ; range.popFront() )
memcpy(&range.front(), p, T.sizeof);
memcpy(addressOf(range.front), p, T.sizeof);
else
static if (isDynamicArray!Range)
memset(range.ptr, 0, range.length * T.sizeof);
else
for ( ; !range.empty ; range.popFront() )
memset(&range.front(), 0, T.sizeof);
memset(addressOf(range.front), 0, T.sizeof);
}
else
fill(range, T.init);
Expand Down Expand Up @@ -9465,7 +9469,7 @@ makeIndex(
// assume collection already ordered
size_t i;
for (; !r.empty; r.popFront(), ++i)
index[i] = &(r.front);
index[i] = addressOf(r.front);
enforce(index.length == i);
// sort the index
sort!((a, b) => binaryFun!less(*a, *b), ss)(index);
Expand Down
2 changes: 1 addition & 1 deletion std/digest/sha.d
Expand Up @@ -234,7 +234,7 @@ struct SHA1

shared static this()
{
transform = hasSSSE3Support() ? &transformSSSE3 : &transformX86;
transform = hasSSSE3Support ? &transformSSSE3 : &transformX86;
}
}
else
Expand Down
2 changes: 1 addition & 1 deletion std/file.d
Expand Up @@ -847,7 +847,7 @@ unittest
/++
Returns whether the given file (or directory) exists.
+/
@property bool exists(in char[] name)
bool exists(in char[] name)
{
version(Windows)
{
Expand Down
2 changes: 1 addition & 1 deletion std/parallelism.d
Expand Up @@ -4103,7 +4103,7 @@ unittest
auto tSlow = task!slowFun();
pool1.put(tSlow);
pool1.finish();
tSlow.yieldForce();
tSlow.yieldForce;
// Can't assert that pool1.status == PoolState.stopNow because status
// doesn't change until after the "done" flag is set and the waiting
// thread is woken up.
Expand Down
10 changes: 5 additions & 5 deletions std/process.d
Expand Up @@ -1965,7 +1965,7 @@ private auto executeImpl(alias pipeFunc, Cmd)(
// Store up to maxOutput bytes in a.
foreach (ubyte[] chunk; p.stdout.byChunk(chunkSize))
{
immutable size_t remain = maxOutput - a.data().length;
immutable size_t remain = maxOutput - a.data.length;

if (chunk.length < remain) a.put(chunk);
else
Expand Down Expand Up @@ -2041,8 +2041,8 @@ class ProcessException : Exception
{
auto errnoMsg = to!string(std.c.string.strerror(errno));
}
auto msg = customMsg.empty() ? errnoMsg
: customMsg ~ " (" ~ errnoMsg ~ ')';
auto msg = customMsg.empty ? errnoMsg
: customMsg ~ " (" ~ errnoMsg ~ ')';
return new ProcessException(msg, file, line);
}

Expand All @@ -2053,8 +2053,8 @@ class ProcessException : Exception
size_t line = __LINE__)
{
auto lastMsg = sysErrorString(GetLastError());
auto msg = customMsg.empty() ? lastMsg
: customMsg ~ " (" ~ lastMsg ~ ')';
auto msg = customMsg.empty ? lastMsg
: customMsg ~ " (" ~ lastMsg ~ ')';
return new ProcessException(msg, file, line);
}
}
Expand Down
4 changes: 2 additions & 2 deletions std/range.d
Expand Up @@ -1887,7 +1887,7 @@ unittest
assert(s1[0..0].empty);
assert(s1[3..3].empty);
// assert(s1[$ .. $].empty);
assert(s1[s1.opDollar() .. s1.opDollar()].empty);
assert(s1[s1.opDollar .. s1.opDollar].empty);

auto s2 = stride(arr, 2);
assert(equal(s2[0..2], [1,3]));
Expand All @@ -1897,7 +1897,7 @@ unittest
assert(s2[0..0].empty);
assert(s2[3..3].empty);
// assert(s2[$ .. $].empty);
assert(s2[s2.opDollar() .. s2.opDollar()].empty);
assert(s2[s2.opDollar .. s2.opDollar].empty);

// Test fix for Bug 5035
auto m = [1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4]; // 3 rows, 4 columns
Expand Down
23 changes: 17 additions & 6 deletions std/typecons.d
Expand Up @@ -2670,7 +2670,7 @@ template wrap(Targets...)
if (Targets.length >= 1 && allSatisfy!(isMutable, Targets))
{
// strict upcast
@property wrap(Source)(inout Source src) @trusted pure nothrow
auto wrap(Source)(inout Source src) @trusted pure nothrow
if (Targets.length == 1 && is(Source : Targets[0]))
{
alias T = Select!(is(Source == shared), shared Targets[0], Targets[0]);
Expand All @@ -2680,7 +2680,7 @@ if (Targets.length >= 1 && allSatisfy!(isMutable, Targets))
template wrap(Source)
if (!allSatisfy!(Bind!(isImplicitlyConvertible, Source), Targets))
{
@property wrap(inout Source src)
auto wrap(inout Source src)
{
static assert(hasRequireMethods!(),
"Source "~Source.stringof~
Expand Down Expand Up @@ -2813,10 +2813,21 @@ if (Targets.length >= 1 && allSatisfy!(isMutable, Targets))
return r;
}
enum n = to!string(i);
static if (fa & FunctionAttribute.property)
{
static if (ParameterTypeTuple!(TargetMembers[i].type).length == 0)
enum fbody = "_wrap_source."~name;
else
enum fbody = "_wrap_source."~name~" = forward!args";
}
else
{
enum fbody = "_wrap_source."~name~"(forward!args)";
}
enum generateFun =
"override "~stc~"ReturnType!(TargetMembers["~n~"].type) "
~ name~"(ParameterTypeTuple!(TargetMembers["~n~"].type) args) "~mod~
"{ return _wrap_source."~name~"(forward!args); }";
"{ return "~fbody~"; }";
}

public:
Expand Down Expand Up @@ -2845,14 +2856,14 @@ template unwrap(Target)
if (isMutable!Target)
{
// strict downcast
@property unwrap(Source)(inout Source src) @trusted pure nothrow
auto unwrap(Source)(inout Source src) @trusted pure nothrow
if (is(Target : Source))
{
alias T = Select!(is(Source == shared), shared Target, Target);
return cast(inout T)(src);
}
// structural downcast
@property unwrap(Source)(inout Source src) @trusted pure nothrow
auto unwrap(Source)(inout Source src) @trusted pure nothrow
if (!is(Target : Source))
{
alias T = Select!(is(Source == shared), shared Target, Target);
Expand Down Expand Up @@ -2931,7 +2942,7 @@ unittest
// structural upcast (two steps)
Quack qx = h1.wrap!Quack; // Human -> Quack
Flyer fx = qx.wrap!Flyer; // Quack -> Flyer
assert(fx.height() == 20); // calls Human.height
assert(fx.height == 20); // calls Human.height
// strucural downcast (two steps)
Quack qy = fx.unwrap!Quack; // Flyer -> Quack
Human hy = qy.unwrap!Human; // Quack -> Human
Expand Down

0 comments on commit 30356d6

Please sign in to comment.