Spicy
vector.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::type {
11 
12 namespace vector {
13 
15 class Iterator : public TypeBase,
22 public:
23  Iterator(Type etype, bool const_, Meta m = Meta())
24  : TypeBase(nodes(std::move(etype)), std::move(m)), _const(const_) {}
25  Iterator(Wildcard /*unused*/, bool const_ = true, Meta m = Meta())
26  : TypeBase(nodes(type::unknown), std::move(m)), _wildcard(true), _const(const_) {}
27 
29  bool isConstant() const { return _const; }
30 
32  auto isEqual(const Type& other) const { return node::isEqual(this, other); }
34  auto _isResolved(ResolvedState* rstate) const { return type::detail::isResolved(dereferencedType(), rstate); }
36  const Type& dereferencedType() const { return child<Type>(0); }
38  auto isWildcard() const { return _wildcard; }
40  auto typeParameters() const { return children(); }
42  auto properties() const { return node::Properties{{"const", _const}}; }
43 
44  bool operator==(const Iterator& other) const { return dereferencedType() == other.dereferencedType(); }
45 
46 private:
47  bool _wildcard = false;
48  bool _const = false;
49 };
50 
51 } // namespace vector
52 
54 class Vector : public TypeBase,
60 public:
61  Vector(const Type& t, const Meta& m = Meta())
62  : TypeBase(nodes(vector::Iterator(t, true, m), vector::Iterator(t, false, m)), m) {}
63  Vector(Wildcard /*unused*/, const Meta& m = Meta())
64  : TypeBase(nodes(vector::Iterator(Wildcard{}, true, m), vector::Iterator(Wildcard{}, false, m)), m),
65  _wildcard(true) {}
66 
68  auto isEqual(const Type& other) const { return node::isEqual(this, other); }
70  auto _isResolved(ResolvedState* rstate) const {
71  return type::detail::isResolved(iteratorType(true), rstate) &&
72  type::detail::isResolved(iteratorType(false), rstate);
73  }
75  const Type& elementType() const { return child<vector::Iterator>(0).dereferencedType(); }
77  const Type& iteratorType(bool const_) const { return const_ ? child<Type>(0) : child<Type>(1); }
79  auto isWildcard() const { return _wildcard; }
81  auto typeParameters() const { return children(); }
83  auto properties() const { return node::Properties{}; }
84 
85  bool operator==(const Vector& other) const { return elementType() == other.elementType(); }
86 
87 private:
88  bool _wildcard = false;
89 };
90 
91 } // namespace hilti::type
auto _isResolved(ResolvedState *rstate) const
Definition: vector.h:70
Definition: type.h:37
auto isWildcard() const
Definition: vector.h:79
Definition: vector.h:15
const auto & children() const
Definition: node.h:472
auto isEqual(const Type &other) const
Definition: vector.h:32
const Type & dereferencedType() const
Definition: vector.h:36
auto properties() const
Definition: vector.h:83
auto typeParameters() const
Definition: vector.h:40
Definition: type.h:38
Definition: meta.h:19
auto isWildcard() const
Definition: vector.h:38
const Type & elementType() const
Definition: vector.h:75
bool isConstant() const
Definition: vector.h:29
Definition: type.h:160
Definition: type.h:36
auto _isResolved(ResolvedState *rstate) const
Definition: vector.h:34
std::map< std::string, node::detail::PropertyValue > Properties
Definition: node.h:98
const Type & iteratorType(bool const_) const
Definition: vector.h:77
Definition: type.h:206
auto properties() const
Definition: vector.h:42
auto isEqual(const Type &other) const
Definition: vector.h:68
Definition: type.h:33
Definition: vector.h:54
Definition: type.h:277
auto typeParameters() const
Definition: vector.h:81
Definition: type.h:26