Clang import: Better bailout for syntax errors when build dir is not used
This commit is contained in:
parent
e8c5c2b154
commit
387f0a268b
|
@ -268,6 +268,50 @@ const char * CppCheck::extraVersion()
|
||||||
return ExtraVersion;
|
return ExtraVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool reportClangErrors(std::istream &is, std::function<void(const ErrorLogger::ErrorMessage&)> reportErr)
|
||||||
|
{
|
||||||
|
std::string line;
|
||||||
|
while (std::getline(is, line)) {
|
||||||
|
if (line.empty() || line[0] == ' ' || line[0] == '`' || line[0] == '-')
|
||||||
|
continue;
|
||||||
|
|
||||||
|
std::string::size_type pos3 = line.find(": error: ");
|
||||||
|
if (pos3 == std::string::npos)
|
||||||
|
pos3 = line.find(": fatal error:");
|
||||||
|
if (pos3 == std::string::npos)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
// file:line:column: error: ....
|
||||||
|
const std::string::size_type pos2 = line.rfind(":", pos3 - 1);
|
||||||
|
const std::string::size_type pos1 = line.rfind(":", pos2 - 1);
|
||||||
|
|
||||||
|
if (pos1 >= pos2 || pos2 >= pos3)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
const std::string filename = line.substr(0, pos1);
|
||||||
|
const std::string linenr = line.substr(pos1+1, pos2-pos1-1);
|
||||||
|
const std::string colnr = line.substr(pos2+1, pos3-pos2-1);
|
||||||
|
const std::string msg = line.substr(line.find(":", pos3+1) + 2);
|
||||||
|
|
||||||
|
std::list<ErrorLogger::ErrorMessage::FileLocation> locationList;
|
||||||
|
ErrorLogger::ErrorMessage::FileLocation loc;
|
||||||
|
loc.setfile(Path::toNativeSeparators(filename));
|
||||||
|
loc.line = std::atoi(linenr.c_str());
|
||||||
|
loc.column = std::atoi(colnr.c_str());
|
||||||
|
locationList.push_back(loc);
|
||||||
|
ErrorLogger::ErrorMessage errmsg(locationList,
|
||||||
|
loc.getfile(),
|
||||||
|
Severity::error,
|
||||||
|
msg,
|
||||||
|
"syntaxError",
|
||||||
|
false);
|
||||||
|
reportErr(errmsg);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
unsigned int CppCheck::check(const std::string &path)
|
unsigned int CppCheck::check(const std::string &path)
|
||||||
{
|
{
|
||||||
if (mSettings.clang) {
|
if (mSettings.clang) {
|
||||||
|
@ -319,41 +363,18 @@ unsigned int CppCheck::check(const std::string &path)
|
||||||
// Ensure there are not syntax errors...
|
// Ensure there are not syntax errors...
|
||||||
if (!mSettings.buildDir.empty()) {
|
if (!mSettings.buildDir.empty()) {
|
||||||
std::ifstream fin(clangStderr);
|
std::ifstream fin(clangStderr);
|
||||||
while (std::getline(fin, line)) {
|
auto reportError = [this](const ErrorLogger::ErrorMessage& errorMessage) {
|
||||||
std::string::size_type pos3 = line.find(": error: ");
|
reportErr(errorMessage);
|
||||||
if (pos3 == std::string::npos)
|
};
|
||||||
pos3 = line.find(": fatal error:");
|
if (reportClangErrors(fin, reportError))
|
||||||
if (pos3 == std::string::npos)
|
return 0;
|
||||||
continue;
|
} else {
|
||||||
|
std::istringstream istr(result2.second);
|
||||||
// file:line:column: error: ....
|
auto reportError = [this](const ErrorLogger::ErrorMessage& errorMessage) {
|
||||||
const std::string::size_type pos2 = line.rfind(":", pos3 - 1);
|
reportErr(errorMessage);
|
||||||
const std::string::size_type pos1 = line.rfind(":", pos2 - 1);
|
};
|
||||||
|
if (reportClangErrors(istr, reportError))
|
||||||
if (pos1 >= pos2 || pos2 >= pos3)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
const std::string filename = line.substr(0, pos1);
|
|
||||||
const std::string linenr = line.substr(pos1+1, pos2-pos1-1);
|
|
||||||
const std::string colnr = line.substr(pos2+1, pos3-pos2-1);
|
|
||||||
const std::string msg = line.substr(line.find(":", pos3+1) + 2);
|
|
||||||
|
|
||||||
std::list<ErrorLogger::ErrorMessage::FileLocation> locationList;
|
|
||||||
ErrorLogger::ErrorMessage::FileLocation loc;
|
|
||||||
loc.setfile(Path::toNativeSeparators(filename));
|
|
||||||
loc.line = std::atoi(linenr.c_str());
|
|
||||||
loc.column = std::atoi(colnr.c_str());
|
|
||||||
locationList.push_back(loc);
|
|
||||||
ErrorLogger::ErrorMessage errmsg(locationList,
|
|
||||||
loc.getfile(),
|
|
||||||
Severity::error,
|
|
||||||
msg,
|
|
||||||
"syntaxError",
|
|
||||||
false);
|
|
||||||
reportErr(errmsg);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//std::cout << "Checking Clang ast dump:\n" << result2.second << std::endl;
|
//std::cout << "Checking Clang ast dump:\n" << result2.second << std::endl;
|
||||||
|
|
Loading…
Reference in New Issue