souffle  2.0.2-371-g6315b36
Constant.h
Go to the documentation of this file.
1 /*
2  * Souffle - A Datalog Compiler
3  * Copyright (c) 2013, 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 Constant.h
12  *
13  * Defines an abstract class for constants
14  *
15  ***********************************************************************/
16 
17 #pragma once
18 
19 #include "ast/Argument.h"
20 #include "ast/Node.h"
21 #include "parser/SrcLocation.h"
22 #include <ostream>
23 #include <string>
24 #include <utility>
25 
26 namespace souffle::ast {
27 
28 /**
29  * @class Constant
30  * @brief Abstract constant class
31  */
32 class Constant : public Argument {
33 public:
34  Constant* clone() const override = 0;
35 
36  /** Get string representation of Constant */
37  const std::string& getConstant() const {
38  return constant;
39  }
40 
41 protected:
42  void print(std::ostream& os) const override {
43  os << getConstant();
44  }
45 
46  bool equal(const Node& node) const override {
47  const auto& other = static_cast<const Constant&>(node);
48  return constant == other.constant;
49  }
50 
51  Constant(std::string value, SrcLocation loc = {})
52  : Argument(std::move(loc)), constant(std::move(value)){};
53 
54 private:
55  /** String representation of constant */
56  const std::string constant;
57 };
58 
59 } // namespace souffle::ast
souffle::ast::Constant::print
void print(std::ostream &os) const override
Output to a given output stream.
Definition: Constant.h:48
SrcLocation.h
souffle::ast::Constant::getConstant
const std::string & getConstant() const
Get string representation of Constant.
Definition: Constant.h:43
souffle::ast::Constant::clone
Constant * clone() const override=0
Create clone.
souffle::ast::Argument
An abstract class for arguments.
Definition: Argument.h:33
Argument.h
souffle::ast::Constant
Abstract constant class.
Definition: Constant.h:38
souffle::ast::Constant::Constant
Constant(std::string value, SrcLocation loc={})
Definition: Constant.h:57
Node.h
souffle::ast::Node
Abstract class for syntactic elements in an input program.
Definition: Node.h:40
souffle::SrcLocation
A class describing a range in an input file.
Definition: SrcLocation.h:32
souffle::ast::Constant::equal
bool equal(const Node &node) const override
Abstract equality check for two AST nodes.
Definition: Constant.h:52
souffle::ast
Definition: Aggregator.h:35
souffle::ast::Constant::constant
const std::string constant
String representation of constant.
Definition: Constant.h:58