Directly use memory allocation functions and remove needless casts in

their usage.  Also use associated modern types instead of k&r ones.
This commit is contained in:
David E. O'Brien 2010-11-07 23:22:42 +00:00
parent c8f6c2ae32
commit 92a010d28b
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=214961
11 changed files with 136 additions and 140 deletions

View File

@ -149,7 +149,7 @@ set_first_derives(void)
print_first_derives(); print_first_derives();
#endif #endif
FREE(EFF); free(EFF);
} }
@ -224,9 +224,9 @@ closure(short *nucleus, int n)
void void
finalize_closure(void) finalize_closure(void)
{ {
FREE(itemset); free(itemset);
FREE(ruleset); free(ruleset);
FREE(first_derives + ntokens * WORDSIZE(nrules)); free(first_derives + ntokens * WORDSIZE(nrules));
} }

View File

@ -133,12 +133,8 @@
/* storage allocation macros */ /* storage allocation macros */
#define CALLOC(k,n) (calloc((unsigned)(k),(unsigned)(n)))
#define FREE(x) (free((char*)(x)))
#define MALLOC(n) (malloc((unsigned)(n)))
#define NEW(t) ((t*)allocate(sizeof(t))) #define NEW(t) ((t*)allocate(sizeof(t)))
#define NEW2(n,t) ((t*)allocate((unsigned)((n)*sizeof(t)))) #define NEW2(n,t) ((t*)allocate((n)*sizeof(t)))
#define REALLOC(p,n) (realloc((char*)(p),(unsigned)(n)))
/* the structure of a symbol table entry */ /* the structure of a symbol table entry */
@ -304,7 +300,7 @@ extern short final_state;
/* global functions */ /* global functions */
char *allocate(unsigned); void *allocate(size_t);
void closure(short *, int); void closure(short *, int);
void create_symbol_table(void); void create_symbol_table(void);
void default_action_warning(void); void default_action_warning(void);

View File

@ -293,7 +293,7 @@ set_goto_map(void)
} }
} }
FREE(temp_map + ntokens); free(temp_map + ntokens);
} }
@ -396,11 +396,11 @@ initialize_F(void)
for (i = 0; i < ngotos; i++) for (i = 0; i < ngotos; i++)
{ {
if (reads[i]) if (reads[i])
FREE(reads[i]); free(reads[i]);
} }
FREE(reads); free(reads);
FREE(edge); free(edge);
} }
@ -487,14 +487,14 @@ build_relations(void)
for (i = 0; i < ngotos; i++) for (i = 0; i < ngotos; i++)
if (includes[i]) if (includes[i])
FREE(includes[i]); free(includes[i]);
FREE(includes); free(includes);
includes = new_includes; includes = new_includes;
FREE(edge); free(edge);
FREE(states); free(states);
} }
@ -562,7 +562,7 @@ transpose(short **R, int n)
} }
} }
FREE(nedges); free(nedges);
for (i = 0; i < n; i++) for (i = 0; i < n; i++)
{ {
@ -574,7 +574,7 @@ transpose(short **R, int n)
} }
} }
FREE(temp_R); free(temp_R);
return (new_R); return (new_R);
} }
@ -615,11 +615,11 @@ compute_lookaheads(void)
for (sp = lookback[i]; sp; sp = next) for (sp = lookback[i]; sp; sp = next)
{ {
next = sp->next; next = sp->next;
FREE(sp); free(sp);
} }
FREE(lookback); free(lookback);
FREE(F); free(F);
} }
@ -642,8 +642,8 @@ digraph(short **relation)
traverse(i, relation); traverse(i, relation);
} }
FREE(INDEX); free(INDEX);
FREE(VERTICES); free(VERTICES);
} }

View File

@ -176,13 +176,13 @@ append_states(void)
static void static void
free_storage(void) free_storage(void)
{ {
FREE(shift_symbol); free(shift_symbol);
FREE(redset); free(redset);
FREE(shiftset); free(shiftset);
FREE(kernel_base); free(kernel_base);
FREE(kernel_end); free(kernel_end);
FREE(kernel_items); free(kernel_items);
FREE(state_set); free(state_set);
} }
@ -290,7 +290,7 @@ initialize_states(void)
for (i = 0; start_derives[i] >= 0; ++i) for (i = 0; start_derives[i] >= 0; ++i)
continue; continue;
p = (core *) MALLOC(sizeof(core) + i*sizeof(short)); p = malloc(sizeof(core) + i*sizeof(short));
if (p == 0) no_space(); if (p == 0) no_space();
p->next = 0; p->next = 0;
@ -579,8 +579,8 @@ set_derives(void)
#if 0 #if 0
free_derives() free_derives()
{ {
FREE(derives[start_symbol]); free(derives[start_symbol]);
FREE(derives); free(derives);
} }
#endif #endif
@ -615,7 +615,7 @@ set_nullable(void)
int empty; int empty;
int done1; int done1;
nullable = MALLOC(nsyms); nullable = malloc(nsyms);
if (nullable == 0) no_space(); if (nullable == 0) no_space();
for (i = 0; i < nsyms; ++i) for (i = 0; i < nsyms; ++i)
@ -661,7 +661,7 @@ set_nullable(void)
#if 0 #if 0
free_nullable(void) free_nullable(void)
{ {
FREE(nullable); free(nullable);
} }
#endif #endif

View File

@ -216,15 +216,15 @@ getargs(int argc, char *argv[])
} }
char * void *
allocate(unsigned n) allocate(size_t n)
{ {
char *p; void *p;
p = NULL; p = NULL;
if (n) if (n)
{ {
p = CALLOC(1, n); p = calloc(1, n);
if (!p) no_space(); if (!p) no_space();
} }
return (p); return (p);
@ -245,11 +245,11 @@ create_file_names(void)
if (len && tmpdir[len-1] != '/') if (len && tmpdir[len-1] != '/')
++i; ++i;
action_file_name = MALLOC(i); action_file_name = malloc(i);
if (action_file_name == 0) no_space(); if (action_file_name == 0) no_space();
text_file_name = MALLOC(i); text_file_name = malloc(i);
if (text_file_name == 0) no_space(); if (text_file_name == 0) no_space();
union_file_name = MALLOC(i); union_file_name = malloc(i);
if (union_file_name == 0) no_space(); if (union_file_name == 0) no_space();
strcpy(action_file_name, tmpdir); strcpy(action_file_name, tmpdir);
@ -280,7 +280,7 @@ create_file_names(void)
else else
{ {
len = strlen(file_prefix); len = strlen(file_prefix);
output_file_name = MALLOC(len + 7); output_file_name = malloc(len + 7);
if (output_file_name == 0) if (output_file_name == 0)
no_space(); no_space();
strcpy(output_file_name, file_prefix); strcpy(output_file_name, file_prefix);
@ -289,7 +289,7 @@ create_file_names(void)
if (rflag) if (rflag)
{ {
code_file_name = MALLOC(len + 8); code_file_name = malloc(len + 8);
if (code_file_name == 0) if (code_file_name == 0)
no_space(); no_space();
strcpy(code_file_name, file_prefix); strcpy(code_file_name, file_prefix);
@ -314,7 +314,7 @@ create_file_names(void)
if (dflag) if (dflag)
{ {
defines_file_name = MALLOC(len + 7); defines_file_name = malloc(len + 7);
if (defines_file_name == 0) if (defines_file_name == 0)
no_space(); no_space();
strcpy(defines_file_name, file_prefix); strcpy(defines_file_name, file_prefix);
@ -332,7 +332,7 @@ create_file_names(void)
if (vflag) if (vflag)
{ {
verbose_file_name = MALLOC(len + 8); verbose_file_name = malloc(len + 8);
if (verbose_file_name == 0) if (verbose_file_name == 0)
no_space(); no_space();
strcpy(verbose_file_name, file_prefix); strcpy(verbose_file_name, file_prefix);

View File

@ -221,7 +221,7 @@ unused_rules(void)
int i; int i;
action *p; action *p;
rules_used = (short *) MALLOC(nrules*sizeof(short)); rules_used = malloc(nrules*sizeof(short));
if (rules_used == 0) no_space(); if (rules_used == 0) no_space();
for (i = 0; i < nrules; ++i) for (i = 0; i < nrules; ++i)
@ -391,7 +391,7 @@ free_action_row(action *p)
while (p) while (p)
{ {
q = p->next; q = p->next;
FREE(p); free(p);
p = q; p = q;
} }
} }
@ -404,5 +404,5 @@ free_parser(void)
for (i = 0; i < nstates; i++) for (i = 0; i < nstates; i++)
free_action_row(parser[i]); free_action_row(parser[i]);
FREE(parser); free(parser);
} }

View File

@ -270,15 +270,15 @@ output_actions(void)
width = NEW2(nvectors, short); width = NEW2(nvectors, short);
token_actions(); token_actions();
FREE(lookaheads); free(lookaheads);
FREE(LA); free(LA);
FREE(LAruleno); free(LAruleno);
FREE(accessing_symbol); free(accessing_symbol);
goto_actions(); goto_actions();
FREE(goto_map + ntokens); free(goto_map + ntokens);
FREE(from_state); free(from_state);
FREE(to_state); free(to_state);
sort_actions(); sort_actions();
pack_table(); pack_table();
@ -370,7 +370,7 @@ token_actions(void)
} }
} }
} }
FREE(actionrow); free(actionrow);
} }
static void static void
@ -403,7 +403,7 @@ goto_actions(void)
if (!rflag) outline += 2; if (!rflag) outline += 2;
fprintf(output_file, "\n};\n"); fprintf(output_file, "\n};\n");
FREE(state_count); free(state_count);
} }
static int static int
@ -555,14 +555,14 @@ pack_table(void)
for (i = 0; i < nvectors; i++) for (i = 0; i < nvectors; i++)
{ {
if (froms[i]) if (froms[i])
FREE(froms[i]); free(froms[i]);
if (tos[i]) if (tos[i])
FREE(tos[i]); free(tos[i]);
} }
FREE(froms); free(froms);
FREE(tos); free(tos);
FREE(pos); free(pos);
} }
@ -762,7 +762,7 @@ output_base(void)
if (!rflag) outline += 2; if (!rflag) outline += 2;
fprintf(output_file, "\n};\n"); fprintf(output_file, "\n};\n");
FREE(base); free(base);
} }
@ -795,7 +795,7 @@ output_table(void)
if (!rflag) outline += 2; if (!rflag) outline += 2;
fprintf(output_file, "\n};\n"); fprintf(output_file, "\n};\n");
FREE(table); free(table);
} }
@ -826,7 +826,7 @@ output_check(void)
if (!rflag) outline += 2; if (!rflag) outline += 2;
fprintf(output_file, "\n};\n"); fprintf(output_file, "\n};\n");
FREE(check); free(check);
} }
@ -972,7 +972,7 @@ output_debug(void)
++outline; ++outline;
fprintf(code_file, "#define YYMAXTOKEN %d\n", max); fprintf(code_file, "#define YYMAXTOKEN %d\n", max);
symnam = (char **) MALLOC((max+1)*sizeof(char *)); symnam = malloc((max+1)*sizeof(char *));
if (symnam == 0) no_space(); if (symnam == 0) no_space();
/* Note that it is not necessary to initialize the element */ /* Note that it is not necessary to initialize the element */
@ -1108,7 +1108,7 @@ output_debug(void)
} }
if (!rflag) outline += 2; if (!rflag) outline += 2;
fprintf(output_file, "\n};\n"); fprintf(output_file, "\n};\n");
FREE(symnam); free(symnam);
if (!rflag) ++outline; if (!rflag) ++outline;
fprintf(output_file, "const char * const %srule[] = {\n", symbol_prefix); fprintf(output_file, "const char * const %srule[] = {\n", symbol_prefix);
@ -1278,11 +1278,11 @@ free_itemsets(void)
{ {
core *cp, *next; core *cp, *next;
FREE(state_table); free(state_table);
for (cp = first_state; cp; cp = next) for (cp = first_state; cp; cp = next)
{ {
next = cp->next; next = cp->next;
FREE(cp); free(cp);
} }
} }
@ -1292,11 +1292,11 @@ free_shifts(void)
{ {
shifts *sp, *next; shifts *sp, *next;
FREE(shift_table); free(shift_table);
for (sp = first_shift; sp; sp = next) for (sp = first_shift; sp; sp = next)
{ {
next = sp->next; next = sp->next;
FREE(sp); free(sp);
} }
} }
@ -1307,11 +1307,11 @@ free_reductions(void)
{ {
reductions *rp, *next; reductions *rp, *next;
FREE(reduction_table); free(reduction_table);
for (rp = first_reduction; rp; rp = next) for (rp = first_reduction; rp; rp = next)
{ {
next = rp->next; next = rp->next;
FREE(rp); free(rp);
} }
} }
@ -1332,9 +1332,9 @@ increase_maxtable(int loc)
newmax = maxtable; newmax = maxtable;
do { newmax += 200; } while (newmax <= loc); do { newmax += 200; } while (newmax <= loc);
table = (short *) REALLOC(table, newmax*sizeof(short)); table = realloc(table, newmax*sizeof(short));
if (table == 0) no_space(); if (table == 0) no_space();
check = (short *) REALLOC(check, newmax*sizeof(short)); check = realloc(check, newmax*sizeof(short));
if (check == 0) no_space(); if (check == 0) no_space();
for (l = maxtable; l < newmax; ++l) for (l = maxtable; l < newmax; ++l)
{ {

View File

@ -126,7 +126,7 @@ cachec(int c)
if (cinc >= cache_size) if (cinc >= cache_size)
{ {
cache_size += 256; cache_size += 256;
cache = REALLOC(cache, cache_size); cache = realloc(cache, cache_size);
if (cache == 0) no_space(); if (cache == 0) no_space();
} }
cache[cinc] = c; cache[cinc] = c;
@ -143,7 +143,7 @@ get_line(void)
if (saw_eof || (c = getc(f)) == EOF) if (saw_eof || (c = getc(f)) == EOF)
{ {
if (line) { FREE(line); line = 0; } if (line) { free(line); line = 0; }
cptr = 0; cptr = 0;
saw_eof = 1; saw_eof = 1;
return; return;
@ -151,9 +151,9 @@ get_line(void)
if (line == 0 || linesize != (LINESIZE + 1)) if (line == 0 || linesize != (LINESIZE + 1))
{ {
if (line) FREE(line); if (line) free(line);
linesize = LINESIZE + 1; linesize = LINESIZE + 1;
line = MALLOC(linesize); line = malloc(linesize);
if (line == 0) no_space(); if (line == 0) no_space();
} }
@ -166,7 +166,7 @@ get_line(void)
if (++i >= linesize) if (++i >= linesize)
{ {
linesize += LINESIZE; linesize += LINESIZE;
line = REALLOC(line, linesize); line = realloc(line, linesize);
if (line == 0) no_space(); if (line == 0) no_space();
} }
c = getc(f); c = getc(f);
@ -189,7 +189,7 @@ dup_line(void)
if (line == 0) return (0); if (line == 0) return (0);
s = line; s = line;
while (*s != '\n') ++s; while (*s != '\n') ++s;
p = MALLOC(s - line + 1); p = malloc(s - line + 1);
if (p == 0) no_space(); if (p == 0) no_space();
s = line; s = line;
@ -214,7 +214,7 @@ skip_comment(void)
if (*s == '*' && s[1] == '/') if (*s == '*' && s[1] == '/')
{ {
cptr = s + 2; cptr = s + 2;
FREE(st_line); free(st_line);
return; return;
} }
if (*s == '\n') if (*s == '\n')
@ -435,7 +435,7 @@ copy_text(void)
if (c == quote) if (c == quote)
{ {
need_newline = 1; need_newline = 1;
FREE(s_line); free(s_line);
goto loop; goto loop;
} }
if (c == '\n') if (c == '\n')
@ -487,7 +487,7 @@ copy_text(void)
{ {
putc('/', f); putc('/', f);
++cptr; ++cptr;
FREE(c_line); free(c_line);
goto loop; goto loop;
} }
if (c == '\n') if (c == '\n')
@ -507,7 +507,7 @@ copy_text(void)
{ {
if (need_newline) putc('\n', f); if (need_newline) putc('\n', f);
++cptr; ++cptr;
FREE(t_line); free(t_line);
return; return;
} }
/* FALLTHROUGH */ /* FALLTHROUGH */
@ -560,7 +560,7 @@ copy_union(void)
if (--depth == 0) if (--depth == 0)
{ {
fprintf(text_file, " YYSTYPE;\n"); fprintf(text_file, " YYSTYPE;\n");
FREE(u_line); free(u_line);
return; return;
} }
goto loop; goto loop;
@ -580,7 +580,7 @@ copy_union(void)
if (dflag) putc(c, union_file); if (dflag) putc(c, union_file);
if (c == quote) if (c == quote)
{ {
FREE(s_line); free(s_line);
goto loop; goto loop;
} }
if (c == '\n') if (c == '\n')
@ -642,7 +642,7 @@ copy_union(void)
putc('/', text_file); putc('/', text_file);
if (dflag) putc('/', union_file); if (dflag) putc('/', union_file);
++cptr; ++cptr;
FREE(c_line); free(c_line);
goto loop; goto loop;
} }
if (c == '\n') if (c == '\n')
@ -751,10 +751,10 @@ get_literal(void)
} }
cachec(c); cachec(c);
} }
FREE(s_line); free(s_line);
n = cinc; n = cinc;
s = MALLOC(n); s = malloc(n);
if (s == 0) no_space(); if (s == 0) no_space();
for (i = 0; i < n; ++i) for (i = 0; i < n; ++i)
@ -807,7 +807,7 @@ get_literal(void)
bp->class = TERM; bp->class = TERM;
if (n == 1 && bp->value == UNDEFINED) if (n == 1 && bp->value == UNDEFINED)
bp->value = *(unsigned char *)s; bp->value = *(unsigned char *)s;
FREE(s); free(s);
return (bp); return (bp);
} }
@ -900,17 +900,17 @@ get_tag(void)
{ {
tagmax += 16; tagmax += 16;
tag_table = (char **) tag_table = (char **)
(tag_table ? REALLOC(tag_table, tagmax*sizeof(char *)) (tag_table ? realloc(tag_table, tagmax*sizeof(char *))
: MALLOC(tagmax*sizeof(char *))); : malloc(tagmax*sizeof(char *)));
if (tag_table == 0) no_space(); if (tag_table == 0) no_space();
} }
s = MALLOC(cinc); s = malloc(cinc);
if (s == 0) no_space(); if (s == 0) no_space();
strcpy(s, cache); strcpy(s, cache);
tag_table[ntags] = s; tag_table[ntags] = s;
++ntags; ++ntags;
FREE(t_line); free(t_line);
return (s); return (s);
} }
@ -1075,7 +1075,7 @@ read_declarations(void)
int c, k; int c, k;
cache_size = 256; cache_size = 256;
cache = MALLOC(cache_size); cache = malloc(cache_size);
if (cache == 0) no_space(); if (cache == 0) no_space();
for (;;) for (;;)
@ -1128,7 +1128,7 @@ initialize_grammar(void)
{ {
nitems = 4; nitems = 4;
maxitems = 300; maxitems = 300;
pitem = (bucket **) MALLOC(maxitems*sizeof(bucket *)); pitem = malloc(maxitems*sizeof(bucket *));
if (pitem == 0) no_space(); if (pitem == 0) no_space();
pitem[0] = 0; pitem[0] = 0;
pitem[1] = 0; pitem[1] = 0;
@ -1137,17 +1137,17 @@ initialize_grammar(void)
nrules = 3; nrules = 3;
maxrules = 100; maxrules = 100;
plhs = (bucket **) MALLOC(maxrules*sizeof(bucket *)); plhs = malloc(maxrules*sizeof(bucket *));
if (plhs == 0) no_space(); if (plhs == 0) no_space();
plhs[0] = 0; plhs[0] = 0;
plhs[1] = 0; plhs[1] = 0;
plhs[2] = 0; plhs[2] = 0;
rprec = (short *) MALLOC(maxrules*sizeof(short)); rprec = malloc(maxrules*sizeof(short));
if (rprec == 0) no_space(); if (rprec == 0) no_space();
rprec[0] = 0; rprec[0] = 0;
rprec[1] = 0; rprec[1] = 0;
rprec[2] = 0; rprec[2] = 0;
rassoc = (char *) MALLOC(maxrules*sizeof(char)); rassoc = malloc(maxrules*sizeof(char));
if (rassoc == 0) no_space(); if (rassoc == 0) no_space();
rassoc[0] = TOKEN; rassoc[0] = TOKEN;
rassoc[1] = TOKEN; rassoc[1] = TOKEN;
@ -1159,7 +1159,7 @@ static void
expand_items(void) expand_items(void)
{ {
maxitems += 300; maxitems += 300;
pitem = (bucket **) REALLOC(pitem, maxitems*sizeof(bucket *)); pitem = realloc(pitem, maxitems*sizeof(bucket *));
if (pitem == 0) no_space(); if (pitem == 0) no_space();
} }
@ -1168,11 +1168,11 @@ static void
expand_rules(void) expand_rules(void)
{ {
maxrules += 100; maxrules += 100;
plhs = (bucket **) REALLOC(plhs, maxrules*sizeof(bucket *)); plhs = realloc(plhs, maxrules*sizeof(bucket *));
if (plhs == 0) no_space(); if (plhs == 0) no_space();
rprec = (short *) REALLOC(rprec, maxrules*sizeof(short)); rprec = realloc(rprec, maxrules*sizeof(short));
if (rprec == 0) no_space(); if (rprec == 0) no_space();
rassoc = (char *) REALLOC(rassoc, maxrules*sizeof(char)); rassoc = realloc(rassoc, maxrules*sizeof(char));
if (rassoc == 0) no_space(); if (rassoc == 0) no_space();
} }
@ -1367,7 +1367,7 @@ copy_action(void)
{ {
fprintf(f, "yyval.%s", tag); fprintf(f, "yyval.%s", tag);
++cptr; ++cptr;
FREE(d_line); free(d_line);
goto loop; goto loop;
} }
else if (isdigit(c)) else if (isdigit(c))
@ -1375,7 +1375,7 @@ copy_action(void)
i = get_number(); i = get_number();
if (i > n) dollar_warning(d_lineno, i); if (i > n) dollar_warning(d_lineno, i);
fprintf(f, "yyvsp[%d].%s", i - n, tag); fprintf(f, "yyvsp[%d].%s", i - n, tag);
FREE(d_line); free(d_line);
goto loop; goto loop;
} }
else if (c == '-' && isdigit(cptr[1])) else if (c == '-' && isdigit(cptr[1]))
@ -1383,7 +1383,7 @@ copy_action(void)
++cptr; ++cptr;
i = -get_number() - n; i = -get_number() - n;
fprintf(f, "yyvsp[%d].%s", i, tag); fprintf(f, "yyvsp[%d].%s", i, tag);
FREE(d_line); free(d_line);
goto loop; goto loop;
} }
else else
@ -1479,7 +1479,7 @@ copy_action(void)
putc(c, f); putc(c, f);
if (c == quote) if (c == quote)
{ {
FREE(s_line); free(s_line);
goto loop; goto loop;
} }
if (c == '\n') if (c == '\n')
@ -1529,7 +1529,7 @@ copy_action(void)
{ {
putc('/', f); putc('/', f);
++cptr; ++cptr;
FREE(c_line); free(c_line);
goto loop; goto loop;
} }
if (c == '\n') if (c == '\n')
@ -1636,9 +1636,9 @@ free_tags(void)
for (i = 0; i < ntags; ++i) for (i = 0; i < ntags; ++i)
{ {
assert(tag_table[i]); assert(tag_table[i]);
FREE(tag_table[i]); free(tag_table[i]);
} }
FREE(tag_table); free(tag_table);
} }
@ -1651,7 +1651,7 @@ pack_names(void)
name_pool_size = 13; /* 13 == sizeof("$end") + sizeof("$accept") */ name_pool_size = 13; /* 13 == sizeof("$end") + sizeof("$accept") */
for (bp = first_symbol; bp; bp = bp->next) for (bp = first_symbol; bp; bp = bp->next)
name_pool_size += strlen(bp->name) + 1; name_pool_size += strlen(bp->name) + 1;
name_pool = MALLOC(name_pool_size); name_pool = malloc(name_pool_size);
if (name_pool == 0) no_space(); if (name_pool == 0) no_space();
strcpy(name_pool, "$accept"); strcpy(name_pool, "$accept");
@ -1662,7 +1662,7 @@ pack_names(void)
p = t; p = t;
s = bp->name; s = bp->name;
while ((*t++ = *s++)) continue; while ((*t++ = *s++)) continue;
FREE(bp->name); free(bp->name);
bp->name = p; bp->name = p;
} }
} }
@ -1704,16 +1704,16 @@ pack_symbols(void)
start_symbol = ntokens; start_symbol = ntokens;
nvars = nsyms - ntokens; nvars = nsyms - ntokens;
symbol_name = (char **) MALLOC(nsyms*sizeof(char *)); symbol_name = malloc(nsyms*sizeof(char *));
if (symbol_name == 0) no_space(); if (symbol_name == 0) no_space();
symbol_value = (short *) MALLOC(nsyms*sizeof(short)); symbol_value = malloc(nsyms*sizeof(short));
if (symbol_value == 0) no_space(); if (symbol_value == 0) no_space();
symbol_prec = (short *) MALLOC(nsyms*sizeof(short)); symbol_prec = malloc(nsyms*sizeof(short));
if (symbol_prec == 0) no_space(); if (symbol_prec == 0) no_space();
symbol_assoc = MALLOC(nsyms); symbol_assoc = malloc(nsyms);
if (symbol_assoc == 0) no_space(); if (symbol_assoc == 0) no_space();
v = (bucket **) MALLOC(nsyms*sizeof(bucket *)); v = malloc(nsyms*sizeof(bucket *));
if (v == 0) no_space(); if (v == 0) no_space();
v[0] = 0; v[0] = 0;
@ -1808,7 +1808,7 @@ pack_symbols(void)
symbol_assoc[k] = v[i]->assoc; symbol_assoc[k] = v[i]->assoc;
} }
FREE(v); free(v);
} }
@ -1818,15 +1818,15 @@ pack_grammar(void)
int i, j; int i, j;
int assoc, preced; int assoc, preced;
ritem = (short *) MALLOC(nitems*sizeof(short)); ritem = malloc(nitems*sizeof(short));
if (ritem == 0) no_space(); if (ritem == 0) no_space();
rlhs = (short *) MALLOC(nrules*sizeof(short)); rlhs = malloc(nrules*sizeof(short));
if (rlhs == 0) no_space(); if (rlhs == 0) no_space();
rrhs = (short *) MALLOC((nrules+1)*sizeof(short)); rrhs = malloc((nrules+1)*sizeof(short));
if (rrhs == 0) no_space(); if (rrhs == 0) no_space();
rprec = (short *) REALLOC(rprec, nrules*sizeof(short)); rprec = realloc(rprec, nrules*sizeof(short));
if (rprec == 0) no_space(); if (rprec == 0) no_space();
rassoc = REALLOC(rassoc, nrules); rassoc = realloc(rassoc, nrules);
if (rassoc == 0) no_space(); if (rassoc == 0) no_space();
ritem[0] = -1; ritem[0] = -1;
@ -1867,8 +1867,8 @@ pack_grammar(void)
} }
rrhs[i] = j; rrhs[i] = j;
FREE(plhs); free(plhs);
FREE(pitem); free(pitem);
} }

View File

@ -157,14 +157,14 @@ const char *body[] =
" else if ((newsize *= 2) > YYMAXDEPTH)", " else if ((newsize *= 2) > YYMAXDEPTH)",
" newsize = YYMAXDEPTH;", " newsize = YYMAXDEPTH;",
" i = yyssp - yyss;", " i = yyssp - yyss;",
" newss = yyss ? (short *)realloc(yyss, newsize * sizeof *newss) :", " newss = yyss ? realloc(yyss, newsize * sizeof *newss) :",
" (short *)malloc(newsize * sizeof *newss);", " malloc(newsize * sizeof *newss);",
" if (newss == NULL)", " if (newss == NULL)",
" return -1;", " return -1;",
" yyss = newss;", " yyss = newss;",
" yyssp = newss + i;", " yyssp = newss + i;",
" newvs = yyvs ? (YYSTYPE *)realloc(yyvs, newsize * sizeof *newvs) :", " newvs = yyvs ? realloc(yyvs, newsize * sizeof *newvs) :",
" (YYSTYPE *)malloc(newsize * sizeof *newvs);", " malloc(newsize * sizeof *newvs);",
" if (newvs == NULL)", " if (newvs == NULL)",
" return -1;", " return -1;",
" yyvs = newvs;", " yyvs = newvs;",

View File

@ -81,11 +81,11 @@ make_bucket(const char *name)
bucket *bp; bucket *bp;
assert(name); assert(name);
bp = (bucket *) MALLOC(sizeof(bucket)); bp = malloc(sizeof(bucket));
if (bp == 0) no_space(); if (bp == 0) no_space();
bp->link = 0; bp->link = 0;
bp->next = 0; bp->next = 0;
bp->name = MALLOC(strlen(name) + 1); bp->name = malloc(strlen(name) + 1);
if (bp->name == 0) no_space(); if (bp->name == 0) no_space();
bp->tag = 0; bp->tag = 0;
bp->value = UNDEFINED; bp->value = UNDEFINED;
@ -130,7 +130,7 @@ create_symbol_table(void)
int i; int i;
bucket *bp; bucket *bp;
symbol_table = (bucket **) MALLOC(TABLE_SIZE*sizeof(bucket *)); symbol_table = malloc(TABLE_SIZE*sizeof(bucket *));
if (symbol_table == 0) no_space(); if (symbol_table == 0) no_space();
for (i = 0; i < TABLE_SIZE; i++) for (i = 0; i < TABLE_SIZE; i++)
symbol_table[i] = 0; symbol_table[i] = 0;
@ -148,7 +148,7 @@ create_symbol_table(void)
void void
free_symbol_table(void) free_symbol_table(void)
{ {
FREE(symbol_table); free(symbol_table);
symbol_table = 0; symbol_table = 0;
} }
@ -161,6 +161,6 @@ free_symbols(void)
for (p = first_symbol; p; p = q) for (p = first_symbol; p; p = q)
{ {
q = p->next; q = p->next;
FREE(p); free(p);
} }
} }

View File

@ -66,12 +66,12 @@ verbose(void)
if (!vflag) return; if (!vflag) return;
null_rules = (short *) MALLOC(nrules*sizeof(short)); null_rules = malloc(nrules*sizeof(short));
if (null_rules == 0) no_space(); if (null_rules == 0) no_space();
fprintf(verbose_file, "\f\n"); fprintf(verbose_file, "\f\n");
for (i = 0; i < nstates; i++) for (i = 0; i < nstates; i++)
print_state(i); print_state(i);
FREE(null_rules); free(null_rules);
if (nunused) if (nunused)
log_unused(); log_unused();