Spicy
tuple.h
1 // Copyright (c) 2020-2021 by the Zeek Project. See LICENSE for details.
2 
3 #pragma once
4 
5 #include <utility>
6 #include <vector>
7 
8 #include <hilti/ast/id.h>
9 #include <hilti/ast/type.h>
10 
11 namespace hilti {
12 namespace type {
13 
16 public:
17  Tuple(std::vector<Type> t, Meta m = Meta()) : TypeBase(nodes(std::move(t)), std::move(m)) {}
18  Tuple(std::vector<std::pair<ID, Type>> t, Meta m = Meta()) : TypeBase(nodes(std::move(t)), std::move(m)) {}
19  Tuple(Wildcard /*unused*/, Meta m = Meta()) : TypeBase(std::move(m)), _wildcard(true) {}
20 
21  auto types() const { return childsOfType<Type>(); }
22  std::vector<ID> ids() const;
23  auto elements() const { return util::zip2(ids(), types()); }
24  std::optional<std::pair<int, Type>> elementByID(const ID& id);
25 
26  bool operator==(const Tuple& other) const {
27  if ( _wildcard || other._wildcard )
28  return _wildcard && other._wildcard;
29 
30  return types() == other.types() && ids() == other.ids();
31  }
32 
34  auto isEqual(const Type& other) const { return node::isEqual(this, other); }
36  auto typeParameters() const { return childs(); }
38  auto isWildcard() const { return _wildcard; }
39 
41  auto properties() const { return node::Properties{{"wildcard", _wildcard}}; }
42 
43 private:
44  bool _wildcard = false;
45 };
46 
47 } // namespace type
48 } // namespace hilti
auto properties() const
Definition: tuple.h:41
auto & childs() const
Definition: node.h:445
std::list< std::pair< A, B > > zip2(const std::list< A > &lhs, const std::list< B > &rhs)
Definition: util.h:475
Definition: meta.h:18
auto isEqual(const Type &other) const
Definition: tuple.h:34
std::map< std::string, node::detail::PropertyValue > Properties
Definition: node.h:83
Definition: type.h:152
Definition: type.h:23
Definition: type.h:249
Definition: tuple.h:15
auto typeParameters() const
Definition: tuple.h:36
auto isWildcard() const
Definition: tuple.h:38
Definition: id.h:18