souffle  2.0.2-371-g6315b36
Variable.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 Variable.h
12  *
13  * Define the variable class
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 Variable
30  * @brief Named variable class
31  */
32 class Variable : public Argument {
33 public:
34  Variable(std::string name, SrcLocation loc = {}) : Argument(std::move(loc)), name(std::move(name)) {}
35 
36  /** Set variable name */
37  void setName(std::string name) {
38  this->name = std::move(name);
39  }
40 
41  /** Return variable name */
42  const std::string& getName() const {
43  return name;
44  }
45 
46  Variable* clone() const override {
47  return new Variable(name, getSrcLoc());
48  }
49 
50 protected:
51  void print(std::ostream& os) const override {
52  os << name;
53  }
54 
55  bool equal(const Node& node) const override {
56  const auto& other = static_cast<const Variable&>(node);
57  return name == other.name;
58  }
59 
60  /** Name */
61  std::string name;
62 };
63 
64 } // namespace souffle::ast
souffle::ast::analysis::Variable::print
virtual void print(std::ostream &out) const
Adds print support.
Definition: ConstraintSystem.h:166
SrcLocation.h
souffle::ast::Variable::setName
void setName(std::string name)
Set variable name.
Definition: Variable.h:43
souffle::ast::Variable::getName
const std::string & getName() const
Return variable name.
Definition: Variable.h:48
souffle::ast::analysis::Variable
A variable to be utilized within constraints to be handled by the constraint solver.
Definition: ConstraintSystem.h:41
Argument.h
souffle::clone
auto clone(const std::vector< A * > &xs)
Definition: ContainerUtil.h:172
souffle::ast::analysis::Variable::Variable
Variable(Id id)
Definition: ConstraintSystem.h:141
Node.h
souffle::ast::Node
Abstract class for syntactic elements in an input program.
Definition: Node.h:40
souffle::ast
Definition: Aggregator.h:35