diff --git a/lib/checkmemoryleak.h b/lib/checkmemoryleak.h index e9984a27e..e384ae9b2 100644 --- a/lib/checkmemoryleak.h +++ b/lib/checkmemoryleak.h @@ -182,6 +182,13 @@ public: /** @brief run all simplified checks */ void runSimplifiedChecks(const Tokenizer *tokenizr, const Settings *settings, ErrorLogger *errLog) { + // Don't use these check for Java and C# programs.. + if (tokenizr->getFiles()->at(0).find(".java") != std::string::npos || + tokenizr->getFiles()->at(0).find(".cs") != std::string::npos) + { + return; + } + CheckMemoryLeakInFunction checkMemoryLeak(tokenizr, settings, errLog); checkMemoryLeak.checkReallocUsage(); checkMemoryLeak.check(); @@ -355,6 +362,13 @@ public: void runSimplifiedChecks(const Tokenizer *tokenizr, const Settings *settings, ErrorLogger *errLog) { + // Don't use these check for Java and C# programs.. + if (tokenizr->getFiles()->at(0).find(".java") != std::string::npos || + tokenizr->getFiles()->at(0).find(".cs") != std::string::npos) + { + return; + } + CheckMemoryLeakInClass checkMemoryLeak(tokenizr, settings, errLog); checkMemoryLeak.check(); } diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 29e48ff42..67fffbb00 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -2162,6 +2162,13 @@ void CheckOther::checkIncompleteStatement() void CheckOther::strPlusChar() { + // Don't use this check for Java and C# programs.. + if (_tokenizer->getFiles()->at(0).find(".java") != std::string::npos || + _tokenizer->getFiles()->at(0).find(".cs") != std::string::npos) + { + return; + } + bool charVars[10000] = {0}; for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next()) diff --git a/lib/filelister.cpp b/lib/filelister.cpp index 6e5748309..a65c803e2 100644 --- a/lib/filelister.cpp +++ b/lib/filelister.cpp @@ -124,7 +124,9 @@ bool FileLister::acceptFile(const std::string &filename) extension == ".c" || extension == ".c++" || extension == ".tpp" || - extension == ".txx") + extension == ".txx" || + extension == ".java" || // Java source file + extension == ".cs") // C# source file { return true; } diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 4f7d7c0dc..c29a51236 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -1722,6 +1722,20 @@ bool Tokenizer::tokenize(std::istream &code, createTokens(code); + // Convert C# code + if (_files[0].find(".cs")) + { + for (Token *tok = _tokens; tok; tok = tok->next()) + { + if (Token::Match(tok, "[;{}] %type% [ ] %var% [=;]")) + { + tok = tok->next()->next(); + tok->str("*"); + tok->deleteNext(); + } + } + } + // remove inline SQL (Oracle PRO*C). Ticket: #1959 for (Token *tok = _tokens; tok; tok = tok->next()) { diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 709cd1594..4dc84603c 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -264,6 +264,9 @@ private: // foo(p = new char[10]); => p = new char[10]; foo(p); TEST_CASE(simplifyAssignmentInFunctionCall); + + // Tokenize C# + TEST_CASE(cs); } @@ -4563,6 +4566,11 @@ private: { ASSERT_EQUALS("; x = g ( ) ; f ( x ) ;", tokenizeAndStringify(";f(x=g());")); } + + void cs() + { + ASSERT_EQUALS("; int * i ;", tokenizeAndStringify("; int [] i;")); + } }; REGISTER_TEST(TestTokenizer)