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