Spicy
set.h
1 // Copyright (c) 2020-2021 by the Zeek Project. See LICENSE for details.
2 
3 #pragma once
4 
5 #include <hilti/ast/operators/common.h>
6 #include <hilti/ast/types/bool.h>
7 #include <hilti/ast/types/integer.h>
8 #include <hilti/ast/types/set.h>
9 #include <hilti/ast/types/void.h>
10 #include <hilti/base/util.h>
11 
12 namespace hilti::operator_ {
13 
14 STANDARD_OPERATOR_1(set::iterator, Deref, operator_::dereferencedType(0),
15  type::constant(type::set::Iterator(type::Wildcard())),
16  "Returns the set element that the iterator refers to.");
17 STANDARD_OPERATOR_1(set::iterator, IncrPostfix, operator_::sameTypeAs(0, "iterator<set<*>>"),
18  type::set::Iterator(type::Wildcard()),
19  "Advances the iterator by one set element, returning the previous position.");
20 STANDARD_OPERATOR_1(set::iterator, IncrPrefix, operator_::sameTypeAs(0, "iterator<set<*>>"),
21  type::set::Iterator(type::Wildcard()),
22  "Advances the iterator by one set element, returning the new position.");
23 STANDARD_OPERATOR_2(set::iterator, Equal, type::Bool(), type::constant(type::set::Iterator(type::Wildcard())),
24  operator_::sameTypeAs(0, "iterator<set<*>>"),
25  "Returns true if two sets iterators refer to the same location.");
26 STANDARD_OPERATOR_2(set::iterator, Unequal, type::Bool(), type::constant(type::set::Iterator(type::Wildcard())),
27  operator_::sameTypeAs(0, "iterator<set<*>>"),
28  "Returns true if two sets iterators refer to different locations.");
29 
30 STANDARD_OPERATOR_1(set, Size, type::UnsignedInteger(64), type::constant(type::Set(type::Wildcard())),
31  "Returns the number of elements a set contains.");
32 STANDARD_OPERATOR_2(set, Equal, type::Bool(), type::constant(type::Set(type::Wildcard())),
33  operator_::sameTypeAs(0, "set<*>"), "Compares two sets element-wise.");
34 STANDARD_OPERATOR_2(set, Unequal, type::Bool(), type::constant(type::Set(type::Wildcard())),
35  operator_::sameTypeAs(0, "set<*>"), "Compares two sets element-wise.");
36 STANDARD_OPERATOR_2(set, In, type::Bool(), type::Any(), type::constant(type::Set(type::Wildcard())),
37  "Returns true if an element is part of the set.");
38 STANDARD_OPERATOR_2(set, Add, type::void_, type::Set(type::Wildcard()), operator_::constantElementType(0, "element"),
39  "Adds an element to the set.")
40 STANDARD_OPERATOR_2(set, Delete, type::void_, type::Set(type::Wildcard()), operator_::constantElementType(0, "element"),
41  "Removes an element from the set.")
42 
43 BEGIN_METHOD(set, Clear)
44  const auto& signature() const {
45  static auto _signature =
46  Signature{.self = type::Set(type::Wildcard()), .result = type::void_, .id = "clear", .args = {}, .doc = R"(
47 Removes all elements from the set.
48 )"};
49  return _signature;
50  }
51 END_METHOD
52 
53 } // namespace hilti::operator_
Definition: operator-registry.h:15