Spicy
declaration.h
1 // Copyright (c) 2020-2021 by the Zeek Project. See LICENSE for details.
2 
3 #pragma once
4 
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, "method"}, {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 
50 #include <hilti/autogen/__declaration.h>
51 
53 inline Node to_node(Declaration t) { return Node(std::move(t)); }
54 
56 inline std::ostream& operator<<(std::ostream& out, Declaration d) { return out << to_node(std::move(d)); }
57 
58 inline bool operator==(const Declaration& x, const Declaration& y) {
59  if ( &x == &y )
60  return true;
61 
62  assert(x.isEqual(y) == y.isEqual(x)); // Expected to be symmetric.
63  return x.isEqual(y);
64 }
65 
66 inline bool operator!=(const Declaration& d1, const Declaration& d2) { return ! (d1 == d2); }
67 
68 } // namespace detail
69 } // namespace declaration
70 
71 using Declaration = declaration::detail::Declaration;
72 using declaration::detail::to_node;
73 
75 template<typename T, typename std::enable_if_t<std::is_base_of<trait::isDeclaration, T>::value>* = nullptr>
76 inline Node to_node(T t) {
77  return Node(Declaration(std::move(t)));
78 }
79 
80 } // namespace hilti
Definition: util.h:637
Definition: node.h:97
Definition: declaration.h:15
Definition: node.h:19