-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFunctionNode.cpp
56 lines (43 loc) · 1.53 KB
/
FunctionNode.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include "FunctionNode.hpp"
ParamFunctionNode::ParamFunctionNode(std::unique_ptr<PatternNode> &&pattern, std::unique_ptr<TypeNode> &&type)
: pattern_(std::move(pattern)), type_(std::move(type)) {}
void ParamFunctionNode::Visit(ISyntaxTreeVisitor *visitor) const {
visitor->PostVisit(this);
}
const PatternNode *ParamFunctionNode::GetPattern() const {
return pattern_.get();
}
const TypeNode *ParamFunctionNode::GetType() const {
return type_.get();
}
FunctionNode::FunctionNode(
std::unique_ptr<IdentifierNode> &&identifier, std::vector<ParamFunctionNode> &¶ms,
std::unique_ptr<TypeNode> &&return_type, std::unique_ptr<BlockNode> &&block, bool is_const)
: identifier_(std::move(identifier)), params_(std::move(params)), return_type_(std::move(return_type)),
block_(std::move(block)), is_const_(is_const) {
for (auto ¶m : params_) {
param.function_node = this;
}
}
void FunctionNode::Visit(ISyntaxTreeVisitor *visitor) const {
visitor->PostVisit(this);
}
const IdentifierNode *FunctionNode::GetIdentifier() const {
return identifier_.get();
}
const TypeNode *FunctionNode::GetReturnType() const {
return return_type_.get();
}
const BlockNode *FunctionNode::GetBlock() const {
return block_.get();
}
std::vector<const ParamFunctionNode *> FunctionNode::GetParams() const {
std::vector<const ParamFunctionNode *> params;
for (const auto ¶m : params_) {
params.push_back(¶m);
}
return params;
}
bool FunctionNode::IsConst() const {
return is_const_;
}