diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2016-11-10 14:30:31 -0800 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2016-11-10 14:30:31 -0800 |
commit | f135ca766f30effc5219ee85387de9a2d91a4d8b (patch) | |
tree | 6ae29647b9bb3abd18955ebe3107492ebf86f9c1 | |
parent | c8f2ff13929c7204dec46b266fa0b155e6faca12 (diff) | |
download | mu-f135ca766f30effc5219ee85387de9a2d91a4d8b.tar.gz |
3658
-rw-r--r-- | 056shape_shifting_recipe.cc | 46 |
1 files changed, 23 insertions, 23 deletions
diff --git a/056shape_shifting_recipe.cc b/056shape_shifting_recipe.cc index 5a9aba49..24304892 100644 --- a/056shape_shifting_recipe.cc +++ b/056shape_shifting_recipe.cc @@ -118,7 +118,7 @@ bool all_concrete_header_reagents_strictly_match(const instruction& inst, const for (int i = 0; i < min(SIZE(inst.products), SIZE(variant.ingredients)); ++i) { if (is_dummy(inst.products.at(i))) continue; if (!concrete_type_names_strictly_match(variant.products.at(i), inst.products.at(i))) { - trace(9993, "transform") << "strict match failed: product " << i << end(); + trace(9993, "transform") << "concrete-type match failed: product " << i << end(); return false; } } @@ -173,28 +173,6 @@ bool concrete_type_names_strictly_match(reagent/*copy*/ to, reagent/*copy*/ from return concrete_type_names_strictly_match(to.type, from.type, from); } -int number_of_concrete_type_names(recipe_ordinal r) { - const recipe& caller = get(Recipe, r); - int result = 0; - for (int i = 0; i < SIZE(caller.ingredients); ++i) - result += number_of_concrete_type_names(caller.ingredients.at(i)); - for (int i = 0; i < SIZE(caller.products); ++i) - result += number_of_concrete_type_names(caller.products.at(i)); - return result; -} - -int number_of_concrete_type_names(const reagent& r) { - return number_of_concrete_type_names(r.type); -} - -int number_of_concrete_type_names(const type_tree* type) { - if (!type) return 0; - if (type->atom) - return is_type_ingredient_name(type->name) ? 0 : 1; - return number_of_concrete_type_names(type->left) - + number_of_concrete_type_names(type->right); -} - bool concrete_type_names_strictly_match(const type_tree* to, const type_tree* from, const reagent& rhs_reagent) { if (!to) return !from; if (!from) return !to; @@ -223,6 +201,28 @@ bool contains_type_ingredient_name(const type_tree* type) { return contains_type_ingredient_name(type->left) || contains_type_ingredient_name(type->right); } +int number_of_concrete_type_names(recipe_ordinal r) { + const recipe& caller = get(Recipe, r); + int result = 0; + for (int i = 0; i < SIZE(caller.ingredients); ++i) + result += number_of_concrete_type_names(caller.ingredients.at(i)); + for (int i = 0; i < SIZE(caller.products); ++i) + result += number_of_concrete_type_names(caller.products.at(i)); + return result; +} + +int number_of_concrete_type_names(const reagent& r) { + return number_of_concrete_type_names(r.type); +} + +int number_of_concrete_type_names(const type_tree* type) { + if (!type) return 0; + if (type->atom) + return is_type_ingredient_name(type->name) ? 0 : 1; + return number_of_concrete_type_names(type->left) + + number_of_concrete_type_names(type->right); +} + recipe_ordinal new_variant(recipe_ordinal exemplar, const instruction& inst, const recipe& caller_recipe) { string new_name = next_unused_recipe_name(inst.name); assert(!contains_key(Recipe_ordinal, new_name)); |