about summary refs log tree commit diff stats
path: root/056recipe_header.cc
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-11-06 11:06:58 -0800
committerKartik K. Agaram <vc@akkartik.com>2015-11-06 11:17:25 -0800
commit795f5244abc9b9f26ff621fd1997db427289d2ba (patch)
tree7018937b9d11ad07dab840789c444ca82ba22333 /056recipe_header.cc
parent90e9eb3d4fa431ed0e7864caead19cd2e06b2c65 (diff)
downloadmu-795f5244abc9b9f26ff621fd1997db427289d2ba.tar.gz
2377 - stop using operator[] in map
I'm still seeing all sorts of failures in turning on layer 11 of edit/,
so I'm backing away and nailing down every culprit I run into. First up:
stop accidentally inserting empty objects into maps during lookups.

Commands run:
  $ sed -i 's/\(Recipe_ordinal\|Recipe\|Type_ordinal\|Type\|Memory\)\[\([^]]*\)\] = \(.*\);/put(\1, \2, \3);/' 0[1-9]*
  $ vi 075scenario_console.cc  # manually fix up Memory[Memory[CONSOLE]]
  $ sed -i 's/\(Memory\)\[\([^]]*\)\]/get_or_insert(\1, \2)/' 0[1-9]*
  $ sed -i 's/\(Recipe_ordinal\|Type_ordinal\)\[\([^]]*\)\]/get(\1, \2)/' 0[1-9]*
  $ sed -i 's/\(Recipe\|Type\)\[\([^]]*\)\]/get(\1, \2)/' 0[1-9]*

Now mu dies pretty quickly because of all the places I try to lookup a
missing value.
Diffstat (limited to '056recipe_header.cc')
-rw-r--r--056recipe_header.cc20
1 files changed, 10 insertions, 10 deletions
diff --git a/056recipe_header.cc b/056recipe_header.cc
index bcea6328..cb63b013 100644
--- a/056recipe_header.cc
+++ b/056recipe_header.cc
@@ -80,7 +80,7 @@ if (result.has_header) {
 if (curr.name == "load-ingredients") {
   curr.clear();
   for (long long int i = 0; i < SIZE(result.ingredients); ++i) {
-    curr.operation = Recipe_ordinal["next-ingredient"];
+    curr.operation = get(Recipe_ordinal, "next-ingredient");
     curr.name = "next-ingredient";
     curr.products.push_back(result.ingredients.at(i));
     result.steps.push_back(curr);
@@ -106,7 +106,7 @@ Transform.push_back(check_header_products);
 
 :(code)
 void check_header_products(const recipe_ordinal r) {
-  const recipe& rr = Recipe[r];
+  const recipe& rr = get(Recipe, r);
   if (rr.products.empty()) return;
   trace(9991, "transform") << "--- checking reply instructions against header for " << rr.name << end();
   for (long long int i = 0; i < SIZE(rr.steps); ++i) {
@@ -143,7 +143,7 @@ Transform.push_back(deduce_types_from_header);
 
 :(code)
 void deduce_types_from_header(const recipe_ordinal r) {
-  recipe& rr = Recipe[r];
+  recipe& rr = get(Recipe, r);
   if (rr.products.empty()) return;
   trace(9991, "transform") << "--- deduce types from header for " << rr.name << end();
   map<string, const type_tree*> header;
@@ -197,13 +197,13 @@ Transform.push_back(fill_in_reply_ingredients);
 
 :(code)
 void fill_in_reply_ingredients(recipe_ordinal r) {
-  if (!Recipe[r].has_header) return;
-  trace(9991, "transform") << "--- fill in reply ingredients from header for recipe " << Recipe[r].name << end();
-  for (long long int i = 0; i < SIZE(Recipe[r].steps); ++i) {
-    instruction& inst = Recipe[r].steps.at(i);
+  if (!get(Recipe, r).has_header) return;
+  trace(9991, "transform") << "--- fill in reply ingredients from header for recipe " << get(Recipe, r).name << end();
+  for (long long int i = 0; i < SIZE(get(Recipe, r).steps); ++i) {
+    instruction& inst = get(Recipe, r).steps.at(i);
     if (inst.name == "reply" && inst.ingredients.empty()) {
-      for (long long int i = 0; i < SIZE(Recipe[r].products); ++i)
-        inst.ingredients.push_back(Recipe[r].products.at(i));
+      for (long long int i = 0; i < SIZE(get(Recipe, r).products); ++i)
+        inst.ingredients.push_back(get(Recipe, r).products.at(i));
     }
   }
 }
@@ -239,7 +239,7 @@ Transform.push_back(deduce_fallthrough_reply);
 
 :(code)
 void deduce_fallthrough_reply(const recipe_ordinal r) {
-  recipe& rr = Recipe[r];
+  recipe& rr = get(Recipe, r);
   if (rr.products.empty()) return;
   if (rr.steps.empty()) return;
   if (rr.steps.at(SIZE(rr.steps)-1).name != "reply") {