/
expree_element.hpp
102 lines (62 loc) · 1.66 KB
/
expree_element.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#ifndef expree_ELEMENT_HPP_INCLUDED
#define expree_ELEMENT_HPP_INCLUDED
#include"expree_operator.hpp"
#include"expree_operand.hpp"
#include"expree_object.hpp"
#ifndef report
#define report printf("[report in %s] %d %s\n",__FILE__,__LINE__,__func__);
#endif
namespace expree{
struct Scope;
enum class
ElementKind
{
null,
operand,
operator_,
prefix_unary_operator,
suffix_unary_operator,
binary_operator,
};
union
ElementData
{
Operator operator_;
Operand operand;
ElementData(){}
~ElementData(){}
};
class
Element
{
ElementKind kind;
ElementData data;
Element* left=nullptr;
Element* right=nullptr;
public:
Element();
Element(Operand&& o);
Element(const Operator& o);
Element(const PrefixUnaryOperator& o);
Element(const SuffixUnaryOperator& o);
Element(const BinaryOperator& o);
Element(const Element& rhs) noexcept;
Element( Element&& rhs) noexcept;
~Element();
Element& operator=(const Element& rhs) noexcept;
Element& operator=( Element&& rhs) noexcept;
const ElementData* operator->() const{return &data;}
bool operator==(ElementKind k) const{return(kind == k);}
bool operator!=(ElementKind k) const{return(kind != k);}
ElementKind get_kind() const{return kind;}
Operand& as_operand(){return data.operand;}
void clear();
void insert_to_left( Element* e);
void insert_to_right(Element* e);
const Element* get_left() const{return left;}
const Element* get_right() const{return right;}
Object make_value(Scope* scope=nullptr, bool create_when_found_not=false) const;
void print() const;
};
}
#endif