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