chigraph  master
Systems programming language written for beginners in LLVM
NodeType.cpp
Go to the documentation of this file.
1 
3 #include "chi/NodeType.hpp"
4 #include "chi/ChiModule.hpp"
5 #include "chi/DataType.hpp"
6 
7 namespace chi {
8 
9 NodeType::NodeType(ChiModule& mod, std::string name, std::string description)
10  : mModule{&mod},
11  mContext{&mod.context()},
12  mName{std::move(name)},
13  mDescription{std::move(description)} {}
14 
15 NodeType::~NodeType() = default;
16 
17 std::string NodeType::qualifiedName() const { return module().fullName() + ":" + name(); }
18 
20  std::vector<chi::NamedDataType, std::allocator<chi::NamedDataType> > newInputs) {
21  mDataInputs = std::move(newInputs);
22 }
23 
25  std::vector<chi::NamedDataType, std::allocator<chi::NamedDataType> > newOutputs) {
26  mDataOutputs = std::move(newOutputs);
27 }
28 
29 void NodeType::setExecInputs(std::vector<std::string> newInputs) {
30  mExecInputs = std::move(newInputs);
31 }
32 
33 void NodeType::setExecOutputs(std::vector<std::string> newOutputs) {
34  mExecOutputs = std::move(newOutputs);
35 }
36 
38  setExecInputs({});
39  setExecOutputs({});
40 
41  mPure = true;
42 }
43 
45  assert(pure() && "Cannot have a nonpure converter node");
46  assert(dataInputs().size() == 1 && "A converter node must have one data input");
47  assert(dataOutputs().size() == 1 && "A converter node must have one data output");
48 
49  mConverter = true;
50 }
51 
52 NodeInstance* NodeType::nodeInstance() const { return mNodeInstance; }
53 
54 void NodeType::setName(std::string newName) { mName = std::move(newName); }
55 
56 void NodeType::setDescription(std::string newDesc) { mDescription = std::move(newDesc); }
57 } // namespace chi
ChiModule & module() const
Get the ChiModule this NodeType belongs to.
Definition: NodeType.hpp:67
const std::vector< NamedDataType > & dataOutputs() const
Get the data outputs for the node.
Definition: NodeType.hpp:76
An instance of a node.
void makeConverter()
Make this a converter node.
Definition: NodeType.cpp:44
void setDescription(std::string newDesc)
Set the description of the node.
Definition: NodeType.cpp:56
std::string name() const
Get the name of the NodeType in the ChiModule.
Definition: NodeType.hpp:61
Basicaly a std::pair<std::string, DataType>, except it has nicer names.
Definition: DataType.hpp:72
void makePure()
Make this node pure For more info on what this means, see https://en.wikipedia.org/wiki/Pure_function...
Definition: NodeType.cpp:37
std::string description() const
Get the description of the NodeType.
Definition: NodeType.hpp:64
NodeInstance * nodeInstance() const
Get the node instance.
Definition: NodeType.cpp:52
std::string fullName() const
Get the full name of the module.
Definition: ChiModule.hpp:61
NodeType(ChiModule &mod, std::string name={}, std::string description={})
Constructor.
Definition: NodeType.cpp:9
An abstract class that represents a module of code in Chigraph Can be compiled to a llvm::Module...
Definition: ChiModule.hpp:24
void setExecOutputs(std::vector< std::string > newOutputs)
Set the exec outputs for the NodeType.
Definition: NodeType.cpp:33
void setDataOutputs(std::vector< NamedDataType > newOutputs)
Set the data outputs for the NodeType.
Definition: NodeType.cpp:24
void setExecInputs(std::vector< std::string > newInputs)
Set the exec inputs for the NodeType.
Definition: NodeType.cpp:29
bool pure()
Get if this node is pure.
Definition: NodeType.hpp:86
void setName(std::string newName)
Set the name of the type.
Definition: NodeType.cpp:54
virtual ~NodeType()
Destructor.
Defines the NodeType class.
Defines the DataType class.
Defines the ChiModule class.
const std::vector< NamedDataType > & dataInputs() const
Get the data inputs for the node.
Definition: NodeType.hpp:73
The namespace where chigraph lives.
std::string qualifiedName() const
Get the qualified name of the node type, like module.name():name()
Definition: NodeType.cpp:17
void setDataInputs(std::vector< NamedDataType > newInputs)
Set the data inputs for the NodeType.
Definition: NodeType.cpp:19