cex: minor style changes

* src/counterexample.h, src/derivation.h, src/derivation.c:
More comments.
Use `out` for FILE*, as elsewhere.
This commit is contained in:
Akim Demaille
2020-07-12 13:13:22 +02:00
parent d8c2af56c1
commit 1e12219775
3 changed files with 34 additions and 25 deletions

View File

@@ -20,11 +20,17 @@
#ifndef COUNTEREXAMPLE_H #ifndef COUNTEREXAMPLE_H
# define COUNTEREXAMPLE_H # define COUNTEREXAMPLE_H
# include "state-item.h" # include "state.h"
// Init/deinit this module.
void counterexample_init (void); void counterexample_init (void);
void counterexample_free (void); void counterexample_free (void);
void counterexample_report_state (const state *s, FILE *out, const char *prefix); // Print the counterexamples for the conflicts of state S.
//
// Used both for the warnings on the terminal (OUT = stderr, PREFIX =
// ""), and for the reports (OUT != stderr, PREFIX != "").
void
counterexample_report_state (const state *s, FILE *out, const char *prefix);
#endif /* COUNTEREXAMPLE_H */ #endif /* COUNTEREXAMPLE_H */

View File

@@ -29,7 +29,7 @@
struct derivation struct derivation
{ {
symbol_number sym; symbol_number sym;
gl_list_t children; derivation_list children;
int reference_count; int reference_count;
}; };
@@ -129,7 +129,7 @@ derivation_size (const derivation *deriv)
/* Print DERIV, colored according to COUNTER. /* Print DERIV, colored according to COUNTER.
Return false if nothing is printed. */ Return false if nothing is printed. */
static bool static bool
derivation_print_impl (const derivation *deriv, FILE *f, derivation_print_impl (const derivation *deriv, FILE *out,
bool leaves_only, bool leaves_only,
int *counter, const char *prefix) int *counter, const char *prefix)
{ {
@@ -139,16 +139,16 @@ derivation_print_impl (const derivation *deriv, FILE *f,
char style[20]; char style[20];
snprintf (style, 20, "cex-%d", *counter); snprintf (style, 20, "cex-%d", *counter);
++*counter; ++*counter;
begin_use_class (style, f); begin_use_class (style, out);
if (!leaves_only) if (!leaves_only)
{ {
fputs (prefix, f); fputs (prefix, out);
begin_use_class ("cex-step", f); begin_use_class ("cex-step", out);
fprintf (f, "%s ", sym->tag); fprintf (out, "%s ", sym->tag);
print_arrow (f); print_arrow (out);
fprintf (f, " [ "); fprintf (out, " [ ");
end_use_class ("cex-step", f); end_use_class ("cex-step", out);
prefix = ""; prefix = "";
} }
bool res = false; bool res = false;
@@ -157,7 +157,7 @@ derivation_print_impl (const derivation *deriv, FILE *f,
derivation_list_next (&it, &child); derivation_list_next (&it, &child);
) )
{ {
if (derivation_print_impl (child, f, leaves_only, counter, prefix)) if (derivation_print_impl (child, out, leaves_only, counter, prefix))
{ {
prefix = " "; prefix = " ";
res = true; res = true;
@@ -167,30 +167,30 @@ derivation_print_impl (const derivation *deriv, FILE *f,
} }
if (!leaves_only) if (!leaves_only)
{ {
begin_use_class ("cex-step", f); begin_use_class ("cex-step", out);
if (res) if (res)
fputs (" ]", f); fputs (" ]", out);
else else
fputs ("]", f); fputs ("]", out);
end_use_class ("cex-step", f); end_use_class ("cex-step", out);
} }
end_use_class (style, f); end_use_class (style, out);
return res; return res;
} }
else if (deriv == &d_dot) else if (deriv == &d_dot)
{ {
fputs (prefix, f); fputs (prefix, out);
begin_use_class ("cex-dot", f); begin_use_class ("cex-dot", out);
print_dot (f); print_dot (out);
end_use_class ("cex-dot", f); end_use_class ("cex-dot", out);
} }
else // leaf. else // leaf.
{ {
fputs (prefix, f); fputs (prefix, out);
const symbol *sym = symbols[deriv->sym]; const symbol *sym = symbols[deriv->sym];
begin_use_class ("cex-leaf", f); begin_use_class ("cex-leaf", out);
fprintf (f, "%s", sym->tag); fprintf (out, "%s", sym->tag);
end_use_class ("cex-leaf", f); end_use_class ("cex-leaf", out);
} }
return true; return true;
} }

View File

@@ -60,12 +60,15 @@ static inline derivation *derivation_new_leaf (symbol_number sym)
{ {
return derivation_new (sym, NULL); return derivation_new (sym, NULL);
} }
// Number of symbols.
size_t derivation_size (const derivation *deriv); size_t derivation_size (const derivation *deriv);
void derivation_print (const derivation *deriv, FILE *out, const char *prefix); void derivation_print (const derivation *deriv, FILE *out, const char *prefix);
void derivation_print_leaves (const derivation *deriv, FILE *out, const char *prefix); void derivation_print_leaves (const derivation *deriv, FILE *out, const char *prefix);
void derivation_free (derivation *deriv); void derivation_free (derivation *deriv);
void derivation_retain (derivation *deriv); void derivation_retain (derivation *deriv);
// A derivation denoting the position of the dot.
derivation *derivation_dot (void); derivation *derivation_dot (void);
#endif /* DERIVATION_H */ #endif /* DERIVATION_H */