souffle  2.0.2-371-g6315b36
StringConstant.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 StringConstant.h
12  *
13  * Defines the string constant class
14  *
15  ***********************************************************************/
16 
17 #pragma once
18 
19 #include "ast/Constant.h"
20 #include "parser/SrcLocation.h"
21 #include <ostream>
22 #include <string>
23 #include <utility>
24 
25 namespace souffle::ast {
26 
27 /**
28  * @class StringConstant
29  * @brief String constant class
30  */
31 class StringConstant : public Constant {
32 public:
33  explicit StringConstant(std::string value, SrcLocation loc = {}) : Constant(std::move(value)) {
34  setSrcLoc(std::move(loc));
35  }
36 
37  StringConstant* clone() const override {
38  auto* res = new StringConstant(getConstant());
39  res->setSrcLoc(getSrcLoc());
40  return res;
41  }
42 
43 protected:
44  void print(std::ostream& os) const override {
45  os << "\"" << getConstant() << "\"";
46  }
47 };
48 
49 } // namespace souffle::ast
SrcLocation.h
souffle::ast::Constant::getConstant
const std::string & getConstant() const
Get string representation of Constant.
Definition: Constant.h:43
souffle::ast::StringConstant::clone
StringConstant * clone() const override
Create clone.
Definition: StringConstant.h:43
Constant.h
souffle::ast::StringConstant::print
void print(std::ostream &os) const override
Output to a given output stream.
Definition: StringConstant.h:50
souffle::ast::Constant::Constant
Constant(std::string value, SrcLocation loc={})
Definition: Constant.h:57
souffle::ast::StringConstant::StringConstant
StringConstant(std::string value, SrcLocation loc={})
Definition: StringConstant.h:39
souffle::ast::Node::setSrcLoc
void setSrcLoc(SrcLocation l)
Set source location for the Node.
Definition: Node.h:51
souffle::ast::Node::getSrcLoc
const SrcLocation & getSrcLoc() const
Return source location of the Node.
Definition: Node.h:46
souffle::ast
Definition: Aggregator.h:35
souffle::ast::StringConstant
String constant class.
Definition: StringConstant.h:37