forked from mirror/boost
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
inspect tool: check for C-style assert macro instead of BOOST_ASSERT
git-svn-id: http://svn.boost.org/svn/boost/trunk@66502 b8fc166d-592f-0410-95f2-cb63ce0dd405
- Loading branch information
eric_niebler
committed
Nov 11, 2010
1 parent
2dda859
commit be79ba8
Showing
6 changed files
with
168 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters