12 #ifndef OPENVDB_AX_CODEGEN_SYMBOL_TABLE_HAS_BEEN_INCLUDED 13 #define OPENVDB_AX_CODEGEN_SYMBOL_TABLE_HAS_BEEN_INCLUDED 15 #include <openvdb/version.h> 22 #include <unordered_map> 39 using MapType = std::unordered_map<std::string, T>;
48 inline const T*
get(
const std::string& name)
const 50 const auto iter = mMap.find(name);
51 if (iter == mMap.end())
return nullptr;
52 return &(iter->second);
59 inline bool exists(
const std::string& name)
const 61 const auto iter = mMap.find(name);
62 return (iter != mMap.end());
71 inline bool insert(
const std::string& name,
const T& value)
73 const auto iter = mMap.emplace(name, value);
83 inline bool replace(
const std::string& name,
const T& value)
85 auto iter = mMap.emplace(name, value);
86 const bool inserted = iter.second;
87 if (!inserted) iter.first->second = value;
93 inline void clear() { mMap.clear(); }
117 using MapType = std::map<size_t, SymbolTable<Value>>;
134 inline bool erase(
const size_t index)
136 const bool existed = (mTables.find(index) != mTables.end());
137 mTables.erase(index);
147 return &(mTables[index]);
156 auto iter = mTables.find(index);
157 if (iter == mTables.end())
return nullptr;
158 return &(iter->second);
169 inline const Value*
find(
const std::string& name,
const size_t startIndex)
const 175 auto it = mTables.lower_bound(startIndex);
176 if (it == mTables.end() || it->first != startIndex) --it;
182 MapType::const_reverse_iterator iter(++it);
184 for (; iter != mTables.crend(); ++iter) {
185 const Value* value = iter->second.get(name);
186 if (value)
return value;
199 return this->find(name, mTables.crbegin()->first);
210 for (
auto it = mTables.rbegin(); it != mTables.rend(); ++it) {
211 if (it->second.get(name)) {
212 it->second.replace(name, value);
229 #endif // OPENVDB_AX_CODEGEN_SYMBOL_TABLE_HAS_BEEN_INCLUDED std::unordered_map< std::string, llvm::openvdb::v12_1::ax::codegen::Value * > MapType
Definition: SymbolTable.h:39
bool insert(const std::string &name, const T &value)
Insert a variable to this symbol table if it does not exist. Returns true if successfully, false if a variable already exists with the given name.
Definition: SymbolTable.h:71
void clear()
Clear all symbols in this table.
Definition: SymbolTable.h:93
SymbolTable< llvm::Value * > & globals()
Access to the list of global variables which are always accessible.
Definition: SymbolTable.h:126
const Value * find(const std::string &name, const size_t startIndex) const
Find a variable within the program starting at a given table index. If the given index does not exist...
Definition: SymbolTable.h:169
A map of unique ids to symbol tables which can be used to represent local variables within a program...
Definition: SymbolTable.h:115
bool replace(const std::string &name, Value value)
Replace the first occurrance of a variable with a given name with a replacement value. Returns true if a replacement occurred.
Definition: SymbolTable.h:208
bool exists(const std::string &name) const
Returns true if a variable exists in this symbol table with the given name.
Definition: SymbolTable.h:59
const MapType & map() const
Access to the underlying map.
Definition: SymbolTable.h:97
#define OPENVDB_ASSERT(X)
Definition: Assert.h:41
Definition: Exceptions.h:13
SymbolTableBlocks()
Definition: SymbolTable.h:119
bool erase(const size_t index)
Erase a given scoped indexed SymbolTable from the list of held SymbolTables. Returns true if the tabl...
Definition: SymbolTable.h:134
SymbolTable< Value > * getOrInsert(const size_t index)
Get or insert and get a SymbolTable with a unique index.
Definition: SymbolTable.h:145
bool replace(const std::string &name, const T &value)
Replace a variable in this symbol table. Returns true if the variable previously existed and false if...
Definition: SymbolTable.h:83
const Value * find(const std::string &name) const
Find a variable within the program starting at the lowest level SymbolTable.
Definition: SymbolTable.h:197
Intermediate representation of supported AX values.
Intermediate representation wrapper for supported value types in AX as immutable instances.
Definition: Value.h:62
SymbolTable()
Definition: SymbolTable.h:41
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h.in:121
const SymbolTable< llvm::Value * > & globals() const
Definition: SymbolTable.h:127
A symbol table which can be used to represent a single scoped set of a programs variables. This is simply an unordered map of strings to llvm::Values.
Definition: SymbolTable.h:37
std::map< size_t, SymbolTable< Value >> MapType
Definition: SymbolTable.h:117
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h.in:218