about summary refs log tree commit diff stats
path: root/058generic_container.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 /058generic_container.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 '058generic_container.cc')
-rw-r--r--058generic_container.cc18
1 files changed, 9 insertions, 9 deletions
diff --git a/058generic_container.cc b/058generic_container.cc
index e757143b..6ba05d5e 100644
--- a/058generic_container.cc
+++ b/058generic_container.cc
@@ -50,9 +50,9 @@ void read_type_ingredients(string& name) {
   string save_name = name;
   istringstream in(save_name);
   name = slurp_until(in, ':');
-  if (Type_ordinal.find(name) == Type_ordinal.end() || Type_ordinal[name] == 0)
-    Type_ordinal[name] = Next_type_ordinal++;
-  type_info& info = Type[Type_ordinal[name]];
+  if (Type_ordinal.find(name) == Type_ordinal.end() || get(Type_ordinal, name) == 0)
+    put(Type_ordinal, name, Next_type_ordinal++);
+  type_info& info = get(Type, get(Type_ordinal, name));
   long long int next_type_ordinal = START_TYPE_INGREDIENTS;
   while (!in.eof()) {
     string curr = slurp_until(in, ':');
@@ -74,7 +74,7 @@ if (type_name.at(0) == '_') {
 
 :(before "End Container Type Checks")
 if (type->value >= START_TYPE_INGREDIENTS
-    && (type->value - START_TYPE_INGREDIENTS) < SIZE(Type[type->value].type_ingredient_names))
+    && (type->value - START_TYPE_INGREDIENTS) < SIZE(get(Type, type->value).type_ingredient_names))
   return;
 
 :(before "End size_of(type) Container Cases")
@@ -103,7 +103,7 @@ long long int size_of_type_ingredient(const type_tree* element_template, const t
   }
   assert(curr);
   assert(!curr->left);  // unimplemented
-  trace(9999, "type") << "type deduced to be " << Type[curr->value].name << "$" << end();
+  trace(9999, "type") << "type deduced to be " << get(Type, curr->value).name << "$" << end();
   type_tree tmp(curr->value);
   if (curr->right)
     tmp.right = new type_tree(*curr->right);
@@ -122,8 +122,8 @@ recipe main [
 +mem: storing 16 in location 2
 
 :(before "End GET field Cases")
-if (Type[base_type].elements.at(i)->value >= START_TYPE_INGREDIENTS) {
-  src += size_of_type_ingredient(Type[base_type].elements.at(i), base.type->right);
+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);
   continue;
 }
 
@@ -212,8 +212,8 @@ recipe main [
 +mem: storing 12 in location 1
 
 :(before "End GET_ADDRESS field Cases")
-if (Type[base_type].elements.at(i)->value >= START_TYPE_INGREDIENTS) {
-  result += size_of_type_ingredient(Type[base_type].elements.at(i), base.type->right);
+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);
   continue;
 }