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::declaration {
13 
15 class Type : public DeclarationBase {
16 public:
17  Type(ID id, ::hilti::Type type, Linkage linkage = Linkage::Private, Meta m = Meta())
18  : DeclarationBase({std::move(id), std::move(type), node::none}, std::move(m)), _linkage(linkage) {}
19 
20  Type(ID id, ::hilti::Type type, std::optional<AttributeSet> attrs, Linkage linkage = Linkage::Private,
21  Meta m = Meta())
22  : DeclarationBase(nodes(std::move(id), std::move(type), std::move(attrs)), std::move(m)), _linkage(linkage) {}
23 
24  const auto& type() const { return child<hilti::Type>(1); }
25  NodeRef typeRef() const { return NodeRef(children()[1]); }
26  auto attributes() const { return children()[2].tryAs<AttributeSet>(); }
27 
28  bool isOnHeap() const {
29  if ( auto x = attributes() )
30  return x->find("&on-heap").has_value();
31  else
32  return false;
33  }
34 
36  auto typeID() const { return children()[1].as<hilti::Type>().typeID(); }
37 
39  auto cxxID() const { return children()[1].as<hilti::Type>().cxxID(); }
40 
42  auto resolvedID() const { return children()[1].as<hilti::Type>().resolvedID(); }
43 
44  void setType(const ::hilti::Type& t) { children()[1] = t; }
45 
46  bool operator==(const Type& other) const { return id() == other.id() && type() == other.type(); }
47 
49  // auto& _typeNode() { return children()[1]; }
50 
52  bool isConstant() const { return true; }
54  const ID& id() const { return child<ID>(0); }
56  Linkage linkage() const { return _linkage; }
58  std::string displayName() const { return "type"; };
60  auto isEqual(const Declaration& other) const { return node::isEqual(this, other); }
61 
63  auto properties() const { return node::Properties{{"linkage", to_string(_linkage)}}; }
64 
65 private:
66  Linkage _linkage;
67 };
68 
69 } // namespace hilti::declaration
Definition: type.h:15
Definition: declaration.h:53
bool isConstant() const
Definition: type.h:52
const Node none
Definition: node.cc:14
const ID & id() const
Definition: type.h:54
auto typeID() const
Definition: type.h:36
const auto & children() const
Definition: node.h:471
auto isEqual(const Declaration &other) const
Definition: type.h:60
auto properties() const
Definition: type.h:63
Definition: meta.h:19
Definition: attribute.h:174
Definition: type.h:160
Definition: declaration.h:87
auto cxxID() const
Definition: type.h:39
auto resolvedID() const
Definition: type.h:42
std::map< std::string, node::detail::PropertyValue > Properties
Definition: node.h:97
Definition: node-ref.h:45
Definition: declaration.h:18
Linkage linkage() const
Definition: type.h:56
std::string displayName() const
Definition: type.h:58
Definition: id.h:18