From fdc21950905d64b2ca1df5a0b2622022beffe922 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 11 Dec 2014 09:45:26 +0200 Subject: Improve diagnostics and error handling g++-4.9 -std=c++14 -g -I.. -o bd bd.cxx target.cxx native.cxx rule.cxx cxx/rule.cxx cxx/target.cxx process.cxx timestamp.cxx path.cxx --- build/diagnostics | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 build/diagnostics (limited to 'build/diagnostics') diff --git a/build/diagnostics b/build/diagnostics new file mode 100644 index 0000000..c8fb169 --- /dev/null +++ b/build/diagnostics @@ -0,0 +1,54 @@ +// file : build/diagnostics -*- C++ -*- +// copyright : Copyright (c) 2014-2015 Code Synthesis Tools CC +// license : MIT; see accompanying LICENSE file + +#ifndef BUILD_DIAGNOSTICS +#define BUILD_DIAGNOSTICS + +#include +#include +#include + +namespace build +{ + // Throw this exception to terminate the build. The handler should + // assume that the diagnostics has already been issued. + // + class error: public std::exception {}; + + // Call a function if there is an exception. + // + template + struct exception_guard; + + template + inline exception_guard> + make_exception_guard (F f, A&&... a) + { + return exception_guard> ( + std::move (f), std::forward_as_tuple (a...)); + } + + template + struct exception_guard> + { + typedef std::tuple T; + + exception_guard (F f, T a): f_ (std::move (f)), a_ (std::move (a)) {} + ~exception_guard () + { + if (std::uncaught_exception ()) + call (std::index_sequence_for ()); + } + + private: + template + void + call (std::index_sequence) {f_ (std::get (a_)...);} + + F f_; + T a_; + }; +} + +#endif // BUILD_DIAGNOSTICS -- cgit v1.1