Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r57820 - in trunk/tools/inspect: . build
From: marshall_at_[hidden]
Date: 2009-11-20 13:14:59


Author: marshall
Date: 2009-11-20 13:14:58 EST (Fri, 20 Nov 2009)
New Revision: 57820
URL: http://svn.boost.org/trac/boost/changeset/57820

Log:
Added test for Apple macros
Added:
   trunk/tools/inspect/apple_macro_check.cpp (contents, props changed)
   trunk/tools/inspect/apple_macro_check.hpp (contents, props changed)
Text files modified:
   trunk/tools/inspect/build/Jamfile.v2 | 2 +-
   trunk/tools/inspect/inspect.cpp | 8 ++++++++
   2 files changed, 9 insertions(+), 1 deletions(-)

Added: trunk/tools/inspect/apple_macro_check.cpp
==============================================================================
--- (empty file)
+++ trunk/tools/inspect/apple_macro_check.cpp 2009-11-20 13:14:58 EST (Fri, 20 Nov 2009)
@@ -0,0 +1,92 @@
+// apple_macro_check implementation ------------------------------------------------//
+
+// Copyright Marshall Clow 2007.
+// Based on the tab-check checker by Beman Dawes
+//
+// 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 "apple_macro_check.hpp"
+#include <functional>
+#include "boost/regex.hpp"
+#include "boost/lexical_cast.hpp"
+
+namespace
+{
+ boost::regex apple_macro_regex(
+ "("
+ "^\\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(check|verify|require|check_error)\\b" // min or max, whole word
+ "\\s*\\(" // followed by 0 or more spaces and an opening paren
+ ")"
+ , boost::regex::normal);
+
+} // unnamed namespace
+
+
+namespace boost
+{
+ namespace inspect
+ {
+ apple_macro_check::apple_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 apple_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:" "naapple_macros" ) != string::npos) return;
+
+ boost::sregex_iterator cur(contents.begin(), contents.end(), apple_macro_regex), end;
+
+ 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()
+ }
+ }
+
+ ++m_files_with_errors;
+ error( library_name, full_path, string(name())
+ + " violation of Boost apple-macro guidelines on line "
+ + boost::lexical_cast<string>( line_number ) );
+ }
+ }
+ }
+ } // namespace inspect
+} // namespace boost
+
+

Added: trunk/tools/inspect/apple_macro_check.hpp
==============================================================================
--- (empty file)
+++ trunk/tools/inspect/apple_macro_check.hpp 2009-11-20 13:14:58 EST (Fri, 20 Nov 2009)
@@ -0,0 +1,39 @@
+// apple_macro_check header --------------------------------------------------------//
+
+// Copyright Marshall Clow 2007.
+// Based on the tab-check checker by Beman Dawes
+// 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_APPLE_MACRO_CHECK_HPP
+#define BOOST_APPLE_MACRO_CHECK_HPP
+
+#include "inspector.hpp"
+
+
+namespace boost
+{
+ namespace inspect
+ {
+ class apple_macro_check : public inspector
+ {
+ long m_files_with_errors;
+ public:
+
+ apple_macro_check();
+ virtual const char * name() const { return "*APPLE-MACROS*"; }
+ virtual const char * desc() const { return "calls to Apple's debugging macros in file"; }
+
+ virtual void inspect(
+ const std::string & library_name,
+ const path & full_path,
+ const std::string & contents );
+
+ virtual ~apple_macro_check()
+ { std::cout << " " << m_files_with_errors << " files with apple macros" << line_break(); }
+ };
+ }
+}
+
+#endif // BOOST_APPLE_MACRO_CHECK_HPP

Modified: trunk/tools/inspect/build/Jamfile.v2
==============================================================================
--- trunk/tools/inspect/build/Jamfile.v2 (original)
+++ trunk/tools/inspect/build/Jamfile.v2 2009-11-20 13:14:58 EST (Fri, 20 Nov 2009)
@@ -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
+ copyright_check.cpp minmax_check.cpp apple_macro_check.cpp
     /boost//filesystem/<link>static
     /boost//regex/<link>static
     :

Modified: trunk/tools/inspect/inspect.cpp
==============================================================================
--- trunk/tools/inspect/inspect.cpp (original)
+++ trunk/tools/inspect/inspect.cpp 2009-11-20 13:14:58 EST (Fri, 20 Nov 2009)
@@ -38,6 +38,7 @@
 #include "path_name_check.hpp"
 #include "tab_check.hpp"
 #include "ascii_check.hpp"
+#include "apple_macro_check.hpp"
 #include "minmax_check.hpp"
 #include "unnamed_namespace_check.hpp"
 
@@ -529,6 +530,7 @@
          " -path_name\n"
          " -tab\n"
          " -ascii\n"
+ " -apple_macro\n"
          " -minmax\n"
          " -unnamed\n"
          " default is all checks on; otherwise options specify desired checks"
@@ -699,6 +701,7 @@
   bool path_name_ck = true;
   bool tab_ck = true;
   bool ascii_ck = true;
+ bool apple_ok = true;
   bool minmax_ck = true;
   bool unnamed_ck = true;
   bool cvs = false;
@@ -731,6 +734,7 @@
     path_name_ck = false;
     tab_ck = false;
     ascii_ck = false;
+ apple_ok = false;
     minmax_ck = false;
     unnamed_ck = false;
   }
@@ -754,6 +758,8 @@
       tab_ck = true;
     else if ( std::strcmp( argv[1], "-ascii" ) == 0 )
       ascii_ck = true;
+ else if ( std::strcmp( argv[1], "-apple_macro" ) == 0 )
+ apple_ok = true;
     else if ( std::strcmp( argv[1], "-minmax" ) == 0 )
         minmax_ck = true;
     else if ( std::strcmp( argv[1], "-unnamed" ) == 0 )
@@ -797,6 +803,8 @@
       inspectors.push_back( inspector_element( new boost::inspect::tab_check ) );
   if ( ascii_ck )
       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 ( 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