Spicy
set.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/type.h>
8 #include <hilti/ast/types/unknown.h>
9 
10 namespace hilti {
11 namespace type {
12 
13 namespace set {
14 
16 class Iterator : public TypeBase,
23 public:
24  Iterator(Type ctype, bool const_, Meta m = Meta()) : TypeBase({std::move(ctype)}, std::move(m)), _const(const_) {}
25  Iterator(Wildcard /*unused*/, Meta m = Meta()) : TypeBase({node::none}, std::move(m)), _wildcard(true) {}
26 
28  Type containerType() const { return _wildcard ? type::unknown : type::effectiveType(child<Type>(0)); }
29 
31  bool isConstant() const { return _const; }
32 
34  auto isEqual(const Type& other) const { return node::isEqual(this, other); }
36  Type dereferencedType() const {
37  return (_wildcard || containerType().isWildcard()) ? type::unknown : containerType().elementType();
38  }
40  auto isWildcard() const { return _wildcard; }
42  auto typeParameters() const { return childs(); }
44  auto properties() const { return node::Properties{{"const", _const}}; }
45 
46  bool operator==(const Iterator& other) const { return dereferencedType() == other.dereferencedType(); }
47 
48 private:
49  bool _wildcard = false;
50  bool _const = false;
51 };
52 
53 } // namespace set
54 
56 class Set : public TypeBase,
62 public:
63  Set(Type t, Meta m = Meta()) : TypeBase({std::move(t)}, std::move(m)) {}
64  Set(Wildcard /*unused*/, Meta m = Meta()) : TypeBase({node::none}, std::move(m)), _wildcard(true) {}
65 
67  auto isEqual(const Type& other) const { return node::isEqual(this, other); }
69  Type elementType() const { return _wildcard ? type::unknown : type::effectiveType(child<Type>(0)); }
71  Type iteratorType(bool const_) const { return set::Iterator(*this, const_, meta()); }
73  auto isWildcard() const { return _wildcard; }
75  auto typeParameters() const { return childs(); }
77  auto properties() const { return node::Properties{}; }
78 
79  bool operator==(const Set& other) const { return elementType() == other.elementType(); }
80 
81 private:
82  bool _wildcard = false;
83 };
84 
85 } // namespace type
86 } // namespace hilti
auto isWildcard() const
Definition: set.h:40
auto & childs() const
Definition: node.h:445
auto isEqual(const Type &other) const
Definition: set.h:34
const Node none
Definition: node.cc:12
Definition: type.h:26
Type elementType() const
Definition: set.h:69
Definition: set.h:16
auto typeParameters() const
Definition: set.h:75
auto properties() const
Definition: set.h:77
Definition: type.h:27
Definition: meta.h:18
auto isEqual(const Type &other) const
Definition: set.h:67
Type dereferencedType() const
Definition: set.h:36
auto typeParameters() const
Definition: set.h:42
Definition: set.h:56
Definition: type.h:25
std::map< std::string, node::detail::PropertyValue > Properties
Definition: node.h:83
Definition: type.h:152
Definition: type.h:23
Definition: type.h:249
Type iteratorType(bool const_) const
Definition: set.h:71
auto & meta() const
Definition: node.h:449
bool isConstant() const
Definition: set.h:31
Type containerType() const
Definition: set.h:28
auto isWildcard() const
Definition: set.h:73
auto properties() const
Definition: set.h:44