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 {
11 namespace ctor {
12 
13 namespace detail {
14 
15 // CHECK: IntegerBase = isCtor
17 template<typename T, typename S>
18 class IntegerBase : public NodeBase, public hilti::trait::isCtor {
19 public:
20  IntegerBase(T v, int w, const Meta& m = Meta()) : NodeBase(nodes(S(w, m)), m), _value(v), _width(w) {}
21 
22  auto value() const { return _value; }
23  auto width() const { return _width; }
24 
26  bool isConstant() const { return true; }
28  auto isLhs() const { return false; }
30  auto isTemporary() const { return true; }
32  const auto& type() const { return child<Type>(0); }
33 
35  auto properties() const { return node::Properties{{"value", _value}, {"width", _width}}; }
36 
37 private:
38  T _value;
39  int _width;
40 };
41 
42 } // namespace detail
43 
45 class SignedInteger : public detail::IntegerBase<int64_t, type::SignedInteger> {
46 public:
48  using Base::IntegerBase;
49 
50  SignedInteger(uint64_t v, int w, const Meta& m = Meta()) : Base::IntegerBase(static_cast<int64_t>(v), w, m) {}
51 
52  bool operator==(const SignedInteger& other) const { return value() == other.value() && width() == other.width(); }
53 
55  auto isEqual(const Ctor& other) const { return node::isEqual(this, other); }
56 };
57 
59 class UnsignedInteger : public detail::IntegerBase<uint64_t, type::UnsignedInteger> {
60 public:
62 
63  bool operator==(const UnsignedInteger& other) const { return value() == other.value() && width() == other.width(); }
64 
66  auto isEqual(const Ctor& other) const { return node::isEqual(this, other); }
67 };
68 
69 } // namespace ctor
70 } // namespace hilti
const auto & type() const
Definition: integer.h:32
Definition: integer.h:18
bool isConstant() const
Definition: integer.h:26
Definition: integer.h:45
Definition: integer.h:59
Definition: meta.h:18
auto properties() const
Definition: integer.h:35
auto isEqual(const Ctor &other) const
Definition: integer.h:66
auto isEqual(const Ctor &other) const
Definition: integer.h:55
std::map< std::string, node::detail::PropertyValue > Properties
Definition: node.h:99
Definition: ctor.h:15
auto isLhs() const
Definition: integer.h:28
auto isTemporary() const
Definition: integer.h:30
Definition: node.h:358