Commit 9d947411 authored by Akim Demaille's avatar Akim Demaille

styles: untabify sources

* src/check.c, src/check.h, src/emit.c, src/emit.h, src/emit_cost.c,
* src/emit_files.c, src/emit_functions.c, src/emit_kids.c,
* src/emit_pretty_print.c, src/main.c, src/mem_clean.c,
* src/mem_clean.h, src/named_subtree.c, src/named_subtree.h,
* src/parser.h, src/rule.c, src/rule.h:
Untabify.
parent 3beaacdc
......@@ -28,41 +28,41 @@ static void mark_reached (Tree *tree);
each non terminal symbols and arity of terminals. */
void check_result ()
{
GList *l;
GList *l;
for (l = term_list; l; l = l->next) {
Term *term = (Term *)l->data;
if (term->arity == -1)
g_warning ("unused terminal \"%s\"",term->name);
}
for (l = term_list; l; l = l->next) {
Term *term = (Term *)l->data;
if (term->arity == -1)
g_warning ("unused terminal \"%s\"",term->name);
}
if (nonterm_list)
check_reach (((NonTerm *)nonterm_list->data));
if (nonterm_list)
check_reach (((NonTerm *)nonterm_list->data));
for (l = nonterm_list; l; l = l->next) {
NonTerm *n = (NonTerm *)l->data;
if (!n->reached)
g_warning ("unreachable nonterm \"%s\"", n->name);
}
for (l = nonterm_list; l; l = l->next) {
NonTerm *n = (NonTerm *)l->data;
if (!n->reached)
g_warning ("unreachable nonterm \"%s\"", n->name);
}
}
static void check_reach (NonTerm *n)
{
GList *l;
GList *l;
n->reached = 1;
for (l = n->rules; l; l = l->next) {
Rule *rule = (Rule *)l->data;
mark_reached (rule->tree);
}
n->reached = 1;
for (l = n->rules; l; l = l->next) {
Rule *rule = (Rule *)l->data;
mark_reached (rule->tree);
}
}
static void mark_reached (Tree *tree)
{
if (tree->nonterm && !tree->nonterm->reached)
check_reach (tree->nonterm);
if (tree->left)
mark_reached (tree->left);
if (tree->right)
mark_reached (tree->right);
if (tree->nonterm && !tree->nonterm->reached)
check_reach (tree->nonterm);
if (tree->left)
mark_reached (tree->left);
if (tree->right)
mark_reached (tree->right);
}
......@@ -21,6 +21,6 @@
#ifndef __MONO_CHECK_H__
# define __MONO_CHECK_H__
void check_result ();
void check_result ();
#endif /* __MONO_CHECK_H__ */
This diff is collapsed.
......@@ -25,27 +25,27 @@
extern FILE *outputfd;
void output (char *fmt, ...);
void output (char *fmt, ...);
void emit_header_file ();
void emit_code_file ();
void emit_header_file ();
void emit_code_file ();
void emit_closure ();
void emit_cost_func ();
void emit_decoders ();
void emit_emitter_func ();
void emit_header ();
void emit_includes ();
void emit_kids ();
void emit_label_func ();
void emit_nonterm ();
void emit_prototypes ();
void emit_state ();
void emit_term ();
void emit_vardefs ();
void emit_rule_string (Rule *rule, char *fill);
void emit_costs (char *st, Tree *t);
void emit_cond_assign (Rule *rule, char *cost, char *fill);
void emit_tree_string (Tree *tree);
void emit_closure ();
void emit_cost_func ();
void emit_decoders ();
void emit_emitter_func ();
void emit_header ();
void emit_includes ();
void emit_kids ();
void emit_label_func ();
void emit_nonterm ();
void emit_prototypes ();
void emit_state ();
void emit_term ();
void emit_vardefs ();
void emit_rule_string (Rule *rule, char *fill);
void emit_costs (char *st, Tree *t);
void emit_cond_assign (Rule *rule, char *cost, char *fill);
void emit_tree_string (Tree *tree);
#endif /* __MONO_EMIT_H__ */
......@@ -26,116 +26,116 @@
/** Emit cost functions. */
void emit_cost_func ()
{
GList *l;
int i;
if (!exported_symbols_p)
output ("static int mono_burg_rule (MBState *state, int goal);\n");
for (l = rule_list, i = 0; l; l = l->next) {
Rule *rule = (Rule *)l->data;
if (rule->cfunc) {
output ("inline static guint16\n");
emit_rule_string (rule, "");
if (dag_mode)
output ("mono_burg_cost_%d (MBState *state, MBCOST_DATA *data)\n", i + 1);
else
output ("mono_burg_cost_%d (MBTREE_TYPE %ctree, MBCOST_DATA *data)\n", i + 1,
(cxx_ref_p ? '&' : '*'));
output ("{\n");
output ("\t(void) data; ");
if (dag_mode)
output ("(void) state;\n");
else
output ("(void) tree;\n");
output ("%s\n", rule->cfunc);
output ("}\n\n");
}
i++;
}
GList *l;
int i;
if (!exported_symbols_p)
output ("static int mono_burg_rule (MBState *state, int goal);\n");
for (l = rule_list, i = 0; l; l = l->next) {
Rule *rule = (Rule *)l->data;
if (rule->cfunc) {
output ("inline static guint16\n");
emit_rule_string (rule, "");
if (dag_mode)
output ("mono_burg_cost_%d (MBState *state, MBCOST_DATA *data)\n", i + 1);
else
output ("mono_burg_cost_%d (MBTREE_TYPE %ctree, MBCOST_DATA *data)\n", i + 1,
(cxx_ref_p ? '&' : '*'));
output ("{\n");
output ("\t(void) data; ");
if (dag_mode)
output ("(void) state;\n");
else
output ("(void) tree;\n");
output ("%s\n", rule->cfunc);
output ("}\n\n");
}
i++;
}
}
/** Emit closure functions. */
void emit_closure ()
{
GList *l, *rl;
GList *l, *rl;
for (l = nonterm_list; l; l = l->next) {
NonTerm *n = (NonTerm *)l->data;
for (l = nonterm_list; l; l = l->next) {
NonTerm *n = (NonTerm *)l->data;
if (n->chain)
output ("static void closure_%s (MBState *p, int c);\n", n->name);
}
if (n->chain)
output ("static void closure_%s (MBState *p, int c);\n", n->name);
}
output ("\n");
output ("\n");
for (l = nonterm_list; l; l = l->next) {
NonTerm *n = (NonTerm *)l->data;
for (l = nonterm_list; l; l = l->next) {
NonTerm *n = (NonTerm *)l->data;
if (n->chain) {
output ("static void\n");
output ("closure_%s (MBState *p, int c)\n{\n", n->name);
for (rl = n->chain; rl; rl = rl->next) {
Rule *rule = (Rule *)rl->data;
if (n->chain) {
output ("static void\n");
output ("closure_%s (MBState *p, int c)\n{\n", n->name);
for (rl = n->chain; rl; rl = rl->next) {
Rule *rule = (Rule *)rl->data;
emit_rule_string (rule, "\t");
emit_cond_assign (rule, rule->cost, "\t");
}
output ("}\n\n");
}
}
emit_rule_string (rule, "\t");
emit_cond_assign (rule, rule->cost, "\t");
}
output ("}\n\n");
}
}
}
/** Emit the cost sum. */
void emit_costs (char *st, Tree *t)
{
char *tn;
if (t->op) {
if (t->left) {
tn = g_strconcat (st, "left->", NULL);
emit_costs (tn, t->left);
g_free (tn);
}
if (t->right) {
tn = g_strconcat (st, "right->", NULL);
emit_costs (tn, t->right);
g_free (tn);
}
} else
output ("%scost[MB_NTERM_%s] + ", st, t->nonterm->name);
char *tn;
if (t->op) {
if (t->left) {
tn = g_strconcat (st, "left->", NULL);
emit_costs (tn, t->left);
g_free (tn);
}
if (t->right) {
tn = g_strconcat (st, "right->", NULL);
emit_costs (tn, t->right);
g_free (tn);
}
} else
output ("%scost[MB_NTERM_%s] + ", st, t->nonterm->name);
}
/** Emit test on cost. */
void emit_cond_assign (Rule *rule, char *cost, char *fill)
{
char *rc;
char *rc;
if (cost)
rc = g_strconcat ("c + ", cost, NULL);
else
rc = g_strdup ("c");
if (cost)
rc = g_strconcat ("c + ", cost, NULL);
else
rc = g_strdup ("c");
output ("%sif (%s < p->cost[MB_NTERM_%s]) {\n", fill, rc, rule->lhs->name);
output ("%sif (%s < p->cost[MB_NTERM_%s]) {\n", fill, rc, rule->lhs->name);
output ("%s\tp->cost[MB_NTERM_%s] = %s;\n", fill, rule->lhs->name, rc);
output ("%s\tp->cost[MB_NTERM_%s] = %s;\n", fill, rule->lhs->name, rc);
output ("%s\tp->rule_%s = %d;\n", fill, rule->lhs->name,
g_list_index (rule->lhs->rules, rule) + 1);
output ("%s\tp->rule_%s = %d;\n", fill, rule->lhs->name,
g_list_index (rule->lhs->rules, rule) + 1);
if (rule->lhs->chain)
output ("%s\tclosure_%s (p, %s);\n", fill, rule->lhs->name, rc);
if (rule->lhs->chain)
output ("%s\tclosure_%s (p, %s);\n", fill, rule->lhs->name, rc);
output ("%s}\n", fill);
output ("%s}\n", fill);
g_free (rc);
g_free (rc);
}
......@@ -26,49 +26,49 @@
/** Output header file data. */
void emit_header_file ()
{
int n_namespace = 0;
GList *namespace = namespaces;
int n_namespace = 0;
GList *namespace = namespaces;
emit_includes ();
emit_header ();
while (namespace)
{
output ("namespace %s {\n", (char *) namespace->data);
namespace = namespace->next;
++n_namespace;
}
emit_term ();
emit_nonterm ();
emit_state ();
emit_prototypes ();
while (n_namespace--)
output ("}\n");
emit_includes ();
emit_header ();
while (namespace)
{
output ("namespace %s {\n", (char *) namespace->data);
namespace = namespace->next;
++n_namespace;
}
emit_term ();
emit_nonterm ();
emit_state ();
emit_prototypes ();
while (n_namespace--)
output ("}\n");
}
/** Output C file data. */
void emit_code_file ()
{
int n_namespace = 0;
GList *namespace = namespaces;
int n_namespace = 0;
GList *namespace = namespaces;
for (namespace = namespaces; namespace; namespace = namespace->next) {
output ("namespace %s {\n", (char *) namespace->data);
g_free (namespace->data);
++n_namespace;
}
g_list_free (namespaces);
emit_vardefs ();
emit_cost_func ();
emit_emitter_func ();
emit_decoders ();
for (namespace = namespaces; namespace; namespace = namespace->next) {
output ("namespace %s {\n", (char *) namespace->data);
g_free (namespace->data);
++n_namespace;
}
g_list_free (namespaces);
emit_vardefs ();
emit_cost_func ();
emit_emitter_func ();
emit_decoders ();
emit_closure ();
emit_label_func ();
emit_closure ();
emit_label_func ();
emit_kids ();
while (n_namespace--)
output ("}\n");
free_rules ();
free_terms ();
free_nonterms ();
emit_kids ();
while (n_namespace--)
output ("}\n");
free_rules ();
free_terms ();
free_nonterms ();
}
......@@ -24,55 +24,55 @@
/** Emit rule functions. */
void emit_emitter_func ()
{
GList *l;
int i, rulen;
GHashTable *cache = g_hash_table_new (g_str_hash, g_str_equal);
GList *l;
int i, rulen;
GHashTable *cache = g_hash_table_new (g_str_hash, g_str_equal);
for (l = rule_list, i = 0; l; l = l->next) {
Rule *rule = (Rule *)l->data;
for (l = rule_list, i = 0; l; l = l->next) {
Rule *rule = (Rule *)l->data;
if (rule->code) {
if ((rulen = GPOINTER_TO_INT (g_hash_table_lookup (cache, rule->code)))) {
emit_rule_string (rule, "");
output ("#define mono_burg_emit_%d mono_burg_emit_%d\n\n", i, rulen - 1);
i++;
continue;
}
output ("static void ");
if (rule->code) {
if ((rulen = GPOINTER_TO_INT (g_hash_table_lookup (cache, rule->code)))) {
emit_rule_string (rule, "");
output ("#define mono_burg_emit_%d mono_burg_emit_%d\n\n", i, rulen - 1);
i++;
continue;
}
output ("static void ");
emit_rule_string (rule, "");
emit_rule_string (rule, "");
if (dag_mode)
output ("mono_burg_emit_%d (MBState *state, MBTREE_TYPE %ctree, MBCGEN_TYPE *s)\n", i,
(cxx_ref_p ? '&' : '*'));
else
output ("mono_burg_emit_%d (MBTREE_TYPE %ctree, MBCGEN_TYPE *s)\n", i,
(cxx_ref_p ? '&' : '*'));
if (dag_mode)
output ("mono_burg_emit_%d (MBState *state, MBTREE_TYPE %ctree, MBCGEN_TYPE *s)\n", i,
(cxx_ref_p ? '&' : '*'));
else
output ("mono_burg_emit_%d (MBTREE_TYPE %ctree, MBCGEN_TYPE *s)\n", i,
(cxx_ref_p ? '&' : '*'));
output ("{\n");
output ("\t(void) tree; (void) s;");
if (dag_mode)
output (" (void) state;");
output ("\n\t{\n%s\n\t}\n", rule->code);
output ("}\n\n");
g_hash_table_insert (cache, rule->code, GINT_TO_POINTER (i + 1));
}
i++;
}
output ("{\n");
output ("\t(void) tree; (void) s;");
if (dag_mode)
output (" (void) state;");
output ("\n\t{\n%s\n\t}\n", rule->code);
output ("}\n\n");
g_hash_table_insert (cache, rule->code, GINT_TO_POINTER (i + 1));
}
i++;
}
g_hash_table_destroy (cache);
g_hash_table_destroy (cache);
if (!exported_symbols_p)
output ("static ");
output ("MBEmitFunc const mono_burg_func [] = {\n");
output ("\tNULL,\n");
for (l = rule_list, i = 0; l; l = l->next) {
Rule *rule = (Rule *)l->data;
if (rule->code)
output ("\tmono_burg_emit_%d,\n", i);
else
output ("\tNULL,\n");
i++;
}
output ("};\n\n");
if (!exported_symbols_p)
output ("static ");
output ("MBEmitFunc const mono_burg_func [] = {\n");
output ("\tNULL,\n");
for (l = rule_list, i = 0; l; l = l->next) {
Rule *rule = (Rule *)l->data;
if (rule->code)
output ("\tmono_burg_emit_%d,\n", i);
else
output ("\tNULL,\n");
i++;
}
output ("};\n\n");
}
......@@ -27,94 +27,94 @@ static char *compute_kids (char *ts, Tree *tree, int *n);
/** Emit `mono_burg_rule' and `mono_burg_kids'. */
void emit_kids ()
{
GList *l, *nl;
int i, j, c, n, *si;
char **sa;
if (!exported_symbols_p)
output ("static ");
output ("int\n");
output ("mono_burg_rule (MBState *state, int goal)\n{\n");
output ("\tg_return_val_if_fail (state != NULL, 0);\n");
output ("\tg_return_val_if_fail (goal > 0, 0);\n\n");
output ("\tswitch (goal) {\n");
for (nl = nonterm_list; nl; nl = nl->next) {
NonTerm *n = (NonTerm *)nl->data;
output ("\tcase MB_NTERM_%s:\n", n->name);
output ("\t\treturn mono_burg_decode_%s [state->rule_%s];\n",
n->name, n->name);
}
output ("\tdefault: g_assert_not_reached ();\n");
output ("\t}\n");
output ("\treturn 0;\n");
output ("}\n\n");
if (dag_mode) {
if (!exported_symbols_p)
output ("static ");
output ("MBState **\n");
output ("mono_burg_kids (MBState *state, int rulenr, MBState *kids [])\n{\n");
output ("\tg_return_val_if_fail (state != NULL, NULL);\n");
output ("\tg_return_val_if_fail (kids != NULL, NULL);\n\n");
} else {
if (!exported_symbols_p)
output ("static ");
output ("MBTREE_TYPE **\n");
output ("mono_burg_kids (MBTREE_TYPE *tree, int rulenr, MBTREE_TYPE *kids [])\n{\n");
output ("\tg_return_val_if_fail (tree != NULL, NULL);\n");
output ("\tg_return_val_if_fail (kids != NULL, NULL);\n\n");
}
output ("\tswitch (rulenr) {\n");
n = g_list_length (rule_list);
sa = g_new0 (char *, n);
si = g_new0 (int, n);
/* compress the case statement */
for (l = rule_list, i = 0, c = 0; l; l = l->next) {
Rule *rule = (Rule *)l->data;
int kn = 0;
char *k;
if (dag_mode)
k = compute_kids ("state", rule->tree, &kn);
else
k = compute_kids ("tree", rule->tree, &kn);
for (j = 0; j < c; j++)
if (!strcmp (sa [j], k))
break;
si [i++] = j;
if (j == c)
sa [c++] = k;
else
g_free (k);
}
for (i = 0; i < c; i++) {
for (l = rule_list, j = 0; l; l = l->next, j++)
if (i == si [j])
output ("\tcase %d:\n", j + 1);
output ("%s", sa [i]);
output ("\t\tbreak;\n");
}
while (c--)
g_free (sa [c]);
g_free (sa);
g_free (si);
output ("\tdefault:\n\t\tg_assert_not_reached ();\n");
output ("\t}\n");
output ("\treturn kids;\n");
output ("}\n\n");
GList *l, *nl;
int i, j, c, n, *si;
char **sa;
if (!exported_symbols_p)
output ("static ");
output ("int\n");
output ("mono_burg_rule (MBState *state, int goal)\n{\n");
output ("\tg_return_val_if_fail (state != NULL, 0);\n");
output ("\tg_return_val_if_fail (goal > 0, 0);\n\n");
output ("\tswitch (goal) {\n");
for (nl = nonterm_list; nl; nl = nl->next) {
NonTerm *n = (NonTerm *)nl->data;
output ("\tcase MB_NTERM_%s:\n", n->name);
output ("\t\treturn mono_burg_decode_%s [state->rule_%s];\n",
n->name, n->name);
}
output ("\tdefault: g_assert_not_reached ();\n");
output ("\t}\n");
output ("\treturn 0;\n");
output ("}\n\n");