From 797ceb9e0463c1a03bcbf3270ba3bd94fe118e0b Mon Sep 17 00:00:00 2001 From: "Wolfgang (Blub) Bumiller" Date: Sun, 25 Nov 2012 22:11:21 +0100 Subject: [PATCH] handling TOKEN_CHARCONST - -Wmultibyte-character --- lexer.c | 8 ++++++++ main.c | 2 ++ opts.def | 1 + parser.c | 2 +- 4 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lexer.c b/lexer.c index 065f60c..6bd47b0 100644 --- a/lexer.c +++ b/lexer.c @@ -1290,6 +1290,14 @@ int lex_do(lex_file *lex) { lex->tok.ttype = TOKEN_VECTORCONST; } + else + { + if (!lex->flags.preprocessing && strlen(lex->tok.value) > 1) { + if (lexwarn(lex, WARN_MULTIBYTE_CHARACTER, "multibyte character: `%s`", lex->tok.value)) + return (lex->tok.ttype = TOKEN_ERROR); + } + lex->tok.constval.i = lex->tok.value[0]; + } return lex->tok.ttype; } diff --git a/main.c b/main.c index d35e33f..6ee7d8e 100644 --- a/main.c +++ b/main.c @@ -473,6 +473,8 @@ int main(int argc, char **argv) { options_set(opts_warn, WARN_PREPROCESSOR, true); options_set(opts_warn, WARN_MULTIFILE_IF, true); options_set(opts_warn, WARN_DOUBLE_DECLARATION, true); + options_set(opts_warn, WARN_CONST_VAR, true); + options_set(opts_warn, WARN_MULTIBYTE_CHARACTER, true); options_set(opts_flags, ADJUST_VECTOR_FIELDS, true); options_set(opts_flags, FTEPP, false); diff --git a/opts.def b/opts.def index c083c2b..7f4c15e 100644 --- a/opts.def +++ b/opts.def @@ -62,6 +62,7 @@ GMQCC_DEFINE_FLAG(MULTIFILE_IF) GMQCC_DEFINE_FLAG(DOUBLE_DECLARATION) GMQCC_DEFINE_FLAG(CONST_VAR) + GMQCC_DEFINE_FLAG(MULTIBYTE_CHARACTER) #endif /* some cleanup so we don't have to */ diff --git a/parser.c b/parser.c index e7e205d..c840ae6 100644 --- a/parser.c +++ b/parser.c @@ -1428,7 +1428,7 @@ static ast_expression* parse_expression_leave(parser_t *parser, bool stopatcomma vec_push(sy.out, syexp(parser_ctx(parser), (ast_expression*)val)); DEBUGSHUNTDO(con_out("push %g\n", parser_token(parser)->constval.f)); } - else if (parser->tok == TOKEN_INTCONST) { + else if (parser->tok == TOKEN_INTCONST || parser->tok == TOKEN_CHARCONST) { ast_value *val; if (wantop) { parseerror(parser, "expected operator or end of statement, got constant"); -- 2.39.2