Spicy
meta.h
1 // Copyright (c) 2020-2021 by the Zeek Project. See LICENSE for details.
2 
3 #pragma once
4 
5 #include <set>
6 #include <string>
7 #include <utility>
8 #include <vector>
9 
10 #include <hilti/ast/location.h>
11 
12 namespace hilti {
13 
18 class Meta {
19 public:
21  using Comments = std::vector<std::string>;
22 
23  Meta(Location location, Comments comments = {}) : _comments(std::move(comments)) {
24  setLocation(std::move(location));
25  }
26 
28  Meta(Comments comments = {}) : _comments(std::move(comments)) {}
29 
30  const Comments& comments() const { return _comments; }
31  const Location& location() const {
32  static Location null;
33  return _location ? *_location : null;
34  }
35 
36  void setLocation(Location l) { _location = &*_cache()->insert(std::move(l)).first; }
37  void setComments(Comments c) { _comments = std::move(c); }
38 
43  explicit operator bool() const { return _location || _comments.size(); }
44 
45 private:
46  std::set<Location>* _cache();
47 
48  const Location* _location = nullptr;
49  Comments _comments;
50 };
51 
52 } // namespace hilti
std::vector< std::string > Comments
Definition: meta.h:21
Meta(Comments comments={})
Definition: meta.h:28
Definition: meta.h:18
Definition: location.h:17
Definition: location.h:86