Removed comments describing changes. Fixed warnings reported by gcc in the test suite

This commit is contained in:
Daniel Holden
2014-10-16 15:38:27 +01:00
parent 1fba0abb39
commit 5094d2c015
8 changed files with 43 additions and 52 deletions

View File

@@ -1,8 +1,3 @@
# 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
STND=-ansi

45
mpc.c
View File

@@ -540,7 +540,6 @@ 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) {
@@ -555,8 +554,8 @@ static int mpc_input_failure(mpc_input_t *i, char c) {
} else {
ungetc(c, i->file);
}
}
default: { break; }
}
default: { break; }
}
return 0;
}
@@ -1676,7 +1675,6 @@ mpc_parser_t *mpc_and(int n, mpc_fold_t f, ...) {
** Common Parsers
*/
/* 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'); }
@@ -1854,7 +1852,6 @@ 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]); }
@@ -1870,7 +1867,6 @@ 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 */
int num;
(void) n;
if (xs[1] == NULL) { return xs[0]; }
@@ -1954,7 +1950,7 @@ static mpc_val_t *mpcf_re_range(mpc_val_t *x) {
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 */
size_t i, j;
if (s[0] == '\0') { free(x); return mpc_fail("Invalid Regex Range Expression"); }
if (s[0] == '^' &&
@@ -2071,7 +2067,7 @@ mpc_parser_t *mpc_re(const char *re) {
/*
** Common Fold Functions
*/
/* 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; }
@@ -2240,7 +2236,7 @@ mpc_val_t *mpcf_unescape_char_raw(mpc_val_t *x) {
free(x);
return y;
}
/* 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]; }
@@ -2271,8 +2267,8 @@ mpc_val_t *mpcf_strfold(int n, mpc_val_t **xs) {
mpc_val_t *mpcf_maths(int n, mpc_val_t **xs) {
int **vs = (int**)xs;
(void) n; /* casting to remove unused warning rather than changing api */
(void) n;
if (strcmp(xs[1], "*") == 0) { *vs[0] *= *vs[2]; }
if (strcmp(xs[1], "/") == 0) { *vs[0] /= *vs[2]; }
if (strcmp(xs[1], "%") == 0) { *vs[0] %= *vs[2]; }
@@ -2422,12 +2418,11 @@ void mpc_print(mpc_parser_t *p) {
**
*/
int mpc_test_fail(mpc_parser_t *p, const char *s, void *d,
int(*tester)(void*, void*),
int mpc_test_fail(mpc_parser_t *p, const char *s, const void *d,
int(*tester)(const void*, const void*),
mpc_dtor_t destructor,
void(*printer)(void*)) {
void(*printer)(const void*)) {
mpc_result_t r;
/* casting to remove unused warning rather than changing api */
(void) printer;
if (mpc_parse("<test>", s, p, &r)) {
@@ -2446,10 +2441,10 @@ int mpc_test_fail(mpc_parser_t *p, const char *s, void *d,
}
int mpc_test_pass(mpc_parser_t *p, const char *s, void *d,
int(*tester)(void*, void*),
int mpc_test_pass(mpc_parser_t *p, const char *s, const void *d,
int(*tester)(const void*, const void*),
mpc_dtor_t destructor,
void(*printer)(void*)) {
void(*printer)(const void*)) {
mpc_result_t r;
if (mpc_parse("<test>", s, p, &r)) {
@@ -2599,7 +2594,10 @@ 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:%lu:%lu '%s'\n", a->tag, a->state.row+1, a->state.col+1, a->contents);
fprintf(fp, "%s:%lu:%lu '%s'\n", a->tag,
(long unsigned int)(a->state.row+1),
(long unsigned int)(a->state.col+1),
a->contents);
} else {
fprintf(fp, "%s \n", a->tag);
}
@@ -2667,7 +2665,6 @@ mpc_val_t *mpcf_state_ast(int n, mpc_val_t **xs) {
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;
}
@@ -2794,7 +2791,6 @@ 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]); }
@@ -2811,7 +2807,6 @@ 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) {
int num;
/* casting to remove unused warning rather than changing api */
(void) n;
if (xs[1] == NULL) { return xs[0]; }
if (strcmp(xs[1], "*") == 0) { free(xs[1]); return mpca_many(xs[0]); }
@@ -2847,8 +2842,7 @@ static mpc_val_t *mpcaf_grammar_regex(mpc_val_t *x, void *s) {
return mpca_state(mpca_tag(mpc_apply(p, mpcf_str_ast), "regex"));
}
/* Should this just use `isdigit` instead */
/* Changed to use size_t for loop index, removes type comparison warning */
/* Should this just use `isdigit` instead? */
static int is_number(const char* s) {
size_t i;
for (i = 0; i < strlen(s); i++) { if (!strchr("0123456789", s[i])) { return 0; } }
@@ -2881,7 +2875,7 @@ 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 *q = st->parsers[i]; /* `p` was shadowing the `p` above, now changed to q */
mpc_parser_t *q = st->parsers[i];
if (q == NULL) { return mpc_failf("Unknown Parser '%s'!", x); }
if (q->name && strcmp(q->name, x) == 0) { return q; }
}
@@ -3004,7 +2998,6 @@ static mpc_val_t *mpca_stmt_afold(int n, mpc_val_t **xs) {
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]);

12
mpc.h
View File

@@ -319,15 +319,15 @@ mpc_err_t *mpca_lang_contents(int flags, const char *filename, ...);
void mpc_print(mpc_parser_t *p);
int mpc_test_pass(mpc_parser_t *p, const char *s, void *d,
int(*tester)(void*, void*),
int mpc_test_pass(mpc_parser_t *p, const char *s, const void *d,
int(*tester)(const void*, const void*),
mpc_dtor_t destructor,
void(*printer)(void*));
void(*printer)(const void*));
int mpc_test_fail(mpc_parser_t *p, const char *s, void *d,
int(*tester)(void*, void*),
int mpc_test_fail(mpc_parser_t *p, const char *s, const void *d,
int(*tester)(const void*, const void*),
mpc_dtor_t destructor,
void(*printer)(void*));
void(*printer)(const void*));

View File

@@ -4,10 +4,10 @@
#include <stdlib.h>
#include <string.h>
static int int_eq(void* x, void* y) { return (*(int*)x == *(int*)y); }
static void int_print(void* x) { printf("'%i'", *((int*)x)); }
static int string_eq(void* x, void* y) { return (strcmp(x, y) == 0); }
static void string_print(void* x) { printf("'%s'", (char*)x); }
static int int_eq(const void* x, const void* y) { return (*(int*)x == *(int*)y); }
static void int_print(const void* x) { printf("'%i'", *((int*)x)); }
static int string_eq(const void* x, const void* y) { return (strcmp(x, y) == 0); }
static void string_print(const void* x) { printf("'%s'", (char*)x); }
void test_ident(void) {

View File

@@ -43,11 +43,11 @@ void test_grammar(void) {
mpc_ast_new("char", "+"),
mpc_ast_new("product|value|regex", "5"));
PT_ASSERT(mpc_test_pass(Maths, " 24 ", t0, (int(*)(void*,void*))mpc_ast_eq, (mpc_dtor_t)mpc_ast_delete, (void(*)(void*))mpc_ast_print));
PT_ASSERT(mpc_test_pass(Maths, "(5)", t1, (int(*)(void*,void*))mpc_ast_eq, (mpc_dtor_t)mpc_ast_delete, (void(*)(void*))mpc_ast_print));
PT_ASSERT(mpc_test_pass(Maths, "(4 * 2 * 11 + 2) + 5", t2, (int(*)(void*,void*))mpc_ast_eq, (mpc_dtor_t)mpc_ast_delete, (void(*)(void*))mpc_ast_print));
PT_ASSERT(mpc_test_fail(Maths, "a", t0, (int(*)(void*,void*))mpc_ast_eq, (mpc_dtor_t)mpc_ast_delete, (void(*)(void*))mpc_ast_print));
PT_ASSERT(mpc_test_fail(Maths, "2b+4", t0, (int(*)(void*,void*))mpc_ast_eq, (mpc_dtor_t)mpc_ast_delete, (void(*)(void*))mpc_ast_print));
PT_ASSERT(mpc_test_pass(Maths, " 24 ", t0, (int(*)(const void*,const void*))mpc_ast_eq, (mpc_dtor_t)mpc_ast_delete, (void(*)(const void*))mpc_ast_print));
PT_ASSERT(mpc_test_pass(Maths, "(5)", t1, (int(*)(const void*,const void*))mpc_ast_eq, (mpc_dtor_t)mpc_ast_delete, (void(*)(const void*))mpc_ast_print));
PT_ASSERT(mpc_test_pass(Maths, "(4 * 2 * 11 + 2) + 5", t2, (int(*)(const void*,const void*))mpc_ast_eq, (mpc_dtor_t)mpc_ast_delete, (void(*)(const void*))mpc_ast_print));
PT_ASSERT(mpc_test_fail(Maths, "a", t0, (int(*)(const void*,const void*))mpc_ast_eq, (mpc_dtor_t)mpc_ast_delete, (void(*)(const void*))mpc_ast_print));
PT_ASSERT(mpc_test_fail(Maths, "2b+4", t0, (int(*)(const void*,const void*))mpc_ast_eq, (mpc_dtor_t)mpc_ast_delete, (void(*)(const void*))mpc_ast_print));
mpc_ast_delete(t0);
mpc_ast_delete(t1);

View File

@@ -94,6 +94,7 @@ static int assert_err_num = 0;
void pt_assert_run(int result, const char* expr, const char* func, const char* file, int line) {
(void) func;
num_asserts++;
test_passing = test_passing && result;
@@ -116,6 +117,7 @@ static void ptest_signal(int sig) {
case SIGFPE: sprintf(assert_err_buff, " %i. Division by Zero\n", assert_err_num+1); break;
case SIGILL: sprintf(assert_err_buff, " %i. Illegal Instruction\n", assert_err_num+1); break;
case SIGSEGV: sprintf(assert_err_buff, " %i. Segmentation Fault\n", assert_err_num+1); break;
default: break;
}
assert_err_num++;
@@ -134,7 +136,7 @@ static void ptest_signal(int sig) {
static void pt_title_case(char* output, const char* input) {
int space = 1;
unsigned int i;
size_t i;
strcpy(output, input);
@@ -213,7 +215,7 @@ static char current_suite[MAX_NAME];
int pt_run(void) {
unsigned int i;
int i;
double total;
printf(" \n");

View File

@@ -4,14 +4,14 @@
#include <string.h>
#include <stdlib.h>
static int string_eq(void* x, void* y) { return (strcmp(x, y) == 0); }
static void string_print(void* x) { printf("'%s'", (char*)x); }
static int string_eq(const void* x, const void* y) { return (strcmp(x, y) == 0); }
static void string_print(const void* x) { printf("'%s'", (char*)x); }
int regex_test_pass(mpc_parser_t *p, char* value, char* match) {
int regex_test_pass(mpc_parser_t *p, const char* value, const char* match) {
return mpc_test_pass(p, value, match, string_eq, free, string_print);
}
int regex_test_fail(mpc_parser_t *p, char* value, char* match) {
int regex_test_fail(mpc_parser_t *p, const char* value, const char* match) {
return mpc_test_fail(p, value, match, string_eq, free, string_print);
}

View File

@@ -5,6 +5,7 @@ void suite_regex(void);
void suite_grammar(void);
int main(int argc, char** argv) {
(void) argc; (void) argv;
pt_add_suite(suite_core);
pt_add_suite(suite_regex);
pt_add_suite(suite_grammar);