Alexandria 2.31.0
SDC-CH common library for the Euclid project
Loading...
Searching...
No Matches
TextReprVisitor.cpp
Go to the documentation of this file.
1
20#include <sstream>
21
22namespace Pyston {
23
24TextReprVisitor::TextReprVisitor(std::ostream& out_stream) : m_stream(out_stream) {}
25
29
31 const auto& children = m_stack.back();
32 std::ostringstream self_repr;
33 std::string node_repr = node->repr();
34
35 if (children.size() == 1 && node_repr.size() == 1) {
36 self_repr << node->repr() << children.front();
37 } else if (children.size() == 1) {
38 self_repr << node->repr() << '(' << children.front() << ')';
39 } else if (children.size() == 2 && node_repr.size() == 1) {
40 self_repr << '(' << children.front() << ' ' << node->repr() << ' ' << children.back() << ')';
41 } else if (children.size() == 2) {
42 self_repr << node->repr() << '(' << children.front() << ", " << children.back() << ')';
43 } else {
44 self_repr << node->repr();
45 }
46
48 if (!m_stack.empty()) {
49 m_stack.back().push_back(self_repr.str());
50 } else {
51 m_stream << self_repr.str();
52 }
53}
54
55} // end of namespace Pyston
T back(T... args)
virtual std::string repr() const =0
void enter(const NodeBase *base) override
std::list< std::list< std::string > > m_stack
void exit(const NodeBase *node) override
TextReprVisitor(std::ostream &out_stream)
T empty(T... args)
T front(T... args)
T pop_back(T... args)
T push_back(T... args)
T size(T... args)
T str(T... args)