Tokenizer: Remove redundant '+'

This commit is contained in:
Daniel Marjamäki 2012-11-28 07:09:56 +01:00
parent f23ce8d254
commit 5d1b4e6dbb
2 changed files with 6 additions and 2 deletions

View File

@ -2151,6 +2151,8 @@ void Tokenizer::concatenateNegativeNumber()
if (Token::Match(tok, "?|:|,|(|[|{|=|return|case|sizeof|%op% - %num%")) { if (Token::Match(tok, "?|:|,|(|[|{|=|return|case|sizeof|%op% - %num%")) {
tok->deleteNext(); tok->deleteNext();
tok->next()->str("-" + tok->next()->str()); tok->next()->str("-" + tok->next()->str());
} else if (Token::Match(tok, "?|:|,|(|[|{|=|return|case|sizeof|%op% +")) {
tok->deleteNext();
} }
} }
} }

View File

@ -71,7 +71,7 @@ private:
TEST_CASE(foreach); // #3690 TEST_CASE(foreach); // #3690
TEST_CASE(minus); TEST_CASE(concatenateNegativeNumber);
TEST_CASE(longtok); TEST_CASE(longtok);
@ -810,12 +810,14 @@ private:
ASSERT_EQUALS("void f ( ) { for ( char c in MyString ) { Console :: Write ( c ) ; } }" ,tokenizeAndStringify(code.c_str())); ASSERT_EQUALS("void f ( ) { for ( char c in MyString ) { Console :: Write ( c ) ; } }" ,tokenizeAndStringify(code.c_str()));
} }
void minus() { void concatenateNegativeNumber() {
ASSERT_EQUALS("i = -12", tokenizeAndStringify("i = -12")); ASSERT_EQUALS("i = -12", tokenizeAndStringify("i = -12"));
ASSERT_EQUALS("1 - 2", tokenizeAndStringify("1-2")); ASSERT_EQUALS("1 - 2", tokenizeAndStringify("1-2"));
ASSERT_EQUALS("foo ( -1 ) - 2", tokenizeAndStringify("foo(-1)-2")); ASSERT_EQUALS("foo ( -1 ) - 2", tokenizeAndStringify("foo(-1)-2"));
ASSERT_EQUALS("int f ( ) { return -2 ; }", tokenizeAndStringify("int f(){return -2;}")); ASSERT_EQUALS("int f ( ) { return -2 ; }", tokenizeAndStringify("int f(){return -2;}"));
ASSERT_EQUALS("int x [ 2 ] = { -2 , 1 }", tokenizeAndStringify("int x[2] = {-2,1}")); ASSERT_EQUALS("int x [ 2 ] = { -2 , 1 }", tokenizeAndStringify("int x[2] = {-2,1}"));
ASSERT_EQUALS("f ( 123 )", tokenizeAndStringify("f(+123)"));
} }