From 0963ddab1b9d52fe69298de00a7e3eb643ac3db7 Mon Sep 17 00:00:00 2001 From: Dalton Woodard Date: Tue, 14 Oct 2014 22:25:52 -0700 Subject: [PATCH 1/9] Update to .gitignore to exclude example executables. --- .gitignore | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.gitignore b/.gitignore index 06a9a1b..4a8162c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,7 @@ *~ *.exe test +doge +lispy +maths +smallc From 1a6ed8de3267260c80f8582915c1a5e6d99d9cb2 Mon Sep 17 00:00:00 2001 From: Dalton Woodard Date: Tue, 14 Oct 2014 22:33:21 -0700 Subject: [PATCH 2/9] Fixed make throwing error on repeated invokation of make clean, added example executables to clean list. Filtered out -Werror on compilation of ptest.c (was thowing errors). --- Makefile | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index d36a7bf..d950655 100644 --- a/Makefile +++ b/Makefile @@ -1,18 +1,18 @@ CC = gcc -CFLAGS = -ansi -pedantic -Wall -Wno-overlength-strings -Werror -O3 -g +CFLAGS = -std=c11 -Wall -Wextra -Werror -O3 -g TESTS = $(wildcard tests/*.c) EXAMPLES = $(wildcard examples/*.c) EXAMPLESEXE = $(EXAMPLES:.c=) all: $(EXAMPLESEXE) check - + check: $(TESTS) mpc.c - $(CC) $(CFLAGS) $^ -lm -o test + $(CC) $(filter-out -Werror, $(CFLAGS)) $^ -lm -o test ./test - + examples/%: examples/%.c mpc.c $(CC) $(CFLAGS) $^ -lm -o $@ clean: - rm test + rm -rf test examples/doge examples/lispy examples/maths examples/smallc From 4bdbf4f2ad46f1a4a11cf2006e47484ae6265050 Mon Sep 17 00:00:00 2001 From: Dalton Woodard Date: Tue, 14 Oct 2014 23:15:00 -0700 Subject: [PATCH 3/9] Update to .gitignore, added *.dSYM (get's rid of OS X crap) --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 4a8162c..14a8995 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ *~ *.exe +*.dSYM test doge lispy From c26ed9a09b659eb4c6a6e70bf469158607c6d850 Mon Sep 17 00:00:00 2001 From: Dalton Woodard Date: Tue, 14 Oct 2014 23:16:11 -0700 Subject: [PATCH 4/9] Update to Makefile, added change notes. --- Makefile | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index d950655..8fea7d5 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,15 @@ +# change notes: +# filter out -Werror when compiling with gcc. It chooses to warn about strange things sometimes. +# Compiles will all flags below on clang with -Werror. + CC = gcc -CFLAGS = -std=c11 -Wall -Wextra -Werror -O3 -g +CFLAGS = -std=c11 -O3 -g -Wall -Wextra -Wformat=2 -Wshadow \ + -Wno-format-nonliteral -Wcast-align -Wwrite-strings -Wstrict-prototypes -Wold-style-definition \ + -Wredundant-decls -Wnested-externs -Wmissing-include-dirs -Wswitch-default + +ifneq ($(CC),gcc) + $(CFLAGS) += -Werror +endif TESTS = $(wildcard tests/*.c) EXAMPLES = $(wildcard examples/*.c) From bd9e5d98d63d68ce99786b5eab6b3374b427410c Mon Sep 17 00:00:00 2001 From: Dalton Woodard Date: Tue, 14 Oct 2014 23:18:02 -0700 Subject: [PATCH 5/9] Fixed all compilation warnings for mpc.c and mpc.h. Now compiles successfully on clang with -Werror and myriad warnings invoked (see Makefile for details). Compiles successfully on gcc with -Werror (ptest.c and example code does not, however). --- mpc.c | 116 ++++++++++++++++++++++++++++++++-------------------------- mpc.h | 10 +++-- 2 files changed, 72 insertions(+), 54 deletions(-) diff --git a/mpc.c b/mpc.c index 5b0c5c4..2a0b4d0 100644 --- a/mpc.c +++ b/mpc.c @@ -6,9 +6,9 @@ static mpc_state_t mpc_state_invalid(void) { mpc_state_t s; - s.pos = -1; - s.row = -1; - s.col = -1; + s.pos = SIZE_MAX; + s.row = SIZE_MAX; + s.col = SIZE_MAX; return s; } @@ -112,7 +112,7 @@ void mpc_err_print_to(mpc_err_t *x, FILE *f) { free(str); } -void mpc_err_string_cat(char *buffer, int *pos, int *max, char *fmt, ...) { +void mpc_err_string_cat(char *buffer, int *pos, int *max, char const *fmt, ...) { /* TODO: Error Checking on Length */ int left = ((*max) - (*pos)); va_list va; @@ -124,7 +124,7 @@ void mpc_err_string_cat(char *buffer, int *pos, int *max, char *fmt, ...) { static char char_unescape_buffer[3]; -static char *mpc_err_char_unescape(char c) { +static const char *mpc_err_char_unescape(char c) { char_unescape_buffer[0] = '\''; char_unescape_buffer[1] = ' '; @@ -157,8 +157,7 @@ char *mpc_err_string(mpc_err_t *x) { if (x->failure) { mpc_err_string_cat(buffer, &pos, &max, - "%s: error: %s\n", - x->filename, x->failure); + "%s: error: %s\n", x->filename, x->failure); return buffer; } @@ -541,12 +540,13 @@ static char mpc_input_peekc(mpc_input_t *i) { } +/* filled in default case */ static int mpc_input_failure(mpc_input_t *i, char c) { switch (i->type) { - case MPC_INPUT_STRING: break; - case MPC_INPUT_FILE: fseek(i->file, -1, SEEK_CUR); break; - case MPC_INPUT_PIPE: + case MPC_INPUT_STRING: { break; } + case MPC_INPUT_FILE: fseek(i->file, -1, SEEK_CUR); { break; } + case MPC_INPUT_PIPE: { if (!i->buffer) { ungetc(c, i->file); break; } @@ -555,9 +555,9 @@ static int mpc_input_failure(mpc_input_t *i, char c) { } else { ungetc(c, i->file); } - + } + default: { break; } } - return 0; } @@ -1676,16 +1676,17 @@ mpc_parser_t *mpc_and(int n, mpc_fold_t f, ...) { ** Common Parsers */ -static int mpc_soi_anchor(char prev, char next) { return (prev == '\0'); } -static int mpc_eoi_anchor(char prev, char next) { return (next == '\0'); } +/* casting to remove warnings rather than changing api */ +static int mpc_soi_anchor(char prev, char next) { (void) next; return (prev == '\0'); } +static int mpc_eoi_anchor(char prev, char next) { (void) prev; return (next == '\0'); } mpc_parser_t *mpc_soi(void) { return mpc_expect(mpc_anchor(mpc_soi_anchor), "start of input"); } mpc_parser_t *mpc_eoi(void) { return mpc_expect(mpc_anchor(mpc_eoi_anchor), "end of input"); } static int mpc_boundary_anchor(char prev, char next) { - char* word = "abcdefghijklmnopqrstuvwxyz" - "ABCDEFGHIJKLMNOPQRSTUVWXYZ" - "0123456789_"; + const char* word = "abcdefghijklmnopqrstuvwxyz" + "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "0123456789_"; if ( strchr(word, next) && prev == '\0') { return 1; } if ( strchr(word, prev) && next == '\0') { return 1; } if ( strchr(word, next) && !strchr(word, prev)) { return 1; } @@ -1853,6 +1854,8 @@ mpc_parser_t *mpc_tok_squares(mpc_parser_t *a, mpc_dtor_t ad) { return mpc_tok_ */ static mpc_val_t *mpcf_re_or(int n, mpc_val_t **xs) { + /* casting to remove unused warning rather than changing api */ + (void) n; if (xs[1] == NULL) { return xs[0]; } else { return mpc_or(2, xs[0], xs[1]); } } @@ -1867,7 +1870,8 @@ static mpc_val_t *mpcf_re_and(int n, mpc_val_t **xs) { } static mpc_val_t *mpcf_re_repeat(int n, mpc_val_t **xs) { - + /* casting to remove unused warning rather than changing api */ + (void) n; int num; if (xs[1] == NULL) { return xs[0]; } if (strcmp(xs[1], "*") == 0) { free(xs[1]); return mpc_many(mpcf_strfold, xs[0]); } @@ -1925,7 +1929,7 @@ static mpc_val_t *mpcf_re_escape(mpc_val_t *x) { return p; } -static char *mpc_re_range_escape_char(char c) { +static const char *mpc_re_range_escape_char(char c) { switch (c) { case '-': return "-"; case 'a': return "\a"; @@ -1946,18 +1950,17 @@ static mpc_val_t *mpcf_re_range(mpc_val_t *x) { mpc_parser_t *out; char *range = calloc(1,1); - char *tmp = NULL; - char *s = x; - char start, end; - int i, j; - int comp = 0; + const char *tmp = NULL; + const char *s = x; + size_t start, end; if (s[0] == '\0') { free(x); return mpc_fail("Invalid Regex Range Expression"); } if (s[0] == '^' && s[1] == '\0') { free(x); return mpc_fail("Invalid Regex Range Expression"); } - if (s[0] == '^') { comp = 1;} - + int comp = s[0] == '^' ? 1 : 0; + + size_t i, j; /* changed to use size_t to remove type comparison warnings */ for (i = comp; i < strlen(s); i++){ /* Regex Range Escape */ @@ -1999,7 +2002,7 @@ static mpc_val_t *mpcf_re_range(mpc_val_t *x) { } - out = comp ? mpc_noneof(range) : mpc_oneof(range); + out = comp == 1 ? mpc_noneof(range) : mpc_oneof(range); free(x); free(range); @@ -2069,8 +2072,8 @@ mpc_parser_t *mpc_re(const char *re) { /* ** Common Fold Functions */ - -void mpcf_dtor_null(mpc_val_t *x) { return; } +/* casting to remove unused warning rather than changing api */ +void mpcf_dtor_null(mpc_val_t *x) { (void) x; return; } mpc_val_t *mpcf_ctor_null(void) { return NULL; } mpc_val_t *mpcf_ctor_str(void) { return calloc(1, 1); } @@ -2104,24 +2107,24 @@ mpc_val_t *mpcf_float(mpc_val_t *x) { return y; } -static char mpc_escape_input_c[] = { +static const char mpc_escape_input_c[] = { '\a', '\b', '\f', '\n', '\r', '\t', '\v', '\\', '\'', '\"', '\0'}; -static char *mpc_escape_output_c[] = { +static const char *mpc_escape_output_c[] = { "\\a", "\\b", "\\f", "\\n", "\\r", "\\t", "\\v", "\\\\", "\\'", "\\\"", "\\0", NULL}; -static char mpc_escape_input_raw_re[] = { '/' }; -static char *mpc_escape_output_raw_re[] = { "\\/", NULL }; +static const char mpc_escape_input_raw_re[] = { '/' }; +static const char *mpc_escape_output_raw_re[] = { "\\/", NULL }; -static char mpc_escape_input_raw_cstr[] = { '"' }; -static char *mpc_escape_output_raw_cstr[] = { "\\\"", NULL }; +static const char mpc_escape_input_raw_cstr[] = { '"' }; +static const char *mpc_escape_output_raw_cstr[] = { "\\\"", NULL }; -static char mpc_escape_input_raw_cchar[] = { '\'' }; -static char *mpc_escape_output_raw_cchar[] = { "\\'", NULL }; +static const char mpc_escape_input_raw_cchar[] = { '\'' }; +static const char *mpc_escape_output_raw_cchar[] = { "\\'", NULL }; -static mpc_val_t *mpcf_escape_new(mpc_val_t *x, char *input, char **output) { +static mpc_val_t *mpcf_escape_new(mpc_val_t *x, const char *input, const char **output) { int i; int found; @@ -2157,7 +2160,7 @@ static mpc_val_t *mpcf_escape_new(mpc_val_t *x, char *input, char **output) { return y; } -static mpc_val_t *mpcf_unescape_new(mpc_val_t *x, char *input, char **output) { +static mpc_val_t *mpcf_unescape_new(mpc_val_t *x, const char *input, const char **output) { int i; int found = 0; @@ -2238,11 +2241,11 @@ mpc_val_t *mpcf_unescape_char_raw(mpc_val_t *x) { free(x); return y; } - -mpc_val_t *mpcf_null(int n, mpc_val_t** xs) { return NULL; } -mpc_val_t *mpcf_fst(int n, mpc_val_t **xs) { return xs[0]; } -mpc_val_t *mpcf_snd(int n, mpc_val_t **xs) { return xs[1]; } -mpc_val_t *mpcf_trd(int n, mpc_val_t **xs) { return xs[2]; } +/* casting to remove unused warnings rather than changing api */ +mpc_val_t *mpcf_null(int n, mpc_val_t** xs) { (void) n; (void) xs; return NULL; } +mpc_val_t *mpcf_fst(int n, mpc_val_t **xs) { (void) n; return xs[0]; } +mpc_val_t *mpcf_snd(int n, mpc_val_t **xs) { (void) n; return xs[1]; } +mpc_val_t *mpcf_trd(int n, mpc_val_t **xs) { (void) n; return xs[2]; } static mpc_val_t *mpcf_nth_free(int n, mpc_val_t **xs, int x) { int i; @@ -2268,7 +2271,8 @@ mpc_val_t *mpcf_strfold(int n, mpc_val_t **xs) { } mpc_val_t *mpcf_maths(int n, mpc_val_t **xs) { - + /* casting to remove unused warning rather than changing api */ + (void) n; int **vs = (int**)xs; if (strcmp(xs[1], "*") == 0) { *vs[0] *= *vs[2]; } @@ -2425,6 +2429,8 @@ int mpc_test_fail(mpc_parser_t *p, const char *s, void *d, mpc_dtor_t destructor, void(*printer)(void*)) { + /* casting to remove unused warning rather than changing api */ + (void) printer; mpc_result_t r; if (mpc_parse("", s, p, &r)) { @@ -2596,7 +2602,7 @@ static void mpc_ast_print_depth(mpc_ast_t *a, int d, FILE *fp) { for (i = 0; i < d; i++) { fprintf(fp, " "); } if (strlen(a->contents)) { - fprintf(fp, "%s:%i:%i '%s'\n", a->tag, a->state.row+1, a->state.col+1, a->contents); + fprintf(fp, "%s:%lu:%lu '%s'\n", a->tag, a->state.row+1, a->state.col+1, a->contents); } else { fprintf(fp, "%s \n", a->tag); } @@ -2660,6 +2666,8 @@ mpc_val_t *mpcf_str_ast(mpc_val_t *c) { } mpc_val_t *mpcf_state_ast(int n, mpc_val_t **xs) { + /* casting to remove unused warning rather than changing api */ + (void) n; mpc_state_t *s = ((mpc_state_t**)xs)[0]; mpc_ast_t *a = ((mpc_ast_t**)xs)[1]; a = mpc_ast_state(a, *s); @@ -2789,6 +2797,8 @@ typedef struct { } mpca_grammar_st_t; static mpc_val_t *mpcaf_grammar_or(int n, mpc_val_t **xs) { + /* casting to remove unused warning rather than changing api */ + (void) n; if (xs[1] == NULL) { return xs[0]; } else { return mpca_or(2, xs[0], xs[1]); } } @@ -2804,6 +2814,8 @@ static mpc_val_t *mpcaf_grammar_and(int n, mpc_val_t **xs) { static mpc_val_t *mpcaf_grammar_repeat(int n, mpc_val_t **xs) { + /* casting to remove unused warning rather than changing api */ + (void) n; int num; if (xs[1] == NULL) { return xs[0]; } if (strcmp(xs[1], "*") == 0) { free(xs[1]); return mpca_many(xs[0]); } @@ -2840,8 +2852,9 @@ static mpc_val_t *mpcaf_grammar_regex(mpc_val_t *x, void *s) { } /* Should this just use `isdigit` instead */ +/* Changed to use size_t for loop index, removes type comparison warning */ static int is_number(const char* s) { - int i; + size_t i; for (i = 0; i < strlen(s); i++) { if (!strchr("0123456789", s[i])) { return 0; } } return 1; } @@ -2872,9 +2885,9 @@ static mpc_parser_t *mpca_grammar_find_parser(char *x, mpca_grammar_st_t *st) { /* Search Existing Parsers */ for (i = 0; i < st->parsers_num; i++) { - mpc_parser_t *p = st->parsers[i]; - if (p == NULL) { return mpc_failf("Unknown Parser '%s'!", x); } - if (p->name && strcmp(p->name, x) == 0) { return p; } + mpc_parser_t *q = st->parsers[i]; /* `p` was shadowing the `p` above, now changed to q */ + if (q == NULL) { return mpc_failf("Unknown Parser '%s'!", x); } + if (q->name && strcmp(q->name, x) == 0) { return q; } } /* Search New Parsers */ @@ -2991,7 +3004,8 @@ typedef struct { } mpca_stmt_t; static mpc_val_t *mpca_stmt_afold(int n, mpc_val_t **xs) { - + /* casting to remove unused warnings rather than changing api */ + (void) n; mpca_stmt_t *stmt = malloc(sizeof(mpca_stmt_t)); stmt->ident = ((char**)xs)[0]; stmt->name = ((char**)xs)[1]; diff --git a/mpc.h b/mpc.h index 708e00c..e72cfc4 100644 --- a/mpc.h +++ b/mpc.h @@ -21,10 +21,14 @@ ** State Type */ +/* +** changed to unsigned values for indexing in state, +** invalid is now signified by SIZE_MAX. +*/ typedef struct { - int pos; - int row; - int col; + size_t pos; + size_t row; + size_t col; } mpc_state_t; /* From ff361562838a86dc271eaef916f7c5d50efd1491 Mon Sep 17 00:00:00 2001 From: Dalton Woodard Date: Tue, 14 Oct 2014 23:21:03 -0700 Subject: [PATCH 6/9] Small update to change notes in Makefile. --- Makefile | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 8fea7d5..4bd4abb 100644 --- a/Makefile +++ b/Makefile @@ -1,16 +1,12 @@ # change notes: -# filter out -Werror when compiling with gcc. It chooses to warn about strange things sometimes. -# Compiles will all flags below on clang with -Werror. +# filter out -Werror when compiling ptest. GCC chooses to warn about strange things sometimes. +# mpc.c and mpc.h ompile will all flags below on clang and gcc with -Werror. CC = gcc -CFLAGS = -std=c11 -O3 -g -Wall -Wextra -Wformat=2 -Wshadow \ +CFLAGS = -std=c11 -O3 -g -Werror -Wall -Wextra -Wformat=2 -Wshadow \ -Wno-format-nonliteral -Wcast-align -Wwrite-strings -Wstrict-prototypes -Wold-style-definition \ -Wredundant-decls -Wnested-externs -Wmissing-include-dirs -Wswitch-default -ifneq ($(CC),gcc) - $(CFLAGS) += -Werror -endif - TESTS = $(wildcard tests/*.c) EXAMPLES = $(wildcard examples/*.c) EXAMPLESEXE = $(EXAMPLES:.c=) From 4f1dc8f6f9feab8d17dbd51713fdf8fe2aa181f8 Mon Sep 17 00:00:00 2001 From: Dalton Woodard Date: Tue, 14 Oct 2014 23:27:42 -0700 Subject: [PATCH 7/9] Added CHANGELOG.md --- CHANGELOG.md | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..f41bcd0 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,10 @@ +# Oct. 14, 2014; Dalton Woodard +- Fixed all compilation warnings in `mpc.h` and `mpc.c`; both now compile successfully on OS X under clang-600.0.51 +and gcc 4.9.1 with the following flags: +``` +-std=c11 -O3 -g -Werror -Wall -Wextra -Wformat=2 -Wshadow -Wno-format-nonliteral -Wcast-align -Wwrite-strings +-Wstrict-prototypes -Wold-style-definition -Wredundant-decls -Wnested-externs -Wmissing-include-dirs -Wswitch-default +``` +- Changed compilation standard from ansi to c11. +- Further small changes in source (documented in-line). + From bae8dd5d82286b3eddb23c92aae984489d415176 Mon Sep 17 00:00:00 2001 From: Dalton Woodard Date: Tue, 14 Oct 2014 23:32:13 -0700 Subject: [PATCH 8/9] Moved changelog to text file. --- CHANGELOG.md => CHANGELOG.txt | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename CHANGELOG.md => CHANGELOG.txt (100%) diff --git a/CHANGELOG.md b/CHANGELOG.txt similarity index 100% rename from CHANGELOG.md rename to CHANGELOG.txt From 6efe026b2550d1a09a93e470bd61e0f592c2f30c Mon Sep 17 00:00:00 2001 From: Dalton Woodard Date: Wed, 15 Oct 2014 16:23:59 -0700 Subject: [PATCH 9/9] Reverted to default standard to -ansi. Fixed warnings under compilation against -ansi. Code now builds and tests successfully under -std=c11 and -ansi on both clang (600.0.51) and gcc (4.9.1). --- Makefile | 10 +++++++--- mpc.c | 27 +++++++++++---------------- 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/Makefile b/Makefile index 4bd4abb..5b4f7d7 100644 --- a/Makefile +++ b/Makefile @@ -1,11 +1,15 @@ # change notes: # filter out -Werror when compiling ptest. GCC chooses to warn about strange things sometimes. # mpc.c and mpc.h ompile will all flags below on clang and gcc with -Werror. +# added standard flag (and reverted to -ansi, can now be changed from command line `make -STD=...` +# to compile against various standards. CC = gcc -CFLAGS = -std=c11 -O3 -g -Werror -Wall -Wextra -Wformat=2 -Wshadow \ - -Wno-format-nonliteral -Wcast-align -Wwrite-strings -Wstrict-prototypes -Wold-style-definition \ - -Wredundant-decls -Wnested-externs -Wmissing-include-dirs -Wswitch-default +STND=-ansi +CFLAGS = $(STND) -pedantic -O3 -g -Werror -Wall -Wextra -Wformat=2 -Wshadow -Wno-long-long \ + -Wno-overlength-strings -Wno-format-nonliteral -Wcast-align \ + -Wwrite-strings -Wstrict-prototypes -Wold-style-definition -Wredundant-decls -Wnested-externs \ + -Wmissing-include-dirs -Wswitch-default TESTS = $(wildcard tests/*.c) EXAMPLES = $(wildcard examples/*.c) diff --git a/mpc.c b/mpc.c index 2a0b4d0..e2901b5 100644 --- a/mpc.c +++ b/mpc.c @@ -1871,8 +1871,8 @@ static mpc_val_t *mpcf_re_and(int n, mpc_val_t **xs) { static mpc_val_t *mpcf_re_repeat(int n, mpc_val_t **xs) { /* casting to remove unused warning rather than changing api */ - (void) n; int num; + (void) n; if (xs[1] == NULL) { return xs[0]; } if (strcmp(xs[1], "*") == 0) { free(xs[1]); return mpc_many(mpcf_strfold, xs[0]); } if (strcmp(xs[1], "+") == 0) { free(xs[1]); return mpc_many1(mpcf_strfold, xs[0]); } @@ -1952,15 +1952,14 @@ static mpc_val_t *mpcf_re_range(mpc_val_t *x) { char *range = calloc(1,1); const char *tmp = NULL; const char *s = x; + int comp = s[0] == '^' ? 1 : 0; size_t start, end; + size_t i, j; /* changed to use size_t to remove type comparison warnings */ if (s[0] == '\0') { free(x); return mpc_fail("Invalid Regex Range Expression"); } if (s[0] == '^' && s[1] == '\0') { free(x); return mpc_fail("Invalid Regex Range Expression"); } - int comp = s[0] == '^' ? 1 : 0; - - size_t i, j; /* changed to use size_t to remove type comparison warnings */ for (i = comp; i < strlen(s); i++){ /* Regex Range Escape */ @@ -2271,9 +2270,8 @@ mpc_val_t *mpcf_strfold(int n, mpc_val_t **xs) { } mpc_val_t *mpcf_maths(int n, mpc_val_t **xs) { - /* casting to remove unused warning rather than changing api */ - (void) n; int **vs = (int**)xs; + (void) n; /* casting to remove unused warning rather than changing api */ if (strcmp(xs[1], "*") == 0) { *vs[0] *= *vs[2]; } if (strcmp(xs[1], "/") == 0) { *vs[0] /= *vs[2]; } @@ -2428,10 +2426,9 @@ int mpc_test_fail(mpc_parser_t *p, const char *s, void *d, int(*tester)(void*, void*), mpc_dtor_t destructor, void(*printer)(void*)) { - + mpc_result_t r; /* casting to remove unused warning rather than changing api */ (void) printer; - mpc_result_t r; if (mpc_parse("", s, p, &r)) { if (tester(r.output, d)) { @@ -2666,12 +2663,12 @@ mpc_val_t *mpcf_str_ast(mpc_val_t *c) { } mpc_val_t *mpcf_state_ast(int n, mpc_val_t **xs) { - /* casting to remove unused warning rather than changing api */ - (void) n; mpc_state_t *s = ((mpc_state_t**)xs)[0]; mpc_ast_t *a = ((mpc_ast_t**)xs)[1]; a = mpc_ast_state(a, *s); free(s); + /* casting to remove unused warning rather than changing api */ + (void) n; return a; } @@ -2812,11 +2809,10 @@ static mpc_val_t *mpcaf_grammar_and(int n, mpc_val_t **xs) { return p; } -static mpc_val_t *mpcaf_grammar_repeat(int n, mpc_val_t **xs) { - +static mpc_val_t *mpcaf_grammar_repeat(int n, mpc_val_t **xs) { + int num; /* casting to remove unused warning rather than changing api */ (void) n; - int num; if (xs[1] == NULL) { return xs[0]; } if (strcmp(xs[1], "*") == 0) { free(xs[1]); return mpca_many(xs[0]); } if (strcmp(xs[1], "+") == 0) { free(xs[1]); return mpca_many1(xs[0]); } @@ -3004,13 +3000,12 @@ typedef struct { } mpca_stmt_t; static mpc_val_t *mpca_stmt_afold(int n, mpc_val_t **xs) { - /* casting to remove unused warnings rather than changing api */ - (void) n; mpca_stmt_t *stmt = malloc(sizeof(mpca_stmt_t)); stmt->ident = ((char**)xs)[0]; stmt->name = ((char**)xs)[1]; stmt->grammar = ((mpc_parser_t**)xs)[3]; - + /* casting to remove unused warnings rather than changing api */ + (void) n; free(((char**)xs)[2]); free(((char**)xs)[4]);