Skip to content

Commit d8239b2

Browse files
committed
Tokenizer: Remove simplifyCalculations from simplifyTokenList2
1 parent c897c04 commit d8239b2

3 files changed

Lines changed: 1 addition & 148 deletions

File tree

lib/tokenize.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5168,9 +5168,6 @@ bool Tokenizer::simplifyTokenList2()
51685168
if (Settings::terminated())
51695169
return false;
51705170

5171-
// Simplify simple calculations before replace constants, this allows the replacement of constants that are calculated
5172-
// e.g. const static int value = sizeof(X)/sizeof(Y);
5173-
simplifyCalculations();
51745171

51755172
bool modified = true;
51765173
while (modified) {
@@ -5179,7 +5176,6 @@ bool Tokenizer::simplifyTokenList2()
51795176

51805177
modified = false;
51815178
modified |= simplifyConstTernaryOp();
5182-
modified |= simplifyCalculations();
51835179
validate();
51845180
}
51855181

@@ -7248,11 +7244,6 @@ void Tokenizer::simplifyTypeIntrinsics()
72487244
}
72497245
}
72507246

7251-
bool Tokenizer::simplifyCalculations()
7252-
{
7253-
return mTemplateSimplifier->simplifyCalculations(nullptr, nullptr, false);
7254-
}
7255-
72567247
//---------------------------------------------------------------------------
72577248
// Helper functions for handling the tokens list
72587249
//---------------------------------------------------------------------------

lib/tokenize.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -179,13 +179,6 @@ class CPPCHECKLIB Tokenizer {
179179
/** Simplify assignment where rhs is a block : "x=({123;});" => "{x=123;}" */
180180
void simplifyAssignmentBlock();
181181

182-
/**
183-
* Simplify constant calculations such as "1+2" => "3"
184-
* @return true if modifications to token-list are done.
185-
* false if no modifications are done.
186-
*/
187-
bool simplifyCalculations();
188-
189182
/** Insert array size where it isn't given */
190183
void arraySize();
191184

test/testsimplifytokens.cpp

Lines changed: 1 addition & 132 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ class TestSimplifyTokens : public TestFixture {
6262
TEST_CASE(double_plus);
6363
TEST_CASE(redundant_plus);
6464
TEST_CASE(redundant_plus_numbers);
65-
TEST_CASE(parentheses1);
6665
TEST_CASE(declareVar);
6766

6867
TEST_CASE(declareArray);
@@ -90,11 +89,6 @@ class TestSimplifyTokens : public TestFixture {
9089
// Simplify "?:"
9190
TEST_CASE(simplifyConditionOperator);
9291

93-
// Simplify calculations
94-
TEST_CASE(calculations);
95-
TEST_CASE(comparisons);
96-
TEST_CASE(simplifyCalculations);
97-
9892
TEST_CASE(simplifyOperator1);
9993
TEST_CASE(simplifyOperator2);
10094

@@ -162,7 +156,6 @@ class TestSimplifyTokens : public TestFixture {
162156
TEST_CASE(simplifyKnownVariables51); // #4409 hang
163157
TEST_CASE(simplifyKnownVariables54); // #4913 'x' is not 0 after *--x=0;
164158
TEST_CASE(simplifyKnownVariables56); // ticket #5301 - >>
165-
TEST_CASE(simplifyKnownVariables57); // ticket #4724
166159
TEST_CASE(simplifyKnownVariables58); // ticket #5268
167160
TEST_CASE(simplifyKnownVariables59); // skip for header
168161
TEST_CASE(simplifyKnownVariables61); // #7805
@@ -1860,11 +1853,6 @@ class TestSimplifyTokens : public TestFixture {
18601853
}
18611854

18621855

1863-
void parentheses1() {
1864-
ASSERT_EQUALS("a <= 110 ;", tok("a <= (10+100);"));
1865-
ASSERT_EQUALS("{ while ( x ( ) == -1 ) { } }", tok("{while((x()) == -1){ }}"));
1866-
}
1867-
18681856
void declareVar() {
18691857
const char code[] = "void f ( ) { char str [ 100 ] = \"100\" ; }";
18701858
ASSERT_EQUALS(code, tok(code));
@@ -2307,7 +2295,7 @@ class TestSimplifyTokens : public TestFixture {
23072295

23082296
{
23092297
const char code[] = "tr = (struct reg){ .a = (1), .c = (2) };";
2310-
const char expected[] = "tr = ( struct reg ) { . a = 1 , . c = 2 } ;";
2298+
const char expected[] = "tr = ( struct reg ) { . a = 1 , . c = ( 2 ) } ;";
23112299
ASSERT_EQUALS(expected, tok(code));
23122300
}
23132301
}
@@ -2387,120 +2375,6 @@ class TestSimplifyTokens : public TestFixture {
23872375
}
23882376
}
23892377

2390-
void calculations() {
2391-
{
2392-
const char code[] = "a[i+8+2];";
2393-
ASSERT_EQUALS("a [ i + 10 ] ;", tok(code));
2394-
}
2395-
{
2396-
const char code[] = "a[8+2+i];";
2397-
ASSERT_EQUALS("a [ 10 + i ] ;", tok(code));
2398-
}
2399-
{
2400-
const char code[] = "a[i + 2 * (2 * 4)];";
2401-
ASSERT_EQUALS("a [ i + 16 ] ;", tok(code));
2402-
}
2403-
{
2404-
const char code[] = "a[i + 100 - 90];";
2405-
ASSERT_EQUALS("a [ i + 10 ] ;", tok(code));
2406-
}
2407-
{
2408-
const char code[] = "a[1+1+1+1+1+1+1+1+1+1-2+5-3];";
2409-
ASSERT_EQUALS("a [ 10 ] ;", tok(code));
2410-
}
2411-
{
2412-
const char code[] = "a[10+10-10-10];";
2413-
ASSERT_EQUALS("a [ 0 ] ;", tok(code));
2414-
}
2415-
2416-
ASSERT_EQUALS("a [ 4 ] ;", tok("a[1+3|4];"));
2417-
ASSERT_EQUALS("a [ 4U ] ;", tok("a[1+3|4U];"));
2418-
ASSERT_EQUALS("a [ 3 ] ;", tok("a[1+2&3];"));
2419-
ASSERT_EQUALS("a [ 3U ] ;", tok("a[1+2&3U];"));
2420-
ASSERT_EQUALS("a [ 5 ] ;", tok("a[1-0^4];"));
2421-
ASSERT_EQUALS("a [ 5U ] ;", tok("a[1-0^4U];"));
2422-
2423-
ASSERT_EQUALS("x = 1 + 2 * y ;", tok("x=1+2*y;"));
2424-
ASSERT_EQUALS("x = 7 ;", tok("x=1+2*3;"));
2425-
ASSERT_EQUALS("x = 47185 ;", tok("x=(65536*72/100);"));
2426-
ASSERT_EQUALS("x = 1500000 / ( ( 90000 ) * 1000 / 54000 ) ;", tok("x = 1500000 / ((145000 - 55000) * 1000 / 54000);"));
2427-
ASSERT_EQUALS("int a [ 8 ] ;", tok("int a[5+6/2];"));
2428-
ASSERT_EQUALS("int a [ 4 ] ;", tok("int a[(10)-1-5];"));
2429-
ASSERT_EQUALS("int a [ i - 9 ] ;", tok("int a[i - 10 + 1];"));
2430-
ASSERT_EQUALS("int a [ i - 11 ] ;", tok("int a[i - 10 - 1];"));
2431-
2432-
ASSERT_EQUALS("x = y ;", tok("x=0+y+0-0;"));
2433-
ASSERT_EQUALS("x = 0 ;", tok("x=0*y;"));
2434-
2435-
ASSERT_EQUALS("x = 501 ;", tok("x = 1000 + 2 >> 1;"));
2436-
ASSERT_EQUALS("x = 125 ;", tok("x = 1000 / 2 >> 2;"));
2437-
2438-
{
2439-
// Ticket #1997
2440-
const char code[] = "void * operator new[](size_t);";
2441-
ASSERT_EQUALS("void * operatornew[] ( long ) ;", tok(code, true, Settings::Win32A));
2442-
}
2443-
2444-
ASSERT_EQUALS("; a [ 0 ] ;", tok(";a[0*(*p)];"));
2445-
2446-
ASSERT_EQUALS(";", tok("; x = x + 0;"));
2447-
2448-
ASSERT_EQUALS("{ if ( a == 2 ) { } }", tok("{if (a==1+1){}}"));
2449-
ASSERT_EQUALS("{ if ( a + 2 != 6 ) { } }", tok("{if (a+1+1!=1+2+3){}}"));
2450-
ASSERT_EQUALS("{ if ( 4 < a ) { } }", tok("{if (14-2*5<a*4/(2*2)){}}"));
2451-
2452-
ASSERT_EQUALS("( y / 2 - 2 ) ;", tok("(y / 2 - 2);"));
2453-
ASSERT_EQUALS("( y % 2 - 2 ) ;", tok("(y % 2 - 2);"));
2454-
2455-
ASSERT_EQUALS("( 4 ) ;", tok("(1 * 2 / 1 * 2);")); // #3722
2456-
2457-
ASSERT_EQUALS("x ( 60129542144 ) ;", tok("x(14<<4+17<<300%17);")); // #4931
2458-
ASSERT_EQUALS("x ( 1 ) ;", tok("x(8|5&6+0 && 7);")); // #6104
2459-
ASSERT_EQUALS("x ( 1 ) ;", tok("x(2 && 4<<4<<5 && 4);")); // #4933
2460-
ASSERT_EQUALS("x ( 1 ) ;", tok("x(9&&8%5%4/3);")); // #4931
2461-
ASSERT_EQUALS("x ( 1 ) ;", tok("x(2 && 2|5<<2%4);")); // #4931
2462-
ASSERT_EQUALS("x ( -2 << 6 | 1 ) ;", tok("x(1-3<<6|5/3);")); // #4931
2463-
ASSERT_EQUALS("x ( 2 ) ;", tok("x(2|0*0&2>>1+0%2*1);")); // #4931
2464-
ASSERT_EQUALS("x ( 0 & 4 != 1 ) ;", tok("x(4%1<<1&4!=1);")); // #4931 (can be simplified further but it's not a problem)
2465-
ASSERT_EQUALS("x ( 1 ) ;", tok("x(0&&4>0==2||4);")); // #4931
2466-
2467-
// don't remove these spaces..
2468-
ASSERT_EQUALS("new ( auto ) ( 4 ) ;", tok("new (auto)(4);"));
2469-
}
2470-
2471-
void comparisons() {
2472-
ASSERT_EQUALS("( 1 ) ;", tok("( 1 < 2 );"));
2473-
ASSERT_EQUALS("( x && 1 ) ;", tok("( x && 1 < 2 );"));
2474-
ASSERT_EQUALS("( 5 ) ;", tok("( 1 < 2 && 3 < 4 ? 5 : 6 );"));
2475-
ASSERT_EQUALS("( 6 ) ;", tok("( 1 > 2 && 3 > 4 ? 5 : 6 );"));
2476-
}
2477-
2478-
void simplifyCalculations() {
2479-
ASSERT_EQUALS("void foo ( char str [ ] ) { char x ; x = ( * str ) ; }",
2480-
tok("void foo ( char str [ ] ) { char x = 0 | ( * str ) ; }"));
2481-
ASSERT_EQUALS("void foo ( ) { if ( b ) { } }",
2482-
tok("void foo ( ) { if (b + 0) { } }"));
2483-
ASSERT_EQUALS("void foo ( ) { if ( b ) { } }",
2484-
tok("void foo ( ) { if (0 + b) { } }"));
2485-
ASSERT_EQUALS("void foo ( ) { if ( b ) { } }",
2486-
tok("void foo ( ) { if (b - 0) { } }"));
2487-
ASSERT_EQUALS("void foo ( ) { if ( b ) { } }",
2488-
tok("void foo ( ) { if (b * 1) { } }"));
2489-
ASSERT_EQUALS("void foo ( ) { if ( b ) { } }",
2490-
tok("void foo ( ) { if (1 * b) { } }"));
2491-
//ASSERT_EQUALS("void foo ( ) { if ( b ) { } }",
2492-
// tok("void foo ( ) { if (b / 1) { } }"));
2493-
ASSERT_EQUALS("void foo ( ) { if ( b ) { } }",
2494-
tok("void foo ( ) { if (b | 0) { } }"));
2495-
ASSERT_EQUALS("void foo ( ) { if ( b ) { } }",
2496-
tok("void foo ( ) { if (0 | b) { } }"));
2497-
ASSERT_EQUALS("void foo ( int b ) { int a ; a = b ; bar ( a ) ; }",
2498-
tok("void foo ( int b ) { int a = b | 0 ; bar ( a ) ; }"));
2499-
ASSERT_EQUALS("void foo ( int b ) { int a ; a = b ; bar ( a ) ; }",
2500-
tok("void foo ( int b ) { int a = 0 | b ; bar ( a ) ; }"));
2501-
}
2502-
2503-
25042378
void simplifyOperator1() {
25052379
// #3237 - error merging namespaces with operators
25062380
const char code[] = "class c {\n"
@@ -3920,11 +3794,6 @@ class TestSimplifyTokens : public TestFixture {
39203794
tokenizeAndStringify("void f() { int a=0,b=0; *p>>a>>b; return a/b; }", true));
39213795
}
39223796

3923-
void simplifyKnownVariables57() { // #4724
3924-
ASSERT_EQUALS("unsigned long long x ; x = 9223372036854775808UL ;", tokenizeAndStringify("unsigned long long x = 1UL << 63 ;", true));
3925-
ASSERT_EQUALS("long long x ; x = -9223372036854775808L ;", tokenizeAndStringify("long long x = 1L << 63 ;", true));
3926-
}
3927-
39283797
void simplifyKnownVariables58() { // #5268
39293798
const char code[] = "enum e { VAL1 = 1, VAL2 }; "
39303799
"typedef char arr_t[VAL2]; "

0 commit comments

Comments
 (0)