parse files with `simplecpp` without providing a stream (#4955)

This commit is contained in:
Oliver Stöneberg 2023-04-30 20:16:51 +02:00 committed by GitHub
parent 8cf6a22ea3
commit 2bc4ee925e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 8 deletions

View File

@ -583,14 +583,13 @@ unsigned int CppCheck::check(const std::string &path)
return mExitCode;
}
std::ifstream fin(path);
return checkFile(Path::simplifyPath(path), emptyString, fin);
return checkFile(Path::simplifyPath(path), emptyString);
}
unsigned int CppCheck::check(const std::string &path, const std::string &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)
@ -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());
return temp.check(Path::simplifyPath(fs.filename));
}
std::ifstream fin(fs.filename);
const unsigned int returnValue = temp.checkFile(Path::simplifyPath(fs.filename), fs.cfg, fin);
const unsigned int returnValue = temp.checkFile(Path::simplifyPath(fs.filename), fs.cfg);
mSettings.nomsg.addSuppressions(temp.mSettings.nomsg.getSuppressions());
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;
@ -663,7 +669,7 @@ unsigned int CppCheck::checkFile(const std::string& filename, const std::string
simplecpp::OutputList outputList;
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
const auto output_it = std::find_if(outputList.cbegin(), outputList.cend(), [](const simplecpp::Output &output){

View File

@ -155,7 +155,7 @@ private:
* @param fileStream stream the file content can be read from
* @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