Bash++
Bash++ compiler internal documentation
IncludeStatement.h
Go to the documentation of this file.
1
6#pragma once
7
8#include <AST/ASTNode.h>
9#include <optional>
10
11namespace AST {
12
13class IncludeStatement : public ASTNode {
14 public:
15 enum class IncludeKeyword {
16 INCLUDE,
18 };
19
20 enum class IncludeType {
21 STATIC,
23 };
24
25 enum class PathType {
27 QUOTED
28 };
29 protected:
34 std::optional<AST::Token<std::string>> m_ASPATH;
35 public:
37 constexpr AST::NodeType getType() const override { return static_type; }
38
40 return m_KEYWORD;
41 }
42
44 m_KEYWORD = keyword;
45 }
46
48 return m_TYPE;
49 }
50
51 void setType(const AST::Token<IncludeType>& type) {
52 m_TYPE = type;
53 }
54
55 const PathType& PATHTYPE() const {
56 return m_PATHTYPE;
57 }
58
59 void setPathType(const PathType& pathtype) {
60 m_PATHTYPE = pathtype;
61 }
62
64 return m_PATH;
65 }
66
67 void setPath(const AST::Token<std::string>& path) {
68 m_PATH = path;
69 }
70
71 const std::optional<AST::Token<std::string>>& ASPATH() const {
72 return m_ASPATH;
73 }
74
75 void setAsPath(const AST::Token<std::string>& aspath) {
76 if (!aspath.getValue().empty()) m_ASPATH = aspath;
77 }
78
79 void clearAsPath() {
80 m_ASPATH = std::nullopt;
81 }
82
83 std::ostream& prettyPrint(std::ostream& os, int indentation_level = 0) const override {
84 std::string indent(indentation_level * PRETTYPRINT_INDENTATION_AMOUNT, ' ');
85 os << indent << "(IncludeStatement\n"
86 << indent << " @" << ((m_KEYWORD.getValue() == IncludeKeyword::INCLUDE) ? "include" : "include_once") << " "
87 << ((m_TYPE.getValue() == IncludeType::STATIC) ? "static" : "dynamic") << " "
88 << ((m_PATHTYPE == PathType::ANGLEBRACKET) ? "<" : "\"") << m_PATH
89 << ((m_PATHTYPE == PathType::ANGLEBRACKET) ? ">" : "\"");
90 if (m_ASPATH.has_value()) {
91 os << " as \"" << m_ASPATH.value() << "\"";
92 }
93 os << ")" << std::flush;
94 return os;
95 }
96};
97
98} // namespace AST
#define PRETTYPRINT_INDENTATION_AMOUNT
Definition ASTNode.h:18
The base class for all non-terminal nodes in the Bash++ AST. Each ASTNode contains information about ...
Definition ASTNode.h:28
Definition IncludeStatement.h:13
void clearAsPath()
Definition IncludeStatement.h:79
AST::Token< IncludeType > m_TYPE
Definition IncludeStatement.h:31
PathType
Definition IncludeStatement.h:25
const AST::Token< IncludeType > & TYPE() const
Definition IncludeStatement.h:47
std::ostream & prettyPrint(std::ostream &os, int indentation_level=0) const override
Definition IncludeStatement.h:83
void setKeyword(const AST::Token< IncludeKeyword > &keyword)
Definition IncludeStatement.h:43
PathType m_PATHTYPE
Definition IncludeStatement.h:32
static constexpr AST::NodeType static_type
Definition IncludeStatement.h:36
void setType(const AST::Token< IncludeType > &type)
Definition IncludeStatement.h:51
IncludeType
Definition IncludeStatement.h:20
void setPath(const AST::Token< std::string > &path)
Definition IncludeStatement.h:67
std::optional< AST::Token< std::string > > m_ASPATH
Definition IncludeStatement.h:34
AST::Token< std::string > m_PATH
Definition IncludeStatement.h:33
const std::optional< AST::Token< std::string > > & ASPATH() const
Definition IncludeStatement.h:71
void setPathType(const PathType &pathtype)
Definition IncludeStatement.h:59
IncludeKeyword
Definition IncludeStatement.h:15
const PathType & PATHTYPE() const
Definition IncludeStatement.h:55
const AST::Token< IncludeKeyword > & KEYWORD() const
Definition IncludeStatement.h:39
AST::Token< IncludeKeyword > m_KEYWORD
Definition IncludeStatement.h:30
const AST::Token< std::string > & PATH() const
Definition IncludeStatement.h:63
void setAsPath(const AST::Token< std::string > &aspath)
Definition IncludeStatement.h:75
constexpr AST::NodeType getType() const override
Definition IncludeStatement.h:37
A class representing a token in the Bash++ AST. Tokens store their value along with line and column i...
Definition Token.h:21
T value
Definition Token.h:23
const T & getValue() const
Definition Token.h:29
Definition AccessModifier.h:8
NodeType
Definition NodeTypes.h:9