Feature added: CppCheck class has now function addFile(string,string) which allows checking of unreal files, by giving just filename and file content as a
parameter.
This commit is contained in:
parent
4f4a2391e0
commit
69ba8ce7f9
30
cppcheck.cpp
30
cppcheck.cpp
|
@ -56,6 +56,12 @@ void CppCheck::addFile( const std::string &path )
|
||||||
_filenames.push_back( path );
|
_filenames.push_back( path );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CppCheck::addFile( const std::string &path, const std::string &content )
|
||||||
|
{
|
||||||
|
_filenames.push_back( path );
|
||||||
|
_fileContents[ path ] = content;
|
||||||
|
}
|
||||||
|
|
||||||
std::string CppCheck::parseFromArgs( int argc, char* argv[] )
|
std::string CppCheck::parseFromArgs( int argc, char* argv[] )
|
||||||
{
|
{
|
||||||
std::vector<std::string> pathnames;
|
std::vector<std::string> pathnames;
|
||||||
|
@ -128,6 +134,7 @@ std::string CppCheck::parseFromArgs( int argc, char* argv[] )
|
||||||
return oss.str();
|
return oss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check function usage if "--style" and "--all" was given.
|
||||||
if ( _settings._showAll && _settings._checkCodingStyle )
|
if ( _settings._showAll && _settings._checkCodingStyle )
|
||||||
_settings._checkFunctionUsage = true;
|
_settings._checkFunctionUsage = true;
|
||||||
|
|
||||||
|
@ -137,10 +144,6 @@ std::string CppCheck::parseFromArgs( int argc, char* argv[] )
|
||||||
void CppCheck::check()
|
void CppCheck::check()
|
||||||
{
|
{
|
||||||
std::sort( _filenames.begin(), _filenames.end() );
|
std::sort( _filenames.begin(), _filenames.end() );
|
||||||
|
|
||||||
// Check function usage if "--style" and "--all" was given.
|
|
||||||
|
|
||||||
|
|
||||||
for (unsigned int c = 0; c < _filenames.size(); c++)
|
for (unsigned int c = 0; c < _filenames.size(); c++)
|
||||||
{
|
{
|
||||||
_errout.str("");
|
_errout.str("");
|
||||||
|
@ -150,12 +153,25 @@ void CppCheck::check()
|
||||||
if ( _settings._errorsOnly == false )
|
if ( _settings._errorsOnly == false )
|
||||||
_errorLogger->reportOut( std::string( "Checking " ) + fname + std::string( "..." ) );
|
_errorLogger->reportOut( std::string( "Checking " ) + fname + std::string( "..." ) );
|
||||||
|
|
||||||
std::ifstream fin( fname.c_str() );
|
|
||||||
std::map<std::string, std::string> code;
|
|
||||||
Preprocessor preprocessor( this );
|
Preprocessor preprocessor( this );
|
||||||
preprocessor.preprocess(fin, code, fname);
|
std::map<std::string, std::string> code;
|
||||||
|
if( _fileContents.size() > 0 && _fileContents.find( _filenames[c] ) != _fileContents.end() )
|
||||||
|
{
|
||||||
|
// File content was given as a string
|
||||||
|
std::istringstream iss( _fileContents[ _filenames[c] ] );
|
||||||
|
preprocessor.preprocess(iss, code, fname);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Only file name was given, read the content from file
|
||||||
|
std::ifstream fin( fname.c_str() );
|
||||||
|
preprocessor.preprocess(fin, code, fname);
|
||||||
|
}
|
||||||
|
|
||||||
for ( std::map<std::string,std::string>::const_iterator it = code.begin(); it != code.end(); ++it )
|
for ( std::map<std::string,std::string>::const_iterator it = code.begin(); it != code.end(); ++it )
|
||||||
|
{
|
||||||
checkFile(it->second, _filenames[c].c_str());
|
checkFile(it->second, _filenames[c].c_str());
|
||||||
|
}
|
||||||
|
|
||||||
if ( _settings._errorsOnly == false && _errout.str().empty() )
|
if ( _settings._errorsOnly == false && _errout.str().empty() )
|
||||||
_errorLogger->reportOut( "No errors found" );
|
_errorLogger->reportOut( "No errors found" );
|
||||||
|
|
12
cppcheck.h
12
cppcheck.h
|
@ -23,6 +23,7 @@
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <map>
|
||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
#include "errorlogger.h"
|
#include "errorlogger.h"
|
||||||
#include "CheckFunctionUsage.h"
|
#include "CheckFunctionUsage.h"
|
||||||
|
@ -69,6 +70,15 @@ class CppCheck : public ErrorLogger
|
||||||
*/
|
*/
|
||||||
void addFile( const std::string &path );
|
void addFile( const std::string &path );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add new unreal file to be checked.
|
||||||
|
*
|
||||||
|
* @param path File name (used for error reporting).
|
||||||
|
* @param content If the file would be a real file, this should be
|
||||||
|
* the content of the file.
|
||||||
|
*/
|
||||||
|
void addFile( const std::string &path, const std::string &content );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse command line args and get settings and file lists
|
* Parse command line args and get settings and file lists
|
||||||
* from there.
|
* from there.
|
||||||
|
@ -104,6 +114,8 @@ class CppCheck : public ErrorLogger
|
||||||
std::ostringstream _errout;
|
std::ostringstream _errout;
|
||||||
Settings _settings;
|
Settings _settings;
|
||||||
std::vector<std::string> _filenames;
|
std::vector<std::string> _filenames;
|
||||||
|
/** Key is file name, and value is the content of the file */
|
||||||
|
std::map<std::string,std::string> _fileContents;
|
||||||
CheckFunctionUsage _checkFunctionUsage;
|
CheckFunctionUsage _checkFunctionUsage;
|
||||||
ErrorLogger *_errorLogger;
|
ErrorLogger *_errorLogger;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue