aboutsummaryrefslogtreecommitdiff
path: root/build/diagnostics.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2015-01-20 17:18:09 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2015-01-20 17:18:09 +0200
commitb0524a0b18eec9d5e5c3f6ce30b6cecdd02a6306 (patch)
tree4b1efc586782507e0647e884d6a13c6605298508 /build/diagnostics.cxx
parent47751abc43dab40e0ac4a1523994fd533e6a3b22 (diff)
Diagnostic infrastructure revamp
Diffstat (limited to 'build/diagnostics.cxx')
-rw-r--r--build/diagnostics.cxx66
1 files changed, 64 insertions, 2 deletions
diff --git a/build/diagnostics.cxx b/build/diagnostics.cxx
index f213707..6b524a5 100644
--- a/build/diagnostics.cxx
+++ b/build/diagnostics.cxx
@@ -6,6 +6,8 @@
#include <iostream>
+#include <build/utility>
+
using namespace std;
namespace build
@@ -13,8 +15,68 @@ namespace build
void
print_process (const char* const* args)
{
+ diag_record r (text);
+
for (const char* const* p (args); *p != nullptr; p++)
- cerr << (p != args ? " " : "") << *p;
- cerr << endl;
+ r << (p != args ? " " : "") << *p;
+ }
+
+ // Trace verbosity level.
+ //
+ uint8_t verb;
+
+ // Diagnostic facility, base infrastructure.
+ //
+ ostream* diag_stream = &cerr;
+
+ diag_record::
+ ~diag_record () noexcept(false)
+ {
+ // Don't flush the record if this destructor was called as part of
+ // the stack unwinding. Right now this means we cannot use this
+ // mechanism in destructors, which is not a big deal, except for
+ // one place: exception_guard. So for now we are going to have
+ // this ugly special check which we will be able to get rid of
+ // once C++17 uncaught_exceptions() becomes available.
+ //
+ if (!empty_ && (!std::uncaught_exception () || exception_unwinding_dtor))
+ {
+ *diag_stream << os_.str () << std::endl;
+
+ if (epilogue_ != nullptr)
+ epilogue_ (*this); // Can throw.
+ }
+ }
+
+ // Diagnostic facility, project specifics.
+ //
+
+ void simple_prologue_base::
+ operator() (const diag_record& r) const
+ {
+ if (type_ != nullptr)
+ r << type_ << ": ";
+
+ if (name_ != nullptr)
+ r << name_ << ": ";
+ }
+
+ void location_prologue_base::
+ operator() (const diag_record& r) const
+ {
+ r << loc_.file << ':' << loc_.line << ':' << loc_.column << ": ";
+
+ if (type_ != nullptr)
+ r << type_ << ": ";
+
+ if (name_ != nullptr)
+ r << name_ << ": ";
}
+
+ const basic_mark error ("error");
+ const basic_mark warn ("warning");
+ const basic_mark info ("info");
+ const basic_mark text (nullptr);
+
+ const fail_mark<failed> fail;
}