From 7817d5b142ade3b1f1d553b6e64f355d4c232bd1 Mon Sep 17 00:00:00 2001 From: Reijo Tomperi Date: Sat, 23 Jan 2010 23:18:11 +0200 Subject: [PATCH] Fix #1279 (Change error message: Invalid number of character ({). Can't process file.) http://sourceforge.net/apps/trac/cppcheck/ticket/1279 --- lib/cppcheck.cpp | 2 +- lib/tokenize.cpp | 11 +++++++++-- lib/tokenize.h | 7 ++++++- test/teststl.cpp | 2 +- test/testtokenize.cpp | 14 +++++++------- 5 files changed, 24 insertions(+), 12 deletions(-) diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index 5a524edb5..c6c3e4d12 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -531,7 +531,7 @@ void CppCheck::checkFile(const std::string &code, const char FileName[]) { std::istringstream istr(code); TIMER_START(); - if (!_tokenizer.tokenize(istr, FileName)) + if (!_tokenizer.tokenize(istr, FileName, cfg)) { // File had syntax errors, abort return; diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 0c5a8337a..fc084c89c 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -805,8 +805,10 @@ void Tokenizer::simplifyTypedef() } } -bool Tokenizer::tokenize(std::istream &code, const char FileName[]) +bool Tokenizer::tokenize(std::istream &code, const char FileName[], const std::string configuration) { + _configuration = configuration; + // The "_files" vector remembers what files have been tokenized.. _files.push_back(FileLister::simplifyPath(FileName)); @@ -5023,7 +5025,12 @@ void Tokenizer::syntaxError(const Token *tok, char c) const ErrorLogger::ErrorMessage errmsg(locationList, "error", - std::string("Invalid number of character (") + c + "). Can't process file.", + std::string("Invalid number of character (") + + c + + ") " + + "when these macros are defined: '" + + _configuration + + "'.", "syntaxError"); if (_errorLogger) diff --git a/lib/tokenize.h b/lib/tokenize.h index 652096c8b..2f735e303 100644 --- a/lib/tokenize.h +++ b/lib/tokenize.h @@ -64,9 +64,10 @@ public: * \endcode * * @param FileName The filename + * @param configuration E.g. "A" for code where "#ifdef A" is true * @return false if Source code contains syntax errors */ - bool tokenize(std::istream &code, const char FileName[]); + bool tokenize(std::istream &code, const char FileName[], const std::string configuration = ""); /** * Create tokens from code. @@ -397,6 +398,10 @@ private: std::vector _files; const Settings * const _settings; ErrorLogger * const _errorLogger; + + /** E.g. "A" for code where "#ifdef A" is true. This is used to + print additional information in error situations. */ + std::string _configuration; }; /// @} diff --git a/test/teststl.cpp b/test/teststl.cpp index 69fdb8e79..e7a150608 100644 --- a/test/teststl.cpp +++ b/test/teststl.cpp @@ -585,7 +585,7 @@ private: Tokenizer tokenizer(0, this); std::istringstream istr(src); ASSERT_EQUALS(false, tokenizer.tokenize(istr, "test.cpp")); - ASSERT_EQUALS("[test.cpp:3]: (error) Invalid number of character ((). Can't process file.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:3]: (error) Invalid number of character (() when these macros are defined: ''.\n", errout.str()); } diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 80b1689de..b30b05361 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -2500,7 +2500,7 @@ private: Tokenizer tokenizer(0, this); std::istringstream istr(code); ASSERT_EQUALS(false, tokenizer.tokenize(istr, "test.cpp")); - ASSERT_EQUALS("[test.cpp:1]: (error) Invalid number of character ({). Can't process file.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:1]: (error) Invalid number of character ({) when these macros are defined: ''.\n", errout.str()); } { @@ -2509,7 +2509,7 @@ private: Tokenizer tokenizer(0, this); std::istringstream istr(code); ASSERT_EQUALS(false, tokenizer.tokenize(istr, "test.cpp")); - ASSERT_EQUALS("[test.cpp:1]: (error) Invalid number of character ((). Can't process file.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:1]: (error) Invalid number of character (() when these macros are defined: ''.\n", errout.str()); } { @@ -2530,8 +2530,8 @@ private: "}\n"; Tokenizer tokenizer(0, this); std::istringstream istr(code); - ASSERT_EQUALS(false, tokenizer.tokenize(istr, "test.cpp")); - ASSERT_EQUALS("[test.cpp:3]: (error) Invalid number of character ((). Can't process file.\n", errout.str()); + ASSERT_EQUALS(false, tokenizer.tokenize(istr, "test.cpp", "ABC")); + ASSERT_EQUALS("[test.cpp:3]: (error) Invalid number of character (() when these macros are defined: 'ABC'.\n", errout.str()); } { @@ -2543,7 +2543,7 @@ private: Tokenizer tokenizer(0, this); std::istringstream istr(code); ASSERT_EQUALS(false, tokenizer.tokenize(istr, "test.cpp")); - ASSERT_EQUALS("[test.cpp:2]: (error) Invalid number of character ({). Can't process file.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:2]: (error) Invalid number of character ({) when these macros are defined: ''.\n", errout.str()); } { @@ -2555,7 +2555,7 @@ private: Tokenizer tokenizer(0, this); std::istringstream istr(code); ASSERT_EQUALS(false, tokenizer.tokenize(istr, "test.cpp")); - ASSERT_EQUALS("[test.cpp:3]: (error) Invalid number of character ([). Can't process file.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:3]: (error) Invalid number of character ([) when these macros are defined: ''.\n", errout.str()); } { @@ -2569,7 +2569,7 @@ private: Tokenizer tokenizer(0, this); std::istringstream istr(code); ASSERT_EQUALS(false, tokenizer.tokenize(istr, "test.cpp")); - ASSERT_EQUALS("[test.cpp:2]: (error) Invalid number of character ((). Can't process file.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:2]: (error) Invalid number of character (() when these macros are defined: ''.\n", errout.str()); } }