]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
dwarflint: Extract checkrule into module of its own
authorPetr Machata <pmachata@redhat.com>
Wed, 15 Sep 2010 18:13:43 +0000 (20:13 +0200)
committerPetr Machata <pmachata@redhat.com>
Wed, 15 Sep 2010 18:13:43 +0000 (20:13 +0200)
dwarflint/Makefile.am
dwarflint/check_duplicate_DW_tag_variable.cc
dwarflint/checkrule.cc [new file with mode: 0644]
dwarflint/checkrule.hh [new file with mode: 0644]
dwarflint/dwarflint.cc
dwarflint/dwarflint.hh
dwarflint/dwarflint.ii [new file with mode: 0644]
dwarflint/main.cc

index faaedb629be5f703585696523d0e58c5a0f1b368..c18c828f1bab55f9ead728e81cba7cc864248322 100644 (file)
@@ -40,11 +40,12 @@ bin_PROGRAMS = dwarflint
 dwarflint_SOURCES = \
        main.cc \
        checkdescriptor.cc checkdescriptor.hh checkdescriptor.ii \
-       dwarflint.cc dwarflint.hh misc.h \
+       checkrule.cc checkrule.hh \
+       dwarflint.cc dwarflint.hh dwarflint.ii misc.h \
        low.c low.h \
        expected-at.cc expected.hh \
        coverage.cc coverage.h \
-       readctx.c  readctx.h \
+       readctx.c readctx.h \
        pri.cc pri.hh \
        messages.cc messages.h \
        section_id.cc section_id.h \
index 67f6a2942c47bf439b571961ade83669645c552b..1a7d027d9c19dfb4f39ddd8db60d2fe9481cca1c 100644 (file)
    Network licensing program, please visit www.openinventionnetwork.com
    <http://www.openinventionnetwork.com>.  */
 
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-
 #include "highlevel_check.hh"
-#include "../src/dwarfstrings.h"
 #include "all-dies-it.hh"
 #include "pri.hh"
 #include "messages.h"
diff --git a/dwarflint/checkrule.cc b/dwarflint/checkrule.cc
new file mode 100644 (file)
index 0000000..44e7a37
--- /dev/null
@@ -0,0 +1,89 @@
+/*
+   Copyright (C) 2010 Red Hat, Inc.
+   This file is part of Red Hat elfutils.
+
+   Red Hat elfutils is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by the
+   Free Software Foundation; version 2 of the License.
+
+   Red Hat elfutils 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 Public License for more details.
+
+   You should have received a copy of the GNU General Public License along
+   with Red Hat elfutils; if not, write to the Free Software Foundation,
+   Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA.
+
+   Red Hat elfutils is an included package of the Open Invention Network.
+   An included package of the Open Invention Network is a package for which
+   Open Invention Network licensees cross-license their patents.  No patent
+   license is granted, either expressly or impliedly, by designation as an
+   included package.  Should you wish to participate in the Open Invention
+   Network licensing program, please visit www.openinventionnetwork.com
+   <http://www.openinventionnetwork.com>.  */
+
+#include "checkrule.hh"
+#include "checkdescriptor.hh"
+#include "dwarflint.hh"
+#include <cassert>
+
+checkrule::checkrule (std::string const &a_name, action_t an_action)
+  : _m_name (a_name)
+  , _m_action (an_action)
+{
+}
+
+namespace
+{
+  bool
+  rule_matches (std::string const &name,
+               checkdescriptor const &cd)
+  {
+    if (name == "@all")
+      return true;
+    if (name == "@none")
+      return false;
+    if (name == cd.name ())
+      return true;
+    return cd.in_group (name);
+  }
+}
+
+bool
+checkrules::should_check (checkstack const &stack) const
+{
+#if 0
+  std::cout << "---\nstack" << std::endl;
+  for (checkstack::const_iterator jt = stack.begin ();
+       jt != stack.end (); ++jt)
+    std::cout << (*jt)->name << std::flush << "  ";
+  std::cout << std::endl;
+#endif
+
+  // We always allow scheduling hidden checks.  Those are service
+  // routines that the user doesn't even see it the list of checks.
+  assert (!stack.empty ());
+  if (stack.back ()->hidden ())
+    return true;
+
+  bool should = false;
+  for (const_iterator it = begin (); it != end (); ++it)
+    {
+      std::string const &rule_name = it->name ();
+      bool nflag = it->action () == checkrule::request;
+      if (nflag == should)
+       continue;
+
+      for (checkstack::const_iterator jt = stack.begin ();
+          jt != stack.end (); ++jt)
+       if (rule_matches (rule_name, **jt))
+         {
+           //std::cout << " rule: " << rule_name << " " << nflag << std::endl;
+           should = nflag;
+           break;
+         }
+    }
+
+  return should;
+}
diff --git a/dwarflint/checkrule.hh b/dwarflint/checkrule.hh
new file mode 100644 (file)
index 0000000..1171f08
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+   Copyright (C) 2010 Red Hat, Inc.
+   This file is part of Red Hat elfutils.
+
+   Red Hat elfutils is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by the
+   Free Software Foundation; version 2 of the License.
+
+   Red Hat elfutils 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 Public License for more details.
+
+   You should have received a copy of the GNU General Public License along
+   with Red Hat elfutils; if not, write to the Free Software Foundation,
+   Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA.
+
+   Red Hat elfutils is an included package of the Open Invention Network.
+   An included package of the Open Invention Network is a package for which
+   Open Invention Network licensees cross-license their patents.  No patent
+   license is granted, either expressly or impliedly, by designation as an
+   included package.  Should you wish to participate in the Open Invention
+   Network licensing program, please visit www.openinventionnetwork.com
+   <http://www.openinventionnetwork.com>.  */
+
+#ifndef DWARFLINT_CHECKRULE_HH
+#define DWARFLINT_CHECKRULE_HH
+
+#include <vector>
+#include <string>
+#include "dwarflint.ii"
+
+struct checkrule
+{
+  enum action_t
+    {
+      forbid,
+      request,
+    };
+
+private:
+  std::string _m_name;
+  action_t _m_action;
+
+public:
+  checkrule (std::string const &name, action_t action);
+
+  std::string const &name () const { return _m_name; }
+  action_t action () const { return _m_action; }
+};
+
+class checkrules
+  : public std::vector<checkrule>
+{
+public:
+  bool should_check (checkstack const &stack) const;
+};
+
+#endif//DWARFLINT_CHECKRULE_HH
index 9c21dbcc0a3a7c730f702e2c86bbec65d1c94ab6..a6d68a043a1da888840192f81b85ad69492cd12b 100644 (file)
@@ -67,7 +67,7 @@ namespace
   }
 }
 
-dwarflint::dwarflint (char const *a_fname, check_rules const &rules)
+dwarflint::dwarflint (char const *a_fname, checkrules const &rules)
   : _m_fname (a_fname)
   , _m_fd (get_fd (_m_fname))
   , _m_rules (rules)
@@ -166,61 +166,6 @@ dwarflint::check_registrar::list_checks () const
       << std::endl;
 }
 
-namespace
-{
-  bool
-  rule_matches (std::string const &name,
-               checkdescriptor const &cd)
-  {
-    if (name == "@all")
-      return true;
-    if (name == "@none")
-      return false;
-    if (name == cd.name ())
-      return true;
-    return cd.in_group (name);
-  }
-}
-
-bool
-check_rules::should_check (checkstack const &stack) const
-{
-#if 0
-  std::cout << "---\nstack" << std::endl;
-  for (checkstack::const_iterator jt = stack.begin ();
-       jt != stack.end (); ++jt)
-    std::cout << (*jt)->name << std::flush << "  ";
-  std::cout << std::endl;
-#endif
-
-  // We always allow scheduling hidden checks.  Those are service
-  // routines that the user doesn't even see it the list of checks.
-  assert (!stack.empty ());
-  if (stack.back ()->hidden ())
-    return true;
-
-  bool should = false;
-  for (const_iterator it = begin (); it != end (); ++it)
-    {
-      std::string const &rule_name = it->name;
-      bool nflag = it->action == check_rule::request;
-      if (nflag == should)
-       continue;
-
-      for (checkstack::const_iterator jt = stack.begin ();
-          jt != stack.end (); ++jt)
-       if (rule_matches (rule_name, **jt))
-         {
-           //std::cout << " rule: " << rule_name << " " << nflag << std::endl;
-           should = nflag;
-           break;
-         }
-    }
-
-  return should;
-}
-
-
 void *const dwarflint::marker = (void *)-1;
 
 void *
index 69baff91c13e31c3817fa1618068f25bc3a27c6f..921967bd43e4dab3eaadd6e5caae032762b3fc12 100644 (file)
 #include <map>
 #include <vector>
 #include <stdexcept>
-#include <string>
 #include <iosfwd>
 
 #include "../libelf/libelf.h"
 #include "checks.ii"
 #include "checkdescriptor.ii"
+#include "checkrule.hh"
 
 class checkstack
   : public std::vector <checkdescriptor const *>
 {};
 std::ostream &operator << (std::ostream &o, checkstack const &stack);
 
-struct check_rule
-{
-  enum action_t
-    {
-      forbid,
-      request,
-    };
-
-  std::string name;
-  action_t action;
-
-  check_rule (std::string const &a_name, action_t an_action)
-    : name (a_name)
-    , action (an_action)
-  {}
-};
-class check_rules
-  : public std::vector<check_rule>
-{
-  friend class dwarflint;
-  bool should_check (checkstack const &stack) const;
-};
-
 class dwarflint
 {
   typedef std::map <void const *, class check_base *> check_map;
   check_map _m_checks;
   char const *_m_fname;
   int _m_fd;
-  check_rules const &_m_rules;
+  checkrules const &_m_rules;
 
   static void *const marker;
 
@@ -109,7 +86,7 @@ public:
     std::vector <item *> _m_items;
   };
 
-  dwarflint (char const *fname, check_rules const &rules);
+  dwarflint (char const *fname, checkrules const &rules);
   ~dwarflint ();
   int fd () { return _m_fd; }
   char const *fname () { return _m_fname; }
diff --git a/dwarflint/dwarflint.ii b/dwarflint/dwarflint.ii
new file mode 100644 (file)
index 0000000..e574a5f
--- /dev/null
@@ -0,0 +1,2 @@
+class checkstack;
+class dwarflint;
index 61a080bef574e7cf780044d91df780431ab9629c..d349892ef3a493103ee01dec4e2c94588e9911c5 100644 (file)
@@ -48,12 +48,12 @@ struct message_criteria error_criteria;
 struct check_option_t
   : public option_common
 {
-  struct initial_check_rules
-    : public check_rules
+  struct initial_checkrules
+    : public checkrules
   {
-    initial_check_rules () {
-      push_back (check_rule ("@all", check_rule::request));
-      push_back (check_rule ("@nodefault", check_rule::forbid));
+    initial_checkrules () {
+      push_back (checkrule ("@all", checkrule::request));
+      push_back (checkrule ("@nodefault", checkrule::forbid));
     }
   } rules;
 
@@ -106,9 +106,9 @@ struct check_option_t
            act = request;
          }
 
-       check_rule::action_t action
-         = act == request ? check_rule::request : check_rule::forbid;
-       rules.push_back (check_rule (item, action));
+       checkrule::action_t action
+         = act == request ? checkrule::request : checkrule::forbid;
+       rules.push_back (checkrule (item, action));
       }
     return 0;
   }