Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r66502 - in trunk/tools/inspect: . build build/msvc doc
From: eric_at_[hidden]
Date: 2010-11-11 17:49:51


Author: eric_niebler
Date: 2010-11-11 17:49:46 EST (Thu, 11 Nov 2010)
New Revision: 66502
URL: http://svn.boost.org/trac/boost/changeset/66502

Log:
inspect tool: check for C-style assert macro instead of BOOST_ASSERT
Added:
   trunk/tools/inspect/assert_macro_check.cpp (contents, props changed)
   trunk/tools/inspect/assert_macro_check.hpp (contents, props changed)
Text files modified:
   trunk/tools/inspect/build/Jamfile.v2 | 2 +-
   trunk/tools/inspect/build/msvc/boost_inspect.vcproj | 4 ++++
   trunk/tools/inspect/doc/inspect.qbk | 20 ++++++++++++++++++--
   trunk/tools/inspect/inspect.cpp | 8 ++++++++
   4 files changed, 31 insertions(+), 3 deletions(-)

Added: trunk/tools/inspect/assert_macro_check.cpp
==============================================================================
--- (empty file)
+++ trunk/tools/inspect/assert_macro_check.cpp 2010-11-11 17:49:46 EST (Thu, 11 Nov 2010)
@@ -0,0 +1,98 @@
+// assert_macro_check implementation ------------------------------------------------//
+
+// Copyright Eric Niebler 2010.
+// Based on the assert_macro_check checker by Marshall Clow
+//
+// 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 "assert_macro_check.hpp"
+#include <functional>
+#include "boost/regex.hpp"
+#include "boost/lexical_cast.hpp"
+#include "boost/filesystem/operations.hpp"
+
+namespace fs = boost::filesystem;
+
+namespace
+{
+ boost::regex assert_macro_regex(
+ "("
+ "^\\s*#\\s*undef\\s*" // # undef
+ "\\b(assert)\\b" // followed by assert macro, whole word
+ ")"
+ "|" // or (ignored)
+ "("
+ "//[^\\n]*" // single line comments (//)
+ "|"
+ "/\\*.*?\\*/" // multi line comments (/**/)
+ "|"
+ "\"(?:\\\\\\\\|\\\\\"|[^\"])*\"" // string literals
+ ")"
+ "|" // or
+ "("
+ "\\b(assert)\\b" // assert macro, whole word
+ "\\s*\\(" // followed by 0 or more spaces and an opening paren
+ ")"
+ , boost::regex::normal);
+
+} // unnamed namespace
+
+
+namespace boost
+{
+ namespace inspect
+ {
+ assert_macro_check::assert_macro_check() : m_files_with_errors(0)
+ {
+ register_signature( ".c" );
+ register_signature( ".cpp" );
+ register_signature( ".cxx" );
+ register_signature( ".h" );
+ register_signature( ".hpp" );
+ register_signature( ".hxx" );
+ register_signature( ".ipp" );
+ }
+
+ void assert_macro_check::inspect(
+ const string & library_name,
+ const path & full_path, // example: c:/foo/boost/filesystem/path.hpp
+ const string & contents ) // contents of file to be inspected
+ {
+ if (contents.find( "boostinspect:" "naassert_macro" ) != string::npos) return;
+
+ boost::sregex_iterator cur(contents.begin(), contents.end(), assert_macro_regex), end;
+
+ long errors = 0;
+
+ for( ; cur != end; ++cur /*, ++m_files_with_errors*/ )
+ {
+
+ 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()
+ }
+ }
+
+ ++errors;
+ error( library_name, full_path, "C-style assert macro", line_number );
+ }
+ }
+ if(errors > 0) {
+ ++m_files_with_errors;
+ }
+ }
+ } // namespace inspect
+} // namespace boost
+
+

Added: trunk/tools/inspect/assert_macro_check.hpp
==============================================================================
--- (empty file)
+++ trunk/tools/inspect/assert_macro_check.hpp 2010-11-11 17:49:46 EST (Thu, 11 Nov 2010)
@@ -0,0 +1,39 @@
+// assert_macro_check header --------------------------------------------------------//
+
+// Copyright Eric Niebler 2010.
+// Based on the apple_macro_check checker by Marshall Clow
+// 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)
+
+#ifndef BOOST_ASSERT_MACRO_CHECK_HPP
+#define BOOST_ASSERT_MACRO_CHECK_HPP
+
+#include "inspector.hpp"
+
+
+namespace boost
+{
+ namespace inspect
+ {
+ class assert_macro_check : public inspector
+ {
+ long m_files_with_errors;
+ public:
+
+ assert_macro_check();
+ virtual const char * name() const { return "*ASSERT-MACROS*"; }
+ virtual const char * desc() const { return "presence of C-style assert macro in file (use BOOST_ASSERT instead)"; }
+
+ virtual void inspect(
+ const std::string & library_name,
+ const path & full_path,
+ const std::string & contents );
+
+ virtual ~assert_macro_check()
+ { std::cout << " " << m_files_with_errors << " files with a C-style assert macro" << line_break(); }
+ };
+ }
+}
+
+#endif // BOOST_ASSERT_MACRO_CHECK_HPP

Modified: trunk/tools/inspect/build/Jamfile.v2
==============================================================================
--- trunk/tools/inspect/build/Jamfile.v2 (original)
+++ trunk/tools/inspect/build/Jamfile.v2 2010-11-11 17:49:46 EST (Thu, 11 Nov 2010)
@@ -15,7 +15,7 @@
 exe inspect
     :
     inspect.cpp license_check.cpp link_check.cpp path_name_check.cpp tab_check.cpp crlf_check.cpp end_check.cpp unnamed_namespace_check.cpp ascii_check.cpp
- copyright_check.cpp minmax_check.cpp apple_macro_check.cpp
+ copyright_check.cpp minmax_check.cpp apple_macro_check.cpp assert_macro_check.cpp
     /boost//filesystem/<link>static
     /boost//regex/<link>static
     :

Modified: trunk/tools/inspect/build/msvc/boost_inspect.vcproj
==============================================================================
--- trunk/tools/inspect/build/msvc/boost_inspect.vcproj (original)
+++ trunk/tools/inspect/build/msvc/boost_inspect.vcproj 2010-11-11 17:49:46 EST (Thu, 11 Nov 2010)
@@ -185,6 +185,10 @@
>
                         </File>
                         <File
+ RelativePath="..\..\assert_macro_check.cpp"
+ >
+ </File>
+ <File
                                 RelativePath="..\..\copyright_check.cpp"
>
                         </File>

Modified: trunk/tools/inspect/doc/inspect.qbk
==============================================================================
--- trunk/tools/inspect/doc/inspect.qbk (original)
+++ trunk/tools/inspect/doc/inspect.qbk 2010-11-11 17:49:46 EST (Thu, 11 Nov 2010)
@@ -54,9 +54,13 @@
   -license
   -copyright
   -crlf
+ -end
   -link
- -long_name
+ -path_name
   -tab
+ -ascii
+ -apple_macro
+ -assert_macro
   -minmax
   -unnamed
  default is all checks on; otherwise options specify desired checks
@@ -86,15 +90,27 @@
   [ [[^-crlf]]
     [Checks that files use consistent EOL chanracters.] ]
 
+ [ [[^-end]]
+ [Checks that files end with a newline character.] ]
+
   [ [[^-link]]
     [Checks the validity of URIs in HTML files.] ]
 
- [ [[^-long_name]]
+ [ [[^-path_name]]
     [Checks for long names, and a variety of other file name problems that inhibit portability of files.] ]
 
   [ [[^-tab]]
     [Checks for files with tab characters.] ]
 
+ [ [[^-ascii]]
+ [Checks for files with non-ASCII characters.] ]
+
+ [ [[^-apple_macro]]
+ [Checks for conflicts with to Apple's unfortunately named debugging macros.] ]
+
+ [ [[^-assert_macro]]
+ [Checks for presence of C-style assert macros (instead of BOOST_ASSERT).] ]
+
   [ [[^-minmax]]
     [Checks for violations of the Boost min/max quidelines.] ]
 

Modified: trunk/tools/inspect/inspect.cpp
==============================================================================
--- trunk/tools/inspect/inspect.cpp (original)
+++ trunk/tools/inspect/inspect.cpp 2010-11-11 17:49:46 EST (Thu, 11 Nov 2010)
@@ -40,6 +40,7 @@
 #include "tab_check.hpp"
 #include "ascii_check.hpp"
 #include "apple_macro_check.hpp"
+#include "assert_macro_check.hpp"
 #include "minmax_check.hpp"
 #include "unnamed_namespace_check.hpp"
 
@@ -547,6 +548,7 @@
          " -tab\n"
          " -ascii\n"
          " -apple_macro\n"
+ " -assert_macro\n"
          " -minmax\n"
          " -unnamed\n"
          " default is all checks on; otherwise options specify desired checks"
@@ -719,6 +721,7 @@
   bool tab_ck = true;
   bool ascii_ck = true;
   bool apple_ok = true;
+ bool assert_ok = true;
   bool minmax_ck = true;
   bool unnamed_ck = true;
   bool cvs = false;
@@ -752,6 +755,7 @@
     tab_ck = false;
     ascii_ck = false;
     apple_ok = false;
+ assert_ok = false;
     minmax_ck = false;
     unnamed_ck = false;
   }
@@ -777,6 +781,8 @@
       ascii_ck = true;
     else if ( std::strcmp( argv[1], "-apple_macro" ) == 0 )
       apple_ok = true;
+ else if ( std::strcmp( argv[1], "-assert_macro" ) == 0 )
+ assert_ok = true;
     else if ( std::strcmp( argv[1], "-minmax" ) == 0 )
         minmax_ck = true;
     else if ( std::strcmp( argv[1], "-unnamed" ) == 0 )
@@ -822,6 +828,8 @@
       inspectors.push_back( inspector_element( new boost::inspect::ascii_check ) );
   if ( apple_ok )
       inspectors.push_back( inspector_element( new boost::inspect::apple_macro_check ) );
+ if ( assert_ok )
+ inspectors.push_back( inspector_element( new boost::inspect::assert_macro_check ) );
   if ( minmax_ck )
       inspectors.push_back( inspector_element( new boost::inspect::minmax_check ) );
   if ( unnamed_ck )


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