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