From eb657034baa2d46424f2d608538de62996dbe033 Mon Sep 17 00:00:00 2001 From: Edoardo Prezioso Date: Mon, 2 Jan 2012 00:21:58 +0100 Subject: [PATCH] Handle also C# multidimensional arrays with no specified dimension. --- lib/tokenize.cpp | 24 +++++++++++++++++++----- test/testtokenize.cpp | 5 +++++ 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index b29da75f8..a2ea8433b 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -2639,14 +2639,28 @@ void Tokenizer::simplifyJavaAndCSharp() if (Token::Match(tok, ") throws %var% {")) tok->deleteNext(2); } else { - //simplify C# arrays of arrays declarations - while (Token::Match(tok, "%type% [ ]") && + //simplify C# arrays of arrays and multidimension arrays + while (Token::Match(tok, "%type% [ ,|]") && (!tok->previous() || Token::Match(tok->previous(), "[,;{}]"))) { - Token *tok2 = tok->tokAt(3); + Token *tok2 = tok->tokAt(2); unsigned int count = 1; - while (Token::simpleMatch(tok2, "[ ]")) { - tok2 = tok2->tokAt(2); + while (tok2 && tok2->str() == ",") { ++count; + tok2 = tok2->next(); + } + if (!tok2 || tok2->str() != "]") + break; + tok2 = tok2->next(); + while (Token::Match(tok2, "[ ,|]")) { + tok2 = tok2->next(); + while (tok2 && tok2->str() == ",") { + ++count; + tok2 = tok2->next(); + } + if (!tok2 || tok2->str() != "]") + break; + ++count; + tok2 = tok2->next(); } if (!tok2) break; diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 7962437cf..9e5651790 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -5960,6 +5960,11 @@ private: 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)); + ASSERT_EQUALS("; int * * x ;", tokenizeAndStringify("; int [,] x;", 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)); + 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[]) {