aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2016-04-20 08:28:06 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2016-04-20 08:28:06 +0200
commit855ee25d977c3e658162210de3c418922e1fe949 (patch)
tree2b875c62c8035880ae72e2953c375220dff4bd71
parent76697cbfae866d4ce2171f18ce164da87c652bc5 (diff)
Print variable/value attributes in dump()
-rw-r--r--build2/dump.cxx61
1 files changed, 45 insertions, 16 deletions
diff --git a/build2/dump.cxx b/build2/dump.cxx
index 442340f..9310405 100644
--- a/build2/dump.cxx
+++ b/build2/dump.cxx
@@ -14,6 +14,45 @@ using namespace std;
namespace build2
{
+ // If type is false, don't print the value's type (e.g., because it is the
+ // same as variable's).
+ //
+ static void
+ dump_value (ostream& os, const value& v, bool type)
+ {
+ // First print attributes if any.
+ //
+ bool a (v.null () || (type && v.type != nullptr));
+
+ if (a)
+ os << '[';
+
+ const char* s ("");
+
+ if (type && v.type != nullptr)
+ {
+ os << s << v.type->name;
+ s = " ";
+ }
+
+ if (v.null ())
+ {
+ os << s << "null";
+ s = " ";
+ }
+
+ if (a)
+ os << ']';
+
+ // Now the value if there is one.
+ //
+ if (!v.null ())
+ {
+ names storage;
+ os << (a ? " " : "") << reverse (v, storage);
+ }
+ }
+
static void
dump_variable (ostream& os,
const variable& var,
@@ -21,10 +60,13 @@ namespace build2
const scope& s,
bool target)
{
+ if (var.type != nullptr)
+ os << '[' << var.type->name << "] ";
+
os << var.name << " = ";
// If this variable is overriden, print both the override and the
- // original.
+ // original values.
//
if (var.override != nullptr &&
var.name.rfind (".__override") == string::npos &&
@@ -38,25 +80,12 @@ namespace build2
if (org != l)
{
- if (l->null ())
- os << "[null]";
- else
- {
- names storage;
- os << reverse (*l, storage);
- }
-
+ dump_value (os, *l, l->type != var.type);
os << " # original: ";
}
}
- if (org->null ())
- os << "[null]";
- else
- {
- names storage;
- os << reverse (*org, storage);
- }
+ dump_value (os, *org, org->type != var.type);
}
static void