souffle  2.0.2-371-g6315b36
ComponentInit.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 ComponentInit.h
12  *
13  * Defines the component-initialization class
14  *
15  ***********************************************************************/
16 
17 #pragma once
18 
19 #include "ast/ComponentType.h"
20 #include "ast/Node.h"
21 #include "ast/utility/NodeMapper.h"
22 #include "parser/SrcLocation.h"
24 #include <memory>
25 #include <ostream>
26 #include <string>
27 #include <utility>
28 #include <vector>
29 
30 namespace souffle::ast {
31 
32 /**
33  * @class ComponentInit
34  * @brief Component initialization class
35  *
36  * Example:
37  * .init X=B<T1,T2>
38  *
39  * Intialization of a component with type parameters
40  */
41 class ComponentInit : public Node {
42 public:
43  ComponentInit(std::string name, Own<ComponentType> type, SrcLocation loc = {})
44  : Node(std::move(loc)), instanceName(std::move(name)), componentType(std::move(type)) {}
45 
46  /** Return instance name */
47  const std::string& getInstanceName() const {
48  return instanceName;
49  }
50 
51  /** Set instance name */
52  void setInstanceName(std::string name) {
53  instanceName = std::move(name);
54  }
55 
56  /** Return component type */
57  const ComponentType* getComponentType() const {
58  return componentType.get();
59  }
60 
61  /** Set component type */
63  componentType = std::move(type);
64  }
65 
66  ComponentInit* clone() const override {
68  }
69 
70  void apply(const NodeMapper& mapper) override {
71  componentType = mapper(std::move(componentType));
72  }
73 
74  std::vector<const Node*> getChildNodes() const override {
75  return {componentType.get()};
76  }
77 
78 protected:
79  void print(std::ostream& os) const override {
80  os << ".init " << instanceName << " = " << *componentType;
81  }
82 
83  bool equal(const Node& node) const override {
84  const auto& other = static_cast<const ComponentInit&>(node);
85  return instanceName == other.instanceName && *componentType == *other.componentType;
86  }
87 
88  /** Instance name */
89  std::string instanceName;
90 
91  /** Actual component arguments for instantiation */
93 };
94 
95 } // namespace souffle::ast
souffle::ast::ComponentInit::ComponentInit
ComponentInit(std::string name, Own< ComponentType > type, SrcLocation loc={})
Definition: ComponentInit.h:49
souffle::ast::ComponentInit::getChildNodes
std::vector< const Node * > getChildNodes() const override
Obtain a list of all embedded AST child nodes.
Definition: ComponentInit.h:80
souffle::ast::ComponentInit::print
void print(std::ostream &os) const override
Output to a given output stream.
Definition: ComponentInit.h:85
souffle::ast::ComponentInit::setInstanceName
void setInstanceName(std::string name)
Set instance name.
Definition: ComponentInit.h:58
SrcLocation.h
souffle::ast::NodeMapper
An abstract class for manipulating AST Nodes by substitution.
Definition: NodeMapper.h:36
souffle::Own
std::unique_ptr< A > Own
Definition: ContainerUtil.h:42
souffle::ast::ComponentInit::apply
void apply(const NodeMapper &mapper) override
Apply the mapper to all child nodes.
Definition: ComponentInit.h:76
MiscUtil.h
souffle::ast::ComponentInit
Component initialization class.
Definition: ComponentInit.h:47
NodeMapper.h
souffle::ast::ComponentType
Component type of a component.
Definition: ComponentType.h:45
souffle::clone
auto clone(const std::vector< A * > &xs)
Definition: ContainerUtil.h:172
souffle::ast::ComponentInit::componentType
Own< ComponentType > componentType
Actual component arguments for instantiation.
Definition: ComponentInit.h:98
ComponentType.h
Node.h
souffle::ast::ComponentInit::getInstanceName
const std::string & getInstanceName() const
Return instance name.
Definition: ComponentInit.h:53
souffle::ast::Node
Abstract class for syntactic elements in an input program.
Definition: Node.h:40
souffle::ast::ComponentInit::setComponentType
void setComponentType(Own< ComponentType > type)
Set component type.
Definition: ComponentInit.h:68
souffle::ast::ComponentInit::getComponentType
const ComponentType * getComponentType() const
Return component type.
Definition: ComponentInit.h:63
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::ComponentInit::equal
bool equal(const Node &node) const override
Abstract equality check for two AST nodes.
Definition: ComponentInit.h:89
souffle::ast::ComponentInit::clone
ComponentInit * clone() const override
Create a clone (i.e.
Definition: ComponentInit.h:72
souffle::ast::ComponentInit::instanceName
std::string instanceName
Instance name.
Definition: ComponentInit.h:95
std::type
ElementType type
Definition: span.h:640