Bash++
Bash++ compiler internal documentation
ObjectReference.h
Go to the documentation of this file.
1
7#pragma once
8
9#include <AST/ASTNode.h>
10
11namespace AST {
12
13class ObjectReference : public ASTNode {
14 protected:
16 std::vector<AST::Token<std::string>> m_IDENTIFIERS;
17 bool m_has_hashkey = false;
18 bool m_lvalue = false;
19 bool m_self_reference = false;
20 bool m_ptr_dereference = false;
21 bool m_address_of = false;
22 public:
24 constexpr AST::NodeType getType() const override { return static_type; }
25
26 void setIdentifier(const AST::Token<std::string>& identifier) {
27 m_IDENTIFIER = identifier;
28 }
30 return m_IDENTIFIER;
31 }
32
33 void addIdentifier(const AST::Token<std::string>& identifier) {
34 m_IDENTIFIERS.push_back(identifier);
35 }
36 const std::vector<AST::Token<std::string>>& IDENTIFIERS() const {
37 return m_IDENTIFIERS;
38 }
39
40 void setHasHashkey(bool has_hashkey) {
41 m_has_hashkey = has_hashkey;
42 }
43 bool hasHashkey() const {
44 return m_has_hashkey;
45 }
46
47 void setLvalue(bool lvalue) {
48 m_lvalue = lvalue;
49 }
50 bool isLvalue() const {
51 return m_lvalue;
52 }
53
54 void setSelfReference(bool self_reference) {
55 m_self_reference = self_reference;
56 }
57 bool isSelfReference() const {
58 return m_self_reference;
59 }
60
61 void setPointerDereference(bool ptr_dereference) {
62 m_ptr_dereference = ptr_dereference;
63 }
64 bool isPointerDereference() const {
65 return m_ptr_dereference;
66 }
67
68 void setAddressOf(bool address_of) {
69 m_address_of = address_of;
70 }
71 bool isAddressOf() const {
72 return m_address_of;
73 }
74
75 std::ostream& prettyPrint(std::ostream& os, int indentation_level = 0) const override {
76 std::string indent(indentation_level * PRETTYPRINT_INDENTATION_AMOUNT, ' ');
77 os << indent << "(ObjectReference ["
78 << (m_lvalue ? "lvalue" : "rvalue")
79 << (m_self_reference ? ", self" : "")
80 << "]\n"
81 << indent << " "
82 << (m_address_of ? "&" : "")
83 << (m_ptr_dereference ? "*" : "")
84 << "@";
85
86 if (m_has_hashkey) {
87 os << "#";
88 }
89
90 os << m_IDENTIFIER;
91 for (const auto& id : m_IDENTIFIERS) {
92 os << "." << id;
93 }
94
95 for (const auto& child : children) {
96 os << std::endl;
97 child->prettyPrint(os, indentation_level + 1);
98 }
99 os << ")" << std::flush;
100 return os;
101 }
102};
103
104} // 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
std::vector< std::shared_ptr< ASTNode > > children
Definition ASTNode.h:31
Definition ObjectReference.h:13
bool isAddressOf() const
Definition ObjectReference.h:71
bool m_has_hashkey
Definition ObjectReference.h:17
constexpr AST::NodeType getType() const override
Definition ObjectReference.h:24
bool isSelfReference() const
Definition ObjectReference.h:57
bool isLvalue() const
Definition ObjectReference.h:50
void setHasHashkey(bool has_hashkey)
Definition ObjectReference.h:40
static constexpr AST::NodeType static_type
Definition ObjectReference.h:23
void setLvalue(bool lvalue)
Definition ObjectReference.h:47
void setIdentifier(const AST::Token< std::string > &identifier)
Definition ObjectReference.h:26
std::vector< AST::Token< std::string > > m_IDENTIFIERS
Definition ObjectReference.h:16
std::ostream & prettyPrint(std::ostream &os, int indentation_level=0) const override
Definition ObjectReference.h:75
bool isPointerDereference() const
Definition ObjectReference.h:64
bool m_ptr_dereference
Definition ObjectReference.h:20
void setAddressOf(bool address_of)
Definition ObjectReference.h:68
const AST::Token< std::string > & IDENTIFIER() const
Definition ObjectReference.h:29
bool hasHashkey() const
Definition ObjectReference.h:43
bool m_self_reference
Definition ObjectReference.h:19
bool m_address_of
Definition ObjectReference.h:21
const std::vector< AST::Token< std::string > > & IDENTIFIERS() const
Definition ObjectReference.h:36
void setSelfReference(bool self_reference)
Definition ObjectReference.h:54
AST::Token< std::string > m_IDENTIFIER
Definition ObjectReference.h:15
bool m_lvalue
Definition ObjectReference.h:18
void setPointerDereference(bool ptr_dereference)
Definition ObjectReference.h:61
void addIdentifier(const AST::Token< std::string > &identifier)
Definition ObjectReference.h:33
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:9
NodeType
Definition NodeTypes.h:10