Merge branch 'master' of git@github.com:danmar/cppcheck
This commit is contained in:
commit
9bc8fb8eec
|
@ -473,6 +473,9 @@ bool Tokenizer::tokenize(std::istream &code, const char FileName[])
|
|||
}
|
||||
}
|
||||
|
||||
// replace "unsigned i" with "unsigned int i"
|
||||
unsignedint();
|
||||
|
||||
simplifyVarDecl();
|
||||
|
||||
// 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 ret = false;
|
||||
|
|
|
@ -100,6 +100,12 @@ public:
|
|||
*/
|
||||
bool simplifyVarDecl();
|
||||
|
||||
/**
|
||||
* insert an "int" after "unsigned" if needed:
|
||||
* "unsigned i" => "unsigned int i"
|
||||
*/
|
||||
void unsignedint();
|
||||
|
||||
/**
|
||||
* Simplify question mark - colon operator
|
||||
* Example: 0 ? (2/0) : 0 => 0
|
||||
|
|
|
@ -145,6 +145,9 @@ private:
|
|||
TEST_CASE(syntax_error);
|
||||
|
||||
TEST_CASE(removeKeywords);
|
||||
|
||||
// unsigned i; => unsigned int i;
|
||||
TEST_CASE(unsigned1);
|
||||
}
|
||||
|
||||
|
||||
|
@ -2028,6 +2031,28 @@ private:
|
|||
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)
|
||||
|
|
Loading…
Reference in New Issue