From d059fe743df6a5e8a72fc1418f2c3ba1ed5ac1e6 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Thu, 20 Oct 2016 00:37:24 -0700 Subject: 3524 --- html/057immutable.cc.html | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) (limited to 'html/057immutable.cc.html') diff --git a/html/057immutable.cc.html b/html/057immutable.cc.html index e1e6faf2..5cb35f7b 100644 --- a/html/057immutable.cc.html +++ b/html/057immutable.cc.html @@ -382,13 +382,13 @@ Transform.push_back(const recipe& caller = get(Recipe, r); trace(9991, "transform") << "--- check mutability of ingredients in recipe " << caller.name << end(); if (!caller.has_header) return; // skip check for old-style recipes calling next-ingredient directly - for (int i = 0; i < SIZE(caller.ingredients); ++i) { + for (int i = 0; i < SIZE(caller.ingredients); ++i) { const reagent& current_ingredient = caller.ingredients.at(i); if (is_present_in_products(caller, current_ingredient.name)) continue; // not expected to be immutable // End Immutable Ingredients Special-cases set<reagent> immutable_vars; immutable_vars.insert(current_ingredient); - for (int i = 0; i < SIZE(caller.steps); ++i) { + for (int i = 0; i < SIZE(caller.steps); ++i) { const instruction& inst = caller.steps.at(i); check_immutable_ingredient_in_instruction(inst, immutable_vars, current_ingredient.name, caller); if (inst.operation == INDEX && inst.ingredients.at(1).name == current_ingredient.name) continue; @@ -403,7 +403,7 @@ Transform.push_back(// primitive recipe switch (inst.operation) { case COPY: - for (set<int>::iterator p = current_ingredient_indices.begin(); p != current_ingredient_indices.end(); ++p) + for (set<int>::iterator p = current_ingredient_indices.begin(); p != current_ingredient_indices.end(); ++p) current_ingredient_and_aliases.insert(inst.products.at(*p).name); break; case GET: @@ -421,7 +421,7 @@ Transform.push_back(else { // defined recipe set<int> contained_in_product_indices = scan_contained_in_product_indices(inst, current_ingredient_indices); - for (set<int>::iterator p = contained_in_product_indices.begin(); p != contained_in_product_indices.end(); ++p) { + for (set<int>::iterator p = contained_in_product_indices.begin(); p != contained_in_product_indices.end(); ++p) { if (*p < SIZE(inst.products)) current_ingredient_and_aliases.insert(inst.products.at(*p)); } @@ -431,12 +431,12 @@ Transform.push_back(int> scan_contained_in_product_indices(const instruction& inst, set<int>& ingredient_indices) { set<reagent> selected_ingredients; const recipe& callee = get(Recipe, inst.operation); - for (set<int>::iterator p = ingredient_indices.begin(); p != ingredient_indices.end(); ++p) { + for (set<int>::iterator p = ingredient_indices.begin(); p != ingredient_indices.end(); ++p) { if (*p >= SIZE(callee.ingredients)) continue; // optional immutable ingredient selected_ingredients.insert(callee.ingredients.at(*p)); } set<int> result; - for (int i = 0; i < SIZE(callee.products); ++i) { + for (int i = 0; i < SIZE(callee.products); ++i) { const reagent& current_product = callee.products.at(i); // TODO const string_tree* contained_in_name = property(current_product, "contained-in"); @@ -474,7 +474,7 @@ set<int> scan_contained_in_product_indices:(code) void check_immutable_ingredient_in_instruction(const instruction& inst, const set<reagent>& current_ingredient_and_aliases, const string& original_ingredient_name, const recipe& caller) { // first check if the instruction is directly modifying something it shouldn't - for (int i = 0; i < SIZE(inst.products); ++i) { + for (int i = 0; i < SIZE(inst.products); ++i) { if (has_property(inst.products.at(i), "lookup") && current_ingredient_and_aliases.find(inst.products.at(i)) != current_ingredient_and_aliases.end()) { string current_product_name = inst.products.at(i).name; @@ -488,7 +488,7 @@ set<int> scan_contained_in_product_indices// check if there's any indirect modification going on set<int> current_ingredient_indices = ingredient_indices(inst, current_ingredient_and_aliases); if (current_ingredient_indices.empty()) return; // ingredient not found in call - for (set<int>::iterator p = current_ingredient_indices.begin(); p != current_ingredient_indices.end(); ++p) { + for (set<int>::iterator p = current_ingredient_indices.begin(); p != current_ingredient_indices.end(); ++p) { const int current_ingredient_index = *p; reagent current_ingredient = inst.ingredients.at(current_ingredient_index); canonize_type(current_ingredient); @@ -531,7 +531,7 @@ set<int> scan_contained_in_product_indices} bool is_present_in_products(const recipe& callee, const string& ingredient_name) { - for (int i = 0; i < SIZE(callee.products); ++i) { + for (int i = 0; i < SIZE(callee.products); ++i) { if (callee.products.at(i).name == ingredient_name) return true; } @@ -539,7 +539,7 @@ set<int> scan_contained_in_product_indices} bool is_present_in_ingredients(const recipe& callee, const string& ingredient_name) { - for (int i = 0; i < SIZE(callee.ingredients); ++i) { + for (int i = 0; i < SIZE(callee.ingredients); ++i) { if (callee.ingredients.at(i).name == ingredient_name) return true; } @@ -548,7 +548,7 @@ set<int> scan_contained_in_product_indicesint> ingredient_indices(const instruction& inst, const set<reagent>& ingredient_names) { set<int> result; - for (int i = 0; i < SIZE(inst.ingredients); ++i) { + for (int i = 0; i < SIZE(inst.ingredients); ++i) { if (is_literal(inst.ingredients.at(i))) continue; if (ingredient_names.find(inst.ingredients.at(i)) != ingredient_names.end()) result.insert(i); @@ -600,11 +600,24 @@ $error: 0 if (has_property(current_ingredient, "contained-in")) { const string_tree* tmp = property(current_ingredient, "contained-in"); if (!tmp->atom - || !is_present_in_ingredients(caller, tmp->value) - || !is_present_in_products(caller, tmp->value)) + || (!is_present_in_ingredients(caller, tmp->value) + && !is_present_in_products(caller, tmp->value))) { raise << maybe(caller.name) << "/contained-in can only point to another ingredient or product, but got '" << to_string(property(current_ingredient, "contained-in")) << "'\n" << end(); + } continue; } + +:(scenario contained_in_check) +container test-list [ + value:num + next:&:test-list +] +def test-remove x:&:test-list/contained-in:result, from:&:test-list -> result:&:test-list [ + local-scope + load-ingredients + result <- copy 0 +] +$error: 0 -- cgit 1.4.1-2-gfad0