Skip to content

Commit

Permalink
update for new compilers
Browse files Browse the repository at this point in the history
  • Loading branch information
9il committed Aug 2, 2023
1 parent 04dd7dd commit bac3308
Show file tree
Hide file tree
Showing 29 changed files with 177 additions and 127 deletions.
2 changes: 1 addition & 1 deletion source/mir/annotated.d
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ struct Annotated(T) {
if (annotations.length == 0)
{
version (D_Exceptions)
throw exc;
{ import mir.exception : toMutable; throw exc.toMutable; }
else
assert(0, excMsg);
}
Expand Down
14 changes: 8 additions & 6 deletions source/mir/base64.d
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ Copyright: 2021 Harrison Ford, Symmetry Investments
+/
module mir.base64;

import mir.exception: toMutable;

package static immutable base64DecodeInvalidCharMsg = "base64: Invalid character encountered.";
package static immutable base64DecodeInvalidLenMsg = "Cannot decode a buffer with given length (not a multiple of 4, missing padding?)";
version(D_Exceptions) {
Expand Down Expand Up @@ -78,7 +80,7 @@ private ubyte lookup_decoding(char i, char plusChar = '+', char slashChar = '/')
}
else {
version(D_Exceptions) {
throw base64DecodeInvalidCharException;
throw base64DecodeInvalidCharException.toMutable;
} else {
assert(0, base64DecodeInvalidCharMsg);
}
Expand Down Expand Up @@ -110,7 +112,7 @@ void decodeBase64(Appender)(scope const(char)[] data,
if (data.length % 4 != 0)
{
version(D_Exceptions) {
throw base64DecodeInvalidLenException;
throw base64DecodeInvalidLenException.toMutable;
} else {
assert(0, base64DecodeInvalidLenMsg);
}
Expand All @@ -137,7 +139,7 @@ void decodeBase64(Appender)(scope const(char)[] data,
if (group[0] == '=' || group[1] == '=')
{
version(D_Exceptions)
throw base64DecodeInvalidCharException;
throw base64DecodeInvalidCharException.toMutable;
else
assert(0, base64DecodeInvalidCharMsg);
}
Expand All @@ -151,7 +153,7 @@ void decodeBase64(Appender)(scope const(char)[] data,
if ((i / 4) != ((data.length / 4) - 1))
{
version(D_Exceptions)
throw base64DecodeInvalidCharException;
throw base64DecodeInvalidCharException.toMutable;
else
assert(0, base64DecodeInvalidCharMsg);
}
Expand All @@ -166,7 +168,7 @@ void decodeBase64(Appender)(scope const(char)[] data,
else
{
version(D_Exceptions)
throw base64DecodeInvalidCharException;
throw base64DecodeInvalidCharException.toMutable;
else
assert(0, base64DecodeInvalidCharMsg);
}
Expand All @@ -180,7 +182,7 @@ void decodeBase64(Appender)(scope const(char)[] data,
if ((i / 4) != ((data.length / 4) - 1))
{
version(D_Exceptions)
throw base64DecodeInvalidCharException;
throw base64DecodeInvalidCharException.toMutable;
else
assert(0, base64DecodeInvalidCharMsg);
}
Expand Down
2 changes: 1 addition & 1 deletion source/mir/bignum/decimal.d
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ struct Decimal(uint size64)
else
{
static immutable exception = new Exception("Can't parse Decimal!" ~ size64.stringof ~ ".");
throw exception;
{ import mir.exception : toMutable; throw exception.toMutable; }
}
}

Expand Down
6 changes: 3 additions & 3 deletions source/mir/bignum/fixed.d
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ struct UInt(size_t size)
else
{
static immutable exception = new Exception("Can't parse UInt!" ~ size.stringof ~ ".");
throw exception;
{ import mir.exception : toMutable; throw exception.toMutable; }
}
}

Expand Down Expand Up @@ -205,7 +205,7 @@ struct UInt(size_t size)
version(D_Exceptions)
{
import mir.bignum.low_level_view: hexStringException;
throw hexStringException;
{ import mir.exception : toMutable; throw hexStringException.toMutable; }
}
else
{
Expand All @@ -232,7 +232,7 @@ struct UInt(size_t size)
version(D_Exceptions)
{
import mir.bignum.low_level_view: binaryStringException;
throw binaryStringException;
{ import mir.exception : toMutable; throw binaryStringException.toMutable; }
}
else
{
Expand Down
8 changes: 4 additions & 4 deletions source/mir/bignum/integer.d
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ struct BigInt(uint size64)
else
{
static immutable exception = new Exception("Can't parse BigInt!" ~ size64.stringof ~ ".");
throw exception;
{ import mir.exception : toMutable; throw exception.toMutable; }
}
}

Expand Down Expand Up @@ -194,7 +194,7 @@ struct BigInt(uint size64)
static immutable bigIntOverflowException = new Exception("BigInt!" ~ size64.stringof ~ ".fromBigEndian: data overflow");
BigInt ret = void;
if (!ret.copyFromBigEndian(data, sign))
throw bigIntOverflowException;
{ import mir.exception : toMutable; throw bigIntOverflowException.toMutable; }
return ret;
}

Expand Down Expand Up @@ -766,7 +766,7 @@ struct BigInt(uint size64)
if (ret.fromHexStringImpl!(char, allowUnderscores)(str))
return ret;
version(D_Exceptions)
throw hexStringException;
{ import mir.exception : toMutable; throw hexStringException.toMutable; }
else
assert(0, hexStringErrorMsg);
}
Expand All @@ -793,7 +793,7 @@ struct BigInt(uint size64)
if (ret.fromBinaryStringImpl!(char, allowUnderscores)(str))
return ret;
version(D_Exceptions)
throw binaryStringException;
{ import mir.exception : toMutable; throw binaryStringException.toMutable; }
else
assert(0, binaryStringErrorMsg);
}
Expand Down
8 changes: 4 additions & 4 deletions source/mir/bignum/low_level_view.d
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ struct BigUIntView(W)
if (view.fromHexStringImpl!(C, allowUnderscores)(str))
return BigUIntView(cast(W[])view.coefficients);
version(D_Exceptions)
throw hexStringException;
{ import mir.exception : toMutable; throw hexStringException.toMutable; }
else
assert(0, hexStringErrorMsg);
}
Expand Down Expand Up @@ -400,7 +400,7 @@ struct BigUIntView(W)
if (view.fromBinaryStringImpl!(C, allowUnderscores)(str))
return BigUIntView(cast(W[])view.coefficients);
version(D_Exceptions)
throw binaryStringException;
{ import mir.exception : toMutable; throw binaryStringException.toMutable; }
else
assert(0, binaryStringErrorMsg);
}
Expand Down Expand Up @@ -1343,7 +1343,7 @@ struct BigIntView(W)
if (ret.fromHexStringImpl!(C, allowUnderscores)(str))
return cast(BigIntView) ret;
version(D_Exceptions)
throw hexStringException;
{ import mir.exception : toMutable; throw hexStringException.toMutable; }
else
assert(0, hexStringErrorMsg);
}
Expand Down Expand Up @@ -1392,7 +1392,7 @@ struct BigIntView(W)
if (ret.fromBinaryStringImpl!(C, allowUnderscores)(str))
return cast(BigIntView) ret;
version(D_Exceptions)
throw binaryStringException;
{ import mir.exception : toMutable; throw binaryStringException.toMutable; }
else
assert(0, binaryStringErrorMsg);
}
Expand Down
28 changes: 14 additions & 14 deletions source/mir/date.d
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ struct YearMonthDay
if (timestamp.precision != Timestamp.Precision.day)
{
static immutable exc = new Exception("YearMonthDay: invalid timestamp precision");
throw exc;
{ import mir.exception : toMutable; throw exc.toMutable; }
}
with(timestamp) this(year, cast(Month)month, day);
}
Expand Down Expand Up @@ -459,7 +459,7 @@ struct YearMonthDay

static if (useExceptions)
{
if (dayOutOfRange) throw InvalidDay;
if (dayOutOfRange) { import mir.exception : toMutable; throw InvalidDay.toMutable; }
}
else
{
Expand Down Expand Up @@ -632,7 +632,7 @@ struct YearMonth
{
static immutable exc = new Exception("Month out of bounds [1, 12]");
if (1 > month || month > 12)
throw exc;
{ import mir.exception : toMutable; throw exc.toMutable; }
this.year = year;
this.month = cast(Month)month;
}
Expand Down Expand Up @@ -711,7 +711,7 @@ struct YearMonth
if (timestamp.precision != Timestamp.Precision.month)
{
static immutable exc = new Exception("YearMonth: invalid timestamp precision");
throw exc;
{ import mir.exception : toMutable; throw exc.toMutable; }
}
with(timestamp) this(year, cast(Month)month);
}
Expand Down Expand Up @@ -851,7 +851,7 @@ struct YearMonth
if (fromISOExtString(str, ret))
return ret;
static immutable exc = new Exception("Invalid YearMonth string");
throw exc;
{ import mir.exception : toMutable; throw exc.toMutable; }
}

nothrow:
Expand Down Expand Up @@ -1087,7 +1087,7 @@ nothrow:

static if (useExceptions)
{
if (dayOutOfRange) throw InvalidDay;
if (dayOutOfRange) { import mir.exception : toMutable; throw InvalidDay.toMutable; }
}
else
{
Expand Down Expand Up @@ -1482,7 +1482,7 @@ struct YearQuarter
if (timestamp.precision != Timestamp.Precision.month)
{
static immutable exc = new Exception("YearMonth: invalid timestamp precision");
throw exc;
{ import mir.exception : toMutable; throw exc.toMutable; }
}
with(timestamp) this(year, cast(Month)month);
}
Expand Down Expand Up @@ -1662,7 +1662,7 @@ struct YearQuarter

static if (useExceptions)
{
if (dayOutOfRange) throw InvalidDay;
if (dayOutOfRange) { import mir.exception : toMutable; throw InvalidDay.toMutable; }
}
else
{
Expand Down Expand Up @@ -2035,7 +2035,7 @@ public:
if (timestamp.precision != Timestamp.Precision.day)
{
static immutable exc = new Exception("Date: invalid timestamp precision");
throw exc;
{ import mir.exception : toMutable; throw exc.toMutable; }
}
with(timestamp) this(year, cast(Month)month, day);
}
Expand Down Expand Up @@ -2119,9 +2119,9 @@ public:
this(int _year, int _month, int _day) @safe pure @nogc
{
if (!valid!"months"(_month))
throw InvalidMonth;
{ import mir.exception : toMutable; throw InvalidMonth.toMutable; }
if (!valid!"days"(_year, cast(Month) _month, _day))
throw InvalidDay;
{ import mir.exception : toMutable; throw InvalidDay.toMutable; }
this = trustedCreate(_year, _month, _day);
}

Expand Down Expand Up @@ -3330,7 +3330,7 @@ public:
Date ret;
if (fromISOString(str, ret))
return ret;
throw InvalidISOString;
{ import mir.exception : toMutable; throw InvalidISOString.toMutable; }
}

///
Expand Down Expand Up @@ -3461,7 +3461,7 @@ public:
Date ret;
if (fromISOExtString(str, ret))
return ret;
throw InvalidISOExtendedString;
{ import mir.exception : toMutable; throw InvalidISOExtendedString.toMutable; }
}

///
Expand Down Expand Up @@ -3732,7 +3732,7 @@ public:
Date ret;
if (fromString(str, ret))
return ret;
throw InvalidString;
{ import mir.exception : toMutable; throw InvalidString.toMutable; }
}

/++
Expand Down
23 changes: 12 additions & 11 deletions source/mir/ediff.d
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,8 @@ import mir.algorithm.iteration: uniq;
import mir.array.allocation;
import mir.math.common;
import mir.ndslice.sorting: sort;
import std.traits: Unqual, getUDAs, hasUDA, isPointer, PointerTarget;
import std.traits: Unqual, isPointer, PointerTarget;
import mir.internal.meta: getUDAs, hasUDA;

@fmamath:

Expand Down Expand Up @@ -405,9 +406,9 @@ template Dependencies(T)
string[] variables;
static foreach (member; __traits(allMembers, T))
{
static if (hasUDA!(__traits(getMember, T, member), Derivative))
static if (hasUDA!(T, member, Derivative))
{
variables ~= getUDAs!(__traits(getMember, T, member), Derivative)[0].variables;
variables ~= getUDAs!(T, member, Derivative)[0].variables;
}
}
return variables.sort.uniq.array.DependsOn;
Expand Down Expand Up @@ -478,8 +479,8 @@ template getDerivative(string[] variables, bool strict = true)
alias V = T;
template hasDerivative(string member)
{
static if (hasUDA!(__traits(getMember, V, member), Derivative))
enum hasDerivative = variables == getUDAs!(__traits(getMember, V, member), Derivative)[0].variables;
static if (hasUDA!(V, member, Derivative))
enum hasDerivative = variables == getUDAs!(V, member, Derivative)[0].variables;
else
enum hasDerivative = false;
}
Expand All @@ -489,7 +490,7 @@ template getDerivative(string[] variables, bool strict = true)
{
static if (hasDerivative!member)
{
static if (hasUDA!(__traits(getMember, V, member), Minus))
static if (hasUDA!(V, member, Minus))
return -__traits(getMember, value, member);
else
return __traits(getMember, value, member);
Expand Down Expand Up @@ -530,16 +531,16 @@ void setDerivatives(bool strict = true, D, E)(scope ref D derivatives, E express
return derivatives.setDerivatives!strict(expression);
else
{
import std.traits: getUDAs, hasUDA, isPointer, PointerTarget;
import std.traits: isPointer, PointerTarget;

static foreach (member; __traits(allMembers, D))
{
static if (hasUDA!(__traits(getMember, D, member), Derivative))
static if (hasUDA!(D, member, Derivative))
{
static if (hasUDA!(__traits(getMember, derivatives, member), Minus))
__traits(getMember, derivatives, member) = -expression.getDerivative!(getUDAs!(__traits(getMember, derivatives, member), Derivative)[0].variables, strict);
static if (hasUDA!(D, member, Minus))
__traits(getMember, derivatives, member) = -expression.getDerivative!(getUDAs!(D, member, Derivative)[0].variables, strict);
else
__traits(getMember, derivatives, member) = expression.getDerivative!(getUDAs!(__traits(getMember, derivatives, member), Derivative)[0].variables, strict);
__traits(getMember, derivatives, member) = expression.getDerivative!(getUDAs!(D, member, Derivative)[0].variables, strict);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions source/mir/graph/package.d
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ GraphSeries!(T, I, J) graphSeries(I = uint, J = size_t, T, Range)(in Range[T] aa
if (index >= keys.length)
{
version(D_Exceptions)
throw exception;
{ import mir.exception : toMutable; throw exception.toMutable; }
else
assert(0, exc_msg);
}
Expand Down Expand Up @@ -132,7 +132,7 @@ RCGraph!(I, J) rcgraph(I = uint, J = size_t, KeyIterator, RangeIterator)(Series!
if (index >= keys.length)
{
version(D_Exceptions)
throw exception;
{ import mir.exception : toMutable; throw exception.toMutable; }
else
assert(0, exc_msg);
}
Expand Down
4 changes: 2 additions & 2 deletions source/mir/interpolate/constant.d
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,12 @@ extern(D):
{
if (x.length < 1)
{
version(D_Exceptions) throw exc_min;
version(D_Exceptions) { import mir.exception : toMutable; throw exc_min.toMutable; }
else assert(0, msg_min);
}
if (x.length != data._lengths[i])
{
version(D_Exceptions) throw exc_eq;
version(D_Exceptions) { import mir.exception : toMutable; throw exc_eq.toMutable; }
else assert(0, msg_eq);
}
_grid[i] = x._iterator;
Expand Down
Loading

0 comments on commit bac3308

Please sign in to comment.