Simplify 2790 by simply not computing any type->value inside
parse_type_tree. It now only generates names, and it turns out the
consumers handle the absence of values anyway. Now parse_type_tree no
longer pollutes the Type_ordinal table with type ingredients.
This commit is contained in:
Kartik K. Agaram 2016-03-19 00:51:19 -07:00
parent 1d1faace5d
commit 968866f7ac
3 changed files with 5 additions and 18 deletions

View File

@ -433,7 +433,6 @@ void insert_container(const string& command, kind_of_type kind, istream& in) {
void replace_unknown_types_with_unique_ordinals(type_tree* type, const type_info& info) {
if (!type) return;
// End insert_container Special-cases
if (!type->name.empty()) {
if (contains_key(Type_ordinal, type->name)) {
type->value = get(Type_ordinal, type->name);
@ -441,12 +440,12 @@ void replace_unknown_types_with_unique_ordinals(type_tree* type, const type_info
else if (is_integer(type->name)) { // sometimes types will contain non-type tags, like numbers for the size of an array
type->value = 0;
}
// End insert_container Special-cases
else if (type->name != "->") { // used in recipe types
put(Type_ordinal, type->name, Next_type_ordinal++);
type->value = get(Type_ordinal, type->name);
}
}
recurse:
replace_unknown_types_with_unique_ordinals(type->left, info);
replace_unknown_types_with_unique_ordinals(type->right, info);
}

View File

@ -94,9 +94,8 @@ void read_type_ingredients(string& name) {
:(before "End insert_container Special-cases")
// check for use of type ingredients
else if (!type->name.empty() && is_type_ingredient_name(type->name)) {
else if (is_type_ingredient_name(type->name)) {
type->value = get(info.type_ingredient_names, type->name);
goto recurse;
}
:(code)
bool is_type_ingredient_name(const string& type) {

View File

@ -463,13 +463,8 @@ type_tree* parse_type_tree(istream& in) {
in.get();
return NULL;
}
if (in.peek() != '(') {
string type_name = next_word(in);
if (!contains_key(Type_ordinal, type_name))
put(Type_ordinal, type_name, Next_type_ordinal++);
type_tree* result = new type_tree(type_name, get(Type_ordinal, type_name));
return result;
}
if (in.peek() != '(')
return new type_tree(next_word(in), 0);
in.get(); // skip '('
type_tree* result = NULL;
type_tree** curr = &result;
@ -479,14 +474,8 @@ type_tree* parse_type_tree(istream& in) {
skip_whitespace_but_not_newline(in);
if (in.peek() == '(')
(*curr)->left = parse_type_tree(in);
else {
else
(*curr)->name = next_word(in);
if (!is_type_ingredient_name((*curr)->name)) {
if (!contains_key(Type_ordinal, (*curr)->name))
put(Type_ordinal, (*curr)->name, Next_type_ordinal++);
(*curr)->value = get(Type_ordinal, (*curr)->name);
}
}
curr = &(*curr)->right;
}
in.get(); // skip ')'