Improve C# simplification code with arrays of arrays.
This commit is contained in:
parent
d0a3560c92
commit
873572d489
|
@ -2639,14 +2639,27 @@ void Tokenizer::simplifyJavaAndCSharp()
|
||||||
if (Token::Match(tok, ") throws %var% {"))
|
if (Token::Match(tok, ") throws %var% {"))
|
||||||
tok->deleteNext(2);
|
tok->deleteNext(2);
|
||||||
} else {
|
} else {
|
||||||
if (Token::Match(tok, "%type% [ ] %var% [=;]") &&
|
//simplify C# arrays of arrays declarations
|
||||||
(!tok->previous() || Token::Match(tok->previous(), "[;{}]"))) {
|
while (Token::Match(tok, "%type% [ ]") &&
|
||||||
tok->deleteNext(2);
|
(!tok->previous() || Token::Match(tok->previous(), "[,;{}]"))) {
|
||||||
tok->insertToken("*");
|
Token *tok2 = tok->tokAt(3);
|
||||||
tok = tok->tokAt(2);
|
unsigned int count = 1;
|
||||||
if (tok->next()->str() == "=")
|
while (Token::simpleMatch(tok2, "[ ]")) {
|
||||||
tok = tok->next();
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5932,8 +5932,10 @@ private:
|
||||||
bool expand = true;
|
bool expand = true;
|
||||||
Settings::PlatformType platform = Settings::Unspecified;
|
Settings::PlatformType platform = Settings::Unspecified;
|
||||||
const std::string filename="test.cs";
|
const std::string filename="test.cs";
|
||||||
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 * i ;", tokenizeAndStringify("; int [] i;", 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[]) {
|
std::string javatest(const char javacode[]) {
|
||||||
|
|
Loading…
Reference in New Issue