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