From 6d007fda037331e7761d2a9ed3a2e435131daf7e Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Fri, 11 Nov 2016 15:54:19 -0800 Subject: 3667 --- html/010vm.cc.html | 113 ++++++++++++++++++++++++++++++++++------------------- 1 file changed, 73 insertions(+), 40 deletions(-) (limited to 'html/010vm.cc.html') diff --git a/html/010vm.cc.html b/html/010vm.cc.html index 22196064..8a104027 100644 --- a/html/010vm.cc.html +++ b/html/010vm.cc.html @@ -97,8 +97,8 @@ recipe_ordinal Next_recipe_ordinal = 1() :type(NULL), value(0), initialized(false) {} ~reagent(); void clear(); - reagent(const reagent& old); - reagent& operator=(const reagent& old); + reagent(const reagent& original); + reagent& operator=(const reagent& original); void set_value(double v) { value = v; initialized = true; } }; @@ -112,13 +112,13 @@ recipe_ordinal Next_recipe_ordinal = 1; // only if !atom type_tree* right; // only if !atom ~type_tree(); - type_tree(const type_tree& old); + type_tree(const type_tree& original); // atomic type ordinal explicit type_tree(string name); type_tree(string name, type_ordinal v) :atom(true), name(name), value(v), left(NULL), right(NULL) {} // tree of type ordinals type_tree(type_tree* l, type_tree* r) :atom(false), value(0), left(l), right(r) {} - type_tree& operator=(const type_tree& old); + type_tree& operator=(const type_tree& original); bool operator==(const type_tree& other) const; bool operator!=(const type_tree& other) const { return !operator==(other); } bool operator<(const type_tree& other) const; @@ -131,7 +131,7 @@ recipe_ordinal Next_recipe_ordinal = 1; // only if !atom string_tree* right; // only if !atom ~string_tree(); - string_tree(const string_tree& old); + string_tree(const string_tree& original); // atomic string explicit string_tree(string v) :atom(true), value(v), left(NULL), right(NULL) {} // tree of strings @@ -337,12 +337,34 @@ reagent::reagent(const(istream& in) { skip_whitespace_but_not_newline(in); if (!has_data(in)) return NULL; - string_tree* left = new string_tree(slurp_until(in, ':')); - if (!has_data(in)) return left; - string_tree* right = parse_property_list(in); - return new string_tree(left, right); + string_tree* first = new string_tree(slurp_until(in, ':')); + if (!has_data(in)) return first; + string_tree* rest = parse_property_list(in); + if (!has_data(in) && rest->atom) + return new string_tree(first, new string_tree(rest, NULL)); + return new string_tree(first, rest); +} +:(before "End Unit Tests") +void test_parse_property_list_atom() { + istringstream in("a"); + string_tree* x = parse_property_list(in); + CHECK(x->atom); + delete x; +} +void test_parse_property_list_list() { + istringstream in("a:b"); + string_tree* x = parse_property_list(in); + CHECK(!x->atom); + CHECK(x->left->atom); + CHECK_EQ(x->left->value, "a"); + CHECK(!x->right->atom); + CHECK(x->right->left->atom); + CHECK_EQ(x->right->left->value, "b"); + CHECK(x->right->right == NULL); + delete x; } +:(code) type_tree* new_type_tree(const string_tree* properties) { if (!properties) return NULL; if (properties->atom) { @@ -377,20 +399,22 @@ reagent::reagent(const// End reagent Copy Constructor } -type_tree::type_tree(const type_tree& old) { - atom = old.atom; - name = old.name; - value = old.value; - left = old.left ? new type_tree(*old.left) : NULL; - right = old.right ? new type_tree(*old.right) : NULL; +type_tree::type_tree(const type_tree& original) { + atom = original.atom; + name = original.name; + value = original.value; + left = original.left ? new type_tree(*original.left) : NULL; + right = original.right ? new type_tree(*original.right) : NULL; } -type_tree& type_tree::operator=(const type_tree& old) { - atom = old.atom; - name = old.name; - value = old.value; - left = old.left ? new type_tree(*old.left) : NULL; - right = old.right ? new type_tree(*old.right) : NULL; +type_tree& type_tree::operator=(const type_tree& original) { + atom = original.atom; + name = original.name; + value = original.value; + if (left) delete left; + left = original.left ? new type_tree(*original.left) : NULL; + if (right) delete right; + right = original.right ? new type_tree(*original.right) : NULL; return *this; } @@ -411,9 +435,10 @@ type_tree& type_tree::operator=if (!left && other.left) return true; if (right && !other.right) return false; if (!right && other.right) return true; + // now if either pointer is unequal neither side can be null // if one side is equal that's easy - if (left == other.left || *left == *other.left) return *right < *other.right; - if (right == other.right || *right == *other.right) return *left < *other.left; + if (left == other.left || *left == *other.left) return right && *right < *other.right; + if (right == other.right || *right == *other.right) return left && *left < *other.left; // if the two sides criss-cross, pick the side with the smaller lhs if ((left == other.right || *left == *other.right) && (right == other.left || *right == *other.left)) @@ -459,25 +484,21 @@ type_tree& type_tree::operator=} void test_compare_list_with_smaller_left_but_larger_right() { reagent a("a:address:number"), b("b:character:array"); - assert(a.type->left->atom && a.type->right->atom); - assert(b.type->left->atom && b.type->right->atom); CHECK(*a.type < *b.type); CHECK(!(*b.type < *a.type)); } void test_compare_list_with_smaller_left_but_larger_right_identical_types() { reagent a("a:address:boolean"), b("b:boolean:address"); - assert(a.type->left->atom && a.type->right->atom); - assert(b.type->left->atom && b.type->right->atom); CHECK(*a.type < *b.type); CHECK(!(*b.type < *a.type)); } :(code) -string_tree::string_tree(const string_tree& old) { - atom = old.atom; - value = old.value; - left = old.left ? new string_tree(*old.left) : NULL; - right = old.right ? new string_tree(*old.right) : NULL; +string_tree::string_tree(const string_tree& original) { + atom = original.atom; + value = original.value; + left = original.left ? new string_tree(*original.left) : NULL; + right = original.right ? new string_tree(*original.right) : NULL; } reagent& reagent::operator=(const reagent& other) { @@ -694,8 +715,11 @@ string to_string(constif (curr->right) out << ' '; curr = curr->right; } - // final right - dump(curr, out); + // check for dotted list; should never happen + if (curr) { + out << ". "; + dump(curr, out); + } out << ')'; } @@ -720,8 +744,11 @@ string to_string(constif (curr->right) out << ' '; curr = curr->right; } - // final right - dump(curr, out); + // check for dotted list; should never happen + if (curr) { + out << ". "; + dump(curr, out); + } out << ')'; } @@ -753,8 +780,11 @@ string names_to_string(const if (curr->right) out << ' '; curr = curr->right; } - // final right - dump_names(curr, out); + // check for dotted list; should never happen + if (curr) { + out << ". "; + dump_names(curr, out); + } out << ')'; } @@ -779,8 +809,11 @@ string names_to_string_without_quotes(if (curr->right) out << ' '; curr = curr->right; } - // final right - dump_names_without_quotes(curr, out); + // check for dotted list; should never happen + if (curr) { + out << ". "; + dump_names_without_quotes(curr, out); + } out << ')'; } -- cgit 1.4.1-2-gfad0