parse files with `simplecpp` without providing a stream (#4955)
This commit is contained in:
parent
8cf6a22ea3
commit
2bc4ee925e
|
@ -583,14 +583,13 @@ unsigned int CppCheck::check(const std::string &path)
|
||||||
return mExitCode;
|
return mExitCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::ifstream fin(path);
|
return checkFile(Path::simplifyPath(path), emptyString);
|
||||||
return checkFile(Path::simplifyPath(path), emptyString, fin);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int CppCheck::check(const std::string &path, const std::string &content)
|
unsigned int CppCheck::check(const std::string &path, const std::string &content)
|
||||||
{
|
{
|
||||||
std::istringstream iss(content);
|
std::istringstream iss(content);
|
||||||
return checkFile(Path::simplifyPath(path), emptyString, iss);
|
return checkFile(Path::simplifyPath(path), emptyString, &iss);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int CppCheck::check(const ImportProject::FileSettings &fs)
|
unsigned int CppCheck::check(const ImportProject::FileSettings &fs)
|
||||||
|
@ -615,13 +614,20 @@ unsigned int CppCheck::check(const ImportProject::FileSettings &fs)
|
||||||
temp.mSettings.includePaths.insert(temp.mSettings.includePaths.end(), fs.systemIncludePaths.cbegin(), fs.systemIncludePaths.cend());
|
temp.mSettings.includePaths.insert(temp.mSettings.includePaths.end(), fs.systemIncludePaths.cbegin(), fs.systemIncludePaths.cend());
|
||||||
return temp.check(Path::simplifyPath(fs.filename));
|
return temp.check(Path::simplifyPath(fs.filename));
|
||||||
}
|
}
|
||||||
std::ifstream fin(fs.filename);
|
const unsigned int returnValue = temp.checkFile(Path::simplifyPath(fs.filename), fs.cfg);
|
||||||
const unsigned int returnValue = temp.checkFile(Path::simplifyPath(fs.filename), fs.cfg, fin);
|
|
||||||
mSettings.nomsg.addSuppressions(temp.mSettings.nomsg.getSuppressions());
|
mSettings.nomsg.addSuppressions(temp.mSettings.nomsg.getSuppressions());
|
||||||
return returnValue;
|
return returnValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int CppCheck::checkFile(const std::string& filename, const std::string &cfgname, std::istream& fileStream)
|
static simplecpp::TokenList createTokenList(const std::string& filename, std::vector<std::string>& files, simplecpp::OutputList* outputList, std::istream* fileStream)
|
||||||
|
{
|
||||||
|
if (fileStream)
|
||||||
|
return {*fileStream, files, filename, outputList};
|
||||||
|
|
||||||
|
return {filename, files, outputList};
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned int CppCheck::checkFile(const std::string& filename, const std::string &cfgname, std::istream* fileStream)
|
||||||
{
|
{
|
||||||
mExitCode = 0;
|
mExitCode = 0;
|
||||||
|
|
||||||
|
@ -663,7 +669,7 @@ unsigned int CppCheck::checkFile(const std::string& filename, const std::string
|
||||||
|
|
||||||
simplecpp::OutputList outputList;
|
simplecpp::OutputList outputList;
|
||||||
std::vector<std::string> files;
|
std::vector<std::string> files;
|
||||||
simplecpp::TokenList tokens1(fileStream, files, filename, &outputList);
|
simplecpp::TokenList tokens1 = createTokenList(filename, files, &outputList, fileStream);
|
||||||
|
|
||||||
// If there is a syntax error, report it and stop
|
// If there is a syntax error, report it and stop
|
||||||
const auto output_it = std::find_if(outputList.cbegin(), outputList.cend(), [](const simplecpp::Output &output){
|
const auto output_it = std::find_if(outputList.cbegin(), outputList.cend(), [](const simplecpp::Output &output){
|
||||||
|
|
|
@ -155,7 +155,7 @@ private:
|
||||||
* @param fileStream stream the file content can be read from
|
* @param fileStream stream the file content can be read from
|
||||||
* @return number of errors found
|
* @return number of errors found
|
||||||
*/
|
*/
|
||||||
unsigned int checkFile(const std::string& filename, const std::string &cfgname, std::istream& fileStream);
|
unsigned int checkFile(const std::string& filename, const std::string &cfgname, std::istream* fileStream = nullptr);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Check raw tokens
|
* @brief Check raw tokens
|
||||||
|
|
Loading…
Reference in New Issue