|
|
Choosing A Webhost: |
CVS: boost/tools/inspect minmax_check.cpp,1.3,1.4: msg#00604lib.boost.cvs
Update of /cvsroot/boost/boost/tools/inspect In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv522 Modified Files: minmax_check.cpp Log Message: Inspect Tool Update: * tightened min/max guidelines checks (conservatively avoid false positives) * removed 64-bit portability warnings with VC8 Index: minmax_check.cpp =================================================================== RCS file: /cvsroot/boost/boost/tools/inspect/minmax_check.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- minmax_check.cpp 18 Jul 2006 03:55:38 -0000 1.3 +++ minmax_check.cpp 29 Jul 2006 15:19:03 -0000 1.4 @@ -1,10 +1,15 @@ -// minmax_check implementation -----------------------------------------------// +// minmax_check implementation --------------------------------------------// -// Copyright Beman Dawes 2002. +// Copyright Beman Dawes 2002. +// Copyright Gennaro Prota 2006. +// // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) + +#include <algorithm> + #include "minmax_check.hpp" #include <boost/regex.hpp> #include <boost/lexical_cast.hpp> @@ -12,9 +17,16 @@ namespace { boost::regex minmax_regex( - "\\b(min|max)\\b" // match min or max, whole word - "\\s*\\(", // followed by 0 or more spaces and an opening paren - boost::regex::normal); + "(" + "^\\s*#\\s*undef\\s*" // # undef + "\\b(min|max)\\b" // followed by min or max, whole word + ")" + "|" // or + "(" + "\\b(min|max)\\b" // min or max, whole word + "\\s*\\(" // followed by 0 or more spaces and an opening paren + ")" + , boost::regex::normal); } // unnamed namespace @@ -23,7 +35,7 @@ namespace inspect { - // minmax_check constructor --------------------------------------------------// + // minmax_check constructor -------------------------------------------// minmax_check::minmax_check() : m_errors(0) @@ -39,7 +51,7 @@ register_signature( ".ipp" ); } - // inspect ( C++ source files ) ----------------------------------------------// + // inspect ( C++ source files ) ---------------------------------------// void minmax_check::inspect( const string & library_name, @@ -50,12 +62,56 @@ boost::sregex_iterator cur(contents.begin(), contents.end(), minmax_regex), end; - for( ; cur != end; ++cur, ++m_errors ) + for( ; cur != end; ++cur /*, ++m_errors*/ ) { - std::string linenbr = boost::lexical_cast<string>( - std::count( contents.begin(), (*cur)[0].first, '\n' ) + 1); + // ~ experimental: try to filter out apparent + // ~ min/max guideline violations in one-line comments + // + // This is just a quick hack to avoid impacting the + // overall application design. To be on the safe side, + // we only aim at one-line comments; the comment must be + // the only non-blank content of the line, and no quote + // character or "*/" shall appear within it. Otherwise we + // give up filtering, at the cost of possible false positives. + // + const string one_line_comment_line ( "^\\s*//" ); + + string::const_iterator it = contents.begin(); + string::const_iterator match_it = (*cur)[0].first; + + string::const_iterator line_start = it; + + string::size_type line_number = 1; + for ( ; it != match_it; ++it) { + if (string::traits_type::eq(*it, '\n')) { + ++line_number; + line_start = it + 1; // could be end() + } + } + + string::const_iterator past_line_content = + std::find(it, contents.end(), '\n'); + + // one-line comment spanning the whole line + // with no quotes and no "*/" pair + // + match_results<string::const_iterator> m; + const string whole_line( line_start, past_line_content ); + const bool filter_out = + regex_search( line_start, past_line_content + , m, boost::regex(one_line_comment_line) ) + && string::npos == whole_line.find('\"') + && string::npos == whole_line.find("*/") + ; + + if (!filter_out) { + + ++m_errors; + error( library_name, full_path, string(name()) + + " violation of Boost min/max guidelines on line " + + boost::lexical_cast<string>( line_number ) ); + } - error( library_name, full_path, string(name()) + " violation of Boost min/max guidelines on line " + linenbr ); } } ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys -- and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
|
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | CVS: boost/tools/inspect inspect.cpp,1.20,1.21, Gennaro Prota |
|---|---|
| Next by Date: | CVS: boost/tools/inspect unnamed_namespace_check.cpp, 1.1, 1.2, Gennaro Prota |
| Previous by Thread: | CVS: boost/tools/inspect inspect.cpp,1.20,1.21, Gennaro Prota |
| Next by Thread: | CVS: boost/tools/inspect unnamed_namespace_check.cpp, 1.1, 1.2, Gennaro Prota |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
Free MagazinesCisco NewsReceive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business. subscribe Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field. subscribe The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business. subscribe Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company. subscribe Total Telecom Total Telecom is "The Economist of the communications industry". subscribe |