Tokenizer: Moved simplifyAssignmentInFunctionCall from simplifyTokenList1 to simplifyTokenList2
This commit is contained in:
parent
0ddb5c12ce
commit
15ecb26a6c
|
@ -3617,9 +3617,6 @@ bool Tokenizer::simplifyTokenList1(const char FileName[])
|
||||||
if (_settings->terminated())
|
if (_settings->terminated())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// f(x=g()) => x=g(); f(x)
|
|
||||||
simplifyAssignmentInFunctionCall();
|
|
||||||
|
|
||||||
// x = ({ 123; }); => { x = 123; }
|
// x = ({ 123; }); => { x = 123; }
|
||||||
simplifyAssignmentBlock();
|
simplifyAssignmentBlock();
|
||||||
|
|
||||||
|
@ -3730,6 +3727,9 @@ bool Tokenizer::simplifyTokenList2()
|
||||||
for (Token *tok = list.front(); tok; tok = tok->next())
|
for (Token *tok = list.front(); tok; tok = tok->next())
|
||||||
tok->clearAst();
|
tok->clearAst();
|
||||||
|
|
||||||
|
// f(x=g()) => x=g(); f(x)
|
||||||
|
simplifyAssignmentInFunctionCall();
|
||||||
|
|
||||||
simplifyCharAt();
|
simplifyCharAt();
|
||||||
|
|
||||||
// simplify references
|
// simplify references
|
||||||
|
|
|
@ -6155,7 +6155,7 @@ private:
|
||||||
" int t;\n"
|
" int t;\n"
|
||||||
" dostuff(t=1,t^c);\n"
|
" dostuff(t=1,t^c);\n"
|
||||||
"}", "test.c");
|
"}", "test.c");
|
||||||
TODO_ASSERT_EQUALS("error", "", errout.str());
|
ASSERT_EQUALS("[test.c:3]: (error) Expression 't=1,t^c' depends on order of evaluation of side effects\n", errout.str());
|
||||||
|
|
||||||
// sizeof
|
// sizeof
|
||||||
check("void f(char *buf) {\n"
|
check("void f(char *buf) {\n"
|
||||||
|
|
|
@ -47,6 +47,9 @@ private:
|
||||||
// correct order
|
// correct order
|
||||||
TEST_CASE(simplifyTokenList1);
|
TEST_CASE(simplifyTokenList1);
|
||||||
|
|
||||||
|
// foo(p = new char[10]); => p = new char[10]; foo(p);
|
||||||
|
TEST_CASE(simplifyAssignmentInFunctionCall);
|
||||||
|
|
||||||
TEST_CASE(cast);
|
TEST_CASE(cast);
|
||||||
TEST_CASE(iftruefalse);
|
TEST_CASE(iftruefalse);
|
||||||
TEST_CASE(combine_strings);
|
TEST_CASE(combine_strings);
|
||||||
|
@ -341,6 +344,12 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void simplifyAssignmentInFunctionCall() {
|
||||||
|
ASSERT_EQUALS("; x = g ( ) ; f ( x ) ;", tok(";f(x=g());"));
|
||||||
|
ASSERT_EQUALS("; hs = ( xyz_t ) { h . centerX , h . centerY , 1 + index } ; putInput ( hs , 1 ) ;", tok(";putInput(hs = (xyz_t) { h->centerX, h->centerY, 1 + index }, 1);"));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void cast() {
|
void cast() {
|
||||||
ASSERT_EQUALS("if ( p == 0 ) { ; }", tok("if (p == (char *)0);"));
|
ASSERT_EQUALS("if ( p == 0 ) { ; }", tok("if (p == (char *)0);"));
|
||||||
ASSERT_EQUALS("return str ;", tok("return (char *)str;"));
|
ASSERT_EQUALS("return str ;", tok("return (char *)str;"));
|
||||||
|
|
|
@ -363,9 +363,6 @@ private:
|
||||||
|
|
||||||
TEST_CASE(simplifyCalculations);
|
TEST_CASE(simplifyCalculations);
|
||||||
|
|
||||||
// foo(p = new char[10]); => p = new char[10]; foo(p);
|
|
||||||
TEST_CASE(simplifyAssignmentInFunctionCall);
|
|
||||||
|
|
||||||
// "x += .." => "x = x + .."
|
// "x += .." => "x = x + .."
|
||||||
TEST_CASE(simplifyCompoundAssignment);
|
TEST_CASE(simplifyCompoundAssignment);
|
||||||
|
|
||||||
|
@ -5727,11 +5724,6 @@ private:
|
||||||
ASSERT_EQUALS("; a = a + ( b = 1 ) ;", tokenizeAndStringify("; a += b = 1;"));
|
ASSERT_EQUALS("; a = a + ( b = 1 ) ;", tokenizeAndStringify("; a += b = 1;"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void simplifyAssignmentInFunctionCall() {
|
|
||||||
ASSERT_EQUALS("; x = g ( ) ; f ( x ) ;", tokenizeAndStringify(";f(x=g());"));
|
|
||||||
ASSERT_EQUALS("; hs = ( xyz_t ) { h . centerX , h . centerY , 1 + index } ; putInput ( hs , 1 ) ;", tokenizeAndStringify(";putInput(hs = (xyz_t) { h->centerX, h->centerY, 1 + index }, 1);"));
|
|
||||||
}
|
|
||||||
|
|
||||||
void simplifyRoundCurlyParentheses() {
|
void simplifyRoundCurlyParentheses() {
|
||||||
ASSERT_EQUALS("; x = 123 ;", tokenizeAndStringify(";x=({123;});"));
|
ASSERT_EQUALS("; x = 123 ;", tokenizeAndStringify(";x=({123;});"));
|
||||||
ASSERT_EQUALS("; x = y ;", tokenizeAndStringify(";x=({y;});"));
|
ASSERT_EQUALS("; x = y ;", tokenizeAndStringify(";x=({y;});"));
|
||||||
|
|
Loading…
Reference in New Issue