Skip to content
Merged
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
6 changes: 4 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ install:
script:
- (cd .. && rdmd ./checkwhitespace.d $(find phobos -name '*.d'))
# enforce whitespace between statements
- grep -E "(for|foreach|foreach_reverse|if|while|switch|catch)\(" $(find . -name '*.d'); test $? -eq 1
- grep -nE "(for|foreach|foreach_reverse|if|while|switch|catch)\(" $(find . -name '*.d'); test $? -eq 1
# enforce whitespace between colon(:) for import statements (doesn't catch everything)
- grep 'import [^/,=]*:' **/*.d | grep -vE 'import ([^ ]+) : '; echo $?
- grep -n 'import [^/,=]*:' $(find . -name '*.d') | grep -vE 'import ([^ ]+) : '; echo $?
# enforce all-man style
- grep -nE "(if|for|foreach|foreach_reverse|while|unittest|switch|else|version) .*{$" $(find . -name '*.d'); test $? -eq 1
# at the moment libdparse has problems to parse some modules (->excludes)
- ./dsc --config .dscanner.ini --styleCheck $(find etc std -type f -name '*.d' | grep -vE 'std/traits.d|std/typecons.d|std/conv.d') -I.
3 changes: 2 additions & 1 deletion etc/c/curl.d
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ alias CURL = void;
alias curl_socket_t = socket_t;

/// jdrewsen - Would like to get socket error constant from std.socket by it is private atm.
version(Windows) {
version(Windows)
{
private import core.sys.windows.windows, core.sys.windows.winsock2;
enum CURL_SOCKET_BAD = SOCKET_ERROR;
}
Expand Down
6 changes: 4 additions & 2 deletions etc/c/zlib.d
Original file line number Diff line number Diff line change
Expand Up @@ -1284,7 +1284,8 @@ void gzclearerr (gzFile file);

uint adler = adler32(0L, Z_NULL, 0);

while (read_buffer(buffer, length) != EOF) {
while (read_buffer(buffer, length) != EOF)
{
adler = adler32(adler, buffer, length);
}
if (adler != original_adler) error();
Expand All @@ -1308,7 +1309,8 @@ uint crc32(uint crc, ubyte* buf, uint len);

uint crc = crc32(0L, Z_NULL, 0);

while (read_buffer(buffer, length) != EOF) {
while (read_buffer(buffer, length) != EOF)
{
crc = crc32(crc, buffer, length);
}
if (crc != original_crc) error();
Expand Down
9 changes: 6 additions & 3 deletions std/algorithm/comparison.d
Original file line number Diff line number Diff line change
Expand Up @@ -923,13 +923,15 @@ private struct Levenshtein(Range, alias equals, CostType = size_t)
EditOp[] result;
size_t i = rows - 1, j = cols - 1;
// restore the path
while (i || j) {
while (i || j)
{
auto cIns = j == 0 ? CostType.max : matrix(i,j - 1);
auto cDel = i == 0 ? CostType.max : matrix(i - 1,j);
auto cSub = i == 0 || j == 0
? CostType.max
: matrix(i - 1,j - 1);
switch (min_index(cSub, cIns, cDel)) {
switch (min_index(cSub, cIns, cDel))
{
case 0:
result ~= matrix(i - 1,j - 1) == matrix(i,j)
? EditOp.none
Expand Down Expand Up @@ -968,7 +970,8 @@ private:
void AllocMatrix(size_t r, size_t c) @trusted {
rows = r;
cols = c;
if (_matrix.length < r * c) {
if (_matrix.length < r * c)
{
import core.stdc.stdlib : realloc;
import core.exception : onOutOfMemoryError;
auto m = cast(CostType *)realloc(_matrix.ptr, r * c * _matrix[0].sizeof);
Expand Down
39 changes: 26 additions & 13 deletions std/algorithm/iteration.d
Original file line number Diff line number Diff line change
Expand Up @@ -1154,12 +1154,14 @@ private struct FilterResult(alias pred, Range)
static assert(isInfinite!(typeof(infinite)));
static assert(isForwardRange!(typeof(infinite)));

foreach (DummyType; AllDummyRanges) {
foreach (DummyType; AllDummyRanges)
{
DummyType d;
auto f = filter!"a & 1"(d);
assert(equal(f, [1,3,5,7,9]));

static if (isForwardRange!DummyType) {
static if (isForwardRange!DummyType)
{
static assert(isForwardRange!(typeof(f)));
}
}
Expand Down Expand Up @@ -1416,7 +1418,8 @@ struct Group(alias pred, R) if (isInputRange!R)
return _current;
}

static if (isForwardRange!R) {
static if (isForwardRange!R)
{
///
@property typeof(this) save() {
typeof(this) ret = this;
Expand Down Expand Up @@ -1451,7 +1454,8 @@ struct Group(alias pred, R) if (isInputRange!R)
tuple(4, 3u), tuple(5, 1u) ][]));
static assert(isForwardRange!(typeof(group(arr))));

foreach (DummyType; AllDummyRanges) {
foreach (DummyType; AllDummyRanges)
{
DummyType d;
auto g = group(d);

Expand Down Expand Up @@ -2480,7 +2484,8 @@ unittest
// Can't use array() or equal() directly because they fail with transient
// .front.
int[] result;
foreach (c; rr.joiner()) {
foreach (c; rr.joiner())
{
result ~= c;
}

Expand Down Expand Up @@ -2525,7 +2530,8 @@ unittest
// Can't use array() or equal() directly because they fail with transient
// .front.
dchar[] result;
foreach (c; rr.joiner()) {
foreach (c; rr.joiner())
{
result ~= c;
}

Expand Down Expand Up @@ -3677,7 +3683,8 @@ if (is(typeof(binaryFun!pred(r.front, s)) : bool)
int[][] w = [ [1, 2], [], [3], [4, 5], [] ];
static assert(isForwardRange!(typeof(splitter(a, 0))));

// foreach (x; splitter(a, 0)) {
// foreach (x; splitter(a, 0))
// {
// writeln("[", x, "]");
// }
assert(equal(splitter(a, 0), w));
Expand Down Expand Up @@ -3715,7 +3722,8 @@ if (is(typeof(binaryFun!pred(r.front, s)) : bool)
assert(split.back == "r ");

foreach (DummyType; AllDummyRanges) { // Bug 4408
static if (isRandomAccessRange!DummyType) {
static if (isRandomAccessRange!DummyType)
{
static assert(isBidirectionalRange!DummyType);
DummyType d;
auto s = splitter(d, 5);
Expand Down Expand Up @@ -4369,8 +4377,10 @@ if (isSomeChar!C)
lines[0] = "line one".dup;
lines[1] = "line \ttwo".dup;
lines[2] = "yah last line\ryah".dup;
foreach (line; lines) {
foreach (word; splitter(strip(line))) {
foreach (line; lines)
{
foreach (word; splitter(strip(line)))
{
if (word in dictionary) continue; // Nothing to do
auto newID = dictionary.length;
dictionary[to!string(word)] = cast(uint)newID;
Expand Down Expand Up @@ -4843,7 +4853,8 @@ private struct UniqResult(alias pred, Range)
@property bool empty() { return _input.empty; }
}

static if (isForwardRange!Range) {
static if (isForwardRange!Range)
{
@property typeof(this) save() {
return typeof(this)(_input.save);
}
Expand All @@ -4865,14 +4876,16 @@ private struct UniqResult(alias pred, Range)
assert(equal(r, [ 1, 2, 3, 4, 5 ][]));
assert(equal(retro(r), retro([ 1, 2, 3, 4, 5 ][])));

foreach (DummyType; AllDummyRanges) {
foreach (DummyType; AllDummyRanges)
{
DummyType d;
auto u = uniq(d);
assert(equal(u, [1,2,3,4,5,6,7,8,9,10]));

static assert(d.rt == RangeType.Input || isForwardRange!(typeof(u)));

static if (d.rt >= RangeType.Bidirectional) {
static if (d.rt >= RangeType.Bidirectional)
{
assert(equal(retro(u), [10,9,8,7,6,5,4,3,2,1]));
}
}
Expand Down
3 changes: 2 additions & 1 deletion std/algorithm/mutation.d
Original file line number Diff line number Diff line change
Expand Up @@ -2396,7 +2396,8 @@ Params:
*/
void swapAt(R)(auto ref R r, size_t i1, size_t i2)
{
static if (is(typeof(&r.swapAt))) {
static if (is(typeof(&r.swapAt)))
{
r.swapAt(i1, i2);
}
else static if (is(typeof(&r[i1])))
Expand Down
9 changes: 6 additions & 3 deletions std/algorithm/searching.d
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,8 @@ is ignored.
import std.algorithm.comparison : equal;
ptrdiff_t virtual_begin = needle.length - offset - portion;
ptrdiff_t ignore = 0;
if (virtual_begin < 0) {
if (virtual_begin < 0)
{
ignore = -virtual_begin;
virtual_begin = 0;
}
Expand Down Expand Up @@ -2173,7 +2174,8 @@ if (Ranges.length > 1 && is(typeof(startsWith!pred(haystack, needles))))
assert(find(a, b) == [ 1, 2, 3, 4, 5 ]);
assert(find(b, a).empty);

foreach (DummyType; AllDummyRanges) {
foreach (DummyType; AllDummyRanges)
{
DummyType d;
auto findRes = find(d, 5);
assert(equal(findRes, [5,6,7,8,9,10]));
Expand Down Expand Up @@ -2206,7 +2208,8 @@ Range1 find(Range1, alias pred, Range2)(
"(.gnu.linkonce.tmain+0x74): In function `main' undefined reference"~
" to `_Dmain':";
string[] ns = ["libphobos", "function", " undefined", "`", ":"];
foreach (n ; ns) {
foreach (n ; ns)
{
auto p = find(h, boyerMooreFinder(n));
assert(!p.empty);
}
Expand Down
21 changes: 14 additions & 7 deletions std/algorithm/sorting.d
Original file line number Diff line number Diff line change
Expand Up @@ -998,7 +998,8 @@ private size_t getPivot(alias less, Range)(Range r)
((cast(uint) (pred(r[0], r[len - 1]))) << 1) |
(cast(uint) (pred(r[mid], r[len - 1])));

switch (result) {
switch (result)
{
case 0b001:
r.swapAt(0, len - 1);
r.swapAt(0, mid);
Expand Down Expand Up @@ -1070,7 +1071,8 @@ private void optimisticInsertionSort(alias less, Range)(Range r)

auto rnd = Random(1);
auto a = new int[uniform(100, 200, rnd)];
foreach (ref e; a) {
foreach (ref e; a)
{
e = uniform(-100, 100, rnd);
}

Expand Down Expand Up @@ -1216,7 +1218,8 @@ unittest
// sort using delegate
auto a = new int[100];
auto rnd = Random(unpredictableSeed);
foreach (ref e; a) {
foreach (ref e; a)
{
e = uniform(-100, 100, rnd);
}

Expand All @@ -1231,7 +1234,8 @@ unittest
assert(isSorted!("a < b")(a));

// sort using function; all elements equal
foreach (ref e; a) {
foreach (ref e; a)
{
e = 5;
}
static bool less(int a, int b) { return a < b; }
Expand Down Expand Up @@ -2223,7 +2227,8 @@ unittest

static double entropy(double[] probs) {
double result = 0;
foreach (p; probs) {
foreach (p; probs)
{
if (!p) continue;
//enforce(p > 0 && p <= 1, "Wrong probability passed to entropy");
result -= p * log2(p);
Expand Down Expand Up @@ -2256,7 +2261,8 @@ unittest

static double entropy(double[] probs) {
double result = 0;
foreach (p; probs) {
foreach (p; probs)
{
if (!p) continue;
//enforce(p > 0 && p <= 1, "Wrong probability passed to entropy");
result -= p * log2(p);
Expand Down Expand Up @@ -2799,7 +2805,8 @@ bool nextPermutation(alias less="a < b", BidirectionalRange)
break;
}

if (i.empty) {
if (i.empty)
{
// Entire range is decreasing: it's lexicographically the greatest. So
// wrap it around.
range.reverse();
Expand Down
3 changes: 2 additions & 1 deletion std/array.d
Original file line number Diff line number Diff line change
Expand Up @@ -2966,7 +2966,8 @@ if (isDynamicArray!A)
}

///
unittest{
unittest
{
auto app = appender!string();
string b = "abcdefg";
foreach (char c; b)
Expand Down
23 changes: 16 additions & 7 deletions std/bigint.d
Original file line number Diff line number Diff line change
Expand Up @@ -223,10 +223,13 @@ public:
}
else static if (op=="*")
{
if (y == 0) {
if (y == 0)
{
sign = false;
data = 0UL;
} else {
}
else
{
sign = ( sign != (y<0) );
data = BigUint.mulInt(data, u);
}
Expand Down Expand Up @@ -716,7 +719,9 @@ public:
Warning: Casting to/from $(D const) or $(D immutable) may break type
system guarantees. Use with care.
*/
T opCast(T)() pure nothrow @nogc const if (is(Unqual!T == BigInt)) {
T opCast(T)() pure nothrow @nogc const
if (is(Unqual!T == BigInt))
{
return this;
}

Expand Down Expand Up @@ -1095,23 +1100,26 @@ Unsigned!T absUnsign(T)(T x) if (isIntegral!T)
}

nothrow pure
unittest {
unittest
{
BigInt a, b;
a = 1;
b = 2;
auto c = a + b;
}

nothrow pure
unittest {
unittest
{
long a;
BigInt b;
auto c = a + b;
auto d = b + a;
}

nothrow pure
unittest {
unittest
{
BigInt x = 1, y = 2;
assert(x < y);
assert(x <= y);
Expand All @@ -1134,7 +1142,8 @@ unittest {
assert(incr == BigInt(1));
}

unittest {
unittest
{
// Radix conversion
assert( toDecimalString(BigInt("-1_234_567_890_123_456_789"))
== "-1234567890123456789");
Expand Down
4 changes: 3 additions & 1 deletion std/bitmanip.d
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,9 @@ The example above creates a tagged reference to an Object in the struct A. This
as $(D taggedPointer), except the first argument which must be a class type instead of a pointer type.
*/

template taggedClassRef(T, string name, Ts...) if (is(T == class)) {
template taggedClassRef(T, string name, Ts...)
if (is(T == class))
{
enum taggedClassRef = createTaggedReference!(T, 8, name, Ts).result;
}

Expand Down
3 changes: 2 additions & 1 deletion std/complex.d
Original file line number Diff line number Diff line change
Expand Up @@ -807,7 +807,8 @@ Complex!T cos(T)(Complex!T z) @safe pure nothrow @nogc
}

///
unittest{
unittest
{
import std.math;
import std.complex;
assert(cos(complex(0.0)) == 1.0);
Expand Down
Loading