Line data Source code
1 : #ifndef AST_STRUCT_H
2 : #define AST_STRUCT_H
3 :
4 : #include "ast_constructorDecl.h"
5 : #include "ast_destructorDecl.h"
6 : #include "ast_methodDecl.h"
7 : #include "attributes.h"
8 : #include <memory>
9 : #include <vector>
10 :
11 : namespace nicole {
12 :
13 : class AST_STRUCT final : public AST {
14 : private:
15 : std::string id_;
16 : mutable std::vector<GenericParameter> generics_;
17 : mutable std::shared_ptr<Type> fatherType_;
18 : mutable Attributes attributes_;
19 : mutable std::vector<std::shared_ptr<AST_METHOD_DECL>> methods_;
20 : mutable std::shared_ptr<AST_CONSTRUCTOR_DECL> constructor_;
21 : mutable std::shared_ptr<AST_DESTRUCTOR_DECL> destructor_;
22 :
23 : public:
24 : explicit AST_STRUCT(
25 : const long long unsigned nodeId, const SourceLocation &srcLoc,
26 : const std::string &id, const std::vector<GenericParameter> &generics,
27 : const std::shared_ptr<Type> &fatherType, const Attributes &attributes,
28 : const std::vector<std::shared_ptr<AST_METHOD_DECL>> &methods,
29 : const std::shared_ptr<AST_CONSTRUCTOR_DECL> &constructor,
30 : const std::shared_ptr<AST_DESTRUCTOR_DECL> &destructor) noexcept
31 0 : : AST(nodeId, AST_TYPE::STRUCT_DECL, srcLoc), id_{id},
32 0 : generics_{generics}, fatherType_{fatherType}, attributes_{attributes},
33 0 : methods_{methods}, constructor_{constructor}, destructor_{destructor} {}
34 :
35 0 : [[nodiscard]] const std::string &id() const noexcept { return id_; }
36 :
37 0 : [[nodiscard]] const std::vector<GenericParameter> &generics() const noexcept {
38 0 : return generics_;
39 0 : }
40 :
41 : void
42 0 : setGenerics(const std::vector<GenericParameter> &generics) const noexcept {
43 0 : generics_ = generics;
44 0 : }
45 :
46 0 : [[nodiscard]] const std::shared_ptr<Type> &fatherType() const noexcept {
47 0 : return fatherType_;
48 0 : }
49 :
50 0 : void setFatherType(const std::shared_ptr<Type> &fatherType) const noexcept {
51 0 : fatherType_ = fatherType;
52 0 : }
53 :
54 0 : [[nodiscard]] const Attributes &attributes() const noexcept {
55 0 : return attributes_;
56 0 : }
57 :
58 0 : void setAttributes(const Attributes &attributes) const noexcept {
59 0 : attributes_ = attributes;
60 0 : }
61 :
62 : [[nodiscard]] const std::vector<std::shared_ptr<AST_METHOD_DECL>> &
63 0 : methods() const noexcept {
64 0 : return methods_;
65 0 : }
66 :
67 : void setMethods(const std::vector<std::shared_ptr<AST_METHOD_DECL>> &methods)
68 0 : const noexcept {
69 0 : methods_ = methods;
70 0 : }
71 :
72 : [[nodiscard]] const std::shared_ptr<AST_CONSTRUCTOR_DECL> &
73 0 : constructor() const noexcept {
74 0 : return constructor_;
75 0 : }
76 :
77 : void setConstructor(
78 0 : const std::shared_ptr<AST_CONSTRUCTOR_DECL> &constructor) const noexcept {
79 0 : constructor_ = constructor;
80 0 : }
81 :
82 : [[nodiscard]] const std::shared_ptr<AST_DESTRUCTOR_DECL> &
83 0 : destructor() const noexcept {
84 0 : return destructor_;
85 0 : }
86 :
87 : void setDestructor(
88 0 : const std::shared_ptr<AST_DESTRUCTOR_DECL> &destructor) const noexcept {
89 0 : destructor_ = destructor;
90 0 : }
91 :
92 : // Métodos accept existentes...
93 : [[nodiscard]] std::expected<std::string, Error>
94 0 : accept(const PrintTree &visitor) const noexcept override {
95 0 : return visitor.visit(this);
96 0 : }
97 :
98 : [[nodiscard]] std::expected<bool, Error>
99 0 : accept(const ValidateTree &visitor) const noexcept override {
100 0 : return visitor.visit(this);
101 0 : }
102 :
103 : [[nodiscard]] std::expected<std::monostate, Error>
104 0 : accept(const FillSemanticInfo &visitor) const noexcept override {
105 0 : return visitor.visit(this);
106 0 : }
107 :
108 : [[nodiscard]] std::expected<std::shared_ptr<Type>, Error>
109 0 : accept(const TypeAnalysis &visitor) const noexcept override {
110 0 : return visitor.visit(this);
111 0 : }
112 :
113 : [[nodiscard]] std::expected<std::monostate, Error>
114 0 : accept(const Monomorphize &visitor) const noexcept override {
115 0 : return visitor.visit(this);
116 0 : }
117 :
118 : [[nodiscard]] std::expected<std::shared_ptr<llvm::Value>, Error>
119 0 : accept(const CodeGeneration &visitor) const noexcept override {
120 0 : return visitor.visit(this);
121 0 : }
122 : };
123 :
124 : } // namespace nicole
125 :
126 : #endif
|