From 2b7338450cd98fba5b856d7431ab853602848b01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Thu, 11 Dec 2008 18:09:20 +0000 Subject: [PATCH] preprocessing : Skip special characters. Refactoring. --- cppcheck.cpp | 2 +- preprocessor.cpp | 12 +++--------- preprocessor.h | 7 +++---- testpreprocessor.cpp | 28 ++++++++++++++-------------- 4 files changed, 21 insertions(+), 28 deletions(-) diff --git a/cppcheck.cpp b/cppcheck.cpp index 8b7f28532..cd209722c 100644 --- a/cppcheck.cpp +++ b/cppcheck.cpp @@ -162,7 +162,7 @@ void CppCheck::check() if ( _settings._errorsOnly == false ) _errorLogger->reportOut( std::string( "Checking " ) + fname + std::string( "..." ) ); - Preprocessor preprocessor( this ); + Preprocessor preprocessor; std::map code; if( _fileContents.size() > 0 && _fileContents.find( _filenames[c] ) != _fileContents.end() ) { diff --git a/preprocessor.cpp b/preprocessor.cpp index 8bfe00c7c..a9b594c32 100644 --- a/preprocessor.cpp +++ b/preprocessor.cpp @@ -28,9 +28,9 @@ #endif -Preprocessor::Preprocessor( ErrorLogger *errorLogger ) +Preprocessor::Preprocessor() { - _errorLogger = errorLogger; + } /** Just read the code into a string. Perform simple cleanup of the code */ @@ -46,13 +46,7 @@ std::string Preprocessor::read(std::istream &istr, const std::string &filename) for (char ch = (char)istr.get(); istr.good(); ch = (char)istr.get()) { if ( ch < 0 ) - { - // Bad content.. - std::ostringstream oss; - oss << "[" << filename << ":" << lineno << "] Bad character found: " << int((unsigned char)ch) << std::endl; - _errorLogger->reportErr( oss.str() ); - return ""; - } + continue; if ( ch == '\n' ) ++lineno; diff --git a/preprocessor.h b/preprocessor.h index 078e2dee1..e5dcd50c5 100644 --- a/preprocessor.h +++ b/preprocessor.h @@ -25,12 +25,13 @@ #include #include #include -#include "errorlogger.h" + class Preprocessor { public: - Preprocessor( ErrorLogger *errorLogger ); + Preprocessor(); + void preprocess(std::istream &istr, std::map &result, const std::string &filename); /** Just read the code into a string. Perform simple cleanup of the code */ @@ -50,8 +51,6 @@ private: std::string getdef(std::string line, bool def); bool match_cfg_def( std::string cfg, const std::string &def ); - - ErrorLogger *_errorLogger; }; //--------------------------------------------------------------------------- diff --git a/testpreprocessor.cpp b/testpreprocessor.cpp index 8903e99e9..dc58c7b52 100644 --- a/testpreprocessor.cpp +++ b/testpreprocessor.cpp @@ -68,7 +68,7 @@ private: { const char code[] = " \t a //\n" " #aa\t /* remove this */\tb \r\n"; - Preprocessor p(NULL); + Preprocessor p; std::istringstream istr(code); std::string codestr( p.read(istr,"") ); ASSERT_EQUALS( "a \n#aa b \n", codestr ); @@ -154,7 +154,7 @@ private: // Preprocess => actual result.. std::istringstream istr(filedata); std::map actual; - Preprocessor preprocessor( this ); + Preprocessor preprocessor; preprocessor.preprocess( istr, actual, "" ); // Compare results.. @@ -178,7 +178,7 @@ private: // Preprocess => actual result.. std::istringstream istr(filedata); std::map actual; - Preprocessor preprocessor( this ); + Preprocessor preprocessor; preprocessor.preprocess( istr, actual, "" ); // Compare results.. @@ -201,7 +201,7 @@ private: // Preprocess => actual result.. std::istringstream istr(filedata); std::map actual; - Preprocessor preprocessor( this ); + Preprocessor preprocessor; preprocessor.preprocess( istr, actual, "" ); // Compare results.. @@ -227,7 +227,7 @@ private: // Preprocess => actual result.. std::istringstream istr(filedata); std::map actual; - Preprocessor preprocessor( this ); + Preprocessor preprocessor; preprocessor.preprocess( istr, actual, "" ); // Compare results.. @@ -251,7 +251,7 @@ private: // Preprocess => actual result.. std::istringstream istr(filedata); std::map actual; - Preprocessor preprocessor( this ); + Preprocessor preprocessor; preprocessor.preprocess( istr, actual, "" ); // Compare results.. @@ -278,7 +278,7 @@ private: // Preprocess => actual result.. std::istringstream istr(filedata); std::map actual; - Preprocessor preprocessor( this ); + Preprocessor preprocessor; preprocessor.preprocess( istr, actual, "" ); // Compare results.. @@ -301,7 +301,7 @@ private: // Preprocess => actual result.. std::istringstream istr(filedata); std::map actual; - Preprocessor preprocessor( this ); + Preprocessor preprocessor; preprocessor.preprocess( istr, actual, "" ); // Compare results.. @@ -324,7 +324,7 @@ private: // Preprocess => actual result.. std::istringstream istr(filedata); std::map actual; - Preprocessor preprocessor( this ); + Preprocessor preprocessor; preprocessor.preprocess( istr, actual, "" ); // Compare results.. @@ -344,7 +344,7 @@ private: // Preprocess => actual result.. std::istringstream istr(filedata); std::map actual; - Preprocessor preprocessor( this ); + Preprocessor preprocessor; preprocessor.preprocess( istr, actual, "" ); // Compare results.. @@ -369,7 +369,7 @@ private: // Preprocess => actual result.. std::istringstream istr(filedata); std::map actual; - Preprocessor preprocessor( this ); + Preprocessor preprocessor; preprocessor.preprocess( istr, actual, "" ); // Compare results.. @@ -389,7 +389,7 @@ private: // Preprocess => actual result.. std::istringstream istr(filedata); std::map actual; - Preprocessor preprocessor( this ); + Preprocessor preprocessor; preprocessor.preprocess( istr, actual, "" ); // Compare results.. @@ -414,7 +414,7 @@ private: // Preprocess => actual result.. std::istringstream istr(filedata); std::map actual; - Preprocessor preprocessor( this ); + Preprocessor preprocessor; preprocessor.preprocess( istr, actual, "" ); // Compare results.. @@ -434,7 +434,7 @@ private: // Preprocess => actual result.. std::istringstream istr(filedata); std::map actual; - Preprocessor preprocessor( this ); + Preprocessor preprocessor; preprocessor.preprocess( istr, actual, "" ); // Compare results..