source: icGREP/icgrep-devel/icgrep/pablo/symbol_generator.cpp @ 4899

Last change on this file since 4899 was 4860, checked in by nmedfort, 4 years ago

Back up check in. Memory leaks should be fixed.

File size: 1.5 KB
Line 
1/*
2 *  Copyright (c) 2014 International Characters.
3 *  This software is licensed to the public under the Open Software License 3.0.
4 *  icgrep is a trademark of International Characters.
5 */
6
7#include <pablo/symbol_generator.h>
8#include <pablo/pe_string.h>
9#include <pablo/pe_integer.h>
10
11namespace pablo {
12
13String * SymbolGenerator::get(const std::string name, const bool generated) {
14    if (name.length() == 0) {
15        throw std::runtime_error("symbol name cannot be 0-length");
16    }
17    auto f = mStringMap.find(name);
18    String * result = nullptr;
19    if (f == mStringMap.end()) {
20        result = new String(name, generated);
21        assert (result);
22        mStringMap.insert(std::make_pair(std::move(name), result));
23    }
24    else {
25        result = f->second;
26    }
27    return result;
28}
29
30Integer * SymbolGenerator::getInteger(const integer_t value) {
31    auto f = mIntegerMap.find(value);
32    Integer * result;
33    if (f == mIntegerMap.end()) {
34        result = new Integer(value);
35        assert (result->value() == value);
36        mIntegerMap.insert(std::make_pair(value, result));
37    } else {
38        result = f->second;
39    }
40    return result;
41}
42
43String * SymbolGenerator::make(const std::string prefix, const bool generated) {
44    auto f = mPrefixMap.find(prefix);
45    unsigned count = 0;
46    if (f == mPrefixMap.end()) {
47        mPrefixMap.insert(std::make_pair(prefix, 1));
48        return get(prefix, generated);
49    } else {
50        count = f->second++;
51        return get(prefix + std::to_string(count), generated);
52    }
53}
54
55}
Note: See TracBrowser for help on using the repository browser.