Spicy
id.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/declaration.h>
8 #include <hilti/ast/declarations/type.h>
9 #include <hilti/ast/id.h>
10 #include <hilti/ast/node_ref.h>
11 #include <hilti/ast/type.h>
12 
13 namespace hilti {
14 namespace type {
15 
18 public:
19  ResolvedID(::hilti::ID id, NodeRef r, Meta m = Meta())
20  : TypeBase({std::move(id)}, std::move(m)), _node(std::move(std::move(r))) {
21  assert(_node && _node->isA<declaration::Type>());
22  }
23 
24  const auto& id() const { return child<::hilti::ID>(0); }
25  auto declaration() const {
26  assert(_node);
27  return _node->as<Declaration>();
28  }
29  auto type() const {
30  assert(_node);
31  return _node->as<declaration::Type>().type();
32  }
33  bool isValid() const { return static_cast<bool>(_node); }
34  const NodeRef& ref() const { return _node; }
35 
36  bool operator==(const ResolvedID& other) const { return type() == other.type(); }
37 
39  bool isEqual(const Type& other) const { return type() == type::effectiveType(other); }
41  Type effectiveType() const { return type(); }
42 
44  auto properties() const {
45  return _node ? node::Properties{{"resolved", _node.renderedRid()}} : node::Properties{{}};
46  }
47 
48 private:
49  NodeRef _node;
50 };
51 
53 class UnresolvedID : public TypeBase {
54 public:
55  UnresolvedID(::hilti::ID id, Meta m = Meta()) : TypeBase({std::move(id)}, std::move(m)) {}
56 
57  const auto& id() const { return child<::hilti::ID>(0); }
58 
59  bool operator==(const UnresolvedID& other) const { return id() == other.id(); }
60 
61  // Type interface.
62  auto isEqual(const Type& other) const { return node::isEqual(this, other); }
63 
64  // Node interface.
65  auto properties() const { return node::Properties{}; }
66 };
67 
68 } // namespace type
69 } // namespace hilti
std::string renderedRid() const
Definition: node_ref.h:68
Definition: type.h:16
Type effectiveType() const
Definition: id.h:41
bool isEqual(const Type &other) const
Definition: id.h:39
Definition: id.h:53
Definition: meta.h:18
auto properties() const
Definition: id.h:44
std::map< std::string, node::detail::PropertyValue > Properties
Definition: node.h:83
Definition: type.h:152
Definition: node_ref.h:44
Definition: id.h:17
Definition: id.h:18