changeset 21023:ec532a439c6f

rework method of disabling warnings from GCC * configure.ac: Check for GCC's #pragma GCC diagnostic feature. * libinterp/module.mk, libinterp/corefcn/module.mk, libinterp/parse-tree/module.mk: Eliminate separate libraries for TeX and Octave parsers. * oct-tex-lexer.in.ll, oct-tex-parser.in.yy, lex.ll, oct-parse.in.yy: Use GCC #pragma GCC diagnostic feature to more selectively disable warnings in generated code. * libgui/module.mk (rcc-command): Use GCC #pragma GCC diagnostic feature to more selectively disable warnings in generated code.
author John W. Eaton <jwe@octave.org>
date Thu, 31 Dec 2015 17:06:36 -0500
parents ebc439187d29
children 6176560b03d9
files configure.ac libgui/module.mk libinterp/corefcn/module.mk libinterp/corefcn/oct-tex-lexer.in.ll libinterp/corefcn/oct-tex-parser.in.yy libinterp/module.mk libinterp/parse-tree/lex.ll libinterp/parse-tree/module.mk libinterp/parse-tree/oct-parse.in.yy
diffstat 9 files changed, 135 insertions(+), 57 deletions(-) [+]
line wrap: on
line diff
--- a/configure.ac	Thu Dec 31 13:45:43 2015 -0500
+++ b/configure.ac	Thu Dec 31 17:06:36 2015 -0500
@@ -2555,6 +2555,27 @@
 AC_SUBST(WARN_CXXFLAGS)
 AC_SUBST(WARN_LDFLAGS)
 
+## Also check for the GCC-specific pragmas for controlling warnings.
+
+AC_CACHE_CHECK([for @%:@pragma GCC diagnostic push/pop/ignore],
+  [octave_cv_gcc_has_pragma_GCC_diagnostic],
+  [AC_LANG_PUSH(C++)
+   AC_TRY_COMPILE([], [
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignore "-Wold-style-cast"
+  int three = (int) 3.1415926;
+#pragma GCC diagnostic pop
+    ],
+    [octave_cv_gcc_has_pragma_GCC_diagnostic=yes],
+    [octave_cv_gcc_has_pragma_GCC_diagnostic=no])
+   AC_LANG_POP(C++)],
+  ])
+
+if test $octave_cv_gcc_has_pragma_GCC_diagnostic = yes; then
+  AC_DEFINE(HAVE_PRAGMA_GCC_DIAGNOSTIC, 1,
+   [define if GCC supports @%:@pragma GCC diagnostic ...])
+fi
+
 ### Check for Java.
 
 build_java=yes
--- a/libgui/module.mk	Thu Dec 31 13:45:43 2015 -0500
+++ b/libgui/module.mk	Thu Dec 31 17:06:36 2015 -0500
@@ -90,6 +90,10 @@
   ( echo "#ifdef HAVE_CONFIG_H"; \
     echo "#include <config.h>"; \
     echo "#endif"; \
+    echo "// Ignore unused variable warnings in generated code."; \
+    echo "#if defined (HAVE_PRAGMA_GCC_DIAGNOSTIC)"; \
+    echo "#pragma GCC diagnostic ignored \"-Wunused-variable\""; \
+    echo "#endif"; \
     $(RCC) -name $(@D) $< ) > $@-t && \
   mv $@-t $@
 endef
--- a/libinterp/corefcn/module.mk	Thu Dec 31 13:45:43 2015 -0500
+++ b/libinterp/corefcn/module.mk	Thu Dec 31 17:06:36 2015 -0500
@@ -20,9 +20,6 @@
   libinterp/corefcn/jit-ir.h \
   libinterp/corefcn/pt-jit.h
 
-TEX_PARSER_INC = \
-  libinterp/corefcn/oct-tex-parser.h
-
 COREFCN_INC = \
   libinterp/corefcn/Cell.h \
   libinterp/corefcn/c-file-ptr-stream.h \
@@ -72,6 +69,7 @@
   libinterp/corefcn/oct-stdstrm.h \
   libinterp/corefcn/oct-stream.h \
   libinterp/corefcn/oct-strstrm.h \
+  libinterp/corefcn/oct-tex-parser.h \
   libinterp/corefcn/oct.h \
   libinterp/corefcn/octave-default-image.h \
   libinterp/corefcn/octave-link.h \
@@ -96,8 +94,7 @@
   libinterp/corefcn/xnorm.h \
   libinterp/corefcn/xpow.h \
   libinterp/corefcn/zfstream.h \
-  $(JIT_INC) \
-  $(TEX_PARSER_INC)
+  $(JIT_INC)
 
 JIT_SRC = \
   libinterp/corefcn/jit-util.cc \
@@ -105,10 +102,6 @@
   libinterp/corefcn/jit-ir.cc \
   libinterp/corefcn/pt-jit.cc
 
-TEX_PARSER_SRC = \
-  libinterp/corefcn/oct-tex-lexer.ll \
-  libinterp/corefcn/oct-tex-parser.yy
-
 C_COREFCN_SRC = \
   libinterp/corefcn/siglist.c
 
@@ -203,6 +196,8 @@
   libinterp/corefcn/oct-procbuf.cc \
   libinterp/corefcn/oct-stream.cc \
   libinterp/corefcn/oct-strstrm.cc \
+  libinterp/corefcn/oct-tex-lexer.ll \
+  libinterp/corefcn/oct-tex-parser.yy \
   libinterp/corefcn/octave-link.cc \
   libinterp/corefcn/ordschur.cc \
   libinterp/corefcn/pager.cc \
@@ -328,8 +323,7 @@
 	$(AM_V_GEN)$(call subst-bison-api-decls,octave_tex_)
 
 noinst_LTLIBRARIES += \
-  libinterp/corefcn/libcorefcn.la \
-  libinterp/corefcn/libtex_parser.la
+  libinterp/corefcn/libcorefcn.la
 
 libinterp_corefcn_libcorefcn_la_SOURCES = $(COREFCN_SRC)
 
@@ -346,13 +340,6 @@
 
 libinterp_corefcn_libcorefcn_la_CXXFLAGS = $(AM_CXXFLAGS) $(WARN_CXXFLAGS) $(LLVM_CXXFLAGS)
 
-libinterp_corefcn_libtex_parser_la_SOURCES = $(TEX_PARSER_SRC)
-
-libinterp_corefcn_libtex_parser_la_CPPFLAGS = $(libinterp_liboctinterp_la_CPPFLAGS)
-
-libinterp_corefcn_libtex_parser_la_CXXFLAGS = \
-  $(filter-out -Wold-style-cast, $(libinterp_corefcn_libcorefcn_la_CXXFLAGS))
-
 libinterp_EXTRA_DIST += \
   libinterp/corefcn/defaults.in.h \
   libinterp/corefcn/graphics.in.h \
--- a/libinterp/corefcn/oct-tex-lexer.in.ll	Thu Dec 31 13:45:43 2015 -0500
+++ b/libinterp/corefcn/oct-tex-lexer.in.ll	Thu Dec 31 17:06:36 2015 -0500
@@ -20,6 +20,24 @@
 
 */
 
+%top {
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#if defined (HAVE_PRAGMA_GCC_DIAGNOSTIC)
+// This one needs to be global.
+#pragma GCC diagnostic ignored "-Wunused-function"
+
+// Disable this warning for code that is generated by flex, including
+// pattern rules.  Push the current state so we can restore the warning
+// state prior to functions we define at the bottom of the file.
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wold-style-cast"
+#endif
+
+}
+
 %option prefix = "octave_tex_"
 %option noyywrap
 %option reentrant
@@ -29,13 +47,6 @@
 %option noyyrealloc
 %option noyyfree
 
-%top {
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-}
-
 %x NUM_MODE
 %x MAYBE_NUM_MODE
 
@@ -171,8 +182,21 @@
     return CH;
   }
 
+%{
+#if defined (HAVE_PRAGMA_GCC_DIAGNOSTIC)
+// Also disable this warning for functions that is generated by flex
+// after the pattern rules.
+#pragma GCC diagnostic ignored "-Wunused-parameter"
+#endif
+%}
+
 %%
 
+#if defined (HAVE_PRAGMA_GCC_DIAGNOSTIC)
+// Restore prevailing warning state for remainder of the file.
+#pragma GCC diagnostic pop
+#endif
+
 void *
 octave_tex_alloc (yy_size_t size, yyscan_t)
 {
--- a/libinterp/corefcn/oct-tex-parser.in.yy	Thu Dec 31 13:45:43 2015 -0500
+++ b/libinterp/corefcn/oct-tex-parser.in.yy	Thu Dec 31 17:06:36 2015 -0500
@@ -45,6 +45,14 @@
 
 #define scanner parser.get_scanner ()
 
+#if defined (HAVE_PRAGMA_GCC_DIAGNOSTIC)
+// Disable this warning for code that is generated by Bison, including
+// grammar rules.  Push the current state so we can restore the warning
+// state prior to functions we define at the bottom of the file.
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wold-style-cast"
+#endif
+
 %}
 
 %API_PREFIX_DECL%
@@ -200,6 +208,11 @@
 
 %%
 
+#if defined (HAVE_PRAGMA_GCC_DIAGNOSTIC)
+// Restore prevailing warning state for remainder of the file.
+#pragma GCC diagnostic pop
+#endif
+
 text_element*
 text_parser_tex::parse (const std::string& s)
 {
--- a/libinterp/module.mk	Thu Dec 31 13:45:43 2015 -0500
+++ b/libinterp/module.mk	Thu Dec 31 17:06:36 2015 -0500
@@ -127,9 +127,7 @@
   libinterp/version.cc \
   $(OCTAVE_VALUE_SRC) \
   $(PARSE_TREE_SRC) \
-  $(PARSER_SRC) \
-  $(COREFCN_SRC) \
-  $(TEX_PARSER_SRC)
+  $(COREFCN_SRC)
 
 include libinterp/parse-tree/module.mk
 include libinterp/octave-value/module.mk
@@ -170,9 +168,7 @@
 libinterp_liboctinterp_la_LIBADD = \
   libinterp/octave-value/liboctave-value.la \
   libinterp/parse-tree/libparse-tree.la \
-  libinterp/parse-tree/libparser.la \
   libinterp/corefcn/libcorefcn.la \
-  libinterp/corefcn/libtex_parser.la \
   $(top_builddir)/liboctave/liboctave.la \
   $(LIBOCTINTERP_LINK_DEPS)
 
--- a/libinterp/parse-tree/lex.ll	Thu Dec 31 13:45:43 2015 -0500
+++ b/libinterp/parse-tree/lex.ll	Thu Dec 31 17:06:36 2015 -0500
@@ -31,6 +31,24 @@
 object) relevant global values before and after the nested call.
 */
 
+%top {
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#if defined (HAVE_PRAGMA_GCC_DIAGNOSTIC)
+// This one needs to be global.
+#pragma GCC diagnostic ignored "-Wunused-function"
+
+// Disable this warning for code that is generated by flex, including
+// pattern rules.  Push the current state so we can restore the warning
+// state prior to functions we define at the bottom of the file.
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wold-style-cast"
+#endif
+
+}
+
 %option prefix = "octave_"
 %option noyywrap
 %option reentrant
@@ -40,13 +58,6 @@
 %option noyyrealloc
 %option noyyfree
 
-%top {
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-}
-
 %x COMMAND_START
 %s MATRIX_START
 
@@ -1723,8 +1734,29 @@
       }
   }
 
+%{
+#if defined (HAVE_PRAGMA_GCC_DIAGNOSTIC)
+// Disable this warning for code that is generated by flex.
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wold-style-cast"
+#endif
+%}
+
+%{
+#if defined (HAVE_PRAGMA_GCC_DIAGNOSTIC)
+// Also disable this warning for functions that is generated by flex
+// after the pattern rules.
+#pragma GCC diagnostic ignored "-Wunused-parameter"
+#endif
+%}
+
 %%
 
+#if defined (HAVE_PRAGMA_GCC_DIAGNOSTIC)
+// Restore prevailing warning state for remainder of the file.
+#pragma GCC diagnostic pop
+#endif
+
 void *
 octave_alloc (yy_size_t size, yyscan_t)
 {
@@ -2711,7 +2743,7 @@
     {
       uint64_t ivalue = 0;
 
-      for (int i = 0; i < strlen (tmptxt); i++)
+      for (size_t i = 0; i < strlen (tmptxt); i++)
         {
           ivalue <<= 1;
           ivalue += static_cast<uint64_t> (tmptxt[i] == '1');
--- a/libinterp/parse-tree/module.mk	Thu Dec 31 13:45:43 2015 -0500
+++ b/libinterp/parse-tree/module.mk	Thu Dec 31 17:06:36 2015 -0500
@@ -1,12 +1,6 @@
-PARSER_INC = \
+PARSE_TREE_INC = \
   libinterp/parse-tree/lex.h \
-  libinterp/parse-tree/parse.h
-
-PARSER_SRC = \
-  libinterp/parse-tree/lex.ll \
-  libinterp/parse-tree/oct-parse.yy
-
-PARSE_TREE_INC = \
+  libinterp/parse-tree/parse.h \
   libinterp/parse-tree/pt-all.h \
   libinterp/parse-tree/pt-arg-list.h \
   libinterp/parse-tree/pt-array-list.h \
@@ -41,6 +35,8 @@
   libinterp/parse-tree/token.h
 
 PARSE_TREE_SRC = \
+  libinterp/parse-tree/lex.ll \
+  libinterp/parse-tree/oct-parse.yy \
   libinterp/parse-tree/pt-arg-list.cc \
   libinterp/parse-tree/pt-array-list.cc \
   libinterp/parse-tree/pt-assign.cc \
@@ -91,25 +87,16 @@
 	$(AM_V_GEN)$(call subst-bison-api-decls,octave_)
 
 noinst_LTLIBRARIES += \
-  libinterp/parse-tree/libparse-tree.la \
-  libinterp/parse-tree/libparser.la
+  libinterp/parse-tree/libparse-tree.la
 
 libinterp_parse_tree_libparse_tree_la_SOURCES = $(PARSE_TREE_SRC)
 
 libinterp_parse_tree_libparse_tree_la_CPPFLAGS = $(libinterp_liboctinterp_la_CPPFLAGS)
 
-libinterp_parse_tree_libparse_tree_la_CFLAGS = $(AM_CFLAGS)	\
-$(WARN_CFLAGS)
+libinterp_parse_tree_libparse_tree_la_CFLAGS = $(AM_CFLAGS) $(WARN_CFLAGS)
 
 libinterp_parse_tree_libparse_tree_la_CXXFLAGS = $(AM_CXXFLAGS) $(WARN_CXXFLAGS)
 
-libinterp_parse_tree_libparser_la_SOURCES = $(PARSER_SRC)
-
-libinterp_parse_tree_libparser_la_CPPFLAGS = $(libinterp_liboctinterp_la_CPPFLAGS)
-
-libinterp_parse_tree_libparser_la_CXXFLAGS = \
-  $(filter-out -Wold-style-cast, $(AM_CXXFLAGS))
-
 libinterp_EXTRA_DIST += \
   libinterp/parse-tree/oct-parse.in.yy \
   libinterp/parse-tree/octave.gperf
--- a/libinterp/parse-tree/oct-parse.in.yy	Thu Dec 31 13:45:43 2015 -0500
+++ b/libinterp/parse-tree/oct-parse.in.yy	Thu Dec 31 17:06:36 2015 -0500
@@ -27,6 +27,7 @@
 // C decarations.
 
 %{
+
 #define YYDEBUG 1
 
 #ifdef HAVE_CONFIG_H
@@ -121,6 +122,14 @@
 #define lexer parser.lexer
 #define scanner lexer.scanner
 
+#if defined (HAVE_PRAGMA_GCC_DIAGNOSTIC)
+// Disable this warning for code that is generated by Bison, including
+// grammar rules.  Push the current state so we can restore the warning
+// state prior to functions we define at the bottom of the file.
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wold-style-cast"
+#endif
+
 %}
 
 // Bison declarations.
@@ -2005,6 +2014,11 @@
 
 %%
 
+#if defined (HAVE_PRAGMA_GCC_DIAGNOSTIC)
+// Restore prevailing warning state for remainder of the file.
+#pragma GCC diagnostic pop
+#endif
+
 // Generic error messages.
 
 #undef lexer