forked from osmocom/wireshark
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
This commit is contained in:
parent
c4ca4312c1
commit
79c3a77752
|
@ -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 */
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 }
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -164,7 +164,7 @@ extern "C" {
|
|||
* warning C6387: 'XXX' could be '0'
|
||||
* warning C28182: Dereferencing NULL pointer
|
||||
*/
|
||||
#define DIAG_OFF_FLEX \
|
||||
#define DIAG_OFF_FLEX() \
|
||||
__pragma(warning(push)) \
|
||||
__pragma(warning(disable:4018)) \
|
||||
__pragma(warning(disable:4244)) \
|
||||
|
@ -174,7 +174,8 @@ extern "C" {
|
|||
__pragma(warning(disable:6386)) \
|
||||
__pragma(warning(disable:6387)) \
|
||||
__pragma(warning(disable:28182))
|
||||
#define DIAG_ON_FLEX __pragma(warning(pop))
|
||||
#define DIAG_ON_FLEX() \
|
||||
__pragma(warning(pop))
|
||||
#else
|
||||
/*
|
||||
* Suppress:
|
||||
|
@ -198,24 +199,35 @@ extern "C" {
|
|||
* you know what you're doing" warning that MSVC does?)
|
||||
*/
|
||||
#if defined(__clang__) || defined(__APPLE__)
|
||||
#define DIAG_OFF_FLEX \
|
||||
#define DIAG_OFF_FLEX() \
|
||||
DIAG_OFF(sign-compare) \
|
||||
DIAG_OFF(shorten-64-to-32) \
|
||||
DIAG_OFF(unreachable-code) \
|
||||
DIAG_OFF(documentation)
|
||||
#define DIAG_ON_FLEX \
|
||||
#define DIAG_ON_FLEX() \
|
||||
DIAG_ON(documentation) \
|
||||
DIAG_ON(unreachable-code) \
|
||||
DIAG_ON(shorten-64-to-32) \
|
||||
DIAG_ON(sign-compare)
|
||||
#else
|
||||
#define DIAG_OFF_FLEX \
|
||||
#define DIAG_OFF_FLEX() \
|
||||
DIAG_OFF(sign-compare)
|
||||
#define DIAG_ON_FLEX \
|
||||
#define DIAG_ON_FLEX() \
|
||||
DIAG_ON(sign-compare)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* Disable Lemon warnings. */
|
||||
#if defined(_MSC_VER)
|
||||
#define DIAG_OFF_LEMON()
|
||||
#define DIAG_ON_LEMON()
|
||||
#else
|
||||
#define DIAG_OFF_LEMON() \
|
||||
DIAG_OFF_CLANG(unreachable-code)
|
||||
#define DIAG_ON_LEMON() \
|
||||
DIAG_ON_CLANG(unreachable-code)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Suppress warnings about casting away constness.
|
||||
* Do this only if you know that the pointer is to something that can
|
||||
|
|
|
@ -26,9 +26,6 @@
|
|||
#include <wsutil/file_util.h>
|
||||
#include <wsutil/str_util.h>
|
||||
|
||||
/* Generated lemon code warns on this. */
|
||||
DIAG_OFF(unreachable-code)
|
||||
|
||||
#define DUMMY void*
|
||||
|
||||
typedef struct _extraction {
|
||||
|
@ -171,6 +168,11 @@ static gchar* recolonize(mate_config* mc, gchar* s) {
|
|||
return r;
|
||||
}
|
||||
|
||||
DIAG_OFF_LEMON()
|
||||
} /* end of %include */
|
||||
|
||||
%code {
|
||||
DIAG_ON_LEMON()
|
||||
}
|
||||
|
||||
%name MateParser
|
||||
|
|
|
@ -87,7 +87,7 @@
|
|||
/*
|
||||
* Disable diagnostics in the code generated by Flex.
|
||||
*/
|
||||
DIAG_OFF_FLEX
|
||||
DIAG_OFF_FLEX()
|
||||
|
||||
void MateParseTrace(FILE*,char*);
|
||||
|
||||
|
@ -337,7 +337,7 @@ blk_cmnt_stop "*/"
|
|||
/*
|
||||
* Turn diagnostics back on, so we check the code that we've written.
|
||||
*/
|
||||
DIAG_ON_FLEX
|
||||
DIAG_ON_FLEX()
|
||||
|
||||
static void ptr_array_free(gpointer data, gpointer user_data _U_)
|
||||
{
|
||||
|
|
|
@ -104,7 +104,7 @@
|
|||
/*
|
||||
* Disable diagnostics in the code generated by Flex.
|
||||
*/
|
||||
DIAG_OFF_FLEX
|
||||
DIAG_OFF_FLEX()
|
||||
|
||||
typedef struct entity_t {
|
||||
gchar *name;
|
||||
|
@ -517,7 +517,7 @@ since_attr since=\042
|
|||
/*
|
||||
* Turn diagnostics back on, so we check the code that we've written.
|
||||
*/
|
||||
DIAG_ON_FLEX
|
||||
DIAG_ON_FLEX()
|
||||
|
||||
static int debugging = 0;
|
||||
|
||||
|
|
|
@ -76,7 +76,7 @@
|
|||
/*
|
||||
* Disable diagnostics in the code generated by Flex.
|
||||
*/
|
||||
DIAG_OFF_FLEX
|
||||
DIAG_OFF_FLEX()
|
||||
|
||||
/*
|
||||
* Flex (v 2.5.35) uses this symbol to "exclude" unistd.h
|
||||
|
@ -132,7 +132,7 @@ eol \r?\n\r?
|
|||
/*
|
||||
* Turn diagnostics back on, so we check the code that we've written.
|
||||
*/
|
||||
DIAG_ON_FLEX
|
||||
DIAG_ON_FLEX()
|
||||
|
||||
import_status_t
|
||||
text_import_scan(FILE *input_file)
|
||||
|
|
|
@ -140,10 +140,12 @@ static void AscendParserFree(void *p, void (*freeProc)(void*));
|
|||
#define ascend_debug(...)
|
||||
#endif
|
||||
|
||||
/* Generated lemon code warns on this. */
|
||||
DIAG_OFF(unreachable-code)
|
||||
DIAG_OFF_LEMON()
|
||||
} /* end of %include */
|
||||
|
||||
} // %include
|
||||
%code {
|
||||
DIAG_ON_LEMON()
|
||||
}
|
||||
|
||||
%name AscendParser
|
||||
|
||||
|
|
|
@ -64,7 +64,7 @@
|
|||
/*
|
||||
* Disable diagnostics in the code generated by Flex.
|
||||
*/
|
||||
DIAG_OFF_FLEX
|
||||
DIAG_OFF_FLEX()
|
||||
|
||||
static int ascend_yyinput(void *buf, ascend_state_t *parser_state) {
|
||||
int c = file_getc(parser_state->fh);
|
||||
|
@ -406,4 +406,4 @@ task:|task|at|time:|octets { return KEYWORD; }
|
|||
/*
|
||||
* Turn diagnostics back on, so we check the code that we've written.
|
||||
*/
|
||||
DIAG_ON_FLEX
|
||||
DIAG_ON_FLEX()
|
||||
|
|
|
@ -34,8 +34,11 @@ static void merge_msg_data(msg_data_t *dst, const msg_data_t *a, const msg_data_
|
|||
memcpy(&dst->data[a->length], &b->data[0], b->length);
|
||||
}
|
||||
|
||||
DIAG_OFF(unreachable-code)
|
||||
DIAG_OFF_LEMON()
|
||||
} /* end of %include */
|
||||
|
||||
%code {
|
||||
DIAG_ON_LEMON()
|
||||
}
|
||||
|
||||
%name BusmasterParser
|
||||
|
@ -369,8 +372,6 @@ data64(R) ::= data32(A) data32(B) . { merge_msg_data(&R, &A, &B); }
|
|||
|
||||
%code {
|
||||
|
||||
DIAG_ON(unreachable-code)
|
||||
|
||||
#include "busmaster_scanner_lex.h"
|
||||
#include "busmaster_parser.h"
|
||||
|
||||
|
|
|
@ -86,7 +86,7 @@ static int busmaster_yyinput(void *buf, unsigned int length, busmaster_state_t *
|
|||
#define busmaster_realloc(ptr, size, yyscanner) (void *)realloc((char *)(ptr), (size))
|
||||
#define busmaster_free(ptr, yyscanner) free((char *)(ptr))
|
||||
|
||||
DIAG_OFF_FLEX
|
||||
DIAG_OFF_FLEX()
|
||||
|
||||
%}
|
||||
|
||||
|
@ -196,4 +196,4 @@ NUM (0x)?[0-9A-Fa-f]+
|
|||
|
||||
%%
|
||||
|
||||
DIAG_ON_FLEX
|
||||
DIAG_ON_FLEX()
|
||||
|
|
|
@ -34,8 +34,11 @@ static void merge_msg_data(msg_data_t *dst, const msg_data_t *a, const msg_data_
|
|||
memcpy(&dst->data[a->length], &b->data[0], b->length);
|
||||
}
|
||||
|
||||
DIAG_OFF(unreachable-code)
|
||||
DIAG_OFF_LEMON()
|
||||
} /* end of %include */
|
||||
|
||||
%code {
|
||||
DIAG_ON_LEMON()
|
||||
}
|
||||
|
||||
%name CandumpParser
|
||||
|
@ -268,8 +271,6 @@ data64(R) ::= data32(A) data32(B) . { merge_msg_data(&R, &A, &B); }
|
|||
|
||||
%code {
|
||||
|
||||
DIAG_ON(unreachable-code)
|
||||
|
||||
#include "candump_scanner_lex.h"
|
||||
#include "candump_parser.h"
|
||||
|
||||
|
|
|
@ -89,7 +89,7 @@ static int candump_yyinput(void *buf, candump_state_t *state)
|
|||
#define candump_realloc(ptr, size, yyscanner) (void *)realloc((char *)(ptr), (size))
|
||||
#define candump_free(ptr, yyscanner) free((char *)(ptr))
|
||||
|
||||
DIAG_OFF_FLEX
|
||||
DIAG_OFF_FLEX()
|
||||
|
||||
%}
|
||||
|
||||
|
@ -141,4 +141,4 @@ R {
|
|||
|
||||
%%
|
||||
|
||||
DIAG_ON_FLEX
|
||||
DIAG_ON_FLEX()
|
||||
|
|
|
@ -106,7 +106,7 @@
|
|||
/*
|
||||
* Disable diagnostics in the code generated by Flex.
|
||||
*/
|
||||
DIAG_OFF_FLEX
|
||||
DIAG_OFF_FLEX()
|
||||
|
||||
/*
|
||||
* State kept by the scanner.
|
||||
|
@ -245,7 +245,7 @@ hdlc HDLC
|
|||
/*
|
||||
* Turn diagnostics back on, so we check the code that we've written.
|
||||
*/
|
||||
DIAG_ON_FLEX
|
||||
DIAG_ON_FLEX()
|
||||
|
||||
/* Fill in pkthdr */
|
||||
|
||||
|
|
Loading…
Reference in New Issue