-
Notifications
You must be signed in to change notification settings - Fork 128
/
dump.cc
64 lines (54 loc) · 1.71 KB
/
dump.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <string>
#include <sstream>
#include "dump.hh"
#include "util.hh"
using namespace std;
std::string graphml_dumper::id(struct prod *p)
{
ostringstream os;
os << pretty_type(p) << "_" << p;
return os.str();
}
graphml_dumper::graphml_dumper(ostream &out)
: o(out)
{
o << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" << endl <<
"<graphml xmlns=\"http://graphml.graphdrawing.org/xmlns\" " <<
"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " <<
"xsi:schemaLocation=\"http://graphml.graphdrawing.org/xmlns " <<
"http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd\">" << endl;
o << "<key id=\"retries\" for=\"node\" "
"attr.name=\"retries\" attr.type=\"double\" />" << endl;
o << "<key id=\"label\" for=\"node\" "
"attr.name=\"label\" attr.type=\"string\" />" << endl;
o << "<key id=\"scope\" for=\"node\" "
"attr.name=\"scope\" attr.type=\"string\" />" << endl;
o << "<graph id=\"ast\" edgedefault=\"directed\">" << endl;
}
void graphml_dumper::visit(struct prod *p)
{
o << "<node id=\"" << id(p) << "\">";
o << "<data key=\"retries\">" << p->retries << "</data>";
o << "<data key=\"label\">" << pretty_type(p) << "</data>";
o << "<data key=\"scope\">" << p->scope << "</data>";
o << "</node>" << endl;
if (p->pprod) {
o << "<edge source=\"" << id(p) << "\" target=\"" << id(p->pprod) << "\"/>";
}
o << endl;
}
graphml_dumper::~graphml_dumper()
{
o << "</graph></graphml>" << endl;
}
void ast_logger::generated(prod &query)
{
string filename("");
filename += "sqlsmith-";
filename += to_string(queries);
filename += ".xml";
ofstream os(filename);
graphml_dumper visitor(os);
query.accept(&visitor);
queries++;
}