00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 #ifndef COMMA_BASIC_IDENTIFIERPOOL_HDR_GUARD
00010 #define COMMA_BASIC_IDENTIFIERPOOL_HDR_GUARD
00011 
00012 #include "comma/basic/IdentifierInfo.h"
00013 #include "llvm/ADT/StringMap.h"
00014 
00015 namespace comma {
00016 
00026 class IdentifierPool {
00027 
00028     typedef llvm::StringMap<IdentifierInfo> PoolType;
00029     PoolType pool;
00030 
00031 public:
00044     IdentifierInfo &getIdentifierInfo(const char *name, size_t len) {
00045         return pool.GetOrCreateValue(name, name + len).getValue();
00046     }
00047 
00055     IdentifierInfo &getIdentifierInfo(const char *name) {
00056         return pool.GetOrCreateValue(name, name + strlen(name)).getValue();
00057     }
00058 
00065     IdentifierInfo &getIdentifierInfo(const std::string& name) {
00066         
00067         
00068         const char *rep = &name[0];
00069         return getIdentifierInfo(rep, name.size());
00070     }
00071 
00072     typedef PoolType::const_iterator iterator;
00073 
00078     iterator begin() const { return pool.begin(); }
00079 
00081     iterator end()   const { return pool.end(); }
00082 
00084     unsigned size() const { return pool.size(); }
00085 };
00086 
00087 } 
00088 
00089 #endif