-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathprinter.cc
46 lines (40 loc) · 1.36 KB
/
printer.cc
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
/*
* Use and distribution licensed under the Apache license version 2.
*
* See the COPYING file in the root project directory for full text.
*/
#include <sqltoast/print.h>
#include "node.h"
#include "fill.h"
#include "printer.h"
namespace sqltoaster {
std::ostream& operator<< (std::ostream& out, printer_t& ptr) {
if (ptr.output_format == OUTPUT_FORMAT_DEFAULT) {
unsigned int x = 0;
for (auto stmt_ptr_it = ptr.res.statements.cbegin();
stmt_ptr_it != ptr.res.statements.cend();
stmt_ptr_it++) {
out << std::endl << "statements[" << x++ << "]:" << std::endl;
out << " " << *(*stmt_ptr_it);
}
} else {
ptr.process_statements();
if (ptr.statement_node_count()) {
mapping_t statements;
statements.setattr("statements", ptr.statements);
print_map(out, statements, 0, false);
}
}
return out;
}
void printer_t::process_statements() {
std::unique_ptr<node_t> statement_node;
for (std::unique_ptr<sqltoast::statement_t>& stmt : res.statements) {
std::unique_ptr<node_t> statement_node = std::make_unique<mapping_t>();
mapping_t& statement_map =
static_cast<mapping_t&>(*statement_node);
fill(statement_map, *stmt);
add_statement_node(statement_node);
}
}
} // namespace sqltoaster