Fix previous commit (symtable operator[] must return a reference to the stored value!)
authormjsousa
Fri, 26 Dec 2014 16:36:06 +0000
changeset 974 a47c2df5ae3d
parent 973 f86d5d6bb04e
child 975 3604464aa80e
Fix previous commit (symtable operator[] must return a reference to the stored value!)
stage3/constant_folding.cc
util/symtable.cc
util/symtable.hh
--- a/stage3/constant_folding.cc	Fri Dec 26 12:43:13 2014 +0000
+++ b/stage3/constant_folding.cc	Fri Dec 26 16:36:06 2014 +0000
@@ -1060,8 +1060,7 @@
     }
     list->elements[i]->const_value = init_value->const_value;
     if (fixed_init_value_) {
-      std::string varName = var_name->value;
-      values[varName] = init_value->const_value;
+      values[var_name->value] = init_value->const_value;
     }
   }
   return NULL;
@@ -1171,8 +1170,7 @@
   // Note that specification->const_value will have been set by handle_var_extern_global_pair(), which is called from declaration_check_c
   symbol->global_var_name->const_value = symbol->specification->const_value;
   if (fixed_init_value_) {
-    std::string varName = get_var_name_c::get_name(symbol->global_var_name)->value;
-    values[varName] = symbol->specification->const_value;
+    values[get_var_name_c::get_name(symbol->global_var_name)->value] = symbol->specification->const_value;
   }
   // If the datatype specification is a subrange or array, do constant folding of all the literals in that type declaration... (ex: literals in array subrange limits)
   symbol->specification->accept(*this);  // should never get to change the const_value of the symbol->specification symbol (only its children!).
@@ -1722,8 +1720,7 @@
 	symbol->r_exp->accept(*this);
 	symbol->l_exp->accept(*this); // if the lvalue has an array, do contant folding of the array indexes!
 	symbol->l_exp->const_value = symbol->r_exp->const_value;
-	varName = get_var_name_c::get_name(symbol->l_exp)->value;
-	values[varName] = symbol->l_exp->const_value;
+	values[get_var_name_c::get_name(symbol->l_exp)->value] = symbol->l_exp->const_value;
 	return NULL;
 }
 
@@ -1762,13 +1759,11 @@
 void *constant_folding_c::visit(for_statement_c *symbol) {
 	map_values_t values_incoming;
 	map_values_t values_statement_result;
-	std::string varName;
 
 	values_incoming = values; /* save incoming status */
 	symbol->beg_expression->accept(*this);
 	symbol->end_expression->accept(*this);
-	varName =  get_var_name_c::get_name(symbol->control_variable)->value;
-	values[varName]._int64.status = const_value_c::cs_non_const;
+	values[get_var_name_c::get_name(symbol->control_variable)->value]._int64.status = const_value_c::cs_non_const;
 
 	/* Optimize dead code */
 	if (NULL != symbol->by_expression) {
--- a/util/symtable.cc	Fri Dec 26 12:43:13 2014 +0000
+++ b/util/symtable.cc	Fri Dec 26 16:36:06 2014 +0000
@@ -149,9 +149,9 @@
 
 // in the operator[] we delegate to find(), since that method will also search in the inner scopes!
 template<typename value_type>
-typename symtable_c<value_type>::value_t symtable_c<value_type>::operator[] (const       char *identifier_str) {return find(identifier_str)->second;}
-template<typename value_type>
-typename symtable_c<value_type>::value_t symtable_c<value_type>::operator[] (const std::string identifier_str) {return find(identifier_str)->second;}
+typename symtable_c<value_type>::value_t& symtable_c<value_type>::operator[] (const       char *identifier_str) {iterator i = find(identifier_str); return (i!=end())?i->second:_base[identifier_str];}
+template<typename value_type>
+typename symtable_c<value_type>::value_t& symtable_c<value_type>::operator[] (const std::string identifier_str) {iterator i = find(identifier_str); return (i!=end())?i->second:_base[identifier_str];}
 
 
 template<typename value_type>
--- a/util/symtable.hh	Fri Dec 26 12:43:13 2014 +0000
+++ b/util/symtable.hh	Fri Dec 26 16:36:06 2014 +0000
@@ -91,9 +91,9 @@
     void insert(const char *identifier_str, value_t value); // insert a new (string,value) pair. Give an error if string already in map associated to different value!
     void insert(const symbol_c *symbol, value_t value);     // insert a new (string,value) pair. Give an error if string already in map associated to different value!
 
-    value_t operator[](const       char *identifier_str);
-    value_t operator[](const std::string identifier_str);
- // value_t operator[](const   symbol_c *identifier    ); // not yet implemented
+    value_t& operator[](const       char *identifier_str);
+    value_t& operator[](const std::string identifier_str);
+ // value_t& operator[](const   symbol_c *identifier    ); // not yet implemented
    
     /* Since symtable_c does not allow duplicates in each level, count() will return
      *  - 0 : if not found in any level