Merge branch 'master' of git@github.com:danmar/cppcheck

This commit is contained in:
Kimmo Varis 2009-06-06 13:09:18 +03:00
commit 9bc8fb8eec
3 changed files with 58 additions and 0 deletions

View File

@ -473,6 +473,9 @@ bool Tokenizer::tokenize(std::istream &code, const char FileName[])
} }
} }
// replace "unsigned i" with "unsigned int i"
unsignedint();
simplifyVarDecl(); simplifyVarDecl();
// Handle templates.. // Handle templates..
@ -2214,6 +2217,30 @@ bool Tokenizer::simplifyVarDecl()
} }
void Tokenizer::unsignedint()
{
for (Token *tok = _tokens; tok; tok = tok->next())
{
// A variable declaration where the "int" is left out?
if (!Token::Match(tok, "unsigned %var% [;,=]"))
continue;
// Previous token should either be a symbol or one of "{};"
if (tok->previous() &&
!tok->previous()->isName() &&
!Token::Match(tok->previous(), "[{};]"))
continue;
// next token should not be a standard type?
if (tok->next()->isStandardType())
continue;
// The "int" is missing.. add it
tok->insertToken("int");
}
}
bool Tokenizer::simplifyIfAssign() bool Tokenizer::simplifyIfAssign()
{ {
bool ret = false; bool ret = false;

View File

@ -100,6 +100,12 @@ public:
*/ */
bool simplifyVarDecl(); bool simplifyVarDecl();
/**
* insert an "int" after "unsigned" if needed:
* "unsigned i" => "unsigned int i"
*/
void unsignedint();
/** /**
* Simplify question mark - colon operator * Simplify question mark - colon operator
* Example: 0 ? (2/0) : 0 => 0 * Example: 0 ? (2/0) : 0 => 0

View File

@ -145,6 +145,9 @@ private:
TEST_CASE(syntax_error); TEST_CASE(syntax_error);
TEST_CASE(removeKeywords); TEST_CASE(removeKeywords);
// unsigned i; => unsigned int i;
TEST_CASE(unsigned1);
} }
@ -2028,6 +2031,28 @@ private:
ASSERT_EQUALS("if ( ! ! x ) { ; }", actual); ASSERT_EQUALS("if ( ! ! x ) { ; }", actual);
} }
/**
* tokenize "unsigned i" => "unsigned int i"
* tokenize "unsigned int" => "unsigned int"
*/
void unsigned1()
{
// No changes..
{
const char code[] = "void foo ( unsigned int , unsigned float ) ;";
ASSERT_EQUALS(code, tokenizeAndStringify(code));
}
// insert "int" after "unsigned"..
{
const char code1[] = "unsigned i ;";
const char code2[] = "unsigned int i ;";
ASSERT_EQUALS(code2, tokenizeAndStringify(code1));
}
}
}; };
REGISTER_TEST(TestTokenizer) REGISTER_TEST(TestTokenizer)