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/expression.h>
9 #include <hilti/ast/id.h>
10 #include <hilti/ast/node.h>
11 #include <hilti/ast/node_ref.h>
12 #include <hilti/ast/types/unknown.h>
13 #include <hilti/base/logger.h>
14 
15 namespace hilti {
16 namespace expression {
17 
20 public:
21  ResolvedID(ID id, NodeRef r, Meta m = Meta()) : NodeBase({std::move(id)}, std::move(m)), _node(std::move(r)) {
22  assert(_node && _node->isA<Declaration>());
23  }
24 
25  const auto& id() const { return child<ID>(0); }
26  auto declaration() const {
27  assert(_node);
28  return _node->as<Declaration>();
29  }
30 
31  bool isValid() const { return static_cast<bool>(_node); }
32 
33  bool operator==(const ResolvedID& other) const {
34  return id() == other.id() && declaration() == other.declaration();
35  }
36 
38  bool isLhs() const { return ! declaration().isConstant(); }
40  bool isTemporary() const { return false; }
42  Type type() const;
44  bool isConstant() const;
46  auto isEqual(const Expression& other) const { return node::isEqual(this, other); }
47 
49  auto properties() const {
50  return _node ? node::Properties{{"resolved", _node.renderedRid()}} : node::Properties{{}};
51  }
52 
53 private:
54  NodeRef _node;
55 };
56 
59 public:
60  UnresolvedID(ID id, Meta m = Meta()) : NodeBase({std::move(id)}, std::move(m)) {}
61 
62  const auto& id() const { return child<ID>(0); }
63 
64  bool operator==(const UnresolvedID& other) const { return id() == other.id(); }
65 
66  // Expression interface.
67  bool isLhs() const { return true; }
68  bool isTemporary() const { return false; }
69  Type type() const { return type::unknown; }
70  auto isConstant() const { return false; }
71  auto isEqual(const Expression& other) const { return node::isEqual(this, other); }
72 
74  auto properties() const { return node::Properties{}; }
75 };
76 
77 } // namespace expression
78 } // namespace hilti
std::string renderedRid() const
Definition: node_ref.h:68
Definition: expression.h:16
auto properties() const
Definition: id.h:49
auto isEqual(const Expression &other) const
Definition: id.h:46
Definition: meta.h:18
bool isTemporary() const
Definition: id.h:40
auto properties() const
Definition: id.h:74
std::map< std::string, node::detail::PropertyValue > Properties
Definition: node.h:83
bool isLhs() const
Definition: id.h:38
Definition: node_ref.h:44
bool isConstant() const
Definition: id.cc:31
Type type() const
Definition: id.cc:10
Definition: id.h:18
Definition: node.h:318