preprocessing : Skip special characters. Refactoring.

This commit is contained in:
Daniel Marjamäki 2008-12-11 18:09:20 +00:00
parent bcf393292e
commit 2b7338450c
4 changed files with 21 additions and 28 deletions

View File

@ -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<std::string, std::string> code;
if( _fileContents.size() > 0 && _fileContents.find( _filenames[c] ) != _fileContents.end() )
{

View File

@ -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;

View File

@ -25,12 +25,13 @@
#include <istream>
#include <string>
#include <list>
#include "errorlogger.h"
class Preprocessor
{
public:
Preprocessor( ErrorLogger *errorLogger );
Preprocessor();
void preprocess(std::istream &istr, std::map<std::string, std::string> &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;
};
//---------------------------------------------------------------------------

View File

@ -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<std::string, std::string> 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<std::string, std::string> 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<std::string, std::string> 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<std::string, std::string> 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<std::string, std::string> 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<std::string, std::string> 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<std::string, std::string> 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<std::string, std::string> 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<std::string, std::string> 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<std::string, std::string> 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<std::string, std::string> 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<std::string, std::string> 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<std::string, std::string> actual;
Preprocessor preprocessor( this );
Preprocessor preprocessor;
preprocessor.preprocess( istr, actual, "" );
// Compare results..