Spicy
enum.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/ctor.h>
8 #include <hilti/ast/declarations/type.h>
9 #include <hilti/ast/types/enum.h>
10 
11 namespace hilti {
12 
13 namespace ctor {
14 
16 class Enum : public NodeBase, public hilti::trait::isCtor {
17 public:
18  Enum(type::enum_::Label v, type::Enum t, Meta m = Meta()) : NodeBase({std::move(v), std::move(t)}, std::move(m)) {}
20  : NodeBase({std::move(v), node::none}, std::move(m)), _type_decl(std::move(td)) {}
21 
22  const auto& value() const { return childs()[0].as<type::enum_::Label>(); }
23 
24  bool operator==(const Enum& other) const { return value() == other.value(); }
25 
27  auto type() const {
28  return type::effectiveType(_type_decl ? type::effectiveType((*_type_decl)->as<declaration::Type>().type()) :
29  childs()[1].as<type::Enum>());
30  }
32  bool isConstant() const { return true; }
34  auto isLhs() const { return false; }
36  auto isTemporary() const { return true; }
38  auto isEqual(const Ctor& other) const { return node::isEqual(this, other); }
39 
41  auto properties() const { return node::Properties{}; }
42 
43 private:
44  std::optional<NodeRef> _type_decl;
45 };
46 
47 } // namespace ctor
48 } // namespace hilti
Definition: enum.h:16
auto & childs() const
Definition: node.h:445
Definition: type.h:16
auto properties() const
Definition: enum.h:41
const Node none
Definition: node.cc:12
auto type() const
Definition: enum.h:27
auto isTemporary() const
Definition: enum.h:36
auto isEqual(const Ctor &other) const
Definition: enum.h:38
Definition: meta.h:18
auto isLhs() const
Definition: enum.h:34
std::map< std::string, node::detail::PropertyValue > Properties
Definition: node.h:83
Definition: enum.h:40
Definition: ctor.h:15
Definition: node_ref.h:44
bool isConstant() const
Definition: enum.h:32
Definition: enum.h:17
Definition: node.h:318