Alexandria
2.31.0
SDC-CH common library for the Euclid project
Loading...
Searching...
No Matches
Pyston
src
lib
TextReprVisitor.cpp
Go to the documentation of this file.
1
19
#include "
Pyston/Util/TextReprVisitor.h
"
20
#include <sstream>
21
22
namespace
Pyston
{
23
24
TextReprVisitor::TextReprVisitor
(
std::ostream
& out_stream) : m_stream(out_stream) {}
25
26
void
TextReprVisitor::enter
(
const
NodeBase
*) {
27
m_stack
.
push_back
({});
28
}
29
30
void
TextReprVisitor::exit
(
const
NodeBase
* node) {
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
47
m_stack
.
pop_back
();
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
TextReprVisitor.h
std::list::back
T back(T... args)
std::ostream
std::ostringstream
std::string
Pyston::NodeBase
Definition
Node.h:39
Pyston::NodeBase::repr
virtual std::string repr() const =0
Pyston::TextReprVisitor::enter
void enter(const NodeBase *base) override
Definition
TextReprVisitor.cpp:26
Pyston::TextReprVisitor::m_stack
std::list< std::list< std::string > > m_stack
Definition
TextReprVisitor.h:52
Pyston::TextReprVisitor::exit
void exit(const NodeBase *node) override
Definition
TextReprVisitor.cpp:30
Pyston::TextReprVisitor::TextReprVisitor
TextReprVisitor(std::ostream &out_stream)
Definition
TextReprVisitor.cpp:24
Pyston::TextReprVisitor::m_stream
std::ostream & m_stream
Definition
TextReprVisitor.h:51
std::list::empty
T empty(T... args)
std::string::front
T front(T... args)
Pyston
Definition
ExceptionRaiser.h:28
std::list::pop_back
T pop_back(T... args)
std::list::push_back
T push_back(T... args)
std::string::size
T size(T... args)
std::ostringstream::str
T str(T... args)
Generated by
1.9.8