souffle  2.0.2-371-g6315b36
ComponentType.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 ComponentType.h
12  *
13  * Defines the component-type class
14  *
15  ***********************************************************************/
16 
17 #pragma once
18 
19 #include "ast/Node.h"
20 #include "ast/QualifiedName.h"
21 #include "parser/SrcLocation.h"
23 #include <ostream>
24 #include <string>
25 #include <utility>
26 #include <vector>
27 
28 namespace souffle::ast {
29 
30 /**
31  * @class ComponentType
32  * @brief Component type of a component
33  *
34  * Example:
35  * name < Type1, Type2, ... >
36  * where name is the component name and < Type, Type, ... > is a
37  * list of component type parameters (either actual or formal).
38  */
39 class ComponentType : public Node {
40 public:
41  ComponentType(std::string name = "", std::vector<QualifiedName> params = {}, SrcLocation loc = {})
42  : Node(std::move(loc)), name(std::move(name)), typeParams(std::move(params)) {}
43 
44  /** Return component name */
45  const std::string& getName() const {
46  return name;
47  }
48 
49  /** Set component name */
50  void setName(std::string n) {
51  name = std::move(n);
52  }
53 
54  /** Return component type parameters */
55  const std::vector<QualifiedName>& getTypeParameters() const {
56  return typeParams;
57  }
58 
59  /** Set component type parameters */
60  void setTypeParameters(const std::vector<QualifiedName>& params) {
61  typeParams = params;
62  }
63 
64  ComponentType* clone() const override {
65  return new ComponentType(name, typeParams, getSrcLoc());
66  }
67 
68 protected:
69  void print(std::ostream& os) const override {
70  os << name;
71  if (!typeParams.empty()) {
72  os << "<" << join(typeParams) << ">";
73  }
74  }
75 
76  bool equal(const Node& node) const override {
77  const auto& other = static_cast<const ComponentType&>(node);
78  return name == other.name && typeParams == other.typeParams;
79  }
80 
81 private:
82  /** Component name */
83  std::string name;
84 
85  /** Component type parameters */
86  std::vector<QualifiedName> typeParams;
87 };
88 
89 } // namespace souffle::ast
SrcLocation.h
souffle::ast::ComponentType::typeParams
std::vector< QualifiedName > typeParams
Component type parameters.
Definition: ComponentType.h:92
souffle::ast::ComponentType::name
std::string name
Component name.
Definition: ComponentType.h:89
souffle::ast::ComponentType::setTypeParameters
void setTypeParameters(const std::vector< QualifiedName > &params)
Set component type parameters.
Definition: ComponentType.h:66
n
var n
Definition: htmlJsChartistMin.h:15
souffle::ast::ComponentType::print
void print(std::ostream &os) const override
Output to a given output stream.
Definition: ComponentType.h:75
souffle::ast::ComponentType::ComponentType
ComponentType(std::string name="", std::vector< QualifiedName > params={}, SrcLocation loc={})
Definition: ComponentType.h:47
souffle::ast::ComponentType::getTypeParameters
const std::vector< QualifiedName > & getTypeParameters() const
Return component type parameters.
Definition: ComponentType.h:61
souffle::ast::ComponentType
Component type of a component.
Definition: ComponentType.h:45
souffle::ast::ComponentType::clone
ComponentType * clone() const override
Create a clone (i.e.
Definition: ComponentType.h:70
souffle::ast::ComponentType::equal
bool equal(const Node &node) const override
Abstract equality check for two AST nodes.
Definition: ComponentType.h:82
souffle::join
detail::joined_sequence< Iter, Printer > join(const Iter &a, const Iter &b, const std::string &sep, const Printer &p)
Creates an object to be forwarded to some output stream for printing sequences of elements interspers...
Definition: StreamUtil.h:175
Node.h
souffle::ast::Node
Abstract class for syntactic elements in an input program.
Definition: Node.h:40
QualifiedName.h
StreamUtil.h
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::ComponentType::getName
const std::string & getName() const
Return component name.
Definition: ComponentType.h:51
souffle::ast::ComponentType::setName
void setName(std::string n)
Set component name.
Definition: ComponentType.h:56