Line data Source code
1 : #ifndef AST_SUPER_H
2 : #define AST_SUPER_H
3 :
4 : #include "../ast.h"
5 : #include <memory>
6 :
7 : namespace nicole {
8 :
9 : class AST_SUPER final : public AST {
10 : private:
11 : std::shared_ptr<Type> fatherType_;
12 : mutable std::vector<std::shared_ptr<Type>> replacements_;
13 : std::vector<std::shared_ptr<AST>> arguments_;
14 :
15 : public:
16 : explicit AST_SUPER(
17 : const long long unsigned nodeId, const SourceLocation &srcLoc,
18 : const std::shared_ptr<Type> &fatherType,
19 : const std::vector<std::shared_ptr<Type>> &replacements,
20 : const std::vector<std::shared_ptr<AST>> &arguments) noexcept
21 0 : : AST{nodeId, AST_TYPE::SUPER, srcLoc}, fatherType_{fatherType},
22 0 : replacements_{replacements}, arguments_{arguments} {}
23 :
24 0 : [[nodiscard]] const std::shared_ptr<Type> fatherType() const noexcept {
25 0 : return fatherType_;
26 0 : }
27 :
28 : [[nodiscard]] const std::vector<std::shared_ptr<AST>>
29 0 : arguments() const noexcept {
30 0 : return arguments_;
31 0 : }
32 :
33 : [[nodiscard]] const std::vector<std::shared_ptr<Type>>
34 0 : replacements() const noexcept {
35 0 : return replacements_;
36 0 : }
37 :
38 : [[nodiscard]] std::expected<std::monostate, Error>
39 : setGenericReplacement(const std::size_t pos,
40 0 : const std::shared_ptr<Type> &type) const noexcept {
41 0 : if (pos >= replacements_.size()) {
42 0 : return createError(
43 0 : ERROR_TYPE::TYPE,
44 0 : "trying to access a invalid position in a replacement list");
45 0 : }
46 0 : replacements_[pos] = type;
47 0 : return {};
48 0 : }
49 :
50 : [[nodiscard]] std::expected<std::string, Error>
51 0 : accept(const PrintTree &visitor) const noexcept override {
52 0 : return visitor.visit(this);
53 0 : }
54 :
55 : [[nodiscard]] std::expected<bool, Error>
56 0 : accept(const ValidateTree &visitor) const noexcept override {
57 0 : return visitor.visit(this);
58 0 : }
59 :
60 : [[nodiscard]] std::expected<std::monostate, Error>
61 0 : accept(const FillSemanticInfo &visitor) const noexcept override {
62 0 : return visitor.visit(this);
63 0 : }
64 :
65 : [[nodiscard]] std::expected<std::shared_ptr<Type>, Error>
66 0 : accept(const TypeAnalysis &visitor) const noexcept override {
67 0 : return visitor.visit(this);
68 0 : }
69 :
70 : [[nodiscard]] std::expected<std::monostate, Error>
71 0 : accept(const Monomorphize &visitor) const noexcept override {
72 0 : return visitor.visit(this);
73 0 : }
74 :
75 : [[nodiscard]] std::expected<std::shared_ptr<llvm::Value>, Error>
76 0 : accept(const CodeGeneration &visitor) const noexcept override {
77 0 : return visitor.visit(this);
78 0 : }
79 : };
80 :
81 : } // namespace nicole
82 :
83 : #endif
|