Fixed #4115 (Incorrect uninitialized variable error message with realloc macro)
This commit is contained in:
parent
37695d44f3
commit
2e3a7db4eb
|
@ -1979,6 +1979,9 @@ bool Tokenizer::tokenize(std::istream &code,
|
||||||
// f(x=g()) => x=g(); f(x)
|
// f(x=g()) => x=g(); f(x)
|
||||||
simplifyAssignmentInFunctionCall();
|
simplifyAssignmentInFunctionCall();
|
||||||
|
|
||||||
|
// x = ({ 123; }); => { x = 123; }
|
||||||
|
simplifyAssignmentBlock();
|
||||||
|
|
||||||
simplifyVariableMultipleAssign();
|
simplifyVariableMultipleAssign();
|
||||||
|
|
||||||
// Remove redundant parentheses
|
// Remove redundant parentheses
|
||||||
|
@ -8560,6 +8563,36 @@ void Tokenizer::simplifyAssignmentInFunctionCall()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Tokenizer::simplifyAssignmentBlock()
|
||||||
|
{
|
||||||
|
for (Token *tok = list.front(); tok; tok = tok->next()) {
|
||||||
|
if (Token::Match(tok, "[;{}] %var% = ( {")) {
|
||||||
|
// goto the "} )"
|
||||||
|
unsigned int indentlevel = 0;
|
||||||
|
Token *tok2 = tok;
|
||||||
|
while (NULL != (tok2 = tok2->next())) {
|
||||||
|
if (tok2->str() == "(" || tok2->str() == "{")
|
||||||
|
++indentlevel;
|
||||||
|
else if (tok2->str() == ")" || tok2->str() == "}") {
|
||||||
|
if (indentlevel <= 2)
|
||||||
|
break;
|
||||||
|
--indentlevel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (indentlevel == 2 && Token::simpleMatch(tok2, "} )")) {
|
||||||
|
tok2 = tok2->tokAt(-3);
|
||||||
|
if (Token::Match(tok2, "[;{}] %any% ;") && (tok2->next()->isName() || tok2->next()->isNumber())) {
|
||||||
|
tok2->insertToken("=");
|
||||||
|
tok2->insertToken(tok->next()->str());
|
||||||
|
tok2->next()->varId(tok->next()->varId());
|
||||||
|
tok->deleteNext(3);
|
||||||
|
tok2->tokAt(5)->deleteNext();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Remove __asm..
|
// Remove __asm..
|
||||||
void Tokenizer::simplifyAsm()
|
void Tokenizer::simplifyAsm()
|
||||||
{
|
{
|
||||||
|
|
|
@ -159,6 +159,9 @@ public:
|
||||||
*/
|
*/
|
||||||
void simplifyAssignmentInFunctionCall();
|
void simplifyAssignmentInFunctionCall();
|
||||||
|
|
||||||
|
/** Simplify assignment where rhs is a block : "x=({123;});" => "{x=123;}" */
|
||||||
|
void simplifyAssignmentBlock();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Simplify constant calculations such as "1+2" => "3"
|
* Simplify constant calculations such as "1+2" => "3"
|
||||||
* @return true if modifications to token-list are done.
|
* @return true if modifications to token-list are done.
|
||||||
|
|
|
@ -418,6 +418,9 @@ private:
|
||||||
// "x += .." => "x = x + .."
|
// "x += .." => "x = x + .."
|
||||||
TEST_CASE(simplifyCompoundAssignment);
|
TEST_CASE(simplifyCompoundAssignment);
|
||||||
|
|
||||||
|
// x = ({ 123; }); => { x = 123; }
|
||||||
|
TEST_CASE(simplifyAssignmentBlock);
|
||||||
|
|
||||||
// Tokenize C#
|
// Tokenize C#
|
||||||
TEST_CASE(cs);
|
TEST_CASE(cs);
|
||||||
|
|
||||||
|
@ -6708,6 +6711,11 @@ private:
|
||||||
ASSERT_EQUALS("; x = g ( ) ; f ( x ) ;", tokenizeAndStringify(";f(x=g());"));
|
ASSERT_EQUALS("; x = g ( ) ; f ( x ) ;", tokenizeAndStringify(";f(x=g());"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void simplifyAssignmentBlock() {
|
||||||
|
ASSERT_EQUALS("; { x = 123 ; } ;", tokenizeAndStringify(";x=({123;});"));
|
||||||
|
ASSERT_EQUALS("; { x = y ; } ;", tokenizeAndStringify(";x=({y;});"));
|
||||||
|
}
|
||||||
|
|
||||||
void cs() {
|
void cs() {
|
||||||
bool simplify = false;
|
bool simplify = false;
|
||||||
bool expand = true;
|
bool expand = true;
|
||||||
|
|
Loading…
Reference in New Issue