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