souffle  2.0.2-371-g6315b36
UnsignedConstant.h
Go to the documentation of this file.
1 /*
2  * Souffle - A Datalog Compiler
3  * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved
4  * Licensed under the Universal Permissive License v 1.0 as shown at:
5  * - https://opensource.org/licenses/UPL
6  * - <souffle root>/licenses/SOUFFLE-UPL.txt
7  */
8 
9 /************************************************************************
10  *
11  * @file UnsignedConstant.h
12  *
13  * Defines a class for evaluating values in the Relational Algebra Machine
14  *
15  ************************************************************************/
16 
17 #pragma once
18 
19 #include "ram/Constant.h"
20 #include "souffle/RamTypes.h"
21 #include <ostream>
22 
23 namespace souffle::ram {
24 
25 /**
26  * @class UnsignedConstant
27  * @brief Represents a unsigned constant
28  *
29  * For example:
30  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~
31  * unsigned(5)
32  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~
33  */
34 class UnsignedConstant : public Constant {
35 public:
36  explicit UnsignedConstant(RamUnsigned val) : Constant(ramBitCast(val)) {}
37 
38  /** @brief Get value of the constant. */
39  RamUnsigned getValue() const {
40  return ramBitCast<RamUnsigned>(constant);
41  }
42 
43  /** Create clone */
44  UnsignedConstant* clone() const override {
45  return new UnsignedConstant(getValue());
46  }
47 
48 protected:
49  void print(std::ostream& os) const override {
50  os << "unsigned(" << getValue() << ")";
51  }
52 };
53 
54 } // namespace souffle::ram
souffle::RamUnsigned
uint32_t RamUnsigned
Definition: RamTypes.h:58
Constant.h
souffle::ram::Constant::Constant
Constant(RamDomain constant)
Definition: Constant.h:44
souffle::ram
Definition: AstToRamTranslator.h:54
souffle::ram::UnsignedConstant
Represents a unsigned constant.
Definition: UnsignedConstant.h:40
souffle::ram::Constant::constant
const RamDomain constant
Constant value.
Definition: Constant.h:52
souffle::ram::UnsignedConstant::print
void print(std::ostream &os) const override
Print RAM node.
Definition: UnsignedConstant.h:55
souffle::ram::UnsignedConstant::UnsignedConstant
UnsignedConstant(RamUnsigned val)
Definition: UnsignedConstant.h:42
souffle::ram::UnsignedConstant::clone
UnsignedConstant * clone() const override
Create clone.
Definition: UnsignedConstant.h:50
RamTypes.h
souffle::ramBitCast
To ramBitCast(From source)
In C++20 there will be a new way to cast between types by reinterpreting bits (std::bit_cast),...
Definition: RamTypes.h:87
souffle::ram::UnsignedConstant::getValue
RamUnsigned getValue() const
Get value of the constant.
Definition: UnsignedConstant.h:45