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 {
11 namespace type {
12 
13 namespace vector {
14 
16 class Iterator : public TypeBase,
23 public:
24  Iterator(Type etype, bool const_, Meta m = Meta())
25  : TypeBase(nodes(std::move(etype)), std::move(m)), _const(const_) {}
26  Iterator(Wildcard /*unused*/, bool const_ = true, Meta m = Meta())
27  : TypeBase(nodes(type::unknown), std::move(m)), _wildcard(true), _const(const_) {}
28 
30  bool isConstant() const { return _const; }
31 
33  auto isEqual(const Type& other) const { return node::isEqual(this, other); }
35  auto _isResolved(ResolvedState* rstate) const { return type::detail::isResolved(dereferencedType(), rstate); }
37  const Type& dereferencedType() const { return child<Type>(0); }
39  auto isWildcard() const { return _wildcard; }
41  auto typeParameters() const { return childs(); }
43  auto properties() const { return node::Properties{{"const", _const}}; }
44 
45  bool operator==(const Iterator& other) const { return dereferencedType() == other.dereferencedType(); }
46 
47 private:
48  bool _wildcard = false;
49  bool _const = false;
50 };
51 
52 } // namespace vector
53 
55 class Vector : public TypeBase,
61 public:
62  Vector(Type t, Meta m = Meta()) : TypeBase(nodes(vector::Iterator(t, true, m), vector::Iterator(t, false, m)), m) {}
63  Vector(Wildcard /*unused*/, 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 childs(); }
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 type
92 } // namespace hilti
auto _isResolved(ResolvedState *rstate) const
Definition: vector.h:70
Definition: type.h:36
auto isWildcard() const
Definition: vector.h:79
Definition: vector.h:16
auto isEqual(const Type &other) const
Definition: vector.h:33
const Type & dereferencedType() const
Definition: vector.h:37
auto properties() const
Definition: vector.h:83
auto typeParameters() const
Definition: vector.h:41
Definition: type.h:37
Definition: meta.h:18
auto isWildcard() const
Definition: vector.h:39
const Type & elementType() const
Definition: vector.h:75
bool isConstant() const
Definition: vector.h:30
Definition: type.h:159
Definition: type.h:35
auto _isResolved(ResolvedState *rstate) const
Definition: vector.h:35
std::map< std::string, node::detail::PropertyValue > Properties
Definition: node.h:99
const Type & iteratorType(bool const_) const
Definition: vector.h:77
Definition: type.h:198
auto properties() const
Definition: vector.h:43
auto isEqual(const Type &other) const
Definition: vector.h:68
Definition: type.h:33
Definition: vector.h:55
Definition: type.h:269
const auto & childs() const
Definition: node.h:470
auto typeParameters() const
Definition: vector.h:81