Spicy
interval.h
1 // Copyright (c) 2020-2021 by the Zeek Project. See LICENSE for details.
2 
3 #pragma once
4 
5 #include <hilti/ast/builder/type.h>
6 #include <hilti/ast/operators/common.h>
7 #include <hilti/ast/types/integer.h>
8 #include <hilti/ast/types/interval.h>
9 #include <hilti/ast/types/real.h>
10 
11 namespace hilti::operator_ {
12 
13 STANDARD_OPERATOR_2(interval, Equal, type::Bool(), type::Interval(), type::Interval(), "Compares two interval values.")
14 STANDARD_OPERATOR_2(interval, Unequal, type::Bool(), type::Interval(), type::Interval(),
15  "Compares two interval values.")
16 STANDARD_OPERATOR_2(interval, Sum, type::Interval(), type::Interval(), type::Interval(),
17  "Returns the sum of the intervals.");
18 STANDARD_OPERATOR_2(interval, Difference, type::Interval(), type::Interval(), type::Interval(),
19  "Returns the difference of the intervals.");
20 STANDARD_OPERATOR_2(interval, Greater, type::Bool(), type::Interval(), type::Interval(), "Compares the intervals.");
21 STANDARD_OPERATOR_2(interval, GreaterEqual, type::Bool(), type::Interval(), type::Interval(),
22  "Compares the intervals.");
23 STANDARD_OPERATOR_2(interval, Lower, type::Bool(), type::Interval(), type::Interval(), "Compares the intervals.");
24 STANDARD_OPERATOR_2(interval, LowerEqual, type::Bool(), type::Interval(), type::Interval(), "Compares the intervals.");
25 STANDARD_OPERATOR_2x(interval, MultipleUnsignedInteger, Multiple, type::Interval(), type::Interval(),
26  type::UnsignedInteger(64), "Multiples the interval with the given factor.");
27 STANDARD_OPERATOR_2x(interval, MultipleReal, Multiple, type::Interval(), type::Interval(), type::Real(),
28  "Multiplies the interval with the given factor.");
29 
30 STANDARD_KEYWORD_CTOR(interval, CtorSignedIntegerNs, "interval_ns", type::Interval(),
31  type::SignedInteger(type::Wildcard()),
32  "Creates an interval interpreting the argument as number of nanoseconds.");
33 STANDARD_KEYWORD_CTOR(interval, CtorSignedIntegerSecs, "interval", type::Interval(),
34  type::SignedInteger(type::Wildcard()),
35  "Creates an interval interpreting the argument as number of seconds.");
36 STANDARD_KEYWORD_CTOR(interval, CtorUnsignedIntegerNs, "interval_ns", type::Interval(),
37  type::UnsignedInteger(type::Wildcard()),
38  "Creates an interval interpreting the argument as number of nanoseconds.");
39 STANDARD_KEYWORD_CTOR(interval, CtorUnsignedIntegerSecs, "interval", type::Interval(),
40  type::UnsignedInteger(type::Wildcard()),
41  "Creates an interval interpreting the argument as number of seconds.");
42 STANDARD_KEYWORD_CTOR(interval, CtorRealSecs, "interval", type::Interval(), type::Real(),
43  "Creates an interval interpreting the argument as number of seconds.");
44 
45 BEGIN_METHOD(interval, Seconds)
46  const auto& signature() const {
47  static auto _signature =
48  Signature{.self = type::Interval(), .result = type::Real(), .id = "seconds", .args = {}, .doc = R"(
49 Returns the interval as a real value representing seconds.
50 )"};
51  return _signature;
52  }
53 END_METHOD
54 
55 BEGIN_METHOD(interval, Nanoseconds)
56  const auto& signature() const {
57  static auto _signature = Signature{.self = type::Interval(),
58  .result = type::SignedInteger(64),
59  .id = "nanoseconds",
60  .args = {},
61  .doc = R"(
62 Returns the interval as an integer value representing nanoseconds.
63 )"};
64  return _signature;
65  }
66 END_METHOD
67 
68 } // namespace hilti::operator_
Definition: operator-registry.h:15