Ignore:
Timestamp:
Sep 29, 2014, 2:11:34 PM (5 years ago)
Author:
nmedfort
Message:

More refactoring of the RE system; moved the original re/RE_Compiler to compiler.cpp and the PBIX_Compiler to the re/RE_Compiler.

File:
1 moved

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/re/symbol_generator.cpp

    r4196 r4197  
    77#include "symbol_generator.h"
    88
    9 SymbolGenerator::SymbolGenerator(){
    10         pfxmap = new std::map<std::string, int>();
    11         //std::cout << "pfxmap initialized" << std::endl;
     9namespace re {
     10
     11SymbolGenerator::SymbolGenerator()
     12: pfxmap()
     13{
    1214}
    1315
    14 std::string SymbolGenerator::gensym(std::string prefix)
    15 {
     16std::string SymbolGenerator::get(std::string prefix) {
     17    auto f = pfxmap.find(prefix);
     18    unsigned count = 0;
     19    if (f == pfxmap.end()) {
     20        pfxmap.insert(std::make_pair(prefix, 1));
     21    }
     22    else {
     23        count = f->second++;
     24    }
     25    return prefix + std::to_string(count);
     26}
    1627
    17     std::pair<std::map<std::string, int>::iterator, bool> ret = pfxmap->insert(make_pair(prefix, 0));
    18     std::string sym;
    19     if (ret.second)
    20     {
    21         //The insertion succeeded
    22         sym = prefix + std::to_string(0);
    23         //std::cout << sym << " created" << std::endl;
    24         return sym;
    25     }
    26     else
    27     {
    28         //The insertion failed so we know that the prefix has already been added.
    29         std::map<std::string, int>::iterator iter = pfxmap->find(prefix);
    30         iter->second++;
    31 
    32         sym = prefix + std::to_string(iter->second);
    33         //std::cout << sym << " created" << std::endl;
    34         return sym;
    35        
    36     }
    3728}
Note: See TracChangeset for help on using the changeset viewer.