From: Dale Weiler Date: Fri, 21 Dec 2012 03:08:21 +0000 (+0000) Subject: Implemented #warning and #error preprocessor directives, they're functionally equival... X-Git-Tag: 0.2~32 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=36a90bb86667d3675b2babdbd9e262282953f09f;p=xonotic%2Fgmqcc.git Implemented #warning and #error preprocessor directives, they're functionally equivalent to CPPs (supporting both string constant and non-string constant versions). Warnings however are printed with a [-Wunused-variable] which isn't correct (TODO: allow systematic changes of -W paramaters in relation to warning fields for preprocessor directives. --- diff --git a/ftepp.c b/ftepp.c index fbe6f96..c7e4273 100644 --- a/ftepp.c +++ b/ftepp.c @@ -1010,6 +1010,54 @@ static char *ftepp_include_find(ftepp_t *ftepp, const char *file) return filename; } +static void ftepp_directive_warning(ftepp_t *ftepp) { + char *message = NULL; + + if (!ftepp_skipspace(ftepp)) + return; + + /* handle the odd non string constant case so it works like C */ + if (ftepp->token != TOKEN_STRINGCONST) { + vec_upload(message, "#warning", 8); + ftepp_next(ftepp); + while (ftepp->token != TOKEN_EOL) { + vec_upload(message, ftepp_tokval(ftepp), strlen(ftepp_tokval(ftepp))); + ftepp_next(ftepp); + } + vec_push(message, '\0'); + (void)!!ftepp_warn(ftepp, LVL_WARNING, message); + vec_free(message); + return; + } + + unescape (ftepp_tokval(ftepp), ftepp_tokval(ftepp)); + (void)!!ftepp_warn(ftepp, LVL_WARNING, "#warning %s", ftepp_tokval(ftepp)); +} + +static void ftepp_directive_error(ftepp_t *ftepp) { + char *message = NULL; + + if (!ftepp_skipspace(ftepp)) + return; + + /* handle the odd non string constant case so it works like C */ + if (ftepp->token != TOKEN_STRINGCONST) { + vec_upload(message, "#error", 6); + ftepp_next(ftepp); + while (ftepp->token != TOKEN_EOL) { + vec_upload(message, ftepp_tokval(ftepp), strlen(ftepp_tokval(ftepp))); + ftepp_next(ftepp); + } + vec_push(message, '\0'); + ftepp_error(ftepp, message); + vec_free(message); + return; + } + + unescape (ftepp_tokval(ftepp), ftepp_tokval(ftepp)); + ftepp_error(ftepp, "#error %s", ftepp_tokval(ftepp)); +} + /** * Include a file. * FIXME: do we need/want a -I option? @@ -1205,6 +1253,14 @@ static bool ftepp_hash(ftepp_t *ftepp) ftepp_out(ftepp, "#", false); break; } + else if (!strcmp(ftepp_tokval(ftepp), "warning")) { + ftepp_directive_warning(ftepp); + break; + } + else if (!strcmp(ftepp_tokval(ftepp), "error")) { + ftepp_directive_error(ftepp); + break; + } else { if (ftepp->output_on) { ftepp_error(ftepp, "unrecognized preprocessor directive: `%s`", ftepp_tokval(ftepp));