Using PointerSet for modules in monicelli::Program.

This commit is contained in:
Stefano Sanfilippo 2015-03-08 21:37:46 +01:00
parent 04cd095e41
commit 79c4303219

View File

@ -486,21 +486,11 @@ bool operator==(const Module &a, const Module &b) {
return (a.getName() == b.getName()) && (a.getType() == b.getType()); return (a.getName() == b.getName()) && (a.getType() == b.getType());
} }
} // namespace static inline
size_t hash_value(const monicelli::Module &e) {
namespace std { return std::hash<std::string>()(e.getName()) ^ std::hash<bool>()(e.getType());
template<>
struct hash<monicelli::Module> {
size_t operator ()(const monicelli::Module &e) const noexcept {
return std::hash<std::string>()(e.getName()) ^ std::hash<bool>()(e.getType());
}
};
} }
namespace monicelli {
class Program: public Emittable { class Program: public Emittable {
public: public:
virtual bool emit(Emitter *emitter) const { virtual bool emit(Emitter *emitter) const {
@ -516,8 +506,7 @@ public:
} }
void addModule(Module *m) { void addModule(Module *m) {
modules.insert(std::move(*m)); modules.insert(m);
delete m;
} }
boost::optional<Function const&> getMain() const { boost::optional<Function const&> getMain() const {
@ -528,14 +517,14 @@ public:
return functions; return functions;
} }
std::unordered_set<Module> const& getModules() const { PointerSet<Module> const& getModules() const {
return modules; return modules;
} }
private: private:
Pointer<Function> main; Pointer<Function> main;
PointerList<Function> functions; PointerList<Function> functions;
std::unordered_set<Module> modules; PointerSet<Module> modules;
}; };