about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2017-02-07 00:05:38 -0800
committerKartik K. Agaram <vc@akkartik.com>2017-02-07 00:05:38 -0800
commitd9e39b3b1cfac9487a9a0aee2525ea86e3e137b1 (patch)
treee46dc9a45858cdf362f1699a5fbac50560738e89
parent95f2fe96262fcc5977c4633828730acc588c99b3 (diff)
downloadmu-d9e39b3b1cfac9487a9a0aee2525ea86e3e137b1.tar.gz
3743
One way to ensure we always set old_name is to create a method to
initialize names as opposed to just assigning them.

Still not ideal because we still assign directly most of the time, so
it's easy to forget.
-rw-r--r--010vm.cc1
-rw-r--r--043space.cc4
-rw-r--r--053recipe_header.cc2
-rw-r--r--060rewrite_literal_string.cc2
-rw-r--r--062convert_ingredients_to_text.cc4
5 files changed, 9 insertions, 4 deletions
diff --git a/010vm.cc b/010vm.cc
index fea11a50..80a817f3 100644
--- a/010vm.cc
+++ b/010vm.cc
@@ -41,6 +41,7 @@ struct instruction {
   instruction();
   void clear();
   bool is_empty();
+  // End instruction Methods
 };
 
 :(before "struct instruction")
diff --git a/043space.cc b/043space.cc
index 33c4bb09..46736615 100644
--- a/043space.cc
+++ b/043space.cc
@@ -266,6 +266,10 @@ string old_name;
 old_name.clear();
 :(before "End next_instruction(curr)")
 curr->old_name = curr->name;  // before rewrite rules modify it
+:(before "End instruction Methods")
+void initialize_name(const string& n) {
+  name = old_name = n;
+}
 
 :(code)
 // is this reagent one of the values returned by the current (return) instruction?
diff --git a/053recipe_header.cc b/053recipe_header.cc
index c8904ba3..7101d7d6 100644
--- a/053recipe_header.cc
+++ b/053recipe_header.cc
@@ -481,7 +481,7 @@ void fill_in_return_ingredients(const recipe_ordinal r) {
   const instruction& final_instruction = caller_recipe.steps.at(SIZE(caller_recipe.steps)-1);
   if (final_instruction.name != "reply" && final_instruction.name != "return") {
     instruction inst;
-    inst.name = "return";
+    inst.initialize_name("return");
     add_header_products(inst, caller_recipe);
     caller_recipe.steps.push_back(inst);
   }
diff --git a/060rewrite_literal_string.cc b/060rewrite_literal_string.cc
index 3310bf9d..1cd27a8b 100644
--- a/060rewrite_literal_string.cc
+++ b/060rewrite_literal_string.cc
@@ -46,7 +46,7 @@ void rewrite_literal_string_to_text(const recipe_ordinal r) {
         instruction def;
         ostringstream ingredient_name;
         ingredient_name << inst.name << '_' << i << '_' << j << ":text";
-        def.name = "new";
+        def.initialize_name("new");
         def.ingredients.push_back(inst.ingredients.at(j));
         def.products.push_back(reagent(ingredient_name.str()));
         new_instructions.push_back(def);
diff --git a/062convert_ingredients_to_text.cc b/062convert_ingredients_to_text.cc
index 94ff5df3..fbdcc4ec 100644
--- a/062convert_ingredients_to_text.cc
+++ b/062convert_ingredients_to_text.cc
@@ -115,13 +115,13 @@ void convert_ingredient_to_text(reagent& r, vector<instruction>& out, const stri
   if (is_static_array(r)) return;
   instruction def;
   if (is_lookup_of_address_of_array(r)) {
-    def.name = "array-to-text-line";
+    def.initialize_name("array-to-text-line");
     reagent/*copy*/ tmp = r;
     drop_one_lookup(tmp);
     def.ingredients.push_back(tmp);
   }
   else {
-    def.name = "to-text-line";
+    def.initialize_name("to-text-line");
     def.ingredients.push_back(r);
   }
   def.products.push_back(reagent(tmp_var));