1 ///////////////////////////////////////////////////////////////////////////////
2 // This file is generated automatically using Prop (version 2.3.5),
3 // last updated on Jun 18, 1997.
4 // The original source file is "paige.pcc".
5 ///////////////////////////////////////////////////////////////////////////////
7 #define PROP_REWRITING_USED
8 #define PROP_STRCMP_USED
9 #define PROP_QUARK_USED
10 #define PROP_TUPLE2_USED
16 #include <AD/pretty/postream.h>
18 #include "willard-ast.h"
20 ///////////////////////////////////////////////////////////////////////////////
22 // Constructor for the Paige/Goyal query transformer
24 ///////////////////////////////////////////////////////////////////////////////
25 PaigeGoyal::PaigeGoyal() : log(*new ofstream
), errlog(cerr
)
26 { True
= LIT(BOOL(true));
27 False
= LIT(BOOL(false));
61 ///////////////////////////////////////////////////////////////////////////////
63 // Destructor for the Paige/Goyal query transformer
65 ///////////////////////////////////////////////////////////////////////////////
66 PaigeGoyal::~PaigeGoyal()
70 ///////////////////////////////////////////////////////////////////////////////
72 // Method to add a subquery
74 ///////////////////////////////////////////////////////////////////////////////
75 void PaigeGoyal::add_subquery(Id x
, Exp e
)
77 // S << "Subquery: " << x << '=' << e << '\n';
81 list_1_(x
,subquery_names
)
93 Bool
PaigeGoyal::has_subqueries() const { return subqueries
!=
101 ///////////////////////////////////////////////////////////////////////////////
103 // Method to collect subqueries into a LET
105 ///////////////////////////////////////////////////////////////////////////////
106 Exp
PaigeGoyal::collect_subqueries(Exp exp
)
107 { exp
= make_let(subquery_names
, subqueries
, exp
);
125 ///////////////////////////////////////////////////////////////////////////////
127 // Method to make a nested LET
129 ///////////////////////////////////////////////////////////////////////////////
130 Exp
PaigeGoyal::make_let(Ids xs
, Exps es
, Exp exp
)
142 xs
= xs
->_2
; es
= es
->_2
;
156 ///////////////////////////////////////////////////////////////////////////////
158 // Methods to define/lookup the range of a variable
160 ///////////////////////////////////////////////////////////////////////////////
161 void PaigeGoyal::define_range(Id x
, Exp e
) { var_range
.insert(x
,e
); }
162 void PaigeGoyal::define_range(Ids xs
, Exps es
)
173 define_range(ids
->_1
,exps
->_1
); ids
= ids
->_2
; exps
= exps
->_2
;
196 errlog
<< "Arity mismatch in " << xs
<< "in" << es
<< ::newline
;
199 Exp
PaigeGoyal::range_of(Id x
)
200 { assert(var_range
.contains(x
));
204 ///////////////////////////////////////////////////////////////////////////////
206 // Method to print messages
208 ///////////////////////////////////////////////////////////////////////////////
209 void PaigeGoyal::message(const char * msg
, Exp e
)
210 { log
<< ::indent
<< e
<< ::newline
<< ::newline
<< ::unindent
211 << '[' << msg
<< ']' << ::newline
<< ::newline
;
214 void PaigeGoyal::error(const char * msg
, Exp e
)
215 { errlog
<< '[' << "ERROR:" << msg
<< ']' << ::newline
<< ::indent
216 << e
<< ::newline
<< ::unindent
;
219 void PaigeGoyal::set_log(ostream
& f
) { log
.set_stream(f
); }
220 void PaigeGoyal::set_error(ostream
& f
) { errlog
.set_stream(f
); }
222 ///////////////////////////////////////////////////////////////////////////////
224 // Method to add an edge into the query graph
226 ///////////////////////////////////////////////////////////////////////////////
227 void PaigeGoyal::add_edge(Id x
, Id y
)
228 { if (parent
.contains(y
))
231 errlog
<< "Edge: " << x
<< "->" << y
<< "conflicts with"
232 << z
<< "->" << y
<< "in the query graph\n";
237 Bool
PaigeGoyal::has_edge(Id x
, Id y
) const
238 { if (! parent
.contains(y
)) return false;
239 return parent
[y
] == x
;
242 void PaigeGoyal::add_edge_query(Id x
, Id y
, Exp q
)
245 #line 137 "paige.pcc"
246 #line 137 "paige.pcc"
248 #line 137 "paige.pcc"
249 #line 137 "paige.pcc"
253 ///////////////////////////////////////////////////////////////////////////////
255 // Method to compute the transitive closure of the query graph
257 ///////////////////////////////////////////////////////////////////////////////
258 void PaigeGoyal::compute_transitive_closure()
260 { parent_closure
.insert(parent
.key(i
),parent
.value(i
));
264 ///////////////////////////////////////////////////////////////////////////////
266 // Methods to push/pop from the quantifier stack
268 ///////////////////////////////////////////////////////////////////////////////
269 void PaigeGoyal::push_quantifier(Id x
) { quantifier_vars
.push(x
); }
270 void PaigeGoyal::push_quantifier(Ids xs
)
272 #line 158 "paige.pcc"
273 #line 158 "paige.pcc"
277 #line 158 "paige.pcc"
278 push_quantifier(xs
->_1
); xs
= xs
->_2
;
279 #line 158 "paige.pcc"
284 #line 158 "paige.pcc"
285 #line 158 "paige.pcc"
287 void PaigeGoyal::pop_quantifier(Id x
) { quantifier_vars
.pop(); }
288 void PaigeGoyal::pop_quantifier(Ids xs
)
290 #line 161 "paige.pcc"
291 #line 161 "paige.pcc"
295 #line 161 "paige.pcc"
296 pop_quantifier(xs
->_1
); xs
= xs
->_2
;
297 #line 161 "paige.pcc"
302 #line 161 "paige.pcc"
303 #line 161 "paige.pcc"
306 ///////////////////////////////////////////////////////////////////////////////
308 // Method to print the query graph
310 ///////////////////////////////////////////////////////////////////////////////
311 void PaigeGoyal::print_query_graph()
312 { log
<< ::tab
<< "[Query Graph]" << ::newline
<< ::indent
;
314 { Id x
= parent
.value(i
);
315 Id y
= parent
.key(i
);
316 log
<< ::tab
<< "edge" << x
<< "->" << y
;
317 if (edge_queries
.contains(
318 #line 174 "paige.pcc"
319 #line 174 "paige.pcc"
321 #line 174 "paige.pcc"
322 #line 174 "paige.pcc"
324 log
<< '\t' << edge_queries
[
325 #line 175 "paige.pcc"
326 #line 175 "paige.pcc"
328 #line 175 "paige.pcc"
329 #line 175 "paige.pcc"
336 ///////////////////////////////////////////////////////////////////////////////
338 // Main method to decompose a query
340 ///////////////////////////////////////////////////////////////////////////////
341 Exp
PaigeGoyal::decompose(Exp e
)
343 #line 187 "paige.pcc"
344 #line 187 "paige.pcc"
346 #line 187 "paige.pcc"
347 #line 187 "paige.pcc"
351 e
= remove_duplicate_names(e
);
352 e
= phase1(e
); // DNF construction
353 e
= construct_query_graph(e
); // query graph construction
354 e
= phase2(e
); // quantifier elimination
355 e
= phase3(e
); // disjunction removal
356 e
= phase4(e
); // conjunction removal
357 e
= projection_recognition(e
);
359 if (changed
) message("Reiterating the transformation",e
);
363 #line 202 "paige.pcc"
365 ------------------------------- Statistics -------------------------------
366 Merge matching rules = yes
367 Number of DFA nodes merged = 8
368 Number of ifs generated = 6
369 Number of switches generated = 0
372 Adaptive matching = disabled
373 Fast string matching = disabled
374 Inline downcasts = disabled
375 --------------------------------------------------------------------------