From 2f069f550fddc109cc71e822531aa4c345e07d43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Tue, 2 Oct 2012 18:44:36 +0200 Subject: [PATCH] Removed Java/C# handling --- lib/checkclass.cpp | 5 -- lib/checkmemoryleak.h | 4 -- lib/checknonreentrantfunctions.cpp | 4 -- lib/checkobsoletefunctions.cpp | 4 -- lib/checkother.cpp | 5 -- lib/tokenize.cpp | 85 ------------------------------ lib/tokenize.h | 12 ----- test/testconstructors.cpp | 27 ---------- test/testtokenize.cpp | 38 ------------- 9 files changed, 184 deletions(-) diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index d91696df2..ce2c459c6 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -1317,11 +1317,6 @@ void CheckClass::checkConst() if (!_settings->isEnabled("style")) return; - // Don't check C# and JAVA classes - if (_tokenizer->isJavaOrCSharp()) { - return; - } - std::list::const_iterator scope; for (scope = symbolDatabase->scopeList.begin(); scope != symbolDatabase->scopeList.end(); ++scope) { diff --git a/lib/checkmemoryleak.h b/lib/checkmemoryleak.h index 0dcbc6d9c..82e40ab6b 100644 --- a/lib/checkmemoryleak.h +++ b/lib/checkmemoryleak.h @@ -199,10 +199,6 @@ 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->isJavaOrCSharp()) - return; - CheckMemoryLeakInFunction checkMemoryLeak(tokenizr, settings, errLog); checkMemoryLeak.checkReallocUsage(); checkMemoryLeak.check(); diff --git a/lib/checknonreentrantfunctions.cpp b/lib/checknonreentrantfunctions.cpp index f4a4addcb..3613df8ce 100644 --- a/lib/checknonreentrantfunctions.cpp +++ b/lib/checknonreentrantfunctions.cpp @@ -35,10 +35,6 @@ void CheckNonReentrantFunctions::nonReentrantFunctions() if (!_settings->standards.posix || !_settings->isEnabled("portability")) return; - // Don't check C# and Java code - if (_tokenizer->isJavaOrCSharp()) - return; - std::map::const_iterator nonReentrant_end = _nonReentrantFunctions.end(); for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next()) { // Look for function invocations diff --git a/lib/checkobsoletefunctions.cpp b/lib/checkobsoletefunctions.cpp index e2d4728b9..e42b10835 100644 --- a/lib/checkobsoletefunctions.cpp +++ b/lib/checkobsoletefunctions.cpp @@ -36,10 +36,6 @@ void CheckObsoleteFunctions::obsoleteFunctions() if (!_settings->isEnabled("style")) return; - // Don't check C# and Java code - if (_tokenizer->isJavaOrCSharp()) - return; - const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase(); for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next()) { diff --git a/lib/checkother.cpp b/lib/checkother.cpp index efa0e7bbb..16387dcaa 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -2045,11 +2045,6 @@ void CheckOther::constStatementError(const Token *tok, const std::string &type) void CheckOther::strPlusChar() { - // Don't use this check for Java and C# programs.. - if (_tokenizer->isJavaOrCSharp()) { - return; - } - const SymbolDatabase* symbolDatabase = _tokenizer->getSymbolDatabase(); for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next()) { diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 9c3c28813..f9d6521b9 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -1640,10 +1640,6 @@ bool Tokenizer::tokenize(std::istream &code, // replace inline SQL with "asm()" (Oracle PRO*C). Ticket: #1959 simplifySQL(); - // Simplify JAVA/C# code - if (isJavaOrCSharp()) - simplifyJavaAndCSharp(); - // Concatenate double sharp: 'a ## b' -> 'ab' concatenateDoubleSharp(); @@ -2321,68 +2317,6 @@ void Tokenizer::simplifyDoublePlusAndDoubleMinus() } } -void Tokenizer::simplifyJavaAndCSharp() -{ - // better don't call isJava in the loop - const bool isJava_ = isJava(); - for (Token *tok = list.front(); tok; tok = tok->next()) { - if (tok->str() == "private") - tok->str("private:"); - else if (tok->str() == "protected") - tok->str("protected:"); - else if (tok->str() == "public") - tok->str("public:"); - - else if (isJava_) { - if (Token::Match(tok, ") throws %var% {")) - tok->deleteNext(2); - } else { - //remove 'using var;' from code - if (Token::Match(tok, "using %var% ;") && - (!tok->previous() || Token::Match(tok->previous(), "[,;{}]"))) { - tok->deleteNext(2); - tok->deleteThis(); - } - - //simplify C# arrays of arrays and multidimension arrays - while (Token::Match(tok, "%type% [ ,|]") && - (!tok->previous() || Token::Match(tok->previous(), "[,;{}]"))) { - Token *tok2 = tok->tokAt(2); - unsigned int count = 1; - while (tok2 && tok2->str() == ",") { - ++count; - tok2 = tok2->next(); - } - if (!tok2 || tok2->str() != "]") - break; - tok2 = tok2->next(); - while (Token::Match(tok2, "[ ,|]")) { - tok2 = tok2->next(); - while (tok2 && tok2->str() == ",") { - ++count; - tok2 = tok2->next(); - } - if (!tok2 || tok2->str() != "]") - break; - ++count; - tok2 = tok2->next(); - } - if (!tok2) - break; - else if (Token::Match(tok2, "%var% [;,=]")) { - Token::eraseTokens(tok, tok2); - do { - tok->insertToken("*"); - } while (--count); - tok = tok2->tokAt(2); - } - } - if (!tok) - break; - } - } -} - /** Specify array size if it hasn't been given */ void Tokenizer::arraySize() @@ -7105,10 +7039,6 @@ public: void Tokenizer::simplifyEnum() { - // Don't simplify enums in java files - if (isJavaOrCSharp()) - return; - std::string className; int classLevel = 0; bool goback = false; @@ -9411,21 +9341,6 @@ const std::string& Tokenizer::getSourceFilePath() const return list.getFiles()[0]; } -bool Tokenizer::isJava() const -{ - return _settings->enforcedLang == Settings::Java || (_settings->enforcedLang == Settings::None && Path::isJava(getSourceFilePath())); -} - -bool Tokenizer::isCSharp() const -{ - return _settings->enforcedLang == Settings::CSharp || (_settings->enforcedLang == Settings::None && Path::isCSharp(getSourceFilePath())); -} - -bool Tokenizer::isJavaOrCSharp() const -{ - return isJava() || isCSharp(); -} - bool Tokenizer::isC() const { return _settings->enforcedLang == Settings::C || (_settings->enforcedLang == Settings::None && Path::isC(getSourceFilePath())); diff --git a/lib/tokenize.h b/lib/tokenize.h index daa0fb5d0..5cd825d90 100644 --- a/lib/tokenize.h +++ b/lib/tokenize.h @@ -51,15 +51,6 @@ public: /** Returns the source file path. e.g. "file.cpp" */ const std::string& getSourceFilePath() const; - /** Is the code JAVA. Used for bailouts */ - bool isJava() const; - - /** Is the code C#. Used for bailouts */ - bool isCSharp() const; - - /** Is the code JAVA/C#. Used for bailouts */ - bool isJavaOrCSharp() const; - /** Is the code C. Used for bailouts */ bool isC() const; @@ -169,9 +160,6 @@ public: */ bool simplifyCalculations(); - /** Simplify Java and C# syntax */ - void simplifyJavaAndCSharp(); - /** Insert array size where it isn't given */ void arraySize(); diff --git a/test/testconstructors.cpp b/test/testconstructors.cpp index c6e6eaf61..3ab2b1e8d 100644 --- a/test/testconstructors.cpp +++ b/test/testconstructors.cpp @@ -142,7 +142,6 @@ private: TEST_CASE(uninitFunction5); TEST_CASE(uninitSameClassName); // No FP when two classes have the same name TEST_CASE(uninitFunctionOverload); // No FP when there are overloaded functions - TEST_CASE(uninitJava); // Java: no FP when variable is initialized in declaration TEST_CASE(uninitVarOperatorEqual); // ticket #2415 TEST_CASE(uninitVarPointer); // ticket #3801 TEST_CASE(uninitConstVar); @@ -2471,32 +2470,6 @@ private: "};"); ASSERT_EQUALS("", errout.str()); } - - void checkJava(const char code[]) { - // Clear the error log - errout.str(""); - - Settings settings; - settings.addEnabled("style"); - - // Tokenize.. - Tokenizer tokenizer(&settings, this); - std::istringstream istr(code); - tokenizer.tokenize(istr, "test.java"); - tokenizer.simplifyTokenList(); - - // Check.. - CheckClass checkClass(&tokenizer, &settings, this); - checkClass.constructors(); - } - - void uninitJava() { - checkJava("class A {\n" - " private: int i = 0;\n" - " public: A() { }\n" - "};"); - ASSERT_EQUALS("", errout.str()); - } }; REGISTER_TEST(TestConstructors) diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index b8028e2e2..e51166604 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -422,12 +422,6 @@ private: // x = ({ 123; }); => { x = 123; } TEST_CASE(simplifyAssignmentBlock); - // Tokenize C# - TEST_CASE(cs); - - // Tokenize JAVA - TEST_CASE(java); - TEST_CASE(simplifyOperatorName1); TEST_CASE(simplifyOperatorName2); TEST_CASE(simplifyOperatorName3); @@ -6722,38 +6716,6 @@ private: ASSERT_EQUALS("; { x = y ; } ;", tokenizeAndStringify(";x=({y;});")); } - void cs() { - bool simplify = false; - bool expand = true; - Settings::PlatformType platform = Settings::Unspecified; - const char filename[] = "test.cs"; - ASSERT_EQUALS("int * x ;", tokenizeAndStringify("int [] x;", simplify, expand, platform, filename)); - ASSERT_EQUALS("; int * x , int * y ;", tokenizeAndStringify("; int [] x, int [] y;", simplify, expand, platform, filename)); - ASSERT_EQUALS("; int * * x ;", tokenizeAndStringify("; int [][] x;", simplify, expand, platform, filename)); - ASSERT_EQUALS("; int * * * x ;", tokenizeAndStringify("; int [][][] x;", simplify, expand, platform, filename)); - ASSERT_EQUALS("; int * * x ;", tokenizeAndStringify("; int [,] x;", simplify, expand, platform, filename)); - ASSERT_EQUALS("; int * * * * x ;", tokenizeAndStringify("; int [][,][] x;", simplify, expand, platform, filename)); - ASSERT_EQUALS("; int * * * x ;", tokenizeAndStringify("; int [,,] x;", simplify, expand, platform, filename)); - ASSERT_EQUALS("; int * * * * * * x ;", tokenizeAndStringify("; int [,][,,][] x;", simplify, expand, platform, filename)); - ASSERT_EQUALS("; int * * * * x ;", tokenizeAndStringify("; int [,,,] x;", simplify, expand, platform, filename)); - } - - std::string javatest(const char javacode[]) { - errout.str(""); - Settings settings; - // tokenize.. - Tokenizer tokenizer(&settings, this); - std::istringstream istr(javacode); - tokenizer.tokenize(istr, "test.java"); - - return tokenizer.tokens()->stringifyList(0, false); - } - - - void java() { - ASSERT_EQUALS("void f ( ) { }", javatest("void f() throws Exception { }")); - } - void simplifyOperatorName1() { // make sure C code doesn't get changed const char code[] = "void operator () {}"