ExpressionPrinter.hh
2.63 KB
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#ifndef EXPRESSIONPRINTER_HH_
#define EXPRESSIONPRINTER_HH_
#include "ExpressionContainer.hh"
//#define ADD_DEBUG_TAG
namespace AMDA {
namespace parser {
namespace Expression {
class ExpressionPrinter : public boost::static_visitor<void>
{
public:
ExpressionPrinter(std::ostream& os) : _os(os) {}
std::ostream& _os;
void operator()(const var& v) const {
#ifdef ADD_DEBUG_TAG
_os << "@VAR@";
#endif
_os << v;
}
void operator()(const BinaryOperation& b) const {
#ifdef ADD_DEBUG_TAG
_os << "@BINOP@";
#endif
_os << "(";
boost::apply_visitor(*this, b.l);
_os << b.op.kernelSymbol;
boost::apply_visitor(*this, b.r);
_os << ")";
}
void operator()(const UnaryOperation& u) const{
#ifdef ADD_DEBUG_TAG
_os << "@UNOP@";
#endif
_os << u.op.kernelSymbol;
boost::apply_visitor(*this, u.e);
}
void operator()(const PowerOperation& p) const{
#ifdef ADD_DEBUG_TAG
_os << "@POWER@";
#endif
_os << "pow(";
boost::apply_visitor(*this, p.l);
_os << ",";
boost::apply_visitor(*this, p.r);
_os << ")";
}
void operator()(const FunctionOperation& f) const{
#ifdef ADD_DEBUG_TAG
_os << "@FUNC@";
#endif
_os << f.func << "(";
bool isProcess = (!f.func.empty() && (f.func[0] == '#'));
for (unsigned int i = 0; i < f.args.size(); ++i) {
if (i != 0) {
_os << (isProcess ? ";" : ",");
}
boost::apply_visitor(*this, f.args[i]);
}
_os << ")";
}
void operator()(const ParameterDef& p) const{
#ifdef ADD_DEBUG_TAG
_os << "@PARAM@";
#endif
std::string components = "";
std::string prefix = "";
std::string suffix = "";
if ((p.components.size() == 1) && (p.components[0].compare("*") != 0)) {
components += "[";
components += p.components[0];
components += "]";
}
else if (p.components.size() == 2) {
if (p.components[0].compare("*") == 0) {
if (p.components[1].compare("*") != 0) {
// Extract column
prefix = "(";
suffix = ").getColumn(";
suffix += p.components[1];
suffix += ")";
}
else {
// *,* => no components defined
}
}
else if (p.components[1].compare("*") == 0) {
components += "[";
components += p.components[0];
components += "]";
}
else {
components += "[";
components += p.components[0];
components += "][";
components += p.components[1];
components += "]";
}
}
_os << prefix;
_os << "$";
_os << p.param;
_os << suffix;
_os << components;
}
};
std::ostream& operator<<(std::ostream& os, const ExpressionContainer& e)
{
boost::apply_visitor(ExpressionPrinter(os), e);
return os;
}
} /* namespace Expression */
} /* namespace parser */
} /* namespace AMDA */
#endif