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-ref.h>
11 #include <hilti/ast/node.h>
12 #include <hilti/ast/types/auto.h>
13 #include <hilti/base/logger.h>
14 
15 namespace hilti {
16 namespace expression {
17 
20 public:
21  ResolvedID(ID id, NodeRef d, Meta m = Meta()) : NodeBase(nodes(std::move(id)), m), _d(std::move(d)) {}
22 
23  const auto& id() const { return child<ID>(0); }
24  const auto& declaration() const { return _d->as<Declaration>(); }
25  const auto& declarationRef() const { return _d; }
26 
27  bool operator==(const ResolvedID& other) const {
28  return id() == other.id() && declaration() == other.declaration();
29  }
30 
32  bool isLhs() const { return ! declaration().isConstant(); }
34  bool isTemporary() const { return false; }
36  const Type& type() const;
38  bool isConstant() const;
40  auto isEqual(const Expression& other) const { return node::isEqual(this, other); }
41 
43  auto properties() const { return node::Properties{{"rid", _d.rid()}}; }
44 
45 private:
46  NodeRef _d;
47 };
48 
51 public:
52  UnresolvedID(ID id, Meta m = Meta()) : NodeBase(nodes(std::move(id), type::auto_), std::move(m)) {}
53 
54  const auto& id() const { return child<ID>(0); }
55 
56  bool operator==(const UnresolvedID& other) const { return id() == other.id(); }
57 
58  // Expression interface.
59  bool isLhs() const { return true; }
60  bool isTemporary() const { return false; }
61  const Type& type() const { return child<Type>(1); }
62  auto isConstant() const { return false; }
63  auto isEqual(const Expression& other) const { return node::isEqual(this, other); }
64 
66  auto properties() const { return node::Properties{}; }
67 };
68 
69 } // namespace expression
70 } // namespace hilti
Definition: declaration.h:53
Definition: expression.h:17
auto properties() const
Definition: id.h:43
auto isEqual(const Expression &other) const
Definition: id.h:40
Definition: meta.h:18
Definition: type.h:159
bool isTemporary() const
Definition: id.h:34
auto properties() const
Definition: id.h:66
std::map< std::string, node::detail::PropertyValue > Properties
Definition: node.h:99
const Type & type() const
Definition: id.cc:12
bool isLhs() const
Definition: id.h:32
Definition: node-ref.h:44
bool isConstant() const
Definition: id.cc:33
uint64_t rid() const
Definition: node-ref.h:60
Definition: id.h:18
Definition: node.h:358