Spicy
integer.h
1 // Copyright (c) 2020-2021 by the Zeek Project. See LICENSE for details.
2 
3 #pragma once
4 
5 #include <utility>
6 
7 #include <hilti/ast/ctor.h>
8 #include <hilti/ast/types/integer.h>
9 
10 namespace hilti::ctor {
11 
12 namespace detail {
13 
14 // CHECK: IntegerBase = isCtor
16 template<typename T, typename S>
17 class IntegerBase : public NodeBase, public hilti::trait::isCtor {
18 public:
19  IntegerBase(T v, int w, const Meta& m = Meta()) : NodeBase(nodes(S(w, m)), m), _value(v), _width(w) {}
20 
21  auto value() const { return _value; }
22  auto width() const { return _width; }
23 
25  bool isConstant() const { return true; }
27  auto isLhs() const { return false; }
29  auto isTemporary() const { return true; }
31  const auto& type() const { return child<Type>(0); }
32 
34  auto properties() const { return node::Properties{{"value", _value}, {"width", _width}}; }
35 
36 private:
37  T _value;
38  int _width;
39 };
40 
41 } // namespace detail
42 
44 class SignedInteger : public detail::IntegerBase<int64_t, type::SignedInteger> {
45 public:
47 
48  bool operator==(const SignedInteger& other) const { return value() == other.value() && width() == other.width(); }
49 
51  auto isEqual(const Ctor& other) const { return node::isEqual(this, other); }
52 };
53 
55 class UnsignedInteger : public detail::IntegerBase<uint64_t, type::UnsignedInteger> {
56 public:
58 
59  bool operator==(const UnsignedInteger& other) const { return value() == other.value() && width() == other.width(); }
60 
62  auto isEqual(const Ctor& other) const { return node::isEqual(this, other); }
63 };
64 
65 } // namespace hilti::ctor
const auto & type() const
Definition: integer.h:31
Definition: integer.h:17
bool isConstant() const
Definition: integer.h:25
Definition: integer.h:44
Definition: integer.h:55
Definition: meta.h:19
auto properties() const
Definition: integer.h:34
auto isEqual(const Ctor &other) const
Definition: integer.h:62
auto isEqual(const Ctor &other) const
Definition: integer.h:51
std::map< std::string, node::detail::PropertyValue > Properties
Definition: node.h:98
Definition: ctor.h:15
auto isLhs() const
Definition: integer.h:27
auto isTemporary() const
Definition: integer.h:29
Definition: node.h:360