Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r57815 - branches/release/tools/inspect
From: daniel_james_at_[hidden]
Date: 2009-11-20 06:08:13


Author: danieljames
Date: 2009-11-20 06:08:13 EST (Fri, 20 Nov 2009)
New Revision: 57815
URL: http://svn.boost.org/trac/boost/changeset/57815

Log:
Merge [53144] Filter out comments and string literals in the min/max check.
Properties modified:
   branches/release/tools/inspect/ (props changed)
Text files modified:
   branches/release/tools/inspect/minmax_check.cpp | 72 +++++++++++++++-------------------------
   1 files changed, 27 insertions(+), 45 deletions(-)

Modified: branches/release/tools/inspect/minmax_check.cpp
==============================================================================
--- branches/release/tools/inspect/minmax_check.cpp (original)
+++ branches/release/tools/inspect/minmax_check.cpp 2009-11-20 06:08:13 EST (Fri, 20 Nov 2009)
@@ -21,6 +21,14 @@
     "^\\s*#\\s*undef\\s*" // # undef
     "\\b(min|max)\\b" // followed by min or max, whole word
     ")"
+ "|" // or (ignored)
+ "("
+ "//[^\\n]*" // single line comments (//)
+ "|"
+ "/\\*.*?\\*/" // multi line comments (/**/)
+ "|"
+ "\"(?:\\\\\\\\|\\\\\"|[^\"])*\"" // string literals
+ ")"
     "|" // or
     "("
     "\\b(min|max)\\b" // min or max, whole word
@@ -64,52 +72,26 @@
 
       for( ; cur != end; ++cur /*, ++m_errors*/ )
       {
- // ~ 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 ) );
+ if(!(*cur)[3].matched)
+ {
+ 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()
+ }
+ }
+
+ ++m_errors;
+ error( library_name, full_path, string(name())
+ + " violation of Boost min/max guidelines on line "
+ + boost::lexical_cast<string>( line_number ) );
         }
 
       }


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk