From f88883e27afbf346108fcc75667f32196d28743a Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Fri, 7 Aug 2015 13:08:12 -0700 Subject: 1953 - more warnings --- 021arithmetic.cc | 36 +++++++++++++++++++++++++++++------- 022boolean.cc | 15 ++++++++++++--- 2 files changed, 41 insertions(+), 10 deletions(-) diff --git a/021arithmetic.cc b/021arithmetic.cc index 9c1de78b..a29c988c 100644 --- a/021arithmetic.cc +++ b/021arithmetic.cc @@ -9,7 +9,10 @@ case ADD: { double result = 0; //? if (!tb_is_active()) cerr << ingredients.at(1).at(0) << '\n'; //? 1 for (long long int i = 0; i < SIZE(ingredients); ++i) { - assert(scalar(ingredients.at(i))); + if (!scalar(ingredients.at(i))) { + raise << current_recipe_name() << ": 'add' requires number ingredients, but got " << current_instruction().ingredients.at(i).original_string << '\n' << end(); + goto finish_instruction; + } result += ingredients.at(i).at(0); } products.resize(1); @@ -47,10 +50,16 @@ case SUBTRACT: { raise << current_recipe_name() << ": 'subtract' has no ingredients\n" << end(); break; } - assert(scalar(ingredients.at(0))); + if (!scalar(ingredients.at(0))) { + raise << current_recipe_name() << ": 'subtract' requires number ingredients, but got " << current_instruction().ingredients.at(0).original_string << '\n' << end(); + goto finish_instruction; + } double result = ingredients.at(0).at(0); for (long long int i = 1; i < SIZE(ingredients); ++i) { - assert(scalar(ingredients.at(i))); + if (!scalar(ingredients.at(i))) { + raise << current_recipe_name() << ": 'subtract' requires number ingredients, but got " << current_instruction().ingredients.at(i).original_string << '\n' << end(); + goto finish_instruction; + } result -= ingredients.at(i).at(0); } products.resize(1); @@ -86,7 +95,10 @@ Recipe_ordinal["multiply"] = MULTIPLY; case MULTIPLY: { double result = 1; for (long long int i = 0; i < SIZE(ingredients); ++i) { - assert(scalar(ingredients.at(i))); + if (!scalar(ingredients.at(i))) { + raise << current_recipe_name() << ": 'multiply' requires number ingredients, but got " << current_instruction().ingredients.at(i).original_string << '\n' << end(); + goto finish_instruction; + } result *= ingredients.at(i).at(0); } products.resize(1); @@ -124,10 +136,16 @@ case DIVIDE: { raise << current_recipe_name() << ": 'divide' has no ingredients\n" << end(); break; } - assert(scalar(ingredients.at(0))); + if (!scalar(ingredients.at(0))) { + raise << current_recipe_name() << ": 'divide' requires number ingredients, but got " << current_instruction().ingredients.at(0).original_string << '\n' << end(); + goto finish_instruction; + } double result = ingredients.at(0).at(0); for (long long int i = 1; i < SIZE(ingredients); ++i) { - assert(scalar(ingredients.at(i))); + if (!scalar(ingredients.at(i))) { + raise << current_recipe_name() << ": 'divide' requires number ingredients, but got " << current_instruction().ingredients.at(i).original_string << '\n' << end(); + goto finish_instruction; + } result /= ingredients.at(i).at(0); } products.resize(1); @@ -165,9 +183,13 @@ Recipe_ordinal["divide-with-remainder"] = DIVIDE_WITH_REMAINDER; case DIVIDE_WITH_REMAINDER: { products.resize(2); if (SIZE(ingredients) != 2) { - raise << current_recipe_name() << ": 'divide-with-remainder' requires exactly two ingredients, but got " << current_instruction().to_string() << '\n' << end(); + raise << current_recipe_name() << ": 'divide-with-remainder' requires exactly two ingredients, but got '" << current_instruction().to_string() << "'\n" << end(); break; } + if (!scalar(ingredients.at(0)) || !scalar(ingredients.at(1))) { + raise << current_recipe_name() << ": 'divide-with-remainder' requires number ingredients, but got '" << current_instruction().to_string() << "'\n" << end(); + goto finish_instruction; + } long long int quotient = ingredients.at(0).at(0) / ingredients.at(1).at(0); long long int remainder = static_cast(ingredients.at(0).at(0)) % static_cast(ingredients.at(1).at(0)); // very large integers will lose precision diff --git a/022boolean.cc b/022boolean.cc index 6b02b4a8..a2406613 100644 --- a/022boolean.cc +++ b/022boolean.cc @@ -8,7 +8,10 @@ Recipe_ordinal["and"] = AND; case AND: { bool result = true; for (long long int i = 0; i < SIZE(ingredients); ++i) { - assert(scalar(ingredients.at(i))); + if (!scalar(ingredients.at(i))) { + raise << current_recipe_name() << ": 'and' requires boolean ingredients, but got " << current_instruction().ingredients.at(i).original_string << '\n' << end(); + goto finish_instruction; + } result = result && ingredients.at(i).at(0); } products.resize(1); @@ -50,7 +53,10 @@ Recipe_ordinal["or"] = OR; case OR: { bool result = false; for (long long int i = 0; i < SIZE(ingredients); ++i) { - assert(scalar(ingredients.at(i))); + if (!scalar(ingredients.at(i))) { + raise << current_recipe_name() << ": 'or' requires boolean ingredients, but got " << current_instruction().ingredients.at(i).original_string << '\n' << end(); + goto finish_instruction; + } result = result || ingredients.at(i).at(0); } products.resize(1); @@ -92,7 +98,10 @@ Recipe_ordinal["not"] = NOT; case NOT: { products.resize(SIZE(ingredients)); for (long long int i = 0; i < SIZE(ingredients); ++i) { - assert(scalar(ingredients.at(i))); + if (!scalar(ingredients.at(i))) { + raise << current_recipe_name() << ": 'not' requires boolean ingredients, but got " << current_instruction().ingredients.at(i).original_string << '\n' << end(); + goto finish_instruction; + } products.at(i).push_back(!ingredients.at(i).at(0)); } break; -- cgit 1.4.1-2-gfad0