SQLsmith  v1.2.1-5-gfacd7a8
A random SQL query generator
dump.cc
1 #include <string>
2 #include <sstream>
3 
4 #include "dump.hh"
5 #include "util.hh"
6 
7 using namespace std;
8 
9 std::string graphml_dumper::id(struct prod *p)
10 {
11  ostringstream os;
12  os << pretty_type(p) << "_" << p;
13  return os.str();
14 }
15 
16 graphml_dumper::graphml_dumper(ostream &out)
17  : o(out)
18 {
19  o << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" << endl <<
20  "<graphml xmlns=\"http://graphml.graphdrawing.org/xmlns\" " <<
21  "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " <<
22  "xsi:schemaLocation=\"http://graphml.graphdrawing.org/xmlns " <<
23  "http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd\">" << endl;
24 
25  o << "<key id=\"retries\" for=\"node\" "
26  "attr.name=\"retries\" attr.type=\"double\" />" << endl;
27  o << "<key id=\"label\" for=\"node\" "
28  "attr.name=\"label\" attr.type=\"string\" />" << endl;
29  o << "<key id=\"scope\" for=\"node\" "
30  "attr.name=\"scope\" attr.type=\"string\" />" << endl;
31 
32  o << "<graph id=\"ast\" edgedefault=\"directed\">" << endl;
33 
34 }
35 
36 void graphml_dumper::visit(struct prod *p)
37 {
38  o << "<node id=\"" << id(p) << "\">";
39  o << "<data key=\"retries\">" << p->retries << "</data>";
40  o << "<data key=\"label\">" << pretty_type(p) << "</data>";
41  o << "<data key=\"scope\">" << p->scope << "</data>";
42  o << "</node>" << endl;
43  if (p->pprod) {
44  o << "<edge source=\"" << id(p) << "\" target=\"" << id(p->pprod) << "\"/>";
45  }
46  o << endl;
47 }
48 
49 graphml_dumper::~graphml_dumper()
50 {
51  o << "</graph></graphml>" << endl;
52 }
53 
54 void ast_logger::generated(prod &query)
55 {
56  string filename("");
57  filename += "sqlsmith-";
58  filename += to_string(queries);
59  filename += ".xml";
60  ofstream os(filename);
61  graphml_dumper visitor(os);
62  query.accept(&visitor);
63  queries++;
64 }
Dump syntax trees as GraphML.
Base class for AST nodes.
Definition: prod.hh:17
struct scope * scope
Scope object to model column/table reference visibility.
Definition: prod.hh:22
struct prod * pprod
Parent production that instanciated this one.
Definition: prod.hh:20
long retries
Number of retries in this production.
Definition: prod.hh:27
virtual void accept(prod_visitor *v)
Visitor pattern for walking the AST.
Definition: prod.hh:41