closure, gram: add missing const

* src/closure.h, src/closure.c, src/gram.h, src/gram.c: Add some missing
const where appropriate.
This commit is contained in:
Akim Demaille
2012-12-28 10:16:37 +01:00
parent 432a008d34
commit 510c8497f8
4 changed files with 24 additions and 22 deletions

View File

@@ -52,7 +52,7 @@ static bitsetv firsts = NULL;
`-----------------*/ `-----------------*/
static void static void
print_closure (char const *title, item_number *array, size_t size) print_closure (char const *title, item_number const *array, size_t size)
{ {
size_t i; size_t i;
fprintf (stderr, "Closure: %s\n", title); fprintf (stderr, "Closure: %s\n", title);
@@ -189,7 +189,7 @@ new_closure (unsigned int n)
void void
closure (item_number *core, size_t n) closure (item_number const *core, size_t n)
{ {
/* Index over CORE. */ /* Index over CORE. */
size_t c; size_t c;

View File

@@ -44,7 +44,7 @@ void new_closure (unsigned int n);
significant). CLOSURE places there the indices of all items which significant). CLOSURE places there the indices of all items which
represent units of input that could arrive next. */ represent units of input that could arrive next. */
void closure (item_number *items, size_t n); void closure (item_number const *items, size_t n);
/* Frees ITEMSET, RULESET and internal data. */ /* Frees ITEMSET, RULESET and internal data. */

View File

@@ -47,25 +47,25 @@ symbol_number *token_translations = NULL;
int max_user_token_number = 256; int max_user_token_number = 256;
bool bool
rule_useful_in_grammar_p (rule *r) rule_useful_in_grammar_p (rule const *r)
{ {
return r->number < nrules; return r->number < nrules;
} }
bool bool
rule_useless_in_grammar_p (rule *r) rule_useless_in_grammar_p (rule const *r)
{ {
return !rule_useful_in_grammar_p (r); return !rule_useful_in_grammar_p (r);
} }
bool bool
rule_useless_in_parser_p (rule *r) rule_useless_in_parser_p (rule const *r)
{ {
return !r->useful && rule_useful_in_grammar_p (r); return !r->useful && rule_useful_in_grammar_p (r);
} }
void void
rule_lhs_print (rule *r, symbol *previous_lhs, FILE *out) rule_lhs_print (rule const *r, symbol const *previous_lhs, FILE *out)
{ {
fprintf (out, " %3d ", r->number); fprintf (out, " %3d ", r->number);
if (previous_lhs != r->lhs) if (previous_lhs != r->lhs)
@@ -82,13 +82,13 @@ rule_lhs_print (rule *r, symbol *previous_lhs, FILE *out)
} }
void void
rule_lhs_print_xml (rule *r, FILE *out, int level) rule_lhs_print_xml (rule const *r, FILE *out, int level)
{ {
xml_printf (out, level, "<lhs>%s</lhs>", r->lhs->tag); xml_printf (out, level, "<lhs>%s</lhs>", r->lhs->tag);
} }
size_t size_t
rule_rhs_length (rule *r) rule_rhs_length (rule const *r)
{ {
size_t res = 0; size_t res = 0;
item_number *rhsp; item_number *rhsp;
@@ -98,7 +98,7 @@ rule_rhs_length (rule *r)
} }
void void
rule_rhs_print (rule *r, FILE *out) rule_rhs_print (rule const *r, FILE *out)
{ {
if (*r->rhs >= 0) if (*r->rhs >= 0)
{ {
@@ -113,7 +113,7 @@ rule_rhs_print (rule *r, FILE *out)
} }
static void static void
rule_rhs_print_xml (rule *r, FILE *out, int level) rule_rhs_print_xml (rule const *r, FILE *out, int level)
{ {
if (*r->rhs >= 0) if (*r->rhs >= 0)
{ {
@@ -133,7 +133,7 @@ rule_rhs_print_xml (rule *r, FILE *out, int level)
} }
static void static void
rule_print (rule *r, FILE *out) rule_print (rule const *r, FILE *out)
{ {
fprintf (out, "%s:", r->lhs->tag); fprintf (out, "%s:", r->lhs->tag);
rule_rhs_print (r, out); rule_rhs_print (r, out);
@@ -263,10 +263,12 @@ grammar_dump (FILE *out, const char *title)
fprintf (out, "Rules\n-----\n\n"); fprintf (out, "Rules\n-----\n\n");
{ {
rule_number i; rule_number i;
fprintf (out, "Num (Prec, Assoc, Useful, Ritem Range) Lhs -> Rhs (Ritem range) [Num]\n"); fprintf (out,
"Num (Prec, Assoc, Useful, Ritem Range) Lhs"
" -> Rhs (Ritem range) [Num]\n");
for (i = 0; i < nrules + nuseless_productions; i++) for (i = 0; i < nrules + nuseless_productions; i++)
{ {
rule *rule_i = &rules[i]; rule const *rule_i = &rules[i];
item_number *rp = NULL; item_number *rp = NULL;
unsigned int rhs_itemno = rule_i->rhs - ritem; unsigned int rhs_itemno = rule_i->rhs - ritem;
unsigned int rhs_count = 0; unsigned int rhs_count = 0;

View File

@@ -203,31 +203,31 @@ typedef struct
extern rule *rules; extern rule *rules;
/* A function that selects a rule. */ /* A function that selects a rule. */
typedef bool (*rule_filter) (rule *); typedef bool (*rule_filter) (rule const *);
/* Return true IFF the rule has a `number' smaller than NRULES. That is, it is /* Return true IFF the rule has a `number' smaller than NRULES. That is, it is
useful in the grammar. */ useful in the grammar. */
bool rule_useful_in_grammar_p (rule *r); bool rule_useful_in_grammar_p (rule const *r);
/* Return true IFF the rule has a `number' higher than NRULES. That is, it is /* Return true IFF the rule has a `number' higher than NRULES. That is, it is
useless in the grammar. */ useless in the grammar. */
bool rule_useless_in_grammar_p (rule *r); bool rule_useless_in_grammar_p (rule const *r);
/* Return true IFF the rule is not flagged as useful but is useful in the /* Return true IFF the rule is not flagged as useful but is useful in the
grammar. In other words, it was discarded because of conflicts. */ grammar. In other words, it was discarded because of conflicts. */
bool rule_useless_in_parser_p (rule *r); bool rule_useless_in_parser_p (rule const *r);
/* Print this rule's number and lhs on OUT. If a PREVIOUS_LHS was /* Print this rule's number and lhs on OUT. If a PREVIOUS_LHS was
already displayed (by a previous call for another rule), avoid already displayed (by a previous call for another rule), avoid
useless repetitions. */ useless repetitions. */
void rule_lhs_print (rule *r, symbol *previous_lhs, FILE *out); void rule_lhs_print (rule const *r, symbol const *previous_lhs, FILE *out);
void rule_lhs_print_xml (rule *r, FILE *out, int level); void rule_lhs_print_xml (rule const *r, FILE *out, int level);
/* Return the length of the RHS. */ /* Return the length of the RHS. */
size_t rule_rhs_length (rule *r); size_t rule_rhs_length (rule const *r);
/* Print this rule's RHS on OUT. */ /* Print this rule's RHS on OUT. */
void rule_rhs_print (rule *r, FILE *out); void rule_rhs_print (rule const *r, FILE *out);