Skip to content

Commit c1b17d7

Browse files
committed
got rid of duplicated error reporting code in CppCheck::checkInternal() / cleanups [skip ci]
1 parent 3ea86e5 commit c1b17d7

File tree

3 files changed

+7
-36
lines changed

3 files changed

+7
-36
lines changed

lib/cppcheck.cpp

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -962,30 +962,11 @@ unsigned int CppCheck::checkInternal(const FileWithDetails& file, const std::str
962962
std::vector<std::string> files;
963963
simplecpp::TokenList tokens1 = createTokenList(files, &outputList);
964964

965-
// If there is a syntax error, report it and stop
966-
const auto output_it = std::find_if(outputList.cbegin(), outputList.cend(), [](const simplecpp::Output &output){
967-
return Preprocessor::hasErrors(output);
968-
});
969-
if (output_it != outputList.cend()) {
970-
const simplecpp::Output &output = *output_it;
971-
std::string locfile = Path::fromNativeSeparators(output.location.file());
972-
if (mSettings.relativePaths)
973-
locfile = Path::getRelativePath(locfile, mSettings.basePaths);
974-
975-
ErrorMessage::FileLocation loc1(locfile, output.location.line, output.location.col);
976-
977-
ErrorMessage errmsg({std::move(loc1)},
978-
"", // TODO: is this correct?
979-
Severity::error,
980-
output.msg,
981-
"syntaxError",
982-
Certainty::normal);
983-
mErrorLogger.reportErr(errmsg);
984-
return mLogger->exitcode();
985-
}
986-
987965
Preprocessor preprocessor(tokens1, mSettings, mErrorLogger, file.lang());
988966

967+
if (preprocessor.reportOutput(outputList, true))
968+
return mLogger->exitcode();
969+
989970
if (!preprocessor.loadFiles(files))
990971
return mLogger->exitcode();
991972

lib/preprocessor.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,11 @@ class CPPCHECKLIB WARN_UNUSED Preprocessor {
140140
*/
141141
void dump(std::ostream &out) const;
142142

143-
static bool hasErrors(const simplecpp::Output &output);
144-
145-
protected:
146143
bool reportOutput(const simplecpp::OutputList &outputList, bool showerror);
147144

148145
private:
146+
static bool hasErrors(const simplecpp::Output &output);
147+
149148
bool handleErrors(const simplecpp::OutputList &outputList, bool throwError);
150149

151150
static void simplifyPragmaAsmPrivate(simplecpp::TokenList &tokenList);

test/testpreprocessor.cpp

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,21 +49,12 @@ class TestPreprocessor : public TestFixture {
4949
TestPreprocessor() : TestFixture("TestPreprocessor") {}
5050

5151
private:
52-
class PreprocessorTest : public Preprocessor
53-
{
54-
friend class TestPreprocessor;
55-
public:
56-
PreprocessorTest(simplecpp::TokenList& tokens, const Settings& settings, ErrorLogger &errorLogger, Standards::Language lang)
57-
: Preprocessor(tokens, settings, errorLogger, lang)
58-
{}
59-
};
60-
6152
template<size_t size>
6253
std::string expandMacros(const char (&code)[size], ErrorLogger &errorLogger) const {
6354
simplecpp::OutputList outputList;
6455
std::vector<std::string> files;
6556
simplecpp::TokenList tokens1 = simplecpp::TokenList(code, files, "file.cpp", &outputList);
66-
PreprocessorTest p(tokens1, settingsDefault, errorLogger, Path::identify(tokens1.getFiles()[0], false));
57+
Preprocessor p(tokens1, settingsDefault, errorLogger, Path::identify(tokens1.getFiles()[0], false));
6758
simplecpp::TokenList tokens2 = p.preprocess("", files, true);
6859
(void)p.reportOutput(outputList, true);
6960
return tokens2.stringify();
@@ -128,7 +119,7 @@ class TestPreprocessor : public TestFixture {
128119

129120
simplecpp::TokenList tokens(code, size, files, Path::simplifyPath(filename), &outputList);
130121
// TODO: we should be using the actual Preprocessor implementation
131-
PreprocessorTest preprocessor(tokens, settings, errorlogger, Path::identify(tokens.getFiles()[0], false));
122+
Preprocessor preprocessor(tokens, settings, errorlogger, Path::identify(tokens.getFiles()[0], false));
132123
if (inlineSuppression)
133124
preprocessor.inlineSuppressions(*inlineSuppression);
134125
preprocessor.removeComments();

0 commit comments

Comments
 (0)