Preprocessor: only throw errors upon request.

This commit is contained in:
Daniel Marjamäki 2018-05-28 14:11:59 +02:00
parent a3b9745557
commit d7dfa29864
3 changed files with 5 additions and 8 deletions

View File

@ -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());

View File

@ -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<std::string> &files)
simplecpp::TokenList Preprocessor::preprocess(const simplecpp::TokenList &tokens1, const std::string &cfg, std::vector<std::string> &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<std::string> &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;

View File

@ -136,7 +136,7 @@ public:
*/
void preprocess(std::istream &srcCodeStream, std::string &processedFile, std::list<std::string> &resultConfigurations, const std::string &filename, const std::list<std::string> &includePaths);
simplecpp::TokenList preprocess(const simplecpp::TokenList &tokens1, const std::string &cfg, std::vector<std::string> &files);
simplecpp::TokenList preprocess(const simplecpp::TokenList &tokens1, const std::string &cfg, std::vector<std::string> &files, bool throwError = false);
std::string getcode(const simplecpp::TokenList &tokens1, const std::string &cfg, std::vector<std::string> &files, const bool writeLocations);