7 #include <unordered_set>
11 #include <hilti/rt/util.h>
13 #include <hilti/ast/location.h>
20 struct std::hash<hilti::Meta> {
36 setLocation(std::move(location));
42 Meta(
const Meta&) =
default;
43 Meta(Meta&&) =
default;
45 const Comments& comments()
const {
return _comments; }
46 const Location& location()
const {
48 return _location ? *_location :
null;
51 void setLocation(Location l) { _location = std::move(l); }
52 void setComments(
Comments c) { _comments = std::move(c); }
54 Meta mergeLocation(
const Location& l)
const {
return Meta(location().merge(l), _comments); }
60 explicit operator bool()
const {
return _location || _comments.size(); }
62 Meta& operator=(
const Meta&) =
default;
65 friend bool operator==(
const Meta& a,
const Meta& b) {
66 return a._location == b._location && a._comments == b._comments;
69 friend bool operator!=(
const Meta& a,
const Meta& b) {
return ! (a == b); }
77 static const Meta*
get(
Meta m) {
return &*_cache.emplace(std::move(m)).first; }
80 std::optional<Location> _location;
83 static std::unordered_set<Meta> _cache;
88 inline size_t std::hash<hilti::Meta>::operator()(
const hilti::Meta& meta)
const {
90 for (
const auto& c : meta.comments() )
91 h = hilti::rt::hashCombine(h, std::hash<std::string>()(c));
93 return hilti::rt::hashCombine(h, std::hash<std::optional<hilti::Location>>()(meta.location()));
Definition: location.h:17