souffle  2.0.2-371-g6315b36
Attribute.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 Attribute.h
12  *
13  * Defines the attribute class
14  *
15  ***********************************************************************/
16 
17 #pragma once
18 
19 #include "ast/Node.h"
20 #include "ast/QualifiedName.h"
21 #include "parser/SrcLocation.h"
22 #include <ostream>
23 #include <string>
24 #include <utility>
25 
26 namespace souffle::ast {
27 
28 /**
29  * @class Attribute
30  * @brief Attribute class
31  *
32  * Example:
33  * x: number
34  * An attribute consists of a name and its type name.
35  */
36 class Attribute : public Node {
37 public:
38  Attribute(std::string n, QualifiedName t, SrcLocation loc = {})
39  : Node(std::move(loc)), name(std::move(n)), typeName(std::move(t)) {}
40 
41  /** Return attribute name */
42  const std::string& getName() const {
43  return name;
44  }
45 
46  /** Return type name */
47  const QualifiedName& getTypeName() const {
48  return typeName;
49  }
50 
51  /** Set type name */
53  typeName = std::move(name);
54  }
55 
56  Attribute* clone() const override {
57  return new Attribute(name, typeName, getSrcLoc());
58  }
59 
60 protected:
61  void print(std::ostream& os) const override {
62  os << name << ":" << typeName;
63  }
64 
65  bool equal(const Node& node) const override {
66  const auto& other = static_cast<const Attribute&>(node);
67  return name == other.name && typeName == other.typeName;
68  }
69 
70 private:
71  /** Attribute name */
72  std::string name;
73 
74  /** Type name */
76 };
77 
78 } // namespace souffle::ast
SrcLocation.h
souffle::ast::Attribute::Attribute
Attribute(std::string n, QualifiedName t, SrcLocation loc={})
Definition: Attribute.h:44
souffle::ast::Attribute::getName
const std::string & getName() const
Return attribute name.
Definition: Attribute.h:48
souffle::ast::Attribute::name
std::string name
Attribute name.
Definition: Attribute.h:78
n
var n
Definition: htmlJsChartistMin.h:15
souffle::ast::Attribute
Attribute class.
Definition: Attribute.h:42
souffle::ast::Attribute::typeName
QualifiedName typeName
Type name.
Definition: Attribute.h:81
souffle::ast::Attribute::setTypeName
void setTypeName(QualifiedName name)
Set type name.
Definition: Attribute.h:58
souffle::ast::Attribute::print
void print(std::ostream &os) const override
Output to a given output stream.
Definition: Attribute.h:67
souffle::ast::Attribute::getTypeName
const QualifiedName & getTypeName() const
Return type name.
Definition: Attribute.h:53
souffle::ast::Attribute::equal
bool equal(const Node &node) const override
Abstract equality check for two AST nodes.
Definition: Attribute.h:71
Node.h
souffle::ast::Node
Abstract class for syntactic elements in an input program.
Definition: Node.h:40
QualifiedName.h
souffle::ast::Attribute::clone
Attribute * clone() const override
Create a clone (i.e.
Definition: Attribute.h:62
souffle::ast::Node::Node
Node(SrcLocation loc={})
Definition: Node.h:42
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::QualifiedName
Qualified Name class defines fully/partially qualified names to identify objects in components.
Definition: QualifiedName.h:39