tcalc 0.2.0
 
Loading...
Searching...
No Matches
program.hpp
Go to the documentation of this file.
1
12#pragma once
13
14#include <vector>
15
16#include "tcalc/ast/node.hpp"
17#include "tcalc/common.hpp"
18
19namespace tcalc::ast {
20
25class ProgramNode : public Node
26{
27private:
28 std::vector<NodePtr<>> _statements;
29
30public:
36 : ProgramNode{ {} }
37 {
38 }
39
45 explicit ProgramNode(std::vector<NodePtr<>> statements)
47 , _statements{ std::move(statements) }
48 {
49 }
50
51 ~ProgramNode() override = default;
52
58 [[nodiscard]] TCALC_INLINE auto& statements() const noexcept
59 {
60 return _statements;
61 }
62
68 TCALC_INLINE auto& statements() noexcept { return _statements; }
69
75 TCALC_INLINE void push_statement(NodePtr<> statement)
76 {
77 _statements.push_back(std::move(statement));
78 }
79};
80
85class ProgramImportNode : public Node
86{
87private:
88 std::string _path;
89
90public:
96 explicit ProgramImportNode(std::string path)
97 : Node{ NodeType::IMPORT }
98 , _path{ std::move(path) }
99 {
100 }
101
102 ~ProgramImportNode() override = default;
103
109 [[nodiscard]] TCALC_INLINE auto& path() const noexcept { return _path; }
110
116 TCALC_INLINE auto& path() noexcept { return _path; }
117
123 TCALC_INLINE void path(std::string path) noexcept { _path = std::move(path); }
124};
125
126}
Base class for AST nodes.
Definition node.hpp:87
Program import node.
Definition program.hpp:86
TCALC_INLINE auto & path() noexcept
Get path.
Definition program.hpp:116
TCALC_INLINE void path(std::string path) noexcept
Set path.
Definition program.hpp:123
ProgramImportNode(std::string path)
Construct a new Program Import Node object.
Definition program.hpp:96
TCALC_INLINE auto & path() const noexcept
Get path.
Definition program.hpp:109
Program node.
Definition program.hpp:26
TCALC_INLINE auto & statements() const noexcept
Get statements.
Definition program.hpp:58
TCALC_INLINE void push_statement(NodePtr<> statement)
Push a statement.
Definition program.hpp:75
TCALC_INLINE auto & statements() noexcept
Get statements.
Definition program.hpp:68
ProgramNode(std::vector< NodePtr<> > statements)
Construct a new Program Node object with statements.
Definition program.hpp:45
ProgramNode()
Construct a new Program Node object without statements.
Definition program.hpp:35
tcalc common header.
Base class for AST nodes.
std::shared_ptr< NT > NodePtr
Shared pointer to a node.
Definition node.hpp:119
NodeType
AST node type.
Definition node.hpp:30