diff options
author | João Valverde <j@v6e.pt> | 2022-11-19 22:52:09 +0000 |
---|---|---|
committer | João Valverde <j@v6e.pt> | 2022-11-20 10:11:27 +0000 |
commit | 79c3a77752bfee8e57cac3796d5e5ef1987e5612 (patch) | |
tree | dd903014caf5145faf5b220afa435d1b653044cf /epan | |
parent | c4ca4312c1c17cf48a1e956d0cd2e6ab5e04d4f2 (diff) |
Add macros to control lemon diagnostics
Rename flex macros using parenthesis (mostly a style issue):
DIAG_OFF_FLEX -> DIAG_OFF_FLEX()
DIAG_ON_FLEX -> DIAG_ON_FLEX()
Use the same kind of construct with lemon generated code using
DIAG_OFF_LEMON() and DIAG_ON_LEMON(). Use %include and %code
directives to enforce the desired order with generated code
in the middle in between pragmas.
Fix a clang-specific pragma to use DIAG_OFF_CLANG().
DIAG_OFF(unreachable-code) -> DIAG_OFF_CLANG(unreachable-code).
Apparently GCC is ignoring the -Wunreachable flag, that's why
it did not trigger an unknown pragma warning. From [1}:
The -Wunreachable-code has been removed, because it was unstable: it
relied on the optimizer, and so different versions of gcc would warn
about different code. The compiler still accepts and ignores the
command line option so that existing Makefiles are not broken. In some
future release the option will be removed entirely. - Ian
[1] https://gcc.gnu.org/legacy-ml/gcc-help/2011-05/msg00360.html
Diffstat (limited to 'epan')
-rw-r--r-- | epan/dfilter/grammar.lemon | 9 | ||||
-rw-r--r-- | epan/dfilter/scanner.l | 4 | ||||
-rw-r--r-- | epan/diam_dict.l | 4 | ||||
-rw-r--r-- | epan/dtd_grammar.lemon | 8 | ||||
-rw-r--r-- | epan/dtd_parse.l | 4 | ||||
-rw-r--r-- | epan/dtd_preparse.l | 4 | ||||
-rw-r--r-- | epan/protobuf_lang_parser.lemon | 8 | ||||
-rw-r--r-- | epan/protobuf_lang_scanner.l | 4 | ||||
-rw-r--r-- | epan/radius_dict.l | 4 | ||||
-rw-r--r-- | epan/uat_load.l | 4 |
10 files changed, 29 insertions, 24 deletions
diff --git a/epan/dfilter/grammar.lemon b/epan/dfilter/grammar.lemon index 3815587c57..d6caa0d927 100644 --- a/epan/dfilter/grammar.lemon +++ b/epan/dfilter/grammar.lemon @@ -15,9 +15,6 @@ #include "grammar.h" -/* Generated lemon code warns on this. */ -DIAG_OFF(unreachable-code) - #ifdef _WIN32 #pragma warning(disable:4671) #endif @@ -27,7 +24,11 @@ new_function(dfwork_t *dfw, stnode_t *node); #define FAIL(dfw, node, ...) dfilter_fail(dfw, stnode_location(node), __VA_ARGS__) -/* End of C code */ +DIAG_OFF_LEMON() +} /* end of %include */ + +%code { +DIAG_ON_LEMON() } /* Parser Information */ diff --git a/epan/dfilter/scanner.l b/epan/dfilter/scanner.l index e1d428c032..b90f1a28b3 100644 --- a/epan/dfilter/scanner.l +++ b/epan/dfilter/scanner.l @@ -75,7 +75,7 @@ /* * Disable diagnostics in the code generated by Flex. */ -DIAG_OFF_FLEX +DIAG_OFF_FLEX() stnode_t *df_lval; @@ -475,7 +475,7 @@ hyphen-bytes {hex2}(-{hex2})+ /* * Turn diagnostics back on, so we check the code that we've written. */ -DIAG_ON_FLEX +DIAG_ON_FLEX() static void _update_location(df_scanner_state_t *state, size_t len) diff --git a/epan/diam_dict.l b/epan/diam_dict.l index afb5edb002..8506ade177 100644 --- a/epan/diam_dict.l +++ b/epan/diam_dict.l @@ -104,7 +104,7 @@ /* * Disable diagnostics in the code generated by Flex. */ -DIAG_OFF_FLEX +DIAG_OFF_FLEX() typedef struct entity_t { char* name; @@ -630,7 +630,7 @@ description_attr description=\042 /* * Turn diagnostics back on, so we check the code that we've written. */ -DIAG_ON_FLEX +DIAG_ON_FLEX() static int debugging = 0; diff --git a/epan/dtd_grammar.lemon b/epan/dtd_grammar.lemon index 58f9c7ff0c..253da126cb 100644 --- a/epan/dtd_grammar.lemon +++ b/epan/dtd_grammar.lemon @@ -22,9 +22,6 @@ #include "dtd.h" #include "dtd_parse.h" -/* Generated lemon code warns on this. */ -DIAG_OFF(unreachable-code) - static dtd_named_list_t* dtd_named_list_new(gchar* name, GPtrArray* list) { dtd_named_list_t* nl = g_new(dtd_named_list_t,1); @@ -45,6 +42,11 @@ static GPtrArray* g_ptr_array_join(GPtrArray* a, GPtrArray* b){ return a; } +DIAG_OFF_LEMON() +} /* end of %include */ + +%code { +DIAG_ON_LEMON() } %name DtdParse diff --git a/epan/dtd_parse.l b/epan/dtd_parse.l index f8da374c44..9d7677d8bf 100644 --- a/epan/dtd_parse.l +++ b/epan/dtd_parse.l @@ -92,7 +92,7 @@ /* * Disable diagnostics in the code generated by Flex. */ -DIAG_OFF_FLEX +DIAG_OFF_FLEX() struct _proto_xmlpi_attr { const gchar* name; @@ -353,7 +353,7 @@ squoted ['][^\']*['] /* * Turn diagnostics back on, so we check the code that we've written. */ -DIAG_ON_FLEX +DIAG_ON_FLEX() static dtd_token_data_t* new_token(gchar* text, gchar* location) { dtd_token_data_t* t = g_new(dtd_token_data_t,1); diff --git a/epan/dtd_preparse.l b/epan/dtd_preparse.l index 5a01c6977a..ff8ab141c1 100644 --- a/epan/dtd_preparse.l +++ b/epan/dtd_preparse.l @@ -101,7 +101,7 @@ /* * Disable diagnostics in the code generated by Flex. */ -DIAG_OFF_FLEX +DIAG_OFF_FLEX() #define ECHO g_string_append(yyextra->current,yytext); @@ -213,7 +213,7 @@ newline \n /* * Turn diagnostics back on, so we check the code that we've written. */ -DIAG_ON_FLEX +DIAG_ON_FLEX() static const gchar* replace_entity(Dtd_PreParse_scanner_state_t* state, gchar* entity) { GString* replacement; diff --git a/epan/protobuf_lang_parser.lemon b/epan/protobuf_lang_parser.lemon index 11034febff..820b99f340 100644 --- a/epan/protobuf_lang_parser.lemon +++ b/epan/protobuf_lang_parser.lemon @@ -30,9 +30,6 @@ #include "protobuf_lang_parser.h" #include "protobuf_lang_scanner_lex.h" -/* Generated lemon code warns on this. */ -DIAG_OFF(unreachable-code) - #define NAME_TO_BE_SET "<NAME_TO_BE_SET>" #define NEED_NOT_NAME "<NEED_NOT_NAME>" @@ -51,8 +48,13 @@ void pbl_parser_error(protobuf_lang_state_t *state, const char *fmt, ...); pbl_set_node_name() later. */ #define CUR_LINENO (protobuf_lang_get_lineno(state->scanner)) +DIAG_OFF_LEMON() } /* end of %include */ +%code { +DIAG_ON_LEMON() +} + %name ProtobufLangParser %extra_argument { protobuf_lang_state_t *state } diff --git a/epan/protobuf_lang_scanner.l b/epan/protobuf_lang_scanner.l index 187ba06839..335d960397 100644 --- a/epan/protobuf_lang_scanner.l +++ b/epan/protobuf_lang_scanner.l @@ -64,7 +64,7 @@ /* * Disable diagnostics in the code generated by Flex. */ -DIAG_OFF_FLEX +DIAG_OFF_FLEX() /* * Sleazy hack to suppress compiler warnings in yy_fatal_error(). @@ -191,4 +191,4 @@ strdup_and_store(void* yyscanner, const char* text) { /* * Turn diagnostics back on, so we check the code that we've written. */ -DIAG_ON_FLEX +DIAG_ON_FLEX() diff --git a/epan/radius_dict.l b/epan/radius_dict.l index 97a0d3aa50..c8c1825c13 100644 --- a/epan/radius_dict.l +++ b/epan/radius_dict.l @@ -96,7 +96,7 @@ /* * Disable diagnostics in the code generated by Flex. */ -DIAG_OFF_FLEX +DIAG_OFF_FLEX() /* * See @@ -413,7 +413,7 @@ static void add_value(Radius_scanner_state_t* state, const gchar* attrib_name, c /* * Turn diagnostics back on, so we check the code that we've written. */ -DIAG_ON_FLEX +DIAG_ON_FLEX() static void add_vendor(Radius_scanner_state_t* state, const gchar* name, guint32 id, guint type_octets, guint length_octets, gboolean has_flags) { radius_vendor_info_t* v; diff --git a/epan/uat_load.l b/epan/uat_load.l index c9d0bcfe5e..06ab49ee23 100644 --- a/epan/uat_load.l +++ b/epan/uat_load.l @@ -98,7 +98,7 @@ /* * Disable diagnostics in the code generated by Flex. */ -DIAG_OFF_FLEX +DIAG_OFF_FLEX() typedef struct { uat_t* uat; @@ -391,7 +391,7 @@ comment #[^\n]*\n /* * Turn diagnostics back on, so we check the code that we've written. */ -DIAG_ON_FLEX +DIAG_ON_FLEX() gboolean uat_load(uat_t *uat, const gchar *filename, char **errx) |