Bash++
Bash++ compiler internal documentation
IncludeStatement.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2025 Andrew S. Rightenburg
3 * Bash++: Bash with classes
4 * SPDX-License-Identifier: GPL-3.0-or-later
5 */
6
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 : uint8_t {
17 INCLUDE,
19 };
20
21 enum class IncludeType : uint8_t {
22 STATIC,
24 };
25
26 enum class PathType : uint8_t {
28 QUOTED
29 };
30 protected:
35 std::optional<AST::Token<std::string>> m_ASPATH;
36 public:
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, size_t 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:14
IncludeKeyword
Definition IncludeStatement.h:16
void clearAsPath()
Definition IncludeStatement.h:79
AST::Token< IncludeType > m_TYPE
Definition IncludeStatement.h:32
PathType
Definition IncludeStatement.h:26
constexpr IncludeStatement()
Definition IncludeStatement.h:37
const AST::Token< IncludeType > & TYPE() const
Definition IncludeStatement.h:47
void setKeyword(const AST::Token< IncludeKeyword > &keyword)
Definition IncludeStatement.h:43
PathType m_PATHTYPE
Definition IncludeStatement.h:33
void setType(const AST::Token< IncludeType > &type)
Definition IncludeStatement.h:51
void setPath(const AST::Token< std::string > &path)
Definition IncludeStatement.h:67
std::optional< AST::Token< std::string > > m_ASPATH
Definition IncludeStatement.h:35
AST::Token< std::string > m_PATH
Definition IncludeStatement.h:34
IncludeType
Definition IncludeStatement.h:21
const std::optional< AST::Token< std::string > > & ASPATH() const
Definition IncludeStatement.h:71
void setPathType(const PathType &pathtype)
Definition IncludeStatement.h:59
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:31
const AST::Token< std::string > & PATH() const
Definition IncludeStatement.h:63
void setAsPath(const AST::Token< std::string > &aspath)
Definition IncludeStatement.h:75
std::ostream & prettyPrint(std::ostream &os, size_t indentation_level=0) const override
Definition IncludeStatement.h:83
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:37
Definition AccessModifier.h:10
NodeType
Definition NodeTypes.h:12