1
2
3
4
5
6 #ifndef SNGCM_AST_FUNCTION_INCLUDED
7 #define SNGCM_AST_FUNCTION_INCLUDED
8 #include <sngcm/ast/Attribute.hpp>
9 #include <sngcm/ast/Specifier.hpp>
10 #include <sngcm/ast/Template.hpp>
11 #include <sngcm/ast/Concept.hpp>
12 #include <sngcm/ast/Parameter.hpp>
13 #include <sngcm/ast/Statement.hpp>
14 #include <sngcm/ast/Identifier.hpp>
15
16 namespace sngcm { namespace ast {
17
18 class FunctionNode : public Node
19 {
20 public:
21 FunctionNode(const Span& span_);
22 FunctionNode(NodeType nodeType_, const Span& span_);
23 FunctionNode(const Span& span_, Specifiers specifiers_, Node* returnTypeExpr_, const std::u32string& groupId_, Attributes* attributes_);
24 FunctionNode(NodeType nodeType_, const Span& span_, Specifiers specifiers_, Node* returnTypeExpr_, const std::u32string& groupId_, Attributes* attributes_);
25 FunctionNode(const FunctionNode&) = delete;
26 FunctionNode& operator=(const FunctionNode&) = delete;
27 Node* Clone(CloneContext& cloneContext) const override;
28 bool IsFunctionNode() const override { return true; }
29 void CloneContent(FunctionNode* clone, CloneContext& cloneContext) const;
30 void Accept(Visitor& visitor) override;
31 void Write(AstWriter& writer) override;
32 void Read(AstReader& reader) override;
33 void AddTemplateParameter(TemplateParameterNode* templateParameter) override;
34 void AddParameter(ParameterNode* parameter) override;
35 void SwitchToBody();
36 Specifiers GetSpecifiers() const override { return specifiers; }
37 const Node* ReturnTypeExpr() const { return returnTypeExpr.get(); }
38 Node* ReturnTypeExpr() { return returnTypeExpr.get(); }
39 const std::u32string& GroupId() const { return groupId; }
40 const NodeList<TemplateParameterNode>& TemplateParameters() const { return templateParameters; }
41 const NodeList<ParameterNode>& Parameters() const { return parameters; }
42 void SetReturnTypeExpr(Node* returnTypeExpr_);
43 const WhereConstraintNode* WhereConstraint() const { return whereConstraint.get(); }
44 WhereConstraintNode* WhereConstraint() { return whereConstraint.get(); }
45 void SetSpecifiers(Specifiers specifiers_);
46 void SetConstraint(WhereConstraintNode* whereConstraint_);
47 const CompoundStatementNode* Body() const { return body.get(); }
48 CompoundStatementNode* Body() { return body.get(); }
49 void SetBody(CompoundStatementNode* body_);
50 const CompoundStatementNode* BodySource() const { return bodySource.get(); }
51 void SetBodySource(CompoundStatementNode* bodySource_);
52 bool IsProgramMain() const { return programMain; }
53 void SetProgramMain() { programMain = true; }
54 Attributes* GetAttributes() const { return attributes.get(); }
55 void SetSpecifierSpan(const Span& specifierSpan_) { specifierSpan = specifierSpan_; }
56 const Span& SpecifierSpan() const { return specifierSpan; }
57 void SetGroupIdSpan(const Span& groupIdSpan_) { groupIdSpan = groupIdSpan_; }
58 const Span& GroupIdSpan() const { return groupIdSpan; }
59 private:
60 Specifiers specifiers;
61 Span specifierSpan;
62 std::unique_ptr<Node> returnTypeExpr;
63 std::u32string groupId;
64 Span groupIdSpan;
65 NodeList<TemplateParameterNode> templateParameters;
66 NodeList<ParameterNode> parameters;
67 std::unique_ptr<WhereConstraintNode> whereConstraint;
68 std::unique_ptr<CompoundStatementNode> body;
69 std::unique_ptr<CompoundStatementNode> bodySource;
70 std::unique_ptr<Attributes> attributes;
71 bool programMain;
72 };
73
74 } }
75
76 #endif // SNGCM_AST_FUNCTION_INCLUDED