From d7dfa29864a985defb21119a390736579089cb38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Mon, 28 May 2018 14:11:59 +0200 Subject: [PATCH] Preprocessor: only throw errors upon request. --- lib/cppcheck.cpp | 5 +---- lib/preprocessor.cpp | 6 +++--- lib/preprocessor.h | 2 +- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index c1cb6fb47..653caa2d6 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -352,7 +352,7 @@ unsigned int CppCheck::checkFile(const std::string& filename, const std::string // Create tokens, skip rest of iteration if failed Timer timer("Tokenizer::createTokens", _settings.showtime, &S_timerResults); - const simplecpp::TokenList &tokensP = preprocessor.preprocess(tokens1, cfg, files); + const simplecpp::TokenList &tokensP = preprocessor.preprocess(tokens1, cfg, files, true); _tokenizer.createTokens(&tokensP); timer.Stop(); hasValidConfig = true; @@ -483,9 +483,6 @@ unsigned int CppCheck::checkFile(const std::string& filename, const std::string } catch (const InternalError &e) { internalError(filename, e.errorMessage); exitcode=1; // e.g. reflect a syntax error - } catch (const simplecpp::Output &o) { - internalError(std::string(o.location.file() + ':' + MathLib::toString(o.location.line)), o.msg); - exitcode=1; // e.g. reflect an error during preprocessing } analyzerInformation.setFileInfo("CheckUnusedFunctions", checkUnusedFunctions.analyzerInfo()); diff --git a/lib/preprocessor.cpp b/lib/preprocessor.cpp index 73106618c..1a60b9664 100644 --- a/lib/preprocessor.cpp +++ b/lib/preprocessor.cpp @@ -608,7 +608,7 @@ void Preprocessor::setPlatformInfo(simplecpp::TokenList *tokens) const tokens->sizeOfType["long double *"] = _settings.sizeof_pointer; } -simplecpp::TokenList Preprocessor::preprocess(const simplecpp::TokenList &tokens1, const std::string &cfg, std::vector &files) +simplecpp::TokenList Preprocessor::preprocess(const simplecpp::TokenList &tokens1, const std::string &cfg, std::vector &files, bool throwError) { const simplecpp::DUI dui = createDUI(_settings, cfg, files[0]); @@ -619,7 +619,7 @@ simplecpp::TokenList Preprocessor::preprocess(const simplecpp::TokenList &tokens const bool showerror = (!_settings.userDefines.empty() && !_settings.force); reportOutput(outputList, showerror); - if (hasErrors(outputList)) { + if (throwError && hasErrors(outputList)) { for (const simplecpp::Output &output : outputList) { switch (output.type) { case simplecpp::Output::ERROR: @@ -646,7 +646,7 @@ simplecpp::TokenList Preprocessor::preprocess(const simplecpp::TokenList &tokens std::string Preprocessor::getcode(const simplecpp::TokenList &tokens1, const std::string &cfg, std::vector &files, const bool writeLocations) { - simplecpp::TokenList tokens2 = preprocess(tokens1, cfg, files); + simplecpp::TokenList tokens2 = preprocess(tokens1, cfg, files, false); unsigned int prevfile = 0; unsigned int line = 1; std::ostringstream ret; diff --git a/lib/preprocessor.h b/lib/preprocessor.h index 566d55262..f4895428d 100644 --- a/lib/preprocessor.h +++ b/lib/preprocessor.h @@ -136,7 +136,7 @@ public: */ void preprocess(std::istream &srcCodeStream, std::string &processedFile, std::list &resultConfigurations, const std::string &filename, const std::list &includePaths); - simplecpp::TokenList preprocess(const simplecpp::TokenList &tokens1, const std::string &cfg, std::vector &files); + simplecpp::TokenList preprocess(const simplecpp::TokenList &tokens1, const std::string &cfg, std::vector &files, bool throwError = false); std::string getcode(const simplecpp::TokenList &tokens1, const std::string &cfg, std::vector &files, const bool writeLocations);