Removed Java/C# handling

This commit is contained in:
Daniel Marjamäki 2012-10-02 18:44:36 +02:00
parent 72666e10d1
commit 2f069f550f
9 changed files with 0 additions and 184 deletions

View File

@ -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<Scope>::const_iterator scope;
for (scope = symbolDatabase->scopeList.begin(); scope != symbolDatabase->scopeList.end(); ++scope) {

View File

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

View File

@ -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<std::string,std::string>::const_iterator nonReentrant_end = _nonReentrantFunctions.end();
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next()) {
// Look for function invocations

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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 () {}"