From 97281fd4454596834142fa43f83af38695b38e5b Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 5 May 2014 15:02:44 -0700 Subject: GCC 4.9.0 compatibility fixes --- odb/gcc-fwd.hxx | 18 ++++++++++++++++++ odb/gcc.hxx | 22 ++++++++++++++++++++-- odb/parser.cxx | 47 +++++++++++++++++++++++++---------------------- odb/pragma.cxx | 4 ++-- odb/pragma.hxx | 9 ++++++--- odb/processor.cxx | 10 +++++----- 6 files changed, 76 insertions(+), 34 deletions(-) diff --git a/odb/gcc-fwd.hxx b/odb/gcc-fwd.hxx index d459a9d..38f9819 100644 --- a/odb/gcc-fwd.hxx +++ b/odb/gcc-fwd.hxx @@ -5,8 +5,26 @@ #ifndef ODB_GCC_FWD_HXX #define ODB_GCC_FWD_HXX +#include + +#if BUILDING_GCC_MAJOR > 4 || BUILDING_GCC_MAJOR == 4 && BUILDING_GCC_MINOR > 8 +# include // CHAR_BIT +# include +#endif + extern "C" { +// The hwint.h header uses gcc_checking_assert macro from system.h. But +// if we include system.h here, it pulls in all kinds of GCC trouble that +// "poisons" standard C/C++ declarations (see safe-ctype.h for an example). +// Instead we are just going to provide the no-op definition of this macro. +// +#if BUILDING_GCC_MAJOR > 4 || BUILDING_GCC_MAJOR == 4 && BUILDING_GCC_MINOR > 8 +# define gcc_checking_assert(expr) ((void)(0 & (expr))) +# include +# undef gcc_checking_assert +#endif + #include typedef unsigned int source_location; // diff --git a/odb/gcc.hxx b/odb/gcc.hxx index 0278819..341b8e0 100644 --- a/odb/gcc.hxx +++ b/odb/gcc.hxx @@ -16,8 +16,6 @@ #include // Include before GCC poisons some declarations. -#include - // GCC 4.7 can be built using either C or C++ compiler. From 4.8 it // is always built as C++. // @@ -56,6 +54,10 @@ extern "C" # include #endif +#if BUILDING_GCC_MAJOR > 4 || BUILDING_GCC_MAJOR == 4 && BUILDING_GCC_MINOR > 8 +# include // get_identifier +#endif + #include #include @@ -63,6 +65,22 @@ extern "C" } // extern "C" #endif +// In 4.9.0 the tree code type was changed from int to enum tree_code. +// the tree_code_name array is also gone with the get_tree_code_name() +// function in its place. +// +#if BUILDING_GCC_MAJOR > 4 || BUILDING_GCC_MAJOR == 4 && BUILDING_GCC_MINOR > 8 +typedef enum tree_code gcc_tree_code_type; + +inline const char* +gcc_tree_code_name (gcc_tree_code_type tc) {return get_tree_code_name (tc);} +#else +typedef int gcc_tree_code_type; + +inline const char* +gcc_tree_code_name (gcc_tree_code_type tc) {return tree_code_name[tc];} +#endif + // Only since GCC 4.7.0. // #ifndef LOCATION_COLUMN diff --git a/odb/parser.cxx b/odb/parser.cxx index 140e09e..6e857bb 100644 --- a/odb/parser.cxx +++ b/odb/parser.cxx @@ -1028,7 +1028,7 @@ type* parser::impl:: emit_type_decl (tree decl) { tree t (TREE_TYPE (decl)); - int tc (TREE_CODE (t)); + gcc_tree_code_type tc (TREE_CODE (t)); tree decl_name (DECL_NAME (decl)); char const* name (IDENTIFIER_POINTER (decl_name)); @@ -1086,7 +1086,7 @@ emit_type_decl (tree decl) { if (trace) - ts << "start " << tree_code_name[tc] << " " << name + ts << "start " << gcc_tree_code_name(tc) << " " << name << " at " << file << ":" << line << endl; switch (tc) @@ -1106,10 +1106,12 @@ emit_type_decl (tree decl) node = &emit_enum (t, decl_access (decl), file, line, clmn); break; } + default: + break; } if (trace) - ts << "end " << tree_code_name[tc] << " " << name + ts << "end " << gcc_tree_code_name(tc) << " " << name << " (" << node << ") at " << DECL_SOURCE_FILE (decl) << ":" << DECL_SOURCE_LINE (decl) << endl; @@ -1176,11 +1178,11 @@ emit_template_decl (tree decl) // Currently we only handle class/union templates. // tree t (TREE_TYPE (DECL_TEMPLATE_RESULT (decl))); - int tc (TREE_CODE (t)); + gcc_tree_code_type tc (TREE_CODE (t)); if (trace) { - ts << tree_code_name[tc] << " template (" << decl << ") " + ts << gcc_tree_code_name(tc) << " template (" << decl << ") " << IDENTIFIER_POINTER (DECL_NAME (decl)) << " (" << t << ") at " << DECL_SOURCE_FILE (decl) << ":" << DECL_SOURCE_LINE (decl) << endl; @@ -1215,7 +1217,7 @@ emit_template_decl (tree decl) char const* name (IDENTIFIER_POINTER (DECL_NAME (decl))); if (trace) - ts << "start " << tree_code_name[tc] << " template " << name << " at " + ts << "start " << gcc_tree_code_name(tc) << " template " << name << " at " << DECL_SOURCE_FILE (decl) << ":" << DECL_SOURCE_LINE (decl) << endl; @@ -1232,7 +1234,7 @@ emit_template_decl (tree decl) unit_->new_edge (*scope_, *t_node, name); if (trace) - ts << "end " << tree_code_name[tc] << " template " << name + ts << "end " << gcc_tree_code_name(tc) << " template " << name << " (" << t_node << ") at " << DECL_SOURCE_FILE (decl) << ":" << DECL_SOURCE_LINE (decl) << endl; @@ -1510,7 +1512,7 @@ emit_type (tree t, if (trace) { - ts << tree_code_name[TREE_CODE (t)] << " " << t + ts << gcc_tree_code_name(TREE_CODE (t)) << " " << t << " main " << mv << endl; for (tree v (TYPE_MAIN_VARIANT (t)); v != 0; v = TYPE_NEXT_VARIANT (v)) @@ -1630,7 +1632,7 @@ create_type (tree t, size_t clmn) { type* r (0); - int tc (TREE_CODE (t)); + gcc_tree_code_type tc (TREE_CODE (t)); switch (tc) { @@ -1671,7 +1673,7 @@ create_type (tree t, tree d (TYPE_NAME (t)); if (trace) - ts << "start anon/stub " << tree_code_name[tc] << " at " + ts << "start anon/stub " << gcc_tree_code_name(tc) << " at " << file << ":" << line << endl; if (d == NULL_TREE || ANON_AGGRNAME_P (DECL_NAME (d))) @@ -1697,7 +1699,7 @@ create_type (tree t, } if (trace) - ts << "end anon/stub " << tree_code_name[tc] << " (" << r << ")" + ts << "end anon/stub " << gcc_tree_code_name(tc) << " (" << r << ")" << " at " << file << ":" << line << endl; } } @@ -1722,7 +1724,7 @@ create_type (tree t, else { if (trace) - ts << "start stub " << tree_code_name[tc] << " template for (" + ts << "start stub " << gcc_tree_code_name(tc) << " template for (" << decl << ") at " << file << ":" << line << endl; if (tc == RECORD_TYPE) @@ -1731,12 +1733,12 @@ create_type (tree t, t_node = &emit_union_template (decl, true); if (trace) - ts << "end stub " << tree_code_name[tc] << " template (" + ts << "end stub " << gcc_tree_code_name(tc) << " template (" << t_node << ") at " << file << ":" << line << endl; } if (trace) - ts << "start " << tree_code_name[tc] << " instantiation (" + ts << "start " << gcc_tree_code_name(tc) << " instantiation (" << t << ") for template (" << t_node << ")" << " at " << file << ":" << line << endl; @@ -1748,7 +1750,7 @@ create_type (tree t, i_node = &emit_union (t, file, line, clmn); if (trace) - ts << "end " << tree_code_name[tc] << " instantiation (" + ts << "end " << gcc_tree_code_name(tc) << " instantiation (" << static_cast (i_node) << ")" << " at " << file << ":" << line << endl; @@ -1769,7 +1771,7 @@ create_type (tree t, tree d (TYPE_NAME (t)); if (trace) - ts << "start anon/stub " << tree_code_name[tc] << " at " + ts << "start anon/stub " << gcc_tree_code_name(tc) << " at " << file << ":" << line << endl; if (d == NULL_TREE || ANON_AGGRNAME_P (DECL_NAME (d))) @@ -1789,7 +1791,7 @@ create_type (tree t, } if (trace) - ts << "end anon/stub " << tree_code_name[tc] << " (" << r << ")" + ts << "end anon/stub " << gcc_tree_code_name(tc) << " (" << r << ")" << " at " << file << ":" << line << endl; break; @@ -1828,7 +1830,8 @@ create_type (tree t, else { error (file, line, clmn) - << "non-integer array index " << tree_code_name[TREE_CODE (max)] + << "non-integer array index " << + gcc_tree_code_name(TREE_CODE (max)) << endl; throw failed (); @@ -1915,11 +1918,11 @@ create_type (tree t, { t = TYPE_MAIN_VARIANT (t); r = &unit_->new_node ( - file, line, clmn, t, tree_code_name[tc]); + file, line, clmn, t, gcc_tree_code_name(tc)); unit_->insert (t, *r); if (trace) - ts << "unsupported " << tree_code_name[tc] << " (" << r << ")" + ts << "unsupported " << gcc_tree_code_name(tc) << " (" << r << ")" << " at " << file << ":" << line << endl; break; @@ -1956,7 +1959,7 @@ emit_type_name (tree type, bool direct) if (CP_TYPE_RESTRICT_P (type)) r += " __restrict"; - int tc (TREE_CODE (type)); + gcc_tree_code_type tc (TREE_CODE (type)); switch (tc) { @@ -2107,7 +2110,7 @@ emit_type_name (tree type, bool direct) } default: { - r = "<" + string (tree_code_name[tc]) + ">"; + r = "<" + string (gcc_tree_code_name(tc)) + ">"; break; } } diff --git a/odb/pragma.cxx b/odb/pragma.cxx index 89cfd50..6a2d6ba 100644 --- a/odb/pragma.cxx +++ b/odb/pragma.cxx @@ -368,7 +368,7 @@ check_spec_decl_type (declaration const& d, string const& p, location_t l) { - int tc (d.tree_code ()); + gcc_tree_code_type tc (d.tree_code ()); bool type (TREE_CODE_CLASS (tc) == tcc_type); if (p == "no_id") @@ -2509,7 +2509,7 @@ check_qual_decl_type (declaration const& d, string const& p, location_t l) { - int tc (d.tree_code ()); + gcc_tree_code_type tc (d.tree_code ()); bool type (TREE_CODE_CLASS (tc) == tcc_type); if (p == "model" || diff --git a/odb/pragma.hxx b/odb/pragma.hxx index 0ccb0d9..37aaeb9 100644 --- a/odb/pragma.hxx +++ b/odb/pragma.hxx @@ -20,12 +20,15 @@ struct virt_declaration { - virt_declaration (location_t l, std::string const& n, int tc, tree t) + virt_declaration (location_t l, + std::string const& n, + gcc_tree_code_type tc, + tree t) : loc (l), name (n), tree_code (tc), type (t) {} location_t loc; std::string name; - int tree_code; + gcc_tree_code_type tree_code; tree type; // Declaration's type. }; @@ -89,7 +92,7 @@ struct declaration virt_declaration const* virt; } decl; - int + gcc_tree_code_type tree_code () const { return (virt ? decl.virt->tree_code : TREE_CODE (decl.real)); diff --git a/odb/processor.cxx b/odb/processor.cxx index 0964645..6a9c2a3 100644 --- a/odb/processor.cxx +++ b/odb/processor.cxx @@ -188,7 +188,7 @@ namespace // suggested in the documentation. // tree r (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (f)))); - int tc (TREE_CODE (r)); + gcc_tree_code_type tc (TREE_CODE (r)); // In the strict mode make sure the function returns for non-array // types a value or a (const) reference to the member type and for @@ -253,7 +253,7 @@ namespace // suggested in the documentation. // tree r (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (f)))); - int tc (TREE_CODE (r)); + gcc_tree_code_type tc (TREE_CODE (r)); // By-reference modifier. Should return a reference or a pointer. // @@ -297,7 +297,7 @@ namespace // with regards to arrays, references, etc. // tree at (TREE_TYPE (a)); - int tc (TREE_CODE (at)); + gcc_tree_code_type tc (TREE_CODE (at)); if (ar != 0 && tc != POINTER_TYPE) return found_none; @@ -2621,7 +2621,7 @@ namespace // template or a type. // decl = resolve_name (p, cp->scope, true); - int tc (TREE_CODE (decl)); + gcc_tree_code_type tc (TREE_CODE (decl)); if (tc == TYPE_DECL) { @@ -2711,7 +2711,7 @@ namespace // Resolve this name and make sure it is a template. // decl = resolve_name (p, cp->scope, true); - int tc (TREE_CODE (decl)); + gcc_tree_code_type tc (TREE_CODE (decl)); if (tc == TEMPLATE_DECL && DECL_CLASS_TEMPLATE_P (decl)) { -- cgit v1.1