From 729b56300c441a0d63c7d2013eb5a881211d352b Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 29 Jul 2015 12:20:53 +0200 Subject: Initial support for target type/pattern-specific variables --- build/dump.cxx | 97 ++++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 78 insertions(+), 19 deletions(-) (limited to 'build/dump.cxx') diff --git a/build/dump.cxx b/build/dump.cxx index 6b6debe..e426f0b 100644 --- a/build/dump.cxx +++ b/build/dump.cxx @@ -18,32 +18,76 @@ using namespace std; namespace build { - static bool - dump_variables (ostream& os, string& ind, const variable_map& vars) + static void + dump_variable (ostream& os, const variable& var, const value_ptr& val) { - bool r (false); + os << var.name << " = "; - for (const auto& e: vars) + if (val == nullptr) + os << "[null]"; + else { - const variable& var (e.first); - const value_ptr& val (e.second); + //@@ TODO: assuming it is a list. + // + os << dynamic_cast (*val); + } + } + static void + dump_variables (ostream& os, string& ind, const variable_map& vars) + { + for (const auto& e: vars) + { os << endl - << ind << var.name << " = "; + << ind; - if (val == nullptr) - os << "[null]"; - else + dump_variable (os, e.first, e.second); + } + } + + static void + dump_variables (ostream& os, string& ind, const variable_type_map& vtm) + { + for (const auto& vt: vtm) + { + const target_type& t (vt.first); + const variable_pattern_map& vpm (vt.second); + + for (const auto& vp: vpm) { - //@@ TODO: assuming it is a list. - // - os << dynamic_cast (*val); - } + const string p (vp.first); + const variable_map& vars (vp.second); - r = true; - } + os << endl + << ind; + + if (t.id != target::static_type.id) + os << t.name << '{'; + + os << p; + + if (t.id != target::static_type.id) + os << '}'; + + os << ':'; - return r; + if (vars.size () == 1) + { + os << ' '; + dump_variable (os, vars.begin ()->first, vars.begin ()->second); + } + else + { + os << endl + << ind << '{'; + ind += " "; + dump_variables (os, ind, vars); + ind.resize (ind.size () - 2); + os << endl + << ind << '}'; + } + } + } } static void @@ -120,9 +164,24 @@ namespace build bool vb (false), sb (false); // Variable/scope block. - // Variables. + // Target type/pattern-sepcific variables. + // + if (!p.target_vars.empty ()) + { + dump_variables (os, ind, p.target_vars); + vb = true; + } + + // Scope variables. // - vb = dump_variables (os, ind, p.vars); + if (!p.vars.empty ()) + { + if (vb) + os << endl; + + dump_variables (os, ind, p.vars); + vb = true; + } // Nested scopes of which we are a parent. // -- cgit v1.1