Skip to content

Commit

Permalink
Remodel
Browse files Browse the repository at this point in the history
  • Loading branch information
olabetskyi committed Feb 2, 2024
1 parent e7bd977 commit 6d8c0aa
Showing 1 changed file with 23 additions and 30 deletions.
53 changes: 23 additions & 30 deletions lib/cppcheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -542,15 +542,21 @@ unsigned int CppCheck::checkClang(const std::string &path)
return mExitCode;
}

static ErrorMessage makeError(const std::string &filename, int line, unsigned int column, const std::string &msg, const std::string &id)
{
const ErrorMessage::FileLocation loc1(filename, line, column);
std::list<ErrorMessage::FileLocation> callstack(1, loc1);

return ErrorMessage(callstack,
emptyString,
Severity::error,
msg,
id,
Certainty::normal);
}

unsigned int CppCheck::check(const std::string &path)
{
if (!Path::isFile(path)) {
std::string fixedpath = Path::simplifyPath(path);
fixedpath = Path::toNativeSeparators(fixedpath);
const std::string errorMsg("File " + fixedpath + " does not exists. Skipping file.");
fileNotFoundError(Path::simplifyPath(path), errorMsg);
return 0;
}
if (mSettings.clang)
return checkClang(path);

Expand All @@ -565,13 +571,6 @@ unsigned int CppCheck::check(const std::string &path, const std::string &content

unsigned int CppCheck::check(const FileSettings &fs)
{
if (!Path::isFile(fs.filename)) {
std::string fixedpath = Path::simplifyPath(fs.filename);
fixedpath = Path::toNativeSeparators(fixedpath);
const std::string errorMsg("File " + fixedpath + " does not exists. Skipping file.");
fileNotFoundError(fs.filename, errorMsg);
return 0;
}
CppCheck temp(mErrorLogger, mUseGlobalSuppressions, mExecuteCommand);
temp.mSettings = mSettings;
if (!temp.mSettings.userDefines.empty())
Expand Down Expand Up @@ -684,7 +683,14 @@ unsigned int CppCheck::checkFile(const std::string& filename, const std::string
output.msg,
"syntaxError",
Certainty::normal);
reportErr(errmsg);
if(output.type == simplecpp::Output::Type::FILE_NOT_FOUND){
const std::string fixedpath = Path::toNativeSeparators(file);
const std::string errorMsg("File " + fixedpath + " does not exists. Skipping file.");
fileNotFoundError(file, errorMsg);
}
else{
reportErr(makeError(file, output.location.line, output.location.col, output.msg, "syntaxError"));
}
return mExitCode;
}

Expand Down Expand Up @@ -1047,28 +1053,15 @@ unsigned int CppCheck::checkFile(const std::string& filename, const std::string
return mExitCode;
}

static ErrorMessage makeError(const std::string &filename, const std::string &msg, const std::string &id)
{
const ErrorMessage::FileLocation loc1(filename, 0, 0);
std::list<ErrorMessage::FileLocation> callstack(1, loc1);

return ErrorMessage(callstack,
emptyString,
Severity::error,
msg,
id,
Certainty::normal);
}

// TODO: replace with ErrorMessage::fromInternalError()
void CppCheck::internalError(const std::string &filename, const std::string &msg)
{
mErrorLogger.reportErr(makeError(filename, "Bailing out from analysis:" + msg, "internalError"));
mErrorLogger.reportErr(makeError(filename, 0, 0U, "Bailing out from analysis:" + msg, "internalError"));
}

void CppCheck::fileNotFoundError(const std::string &filename, const std::string &msg)
{
mErrorLogger.reportErr(makeError(filename, msg, "fileNotFound"));
mErrorLogger.reportErr(makeError(filename, 0, 0U, msg, "fileNotFound"));
}

//---------------------------------------------------------------------------
Expand Down

0 comments on commit 6d8c0aa

Please sign in to comment.