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 {
13 namespace operator_ {
14 
15 STANDARD_OPERATOR_1(set::iterator, Deref, operator_::dereferencedType(0),
16  type::constant(type::set::Iterator(type::Wildcard())),
17  "Returns the set element that the iterator refers to.");
18 STANDARD_OPERATOR_1(set::iterator, IncrPostfix, operator_::sameTypeAs(0, "iterator<set<*>>"),
19  type::set::Iterator(type::Wildcard()),
20  "Advances the iterator by one set element, returning the previous position.");
21 STANDARD_OPERATOR_1(set::iterator, IncrPrefix, operator_::sameTypeAs(0, "iterator<set<*>>"),
22  type::set::Iterator(type::Wildcard()),
23  "Advances the iterator by one set element, returning the new position.");
24 STANDARD_OPERATOR_2(set::iterator, Equal, type::Bool(), type::constant(type::set::Iterator(type::Wildcard())),
25  operator_::sameTypeAs(0, "iterator<set<*>>"),
26  "Returns true if two sets iterators refer to the same location.");
27 STANDARD_OPERATOR_2(set::iterator, Unequal, type::Bool(), type::constant(type::set::Iterator(type::Wildcard())),
28  operator_::sameTypeAs(0, "iterator<set<*>>"),
29  "Returns true if two sets iterators refer to different locations.");
30 
31 STANDARD_OPERATOR_1(set, Size, type::UnsignedInteger(64), type::constant(type::Set(type::Wildcard())),
32  "Returns the number of elements a set contains.");
33 STANDARD_OPERATOR_2(set, Equal, type::Bool(), type::constant(type::Set(type::Wildcard())),
34  operator_::sameTypeAs(0, "set<*>"), "Compares two sets element-wise.");
35 STANDARD_OPERATOR_2(set, Unequal, type::Bool(), type::constant(type::Set(type::Wildcard())),
36  operator_::sameTypeAs(0, "set<*>"), "Compares two sets element-wise.");
37 STANDARD_OPERATOR_2(set, In, type::Bool(), type::Any(), type::constant(type::Set(type::Wildcard())),
38  "Returns true if an element is part of the set.");
39 STANDARD_OPERATOR_2(set, Add, type::void_, type::Set(type::Wildcard()), operator_::constantElementType(0, "element"),
40  "Adds an element to the set.")
41 STANDARD_OPERATOR_2(set, Delete, type::void_, type::Set(type::Wildcard()), operator_::constantElementType(0, "element"),
42  "Removes an element from the set.")
43 
44 BEGIN_METHOD(set, Clear)
45  auto signature() const {
46  return Signature{.self = type::Set(type::Wildcard()),
47  .result = type::void_,
48  .id = "clear",
49  .args = {},
50  .doc = R"(
51 Removes all elements from the set.
52 )"};
53  }
54 END_METHOD
55 
56 } // namespace operator_
57 
58 } // namespace hilti