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/vector.h> 9 #include <hilti/ast/types/void.h> 10 #include <hilti/base/util.h> 14 STANDARD_OPERATOR_1(vector::iterator, Deref, operator_::dereferencedType(0),
15 type::constant(type::vector::Iterator(type::Wildcard())),
16 "Returns the vector element that the iterator refers to.");
17 STANDARD_OPERATOR_1(vector::iterator, IncrPostfix, operator_::sameTypeAs(0,
"iterator<vector<*>>"),
18 type::vector::Iterator(type::Wildcard()),
19 "Advances the iterator by one vector element, returning the previous position.");
20 STANDARD_OPERATOR_1(vector::iterator, IncrPrefix, operator_::sameTypeAs(0,
"iterator<vector<*>>"),
21 type::vector::Iterator(type::Wildcard()),
22 "Advances the iterator by one vector element, returning the new position.");
23 STANDARD_OPERATOR_2(vector::iterator, Equal, type::Bool(), type::constant(type::vector::Iterator(type::Wildcard())),
24 operator_::sameTypeAs(0,
"iterator<vector<*>>"),
25 "Returns true if two vector iterators refer to the same location.");
26 STANDARD_OPERATOR_2(vector::iterator, Unequal, type::Bool(), type::constant(type::vector::Iterator(type::Wildcard())),
27 operator_::sameTypeAs(0,
"iterator<vector<*>>"),
28 "Returns true if two vector iterators refer to different locations.");
30 STANDARD_OPERATOR_1(vector, Size, type::UnsignedInteger(64), type::constant(type::Vector(type::Wildcard())),
31 "Returns the number of elements a vector contains.");
32 STANDARD_OPERATOR_2(vector, Equal, type::Bool(), type::constant(type::Vector(type::Wildcard())),
33 operator_::sameTypeAs(0,
"vector<*>"),
"Compares two vectors element-wise.");
34 STANDARD_OPERATOR_2x_low_prio(vector, IndexConst, Index, operator_::constantElementType(0),
35 type::constant(type::Vector(type::Wildcard())), type::UnsignedInteger(64),
36 "Returns the vector element at the given index.");
37 STANDARD_OPERATOR_2x_lhs(vector, IndexNonConst, Index, operator_::elementType(0), type::Vector(type::Wildcard()),
38 type::UnsignedInteger(64),
"Returns the vector element at the given index.");
39 STANDARD_OPERATOR_2(vector, Unequal, type::Bool(), type::constant(type::Vector(type::Wildcard())),
40 operator_::sameTypeAs(0,
"vector<*>"),
"Compares two vectors element-wise.");
42 STANDARD_OPERATOR_2(vector, Sum, operator_::sameTypeAs(0,
"vector<*>"), type::Vector(type::Wildcard()),
43 operator_::sameTypeAs(0,
"vector<*>"),
"Returns the concatenation of two vectors.")
44 STANDARD_OPERATOR_2(vector, SumAssign, operator_::sameTypeAs(0, "vector<*>"), type::Vector(type::Wildcard()),
45 operator_::sameTypeAs(0, "vector<*>"), "Concatenates another vector to the vector.")
47 BEGIN_METHOD(vector, Assign)
48 const auto& signature()
const {
49 static auto _signature = Signature{.self = type::Vector(type::Wildcard()),
50 .result = type::void_,
52 .args = {{
"i", type::UnsignedInteger(64)}, {
"x", type::Any()}},
54 Assigns *x* to the *i*th element of the vector. If the vector contains less 55 than *i* elements a sufficient number of default-initialized elements is added 56 to carry out the assignment. 62 BEGIN_METHOD(vector, PushBack)
63 const auto& signature()
const {
64 static auto _signature = Signature{.self = type::Vector(type::Wildcard()),
65 .result = type::void_,
67 .args = {{
"x", type::Any()}},
69 Appends *x* to the end of the vector. 75 BEGIN_METHOD(vector, PopBack)
76 const auto& signature()
const {
77 static auto _signature = Signature{.self = type::Vector(type::Wildcard()),
78 .result = type::void_,
82 Removes the last element from the vector, which must be non-empty. 88 BEGIN_METHOD(vector, Front)
89 const auto& signature()
const {
90 static auto _signature = Signature{.self = type::constant(type::Vector(type::Wildcard())),
91 .result = operator_::constantElementType(0),
95 Returns the first element of the vector. It throws an exception if the vector is 103 BEGIN_METHOD(vector, Back)
104 const auto& signature()
const {
105 static auto _signature = Signature{.self = type::constant(type::Vector(type::Wildcard())),
106 .result = operator_::constantElementType(0),
110 Returns the last element of the vector. It throws an exception if the vector is 117 BEGIN_METHOD(vector, Reserve)
118 const auto& signature()
const {
119 static auto _signature = Signature{.self = type::Vector(type::Wildcard()),
120 .result = type::void_,
122 .args = {{
"n", type::constant(type::UnsignedInteger(64))}},
124 Reserves space for at least *n* elements. This operation does not change the 125 vector in any observable way but provides a hint about the size that will be 132 BEGIN_METHOD(vector, Resize)
133 const auto& signature()
const {
134 static auto _signature = Signature{.self = type::Vector(type::Wildcard()),
135 .result = type::void_,
137 .args = {{
"n", type::constant(type::UnsignedInteger(64))}},
139 Resizes the vector to hold exactly *n* elements. If *n* is larger than the 140 current size, the new slots are filled with default values. If *n* is smaller 141 than the current size, the excessive elements are removed. 147 BEGIN_METHOD(vector, At)
148 const auto& signature()
const {
149 static auto _signature = Signature{.self = type::constant(type::Vector(type::Wildcard())),
150 .result = operator_::iteratorType(0,
true),
152 .args = {{
"i", type::UnsignedInteger(64)}},
154 Returns an iterator referring to the element at vector index *i*. 160 BEGIN_METHOD(vector, SubRange)
161 const auto& signature()
const {
162 static auto _signature =
163 Signature{.self = type::constant(type::Vector(type::Wildcard())),
164 .result = operator_::sameTypeAs(0,
"vector<*>"),
166 .args = {{
"begin", type::UnsignedInteger(64)}, {
"end", type::UnsignedInteger(64)}},
168 Extracts a subsequence of vector elements spanning from index *begin* 169 to (but not including) index *end*. 175 BEGIN_METHOD(vector, SubEnd)
176 const auto& signature()
const {
177 static auto _signature = Signature{.self = type::constant(type::Vector(type::Wildcard())),
178 .result = operator_::sameTypeAs(0,
"vector<*>"),
180 .args = {{
"end", type::UnsignedInteger(64)}},
182 Extracts a subsequence of vector elements spanning from the beginning 183 to (but not including) the index *end* as a new vector. Definition: operator-registry.h:15