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::expression {
16 
19 public:
20  ResolvedID(ID id, NodeRef d, Meta m = Meta()) : NodeBase(nodes(std::move(id)), std::move(m)), _d(std::move(d)) {}
21 
22  const auto& id() const { return child<ID>(0); }
23  const auto& declaration() const { return _d->as<Declaration>(); }
24  const auto& declarationRef() const { return _d; }
25 
26  bool operator==(const ResolvedID& other) const {
27  return id() == other.id() && declaration() == other.declaration();
28  }
29 
31  bool isLhs() const { return ! declaration().isConstant(); }
33  bool isTemporary() const { return false; }
35  const Type& type() const;
37  bool isConstant() const;
39  auto isEqual(const Expression& other) const { return node::isEqual(this, other); }
40 
42  auto properties() const { return node::Properties{{"rid", _d.rid()}}; }
43 
44 private:
45  NodeRef _d;
46 };
47 
50 public:
51  UnresolvedID(ID id, Meta m = Meta()) : NodeBase(nodes(std::move(id), type::auto_), std::move(m)) {}
52 
53  const auto& id() const { return child<ID>(0); }
54 
55  bool operator==(const UnresolvedID& other) const { return id() == other.id(); }
56 
57  // Expression interface.
58  bool isLhs() const { return true; }
59  bool isTemporary() const { return false; }
60  const Type& type() const { return child<Type>(1); }
61  auto isConstant() const { return false; }
62  auto isEqual(const Expression& other) const { return node::isEqual(this, other); }
63 
65  auto properties() const { return node::Properties{}; }
66 };
67 
68 } // namespace hilti::expression
Definition: declaration.h:53
Definition: expression.h:18
auto properties() const
Definition: id.h:42
auto isEqual(const Expression &other) const
Definition: id.h:39
Definition: meta.h:19
Definition: type.h:160
bool isTemporary() const
Definition: id.h:33
auto properties() const
Definition: id.h:65
std::map< std::string, node::detail::PropertyValue > Properties
Definition: node.h:97
const Type & type() const
Definition: id.cc:12
bool isLhs() const
Definition: id.h:31
Definition: node-ref.h:45
bool isConstant() const
Definition: id.cc:33
uint64_t rid() const
Definition: node-ref.h:61
Definition: id.h:18
Definition: node.h:359
Definition: expression.h:21