1#include <sstream>
2#include <string>
3
4#include "dump.hh"
5#include "util.hh"
6
7using namespace std;
8
9std::string graphml_dumper::id(struct prod *p) {
10 ostringstream os;
11 os << pretty_type(p) << "_" << p;
12 return os.str();
13}
14
15graphml_dumper::graphml_dumper(ostream &out) : o(out) {
16 o << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" << endl
17 << "<graphml xmlns=\"http://graphml.graphdrawing.org/xmlns\" "
18 << "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" "
19 << "xsi:schemaLocation=\"http://graphml.graphdrawing.org/xmlns "
20 << "http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd\">" << endl;
21
22 o << "<key id=\"retries\" for=\"node\" "
23 "attr.name=\"retries\" attr.type=\"double\" />"
24 << endl;
25 o << "<key id=\"label\" for=\"node\" "
26 "attr.name=\"label\" attr.type=\"string\" />"
27 << endl;
28 o << "<key id=\"scope\" for=\"node\" "
29 "attr.name=\"scope\" attr.type=\"string\" />"
30 << endl;
31
32 o << "<graph id=\"ast\" edgedefault=\"directed\">" << endl;
33}
34
35void graphml_dumper::visit(struct prod *p) {
36 o << "<node id=\"" << id(p) << "\">";
37 o << "<data key=\"retries\">" << p->retries << "</data>";
38 o << "<data key=\"label\">" << pretty_type(p) << "</data>";
39 o << "<data key=\"scope\">" << p->scope << "</data>";
40 o << "</node>" << endl;
41 if (p->pprod) {
42 o << "<edge source=\"" << id(p) << "\" target=\"" << id(p->pprod) << "\"/>";
43 }
44 o << endl;
45}
46
47graphml_dumper::~graphml_dumper() {
48 o << "</graph></graphml>" << endl;
49}
50
51void ast_logger::generated(prod &query) {
52 string filename("");
53 filename += "sqlsmith-";
54 filename += to_string(queries);
55 filename += ".xml";
56 ofstream os(filename);
57 graphml_dumper visitor(os);
58 query.accept(&visitor);
59 queries++;
60}
61