diff options
Diffstat (limited to '059shape_shifting_recipe.cc')
-rw-r--r-- | 059shape_shifting_recipe.cc | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/059shape_shifting_recipe.cc b/059shape_shifting_recipe.cc index e8c3fcdf..79f4094c 100644 --- a/059shape_shifting_recipe.cc +++ b/059shape_shifting_recipe.cc @@ -430,6 +430,28 @@ void replace_type_ingredients(string_tree* type, const map<string, const string_ replace_type_ingredients(type->right, mappings); } +string inspect(const string_tree* x) { + ostringstream out; + dump_inspect(x, out); + return out.str(); +} + +void dump_inspect(const string_tree* x, ostream& out) { + if (!x->left && !x->right) { + out << x->value; + return; + } + out << '('; + for (const string_tree* curr = x; curr; curr = curr->right) { + if (curr != x) out << ' '; + if (curr->left) + dump_inspect(curr->left, out); + else + out << curr->value; + } + out << ')'; +} + void ensure_all_concrete_types(/*const*/ recipe& new_recipe, const recipe& exemplar) { for (long long int i = 0; i < SIZE(new_recipe.ingredients); ++i) ensure_all_concrete_types(new_recipe.ingredients.at(i), exemplar); |