From 85e8cc6c5f6cc408ff7382f8c5d09327d65435e0 Mon Sep 17 00:00:00 2001 From: Cary R Date: Sun, 10 Jan 2021 17:45:07 -0800 Subject: [PATCH] Update some preprocessor error messages --- ivlpp/lexor.lex | 55 +++++++++++++++++++++++++------------------------ lexor.lex | 3 ++- 2 files changed, 30 insertions(+), 28 deletions(-) diff --git a/ivlpp/lexor.lex b/ivlpp/lexor.lex index f8ac2d11c..d6b77082e 100644 --- a/ivlpp/lexor.lex +++ b/ivlpp/lexor.lex @@ -1,7 +1,7 @@ %option prefix="yy" %{ /* - * Copyright (c) 1999-2020 Stephen Williams (steve@icarus.com) + * Copyright (c) 1999-2021 Stephen Williams (steve@icarus.com) * * This source code is free software; you can redistribute it * and/or modify it in source code form under the terms of the GNU @@ -249,9 +249,9 @@ keywords (include|define|undef|ifdef|ifndef|else|elseif|endif) `{keywords} { emit_pathline(istack); + fprintf(stderr, "error: macro expansion cannot be directive keywords " + "('%s').\n", yytext); error_count += 1; - fprintf(stderr, "error: macro names cannot be directive keywords " - "('%s'); replaced with nothing.\n", yytext); } `[a-zA-Z][a-zA-Z0-9_$]* { @@ -279,9 +279,10 @@ keywords (include|define|undef|ifdef|ifndef|else|elseif|endif) `{keywords} { emit_pathline(istack); + fprintf(stderr, "error: macro expansion cannot be directive keywords " + "('%s').\n", yytext); error_count += 1; - fprintf(stderr, "error: macro names cannot be directive keywords " - "('%s'); replaced with nothing.\n", yytext); + BEGIN(ERROR_LINE); } `[a-zA-Z][a-zA-Z0-9_]* { @@ -331,10 +332,10 @@ keywords (include|define|undef|ifdef|ifndef|else|elseif|endif) {keywords}{W}? { emit_pathline(istack); + fprintf(stderr, "error: malformed `define directive: macro names " + "cannot be directive keywords ('%s')\n", yytext); error_count += 1; BEGIN(ERROR_LINE); - fprintf(stderr, "error: malformed `define directive: macro names " - "cannot be directive keywords\n"); } [a-zA-Z_][a-zA-Z0-9_$]*"("{W}? { BEGIN(DEF_ARG); def_start(); } @@ -361,7 +362,7 @@ keywords (include|define|undef|ifdef|ifndef|else|elseif|endif) . { emit_pathline(istack); - fprintf(stderr, "error: malformed `define directive.\n"); + fprintf(stderr, "error: malformed `define directive ('%s').\n", yytext); error_count += 1; BEGIN(ERROR_LINE); } @@ -474,9 +475,9 @@ keywords (include|define|undef|ifdef|ifndef|else|elseif|endif) (\n|\r) | . | `ifdef { + emit_pathline(istack); + fprintf(stderr, "error: `ifdef without a macro name.\n"); error_count += 1; - fprintf(stderr, "%s:%u: `ifdef without a macro name - ignored.\n", - istack->path, istack->lineno+1); if (YY_START == IFDEF_NAME) { ifdef_leave(); yy_pop_state(); @@ -487,9 +488,9 @@ keywords (include|define|undef|ifdef|ifndef|else|elseif|endif) (\n|\r) | . | `ifndef { + emit_pathline(istack); + fprintf(stderr, "error: `ifndef without a macro name.\n"); error_count += 1; - fprintf(stderr, "%s:%u: `ifndef without a macro name - ignored.\n", - istack->path, istack->lineno+1); if (YY_START == IFNDEF_NAME) { ifdef_leave(); yy_pop_state(); @@ -500,9 +501,9 @@ keywords (include|define|undef|ifdef|ifndef|else|elseif|endif) (\n|\r) | . | `elsif { + emit_pathline(istack); + fprintf(stderr, "error: `elsif without a macro name.\n"); error_count += 1; - fprintf(stderr, "%s:%u: `elsif without a macro name - ignored.\n", - istack->path, istack->lineno+1); if (YY_START != INITIAL) { BEGIN(prev_state); unput(yytext[0]); @@ -510,28 +511,28 @@ keywords (include|define|undef|ifdef|ifndef|else|elseif|endif) } `elsif{W}[a-zA-Z_][a-zA-Z0-9_$]* { + emit_pathline(istack); + fprintf(stderr, "error: `elsif without a matching `ifdef.\n"); error_count += 1; - fprintf(stderr, "%s:%u: `elsif without a matching `ifdef - ignored.\n", - istack->path, istack->lineno+1); } `else { + emit_pathline(istack); + fprintf(stderr, "error: `else without a matching `ifdef.\n"); error_count += 1; - fprintf(stderr, "%s:%u: `else without a matching `ifdef - ignored.\n", - istack->path, istack->lineno+1); } `endif { + emit_pathline(istack); + fprintf(stderr, "error: `endif without a matching `ifdef.\n"); error_count += 1; - fprintf(stderr, "%s:%u: `endif without a matching `ifdef - ignored.\n", - istack->path, istack->lineno+1); } `{keywords} { emit_pathline(istack); + fprintf(stderr, "error: macro expansion cannot be directive keywords " + "('%s').\n", yytext); error_count += 1; - fprintf(stderr, "error: macro names cannot be directive keywords " - "('%s'); replaced with nothing.\n", yytext); } /* This pattern notices macros and arranges for them to be replaced. */ @@ -601,7 +602,6 @@ keywords (include|define|undef|ifdef|ifndef|else|elseif|endif) . { emit_pathline(istack); - fprintf(stderr, "error: missing argument list for `%s.\n", macro_name()); error_count += 1; @@ -1156,11 +1156,12 @@ static void do_define(void) */ if ((def_argc > 1) && strchr(head, ARG_MARK)) { emit_pathline(istack); - error_count += 1; def_argc = 0; fprintf(stderr, "error: implementation restriction - " - "macro text may not contain a %s character\n", _STR2(ARG_MARK)); + "macro text may not contain a %s character\n", + _STR2(ARG_MARK)); + error_count += 1; } /* Look for formal argument names in the definition, and replace @@ -1831,11 +1832,11 @@ static void lexor_done(void) ifdef_stack = cur->next; fprintf(stderr, "%s:%u: error: This `ifdef lacks an `endif.\n", - cur->path, cur->lineno+1); + cur->path, cur->lineno+1); + error_count += 1; free(cur->path); free(cur); - error_count += 1; } } diff --git a/lexor.lex b/lexor.lex index b0fc37110..c88725545 100644 --- a/lexor.lex +++ b/lexor.lex @@ -4,7 +4,7 @@ %{ /* - * Copyright (c) 1998-2020 Stephen Williams (steve@icarus.com) + * Copyright (c) 1998-2021 Stephen Williams (steve@icarus.com) * * This source code is free software; you can redistribute it * and/or modify it in source code form under the terms of the GNU @@ -167,6 +167,7 @@ TU [munpf] that flag to attach implicit attributes to "initial" and "always" statements. */ +"// Icarus preprocessor had ("[0-9]+") errors."\n { pre_process_failed(yytext); } "//"{W}*"synthesis"{W}+"translate_on"{W}*\n { pform_mc_translate_on(true); } "//"{W}*"synthesis"{W}+"translate_off"{W}*\n { pform_mc_translate_on(false); } "//" { comment_enter = YY_START; BEGIN(LCOMMENT); }