llvm.org GIT mirror llvm / 9c94042
Use unique_ptr for the result of Registry entries. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@206248 91177308-0d34-0410-b5e6-96231b3b80d8 David Blaikie 6 years ago
3 changed file(s) with 15 addition(s) and 14 deletion(s). Raw diff Collapse all Expand all
1313 #ifndef LLVM_SUPPORT_REGISTRY_H
1414 #define LLVM_SUPPORT_REGISTRY_H
1515
16 #include "llvm/ADT/STLExtras.h"
1617 #include "llvm/Support/Compiler.h"
18
19 #include
1720
1821 namespace llvm {
1922 /// A simple registry entry which provides only a name, description, and
2124 template
2225 class SimpleRegistryEntry {
2326 const char *Name, *Desc;
24 T *(*Ctor)();
25
26 public:
27 SimpleRegistryEntry(const char *N, const char *D, T *(*C)())
27 std::unique_ptr (*Ctor)();
28
29 public:
30 SimpleRegistryEntry(const char *N, const char *D, std::unique_ptr (*C)())
2831 : Name(N), Desc(D), Ctor(C)
2932 {}
3033
3134 const char *getName() const { return Name; }
3235 const char *getDesc() const { return Desc; }
33 T *instantiate() const { return Ctor(); }
36 std::unique_ptr instantiate() const { return Ctor(); }
3437 };
3538
3639
194197 entry Entry;
195198 node Node;
196199
197 static T *CtorFn() { return new V(); }
200 static std::unique_ptr CtorFn() { return make_unique(); }
198201
199202 public:
200203 Add(const char *Name, const char *Desc)
6161
6262 char AsmPrinter::ID = 0;
6363
64 typedef DenseMapGCMetadataPrinter*> gcp_map_type;
64 typedef DenseMap std::unique_ptr> gcp_map_type;
6565 static gcp_map_type &getGCMap(void *&P) {
6666 if (P == 0)
6767 P = new gcp_map_type();
113113 if (GCMetadataPrinters != 0) {
114114 gcp_map_type &GCMap = getGCMap(GCMetadataPrinters);
115115
116 for (gcp_map_type::iterator I = GCMap.begin(), E = GCMap.end(); I != E; ++I)
117 delete I->second;
118116 delete &GCMap;
119117 GCMetadataPrinters = 0;
120118 }
22372235 gcp_map_type &GCMap = getGCMap(GCMetadataPrinters);
22382236 gcp_map_type::iterator GCPI = GCMap.find(&S);
22392237 if (GCPI != GCMap.end())
2240 return GCPI->second;
2238 return GCPI->second.get();
22412239
22422240 const char *Name = S.getName().c_str();
22432241
22452243 I = GCMetadataPrinterRegistry::begin(),
22462244 E = GCMetadataPrinterRegistry::end(); I != E; ++I)
22472245 if (strcmp(Name, I->getName()) == 0) {
2248 GCMetadataPrinter *GMP = I->instantiate();
2246 std::unique_ptr GMP = I->instantiate();
22492247 GMP->S = &S;
2250 GCMap.insert(std::make_pair(&S, GMP));
2251 return GMP;
2248 auto IterBool = GCMap.insert(std::make_pair(&S, std::move(GMP)));
2249 return IterBool.first->second.get();
22522250 }
22532251
22542252 report_fatal_error("no GCMetadataPrinter registered for GC: " + Twine(Name));
6969 for (GCRegistry::iterator I = GCRegistry::begin(),
7070 E = GCRegistry::end(); I != E; ++I) {
7171 if (Name == I->getName()) {
72 std::unique_ptr S(I->instantiate());
72 std::unique_ptr S = I->instantiate();
7373 S->M = M;
7474 S->Name = Name;
7575 StrategyMap.GetOrCreateValue(Name).setValue(S.get());