From 0b01a969e4705f4e97000a45b4f6b0e2e7486ee9 Mon Sep 17 00:00:00 2001 From: anders_k Date: Wed, 31 Jan 2018 15:31:49 +0000 Subject: [PATCH] Refactor and document !pragma warning error and warning states git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@6980 212acab6-be3b-0410-9dea-997c60f758d6 --- Docs/src/compiler.but | 2 +- Docs/src/history.but | 2 ++ Source/build.cpp | 32 +++++++++----------------------- Source/tokens.cpp | 2 +- 4 files changed, 13 insertions(+), 25 deletions(-) diff --git a/Docs/src/compiler.but b/Docs/src/compiler.but index 9f7376d7..3fb884c7 100644 --- a/Docs/src/compiler.but +++ b/Docs/src/compiler.but @@ -184,7 +184,7 @@ This command will issue a warning to the script compiler. You can also add a mes \S1{pragma} !pragma -\c warning code +\c warning \c warning The pragma commands allows you to change compiler features and behavior. diff --git a/Docs/src/history.but b/Docs/src/history.but index 0fd50393..6e03bb4d 100644 --- a/Docs/src/history.but +++ b/Docs/src/history.but @@ -38,6 +38,8 @@ Released on January 29th, 2018 \b MakeNSIS exits with code 0 for various information commands (\W{http://sf.net/p/nsis/bugs/1193}{bug #1193}) +\b Added error and warning states to !pragma warning + \b Removed unused NSD_LB_Clear macro parameter \S2{} Translations diff --git a/Source/build.cpp b/Source/build.cpp index b0d58014..77b150a6 100644 --- a/Source/build.cpp +++ b/Source/build.cpp @@ -3447,34 +3447,20 @@ int CEXEBuild::parse_pragma(LineParser &line) if (!diagstate.pop()) ret = rvWarn, warning_fl(DW_PP_PRAGMA_INVALID, _T("Unexpected")); } - else // warning: error/warning/disable/enable/default + else // warning: error/warning/disable/enable/default <%code%|all> [..] { for (int ti = 3; ti < line.getnumtokens(); ++ti) { DIAGCODE code = static_cast(line.gettoken_int(ti)); - bool all = 0 == line.gettoken_enum(ti, _T("all\0")); - if (diagstate.is_valid_code(code)) + bool all = line.gettoken_enum(ti, _T("all\0")) == 0, isCode = diagstate.is_valid_code(code); + switch((isCode||all) ? warnOp : invalidwop) { - switch(warnOp) - { - case woperr: diagstate.error(code); break; - case wopwar: diagstate.warning(code); break; - case wopdis: diagstate.disable(code); break; - case wopena: diagstate.enable(code); break; - case wopdef: diagstate.def(code); break; - default: assert(0); - } - } - else - { - switch(all ? warnOp : invalidwop) - { - case woperr: diagstate.set_all(diagstate.werror); break; - case wopdis: diagstate.set_all(DiagState::wdisabled); break; - case wopena: diagstate.set_all(DiagState::wenabled); break; - case wopdef: diagstate.set_all(DiagState::get_default_state()); break; - default: ret = rvWarn, warning_fl(DW_PP_PRAGMA_INVALID, _T("Invalid number: \"%") NPRIs _T("\""), line.gettoken_str(ti)); - } + case woperr: all ? diagstate.set_all(DiagState::werror) : diagstate.error(code); break; + case wopwar: all ? diagstate.set_all(DiagState::wwarning) : diagstate.warning(code); break; + case wopdis: all ? diagstate.set_all(DiagState::wdisabled) : diagstate.disable(code); break; + case wopena: all ? diagstate.set_all(DiagState::wenabled) : diagstate.enable(code); break; + case wopdef: all ? diagstate.set_all(DiagState::get_default_state()) : diagstate.def(code); break; + default: ret = rvWarn, warning_fl(DW_PP_PRAGMA_INVALID, _T("Invalid number: \"%") NPRIs _T("\""), line.gettoken_str(ti)); } } } diff --git a/Source/tokens.cpp b/Source/tokens.cpp index f1b4b463..a00caa6a 100644 --- a/Source/tokens.cpp +++ b/Source/tokens.cpp @@ -276,7 +276,7 @@ static tokenType tokenlist[TOK__LAST] = {TOK_P_ERROR,_T("!error"),0,1,_T("[error_message]"),TP_ALL}, {TOK_P_VERBOSE,_T("!verbose"),1,-1,_T("verbose_level | push | pop [...]"),TP_ALL}, -{TOK_P_PRAGMA,_T("!pragma"),2,-1,_T("warning number | warning "),TP_ALL}, +{TOK_P_PRAGMA,_T("!pragma"),1,-1,_T("warning | warning "),TP_ALL}, {TOK_P_MACRO,_T("!macro"),1,-1,_T("macroname [parms ...]"),TP_ALL}, {TOK_P_MACROEND,_T("!macroend"),0,0,_T(""),TP_ALL},