combine .cvsignore files into .gitignore file
[sppoc.git] / Omega / omega / omega_lib / src / pres_print.c
blobb27804a18f4946278ddc0926b9459c436fb21950
1 /* $Id: pres_print.c,v 1.2 2006/05/04 08:59:31 boulet Exp $ */
3 #include <basic/bool.h>
4 #include <omega/pres_gen.h>
5 #include <omega/pres_var.h>
6 #include <omega/pres_tree.h>
7 #include <omega/pres_conj.h>
8 #include <omega/Relation.h>
9 #include <basic/Bag.h>
10 #include <omega/omega_i.h>
11 #include <basic/Exit.h>
12 #include <omega/omega_core/oc.h>
16 ////////////////////////////////////////
17 // //
18 // Print functions. //
19 // //
20 ////////////////////////////////////////
22 void Conjunct::reorder_for_print(bool reverseOrder,
23 int first_pass_input,
24 int first_pass_output,
25 bool sort
26 ) {
28 Conjunct *C2 = copy_conj_same_relation();
29 Variable_ID_Tuple newpos(0),wcvars(0),gvars(0);
31 // We reorder the original Variable_ID's into the newpos list; later, we
32 // copy from their original column (using find_column) to the new one.
33 int n = mappedVars.size();
34 int i;
35 // there may be more inp/outp vars than maxVars; must do dynamically
36 skip_set_checks++;
37 Tuple<bool> input_used(myRelation->n_inp());
38 Tuple<bool> output_used(myRelation->n_out());
39 for(i=1; i<=myRelation->n_inp();i++) input_used[i] = false;
40 for(i=1; i<=myRelation->n_out();i++) output_used[i] = false;
41 for(i=1; i<=n;i++) {
42 if (mappedVars[i]->kind() == Input_Var)
43 input_used[mappedVars[i]->get_position()] = true;
44 else if (mappedVars[i]->kind() == Output_Var)
45 output_used[mappedVars[i]->get_position()] = true;
46 else if(mappedVars[i]->kind() == Global_Var)
47 gvars.append(mappedVars[i]);
51 if(sort)
52 for(i=1; i<=gvars.size();i++)
53 for(int j=1; j <= gvars.size(); j++)
54 if(gvars[j]->get_global_var()->base_name()
55 < gvars[j+1]->get_global_var()->base_name()) {
56 Variable_ID t = gvars[j]; gvars[j] = gvars[j+1]; gvars[j+1] = t;
59 newpos.join(gvars);
61 if(!reverseOrder) {
62 for(i=1; i<=min(myRelation->n_inp(),first_pass_input);i++)
63 if (input_used[i]) newpos.append(input_vars[i]);
64 for(i=1; i<=min(myRelation->n_out(),first_pass_output);i++)
65 if (output_used[i]) newpos.append(output_vars[i]);
66 for(i=max(1,first_pass_input+1); i<=myRelation->n_inp();i++)
67 if (input_used[i]) newpos.append(input_vars[i]);
68 for(i=max(1,first_pass_output+1); i<=myRelation->n_out();i++)
69 if (output_used[i]) newpos.append(output_vars[i]);
71 else {
72 for(i=1; i<=min(myRelation->n_out(),first_pass_output);i++)
73 if (output_used[i]) newpos.append(output_vars[i]);
74 for(i=1; i<=min(myRelation->n_inp(),first_pass_input);i++)
75 if (input_used[i]) newpos.append(input_vars[i]);
76 for(i=max(1,first_pass_output+1); i<=myRelation->n_out();i++)
77 if (output_used[i]) newpos.append(output_vars[i]);
78 for(i=max(1,first_pass_input+1); i<=myRelation->n_inp();i++)
79 if (input_used[i]) newpos.append(input_vars[i]);
83 for(i=1; i<=n;i++)
84 if (mappedVars[i]->kind() == Wildcard_Var)
85 wcvars.append(mappedVars[i]);
87 if(sort)
88 for(i=1; i<=gvars.size();i++)
89 for(int j=1; j <= gvars.size(); j++)
90 if(gvars[j]->name() < gvars[j+1]->name()) {
91 Variable_ID t = gvars[j]; gvars[j] = gvars[j+1]; gvars[j+1] = t;
94 newpos.join(wcvars);
96 assert(problem->nVars == newpos.size()); // i.e. no other variable types
98 // Copy coef columns into new order. Constant column is unchanged.
99 for(int e=0; e<problem->nGEQs; e++) problem->GEQs[e].touched = 1;
101 for(i=1; i<=problem->nVars; i++) {
102 int col = find_column(newpos[i]); // Find column in original conj.
103 assert(col != 0);
104 copy_column(problem, i, // Copy it from orig. column in the copy.
105 C2->problem, col, 0, 0);
106 problem->var[i] = i;
108 for(i=1; i<=problem->nVars; i++)
109 problem->forwardingAddress[i] = i;
111 mappedVars = newpos;
112 delete C2;
113 skip_set_checks--;
116 void Rel_Body::print_with_subs(FILE *output_file, bool printSym, bool newline)
118 String s = this->print_with_subs_to_string(printSym, newline);
119 fprintf(output_file, (const char *) s);
122 void Rel_Body::print_with_subs()
124 this->print_with_subs(stdout, 0, 1);
127 static
128 String tryToPrintVarToStringWithDiv(Conjunct *C, Variable_ID v) {
129 String s;
130 bool seen = false;
131 // This assumes that there is one EQ involving v, that v cannot be
132 // substituted and hence has a non-unit coefficient.
133 for(EQ_Iterator e(C); e; e++) {
134 if ((*e).get_coef(v) != 0) {
135 assert(!seen); // This asserts just one EQ with v
136 coef_t v_coef = (*e).get_coef(v);
137 int v_sign = v_coef > 0 ? 1 : -1;
138 v_coef *= v_sign;
139 int sign_adj = -v_sign;
141 s += "intDiv(";
142 bool first=true;
143 for(Constr_Vars_Iter i(*e,false); i; i++) {
144 if ((*i).var != v && (*i).coef != 0) {
145 coef_t this_coef = sign_adj*(*i).coef;
146 if(!first && this_coef > 0)
147 s+= "+";
148 if (this_coef == 1)
149 s += (*i).var->name();
150 else if (this_coef == -1)
152 s += "-"; s += (*i).var->name();
154 else
156 s += itoS(this_coef) + "*" + (*i).var->name();
158 first = false;
161 coef_t the_const = (*e).get_const()* sign_adj;
162 if (the_const > 0 && !first)
163 s+= "+";
164 if (the_const != 0)
165 s += itoS(the_const);
166 s += "," + itoS(v_coef) + ")";
167 seen = true;
170 return s;
174 // This function prints the output tuple of a relation with each one as a
175 // function of the input variables.
176 // This will fail or look goofy if the outputs are not affine functions of
177 // the inputs.
178 // BIG WARNING: Call this only from the codegen stuff, since it assumes things
179 // about coefficients
180 String Rel_Body::print_outputs_with_subs_to_string()
182 Rel_Body S(this),Q(this);
183 S.setup_names();
184 Conjunct *C = S.single_conjunct();
185 Conjunct *D = Q.single_conjunct(); // ordered_elimination futzes with conj
186 String s; // = "[";
187 C->reorder_for_print();
188 C->ordered_elimination(S.global_decls()->length());
189 // Print output names with substitutions in them
190 for(int i=1; i<=S.n_out(); i++) {
191 String t;
192 int col = C->find_column(output_vars[i]);
193 if (col != 0)
194 t = C->print_sub_to_string(col);
195 if (col == 0 || t == output_vars[i]->name()) // no sub found
196 // Assume you can't get a unit coefficient on v, must use div
197 t = tryToPrintVarToStringWithDiv(D,output_vars[i]);
198 s += t;
199 if (i < S.n_out()) s += ",";
201 // s += "] ";
202 return s;
205 String Rel_Body::print_outputs_with_subs_to_string(int i)
207 Rel_Body S(this),Q(this);
208 S.setup_names();
209 Conjunct *C = S.single_conjunct();
210 Conjunct *D = Q.single_conjunct(); // ordered_elimination futzes with conj
211 String s;
212 C->reorder_for_print();
213 C->ordered_elimination(S.global_decls()->length());
214 // Print output names with substitutions in them
216 String t;
217 int col = C->find_column(output_vars[i]);
218 if (col != 0)
219 t = C->print_sub_to_string(col);
220 if (col == 0 || t == output_vars[i]->name()) // no sub found?
221 t = tryToPrintVarToStringWithDiv(D,output_vars[i]);
222 // should check for failure
223 s += t;
225 return s;
228 String Rel_Body::print_with_subs_to_string(bool printSym, bool newline)
230 String s="";
232 if (pres_debug) {
233 fprintf(DebugFile,"print_with_subs_to_string:\n");
234 prefix_print(DebugFile);
237 int anythingPrinted = 0;
239 if (this->is_null())
241 s = "NULL Rel_Body\n";
242 return s;
245 Rel_Body R(this);
246 bool firstRelation = true;
248 for(DNF_Iterator DI(R.query_DNF()); DI.live(); DI.next()) {
250 Rel_Body S(&R, DI.curr());
251 Conjunct *C = S.single_conjunct();
252 if(!simplify_conj(C, true, 4, black)) continue;
254 S.setup_names();
256 if(! firstRelation)
258 s += " union";
259 if (newline) s += "\n ";
261 else
262 firstRelation = false;
264 anythingPrinted = 1;
266 C->reorder_for_print(false,C->max_ufs_arity_of_in(),
267 C->max_ufs_arity_of_out());
268 C->ordered_elimination(S.Symbolic.length()
269 +C->max_ufs_arity_of_in()
270 +C->max_ufs_arity_of_out());
271 // assert(C->problem->variablesInitialized);
273 if (pres_debug) S.prefix_print(DebugFile);
275 /* Do actual printing of Conjunct C as a relation */
276 s += "{";
278 if (!Symbolic.empty())
280 if (printSym) s += "Sym=[";
281 for (Variable_ID_Iterator Sym_I = S.Symbolic; Sym_I;)
283 if (printSym)
284 s += (*Sym_I)->name();
285 Sym_I++;
286 if (printSym && Sym_I) s+= ",";
288 if (printSym) s += "] ";
291 int i, col;
293 if (S.number_input != 0) {
294 s += "[";
295 // Print input names with substitutions in them
296 for(i=1; i<=S.number_input; i++) {
297 col = C->find_column(input_vars[i]);
298 if (col != 0)
299 s += C->problem->print_sub_to_string(col);
300 else
301 s += input_vars[i]->name();
302 if (i<S.number_input) s += ",";
304 s += "]";
307 if (! S.is_set())
308 s += " -> ";
310 if (S.number_output != 0)
312 s += "[";
314 // Print output names with substitutions in them
315 for(i=1; i<=S.number_output; i++) {
316 col = C->find_column(output_vars[i]);
317 if (col != 0)
318 s += C->problem->print_sub_to_string(col);
319 else
320 s += output_vars[i]->name();
321 if (i < S.number_output) s += ",";
323 s += "] ";
326 if (C->is_unknown())
328 if (S.number_input != 0 || S.number_output != 0)
329 s += ":";
330 s += " UNKNOWN";
332 else
335 // Empty conj means TRUE, so don't print colon
336 if (C->problem->nEQs != 0 || C->problem->nGEQs != 0) {
337 C->problem->clearSubs();
338 if (S.number_input != 0 || S.number_output != 0)
339 s += ":";
340 s += " ";
341 s += C->print_to_string(false);
343 else
345 if (S.number_input == 0 && S.number_output == 0)
346 s += " TRUE ";
350 s += "}";
353 if (!anythingPrinted)
355 R.setup_names();
356 s = "{";
357 s += R.print_variables_to_string(printSym);
358 if (R.number_input != 0 || R.number_output != 0)
359 s += " :";
360 s += " FALSE }";
361 if (newline) s += "\n";
362 return s;
365 if (newline) s += "\n";
366 return s;
370 void print_var_addrs(String &s, Variable_ID v) {
371 if(pres_debug>=2) {
372 char ss[20];
373 sprintf(ss, "(%p,%p)", v, v->remap);
374 s += ss;
378 String Rel_Body::print_variables_to_string(bool printSym)
380 String s="";
382 if (! Symbolic.empty())
384 if (printSym) s += " Sym=[";
385 for (Variable_ID_Iterator Sym_I(Symbolic); Sym_I; )
387 if (printSym) s += (*Sym_I)->name();
388 print_var_addrs(s, *Sym_I);
389 Sym_I++;
390 if (printSym && Sym_I) s += ",";
392 if (printSym) s += "] ";
394 int i;
396 if (number_input) {
397 s += "[";
398 for (i=1;i<=number_input;i++) {
399 s += input_vars[i]->name();
400 print_var_addrs(s, input_vars[i]);
401 if(i < number_input) s += ",";
403 s += "] ";
406 if (number_output)
408 s += "-> [";
409 for (i=1;i<=number_output;i++) {
410 s += output_vars[i]->name();
411 print_var_addrs(s, output_vars[i]);
412 if(i < number_output) s += ",";
414 s += "] ";
417 return s;
421 int F_Declaration::priority() {
422 return 3;
424 int Formula::priority () {
425 return 0;
428 int F_Or::priority() {
429 return 0;
431 int F_And::priority() {
432 return 1;
434 int Conjunct::priority() {
435 return 1;
438 int F_Not::priority() {
439 return 2;
444 // print() functions
446 void Formula::print(FILE *output_file)
448 if(myChildren.empty())
450 if(node_type()==Op_Relation || node_type()==Op_Or)
451 fprintf(output_file, "FALSE");
452 else if(node_type()==Op_And)
453 fprintf(output_file, "TRUE");
454 else
456 assert(0);
460 for(List_Iterator<Formula*> c(myChildren); c;)
462 if (node_type() == Op_Exists || node_type() == Op_Forall
463 || (*c)->priority() < priority())
464 fprintf(output_file, "( ");
465 (*c)->print(output_file);
466 if (node_type() == Op_Exists || node_type() == Op_Forall
467 || (*c)->priority() < priority())
468 fprintf(output_file, " )");
469 c++;
470 if(c.live())
471 print_separator(output_file);
475 String Rel_Body::print_formula_to_string() {
476 String s;
477 setup_names();
478 for(DNF_Iterator DI(query_DNF()); DI.live();) {
480 s += (*DI)->print_to_string(1);
481 DI.next();
482 if (DI.live()) s += " && ";
483 if (pres_debug) fprintf(DebugFile,"Partial print to string: %s\n",
484 (const char *) s);
486 return s;
489 void Rel_Body::print(FILE *output_file, bool printSym) {
490 if (this->is_null()) {
491 fprintf(output_file, "NULL Rel_Body\n");
492 return;
495 setup_names();
497 fprintf(output_file, "{");
499 String s = print_variables_to_string(printSym);
500 fprintf(output_file, (const char *) s);
502 if(simplified_DNF==NULL) {
503 Formula::print(output_file);
504 } else {
505 assert(children().empty());
506 simplified_DNF->print(output_file);
509 fprintf(output_file, " }\n");
512 void Rel_Body::print() {
513 this->print(stdout);
516 void F_Not::print(FILE *output_file) {
517 fprintf(output_file, " not ");
518 Formula::print(output_file);
521 void F_And::print_separator(FILE *output_file) {
522 fprintf(output_file, " and ");
525 void Conjunct::print(FILE *output_file) {
526 String s = print_to_string(true);
527 fprintf(output_file, (const char *) s);
530 String Conjunct::print_to_string(int true_printed) {
531 String s="";
533 int num = myLocals.size();
534 if(num) {
535 s += "Exists ( ";
536 int i;
537 for (i = 1; i <= num; i++) {
538 Variable_ID v = myLocals[i];
539 s += v->char_name();
540 if(i < num) s += ",";
542 if (true_printed || !(is_true())) s += " : ";
545 if(is_true()) {
546 s += true_printed ? "TRUE" : "";
547 } else {
548 if (is_unknown())
549 s += "UNKNOWN";
550 else {
551 s += problem->prettyPrintProblemToString();
552 if (!exact)
553 s += " && UNKNOWN";
558 if (num) s += ")";
559 return s;
562 void F_Or::print_separator(FILE *output_file) {
563 fprintf(output_file, " or ");
566 void F_Declaration::print(FILE *output_file) {
567 String s="";
568 for(Variable_ID_Iterator VI(myLocals); VI; ) {
569 s += (*VI)->name();
570 VI++;
571 if(VI) s += ",";
573 fprintf(output_file, "( %s : ", (const char *) s);
574 Formula::print(output_file);
575 fprintf(output_file, ")");
578 void F_Forall::print(FILE *output_file) {
579 fprintf(output_file, "forall ");
580 F_Declaration::print(output_file);
583 void F_Exists::print(FILE *output_file) {
584 fprintf(output_file, "exists ");
585 F_Declaration::print(output_file);
588 void Formula::print_separator(FILE *) {
589 assert(0); // should never be called, it's only for derived classes
593 // Setup names in formula.
596 typedef Set<Global_Var_ID> g_set;
597 void Rel_Body::setup_names() {
598 int i;
601 if (use_ugly_names) return;
603 if (pres_debug>=2)
604 fprintf(DebugFile,"Setting up names for 0x%p\n", this);
606 for(i=1; i<=number_input; i++) {
607 input_vars[i]->base_name = In_Names[i];
609 for(i=1; i<=number_output; i++) {
610 output_vars[i]->base_name = Out_Names[i];
613 g_set gbls;
615 wildCardInstanceNumber = 0;
617 for(i=1; i<= Symbolic.size(); i++) {
618 gbls.insert(Symbolic[i]->get_global_var());
621 foreach(g,Global_Var_ID,gbls,
622 g->instance = g->base_name()++);
624 for(i=1; i<=number_input; i++) {
625 if (!input_vars[i]->base_name.null())
626 input_vars[i]->instance = input_vars[i]->base_name++;
628 for(i=1; i<=number_output; i++) {
629 if (!output_vars[i]->base_name.null())
630 output_vars[i]->instance = output_vars[i]->base_name++;
633 if (simplified_DNF != NULL) // It is simplified
634 simplified_DNF->setup_names();
635 else // not simplified
636 Formula::setup_names();
638 for(i=1; i<=number_output; i++) {
639 if (!output_vars[i]->base_name.null())
640 output_vars[i]->base_name--;
642 for(i=1; i<=number_input; i++) {
643 if (!input_vars[i]->base_name.null())
644 input_vars[i]->base_name--;
646 foreach(g,Global_Var_ID,gbls, g->base_name()--);
649 void Formula::setup_names()
651 if (pres_debug>=2)
652 fprintf(DebugFile,"Setting up names for formula 0x%p\n", this);
654 for(List_Iterator<Formula*> c(myChildren); c; c++)
655 (*c)->setup_names();
658 void DNF::setup_names()
660 if (pres_debug>=2)
661 fprintf(DebugFile,"Setting up names for DNF 0x%p\n", this);
663 for(DNF_Iterator DI(this); DI.live(); DI.next())
664 DI.curr()->setup_names();
668 void F_Declaration::setup_names() {
669 if (pres_debug>=2)
670 fprintf(DebugFile,"Setting up names for Declaration 0x%p\n", this);
672 // Allow re-use of wc names in other scopes
673 int savedWildCardInstanceNumber = wildCardInstanceNumber;
675 for(Tuple_Iterator<Variable_ID> VI(myLocals); VI; VI++) {
676 Variable_ID v = *VI;
677 if (!v->base_name.null()) v->instance = v->base_name++;
678 else v->instance = wildCardInstanceNumber++;
681 for(List_Iterator<Formula*> c(children()); c; c++)
682 (*c)->setup_names();
684 for(Tuple_Iterator<Variable_ID> VI2(myLocals); VI2; VI2++) {
685 Variable_ID v = *VI2;
686 if (!v->base_name.null()) v->base_name--;
688 wildCardInstanceNumber = savedWildCardInstanceNumber;
693 // Prefix_print functions.
694 // Print Formula Tree, used in debugging.
696 static int level = 0;
698 void Formula::prefix_print(FILE *output_file, int debug)
700 for(List_Iterator<Formula*> c(children()); c; c++)
701 (*c)->prefix_print(output_file, debug);
702 level--;
706 void Rel_Body::prefix_print() {
707 this->prefix_print(stdout, 1);
710 void Rel_Body::prefix_print(FILE *output_file, int debug) {
711 int old_use_ugly_names = use_ugly_names;
712 use_ugly_names = 0;
714 setup_names();
716 level = 0;
717 if(pres_debug>=2) fprintf(output_file, "(@%p)", this);
718 fprintf(output_file, is_set() ? "SET: " : "RELATION: ");
719 String s = print_variables_to_string(true);
720 fprintf(output_file, "%s\n", (const char *) s);
722 if(simplified_DNF==NULL) {
723 Formula::prefix_print(output_file, debug);
724 } else {
725 assert(children().empty());
726 simplified_DNF->prefix_print(output_file, debug,true);
728 fprintf(output_file, "\n");
729 use_ugly_names = old_use_ugly_names;
733 void F_Forall::prefix_print(FILE *output_file, int debug) {
734 Formula::print_head(output_file);
735 fprintf(output_file, "FORALL [");
736 F_Declaration::prefix_print(output_file, debug);
737 for (Variable_ID_Iterator VI(myLocals); VI; VI++)
738 assert((*VI)->kind() == Forall_Var);
742 void F_Exists::prefix_print(FILE *output_file, int debug) {
743 Formula::print_head(output_file);
744 if(pres_debug>=2) fprintf(output_file, "(@%p)", this);
745 fprintf(output_file, "EXISTS [");
746 F_Declaration::prefix_print(output_file, debug);
747 for (Variable_ID_Iterator VI(myLocals); VI; VI++)
748 assert((*VI)->kind() == Exists_Var);
751 void F_Declaration::prefix_print(FILE *output_file, int debug) {
752 String s = "";
753 for (Variable_ID_Iterator VI(myLocals); VI; ) {
754 s += (*VI)->name();
755 print_var_addrs(s, *VI);
756 VI++;
757 if(VI) s += ",";
759 s += "]\n";
760 fprintf(output_file, (const char *) s);
761 Formula::prefix_print(output_file, debug);
764 void F_Or::prefix_print(FILE *output_file, int debug) {
765 Formula::print_head(output_file);
766 fprintf(output_file, "OR\n");
767 Formula::prefix_print(output_file, debug);
770 void F_And::prefix_print(FILE *output_file, int debug) {
771 Formula::print_head(output_file);
772 fprintf(output_file, "AND\n");
773 Formula::prefix_print(output_file, debug);
776 void F_Not::prefix_print(FILE *output_file, int debug) {
777 Formula::print_head(output_file);
778 fprintf(output_file, "NOT\n");
779 Formula::prefix_print(output_file, debug);
782 void Conjunct::prefix_print(FILE *output_file, int debug) {
783 static char dir_glyphs[] = { '-', '?', '+' };
785 if (debug)
787 Formula::print_head(output_file);
788 if(pres_debug>=2) fprintf(output_file, "(@%p)", this);
789 fprintf(output_file, "%s CONJUNCT, ",
790 exact ? "EXACT" : "INEXACT");
791 if (simplified) fprintf(output_file, "simplified, ");
792 if (verified) fprintf(output_file, "verified, ");
793 if (possible_leading_0s != -1 && guaranteed_leading_0s != -1)
794 assert (guaranteed_leading_0s <= possible_leading_0s);
795 if (guaranteed_leading_0s != -1
796 && guaranteed_leading_0s == possible_leading_0s)
797 fprintf(output_file,"# leading 0's = %d,", possible_leading_0s);
798 else if (possible_leading_0s != -1 || guaranteed_leading_0s != -1) {
799 if (guaranteed_leading_0s != -1)
800 fprintf(output_file,"%d <= ",guaranteed_leading_0s);
801 fprintf(output_file,"#O's");
802 if (possible_leading_0s != -1)
803 fprintf(output_file," <= %d",possible_leading_0s);
804 fprintf(output_file,", ");
806 if (dir_glyphs[leading_dir+1] != '?')
807 fprintf(output_file," first = %c, ", dir_glyphs[leading_dir+1]);
808 fprintf(output_file,"myLocals=[");
809 String s="";
810 for (Variable_ID_Iterator VI(myLocals); VI; ) {
811 assert( (*VI)->kind() == Wildcard_Var);
812 s += (*VI)->name();
813 print_var_addrs(s, *VI);
814 VI++;
815 if(VI) s += ",";
817 s += "] mappedVars=[";
818 for(Variable_ID_Iterator MVI(mappedVars); MVI; ) {
819 s += (*MVI)->name();
820 print_var_addrs(s, *MVI);
821 MVI++;
822 if(MVI) s += ",";
824 fprintf(output_file, "%s]\n", (const char *) s);
826 else
827 level++;
829 setOutputFile(output_file);
830 setPrintLevel(level+1);
831 problem->printProblem(debug);
832 setPrintLevel(0);
833 Formula::prefix_print(output_file, debug);
836 void Formula::print_head(FILE *output_file) {
837 level++;
838 int i;
839 for(i=0; i<level; i++) {
840 fprintf(output_file, ". ");
845 // Print DNF.
847 void DNF::print(FILE *out_file) {
848 DNF_Iterator p(this);
849 if (!p.live())
850 fprintf(out_file, "FALSE");
851 else
852 for(; p.live(); ) {
853 p.curr()->print(out_file);
854 p.next();
855 if(p.live())
856 fprintf(out_file, " OR ");
860 void DNF::prefix_print(FILE *out_file, int debug, bool parent_names_setup) {
862 wildCardInstanceNumber = 0;
863 Variable_ID_Tuple all_vars;
864 if(!use_ugly_names && !parent_names_setup) {
865 // We need to manually set up all of the input,output, and symbolic
866 // variables, since during simplification, a dnf's conjuncts may not
867 // be listed as part of a relation, or perhaps as part of different
868 // relations (?) (grr).
869 for(DNF_Iterator p0(this); p0.live(); p0.next()) {
870 for(Variable_Iterator vi((*p0)->mappedVars); vi; vi++)
871 if((*vi)->kind() != Wildcard_Var && all_vars.index(*vi) == 0)
872 all_vars.append(*vi);
873 (*p0)->setup_names();
875 foreach(v,Variable_ID,all_vars,
876 if (!v->base_name.null()) v->instance = v->base_name++;
877 else v->instance = wildCardInstanceNumber++;
881 int i = 1;
882 level = 0;
883 for(DNF_Iterator p(this); p.live(); p.next(), i++) {
884 fprintf(out_file, "#%d ", i);
885 if(*p == NULL)
886 fprintf(out_file, "(NULL)\n");
887 else
888 (*p)->prefix_print(out_file, debug);
891 foreach(v,Variable_ID,all_vars,if (!v->base_name.null()) v->base_name--);
893 fprintf(out_file, "\n");
896 String Constraint_Handle::print_to_string() const {
897 assert(0);
898 Exit(1);
899 return "FOO";
902 String EQ_Handle::print_to_string() const {
903 relation()->setup_names();
904 String s = c->print_EQ_to_string(e);
905 return s;
908 String GEQ_Handle::print_to_string() const {
909 relation()->setup_names();
910 String s = c->print_GEQ_to_string(e);
911 return s;
914 String Constraint_Handle::print_term_to_string() const {
915 assert(0);
916 Exit(1);
917 return "FOO";
920 String EQ_Handle::print_term_to_string() const {
921 relation()->setup_names();
922 String s = c->print_EQ_term_to_string(e);
923 return s;
926 String GEQ_Handle::print_term_to_string() const {
927 relation()->setup_names();
928 String s = c->print_GEQ_term_to_string(e);
929 return s;