Spicy
reference.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/ctor.h>
8 #include <hilti/ast/ctors/null.h>
9 #include <hilti/ast/expressions/ctor.h>
10 #include <hilti/ast/types/reference.h>
11 
12 namespace hilti {
13 namespace ctor {
14 
17 public:
19  StrongReference(Type t, Meta m = Meta()) : NodeBase({std::move(t)}, std::move(m)) {}
20 
21  Type dereferencedType() const { return type::effectiveType(child<Type>(0)); }
22 
23  bool operator==(const StrongReference& other) const { return dereferencedType() == other.dereferencedType(); }
24 
26  Type type() const { return type::StrongReference(dereferencedType(), meta()); }
27 
29  bool isConstant() const { return true; }
31  bool isLhs() const { return false; }
33  auto isTemporary() const { return true; }
34 
36  auto isEqual(const Ctor& other) const { return node::isEqual(this, other); }
37 
39  auto properties() const { return node::Properties{}; }
40 };
41 
44 public:
46  WeakReference(Type t, Meta m = Meta()) : NodeBase({std::move(t)}, std::move(m)) {}
47 
48  Type dereferencedType() const { return type::effectiveType(child<Type>(0)); }
49 
50  bool operator==(const WeakReference& other) const { return dereferencedType() == other.dereferencedType(); }
51 
53  Type type() const { return type::WeakReference(dereferencedType(), meta()); }
54 
56  bool isConstant() const { return true; }
58  bool isLhs() const { return false; }
60  auto isTemporary() const { return true; }
61 
63  auto isEqual(const Ctor& other) const { return node::isEqual(this, other); }
64 
66  auto properties() const { return node::Properties{}; }
67 };
68 
71 public:
73  ValueReference(Expression e, Meta m = Meta()) : NodeBase({std::move(e)}, std::move(m)) {}
74 
75  const Expression& expression() const { return child<Expression>(0); }
76  Type dereferencedType() const { return child<Expression>(0).type(); }
77 
78  bool operator==(const ValueReference& other) const { return dereferencedType() == other.dereferencedType(); }
79 
81  Type type() const { return type::ValueReference(dereferencedType(), meta()); }
83  bool isConstant() const { return true; }
85  bool isLhs() const { return false; }
87  auto isTemporary() const { return true; }
88 
90  auto isEqual(const Ctor& other) const { return node::isEqual(this, other); }
91 
93  auto properties() const { return node::Properties{}; }
94 };
95 
96 } // namespace ctor
97 } // namespace hilti
Definition: reference.h:16
WeakReference(Type t, Meta m=Meta())
Definition: reference.h:46
Type type() const
Definition: reference.h:53
StrongReference(Type t, Meta m=Meta())
Definition: reference.h:19
bool isConstant() const
Definition: reference.h:29
auto properties() const
Definition: reference.h:93
Definition: reference.h:16
auto isEqual(const Ctor &other) const
Definition: reference.h:90
auto properties() const
Definition: reference.h:66
Definition: meta.h:18
auto isTemporary() const
Definition: reference.h:60
auto isEqual(const Ctor &other) const
Definition: reference.h:63
bool isConstant() const
Definition: reference.h:83
Definition: reference.h:86
auto isTemporary() const
Definition: reference.h:33
bool isLhs() const
Definition: reference.h:31
auto isEqual(const Ctor &other) const
Definition: reference.h:36
std::map< std::string, node::detail::PropertyValue > Properties
Definition: node.h:83
ValueReference(Expression e, Meta m=Meta())
Definition: reference.h:73
auto isTemporary() const
Definition: reference.h:87
auto properties() const
Definition: reference.h:39
Definition: ctor.h:15
bool isLhs() const
Definition: reference.h:58
bool isLhs() const
Definition: reference.h:85
bool isConstant() const
Definition: reference.h:56
auto & meta() const
Definition: node.h:449
Definition: reference.h:53
Definition: reference.h:70
Definition: reference.h:43
Type type() const
Definition: reference.h:81
Definition: node.h:318
Type type() const
Definition: reference.h:26