From 65dca85d0acc1ae69518e85b52a2877e38dc8c6d Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 2 Apr 2015 15:06:55 +0200 Subject: Implement translation of meta/operations to natural language --- build/diagnostics.cxx | 99 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) (limited to 'build/diagnostics.cxx') diff --git a/build/diagnostics.cxx b/build/diagnostics.cxx index 43ee0e5..aab7675 100644 --- a/build/diagnostics.cxx +++ b/build/diagnostics.cxx @@ -4,8 +4,12 @@ #include +#include #include +#include +#include +#include #include #include @@ -53,6 +57,101 @@ namespace build return p.string (); } + // diag_do(), etc. + // + string + diag_do (const action& a, const target& t) + { + // @@ root scope + // + scope& root ( + scopes.find ( + scopes.find (t.dir)["out_root"].as ())); + + const meta_operation_info& mi (root.meta_operations[a.meta_operation ()]); + const operation_info& oi (root.operations[a.operation ()]); + + ostringstream os; + + // perform(update(x)) -> "update x" + // configure(update(x)) -> "configure updating x" + // + if (mi.name_do.empty ()) + os << oi.name_do << ' '; + else + { + os << mi.name_do << ' '; + + if (!oi.name_doing.empty ()) + os << oi.name_doing << ' '; + } + + os << t; + return os.str (); + } + + string + diag_doing (const action& a, const target& t) + { + // @@ root scope + // + scope& root ( + scopes.find ( + scopes.find (t.dir)["out_root"].as ())); + + const meta_operation_info& mi (root.meta_operations[a.meta_operation ()]); + const operation_info& oi (root.operations[a.operation ()]); + + ostringstream os; + + // perform(update(x)) -> "updating x" + // configure(update(x)) -> "configuring updating x" + // + if (!mi.name_doing.empty ()) + os << mi.name_doing << ' '; + + if (!oi.name_doing.empty ()) + os << oi.name_doing << ' '; + + os << t; + return os.str (); + } + + string + diag_already_done (const action& a, const target& t) + { + // @@ root scope + // + scope& root ( + scopes.find ( + scopes.find (t.dir)["out_root"].as ())); + + const meta_operation_info& mi (root.meta_operations[a.meta_operation ()]); + const operation_info& oi (root.operations[a.operation ()]); + + ostringstream os; + + // perform(update(x)) -> "x is already up to date" + // configure(update(x)) -> "updating x is already configured" + // + if (mi.name_already_done.empty ()) + { + os << t; + + if (!oi.name_already_done.empty ()) + os << " is already " << oi.name_already_done; + } + else + { + if (!oi.name_doing.empty ()) + os << oi.name_doing << ' '; + + os << t << " is already " << mi.name_already_done; + } + + return os.str (); + } + void print_process (const char* const* args) { -- cgit v1.1