Fixed two TODO unit tests by delaying arraySize simpification until createLink2 is executed
This commit is contained in:
parent
0a34b206e8
commit
3645e3c16b
|
@ -2131,24 +2131,24 @@ void Tokenizer::simplifyDoublePlusAndDoubleMinus()
|
|||
void Tokenizer::arraySize()
|
||||
{
|
||||
for (Token *tok = list.front(); tok; tok = tok->next()) {
|
||||
if (!tok->isName() || !Token::Match(tok, "%name% [ ] ="))
|
||||
if (!tok->isName() || !Token::Match(tok, "%var% [ ] ="))
|
||||
continue;
|
||||
bool addlength = false;
|
||||
if (Token::Match(tok, "%name% [ ] = { %str% } ;")) {
|
||||
if (Token::Match(tok, "%var% [ ] = { %str% } ;")) {
|
||||
Token *t = tok->tokAt(3);
|
||||
t->deleteNext();
|
||||
t->next()->deleteNext();
|
||||
addlength = true;
|
||||
}
|
||||
|
||||
if (addlength || Token::Match(tok, "%name% [ ] = %str% ;")) {
|
||||
if (addlength || Token::Match(tok, "%var% [ ] = %str% ;")) {
|
||||
tok = tok->next();
|
||||
std::size_t sz = Token::getStrSize(tok->tokAt(3));
|
||||
tok->insertToken(MathLib::toString((unsigned int)sz));
|
||||
tok = tok->tokAt(5);
|
||||
}
|
||||
|
||||
else if (Token::Match(tok, "%name% [ ] = {")) {
|
||||
else if (Token::Match(tok, "%var% [ ] = {")) {
|
||||
unsigned int sz = 1;
|
||||
tok = tok->next();
|
||||
Token *end = tok->linkAt(3);
|
||||
|
@ -2163,9 +2163,6 @@ void Tokenizer::arraySize()
|
|||
}
|
||||
}
|
||||
tok2 = tok2->link();
|
||||
} else if (tok2->str() == "<") { // Bailout. TODO: When link() supports <>, this bailout becomes unnecessary
|
||||
sz = 0;
|
||||
break;
|
||||
} else if (tok2->str() == ",") {
|
||||
if (!Token::Match(tok2->next(), "[},]"))
|
||||
++sz;
|
||||
|
@ -3328,9 +3325,6 @@ bool Tokenizer::simplifyTokenList1(const char FileName[])
|
|||
simplifyVarDecl(true);
|
||||
simplifyFunctionParameters();
|
||||
|
||||
// specify array size..
|
||||
arraySize();
|
||||
|
||||
// simplify labels and 'case|default'-like syntaxes
|
||||
simplifyLabelsCaseDefault();
|
||||
|
||||
|
@ -3462,9 +3456,6 @@ bool Tokenizer::simplifyTokenList1(const char FileName[])
|
|||
if (_settings->terminated())
|
||||
return false;
|
||||
|
||||
// specify array size.. needed when arrays are split
|
||||
arraySize();
|
||||
|
||||
// f(x=g()) => x=g(); f(x)
|
||||
simplifyAssignmentInFunctionCall();
|
||||
|
||||
|
@ -3529,6 +3520,9 @@ bool Tokenizer::simplifyTokenList1(const char FileName[])
|
|||
// Link < with >
|
||||
createLinks2();
|
||||
|
||||
// specify array size
|
||||
arraySize();
|
||||
|
||||
// The simplify enum might have inner loops
|
||||
if (_settings->terminated())
|
||||
return false;
|
||||
|
|
|
@ -4608,7 +4608,7 @@ private:
|
|||
void functionpointer5() {
|
||||
const char code[] = ";void (*fp[])(int a) = {0,0,0};";
|
||||
const char expected[] = "\n\n##file 0\n"
|
||||
"1: ; void * fp@1 [ ] = { 0 , 0 , 0 } ;\n";
|
||||
"1: ; void * fp@1 [ 3 ] = { 0 , 0 , 0 } ;\n";
|
||||
ASSERT_EQUALS(expected, tokenizeDebugListing(code, false));
|
||||
}
|
||||
|
||||
|
@ -4786,9 +4786,9 @@ private:
|
|||
ASSERT_EQUALS("; int a [ 3 ] = { 1 , 2 , 3 } ;", tokenizeAndStringify(";int a[]={1,2,3};"));
|
||||
ASSERT_EQUALS("; int a [ 3 ] = { 1 , 2 , 3 } ;", tokenizeAndStringify(";int a[]={1,2,3,};"));
|
||||
ASSERT_EQUALS("; foo a [ 3 ] = { { 1 , 2 } , { 3 , 4 } , { 5 , 6 } } ;", tokenizeAndStringify(";foo a[]={{1,2},{3,4},{5,6}};"));
|
||||
TODO_ASSERT_EQUALS("; int a [ 1 ] = { foo < bar1 , bar2 > ( 123 , 4 ) } ;", "; int a [ ] = { foo < bar1 , bar2 > ( 123 , 4 ) } ;", tokenizeAndStringify(";int a[]={foo<bar1,bar2>(123,4)};"));
|
||||
ASSERT_EQUALS("; int a [ 1 ] = { foo < bar1 , bar2 > ( 123 , 4 ) } ;", tokenizeAndStringify(";int a[]={foo<bar1,bar2>(123,4)};"));
|
||||
ASSERT_EQUALS("; int a [ 2 ] = { b > c ? 1 : 2 , 3 } ;", tokenizeAndStringify(";int a[]={ b>c?1:2,3};"));
|
||||
TODO_ASSERT_EQUALS("int main ( ) { int a [ 2 ] = { b < c ? 1 : 2 , 3 } }", "int main ( ) { int a [ ] = { b < c ? 1 : 2 , 3 } }", tokenizeAndStringify("int main(){int a[]={b<c?1:2,3}}"));
|
||||
ASSERT_EQUALS("int main ( ) { int a [ 2 ] = { b < c ? 1 : 2 , 3 } }", tokenizeAndStringify("int main(){int a[]={b<c?1:2,3}}"));
|
||||
ASSERT_EQUALS("; int a [ 3 ] = { ABC , 2 , 3 } ;", tokenizeAndStringify(";int a[]={ABC,2,3};"));
|
||||
ASSERT_EQUALS("; int a [ 3 ] = { [ 2 ] = 5 } ;", tokenizeAndStringify(";int a[]={ [2] = 5 };"));
|
||||
ASSERT_EQUALS("; int a [ 5 ] = { 1 , 2 , [ 2 ] = 5 , 3 , 4 } ;", tokenizeAndStringify(";int a[]={ 1, 2, [2] = 5, 3, 4 };"));
|
||||
|
|
Loading…
Reference in New Issue