From 5ed3a6ae29731e09d86b41ae9bd8d304be447279 Mon Sep 17 00:00:00 2001 From: Mike Bierlee Date: Tue, 13 Dec 2016 22:00:34 +0100 Subject: [PATCH] Add Phobos 2.066.1 forwards-compatibility for GDC --- .travis.yml | 5 +++- README.md | 2 +- source/poodinis/autowire.d | 1 + source/poodinis/context.d | 1 + source/poodinis/factory.d | 2 +- source/poodinis/polyfill.d | 56 ++++++++++++++++++++++++++++++++++++-- 6 files changed, 62 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index 855a72a..abe1237 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,10 +6,13 @@ d: - dmd-2.070.2 - dmd-2.069.2 - dmd-2.068.2 - - dmd-2.068.0 + - dmd-2.067.2 + - dmd-2.066.2 + - dmd-2.066.1 - ldc - ldc-1.1.0-beta5 - ldc-0.17.2 + - gdc sudo: false diff --git a/README.md b/README.md index 4550822..3cdc19c 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ Master: [![Build Status](https://api.travis-ci.org/mbierlee/poodinis.png?branch= Poodinis is a dependency injection framework for the D programming language. It is inspired by the [Spring Framework] and [Hypodermic] IoC container for C++. Poodinis supports registering and resolving classes either by concrete type or interface. Automatic injection of dependencies is supported through the use of UDAs or constructors. -Requires at least a D 2.068.0 compatible compiler +Requires at least a D 2.066.1 compatible compiler Uses the Phobos standard library Can be built with DUB 0.9.24 or higher diff --git a/source/poodinis/autowire.d b/source/poodinis/autowire.d index 0aa4513..61715b4 100644 --- a/source/poodinis/autowire.d +++ b/source/poodinis/autowire.d @@ -21,6 +21,7 @@ import poodinis.container; import poodinis.registration; import poodinis.factory; import poodinis.valueinjection; +import poodinis.polyfill; import std.exception; import std.stdio; diff --git a/source/poodinis/context.d b/source/poodinis/context.d index c384d4c..83b1729 100644 --- a/source/poodinis/context.d +++ b/source/poodinis/context.d @@ -16,6 +16,7 @@ module poodinis.context; import poodinis.container; import poodinis.registration; import poodinis.factory; +import poodinis.polyfill; import std.traits; diff --git a/source/poodinis/factory.d b/source/poodinis/factory.d index 17c2ce6..9d2f9a3 100644 --- a/source/poodinis/factory.d +++ b/source/poodinis/factory.d @@ -16,9 +16,9 @@ import poodinis.container; import std.typecons; import std.exception; import std.traits; -import std.meta; import std.string; import std.stdio; +import poodinis.polyfill; alias CreatesSingleton = Flag!"CreatesSingleton"; alias InstanceFactoryMethod = Object delegate(); diff --git a/source/poodinis/polyfill.d b/source/poodinis/polyfill.d index 1178eb3..43a5c6d 100644 --- a/source/poodinis/polyfill.d +++ b/source/poodinis/polyfill.d @@ -14,18 +14,70 @@ module poodinis.polyfill; import std.exception; +import std.traits; static if (!__traits(compiles, basicExceptionCtors)) { mixin template basicExceptionCtors() { - this(string msg, string file = __FILE__, size_t line = __LINE__, Throwable next = null) @nogc @safe pure nothrow + this(string msg, string file = __FILE__, size_t line = __LINE__, Throwable next = null) @safe pure nothrow { super(msg, file, line, next); } - this(string msg, Throwable next, string file = __FILE__, size_t line = __LINE__) @nogc @safe pure nothrow + this(string msg, Throwable next, string file = __FILE__, size_t line = __LINE__) @safe pure nothrow { super(msg, file, line, next); } } } + +static if (!__traits(compiles, enforce!Exception(true, "Message"))) { + T enforce(E: Exception, T)(T value, string message) { + if (value) { + return value; + } + + throw new E(message); + } +} + +static if (!__traits(compiles, FieldNameTuple)) { + private enum NameOf(alias T) = T.stringof; + + template FieldNameTuple(T) + { + import std.typetuple : staticMap; + static if (is(T == struct) || is(T == union)) + alias FieldNameTuple = staticMap!(NameOf, T.tupleof[0 .. $ - isNested!T]); + else static if (is(T == class)) + alias FieldNameTuple = staticMap!(NameOf, T.tupleof); + else + alias FieldNameTuple = TypeTuple!""; + } +} + +static if (!__traits(compiles, hasUDA)) { + template hasUDA(alias symbol, alias attribute) + { + public static bool hasUda() { + foreach(uda; __traits(getAttributes, symbol)) { + if (is(uda == attribute)) { + return true; + } + } + return false; + } + enum hasUDA = hasUda(); + } +} + +static if (!__traits(compiles, Parameters)) { + template Parameters(func...) + if (func.length == 1 && isCallable!func) + { + static if (is(FunctionTypeOf!func P == function)) + alias Parameters = P; + else + static assert(0, "argument has no parameters"); + } +}