Skip to content

Commit

Permalink
update for newer compilers
Browse files Browse the repository at this point in the history
  • Loading branch information
9il committed Aug 2, 2023
1 parent 9c64ad5 commit 89426d1
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 12 deletions.
9 changes: 5 additions & 4 deletions source/mir/algebraic.d
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ module mir.algebraic;

import mir.internal.meta;
import mir.functional: naryFun;
import mir.exception: toMutable;

/++
The attribute is used to define a permanent member field in an anlgebraic type.
Expand Down Expand Up @@ -1759,7 +1760,7 @@ struct Algebraic(T__...)
import mir.utility: _expect;
if (_expect(!identifier__, false))
{
throw variantNullException;
throw variantNullException.toMutable;
}
static if (AllowedTypes.length != 2)
{
Expand Down Expand Up @@ -1976,7 +1977,7 @@ struct Algebraic(T__...)
return Ret(trustedGet!T);
}
default:
throw variantMemberException;
throw variantMemberException.toMutable;
}
}
}
Expand Down Expand Up @@ -2124,7 +2125,7 @@ struct Algebraic(T__...)
{
if (_expect(i != identifier__, false))
{
throw variantException;
throw variantException.toMutable;
}
}
return trustedGet!T;
Expand Down Expand Up @@ -4022,7 +4023,7 @@ private noreturn throwMe(T...)(auto ref T args) {
enum simpleThrow = false;
static if (simpleThrow)
{
throw args[0];
throw args[0].toMutable;
}
else
{
Expand Down
3 changes: 2 additions & 1 deletion source/mir/conv.d
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Authors: Ilia Ki
+/
module mir.conv;

import mir.exception: toMutable;
public import core.lifetime: emplace;

import std.traits;
Expand Down Expand Up @@ -71,7 +72,7 @@ template to(T)
version (D_Exceptions)
{
static immutable Exception exc = new Exception(msg);
throw exc;
throw exc.toMutable;
}
else
{
Expand Down
26 changes: 25 additions & 1 deletion source/mir/exception.d
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,30 @@ package template staticException(string fmt, string file, int line)
static immutable staticException = new Exception(fmt, file, line);
}

@trusted pure nothrow @nogc
Exception toMutable()(immutable Exception e)
{
return cast() e;
}

@trusted pure nothrow @nogc
Error toMutable()(immutable Error e)
{
return cast() e;
}

@trusted pure nothrow @nogc
Exception toMutable()(const Exception e)
{
return cast() e;
}

@trusted pure nothrow @nogc
Error toMutable()(const Error e)
{
return cast() e;
}

///
auto ref enforce(string fmt, string file = __FILE__, int line = __LINE__, Expr)(scope auto return ref Expr arg) @trusted
{
Expand All @@ -36,7 +60,7 @@ auto ref enforce(string fmt, string file = __FILE__, int line = __LINE__, Expr)(
if (_expect(cast(bool)arg, true))
return forward!arg;
}
throw staticException!(fmt, file, line);
throw staticException!(fmt, file, line).toMutable;
}

///
Expand Down
17 changes: 13 additions & 4 deletions source/mir/internal/meta.d
Original file line number Diff line number Diff line change
Expand Up @@ -265,21 +265,30 @@ template getUDAs(T, string member, alias attribute)
import std.meta : Filter, AliasSeq, staticMap;
private __gshared T* aggregate;
static if (!__traits(hasMember, T, member))
{
alias getUDAs = AliasSeq!();
}
else
static if (!__traits(compiles, __traits(getMember, *aggregate, member)))
static if (is(T == union) && !__traits(compiles, __traits(getMember, aggregate, member)))
{

alias getUDAs = AliasSeq!();
}
else
static if (AliasSeq!(__traits(getMember, T, member)).length != 1)
{
alias getUDAs = AliasSeq!();
}
else
static if (__traits(getOverloads, T, member).length > 1)
static if (__traits(getOverloads, T, member, true).length >= 1)
{
alias getUDAsImpl(alias overload) = Filter!(isDesiredUDA!attribute, autoGetUDAs!overload);
alias getUDAs = staticMap!(getUDAsImpl, __traits(getOverloads, T, member));
alias getUDAs = staticMap!(getUDAsImpl, __traits(getOverloads, T, member, true));
}
else
alias getUDAs = Filter!(isDesiredUDA!attribute, __traits(getAttributes, __traits(getMember, *aggregate, member)));
{
alias getUDAs = Filter!(isDesiredUDA!attribute, __traits(getAttributes, __traits(getMember, T, member)));
}
}

/++
Expand Down
20 changes: 18 additions & 2 deletions source/mir/reflection.d
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import std.meta;
import std.traits: Parameters, isSomeFunction, FunctionAttribute, functionAttributes, EnumMembers, isAggregateType;
import mir.internal.meta: hasUDA, getUDAs;
import mir.functional: Tuple;
import mir.exception: toMutable;

deprecated
package alias isSomeStruct = isAggregateType;
Expand Down Expand Up @@ -422,6 +423,21 @@ template getUDA(alias symbol, alias attribute)
}
}

/// ditto
template getUDA(T, string member, alias attribute)
{
private alias all = getUDAs!(T, member, attribute);
static if (all.length != 1)
static assert(0, "Exactly one " ~ attribute.stringof ~ " attribute is required, " ~ "got " ~ all.length.stringof);
else
{
static if (is(typeof(all[0])))
enum getUDA = all[0];
else
alias getUDA = all[0];
}
}

/++
Checks if T has a field member.
+/
Expand Down Expand Up @@ -605,7 +621,7 @@ Note: The implementation ignores templates.
template getSetters(T, string member)
{
static if (__traits(hasMember, T, member))
alias getSetters = Filter!(hasSingleArgument, Filter!(isPropertyImpl, __traits(getOverloads, T, member)));
alias getSetters = Filter!(hasSingleArgument, Filter!(isPropertyImpl, __traits(getOverloads, T, member, true)));
else
alias getSetters = AliasSeq!();
}
Expand Down Expand Up @@ -897,7 +913,7 @@ private template isGetter(T, string member)
{
static if (isSomeFunction!(__traits(getMember, *aggregate, member)))
{
enum bool isGetter = Filter!(hasZeroArguments, Filter!(isPropertyImpl, __traits(getOverloads, T, member))).length == 1;
enum bool isGetter = Filter!(hasZeroArguments, Filter!(isPropertyImpl, __traits(getOverloads, T, member, true))).length == 1;
}
else
{
Expand Down

0 comments on commit 89426d1

Please sign in to comment.