+/// LinkerTypeMap - This implements a map of types that is stable
+/// even if types are resolved/refined to other types. This is not a general
+/// purpose map, it is specific to the linker's use.
+namespace {
+class LinkerTypeMap : public AbstractTypeUser {
+ typedef DenseMap<const Type*, PATypeHolder> TheMapTy;
+ TheMapTy TheMap;
+
+ LinkerTypeMap(const LinkerTypeMap&); // DO NOT IMPLEMENT
+ void operator=(const LinkerTypeMap&); // DO NOT IMPLEMENT
+public:
+ LinkerTypeMap() {}
+ ~LinkerTypeMap() {
+ for (DenseMap<const Type*, PATypeHolder>::iterator I = TheMap.begin(),
+ E = TheMap.end(); I != E; ++I)
+ I->first->removeAbstractTypeUser(this);
+ }
+
+ /// lookup - Return the value for the specified type or null if it doesn't
+ /// exist.
+ const Type *lookup(const Type *Ty) const {
+ TheMapTy::const_iterator I = TheMap.find(Ty);
+ if (I != TheMap.end()) return I->second;
+ return 0;
+ }
+
+ /// erase - Remove the specified type, returning true if it was in the set.
+ bool erase(const Type *Ty) {
+ if (!TheMap.erase(Ty))
+ return false;
+ if (Ty->isAbstract())
+ Ty->removeAbstractTypeUser(this);
+ return true;
+ }
+
+ /// insert - This returns true if the pointer was new to the set, false if it
+ /// was already in the set.
+ bool insert(const Type *Src, const Type *Dst) {
+ if (!TheMap.insert(std::make_pair(Src, PATypeHolder(Dst))).second)
+ return false; // Already in map.
+ if (Src->isAbstract())
+ Src->addAbstractTypeUser(this);
+ return true;
+ }
+
+protected:
+ /// refineAbstractType - The callback method invoked when an abstract type is
+ /// resolved to another type. An object must override this method to update
+ /// its internal state to reference NewType instead of OldType.
+ ///
+ virtual void refineAbstractType(const DerivedType *OldTy,
+ const Type *NewTy) {
+ TheMapTy::iterator I = TheMap.find(OldTy);
+ const Type *DstTy = I->second;
+
+ TheMap.erase(I);
+ if (OldTy->isAbstract())
+ OldTy->removeAbstractTypeUser(this);
+
+ // Don't reinsert into the map if the key is concrete now.
+ if (NewTy->isAbstract())
+ insert(NewTy, DstTy);
+ }
+
+ /// The other case which AbstractTypeUsers must be aware of is when a type
+ /// makes the transition from being abstract (where it has clients on it's
+ /// AbstractTypeUsers list) to concrete (where it does not). This method
+ /// notifies ATU's when this occurs for a type.
+ virtual void typeBecameConcrete(const DerivedType *AbsTy) {
+ TheMap.erase(AbsTy);
+ AbsTy->removeAbstractTypeUser(this);
+ }
+
+ // for debugging...
+ virtual void dump() const {
+ cerr << "AbstractTypeSet!\n";
+ }
+};