diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 4124751fb..691da017a 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -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; diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 4ebbaa103..0b9adbfdc 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -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(123,4)};")); + ASSERT_EQUALS("; int a [ 1 ] = { foo < bar1 , bar2 > ( 123 , 4 ) } ;", tokenizeAndStringify(";int a[]={foo(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