Line data Source code
1 : #ifndef AST_IF_H
2 : #define AST_IF_H
3 :
4 : #include "ast_condition.h"
5 : #include "ast_elseIf.h"
6 : #include <memory>
7 : #include <vector>
8 :
9 : namespace nicole {
10 :
11 : class AST_IF : public AST {
12 : private:
13 : std::shared_ptr<AST_CONDITION> condition_;
14 : std::shared_ptr<AST_BODY> body_;
15 : std::vector<std::shared_ptr<AST_ELSE_IF>> elseIf_;
16 : std::shared_ptr<AST_BODY> elseBody_;
17 :
18 : public:
19 : explicit AST_IF(const long long unsigned nodeId, const SourceLocation &srcLoc,
20 : const std::shared_ptr<AST_CONDITION> &condition,
21 : const std::shared_ptr<AST_BODY> &body,
22 : const std::vector<std::shared_ptr<AST_ELSE_IF>> &elseIf,
23 : const std::shared_ptr<AST_BODY> &elseBody) noexcept
24 1 : : AST(nodeId, AST_TYPE::IF, srcLoc), condition_{condition}, body_{body},
25 1 : elseIf_{elseIf}, elseBody_{elseBody} {}
26 :
27 : [[nodiscard]] const std::shared_ptr<AST_CONDITION> &
28 9 : condition() const noexcept {
29 9 : return condition_;
30 9 : }
31 :
32 9 : [[nodiscard]] const std::shared_ptr<AST_BODY> &body() const noexcept {
33 9 : return body_;
34 9 : }
35 :
36 : [[nodiscard]] const std::vector<std::shared_ptr<AST_ELSE_IF>> &
37 18 : elseIf() const noexcept {
38 18 : return elseIf_;
39 18 : }
40 :
41 9 : [[nodiscard]] const std::shared_ptr<AST_BODY> &elseBody() const noexcept {
42 9 : return elseBody_;
43 9 : }
44 :
45 : [[nodiscard]] std::expected<std::string, Error>
46 0 : accept(const PrintTree &visitor) const noexcept override {
47 0 : return visitor.visit(this);
48 0 : }
49 :
50 : [[nodiscard]] std::expected<bool, Error>
51 0 : accept(const ValidateTree &visitor) const noexcept override {
52 0 : return visitor.visit(this);
53 0 : }
54 :
55 : [[nodiscard]] std::expected<std::monostate, Error>
56 0 : accept(const FillSemanticInfo &visitor) const noexcept override {
57 0 : return visitor.visit(this);
58 0 : }
59 :
60 : [[nodiscard]] std::expected<std::shared_ptr<Type>, Error>
61 0 : accept(const TypeAnalysis &visitor) const noexcept override {
62 0 : return visitor.visit(this);
63 0 : }
64 :
65 : [[nodiscard]] std::expected<std::monostate, Error>
66 0 : accept(const Monomorphize &visitor) const noexcept override {
67 0 : return visitor.visit(this);
68 0 : }
69 :
70 : [[nodiscard]] std::expected<std::shared_ptr<llvm::Value>, Error>
71 0 : accept(const CodeGeneration &visitor) const noexcept override {
72 0 : return visitor.visit(this);
73 0 : }
74 : };
75 :
76 : } // namespace nicole
77 :
78 : #endif
|