CppCheck: extracted clang-specific code from `check(const std::string&)` into separate method (#5842)
This commit is contained in:
parent
bd9700b848
commit
44ed53319e
|
@ -423,12 +423,12 @@ static bool reportClangErrors(std::istream &is, const std::function<void(const E
|
|||
return false;
|
||||
}
|
||||
|
||||
unsigned int CppCheck::check(const std::string &path)
|
||||
unsigned int CppCheck::checkClang(const std::string &path)
|
||||
{
|
||||
if (mSettings.clang) {
|
||||
if (!mSettings.quiet)
|
||||
mErrorLogger.reportOut(std::string("Checking ") + path + " ...", Color::FgGreen);
|
||||
|
||||
// TODO: this ignores the configured language
|
||||
const std::string lang = Path::isCPP(path) ? "-x c++" : "-x c";
|
||||
const std::string analyzerInfo = mSettings.buildDir.empty() ? std::string() : AnalyzerInformation::getAnalyzerInfoFile(mSettings.buildDir, path, emptyString);
|
||||
const std::string clangcmd = analyzerInfo + ".clang-cmd";
|
||||
|
@ -443,6 +443,7 @@ unsigned int CppCheck::check(const std::string &path)
|
|||
#endif
|
||||
|
||||
std::string flags(lang + " ");
|
||||
// TODO: does not apply C standard
|
||||
if (Path::isCPP(path) && !mSettings.standards.stdValue.empty())
|
||||
flags += "-std=" + mSettings.standards.stdValue + " ";
|
||||
|
||||
|
@ -508,6 +509,7 @@ unsigned int CppCheck::check(const std::string &path)
|
|||
std::string dumpFile;
|
||||
createDumpFile(mSettings, path, fdump, dumpFile);
|
||||
if (fdump.is_open()) {
|
||||
// TODO: use tinyxml2 to create XML
|
||||
fdump << "<dump cfg=\"\">\n";
|
||||
for (const ErrorMessage& errmsg: compilerWarnings)
|
||||
fdump << " <clang-warning file=\"" << toxml(errmsg.callStack.front().getfile()) << "\" line=\"" << errmsg.callStack.front().line << "\" column=\"" << errmsg.callStack.front().column << "\" message=\"" << toxml(errmsg.shortMessage()) << "\"/>\n";
|
||||
|
@ -535,7 +537,12 @@ unsigned int CppCheck::check(const std::string &path)
|
|||
}
|
||||
|
||||
return mExitCode;
|
||||
}
|
||||
}
|
||||
|
||||
unsigned int CppCheck::check(const std::string &path)
|
||||
{
|
||||
if (mSettings.clang)
|
||||
return checkClang(path);
|
||||
|
||||
return checkFile(Path::simplifyPath(path), emptyString);
|
||||
}
|
||||
|
|
|
@ -200,6 +200,8 @@ private:
|
|||
void executeRules(const std::string &tokenlist, const Tokenizer &tokenizer);
|
||||
#endif
|
||||
|
||||
unsigned int checkClang(const std::string &path);
|
||||
|
||||
/**
|
||||
* @brief Errors and warnings are directed here.
|
||||
*
|
||||
|
|
|
@ -31,14 +31,17 @@ struct CPPCHECKLIB FileSettings {
|
|||
std::string cfg;
|
||||
std::string filename;
|
||||
std::string defines;
|
||||
// TODO: handle differently
|
||||
std::string cppcheckDefines() const {
|
||||
return defines + (msc ? ";_MSC_VER=1900" : "") + (useMfc ? ";__AFXWIN_H__=1" : "");
|
||||
}
|
||||
std::set<std::string> undefs;
|
||||
std::list<std::string> includePaths;
|
||||
// only used by clang mode
|
||||
std::list<std::string> systemIncludePaths;
|
||||
std::string standard;
|
||||
Platform::Type platformType = Platform::Type::Unspecified;
|
||||
// TODO: get rid of these
|
||||
bool msc{};
|
||||
bool useMfc{};
|
||||
};
|
||||
|
|
|
@ -757,6 +757,7 @@ bool ImportProject::importVcxproj(const std::string &filename, std::map<std::str
|
|||
FileSettings fs;
|
||||
fs.filename = cfilename;
|
||||
fs.cfg = p.name;
|
||||
// TODO: detect actual MSC version
|
||||
fs.msc = true;
|
||||
fs.useMfc = useOfMfc;
|
||||
fs.defines = "_WIN32=1";
|
||||
|
|
Loading…
Reference in New Issue