proper c flags
This commit is contained in:
parent
b9266cdf96
commit
9b24c8a496
3 changed files with 32 additions and 31 deletions
|
@ -3,6 +3,13 @@ project(log-e-sappho C)
|
||||||
|
|
||||||
set(CMAKE_C_STANDARD 99)
|
set(CMAKE_C_STANDARD 99)
|
||||||
set(CMAKE_C_STANDARD_REQUIRED True)
|
set(CMAKE_C_STANDARD_REQUIRED True)
|
||||||
|
string(JOIN " " CMAKE_C_FLAGS
|
||||||
|
"-Wall -Wextra -Wformat=2"
|
||||||
|
"-Wconversion -Wsign-conversion -Wimplicit-fallthrough"
|
||||||
|
"-Werror=implicit -Werror=incompatible-pointer-types"
|
||||||
|
"-Werror=int-conversion")
|
||||||
|
set(CMAKE_VERBOSE_MAKEFILE ON)
|
||||||
|
|
||||||
|
|
||||||
include(CheckSymbolExists)
|
include(CheckSymbolExists)
|
||||||
|
|
||||||
|
|
|
@ -102,7 +102,8 @@ enum msph_tok_type {
|
||||||
|
|
||||||
TOK_AMP, // &
|
TOK_AMP, // &
|
||||||
TOK_PIPE, // |
|
TOK_PIPE, // |
|
||||||
TOK_RARROW, // =>
|
TOK_IMPL, // =>
|
||||||
|
TOK_RARROW, // ->
|
||||||
TOK_SUB, // <:
|
TOK_SUB, // <:
|
||||||
|
|
||||||
TOK_KW_TYPE, // type
|
TOK_KW_TYPE, // type
|
||||||
|
@ -136,7 +137,7 @@ struct msph_token {
|
||||||
};
|
};
|
||||||
|
|
||||||
#define MSPH_FILE_NAME_LEN 1024
|
#define MSPH_FILE_NAME_LEN 1024
|
||||||
#define MSPH_FILE_BUF_LEN 4096
|
#define MSPH_FILE_BUF_LEN 2048
|
||||||
#define MSPH_TOKEN_SRC_FILE 1
|
#define MSPH_TOKEN_SRC_FILE 1
|
||||||
|
|
||||||
struct msph_token_src_file {
|
struct msph_token_src_file {
|
||||||
|
@ -187,7 +188,7 @@ ssize_t msph_token_stream_read_tok(struct msph_token *, size_t,
|
||||||
struct msph_token_stream *);
|
struct msph_token_stream *);
|
||||||
int msph_token_stream_print(struct msph_token_stream *, FILE *);
|
int msph_token_stream_print(struct msph_token_stream *, FILE *);
|
||||||
|
|
||||||
size_t msph_token_str(char *buf, size_t len, struct msph_token *tok);
|
ssize_t msph_token_str(char *buf, size_t len, struct msph_token *tok);
|
||||||
|
|
||||||
|
|
||||||
#endif /* _MSPH_EXPR_H */
|
#endif /* _MSPH_EXPR_H */
|
||||||
|
|
|
@ -29,6 +29,7 @@ struct msph_matcher token_matcher[] = {
|
||||||
|
|
||||||
{ 0, 0, TOK_AMP },
|
{ 0, 0, TOK_AMP },
|
||||||
{ 0, 0, TOK_PIPE },
|
{ 0, 0, TOK_PIPE },
|
||||||
|
{ 0, 0, TOK_IMPL },
|
||||||
{ 0, 0, TOK_RARROW },
|
{ 0, 0, TOK_RARROW },
|
||||||
{ 0, 0, TOK_SUB },
|
{ 0, 0, TOK_SUB },
|
||||||
|
|
||||||
|
@ -64,7 +65,8 @@ struct msph_token_info {
|
||||||
|
|
||||||
TOK_INFO(TOK_AMP, "&"),
|
TOK_INFO(TOK_AMP, "&"),
|
||||||
TOK_INFO(TOK_PIPE, "|"),
|
TOK_INFO(TOK_PIPE, "|"),
|
||||||
TOK_INFO(TOK_RARROW, "=>"),
|
TOK_INFO(TOK_IMPL, "=>"),
|
||||||
|
TOK_INFO(TOK_RARROW, "->"),
|
||||||
TOK_INFO(TOK_SUB, "<:"),
|
TOK_INFO(TOK_SUB, "<:"),
|
||||||
|
|
||||||
TOK_INFO(TOK_KW_TYPE, "type"),
|
TOK_INFO(TOK_KW_TYPE, "type"),
|
||||||
|
@ -170,22 +172,22 @@ msph_token_stream_frombuf(struct msph_ctx *ctx, const char *buf, size_t len)
|
||||||
return (ret);
|
return (ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t
|
ssize_t
|
||||||
msph_token_str(char *buf, size_t len, struct msph_token *tok)
|
msph_token_str(char *buf, size_t len, struct msph_token *tok)
|
||||||
{
|
{
|
||||||
size_t ret;
|
ssize_t ret;
|
||||||
|
|
||||||
ret = snprintf(buf, len, "%s", tok_base_str(tok));
|
ret = (ssize_t)snprintf(buf, len, "%s", tok_base_str(tok));
|
||||||
|
|
||||||
if (ret > len)
|
if (ret < 0 || ret >= (ssize_t)len)
|
||||||
return (ret);
|
return (ret);
|
||||||
|
|
||||||
len -= ret;
|
len -= (size_t)ret;
|
||||||
buf += ret;
|
buf += ret;
|
||||||
|
|
||||||
switch (tok->type) {
|
switch (tok->type) {
|
||||||
case TOK_IDENT:
|
case TOK_IDENT:
|
||||||
ret += snprintf(buf, len, "(%s)", tok->d.s.buf);
|
ret += (ssize_t)snprintf(buf, len, "(%s)", tok->d.s.buf);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
@ -199,20 +201,19 @@ int
|
||||||
msph_token_stream_print(struct msph_token_stream *s, FILE *out)
|
msph_token_stream_print(struct msph_token_stream *s, FILE *out)
|
||||||
{
|
{
|
||||||
ssize_t ret;
|
ssize_t ret;
|
||||||
ssize_t i;
|
|
||||||
struct msph_token tok;
|
struct msph_token tok;
|
||||||
char tokstr[MSPH_TOKEN_PRINT_BUF_LEN];
|
char tokstr[MSPH_TOKEN_PRINT_BUF_LEN];
|
||||||
|
|
||||||
while ((ret = msph_token_stream_read_tok( &tok, 1, s)) > 0) {
|
while ((ret = msph_token_stream_read_tok( &tok, 1, s)) > 0) {
|
||||||
SPHO_DEBUG_PRINT("msph_token_stream_print: ret=%zd\n", ret);
|
ret = msph_token_str(tokstr, BUF_LEN(tokstr), &tok);
|
||||||
if (msph_token_str(
|
if (ret < 0)
|
||||||
tokstr, BUF_LEN(tokstr), &tok) > BUF_LEN(tokstr)) {
|
continue;
|
||||||
tokstr[BUF_LEN(tokstr) - 1] = '\0';
|
|
||||||
}
|
|
||||||
fprintf(out, "%s\n", tokstr);
|
|
||||||
}
|
|
||||||
|
|
||||||
SPHO_DEBUG_PRINT("msph_token_stream_print: ret=%zd\n", ret);
|
if ((size_t)ret < BUF_LEN(tokstr))
|
||||||
|
fprintf(out, "%s\n", tokstr);
|
||||||
|
else
|
||||||
|
fprintf(out, "%s...(trunkated)", tokstr);
|
||||||
|
}
|
||||||
|
|
||||||
return ((int)ret);
|
return ((int)ret);
|
||||||
}
|
}
|
||||||
|
@ -281,7 +282,6 @@ read_single_tok(struct msph_token *ptr, struct msph_token_stream *s)
|
||||||
max_m = 0;
|
max_m = 0;
|
||||||
for (m = 1; token_matcher[m].type != TOK_END; m++) {
|
for (m = 1; token_matcher[m].type != TOK_END; m++) {
|
||||||
res = tok_match(ctx, src, &token_matcher[m]);
|
res = tok_match(ctx, src, &token_matcher[m]);
|
||||||
SPHO_DEBUG_PRINT("read_single_tok: tok_match=%d\n", res);
|
|
||||||
|
|
||||||
if (res == -1)
|
if (res == -1)
|
||||||
return (-1);
|
return (-1);
|
||||||
|
@ -295,10 +295,8 @@ read_single_tok(struct msph_token *ptr, struct msph_token_stream *s)
|
||||||
if (max_m == 0)
|
if (max_m == 0)
|
||||||
return (0);
|
return (0);
|
||||||
|
|
||||||
SPHO_DEBUG_PRINT("read_single_tok: commit=%zu\n", max_m);
|
|
||||||
if (tok_commit(ctx, src, &token_matcher[max_m], ptr) == -1)
|
if (tok_commit(ctx, src, &token_matcher[max_m], ptr) == -1)
|
||||||
return (-1);
|
return (-1);
|
||||||
SPHO_DEBUG_PRINT("read_single_tok: committed\n");
|
|
||||||
|
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
@ -393,6 +391,7 @@ char_at(struct msph_ctx *ctx, struct msph_token_src *src, size_t i, char *out)
|
||||||
int ret;
|
int ret;
|
||||||
struct msph_token_src_str *str;
|
struct msph_token_src_str *str;
|
||||||
|
|
||||||
|
ret = -1;
|
||||||
switch (src->type) {
|
switch (src->type) {
|
||||||
case MSPH_TOKEN_SRC_FILE:
|
case MSPH_TOKEN_SRC_FILE:
|
||||||
ret = file_char_at(ctx, src, i, out);
|
ret = file_char_at(ctx, src, i, out);
|
||||||
|
@ -443,7 +442,6 @@ tok_match(struct msph_ctx *ctx, struct msph_token_src *src,
|
||||||
struct msph_matcher *m)
|
struct msph_matcher *m)
|
||||||
{
|
{
|
||||||
int res;
|
int res;
|
||||||
int more;
|
|
||||||
char chr;
|
char chr;
|
||||||
const char *match_str;
|
const char *match_str;
|
||||||
size_t off, len;
|
size_t off, len;
|
||||||
|
@ -506,8 +504,10 @@ tok_match(struct msph_ctx *ctx, struct msph_token_src *src,
|
||||||
MATCH_CHAR('&');
|
MATCH_CHAR('&');
|
||||||
case TOK_PIPE:
|
case TOK_PIPE:
|
||||||
MATCH_CHAR('|');
|
MATCH_CHAR('|');
|
||||||
case TOK_RARROW:
|
case TOK_IMPL:
|
||||||
MATCH_STR("=>");
|
MATCH_STR("=>");
|
||||||
|
case TOK_RARROW:
|
||||||
|
MATCH_STR("->");
|
||||||
case TOK_SUB:
|
case TOK_SUB:
|
||||||
MATCH_STR("<:");
|
MATCH_STR("<:");
|
||||||
case TOK_KW_TYPE:
|
case TOK_KW_TYPE:
|
||||||
|
@ -567,20 +567,16 @@ tok_commit(struct msph_ctx *ctx, struct msph_token_src *src,
|
||||||
SPHO_PRECOND(ctx != NULL && m != NULL);
|
SPHO_PRECOND(ctx != NULL && m != NULL);
|
||||||
SPHO_PRECOND(m->matchlen != 0);
|
SPHO_PRECOND(m->matchlen != 0);
|
||||||
|
|
||||||
SPHO_DEBUG_PRINT("committing\n");
|
|
||||||
|
|
||||||
switch (src->type) {
|
switch (src->type) {
|
||||||
case MSPH_TOKEN_SRC_FILE:
|
case MSPH_TOKEN_SRC_FILE:
|
||||||
file = &src->inner.file;
|
file = &src->inner.file;
|
||||||
pos_old = file->pos;
|
pos_old = file->pos;
|
||||||
|
|
||||||
SPHO_DEBUG_PRINT("committing\n");
|
|
||||||
file->pos += m->matchlen;
|
file->pos += m->matchlen;
|
||||||
file->pos %= BUF_LEN(file->buf);
|
file->pos %= BUF_LEN(file->buf);
|
||||||
SPHO_ASSERT(file->pos < BUF_LEN(file->buf) ||
|
SPHO_ASSERT(file->pos < BUF_LEN(file->buf) ||
|
||||||
file->pos < pos_old);
|
file->pos < pos_old);
|
||||||
|
|
||||||
SPHO_DEBUG_PRINT("committing\n");
|
|
||||||
if (ptr == NULL)
|
if (ptr == NULL)
|
||||||
return (0);
|
return (0);
|
||||||
|
|
||||||
|
@ -588,20 +584,17 @@ tok_commit(struct msph_ctx *ctx, struct msph_token_src *src,
|
||||||
if (! TOK_HAS_DATA(ptr->type))
|
if (! TOK_HAS_DATA(ptr->type))
|
||||||
return (0);
|
return (0);
|
||||||
|
|
||||||
SPHO_DEBUG_PRINT("committing\n");
|
|
||||||
if (m->matchlen >= sizeof(ptr->d.s.buf)) {
|
if (m->matchlen >= sizeof(ptr->d.s.buf)) {
|
||||||
MSPH_ERR(ctx, MSPH_ERR_TOOLONG);
|
MSPH_ERR(ctx, MSPH_ERR_TOOLONG);
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
SPHO_DEBUG_PRINT("committing\n");
|
|
||||||
if (fromcbuf_charcpy(ptr->d.s.buf, file->buf, sizeof(file->buf),
|
if (fromcbuf_charcpy(ptr->d.s.buf, file->buf, sizeof(file->buf),
|
||||||
pos_old, m->matchlen) == -1) {
|
pos_old, m->matchlen) == -1) {
|
||||||
MSPH_ERR(ctx, MSPH_ERR_TOOLONG);
|
MSPH_ERR(ctx, MSPH_ERR_TOOLONG);
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
SPHO_DEBUG_PRINT("committing\n");
|
|
||||||
ptr->d.s.buf[m->matchlen] = '\0';
|
ptr->d.s.buf[m->matchlen] = '\0';
|
||||||
return (0);
|
return (0);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue