about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--010vm.cc91
-rw-r--r--030container.cc6
-rw-r--r--031address.cc3
-rw-r--r--032array.cc4
-rw-r--r--036call_reply.cc2
-rw-r--r--043new.cc4
-rw-r--r--048check_type_by_name.cc4
-rw-r--r--056recipe_header.cc4
-rw-r--r--058generic_container.cc32
-rw-r--r--059generic_recipe.cc20
10 files changed, 83 insertions, 87 deletions
diff --git a/010vm.cc b/010vm.cc
index cade8df8..cfd12fce 100644
--- a/010vm.cc
+++ b/010vm.cc
@@ -21,6 +21,7 @@ struct recipe {
   vector<instruction> steps;
   // End recipe Fields
   recipe();
+  string to_string() const;
 };
 
 :(before "struct recipe")
@@ -269,7 +270,6 @@ string_tree* parse_property_list(istream& in) {
 }
 
 type_tree* new_type_tree(const string_tree* properties) {
-//?   dump_property(properties, cerr);  cerr << '\n';
   if (!properties) return NULL;
   type_tree* result = new type_tree(0);
   if (!properties->value.empty()) {
@@ -349,25 +349,30 @@ string reagent::to_string() const {
     out << "{";
     for (long long int i = 0; i < SIZE(properties); ++i) {
       if (i > 0) out << ", ";
-      out << "\"" << properties.at(i).first << "\": ";
-      dump_property(properties.at(i).second, out);
+      out << "\"" << properties.at(i).first << "\": " << debug_string(properties.at(i).second);
     }
     out << "}";
   }
   return out.str();
 }
 
-void dump_property(const string_tree* property, ostream& out) {
+string debug_string(const reagent& x) {
+  ostringstream out;
+  out << x.name << ": " << debug_string(x.type) << " -- " << x.to_string();
+  return out.str();
+}
+
+string debug_string(const string_tree* property) {
   if (!property) {
-    out << "<>";
-    return;
+    return "<>";
   }
-  // abbreviate a single-node tree to just its contents
-  if (!property->left && !property->right) {
+  ostringstream out;
+  if (!property->left && !property->right)
+    // abbreviate a single-node tree to just its contents
     out << '"' << property->value << '"';
-    return;
-  }
-  dump_property_tree(property, out);
+  else
+    dump_property_tree(property, out);
+  return out.str();
 }
 
 void dump_property_tree(const string_tree* property, ostream& out) {
@@ -384,23 +389,17 @@ void dump_property_tree(const string_tree* property, ostream& out) {
   out << ">";
 }
 
-string dump_types(const reagent& x) {
-  ostringstream out;
-  dump_types(x.type, out);
-  return out.str();
-}
-
-void dump_types(const type_tree* type, ostream& out) {
+string debug_string(const type_tree* type) {
   // abbreviate a single-node tree to just its contents
   if (!type) {
-    out << "NULLNULLNULL";  // should never happen
-    return;
+    return "NULLNULLNULL";  // should never happen
   }
-  if (!type->left && !type->right) {
+  ostringstream out;
+  if (!type->left && !type->right)
     dump_type_name(type->value, out);
-    return;
-  }
-  dump_types_tree(type, out);
+  else
+    dump_types_tree(type, out);
+  return out.str();
 }
 
 void dump_types_tree(const type_tree* type, ostream& out) {
@@ -440,6 +439,22 @@ string instruction::to_string() const {
   return out.str();
 }
 
+string debug_string(const recipe& x) {
+  ostringstream out;
+  out << "recipe " << x.name << '\n';
+  for (long long int index = 0; index < SIZE(x.steps); ++index) {
+    const instruction& inst = x.steps.at(index);
+    out << "  inst: " << inst.to_string() << '\n';
+    out << "  ingredients\n";
+    for (long long int i = 0; i < SIZE(inst.ingredients); ++i)
+      out << "    " << debug_string(inst.ingredients.at(i)) << '\n';
+    out << "  products\n";
+    for (long long int i = 0; i < SIZE(inst.products); ++i)
+      out << "    " << debug_string(inst.products.at(i)) << '\n';
+  }
+  return out.str();
+}
+
 string slurp_until(istream& in, char delim) {
   ostringstream out;
   char c;
@@ -482,27 +497,15 @@ void dump_memory() {
   }
 }
 
-void dump_recipe(const string& recipe_name) {
-  const recipe& r = get(Recipe, get(Recipe_ordinal, recipe_name));
-  cout << "recipe " << r.name << " [\n";
-  for (long long int i = 0; i < SIZE(r.steps); ++i) {
-    cout << "  " << r.steps.at(i).to_string() << '\n';
+string recipe::to_string() const {
+  ostringstream out;
+  out << "recipe " << name << " [\n";
+  for (long long int i = 0; i < SIZE(steps); ++i) {
+    out << "  " << steps.at(i).to_string() << '\n';
   }
-  cout << "]\n";
-}
-
-//? string debug_string(const recipe& x) {
-//?   for (long long int index = 0; index < SIZE(x.steps); ++index) {
-//?     const instruction& inst = x.steps.at(index);
-//?     cerr << "inst: " << inst.to_string() << '\n';
-//?     for (long long int i = 0; i < SIZE(inst.ingredients); ++i) {
-//?       cerr << "  " << inst.ingredients.at(i).to_string() << " => " << dump_types(inst.ingredients.at(i)) << '\n';
-//?     }
-//?     cerr << "--\n";
-//?     for (long long int i = 0; i < SIZE(inst.products); ++i)
-//?       cerr << "  " << inst.products.at(i).to_string() << " => " << dump_types(inst.products.at(i)) << '\n';
-//?   }
-//? }
+  out << "]\n";
+  return out.str();
+}
 
 void skip_whitespace(istream& in) {
   while (!in.eof() && isspace(in.peek()) && in.peek() != '\n') {
diff --git a/030container.cc b/030container.cc
index 0db73c1d..72ac7e73 100644
--- a/030container.cc
+++ b/030container.cc
@@ -160,7 +160,7 @@ case GET: {
   // Update GET product in Check
   const reagent element = element_type(base, offset_value);
   if (!types_match(product, element)) {
-    raise_error << maybe(get(Recipe, r).name) << "'get' " << offset.original_string << " (" << offset_value << ") on " << get(Type, base_type).name << " can't be saved in " << product.original_string << "; type should be " << dump_types(element) << '\n' << end();
+    raise_error << maybe(get(Recipe, r).name) << "'get' " << offset.original_string << " (" << offset_value << ") on " << get(Type, base_type).name << " can't be saved in " << product.original_string << "; type should be " << debug_string(element.type) << '\n' << end();
     break;
   }
   break;
@@ -185,7 +185,7 @@ case GET: {
   trace(9998, "run") << "address to copy is " << src << end();
   reagent tmp = element_type(base, offset);
   tmp.set_value(src);
-  trace(9998, "run") << "its type is " << dump_types(tmp) << end();
+  trace(9998, "run") << "its type is " << debug_string(tmp.type) << end();
   products.push_back(read_memory(tmp));
   break;
 }
@@ -292,7 +292,7 @@ case GET_ADDRESS: {
   // ..except for an address at the start
   element.type = new type_tree(get(Type_ordinal, "address"), element.type);
   if (!types_match(product, element)) {
-    raise_error << maybe(get(Recipe, r).name) << "'get-address' " << offset.original_string << " (" << offset_value << ") on " << get(Type, base_type).name << " can't be saved in " << product.original_string << "; type should be " << dump_types(element) << '\n' << end();
+    raise_error << maybe(get(Recipe, r).name) << "'get-address' " << offset.original_string << " (" << offset_value << ") on " << get(Type, base_type).name << " can't be saved in " << product.original_string << "; type should be " << debug_string(element.type) << '\n' << end();
     break;
   }
   break;
diff --git a/031address.cc b/031address.cc
index 79c951d0..ebbc4e95 100644
--- a/031address.cc
+++ b/031address.cc
@@ -78,8 +78,7 @@ void lookup_memory(reagent& x) {
 bool canonize_type(reagent& r) {
   while (has_property(r, "lookup")) {
     if (!r.type || r.type->value != get(Type_ordinal, "address")) {
-      raise_error << "can't lookup non-address: " << r.to_string() << '\n' << end();
-      dump_types(r.type, cerr);  cerr << '\n';
+      raise_error << "can't lookup non-address: " << r.to_string() << ": " << debug_string(r.type) << '\n' << end();
       return false;
     }
     drop_address_from_type(r);
diff --git a/032array.cc b/032array.cc
index e2bc4ae2..085e2b52 100644
--- a/032array.cc
+++ b/032array.cc
@@ -161,7 +161,7 @@ case INDEX: {
   reagent element;
   element.type = new type_tree(*array_element(base.type));
   if (!types_match(product, element)) {
-    raise_error << maybe(get(Recipe, r).name) << "'index' on " << base.original_string << " can't be saved in " << product.original_string << "; type should be " << dump_types(element) << '\n' << end();
+    raise_error << maybe(get(Recipe, r).name) << "'index' on " << base.original_string << " can't be saved in " << product.original_string << "; type should be " << debug_string(element.type) << '\n' << end();
     break;
   }
   break;
@@ -289,7 +289,7 @@ case INDEX_ADDRESS: {
   element.type = new type_tree(*array_element(base.type));
   element.type = new type_tree(get(Type_ordinal, "address"), element.type);
   if (!types_match(product, element)) {
-    raise_error << maybe(get(Recipe, r).name) << "'index' on " << base.original_string << " can't be saved in " << product.original_string << "; type should be " << dump_types(element) << '\n' << end();
+    raise_error << maybe(get(Recipe, r).name) << "'index' on " << base.original_string << " can't be saved in " << product.original_string << "; type should be " << debug_string(element.type) << '\n' << end();
     break;
   }
   break;
diff --git a/036call_reply.cc b/036call_reply.cc
index 6c613a95..2bc6485c 100644
--- a/036call_reply.cc
+++ b/036call_reply.cc
@@ -47,7 +47,7 @@ case REPLY: {
       canonize_type(lhs);
       reagent rhs = caller_instruction.products.at(i);
       canonize_type(rhs);
-      raise_error << dump_types(lhs) << " ==== vs === " << dump_types(rhs) << '\n' << end();
+      raise_error << debug_string(lhs.type) << " ==== vs === " << debug_string(rhs.type) << '\n' << end();
       DUMP("");
       exit(0);
       goto finish_reply;
diff --git a/043new.cc b/043new.cc
index b5b2ec76..c442f58a 100644
--- a/043new.cc
+++ b/043new.cc
@@ -65,9 +65,7 @@ void transform_new_to_allocate(const recipe_ordinal r) {
       // End Post-processing(type_name) When Converting 'new'
       type_tree* type = new_type_tree(type_name);
       inst.ingredients.at(0).set_value(size_of(type));
-      ostringstream out;
-      dump_property(type_name, out);
-      trace(9992, "new") << "size of " << out.str() << " is " << inst.ingredients.at(0).value << end();
+      trace(9992, "new") << "size of " << debug_string(type_name) << " is " << inst.ingredients.at(0).value << end();
       delete type;
       delete type_name;
     }
diff --git a/048check_type_by_name.cc b/048check_type_by_name.cc
index 27807103..e9b65b8c 100644
--- a/048check_type_by_name.cc
+++ b/048check_type_by_name.cc
@@ -40,7 +40,7 @@ void deduce_missing_type(map<string, type_tree*>& type, map<string, string_tree*
   if (x.type) return;
   if (!contains_key(type, x.name)) return;
   x.type = new type_tree(*type[x.name]);
-  trace(9992, "transform") << x.name << " <= " << dump_types(x) << end();
+  trace(9992, "transform") << x.name << " <= " << debug_string(x.type) << end();
   assert(!x.properties.at(0).second);
   x.properties.at(0).second = new string_tree(*type_name[x.name]);
 }
@@ -52,7 +52,7 @@ void check_type(map<string, type_tree*>& type, map<string, string_tree*>& type_n
   if (is_integer(x.name)) return;
   if (!x.type) return;  // will throw a more precise error elsewhere
   if (!contains_key(type, x.name)) {
-    trace(9992, "transform") << x.name << " => " << dump_types(x) << end();
+    trace(9992, "transform") << x.name << " => " << debug_string(x.type) << end();
     type[x.name] = x.type;
   }
   if (!contains_key(type_name, x.name)) {
diff --git a/056recipe_header.cc b/056recipe_header.cc
index 1558ca95..85fa1c1e 100644
--- a/056recipe_header.cc
+++ b/056recipe_header.cc
@@ -165,7 +165,7 @@ void deduce_types_from_header(const recipe_ordinal r) {
         continue;
       }
       inst.ingredients.at(i).type = new type_tree(*header[inst.ingredients.at(i).name]);
-      trace(9993, "transform") << "type of " << inst.ingredients.at(i).name << " is " << dump_types(inst.ingredients.at(i)) << end();
+      trace(9993, "transform") << "type of " << inst.ingredients.at(i).name << " is " << debug_string(inst.ingredients.at(i).type) << end();
     }
     for (long long int i = 0; i < SIZE(inst.products); ++i) {
       if (inst.products.at(i).type) continue;
@@ -174,7 +174,7 @@ void deduce_types_from_header(const recipe_ordinal r) {
         continue;
       }
       inst.products.at(i).type = new type_tree(*header[inst.products.at(i).name]);
-      trace(9993, "transform") << "type of " << inst.products.at(i).name << " is " << dump_types(inst.products.at(i)) << end();
+      trace(9993, "transform") << "type of " << inst.products.at(i).name << " is " << debug_string(inst.products.at(i).type) << end();
     }
   }
 }
diff --git a/058generic_container.cc b/058generic_container.cc
index df9b63bc..68258249 100644
--- a/058generic_container.cc
+++ b/058generic_container.cc
@@ -81,11 +81,8 @@ if (type->value >= START_TYPE_INGREDIENTS
 if (t.elements.at(i)->value >= START_TYPE_INGREDIENTS) {
   trace(9999, "type") << "checking size of type ingredient\n" << end();
   long long int size = size_of_type_ingredient(t.elements.at(i), type->right);
-  if (!size) {
-    ostringstream out;
-    dump_types(type, out);
-    raise_error << "illegal type '" << out.str() << "' seems to be missing a type ingredient or three\n" << end();
-  }
+  if (!size)
+    raise_error << "illegal type '" << debug_string(type) << "' seems to be missing a type ingredient or three\n" << end();
   result += size;
   continue;
 }
@@ -123,8 +120,12 @@ recipe main [
 +mem: storing 16 in location 2
 
 :(before "End GET field Cases")
-if (get(Type, base_type).elements.at(i)->value >= START_TYPE_INGREDIENTS) {
-  src += size_of_type_ingredient(get(Type, base_type).elements.at(i), base.type->right);
+const type_tree* type = get(Type, base_type).elements.at(i);
+if (type->value >= START_TYPE_INGREDIENTS) {
+  long long int size = size_of_type_ingredient(type, base.type->right);
+  if (!size)
+    raise_error << "illegal field type '" << debug_string(type) << "' seems to be missing a type ingredient or three\n" << end();
+  src += size;
   continue;
 }
 
@@ -142,9 +143,8 @@ recipe main [
 
 :(before "End element_type Special-cases")
 if (contains_type_ingredient(element)) {
-  if (!canonized_base.type->right) {
-    raise_error << "illegal type '" << dump_types(canonized_base) << "' seems to be missing a type ingredient or three\n" << end();
-  }
+  if (!canonized_base.type->right)
+    raise_error << "illegal type '" << debug_string(canonized_base.type) << "' seems to be missing a type ingredient or three\n" << end();
   replace_type_ingredients(element.type, canonized_base.type->right);
 }
 
@@ -164,9 +164,7 @@ void replace_type_ingredients(type_tree* element_type, type_tree* callsite_type)
   if (!element_type) return;
   if (element_type->value >= START_TYPE_INGREDIENTS) {
     if (!has_nth_type(callsite_type, element_type->value-START_TYPE_INGREDIENTS)) {
-      ostringstream out;
-      dump_types(callsite_type, out);
-      raise_error << "illegal type '" << out.str() << "' seems to be missing a type ingredient or three\n" << end();
+      raise_error << "illegal type '" << debug_string(callsite_type) << "' seems to be missing a type ingredient or three\n" << end();
       return;
     }
     element_type->value = nth_type(callsite_type, element_type->value-START_TYPE_INGREDIENTS);
@@ -213,8 +211,12 @@ recipe main [
 +mem: storing 12 in location 1
 
 :(before "End GET_ADDRESS field Cases")
-if (get(Type, base_type).elements.at(i)->value >= START_TYPE_INGREDIENTS) {
-  result += size_of_type_ingredient(get(Type, base_type).elements.at(i), base.type->right);
+const type_tree* type = get(Type, base_type).elements.at(i);
+if (type->value >= START_TYPE_INGREDIENTS) {
+  long long int size = size_of_type_ingredient(type, base.type->right);
+  if (!size)
+    raise_error << "illegal type '" << debug_string(type) << "' seems to be missing a type ingredient or three\n" << end();
+  result += size;
   continue;
 }
 
diff --git a/059generic_recipe.cc b/059generic_recipe.cc
index 811869b6..afdc960f 100644
--- a/059generic_recipe.cc
+++ b/059generic_recipe.cc
@@ -170,8 +170,10 @@ void compute_type_names(recipe& variant) {
 }
 
 void save_or_deduce_type_name(reagent& x, map<string, string_tree*>& type_name) {
+  trace(9994, "transform") << "    checking " << x.to_string() << ": " << debug_string(x.properties.at(0).second) << end();
   if (!x.properties.at(0).second && contains_key(type_name, x.name)) {
     x.properties.at(0).second = new string_tree(*get(type_name, x.name));
+    trace(9994, "transform") << "    deducing type to " << debug_string(x.properties.at(0).second) << end();
     return;
   }
   if (!x.properties.at(0).second) {
@@ -181,9 +183,7 @@ void save_or_deduce_type_name(reagent& x, map<string, string_tree*>& type_name)
   if (contains_key(type_name, x.name)) return;
   if (x.properties.at(0).second->value == "offset" || x.properties.at(0).second->value == "variant") return;  // special-case for container-access instructions
   put(type_name, x.name, x.properties.at(0).second);
-  ostringstream type_name_buf;
-  dump_property(x.properties.at(0).second, type_name_buf);
-  trace(9993, "transform") << "type of " << x.name << " is " << type_name_buf.str() << end();
+  trace(9993, "transform") << "type of " << x.name << " is " << debug_string(x.properties.at(0).second) << end();
 }
 
 void compute_type_ingredient_mappings(const recipe& exemplar, const instruction& inst, map<string, const string_tree*>& mappings) {
@@ -221,9 +221,7 @@ void accumulate_type_ingredients(const string_tree* base, const string_tree* ref
       return;
     }
     if (!contains_key(mappings, base->value)) {
-      ostringstream tmp;
-      dump_property(refinement, tmp);
-      trace(9993, "transform") << "adding mapping from " << base->value << " to " << tmp.str() << end();
+      trace(9993, "transform") << "adding mapping from " << base->value << " to " << debug_string(refinement) << end();
       put(mappings, base->value, new string_tree(*refinement));
     }
     else {
@@ -298,22 +296,18 @@ void replace_type_ingredients(reagent& x, const map<string, const string_tree*>&
   delete x.type;
   x.type = new_type_tree(x.properties.at(0).second);
   if (x.type)
-    trace(9993, "transform") << "  after: " << dump_types(x) << end();
+    trace(9993, "transform") << "  after: " << debug_string(x.type) << end();
 }
 
 void replace_type_ingredients(string_tree* type, const map<string, const string_tree*>& mappings) {
   if (!type) return;
   if (is_type_ingredient_name(type->value) && contains_key(mappings, type->value)) {
     const string_tree* replacement = get(mappings, type->value);
-    ostringstream tmp;
-    dump_property(replacement, tmp);
-    trace(9993, "transform") << type->value << " => " << tmp.str() << end();
+    trace(9993, "transform") << type->value << " => " << debug_string(replacement) << end();
     type->value = replacement->value;
     if (replacement->left) type->left = new string_tree(*replacement->left);
     if (replacement->right) type->right = new string_tree(*replacement->right);
-    ostringstream tmp2;
-    dump_property(type, tmp2);
-    trace(9993, "transform") << " ===> " << tmp2.str() << end();
+    trace(9993, "transform") << " ===> " << debug_string(type) << end();
   }
   replace_type_ingredients(type->left, mappings);
   replace_type_ingredients(type->right, mappings);