Spicy
declaration.h
1 
2 #pragma once
3 
4 #include <optional>
5 #include <string>
6 #include <utility>
7 
8 #include <hilti/ast/id.h>
9 #include <hilti/ast/node.h>
10 #include <hilti/base/type_erase.h>
11 
12 namespace hilti {
13 
14 namespace trait {
16 class isDeclaration : public isNode {};
17 } // namespace trait
18 
19 namespace declaration {
20 
22 enum class Linkage {
23  Init,
24  PreInit,
25  Struct,
26  Private,
27  Public,
28 };
29 
30 namespace detail {
31 constexpr util::enum_::Value<Linkage> linkages[] = {
32  {Linkage::Struct, "struct"}, {Linkage::Public, "public"}, {Linkage::Private, "private"},
33  {Linkage::Init, "init"}, {Linkage::PreInit, "preinit"},
34 };
35 } // namespace detail
36 
38 constexpr auto to_string(Linkage f) { return util::enum_::to_string(f, detail::linkages); }
39 
40 namespace linkage {
46 constexpr auto from_string(const std::string_view& s) { return util::enum_::from_string<Linkage>(s, detail::linkages); }
47 } // namespace linkage
48 
49 namespace detail {
50 #include <hilti/autogen/__declaration.h>
51 }
52 } // namespace declaration
53 
54 class Declaration : public declaration::detail::Declaration {
55 public:
56  using declaration::detail::Declaration::Declaration;
57 };
58 
60 inline Node to_node(Declaration t) { return Node(std::move(t)); }
61 
63 inline std::ostream& operator<<(std::ostream& out, Declaration d) { return out << to_node(std::move(d)); }
64 
65 inline bool operator==(const Declaration& x, const Declaration& y) {
66  if ( &x == &y )
67  return true;
68 
69  assert(x.isEqual(y) == y.isEqual(x)); // Expected to be symmetric.
70  return x.isEqual(y);
71 }
72 
73 inline bool operator!=(const Declaration& d1, const Declaration& d2) { return ! (d1 == d2); }
74 
75 namespace declaration {
77 template<typename T, typename std::enable_if_t<std::is_base_of<trait::isDeclaration, T>::value>* = nullptr>
78 inline Node to_node(T t) {
79  return Node(Declaration(std::move(t)));
80 }
81 } // namespace declaration
82 
89 public:
90  using NodeBase::NodeBase;
91 
93  const ID& canonicalID() const { return _id; }
95  void setCanonicalID(ID id) { _id = std::move(id); }
96 
97 private:
98  ID _id;
99 };
100 
101 } // namespace hilti
Definition: util.h:596
Definition: declaration.h:54
const ID & canonicalID() const
Definition: declaration.h:93
Definition: node.h:491
Definition: declaration.h:88
void setCanonicalID(ID id)
Definition: declaration.h:95
Definition: node.h:112
Definition: declaration.h:16
Definition: node.h:21
Definition: id.h:18
Definition: node.h:360