Fixed ticket #3580 (syntax error in multi variable declaration header).

This commit is contained in:
Edoardo Prezioso 2012-03-31 18:45:29 +02:00
parent 8949464ed6
commit af02908d42
2 changed files with 24 additions and 2 deletions

View File

@ -5124,12 +5124,13 @@ void Tokenizer::simplifyVarDecl(bool only_k_r_fpar)
{
// Split up variable declarations..
// "int a=4;" => "int a; a=4;"
bool finishedwithkr = true;
for (Token *tok = _tokens; tok; tok = tok->next()) {
if (Token::simpleMatch(tok, "= {")) {
tok = tok->next()->link();
}
if (only_k_r_fpar) {
if (only_k_r_fpar && finishedwithkr) {
if (tok->str() == "(" || tok->str() == "[" || tok->str() == "{") {
tok = tok->link();
if (tok->next() && Token::Match(tok, ") !!{"))
@ -5292,8 +5293,11 @@ void Tokenizer::simplifyVarDecl(bool only_k_r_fpar)
tok2 = NULL;
}
if (!tok2)
if (!tok2) {
if (only_k_r_fpar)
finishedwithkr = false;
continue;
}
if (tok2->str() == ",") {
tok2->str(";");
@ -5352,6 +5356,8 @@ void Tokenizer::simplifyVarDecl(bool only_k_r_fpar)
tok2 = tok2->next();
}
}
if (only_k_r_fpar && !finishedwithkr && tok2->strAt(1) == "{")
finishedwithkr = true;
}
}

View File

@ -293,6 +293,7 @@ private:
TEST_CASE(vardecl16);
TEST_CASE(vardecl17);
TEST_CASE(vardecl18);
TEST_CASE(vardecl19);
TEST_CASE(vardecl_stl_1);
TEST_CASE(vardecl_stl_2);
TEST_CASE(vardecl_template);
@ -4699,6 +4700,21 @@ private:
"}", tokenizeAndStringify(code));
}
void vardecl19() {
const char code[] = "void func(in, r, m)\n"
"int in;"
"int r,m;"
"{\n"
"}\n";
ASSERT_EQUALS("void func (\n"
"int in,\n"
"int r,\n"
"int m)\n"
"{\n"
"}", tokenizeAndStringify(code));
}
void volatile_variables() {
const char code[] = "volatile int a=0;\n"
"volatile int b=0;\n"