Bash++
Bash++ compiler internal documentation
DynamicCastTarget.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 DynamicCastTarget : public ASTNode {
15 protected:
16 std::optional<AST::Token<std::string>> m_TARGETTYPE;
17 public:
19
20 void setTargetType(const AST::Token<std::string>& target_type) {
21 m_TARGETTYPE = target_type;
22 }
23 const std::optional<AST::Token<std::string>>& TARGETTYPE() const {
24 return m_TARGETTYPE;
25 }
26
27 std::ostream& prettyPrint(std::ostream& os, size_t indentation_level = 0) const override {
28 std::string indent(indentation_level * PRETTYPRINT_INDENTATION_AMOUNT, ' ');
29 os << indent << "(DynamicCastTarget"
30 << (m_TARGETTYPE.has_value() ? " " + m_TARGETTYPE->getValue() : "");
31 for (const auto& child : children) {
32 os << std::endl;
33 child->prettyPrint(os, indentation_level + 1);
34 }
35 os << ")" << std::flush;
36 return os;
37 }
38};
39
40} // 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
std::vector< std::shared_ptr< ASTNode > > children
Definition ASTNode.h:32
Definition DynamicCastTarget.h:14
const std::optional< AST::Token< std::string > > & TARGETTYPE() const
Definition DynamicCastTarget.h:23
std::optional< AST::Token< std::string > > m_TARGETTYPE
Definition DynamicCastTarget.h:16
std::ostream & prettyPrint(std::ostream &os, size_t indentation_level=0) const override
Definition DynamicCastTarget.h:27
void setTargetType(const AST::Token< std::string > &target_type)
Definition DynamicCastTarget.h:20
constexpr DynamicCastTarget()
Definition DynamicCastTarget.h:18
A class representing a token in the Bash++ AST. Tokens store their value along with line and column i...
Definition Token.h:22
Definition AccessModifier.h:10
NodeType
Definition NodeTypes.h:12