Alexandria
2.27.0
SDC-CH common library for the Euclid project
Main Page
Related Pages
Namespaces
Classes
Files
Examples
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
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
std::list::empty
T empty(T...args)
Pyston::TextReprVisitor::m_stack
std::list< std::list< std::string > > m_stack
Definition:
TextReprVisitor.h:52
Pyston::TextReprVisitor::TextReprVisitor
TextReprVisitor(std::ostream &out_stream)
Definition:
TextReprVisitor.cpp:24
std::string::front
T front(T...args)
Pyston::TextReprVisitor::exit
void exit(const NodeBase *node) override
Definition:
TextReprVisitor.cpp:30
std::string
STL class.
std::list::push_back
T push_back(T...args)
std::ostringstream
STL class.
std::list::pop_back
T pop_back(T...args)
std::ostringstream::str
T str(T...args)
std::string::size
T size(T...args)
Pyston::NodeBase
Definition:
Node.h:39
std::list::back
T back(T...args)
Pyston::TextReprVisitor::enter
void enter(const NodeBase *base) override
Definition:
TextReprVisitor.cpp:26
TextReprVisitor.h
Pyston::TextReprVisitor::m_stream
std::ostream & m_stream
Definition:
TextReprVisitor.h:51
std::ostream
STL class.
Pyston::NodeBase::repr
virtual std::string repr() const =0
Generated by
1.8.5