From c618987255838a2af9813a69eb1f4f20a8df6315 Mon Sep 17 00:00:00 2001 From: Reinhold Kainhofer Date: Wed, 28 Sep 2011 12:39:12 +0200 Subject: [PATCH] Warnings: Move all warning-as-error handling to warn.cc This finally makes that option apply to ALL warnings, and it considerably cleans up the error/warning functions. --- flower/include/warn.hh | 2 ++ flower/warn.cc | 25 +++++++++++++++---------- lily/input.cc | 10 ++-------- lily/program-option-scheme.cc | 6 +++++- lily/warn-scheme.cc | 21 +++------------------ 5 files changed, 27 insertions(+), 37 deletions(-) diff --git a/flower/include/warn.hh b/flower/include/warn.hh index f17bef2804..959a556291 100644 --- a/flower/include/warn.hh +++ b/flower/include/warn.hh @@ -41,6 +41,8 @@ #define LOGLEVEL_DEBUG (LOGLEVEL_INFO | LOG_DEBUG) extern int loglevel; +extern bool warning_as_error; + /* output messages, in decreasing order of importance */ void error (string s, string location = ""); // Fatal error, exits lilypond! diff --git a/flower/warn.cc b/flower/warn.cc index af16f20beb..8cdfcb6b99 100644 --- a/flower/warn.cc +++ b/flower/warn.cc @@ -40,6 +40,7 @@ using namespace std; /* Define the loglevel (default is INFO) */ int loglevel = LOGLEVEL_INFO; +bool warning_as_error = false; bool is_loglevel (int level) @@ -188,12 +189,15 @@ error (string s, string location) void programming_error (string s, string location) { - if (is_expected (s)) { + if (is_expected (s)) print_message (LOG_DEBUG, location, _f ("suppressed programming error: %s", s) + "\n"); - } else { - print_message (LOG_ERROR, location, _f ("programming error: %s", s) + "\n"); - print_message (LOG_ERROR, location, _ ("continuing, cross fingers") + "\n"); - } + else if (warning_as_error) + error (s, location); + else + { + print_message (LOG_ERROR, location, _f ("programming error: %s", s) + "\n"); + print_message (LOG_ERROR, location, _ ("continuing, cross fingers") + "\n"); + } } /* Display a non-fatal error message, don't exit. */ @@ -202,9 +206,10 @@ non_fatal_error (string s, string location) { if (is_expected (s)) print_message (LOG_DEBUG, location, _f ("suppressed error: %s", s) + "\n"); - else { + else if (warning_as_error) + error (s, location); + else print_message (LOG_ERROR, location, _f ("error: %s", s) + "\n"); - } } /* Display a warning message. */ @@ -213,10 +218,10 @@ warning (string s, string location) { if (is_expected (s)) print_message (LOG_DEBUG, location, _f ("suppressed warning: %s", s) + "\n"); - else { - // TODO: Add warning-as-error check here + else if (warning_as_error) + error (s, location); + else print_message (LOG_WARN, location, _f ("warning: %s", s) + "\n"); - } } /* Display a success message. */ diff --git a/lily/input.cc b/lily/input.cc index 28923f4948..9ba3767638 100644 --- a/lily/input.cc +++ b/lily/input.cc @@ -103,10 +103,7 @@ Input::error (string s) const void Input::programming_error (string s) const { - if (get_program_option ("warning-as-error")) - ::error (message_string (s), message_location ()); - else - ::programming_error (message_string (s), message_location ()); + ::programming_error (message_string (s), message_location ()); } void @@ -118,10 +115,7 @@ Input::non_fatal_error (string s) const void Input::warning (string s) const { - if (get_program_option ("warning-as-error")) - ::non_fatal_error (message_string (s), message_location ()); - else - ::warning (message_string (s), message_location ()); + ::warning (message_string (s), message_location ()); } void diff --git a/lily/program-option-scheme.cc b/lily/program-option-scheme.cc index 2c3d60dc87..2d65001a14 100644 --- a/lily/program-option-scheme.cc +++ b/lily/program-option-scheme.cc @@ -123,7 +123,11 @@ internal_set_option (SCM var, val = val_scm_bool; } else if (varstr == "warning-as-error") - val = val_scm_bool; + { + /* warning_as_error is defined in flower/warn.cc */ + warning_as_error = valbool; + val = val_scm_bool; + } else if (varstr == "music-strings-to-paths") { music_strings_to_paths = valbool; diff --git a/lily/warn-scheme.cc b/lily/warn-scheme.cc index 2f7a1af611..3b917b760e 100644 --- a/lily/warn-scheme.cc +++ b/lily/warn-scheme.cc @@ -49,12 +49,7 @@ LY_DEFINE (ly_programming_error, "ly:programming-error", { LY_ASSERT_TYPE (scm_is_string, str, 1); str = scm_simple_format (SCM_BOOL_F, str, rest); - - if (get_program_option ("warning-as-error")) - error (ly_scm2string (str)); - else - programming_error (ly_scm2string (str)); - + programming_error (ly_scm2string (str)); return SCM_UNSPECIFIED; } @@ -65,12 +60,7 @@ LY_DEFINE (ly_warning, "ly:warning", { LY_ASSERT_TYPE (scm_is_string, str, 1); str = scm_simple_format (SCM_BOOL_F, str, rest); - - if (get_program_option ("warning-as-error")) - error (ly_scm2string (str)); - else - warning (ly_scm2string (str)); - + warning (ly_scm2string (str)); return SCM_UNSPECIFIED; } @@ -129,12 +119,7 @@ LY_DEFINE (ly_warning_located, "ly:warning-located", LY_ASSERT_TYPE (scm_is_string, location, 1); LY_ASSERT_TYPE (scm_is_string, str, 2); str = scm_simple_format (SCM_BOOL_F, str, rest); - - if (get_program_option ("warning-as-error")) - error (ly_scm2string (str), ly_scm2string (location)); - else - warning (ly_scm2string (str), ly_scm2string (location)); - + warning (ly_scm2string (str), ly_scm2string (location)); return SCM_UNSPECIFIED; } -- 2.39.2