1 #include <AD/pretty/postream.h>
2 #include "querygraph.ph"
4 ///////////////////////////////////////////////////////////////////////////////
6 // Constructor and destructor for query graph construction
8 ///////////////////////////////////////////////////////////////////////////////
9 QueryGraphConstruction::QueryGraphConstruction() {}
10 QueryGraphConstruction::~QueryGraphConstruction() {}
12 ///////////////////////////////////////////////////////////////////////////////
14 // Method to invoke the query graph construction phase
16 ///////////////////////////////////////////////////////////////////////////////
17 Exp QueryGraphConstruction::construct_query_graph(Exp e)
18 { message("Constructing the query graph", e);
19 parent.clear(); // clears the query graph
20 (*this)(e); // construct the graph
21 compute_transitive_closure(); // compute the transitive closure
26 ///////////////////////////////////////////////////////////////////////////////
28 // Method to check whether a variable preceeds another in the quantifier
31 ///////////////////////////////////////////////////////////////////////////////
32 Bool QueryGraphConstruction::preceeds(Id x, Id y) const
33 { for (int i = 0; i < quantifier_vars.size(); i++)
34 { if (quantifier_vars[i] == x)
35 { for (int j = i+1; j < quantifier_vars.size(); j++)
36 if (quantifier_vars[j] == y) return true;
43 ///////////////////////////////////////////////////////////////////////////////
45 // Transformation rules
47 ///////////////////////////////////////////////////////////////////////////////
48 rewrite QueryGraphConstruction
52 // Push and pop quantifier names.
55 FORALL(x,_,_): { push_quantifier(x); }
56 | EXISTS(x,_,_): { push_quantifier(x); }
57 | GENERATOR(xs,_,_): { push_quantifier(xs); }
60 | FORALL(x,_,_): { pop_quantifier(x); }
61 | EXISTS(x,_,_): { pop_quantifier(x); }
62 | GENERATOR(xs,_,_): { pop_quantifier(xs); }
64 // Locate all atomic predicates and add edges into the query graph
66 | OP("=" || "/=" || "<" || ">" || "<=" || ">=" || "#",es):
68 // Collect all free variables in this expression.
72 // Now add edges to the query graph.
77 if (x != y && preceeds(x,y)) add_edge(x,y);