Handle also C# multidimensional arrays with no specified dimension.

This commit is contained in:
Edoardo Prezioso 2012-01-02 00:21:58 +01:00
parent e33b80329b
commit eb657034ba
2 changed files with 24 additions and 5 deletions

View File

@ -2639,14 +2639,28 @@ void Tokenizer::simplifyJavaAndCSharp()
if (Token::Match(tok, ") throws %var% {")) if (Token::Match(tok, ") throws %var% {"))
tok->deleteNext(2); tok->deleteNext(2);
} else { } else {
//simplify C# arrays of arrays declarations //simplify C# arrays of arrays and multidimension arrays
while (Token::Match(tok, "%type% [ ]") && while (Token::Match(tok, "%type% [ ,|]") &&
(!tok->previous() || Token::Match(tok->previous(), "[,;{}]"))) { (!tok->previous() || Token::Match(tok->previous(), "[,;{}]"))) {
Token *tok2 = tok->tokAt(3); Token *tok2 = tok->tokAt(2);
unsigned int count = 1; unsigned int count = 1;
while (Token::simpleMatch(tok2, "[ ]")) { while (tok2 && tok2->str() == ",") {
tok2 = tok2->tokAt(2);
++count; ++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) if (!tok2)
break; break;

View File

@ -5960,6 +5960,11 @@ private:
ASSERT_EQUALS("; int * x , int * y ;", tokenizeAndStringify("; int [] x, int [] y;", 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));
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[]) { std::string javatest(const char javacode[]) {