From 65c905fe84c0e8b7acd6839469d7bb9727f0632b Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Sat, 20 Feb 2016 20:05:52 -0800 Subject: 2678 Start using type names from the type tree rather than the property tree in most places. Hopefully the only occurrences of 'properties.at(0).second' left are ones where we're managing it. Next we can stop writing to it. --- 059shape_shifting_recipe.cc | 64 ++++++++++++++++++++++----------------------- 1 file changed, 32 insertions(+), 32 deletions(-) (limited to '059shape_shifting_recipe.cc') diff --git a/059shape_shifting_recipe.cc b/059shape_shifting_recipe.cc index dd874bb7..e8c3fcdf 100644 --- a/059shape_shifting_recipe.cc +++ b/059shape_shifting_recipe.cc @@ -121,14 +121,14 @@ bool all_concrete_header_reagents_strictly_match(const instruction& inst, const return false; } for (long long int i = 0; i < SIZE(variant.ingredients); ++i) { - if (!concrete_types_strictly_match(variant.ingredients.at(i), inst.ingredients.at(i))) { + if (!concrete_type_names_strictly_match(variant.ingredients.at(i), inst.ingredients.at(i))) { trace(9993, "transform") << "concrete-type match failed: ingredient " << i << end(); return false; } } for (long long int i = 0; i < SIZE(inst.products); ++i) { if (is_dummy(inst.products.at(i))) continue; - if (!concrete_types_strictly_match(variant.products.at(i), inst.products.at(i))) { + if (!concrete_type_names_strictly_match(variant.products.at(i), inst.products.at(i))) { trace(9993, "transform") << "strict match failed: product " << i << end(); return false; } @@ -142,7 +142,7 @@ recipe_ordinal best_shape_shifting_variant(const instruction& inst, vector -1); if (score > max_score) max_score = score; } @@ -150,7 +150,7 @@ recipe_ordinal best_shape_shifting_variant(const instruction& inst, vectorvalue.empty() && !is_type_ingredient_name(type->value)) + if (!type->name.empty() && !is_type_ingredient_name(type->name)) result++; - result += number_of_concrete_types(type->left); - result += number_of_concrete_types(type->right); + result += number_of_concrete_type_names(type->left); + result += number_of_concrete_type_names(type->right); return result; } -bool concrete_types_strictly_match(const string_tree* to, const string_tree* from, const reagent& rhs_reagent) { +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; - if (is_type_ingredient_name(to->value)) return true; // type ingredient matches anything - if (to->value == "literal" && from->value == "literal") + if (is_type_ingredient_name(to->name)) return true; // type ingredient matches anything + if (to->name == "literal" && from->name == "literal") return true; - if (to->value == "literal" - && Literal_type_names.find(from->value) != Literal_type_names.end()) + if (to->name == "literal" + && Literal_type_names.find(from->name) != Literal_type_names.end()) return true; - if (from->value == "literal" - && Literal_type_names.find(to->value) != Literal_type_names.end()) + if (from->name == "literal" + && Literal_type_names.find(to->name) != Literal_type_names.end()) return true; - if (from->value == "literal" && to->value == "address") + if (from->name == "literal" && to->name == "address") return rhs_reagent.name == "0"; -//? cerr << to->value << " vs " << from->value << '\n'; - return to->value == from->value - && concrete_types_strictly_match(to->left, from->left, rhs_reagent) - && concrete_types_strictly_match(to->right, from->right, rhs_reagent); +//? cerr << to->name << " vs " << from->name << '\n'; + return to->name == from->name + && concrete_type_names_strictly_match(to->left, from->left, rhs_reagent) + && concrete_type_names_strictly_match(to->right, from->right, rhs_reagent); } bool contains_type_ingredient_name(const reagent& x) { - return contains_type_ingredient_name(x.properties.at(0).second); + return contains_type_ingredient_name(x.type); } -bool contains_type_ingredient_name(const string_tree* type) { +bool contains_type_ingredient_name(const type_tree* type) { if (!type) return false; - if (is_type_ingredient_name(type->value)) return true; + if (is_type_ingredient_name(type->name)) return true; return contains_type_ingredient_name(type->left) || contains_type_ingredient_name(type->right); } @@ -301,7 +301,7 @@ void save_or_deduce_type_name(reagent& x, map& type_name, return; } if (contains_key(type_name, x.name)) return; - if (x.properties.at(0).second->value == "offset" || x.properties.at(0).second->value == "variant") return; // special-case for container-access instructions + if (x.type->name == "offset" || x.type->name == "variant") return; // special-case for container-access instructions put(type_name, x.name, x.properties.at(0).second); trace(9993, "transform") << "type of " << x.name << " is " << to_string(x.properties.at(0).second) << end(); } @@ -390,7 +390,7 @@ void replace_type_ingredients(recipe& new_recipe, const mapvalue != "literal-string") { + if (inst.name == "new" && inst.ingredients.at(0).type->name != "literal-string") { string_tree* type_name = parse_string_tree(inst.ingredients.at(0).name); replace_type_ingredients(type_name, mappings); inst.ingredients.at(0).name = inspect(type_name); -- cgit 1.4.1-2-gfad0