SQLsmith  v1.2.1-5-gfacd7a8
A random SQL query generator
prod.cc
Go to the documentation of this file.
1 #include <typeinfo>
4 #include <stdexcept>
5 #include "prod.hh"
6 #include "impedance.hh"
7 
8 prod::prod(struct prod *parent)
9  : pprod(parent)
10 {
11  if (parent) {
12  level = parent->level + 1;
13  scope = parent->scope;
14  } else {
15  scope = 0;
16  level = 0;
17  }
18 }
19 
20 void prod::indent(std::ostream &out)
21 {
22  out << std::endl;
23  for (int i = 0; i < level; i++)
24  out << " ";
25 }
26 
28 {
29  impedance::retry(this);
30  if (retries++ <= retry_limit)
31  return;
32 
33  impedance::limit(this);
34  throw std::runtime_error(std::string("excessive retries in ")
35  + typeid(*this).name());
36 }
37 
39 {
40  if (!impedance::matched(this))
41  throw std::runtime_error("impedance mismatch");
42 }
43 
44 void prod::fail(const char *reason)
45 {
46  impedance::fail(this);
47  throw std::runtime_error(reason);
48 }
feedback to the grammar about failed productions
Base class for grammar productions.
Base class for AST nodes.
Definition: prod.hh:17
virtual void indent(std::ostream &out)
Newline and indent according to tree level.
Definition: prod.cc:20
void retry()
Increase the retry count and throw an exception when retry_limit is exceeded.
Definition: prod.cc:27
struct scope * scope
Scope object to model column/table reference visibility.
Definition: prod.hh:22
long retry_limit
Maximum number of retries allowed before reporting a failure to the Parent prod.
Definition: prod.hh:30
int level
Level of this production in the AST. 0 for root node.
Definition: prod.hh:24
virtual void out(std::ostream &out)=0
Emit SQL for this production.
virtual void fail(const char *reason)
Report a "failed to generate" error.
Definition: prod.cc:44
long retries
Number of retries in this production.
Definition: prod.hh:27
virtual void match()
Check with the impedance matching code whether this production has been blacklisted and throw an exce...
Definition: prod.cc:38