diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index d2b11465f..442e2393e 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -2639,14 +2639,27 @@ void Tokenizer::simplifyJavaAndCSharp() if (Token::Match(tok, ") throws %var% {")) tok->deleteNext(2); } else { - if (Token::Match(tok, "%type% [ ] %var% [=;]") && - (!tok->previous() || Token::Match(tok->previous(), "[;{}]"))) { - tok->deleteNext(2); - tok->insertToken("*"); - tok = tok->tokAt(2); - if (tok->next()->str() == "=") - tok = tok->next(); + //simplify C# arrays of arrays declarations + while (Token::Match(tok, "%type% [ ]") && + (!tok->previous() || Token::Match(tok->previous(), "[,;{}]"))) { + Token *tok2 = tok->tokAt(3); + unsigned int count = 1; + while (Token::simpleMatch(tok2, "[ ]")) { + tok2 = tok2->tokAt(2); + ++count; + } + if (!tok2) + break; + else if (Token::Match(tok2, "%var% [;,=]")) { + Token::eraseTokens(tok, tok2); + do { + tok->insertToken("*"); + } while (--count); + tok = tok2->tokAt(2); + } } + if (!tok) + break; } } } diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 5760b5fcd..ba214c849 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -5932,8 +5932,10 @@ private: bool expand = true; Settings::PlatformType platform = Settings::Unspecified; const std::string filename="test.cs"; - ASSERT_EQUALS("int * i ;", tokenizeAndStringify("int [] i;", simplify, expand, platform, filename)); - ASSERT_EQUALS("; int * i ;", tokenizeAndStringify("; int [] i;", simplify, expand, platform, filename)); + ASSERT_EQUALS("int * x ;", tokenizeAndStringify("int [] x;", simplify, expand, platform, filename)); + ASSERT_EQUALS("; int * x , int * y ;", tokenizeAndStringify("; int [] x, int [] y;", simplify, expand, platform, filename)); + ASSERT_EQUALS("; int * * x ;", tokenizeAndStringify("; int [][] x;", simplify, expand, platform, filename)); + ASSERT_EQUALS("; int * * * x ;", tokenizeAndStringify("; int [][][] x;", simplify, expand, platform, filename)); } std::string javatest(const char javacode[]) {