2 pass checking: broke out Cppcheck::analyseFile. To be used for tests

This commit is contained in:
Daniel Marjamäki 2010-05-21 21:06:11 +02:00
parent 75c9355e9a
commit 8f76aea6ed
2 changed files with 38 additions and 28 deletions

View File

@ -639,34 +639,8 @@ unsigned int CppCheck::check()
reportOut("Analysing " + fname + "..");
// Preprocess file..
Preprocessor preprocessor(&_settings, this);
std::list<std::string> configurations;
std::string filedata = "";
std::ifstream fin(fname.c_str());
preprocessor.preprocess(fin, filedata, configurations, fname, _settings._includePaths);
const std::string code = Preprocessor::getcode(filedata, "", fname, &_errorLogger);
// Tokenize..
Tokenizer tokenizer(&_settings, this);
std::istringstream istr(code);
tokenizer.tokenize(istr, fname.c_str(), "");
tokenizer.simplifyTokenList();
// Analyse the tokens..
std::set<std::string> data;
for (std::list<Check *>::const_iterator it = Check::instances().begin(); it != Check::instances().end(); ++it)
{
(*it)->analyse(tokenizer.tokens(), data);
}
// Save analysis results..
// TODO: This loop should be protected by a mutex or something like that
// The saveAnalysisData must _not_ be called from many threads at the same time.
for (std::list<Check *>::const_iterator it = Check::instances().begin(); it != Check::instances().end(); ++it)
{
(*it)->saveAnalysisData(data);
}
std::ifstream f(fname.c_str());
analyseFile(f, fname);
}
}
@ -761,6 +735,36 @@ unsigned int CppCheck::check()
return exitcode;
}
void CppCheck::analyseFile(std::istream &fin, const std::string &filename)
{
// Preprocess file..
Preprocessor preprocessor(&_settings, this);
std::list<std::string> configurations;
std::string filedata = "";
preprocessor.preprocess(fin, filedata, configurations, filename, _settings._includePaths);
const std::string code = Preprocessor::getcode(filedata, "", filename, &_errorLogger);
// Tokenize..
Tokenizer tokenizer(&_settings, this);
std::istringstream istr(code);
tokenizer.tokenize(istr, filename.c_str(), "");
tokenizer.simplifyTokenList();
// Analyse the tokens..
std::set<std::string> data;
for (std::list<Check *>::const_iterator it = Check::instances().begin(); it != Check::instances().end(); ++it)
{
(*it)->analyse(tokenizer.tokens(), data);
}
// Save analysis results..
// TODO: This loop should be protected by a mutex or something like that
// The saveAnalysisData must _not_ be called from many threads at the same time.
for (std::list<Check *>::const_iterator it = Check::instances().begin(); it != Check::instances().end(); ++it)
{
(*it)->saveAnalysisData(data);
}
}
//---------------------------------------------------------------------------
// CppCheck - A function that checks a specified file

View File

@ -130,7 +130,13 @@ public:
*/
void getErrorMessages();
/**
* @brief Analyse file - It's public so unit tests can be written
*/
void analyseFile(std::istream &f, const std::string &filename);
private:
/** @brief Check file */
void checkFile(const std::string &code, const char FileName[]);
/**