Factorize out parsing of integral types
authorDodji Seketeli <dodji@redhat.com>
Tue, 1 Nov 2016 10:16:55 +0000 (11:16 +0100)
committerDodji Seketeli <dodji@redhat.com>
Thu, 3 Nov 2016 14:13:17 +0000 (15:13 +0100)
Until now, integral_type has been just a "private" helper type used in
the building of a type_decl.

Now it's going to be helpful in determining the name of an integral
type, directly from DIEs -- without having to build a type_decl.

This patch factorizes out the parsing and building of an integral_type
by introducing a src/abg-ir-priv.h file that is meant to declare
interfaces that are going to be private to libabigail.so but usable by
all of its modules.

* src/abg-ir-priv.h: New file.
* src/Makefile.am: Add abg-ir-priv.h to the build system.
* src/abg-ir.cc: Include the new abg-ir-priv.h header file.
(class_integral_type): Move this type
declaration to the new abg-ir-priv.h header.
(integral_type::modifiers_type): Make this non-static.
(parse_integral_type): This new overload is a factorized out of
...
(integral_type::integral_type): ... here.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
src/Makefile.am
src/abg-ir-priv.h [new file with mode: 0644]
src/abg-ir.cc

index bcd69663e4fcc200f979daa41538079aef567caf..df451f601fea18291489a8eee46eee22dea710c1 100644 (file)
@@ -15,6 +15,7 @@ endif
 libabigail_la_SOURCES =                        \
 abg-internal.h                         \
 abg-traverse.cc                                \
+abg-ir-priv.h                          \
 abg-ir.cc                              \
 abg-corpus.cc                          \
 abg-diff-utils.cc                      \
diff --git a/src/abg-ir-priv.h b/src/abg-ir-priv.h
new file mode 100644 (file)
index 0000000..fa160f8
--- /dev/null
@@ -0,0 +1,138 @@
+// -*- Mode: C++ -*-
+//
+// Copyright (C) 2016 Red Hat, Inc.
+//
+// This file is part of the GNU Application Binary Interface Generic
+// Analysis and Instrumentation Library (libabigail).  This library is
+// free software; you can redistribute it and/or modify it under the
+// terms of the GNU Lesser General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option) any
+// later version.
+
+// This library is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// General Lesser Public License for more details.
+
+// You should have received a copy of the GNU Lesser General Public
+// License along with this program; see the file COPYING-LGPLV3.  If
+// not, see <http://www.gnu.org/licenses/>.
+//
+// Author: Dodji Seketeli
+
+/// @file
+///
+/// This contains the private implementation of the suppression engine
+/// of libabigail.
+
+#ifndef __ABG_IR_PRIV_H__
+#define __ABG_IR_PRIV_H__
+
+#include <string>
+
+namespace abigail
+{
+
+namespace ir
+{
+
+using std::string;
+
+/// The internal representation of an integral type.
+///
+/// This is a "utility type" used internally to canonicalize the name
+/// of fundamental integral types, so that "unsignd long" and "long
+/// unsined int" end-up having the same name.
+class integral_type
+{
+public:
+  /// The possible base types of integral types.  We might have
+  /// forgotten many of these, so do not hesitate to add new ones.
+  ///
+  /// If you do add new ones, please also consider updating functions
+  /// parse_base_integral_type and integral_type::to_string.
+  enum base_type
+  {
+    /// The "int" base type.
+    INT_BASE_TYPE,
+    /// The "char" base type.
+    CHAR_BASE_TYPE,
+    /// The "bool" base type in C++ or "_Bool" in C11.
+    BOOL_BASE_TYPE,
+    /// The "double" base type.
+    DOUBLE_BASE_TYPE,
+    /// The "float" base type.
+    FLOAT_BASE_TYPE,
+    /// The "char16_t base type.
+    CHAR16_T_BASE_TYPE,
+    /// The "char32_t" base type.
+    CHAR32_T_BASE_TYPE,
+    /// The "wchar_t" base type.
+    WCHAR_T_BASE_TYPE
+  };
+
+  /// The modifiers of the base types above.  Several modifiers can be
+  /// combined for a given base type.  The presence of modifiers is
+  /// usually modelled by a bitmap of modifiers.
+  ///
+  /// If you add a new modifier, please consider updating functions
+  /// parse_integral_type_modifier and integral_type::to_string.
+  enum modifiers_type
+  {
+    NO_MODIFIER = 0,
+    /// The "signed" modifier.
+    SIGNED_MODIFIER = 1,
+    /// The "unsigned" modier.
+    UNSIGNED_MODIFIER = 1 << 1,
+    /// The "short" modifier.
+    SHORT_MODIFIER = 1 << 2,
+    /// The "long" modifier.
+    LONG_MODIFIER = 1 << 3,
+    /// The "long long" modifier.
+    LONG_LONG_MODIFIER = 1 << 4
+  };
+
+private:
+  base_type    base_;
+  modifiers_type modifiers_;
+
+public:
+
+  integral_type();
+  integral_type(const string& name);
+  integral_type(base_type, modifiers_type);
+
+  base_type
+  get_base_type() const;
+
+  modifiers_type
+  get_modifiers() const;
+
+  bool
+  operator==(const integral_type&) const;
+
+  string
+  to_string() const;
+
+  operator string() const;
+}; // end class integral_type
+
+integral_type::modifiers_type
+operator|(integral_type::modifiers_type l, integral_type::modifiers_type r);
+
+integral_type::modifiers_type
+operator&(integral_type::modifiers_type l, integral_type::modifiers_type r);
+
+integral_type::modifiers_type&
+operator|=(integral_type::modifiers_type& l, integral_type::modifiers_type r);
+
+bool
+parse_integral_type(const string& type_name,
+                   integral_type& type);
+
+} // end namespace ir
+
+} // end namespace abigail
+
+#endif // __ABG_IR_PRIV_H__
+
index e16a409feefec119bac42cc3bb862dea8c23cdf2..45768af314b692a11095e19f68663a8b4843f529 100644 (file)
@@ -33,6 +33,7 @@
 #include <sstream>
 #include <tr1/memory>
 #include <tr1/unordered_map>
+#include "abg-ir-priv.h"
 
 #include "abg-internal.h"
 // <headers defining libabigail's API go under here>
@@ -7416,85 +7417,6 @@ type_base::~type_base()
 
 // <integral_type definitions>
 
-/// The internal representation of an integral type.
-///
-/// This is a "utility type" used internally to canonicalize the name
-/// of fundamental integral types, so that "unsignd long" and "long
-/// unsined int" end-up having the same name.
-class integral_type
-{
-public:
-  /// The possible base types of integral types.  We might have
-  /// forgotten many of these, so do not hesitate to add new ones.
-  ///
-  /// If you do add new ones, please also consider updating functions
-  /// parse_base_integral_type and integral_type::to_string.
-  enum base_type
-  {
-    /// The "int" base type.
-    INT_BASE_TYPE,
-    /// The "char" base type.
-    CHAR_BASE_TYPE,
-    /// The "bool" base type in C++ or "_Bool" in C11.
-    BOOL_BASE_TYPE,
-    /// The "double" base type.
-    DOUBLE_BASE_TYPE,
-    /// The "float" base type.
-    FLOAT_BASE_TYPE,
-    /// The "char16_t base type.
-    CHAR16_T_BASE_TYPE,
-    /// The "char32_t" base type.
-    CHAR32_T_BASE_TYPE,
-    /// The "wchar_t" base type.
-    WCHAR_T_BASE_TYPE
-  };
-
-  /// The modifiers of the base types above.  Several modifiers can be
-  /// combined for a given base type.  The presence of modifiers is
-  /// usually modelled by a bitmap of modifiers.
-  ///
-  /// If you add a new modifier, please consider updating functions
-  /// parse_integral_type_modifier and integral_type::to_string.
-  enum modifiers_type
-  {
-    NO_MODIFIER = 0,
-    /// The "signed" modifier.
-    SIGNED_MODIFIER = 1,
-    /// The "unsigned" modier.
-    UNSIGNED_MODIFIER = 1 << 1,
-    /// The "short" modifier.
-    SHORT_MODIFIER = 1 << 2,
-    /// The "long" modifier.
-    LONG_MODIFIER = 1 << 3,
-    /// The "long long" modifier.
-    LONG_LONG_MODIFIER = 1 << 4
-  };
-
-private:
-  base_type    base_;
-  modifiers_type modifiers_;
-
-public:
-
-  integral_type();
-  integral_type(const string& name);
-  integral_type(base_type, modifiers_type);
-
-  base_type
-  get_base_type() const;
-
-  modifiers_type
-  get_modifiers() const;
-
-  bool
-  operator==(const integral_type&) const;
-
-  string
-  to_string() const;
-
-  operator string() const;
-}; // end class integral_type
-
 /// Bitwise OR operator for integral_type::modifiers_type.
 ///
 /// @param l the left-hand side operand.
@@ -7516,7 +7438,7 @@ operator|(integral_type::modifiers_type l, integral_type::modifiers_type r)
 /// @param r the right-hand side operand.
 ///
 /// @return the result of the bitwise AND.
-static integral_type::modifiers_type
+integral_type::modifiers_type
 operator&(integral_type::modifiers_type l, integral_type::modifiers_type r)
 {
   return static_cast<integral_type::modifiers_type>(static_cast<unsigned>(l)
@@ -7530,7 +7452,7 @@ operator&(integral_type::modifiers_type l, integral_type::modifiers_type r)
 /// @param r the right-hand side operand.
 ///
 /// @return the result of the bitwise |=.
-static integral_type::modifiers_type&
+integral_type::modifiers_type&
 operator|=(integral_type::modifiers_type& l, integral_type::modifiers_type r)
 {
   l = l | r;
@@ -7604,7 +7526,7 @@ parse_base_integral_type(const string& type_name,
   return true;
 }
 
-/// Parse an integral type, from a string.
+/// Parse an integral type from a string.
 ///
 /// @param type_name the string containing the integral type to parse.
 ///
@@ -7672,6 +7594,30 @@ parse_integral_type(const string&                        type_name,
   return ok;
 }
 
+/// Parse an integral type from a string.
+///
+/// @param str the string containing the integral type to parse.
+///
+///@param type the resulting @ref integral_type.  Is set to the result
+///of the parse, iff the function returns true.
+///
+/// @return true iff the function could parse an integral type from @p
+/// str.
+bool
+parse_integral_type(const string& str, integral_type& type)
+{
+  integral_type::base_type base_type = integral_type::INT_BASE_TYPE;
+  integral_type::modifiers_type modifiers = integral_type::NO_MODIFIER;
+
+  if (!parse_integral_type(str, base_type, modifiers))
+    return false;
+
+  // So this is an integral type.
+  integral_type int_type(base_type, modifiers);
+  type = int_type;
+  return true;
+}
+
 /// Default constructor of the @ref integral_type.
 integral_type::integral_type()
   : base_(INT_BASE_TYPE),
@@ -7808,14 +7754,9 @@ type_decl::type_decl(const environment* env,
 {
   integral_type::base_type base_type = integral_type::INT_BASE_TYPE;
   integral_type::modifiers_type modifiers = integral_type::NO_MODIFIER;
-
-  if (parse_integral_type(name, base_type, modifiers))
+  integral_type int_type(base_type, modifiers);
+  if (parse_integral_type(name, int_type))
     {
-      // So this is an integral type.  Let's set its name into a
-      // canonical form, so that "short unsigned" and "unsigned short"
-      // both end-up having the same name, which would be "unsigned
-      // short int".
-      integral_type int_type(base_type, modifiers);
       // Convert the integral_type into its canonical string
       // representation.
       string integral_type_name = int_type;