util/dsymtable.cc
changeset 972 bc90dd4bbf4f
parent 721 5dc33058e041
equal deleted inserted replaced
971:8aee27d46208 972:bc90dd4bbf4f
    36 #include "../main.hh" // required for ERROR() and ERROR_MSG() macros.
    36 #include "../main.hh" // required for ERROR() and ERROR_MSG() macros.
    37 
    37 
    38 
    38 
    39 
    39 
    40  /* clear all entries... */
    40  /* clear all entries... */
    41 template<typename value_type, value_type null_value>
    41 template<typename value_type>
    42 void dsymtable_c<value_type, null_value>::reset(void) {
    42 void dsymtable_c<value_type>::reset(void) {
    43   _base.clear();
    43   _base.clear();
    44 }
    44 }
    45 
    45 
    46 
    46 
    47 template<typename value_type, value_type null_value>
    47 template<typename value_type>
    48 void dsymtable_c<value_type, null_value>::insert(const char *identifier_str, value_t new_value) {
    48 void dsymtable_c<value_type>::insert(const char *identifier_str, value_t new_value) {
    49   // std::cout << "store_identifier(" << identifier_str << "): \n";
    49   // std::cout << "store_identifier(" << identifier_str << "): \n";
    50   std::pair<const char *, value_t> new_element(identifier_str, new_value);
    50   std::pair<const char *, value_t> new_element(identifier_str, new_value);
    51   /* iterator res = */ _base.insert(new_element);
    51   /* iterator res = */ _base.insert(new_element);
    52 }
    52 }
    53 
    53 
    54 
    54 
    55 template<typename value_type, value_type null_value>
    55 template<typename value_type>
    56 void dsymtable_c<value_type, null_value>::insert(const symbol_c *symbol, value_t new_value) {
    56 void dsymtable_c<value_type>::insert(const symbol_c *symbol, value_t new_value) {
    57   const token_c *name = dynamic_cast<const token_c *>(symbol);
    57   const token_c *name = dynamic_cast<const token_c *>(symbol);
    58   if (name == NULL)
    58   if (name == NULL)
    59     ERROR;
    59     ERROR;
    60   insert(name->value, new_value);
    60   insert(name->value, new_value);
    61 }
    61 }
    62 
    62 
    63 
    63 
    64 #if 0
    64 #if 0
    65 template<typename value_type, value_type null_value>
    65 template<typename value_type>
    66 void dsymtable_c<value_type, null_value>::insert_noduplicate(const char *identifier_str, value_t new_value) {
    66 void dsymtable_c<value_type>::insert_noduplicate(const char *identifier_str, value_t new_value) {
    67   if (find_value(identifier_str) != null_value)
    67   if (find_value(identifier_str) != null_value)
    68     /* already present in the set! */
    68     /* already present in the set! */
    69     ERROR;
    69     ERROR;
    70 
    70 
    71   // std::cout << "store_identifier(" << identifier_str << "): \n";
    71   // std::cout << "store_identifier(" << identifier_str << "): \n";
    72   std::pair<const char *, value_t> new_element(identifier_str, new_value);
    72   std::pair<const char *, value_t> new_element(identifier_str, new_value);
    73   /* iterator res = */ _base.insert(new_element);
    73   /* iterator res = */ _base.insert(new_element);
    74 }
    74 }
    75 
    75 
    76 
    76 
    77 template<typename value_type, value_type null_value>
    77 template<typename value_type>
    78 void dsymtable_c<value_type, null_value>::insert_noduplicate(const symbol_c *symbol, value_t new_value) {
    78 void dsymtable_c<value_type>::insert_noduplicate(const symbol_c *symbol, value_t new_value) {
    79   const token_c *name = dynamic_cast<const token_c *>(symbol);
    79   const token_c *name = dynamic_cast<const token_c *>(symbol);
    80   if (name == NULL)
    80   if (name == NULL)
    81     ERROR;
    81     ERROR;
    82   insert_noduplicate(name->value, new_value);
    82   insert_noduplicate(name->value, new_value);
    83 }
    83 }
    84 #endif
    84 #endif
    85 
    85 
    86 
    86 
    87 
    87 
    88 
    88 
    89 /* returns null_value if not found! */
    89 template<typename value_type>
    90 template<typename value_type, value_type null_value>
    90 const char * dsymtable_c<value_type>::symbol_to_string(const symbol_c *symbol) {
    91 value_type dsymtable_c<value_type, null_value>::find_value(const char *identifier_str) {
       
    92   iterator i = _base.find(identifier_str);
       
    93 
       
    94   if (i == _base.end())
       
    95     return null_value;
       
    96   else
       
    97     return i->second;
       
    98 }
       
    99 
       
   100 
       
   101 template<typename value_type, value_type null_value>
       
   102 const char * dsymtable_c<value_type, null_value>::symbol_to_string(const symbol_c *symbol) {
       
   103   const token_c *name = dynamic_cast<const token_c *>(symbol);
    91   const token_c *name = dynamic_cast<const token_c *>(symbol);
   104   if (name == NULL)
    92   if (name == NULL)
   105     ERROR;
    93     ERROR;
   106   return name->value;
    94   return name->value;
   107 }
    95 }
   108 
    96 
   109 
    97 
   110 /* debuging function... */
    98 /* debuging function... */
   111 template<typename value_type, value_type null_value>
    99 template<typename value_type>
   112 void dsymtable_c<value_type, null_value>::print(void) {
   100 void dsymtable_c<value_type>::print(void) {
   113   for(iterator i = _base.begin();
   101   for(iterator i = _base.begin();
   114       i != _base.end();
   102       i != _base.end();
   115       i++)
   103       i++)
   116     std::cout << i->second << ":" << i->first << "\n";
   104     std::cout << i->second << ":" << i->first << "\n";
   117   std::cout << "=====================\n";
   105   std::cout << "=====================\n";