diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2015-11-06 17:03:02 -0800 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2015-11-06 17:03:02 -0800 |
commit | 57d01f212c8cddb14f585b3ab32984d11a9222e3 (patch) | |
tree | 924df28cf2b5aa37a037f7375343667ec8ca0341 /030container.cc | |
parent | 3bcc53bcd6345dc5aa6ddeca949ab59dba6e7590 (diff) | |
download | mu-57d01f212c8cddb14f585b3ab32984d11a9222e3.tar.gz |
2382
Starting to leave commented out prints again out of desperation.
Diffstat (limited to '030container.cc')
-rw-r--r-- | 030container.cc | 53 |
1 files changed, 44 insertions, 9 deletions
diff --git a/030container.cc b/030container.cc index 5c19c4c8..6a063658 100644 --- a/030container.cc +++ b/030container.cc @@ -517,32 +517,39 @@ container bar [ $error: 0 :(after "Begin Transforms") -Transform.push_back(check_invalid_types); +Transform.push_back(check_or_set_invalid_types); :(code) -void check_invalid_types(const recipe_ordinal r) { +void check_or_set_invalid_types(const recipe_ordinal r) { for (long long int index = 0; index < SIZE(get(Recipe, r).steps); ++index) { const instruction& inst = get(Recipe, r).steps.at(index); for (long long int i = 0; i < SIZE(inst.ingredients); ++i) { - check_invalid_types(inst.ingredients.at(i).type, maybe(get(Recipe, r).name), "'"+inst.to_string()+"'"); + check_or_set_invalid_types(inst.ingredients.at(i).type, inst.ingredients.at(i).properties.at(0).second, + maybe(get(Recipe, r).name), "'"+inst.to_string()+"'"); } for (long long int i = 0; i < SIZE(inst.products); ++i) { - check_invalid_types(inst.products.at(i).type, maybe(get(Recipe, r).name), "'"+inst.to_string()+"'"); + check_or_set_invalid_types(inst.products.at(i).type, inst.products.at(i).properties.at(0).second, + maybe(get(Recipe, r).name), "'"+inst.to_string()+"'"); } } } -void check_invalid_types(const type_tree* type, const string& block, const string& name) { +void check_or_set_invalid_types(type_tree* type, const string_tree* type_name, const string& block, const string& name) { if (!type) return; // will throw a more precise error elsewhere +//? cerr << "checking "; dump_types(type, cerr); cerr << '\n'; // End Container Type Checks if (type->value == 0) { assert(!type->left && !type->right); return; } - if (!contains_key(Type, type->value)) - raise_error << block << "unknown type in " << name << '\n' << end(); - check_invalid_types(type->left, block, name); - check_invalid_types(type->right, block, name); + if (!contains_key(Type, type->value)) { + if (type_name && contains_key(Type_ordinal, type_name->value)) + type->value = get(Type_ordinal, type_name->value); + else + raise_error << block << "unknown type in " << name << '\n' << end(); + } + check_or_set_invalid_types(type->left, type_name ? type_name->left : NULL, block, name); + check_or_set_invalid_types(type->right, type_name ? type_name->right : NULL, block, name); } :(scenario container_unknown_field) @@ -579,6 +586,34 @@ void check_container_field_types() { } } +void check_invalid_types(const recipe_ordinal r) { + for (long long int index = 0; index < SIZE(get(Recipe, r).steps); ++index) { + const instruction& inst = get(Recipe, r).steps.at(index); + for (long long int i = 0; i < SIZE(inst.ingredients); ++i) { + check_invalid_types(inst.ingredients.at(i).type, + maybe(get(Recipe, r).name), "'"+inst.to_string()+"'"); + } + for (long long int i = 0; i < SIZE(inst.products); ++i) { + check_invalid_types(inst.products.at(i).type, + maybe(get(Recipe, r).name), "'"+inst.to_string()+"'"); + } + } +} + +void check_invalid_types(type_tree* type, const string& block, const string& name) { + if (!type) return; // will throw a more precise error elsewhere +//? cerr << "checking "; dump_types(type, cerr); cerr << '\n'; + // End Container Type Checks + if (type->value == 0) { + assert(!type->left && !type->right); + return; + } + if (!contains_key(Type, type->value)) + raise_error << block << "unknown type in " << name << '\n' << end(); + check_invalid_types(type->left, block, name); + check_invalid_types(type->right, block, name); +} + //:: Construct types out of their constituent fields. Doesn't currently do //:: type-checking but *does* match sizes. :(before "End Primitive Recipe Declarations") |