From: Petr Machata Date: Wed, 15 Sep 2010 18:13:43 +0000 (+0200) Subject: dwarflint: Extract checkrule into module of its own X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=77fa9aeeb5cfa975f2f1bb9e6c338187839f458e;p=thirdparty%2Felfutils.git dwarflint: Extract checkrule into module of its own --- diff --git a/dwarflint/Makefile.am b/dwarflint/Makefile.am index faaedb629..c18c828f1 100644 --- a/dwarflint/Makefile.am +++ b/dwarflint/Makefile.am @@ -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 \ diff --git a/dwarflint/check_duplicate_DW_tag_variable.cc b/dwarflint/check_duplicate_DW_tag_variable.cc index 67f6a2942..1a7d027d9 100644 --- a/dwarflint/check_duplicate_DW_tag_variable.cc +++ b/dwarflint/check_duplicate_DW_tag_variable.cc @@ -23,12 +23,7 @@ Network licensing program, please visit www.openinventionnetwork.com . */ -#ifdef HAVE_CONFIG_H -# include -#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 index 000000000..44e7a3704 --- /dev/null +++ b/dwarflint/checkrule.cc @@ -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 + . */ + +#include "checkrule.hh" +#include "checkdescriptor.hh" +#include "dwarflint.hh" +#include + +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 index 000000000..1171f08b4 --- /dev/null +++ b/dwarflint/checkrule.hh @@ -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 + . */ + +#ifndef DWARFLINT_CHECKRULE_HH +#define DWARFLINT_CHECKRULE_HH + +#include +#include +#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 +{ +public: + bool should_check (checkstack const &stack) const; +}; + +#endif//DWARFLINT_CHECKRULE_HH diff --git a/dwarflint/dwarflint.cc b/dwarflint/dwarflint.cc index 9c21dbcc0..a6d68a043 100644 --- a/dwarflint/dwarflint.cc +++ b/dwarflint/dwarflint.cc @@ -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 * diff --git a/dwarflint/dwarflint.hh b/dwarflint/dwarflint.hh index 69baff91c..921967bd4 100644 --- a/dwarflint/dwarflint.hh +++ b/dwarflint/dwarflint.hh @@ -29,48 +29,25 @@ #include #include #include -#include #include #include "../libelf/libelf.h" #include "checks.ii" #include "checkdescriptor.ii" +#include "checkrule.hh" class checkstack : public std::vector {}; 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 -{ - friend class dwarflint; - bool should_check (checkstack const &stack) const; -}; - class dwarflint { typedef std::map 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 _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 index 000000000..e574a5ffa --- /dev/null +++ b/dwarflint/dwarflint.ii @@ -0,0 +1,2 @@ +class checkstack; +class dwarflint; diff --git a/dwarflint/main.cc b/dwarflint/main.cc index 61a080bef..d349892ef 100644 --- a/dwarflint/main.cc +++ b/dwarflint/main.cc @@ -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; }