Spicy
type.h
1 // Copyright (c) 2020-2021 by the Zeek Project. See LICENSE for details.
2 
3 #pragma once
4 
5 #include <string>
6 #include <utility>
7 
8 #include <hilti/ast/attribute.h>
9 #include <hilti/ast/id.h>
10 #include <hilti/ast/type.h>
11 
12 namespace hilti {
13 namespace declaration {
14 
16 class Type : public DeclarationBase {
17 public:
18  Type(ID id, ::hilti::Type type, Linkage linkage = Linkage::Private, Meta m = Meta())
19  : DeclarationBase({std::move(id), std::move(type), node::none}, std::move(m)), _linkage(linkage) {}
20 
21  Type(ID id, ::hilti::Type type, std::optional<AttributeSet> attrs, Linkage linkage = Linkage::Private,
22  Meta m = Meta())
23  : DeclarationBase(nodes(std::move(id), std::move(type), std::move(attrs)), std::move(m)), _linkage(linkage) {}
24 
25  const auto& type() const { return child<hilti::Type>(1); }
26  NodeRef typeRef() const { return NodeRef(childs()[1]); }
27  auto attributes() const { return childs()[2].tryAs<AttributeSet>(); }
28 
29  bool isOnHeap() const {
30  if ( auto x = attributes() )
31  return x->find("&on-heap").has_value();
32  else
33  return false;
34  }
35 
37  auto typeID() const { return childs()[1].as<hilti::Type>().typeID(); }
38 
40  auto cxxID() const { return childs()[1].as<hilti::Type>().cxxID(); }
41 
43  auto resolvedID() const { return childs()[1].as<hilti::Type>().resolvedID(); }
44 
45  void setType(::hilti::Type t) { childs()[1] = std::move(t); }
46 
47  bool operator==(const Type& other) const { return id() == other.id() && type() == other.type(); }
48 
50  // auto& _typeNode() { return childs()[1]; }
51 
53  bool isConstant() const { return true; }
55  const ID& id() const { return child<ID>(0); }
57  Linkage linkage() const { return _linkage; }
59  std::string displayName() const { return "type"; };
61  auto isEqual(const Declaration& other) const { return node::isEqual(this, other); }
62 
64  auto properties() const { return node::Properties{{"linkage", to_string(_linkage)}}; }
65 
66 private:
67  Linkage _linkage;
68 };
69 
70 } // namespace declaration
71 } // namespace hilti
Definition: type.h:16
Definition: declaration.h:53
bool isConstant() const
Definition: type.h:53
const Node none
Definition: node.cc:14
const ID & id() const
Definition: type.h:55
auto typeID() const
Definition: type.h:37
auto isEqual(const Declaration &other) const
Definition: type.h:61
auto properties() const
Definition: type.h:64
Definition: meta.h:18
Definition: attribute.h:145
Definition: type.h:159
Definition: declaration.h:87
auto cxxID() const
Definition: type.h:40
auto resolvedID() const
Definition: type.h:43
std::map< std::string, node::detail::PropertyValue > Properties
Definition: node.h:99
Definition: node-ref.h:44
const auto & childs() const
Definition: node.h:470
Linkage linkage() const
Definition: type.h:57
std::string displayName() const
Definition: type.h:59
Definition: id.h:18