Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion externals/simplecpp/simplecpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2426,8 +2426,16 @@ std::map<std::string, simplecpp::TokenList*> simplecpp::load(const simplecpp::To
continue;

std::ifstream fin(filename.c_str());
if (!fin.is_open())
if (!fin.is_open()) {
if (outputList) {
simplecpp::Output err(fileNumbers);
err.type = simplecpp::Output::EXPLICIT_INCLUDE_NOT_FOUND;
err.location = Location(fileNumbers);
err.msg = "Can not open include file '" + filename + "' that is explicitly included.";
outputList->push_back(err);
}
continue;
}

TokenList *tokenlist = new TokenList(fin, fileNumbers, filename, outputList);
if (!tokenlist->front()) {
Expand Down
3 changes: 2 additions & 1 deletion externals/simplecpp/simplecpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,8 @@ namespace simplecpp {
INCLUDE_NESTED_TOO_DEEPLY,
SYNTAX_ERROR,
PORTABILITY_BACKSLASH,
UNHANDLED_CHAR_ERROR
UNHANDLED_CHAR_ERROR,
EXPLICIT_INCLUDE_NOT_FOUND
} type;
Location location;
std::string msg;
Expand Down
4 changes: 3 additions & 1 deletion lib/cppcheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ unsigned int CppCheck::checkFile(const std::string& filename, const std::string
case simplecpp::Output::INCLUDE_NESTED_TOO_DEEPLY:
case simplecpp::Output::SYNTAX_ERROR:
case simplecpp::Output::UNHANDLED_CHAR_ERROR:
case simplecpp::Output::EXPLICIT_INCLUDE_NOT_FOUND:
err = true;
break;
case simplecpp::Output::WARNING:
Expand All @@ -299,7 +300,8 @@ unsigned int CppCheck::checkFile(const std::string& filename, const std::string
}
}

preprocessor.loadFiles(tokens1, files);
if (!preprocessor.loadFiles(tokens1, files))
return mExitCode;

if (!mSettings.plistOutput.empty()) {
std::string filename2;
Expand Down
50 changes: 31 additions & 19 deletions lib/preprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,7 @@ static bool hasErrors(const simplecpp::OutputList &outputList)
case simplecpp::Output::INCLUDE_NESTED_TOO_DEEPLY:
case simplecpp::Output::SYNTAX_ERROR:
case simplecpp::Output::UNHANDLED_CHAR_ERROR:
case simplecpp::Output::EXPLICIT_INCLUDE_NOT_FOUND:
return true;
case simplecpp::Output::WARNING:
case simplecpp::Output::MISSING_HEADER:
Expand All @@ -569,12 +570,36 @@ static bool hasErrors(const simplecpp::OutputList &outputList)
return false;
}

void Preprocessor::handleErrors(const simplecpp::OutputList& outputList, bool throwError)
{
const bool showerror = (!mSettings.userDefines.empty() && !mSettings.force);
reportOutput(outputList, showerror);
if (throwError) {
for (const simplecpp::Output& output : outputList) {
switch (output.type) {
case simplecpp::Output::ERROR:
case simplecpp::Output::INCLUDE_NESTED_TOO_DEEPLY:
case simplecpp::Output::SYNTAX_ERROR:
case simplecpp::Output::UNHANDLED_CHAR_ERROR:
case simplecpp::Output::EXPLICIT_INCLUDE_NOT_FOUND:
throw output;
case simplecpp::Output::WARNING:
case simplecpp::Output::MISSING_HEADER:
case simplecpp::Output::PORTABILITY_BACKSLASH:
break;
};
}
}
}

void Preprocessor::loadFiles(const simplecpp::TokenList &rawtokens, std::vector<std::string> &files)
bool Preprocessor::loadFiles(const simplecpp::TokenList &rawtokens, std::vector<std::string> &files)
{
const simplecpp::DUI dui = createDUI(mSettings, emptyString, files[0]);

mTokenLists = simplecpp::load(rawtokens, files, dui, nullptr);
simplecpp::OutputList outputList;
mTokenLists = simplecpp::load(rawtokens, files, dui, &outputList);
handleErrors(outputList, false);
return !hasErrors(outputList);
}

void Preprocessor::removeComments()
Expand Down Expand Up @@ -614,23 +639,7 @@ simplecpp::TokenList Preprocessor::preprocess(const simplecpp::TokenList &tokens
simplecpp::TokenList tokens2(files);
simplecpp::preprocess(tokens2, tokens1, files, mTokenLists, dui, &outputList, &macroUsage);

const bool showerror = (!mSettings.userDefines.empty() && !mSettings.force);
reportOutput(outputList, showerror);
if (throwError && hasErrors(outputList)) {
for (const simplecpp::Output &output : outputList) {
switch (output.type) {
case simplecpp::Output::ERROR:
case simplecpp::Output::INCLUDE_NESTED_TOO_DEEPLY:
case simplecpp::Output::SYNTAX_ERROR:
case simplecpp::Output::UNHANDLED_CHAR_ERROR:
throw output;
case simplecpp::Output::WARNING:
case simplecpp::Output::MISSING_HEADER:
case simplecpp::Output::PORTABILITY_BACKSLASH:
break;
};
}
}
handleErrors(outputList, throwError);

tokens2.removeComments();

Expand Down Expand Up @@ -717,6 +726,9 @@ void Preprocessor::reportOutput(const simplecpp::OutputList &outputList, bool sh
case simplecpp::Output::UNHANDLED_CHAR_ERROR:
error(out.location.file(), out.location.line, out.msg);
break;
case simplecpp::Output::EXPLICIT_INCLUDE_NOT_FOUND:
error(emptyString, 0, out.msg);
break;
};
}
}
Expand Down
4 changes: 3 additions & 1 deletion lib/preprocessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ class CPPCHECKLIB Preprocessor {

std::set<std::string> getConfigs(const simplecpp::TokenList &tokens) const;

void loadFiles(const simplecpp::TokenList &rawtokens, std::vector<std::string> &files);
void handleErrors(const simplecpp::OutputList &outputList, bool throwError);

bool loadFiles(const simplecpp::TokenList &rawtokens, std::vector<std::string> &files);

void removeComments();

Expand Down