Line data Source code
1 : #ifndef AST_H
2 : #define AST_H
3 :
4 : #include "../../lexicalAnalysis/sourceLocation.h"
5 : #include "../../visitors/codeGeneration/codeGeneration.h"
6 : #include "../../visitors/fillSemanticInfo/fillSemanticInfo.h"
7 : #include "../../visitors/monomorphize/monomorphize.h"
8 : #include "../../visitors/printTree/printTree.h"
9 : #include "../../visitors/typeAnalysis/typeAnalysis.h"
10 : #include "../../visitors/validateTree/validateTree.h"
11 : #include "astType.h"
12 : #include <memory>
13 : #include <variant>
14 :
15 : namespace nicole {
16 :
17 : class AST {
18 : private:
19 : long long unsigned nodeId_;
20 : AST_TYPE type_;
21 : std::weak_ptr<AST> father_;
22 : SourceLocation srcLoc_;
23 : mutable std::shared_ptr<Type> returnedFromTypeAnalysis_{nullptr};
24 :
25 : public:
26 : explicit AST(const long long unsigned nodeId, const AST_TYPE type,
27 : const SourceLocation &srcLoc) noexcept
28 130 : : nodeId_{nodeId}, type_{type}, srcLoc_{srcLoc} {}
29 :
30 1170 : virtual ~AST() noexcept = default;
31 :
32 0 : [[nodiscard]] long long unsigned nodeId() const noexcept { return nodeId_; }
33 :
34 72 : [[nodiscard]] AST_TYPE type() const noexcept { return type_; }
35 :
36 9 : [[nodiscard]] const std::shared_ptr<AST> father() const noexcept {
37 9 : return father_.lock();
38 9 : }
39 :
40 0 : [[nodiscard]] const SourceLocation &srcLoc() const noexcept {
41 0 : return srcLoc_;
42 0 : }
43 :
44 : [[nodiscard]] const std::shared_ptr<Type> &
45 0 : returnedFromTypeAnalysis() const noexcept {
46 0 : return returnedFromTypeAnalysis_;
47 0 : }
48 :
49 513 : void setFather(const std::shared_ptr<AST> &father) noexcept {
50 513 : father_ = father;
51 513 : }
52 :
53 : void
54 0 : setReturnedFromAnalysis(const std::shared_ptr<Type> &type) const noexcept {
55 0 : returnedFromTypeAnalysis_ = type;
56 0 : }
57 :
58 : [[nodiscard]] virtual std::expected<std::string, Error>
59 : accept(const PrintTree &visitor) const noexcept = 0;
60 :
61 : [[nodiscard]] virtual std::expected<bool, Error>
62 : accept(const ValidateTree &visitor) const noexcept = 0;
63 :
64 : [[nodiscard]] virtual std::expected<std::monostate, Error>
65 : accept(const FillSemanticInfo &visitor) const noexcept = 0;
66 :
67 : [[nodiscard]] virtual std::expected<std::shared_ptr<Type>, Error>
68 : accept(const TypeAnalysis &visitor) const noexcept = 0;
69 :
70 : [[nodiscard]] virtual std::expected<std::monostate, Error>
71 : accept(const Monomorphize &visitor) const noexcept = 0;
72 :
73 : [[nodiscard]] virtual std::expected<std::shared_ptr<llvm::Value>, Error>
74 : accept(const CodeGeneration &visitor) const noexcept = 0;
75 : };
76 :
77 : } // namespace nicole
78 :
79 : #endif // AST_H
|