Skip to content

Commit

Permalink
Remodel
Browse files Browse the repository at this point in the history
  • Loading branch information
olabetskyi committed Feb 1, 2024
1 parent 4e40136 commit 78a24b4
Show file tree
Hide file tree
Showing 2 changed files with 24 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
1 change: 1 addition & 0 deletions lib/preprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -752,6 +752,7 @@ bool Preprocessor::hasErrors(const simplecpp::Output &output)
case simplecpp::Output::SYNTAX_ERROR:
case simplecpp::Output::UNHANDLED_CHAR_ERROR:
case simplecpp::Output::EXPLICIT_INCLUDE_NOT_FOUND:
case simplecpp::Output::FILE_NOT_FOUND:
return true;
case simplecpp::Output::WARNING:
case simplecpp::Output::MISSING_HEADER:
Expand Down

0 comments on commit 78a24b4

Please sign in to comment.