Spicy
list.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 list {
14 
16 class Iterator : public TypeBase,
23 public:
24  Iterator(Type ctype, Meta m = Meta()) : TypeBase({std::move(ctype)}, std::move(m)) {}
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  auto isEqual(const Type& other) const { return node::isEqual(this, other); }
33  Type dereferencedType() const {
34  return (_wildcard || containerType().isWildcard()) ? type::unknown : containerType().elementType();
35  }
37  auto isWildcard() const { return _wildcard; }
39  auto typeParameters() const { return childs(); }
41  auto properties() const { return node::Properties{}; }
42 
43  bool operator==(const Iterator& other) const { return dereferencedType() == other.dereferencedType(); }
44 
45 private:
46  bool _wildcard = false;
47 };
48 
49 } // namespace list
50 
52 class List : public TypeBase,
58 public:
59  List(Type t, Meta m = Meta()) : TypeBase({std::move(t)}, std::move(m)) {}
60  List(Wildcard /*unused*/, Meta m = Meta()) : TypeBase({node::none}, std::move(m)), _wildcard(true) {}
61 
63  auto isEqual(const Type& other) const { return node::isEqual(this, other); }
65  Type elementType() const { return _wildcard ? type::unknown : type::effectiveType(child<Type>(0)); }
67  Type iteratorType(bool /* const_ */) const { return list::Iterator(*this, meta()); }
69  auto isWildcard() const { return _wildcard; }
71  auto typeParameters() const { return childs(); }
73  auto properties() const { return node::Properties{}; }
74 
75  bool operator==(const List& other) const { return elementType() == other.elementType(); }
76 
77 private:
78  bool _wildcard = false;
79 };
80 
81 } // namespace type
82 } // namespace hilti
auto & childs() const
Definition: node.h:445
Type dereferencedType() const
Definition: list.h:33
auto isEqual(const Type &other) const
Definition: list.h:63
const Node none
Definition: node.cc:12
Definition: type.h:26
auto isWildcard() const
Definition: list.h:37
Type iteratorType(bool) const
Definition: list.h:67
auto properties() const
Definition: list.h:41
Definition: type.h:27
auto isWildcard() const
Definition: list.h:69
Definition: meta.h:18
auto properties() const
Definition: list.h:73
Definition: list.h:52
Definition: list.h:16
auto isEqual(const Type &other) const
Definition: list.h:31
Definition: type.h:25
std::map< std::string, node::detail::PropertyValue > Properties
Definition: node.h:83
auto typeParameters() const
Definition: list.h:71
Definition: type.h:152
Type elementType() const
Definition: list.h:65
Definition: type.h:23
Definition: type.h:249
Type containerType() const
Definition: list.h:28
auto typeParameters() const
Definition: list.h:39
auto & meta() const
Definition: node.h:449