return 0;
}
-// Erase a specific type from the symbol table
-bool TypeSymbolTable::remove(Type *N) {
- for (iterator TI = tmap.begin(), TE = tmap.end(); TI != TE; ++TI) {
- if (TI->second == N) {
- this->remove(TI);
- return true;
- }
- }
- return false;
-}
-
// remove - Remove a type from the symbol table...
Type* TypeSymbolTable::remove(iterator Entry) {
assert(Entry != tmap.end() && "Invalid entry to remove!");
void TypeSymbolTable::insert(const std::string& Name, const Type* T) {
assert(T && "Can't insert null type into symbol table!");
- // Check to see if there is a naming conflict. If so, rename this type!
- std::string UniqueName = Name;
- if (lookup(Name))
- UniqueName = getUniqueName(Name);
-
+ if (tmap.insert(make_pair(Name, T)).second) {
+ // Type inserted fine with no conflict.
+
#if DEBUG_SYMBOL_TABLE
- dump();
- cerr << " Inserting type: " << UniqueName << ": "
- << T->getDescription() << "\n";
+ dump();
+ cerr << " Inserted type: " << Name << ": " << T->getDescription() << "\n";
+#endif
+ } else {
+ // If there is a name conflict...
+
+ // Check to see if there is a naming conflict. If so, rename this type!
+ std::string UniqueName = Name;
+ if (lookup(Name))
+ UniqueName = getUniqueName(Name);
+
+#if DEBUG_SYMBOL_TABLE
+ dump();
+ cerr << " Inserting type: " << UniqueName << ": "
+ << T->getDescription() << "\n";
#endif
- // Insert the tmap entry
- tmap.insert(make_pair(UniqueName, T));
+ // Insert the tmap entry
+ tmap.insert(make_pair(UniqueName, T));
+ }
// If we are adding an abstract type, add the symbol table to it's use list.
if (T->isAbstract()) {
}
}
-// Strip the symbol table of its names.
-bool TypeSymbolTable::strip() {
- bool RemovedSymbol = false;
- for (iterator TI = tmap.begin(); TI != tmap.end(); ) {
- remove(TI++);
- RemovedSymbol = true;
- }
-
- return RemovedSymbol;
-}
-
-/// rename - Given a value with a non-empty name, remove its existing entry
-/// from the symbol table and insert a new one for Name. This is equivalent to
-/// doing "remove(V), V->Name = Name, insert(V)", but is faster, and will not
-/// temporarily remove the symbol table plane if V is the last value in the
-/// symtab with that name (which could invalidate iterators to that plane).
-bool TypeSymbolTable::rename(Type *T, const std::string &name) {
- for (iterator TI = tmap.begin(), TE = tmap.end(); TI != TE; ++TI) {
- if (TI->second == T) {
- // Remove the old entry.
- tmap.erase(TI);
- // Add the new entry.
- this->insert(name,T);
- return true;
- }
- }
- return false;
-}
-
// This function is called when one of the types in the type plane are refined
void TypeSymbolTable::refineAbstractType(const DerivedType *OldType,
const Type *NewType) {